64 // This adds at most one step to the binary search, an amount which |
64 // This adds at most one step to the binary search, an amount which |
65 // decreases for complex compilation tasks. |
65 // decreases for complex compilation tasks. |
66 |
66 |
67 // ------------------------------------------------------------------ |
67 // ------------------------------------------------------------------ |
68 // ciField::ciField |
68 // ciField::ciField |
69 ciField::ciField(ciInstanceKlass* klass, int index): _known_to_link_with_put(NULL), _known_to_link_with_get(NULL) { |
69 ciField::ciField(ciInstanceKlass* klass, int index) : |
|
70 _known_to_link_with_put(NULL), _known_to_link_with_get(NULL) { |
70 ASSERT_IN_VM; |
71 ASSERT_IN_VM; |
71 CompilerThread *thread = CompilerThread::current(); |
72 CompilerThread *thread = CompilerThread::current(); |
72 |
73 |
73 assert(ciObjectFactory::is_initialized(), "not a shared field"); |
74 assert(ciObjectFactory::is_initialized(), "not a shared field"); |
74 |
75 |
171 |
172 |
172 assert(canonical_holder == field_desc.field_holder(), "just checking"); |
173 assert(canonical_holder == field_desc.field_holder(), "just checking"); |
173 initialize_from(&field_desc); |
174 initialize_from(&field_desc); |
174 } |
175 } |
175 |
176 |
176 ciField::ciField(fieldDescriptor *fd): _known_to_link_with_put(NULL), _known_to_link_with_get(NULL) { |
177 ciField::ciField(fieldDescriptor *fd) : |
|
178 _known_to_link_with_put(NULL), _known_to_link_with_get(NULL) { |
177 ASSERT_IN_VM; |
179 ASSERT_IN_VM; |
178 |
180 |
179 // Get the field's name, signature, and type. |
181 // Get the field's name, signature, and type. |
180 ciEnv* env = CURRENT_ENV; |
182 ciEnv* env = CURRENT_ENV; |
181 _name = env->get_symbol(fd->name()); |
183 _name = env->get_symbol(fd->name()); |
235 _holder = CURRENT_ENV->get_instance_klass(fd->field_holder()); |
237 _holder = CURRENT_ENV->get_instance_klass(fd->field_holder()); |
236 |
238 |
237 // Check to see if the field is constant. |
239 // Check to see if the field is constant. |
238 Klass* k = _holder->get_Klass(); |
240 Klass* k = _holder->get_Klass(); |
239 bool is_stable_field = FoldStableValues && is_stable(); |
241 bool is_stable_field = FoldStableValues && is_stable(); |
240 if (is_final() || is_stable_field) { |
242 if ((is_final() && !has_initialized_final_update()) || is_stable_field) { |
241 if (is_static()) { |
243 if (is_static()) { |
242 // This field just may be constant. The only case where it will |
244 // This field just may be constant. The only case where it will |
243 // not be constant is when the field is a *special* static & final field |
245 // not be constant is when the field is a *special* static & final field |
244 // whose value may change. The three examples are java.lang.System.in, |
246 // whose value may change. The three examples are java.lang.System.in, |
245 // java.lang.System.out, and java.lang.System.err. |
247 // java.lang.System.out, and java.lang.System.err. |
263 } else { |
265 } else { |
264 // For CallSite objects treat the target field as a compile time constant. |
266 // For CallSite objects treat the target field as a compile time constant. |
265 assert(SystemDictionary::CallSite_klass() != NULL, "should be already initialized"); |
267 assert(SystemDictionary::CallSite_klass() != NULL, "should be already initialized"); |
266 if (k == SystemDictionary::CallSite_klass() && |
268 if (k == SystemDictionary::CallSite_klass() && |
267 _offset == java_lang_invoke_CallSite::target_offset_in_bytes()) { |
269 _offset == java_lang_invoke_CallSite::target_offset_in_bytes()) { |
|
270 assert(!has_initialized_final_update(), "CallSite is not supposed to have writes to final fields outside initializers"); |
268 _is_constant = true; |
271 _is_constant = true; |
269 } else { |
272 } else { |
270 // Non-final & non-stable fields are not constants. |
273 // Non-final & non-stable fields are not constants. |
271 _is_constant = false; |
274 _is_constant = false; |
272 } |
275 } |
338 // ------------------------------------------------------------------ |
341 // ------------------------------------------------------------------ |
339 // ciField::will_link |
342 // ciField::will_link |
340 // |
343 // |
341 // Can a specific access to this field be made without causing |
344 // Can a specific access to this field be made without causing |
342 // link errors? |
345 // link errors? |
343 bool ciField::will_link(ciInstanceKlass* accessing_klass, |
346 bool ciField::will_link(ciMethod* accessing_method, |
344 Bytecodes::Code bc) { |
347 Bytecodes::Code bc) { |
345 VM_ENTRY_MARK; |
348 VM_ENTRY_MARK; |
346 assert(bc == Bytecodes::_getstatic || bc == Bytecodes::_putstatic || |
349 assert(bc == Bytecodes::_getstatic || bc == Bytecodes::_putstatic || |
347 bc == Bytecodes::_getfield || bc == Bytecodes::_putfield, |
350 bc == Bytecodes::_getfield || bc == Bytecodes::_putfield, |
348 "unexpected bytecode"); |
351 "unexpected bytecode"); |
361 } |
364 } |
362 |
365 |
363 // Get and put can have different accessibility rules |
366 // Get and put can have different accessibility rules |
364 bool is_put = (bc == Bytecodes::_putfield || bc == Bytecodes::_putstatic); |
367 bool is_put = (bc == Bytecodes::_putfield || bc == Bytecodes::_putstatic); |
365 if (is_put) { |
368 if (is_put) { |
366 if (_known_to_link_with_put == accessing_klass) { |
369 if (_known_to_link_with_put == accessing_method) { |
367 return true; |
370 return true; |
368 } |
371 } |
369 } else { |
372 } else { |
370 if (_known_to_link_with_get == accessing_klass) { |
373 if (_known_to_link_with_get == accessing_method->holder()) { |
371 return true; |
374 return true; |
372 } |
375 } |
373 } |
376 } |
374 |
377 |
375 LinkInfo link_info(_holder->get_instanceKlass(), |
378 LinkInfo link_info(_holder->get_instanceKlass(), |
376 _name->get_symbol(), _signature->get_symbol(), |
379 _name->get_symbol(), _signature->get_symbol(), |
377 accessing_klass->get_Klass()); |
380 accessing_method->get_Method()); |
378 fieldDescriptor result; |
381 fieldDescriptor result; |
379 LinkResolver::resolve_field(result, link_info, bc, false, KILL_COMPILE_ON_FATAL_(false)); |
382 LinkResolver::resolve_field(result, link_info, bc, false, KILL_COMPILE_ON_FATAL_(false)); |
380 |
383 |
381 // update the hit-cache, unless there is a problem with memory scoping: |
384 // update the hit-cache, unless there is a problem with memory scoping: |
382 if (accessing_klass->is_shared() || !is_shared()) { |
385 if (accessing_method->holder()->is_shared() || !is_shared()) { |
383 if (is_put) { |
386 if (is_put) { |
384 _known_to_link_with_put = accessing_klass; |
387 _known_to_link_with_put = accessing_method; |
385 } else { |
388 } else { |
386 _known_to_link_with_get = accessing_klass; |
389 _known_to_link_with_get = accessing_method->holder(); |
387 } |
390 } |
388 } |
391 } |
389 |
392 |
390 return true; |
393 return true; |
391 } |
394 } |