8233454: Test fails with assert(!is_init_completed(), "should only happen during init") after JDK-8229516
Reviewed-by: jiefu, dcubed
--- 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);
}