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

(0.47) Destroy virtual thread data after VirtualThreadEnd callback #19874

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions runtime/include/ibmjvmti.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@

#define COM_SUN_HOTSPOT_EVENTS_VIRTUAL_THREAD_MOUNT "com.sun.hotspot.events.VirtualThreadMount"
#define COM_SUN_HOTSPOT_EVENTS_VIRTUAL_THREAD_UNMOUNT "com.sun.hotspot.events.VirtualThreadUnmount"
#define COM_SUN_HOTSPOT_EVENTS_VIRTUAL_THREAD_DESTROY "com.sun.hotspot.events.VirtualThreadDestroy"

#define OPENJ9_EVENT_VM_CHECKPOINT "openj9.event.VMCheckpoint"
#define OPENJ9_EVENT_VM_RESTORE "openj9.event.VMRestore"
Expand Down
1 change: 1 addition & 0 deletions runtime/j9vm/javanextvmi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ JVM_VirtualThreadEnd(JNIEnv *env, jobject vthread)
TRIGGER_J9HOOK_VM_VIRTUAL_THREAD_END(vm->hookInterface, currentThread);
setContinuationStateToLastUnmount((J9VMThread *)env, vthread);
virtualThreadUnmountBegin(env, vthread);
TRIGGER_J9HOOK_VM_VIRTUAL_THREAD_DESTROY(vm->hookInterface, currentThread);

vmFuncs->internalExitVMToJNI(currentThread);

Expand Down
12 changes: 12 additions & 0 deletions runtime/jvmti/jvmtiExtensionMechanism.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,12 @@ static const jvmtiParamInfo jvmtiVirtualThreadUnmount_params[] = {
{ "jni_env", JVMTI_KIND_IN_PTR, JVMTI_TYPE_JNIENV, JNI_FALSE },
{ "thread", JVMTI_KIND_IN, JVMTI_TYPE_JTHREAD, JNI_FALSE }
};

/* (jvmtiEnv *jvmti_env, jthread thread) */
static const jvmtiParamInfo jvmtiVirtualThreadDestroy_params[] = {
{ "jni_env", JVMTI_KIND_IN_PTR, JVMTI_TYPE_JNIENV, JNI_FALSE },
{ "thread", JVMTI_KIND_IN, JVMTI_TYPE_JTHREAD, JNI_FALSE }
};
#endif /* JAVA_SPEC_VERSION >= 19 */

#if JAVA_SPEC_VERSION >= 19
Expand Down Expand Up @@ -906,6 +912,12 @@ static const J9JVMTIExtensionEventInfo J9JVMTIExtensionEventInfoTable[] = {
J9NLS_JVMTI_COM_SUN_HOTSPOT_EVENTS_VIRTUAL_THREAD_UNMOUNT,
SIZE_AND_TABLE(jvmtiVirtualThreadUnmount_params),
},
{
J9JVMTI_EVENT_COM_SUN_HOTSPOT_EVENTS_VIRTUAL_THREAD_DESTROY,
COM_SUN_HOTSPOT_EVENTS_VIRTUAL_THREAD_DESTROY,
J9NLS_JVMTI_COM_SUN_HOTSPOT_EVENTS_VIRTUAL_THREAD_DESTROY,
SIZE_AND_TABLE(jvmtiVirtualThreadDestroy_params),
},
#endif /* JAVA_SPEC_VERSION >= 19 */
#if defined(J9VM_OPT_CRIU_SUPPORT)
{
Expand Down
1 change: 1 addition & 0 deletions runtime/jvmti/jvmtiHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ static const UDATA reasonCodeFromJVMTIEvent[] = {
J9_JNI_OFFLOAD_SWITCH_J9JVMTI_GC_CYCLE_FINISH, /* J9JVMTI_EVENT_COM_IBM_GARBAGE_COLLECTION_CYCLE_FINISH */
J9_JNI_OFFLOAD_SWITCH_J9JVMTI_VIRTUAL_THREAD_MOUNT, /* J9JVMTI_EVENT_COM_SUN_HOTSPOT_EVENTS_VIRTUAL_THREAD_MOUNT */
J9_JNI_OFFLOAD_SWITCH_J9JVMTI_VIRTUAL_THREAD_UNMOUNT, /* J9JVMTI_EVENT_COM_SUN_HOTSPOT_EVENTS_VIRTUAL_THREAD_UNMOUNT */
J9_JNI_OFFLOAD_SWITCH_J9JVMTI_VIRTUAL_THREAD_DESTROY, /* J9JVMTI_EVENT_COM_SUN_HOTSPOT_EVENTS_VIRTUAL_THREAD_DESTROY */
J9_JNI_OFFLOAD_SWITCH_J9JVMTI_EVENT_OPENJ9_VM_CHECKPOINT, /* J9JVMTI_EVENT_OPENJ9_VM_CHECKPOINT */
J9_JNI_OFFLOAD_SWITCH_J9JVMTI_EVENT_OPENJ9_VM_RESTORE, /* J9JVMTI_EVENT_OPENJ9_VM_RESTORE */
};
Expand Down
4 changes: 2 additions & 2 deletions runtime/jvmti/jvmtiHook.c
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ 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);
hookUnregister(vmHook, J9HOOK_VM_VIRTUAL_THREAD_DESTROY, jvmtiHookVirtualThreadDestroy, NULL, j9env);
#endif /* JAVA_SPEC_VERSION >= 19 */
hookUnregister(vmHook, J9HOOK_VM_POP_FRAMES_INTERRUPT, jvmtiHookPopFramesInterrupt, NULL, j9env);

