641 |
641 |
642 // abort if someone beat us to the initialization |
642 // abort if someone beat us to the initialization |
643 if (!is_not_initialized()) return; // note: not equivalent to is_initialized() |
643 if (!is_not_initialized()) return; // note: not equivalent to is_initialized() |
644 |
644 |
645 ClassState old_state = init_state(); |
645 ClassState old_state = init_state(); |
646 link_class_impl(true, THREAD); |
646 link_class_impl(THREAD); |
647 if (HAS_PENDING_EXCEPTION) { |
647 if (HAS_PENDING_EXCEPTION) { |
648 CLEAR_PENDING_EXCEPTION; |
648 CLEAR_PENDING_EXCEPTION; |
649 // Abort if linking the class throws an exception. |
649 // Abort if linking the class throws an exception. |
650 |
650 |
651 // Use a test to avoid redundantly resetting the state if there's |
651 // Use a test to avoid redundantly resetting the state if there's |
679 assert(is_initialized(), "sanity check"); |
679 assert(is_initialized(), "sanity check"); |
680 } |
680 } |
681 } |
681 } |
682 |
682 |
683 |
683 |
684 bool InstanceKlass::verify_code(bool throw_verifyerror, TRAPS) { |
684 bool InstanceKlass::verify_code(TRAPS) { |
685 // 1) Verify the bytecodes |
685 // 1) Verify the bytecodes |
686 Verifier::Mode mode = |
686 return Verifier::verify(this, should_verify_class(), THREAD); |
687 throw_verifyerror ? Verifier::ThrowException : Verifier::NoException; |
|
688 return Verifier::verify(this, mode, should_verify_class(), THREAD); |
|
689 } |
687 } |
690 |
688 |
691 |
689 |
692 // Used exclusively by the shared spaces dump mechanism to prevent |
690 // Used exclusively by the shared spaces dump mechanism to prevent |
693 // classes mapped into the shared regions in new VMs from appearing linked. |
691 // classes mapped into the shared regions in new VMs from appearing linked. |
698 } |
696 } |
699 |
697 |
700 void InstanceKlass::link_class(TRAPS) { |
698 void InstanceKlass::link_class(TRAPS) { |
701 assert(is_loaded(), "must be loaded"); |
699 assert(is_loaded(), "must be loaded"); |
702 if (!is_linked()) { |
700 if (!is_linked()) { |
703 link_class_impl(true, CHECK); |
701 link_class_impl(CHECK); |
704 } |
702 } |
705 } |
703 } |
706 |
704 |
707 // Called to verify that a class can link during initialization, without |
705 // Called to verify that a class can link during initialization, without |
708 // throwing a VerifyError. |
706 // throwing a VerifyError. |
709 bool InstanceKlass::link_class_or_fail(TRAPS) { |
707 bool InstanceKlass::link_class_or_fail(TRAPS) { |
710 assert(is_loaded(), "must be loaded"); |
708 assert(is_loaded(), "must be loaded"); |
711 if (!is_linked()) { |
709 if (!is_linked()) { |
712 link_class_impl(false, CHECK_false); |
710 link_class_impl(CHECK_false); |
713 } |
711 } |
714 return is_linked(); |
712 return is_linked(); |
715 } |
713 } |
716 |
714 |
717 bool InstanceKlass::link_class_impl(bool throw_verifyerror, TRAPS) { |
715 bool InstanceKlass::link_class_impl(TRAPS) { |
718 if (DumpSharedSpaces && is_in_error_state()) { |
716 if (DumpSharedSpaces && is_in_error_state()) { |
719 // This is for CDS dumping phase only -- we use the in_error_state to indicate that |
717 // This is for CDS dumping phase only -- we use the in_error_state to indicate that |
720 // the class has failed verification. Throwing the NoClassDefFoundError here is just |
718 // the class has failed verification. Throwing the NoClassDefFoundError here is just |
721 // a convenient way to stop repeat attempts to verify the same (bad) class. |
719 // a convenient way to stop repeat attempts to verify the same (bad) class. |
722 // |
720 // |
754 ); |
752 ); |
755 return false; |
753 return false; |
756 } |
754 } |
757 |
755 |
758 InstanceKlass* ik_super = InstanceKlass::cast(super_klass); |
756 InstanceKlass* ik_super = InstanceKlass::cast(super_klass); |
759 ik_super->link_class_impl(throw_verifyerror, CHECK_false); |
757 ik_super->link_class_impl(CHECK_false); |
760 } |
758 } |
761 |
759 |
762 // link all interfaces implemented by this class before linking this class |
760 // link all interfaces implemented by this class before linking this class |
763 Array<InstanceKlass*>* interfaces = local_interfaces(); |
761 Array<InstanceKlass*>* interfaces = local_interfaces(); |
764 int num_interfaces = interfaces->length(); |
762 int num_interfaces = interfaces->length(); |
765 for (int index = 0; index < num_interfaces; index++) { |
763 for (int index = 0; index < num_interfaces; index++) { |
766 InstanceKlass* interk = interfaces->at(index); |
764 InstanceKlass* interk = interfaces->at(index); |
767 interk->link_class_impl(throw_verifyerror, CHECK_false); |
765 interk->link_class_impl(CHECK_false); |
768 } |
766 } |
769 |
767 |
770 // in case the class is linked in the process of linking its superclasses |
768 // in case the class is linked in the process of linking its superclasses |
771 if (is_linked()) { |
769 if (is_linked()) { |
772 return true; |
770 return true; |