Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release VMAccess in JFR teardown before waiting on lock #20754

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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