657 } 658 Rewriter::rewrite(this_k, CHECK); 659 this_k->set_rewritten(); 660 } 661 662 // Now relocate and link method entry points after class is rewritten. 663 // This is outside is_rewritten flag. In case of an exception, it can be 664 // executed more than once. 665 void InstanceKlass::link_methods(TRAPS) { 666 int len = methods()->length(); 667 for (int i = len-1; i >= 0; i--) { 668 methodHandle m(THREAD, methods()->at(i)); 669 670 // Set up method entry points for compiler and interpreter . 671 m->link_method(m, CHECK); 672 } 673 } 674 675 // Eagerly initialize superinterfaces that declare default methods (concrete instance: any access) 676 void InstanceKlass::initialize_super_interfaces(instanceKlassHandle this_k, TRAPS) { 677 assert (this_k->has_default_methods(), "caller should have checked this"); 678 for (int i = 0; i < this_k->local_interfaces()->length(); ++i) { 679 Klass* iface = this_k->local_interfaces()->at(i); 680 InstanceKlass* ik = InstanceKlass::cast(iface); 681 682 // Initialization is depth first search ie. we start with top of the inheritance tree 683 // has_default_methods drives searching superinterfaces since it 684 // means has_default_methods in its superinterface hierarchy 685 if (ik->has_default_methods()) { 686 ik->initialize_super_interfaces(ik, CHECK); 687 } 688 689 // Only initialize() interfaces that "declare" concrete methods. 690 if (ik->should_be_initialized() && ik->declares_default_methods()) { 691 ik->initialize(CHECK); 692 } 693 } 694 } 695 696 void InstanceKlass::initialize_impl(instanceKlassHandle this_k, TRAPS) { 697 // Make sure klass is linked (verified) before initialization 698 // A class could already be verified, since it has been reflected upon. 699 this_k->link_class(CHECK); 700 701 DTRACE_CLASSINIT_PROBE(required, this_k(), -1); 702 703 bool wait = false; 704 705 // refer to the JVM book page 47 for description of steps 706 // Step 1 707 { 708 oop init_lock = this_k->init_lock(); 709 ObjectLocker ol(init_lock, THREAD, init_lock != NULL); 710 744 THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), className); 745 } else { 746 jio_snprintf(message, msglen, "%s%s", desc, className); 747 THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), message); 748 } 749 } 750 751 // Step 6 752 this_k->set_init_state(being_initialized); 753 this_k->set_init_thread(self); 754 } 755 756 // Step 7 757 // Next, if C is a class rather than an interface, initialize it's super class and super 758 // interfaces. 759 if (!this_k->is_interface()) { 760 Klass* super_klass = this_k->super(); 761 if (super_klass != NULL && super_klass->should_be_initialized()) { 762 super_klass->initialize(THREAD); 763 } 764 // If C implements any interfaces that declares a non-abstract, non-static method, 765 // the initialization of C triggers initialization of its super interfaces. 766 // Only need to recurse if has_default_methods which includes declaring and 767 // inheriting default methods 768 if (!HAS_PENDING_EXCEPTION && this_k->has_default_methods()) { 769 this_k->initialize_super_interfaces(this_k, THREAD); 770 } 771 772 // If any exceptions, complete abruptly, throwing the same exception as above. 773 if (HAS_PENDING_EXCEPTION) { 774 Handle e(THREAD, PENDING_EXCEPTION); 775 CLEAR_PENDING_EXCEPTION; 776 { 777 EXCEPTION_MARK; 778 // Locks object, set state, and notify all waiting threads 779 this_k->set_initialization_state_and_notify(initialization_error, THREAD); 780 CLEAR_PENDING_EXCEPTION; 781 } 782 DTRACE_CLASSINIT_PROBE_WAIT(super__failed, this_k(), -1,wait); 783 THROW_OOP(e()); 784 } 785 } 786 787 788 // Step 8 | 657 } 658 Rewriter::rewrite(this_k, CHECK); 659 this_k->set_rewritten(); 660 } 661 662 // Now relocate and link method entry points after class is rewritten. 663 // This is outside is_rewritten flag. In case of an exception, it can be 664 // executed more than once. 665 void InstanceKlass::link_methods(TRAPS) { 666 int len = methods()->length(); 667 for (int i = len-1; i >= 0; i--) { 668 methodHandle m(THREAD, methods()->at(i)); 669 670 // Set up method entry points for compiler and interpreter . 671 m->link_method(m, CHECK); 672 } 673 } 674 675 // Eagerly initialize superinterfaces that declare default methods (concrete instance: any access) 676 void InstanceKlass::initialize_super_interfaces(instanceKlassHandle this_k, TRAPS) { 677 assert (this_k->has_nonstatic_concrete_methods(), "caller should have checked this"); 678 for (int i = 0; i < this_k->local_interfaces()->length(); ++i) { 679 Klass* iface = this_k->local_interfaces()->at(i); 680 InstanceKlass* ik = InstanceKlass::cast(iface); 681 682 // Initialization is depth first search ie. we start with top of the inheritance tree 683 // has_nonstatic_concrete_methods drives searching superinterfaces since it 684 // means has_nonstatic_concrete_methods in its superinterface hierarchy 685 if (ik->has_nonstatic_concrete_methods()) { 686 ik->initialize_super_interfaces(ik, CHECK); 687 } 688 689 // Only initialize() interfaces that "declare" concrete methods. 690 if (ik->should_be_initialized() && ik->declares_nonstatic_concrete_methods()) { 691 ik->initialize(CHECK); 692 } 693 } 694 } 695 696 void InstanceKlass::initialize_impl(instanceKlassHandle this_k, TRAPS) { 697 // Make sure klass is linked (verified) before initialization 698 // A class could already be verified, since it has been reflected upon. 699 this_k->link_class(CHECK); 700 701 DTRACE_CLASSINIT_PROBE(required, this_k(), -1); 702 703 bool wait = false; 704 705 // refer to the JVM book page 47 for description of steps 706 // Step 1 707 { 708 oop init_lock = this_k->init_lock(); 709 ObjectLocker ol(init_lock, THREAD, init_lock != NULL); 710 744 THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), className); 745 } else { 746 jio_snprintf(message, msglen, "%s%s", desc, className); 747 THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), message); 748 } 749 } 750 751 // Step 6 752 this_k->set_init_state(being_initialized); 753 this_k->set_init_thread(self); 754 } 755 756 // Step 7 757 // Next, if C is a class rather than an interface, initialize it's super class and super 758 // interfaces. 759 if (!this_k->is_interface()) { 760 Klass* super_klass = this_k->super(); 761 if (super_klass != NULL && super_klass->should_be_initialized()) { 762 super_klass->initialize(THREAD); 763 } 764 // If C implements any interface that declares a non-static, concrete method, 765 // the initialization of C triggers initialization of its super interfaces. 766 // Only need to recurse if has_nonstatic_concrete_methods which includes declaring and 767 // having a superinterface that declares, non-static, concrete methods 768 if (!HAS_PENDING_EXCEPTION && this_k->has_nonstatic_concrete_methods()) { 769 this_k->initialize_super_interfaces(this_k, THREAD); 770 } 771 772 // If any exceptions, complete abruptly, throwing the same exception as above. 773 if (HAS_PENDING_EXCEPTION) { 774 Handle e(THREAD, PENDING_EXCEPTION); 775 CLEAR_PENDING_EXCEPTION; 776 { 777 EXCEPTION_MARK; 778 // Locks object, set state, and notify all waiting threads 779 this_k->set_initialization_state_and_notify(initialization_error, THREAD); 780 CLEAR_PENDING_EXCEPTION; 781 } 782 DTRACE_CLASSINIT_PROBE_WAIT(super__failed, this_k(), -1,wait); 783 THROW_OOP(e()); 784 } 785 } 786 787 788 // Step 8 |