hotspot/src/share/vm/oops/instanceKlass.cpp
changeset 21079 7028d0cb9b49
parent 20684 057f5443edab
child 21183 e148e499e5cd
equal deleted inserted replaced
21077:85a46889c631 21079:7028d0cb9b49
   496   return java_lang_Class::signers(java_mirror());
   496   return java_lang_Class::signers(java_mirror());
   497 }
   497 }
   498 
   498 
   499 oop InstanceKlass::init_lock() const {
   499 oop InstanceKlass::init_lock() const {
   500   // return the init lock from the mirror
   500   // return the init lock from the mirror
   501   return java_lang_Class::init_lock(java_mirror());
   501   oop lock = java_lang_Class::init_lock(java_mirror());
       
   502   assert((oop)lock != NULL || !is_not_initialized(), // initialized or in_error state
       
   503          "only fully initialized state can have a null lock");
       
   504   return lock;
       
   505 }
       
   506 
       
   507 // Set the initialization lock to null so the object can be GC'ed.  Any racing
       
   508 // threads to get this lock will see a null lock and will not lock.
       
   509 // That's okay because they all check for initialized state after getting
       
   510 // the lock and return.
       
   511 void InstanceKlass::fence_and_clear_init_lock() {
       
   512   // make sure previous stores are all done, notably the init_state.
       
   513   OrderAccess::storestore();
       
   514   java_lang_Class::set_init_lock(java_mirror(), NULL);
       
   515   assert(!is_not_initialized(), "class must be initialized now");
   502 }
   516 }
   503 
   517 
   504 void InstanceKlass::eager_initialize_impl(instanceKlassHandle this_oop) {
   518 void InstanceKlass::eager_initialize_impl(instanceKlassHandle this_oop) {
   505   EXCEPTION_MARK;
   519   EXCEPTION_MARK;
   506   oop init_lock = this_oop->init_lock();
   520   oop init_lock = this_oop->init_lock();
   507   ObjectLocker ol(init_lock, THREAD);
   521   ObjectLocker ol(init_lock, THREAD, init_lock != NULL);
   508 
   522 
   509   // abort if someone beat us to the initialization
   523   // abort if someone beat us to the initialization
   510   if (!this_oop->is_not_initialized()) return;  // note: not equivalent to is_initialized()
   524   if (!this_oop->is_not_initialized()) return;  // note: not equivalent to is_initialized()
   511 
   525 
   512   ClassState old_state = this_oop->init_state();
   526   ClassState old_state = this_oop->init_state();
   521     if( old_state != this_oop->_init_state )
   535     if( old_state != this_oop->_init_state )
   522       this_oop->set_init_state (old_state);
   536       this_oop->set_init_state (old_state);
   523   } else {
   537   } else {
   524     // linking successfull, mark class as initialized
   538     // linking successfull, mark class as initialized
   525     this_oop->set_init_state (fully_initialized);
   539     this_oop->set_init_state (fully_initialized);
       
   540     this_oop->fence_and_clear_init_lock();
   526     // trace
   541     // trace
   527     if (TraceClassInitialization) {
   542     if (TraceClassInitialization) {
   528       ResourceMark rm(THREAD);
   543       ResourceMark rm(THREAD);
   529       tty->print_cr("[Initialized %s without side effects]", this_oop->external_name());
   544       tty->print_cr("[Initialized %s without side effects]", this_oop->external_name());
   530     }
   545     }
   647                              PerfClassTraceTime::CLASS_LINK);
   662                              PerfClassTraceTime::CLASS_LINK);
   648 
   663 
   649   // verification & rewriting
   664   // verification & rewriting
   650   {
   665   {
   651     oop init_lock = this_oop->init_lock();
   666     oop init_lock = this_oop->init_lock();
   652     ObjectLocker ol(init_lock, THREAD);
   667     ObjectLocker ol(init_lock, THREAD, init_lock != NULL);
   653     // rewritten will have been set if loader constraint error found
   668     // rewritten will have been set if loader constraint error found
   654     // on an earlier link attempt
   669     // on an earlier link attempt
   655     // don't verify or rewrite if already rewritten
   670     // don't verify or rewrite if already rewritten
   656 
   671 
   657     if (!this_oop->is_linked()) {
   672     if (!this_oop->is_linked()) {
   770 
   785 
   771   // refer to the JVM book page 47 for description of steps
   786   // refer to the JVM book page 47 for description of steps
   772   // Step 1
   787   // Step 1
   773   {
   788   {
   774     oop init_lock = this_oop->init_lock();
   789     oop init_lock = this_oop->init_lock();
   775     ObjectLocker ol(init_lock, THREAD);
   790     ObjectLocker ol(init_lock, THREAD, init_lock != NULL);
   776 
   791 
   777     Thread *self = THREAD; // it's passed the current thread
   792     Thread *self = THREAD; // it's passed the current thread
   778 
   793 
   779     // Step 2
   794     // Step 2
   780     // If we were to use wait() instead of waitInterruptibly() then
   795     // If we were to use wait() instead of waitInterruptibly() then
   918   set_initialization_state_and_notify_impl(kh, state, CHECK);
   933   set_initialization_state_and_notify_impl(kh, state, CHECK);
   919 }
   934 }
   920 
   935 
   921 void InstanceKlass::set_initialization_state_and_notify_impl(instanceKlassHandle this_oop, ClassState state, TRAPS) {
   936 void InstanceKlass::set_initialization_state_and_notify_impl(instanceKlassHandle this_oop, ClassState state, TRAPS) {
   922   oop init_lock = this_oop->init_lock();
   937   oop init_lock = this_oop->init_lock();
   923   ObjectLocker ol(init_lock, THREAD);
   938   ObjectLocker ol(init_lock, THREAD, init_lock != NULL);
   924   this_oop->set_init_state(state);
   939   this_oop->set_init_state(state);
       
   940   this_oop->fence_and_clear_init_lock();
   925   ol.notify_all(CHECK);
   941   ol.notify_all(CHECK);
   926 }
   942 }
   927 
   943 
   928 // The embedded _implementor field can only record one implementor.
   944 // The embedded _implementor field can only record one implementor.
   929 // When there are more than one implementors, the _implementor field
   945 // When there are more than one implementors, the _implementor field