diff --git a/src/hotspot/share/runtime/globals.hpp b/src/hotspot/share/runtime/globals.hpp index cf721f3de0c3e..455885782a442 100644 --- a/src/hotspot/share/runtime/globals.hpp +++ b/src/hotspot/share/runtime/globals.hpp @@ -831,6 +831,11 @@ const int ObjectAlignmentInBytes = 8; "JVM aborts, producing an error log and core/mini dump, on the " \ "first occurrence of an out-of-memory error thrown from JVM") \ \ + product(intx, WaitUserThreadAtExitTimeout, 300, \ + "Maximum delay in milliseconds at exit waiting for user threads " \ + "in native") \ + range(0, max_intx) \ + \ /* tracing */ \ \ develop(bool, StressRewriter, false, \ diff --git a/src/hotspot/share/runtime/vmOperations.cpp b/src/hotspot/share/runtime/vmOperations.cpp index fefb96acc7aea..635ef29b13959 100644 --- a/src/hotspot/share/runtime/vmOperations.cpp +++ b/src/hotspot/share/runtime/vmOperations.cpp @@ -391,10 +391,10 @@ int VM_Exit::wait_for_threads_in_native_to_block() { // don't have to wait for user threads to be quiescent, but it's always // better to terminate VM when current thread is the only active thread, so // wait for user threads too. Numbers are in 10 milliseconds. - int max_wait_user_thread = 30; // at least 300 milliseconds - int max_wait_compiler_thread = 1000; // at least 10 seconds - - int max_wait = max_wait_compiler_thread; + int wait_time_per_attempt = 10; // in milliseconds + int max_wait_attempts_user_thread = + WaitUserThreadAtExitTimeout / wait_time_per_attempt; + int max_wait_attempts_compiler_thread = 1000; // at least 10 seconds int attempts = 0; JavaThreadIteratorWithHandle jtiwh; @@ -427,16 +427,17 @@ int VM_Exit::wait_for_threads_in_native_to_block() { if (num_active == 0) { return 0; - } else if (attempts > max_wait) { + } else if (attempts >= max_wait_attempts_compiler_thread) { return num_active; - } else if (num_active_compiler_thread == 0 && attempts > max_wait_user_thread) { + } else if (num_active_compiler_thread == 0 && + attempts >= max_wait_attempts_user_thread) { return num_active; } attempts++; MonitorLocker ml(&timer, Mutex::_no_safepoint_check_flag); - ml.wait(10); + ml.wait(wait_time_per_attempt); } }