Skip to content

Commit

Permalink
Merge pull request #16996 from fengxue-IS/16983
Browse files Browse the repository at this point in the history
(0.37) Fix GetCurrentContendedMonitor on mounted CarrierThread
  • Loading branch information
babsingh authored Mar 22, 2023
2 parents bfd1f32 + 3b4a0bf commit 934ce94
Showing 1 changed file with 5 additions and 15 deletions.
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

0 comments on commit 934ce94

Please sign in to comment.