src/share/vm/oops/cpCache.hpp

Tue, 17 Oct 2017 12:58:25 +0800

author
aoqi
date
Tue, 17 Oct 2017 12:58:25 +0800
changeset 7994
04ff2f6cd0eb
parent 7795
157895117ad5
parent 7535
7ae4e26cb1e0
child 8604
04d83ba48607
permissions
-rw-r--r--

merge

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

mercurial