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

WIP: Print actual string arguments with -Xtrace (part 2) #20662

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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/oti/j9trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 8 additions & 6 deletions runtime/rastrace/j9rastrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

/*
* ======================================================================
Expand Down Expand Up @@ -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);

/*
* =============================================================================
Expand Down
11 changes: 6 additions & 5 deletions runtime/rastrace/method_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -476,10 +476,12 @@ 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;

Expand All @@ -495,16 +497,15 @@ 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 > methodStrArgLength) {
j9str_printf(PORTLIB, cursor, length, "(String)\"%.*s\"...", (U_32)methodStrArgLength, utf8String);
} else {
j9str_printf(PORTLIB, cursor, length, "(String)\"%.*s\"", (U_32)utf8Length, utf8String);
}

if (utf8Buffer != utf8String) {
j9mem_free_memory(utf8String);
}
#undef DEFAULT_STRING_LENGTH
} else {
/* TODO: handle arrays */

Expand Down
49 changes: 46 additions & 3 deletions runtime/rastrace/method_trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -547,6 +546,50 @@ 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
}

/**************************************************************************
* name - addTriggeredMethodSpec
* description - Take a user specified method trigger rule (from the
Expand Down Expand Up @@ -654,12 +697,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);
}
Expand Down
1 change: 1 addition & 0 deletions runtime/rastrace/trcengine.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down