32 #include "runtime/orderAccess.hpp"
33 #include "utilities/align.hpp"
34
35 class PSPromotionManager;
36
37 // The ConstantPoolCache is not a cache! It is the resolution table that the
38 // interpreter uses to avoid going into the runtime and a way to access resolved
39 // values.
40
41 // A ConstantPoolCacheEntry describes an individual entry of the constant
42 // pool cache. There's 2 principal kinds of entries: field entries for in-
43 // stance & static field access, and method entries for invokes. Some of
44 // the entry layout is shared and looks as follows:
45 //
46 // bit number |31 0|
47 // bit length |-8--|-8--|---16----|
48 // --------------------------------
49 // _indices [ b2 | b1 | index ] index = constant_pool_index
50 // _f1 [ entry specific ] metadata ptr (method or klass)
51 // _f2 [ entry specific ] vtable or res_ref index, or vfinal method ptr
52 // _flags [tos|0|F=1|0|0|0|f|v|0 |0000|field_index] (for field entries)
53 // bit length [ 4 |1| 1 |1|1|1|1|1|1 |-4--|----16-----]
54 // _flags [tos|0|F=0|M|A|I|f|0|vf|0000|00000|psize] (for method entries)
55 // bit length [ 4 |1| 1 |1|1|1|1|1|1 |-4--|--8--|--8--]
56
57 // --------------------------------
58 //
59 // with:
60 // index = original constant pool index
61 // b1 = bytecode 1
62 // b2 = bytecode 2
63 // psize = parameters size (method entries only)
64 // field_index = index into field information in holder InstanceKlass
65 // The index max is 0xffff (max number of fields in constant pool)
66 // and is multiplied by (InstanceKlass::next_offset) when accessing.
67 // tos = TosState
68 // F = the entry is for a field (or F=0 for a method)
69 // A = call site has an appendix argument (loaded from resolved references)
70 // I = interface call is forced virtual (must use a vtable index or vfinal)
71 // f = field or method is final
72 // v = field is volatile
73 // vf = virtual but final (method entries only: is_vfinal())
74 //
75 // The flags after TosState have the following interpretation:
76 // bit 27: 0 for fields, 1 for methods
77 // f flag true if field is marked final
78 // v flag true if field is volatile (only for fields)
79 // f2 flag true if f2 contains an oop (e.g., virtual final method)
80 // fv flag true if invokeinterface used for method in class Object
81 //
82 // The flags 31, 30, 29, 28 together build a 4 bit number 0 to 16 with the
83 // following mapping to the TosState states:
84 //
85 // btos: 0
86 // ztos: 1
87 // ctos: 2
88 // stos: 3
89 // itos: 4
90 // ltos: 5
91 // ftos: 6
92 // dtos: 7
93 // atos: 8
94 // qtos: 9
95 // vtos: 10
96 //
171 set_flags(make_flags(return_type, option_bits, method_params));
172 }
173 bool init_method_flags_atomic(TosState return_type, int option_bits, int method_params) {
174 assert((method_params & parameter_size_mask) == method_params, "method_params in range");
175 return init_flags_atomic(make_flags(return_type, option_bits, method_params));
176 }
177
178 public:
179 // specific bit definitions for the flags field:
180 // (Note: the interpreter must use these definitions to access the CP cache.)
181 enum {
182 // high order bits are the TosState corresponding to field type or method return type
183 tos_state_bits = 4,
184 tos_state_mask = right_n_bits(tos_state_bits),
185 tos_state_shift = BitsPerInt - tos_state_bits, // see verify_tos_state_shift below
186 // misc. option bits; can be any bit position in [16..27]
187 is_field_entry_shift = 26, // (F) is it a field or a method?
188 has_method_type_shift = 25, // (M) does the call site have a MethodType?
189 has_appendix_shift = 24, // (A) does the call site have an appendix argument?
190 is_forced_virtual_shift = 23, // (I) is the interface reference forced to virtual mode?
191 is_final_shift = 22, // (f) is the field or method final?
192 is_volatile_shift = 21, // (v) is the field volatile?
193 is_vfinal_shift = 20, // (vf) did the call resolve to a final method?
194 // low order bits give field index (for FieldInfo) or method parameter size:
195 field_index_bits = 16,
196 field_index_mask = right_n_bits(field_index_bits),
197 parameter_size_bits = 8, // subset of field_index_mask, range is 0..255
198 parameter_size_mask = right_n_bits(parameter_size_bits),
199 option_bits_mask = ~(((~0u) << tos_state_shift) | (field_index_mask | parameter_size_mask))
200 };
201
202 // specific bit definitions for the indices field:
203 enum {
204 cp_index_bits = 2*BitsPerByte,
205 cp_index_mask = right_n_bits(cp_index_bits),
206 bytecode_1_shift = cp_index_bits,
207 bytecode_1_mask = right_n_bits(BitsPerByte), // == (u1)0xFF
208 bytecode_2_shift = cp_index_bits + BitsPerByte,
209 bytecode_2_mask = right_n_bits(BitsPerByte) // == (u1)0xFF
210 };
211
212
213 // Initialization
214 void initialize_entry(int original_index); // initialize primary entry
215 void initialize_resolved_reference_index(int ref_index) {
216 assert(_f2 == 0, "set once"); // note: ref_index might be zero also
217 _f2 = ref_index;
218 }
219
220 void set_field( // sets entry to resolved field state
221 Bytecodes::Code get_code, // the bytecode used for reading the field
222 Bytecodes::Code put_code, // the bytecode used for writing the field
223 Klass* field_holder, // the object/klass holding the field
224 int orig_field_index, // the original field index in the field holder
225 int field_offset, // the field offset in words in the field holder
226 TosState field_type, // the (machine) field type
227 bool is_final, // the field is final
228 bool is_volatile, // the field is volatile
229 Klass* root_klass // needed by the GC to dirty the klass
230 );
231
232 private:
233 void set_direct_or_vtable_call(
234 Bytecodes::Code invoke_code, // the bytecode used for invoking the method
235 const methodHandle& method, // the method/prototype if any (NULL, otherwise)
236 int vtable_index, // the vtable index if any, else negative
237 bool sender_is_interface
238 );
239
240 public:
241 void set_direct_call( // sets entry to exact concrete method entry
242 Bytecodes::Code invoke_code, // the bytecode used for invoking the method
243 const methodHandle& method, // the method to call
244 bool sender_is_interface
245 );
246
247 void set_vtable_call( // sets entry to vtable index
248 Bytecodes::Code invoke_code, // the bytecode used for invoking the method
337 int indices_ord() const { return (intx)OrderAccess::load_ptr_acquire(&_indices); }
338 int constant_pool_index() const { return (indices() & cp_index_mask); }
339 Bytecodes::Code bytecode_1() const { return Bytecodes::cast((indices_ord() >> bytecode_1_shift) & bytecode_1_mask); }
340 Bytecodes::Code bytecode_2() const { return Bytecodes::cast((indices_ord() >> bytecode_2_shift) & bytecode_2_mask); }
341 Metadata* f1_ord() const { return (Metadata *)OrderAccess::load_ptr_acquire(&_f1); }
342 Method* f1_as_method() const { Metadata* f1 = f1_ord(); assert(f1 == NULL || f1->is_method(), ""); return (Method*)f1; }
343 Klass* f1_as_klass() const { Metadata* f1 = f1_ord(); assert(f1 == NULL || f1->is_klass(), ""); return (Klass*)f1; }
344 // Use the accessor f1() to acquire _f1's value. This is needed for
345 // example in BytecodeInterpreter::run(), where is_f1_null() is
346 // called to check if an invokedynamic call is resolved. This load
347 // of _f1 must be ordered with the loads performed by
348 // cache->main_entry_index().
349 bool is_f1_null() const { Metadata* f1 = f1_ord(); return f1 == NULL; } // classifies a CPC entry as unbound
350 int f2_as_index() const { assert(!is_vfinal(), ""); return (int) _f2; }
351 Method* f2_as_vfinal_method() const { assert(is_vfinal(), ""); return (Method*)_f2; }
352 int f2_as_offset() const { assert(is_field_entry(), ""); return (int)_f2; }
353 int field_index() const { assert(is_field_entry(), ""); return (_flags & field_index_mask); }
354 int parameter_size() const { assert(is_method_entry(), ""); return (_flags & parameter_size_mask); }
355 bool is_volatile() const { return (_flags & (1 << is_volatile_shift)) != 0; }
356 bool is_final() const { return (_flags & (1 << is_final_shift)) != 0; }
357 bool is_forced_virtual() const { return (_flags & (1 << is_forced_virtual_shift)) != 0; }
358 bool is_vfinal() const { return (_flags & (1 << is_vfinal_shift)) != 0; }
359 bool has_appendix() const { return (!is_f1_null()) && (_flags & (1 << has_appendix_shift)) != 0; }
360 bool has_method_type() const { return (!is_f1_null()) && (_flags & (1 << has_method_type_shift)) != 0; }
361 bool is_method_entry() const { return (_flags & (1 << is_field_entry_shift)) == 0; }
362 bool is_field_entry() const { return (_flags & (1 << is_field_entry_shift)) != 0; }
363 bool is_long() const { return flag_state() == ltos; }
364 bool is_double() const { return flag_state() == dtos; }
365 bool is_valuetype() const { return flag_state() == qtos; }
366 TosState flag_state() const { assert((uint)number_of_states <= (uint)tos_state_mask+1, "");
367 return (TosState)((_flags >> tos_state_shift) & tos_state_mask); }
368
369 // Code generation support
370 static WordSize size() {
371 return in_WordSize(align_up((int)sizeof(ConstantPoolCacheEntry), wordSize) / wordSize);
372 }
373 static ByteSize size_in_bytes() { return in_ByteSize(sizeof(ConstantPoolCacheEntry)); }
374 static ByteSize indices_offset() { return byte_offset_of(ConstantPoolCacheEntry, _indices); }
375 static ByteSize f1_offset() { return byte_offset_of(ConstantPoolCacheEntry, _f1); }
376 static ByteSize f2_offset() { return byte_offset_of(ConstantPoolCacheEntry, _f2); }
|
32 #include "runtime/orderAccess.hpp"
33 #include "utilities/align.hpp"
34
35 class PSPromotionManager;
36
37 // The ConstantPoolCache is not a cache! It is the resolution table that the
38 // interpreter uses to avoid going into the runtime and a way to access resolved
39 // values.
40
41 // A ConstantPoolCacheEntry describes an individual entry of the constant
42 // pool cache. There's 2 principal kinds of entries: field entries for in-
43 // stance & static field access, and method entries for invokes. Some of
44 // the entry layout is shared and looks as follows:
45 //
46 // bit number |31 0|
47 // bit length |-8--|-8--|---16----|
48 // --------------------------------
49 // _indices [ b2 | b1 | index ] index = constant_pool_index
50 // _f1 [ entry specific ] metadata ptr (method or klass)
51 // _f2 [ entry specific ] vtable or res_ref index, or vfinal method ptr
52 // _flags [tos|0|F=1|0|0|i|f|v|0 |0000|field_index] (for field entries)
53 // bit length [ 4 |1| 1 |1|1|1|1|1|1 |-4--|----16-----]
54 // _flags [tos|0|F=0|M|A|I|f|0|vf|0000|00000|psize] (for method entries)
55 // bit length [ 4 |1| 1 |1|1|1|1|1|1 |-4--|--8--|--8--]
56
57 // --------------------------------
58 //
59 // with:
60 // index = original constant pool index
61 // b1 = bytecode 1
62 // b2 = bytecode 2
63 // psize = parameters size (method entries only)
64 // field_index = index into field information in holder InstanceKlass
65 // The index max is 0xffff (max number of fields in constant pool)
66 // and is multiplied by (InstanceKlass::next_offset) when accessing.
67 // tos = TosState
68 // F = the entry is for a field (or F=0 for a method)
69 // A = call site has an appendix argument (loaded from resolved references)
70 // I = interface call is forced virtual (must use a vtable index or vfinal)
71 // f = field or method is final
72 // v = field is volatile
73 // vf = virtual but final (method entries only: is_vfinal())
74 //
75 // The flags after TosState have the following interpretation:
76 // bit 27: 0 for fields, 1 for methods
77 // i flag true if field is inlined (flatten)
78 // f flag true if field is marked final
79 // v flag true if field is volatile (only for fields)
80 // f2 flag true if f2 contains an oop (e.g., virtual final method)
81 // fv flag true if invokeinterface used for method in class Object
82 //
83 // The flags 31, 30, 29, 28 together build a 4 bit number 0 to 16 with the
84 // following mapping to the TosState states:
85 //
86 // btos: 0
87 // ztos: 1
88 // ctos: 2
89 // stos: 3
90 // itos: 4
91 // ltos: 5
92 // ftos: 6
93 // dtos: 7
94 // atos: 8
95 // qtos: 9
96 // vtos: 10
97 //
172 set_flags(make_flags(return_type, option_bits, method_params));
173 }
174 bool init_method_flags_atomic(TosState return_type, int option_bits, int method_params) {
175 assert((method_params & parameter_size_mask) == method_params, "method_params in range");
176 return init_flags_atomic(make_flags(return_type, option_bits, method_params));
177 }
178
179 public:
180 // specific bit definitions for the flags field:
181 // (Note: the interpreter must use these definitions to access the CP cache.)
182 enum {
183 // high order bits are the TosState corresponding to field type or method return type
184 tos_state_bits = 4,
185 tos_state_mask = right_n_bits(tos_state_bits),
186 tos_state_shift = BitsPerInt - tos_state_bits, // see verify_tos_state_shift below
187 // misc. option bits; can be any bit position in [16..27]
188 is_field_entry_shift = 26, // (F) is it a field or a method?
189 has_method_type_shift = 25, // (M) does the call site have a MethodType?
190 has_appendix_shift = 24, // (A) does the call site have an appendix argument?
191 is_forced_virtual_shift = 23, // (I) is the interface reference forced to virtual mode?
192 is_flatten_field = 23, // (i) is the value field flatten?
193 is_final_shift = 22, // (f) is the field or method final?
194 is_volatile_shift = 21, // (v) is the field volatile?
195 is_vfinal_shift = 20, // (vf) did the call resolve to a final method?
196 // low order bits give field index (for FieldInfo) or method parameter size:
197 field_index_bits = 16,
198 field_index_mask = right_n_bits(field_index_bits),
199 parameter_size_bits = 8, // subset of field_index_mask, range is 0..255
200 parameter_size_mask = right_n_bits(parameter_size_bits),
201 option_bits_mask = ~(((~0u) << tos_state_shift) | (field_index_mask | parameter_size_mask))
202 };
203
204 // specific bit definitions for the indices field:
205 enum {
206 cp_index_bits = 2*BitsPerByte,
207 cp_index_mask = right_n_bits(cp_index_bits),
208 bytecode_1_shift = cp_index_bits,
209 bytecode_1_mask = right_n_bits(BitsPerByte), // == (u1)0xFF
210 bytecode_2_shift = cp_index_bits + BitsPerByte,
211 bytecode_2_mask = right_n_bits(BitsPerByte) // == (u1)0xFF
212 };
213
214
215 // Initialization
216 void initialize_entry(int original_index); // initialize primary entry
217 void initialize_resolved_reference_index(int ref_index) {
218 assert(_f2 == 0, "set once"); // note: ref_index might be zero also
219 _f2 = ref_index;
220 }
221
222 void set_field( // sets entry to resolved field state
223 Bytecodes::Code get_code, // the bytecode used for reading the field
224 Bytecodes::Code put_code, // the bytecode used for writing the field
225 Klass* field_holder, // the object/klass holding the field
226 int orig_field_index, // the original field index in the field holder
227 int field_offset, // the field offset in words in the field holder
228 TosState field_type, // the (machine) field type
229 bool is_final, // the field is final
230 bool is_volatile, // the field is volatile
231 bool is_flatten, // the field is flatten (value field)
232 Klass* root_klass // needed by the GC to dirty the klass
233 );
234
235 private:
236 void set_direct_or_vtable_call(
237 Bytecodes::Code invoke_code, // the bytecode used for invoking the method
238 const methodHandle& method, // the method/prototype if any (NULL, otherwise)
239 int vtable_index, // the vtable index if any, else negative
240 bool sender_is_interface
241 );
242
243 public:
244 void set_direct_call( // sets entry to exact concrete method entry
245 Bytecodes::Code invoke_code, // the bytecode used for invoking the method
246 const methodHandle& method, // the method to call
247 bool sender_is_interface
248 );
249
250 void set_vtable_call( // sets entry to vtable index
251 Bytecodes::Code invoke_code, // the bytecode used for invoking the method
340 int indices_ord() const { return (intx)OrderAccess::load_ptr_acquire(&_indices); }
341 int constant_pool_index() const { return (indices() & cp_index_mask); }
342 Bytecodes::Code bytecode_1() const { return Bytecodes::cast((indices_ord() >> bytecode_1_shift) & bytecode_1_mask); }
343 Bytecodes::Code bytecode_2() const { return Bytecodes::cast((indices_ord() >> bytecode_2_shift) & bytecode_2_mask); }
344 Metadata* f1_ord() const { return (Metadata *)OrderAccess::load_ptr_acquire(&_f1); }
345 Method* f1_as_method() const { Metadata* f1 = f1_ord(); assert(f1 == NULL || f1->is_method(), ""); return (Method*)f1; }
346 Klass* f1_as_klass() const { Metadata* f1 = f1_ord(); assert(f1 == NULL || f1->is_klass(), ""); return (Klass*)f1; }
347 // Use the accessor f1() to acquire _f1's value. This is needed for
348 // example in BytecodeInterpreter::run(), where is_f1_null() is
349 // called to check if an invokedynamic call is resolved. This load
350 // of _f1 must be ordered with the loads performed by
351 // cache->main_entry_index().
352 bool is_f1_null() const { Metadata* f1 = f1_ord(); return f1 == NULL; } // classifies a CPC entry as unbound
353 int f2_as_index() const { assert(!is_vfinal(), ""); return (int) _f2; }
354 Method* f2_as_vfinal_method() const { assert(is_vfinal(), ""); return (Method*)_f2; }
355 int f2_as_offset() const { assert(is_field_entry(), ""); return (int)_f2; }
356 int field_index() const { assert(is_field_entry(), ""); return (_flags & field_index_mask); }
357 int parameter_size() const { assert(is_method_entry(), ""); return (_flags & parameter_size_mask); }
358 bool is_volatile() const { return (_flags & (1 << is_volatile_shift)) != 0; }
359 bool is_final() const { return (_flags & (1 << is_final_shift)) != 0; }
360 bool is_flatten() const { return (_flags & (1 << is_flatten_field)) != 0; }
361 bool is_forced_virtual() const { return (_flags & (1 << is_forced_virtual_shift)) != 0; }
362 bool is_vfinal() const { return (_flags & (1 << is_vfinal_shift)) != 0; }
363 bool has_appendix() const { return (!is_f1_null()) && (_flags & (1 << has_appendix_shift)) != 0; }
364 bool has_method_type() const { return (!is_f1_null()) && (_flags & (1 << has_method_type_shift)) != 0; }
365 bool is_method_entry() const { return (_flags & (1 << is_field_entry_shift)) == 0; }
366 bool is_field_entry() const { return (_flags & (1 << is_field_entry_shift)) != 0; }
367 bool is_long() const { return flag_state() == ltos; }
368 bool is_double() const { return flag_state() == dtos; }
369 bool is_valuetype() const { return flag_state() == qtos; }
370 TosState flag_state() const { assert((uint)number_of_states <= (uint)tos_state_mask+1, "");
371 return (TosState)((_flags >> tos_state_shift) & tos_state_mask); }
372
373 // Code generation support
374 static WordSize size() {
375 return in_WordSize(align_up((int)sizeof(ConstantPoolCacheEntry), wordSize) / wordSize);
376 }
377 static ByteSize size_in_bytes() { return in_ByteSize(sizeof(ConstantPoolCacheEntry)); }
378 static ByteSize indices_offset() { return byte_offset_of(ConstantPoolCacheEntry, _indices); }
379 static ByteSize f1_offset() { return byte_offset_of(ConstantPoolCacheEntry, _f1); }
380 static ByteSize f2_offset() { return byte_offset_of(ConstantPoolCacheEntry, _f2); }
|