< prev index next >

src/hotspot/share/oops/instanceKlass.cpp

Print this page

 917   return lock;
 918 }
 919 
 920 // Set the initialization lock to null so the object can be GC'ed. Any racing
 921 // threads to get this lock will see a null lock and will not lock.
 922 // That's okay because they all check for initialized state after getting
 923 // the lock and return. For preempted vthreads we keep the oop protected
 924 // in the ObjectMonitor (see ObjectMonitor::set_object_strong()).
 925 void InstanceKlass::fence_and_clear_init_lock() {
 926   // make sure previous stores are all done, notably the init_state.
 927   OrderAccess::storestore();
 928   java_lang_Class::clear_init_lock(java_mirror());
 929   assert(!is_not_initialized(), "class must be initialized now");
 930 }
 931 
 932 class PreemptableInitCall {
 933   JavaThread* _thread;
 934   bool _previous;
 935   DEBUG_ONLY(InstanceKlass* _previous_klass;)
 936  public:
 937   PreemptableInitCall(JavaThread* thread, InstanceKlass* ik) : _thread(thread) {
 938     _previous = thread->at_preemptable_init();
 939     _thread->set_at_preemptable_init(true);
 940     DEBUG_ONLY(_previous_klass = _thread->preempt_init_klass();)
 941     DEBUG_ONLY(_thread->set_preempt_init_klass(ik));



 942   }
 943   ~PreemptableInitCall() {
 944     _thread->set_at_preemptable_init(_previous);
 945     DEBUG_ONLY(_thread->set_preempt_init_klass(_previous_klass));


 946   }
 947 };
 948 
 949 void InstanceKlass::initialize_preemptable(TRAPS) {
 950   if (this->should_be_initialized()) {
 951     PreemptableInitCall pic(THREAD, this);
 952     initialize_impl(THREAD);
 953   } else {
 954     assert(is_initialized(), "sanity check");
 955   }
 956 }
 957 
 958 // See "The Virtual Machine Specification" section 2.16.5 for a detailed explanation of the class initialization
 959 // process. The step comments refers to the procedure described in that section.
 960 // Note: implementation moved to static method to expose the this pointer.
 961 void InstanceKlass::initialize(TRAPS) {
 962   if (this->should_be_initialized()) {
 963     initialize_impl(CHECK);
 964     // Note: at this point the class may be initialized
 965     //       OR it may be in the state of being initialized

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