Skip to content

Commit

Permalink
Fix jvmtiGetVirtualThread and make it more robust
Browse files Browse the repository at this point in the history
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: eclipse-openj9#16688
Related: eclipse-openj9#16751

Signed-off-by: Babneet Singh <sbabneet@ca.ibm.com>
  • Loading branch information
babsingh committed Feb 27, 2023
1 parent 9bf20a0 commit 86709c3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions runtime/jvmti/jvmtiExtensionMechanism.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 86709c3

Please sign in to comment.