Skip to content

Commit

Permalink
8346306: Unattached thread can cause crash during VM exit if it calls…
Browse files Browse the repository at this point in the history
… wait_if_vm_exited

Reviewed-by: coleenp, ccheung
  • Loading branch information
David Holmes committed Dec 19, 2024
1 parent b0c40aa commit 484229e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/hotspot/share/prims/jvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3319,8 +3319,9 @@ JVM_END
// VM Raw monitors (not to be confused with JvmtiRawMonitors) are a simple mutual exclusion
// lock (not actually monitors: no wait/notify) that is exported by the VM for use by JDK
// library code. They may be used by JavaThreads and non-JavaThreads and do not participate
// in the safepoint protocol, thread suspension, thread interruption, or anything of that
// nature. JavaThreads will be "in native" when using this API from JDK code.
// in the safepoint protocol, thread suspension, thread interruption, or most things of that
// nature, except JavaThreads will be blocked by VM_Exit::block_if_vm_exited if the VM has
// shutdown. JavaThreads will be "in native" when using this API from JDK code.


JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void) {
Expand Down
16 changes: 10 additions & 6 deletions src/hotspot/share/runtime/vmOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,12 +611,16 @@ void VM_Exit::doit() {


void VM_Exit::wait_if_vm_exited() {
if (_vm_exited &&
Thread::current_or_null() != _shutdown_thread) {
// _vm_exited is set at safepoint, and the Threads_lock is never released
// so we will block here until the process dies.
Threads_lock->lock();
ShouldNotReachHere();
if (_vm_exited) {
// Need to check for an unattached thread as only attached threads
// can acquire the lock.
Thread* current = Thread::current_or_null();
if (current != nullptr && current != _shutdown_thread) {
// _vm_exited is set at safepoint, and the Threads_lock is never released
// so we will block here until the process dies.
Threads_lock->lock();
ShouldNotReachHere();
}
}
}

Expand Down

0 comments on commit 484229e

Please sign in to comment.