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