Expand All @@ -987,7 +987,7 @@ hookRequiredEvents(J9JVMTIEnv * j9env)
}

#if JAVA_SPEC_VERSION >= 19
if (hookRegister(vmHook, J9HOOK_VM_VIRTUAL_THREAD_END, jvmtiHookVirtualThreadDestroy, OMR_GET_CALLSITE(), j9env)) {
if (hookRegister(vmHook, J9HOOK_VM_VIRTUAL_THREAD_DESTROY, jvmtiHookVirtualThreadDestroy, OMR_GET_CALLSITE(), j9env)) {
return 1;
}
#endif /* JAVA_SPEC_VERSION >= 19 */
Expand Down
7 changes: 7 additions & 0 deletions runtime/nls/j9ti/jvmti.nls
Original file line number Diff line number Diff line change
Expand Up @@ -666,3 +666,10 @@ J9NLS_J9JVMTI_OPENJ9_FUNCTION_REMOVE_DEBUG_THREAD.explanation=Remove a JDWP thre
J9NLS_J9JVMTI_OPENJ9_FUNCTION_REMOVE_DEBUG_THREAD.system_action=None
J9NLS_J9JVMTI_OPENJ9_FUNCTION_REMOVE_DEBUG_THREAD.user_response=None
# END NON-TRANSLATABLE

J9NLS_JVMTI_COM_SUN_HOTSPOT_EVENTS_VIRTUAL_THREAD_DESTROY=Free native resources after a virtual thread ends.
# START NON-TRANSLATABLE
J9NLS_JVMTI_COM_SUN_HOTSPOT_EVENTS_VIRTUAL_THREAD_DESTROY.explanation=Internationalized description of a JVMTI extension
J9NLS_JVMTI_COM_SUN_HOTSPOT_EVENTS_VIRTUAL_THREAD_DESTROY.system_action=None
J9NLS_JVMTI_COM_SUN_HOTSPOT_EVENTS_VIRTUAL_THREAD_DESTROY.user_response=None
# END NON-TRANSLATABLE
2 changes: 1 addition & 1 deletion runtime/oti/j9consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ extern "C" {
#define J9_JNI_OFFLOAD_SWITCH_JVMTI_MONITOR_CONTENDED_ENTERED 0x30
#define J9_JNI_OFFLOAD_SWITCH_J9JVMTI_VIRTUAL_THREAD_MOUNT 0x31
#define J9_JNI_OFFLOAD_SWITCH_J9JVMTI_VIRTUAL_THREAD_UNMOUNT 0x32
/* 0x33 Reserved for JVMTI event */
#define J9_JNI_OFFLOAD_SWITCH_J9JVMTI_VIRTUAL_THREAD_DESTROY 0x33
#define J9_JNI_OFFLOAD_SWITCH_JVMTI_RESOURCE_EXHAUSTED 0x34
#define J9_JNI_OFFLOAD_SWITCH_JVMTI_GC_START 0x35
#define J9_JNI_OFFLOAD_SWITCH_JVMTI_GC_FINISH 0x36
Expand Down
10 changes: 10 additions & 0 deletions runtime/oti/j9vm.hdf
Original file line number Diff line number Diff line change
Expand Up @@ -1383,6 +1383,16 @@ typedef UDATA (* lookupNativeAddressCallback)(struct J9VMThread *currentThread,
<data type="struct J9VMThread*" name="currentThread" description="current thread" />
</event>

<event>
<name>J9HOOK_VM_VIRTUAL_THREAD_DESTROY</name>
<description>
Triggered after J9HOOK_VM_VIRTUAL_THREAD_END to free native resources.
currentThread->threadObject is the virtual thread at the point of trigger.
</description>
<struct>J9VMVirtualThreadDestroyEvent</struct>
<data type="struct J9VMThread*" name="currentThread" description="current thread" />
</event>

<event>
<name>J9HOOK_VM_CRIU_CHECKPOINT</name>
<description>Triggered at the end of CRIU checkpoint, just before CRIU dump</description>
Expand Down
1 change: 1 addition & 0 deletions runtime/oti/jvmtiInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ typedef enum {
J9JVMTI_EVENT_COM_IBM_GARBAGE_COLLECTION_CYCLE_FINISH,
J9JVMTI_EVENT_COM_SUN_HOTSPOT_EVENTS_VIRTUAL_THREAD_MOUNT,
J9JVMTI_EVENT_COM_SUN_HOTSPOT_EVENTS_VIRTUAL_THREAD_UNMOUNT,
J9JVMTI_EVENT_COM_SUN_HOTSPOT_EVENTS_VIRTUAL_THREAD_DESTROY,
J9JVMTI_EVENT_OPENJ9_VM_CHECKPOINT,
J9JVMTI_EVENT_OPENJ9_VM_RESTORE,
J9JVMTI_AFTER_LAST_EXTENSION_EVENT
Expand Down