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

Update getVirtualThreadState to handle all mounted scenarios #15968

Merged
merged 1 commit into from
Sep 28, 2022
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
120 changes: 61 additions & 59 deletions runtime/jvmti/jvmtiHelpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -789,69 +789,71 @@ getVirtualThreadState(J9VMThread *currentThread, jthread thread)
Assert_JVMTI_notNull(thread);
Assert_JVMTI_mustHaveVMAccess(currentThread);
if (JVMTI_ERROR_NONE == getVMThread(currentThread, thread, &targetThread, FALSE, FALSE)) {
j9object_t vThreadObject = J9_JNI_UNWRAP_REFERENCE(thread);
jint vThreadState = (jint) J9VMJAVALANGVIRTUALTHREAD_STATE(currentThread, vThreadObject);
/* The mapping from JVMTI_VTHREAD_STATE_XXX to JVMTI_JAVA_LANG_THREAD_STATE_XXX is based on j.l.VirtualThread.threadState(). */
switch (vThreadState) {
case JVMTI_VTHREAD_STATE_NEW:
rc = JVMTI_JAVA_LANG_THREAD_STATE_NEW;
break;
case JVMTI_VTHREAD_STATE_STARTED:
{
JNIEnv *env = (JNIEnv *)currentThread;
jfieldID fid = NULL;
jclass jlThread = NULL;

vm->internalVMFunctions->internalExitVMToJNI(currentThread);
jlThread = (*env)->FindClass(env, "java/lang/Thread");
if (NULL != jlThread) {
fid = (*env)->GetFieldID(env, jlThread, "container", "Ljdk/internal/vm/ThreadContainer;");
}
if ((NULL != fid)
&& (NULL == (*env)->GetObjectField(env, thread, fid))
) {
if (NULL != targetThread) {
vm->internalVMFunctions->haltThreadForInspection(currentThread, targetThread);
rc = getThreadState(currentThread, targetThread->carrierThreadObject);
vm->internalVMFunctions->resumeThreadForInspection(currentThread, targetThread);
} else {
j9object_t vThreadObject = J9_JNI_UNWRAP_REFERENCE(thread);
jint vThreadState = (jint) J9VMJAVALANGVIRTUALTHREAD_STATE(currentThread, vThreadObject);
/* The mapping from JVMTI_VTHREAD_STATE_XXX to JVMTI_JAVA_LANG_THREAD_STATE_XXX is based
* on j.l.VirtualThread.threadState().
*/
switch (vThreadState) {
case JVMTI_VTHREAD_STATE_NEW:
rc = JVMTI_JAVA_LANG_THREAD_STATE_NEW;
} else {
rc = JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLE;
break;
case JVMTI_VTHREAD_STATE_STARTED:
{
JNIEnv *env = (JNIEnv *)currentThread;
jfieldID fid = NULL;
jclass jlThread = NULL;

vm->internalVMFunctions->internalExitVMToJNI(currentThread);
jlThread = (*env)->FindClass(env, "java/lang/Thread");
if (NULL != jlThread) {
fid = (*env)->GetFieldID(env, jlThread, "container", "Ljdk/internal/vm/ThreadContainer;");
}
if ((NULL != fid)
&& (NULL == (*env)->GetObjectField(env, thread, fid))
) {
rc = JVMTI_JAVA_LANG_THREAD_STATE_NEW;
} else {
rc = JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLE;
}
vm->internalVMFunctions->internalEnterVMFromJNI(currentThread);
break;
}
vm->internalVMFunctions->internalEnterVMFromJNI(currentThread);
break;
}
case JVMTI_VTHREAD_STATE_RUNNABLE:
rc = JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLE;
break;
case JVMTI_VTHREAD_STATE_RUNNABLE_SUSPENDED:
rc = JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLE | JVMTI_THREAD_STATE_SUSPENDED;
break;
case JVMTI_VTHREAD_STATE_RUNNING:
if (NULL != targetThread) {
vm->internalVMFunctions->haltThreadForInspection(currentThread, targetThread);
rc = getThreadState(currentThread, targetThread->carrierThreadObject);
vm->internalVMFunctions->resumeThreadForInspection(currentThread, targetThread);
} else {
case JVMTI_VTHREAD_STATE_RUNNABLE:
rc = JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLE;
break;
case JVMTI_VTHREAD_STATE_RUNNABLE_SUSPENDED:
rc = JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLE | JVMTI_THREAD_STATE_SUSPENDED;
break;
case JVMTI_VTHREAD_STATE_RUNNING:
rc = JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLE;
break;
case JVMTI_VTHREAD_STATE_PARKING:
/* Fall Through */
case JVMTI_VTHREAD_STATE_YIELDING:
rc = JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLE;
break;
case JVMTI_VTHREAD_STATE_PARKED:
rc = JVMTI_JAVA_LANG_THREAD_STATE_WAITING | JVMTI_THREAD_STATE_PARKED;
break;
case JVMTI_VTHREAD_STATE_PARKED_SUSPENDED:
rc = JVMTI_JAVA_LANG_THREAD_STATE_WAITING | JVMTI_THREAD_STATE_PARKED | JVMTI_THREAD_STATE_SUSPENDED;
break;
case JVMTI_VTHREAD_STATE_PINNED:
rc = JVMTI_JAVA_LANG_THREAD_STATE_WAITING;
break;
case JVMTI_VTHREAD_STATE_TERMINATED:
rc = JVMTI_JAVA_LANG_THREAD_STATE_TERMINATED;
break;
default:
Assert_JVMTI_unreachable();
rc = JVMTI_ERROR_INTERNAL;
}
break;
case JVMTI_VTHREAD_STATE_PARKING:
/* Fall Through */
case JVMTI_VTHREAD_STATE_YIELDING:
rc = JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLE;
break;
case JVMTI_VTHREAD_STATE_PARKED:
rc = JVMTI_JAVA_LANG_THREAD_STATE_WAITING | JVMTI_THREAD_STATE_PARKED;
break;
case JVMTI_VTHREAD_STATE_PARKED_SUSPENDED:
rc = JVMTI_JAVA_LANG_THREAD_STATE_WAITING | JVMTI_THREAD_STATE_PARKED | JVMTI_THREAD_STATE_SUSPENDED;
break;
case JVMTI_VTHREAD_STATE_PINNED:
rc = JVMTI_JAVA_LANG_THREAD_STATE_WAITING;
break;
case JVMTI_VTHREAD_STATE_TERMINATED:
rc = JVMTI_JAVA_LANG_THREAD_STATE_TERMINATED;
break;
default:
Assert_JVMTI_unreachable();
rc = JVMTI_ERROR_INTERNAL;
}
releaseVMThread(currentThread, targetThread, thread);
} else {
Expand Down