Skip to content

Commit d60ee94

Browse files
committed
Add missing exclusive access for thread iteration
Signed-off-by: Tobi Ajila <atobia@ca.ibm.com>
1 parent 16776fb commit d60ee94

2 files changed

Lines changed: 37 additions & 2 deletions

File tree

runtime/vm/jfr.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,7 +950,9 @@ initializeJFR(J9JavaVM *vm)
950950

951951
U_8 *buffer = NULL;
952952
UDATA timeSuccess = 0;
953+
J9VMThread *currentThread = currentVMThread(vm);
953954
J9VMThread *walkThread = NULL;
955+
J9HookInterface **vmHooks = getVMHookInterface(vm);
954956

955957
Assert_VM_false(vm->jfrState.isCreated);
956958

@@ -1031,6 +1033,7 @@ initializeJFR(J9JavaVM *vm)
10311033
goto fail;
10321034
}
10331035

1036+
acquireExclusiveVMAccess(currentThread);
10341037
/* Go through existing threads. */
10351038
walkThread = J9_LINKED_LIST_START_DO(vm->mainThread);
10361039
while (NULL != walkThread) {
@@ -1050,6 +1053,12 @@ initializeJFR(J9JavaVM *vm)
10501053
walkThread = J9_LINKED_LIST_NEXT_DO(vm->mainThread, walkThread);
10511054
}
10521055

1056+
if ((*vmHooks)->J9HookRegisterWithCallSite(vmHooks, J9HOOK_VM_THREAD_CREATED, jfrThreadCreated, OMR_GET_CALLSITE(), NULL)) {
1057+
goto done;
1058+
}
1059+
1060+
releaseExclusiveVMAccess(currentThread);
1061+
10531062
vm->jfrState.isCreated = TRUE;
10541063

10551064
if (!isJFRV2SupportEnabled(vm)) {
@@ -2216,8 +2225,8 @@ JfrPeriodicEventSet::requestCPULoad(J9VMThread *currentThread)
22162225
void
22172226
JfrPeriodicEventSet::requestThreadCPULoad(J9VMThread *currentThread)
22182227
{
2219-
jfrThreadCPULoad(currentThread, currentThread);
2220-
}
2228+
J9JavaVM *vm = currentThread->javaVM;
2229+
J9SignalAsyncEvent(vm, NULL, vm->jfrThreadCPULoadAsyncKey);
22212230

22222231
void
22232232
JfrPeriodicEventSet::requestThreadContextSwitchRate(J9VMThread *currentThread)

test/functional/cmdLineTests/jfr/jfrV2.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,30 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-ex
107107
<output type="failure" caseSensitive="yes" regex="no">Found additional fields in mirror class</output>
108108
<output type="failure" caseSensitive="yes" regex="no">Error</output>
109109
</test>
110+
<test id="test jfr summary - approx 5 seconds">
111+
<command>$JFR_EXE$ summary testrecording.jfr</command>
112+
<output type="required" caseSensitive="yes" regex="no">Version: 2.1</output>
113+
<output type="required" caseSensitive="yes" regex="no">jdk.ExecutionSample</output>
114+
<output type="success" caseSensitive="yes" regex="no">jdk.CPULoad</output>
115+
<output type="success" caseSensitive="yes" regex="no">jdk.JavaThreadStatistics</output>
116+
<output type="success" caseSensitive="yes" regex="no">jdk.ClassLoadingStatistics</output>
117+
<output type="success" caseSensitive="yes" regex="no">jdk.ThreadCPULoad</output>
118+
<output type="required" caseSensitive="yes" regex="no">jdk.Metadata</output>
119+
</test>
120+
<test id="test jfr execution sample - approx 5 seconds">
121+
<command>$JFR_EXE$ print --xml --events "ExecutionSample" --stack-depth 1 testrecording.jfr</command>
122+
<output type="required" caseSensitive="yes" regex="no">http://www.w3.org/2001/XMLSchema-instance</output>
123+
<output type="required" caseSensitive="yes" regex="no">jdk.ExecutionSample</output>
124+
<output type="required" caseSensitive="yes" regex="no">startTime</output>
125+
<output type="required" caseSensitive="yes" regex="no">sampledThread</output>
126+
<output type="required" caseSensitive="yes" regex="no">stackTrace</output>
127+
<output type="required" caseSensitive="yes" regex="no">frames</output>
128+
<output type="success" caseSensitive="yes" regex="no">STATE_RUNNABLE</output>
129+
<output type="failure" caseSensitive="yes" regex="no">jfr print: could not read recording</output>
130+
</test>
131+
<test id="Test JFRv2 with profile config">
132+
<command>$EXE$ -XX:+EnableOpenJ9ExperimentalFlightRecording -XX:StartFlightRecording:filename=profile.jfr,dumponexit=true,settings=default.jfc --add-opens jdk.jfr/jdk.jfr.internal=ALL-UNNAMED -cp $RESJAR$ org.openj9.test.WorkLoad</command>
133+
<output type="success" caseSensitive="yes" regex="no">All runs complete</output>
134+
<output type="required" caseSensitive="yes" regex="no">0 / 100 complete</output>
135+
</test>
110136
</suite>

0 commit comments

Comments
 (0)