--- old/src/hotspot/share/runtime/thread.cpp 2017-10-11 15:25:44.413709275 +0200 +++ new/src/hotspot/share/runtime/thread.cpp 2017-10-11 15:25:44.226701246 +0200 @@ -65,6 +65,7 @@ #include "runtime/deoptimization.hpp" #include "runtime/frame.inline.hpp" #include "runtime/globals.hpp" +#include "runtime/handshake.hpp" #include "runtime/init.hpp" #include "runtime/interfaceSupport.hpp" #include "runtime/java.hpp" @@ -1495,6 +1496,10 @@ _popframe_preserved_args_size = 0; _frames_to_pop_failed_realloc = 0; + if (SafepointMechanism::uses_thread_local_poll()) { + SafepointMechanism::initialize_header(this); + } + pd_initialize(); } @@ -1911,6 +1916,11 @@ // 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 INCLUDE_ALL_GCS