Skip to content

Commit

Permalink
Print actual String arguments with Xtrace part 1
Browse files Browse the repository at this point in the history
The changes reflect the feature request #16416.

Print the actual string instead of address at max of 32 characters.
Subsequent PRs: cmdline option for length (Part 2) and tests (Part 3).

Signed-off-by: Nick Kamal <[email protected]>
  • Loading branch information
h3110n3rv3 committed Nov 21, 2024
1 parent 44766de commit 4772a09
Showing 1 changed file with 40 additions and 5 deletions.
45 changes: 40 additions & 5 deletions runtime/rastrace/method_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,13 +474,48 @@ traceMethodArgObject(J9VMThread *thr, UDATA* arg0EA, char* cursor, UDATA length)
if (object == NULL) {
j9str_printf(PORTLIB, cursor, length, "null");
} else {
J9Class* clazz = J9OBJECT_CLAZZ(thr, object);
J9ROMClass * romClass = clazz->romClass;
J9UTF8* className = J9ROMCLASS_CLASSNAME(romClass);
/* string arg */
J9Class *clazz = J9OBJECT_CLAZZ(thr, object);
J9JavaVM *vm = thr->javaVM;

if (clazz == J9VMJAVALANGSTRING_OR_NULL(vm)) {

#define DEFAULT_STRING_LENGTH 32

char utf8Buffer[128];
UDATA utf8Length = 0;

char *utf8String = vm->internalVMFunctions->copyStringToUTF8WithMemAlloc(
thr,
object,
0,
"",
0,
utf8Buffer,
sizeof(utf8Buffer),
&utf8Length);

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 {
j9str_printf(PORTLIB, cursor, length, "(String)\"%.*s\"", (U_32)utf8Length, utf8String);
}

if (utf8Buffer != utf8String) {
j9mem_free_memory(utf8String);
}

/* TODO: handle arrays */
#undef DEFAULT_STRING_LENGTH

j9str_printf(PORTLIB, cursor, length, "%.*s@%p", (U_32)J9UTF8_LENGTH(className), J9UTF8_DATA(className), object);
} else {
/* TODO: handle arrays */

J9ROMClass *romClass = clazz->romClass;
J9UTF8 *className = J9ROMCLASS_CLASSNAME(romClass);
j9str_printf(PORTLIB, cursor, length, "%.*s@%p", (U_32)J9UTF8_LENGTH(className), J9UTF8_DATA(className), object);
}
}
}

Expand Down

0 comments on commit 4772a09

Please sign in to comment.