From 50c8643e36349981872675a54f4183127eb3a46b Mon Sep 17 00:00:00 2001 From: tajila Date: Wed, 4 Dec 2024 12:26:03 -0500 Subject: [PATCH] Release VMAccess before performing JFR teardown Signed-off-by: tajila --- runtime/vm/jfr.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/runtime/vm/jfr.cpp b/runtime/vm/jfr.cpp index 7fd9310294a..90335cd1dd8 100644 --- a/runtime/vm/jfr.cpp +++ b/runtime/vm/jfr.cpp @@ -440,6 +440,7 @@ jfrVMShutdown(J9HookInterface **hook, UDATA eventNum, void *eventData, void *use { J9VMShutdownEvent *event = (J9VMShutdownEvent *)eventData; J9VMThread *currentThread = event->vmThread; + bool needsVMAccess = J9_ARE_NO_BITS_SET(currentThread->publicFlags, J9_PUBLIC_FLAGS_VM_ACCESS); bool acquiredExclusive = false; #if defined(DEBUG) @@ -447,8 +448,11 @@ jfrVMShutdown(J9HookInterface **hook, UDATA eventNum, void *eventData, void *use j9tty_printf(PORTLIB, "\n!!! shutdown %p\n", currentThread); #endif /* defined(DEBUG) */ - if (J9_XACCESS_NONE == currentThread->javaVM->exclusiveAccessState) { + if (needsVMAccess) { internalAcquireVMAccess(currentThread); + } + + if (J9_XACCESS_NONE == currentThread->javaVM->exclusiveAccessState) { acquireExclusiveVMAccess(currentThread); acquiredExclusive = true; } @@ -459,10 +463,13 @@ jfrVMShutdown(J9HookInterface **hook, UDATA eventNum, void *eventData, void *use if (acquiredExclusive) { releaseExclusiveVMAccess(currentThread); - internalReleaseVMAccess(currentThread); } tearDownJFR(currentThread->javaVM); + + if (needsVMAccess) { + internalReleaseVMAccess(currentThread); + } } /** @@ -762,8 +769,13 @@ void tearDownJFR(J9JavaVM *vm) { PORT_ACCESS_FROM_JAVAVM(vm); + J9VMThread *currentThread = currentVMThread(vm); J9HookInterface **vmHooks = getVMHookInterface(vm); + Assert_VM_mustHaveVMAccess(currentThread); + + internalReleaseVMAccess(currentThread); + /* Stop the sampler thread */ if (NULL != vm->jfrSamplerMutex) { omrthread_monitor_enter(vm->jfrSamplerMutex); @@ -778,6 +790,9 @@ tearDownJFR(J9JavaVM *vm) omrthread_monitor_destroy(vm->jfrSamplerMutex); vm->jfrSamplerMutex = NULL; } + + internalAcquireVMAccess(currentThread); + vm->jfrState.isStarted = FALSE; vm->jfrSamplerState = J9JFR_SAMPLER_STATE_UNINITIALIZED;