Tue, 24 Jul 2012 10:51:00 -0700
7023639: JSR 292 method handle invocation needs a fast path for compiled code
6984705: JSR 292 method handle creation should not go through JNI
Summary: remove assembly code for JDK 7 chained method handles
Reviewed-by: jrose, twisti, kvn, mhaupt
Contributed-by: John Rose <john.r.rose@oracle.com>, Christian Thalinger <christian.thalinger@oracle.com>, Michael Haupt <michael.haupt@oracle.com>
duke@435 | 1 | /* |
stefank@2534 | 2 | * Copyright (c) 1998, 2011, 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" |
stefank@2314 | 30 | #include "oops/arrayOop.hpp" |
stefank@2314 | 31 | #include "utilities/array.hpp" |
stefank@2314 | 32 | |
duke@435 | 33 | // A ConstantPoolCacheEntry describes an individual entry of the constant |
duke@435 | 34 | // pool cache. There's 2 principal kinds of entries: field entries for in- |
duke@435 | 35 | // stance & static field access, and method entries for invokes. Some of |
duke@435 | 36 | // the entry layout is shared and looks as follows: |
duke@435 | 37 | // |
duke@435 | 38 | // bit number |31 0| |
duke@435 | 39 | // bit length |-8--|-8--|---16----| |
duke@435 | 40 | // -------------------------------- |
twisti@3969 | 41 | // _indices [ b2 | b1 | index ] index = constant_pool_index (!= 0, normal entries only) |
twisti@3969 | 42 | // _indices [ index | 00000 ] index = main_entry_index (secondary entries only) |
twisti@3969 | 43 | // _f1 [ entry specific ] method, klass, or oop (MethodType or CallSite) |
twisti@3969 | 44 | // _f2 [ entry specific ] vtable index or vfinal method |
twisti@3969 | 45 | // _flags [tos|0|00|00|00|f|v|f2|unused|field_index] (for field entries) |
twisti@3969 | 46 | // bit length [ 4 |1|1 |1 | 1|1|1| 1|---5--|----16-----] |
twisti@3969 | 47 | // _flags [tos|M|vf|fv|ea|f|0|f2|unused|00000|psize] (for method entries) |
twisti@3969 | 48 | // bit length [ 4 |1|1 |1 | 1|1|1| 1|---5--|--8--|--8--] |
duke@435 | 49 | |
duke@435 | 50 | // -------------------------------- |
duke@435 | 51 | // |
duke@435 | 52 | // with: |
duke@435 | 53 | // index = original constant pool index |
duke@435 | 54 | // b1 = bytecode 1 |
duke@435 | 55 | // b2 = bytecode 2 |
twisti@3969 | 56 | // psize = parameters size (method entries only) |
duke@435 | 57 | // field_index = index into field information in holder instanceKlass |
duke@435 | 58 | // The index max is 0xffff (max number of fields in constant pool) |
duke@435 | 59 | // and is multiplied by (instanceKlass::next_offset) when accessing. |
duke@435 | 60 | // t = TosState (see below) |
duke@435 | 61 | // f = field is marked final (see below) |
twisti@3969 | 62 | // f2 = virtual but final (method entries only: is_vfinal()) |
duke@435 | 63 | // v = field is volatile (see below) |
duke@435 | 64 | // m = invokeinterface used for method in class Object (see below) |
duke@435 | 65 | // h = RedefineClasses/Hotswap bit (see below) |
duke@435 | 66 | // |
duke@435 | 67 | // The flags after TosState have the following interpretation: |
twisti@3969 | 68 | // bit 27: 0 for fields, 1 for methods |
twisti@3969 | 69 | // f flag true if field is marked final |
twisti@3969 | 70 | // v flag true if field is volatile (only for fields) |
twisti@3969 | 71 | // f2 flag true if f2 contains an oop (e.g., virtual final method) |
twisti@3969 | 72 | // fv flag true if invokeinterface used for method in class Object |
duke@435 | 73 | // |
duke@435 | 74 | // The flags 31, 30, 29, 28 together build a 4 bit number 0 to 8 with the |
duke@435 | 75 | // following mapping to the TosState states: |
duke@435 | 76 | // |
duke@435 | 77 | // btos: 0 |
duke@435 | 78 | // ctos: 1 |
duke@435 | 79 | // stos: 2 |
duke@435 | 80 | // itos: 3 |
duke@435 | 81 | // ltos: 4 |
duke@435 | 82 | // ftos: 5 |
duke@435 | 83 | // dtos: 6 |
duke@435 | 84 | // atos: 7 |
duke@435 | 85 | // vtos: 8 |
duke@435 | 86 | // |
duke@435 | 87 | // Entry specific: field entries: |
duke@435 | 88 | // _indices = get (b1 section) and put (b2 section) bytecodes, original constant pool index |
twisti@3969 | 89 | // _f1 = field holder (as a java.lang.Class, not a klassOop) |
twisti@3969 | 90 | // _f2 = field offset in bytes |
twisti@3969 | 91 | // _flags = field type information, original FieldInfo index in field holder |
duke@435 | 92 | // (field_index section) |
duke@435 | 93 | // |
duke@435 | 94 | // Entry specific: method entries: |
duke@435 | 95 | // _indices = invoke code for f1 (b1 section), invoke code for f2 (b2 section), |
duke@435 | 96 | // original constant pool index |
twisti@3969 | 97 | // _f1 = methodOop for non-virtual calls, unused by virtual calls. |
twisti@3969 | 98 | // for interface calls, which are essentially virtual but need a klass, |
twisti@3969 | 99 | // contains klassOop for the corresponding interface. |
twisti@3969 | 100 | // for invokedynamic, f1 contains a site-specific CallSite object (as an appendix) |
twisti@3969 | 101 | // for invokehandle, f1 contains a site-specific MethodType object (as an appendix) |
twisti@3969 | 102 | // (upcoming metadata changes will move the appendix to a separate array) |
twisti@3969 | 103 | // _f2 = vtable/itable index (or final methodOop) for virtual calls only, |
twisti@3969 | 104 | // unused by non-virtual. The is_vfinal flag indicates this is a |
twisti@3969 | 105 | // method pointer for a final method, not an index. |
twisti@3969 | 106 | // _flags = method type info (t section), |
twisti@3969 | 107 | // virtual final bit (vfinal), |
twisti@3969 | 108 | // parameter size (psize section) |
duke@435 | 109 | // |
duke@435 | 110 | // Note: invokevirtual & invokespecial bytecodes can share the same constant |
duke@435 | 111 | // pool entry and thus the same constant pool cache entry. All invoke |
duke@435 | 112 | // bytecodes but invokevirtual use only _f1 and the corresponding b1 |
duke@435 | 113 | // bytecode, while invokevirtual uses only _f2 and the corresponding |
duke@435 | 114 | // b2 bytecode. The value of _flags is shared for both types of entries. |
duke@435 | 115 | // |
duke@435 | 116 | // The fields are volatile so that they are stored in the order written in the |
duke@435 | 117 | // source code. The _indices field with the bytecode must be written last. |
duke@435 | 118 | |
duke@435 | 119 | class ConstantPoolCacheEntry VALUE_OBJ_CLASS_SPEC { |
duke@435 | 120 | friend class VMStructs; |
jrose@1161 | 121 | friend class constantPoolCacheKlass; |
jrose@1957 | 122 | friend class constantPoolOopDesc; //resolve_constant_at_impl => set_f1 |
jrose@1161 | 123 | |
duke@435 | 124 | private: |
duke@435 | 125 | volatile intx _indices; // constant pool index & rewrite bytecodes |
duke@435 | 126 | volatile oop _f1; // entry specific oop field |
duke@435 | 127 | volatile intx _f2; // entry specific int/oop field |
duke@435 | 128 | volatile intx _flags; // flags |
duke@435 | 129 | |
duke@435 | 130 | |
duke@435 | 131 | #ifdef ASSERT |
duke@435 | 132 | bool same_methodOop(oop cur_f1, oop f1); |
duke@435 | 133 | #endif |
duke@435 | 134 | |
duke@435 | 135 | void set_bytecode_1(Bytecodes::Code code); |
duke@435 | 136 | void set_bytecode_2(Bytecodes::Code code); |
duke@435 | 137 | void set_f1(oop f1) { |
duke@435 | 138 | oop existing_f1 = _f1; // read once |
duke@435 | 139 | assert(existing_f1 == NULL || existing_f1 == f1, "illegal field change"); |
duke@435 | 140 | oop_store(&_f1, f1); |
duke@435 | 141 | } |
twisti@3969 | 142 | void release_set_f1(oop f1); |
twisti@3969 | 143 | void set_f2(intx f2) { assert(_f2 == 0 || _f2 == f2, "illegal field change"); _f2 = f2; } |
twisti@3969 | 144 | void set_f2_as_vfinal_method(methodOop f2) { assert(_f2 == 0 || _f2 == (intptr_t) f2, "illegal field change"); assert(is_vfinal(), "flags must be set"); _f2 = (intptr_t) f2; } |
twisti@3969 | 145 | int make_flags(TosState state, int option_bits, int field_index_or_method_params); |
duke@435 | 146 | void set_flags(intx flags) { _flags = flags; } |
twisti@3969 | 147 | bool init_flags_atomic(intx flags); |
twisti@3969 | 148 | void set_field_flags(TosState field_type, int option_bits, int field_index) { |
twisti@3969 | 149 | assert((field_index & field_index_mask) == field_index, "field_index in range"); |
twisti@3969 | 150 | set_flags(make_flags(field_type, option_bits | (1 << is_field_entry_shift), field_index)); |
twisti@3969 | 151 | } |
twisti@3969 | 152 | void set_method_flags(TosState return_type, int option_bits, int method_params) { |
twisti@3969 | 153 | assert((method_params & parameter_size_mask) == method_params, "method_params in range"); |
twisti@3969 | 154 | set_flags(make_flags(return_type, option_bits, method_params)); |
twisti@3969 | 155 | } |
twisti@3969 | 156 | bool init_method_flags_atomic(TosState return_type, int option_bits, int method_params) { |
twisti@3969 | 157 | assert((method_params & parameter_size_mask) == method_params, "method_params in range"); |
twisti@3969 | 158 | return init_flags_atomic(make_flags(return_type, option_bits, method_params)); |
twisti@3969 | 159 | } |
duke@435 | 160 | |
duke@435 | 161 | public: |
twisti@3969 | 162 | // specific bit definitions for the flags field: |
twisti@3969 | 163 | // (Note: the interpreter must use these definitions to access the CP cache.) |
twisti@3969 | 164 | enum { |
twisti@3969 | 165 | // high order bits are the TosState corresponding to field type or method return type |
twisti@3969 | 166 | tos_state_bits = 4, |
twisti@3969 | 167 | tos_state_mask = right_n_bits(tos_state_bits), |
twisti@3969 | 168 | tos_state_shift = BitsPerInt - tos_state_bits, // see verify_tos_state_shift below |
twisti@3969 | 169 | // misc. option bits; can be any bit position in [16..27] |
twisti@3969 | 170 | is_vfinal_shift = 21, |
twisti@3969 | 171 | is_volatile_shift = 22, |
twisti@3969 | 172 | is_final_shift = 23, |
twisti@3969 | 173 | has_appendix_shift = 24, |
twisti@3969 | 174 | is_forced_virtual_shift = 25, |
twisti@3969 | 175 | is_field_entry_shift = 26, |
twisti@3969 | 176 | // low order bits give field index (for FieldInfo) or method parameter size: |
twisti@3969 | 177 | field_index_bits = 16, |
twisti@3969 | 178 | field_index_mask = right_n_bits(field_index_bits), |
twisti@3969 | 179 | parameter_size_bits = 8, // subset of field_index_mask, range is 0..255 |
twisti@3969 | 180 | parameter_size_mask = right_n_bits(parameter_size_bits), |
twisti@3969 | 181 | option_bits_mask = ~(((-1) << tos_state_shift) | (field_index_mask | parameter_size_mask)) |
duke@435 | 182 | }; |
duke@435 | 183 | |
twisti@3969 | 184 | // specific bit definitions for the indices field: |
twisti@3969 | 185 | enum { |
twisti@3969 | 186 | main_cp_index_bits = 2*BitsPerByte, |
twisti@3969 | 187 | main_cp_index_mask = right_n_bits(main_cp_index_bits), |
twisti@3969 | 188 | bytecode_1_shift = main_cp_index_bits, |
twisti@3969 | 189 | bytecode_1_mask = right_n_bits(BitsPerByte), // == (u1)0xFF |
twisti@3969 | 190 | bytecode_2_shift = main_cp_index_bits + BitsPerByte, |
twisti@3969 | 191 | bytecode_2_mask = right_n_bits(BitsPerByte), // == (u1)0xFF |
twisti@3969 | 192 | // the secondary cp index overlaps with bytecodes 1 and 2: |
twisti@3969 | 193 | secondary_cp_index_shift = bytecode_1_shift, |
twisti@3969 | 194 | secondary_cp_index_bits = BitsPerInt - main_cp_index_bits |
twisti@3969 | 195 | }; |
duke@435 | 196 | |
duke@435 | 197 | |
duke@435 | 198 | // Initialization |
jrose@1494 | 199 | void initialize_entry(int original_index); // initialize primary entry |
jrose@1494 | 200 | void initialize_secondary_entry(int main_index); // initialize secondary entry |
duke@435 | 201 | |
duke@435 | 202 | void set_field( // sets entry to resolved field state |
duke@435 | 203 | Bytecodes::Code get_code, // the bytecode used for reading the field |
duke@435 | 204 | Bytecodes::Code put_code, // the bytecode used for writing the field |
duke@435 | 205 | KlassHandle field_holder, // the object/klass holding the field |
duke@435 | 206 | int orig_field_index, // the original field index in the field holder |
duke@435 | 207 | int field_offset, // the field offset in words in the field holder |
duke@435 | 208 | TosState field_type, // the (machine) field type |
duke@435 | 209 | bool is_final, // the field is final |
duke@435 | 210 | bool is_volatile // the field is volatile |
duke@435 | 211 | ); |
duke@435 | 212 | |
duke@435 | 213 | void set_method( // sets entry to resolved method entry |
duke@435 | 214 | Bytecodes::Code invoke_code, // the bytecode used for invoking the method |
duke@435 | 215 | methodHandle method, // the method/prototype if any (NULL, otherwise) |
duke@435 | 216 | int vtable_index // the vtable index if any, else negative |
duke@435 | 217 | ); |
duke@435 | 218 | |
duke@435 | 219 | void set_interface_call( |
duke@435 | 220 | methodHandle method, // Resolved method |
duke@435 | 221 | int index // Method index into interface |
duke@435 | 222 | ); |
duke@435 | 223 | |
twisti@3969 | 224 | void set_method_handle( |
twisti@3969 | 225 | methodHandle method, // adapter for invokeExact, etc. |
twisti@3969 | 226 | Handle appendix // stored in f1; could be a java.lang.invoke.MethodType |
jrose@1161 | 227 | ); |
jrose@1161 | 228 | |
twisti@3969 | 229 | void set_dynamic_call( |
twisti@3969 | 230 | methodHandle method, // adapter for this call site |
twisti@3969 | 231 | Handle appendix // stored in f1; could be a java.lang.invoke.CallSite |
twisti@3969 | 232 | ); |
jrose@2982 | 233 | |
twisti@3969 | 234 | // Common code for invokedynamic and MH invocations. |
jrose@2015 | 235 | |
twisti@3969 | 236 | // The "appendix" is an optional call-site-specific parameter which is |
twisti@3969 | 237 | // pushed by the JVM at the end of the argument list. This argument may |
twisti@3969 | 238 | // be a MethodType for the MH.invokes and a CallSite for an invokedynamic |
twisti@3969 | 239 | // instruction. However, its exact type and use depends on the Java upcall, |
twisti@3969 | 240 | // which simply returns a compiled LambdaForm along with any reference |
twisti@3969 | 241 | // that LambdaForm needs to complete the call. If the upcall returns a |
twisti@3969 | 242 | // null appendix, the argument is not passed at all. |
twisti@3969 | 243 | // |
twisti@3969 | 244 | // The appendix is *not* represented in the signature of the symbolic |
twisti@3969 | 245 | // reference for the call site, but (if present) it *is* represented in |
twisti@3969 | 246 | // the methodOop bound to the site. This means that static and dynamic |
twisti@3969 | 247 | // resolution logic needs to make slightly different assessments about the |
twisti@3969 | 248 | // number and types of arguments. |
twisti@3969 | 249 | void set_method_handle_common( |
twisti@3969 | 250 | Bytecodes::Code invoke_code, // _invokehandle or _invokedynamic |
twisti@3969 | 251 | methodHandle adapter, // invoker method (f2) |
twisti@3969 | 252 | Handle appendix // appendix such as CallSite, MethodType, etc. (f1) |
twisti@3969 | 253 | ); |
twisti@3969 | 254 | |
twisti@3969 | 255 | methodOop method_if_resolved(constantPoolHandle cpool); |
twisti@3969 | 256 | |
twisti@3969 | 257 | void set_parameter_size(int value); |
duke@435 | 258 | |
duke@435 | 259 | // Which bytecode number (1 or 2) in the index field is valid for this bytecode? |
duke@435 | 260 | // Returns -1 if neither is valid. |
duke@435 | 261 | static int bytecode_number(Bytecodes::Code code) { |
duke@435 | 262 | switch (code) { |
duke@435 | 263 | case Bytecodes::_getstatic : // fall through |
duke@435 | 264 | case Bytecodes::_getfield : // fall through |
duke@435 | 265 | case Bytecodes::_invokespecial : // fall through |
duke@435 | 266 | case Bytecodes::_invokestatic : // fall through |
duke@435 | 267 | case Bytecodes::_invokeinterface : return 1; |
duke@435 | 268 | case Bytecodes::_putstatic : // fall through |
duke@435 | 269 | case Bytecodes::_putfield : // fall through |
twisti@3969 | 270 | case Bytecodes::_invokehandle : // fall through |
twisti@3969 | 271 | case Bytecodes::_invokedynamic : // fall through |
duke@435 | 272 | case Bytecodes::_invokevirtual : return 2; |
duke@435 | 273 | default : break; |
duke@435 | 274 | } |
duke@435 | 275 | return -1; |
duke@435 | 276 | } |
duke@435 | 277 | |
duke@435 | 278 | // Has this bytecode been resolved? Only valid for invokes and get/put field/static. |
duke@435 | 279 | bool is_resolved(Bytecodes::Code code) const { |
duke@435 | 280 | switch (bytecode_number(code)) { |
duke@435 | 281 | case 1: return (bytecode_1() == code); |
duke@435 | 282 | case 2: return (bytecode_2() == code); |
duke@435 | 283 | } |
duke@435 | 284 | return false; // default: not resolved |
duke@435 | 285 | } |
duke@435 | 286 | |
duke@435 | 287 | // Accessors |
twisti@3969 | 288 | bool is_secondary_entry() const { return (_indices & main_cp_index_mask) == 0; } |
twisti@3969 | 289 | int main_entry_index() const { assert(is_secondary_entry(), "must be secondary entry"); |
twisti@3969 | 290 | return ((uintx)_indices >> secondary_cp_index_shift); } |
twisti@3969 | 291 | int primary_entry_indices() const { assert(!is_secondary_entry(), "must be main entry"); |
twisti@3969 | 292 | return _indices; } |
twisti@3969 | 293 | int constant_pool_index() const { return (primary_entry_indices() & main_cp_index_mask); } |
twisti@3969 | 294 | Bytecodes::Code bytecode_1() const { return Bytecodes::cast((primary_entry_indices() >> bytecode_1_shift) |
twisti@3969 | 295 | & bytecode_1_mask); } |
twisti@3969 | 296 | Bytecodes::Code bytecode_2() const { return Bytecodes::cast((primary_entry_indices() >> bytecode_2_shift) |
twisti@3969 | 297 | & bytecode_2_mask); } |
twisti@3969 | 298 | methodOop f1_as_method() const { oop f1 = _f1; assert(f1 == NULL || f1->is_method(), ""); return methodOop(f1); } |
twisti@3969 | 299 | klassOop f1_as_klass() const { oop f1 = _f1; assert(f1 == NULL || f1->is_klass(), ""); return klassOop(f1); } |
twisti@3969 | 300 | oop f1_as_klass_mirror() const { oop f1 = f1_as_instance(); return f1; } // i.e., return a java_mirror |
twisti@3969 | 301 | oop f1_as_instance() const { oop f1 = _f1; assert(f1 == NULL || f1->is_instance() || f1->is_array(), ""); return f1; } |
twisti@3969 | 302 | oop f1_appendix() const { assert(has_appendix(), ""); return f1_as_instance(); } |
twisti@3969 | 303 | bool is_f1_null() const { oop f1 = _f1; return f1 == NULL; } // classifies a CPC entry as unbound |
twisti@3969 | 304 | int f2_as_index() const { assert(!is_vfinal(), ""); return (int) _f2; } |
twisti@3969 | 305 | methodOop f2_as_vfinal_method() const { assert(is_vfinal(), ""); return methodOop(_f2); } |
twisti@3969 | 306 | int field_index() const { assert(is_field_entry(), ""); return (_flags & field_index_mask); } |
twisti@3969 | 307 | int parameter_size() const { assert(is_method_entry(), ""); return (_flags & parameter_size_mask); } |
twisti@3969 | 308 | bool is_volatile() const { return (_flags & (1 << is_volatile_shift)) != 0; } |
twisti@3969 | 309 | bool is_final() const { return (_flags & (1 << is_final_shift)) != 0; } |
twisti@3969 | 310 | bool has_appendix() const { return (_flags & (1 << has_appendix_shift)) != 0; } |
twisti@3969 | 311 | bool is_forced_virtual() const { return (_flags & (1 << is_forced_virtual_shift)) != 0; } |
twisti@3969 | 312 | bool is_vfinal() const { return (_flags & (1 << is_vfinal_shift)) != 0; } |
twisti@3969 | 313 | bool is_method_entry() const { return (_flags & (1 << is_field_entry_shift)) == 0; } |
twisti@3969 | 314 | bool is_field_entry() const { return (_flags & (1 << is_field_entry_shift)) != 0; } |
twisti@3969 | 315 | bool is_byte() const { return flag_state() == btos; } |
twisti@3969 | 316 | bool is_char() const { return flag_state() == ctos; } |
twisti@3969 | 317 | bool is_short() const { return flag_state() == stos; } |
twisti@3969 | 318 | bool is_int() const { return flag_state() == itos; } |
twisti@3969 | 319 | bool is_long() const { return flag_state() == ltos; } |
twisti@3969 | 320 | bool is_float() const { return flag_state() == ftos; } |
twisti@3969 | 321 | bool is_double() const { return flag_state() == dtos; } |
twisti@3969 | 322 | bool is_object() const { return flag_state() == atos; } |
twisti@3969 | 323 | TosState flag_state() const { assert((uint)number_of_states <= (uint)tos_state_mask+1, ""); |
twisti@3969 | 324 | return (TosState)((_flags >> tos_state_shift) & tos_state_mask); } |
duke@435 | 325 | |
duke@435 | 326 | // Code generation support |
duke@435 | 327 | static WordSize size() { return in_WordSize(sizeof(ConstantPoolCacheEntry) / HeapWordSize); } |
jrose@1494 | 328 | static ByteSize size_in_bytes() { return in_ByteSize(sizeof(ConstantPoolCacheEntry)); } |
duke@435 | 329 | static ByteSize indices_offset() { return byte_offset_of(ConstantPoolCacheEntry, _indices); } |
duke@435 | 330 | static ByteSize f1_offset() { return byte_offset_of(ConstantPoolCacheEntry, _f1); } |
duke@435 | 331 | static ByteSize f2_offset() { return byte_offset_of(ConstantPoolCacheEntry, _f2); } |
duke@435 | 332 | static ByteSize flags_offset() { return byte_offset_of(ConstantPoolCacheEntry, _flags); } |
duke@435 | 333 | |
duke@435 | 334 | // GC Support |
duke@435 | 335 | void oops_do(void f(oop*)); |
duke@435 | 336 | void oop_iterate(OopClosure* blk); |
duke@435 | 337 | void oop_iterate_m(OopClosure* blk, MemRegion mr); |
duke@435 | 338 | void follow_contents(); |
duke@435 | 339 | void adjust_pointers(); |
duke@435 | 340 | |
duke@435 | 341 | #ifndef SERIALGC |
duke@435 | 342 | // Parallel Old |
duke@435 | 343 | void follow_contents(ParCompactionManager* cm); |
duke@435 | 344 | #endif // SERIALGC |
duke@435 | 345 | |
duke@435 | 346 | void update_pointers(); |
duke@435 | 347 | |
duke@435 | 348 | // RedefineClasses() API support: |
duke@435 | 349 | // If this constantPoolCacheEntry refers to old_method then update it |
duke@435 | 350 | // to refer to new_method. |
duke@435 | 351 | // trace_name_printed is set to true if the current call has |
duke@435 | 352 | // printed the klass name so that other routines in the adjust_* |
duke@435 | 353 | // group don't print the klass name. |
duke@435 | 354 | bool adjust_method_entry(methodOop old_method, methodOop new_method, |
duke@435 | 355 | bool * trace_name_printed); |
duke@435 | 356 | bool is_interesting_method_entry(klassOop k); |
duke@435 | 357 | |
duke@435 | 358 | // Debugging & Printing |
duke@435 | 359 | void print (outputStream* st, int index) const; |
duke@435 | 360 | void verify(outputStream* st) const; |
duke@435 | 361 | |
twisti@3969 | 362 | static void verify_tos_state_shift() { |
twisti@3969 | 363 | // When shifting flags as a 32-bit int, make sure we don't need an extra mask for tos_state: |
twisti@3969 | 364 | assert((((u4)-1 >> tos_state_shift) & ~tos_state_mask) == 0, "no need for tos_state mask"); |
duke@435 | 365 | } |
duke@435 | 366 | }; |
duke@435 | 367 | |
duke@435 | 368 | |
duke@435 | 369 | // A constant pool cache is a runtime data structure set aside to a constant pool. The cache |
duke@435 | 370 | // holds interpreter runtime information for all field access and invoke bytecodes. The cache |
duke@435 | 371 | // is created and initialized before a class is actively used (i.e., initialized), the indivi- |
duke@435 | 372 | // dual cache entries are filled at resolution (i.e., "link") time (see also: rewriter.*). |
duke@435 | 373 | |
coleenp@548 | 374 | class constantPoolCacheOopDesc: public oopDesc { |
duke@435 | 375 | friend class VMStructs; |
duke@435 | 376 | private: |
coleenp@548 | 377 | int _length; |
duke@435 | 378 | constantPoolOop _constant_pool; // the corresponding constant pool |
duke@435 | 379 | |
duke@435 | 380 | // Sizing |
coleenp@548 | 381 | debug_only(friend class ClassVerifier;) |
jrose@2268 | 382 | public: |
coleenp@548 | 383 | int length() const { return _length; } |
jrose@2268 | 384 | private: |
coleenp@548 | 385 | void set_length(int length) { _length = length; } |
coleenp@548 | 386 | |
duke@435 | 387 | static int header_size() { return sizeof(constantPoolCacheOopDesc) / HeapWordSize; } |
duke@435 | 388 | static int object_size(int length) { return align_object_size(header_size() + length * in_words(ConstantPoolCacheEntry::size())); } |
duke@435 | 389 | int object_size() { return object_size(length()); } |
duke@435 | 390 | |
duke@435 | 391 | // Helpers |
duke@435 | 392 | constantPoolOop* constant_pool_addr() { return &_constant_pool; } |
duke@435 | 393 | ConstantPoolCacheEntry* base() const { return (ConstantPoolCacheEntry*)((address)this + in_bytes(base_offset())); } |
duke@435 | 394 | |
duke@435 | 395 | friend class constantPoolCacheKlass; |
jrose@1494 | 396 | friend class ConstantPoolCacheEntry; |
duke@435 | 397 | |
duke@435 | 398 | public: |
duke@435 | 399 | // Initialization |
duke@435 | 400 | void initialize(intArray& inverse_index_map); |
duke@435 | 401 | |
jrose@1161 | 402 | // Secondary indexes. |
jrose@1161 | 403 | // They must look completely different from normal indexes. |
jrose@1161 | 404 | // The main reason is that byte swapping is sometimes done on normal indexes. |
jrose@1494 | 405 | // Also, some of the CP accessors do different things for secondary indexes. |
jrose@1494 | 406 | // Finally, it is helpful for debugging to tell the two apart. |
jrose@1161 | 407 | static bool is_secondary_index(int i) { return (i < 0); } |
jrose@1161 | 408 | static int decode_secondary_index(int i) { assert(is_secondary_index(i), ""); return ~i; } |
jrose@1161 | 409 | static int encode_secondary_index(int i) { assert(!is_secondary_index(i), ""); return ~i; } |
jrose@1161 | 410 | |
duke@435 | 411 | // Accessors |
duke@435 | 412 | void set_constant_pool(constantPoolOop pool) { oop_store_without_check((oop*)&_constant_pool, (oop)pool); } |
duke@435 | 413 | constantPoolOop constant_pool() const { return _constant_pool; } |
jrose@1494 | 414 | // Fetches the entry at the given index. |
jrose@1494 | 415 | // The entry may be either primary or secondary. |
jrose@1494 | 416 | // In either case the index must not be encoded or byte-swapped in any way. |
jrose@1494 | 417 | ConstantPoolCacheEntry* entry_at(int i) const { |
jrose@1494 | 418 | assert(0 <= i && i < length(), "index out of bounds"); |
jrose@1494 | 419 | return base() + i; |
jrose@1494 | 420 | } |
jrose@1494 | 421 | // Fetches the secondary entry referred to by index. |
jrose@1494 | 422 | // The index may be a secondary index, and must not be byte-swapped. |
jrose@1494 | 423 | ConstantPoolCacheEntry* secondary_entry_at(int i) const { |
jrose@1494 | 424 | int raw_index = i; |
jrose@1494 | 425 | if (is_secondary_index(i)) { // correct these on the fly |
jrose@1494 | 426 | raw_index = decode_secondary_index(i); |
jrose@1494 | 427 | } |
jrose@1494 | 428 | assert(entry_at(raw_index)->is_secondary_entry(), "not a secondary entry"); |
jrose@1494 | 429 | return entry_at(raw_index); |
jrose@1494 | 430 | } |
jrose@1494 | 431 | // Given a primary or secondary index, fetch the corresponding primary entry. |
jrose@1494 | 432 | // Indirect through the secondary entry, if the index is encoded as a secondary index. |
jrose@1494 | 433 | // The index must not be byte-swapped. |
jrose@1161 | 434 | ConstantPoolCacheEntry* main_entry_at(int i) const { |
jrose@1494 | 435 | int primary_index = i; |
jrose@1161 | 436 | if (is_secondary_index(i)) { |
jrose@1161 | 437 | // run through an extra level of indirection: |
jrose@1494 | 438 | int raw_index = decode_secondary_index(i); |
jrose@1494 | 439 | primary_index = entry_at(raw_index)->main_entry_index(); |
jrose@1161 | 440 | } |
jrose@1494 | 441 | assert(!entry_at(primary_index)->is_secondary_entry(), "only one level of indirection"); |
jrose@1494 | 442 | return entry_at(primary_index); |
jrose@1161 | 443 | } |
duke@435 | 444 | |
duke@435 | 445 | // Code generation |
duke@435 | 446 | static ByteSize base_offset() { return in_ByteSize(sizeof(constantPoolCacheOopDesc)); } |
jrose@1494 | 447 | static ByteSize entry_offset(int raw_index) { |
jrose@1494 | 448 | int index = raw_index; |
jrose@1494 | 449 | if (is_secondary_index(raw_index)) |
jrose@1494 | 450 | index = decode_secondary_index(raw_index); |
jrose@1494 | 451 | return (base_offset() + ConstantPoolCacheEntry::size_in_bytes() * index); |
jrose@1494 | 452 | } |
duke@435 | 453 | |
duke@435 | 454 | // RedefineClasses() API support: |
duke@435 | 455 | // If any entry of this constantPoolCache points to any of |
duke@435 | 456 | // old_methods, replace it with the corresponding new_method. |
duke@435 | 457 | // trace_name_printed is set to true if the current call has |
duke@435 | 458 | // printed the klass name so that other routines in the adjust_* |
duke@435 | 459 | // group don't print the klass name. |
duke@435 | 460 | void adjust_method_entries(methodOop* old_methods, methodOop* new_methods, |
duke@435 | 461 | int methods_length, bool * trace_name_printed); |
duke@435 | 462 | }; |
stefank@2314 | 463 | |
stefank@2314 | 464 | #endif // SHARE_VM_OOPS_CPCACHEOOP_HPP |