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

Print string contents for "this" references #20933

Open
wants to merge 1 commit 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
46 changes: 41 additions & 5 deletions runtime/rastrace/method_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,48 @@ 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_MethodEntryStr(thr, J9UTF8_LENGTH(className), J9UTF8_DATA(className), J9UTF8_LENGTH(methodName), J9UTF8_DATA(methodName), J9UTF8_LENGTH(methodSignature), J9UTF8_DATA(methodSignature), receiver, 0, "");
}

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

if ((receiverClazz == J9VMJAVALANGSTRING_OR_NULL(vm))
&& (0 != maxStringLength)
&& !J9UTF8_LITERAL_EQUALS(J9UTF8_DATA(methodName), J9UTF8_LENGTH(methodName), "<init>")
h3110n3rv3 marked this conversation as resolved.
Show resolved Hide resolved
) {
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_MethodEntryStr(thr, J9UTF8_LENGTH(className), J9UTF8_DATA(className), J9UTF8_LENGTH(methodName), J9UTF8_DATA(methodName), J9UTF8_LENGTH(methodSignature), J9UTF8_DATA(methodSignature), receiver, J9UTF8_LENGTH(outputString), outputString);

if (utf8Buffer != utf8String) {
j9mem_free_memory(utf8String);
}
}
Trc_MethodArguments(
thr,
thr,
(U_32)J9UTF8_LENGTH(receiverClassName),
J9UTF8_DATA(receiverClassName),
receiver,
Expand Down Expand Up @@ -496,11 +532,11 @@ traceMethodArgObject(J9VMThread *thr, UDATA* arg0EA, char* cursor, UDATA length)
&utf8Length);

if (NULL == utf8String) {
j9str_printf(PORTLIB, cursor, length, "(String)<Memory allocation error>");
j9str_printf(PORTLIB, cursor, length, "(String)@%p - <Memory allocation error>", object);
} else if (utf8Length > maxStringLength) {
j9str_printf(PORTLIB, cursor, length, "(String)\"%.*s\"...", (U_32)maxStringLength, utf8String);
j9str_printf(PORTLIB, cursor, length, "(String)@%p - \"%.*s\"...", object, (U_32)maxStringLength, utf8String);
} else {
j9str_printf(PORTLIB, cursor, length, "(String)\"%.*s\"", (U_32)utf8Length, utf8String);
j9str_printf(PORTLIB, cursor, length, "(String)@%p - \"%.*s\"", object, (U_32)utf8Length, utf8String);
}

if (utf8Buffer != utf8String) {
Expand Down
4 changes: 3 additions & 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 Obsolete Overhead=1 Level=5 Group=bytecodeMethods Template="%.*s.%.*s%.*s bytecode method, this = 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 Expand Up @@ -59,3 +59,5 @@ TraceExit-Exception=Trc_MethodExitNXS Overhead=1 Level=5 Group=throw,nativeMetho

TraceEvent=Trc_MethodReturn Overhead=1 Level=5 Group=methodArguments Template="return value: %s"
TraceEvent=Trc_MethodException Overhead=1 Level=5 Group=methodArguments Template="exception: %s"

TraceEntry=Trc_MethodEntryStr Overhead=1 Level=5 Group=bytecodeMethods Template="%.*s.%.*s%.*s bytecode method, this = 0x%zx %.*s"