From c528fab49f91695d4aab2da15d8c68b2eafdc1f4 Mon Sep 17 00:00:00 2001 From: Babneet Singh Date: Wed, 15 Nov 2023 20:05:32 -0500 Subject: [PATCH] Make java.lang.Thread.container a known field java.lang.Thread.container is added in vmconstantpool.xml. Accessing java.lang.Thread.container as a known field simplifies and fixes the incorrect error handling in getVirtualThreadState. Signed-off-by: Babneet Singh --- runtime/jvmti/jvmtiHelpers.cpp | 17 ++--------------- runtime/oti/vmconstantpool.xml | 1 + 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/runtime/jvmti/jvmtiHelpers.cpp b/runtime/jvmti/jvmtiHelpers.cpp index 3f0b28d1373..de5338a01b9 100644 --- a/runtime/jvmti/jvmtiHelpers.cpp +++ b/runtime/jvmti/jvmtiHelpers.cpp @@ -846,25 +846,12 @@ getVirtualThreadState(J9VMThread *currentThread, jthread thread) break; case JVMTI_VTHREAD_STATE_STARTED: { - JNIEnv *env = (JNIEnv *)currentThread; - jfieldID fid = NULL; - jclass jlThread = NULL; - - vm->internalVMFunctions->internalExitVMToJNI(currentThread); - jlThread = env->FindClass("java/lang/Thread"); - if (NULL != jlThread) { - fid = env->GetFieldID(jlThread, "container", "Ljdk/internal/vm/ThreadContainer;"); - } - if ((NULL != fid) - && (NULL == env->GetObjectField(thread, fid)) - ) { + j9object_t threadContainer = J9VMJAVALANGTHREAD_CONTAINER(currentThread, vThreadObject); + if (NULL == threadContainer) { rc = JVMTI_JAVA_LANG_THREAD_STATE_NEW; } else { rc = JVMTI_JAVA_LANG_THREAD_STATE_RUNNABLE; } - vm->internalVMFunctions->internalEnterVMFromJNI(currentThread); - /* Re-fetch object to correctly set the isSuspendedInternal field. */ - vThreadObject = J9_JNI_UNWRAP_REFERENCE(thread); break; } case JVMTI_VTHREAD_STATE_RUNNABLE: diff --git a/runtime/oti/vmconstantpool.xml b/runtime/oti/vmconstantpool.xml index 8ab519f20ce..1f6db643343 100644 --- a/runtime/oti/vmconstantpool.xml +++ b/runtime/oti/vmconstantpool.xml @@ -247,6 +247,7 @@ SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-ex +