Skip to content

Commit

Permalink
The changes reflect the feature request eclipse-openj9#16416.
Browse files Browse the repository at this point in the history
Instead of printing the memory address for string arguments, print the actual string at max of 255 characters.

Closes: eclipse-openj9#16416
Signed-off-by: Nick Kamal <[email protected]>
  • Loading branch information
h3110n3rv3 committed Nov 20, 2024
1 parent 5f6daa8 commit ca304aa
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions runtime/rastrace/method_trace.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 OR GPL-2.0-only WITH OpenJDK-assembly-exception-1.0
*******************************************************************************/


#include "rommeth.h"

#define _UTE_STATIC_
Expand All @@ -30,6 +31,8 @@
#undef UT_MODULE_UNLOADED
#include "ut_mt.h"

#define DEFAULT_STRING_LENGTH 32

static void hookRAMClassLoad(J9HookInterface** hook, UDATA eventNum, void* eventData, void* userData);
static void traceMethodArgInt (J9VMThread *thr, UDATA* arg0EA, char* cursor, UDATA length, char* type);
static void traceMethodArgDouble (J9VMThread *thr, UDATA* arg0EA, char* cursor, UDATA length);
Expand All @@ -42,7 +45,7 @@ static char* traceMethodReturnVal(J9VMThread* thr, J9UTF8* signature, void* retu
static void traceMethodArgBoolean (J9VMThread *thr, UDATA* arg0EA, char* cursor, UDATA length);
static void traceMethodEnter (J9VMThread *thr, J9Method *method, void *receiverAddress, UDATA isCompiled, UDATA doParameters);
static void traceMethodArgLong (J9VMThread *thr, UDATA* arg0EA, char* cursor, UDATA length);
static U_8 checkMethod (J9VMThread *thr, J9Method *method);
static U_8 checkMethod (J9VMThread *thr, J9Method *method, int *stringArgLength);

/**************************************************************************
* name - matchMethod
Expand Down Expand Up @@ -113,10 +116,11 @@ matchMethod(RasMethodTable * methodTable, J9Method *method)
* the trace spec and thus need to be traced.
* parameters - Pointer to the current thread
* Pointer to the method
* Pointer to int variable to be filled
* returns - none
*************************************************************************/
static
U_8 checkMethod(J9VMThread *thr, J9Method *method)
U_8 checkMethod(J9VMThread *thr, J9Method *method, int *stringArgLength)
{
RasMethodTable *methodTable;
U_8 flag = J9_RAS_METHOD_SEEN;
Expand All @@ -141,6 +145,7 @@ U_8 checkMethod(J9VMThread *thr, J9Method *method)

if(methodTable->traceInputRetVals == TRUE) {
flag |= J9_RAS_METHOD_TRACE_ARGS;
*stringArgLength = methodTable->stringArgLength;
}
} else {
/* Disable all method trace for this method */
Expand Down Expand Up @@ -314,14 +319,15 @@ traceMethodExitX(J9VMThread *thr, J9Method *method, UDATA isCompiled, void* exce
BOOLEAN
setRAMClassExtendedMethodFlagsHelper(J9VMThread *thr, J9Class *clazz, const char **nlsMsgFormat)
{
int stringArgLength;
J9JavaVM *vm = thr->javaVM;
J9Method *method = clazz->ramMethods;
U_32 i = 0;
U_32 romMethodCount = clazz->romClass->romMethodCount;

for (i = 0; i < romMethodCount; i++) {
U_8 *mtFlag = fetchMethodExtendedFlagsPointer(method);
setExtendedMethodFlags(vm, mtFlag, (checkMethod(thr, method) | rasSetTriggerTrace(thr, method)));
setExtendedMethodFlags(vm, mtFlag, (checkMethod(thr, method, &stringArgLength) | rasSetTriggerTrace(thr, method)));
method++;
}

Expand Down Expand Up @@ -481,11 +487,18 @@ traceMethodArgObject(J9VMThread *thr, UDATA* arg0EA, char* cursor, UDATA length)

if (clazz == J9VMJAVALANGSTRING_OR_NULL(vm)) {
/* string arg */
char stringArgBuffer[J9_ARRAY_DIMENSION_LIMIT];
char stringArgBuffer[DEFAULT_STRING_LENGTH];

J9InternalVMFunctions const * const vmFuncs = thr->javaVM->internalVMFunctions;
char *stringArgUTF8 = vmFuncs->copyStringToUTF8WithMemAlloc(thr, object, J9_STR_NULL_TERMINATE_RESULT, " ", 2, stringArgBuffer, J9_ARRAY_DIMENSION_LIMIT, NULL);
j9str_printf(PORTLIB, cursor, length, "%.*s@%.*s", (U_32)J9UTF8_LENGTH(className), J9UTF8_DATA(className), J9UTF8_LENGTH(stringArgUTF8), J9UTF8_DATA(stringArgUTF8));
char *stringArgUTF8 = vmFuncs->copyStringToUTF8WithMemAlloc(thr, object, J9_STR_NULL_TERMINATE_RESULT, " ", 2, stringArgBuffer, DEFAULT_STRING_LENGTH, NULL);
stringArgUTF8[DEFAULT_STRING_LENGTH - 1] = '\0';

if(DEFAULT_STRING_LENGTH - 1 == strlen(stringArgUTF8)) {
stringArgUTF8[DEFAULT_STRING_LENGTH - 4] = '.';
stringArgUTF8[DEFAULT_STRING_LENGTH - 3] = '.';
stringArgUTF8[DEFAULT_STRING_LENGTH - 2] = '.';
}
j9str_printf(PORTLIB, cursor, length, "%.*s@%s", (U_32)J9UTF8_LENGTH(className), J9UTF8_DATA(className), stringArgUTF8);
} else {
/* TODO: handle arrays */
j9str_printf(PORTLIB, cursor, length, "%.*s@%p", (U_32)J9UTF8_LENGTH(className), J9UTF8_DATA(className), object);
Expand Down

0 comments on commit ca304aa

Please sign in to comment.