218 // until the loader_data is registered.
219 Handle mirror_handle;
220
221 Symbol* name = NULL;
222 Handle loader;
223 { MonitorLockerEx ml(this_oop->lock());
224
225 if (this_oop->tag_at(which).is_unresolved_klass()) {
226 if (this_oop->tag_at(which).is_unresolved_klass_in_error()) {
227 in_error = true;
228 } else {
229 do_resolve = true;
230 name = this_oop->unresolved_klass_at(which);
231 loader = Handle(THREAD, this_oop->pool_holder()->class_loader());
232 }
233 }
234 } // unlocking constantPool
235
236
237 // The original attempt to resolve this constant pool entry failed so find the
238 // original error and throw it again (JVMS 5.4.3).
239 if (in_error) {
240 Symbol* error = SystemDictionary::find_resolution_error(this_oop, which);
241 guarantee(error != (Symbol*)NULL, "tag mismatch with resolution error table");
242 ResourceMark rm;
243 // exception text will be the class name
244 const char* className = this_oop->unresolved_klass_at(which)->as_C_string();
245 THROW_MSG_0(error, className);
246 }
247
248 if (do_resolve) {
249 // this_oop must be unlocked during resolve_or_fail
250 oop protection_domain = this_oop->pool_holder()->protection_domain();
251 Handle h_prot (THREAD, protection_domain);
252 Klass* k_oop = SystemDictionary::resolve_or_fail(name, loader, h_prot, true, THREAD);
253 KlassHandle k;
254 if (!HAS_PENDING_EXCEPTION) {
255 k = KlassHandle(THREAD, k_oop);
256 // preserve the resolved klass.
257 mirror_handle = Handle(THREAD, k_oop->java_mirror());
258 // Do access check for klasses
259 verify_constant_pool_resolve(this_oop, k, THREAD);
260 }
261
262 // Failed to resolve class. We must record the errors so that subsequent attempts
263 // to resolve this constant pool entry fail with the same error (JVMS 5.4.3).
264 if (HAS_PENDING_EXCEPTION) {
265 ResourceMark rm;
266 Symbol* error = PENDING_EXCEPTION->klass()->name();
267
268 bool throw_orig_error = false;
269 {
270 MonitorLockerEx ml(this_oop->lock());
271
272 // some other thread has beaten us and has resolved the class.
273 if (this_oop->tag_at(which).is_klass()) {
274 CLEAR_PENDING_EXCEPTION;
275 entry = this_oop->resolved_klass_at(which);
276 return entry.get_klass();
277 }
278
279 if (!PENDING_EXCEPTION->
280 is_a(SystemDictionary::LinkageError_klass())) {
281 // Just throw the exception and don't prevent these classes from
282 // being loaded due to virtual machine errors like StackOverflow
283 // and OutOfMemoryError, etc, or if the thread was hit by stop()
284 // Needs clarification to section 5.4.3 of the VM spec (see 6308271)
285 }
286 else if (!this_oop->tag_at(which).is_unresolved_klass_in_error()) {
287 SystemDictionary::add_resolution_error(this_oop, which, error);
288 this_oop->tag_at_put(which, JVM_CONSTANT_UnresolvedClassInError);
289 } else {
290 // some other thread has put the class in error state.
291 error = SystemDictionary::find_resolution_error(this_oop, which);
292 assert(error != NULL, "checking");
293 throw_orig_error = true;
294 }
295 } // unlocked
296
297 if (throw_orig_error) {
298 CLEAR_PENDING_EXCEPTION;
299 ResourceMark rm;
300 const char* className = this_oop->unresolved_klass_at(which)->as_C_string();
301 THROW_MSG_0(error, className);
302 }
303
304 return 0;
305 }
306
307 if (TraceClassResolution && !k()->oop_is_array()) {
308 // skip resolving the constant pool so that this code get's
309 // called the next time some bytecodes refer to this class.
310 ResourceMark rm;
311 int line_number = -1;
312 const char * source_file = NULL;
313 if (JavaThread::current()->has_last_Java_frame()) {
314 // try to identify the method which called this function.
315 vframeStream vfst(JavaThread::current());
316 if (!vfst.at_end()) {
317 line_number = vfst.method()->line_number_from_bci(vfst.bci());
318 Symbol* s = vfst.method()->method_holder()->source_file_name();
319 if (s != NULL) {
320 source_file = s->as_C_string();
321 }
322 }
323 }
324 if (k() != this_oop->pool_holder()) {
580 }
581 }
582 }
583
584 // Resolve all the classes in the constant pool. If they are all resolved,
585 // the constant pool is read-only. Enhancement: allocate cp entries to
586 // another metaspace, and copy to read-only or read-write space if this
587 // bit is set.
588 bool ConstantPool::resolve_class_constants(TRAPS) {
589 constantPoolHandle cp(THREAD, this);
590 for (int index = 1; index < length(); index++) { // Index 0 is unused
591 if (tag_at(index).is_unresolved_klass() &&
592 klass_at_if_loaded(cp, index) == NULL) {
593 return false;
594 }
595 }
596 // set_preresolution(); or some bit for future use
597 return true;
598 }
599
600 // If resolution for MethodHandle or MethodType fails, save the exception
601 // in the resolution error table, so that the same exception is thrown again.
602 void ConstantPool::save_and_throw_exception(constantPoolHandle this_oop, int which,
603 int tag, TRAPS) {
604 ResourceMark rm;
605 Symbol* error = PENDING_EXCEPTION->klass()->name();
606 MonitorLockerEx ml(this_oop->lock()); // lock cpool to change tag.
607
608 int error_tag = (tag == JVM_CONSTANT_MethodHandle) ?
609 JVM_CONSTANT_MethodHandleInError : JVM_CONSTANT_MethodTypeInError;
610
611 if (!PENDING_EXCEPTION->
612 is_a(SystemDictionary::LinkageError_klass())) {
613 // Just throw the exception and don't prevent these classes from
614 // being loaded due to virtual machine errors like StackOverflow
615 // and OutOfMemoryError, etc, or if the thread was hit by stop()
616 // Needs clarification to section 5.4.3 of the VM spec (see 6308271)
617
618 } else if (this_oop->tag_at(which).value() != error_tag) {
619 SystemDictionary::add_resolution_error(this_oop, which, error);
620 this_oop->tag_at_put(which, error_tag);
621 } else {
622 // some other thread has put the class in error state.
623 error = SystemDictionary::find_resolution_error(this_oop, which);
624 assert(error != NULL, "checking");
625 CLEAR_PENDING_EXCEPTION;
626 THROW_MSG(error, "");
627 }
628 }
629
630
631 // Called to resolve constants in the constant pool and return an oop.
632 // Some constant pool entries cache their resolved oop. This is also
633 // called to create oops from constants to use in arguments for invokedynamic
634 oop ConstantPool::resolve_constant_at_impl(constantPoolHandle this_oop, int index, int cache_index, TRAPS) {
635 oop result_oop = NULL;
636 Handle throw_exception;
637
638 if (cache_index == _possible_index_sentinel) {
639 // It is possible that this constant is one which is cached in the objects.
640 // We'll do a linear search. This should be OK because this usage is rare.
641 assert(index > 0, "valid index");
642 cache_index = this_oop->cp_to_object_index(index);
643 }
644 assert(cache_index == _no_index_sentinel || cache_index >= 0, "");
645 assert(index == _no_index_sentinel || index >= 0, "");
646
647 if (cache_index >= 0) {
648 result_oop = this_oop->resolved_references()->obj_at(cache_index);
649 if (result_oop != NULL) {
650 return result_oop;
651 // That was easy...
652 }
653 index = this_oop->object_to_cp_index(cache_index);
654 }
655
656 jvalue prim_value; // temp used only in a few cases below
657
658 int tag_value = this_oop->tag_at(index).value();
659
660 switch (tag_value) {
661
662 case JVM_CONSTANT_UnresolvedClass:
663 case JVM_CONSTANT_UnresolvedClassInError:
664 case JVM_CONSTANT_Class:
665 {
666 assert(cache_index == _no_index_sentinel, "should not have been set");
667 Klass* resolved = klass_at_impl(this_oop, index, CHECK_NULL);
668 // ldc wants the java mirror.
669 result_oop = resolved->java_mirror();
670 break;
671 }
672
673 case JVM_CONSTANT_String:
674 assert(cache_index != _no_index_sentinel, "should have been set");
675 if (this_oop->is_pseudo_string_at(index)) {
676 result_oop = this_oop->pseudo_string_at(index, cache_index);
677 break;
678 }
679 result_oop = string_at_impl(this_oop, index, cache_index, CHECK_NULL);
680 break;
681
682 case JVM_CONSTANT_MethodHandleInError:
683 case JVM_CONSTANT_MethodTypeInError:
684 {
685 Symbol* error = SystemDictionary::find_resolution_error(this_oop, index);
686 guarantee(error != (Symbol*)NULL, "tag mismatch with resolution error table");
687 ResourceMark rm;
688 THROW_MSG_0(error, "");
689 break;
690 }
691
692 case JVM_CONSTANT_MethodHandle:
693 {
694 int ref_kind = this_oop->method_handle_ref_kind_at(index);
695 int callee_index = this_oop->method_handle_klass_index_at(index);
696 Symbol* name = this_oop->method_handle_name_ref_at(index);
697 Symbol* signature = this_oop->method_handle_signature_ref_at(index);
698 if (PrintMiscellaneous)
699 tty->print_cr("resolve JVM_CONSTANT_MethodHandle:%d [%d/%d/%d] %s.%s",
700 ref_kind, index, this_oop->method_handle_index_at(index),
701 callee_index, name->as_C_string(), signature->as_C_string());
702 KlassHandle callee;
703 { Klass* k = klass_at_impl(this_oop, callee_index, CHECK_NULL);
704 callee = KlassHandle(THREAD, k);
705 }
706 KlassHandle klass(THREAD, this_oop->pool_holder());
707 Handle value = SystemDictionary::link_method_handle_constant(klass, ref_kind,
708 callee, name, signature,
709 THREAD);
710 result_oop = value();
711 if (HAS_PENDING_EXCEPTION) {
712 save_and_throw_exception(this_oop, index, tag_value, CHECK_NULL);
713 }
714 break;
715 }
716
717 case JVM_CONSTANT_MethodType:
718 {
719 Symbol* signature = this_oop->method_type_signature_at(index);
720 if (PrintMiscellaneous)
721 tty->print_cr("resolve JVM_CONSTANT_MethodType [%d/%d] %s",
722 index, this_oop->method_type_index_at(index),
723 signature->as_C_string());
724 KlassHandle klass(THREAD, this_oop->pool_holder());
725 Handle value = SystemDictionary::find_method_handle_type(signature, klass, THREAD);
726 result_oop = value();
727 if (HAS_PENDING_EXCEPTION) {
728 save_and_throw_exception(this_oop, index, tag_value, CHECK_NULL);
729 }
730 break;
731 }
732
733 case JVM_CONSTANT_Integer:
734 assert(cache_index == _no_index_sentinel, "should not have been set");
735 prim_value.i = this_oop->int_at(index);
736 result_oop = java_lang_boxing_object::create(T_INT, &prim_value, CHECK_NULL);
737 break;
738
739 case JVM_CONSTANT_Float:
740 assert(cache_index == _no_index_sentinel, "should not have been set");
741 prim_value.f = this_oop->float_at(index);
742 result_oop = java_lang_boxing_object::create(T_FLOAT, &prim_value, CHECK_NULL);
743 break;
744
745 case JVM_CONSTANT_Long:
746 assert(cache_index == _no_index_sentinel, "should not have been set");
747 prim_value.j = this_oop->long_at(index);
748 result_oop = java_lang_boxing_object::create(T_LONG, &prim_value, CHECK_NULL);
749 break;
750
751 case JVM_CONSTANT_Double:
752 assert(cache_index == _no_index_sentinel, "should not have been set");
753 prim_value.d = this_oop->double_at(index);
754 result_oop = java_lang_boxing_object::create(T_DOUBLE, &prim_value, CHECK_NULL);
755 break;
756
757 default:
758 DEBUG_ONLY( tty->print_cr("*** %p: tag at CP[%d/%d] = %d",
759 this_oop(), index, cache_index, tag_value) );
760 assert(false, "unexpected constant tag");
761 break;
762 }
763
764 if (cache_index >= 0) {
765 // Cache the oop here also.
766 Handle result_handle(THREAD, result_oop);
767 MonitorLockerEx ml(this_oop->lock()); // don't know if we really need this
768 oop result = this_oop->resolved_references()->obj_at(cache_index);
769 // Benign race condition: resolved_references may already be filled in while we were trying to lock.
770 // The important thing here is that all threads pick up the same result.
771 // It doesn't matter which racing thread wins, as long as only one
772 // result is used by all threads, and all future queries.
773 // That result may be either a resolved constant or a failure exception.
774 if (result == NULL) {
775 this_oop->resolved_references()->obj_at_put(cache_index, result_handle());
776 return result_handle();
777 } else {
778 // Return the winning thread's result. This can be different than
779 // result_handle() for MethodHandles.
|
218 // until the loader_data is registered.
219 Handle mirror_handle;
220
221 Symbol* name = NULL;
222 Handle loader;
223 { MonitorLockerEx ml(this_oop->lock());
224
225 if (this_oop->tag_at(which).is_unresolved_klass()) {
226 if (this_oop->tag_at(which).is_unresolved_klass_in_error()) {
227 in_error = true;
228 } else {
229 do_resolve = true;
230 name = this_oop->unresolved_klass_at(which);
231 loader = Handle(THREAD, this_oop->pool_holder()->class_loader());
232 }
233 }
234 } // unlocking constantPool
235
236
237 // The original attempt to resolve this constant pool entry failed so find the
238 // class of the original error and throw another error of the same class (JVMS 5.4.3).
239 // If there is a detail message, pass that detail message to the error constructor.
240 // The JVMS does not strictly require us to duplicate the same detail message,
241 // or any internal exception fields such as cause or stacktrace. But since the
242 // detail message is often a class name or other literal string, we will repeat it if
243 // we can find it in the symbol table.
244 if (in_error) {
245 throw_resolution_error(this_oop, which, CHECK_0);
246 }
247
248 if (do_resolve) {
249 // this_oop must be unlocked during resolve_or_fail
250 oop protection_domain = this_oop->pool_holder()->protection_domain();
251 Handle h_prot (THREAD, protection_domain);
252 Klass* k_oop = SystemDictionary::resolve_or_fail(name, loader, h_prot, true, THREAD);
253 KlassHandle k;
254 if (!HAS_PENDING_EXCEPTION) {
255 k = KlassHandle(THREAD, k_oop);
256 // preserve the resolved klass.
257 mirror_handle = Handle(THREAD, k_oop->java_mirror());
258 // Do access check for klasses
259 verify_constant_pool_resolve(this_oop, k, THREAD);
260 }
261
262 // Failed to resolve class. We must record the errors so that subsequent attempts
263 // to resolve this constant pool entry fail with the same error (JVMS 5.4.3).
264 if (HAS_PENDING_EXCEPTION) {
265 MonitorLockerEx ml(this_oop->lock());
266
267 // some other thread has beaten us and has resolved the class.
268 if (this_oop->tag_at(which).is_klass()) {
269 CLEAR_PENDING_EXCEPTION;
270 entry = this_oop->resolved_klass_at(which);
271 return entry.get_klass();
272 }
273
274 // The tag could have changed to in-error before the lock but we have to
275 // handle that here for the class case.
276 save_and_throw_exception(this_oop, which, constantTag(JVM_CONSTANT_UnresolvedClass), CHECK_0);
277 }
278
279 if (TraceClassResolution && !k()->oop_is_array()) {
280 // skip resolving the constant pool so that this code get's
281 // called the next time some bytecodes refer to this class.
282 ResourceMark rm;
283 int line_number = -1;
284 const char * source_file = NULL;
285 if (JavaThread::current()->has_last_Java_frame()) {
286 // try to identify the method which called this function.
287 vframeStream vfst(JavaThread::current());
288 if (!vfst.at_end()) {
289 line_number = vfst.method()->line_number_from_bci(vfst.bci());
290 Symbol* s = vfst.method()->method_holder()->source_file_name();
291 if (s != NULL) {
292 source_file = s->as_C_string();
293 }
294 }
295 }
296 if (k() != this_oop->pool_holder()) {
552 }
553 }
554 }
555
556 // Resolve all the classes in the constant pool. If they are all resolved,
557 // the constant pool is read-only. Enhancement: allocate cp entries to
558 // another metaspace, and copy to read-only or read-write space if this
559 // bit is set.
560 bool ConstantPool::resolve_class_constants(TRAPS) {
561 constantPoolHandle cp(THREAD, this);
562 for (int index = 1; index < length(); index++) { // Index 0 is unused
563 if (tag_at(index).is_unresolved_klass() &&
564 klass_at_if_loaded(cp, index) == NULL) {
565 return false;
566 }
567 }
568 // set_preresolution(); or some bit for future use
569 return true;
570 }
571
572 Symbol* ConstantPool::exception_message(constantPoolHandle this_oop, int which, constantTag tag, oop pending_exception) {
573 // Dig out the detailed message to reuse if possible
574 Symbol* message = java_lang_Throwable::detail_message(pending_exception);
575 if (message != NULL) {
576 return message;
577 }
578
579 // Return specific message for the tag
580 switch (tag.value()) {
581 case JVM_CONSTANT_UnresolvedClass:
582 // return the class name in the error message
583 message = this_oop->unresolved_klass_at(which);
584 break;
585 case JVM_CONSTANT_MethodHandle:
586 // return the method handle name in the error message
587 message = this_oop->method_handle_name_ref_at(which);
588 break;
589 case JVM_CONSTANT_MethodType:
590 // return the method type signature in the error message
591 message = this_oop->method_type_signature_at(which);
592 break;
593 default:
594 ShouldNotReachHere();
595 }
596
597 return message;
598 }
599
600 void ConstantPool::throw_resolution_error(constantPoolHandle this_oop, int which, TRAPS) {
601 Symbol* message = NULL;
602 Symbol* error = SystemDictionary::find_resolution_error(this_oop, which, &message);
603 assert(error != NULL && message != NULL, "checking");
604 CLEAR_PENDING_EXCEPTION;
605 ResourceMark rm;
606 THROW_MSG(error, message->as_C_string());
607 }
608
609 // If resolution for Class, MethodHandle or MethodType fails, save the exception
610 // in the resolution error table, so that the same exception is thrown again.
611 void ConstantPool::save_and_throw_exception(constantPoolHandle this_oop, int which,
612 constantTag tag, TRAPS) {
613 assert(this_oop->lock()->is_locked(), "constant pool lock should be held");
614 Symbol* error = PENDING_EXCEPTION->klass()->name();
615
616 int error_tag = tag.error_value();
617
618 if (!PENDING_EXCEPTION->
619 is_a(SystemDictionary::LinkageError_klass())) {
620 // Just throw the exception and don't prevent these classes from
621 // being loaded due to virtual machine errors like StackOverflow
622 // and OutOfMemoryError, etc, or if the thread was hit by stop()
623 // Needs clarification to section 5.4.3 of the VM spec (see 6308271)
624 } else if (this_oop->tag_at(which).value() != error_tag) {
625 Symbol* message = exception_message(this_oop, which, tag, PENDING_EXCEPTION);
626 SystemDictionary::add_resolution_error(this_oop, which, error, message);
627 this_oop->tag_at_put(which, error_tag);
628 } else {
629 // some other thread put this in error state
630 throw_resolution_error(this_oop, which, CHECK);
631 }
632
633 // This exits with some pending exception
634 assert(HAS_PENDING_EXCEPTION, "should not be cleared");
635 }
636
637
638
639 // Called to resolve constants in the constant pool and return an oop.
640 // Some constant pool entries cache their resolved oop. This is also
641 // called to create oops from constants to use in arguments for invokedynamic
642 oop ConstantPool::resolve_constant_at_impl(constantPoolHandle this_oop, int index, int cache_index, TRAPS) {
643 oop result_oop = NULL;
644 Handle throw_exception;
645
646 if (cache_index == _possible_index_sentinel) {
647 // It is possible that this constant is one which is cached in the objects.
648 // We'll do a linear search. This should be OK because this usage is rare.
649 assert(index > 0, "valid index");
650 cache_index = this_oop->cp_to_object_index(index);
651 }
652 assert(cache_index == _no_index_sentinel || cache_index >= 0, "");
653 assert(index == _no_index_sentinel || index >= 0, "");
654
655 if (cache_index >= 0) {
656 result_oop = this_oop->resolved_references()->obj_at(cache_index);
657 if (result_oop != NULL) {
658 return result_oop;
659 // That was easy...
660 }
661 index = this_oop->object_to_cp_index(cache_index);
662 }
663
664 jvalue prim_value; // temp used only in a few cases below
665
666 constantTag tag = this_oop->tag_at(index);
667
668 switch (tag.value()) {
669
670 case JVM_CONSTANT_UnresolvedClass:
671 case JVM_CONSTANT_UnresolvedClassInError:
672 case JVM_CONSTANT_Class:
673 {
674 assert(cache_index == _no_index_sentinel, "should not have been set");
675 Klass* resolved = klass_at_impl(this_oop, index, CHECK_NULL);
676 // ldc wants the java mirror.
677 result_oop = resolved->java_mirror();
678 break;
679 }
680
681 case JVM_CONSTANT_String:
682 assert(cache_index != _no_index_sentinel, "should have been set");
683 if (this_oop->is_pseudo_string_at(index)) {
684 result_oop = this_oop->pseudo_string_at(index, cache_index);
685 break;
686 }
687 result_oop = string_at_impl(this_oop, index, cache_index, CHECK_NULL);
688 break;
689
690 case JVM_CONSTANT_MethodHandleInError:
691 case JVM_CONSTANT_MethodTypeInError:
692 {
693 throw_resolution_error(this_oop, index, CHECK_NULL);
694 break;
695 }
696
697 case JVM_CONSTANT_MethodHandle:
698 {
699 int ref_kind = this_oop->method_handle_ref_kind_at(index);
700 int callee_index = this_oop->method_handle_klass_index_at(index);
701 Symbol* name = this_oop->method_handle_name_ref_at(index);
702 Symbol* signature = this_oop->method_handle_signature_ref_at(index);
703 if (PrintMiscellaneous)
704 tty->print_cr("resolve JVM_CONSTANT_MethodHandle:%d [%d/%d/%d] %s.%s",
705 ref_kind, index, this_oop->method_handle_index_at(index),
706 callee_index, name->as_C_string(), signature->as_C_string());
707 KlassHandle callee;
708 { Klass* k = klass_at_impl(this_oop, callee_index, CHECK_NULL);
709 callee = KlassHandle(THREAD, k);
710 }
711 KlassHandle klass(THREAD, this_oop->pool_holder());
712 Handle value = SystemDictionary::link_method_handle_constant(klass, ref_kind,
713 callee, name, signature,
714 THREAD);
715 result_oop = value();
716 if (HAS_PENDING_EXCEPTION) {
717 MonitorLockerEx ml(this_oop->lock()); // lock cpool to change tag.
718 save_and_throw_exception(this_oop, index, tag, CHECK_NULL);
719 }
720 break;
721 }
722
723 case JVM_CONSTANT_MethodType:
724 {
725 Symbol* signature = this_oop->method_type_signature_at(index);
726 if (PrintMiscellaneous)
727 tty->print_cr("resolve JVM_CONSTANT_MethodType [%d/%d] %s",
728 index, this_oop->method_type_index_at(index),
729 signature->as_C_string());
730 KlassHandle klass(THREAD, this_oop->pool_holder());
731 Handle value = SystemDictionary::find_method_handle_type(signature, klass, THREAD);
732 result_oop = value();
733 if (HAS_PENDING_EXCEPTION) {
734 MonitorLockerEx ml(this_oop->lock()); // lock cpool to change tag.
735 save_and_throw_exception(this_oop, index, tag, CHECK_NULL);
736 }
737 break;
738 }
739
740 case JVM_CONSTANT_Integer:
741 assert(cache_index == _no_index_sentinel, "should not have been set");
742 prim_value.i = this_oop->int_at(index);
743 result_oop = java_lang_boxing_object::create(T_INT, &prim_value, CHECK_NULL);
744 break;
745
746 case JVM_CONSTANT_Float:
747 assert(cache_index == _no_index_sentinel, "should not have been set");
748 prim_value.f = this_oop->float_at(index);
749 result_oop = java_lang_boxing_object::create(T_FLOAT, &prim_value, CHECK_NULL);
750 break;
751
752 case JVM_CONSTANT_Long:
753 assert(cache_index == _no_index_sentinel, "should not have been set");
754 prim_value.j = this_oop->long_at(index);
755 result_oop = java_lang_boxing_object::create(T_LONG, &prim_value, CHECK_NULL);
756 break;
757
758 case JVM_CONSTANT_Double:
759 assert(cache_index == _no_index_sentinel, "should not have been set");
760 prim_value.d = this_oop->double_at(index);
761 result_oop = java_lang_boxing_object::create(T_DOUBLE, &prim_value, CHECK_NULL);
762 break;
763
764 default:
765 DEBUG_ONLY( tty->print_cr("*** %p: tag at CP[%d/%d] = %d",
766 this_oop(), index, cache_index, tag.value()));
767 assert(false, "unexpected constant tag");
768 break;
769 }
770
771 if (cache_index >= 0) {
772 // Cache the oop here also.
773 Handle result_handle(THREAD, result_oop);
774 MonitorLockerEx ml(this_oop->lock()); // don't know if we really need this
775 oop result = this_oop->resolved_references()->obj_at(cache_index);
776 // Benign race condition: resolved_references may already be filled in while we were trying to lock.
777 // The important thing here is that all threads pick up the same result.
778 // It doesn't matter which racing thread wins, as long as only one
779 // result is used by all threads, and all future queries.
780 // That result may be either a resolved constant or a failure exception.
781 if (result == NULL) {
782 this_oop->resolved_references()->obj_at_put(cache_index, result_handle());
783 return result_handle();
784 } else {
785 // Return the winning thread's result. This can be different than
786 // result_handle() for MethodHandles.
|