8199012: SEGV in jni_DetachCurrentThread during VM shutdown
authordholmes
Thu, 08 Mar 2018 16:44:29 -0500
changeset 49362 2085742233ed
parent 49361 1956d0ec092a
child 49363 7be58576e71a
8199012: SEGV in jni_DetachCurrentThread during VM shutdown Reviewed-by: stuefe, dcubed
src/hotspot/share/prims/jni.cpp
--- a/src/hotspot/share/prims/jni.cpp	Thu Mar 08 19:10:25 2018 +0100
+++ b/src/hotspot/share/prims/jni.cpp	Thu Mar 08 16:44:29 2018 -0500
@@ -4215,25 +4215,26 @@
 
 jint JNICALL jni_DetachCurrentThread(JavaVM *vm)  {
   HOTSPOT_JNI_DETACHCURRENTTHREAD_ENTRY(vm);
-  VM_Exit::block_if_vm_exited();
 
   JNIWrapper("DetachCurrentThread");
 
   // If the thread has already been detached the operation is a no-op
   if (Thread::current_or_null() == NULL) {
-  HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN(JNI_OK);
+    HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN(JNI_OK);
     return JNI_OK;
   }
 
+  VM_Exit::block_if_vm_exited();
+
   JavaThread* thread = JavaThread::current();
   if (thread->has_last_Java_frame()) {
-  HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN((uint32_t) JNI_ERR);
+    HOTSPOT_JNI_DETACHCURRENTTHREAD_RETURN((uint32_t) JNI_ERR);
     // Can't detach a thread that's running java, that can't work.
     return JNI_ERR;
   }
 
   // Safepoint support. Have to do call-back to safepoint code, if in the
-  // middel of a safepoint operation
+  // middle of a safepoint operation
   ThreadStateTransition::transition_from_native(thread, _thread_in_vm);
 
   // XXX: Note that JavaThread::exit() call below removes the guards on the