annotate src/share/vm/oops/cpCache.hpp @ 13395:f19b6d14a035

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