8233454: Test fails with assert(!is_init_completed(), "should only happen during init") after JDK-8229516
authordholmes
Wed, 06 Nov 2019 21:18:42 -0500
changeset 58956 9a0a5e70eeb2
parent 58955 dfd5196652dd
child 58957 00244fd3169a
8233454: Test fails with assert(!is_init_completed(), "should only happen during init") after JDK-8229516 Reviewed-by: jiefu, dcubed
src/hotspot/share/classfile/javaClasses.cpp
src/hotspot/share/runtime/thread.cpp
--- a/src/hotspot/share/classfile/javaClasses.cpp	Thu Nov 07 03:01:52 2019 +0100
+++ b/src/hotspot/share/classfile/javaClasses.cpp	Wed Nov 06 21:18:42 2019 -0500
@@ -1681,13 +1681,6 @@
 }
 
 bool java_lang_Thread::interrupted(oop java_thread) {
-#if INCLUDE_JFR
-  if (java_thread == NULL) {
-    // can happen from Jfr::on_vm_init leading to call of JavaThread::sleep
-    assert(!is_init_completed(), "should only happen during init");
-    return false;
-  }
-#endif
   return java_thread->bool_field_volatile(_interrupted_offset);
 }
 
--- a/src/hotspot/share/runtime/thread.cpp	Thu Nov 07 03:01:52 2019 +0100
+++ b/src/hotspot/share/runtime/thread.cpp	Wed Nov 06 21:18:42 2019 -0500
@@ -1741,6 +1741,16 @@
 
 bool JavaThread::is_interrupted(bool clear_interrupted) {
   debug_only(check_for_dangling_thread_pointer(this);)
+
+  if (threadObj() == NULL) {
+    // If there is no j.l.Thread then it is impossible to have
+    // been interrupted. We can find NULL during VM initialization
+    // or when a JNI thread is still in the process of attaching.
+    // In such cases this must be the current thread.
+    assert(this == Thread::current(), "invariant");
+    return false;
+  }
+
   bool interrupted = java_lang_Thread::interrupted(threadObj());
 
   // NOTE that since there is no "lock" around the interrupt and
@@ -1759,6 +1769,7 @@
   // state if we are going to report that we were interrupted; otherwise
   // an interrupt that happens just after we read the field would be lost.
   if (interrupted && clear_interrupted) {
+    assert(this == Thread::current(), "only the current thread can clear");
     java_lang_Thread::set_interrupted(threadObj(), false);
     osthread()->set_interrupted(false);
   }