From 86709c33536b8792b8bc214c1a4dab58d5944175 Mon Sep 17 00:00:00 2001 From: Babneet Singh Date: Mon, 27 Feb 2023 13:59:06 -0800 Subject: [PATCH] Fix jvmtiGetVirtualThread and make it more robust If no virtual thread is mounted on the targetThread i.e. carrierThreadObject == threadObject, then return null for the output virtual thread value. Virtual thread is not pinned in this function. So, read threadObject and carrierThreadObject once and store their values to avoid inconsistency. Related: #16688 Related: #16751 Signed-off-by: Babneet Singh --- runtime/jvmti/jvmtiExtensionMechanism.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/runtime/jvmti/jvmtiExtensionMechanism.c b/runtime/jvmti/jvmtiExtensionMechanism.c index 9dd2b0f6463..961789e3f9c 100644 --- a/runtime/jvmti/jvmtiExtensionMechanism.c +++ b/runtime/jvmti/jvmtiExtensionMechanism.c @@ -3805,10 +3805,14 @@ jvmtiGetVirtualThread(jvmtiEnv* jvmti_env, ...) currentThread, carrier_thread, &targetThread, JVMTI_ERROR_NONE, J9JVMTI_GETVMTHREAD_ERROR_ON_DEAD_THREAD); if (JVMTI_ERROR_NONE == rc) { - if (NULL != targetThread->threadObject) { + j9object_t threadObject = targetThread->threadObject; + j9object_t carrierThreadObject = targetThread->carrierThreadObject; + if ((NULL != threadObject) + && (threadObject != carrierThreadObject) + ) { rv_virtual_thread = (jthread)vm->internalVMFunctions->j9jni_createLocalRef( (JNIEnv *)currentThread, - (j9object_t)targetThread->threadObject); + (j9object_t)threadObject); } releaseVMThread(currentThread, targetThread, carrier_thread); }