From 2a7753570946dd9741d69745c1240fb9bd114706 Mon Sep 17 00:00:00 2001 From: Nick Kamal Date: Tue, 19 Nov 2024 14:28:35 -0500 Subject: [PATCH 1/6] Print actual string arguments with -Xtrace (part 2) The changes reflect the feature request #16416. Adding cmdline option to specify string argument length. -Xtrace:methodstrarglen=[1-128] methodStrArgLen takes an unsigned integer value from 1 to 128 If methodStrArgLen = 0 or unspecified, default to 32. Other invalid inputs result in the input error. There will be subsequent PR for tests (part 3). Signed-off-by: Nick Kamal --- runtime/oti/j9trace.h | 1 + runtime/rastrace/j9rastrace.h | 14 +++++---- runtime/rastrace/method_trace.c | 7 +++++ runtime/rastrace/method_trigger.c | 48 +++++++++++++++++++++++++++++-- runtime/rastrace/trcengine.c | 1 + 5 files changed, 62 insertions(+), 9 deletions(-) diff --git a/runtime/oti/j9trace.h b/runtime/oti/j9trace.h index 03fe720b4a0..ec6624c0e00 100644 --- a/runtime/oti/j9trace.h +++ b/runtime/oti/j9trace.h @@ -63,6 +63,7 @@ typedef struct RasGlobalStorage { void * traceMethodTable; int stackdepth; unsigned int stackCompressionLevel; + unsigned int methodStrArgLength; ConfigureTraceFunction configureTraceEngine; #if defined(J9VM_OPT_CRIU_SUPPORT) CRIURestoreInitializeTrace criuRestoreInitializeTrace; diff --git a/runtime/rastrace/j9rastrace.h b/runtime/rastrace/j9rastrace.h index d754ec60f0d..9b1c08e47d8 100644 --- a/runtime/rastrace/j9rastrace.h +++ b/runtime/rastrace/j9rastrace.h @@ -48,12 +48,13 @@ extern "C" { * Keywords for options added by J9VM layer. * ============================================================================= */ -#define RAS_METHODS_KEYWORD "METHODS" -#define RAS_DEBUG_KEYWORD "DEBUG" -#define RAS_TRIGGER_KEYWORD "TRIGGER" -#define RAS_STACKDEPTH_KEYWORD "STACKDEPTH" -#define RAS_SLEEPTIME_KEYWORD "SLEEPTIME" -#define RAS_COMPRESSION_LEVEL_KEYWORD "STACKCOMPRESSIONLEVEL" +#define RAS_METHODS_KEYWORD "METHODS" +#define RAS_DEBUG_KEYWORD "DEBUG" +#define RAS_TRIGGER_KEYWORD "TRIGGER" +#define RAS_STACKDEPTH_KEYWORD "STACKDEPTH" +#define RAS_SLEEPTIME_KEYWORD "SLEEPTIME" +#define RAS_COMPRESSION_LEVEL_KEYWORD "STACKCOMPRESSIONLEVEL" +#define RAS_METHOD_STRING_LENGTH_KEYWORD "METHODSTRARGLEN" /* * ====================================================================== @@ -130,6 +131,7 @@ omr_error_t processTriggerMethodClause(OMR_VMThread *, char *, BOOLEAN atRuntime void doTriggerActionJstacktrace(OMR_VMThread *thr); omr_error_t setStackDepth(J9JavaVM *thr, const char * value, BOOLEAN atRuntime); omr_error_t setStackCompressionLevel(J9JavaVM * vm, const char *str, BOOLEAN atRuntime); +omr_error_t setMethodStrArgLength(J9JavaVM * vm, const char *str, BOOLEAN atRuntime); /* * ============================================================================= diff --git a/runtime/rastrace/method_trace.c b/runtime/rastrace/method_trace.c index 82b3eb207d5..f6be41d288c 100644 --- a/runtime/rastrace/method_trace.c +++ b/runtime/rastrace/method_trace.c @@ -30,6 +30,9 @@ #undef UT_MODULE_UNLOADED #include "ut_mt.h" +#define DEFAULT_BUFFER_LENGTH 128 +#define DEFAULT_STRING_LENGTH 32 + static void hookRAMClassLoad(J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData); static void traceMethodArgInt (J9VMThread *thr, UDATA* arg0EA, char* cursor, UDATA length, char* type); static void traceMethodArgDouble (J9VMThread *thr, UDATA* arg0EA, char* cursor, UDATA length); @@ -476,12 +479,16 @@ traceMethodArgObject(J9VMThread *thr, UDATA* arg0EA, char* cursor, UDATA length) } else { J9Class *clazz = J9OBJECT_CLAZZ(thr, object); J9JavaVM *vm = thr->javaVM; + const unsigned int methodStrArgLength = ((RasGlobalStorage *)thr->javaVM->j9rasGlobalStorage)->methodStrArgLength; + unsigned int strArgLength = methodStrArgLength == 0 ? DEFAULT_STRING_LENGTH : methodStrArgLength; if (clazz == J9VMJAVALANGSTRING_OR_NULL(vm)) { /* string argument */ #define DEFAULT_STRING_LENGTH 32 char utf8Buffer[128]; UDATA utf8Length = 0; + const unsigned int methodStrArgLength = ((RasGlobalStorage *)thr->javaVM->j9rasGlobalStorage)->methodStrArgLength; + unsigned int strArgLength = methodStrArgLength == 0 ? DEFAULT_STRING_LENGTH : methodStrArgLength; char *utf8String = vm->internalVMFunctions->copyStringToUTF8WithMemAlloc( thr, diff --git a/runtime/rastrace/method_trigger.c b/runtime/rastrace/method_trigger.c index cccaddde31f..ba815a30cc2 100644 --- a/runtime/rastrace/method_trigger.c +++ b/runtime/rastrace/method_trigger.c @@ -60,7 +60,6 @@ static const StackTraceFormattingFunction stackTraceFormattingFunctions[] = { #define NUM_STACK_TRACE_FORMATTING_FUNCTIONS (sizeof(stackTraceFormattingFunctions) / sizeof(stackTraceFormattingFunctions[0])) - /************************************************************************** * name - rasSetTriggerTrace * description - Called whenever a class is loaded. @@ -547,6 +546,49 @@ decimalString2Int(J9PortLibrary* portLibrary, const char *decString, I_32 signed return num; } +/************************************************************************** + * name - setMethodStrArgLength + * description - Set method string argument length + * parameters - thr, trace options, atRuntime flag + * returns - JNI return code + *************************************************************************/ +omr_error_t +setMethodStrArgLength(J9JavaVM *vm, const char *str, BOOLEAN atRuntime) +{ +#define MAX_STRING_LENGTH 128 + PORT_ACCESS_FROM_JAVAVM(vm); + int value, length; + omr_error_t rc = OMR_ERROR_NONE; + const char *p; + + if (getParmNumber(str) != 1) { + goto err; + } + + p = getPositionalParm(1, str, &length); + + if (length > 3) { + goto err; + } + + value = decimalString2Int(PORTLIB, p, FALSE, &rc); + if (OMR_ERROR_NONE != rc) { + goto err; + } + + if ((0 > value) || + (MAX_STRING_LENGTH < value)) { + goto err; + } + + RAS_GLOBAL_FROM_JAVAVM(methodStrArgLength,vm) = (unsigned int)value; + return OMR_ERROR_NONE; +err: + vaReportJ9VMCommandLineError(PORTLIB, "methodstrarglen takes an unsigned integer value from 1 to %d", MAX_STRING_LENGTH); + return OMR_ERROR_INTERNAL; +#undef MAX_STRING_LENGTH 128 +} + /************************************************************************** * name - addTriggeredMethodSpec * description - Take a user specified method trigger rule (from the @@ -654,12 +696,12 @@ addTriggeredMethodSpec(J9VMThread *thr, const char *ptrMethodSpec, const struct } if (methodRule->entryAction != NULL && methodRule->entryAction->name != NULL - && j9_cmdla_stricmp((char *)methodRule->entryAction->name, "jstacktrace") == 0) { + && j9_cmdla_stricmp((char *)methodRule->entryAction->name, "jstacktrace") == 0) { /* set up the current method spec to be enabled for trace */ setMethod(thr->javaVM, ptrMethodSpec, FALSE); } if (methodRule->exitAction != NULL && methodRule->exitAction->name != NULL - && j9_cmdla_stricmp((char *)methodRule->exitAction->name, "jstacktrace") == 0) { + && j9_cmdla_stricmp((char *)methodRule->exitAction->name, "jstacktrace") == 0) { /* set up the current method spec to be enabled for trace */ setMethod(thr->javaVM, ptrMethodSpec, FALSE); } diff --git a/runtime/rastrace/trcengine.c b/runtime/rastrace/trcengine.c index 2c07f8a11a2..6fae3efeac9 100644 --- a/runtime/rastrace/trcengine.c +++ b/runtime/rastrace/trcengine.c @@ -117,6 +117,7 @@ const struct traceOption TRACE_OPTIONS[] = {RAS_METHODS_KEYWORD, FALSE, setMethod}, {RAS_STACKDEPTH_KEYWORD, TRUE, setStackDepth}, {RAS_COMPRESSION_LEVEL_KEYWORD, TRUE, setStackCompressionLevel}, + {RAS_METHOD_STRING_LENGTH_KEYWORD, FALSE, setMethodStrArgLength}, }; #define NUMBER_OF_TRACE_OPTIONS ( sizeof(TRACE_OPTIONS) / sizeof(struct traceOption)) From 9e42d096d2c25bf78f2d46fb7012de7c427f7748 Mon Sep 17 00:00:00 2001 From: Nick Kamal Date: Thu, 28 Nov 2024 07:58:32 -0500 Subject: [PATCH 2/6] Print actual string arguments with -Xtrace (part 2) The changes reflect the feature request #16416. Adding cmdline option to specify string argument length. -Xtrace:methodstrarglen=[1-128] methodStrArgLen takes an unsigned integer value from 1 to 128 If methodStrArgLen = 0 or unspecified, default to 32. Other invalid inputs result in the input error. There will be subsequent PR for tests (part 3). Signed-off-by: Nick Kamal --- runtime/rastrace/method_trace.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/runtime/rastrace/method_trace.c b/runtime/rastrace/method_trace.c index f6be41d288c..ef22f45024c 100644 --- a/runtime/rastrace/method_trace.c +++ b/runtime/rastrace/method_trace.c @@ -30,9 +30,6 @@ #undef UT_MODULE_UNLOADED #include "ut_mt.h" -#define DEFAULT_BUFFER_LENGTH 128 -#define DEFAULT_STRING_LENGTH 32 - static void hookRAMClassLoad(J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData); static void traceMethodArgInt (J9VMThread *thr, UDATA* arg0EA, char* cursor, UDATA length, char* type); static void traceMethodArgDouble (J9VMThread *thr, UDATA* arg0EA, char* cursor, UDATA length); From c4685ae7bc03c1f6c0b9ee33ab924bd4a628e04e Mon Sep 17 00:00:00 2001 From: Nick Kamal Date: Thu, 28 Nov 2024 08:03:49 -0500 Subject: [PATCH 3/6] Print actual string arguments with -Xtrace (part 2) The changes reflect the feature request #16416. Adding cmdline option to specify string argument length. -Xtrace:methodstrarglen=[1-128] methodStrArgLen takes an unsigned integer value from 1 to 128 If methodStrArgLen = 0 or unspecified, default to 32. Other invalid inputs result in the input error. There will be subsequent PR for tests (part 3). Signed-off-by: Nick Kamal --- runtime/rastrace/method_trace.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/runtime/rastrace/method_trace.c b/runtime/rastrace/method_trace.c index ef22f45024c..11abf788547 100644 --- a/runtime/rastrace/method_trace.c +++ b/runtime/rastrace/method_trace.c @@ -476,8 +476,6 @@ traceMethodArgObject(J9VMThread *thr, UDATA* arg0EA, char* cursor, UDATA length) } else { J9Class *clazz = J9OBJECT_CLAZZ(thr, object); J9JavaVM *vm = thr->javaVM; - const unsigned int methodStrArgLength = ((RasGlobalStorage *)thr->javaVM->j9rasGlobalStorage)->methodStrArgLength; - unsigned int strArgLength = methodStrArgLength == 0 ? DEFAULT_STRING_LENGTH : methodStrArgLength; if (clazz == J9VMJAVALANGSTRING_OR_NULL(vm)) { /* string argument */ From b8de030511cd643d37c16af613ec9aedff1756a8 Mon Sep 17 00:00:00 2001 From: Nick Kamal Date: Thu, 28 Nov 2024 08:41:53 -0500 Subject: [PATCH 4/6] Fix macro --- runtime/rastrace/method_trigger.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/rastrace/method_trigger.c b/runtime/rastrace/method_trigger.c index ba815a30cc2..38d0ef58bf9 100644 --- a/runtime/rastrace/method_trigger.c +++ b/runtime/rastrace/method_trigger.c @@ -586,7 +586,7 @@ setMethodStrArgLength(J9JavaVM *vm, const char *str, BOOLEAN atRuntime) err: vaReportJ9VMCommandLineError(PORTLIB, "methodstrarglen takes an unsigned integer value from 1 to %d", MAX_STRING_LENGTH); return OMR_ERROR_INTERNAL; -#undef MAX_STRING_LENGTH 128 +#undef MAX_STRING_LENGTH } /************************************************************************** From ebebd7593ed38eedc5900c5c061a8b4fcc390290 Mon Sep 17 00:00:00 2001 From: Nick Kamal Date: Thu, 28 Nov 2024 09:59:36 -0500 Subject: [PATCH 5/6] update case of str length == 0 if argument == 0 default to address printing --- runtime/rastrace/method_trace.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/runtime/rastrace/method_trace.c b/runtime/rastrace/method_trace.c index 11abf788547..b79ffaa7f95 100644 --- a/runtime/rastrace/method_trace.c +++ b/runtime/rastrace/method_trace.c @@ -476,14 +476,13 @@ traceMethodArgObject(J9VMThread *thr, UDATA* arg0EA, char* cursor, UDATA length) } else { J9Class *clazz = J9OBJECT_CLAZZ(thr, object); J9JavaVM *vm = thr->javaVM; + const unsigned int methodStrArgLength = ((RasGlobalStorage *)thr->javaVM->j9rasGlobalStorage)->methodStrArgLength; - if (clazz == J9VMJAVALANGSTRING_OR_NULL(vm)) { + if (clazz == J9VMJAVALANGSTRING_OR_NULL(vm) && + (0 != methodStrArgLength)) { /* string argument */ -#define DEFAULT_STRING_LENGTH 32 char utf8Buffer[128]; UDATA utf8Length = 0; - const unsigned int methodStrArgLength = ((RasGlobalStorage *)thr->javaVM->j9rasGlobalStorage)->methodStrArgLength; - unsigned int strArgLength = methodStrArgLength == 0 ? DEFAULT_STRING_LENGTH : methodStrArgLength; char *utf8String = vm->internalVMFunctions->copyStringToUTF8WithMemAlloc( thr, @@ -497,8 +496,8 @@ traceMethodArgObject(J9VMThread *thr, UDATA* arg0EA, char* cursor, UDATA length) if (NULL == utf8String) { j9str_printf(PORTLIB, cursor, length, "(String)"); - } else if (utf8Length > DEFAULT_STRING_LENGTH) { - j9str_printf(PORTLIB, cursor, length, "(String)\"%.*s\"...", (U_32)DEFAULT_STRING_LENGTH, utf8String); + } else if (utf8Length > methodStrArgLength) { + j9str_printf(PORTLIB, cursor, length, "(String)\"%.*s\"...", (U_32)methodStrArgLength, utf8String); } else { j9str_printf(PORTLIB, cursor, length, "(String)\"%.*s\"", (U_32)utf8Length, utf8String); } @@ -506,7 +505,6 @@ traceMethodArgObject(J9VMThread *thr, UDATA* arg0EA, char* cursor, UDATA length) if (utf8Buffer != utf8String) { j9mem_free_memory(utf8String); } -#undef DEFAULT_STRING_LENGTH } else { /* TODO: handle arrays */ From b59d39bad021c1d4e47522a031f12131dce90835 Mon Sep 17 00:00:00 2001 From: Nick Kamal Date: Thu, 28 Nov 2024 11:31:35 -0500 Subject: [PATCH 6/6] fixed formatting conditions --- runtime/rastrace/method_trace.c | 5 +++-- runtime/rastrace/method_trigger.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/runtime/rastrace/method_trace.c b/runtime/rastrace/method_trace.c index b79ffaa7f95..9d70cbd9413 100644 --- a/runtime/rastrace/method_trace.c +++ b/runtime/rastrace/method_trace.c @@ -478,8 +478,9 @@ traceMethodArgObject(J9VMThread *thr, UDATA* arg0EA, char* cursor, UDATA length) J9JavaVM *vm = thr->javaVM; const unsigned int methodStrArgLength = ((RasGlobalStorage *)thr->javaVM->j9rasGlobalStorage)->methodStrArgLength; - if (clazz == J9VMJAVALANGSTRING_OR_NULL(vm) && - (0 != methodStrArgLength)) { + if (clazz == J9VMJAVALANGSTRING_OR_NULL(vm) + && (0 != methodStrArgLength) + ) { /* string argument */ char utf8Buffer[128]; UDATA utf8Length = 0; diff --git a/runtime/rastrace/method_trigger.c b/runtime/rastrace/method_trigger.c index 38d0ef58bf9..5a76147a18f 100644 --- a/runtime/rastrace/method_trigger.c +++ b/runtime/rastrace/method_trigger.c @@ -576,8 +576,9 @@ setMethodStrArgLength(J9JavaVM *vm, const char *str, BOOLEAN atRuntime) goto err; } - if ((0 > value) || - (MAX_STRING_LENGTH < value)) { + if ((0 > value) + || (MAX_STRING_LENGTH < value) + ) { goto err; }