comparison src/share/vm/oops/cpCacheOop.hpp @ 6266:1d7922586cf6

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>
author twisti
date Tue, 24 Jul 2012 10:51:00 -0700
parents ddd894528dbc
children
comparison
equal deleted inserted replaced
6241:aba91a731143 6266:1d7922586cf6
36 // the entry layout is shared and looks as follows: 36 // the entry layout is shared and looks as follows:
37 // 37 //
38 // bit number |31 0| 38 // bit number |31 0|
39 // bit length |-8--|-8--|---16----| 39 // bit length |-8--|-8--|---16----|
40 // -------------------------------- 40 // --------------------------------
41 // _indices [ b2 | b1 | index ] 41 // _indices [ b2 | b1 | index ] index = constant_pool_index (!= 0, normal entries only)
42 // _f1 [ entry specific ] 42 // _indices [ index | 00000 ] index = main_entry_index (secondary entries only)
43 // _f2 [ entry specific ] 43 // _f1 [ entry specific ] method, klass, or oop (MethodType or CallSite)
44 // _flags [t|f|vf|v|m|h|unused|field_index] (for field entries) 44 // _f2 [ entry specific ] vtable index or vfinal method
45 // bit length |4|1|1 |1|1|0|---7--|----16-----] 45 // _flags [tos|0|00|00|00|f|v|f2|unused|field_index] (for field entries)
46 // _flags [t|f|vf|v|m|h|unused|eidx|psze] (for method entries) 46 // bit length [ 4 |1|1 |1 | 1|1|1| 1|---5--|----16-----]
47 // bit length |4|1|1 |1|1|1|---7--|-8--|-8--] 47 // _flags [tos|M|vf|fv|ea|f|0|f2|unused|00000|psize] (for method entries)
48 // bit length [ 4 |1|1 |1 | 1|1|1| 1|---5--|--8--|--8--]
48 49
49 // -------------------------------- 50 // --------------------------------
50 // 51 //
51 // with: 52 // with:
52 // index = original constant pool index 53 // index = original constant pool index
53 // b1 = bytecode 1 54 // b1 = bytecode 1
54 // b2 = bytecode 2 55 // b2 = bytecode 2
55 // psze = parameters size (method entries only) 56 // psize = parameters size (method entries only)
56 // eidx = interpreter entry index (method entries only)
57 // field_index = index into field information in holder instanceKlass 57 // field_index = index into field information in holder instanceKlass
58 // The index max is 0xffff (max number of fields in constant pool) 58 // The index max is 0xffff (max number of fields in constant pool)
59 // and is multiplied by (instanceKlass::next_offset) when accessing. 59 // and is multiplied by (instanceKlass::next_offset) when accessing.
60 // t = TosState (see below) 60 // t = TosState (see below)
61 // f = field is marked final (see below) 61 // f = field is marked final (see below)
62 // vf = virtual, final (method entries only : is_vfinal()) 62 // f2 = virtual but final (method entries only: is_vfinal())
63 // v = field is volatile (see below) 63 // v = field is volatile (see below)
64 // m = invokeinterface used for method in class Object (see below) 64 // m = invokeinterface used for method in class Object (see below)
65 // h = RedefineClasses/Hotswap bit (see below) 65 // h = RedefineClasses/Hotswap bit (see below)
66 // 66 //
67 // The flags after TosState have the following interpretation: 67 // The flags after TosState have the following interpretation:
68 // bit 27: f flag true if field is marked final 68 // bit 27: 0 for fields, 1 for methods
69 // bit 26: vf flag true if virtual final method 69 // f flag true if field is marked final
70 // bit 25: v flag true if field is volatile (only for fields) 70 // v flag true if field is volatile (only for fields)
71 // bit 24: m flag true if invokeinterface used for method in class Object 71 // f2 flag true if f2 contains an oop (e.g., virtual final method)
72 // bit 23: 0 for fields, 1 for methods 72 // fv flag true if invokeinterface used for method in class Object
73 // 73 //
74 // The flags 31, 30, 29, 28 together build a 4 bit number 0 to 8 with the 74 // The flags 31, 30, 29, 28 together build a 4 bit number 0 to 8 with the
75 // following mapping to the TosState states: 75 // following mapping to the TosState states:
76 // 76 //
77 // btos: 0 77 // btos: 0
84 // atos: 7 84 // atos: 7
85 // vtos: 8 85 // vtos: 8
86 // 86 //
87 // Entry specific: field entries: 87 // Entry specific: field entries:
88 // _indices = get (b1 section) and put (b2 section) bytecodes, original constant pool index 88 // _indices = get (b1 section) and put (b2 section) bytecodes, original constant pool index
89 // _f1 = field holder 89 // _f1 = field holder (as a java.lang.Class, not a klassOop)
90 // _f2 = field offset in words 90 // _f2 = field offset in bytes
91 // _flags = field type information, original field index in field holder 91 // _flags = field type information, original FieldInfo index in field holder
92 // (field_index section) 92 // (field_index section)
93 // 93 //
94 // Entry specific: method entries: 94 // Entry specific: method entries:
95 // _indices = invoke code for f1 (b1 section), invoke code for f2 (b2 section), 95 // _indices = invoke code for f1 (b1 section), invoke code for f2 (b2 section),
96 // original constant pool index 96 // original constant pool index
97 // _f1 = method for all but virtual calls, unused by virtual calls 97 // _f1 = methodOop for non-virtual calls, unused by virtual calls.
98 // (note: for interface calls, which are essentially virtual, 98 // for interface calls, which are essentially virtual but need a klass,
99 // contains klassOop for the corresponding interface. 99 // contains klassOop for the corresponding interface.
100 // for invokedynamic, f1 contains the CallSite object for the invocation 100 // for invokedynamic, f1 contains a site-specific CallSite object (as an appendix)
101 // _f2 = method/vtable index for virtual calls only, unused by all other 101 // for invokehandle, f1 contains a site-specific MethodType object (as an appendix)
102 // calls. The vf flag indicates this is a method pointer not an 102 // (upcoming metadata changes will move the appendix to a separate array)
103 // index. 103 // _f2 = vtable/itable index (or final methodOop) for virtual calls only,
104 // _flags = field type info (f section), 104 // unused by non-virtual. The is_vfinal flag indicates this is a
105 // virtual final entry (vf), 105 // method pointer for a final method, not an index.
106 // interpreter entry index (eidx section), 106 // _flags = method type info (t section),
107 // parameter size (psze section) 107 // virtual final bit (vfinal),
108 // parameter size (psize section)
108 // 109 //
109 // Note: invokevirtual & invokespecial bytecodes can share the same constant 110 // Note: invokevirtual & invokespecial bytecodes can share the same constant
110 // pool entry and thus the same constant pool cache entry. All invoke 111 // pool entry and thus the same constant pool cache entry. All invoke
111 // bytecodes but invokevirtual use only _f1 and the corresponding b1 112 // bytecodes but invokevirtual use only _f1 and the corresponding b1
112 // bytecode, while invokevirtual uses only _f2 and the corresponding 113 // bytecode, while invokevirtual uses only _f2 and the corresponding
136 void set_f1(oop f1) { 137 void set_f1(oop f1) {
137 oop existing_f1 = _f1; // read once 138 oop existing_f1 = _f1; // read once
138 assert(existing_f1 == NULL || existing_f1 == f1, "illegal field change"); 139 assert(existing_f1 == NULL || existing_f1 == f1, "illegal field change");
139 oop_store(&_f1, f1); 140 oop_store(&_f1, f1);
140 } 141 }
141 void set_f1_if_null_atomic(oop f1); 142 void release_set_f1(oop f1);
142 void set_f2(intx f2) { assert(_f2 == 0 || _f2 == f2, "illegal field change"); _f2 = f2; } 143 void set_f2(intx f2) { assert(_f2 == 0 || _f2 == f2, "illegal field change"); _f2 = f2; }
143 int as_flags(TosState state, bool is_final, bool is_vfinal, bool is_volatile, 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; }
144 bool is_method_interface, bool is_method); 145 int make_flags(TosState state, int option_bits, int field_index_or_method_params);
145 void set_flags(intx flags) { _flags = flags; } 146 void set_flags(intx flags) { _flags = flags; }
147 bool init_flags_atomic(intx flags);
148 void set_field_flags(TosState field_type, int option_bits, int field_index) {
149 assert((field_index & field_index_mask) == field_index, "field_index in range");
150 set_flags(make_flags(field_type, option_bits | (1 << is_field_entry_shift), field_index));
151 }
152 void set_method_flags(TosState return_type, int option_bits, int method_params) {
153 assert((method_params & parameter_size_mask) == method_params, "method_params in range");
154 set_flags(make_flags(return_type, option_bits, method_params));
155 }
156 bool init_method_flags_atomic(TosState return_type, int option_bits, int method_params) {
157 assert((method_params & parameter_size_mask) == method_params, "method_params in range");
158 return init_flags_atomic(make_flags(return_type, option_bits, method_params));
159 }
146 160
147 public: 161 public:
148 // specific bit values in flag field 162 // specific bit definitions for the flags field:
149 // Note: the interpreter knows this layout! 163 // (Note: the interpreter must use these definitions to access the CP cache.)
150 enum FlagBitValues { 164 enum {
151 hotSwapBit = 23, 165 // high order bits are the TosState corresponding to field type or method return type
152 methodInterface = 24, 166 tos_state_bits = 4,
153 volatileField = 25, 167 tos_state_mask = right_n_bits(tos_state_bits),
154 vfinalMethod = 26, 168 tos_state_shift = BitsPerInt - tos_state_bits, // see verify_tos_state_shift below
155 finalField = 27 169 // misc. option bits; can be any bit position in [16..27]
170 is_vfinal_shift = 21,
171 is_volatile_shift = 22,
172 is_final_shift = 23,
173 has_appendix_shift = 24,
174 is_forced_virtual_shift = 25,
175 is_field_entry_shift = 26,
176 // low order bits give field index (for FieldInfo) or method parameter size:
177 field_index_bits = 16,
178 field_index_mask = right_n_bits(field_index_bits),
179 parameter_size_bits = 8, // subset of field_index_mask, range is 0..255
180 parameter_size_mask = right_n_bits(parameter_size_bits),
181 option_bits_mask = ~(((-1) << tos_state_shift) | (field_index_mask | parameter_size_mask))
156 }; 182 };
157 183
158 enum { field_index_mask = 0xFFFF }; 184 // specific bit definitions for the indices field:
159 185 enum {
160 // start of type bits in flags 186 main_cp_index_bits = 2*BitsPerByte,
161 // Note: the interpreter knows this layout! 187 main_cp_index_mask = right_n_bits(main_cp_index_bits),
162 enum FlagValues { 188 bytecode_1_shift = main_cp_index_bits,
163 tosBits = 28 189 bytecode_1_mask = right_n_bits(BitsPerByte), // == (u1)0xFF
190 bytecode_2_shift = main_cp_index_bits + BitsPerByte,
191 bytecode_2_mask = right_n_bits(BitsPerByte), // == (u1)0xFF
192 // the secondary cp index overlaps with bytecodes 1 and 2:
193 secondary_cp_index_shift = bytecode_1_shift,
194 secondary_cp_index_bits = BitsPerInt - main_cp_index_bits
164 }; 195 };
196
165 197
166 // Initialization 198 // Initialization
167 void initialize_entry(int original_index); // initialize primary entry 199 void initialize_entry(int original_index); // initialize primary entry
168 void initialize_secondary_entry(int main_index); // initialize secondary entry 200 void initialize_secondary_entry(int main_index); // initialize secondary entry
169 201
187 void set_interface_call( 219 void set_interface_call(
188 methodHandle method, // Resolved method 220 methodHandle method, // Resolved method
189 int index // Method index into interface 221 int index // Method index into interface
190 ); 222 );
191 223
224 void set_method_handle(
225 methodHandle method, // adapter for invokeExact, etc.
226 Handle appendix // stored in f1; could be a java.lang.invoke.MethodType
227 );
228
192 void set_dynamic_call( 229 void set_dynamic_call(
193 Handle call_site, // Resolved java.lang.invoke.CallSite (f1) 230 methodHandle method, // adapter for this call site
194 methodHandle signature_invoker // determines signature information 231 Handle appendix // stored in f1; could be a java.lang.invoke.CallSite
195 ); 232 );
196 233
197 methodOop get_method_if_resolved(Bytecodes::Code invoke_code, constantPoolHandle cpool); 234 // Common code for invokedynamic and MH invocations.
198 235
199 // For JVM_CONSTANT_InvokeDynamic cache entries: 236 // The "appendix" is an optional call-site-specific parameter which is
200 void initialize_bootstrap_method_index_in_cache(int bsm_cache_index); 237 // pushed by the JVM at the end of the argument list. This argument may
201 int bootstrap_method_index_in_cache(); 238 // be a MethodType for the MH.invokes and a CallSite for an invokedynamic
202 239 // instruction. However, its exact type and use depends on the Java upcall,
203 void set_parameter_size(int value) { 240 // which simply returns a compiled LambdaForm along with any reference
204 assert(parameter_size() == 0 || parameter_size() == value, 241 // that LambdaForm needs to complete the call. If the upcall returns a
205 "size must not change"); 242 // null appendix, the argument is not passed at all.
206 // Setting the parameter size by itself is only safe if the 243 //
207 // current value of _flags is 0, otherwise another thread may have 244 // The appendix is *not* represented in the signature of the symbolic
208 // updated it and we don't want to overwrite that value. Don't 245 // reference for the call site, but (if present) it *is* represented in
209 // bother trying to update it once it's nonzero but always make 246 // the methodOop bound to the site. This means that static and dynamic
210 // sure that the final parameter size agrees with what was passed. 247 // resolution logic needs to make slightly different assessments about the
211 if (_flags == 0) { 248 // number and types of arguments.
212 Atomic::cmpxchg_ptr((value & 0xFF), &_flags, 0); 249 void set_method_handle_common(
213 } 250 Bytecodes::Code invoke_code, // _invokehandle or _invokedynamic
214 guarantee(parameter_size() == value, "size must not change"); 251 methodHandle adapter, // invoker method (f2)
215 } 252 Handle appendix // appendix such as CallSite, MethodType, etc. (f1)
253 );
254
255 methodOop method_if_resolved(constantPoolHandle cpool);
256
257 void set_parameter_size(int value);
216 258
217 // Which bytecode number (1 or 2) in the index field is valid for this bytecode? 259 // Which bytecode number (1 or 2) in the index field is valid for this bytecode?
218 // Returns -1 if neither is valid. 260 // Returns -1 if neither is valid.
219 static int bytecode_number(Bytecodes::Code code) { 261 static int bytecode_number(Bytecodes::Code code) {
220 switch (code) { 262 switch (code) {
221 case Bytecodes::_getstatic : // fall through 263 case Bytecodes::_getstatic : // fall through
222 case Bytecodes::_getfield : // fall through 264 case Bytecodes::_getfield : // fall through
223 case Bytecodes::_invokespecial : // fall through 265 case Bytecodes::_invokespecial : // fall through
224 case Bytecodes::_invokestatic : // fall through 266 case Bytecodes::_invokestatic : // fall through
225 case Bytecodes::_invokedynamic : // fall through
226 case Bytecodes::_invokeinterface : return 1; 267 case Bytecodes::_invokeinterface : return 1;
227 case Bytecodes::_putstatic : // fall through 268 case Bytecodes::_putstatic : // fall through
228 case Bytecodes::_putfield : // fall through 269 case Bytecodes::_putfield : // fall through
270 case Bytecodes::_invokehandle : // fall through
271 case Bytecodes::_invokedynamic : // fall through
229 case Bytecodes::_invokevirtual : return 2; 272 case Bytecodes::_invokevirtual : return 2;
230 default : break; 273 default : break;
231 } 274 }
232 return -1; 275 return -1;
233 } 276 }
240 } 283 }
241 return false; // default: not resolved 284 return false; // default: not resolved
242 } 285 }
243 286
244 // Accessors 287 // Accessors
245 bool is_secondary_entry() const { return (_indices & 0xFFFF) == 0; } 288 bool is_secondary_entry() const { return (_indices & main_cp_index_mask) == 0; }
246 int constant_pool_index() const { assert((_indices & 0xFFFF) != 0, "must be main entry"); 289 int main_entry_index() const { assert(is_secondary_entry(), "must be secondary entry");
247 return (_indices & 0xFFFF); } 290 return ((uintx)_indices >> secondary_cp_index_shift); }
248 int main_entry_index() const { assert((_indices & 0xFFFF) == 0, "must be secondary entry"); 291 int primary_entry_indices() const { assert(!is_secondary_entry(), "must be main entry");
249 return ((uintx)_indices >> 16); } 292 return _indices; }
250 Bytecodes::Code bytecode_1() const { return Bytecodes::cast((_indices >> 16) & 0xFF); } 293 int constant_pool_index() const { return (primary_entry_indices() & main_cp_index_mask); }
251 Bytecodes::Code bytecode_2() const { return Bytecodes::cast((_indices >> 24) & 0xFF); } 294 Bytecodes::Code bytecode_1() const { return Bytecodes::cast((primary_entry_indices() >> bytecode_1_shift)
252 volatile oop f1() const { return _f1; } 295 & bytecode_1_mask); }
253 bool is_f1_null() const { return (oop)_f1 == NULL; } // classifies a CPC entry as unbound 296 Bytecodes::Code bytecode_2() const { return Bytecodes::cast((primary_entry_indices() >> bytecode_2_shift)
254 intx f2() const { return _f2; } 297 & bytecode_2_mask); }
255 int field_index() const; 298 methodOop f1_as_method() const { oop f1 = _f1; assert(f1 == NULL || f1->is_method(), ""); return methodOop(f1); }
256 int parameter_size() const { return _flags & 0xFF; } 299 klassOop f1_as_klass() const { oop f1 = _f1; assert(f1 == NULL || f1->is_klass(), ""); return klassOop(f1); }
257 bool is_vfinal() const { return ((_flags & (1 << vfinalMethod)) == (1 << vfinalMethod)); } 300 oop f1_as_klass_mirror() const { oop f1 = f1_as_instance(); return f1; } // i.e., return a java_mirror
258 bool is_volatile() const { return ((_flags & (1 << volatileField)) == (1 << volatileField)); } 301 oop f1_as_instance() const { oop f1 = _f1; assert(f1 == NULL || f1->is_instance() || f1->is_array(), ""); return f1; }
259 bool is_methodInterface() const { return ((_flags & (1 << methodInterface)) == (1 << methodInterface)); } 302 oop f1_appendix() const { assert(has_appendix(), ""); return f1_as_instance(); }
260 bool is_byte() const { return (((uintx) _flags >> tosBits) == btos); } 303 bool is_f1_null() const { oop f1 = _f1; return f1 == NULL; } // classifies a CPC entry as unbound
261 bool is_char() const { return (((uintx) _flags >> tosBits) == ctos); } 304 int f2_as_index() const { assert(!is_vfinal(), ""); return (int) _f2; }
262 bool is_short() const { return (((uintx) _flags >> tosBits) == stos); } 305 methodOop f2_as_vfinal_method() const { assert(is_vfinal(), ""); return methodOop(_f2); }
263 bool is_int() const { return (((uintx) _flags >> tosBits) == itos); } 306 int field_index() const { assert(is_field_entry(), ""); return (_flags & field_index_mask); }
264 bool is_long() const { return (((uintx) _flags >> tosBits) == ltos); } 307 int parameter_size() const { assert(is_method_entry(), ""); return (_flags & parameter_size_mask); }
265 bool is_float() const { return (((uintx) _flags >> tosBits) == ftos); } 308 bool is_volatile() const { return (_flags & (1 << is_volatile_shift)) != 0; }
266 bool is_double() const { return (((uintx) _flags >> tosBits) == dtos); } 309 bool is_final() const { return (_flags & (1 << is_final_shift)) != 0; }
267 bool is_object() const { return (((uintx) _flags >> tosBits) == atos); } 310 bool has_appendix() const { return (_flags & (1 << has_appendix_shift)) != 0; }
268 TosState flag_state() const { assert( ( (_flags >> tosBits) & 0x0F ) < number_of_states, "Invalid state in as_flags"); 311 bool is_forced_virtual() const { return (_flags & (1 << is_forced_virtual_shift)) != 0; }
269 return (TosState)((_flags >> tosBits) & 0x0F); } 312 bool is_vfinal() const { return (_flags & (1 << is_vfinal_shift)) != 0; }
313 bool is_method_entry() const { return (_flags & (1 << is_field_entry_shift)) == 0; }
314 bool is_field_entry() const { return (_flags & (1 << is_field_entry_shift)) != 0; }
315 bool is_byte() const { return flag_state() == btos; }
316 bool is_char() const { return flag_state() == ctos; }
317 bool is_short() const { return flag_state() == stos; }
318 bool is_int() const { return flag_state() == itos; }
319 bool is_long() const { return flag_state() == ltos; }
320 bool is_float() const { return flag_state() == ftos; }
321 bool is_double() const { return flag_state() == dtos; }
322 bool is_object() const { return flag_state() == atos; }
323 TosState flag_state() const { assert((uint)number_of_states <= (uint)tos_state_mask+1, "");
324 return (TosState)((_flags >> tos_state_shift) & tos_state_mask); }
270 325
271 // Code generation support 326 // Code generation support
272 static WordSize size() { return in_WordSize(sizeof(ConstantPoolCacheEntry) / HeapWordSize); } 327 static WordSize size() { return in_WordSize(sizeof(ConstantPoolCacheEntry) / HeapWordSize); }
273 static ByteSize size_in_bytes() { return in_ByteSize(sizeof(ConstantPoolCacheEntry)); } 328 static ByteSize size_in_bytes() { return in_ByteSize(sizeof(ConstantPoolCacheEntry)); }
274 static ByteSize indices_offset() { return byte_offset_of(ConstantPoolCacheEntry, _indices); } 329 static ByteSize indices_offset() { return byte_offset_of(ConstantPoolCacheEntry, _indices); }
297 // printed the klass name so that other routines in the adjust_* 352 // printed the klass name so that other routines in the adjust_*
298 // group don't print the klass name. 353 // group don't print the klass name.
299 bool adjust_method_entry(methodOop old_method, methodOop new_method, 354 bool adjust_method_entry(methodOop old_method, methodOop new_method,
300 bool * trace_name_printed); 355 bool * trace_name_printed);
301 bool is_interesting_method_entry(klassOop k); 356 bool is_interesting_method_entry(klassOop k);
302 bool is_field_entry() const { return (_flags & (1 << hotSwapBit)) == 0; }
303 bool is_method_entry() const { return (_flags & (1 << hotSwapBit)) != 0; }
304 357
305 // Debugging & Printing 358 // Debugging & Printing
306 void print (outputStream* st, int index) const; 359 void print (outputStream* st, int index) const;
307 void verify(outputStream* st) const; 360 void verify(outputStream* st) const;
308 361
309 static void verify_tosBits() { 362 static void verify_tos_state_shift() {
310 assert(tosBits == 28, "interpreter now assumes tosBits is 28"); 363 // When shifting flags as a 32-bit int, make sure we don't need an extra mask for tos_state:
364 assert((((u4)-1 >> tos_state_shift) & ~tos_state_mask) == 0, "no need for tos_state mask");
311 } 365 }
312 }; 366 };
313 367
314 368
315 // A constant pool cache is a runtime data structure set aside to a constant pool. The cache 369 // A constant pool cache is a runtime data structure set aside to a constant pool. The cache