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

(v0.29.1-release) JVMTI trigger VMStart event according to can_generate_early_vmstart #13747

Merged
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: 0 additions & 1 deletion runtime/j9vm/java11vmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,6 @@ JVM_DefineModule(JNIEnv * env, jobject module, jboolean isOpen, jstring version,
}

vm->runtimeFlags |= J9_RUNTIME_JAVA_BASE_MODULE_CREATED;
TRIGGER_J9HOOK_JAVA_BASE_LOADED(vm->hookInterface, currentThread);
Trc_MODULE_defineModule(currentThread, "java.base", j9mod);
}

Expand Down
6 changes: 5 additions & 1 deletion runtime/jcl/common/stdinit.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 1998, 2020 IBM Corp. and others
* Copyright (c) 1998, 2021 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -209,6 +209,10 @@ standardInit( J9JavaVM *vm, char *dllName)
vmFuncs->internalReleaseVMAccess(vmThread);
#endif /* J9VM_INTERP_ATOMIC_FREE_JNI */
vmFuncs->initializeAttachedThread(vmThread, threadName, (j9object_t *)threadGroup, FALSE, vmThread);
#if JAVA_SPEC_VERSION >= 11
/* Trigger the VMStart event via jvmtiHookVMStarted handler if the can_generate_early_vmstart capability is set */
TRIGGER_J9HOOK_JAVA_BASE_LOADED(vm->hookInterface, vmThread);
#endif /* JAVA_SPEC_VERSION >= 11 */

vmFuncs->internalAcquireVMAccess(vmThread);

