< prev index next >

src/hotspot/share/oops/instanceKlass.cpp

Print this page

 931   return lock;
 932 }
 933 
 934 // Set the initialization lock to null so the object can be GC'ed. Any racing
 935 // threads to get this lock will see a null lock and will not lock.
 936 // That's okay because they all check for initialized state after getting
 937 // the lock and return. For preempted vthreads we keep the oop protected
 938 // in the ObjectMonitor (see ObjectMonitor::set_object_strong()).
 939 void InstanceKlass::fence_and_clear_init_lock() {
 940   // make sure previous stores are all done, notably the init_state.
 941   OrderAccess::storestore();
 942   java_lang_Class::clear_init_lock(java_mirror());
 943   assert(!is_not_initialized(), "class must be initialized now");
 944 }
 945 
 946 class PreemptableInitCall {
 947   JavaThread* _thread;
 948   bool _previous;
 949   DEBUG_ONLY(InstanceKlass* _previous_klass;)
 950  public:
 951   PreemptableInitCall(JavaThread* thread, InstanceKlass* ik) : _thread(thread) {
 952     _previous = thread->at_preemptable_init();
 953     _thread->set_at_preemptable_init(true);
 954     DEBUG_ONLY(_previous_klass = _thread->preempt_init_klass();)
 955     DEBUG_ONLY(_thread->set_preempt_init_klass(ik));



 956   }
 957   ~PreemptableInitCall() {
 958     _thread->set_at_preemptable_init(_previous);
 959     DEBUG_ONLY(_thread->set_preempt_init_klass(_previous_klass));


 960   }
 961 };
 962 
 963 void InstanceKlass::initialize_preemptable(TRAPS) {
 964   if (this->should_be_initialized()) {
 965     PreemptableInitCall pic(THREAD, this);
 966     initialize_impl(THREAD);
 967   } else {
 968     assert(is_initialized(), "sanity check");
 969   }
 970 }
 971 
 972 // See "The Virtual Machine Specification" section 2.16.5 for a detailed explanation of the class initialization
 973 // process. The step comments refers to the procedure described in that section.
 974 // Note: implementation moved to static method to expose the this pointer.
 975 void InstanceKlass::initialize(TRAPS) {
 976   if (this->should_be_initialized()) {
 977     initialize_impl(CHECK);
 978     // Note: at this point the class may be initialized
 979     //       OR it may be in the state of being initialized

 931   return lock;
 932 }
 933 
 934 // Set the initialization lock to null so the object can be GC'ed. Any racing
 935 // threads to get this lock will see a null lock and will not lock.
 936 // That's okay because they all check for initialized state after getting
 937 // the lock and return. For preempted vthreads we keep the oop protected
 938 // in the ObjectMonitor (see ObjectMonitor::set_object_strong()).
 939 void InstanceKlass::fence_and_clear_init_lock() {
 940   // make sure previous stores are all done, notably the init_state.
 941   OrderAccess::storestore();
 942   java_lang_Class::clear_init_lock(java_mirror());
 943   assert(!is_not_initialized(), "class must be initialized now");
 944 }
 945 
 946 class PreemptableInitCall {
 947   JavaThread* _thread;
 948   bool _previous;
 949   DEBUG_ONLY(InstanceKlass* _previous_klass;)
 950  public:
 951   PreemptableInitCall(JavaThread* thread, InstanceKlass* ik) : _thread(nullptr) {
 952     if (thread->is_vthread_mounted()) {
 953       _thread = thread;
 954       _previous = _thread->at_preemptable_init();
 955       _thread->set_at_preemptable_init(true);
 956       DEBUG_ONLY(_previous_klass = _thread->preempt_init_klass();)
 957       DEBUG_ONLY(_thread->set_preempt_init_klass(ik));
 958     }
 959   }
 960   ~PreemptableInitCall() {
 961     if (_thread != nullptr) {
 962       _thread->set_at_preemptable_init(_previous);
 963       DEBUG_ONLY(_thread->set_preempt_init_klass(_previous_klass));
 964     }
 965   }
 966 };
 967 
 968 void InstanceKlass::initialize_preemptable(TRAPS) {
 969   if (this->should_be_initialized()) {
 970     PreemptableInitCall pic(THREAD, this);
 971     initialize_impl(THREAD);
 972   } else {
 973     assert(is_initialized(), "sanity check");
 974   }
 975 }
 976 
 977 // See "The Virtual Machine Specification" section 2.16.5 for a detailed explanation of the class initialization
 978 // process. The step comments refers to the procedure described in that section.
 979 // Note: implementation moved to static method to expose the this pointer.
 980 void InstanceKlass::initialize(TRAPS) {
 981   if (this->should_be_initialized()) {
 982     initialize_impl(CHECK);
 983     // Note: at this point the class may be initialized
 984     //       OR it may be in the state of being initialized
< prev index next >