--- old/src/hotspot/share/runtime/thread.cpp Sat Nov 18 16:53:57 2017 +++ new/src/hotspot/share/runtime/thread.cpp Sat Nov 18 16:53:56 2017 @@ -2023,11 +2023,6 @@ // Remove from list of active threads list, and notify VM thread if we are the last non-daemon thread Threads::remove(this); - // If someone set a handshake on us just as we entered exit path, we simple cancel it. - if (ThreadLocalHandshakes) { - cancel_handshake(); - } - if (log_is_enabled(Debug, os, thread, timer)) { _timer_exit_phase4.stop(); ResourceMark rm(this); @@ -4830,6 +4825,11 @@ // Retry the whole scenario. } + // If someone set a handshake on us just as we entered exit path, we simple cancel it. + if (ThreadLocalHandshakes) { + thread->cancel_handshake(); + } + delete thread; if (EnableThreadSMRStatistics) { timer.stop();