Skip to content

Commit

Permalink
The changes reflect the feature request eclipse-openj9#16416 - part 2…
Browse files Browse the repository at this point in the history
… following eclipse-openj9#20641

Adding cmdline option to specify string argument length to be printed.
-Xtrace:methodstrarglen=[1-128]
methodStrArgLen takes an unsigned integer value from 1 to 128
If no methodStrArgLen is specified, or is set to 0, the printed length is the default value of 32.
Other invalid inputs result in the following:
"Error processing trace option, detail: methodstrarglen takes an unsigned integer value from 1 to 128
Trace option unrecognized: -Xtrace:methodStrArgLen
Error processing trace option: -Xtrace:methodStrArgLen=invalid input"

There will be subsequent PRs for tests (part 3).

Signed-off-by: Nick Kamal <[email protected]>
  • Loading branch information
h3110n3rv3 committed Dec 17, 2024
1 parent e1e0982 commit 95ac521
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
14 changes: 7 additions & 7 deletions runtime/rastrace/j9rastrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +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_METHOD_STRING_LENGTH_KEYWORD "METHODSTRARGLEN"
#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"

/*
* ======================================================================
Expand Down
6 changes: 4 additions & 2 deletions runtime/rastrace/method_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,8 @@ traceMethodArgObject(J9VMThread *thr, UDATA* arg0EA, char* cursor, UDATA length)

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,
Expand All @@ -500,8 +502,8 @@ traceMethodArgObject(J9VMThread *thr, UDATA* arg0EA, char* cursor, UDATA length)

if (NULL == utf8String) {
j9str_printf(PORTLIB, cursor, length, "(String)<Memory allocation error>");
} else if (utf8Length > DEFAULT_STRING_LENGTH) {
j9str_printf(PORTLIB, cursor, length, "(String)\"%.*s\"...", (U_32)DEFAULT_STRING_LENGTH, utf8String);
} else if (utf8Length > strArgLength) {
j9str_printf(PORTLIB, cursor, length, "(String)\"%.*s\"...", (U_32)strArgLength, utf8String);
} else {
j9str_printf(PORTLIB, cursor, length, "(String)\"%.*s\"", (U_32)utf8Length, utf8String);
}
Expand Down
5 changes: 4 additions & 1 deletion runtime/rastrace/method_trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ static const StackTraceFormattingFunction stackTraceFormattingFunctions[] = {
};

#define NUM_STACK_TRACE_FORMATTING_FUNCTIONS (sizeof(stackTraceFormattingFunctions) / sizeof(stackTraceFormattingFunctions[0]))
#define MAX_STRING_LENGTH 128

/**************************************************************************
* name - rasSetTriggerTrace
Expand Down Expand Up @@ -556,6 +555,8 @@ decimalString2Int(J9PortLibrary* portLibrary, const char *decString, I_32 signed
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;
Expand Down Expand Up @@ -587,6 +588,8 @@ 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
}

/**************************************************************************
Expand Down

0 comments on commit 95ac521

Please sign in to comment.