Skip to content

Commit

Permalink
8314243: Make VM_Exit::wait_for_threads_in_native_to_block wait for u…
Browse files Browse the repository at this point in the history
…ser threads time configurable
  • Loading branch information
jianglizhou committed Aug 15, 2023
1 parent f239954 commit 3afc48d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
5 changes: 5 additions & 0 deletions src/hotspot/share/runtime/globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, \
Expand Down
15 changes: 8 additions & 7 deletions src/hotspot/share/runtime/vmOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 3afc48d

Please sign in to comment.