Skip to content

Commit

Permalink
Add command line option for dynamic agent loading
Browse files Browse the repository at this point in the history
Signed-off-by: Devin Nakamura <[email protected]>
  • Loading branch information
dnakamura committed Jun 8, 2023
1 parent 26c5e55 commit 86e7238
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 3 deletions.
2 changes: 2 additions & 0 deletions runtime/jvmti/j9jvmti.tdf
Original file line number Diff line number Diff line change
Expand Up @@ -658,3 +658,5 @@ TraceExit=Trc_JVMTI_jvmtiHookVirtualThreadUnmount_Exit Overhead=1 Level=5 Noenv

TraceEntry=Trc_JVMTI_jvmtiHookVirtualThreadMount_Entry Overhead=1 Level=5 Noenv Template="HookVirtualThreadMount"
TraceExit=Trc_JVMTI_jvmtiHookVirtualThreadMount_Exit Overhead=1 Level=5 Noenv Template="HookVirtualThreadMount"

TraceEvent=Trc_JVMTI_loadAgentLibraryOnAttach_agentLoadingDisabled Overhead=1 Level=5 Noenv Template="loadAgentLibraryOnAttach: Dynamic agent loading is is disabled"
13 changes: 13 additions & 0 deletions runtime/jvmti/jvmtiStartup.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,12 @@ loadAgentLibraryOnAttach(struct J9JavaVM * vm, const char * library, const char

Trc_JVMTI_loadAgentLibraryOnAttach_Entry(library);

if (J9_ARE_ANY_BITS_SET(vm->runtimeFlags, J9_RUNTIME_ALLOW_DYNAMIC_AGENT)){
Trc_JVMTI_loadAgentLibraryOnAttach_agentLoadingDisabled();
rc = JNI_ERR;
goto exit;
}

Assert_JVMTI_true(NULL != library); /* Library name must be non-null. */

if (NULL != options) {
Expand Down Expand Up @@ -701,6 +707,13 @@ loadAgentLibrary(J9JavaVM * vm, J9JVMTIAgentLibrary * agentLibrary)

Trc_JVMTI_loadAgentLibrary_Entry(agentLibrary->nativeLib.name);

/* If dynamic agent loading is disabled, the HCR/OSR flags default to off. */
omrthread_monitor_enter(vm->runtimeFlagsMutex);
if (J9_ARE_NO_BITS_SET(vm->runtimeFlags, J9_RUNTIME_ALLOW_DYNAMIC_AGENT)) {
vm->extendedRuntimeFlags |= (J9_EXTENDED_RUNTIME_OSR_SAFE_POINT | (UDATA)J9_EXTENDED_RUNTIME_ENABLE_HCR);
}
omrthread_monitor_exit(vm->runtimeFlagsMutex);

/* Attempt linking the agent statically, looking for Agent_OnLoad_L.
* If this is not found, fall back on the regular, dynamic linking way.
*/
Expand Down
2 changes: 1 addition & 1 deletion runtime/oti/j9consts.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ extern "C" {
#define J9_RUNTIME_ARGENCODING_UNICODE 0x2000
#define J9_RUNTIME_ARGENCODING_LATIN 0x4000
#define J9_RUNTIME_ARGENCODING_UTF8 0x8000
#define J9_RUNTIME_UNUSED_0x10000 0x10000
#define J9_RUNTIME_ALLOW_DYNAMIC_AGENT 0x10000
#define J9_RUNTIME_UNUSED_0x20000 0x20000
#define J9_RUNTIME_UNUSED_0x40000 0x40000
#define J9_RUNTIME_UNUSED_0x80000 0x80000
Expand Down
3 changes: 3 additions & 0 deletions runtime/oti/jvminit.h
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,9 @@ enum INIT_STAGE {
#define VMOPT_XSYSLOG_OPT "-Xsyslog"
#define MAPOPT_XSYSLOG_OPT_COLON "-Xsyslog:"

#define VMOPT_XXENABLEDYNAMICAGENTLOADING "-XX:+EnableDynamicAgentLoading"
#define VMOPT_XXNOENABLEDYNAMICAGENTLOADING "-XX:-EnableDynamicAgentLoading"

/* Modularity command line options */
#define VMOPT_MODULE_UPGRADE_PATH "--upgrade-module-path"
#define VMOPT_MODULE_PATH "--module-path"
Expand Down
14 changes: 12 additions & 2 deletions runtime/vm/jvminit.c
Original file line number Diff line number Diff line change
Expand Up @@ -3569,10 +3569,20 @@ processVMArgsFromFirstToLast(J9JavaVM * vm)
if (J2SE_VERSION(vm) >= J2SE_V11) {
vm->extendedRuntimeFlags |= (UDATA)J9_EXTENDED_RUNTIME_RESTRICT_IFA; /* Enable zAAP switching for Registered Natives and JVMTI callbacks by default in Java 9 and later. */
}
vm->extendedRuntimeFlags |= J9_EXTENDED_RUNTIME_OSR_SAFE_POINT; /* Enable OSR safe point by default */
vm->extendedRuntimeFlags |= (UDATA)J9_EXTENDED_RUNTIME_ENABLE_HCR; /* Enable HCR by default */
vm->extendedRuntimeFlags2 |= J9_EXTENDED_RUNTIME2_ENABLE_UTF_CACHE; /* Enable UTF cache by default */

{
IDATA noDynamicAgentLoading = FIND_AND_CONSUME_VMARG(EXACT_MATCH, VMOPT_XXNOENABLEDYNAMICAGENTLOADING, NULL);
IDATA dynamicAgentLoading = FIND_AND_CONSUME_VMARG(EXACT_MATCH, VMOPT_XXENABLEDYNAMICAGENTLOADING, NULL);
if (noDynamicAgentLoading > dynamicAgentLoading) {
vm->runtimeFlags &= J9_RUNTIME_ALLOW_DYNAMIC_AGENT;
vm->extendedRuntimeFlags &= ~(UDATA)(J9_EXTENDED_RUNTIME_OSR_SAFE_POINT | (UDATA) J9_EXTENDED_RUNTIME_ENABLE_HCR);
} else {
vm->runtimeFlags |= J9_RUNTIME_ALLOW_DYNAMIC_AGENT;
vm->extendedRuntimeFlags |= (J9_EXTENDED_RUNTIME_OSR_SAFE_POINT | (UDATA)J9_EXTENDED_RUNTIME_ENABLE_HCR);
}
}

#if defined(J9VM_ARCH_X86) || defined(J9VM_ARCH_POWER) || defined(J9VM_ARCH_S390)
/* Enabled field watch by default on x86, Power, and S390 platforms */
vm->extendedRuntimeFlags |= J9_EXTENDED_RUNTIME_JIT_INLINE_WATCHES;
Expand Down

0 comments on commit 86e7238

Please sign in to comment.