src/share/vm/oops/cpCache.hpp

Thu, 24 May 2018 17:06:56 +0800

author
aoqi
date
Thu, 24 May 2018 17:06:56 +0800
changeset 8604
04d83ba48607
parent 8368
32b682649973
parent 7994
04ff2f6cd0eb
child 8856
ac27a9c85bea
permissions
-rw-r--r--

Merge

aoqi@0 1 /*
kevinw@8368 2 * Copyright (c) 1998, 2016, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_OOPS_CPCACHEOOP_HPP
aoqi@0 26 #define SHARE_VM_OOPS_CPCACHEOOP_HPP
aoqi@0 27
aoqi@0 28 #include "interpreter/bytecodes.hpp"
aoqi@0 29 #include "memory/allocation.hpp"
goetz@6911 30 #include "runtime/orderAccess.hpp"
aoqi@0 31 #include "utilities/array.hpp"
aoqi@0 32
aoqi@0 33 class PSPromotionManager;
aoqi@0 34
aoqi@0 35 // The ConstantPoolCache is not a cache! It is the resolution table that the
aoqi@0 36 // interpreter uses to avoid going into the runtime and a way to access resolved
aoqi@0 37 // values.
aoqi@0 38
aoqi@0 39 // A ConstantPoolCacheEntry describes an individual entry of the constant
aoqi@0 40 // pool cache. There's 2 principal kinds of entries: field entries for in-
aoqi@0 41 // stance & static field access, and method entries for invokes. Some of
aoqi@0 42 // the entry layout is shared and looks as follows:
aoqi@0 43 //
aoqi@0 44 // bit number |31 0|
aoqi@0 45 // bit length |-8--|-8--|---16----|
aoqi@0 46 // --------------------------------
aoqi@0 47 // _indices [ b2 | b1 | index ] index = constant_pool_index
aoqi@0 48 // _f1 [ entry specific ] metadata ptr (method or klass)
aoqi@0 49 // _f2 [ entry specific ] vtable or res_ref index, or vfinal method ptr
aoqi@0 50 // _flags [tos|0|F=1|0|0|0|f|v|0 |0000|field_index] (for field entries)
aoqi@0 51 // bit length [ 4 |1| 1 |1|1|1|1|1|1 |-4--|----16-----]
aoqi@0 52 // _flags [tos|0|F=0|M|A|I|f|0|vf|0000|00000|psize] (for method entries)
aoqi@0 53 // bit length [ 4 |1| 1 |1|1|1|1|1|1 |-4--|--8--|--8--]
aoqi@0 54
aoqi@0 55 // --------------------------------
aoqi@0 56 //
aoqi@0 57 // with:
aoqi@0 58 // index = original constant pool index
aoqi@0 59 // b1 = bytecode 1
aoqi@0 60 // b2 = bytecode 2
aoqi@0 61 // psize = parameters size (method entries only)
aoqi@0 62 // field_index = index into field information in holder InstanceKlass
aoqi@0 63 // The index max is 0xffff (max number of fields in constant pool)
aoqi@0 64 // and is multiplied by (InstanceKlass::next_offset) when accessing.
aoqi@0 65 // tos = TosState
aoqi@0 66 // F = the entry is for a field (or F=0 for a method)
aoqi@0 67 // A = call site has an appendix argument (loaded from resolved references)
aoqi@0 68 // I = interface call is forced virtual (must use a vtable index or vfinal)
aoqi@0 69 // f = field or method is final
aoqi@0 70 // v = field is volatile
aoqi@0 71 // vf = virtual but final (method entries only: is_vfinal())
aoqi@0 72 //
aoqi@0 73 // The flags after TosState have the following interpretation:
aoqi@0 74 // bit 27: 0 for fields, 1 for methods
aoqi@0 75 // f flag true if field is marked final
aoqi@0 76 // v flag true if field is volatile (only for fields)
aoqi@0 77 // f2 flag true if f2 contains an oop (e.g., virtual final method)
aoqi@0 78 // fv flag true if invokeinterface used for method in class Object
aoqi@0 79 //
kevinw@8368 80 // The flags 31, 30, 29, 28 together build a 4 bit number 0 to 16 with the
aoqi@0 81 // following mapping to the TosState states:
aoqi@0 82 //
aoqi@0 83 // btos: 0
kevinw@8368 84 // ztos: 1
kevinw@8368 85 // ctos: 2
kevinw@8368 86 // stos: 3
kevinw@8368 87 // itos: 4
kevinw@8368 88 // ltos: 5
kevinw@8368 89 // ftos: 6
kevinw@8368 90 // dtos: 7
kevinw@8368 91 // atos: 8
kevinw@8368 92 // vtos: 9
aoqi@0 93 //
aoqi@0 94 // Entry specific: field entries:
aoqi@0 95 // _indices = get (b1 section) and put (b2 section) bytecodes, original constant pool index
aoqi@0 96 // _f1 = field holder (as a java.lang.Class, not a Klass*)
aoqi@0 97 // _f2 = field offset in bytes
aoqi@0 98 // _flags = field type information, original FieldInfo index in field holder
aoqi@0 99 // (field_index section)
aoqi@0 100 //
aoqi@0 101 // Entry specific: method entries:
aoqi@0 102 // _indices = invoke code for f1 (b1 section), invoke code for f2 (b2 section),
aoqi@0 103 // original constant pool index
aoqi@0 104 // _f1 = Method* for non-virtual calls, unused by virtual calls.
aoqi@0 105 // for interface calls, which are essentially virtual but need a klass,
aoqi@0 106 // contains Klass* for the corresponding interface.
aoqi@0 107 // for invokedynamic, f1 contains a site-specific CallSite object (as an appendix)
aoqi@0 108 // for invokehandle, f1 contains a site-specific MethodType object (as an appendix)
aoqi@0 109 // (upcoming metadata changes will move the appendix to a separate array)
aoqi@0 110 // _f2 = vtable/itable index (or final Method*) for virtual calls only,
aoqi@0 111 // unused by non-virtual. The is_vfinal flag indicates this is a
aoqi@0 112 // method pointer for a final method, not an index.
aoqi@0 113 // _flags = method type info (t section),
aoqi@0 114 // virtual final bit (vfinal),
aoqi@0 115 // parameter size (psize section)
aoqi@0 116 //
aoqi@0 117 // Note: invokevirtual & invokespecial bytecodes can share the same constant
aoqi@0 118 // pool entry and thus the same constant pool cache entry. All invoke
aoqi@0 119 // bytecodes but invokevirtual use only _f1 and the corresponding b1
aoqi@0 120 // bytecode, while invokevirtual uses only _f2 and the corresponding
aoqi@0 121 // b2 bytecode. The value of _flags is shared for both types of entries.
aoqi@0 122 //
aoqi@0 123 // The fields are volatile so that they are stored in the order written in the
aoqi@0 124 // source code. The _indices field with the bytecode must be written last.
aoqi@0 125
aoqi@0 126 class CallInfo;
aoqi@0 127
aoqi@0 128 class ConstantPoolCacheEntry VALUE_OBJ_CLASS_SPEC {
aoqi@0 129 friend class VMStructs;
aoqi@0 130 friend class constantPoolCacheKlass;
aoqi@0 131 friend class ConstantPool;
aoqi@0 132 friend class InterpreterRuntime;
aoqi@0 133
aoqi@0 134 private:
aoqi@0 135 volatile intx _indices; // constant pool index & rewrite bytecodes
aoqi@0 136 volatile Metadata* _f1; // entry specific metadata field
aoqi@0 137 volatile intx _f2; // entry specific int/metadata field
aoqi@0 138 volatile intx _flags; // flags
aoqi@0 139
aoqi@0 140
aoqi@0 141 void set_bytecode_1(Bytecodes::Code code);
aoqi@0 142 void set_bytecode_2(Bytecodes::Code code);
aoqi@0 143 void set_f1(Metadata* f1) {
aoqi@0 144 Metadata* existing_f1 = (Metadata*)_f1; // read once
aoqi@0 145 assert(existing_f1 == NULL || existing_f1 == f1, "illegal field change");
aoqi@0 146 _f1 = f1;
aoqi@0 147 }
aoqi@0 148 void release_set_f1(Metadata* f1);
aoqi@0 149 void set_f2(intx f2) {
aoqi@0 150 intx existing_f2 = _f2; // read once
aoqi@0 151 assert(existing_f2 == 0 || existing_f2 == f2, "illegal field change");
aoqi@0 152 _f2 = f2;
aoqi@0 153 }
aoqi@0 154 void set_f2_as_vfinal_method(Method* f2) {
aoqi@0 155 assert(is_vfinal(), "flags must be set");
aoqi@0 156 set_f2((intx)f2);
aoqi@0 157 }
aoqi@0 158 int make_flags(TosState state, int option_bits, int field_index_or_method_params);
aoqi@0 159 void set_flags(intx flags) { _flags = flags; }
aoqi@0 160 bool init_flags_atomic(intx flags);
aoqi@0 161 void set_field_flags(TosState field_type, int option_bits, int field_index) {
aoqi@0 162 assert((field_index & field_index_mask) == field_index, "field_index in range");
aoqi@0 163 set_flags(make_flags(field_type, option_bits | (1 << is_field_entry_shift), field_index));
aoqi@0 164 }
aoqi@0 165 void set_method_flags(TosState return_type, int option_bits, int method_params) {
aoqi@0 166 assert((method_params & parameter_size_mask) == method_params, "method_params in range");
aoqi@0 167 set_flags(make_flags(return_type, option_bits, method_params));
aoqi@0 168 }
aoqi@0 169 bool init_method_flags_atomic(TosState return_type, int option_bits, int method_params) {
aoqi@0 170 assert((method_params & parameter_size_mask) == method_params, "method_params in range");
aoqi@0 171 return init_flags_atomic(make_flags(return_type, option_bits, method_params));
aoqi@0 172 }
aoqi@0 173
aoqi@0 174 public:
aoqi@0 175 // specific bit definitions for the flags field:
aoqi@0 176 // (Note: the interpreter must use these definitions to access the CP cache.)
aoqi@0 177 enum {
aoqi@0 178 // high order bits are the TosState corresponding to field type or method return type
aoqi@0 179 tos_state_bits = 4,
aoqi@0 180 tos_state_mask = right_n_bits(tos_state_bits),
aoqi@0 181 tos_state_shift = BitsPerInt - tos_state_bits, // see verify_tos_state_shift below
aoqi@0 182 // misc. option bits; can be any bit position in [16..27]
aoqi@0 183 is_field_entry_shift = 26, // (F) is it a field or a method?
aoqi@0 184 has_method_type_shift = 25, // (M) does the call site have a MethodType?
aoqi@0 185 has_appendix_shift = 24, // (A) does the call site have an appendix argument?
aoqi@0 186 is_forced_virtual_shift = 23, // (I) is the interface reference forced to virtual mode?
aoqi@0 187 is_final_shift = 22, // (f) is the field or method final?
aoqi@0 188 is_volatile_shift = 21, // (v) is the field volatile?
aoqi@0 189 is_vfinal_shift = 20, // (vf) did the call resolve to a final method?
aoqi@0 190 // low order bits give field index (for FieldInfo) or method parameter size:
aoqi@0 191 field_index_bits = 16,
aoqi@0 192 field_index_mask = right_n_bits(field_index_bits),
aoqi@0 193 parameter_size_bits = 8, // subset of field_index_mask, range is 0..255
aoqi@0 194 parameter_size_mask = right_n_bits(parameter_size_bits),
aoqi@0 195 option_bits_mask = ~(((-1) << tos_state_shift) | (field_index_mask | parameter_size_mask))
aoqi@0 196 };
aoqi@0 197
aoqi@0 198 // specific bit definitions for the indices field:
aoqi@0 199 enum {
aoqi@0 200 cp_index_bits = 2*BitsPerByte,
aoqi@0 201 cp_index_mask = right_n_bits(cp_index_bits),
aoqi@0 202 bytecode_1_shift = cp_index_bits,
aoqi@0 203 bytecode_1_mask = right_n_bits(BitsPerByte), // == (u1)0xFF
aoqi@0 204 bytecode_2_shift = cp_index_bits + BitsPerByte,
aoqi@0 205 bytecode_2_mask = right_n_bits(BitsPerByte) // == (u1)0xFF
aoqi@0 206 };
aoqi@0 207
aoqi@0 208
aoqi@0 209 // Initialization
aoqi@0 210 void initialize_entry(int original_index); // initialize primary entry
aoqi@0 211 void initialize_resolved_reference_index(int ref_index) {
aoqi@0 212 assert(_f2 == 0, "set once"); // note: ref_index might be zero also
aoqi@0 213 _f2 = ref_index;
aoqi@0 214 }
aoqi@0 215
aoqi@0 216 void set_field( // sets entry to resolved field state
aoqi@0 217 Bytecodes::Code get_code, // the bytecode used for reading the field
aoqi@0 218 Bytecodes::Code put_code, // the bytecode used for writing the field
aoqi@0 219 KlassHandle field_holder, // the object/klass holding the field
aoqi@0 220 int orig_field_index, // the original field index in the field holder
aoqi@0 221 int field_offset, // the field offset in words in the field holder
aoqi@0 222 TosState field_type, // the (machine) field type
aoqi@0 223 bool is_final, // the field is final
aoqi@0 224 bool is_volatile, // the field is volatile
aoqi@0 225 Klass* root_klass // needed by the GC to dirty the klass
aoqi@0 226 );
aoqi@0 227
aoqi@0 228 private:
aoqi@0 229 void set_direct_or_vtable_call(
aoqi@0 230 Bytecodes::Code invoke_code, // the bytecode used for invoking the method
aoqi@0 231 methodHandle method, // the method/prototype if any (NULL, otherwise)
aoqi@0 232 int vtable_index // the vtable index if any, else negative
aoqi@0 233 );
aoqi@0 234
aoqi@0 235 public:
aoqi@0 236 void set_direct_call( // sets entry to exact concrete method entry
aoqi@0 237 Bytecodes::Code invoke_code, // the bytecode used for invoking the method
aoqi@0 238 methodHandle method // the method to call
aoqi@0 239 );
aoqi@0 240
aoqi@0 241 void set_vtable_call( // sets entry to vtable index
aoqi@0 242 Bytecodes::Code invoke_code, // the bytecode used for invoking the method
aoqi@0 243 methodHandle method, // resolved method which declares the vtable index
aoqi@0 244 int vtable_index // the vtable index
aoqi@0 245 );
aoqi@0 246
aoqi@0 247 void set_itable_call(
aoqi@0 248 Bytecodes::Code invoke_code, // the bytecode used; must be invokeinterface
aoqi@0 249 methodHandle method, // the resolved interface method
aoqi@0 250 int itable_index // index into itable for the method
aoqi@0 251 );
aoqi@0 252
aoqi@0 253 void set_method_handle(
aoqi@0 254 constantPoolHandle cpool, // holding constant pool (required for locking)
aoqi@0 255 const CallInfo &call_info // Call link information
aoqi@0 256 );
aoqi@0 257
aoqi@0 258 void set_dynamic_call(
aoqi@0 259 constantPoolHandle cpool, // holding constant pool (required for locking)
aoqi@0 260 const CallInfo &call_info // Call link information
aoqi@0 261 );
aoqi@0 262
aoqi@0 263 // Common code for invokedynamic and MH invocations.
aoqi@0 264
aoqi@0 265 // The "appendix" is an optional call-site-specific parameter which is
aoqi@0 266 // pushed by the JVM at the end of the argument list. This argument may
aoqi@0 267 // be a MethodType for the MH.invokes and a CallSite for an invokedynamic
aoqi@0 268 // instruction. However, its exact type and use depends on the Java upcall,
aoqi@0 269 // which simply returns a compiled LambdaForm along with any reference
aoqi@0 270 // that LambdaForm needs to complete the call. If the upcall returns a
aoqi@0 271 // null appendix, the argument is not passed at all.
aoqi@0 272 //
aoqi@0 273 // The appendix is *not* represented in the signature of the symbolic
aoqi@0 274 // reference for the call site, but (if present) it *is* represented in
aoqi@0 275 // the Method* bound to the site. This means that static and dynamic
aoqi@0 276 // resolution logic needs to make slightly different assessments about the
aoqi@0 277 // number and types of arguments.
aoqi@0 278 void set_method_handle_common(
aoqi@0 279 constantPoolHandle cpool, // holding constant pool (required for locking)
aoqi@0 280 Bytecodes::Code invoke_code, // _invokehandle or _invokedynamic
aoqi@0 281 const CallInfo &call_info // Call link information
aoqi@0 282 );
aoqi@0 283
aoqi@0 284 // invokedynamic and invokehandle call sites have two entries in the
aoqi@0 285 // resolved references array:
aoqi@0 286 // appendix (at index+0)
aoqi@0 287 // MethodType (at index+1)
aoqi@0 288 enum {
aoqi@0 289 _indy_resolved_references_appendix_offset = 0,
aoqi@0 290 _indy_resolved_references_method_type_offset = 1,
aoqi@0 291 _indy_resolved_references_entries
aoqi@0 292 };
aoqi@0 293
aoqi@0 294 Method* method_if_resolved(constantPoolHandle cpool);
aoqi@0 295 oop appendix_if_resolved(constantPoolHandle cpool);
aoqi@0 296 oop method_type_if_resolved(constantPoolHandle cpool);
aoqi@0 297
aoqi@0 298 void set_parameter_size(int value);
aoqi@0 299
aoqi@0 300 // Which bytecode number (1 or 2) in the index field is valid for this bytecode?
aoqi@0 301 // Returns -1 if neither is valid.
aoqi@0 302 static int bytecode_number(Bytecodes::Code code) {
aoqi@0 303 switch (code) {
aoqi@0 304 case Bytecodes::_getstatic : // fall through
aoqi@0 305 case Bytecodes::_getfield : // fall through
aoqi@0 306 case Bytecodes::_invokespecial : // fall through
aoqi@0 307 case Bytecodes::_invokestatic : // fall through
aoqi@0 308 case Bytecodes::_invokehandle : // fall through
aoqi@0 309 case Bytecodes::_invokedynamic : // fall through
aoqi@0 310 case Bytecodes::_invokeinterface : return 1;
aoqi@0 311 case Bytecodes::_putstatic : // fall through
aoqi@0 312 case Bytecodes::_putfield : // fall through
aoqi@0 313 case Bytecodes::_invokevirtual : return 2;
aoqi@0 314 default : break;
aoqi@0 315 }
aoqi@0 316 return -1;
aoqi@0 317 }
aoqi@0 318
aoqi@0 319 // Has this bytecode been resolved? Only valid for invokes and get/put field/static.
aoqi@0 320 bool is_resolved(Bytecodes::Code code) const {
aoqi@0 321 switch (bytecode_number(code)) {
aoqi@0 322 case 1: return (bytecode_1() == code);
aoqi@0 323 case 2: return (bytecode_2() == code);
aoqi@0 324 }
aoqi@0 325 return false; // default: not resolved
aoqi@0 326 }
aoqi@0 327
aoqi@0 328 // Accessors
aoqi@0 329 int indices() const { return _indices; }
aoqi@0 330 int indices_ord() const { return (intx)OrderAccess::load_ptr_acquire(&_indices); }
aoqi@0 331 int constant_pool_index() const { return (indices() & cp_index_mask); }
aoqi@0 332 Bytecodes::Code bytecode_1() const { return Bytecodes::cast((indices_ord() >> bytecode_1_shift) & bytecode_1_mask); }
aoqi@0 333 Bytecodes::Code bytecode_2() const { return Bytecodes::cast((indices_ord() >> bytecode_2_shift) & bytecode_2_mask); }
aoqi@0 334 Metadata* f1_ord() const { return (Metadata *)OrderAccess::load_ptr_acquire(&_f1); }
aoqi@0 335 Method* f1_as_method() const { Metadata* f1 = f1_ord(); assert(f1 == NULL || f1->is_method(), ""); return (Method*)f1; }
aoqi@0 336 Klass* f1_as_klass() const { Metadata* f1 = f1_ord(); assert(f1 == NULL || f1->is_klass(), ""); return (Klass*)f1; }
aoqi@0 337 // Use the accessor f1() to acquire _f1's value. This is needed for
aoqi@0 338 // example in BytecodeInterpreter::run(), where is_f1_null() is
aoqi@0 339 // called to check if an invokedynamic call is resolved. This load
aoqi@0 340 // of _f1 must be ordered with the loads performed by
aoqi@0 341 // cache->main_entry_index().
aoqi@0 342 bool is_f1_null() const { Metadata* f1 = f1_ord(); return f1 == NULL; } // classifies a CPC entry as unbound
aoqi@0 343 int f2_as_index() const { assert(!is_vfinal(), ""); return (int) _f2; }
aoqi@0 344 Method* f2_as_vfinal_method() const { assert(is_vfinal(), ""); return (Method*)_f2; }
aoqi@0 345 int field_index() const { assert(is_field_entry(), ""); return (_flags & field_index_mask); }
aoqi@0 346 int parameter_size() const { assert(is_method_entry(), ""); return (_flags & parameter_size_mask); }
aoqi@0 347 bool is_volatile() const { return (_flags & (1 << is_volatile_shift)) != 0; }
aoqi@0 348 bool is_final() const { return (_flags & (1 << is_final_shift)) != 0; }
aoqi@0 349 bool is_forced_virtual() const { return (_flags & (1 << is_forced_virtual_shift)) != 0; }
aoqi@0 350 bool is_vfinal() const { return (_flags & (1 << is_vfinal_shift)) != 0; }
aoqi@0 351 bool has_appendix() const { return (!is_f1_null()) && (_flags & (1 << has_appendix_shift)) != 0; }
aoqi@0 352 bool has_method_type() const { return (!is_f1_null()) && (_flags & (1 << has_method_type_shift)) != 0; }
aoqi@0 353 bool is_method_entry() const { return (_flags & (1 << is_field_entry_shift)) == 0; }
aoqi@0 354 bool is_field_entry() const { return (_flags & (1 << is_field_entry_shift)) != 0; }
aoqi@0 355 bool is_long() const { return flag_state() == ltos; }
aoqi@0 356 bool is_double() const { return flag_state() == dtos; }
aoqi@0 357 TosState flag_state() const { assert((uint)number_of_states <= (uint)tos_state_mask+1, "");
aoqi@0 358 return (TosState)((_flags >> tos_state_shift) & tos_state_mask); }
aoqi@0 359
aoqi@0 360 // Code generation support
aoqi@0 361 static WordSize size() { return in_WordSize(sizeof(ConstantPoolCacheEntry) / HeapWordSize); }
aoqi@0 362 static ByteSize size_in_bytes() { return in_ByteSize(sizeof(ConstantPoolCacheEntry)); }
aoqi@0 363 static ByteSize indices_offset() { return byte_offset_of(ConstantPoolCacheEntry, _indices); }
aoqi@0 364 static ByteSize f1_offset() { return byte_offset_of(ConstantPoolCacheEntry, _f1); }
aoqi@0 365 static ByteSize f2_offset() { return byte_offset_of(ConstantPoolCacheEntry, _f2); }
aoqi@0 366 static ByteSize flags_offset() { return byte_offset_of(ConstantPoolCacheEntry, _flags); }
aoqi@0 367
aoqi@0 368 #if INCLUDE_JVMTI
aoqi@0 369 // RedefineClasses() API support:
aoqi@0 370 // If this ConstantPoolCacheEntry refers to old_method then update it
aoqi@0 371 // to refer to new_method.
aoqi@0 372 // trace_name_printed is set to true if the current call has
aoqi@0 373 // printed the klass name so that other routines in the adjust_*
aoqi@0 374 // group don't print the klass name.
aoqi@0 375 bool adjust_method_entry(Method* old_method, Method* new_method,
sspitsyn@7636 376 bool* trace_name_printed);
aoqi@0 377 bool check_no_old_or_obsolete_entries();
sspitsyn@7636 378 Method* get_interesting_method_entry(Klass* k);
aoqi@0 379 #endif // INCLUDE_JVMTI
aoqi@0 380
aoqi@0 381 // Debugging & Printing
aoqi@0 382 void print (outputStream* st, int index) const;
aoqi@0 383 void verify(outputStream* st) const;
aoqi@0 384
aoqi@0 385 static void verify_tos_state_shift() {
aoqi@0 386 // When shifting flags as a 32-bit int, make sure we don't need an extra mask for tos_state:
aoqi@0 387 assert((((u4)-1 >> tos_state_shift) & ~tos_state_mask) == 0, "no need for tos_state mask");
aoqi@0 388 }
aoqi@0 389 };
aoqi@0 390
aoqi@0 391
aoqi@0 392 // A constant pool cache is a runtime data structure set aside to a constant pool. The cache
aoqi@0 393 // holds interpreter runtime information for all field access and invoke bytecodes. The cache
aoqi@0 394 // is created and initialized before a class is actively used (i.e., initialized), the indivi-
aoqi@0 395 // dual cache entries are filled at resolution (i.e., "link") time (see also: rewriter.*).
aoqi@0 396
aoqi@0 397 class ConstantPoolCache: public MetaspaceObj {
aoqi@0 398 friend class VMStructs;
aoqi@0 399 friend class MetadataFactory;
aoqi@0 400 private:
aoqi@0 401 int _length;
aoqi@0 402 ConstantPool* _constant_pool; // the corresponding constant pool
aoqi@0 403
aoqi@0 404 // Sizing
aoqi@0 405 debug_only(friend class ClassVerifier;)
aoqi@0 406
aoqi@0 407 // Constructor
aoqi@0 408 ConstantPoolCache(int length,
aoqi@0 409 const intStack& inverse_index_map,
aoqi@0 410 const intStack& invokedynamic_inverse_index_map,
aoqi@0 411 const intStack& invokedynamic_references_map) :
aoqi@0 412 _length(length),
aoqi@0 413 _constant_pool(NULL) {
aoqi@0 414 initialize(inverse_index_map, invokedynamic_inverse_index_map,
aoqi@0 415 invokedynamic_references_map);
aoqi@0 416 for (int i = 0; i < length; i++) {
aoqi@0 417 assert(entry_at(i)->is_f1_null(), "Failed to clear?");
aoqi@0 418 }
aoqi@0 419 }
aoqi@0 420
aoqi@0 421 // Initialization
aoqi@0 422 void initialize(const intArray& inverse_index_map,
aoqi@0 423 const intArray& invokedynamic_inverse_index_map,
aoqi@0 424 const intArray& invokedynamic_references_map);
aoqi@0 425 public:
aoqi@0 426 static ConstantPoolCache* allocate(ClassLoaderData* loader_data,
aoqi@0 427 const intStack& cp_cache_map,
aoqi@0 428 const intStack& invokedynamic_cp_cache_map,
aoqi@0 429 const intStack& invokedynamic_references_map, TRAPS);
aoqi@0 430 bool is_constantPoolCache() const { return true; }
aoqi@0 431
aoqi@0 432 int length() const { return _length; }
aoqi@0 433 private:
aoqi@0 434 void set_length(int length) { _length = length; }
aoqi@0 435
aoqi@0 436 static int header_size() { return sizeof(ConstantPoolCache) / HeapWordSize; }
aoqi@0 437 static int size(int length) { return align_object_size(header_size() + length * in_words(ConstantPoolCacheEntry::size())); }
aoqi@0 438 public:
aoqi@0 439 int size() const { return size(length()); }
aoqi@0 440 private:
aoqi@0 441
aoqi@0 442 // Helpers
aoqi@0 443 ConstantPool** constant_pool_addr() { return &_constant_pool; }
aoqi@0 444 ConstantPoolCacheEntry* base() const { return (ConstantPoolCacheEntry*)((address)this + in_bytes(base_offset())); }
aoqi@0 445
aoqi@0 446 friend class constantPoolCacheKlass;
aoqi@0 447 friend class ConstantPoolCacheEntry;
aoqi@0 448
aoqi@0 449 public:
aoqi@0 450 // Accessors
aoqi@0 451 void set_constant_pool(ConstantPool* pool) { _constant_pool = pool; }
aoqi@0 452 ConstantPool* constant_pool() const { return _constant_pool; }
aoqi@0 453 // Fetches the entry at the given index.
aoqi@0 454 // In either case the index must not be encoded or byte-swapped in any way.
aoqi@0 455 ConstantPoolCacheEntry* entry_at(int i) const {
aoqi@0 456 assert(0 <= i && i < length(), "index out of bounds");
aoqi@0 457 return base() + i;
aoqi@0 458 }
aoqi@0 459
aoqi@0 460 // Code generation
aoqi@0 461 static ByteSize base_offset() { return in_ByteSize(sizeof(ConstantPoolCache)); }
aoqi@0 462 static ByteSize entry_offset(int raw_index) {
aoqi@0 463 int index = raw_index;
aoqi@0 464 return (base_offset() + ConstantPoolCacheEntry::size_in_bytes() * index);
aoqi@0 465 }
aoqi@0 466
aoqi@0 467 #if INCLUDE_JVMTI
aoqi@0 468 // RedefineClasses() API support:
aoqi@0 469 // If any entry of this ConstantPoolCache points to any of
aoqi@0 470 // old_methods, replace it with the corresponding new_method.
aoqi@0 471 // trace_name_printed is set to true if the current call has
aoqi@0 472 // printed the klass name so that other routines in the adjust_*
aoqi@0 473 // group don't print the klass name.
sspitsyn@7636 474 void adjust_method_entries(InstanceKlass* holder, bool* trace_name_printed);
aoqi@0 475 bool check_no_old_or_obsolete_entries();
aoqi@0 476 void dump_cache();
aoqi@0 477 #endif // INCLUDE_JVMTI
aoqi@0 478
aoqi@0 479 // Deallocate - no fields to deallocate
aoqi@0 480 DEBUG_ONLY(bool on_stack() { return false; })
aoqi@0 481 void deallocate_contents(ClassLoaderData* data) {}
aoqi@0 482 bool is_klass() const { return false; }
aoqi@0 483
aoqi@0 484 // Printing
aoqi@0 485 void print_on(outputStream* st) const;
aoqi@0 486 void print_value_on(outputStream* st) const;
aoqi@0 487
aoqi@0 488 const char* internal_name() const { return "{constant pool cache}"; }
aoqi@0 489
aoqi@0 490 // Verify
aoqi@0 491 void verify_on(outputStream* st);
aoqi@0 492 };
aoqi@0 493
aoqi@0 494 #endif // SHARE_VM_OOPS_CPCACHEOOP_HPP

mercurial