changeset 9104:9a7135d0a309

8225141: Better handling of classes in error state in fast class initialization checks Reviewed-by: andrew
author zgu
date Tue, 17 Dec 2019 05:07:06 +0000
parents 371da86379cf
children 7386b3a385ac
files src/share/vm/oops/instanceKlass.cpp src/share/vm/oops/instanceKlass.hpp
diffstat 2 files changed, 5 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/oops/instanceKlass.cpp	Wed Dec 04 16:24:15 2019 +0000
+++ b/src/share/vm/oops/instanceKlass.cpp	Tue Dec 17 05:07:06 2019 +0000
@@ -294,6 +294,7 @@
   set_has_unloaded_dependent(false);
   set_init_state(InstanceKlass::allocated);
   set_init_thread(NULL);
+  set_init_state(allocated);
   set_reference_type(rt);
   set_oop_map_cache(NULL);
   set_jni_ids(NULL);
@@ -978,11 +979,13 @@
   oop init_lock = this_oop->init_lock();
   if (init_lock != NULL) {
     ObjectLocker ol(init_lock, THREAD);
+    this_oop->set_init_thread(NULL); // reset _init_thread before changing _init_state
     this_oop->set_init_state(state);
     this_oop->fence_and_clear_init_lock();
     ol.notify_all(CHECK);
   } else {
     assert(init_lock != NULL, "The initialization state should never be set twice");
+    this_oop->set_init_thread(NULL); // reset _init_thread before changing _init_state
     this_oop->set_init_state(state);
   }
 }
@@ -3602,6 +3605,7 @@
   bool good_state = is_shared() ? (_init_state <= state)
                                                : (_init_state < state);
   assert(good_state || state == allocated, "illegal state transition");
+  set_initialization_state_and_notify_implassert(_init_thread == NULL, "should be cleared before state change");
   _init_state = (u1)state;
 }
 #endif
--- a/src/share/vm/oops/instanceKlass.hpp	Wed Dec 04 16:24:15 2019 +0000
+++ b/src/share/vm/oops/instanceKlass.hpp	Tue Dec 17 05:07:06 2019 +0000
@@ -241,7 +241,7 @@
   u2              _misc_flags;
   u2              _minor_version;        // minor version number of class file
   u2              _major_version;        // major version number of class file
-  Thread*         _init_thread;          // Pointer to current thread doing initialization (to handle recusive initialization)
+  Thread*         _init_thread;          // Pointer to current thread doing initialization (to handle recursive initialization)
   int             _vtable_len;           // length of Java vtable (in words)
   int             _itable_len;           // length of Java itable (in words)
   OopMapCache*    volatile _oop_map_cache;   // OopMapCache for all methods in the klass (allocated lazily)