From 2ffaacf482435098348af887d1daef422559ede7 Mon Sep 17 00:00:00 2001 From: Gengchen Tuo Date: Thu, 11 Jul 2024 15:35:46 -0400 Subject: [PATCH] Destroy virtual thread data after VirtualThreadEnd callback Currently destroyThreadData() is hooked onto the VirtualThreadEnd event which is called before the event callback. In JDWP, the agent uses TLS to associate nodes in the running thread list. Clearing TLS before the event callback makes the agent lose track of the node thus failed to remove existed virtual threads from the list. This commit removes jvmtiHookVirtualThreadDestroy() and calls destroyThreadData() directly inside jvmtiHookVirtualThreadEnd(). Fixes: https://github.com/ibmruntimes/Semeru-Runtimes/issues/80 https://github.com/eclipse-openj9/openj9/issues/19759 Signed-off-by: Gengchen Tuo --- runtime/jvmti/jvmtiHook.c | 26 +------------------------- 1 file changed, 1 insertion(+), 25 deletions(-) diff --git a/runtime/jvmti/jvmtiHook.c b/runtime/jvmti/jvmtiHook.c index fa52875bcb1..515ec972a96 100644 --- a/runtime/jvmti/jvmtiHook.c +++ b/runtime/jvmti/jvmtiHook.c @@ -147,7 +147,6 @@ static UDATA methodExists(J9Class * methodClass, U_8 * nameData, UDATA nameLengt #if JAVA_SPEC_VERSION >= 19 static void jvmtiHookVirtualThreadStarted (J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData); static void jvmtiHookVirtualThreadEnd (J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData); -static void jvmtiHookVirtualThreadDestroy (J9HookInterface **hook, UDATA eventNum, void *eventData, void *userData); static void jvmtiHookVirtualThreadMount (J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData); static void jvmtiHookVirtualThreadUnmount (J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData); #endif /* JAVA_SPEC_VERSION >= 19 */ @@ -412,25 +411,11 @@ jvmtiHookVirtualThreadEnd(J9HookInterface **hook, UDATA eventNum, void *eventDat } } - TRACE_JVMTI_EVENT_RETURN(jvmtiHookVirtualThreadEnd); -} - -static void -jvmtiHookVirtualThreadDestroy(J9HookInterface **hook, UDATA eventNum, void *eventData, void *userData) -{ - J9VirtualThreadEndEvent *data = eventData; - J9JVMTIEnv *j9env = userData; - J9VMThread *currentThread = data->currentThread; - - Trc_JVMTI_jvmtiHookVirtualThreadDestroy_Entry(); - - /* The final thread in the system is destroyed very late, JVMTI could be shut down by then. */ - if (NULL != currentThread->javaVM->jvmtiData) { destroyThreadData(j9env, currentThread); } - TRACE_JVMTI_EVENT_RETURN(jvmtiHookVirtualThreadDestroy); + TRACE_JVMTI_EVENT_RETURN(jvmtiHookVirtualThreadEnd); } /** @@ -967,9 +952,6 @@ unhookAllEvents(J9JVMTIEnv * j9env) } hookUnregister(vmHook, J9HOOK_VM_THREAD_DESTROY, jvmtiHookThreadDestroy, NULL, j9env); -#if JAVA_SPEC_VERSION >= 19 - hookUnregister(vmHook, J9HOOK_VM_VIRTUAL_THREAD_END, jvmtiHookVirtualThreadDestroy, NULL, j9env); -#endif /* JAVA_SPEC_VERSION >= 19 */ hookUnregister(vmHook, J9HOOK_VM_POP_FRAMES_INTERRUPT, jvmtiHookPopFramesInterrupt, NULL, j9env); hookUnregister(gcOmrHook, J9HOOK_MM_OMR_GLOBAL_GC_END, jvmtiHookGCEnd, NULL, j9env); @@ -986,12 +968,6 @@ hookRequiredEvents(J9JVMTIEnv * j9env) return 1; } -#if JAVA_SPEC_VERSION >= 19 - if (hookRegister(vmHook, J9HOOK_VM_VIRTUAL_THREAD_END, jvmtiHookVirtualThreadDestroy, OMR_GET_CALLSITE(), j9env)) { - return 1; - } -#endif /* JAVA_SPEC_VERSION >= 19 */ - return 0; }