468 OrderAccess::storestore(); |
468 OrderAccess::storestore(); |
469 java_lang_Class::set_init_lock(java_mirror(), NULL); |
469 java_lang_Class::set_init_lock(java_mirror(), NULL); |
470 assert(!is_not_initialized(), "class must be initialized now"); |
470 assert(!is_not_initialized(), "class must be initialized now"); |
471 } |
471 } |
472 |
472 |
473 void InstanceKlass::eager_initialize_impl(instanceKlassHandle this_oop) { |
473 void InstanceKlass::eager_initialize_impl(instanceKlassHandle this_k) { |
474 EXCEPTION_MARK; |
474 EXCEPTION_MARK; |
475 oop init_lock = this_oop->init_lock(); |
475 oop init_lock = this_k->init_lock(); |
476 ObjectLocker ol(init_lock, THREAD, init_lock != NULL); |
476 ObjectLocker ol(init_lock, THREAD, init_lock != NULL); |
477 |
477 |
478 // abort if someone beat us to the initialization |
478 // abort if someone beat us to the initialization |
479 if (!this_oop->is_not_initialized()) return; // note: not equivalent to is_initialized() |
479 if (!this_k->is_not_initialized()) return; // note: not equivalent to is_initialized() |
480 |
480 |
481 ClassState old_state = this_oop->init_state(); |
481 ClassState old_state = this_k->init_state(); |
482 link_class_impl(this_oop, true, THREAD); |
482 link_class_impl(this_k, true, THREAD); |
483 if (HAS_PENDING_EXCEPTION) { |
483 if (HAS_PENDING_EXCEPTION) { |
484 CLEAR_PENDING_EXCEPTION; |
484 CLEAR_PENDING_EXCEPTION; |
485 // Abort if linking the class throws an exception. |
485 // Abort if linking the class throws an exception. |
486 |
486 |
487 // Use a test to avoid redundantly resetting the state if there's |
487 // Use a test to avoid redundantly resetting the state if there's |
488 // no change. Set_init_state() asserts that state changes make |
488 // no change. Set_init_state() asserts that state changes make |
489 // progress, whereas here we might just be spinning in place. |
489 // progress, whereas here we might just be spinning in place. |
490 if( old_state != this_oop->_init_state ) |
490 if( old_state != this_k->_init_state ) |
491 this_oop->set_init_state (old_state); |
491 this_k->set_init_state (old_state); |
492 } else { |
492 } else { |
493 // linking successfull, mark class as initialized |
493 // linking successfull, mark class as initialized |
494 this_oop->set_init_state (fully_initialized); |
494 this_k->set_init_state (fully_initialized); |
495 this_oop->fence_and_clear_init_lock(); |
495 this_k->fence_and_clear_init_lock(); |
496 // trace |
496 // trace |
497 if (TraceClassInitialization) { |
497 if (TraceClassInitialization) { |
498 ResourceMark rm(THREAD); |
498 ResourceMark rm(THREAD); |
499 tty->print_cr("[Initialized %s without side effects]", this_oop->external_name()); |
499 tty->print_cr("[Initialized %s without side effects]", this_k->external_name()); |
500 } |
500 } |
501 } |
501 } |
502 } |
502 } |
503 |
503 |
504 |
504 |
506 // process. The step comments refers to the procedure described in that section. |
506 // process. The step comments refers to the procedure described in that section. |
507 // Note: implementation moved to static method to expose the this pointer. |
507 // Note: implementation moved to static method to expose the this pointer. |
508 void InstanceKlass::initialize(TRAPS) { |
508 void InstanceKlass::initialize(TRAPS) { |
509 if (this->should_be_initialized()) { |
509 if (this->should_be_initialized()) { |
510 HandleMark hm(THREAD); |
510 HandleMark hm(THREAD); |
511 instanceKlassHandle this_oop(THREAD, this); |
511 instanceKlassHandle this_k(THREAD, this); |
512 initialize_impl(this_oop, CHECK); |
512 initialize_impl(this_k, CHECK); |
513 // Note: at this point the class may be initialized |
513 // Note: at this point the class may be initialized |
514 // OR it may be in the state of being initialized |
514 // OR it may be in the state of being initialized |
515 // in case of recursive initialization! |
515 // in case of recursive initialization! |
516 } else { |
516 } else { |
517 assert(is_initialized(), "sanity check"); |
517 assert(is_initialized(), "sanity check"); |
518 } |
518 } |
519 } |
519 } |
520 |
520 |
521 |
521 |
522 bool InstanceKlass::verify_code( |
522 bool InstanceKlass::verify_code( |
523 instanceKlassHandle this_oop, bool throw_verifyerror, TRAPS) { |
523 instanceKlassHandle this_k, bool throw_verifyerror, TRAPS) { |
524 // 1) Verify the bytecodes |
524 // 1) Verify the bytecodes |
525 Verifier::Mode mode = |
525 Verifier::Mode mode = |
526 throw_verifyerror ? Verifier::ThrowException : Verifier::NoException; |
526 throw_verifyerror ? Verifier::ThrowException : Verifier::NoException; |
527 return Verifier::verify(this_oop, mode, this_oop->should_verify_class(), CHECK_false); |
527 return Verifier::verify(this_k, mode, this_k->should_verify_class(), CHECK_false); |
528 } |
528 } |
529 |
529 |
530 |
530 |
531 // Used exclusively by the shared spaces dump mechanism to prevent |
531 // Used exclusively by the shared spaces dump mechanism to prevent |
532 // classes mapped into the shared regions in new VMs from appearing linked. |
532 // classes mapped into the shared regions in new VMs from appearing linked. |
538 |
538 |
539 void InstanceKlass::link_class(TRAPS) { |
539 void InstanceKlass::link_class(TRAPS) { |
540 assert(is_loaded(), "must be loaded"); |
540 assert(is_loaded(), "must be loaded"); |
541 if (!is_linked()) { |
541 if (!is_linked()) { |
542 HandleMark hm(THREAD); |
542 HandleMark hm(THREAD); |
543 instanceKlassHandle this_oop(THREAD, this); |
543 instanceKlassHandle this_k(THREAD, this); |
544 link_class_impl(this_oop, true, CHECK); |
544 link_class_impl(this_k, true, CHECK); |
545 } |
545 } |
546 } |
546 } |
547 |
547 |
548 // Called to verify that a class can link during initialization, without |
548 // Called to verify that a class can link during initialization, without |
549 // throwing a VerifyError. |
549 // throwing a VerifyError. |
550 bool InstanceKlass::link_class_or_fail(TRAPS) { |
550 bool InstanceKlass::link_class_or_fail(TRAPS) { |
551 assert(is_loaded(), "must be loaded"); |
551 assert(is_loaded(), "must be loaded"); |
552 if (!is_linked()) { |
552 if (!is_linked()) { |
553 HandleMark hm(THREAD); |
553 HandleMark hm(THREAD); |
554 instanceKlassHandle this_oop(THREAD, this); |
554 instanceKlassHandle this_k(THREAD, this); |
555 link_class_impl(this_oop, false, CHECK_false); |
555 link_class_impl(this_k, false, CHECK_false); |
556 } |
556 } |
557 return is_linked(); |
557 return is_linked(); |
558 } |
558 } |
559 |
559 |
560 bool InstanceKlass::link_class_impl( |
560 bool InstanceKlass::link_class_impl( |
561 instanceKlassHandle this_oop, bool throw_verifyerror, TRAPS) { |
561 instanceKlassHandle this_k, bool throw_verifyerror, TRAPS) { |
562 // check for error state |
562 // check for error state |
563 if (this_oop->is_in_error_state()) { |
563 if (this_k->is_in_error_state()) { |
564 ResourceMark rm(THREAD); |
564 ResourceMark rm(THREAD); |
565 THROW_MSG_(vmSymbols::java_lang_NoClassDefFoundError(), |
565 THROW_MSG_(vmSymbols::java_lang_NoClassDefFoundError(), |
566 this_oop->external_name(), false); |
566 this_k->external_name(), false); |
567 } |
567 } |
568 // return if already verified |
568 // return if already verified |
569 if (this_oop->is_linked()) { |
569 if (this_k->is_linked()) { |
570 return true; |
570 return true; |
571 } |
571 } |
572 |
572 |
573 // Timing |
573 // Timing |
574 // timer handles recursion |
574 // timer handles recursion |
575 assert(THREAD->is_Java_thread(), "non-JavaThread in link_class_impl"); |
575 assert(THREAD->is_Java_thread(), "non-JavaThread in link_class_impl"); |
576 JavaThread* jt = (JavaThread*)THREAD; |
576 JavaThread* jt = (JavaThread*)THREAD; |
577 |
577 |
578 // link super class before linking this class |
578 // link super class before linking this class |
579 instanceKlassHandle super(THREAD, this_oop->super()); |
579 instanceKlassHandle super(THREAD, this_k->super()); |
580 if (super.not_null()) { |
580 if (super.not_null()) { |
581 if (super->is_interface()) { // check if super class is an interface |
581 if (super->is_interface()) { // check if super class is an interface |
582 ResourceMark rm(THREAD); |
582 ResourceMark rm(THREAD); |
583 Exceptions::fthrow( |
583 Exceptions::fthrow( |
584 THREAD_AND_LOCATION, |
584 THREAD_AND_LOCATION, |
585 vmSymbols::java_lang_IncompatibleClassChangeError(), |
585 vmSymbols::java_lang_IncompatibleClassChangeError(), |
586 "class %s has interface %s as super class", |
586 "class %s has interface %s as super class", |
587 this_oop->external_name(), |
587 this_k->external_name(), |
588 super->external_name() |
588 super->external_name() |
589 ); |
589 ); |
590 return false; |
590 return false; |
591 } |
591 } |
592 |
592 |
593 link_class_impl(super, throw_verifyerror, CHECK_false); |
593 link_class_impl(super, throw_verifyerror, CHECK_false); |
594 } |
594 } |
595 |
595 |
596 // link all interfaces implemented by this class before linking this class |
596 // link all interfaces implemented by this class before linking this class |
597 Array<Klass*>* interfaces = this_oop->local_interfaces(); |
597 Array<Klass*>* interfaces = this_k->local_interfaces(); |
598 int num_interfaces = interfaces->length(); |
598 int num_interfaces = interfaces->length(); |
599 for (int index = 0; index < num_interfaces; index++) { |
599 for (int index = 0; index < num_interfaces; index++) { |
600 HandleMark hm(THREAD); |
600 HandleMark hm(THREAD); |
601 instanceKlassHandle ih(THREAD, interfaces->at(index)); |
601 instanceKlassHandle ih(THREAD, interfaces->at(index)); |
602 link_class_impl(ih, throw_verifyerror, CHECK_false); |
602 link_class_impl(ih, throw_verifyerror, CHECK_false); |
603 } |
603 } |
604 |
604 |
605 // in case the class is linked in the process of linking its superclasses |
605 // in case the class is linked in the process of linking its superclasses |
606 if (this_oop->is_linked()) { |
606 if (this_k->is_linked()) { |
607 return true; |
607 return true; |
608 } |
608 } |
609 |
609 |
610 // trace only the link time for this klass that includes |
610 // trace only the link time for this klass that includes |
611 // the verification time |
611 // the verification time |
616 jt->get_thread_stat()->perf_timers_addr(), |
616 jt->get_thread_stat()->perf_timers_addr(), |
617 PerfClassTraceTime::CLASS_LINK); |
617 PerfClassTraceTime::CLASS_LINK); |
618 |
618 |
619 // verification & rewriting |
619 // verification & rewriting |
620 { |
620 { |
621 oop init_lock = this_oop->init_lock(); |
621 oop init_lock = this_k->init_lock(); |
622 ObjectLocker ol(init_lock, THREAD, init_lock != NULL); |
622 ObjectLocker ol(init_lock, THREAD, init_lock != NULL); |
623 // rewritten will have been set if loader constraint error found |
623 // rewritten will have been set if loader constraint error found |
624 // on an earlier link attempt |
624 // on an earlier link attempt |
625 // don't verify or rewrite if already rewritten |
625 // don't verify or rewrite if already rewritten |
626 |
626 |
627 if (!this_oop->is_linked()) { |
627 if (!this_k->is_linked()) { |
628 if (!this_oop->is_rewritten()) { |
628 if (!this_k->is_rewritten()) { |
629 { |
629 { |
630 // Timer includes any side effects of class verification (resolution, |
630 // Timer includes any side effects of class verification (resolution, |
631 // etc), but not recursive entry into verify_code(). |
631 // etc), but not recursive entry into verify_code(). |
632 PerfClassTraceTime timer(ClassLoader::perf_class_verify_time(), |
632 PerfClassTraceTime timer(ClassLoader::perf_class_verify_time(), |
633 ClassLoader::perf_class_verify_selftime(), |
633 ClassLoader::perf_class_verify_selftime(), |
634 ClassLoader::perf_classes_verified(), |
634 ClassLoader::perf_classes_verified(), |
635 jt->get_thread_stat()->perf_recursion_counts_addr(), |
635 jt->get_thread_stat()->perf_recursion_counts_addr(), |
636 jt->get_thread_stat()->perf_timers_addr(), |
636 jt->get_thread_stat()->perf_timers_addr(), |
637 PerfClassTraceTime::CLASS_VERIFY); |
637 PerfClassTraceTime::CLASS_VERIFY); |
638 bool verify_ok = verify_code(this_oop, throw_verifyerror, THREAD); |
638 bool verify_ok = verify_code(this_k, throw_verifyerror, THREAD); |
639 if (!verify_ok) { |
639 if (!verify_ok) { |
640 return false; |
640 return false; |
641 } |
641 } |
642 } |
642 } |
643 |
643 |
644 // Just in case a side-effect of verify linked this class already |
644 // Just in case a side-effect of verify linked this class already |
645 // (which can sometimes happen since the verifier loads classes |
645 // (which can sometimes happen since the verifier loads classes |
646 // using custom class loaders, which are free to initialize things) |
646 // using custom class loaders, which are free to initialize things) |
647 if (this_oop->is_linked()) { |
647 if (this_k->is_linked()) { |
648 return true; |
648 return true; |
649 } |
649 } |
650 |
650 |
651 // also sets rewritten |
651 // also sets rewritten |
652 this_oop->rewrite_class(CHECK_false); |
652 this_k->rewrite_class(CHECK_false); |
653 } |
653 } |
654 |
654 |
655 // relocate jsrs and link methods after they are all rewritten |
655 // relocate jsrs and link methods after they are all rewritten |
656 this_oop->link_methods(CHECK_false); |
656 this_k->link_methods(CHECK_false); |
657 |
657 |
658 // Initialize the vtable and interface table after |
658 // Initialize the vtable and interface table after |
659 // methods have been rewritten since rewrite may |
659 // methods have been rewritten since rewrite may |
660 // fabricate new Method*s. |
660 // fabricate new Method*s. |
661 // also does loader constraint checking |
661 // also does loader constraint checking |
662 if (!this_oop()->is_shared()) { |
662 if (!this_k()->is_shared()) { |
663 ResourceMark rm(THREAD); |
663 ResourceMark rm(THREAD); |
664 this_oop->vtable()->initialize_vtable(true, CHECK_false); |
664 this_k->vtable()->initialize_vtable(true, CHECK_false); |
665 this_oop->itable()->initialize_itable(true, CHECK_false); |
665 this_k->itable()->initialize_itable(true, CHECK_false); |
666 } |
666 } |
667 #ifdef ASSERT |
667 #ifdef ASSERT |
668 else { |
668 else { |
669 ResourceMark rm(THREAD); |
669 ResourceMark rm(THREAD); |
670 this_oop->vtable()->verify(tty, true); |
670 this_k->vtable()->verify(tty, true); |
671 // In case itable verification is ever added. |
671 // In case itable verification is ever added. |
672 // this_oop->itable()->verify(tty, true); |
672 // this_k->itable()->verify(tty, true); |
673 } |
673 } |
674 #endif |
674 #endif |
675 this_oop->set_init_state(linked); |
675 this_k->set_init_state(linked); |
676 if (JvmtiExport::should_post_class_prepare()) { |
676 if (JvmtiExport::should_post_class_prepare()) { |
677 Thread *thread = THREAD; |
677 Thread *thread = THREAD; |
678 assert(thread->is_Java_thread(), "thread->is_Java_thread()"); |
678 assert(thread->is_Java_thread(), "thread->is_Java_thread()"); |
679 JvmtiExport::post_class_prepare((JavaThread *) thread, this_oop()); |
679 JvmtiExport::post_class_prepare((JavaThread *) thread, this_k()); |
680 } |
680 } |
681 } |
681 } |
682 } |
682 } |
683 return true; |
683 return true; |
684 } |
684 } |
687 // Rewrite the byte codes of all of the methods of a class. |
687 // Rewrite the byte codes of all of the methods of a class. |
688 // The rewriter must be called exactly once. Rewriting must happen after |
688 // The rewriter must be called exactly once. Rewriting must happen after |
689 // verification but before the first method of the class is executed. |
689 // verification but before the first method of the class is executed. |
690 void InstanceKlass::rewrite_class(TRAPS) { |
690 void InstanceKlass::rewrite_class(TRAPS) { |
691 assert(is_loaded(), "must be loaded"); |
691 assert(is_loaded(), "must be loaded"); |
692 instanceKlassHandle this_oop(THREAD, this); |
692 instanceKlassHandle this_k(THREAD, this); |
693 if (this_oop->is_rewritten()) { |
693 if (this_k->is_rewritten()) { |
694 assert(this_oop()->is_shared(), "rewriting an unshared class?"); |
694 assert(this_k()->is_shared(), "rewriting an unshared class?"); |
695 return; |
695 return; |
696 } |
696 } |
697 Rewriter::rewrite(this_oop, CHECK); |
697 Rewriter::rewrite(this_k, CHECK); |
698 this_oop->set_rewritten(); |
698 this_k->set_rewritten(); |
699 } |
699 } |
700 |
700 |
701 // Now relocate and link method entry points after class is rewritten. |
701 // Now relocate and link method entry points after class is rewritten. |
702 // This is outside is_rewritten flag. In case of an exception, it can be |
702 // This is outside is_rewritten flag. In case of an exception, it can be |
703 // executed more than once. |
703 // executed more than once. |
727 #endif //ASSERT |
727 #endif //ASSERT |
728 } |
728 } |
729 } |
729 } |
730 |
730 |
731 |
731 |
732 void InstanceKlass::initialize_impl(instanceKlassHandle this_oop, TRAPS) { |
732 void InstanceKlass::initialize_impl(instanceKlassHandle this_k, TRAPS) { |
733 // Make sure klass is linked (verified) before initialization |
733 // Make sure klass is linked (verified) before initialization |
734 // A class could already be verified, since it has been reflected upon. |
734 // A class could already be verified, since it has been reflected upon. |
735 this_oop->link_class(CHECK); |
735 this_k->link_class(CHECK); |
736 |
736 |
737 DTRACE_CLASSINIT_PROBE(required, InstanceKlass::cast(this_oop()), -1); |
737 DTRACE_CLASSINIT_PROBE(required, InstanceKlass::cast(this_k()), -1); |
738 |
738 |
739 bool wait = false; |
739 bool wait = false; |
740 |
740 |
741 // refer to the JVM book page 47 for description of steps |
741 // refer to the JVM book page 47 for description of steps |
742 // Step 1 |
742 // Step 1 |
743 { |
743 { |
744 oop init_lock = this_oop->init_lock(); |
744 oop init_lock = this_k->init_lock(); |
745 ObjectLocker ol(init_lock, THREAD, init_lock != NULL); |
745 ObjectLocker ol(init_lock, THREAD, init_lock != NULL); |
746 |
746 |
747 Thread *self = THREAD; // it's passed the current thread |
747 Thread *self = THREAD; // it's passed the current thread |
748 |
748 |
749 // Step 2 |
749 // Step 2 |
750 // If we were to use wait() instead of waitInterruptibly() then |
750 // If we were to use wait() instead of waitInterruptibly() then |
751 // we might end up throwing IE from link/symbol resolution sites |
751 // we might end up throwing IE from link/symbol resolution sites |
752 // that aren't expected to throw. This would wreak havoc. See 6320309. |
752 // that aren't expected to throw. This would wreak havoc. See 6320309. |
753 while(this_oop->is_being_initialized() && !this_oop->is_reentrant_initialization(self)) { |
753 while(this_k->is_being_initialized() && !this_k->is_reentrant_initialization(self)) { |
754 wait = true; |
754 wait = true; |
755 ol.waitUninterruptibly(CHECK); |
755 ol.waitUninterruptibly(CHECK); |
756 } |
756 } |
757 |
757 |
758 // Step 3 |
758 // Step 3 |
759 if (this_oop->is_being_initialized() && this_oop->is_reentrant_initialization(self)) { |
759 if (this_k->is_being_initialized() && this_k->is_reentrant_initialization(self)) { |
760 DTRACE_CLASSINIT_PROBE_WAIT(recursive, InstanceKlass::cast(this_oop()), -1,wait); |
760 DTRACE_CLASSINIT_PROBE_WAIT(recursive, InstanceKlass::cast(this_k()), -1,wait); |
761 return; |
761 return; |
762 } |
762 } |
763 |
763 |
764 // Step 4 |
764 // Step 4 |
765 if (this_oop->is_initialized()) { |
765 if (this_k->is_initialized()) { |
766 DTRACE_CLASSINIT_PROBE_WAIT(concurrent, InstanceKlass::cast(this_oop()), -1,wait); |
766 DTRACE_CLASSINIT_PROBE_WAIT(concurrent, InstanceKlass::cast(this_k()), -1,wait); |
767 return; |
767 return; |
768 } |
768 } |
769 |
769 |
770 // Step 5 |
770 // Step 5 |
771 if (this_oop->is_in_error_state()) { |
771 if (this_k->is_in_error_state()) { |
772 DTRACE_CLASSINIT_PROBE_WAIT(erroneous, InstanceKlass::cast(this_oop()), -1,wait); |
772 DTRACE_CLASSINIT_PROBE_WAIT(erroneous, InstanceKlass::cast(this_k()), -1,wait); |
773 ResourceMark rm(THREAD); |
773 ResourceMark rm(THREAD); |
774 const char* desc = "Could not initialize class "; |
774 const char* desc = "Could not initialize class "; |
775 const char* className = this_oop->external_name(); |
775 const char* className = this_k->external_name(); |
776 size_t msglen = strlen(desc) + strlen(className) + 1; |
776 size_t msglen = strlen(desc) + strlen(className) + 1; |
777 char* message = NEW_RESOURCE_ARRAY(char, msglen); |
777 char* message = NEW_RESOURCE_ARRAY(char, msglen); |
778 if (NULL == message) { |
778 if (NULL == message) { |
779 // Out of memory: can't create detailed error message |
779 // Out of memory: can't create detailed error message |
780 THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), className); |
780 THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), className); |
783 THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), message); |
783 THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), message); |
784 } |
784 } |
785 } |
785 } |
786 |
786 |
787 // Step 6 |
787 // Step 6 |
788 this_oop->set_init_state(being_initialized); |
788 this_k->set_init_state(being_initialized); |
789 this_oop->set_init_thread(self); |
789 this_k->set_init_thread(self); |
790 } |
790 } |
791 |
791 |
792 // Step 7 |
792 // Step 7 |
793 Klass* super_klass = this_oop->super(); |
793 Klass* super_klass = this_k->super(); |
794 if (super_klass != NULL && !this_oop->is_interface() && super_klass->should_be_initialized()) { |
794 if (super_klass != NULL && !this_k->is_interface() && super_klass->should_be_initialized()) { |
795 super_klass->initialize(THREAD); |
795 super_klass->initialize(THREAD); |
796 |
796 |
797 if (HAS_PENDING_EXCEPTION) { |
797 if (HAS_PENDING_EXCEPTION) { |
798 Handle e(THREAD, PENDING_EXCEPTION); |
798 Handle e(THREAD, PENDING_EXCEPTION); |
799 CLEAR_PENDING_EXCEPTION; |
799 CLEAR_PENDING_EXCEPTION; |
800 { |
800 { |
801 EXCEPTION_MARK; |
801 EXCEPTION_MARK; |
802 this_oop->set_initialization_state_and_notify(initialization_error, THREAD); // Locks object, set state, and notify all waiting threads |
802 this_k->set_initialization_state_and_notify(initialization_error, THREAD); // Locks object, set state, and notify all waiting threads |
803 CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, superclass initialization error is thrown below |
803 CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, superclass initialization error is thrown below |
804 } |
804 } |
805 DTRACE_CLASSINIT_PROBE_WAIT(super__failed, InstanceKlass::cast(this_oop()), -1,wait); |
805 DTRACE_CLASSINIT_PROBE_WAIT(super__failed, InstanceKlass::cast(this_k()), -1,wait); |
806 THROW_OOP(e()); |
806 THROW_OOP(e()); |
807 } |
807 } |
808 } |
808 } |
809 |
809 |
810 if (this_oop->has_default_methods()) { |
810 if (this_k->has_default_methods()) { |
811 // Step 7.5: initialize any interfaces which have default methods |
811 // Step 7.5: initialize any interfaces which have default methods |
812 for (int i = 0; i < this_oop->local_interfaces()->length(); ++i) { |
812 for (int i = 0; i < this_k->local_interfaces()->length(); ++i) { |
813 Klass* iface = this_oop->local_interfaces()->at(i); |
813 Klass* iface = this_k->local_interfaces()->at(i); |
814 InstanceKlass* ik = InstanceKlass::cast(iface); |
814 InstanceKlass* ik = InstanceKlass::cast(iface); |
815 if (ik->has_default_methods() && ik->should_be_initialized()) { |
815 if (ik->has_default_methods() && ik->should_be_initialized()) { |
816 ik->initialize(THREAD); |
816 ik->initialize(THREAD); |
817 |
817 |
818 if (HAS_PENDING_EXCEPTION) { |
818 if (HAS_PENDING_EXCEPTION) { |
819 Handle e(THREAD, PENDING_EXCEPTION); |
819 Handle e(THREAD, PENDING_EXCEPTION); |
820 CLEAR_PENDING_EXCEPTION; |
820 CLEAR_PENDING_EXCEPTION; |
821 { |
821 { |
822 EXCEPTION_MARK; |
822 EXCEPTION_MARK; |
823 // Locks object, set state, and notify all waiting threads |
823 // Locks object, set state, and notify all waiting threads |
824 this_oop->set_initialization_state_and_notify( |
824 this_k->set_initialization_state_and_notify( |
825 initialization_error, THREAD); |
825 initialization_error, THREAD); |
826 |
826 |
827 // ignore any exception thrown, superclass initialization error is |
827 // ignore any exception thrown, superclass initialization error is |
828 // thrown below |
828 // thrown below |
829 CLEAR_PENDING_EXCEPTION; |
829 CLEAR_PENDING_EXCEPTION; |
830 } |
830 } |
831 DTRACE_CLASSINIT_PROBE_WAIT( |
831 DTRACE_CLASSINIT_PROBE_WAIT( |
832 super__failed, InstanceKlass::cast(this_oop()), -1, wait); |
832 super__failed, InstanceKlass::cast(this_k()), -1, wait); |
833 THROW_OOP(e()); |
833 THROW_OOP(e()); |
834 } |
834 } |
835 } |
835 } |
836 } |
836 } |
837 } |
837 } |
838 |
838 |
839 // Step 8 |
839 // Step 8 |
840 { |
840 { |
841 assert(THREAD->is_Java_thread(), "non-JavaThread in initialize_impl"); |
841 assert(THREAD->is_Java_thread(), "non-JavaThread in initialize_impl"); |
842 JavaThread* jt = (JavaThread*)THREAD; |
842 JavaThread* jt = (JavaThread*)THREAD; |
843 DTRACE_CLASSINIT_PROBE_WAIT(clinit, InstanceKlass::cast(this_oop()), -1,wait); |
843 DTRACE_CLASSINIT_PROBE_WAIT(clinit, InstanceKlass::cast(this_k()), -1,wait); |
844 // Timer includes any side effects of class initialization (resolution, |
844 // Timer includes any side effects of class initialization (resolution, |
845 // etc), but not recursive entry into call_class_initializer(). |
845 // etc), but not recursive entry into call_class_initializer(). |
846 PerfClassTraceTime timer(ClassLoader::perf_class_init_time(), |
846 PerfClassTraceTime timer(ClassLoader::perf_class_init_time(), |
847 ClassLoader::perf_class_init_selftime(), |
847 ClassLoader::perf_class_init_selftime(), |
848 ClassLoader::perf_classes_inited(), |
848 ClassLoader::perf_classes_inited(), |
849 jt->get_thread_stat()->perf_recursion_counts_addr(), |
849 jt->get_thread_stat()->perf_recursion_counts_addr(), |
850 jt->get_thread_stat()->perf_timers_addr(), |
850 jt->get_thread_stat()->perf_timers_addr(), |
851 PerfClassTraceTime::CLASS_CLINIT); |
851 PerfClassTraceTime::CLASS_CLINIT); |
852 this_oop->call_class_initializer(THREAD); |
852 this_k->call_class_initializer(THREAD); |
853 } |
853 } |
854 |
854 |
855 // Step 9 |
855 // Step 9 |
856 if (!HAS_PENDING_EXCEPTION) { |
856 if (!HAS_PENDING_EXCEPTION) { |
857 this_oop->set_initialization_state_and_notify(fully_initialized, CHECK); |
857 this_k->set_initialization_state_and_notify(fully_initialized, CHECK); |
858 { ResourceMark rm(THREAD); |
858 { ResourceMark rm(THREAD); |
859 debug_only(this_oop->vtable()->verify(tty, true);) |
859 debug_only(this_k->vtable()->verify(tty, true);) |
860 } |
860 } |
861 } |
861 } |
862 else { |
862 else { |
863 // Step 10 and 11 |
863 // Step 10 and 11 |
864 Handle e(THREAD, PENDING_EXCEPTION); |
864 Handle e(THREAD, PENDING_EXCEPTION); |
866 // JVMTI has already reported the pending exception |
866 // JVMTI has already reported the pending exception |
867 // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError |
867 // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError |
868 JvmtiExport::clear_detected_exception((JavaThread*)THREAD); |
868 JvmtiExport::clear_detected_exception((JavaThread*)THREAD); |
869 { |
869 { |
870 EXCEPTION_MARK; |
870 EXCEPTION_MARK; |
871 this_oop->set_initialization_state_and_notify(initialization_error, THREAD); |
871 this_k->set_initialization_state_and_notify(initialization_error, THREAD); |
872 CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, class initialization error is thrown below |
872 CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, class initialization error is thrown below |
873 // JVMTI has already reported the pending exception |
873 // JVMTI has already reported the pending exception |
874 // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError |
874 // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError |
875 JvmtiExport::clear_detected_exception((JavaThread*)THREAD); |
875 JvmtiExport::clear_detected_exception((JavaThread*)THREAD); |
876 } |
876 } |
877 DTRACE_CLASSINIT_PROBE_WAIT(error, InstanceKlass::cast(this_oop()), -1,wait); |
877 DTRACE_CLASSINIT_PROBE_WAIT(error, InstanceKlass::cast(this_k()), -1,wait); |
878 if (e->is_a(SystemDictionary::Error_klass())) { |
878 if (e->is_a(SystemDictionary::Error_klass())) { |
879 THROW_OOP(e()); |
879 THROW_OOP(e()); |
880 } else { |
880 } else { |
881 JavaCallArguments args(e); |
881 JavaCallArguments args(e); |
882 THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(), |
882 THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(), |
883 vmSymbols::throwable_void_signature(), |
883 vmSymbols::throwable_void_signature(), |
884 &args); |
884 &args); |
885 } |
885 } |
886 } |
886 } |
887 DTRACE_CLASSINIT_PROBE_WAIT(end, InstanceKlass::cast(this_oop()), -1,wait); |
887 DTRACE_CLASSINIT_PROBE_WAIT(end, InstanceKlass::cast(this_k()), -1,wait); |
888 } |
888 } |
889 |
889 |
890 |
890 |
891 // Note: implementation moved to static method to expose the this pointer. |
891 // Note: implementation moved to static method to expose the this pointer. |
892 void InstanceKlass::set_initialization_state_and_notify(ClassState state, TRAPS) { |
892 void InstanceKlass::set_initialization_state_and_notify(ClassState state, TRAPS) { |
893 instanceKlassHandle kh(THREAD, this); |
893 instanceKlassHandle kh(THREAD, this); |
894 set_initialization_state_and_notify_impl(kh, state, CHECK); |
894 set_initialization_state_and_notify_impl(kh, state, CHECK); |
895 } |
895 } |
896 |
896 |
897 void InstanceKlass::set_initialization_state_and_notify_impl(instanceKlassHandle this_oop, ClassState state, TRAPS) { |
897 void InstanceKlass::set_initialization_state_and_notify_impl(instanceKlassHandle this_k, ClassState state, TRAPS) { |
898 oop init_lock = this_oop->init_lock(); |
898 oop init_lock = this_k->init_lock(); |
899 ObjectLocker ol(init_lock, THREAD, init_lock != NULL); |
899 ObjectLocker ol(init_lock, THREAD, init_lock != NULL); |
900 this_oop->set_init_state(state); |
900 this_k->set_init_state(state); |
901 this_oop->fence_and_clear_init_lock(); |
901 this_k->fence_and_clear_init_lock(); |
902 ol.notify_all(CHECK); |
902 ol.notify_all(CHECK); |
903 } |
903 } |
904 |
904 |
905 // The embedded _implementor field can only record one implementor. |
905 // The embedded _implementor field can only record one implementor. |
906 // When there are more than one implementors, the _implementor field |
906 // When there are more than one implementors, the _implementor field |
1081 : vmSymbols::java_lang_IllegalAccessException(), external_name()); |
1080 : vmSymbols::java_lang_IllegalAccessException(), external_name()); |
1082 } |
1081 } |
1083 } |
1082 } |
1084 |
1083 |
1085 Klass* InstanceKlass::array_klass_impl(bool or_null, int n, TRAPS) { |
1084 Klass* InstanceKlass::array_klass_impl(bool or_null, int n, TRAPS) { |
1086 instanceKlassHandle this_oop(THREAD, this); |
1085 instanceKlassHandle this_k(THREAD, this); |
1087 return array_klass_impl(this_oop, or_null, n, THREAD); |
1086 return array_klass_impl(this_k, or_null, n, THREAD); |
1088 } |
1087 } |
1089 |
1088 |
1090 Klass* InstanceKlass::array_klass_impl(instanceKlassHandle this_oop, bool or_null, int n, TRAPS) { |
1089 Klass* InstanceKlass::array_klass_impl(instanceKlassHandle this_k, bool or_null, int n, TRAPS) { |
1091 if (this_oop->array_klasses() == NULL) { |
1090 if (this_k->array_klasses() == NULL) { |
1092 if (or_null) return NULL; |
1091 if (or_null) return NULL; |
1093 |
1092 |
1094 ResourceMark rm; |
1093 ResourceMark rm; |
1095 JavaThread *jt = (JavaThread *)THREAD; |
1094 JavaThread *jt = (JavaThread *)THREAD; |
1096 { |
1095 { |
1097 // Atomic creation of array_klasses |
1096 // Atomic creation of array_klasses |
1098 MutexLocker mc(Compile_lock, THREAD); // for vtables |
1097 MutexLocker mc(Compile_lock, THREAD); // for vtables |
1099 MutexLocker ma(MultiArray_lock, THREAD); |
1098 MutexLocker ma(MultiArray_lock, THREAD); |
1100 |
1099 |
1101 // Check if update has already taken place |
1100 // Check if update has already taken place |
1102 if (this_oop->array_klasses() == NULL) { |
1101 if (this_k->array_klasses() == NULL) { |
1103 Klass* k = ObjArrayKlass::allocate_objArray_klass(this_oop->class_loader_data(), 1, this_oop, CHECK_NULL); |
1102 Klass* k = ObjArrayKlass::allocate_objArray_klass(this_k->class_loader_data(), 1, this_k, CHECK_NULL); |
1104 this_oop->set_array_klasses(k); |
1103 this_k->set_array_klasses(k); |
1105 } |
1104 } |
1106 } |
1105 } |
1107 } |
1106 } |
1108 // _this will always be set at this point |
1107 // _this will always be set at this point |
1109 ObjArrayKlass* oak = (ObjArrayKlass*)this_oop->array_klasses(); |
1108 ObjArrayKlass* oak = (ObjArrayKlass*)this_k->array_klasses(); |
1110 if (or_null) { |
1109 if (or_null) { |
1111 return oak->array_klass_or_null(n); |
1110 return oak->array_klass_or_null(n); |
1112 } |
1111 } |
1113 return oak->array_klass(n, CHECK_NULL); |
1112 return oak->array_klass(n, CHECK_NULL); |
1114 } |
1113 } |
1131 return clinit; |
1130 return clinit; |
1132 } |
1131 } |
1133 return NULL; |
1132 return NULL; |
1134 } |
1133 } |
1135 |
1134 |
1136 void InstanceKlass::call_class_initializer_impl(instanceKlassHandle this_oop, TRAPS) { |
1135 void InstanceKlass::call_class_initializer_impl(instanceKlassHandle this_k, TRAPS) { |
1137 if (ReplayCompiles && |
1136 if (ReplayCompiles && |
1138 (ReplaySuppressInitializers == 1 || |
1137 (ReplaySuppressInitializers == 1 || |
1139 ReplaySuppressInitializers >= 2 && this_oop->class_loader() != NULL)) { |
1138 ReplaySuppressInitializers >= 2 && this_k->class_loader() != NULL)) { |
1140 // Hide the existence of the initializer for the purpose of replaying the compile |
1139 // Hide the existence of the initializer for the purpose of replaying the compile |
1141 return; |
1140 return; |
1142 } |
1141 } |
1143 |
1142 |
1144 methodHandle h_method(THREAD, this_oop->class_initializer()); |
1143 methodHandle h_method(THREAD, this_k->class_initializer()); |
1145 assert(!this_oop->is_initialized(), "we cannot initialize twice"); |
1144 assert(!this_k->is_initialized(), "we cannot initialize twice"); |
1146 if (TraceClassInitialization) { |
1145 if (TraceClassInitialization) { |
1147 tty->print("%d Initializing ", call_class_initializer_impl_counter++); |
1146 tty->print("%d Initializing ", call_class_initializer_impl_counter++); |
1148 this_oop->name()->print_value(); |
1147 this_k->name()->print_value(); |
1149 tty->print_cr("%s (" INTPTR_FORMAT ")", h_method() == NULL ? "(no method)" : "", (address)this_oop()); |
1148 tty->print_cr("%s (" INTPTR_FORMAT ")", h_method() == NULL ? "(no method)" : "", (address)this_k()); |
1150 } |
1149 } |
1151 if (h_method() != NULL) { |
1150 if (h_method() != NULL) { |
1152 JavaCallArguments args; // No arguments |
1151 JavaCallArguments args; // No arguments |
1153 JavaValue result(T_VOID); |
1152 JavaValue result(T_VOID); |
1154 JavaCalls::call(&result, h_method, &args, CHECK); // Static call (no args) |
1153 JavaCalls::call(&result, h_method, &args, CHECK); // Static call (no args) |