diff --git a/runtime/rastrace/method_trace.c b/runtime/rastrace/method_trace.c index bc489a837f4..eca88af2ea9 100644 --- a/runtime/rastrace/method_trace.c +++ b/runtime/rastrace/method_trace.c @@ -477,48 +477,29 @@ traceMethodArgObject(J9VMThread *thr, UDATA* arg0EA, char* cursor, UDATA length) if (object == NULL) { j9str_printf(PORTLIB, cursor, length, "null"); } else { - /* string arg */ - J9Class *clazz = J9OBJECT_CLAZZ(thr, object); + J9Class* clazz = J9OBJECT_CLAZZ(thr, object); + J9ROMClass * romClass = clazz->romClass; + J9UTF8* className = J9ROMCLASS_CLASSNAME(romClass); J9JavaVM *vm = thr->javaVM; if (clazz == J9VMJAVALANGSTRING_OR_NULL(vm)) { + /* string arg */ + char stringArgBuffer[DEFAULT_BUFFER_LENGTH]; -#define DEFAULT_STRING_LENGTH 32 + J9InternalVMFunctions const * const vmFuncs = thr->javaVM->internalVMFunctions; + char *stringArgUTF8 = vmFuncs->copyStringToUTF8WithMemAlloc(thr, object, J9_STR_NULL_TERMINATE_RESULT, " ", 2, stringArgBuffer, DEFAULT_BUFFER_LENGTH, NULL); - char utf8Buffer[128]; - UDATA utf8Length = 0; - const unsigned int methodStrArgLength = ((RasGlobalStorage *)thr->javaVM->j9rasGlobalStorage)->methodStrArgLength; - unsigned int strArgLength = methodStrArgLength == 0 ? DEFAULT_STRING_LENGTH : methodStrArgLength; - - char *utf8String = vm->internalVMFunctions->copyStringToUTF8WithMemAlloc( - thr, - object, - 0, - "", - 0, - utf8Buffer, - sizeof(utf8Buffer), - &utf8Length); - - if (NULL == utf8String) { - j9str_printf(PORTLIB, cursor, length, "(String)"); - } else if (utf8Length > strArgLength) { - j9str_printf(PORTLIB, cursor, length, "(String)\"%.*s\"...", (U_32)strArgLength, utf8String); + if(DEFAULT_STRING_LENGTH < strlen(stringArgUTF8)) { + j9str_printf(PORTLIB, cursor, length, "(String)%.*s...", (U_32)DEFAULT_STRING_LENGTH, J9UTF8_DATA(stringArgUTF8)); } else { - j9str_printf(PORTLIB, cursor, length, "(String)\"%.*s\"", (U_32)utf8Length, utf8String); + j9str_printf(PORTLIB, cursor, length, "(String)%.*s", (U_32)J9UTF8_LENGTH(stringArgUTF8), J9UTF8_DATA(stringArgUTF8)); } - if (utf8Buffer != utf8String) { - j9mem_free_memory(utf8String); + if ((char*)stringArgBuffer != stringArgUTF8) { + j9mem_free_memory(stringArgUTF8); } - -#undef DEFAULT_STRING_LENGTH - } 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); } }