Skip to content

Commit

Permalink
Merge pull request #20754 from tajila/jfr2
Browse files Browse the repository at this point in the history
Release VMAccess in JFR teardown before waiting on lock
  • Loading branch information
babsingh authored Dec 5, 2024
2 parents c963d9e + 3df42a1 commit ba6e625
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions runtime/vm/jfr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,15 +436,19 @@ 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)
PORT_ACCESS_FROM_VMC(currentThread);
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;
}
Expand All @@ -455,10 +459,13 @@ jfrVMShutdown(J9HookInterface **hook, UDATA eventNum, void *eventData, void *use

if (acquiredExclusive) {
releaseExclusiveVMAccess(currentThread);
internalReleaseVMAccess(currentThread);
}

tearDownJFR(currentThread->javaVM);

if (needsVMAccess) {
internalReleaseVMAccess(currentThread);
}
}

/**
Expand Down Expand Up @@ -758,8 +765,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);
Expand All @@ -774,6 +786,9 @@ tearDownJFR(J9JavaVM *vm)
omrthread_monitor_destroy(vm->jfrSamplerMutex);
vm->jfrSamplerMutex = NULL;
}

internalAcquireVMAccess(currentThread);

vm->jfrState.isStarted = FALSE;
vm->jfrSamplerState = J9JFR_SAMPLER_STATE_UNINITIALIZED;

Expand Down

0 comments on commit ba6e625

Please sign in to comment.