@@ -926,8 +926,9 @@ jvmtiGetCurrentContendedMonitor(jvmtiEnv *env,
926
926
rc = getCurrentVMThread (vm, ¤tThread);
927
927
if (JVMTI_ERROR_NONE == rc) {
928
928
J9VMThread *targetThread = NULL ;
929
+ J9InternalVMFunctions const * const vmFuncs = vm->internalVMFunctions ;
929
930
930
- vm-> internalVMFunctions ->internalEnterVMFromJNI (currentThread);
931
+ vmFuncs ->internalEnterVMFromJNI (currentThread);
931
932
932
933
ENSURE_PHASE_LIVE (env);
933
934
ENSURE_CAPABILITY (env, can_get_current_contended_monitor);
@@ -944,35 +945,51 @@ jvmtiGetCurrentContendedMonitor(jvmtiEnv *env,
944
945
#if JAVA_SPEC_VERSION >= 19
945
946
j9object_t threadObject = (NULL == thread) ? currentThread->threadObject : J9_JNI_UNWRAP_REFERENCE (thread);
946
947
947
- /* Unmounted VirtualThread and CarrierThread with VirtualThread mounted cannot be contended. */
948
- if (((NULL == targetThread) && IS_JAVA_LANG_VIRTUALTHREAD (currentThread, threadObject))
949
- || ((NULL != targetThread) && (threadObject == targetThread->carrierThreadObject ) && (NULL != targetThread->currentContinuation ))
950
- ) {
948
+ if ((NULL == targetThread) && IS_JAVA_LANG_VIRTUALTHREAD (currentThread, threadObject)) {
949
+ #if JAVA_SPEC_VERSION >= 24
950
+ j9object_t continuationObject = J9VMJAVALANGVIRTUALTHREAD_CONT (currentThread, threadObject);
951
+
952
+ if (NULL != continuationObject) {
953
+ j9object_t syncObject = J9VMJDKINTERNALVMCONTINUATION_BLOCKER (currentThread, continuationObject);
954
+
955
+ /* Check if the Continuation.blocker field is set. */
956
+ if (NULL != syncObject) {
957
+ U_32 state = J9VMJAVALANGVIRTUALTHREAD_STATE (currentThread, threadObject);
958
+ if ((JVMTI_VTHREAD_STATE_BLOCKING == state) || (JVMTI_VTHREAD_STATE_BLOCKED == state)) {
959
+ rv_monitor = (jobject)vmFuncs->j9jni_createLocalRef ((JNIEnv *)currentThread, syncObject);
960
+ }
961
+ }
962
+ }
963
+ #endif /* JAVA_SPEC_VERSION >= 24 */
964
+ /* Prior to JDK24, an unmounted VirtualThread cannot be contended. */
965
+ goto release;
966
+ } else if ((NULL != targetThread) && (threadObject == targetThread->carrierThreadObject ) && (NULL != targetThread->currentContinuation )) {
967
+ /* CarrierThread with VirtualThread mounted cannot be contended. */
951
968
goto release;
952
969
}
953
970
#endif /* JAVA_SPEC_VERSION >= 19 */
954
971
955
972
/* CMVC 184481 - The targetThread should be suspended while we attempt to get its state. */
956
- vm-> internalVMFunctions ->haltThreadForInspection (currentThread, targetThread);
973
+ vmFuncs ->haltThreadForInspection (currentThread, targetThread);
957
974
958
975
vmstate = getVMThreadObjectStatesAll (targetThread, &lockObject, NULL , NULL );
959
976
960
977
if ((NULL != lockObject)
961
978
&& (OMR_ARE_NO_BITS_SET (vmstate, J9VMTHREAD_STATE_PARKED | J9VMTHREAD_STATE_PARKED_TIMED))
962
979
) {
963
- rv_monitor = (jobject)vm-> internalVMFunctions ->j9jni_createLocalRef ((JNIEnv *)currentThread, lockObject);
980
+ rv_monitor = (jobject)vmFuncs ->j9jni_createLocalRef ((JNIEnv *)currentThread, lockObject);
964
981
} else {
965
982
rv_monitor = NULL ;
966
983
}
967
984
968
- vm-> internalVMFunctions ->resumeThreadForInspection (currentThread, targetThread);
985
+ vmFuncs ->resumeThreadForInspection (currentThread, targetThread);
969
986
#if JAVA_SPEC_VERSION >= 19
970
987
release:
971
988
#endif /* JAVA_SPEC_VERSION >= 19 */
972
989
releaseVMThread (currentThread, targetThread, thread);
973
990
}
974
991
done:
975
- vm-> internalVMFunctions ->internalExitVMToJNI (currentThread);
992
+ vmFuncs ->internalExitVMToJNI (currentThread);
976
993
}
977
994
978
995
if (NULL != monitor_ptr) {
0 commit comments