hotspot/src/share/vm/oops/instanceKlass.cpp
changeset 41293 871b2f487dc0
parent 41183 207b92e69457
child 41669 2091069b6851
equal deleted inserted replaced
41291:e9a1638b8cea 41293:871b2f487dc0
   515   return is_linked();
   515   return is_linked();
   516 }
   516 }
   517 
   517 
   518 bool InstanceKlass::link_class_impl(
   518 bool InstanceKlass::link_class_impl(
   519     instanceKlassHandle this_k, bool throw_verifyerror, TRAPS) {
   519     instanceKlassHandle this_k, bool throw_verifyerror, TRAPS) {
   520   // check for error state
   520   // check for error state.
       
   521   // This is checking for the wrong state.  If the state is initialization_error,
       
   522   // then this class *was* linked.  The CDS code does a try_link_class and uses
       
   523   // initialization_error to mark classes to not include in the archive during
       
   524   // DumpSharedSpaces.  This should be removed when the CDS bug is fixed.
   521   if (this_k->is_in_error_state()) {
   525   if (this_k->is_in_error_state()) {
   522     ResourceMark rm(THREAD);
   526     ResourceMark rm(THREAD);
   523     THROW_MSG_(vmSymbols::java_lang_NoClassDefFoundError(),
   527     THROW_MSG_(vmSymbols::java_lang_NoClassDefFoundError(),
   524                this_k->external_name(), false);
   528                this_k->external_name(), false);
   525   }
   529   }
   668   }
   672   }
   669 }
   673 }
   670 
   674 
   671 // Eagerly initialize superinterfaces that declare default methods (concrete instance: any access)
   675 // Eagerly initialize superinterfaces that declare default methods (concrete instance: any access)
   672 void InstanceKlass::initialize_super_interfaces(instanceKlassHandle this_k, TRAPS) {
   676 void InstanceKlass::initialize_super_interfaces(instanceKlassHandle this_k, TRAPS) {
   673   if (this_k->has_default_methods()) {
   677   assert (this_k->has_default_methods(), "caller should have checked this");
   674     for (int i = 0; i < this_k->local_interfaces()->length(); ++i) {
   678   for (int i = 0; i < this_k->local_interfaces()->length(); ++i) {
   675       Klass* iface = this_k->local_interfaces()->at(i);
   679     Klass* iface = this_k->local_interfaces()->at(i);
   676       InstanceKlass* ik = InstanceKlass::cast(iface);
   680     InstanceKlass* ik = InstanceKlass::cast(iface);
   677       if (ik->should_be_initialized()) {
   681 
   678         if (ik->has_default_methods()) {
   682     // Initialization is depth first search ie. we start with top of the inheritance tree
   679           ik->initialize_super_interfaces(ik, THREAD);
   683     // has_default_methods drives searching superinterfaces since it
   680         }
   684     // means has_default_methods in its superinterface hierarchy
   681         // Only initialize() interfaces that "declare" concrete methods.
   685     if (ik->has_default_methods()) {
   682         // has_default_methods drives searching superinterfaces since it
   686       ik->initialize_super_interfaces(ik, CHECK);
   683         // means has_default_methods in its superinterface hierarchy
   687     }
   684         if (!HAS_PENDING_EXCEPTION && ik->declares_default_methods()) {
   688 
   685           ik->initialize(THREAD);
   689     // Only initialize() interfaces that "declare" concrete methods.
   686         }
   690     if (ik->should_be_initialized() && ik->declares_default_methods()) {
   687         if (HAS_PENDING_EXCEPTION) {
   691       ik->initialize(CHECK);
   688           Handle e(THREAD, PENDING_EXCEPTION);
       
   689           CLEAR_PENDING_EXCEPTION;
       
   690           {
       
   691             EXCEPTION_MARK;
       
   692             // Locks object, set state, and notify all waiting threads
       
   693             this_k->set_initialization_state_and_notify(
       
   694                 initialization_error, THREAD);
       
   695 
       
   696             // ignore any exception thrown, superclass initialization error is
       
   697             // thrown below
       
   698             CLEAR_PENDING_EXCEPTION;
       
   699           }
       
   700           THROW_OOP(e());
       
   701         }
       
   702       }
       
   703     }
   692     }
   704   }
   693   }
   705 }
   694 }
   706 
   695 
   707 void InstanceKlass::initialize_impl(instanceKlassHandle this_k, TRAPS) {
   696 void InstanceKlass::initialize_impl(instanceKlassHandle this_k, TRAPS) {
   763     this_k->set_init_state(being_initialized);
   752     this_k->set_init_state(being_initialized);
   764     this_k->set_init_thread(self);
   753     this_k->set_init_thread(self);
   765   }
   754   }
   766 
   755 
   767   // Step 7
   756   // Step 7
   768   Klass* super_klass = this_k->super();
   757   // Next, if C is a class rather than an interface, initialize it's super class and super
   769   if (super_klass != NULL && !this_k->is_interface() && super_klass->should_be_initialized()) {
   758   // interfaces.
   770     super_klass->initialize(THREAD);
   759   if (!this_k->is_interface()) {
   771 
   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.
   772     if (HAS_PENDING_EXCEPTION) {
   773     if (HAS_PENDING_EXCEPTION) {
   773       Handle e(THREAD, PENDING_EXCEPTION);
   774       Handle e(THREAD, PENDING_EXCEPTION);
   774       CLEAR_PENDING_EXCEPTION;
   775       CLEAR_PENDING_EXCEPTION;
   775       {
   776       {
   776         EXCEPTION_MARK;
   777         EXCEPTION_MARK;
   777         this_k->set_initialization_state_and_notify(initialization_error, THREAD); // Locks object, set state, and notify all waiting threads
   778         // Locks object, set state, and notify all waiting threads
   778         CLEAR_PENDING_EXCEPTION;   // ignore any exception thrown, superclass initialization error is thrown below
   779         this_k->set_initialization_state_and_notify(initialization_error, THREAD);
       
   780         CLEAR_PENDING_EXCEPTION;
   779       }
   781       }
   780       DTRACE_CLASSINIT_PROBE_WAIT(super__failed, this_k(), -1,wait);
   782       DTRACE_CLASSINIT_PROBE_WAIT(super__failed, this_k(), -1,wait);
   781       THROW_OOP(e());
   783       THROW_OOP(e());
   782     }
   784     }
   783   }
   785   }
   784 
   786 
   785   // If C is an interface that declares a non-abstract, non-static method,
       
   786   // the initialization of a class (not an interface) that implements C directly or
       
   787   // indirectly.
       
   788   // Recursively initialize any superinterfaces that declare default methods
       
   789   // Only need to recurse if has_default_methods which includes declaring and
       
   790   // inheriting default methods
       
   791   if (!this_k->is_interface() && this_k->has_default_methods()) {
       
   792     this_k->initialize_super_interfaces(this_k, CHECK);
       
   793   }
       
   794 
   787 
   795   // Step 8
   788   // Step 8
   796   {
   789   {
   797     assert(THREAD->is_Java_thread(), "non-JavaThread in initialize_impl");
   790     assert(THREAD->is_Java_thread(), "non-JavaThread in initialize_impl");
   798     JavaThread* jt = (JavaThread*)THREAD;
   791     JavaThread* jt = (JavaThread*)THREAD;
   850   set_initialization_state_and_notify_impl(kh, state, CHECK);
   843   set_initialization_state_and_notify_impl(kh, state, CHECK);
   851 }
   844 }
   852 
   845 
   853 void InstanceKlass::set_initialization_state_and_notify_impl(instanceKlassHandle this_k, ClassState state, TRAPS) {
   846 void InstanceKlass::set_initialization_state_and_notify_impl(instanceKlassHandle this_k, ClassState state, TRAPS) {
   854   oop init_lock = this_k->init_lock();
   847   oop init_lock = this_k->init_lock();
   855   ObjectLocker ol(init_lock, THREAD, init_lock != NULL);
   848   if (init_lock != NULL) {
   856   this_k->set_init_state(state);
   849     ObjectLocker ol(init_lock, THREAD);
   857   this_k->fence_and_clear_init_lock();
   850     this_k->set_init_state(state);
   858   ol.notify_all(CHECK);
   851     this_k->fence_and_clear_init_lock();
       
   852     ol.notify_all(CHECK);
       
   853   } else {
       
   854     assert(init_lock != NULL, "The initialization state should never be set twice");
       
   855     this_k->set_init_state(state);
       
   856   }
   859 }
   857 }
   860 
   858 
   861 // The embedded _implementor field can only record one implementor.
   859 // The embedded _implementor field can only record one implementor.
   862 // When there are more than one implementors, the _implementor field
   860 // When there are more than one implementors, the _implementor field
   863 // is set to the interface Klass* itself. Following are the possible
   861 // is set to the interface Klass* itself. Following are the possible