Expand Down
77 changes: 34 additions & 43 deletions runtime/jvmti/jvmtiHook.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ processEvent(J9JVMTIEnv* j9env, jint event, J9HookRedirectorFunction redirectorF

case JVMTI_EVENT_VM_START:
return redirectorFunction(vmHook, J9HOOK_VM_STARTED, jvmtiHookVMStarted, OMR_GET_CALLSITE(), j9env)
#if JAVA_SPEC_VERSION >= 9
&& redirectorFunction(vmHook, J9HOOK_JAVA_BASE_LOADED, jvmtiHookModuleSystemStarted, OMR_GET_CALLSITE(), j9env)
# endif /* JAVA_SPEC_VERSION >= 9 */
#if JAVA_SPEC_VERSION >= 11
|| redirectorFunction(vmHook, J9HOOK_JAVA_BASE_LOADED, jvmtiHookModuleSystemStarted, OMR_GET_CALLSITE(), j9env)
# endif /* JAVA_SPEC_VERSION >= 11 */
;

case JVMTI_EVENT_VM_DEATH:
Expand Down Expand Up @@ -590,73 +590,64 @@ jvmtiHookVMStartedFirst(J9HookInterface** hook, UDATA eventNum, void* eventData,
static void
jvmtiHookVMStarted(J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData)
{
J9VMInitEvent * data = eventData;
J9JVMTIEnv * j9env = userData;
jvmtiEventVMStart callback = j9env->callbacks.VMStart;

Trc_JVMTI_jvmtiHookVMStarted_Entry();

if (callback != NULL) {
J9VMThread *currentThread = data->vmThread;
UDATA hadVMAccess;
UDATA javaOffloadOldState = 0;
if (NULL != callback) {
BOOLEAN reportEvent = TRUE;

#if JAVA_SPEC_VERSION >= 9
J9JavaVM *vm = currentThread->javaVM;
if (J2SE_VERSION(vm) >= J2SE_V11) {
if (j9env->capabilities.can_generate_early_vmstart == 0) {
reportEvent = FALSE;
}
}
#endif /* JAVA_SPEC_VERSION >= 9 */
if (TRUE == reportEvent) {
if (prepareForEvent(j9env, currentThread, currentThread, JVMTI_EVENT_VM_START, NULL, &hadVMAccess, FALSE, 0, &javaOffloadOldState)) {
callback((jvmtiEnv *) j9env, (JNIEnv *) currentThread);
finishedEvent(currentThread, JVMTI_EVENT_VM_START, hadVMAccess, javaOffloadOldState);
}
}
#if JAVA_SPEC_VERSION >= 11
if (0 != j9env->capabilities.can_generate_early_vmstart) {
JasonFengJ9 marked this conversation as resolved.
Show resolved Hide resolved
/* VMStart event is already triggered via the jvmtiHookModuleSystemStarted handler */
reportEvent = FALSE;
}
#endif /* JAVA_SPEC_VERSION >= 11 */
if (reportEvent) {
J9VMThread *currentThread = ((J9VMInitEvent *)eventData)->vmThread;
UDATA hadVMAccess = 0;
UDATA javaOffloadOldState = 0;
if (prepareForEvent(j9env, currentThread, currentThread, JVMTI_EVENT_VM_START, NULL, &hadVMAccess, FALSE, 0, &javaOffloadOldState)) {
callback((jvmtiEnv *) j9env, (JNIEnv *) currentThread);
finishedEvent(currentThread, JVMTI_EVENT_VM_START, hadVMAccess, javaOffloadOldState);
}
}
}

TRACE_JVMTI_EVENT_RETURN(jvmtiHookVMStarted);
}

#if JAVA_SPEC_VERSION >= 9
#if JAVA_SPEC_VERSION >= 11
static void
jvmtiHookModuleSystemStarted(J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData) {
J9VMModuleStartEvent * data = eventData;
J9JVMTIEnv * j9env = userData;
jvmtiEventVMStart callback = j9env->callbacks.VMStart;
J9VMThread *currentThread = data->vmThread;
J9JavaVM *vm = currentThread->javaVM;
J9VMThread *currentThread = ((J9VMModuleStartEvent *)eventData)->vmThread;

Trc_JVMTI_jvmtiHookModuleSystemStarted_Entry();

Assert_JVMTI_true(J9_ARE_ALL_BITS_SET(vm->runtimeFlags, J9_RUNTIME_JAVA_BASE_MODULE_CREATED));
Assert_JVMTI_true(J2SE_VERSION(vm) >= J2SE_V11);
Assert_JVMTI_true(J9_ARE_ALL_BITS_SET(currentThread->javaVM->runtimeFlags, J9_RUNTIME_JAVA_BASE_MODULE_CREATED));

/*
* In Java9 the VMStart event can be triggered from either the J9HOOK_VM_STARTED
* hook or J9HOOK_JAVA_BASE_LOADED. If the can_generate_early_vmstart capability is set
* we can trigger this event as early as possible in the jvmtiHookVMStarted handler.
* Otherwise we have to wait until we have loaded java.base and trigger the VMStart event
* here (jvmtiHookModuleSystemStarted handler).
* Since Java9 the VMStart event can be triggered from either the J9HOOK_VM_STARTED hook or J9HOOK_JAVA_BASE_LOADED.
* If the can_generate_early_vmstart capability is set, we can trigger this event as early as possible here
* (jvmtiHookModuleSystemStarted handler). Otherwise we have to wait until JavaVM initialization is finished,
* and trigger the VMStart event in the jvmtiHookVMStarted handler.
*/

if (callback != NULL) {
UDATA hadVMAccess;
if ((NULL != callback)
&& (0 != j9env->capabilities.can_generate_early_vmstart)
) {
UDATA javaOffloadOldState = 0;

if (j9env->capabilities.can_generate_early_vmstart == 0) {
if (prepareForEvent(j9env, currentThread, currentThread, JVMTI_EVENT_VM_START, NULL, &hadVMAccess, FALSE, 0, &javaOffloadOldState)) {
callback((jvmtiEnv *) j9env, (JNIEnv *) currentThread);
finishedEvent(currentThread, JVMTI_EVENT_VM_START, hadVMAccess, javaOffloadOldState);
}
UDATA hadVMAccess = 0;
if (prepareForEvent(j9env, currentThread, currentThread, JVMTI_EVENT_VM_START, NULL, &hadVMAccess, FALSE, 0, &javaOffloadOldState)) {
callback((jvmtiEnv *) j9env, (JNIEnv *) currentThread);
finishedEvent(currentThread, JVMTI_EVENT_VM_START, hadVMAccess, javaOffloadOldState);
}
}
TRACE_JVMTI_EVENT_RETURN(jvmtiHookModuleSystemStarted);
}
#endif /* JAVA_SPEC_VERSION >= 9 */
#endif /* JAVA_SPEC_VERSION >= 11 */


static void
Expand Down