From a1819eda091634b54bd6611d4fecfdeaeefead02 Mon Sep 17 00:00:00 2001 From: Nick Kamal Date: Mon, 13 Jan 2025 11:57:24 -0500 Subject: [PATCH] Print string contents for "this" references 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 --- runtime/rastrace/method_trace.c | 46 +++++++++++++++++++++++++++++---- runtime/rastrace/mt.tdf | 4 ++- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/runtime/rastrace/method_trace.c b/runtime/rastrace/method_trace.c index b4ea0ce58ce..dabd5ff4659 100644 --- a/runtime/rastrace/method_trace.c +++ b/runtime/rastrace/method_trace.c @@ -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), "") + ) { + 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)"); + } 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, @@ -496,11 +532,11 @@ traceMethodArgObject(J9VMThread *thr, UDATA* arg0EA, char* cursor, UDATA length) &utf8Length); if (NULL == utf8String) { - j9str_printf(PORTLIB, cursor, length, "(String)"); + j9str_printf(PORTLIB, cursor, length, "(String)@%p - ", 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) { diff --git a/runtime/rastrace/mt.tdf b/runtime/rastrace/mt.tdf index 4a5ce1bc02e..e454b83bdd4 100644 --- a/runtime/rastrace/mt.tdf +++ b/runtime/rastrace/mt.tdf @@ -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" @@ -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"