--- old/src/hotspot/share/runtime/thread.cpp 2019-10-31 00:10:59.906198673 -0400 +++ new/src/hotspot/share/runtime/thread.cpp 2019-10-31 00:10:58.763185442 -0400 @@ -1725,19 +1725,13 @@ void JavaThread::interrupt() { debug_only(check_for_dangling_thread_pointer(this);) - if (!osthread()->interrupted()) { - osthread()->set_interrupted(true); - // More than one thread can get here with the same value of osthread, - // resulting in multiple notifications. We do, however, want the store - // to interrupted() to be visible to other threads before we execute unpark(). - OrderAccess::fence(); - - // For JavaThread::sleep. Historically we only unpark if changing to the interrupted - // state, in contrast to the other events below. Not clear exactly why. - _SleepEvent->unpark(); - } + // For Windows _interrupt_event + osthread()->set_interrupted(true); + + // For Thread.sleep + _SleepEvent->unpark(); - // For JSR166. Unpark even if interrupt status already was set. + // For JSR166 LockSupport.park parker()->unpark(); // For ObjectMonitor and JvmtiRawMonitor @@ -1747,11 +1741,11 @@ bool JavaThread::is_interrupted(bool clear_interrupted) { debug_only(check_for_dangling_thread_pointer(this);) - bool interrupted = osthread()->interrupted(); + bool interrupted = java_lang_Thread::interrupted(threadObj()); // NOTE that since there is no "lock" around the interrupt and // is_interrupted operations, there is the possibility that the - // interrupted flag (in osThread) will be "false" but that the + // interrupted flag will be "false" but that the // low-level events will be in the signaled state. This is // intentional. The effect of this is that Object.wait() and // LockSupport.park() will appear to have a spurious wakeup, which @@ -1761,9 +1755,12 @@ // to JavaThread::sleep, so there is no early return. It has also been // recommended not to put the interrupted flag into the "event" // structure because it hides the issue. + // Also, because there is no lock, we must only clear the interrupt + // 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) { + java_lang_Thread::set_interrupted(threadObj(), false); osthread()->set_interrupted(false); - // consider thread->_SleepEvent->reset() ... optional optimization } return interrupted; @@ -2417,6 +2414,7 @@ // Interrupt thread so it will wake up from a potential wait()/sleep()/park() + java_lang_Thread::set_interrupted(threadObj(), true); this->interrupt(); }