< prev index next >

src/hotspot/share/oops/instanceKlass.cpp

Print this page

 803   return lock;
 804 }
 805 
 806 // Set the initialization lock to null so the object can be GC'ed. Any racing
 807 // threads to get this lock will see a null lock and will not lock.
 808 // That's okay because they all check for initialized state after getting
 809 // the lock and return. For preempted vthreads we keep the oop protected
 810 // in the ObjectMonitor (see ObjectMonitor::set_object_strong()).
 811 void InstanceKlass::fence_and_clear_init_lock() {
 812   // make sure previous stores are all done, notably the init_state.
 813   OrderAccess::storestore();
 814   java_lang_Class::clear_init_lock(java_mirror());
 815   assert(!is_not_initialized(), "class must be initialized now");
 816 }
 817 
 818 class PreemptableInitCall {
 819   JavaThread* _thread;
 820   bool _previous;
 821   DEBUG_ONLY(InstanceKlass* _previous_klass;)
 822  public:
 823   PreemptableInitCall(JavaThread* thread, InstanceKlass* ik) : _thread(thread) {
 824     _previous = thread->at_preemptable_init();
 825     _thread->set_at_preemptable_init(true);
 826     DEBUG_ONLY(_previous_klass = _thread->preempt_init_klass();)
 827     DEBUG_ONLY(_thread->set_preempt_init_klass(ik));



 828   }
 829   ~PreemptableInitCall() {
 830     _thread->set_at_preemptable_init(_previous);
 831     DEBUG_ONLY(_thread->set_preempt_init_klass(_previous_klass));


 832   }
 833 };
 834 
 835 void InstanceKlass::initialize_preemptable(TRAPS) {
 836   if (this->should_be_initialized()) {
 837     PreemptableInitCall pic(THREAD, this);
 838     initialize_impl(THREAD);
 839   } else {
 840     assert(is_initialized(), "sanity check");
 841   }
 842 }
 843 
 844 // See "The Virtual Machine Specification" section 2.16.5 for a detailed explanation of the class initialization
 845 // process. The step comments refers to the procedure described in that section.
 846 // Note: implementation moved to static method to expose the this pointer.
 847 void InstanceKlass::initialize(TRAPS) {
 848   if (this->should_be_initialized()) {
 849     initialize_impl(CHECK);
 850     // Note: at this point the class may be initialized
 851     //       OR it may be in the state of being initialized

 803   return lock;
 804 }
 805 
 806 // Set the initialization lock to null so the object can be GC'ed. Any racing
 807 // threads to get this lock will see a null lock and will not lock.
 808 // That's okay because they all check for initialized state after getting
 809 // the lock and return. For preempted vthreads we keep the oop protected
 810 // in the ObjectMonitor (see ObjectMonitor::set_object_strong()).
 811 void InstanceKlass::fence_and_clear_init_lock() {
 812   // make sure previous stores are all done, notably the init_state.
 813   OrderAccess::storestore();
 814   java_lang_Class::clear_init_lock(java_mirror());
 815   assert(!is_not_initialized(), "class must be initialized now");
 816 }
 817 
 818 class PreemptableInitCall {
 819   JavaThread* _thread;
 820   bool _previous;
 821   DEBUG_ONLY(InstanceKlass* _previous_klass;)
 822  public:
 823   PreemptableInitCall(JavaThread* thread, InstanceKlass* ik) : _thread(nullptr) {
 824     if (thread->is_vthread_mounted()) {
 825       _thread = thread;
 826       _previous = _thread->at_preemptable_init();
 827       _thread->set_at_preemptable_init(true);
 828       DEBUG_ONLY(_previous_klass = _thread->preempt_init_klass();)
 829       DEBUG_ONLY(_thread->set_preempt_init_klass(ik));
 830     }
 831   }
 832   ~PreemptableInitCall() {
 833     if (_thread != nullptr) {
 834       _thread->set_at_preemptable_init(_previous);
 835       DEBUG_ONLY(_thread->set_preempt_init_klass(_previous_klass));
 836     }
 837   }
 838 };
 839 
 840 void InstanceKlass::initialize_preemptable(TRAPS) {
 841   if (this->should_be_initialized()) {
 842     PreemptableInitCall pic(THREAD, this);
 843     initialize_impl(THREAD);
 844   } else {
 845     assert(is_initialized(), "sanity check");
 846   }
 847 }
 848 
 849 // See "The Virtual Machine Specification" section 2.16.5 for a detailed explanation of the class initialization
 850 // process. The step comments refers to the procedure described in that section.
 851 // Note: implementation moved to static method to expose the this pointer.
 852 void InstanceKlass::initialize(TRAPS) {
 853   if (this->should_be_initialized()) {
 854     initialize_impl(CHECK);
 855     // Note: at this point the class may be initialized
 856     //       OR it may be in the state of being initialized
< prev index next >