--- old/src/hotspot/share/runtime/vm_operations.cpp 2018-03-23 15:32:38.000000000 -0400 +++ new/src/hotspot/share/runtime/vm_operations.cpp 2018-03-23 15:32:38.000000000 -0400 @@ -417,17 +417,15 @@ } volatile bool VM_Exit::_vm_exited = false; -Thread * VM_Exit::_shutdown_thread = NULL; +Thread * volatile VM_Exit::_shutdown_thread = NULL; int VM_Exit::set_vm_exited() { - Thread * thr_cur = Thread::current(); - + assert(_shutdown_thread == thr_cur, "_shutdown_thread should be current thread"); assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint already"); int num_active = 0; - _shutdown_thread = thr_cur; _vm_exited = true; // global flag for (JavaThreadIteratorWithHandle jtiwh; JavaThread *thr = jtiwh.next(); ) { if (thr!=thr_cur && thr->thread_state() == _thread_in_native) { @@ -502,6 +500,11 @@ // running in native; the other 6% are quiescent within 250ms (Ultra 80). wait_for_threads_in_native_to_block(); + // Remember the Thread that is shutting down the VM because it needs + // to be immune to some of the sanity checks and policies that have + // to happen at VM shutdown time. + VM_Exit::set_shutdown_thread(Thread::current()); + set_vm_exited(); // cleanup globals resources before exiting. exit_globals() currently