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