Skip to content

Commit

Permalink
Print string contents for "this" references
Browse files Browse the repository at this point in the history
The changes reflect the feature request #20878.

Print string contents for this references.
Also, print address for string arguments and returns.

Closes: #20878
Signed-off-by: Nick Kamal <[email protected]>
  • Loading branch information
h3110n3rv3 committed Jan 17, 2025
1 parent 30f423a commit ca5dd4d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
45 changes: 41 additions & 4 deletions runtime/rastrace/method_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,49 @@ traceMethodEnter(J9VMThread *thr, J9Method *method, void *receiverAddress, UDATA
if (modifiers & J9AccNative) {
Trc_MethodEntryN(thr, J9UTF8_LENGTH(className), J9UTF8_DATA(className), J9UTF8_LENGTH(methodName), J9UTF8_DATA(methodName), J9UTF8_LENGTH(methodSignature), J9UTF8_DATA(methodSignature), receiver);
} else {
Trc_MethodEntry(thr, J9UTF8_LENGTH(className), J9UTF8_DATA(className), J9UTF8_LENGTH(methodName), J9UTF8_DATA(methodName), J9UTF8_LENGTH(methodSignature), J9UTF8_DATA(methodSignature), receiver);
Trc_MethodEntry(thr, J9UTF8_LENGTH(className), J9UTF8_DATA(className), J9UTF8_LENGTH(methodName), J9UTF8_DATA(methodName), J9UTF8_LENGTH(methodSignature), J9UTF8_DATA(methodSignature), 0, "", receiver);
}

if (doParameters) {
J9JavaVM *vm = thr->javaVM;
const unsigned int maxStringLength = RAS_GLOBAL_FROM_JAVAVM(maxStringLength, vm);

if ((NULL != receiver)
&& (receiverClazz == J9VMJAVALANGSTRING_OR_NULL(vm))
&& (0 != maxStringLength)
&& !J9UTF8_LITERAL_EQUALS(J9UTF8_DATA(methodName), J9UTF8_LENGTH(methodName), "<init>")
) {
PORT_ACCESS_FROM_VMC(thr);
char utf8Buffer[RAS_MAX_STRING_LENGTH_LIMIT + 1];
char outputString[RAS_MAX_STRING_LENGTH_LIMIT + 1];
UDATA utf8Length = 0;

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

if (NULL == utf8String) {
sprintf(outputString, "(String)<Memory allocation error>");
} else if (utf8Length > maxStringLength) {
sprintf(outputString, "(String)\"%.*s\"...", (U_32)maxStringLength, utf8String);
} else {
sprintf(outputString, "(String)\"%.*s\"", (U_32)utf8Length, utf8String);
}

Trc_MethodEntry(thr, J9UTF8_LENGTH(className), J9UTF8_DATA(className), J9UTF8_LENGTH(methodName), J9UTF8_DATA(methodName), J9UTF8_LENGTH(methodSignature), J9UTF8_DATA(methodSignature), J9UTF8_LENGTH(outputString), outputString, receiver);

if (utf8Buffer != utf8String) {
j9mem_free_memory(utf8String);
}
}
Trc_MethodArguments(
thr,
thr,
(U_32)J9UTF8_LENGTH(receiverClassName),
J9UTF8_DATA(receiverClassName),
receiver,
Expand Down Expand Up @@ -498,9 +535,9 @@ traceMethodArgObject(J9VMThread *thr, UDATA* arg0EA, char* cursor, UDATA length)
if (NULL == utf8String) {
j9str_printf(PORTLIB, cursor, length, "(String)<Memory allocation error>");
} else if (utf8Length > maxStringLength) {
j9str_printf(PORTLIB, cursor, length, "(String)\"%.*s\"...", (U_32)maxStringLength, utf8String);
j9str_printf(PORTLIB, cursor, length, "(String)@%p - \"%.*s\"...", (U_32)maxStringLength, utf8String, object);
} else {
j9str_printf(PORTLIB, cursor, length, "(String)\"%.*s\"", (U_32)utf8Length, utf8String);
j9str_printf(PORTLIB, cursor, length, "@%p - (String)\"%.*s\"", (U_32)utf8Length, utf8String, object);
}

if (utf8Buffer != utf8String) {
Expand Down
2 changes: 1 addition & 1 deletion runtime/rastrace/mt.tdf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
Executable=mt
DATFileName=J9TraceFormat.dat

TraceEntry=Trc_MethodEntry Overhead=1 Level=5 Group=bytecodeMethods Template="%.*s.%.*s%.*s bytecode method, this = 0x%zx"
TraceEntry=Trc_MethodEntry Overhead=1 Level=5 Group=bytecodeMethods Template="%.*s.%.*s%.*s bytecode method, this = %.*s 0x%zx,"
TraceEntry=Trc_MethodEntryC Overhead=1 Level=5 Group=compiledMethods Template="%.*s.%.*s%.*s compiled method, this = 0x%zx"
TraceEntry=Trc_MethodEntryN Overhead=1 Level=5 Group=nativeMethods Template="%.*s.%.*s%.*s native method, this = 0x%zx"
TraceEntry=Trc_MethodEntryS Overhead=1 Level=5 Group=bytecodeMethods,staticMethods Template="%.*s.%.*s%.*s bytecode static method"
Expand Down

0 comments on commit ca5dd4d

Please sign in to comment.