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

(0.37) Fix GetCurrentContendedMonitor on mounted CarrierThread #16996

Merged
merged 1 commit into from
Mar 22, 2023
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
20 changes: 5 additions & 15 deletions runtime/jvmti/jvmtiThread.c
Original file line number Diff line number Diff line change
Expand Up @@ -864,32 +864,22 @@ jvmtiGetCurrentContendedMonitor(jvmtiEnv *env,
if (JVMTI_ERROR_NONE == rc) {
j9object_t lockObject = NULL;
UDATA vmstate = 0;
J9VMThread *threadToWalk = targetThread;

#if JAVA_SPEC_VERSION >= 19
J9VMThread stackThread = {0};
J9VMEntryLocalStorage els = {0};
j9object_t threadObject = (NULL == thread) ? currentThread->threadObject : J9_JNI_UNWRAP_REFERENCE(thread);
J9VMContinuation *continuation = NULL;

if ((NULL == targetThread) && IS_JAVA_LANG_VIRTUALTHREAD(currentThread, threadObject)) {
/* Unmounted VirtualThread and CarrierThread with VirtualThread mounted cannot be contended. */
if (((NULL == targetThread) && IS_JAVA_LANG_VIRTUALTHREAD(currentThread, threadObject))
|| ((NULL != targetThread) && (threadObject == targetThread->carrierThreadObject) && (NULL != targetThread->currentContinuation))
) {
goto release;
}
#endif /* JAVA_SPEC_VERSION >= 19 */

/* CMVC 184481 - The targetThread should be suspended while we attempt to get its state. */
vm->internalVMFunctions->haltThreadForInspection(currentThread, targetThread);

#if JAVA_SPEC_VERSION >= 19
continuation = getJ9VMContinuationToWalk(currentThread, targetThread, threadObject);
if (NULL != continuation) {
memcpy(&stackThread, targetThread, sizeof(J9VMThread));
vm->internalVMFunctions->copyFieldsFromContinuation(currentThread, &stackThread, &els, continuation);
threadToWalk = &stackThread;
}
#endif /* JAVA_SPEC_VERSION >= 19 */

vmstate = getVMThreadObjectStatesAll(threadToWalk, &lockObject, NULL, NULL);
vmstate = getVMThreadObjectStatesAll(targetThread, &lockObject, NULL, NULL);

if ((NULL != lockObject)
&& (OMR_ARE_NO_BITS_SET(vmstate, J9VMTHREAD_STATE_PARKED | J9VMTHREAD_STATE_PARKED_TIMED))
Expand Down