Skip to content

Commit

Permalink
Merge pull request #18662 from babsingh/18660_042
Browse files Browse the repository at this point in the history
(0.42) Fix GetThreadStateTest
  • Loading branch information
pshipton authored Dec 20, 2023
2 parents 012884b + f50d655 commit 69b6ceb
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions runtime/jvmti/jvmtiHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 69b6ceb

Please sign in to comment.