Skip to content

Commit 484229e

Browse files
author
David Holmes
committed
8346306: Unattached thread can cause crash during VM exit if it calls wait_if_vm_exited
Reviewed-by: coleenp, ccheung
1 parent b0c40aa commit 484229e

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/hotspot/share/prims/jvm.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3319,8 +3319,9 @@ JVM_END
33193319
// VM Raw monitors (not to be confused with JvmtiRawMonitors) are a simple mutual exclusion
33203320
// lock (not actually monitors: no wait/notify) that is exported by the VM for use by JDK
33213321
// library code. They may be used by JavaThreads and non-JavaThreads and do not participate
3322-
// in the safepoint protocol, thread suspension, thread interruption, or anything of that
3323-
// nature. JavaThreads will be "in native" when using this API from JDK code.
3322+
// in the safepoint protocol, thread suspension, thread interruption, or most things of that
3323+
// nature, except JavaThreads will be blocked by VM_Exit::block_if_vm_exited if the VM has
3324+
// shutdown. JavaThreads will be "in native" when using this API from JDK code.
33243325

33253326

33263327
JNIEXPORT void* JNICALL JVM_RawMonitorCreate(void) {

src/hotspot/share/runtime/vmOperations.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -611,12 +611,16 @@ void VM_Exit::doit() {
611611

612612

613613
void VM_Exit::wait_if_vm_exited() {
614-
if (_vm_exited &&
615-
Thread::current_or_null() != _shutdown_thread) {
616-
// _vm_exited is set at safepoint, and the Threads_lock is never released
617-
// so we will block here until the process dies.
618-
Threads_lock->lock();
619-
ShouldNotReachHere();
614+
if (_vm_exited) {
615+
// Need to check for an unattached thread as only attached threads
616+
// can acquire the lock.
617+
Thread* current = Thread::current_or_null();
618+
if (current != nullptr && current != _shutdown_thread) {
619+
// _vm_exited is set at safepoint, and the Threads_lock is never released
620+
// so we will block here until the process dies.
621+
Threads_lock->lock();
622+
ShouldNotReachHere();
623+
}
620624
}
621625
}
622626

0 commit comments

Comments
 (0)