annotate src/share/vm/oops/cpCache.hpp @ 7745:6dc8db7164d2

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