diff --git a/runtime/jvmti/jvmtiHelpers.cpp b/runtime/jvmti/jvmtiHelpers.cpp index de5338a01b9..46910703a76 100644 --- a/runtime/jvmti/jvmtiHelpers.cpp +++ b/runtime/jvmti/jvmtiHelpers.cpp @@ -148,16 +148,21 @@ getVMThread(J9VMThread *currentThread, jthread thread, J9VMThread **vmThreadPtr, } } +#if JAVA_SPEC_VERSION >= 19 + isVirtualThread = IS_JAVA_LANG_VIRTUALTHREAD(currentThread, threadObject); + if (isVirtualThread) { + vm->internalVMFunctions->acquireVThreadInspector(currentThread, thread, TRUE); + /* Re-fetch threadObject since acquireVThreadInspector can release and reacquire VM access. */ + threadObject = J9_JNI_UNWRAP_REFERENCE(thread); + } +#endif /* JAVA_SPEC_VERSION >= 19 */ + /* Make sure the vmThread stays alive while it is being used. */ omrthread_monitor_enter(vm->vmThreadListMutex); #if JAVA_SPEC_VERSION >= 19 - isVirtualThread = IS_JAVA_LANG_VIRTUALTHREAD(currentThread, threadObject); if (isVirtualThread) { jint vthreadState = 0; j9object_t carrierThread = NULL; - vm->internalVMFunctions->acquireVThreadInspector(currentThread, thread, TRUE); - /* Re-fetch threadObject since acquireVThreadInspector can release and reacquire VM access. */ - threadObject = J9_JNI_UNWRAP_REFERENCE(thread); vthreadState = J9VMJAVALANGVIRTUALTHREAD_STATE(currentThread, threadObject); carrierThread = (j9object_t)J9VMJAVALANGVIRTUALTHREAD_CARRIERTHREAD(currentThread, threadObject); if (NULL != carrierThread) { @@ -173,12 +178,12 @@ getVMThread(J9VMThread *currentThread, jthread thread, J9VMThread **vmThreadPtr, if (!isThreadAlive) { if (OMR_ARE_ANY_BITS_SET(flags, J9JVMTI_GETVMTHREAD_ERROR_ON_DEAD_THREAD)) { + omrthread_monitor_exit(vm->vmThreadListMutex); #if JAVA_SPEC_VERSION >= 19 if (isVirtualThread) { vm->internalVMFunctions->releaseVThreadInspector(currentThread, thread); } #endif /* JAVA_SPEC_VERSION >= 19 */ - omrthread_monitor_exit(vm->vmThreadListMutex); return JVMTI_ERROR_THREAD_NOT_ALIVE; } } @@ -861,18 +866,14 @@ getVirtualThreadState(J9VMThread *currentThread, jthread thread) case JVMTI_VTHREAD_STATE_YIELDING: rc = JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLE; break; + case JVMTI_VTHREAD_STATE_PINNED: case JVMTI_VTHREAD_STATE_PARKED: rc = JVMTI_JAVA_LANG_THREAD_STATE_WAITING | JVMTI_THREAD_STATE_PARKED; break; + case JVMTI_VTHREAD_STATE_TIMED_PINNED: case JVMTI_VTHREAD_STATE_TIMED_PARKED: rc = JVMTI_JAVA_LANG_THREAD_STATE_TIMED_WAITING | JVMTI_THREAD_STATE_PARKED; break; - case JVMTI_VTHREAD_STATE_PINNED: - rc = JVMTI_JAVA_LANG_THREAD_STATE_WAITING; - break; - case JVMTI_VTHREAD_STATE_TIMED_PINNED: - rc = JVMTI_JAVA_LANG_THREAD_STATE_TIMED_WAITING; - break; case JVMTI_VTHREAD_STATE_TERMINATED: rc = JVMTI_JAVA_LANG_THREAD_STATE_TERMINATED; break;