changeset 13608:409753e9c98e

8186437: Lock held when compiler thread creation fails. Reviewed-by: stuefe, kvn
author goetz
date Tue, 22 Aug 2017 15:12:26 +0200
parents 36780bca7e82
children 35045bc7f7f6
files src/share/vm/compiler/compileBroker.cpp
diffstat 1 files changed, 40 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/compiler/compileBroker.cpp	Fri Aug 25 14:07:18 2017 -0700
+++ b/src/share/vm/compiler/compileBroker.cpp	Tue Aug 22 15:12:26 2017 +0200
@@ -720,44 +720,49 @@
     // At this point it may be possible that no osthread was created for the
     // JavaThread due to lack of memory. We would have to throw an exception
     // in that case. However, since this must work and we do not allow
-    // exceptions anyway, check and abort if this fails.
+    // exceptions anyway, check and abort if this fails. But first release the
+    // lock.
 
-    if (thread == NULL || thread->osthread() == NULL) {
-      vm_exit_during_initialization("java.lang.OutOfMemoryError",
-                                    os::native_thread_creation_failed_msg());
+    if (thread != NULL && thread->osthread() != NULL) {
+
+      java_lang_Thread::set_thread(thread_oop(), thread);
+
+      // Note that this only sets the JavaThread _priority field, which by
+      // definition is limited to Java priorities and not OS priorities.
+      // The os-priority is set in the CompilerThread startup code itself
+
+      java_lang_Thread::set_priority(thread_oop(), NearMaxPriority);
+
+      // Note that we cannot call os::set_priority because it expects Java
+      // priorities and we are *explicitly* using OS priorities so that it's
+      // possible to set the compiler thread priority higher than any Java
+      // thread.
+
+      int native_prio = CompilerThreadPriority;
+      if (native_prio == -1) {
+        if (UseCriticalCompilerThreadPriority) {
+          native_prio = os::java_to_os_priority[CriticalPriority];
+        } else {
+          native_prio = os::java_to_os_priority[NearMaxPriority];
+        }
+      }
+      os::set_native_priority(thread, native_prio);
+
+      java_lang_Thread::set_daemon(thread_oop());
+
+      thread->set_threadObj(thread_oop());
+      if (compiler_thread) {
+        thread->as_CompilerThread()->set_compiler(comp);
+      }
+      Threads::add(thread);
+      Thread::start(thread);
     }
+  }
 
-    java_lang_Thread::set_thread(thread_oop(), thread);
-
-    // Note that this only sets the JavaThread _priority field, which by
-    // definition is limited to Java priorities and not OS priorities.
-    // The os-priority is set in the CompilerThread startup code itself
-
-    java_lang_Thread::set_priority(thread_oop(), NearMaxPriority);
-
-    // Note that we cannot call os::set_priority because it expects Java
-    // priorities and we are *explicitly* using OS priorities so that it's
-    // possible to set the compiler thread priority higher than any Java
-    // thread.
-
-    int native_prio = CompilerThreadPriority;
-    if (native_prio == -1) {
-      if (UseCriticalCompilerThreadPriority) {
-        native_prio = os::java_to_os_priority[CriticalPriority];
-      } else {
-        native_prio = os::java_to_os_priority[NearMaxPriority];
-      }
-    }
-    os::set_native_priority(thread, native_prio);
-
-    java_lang_Thread::set_daemon(thread_oop());
-
-    thread->set_threadObj(thread_oop());
-    if (compiler_thread) {
-      thread->as_CompilerThread()->set_compiler(comp);
-    }
-    Threads::add(thread);
-    Thread::start(thread);
+  // First release lock before aborting VM.
+  if (thread == NULL || thread->osthread() == NULL) {
+    vm_exit_during_initialization("java.lang.OutOfMemoryError",
+                                  os::native_thread_creation_failed_msg());
   }
 
   // Let go of Threads_lock before yielding