Skip to content

Commit

Permalink
fix: generate "good" and "bad" trace log files.
Browse files Browse the repository at this point in the history
* Log files where the test last passed will be named
goodJitCompilationLog_opt_index_<num>.log

* Log files where the test fail will be named
badJitCompilationLog_opt_index_<num>.log

Refactor to use safer snprinf, and removed malloc

Also dynamically set number of digits of last opt index

Ref: https://www.cplusplus.com/reference/cstdio/snprintf/
https://www.cplusplus.com/reference/cstdio/sprintf/

Refactor to get int length without for loop

* Specify file extension in snprintf
* Hard code length of extension str
  • Loading branch information
qasimy123 authored and r30shah committed Jun 28, 2024
1 parent a158017 commit f7396f1
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 7 deletions.
25 changes: 23 additions & 2 deletions runtime/compiler/control/DebugAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ debugAgentRevertToInterpreter(J9VMThread* vmThread, J9JITExceptionTable *jitMeth
}

extern J9_CFUNC BOOLEAN
debugAgentRecompile(J9VMThread* vmThread, J9JITExceptionTable *jitMethod, IDATA lastOptIndex, IDATA lastOptSubIndex, BOOLEAN enableTracing)
debugAgentRecompile(J9VMThread* vmThread, J9JITExceptionTable *jitMethod, IDATA lastOptIndex, IDATA lastOptSubIndex, BOOLEAN enableTracing, BOOLEAN goodLog)
{
J9JITConfig *jitConfig = vmThread->javaVM->jitConfig;
if (NULL == jitConfig)
Expand Down Expand Up @@ -297,7 +297,23 @@ debugAgentRecompile(J9VMThread* vmThread, J9JITExceptionTable *jitMethod, IDATA
}

plan->setInsertInstrumentation(bodyInfo->getIsProfilingBody());
// plan->setLogCompilation(jitdumpFile);

char *fileName = "goodJitCompilationLog_opt_index_";
if (!goodLog)
{
fileName = "badJitCompilationLog_opt_index_";
}
// Ref: https://github.com/eclipse-openj9/openj9-omr/blob/openj9/compiler/ras/Tree.cpp#L1168
int numDigits = ( lastOptIndex == 0 ? 1 : ((int) log10( (double)lastOptIndex ) + 1) );
int maxSize = strlen(fileName) + numDigits + 5;
char fileNameWithLastOptIndex[maxSize];
snprintf(fileNameWithLastOptIndex, maxSize, "%s%d.log", fileName, (int)lastOptIndex);
TR::FILE *jitCompilationLog = enableTracing ? trfopen(fileNameWithLastOptIndex, "ab", false) : NULL;
if (enableTracing)
{
plan->setLogCompilation(jitCompilationLog);
TR::Options::getCmdLineOptions()->setOption(TR_TraceAll);
}

TR::Options::getCmdLineOptions()->setLastOptIndex(lastOptIndex);
TR::Options::getCmdLineOptions()->setLastOptSubIndex(lastOptSubIndex);
Expand All @@ -310,6 +326,11 @@ debugAgentRecompile(J9VMThread* vmThread, J9JITExceptionTable *jitMethod, IDATA
auto rc = compilationOK;
auto queued = false;
compInfo->compileMethod(vmThread, details, pc, TR_no, &rc, &queued, plan);
if (enableTracing)
{
trfflush(jitCompilationLog);
trfclose(jitCompilationLog);
}

vmThread->javaVM->internalVMFunctions->internalReleaseVMAccess(vmThread);

Expand Down
2 changes: 1 addition & 1 deletion runtime/compiler/control/DebugAgent.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ extern J9_CFUNC BOOLEAN
debugAgentRevertToInterpreter(J9VMThread* vmThread, J9JITExceptionTable *jitMethod);

extern J9_CFUNC BOOLEAN
debugAgentRecompile(J9VMThread* vmThread, J9JITExceptionTable *jitMethod, IDATA lastOptIndex, IDATA lastOptSubIndex, BOOLEAN enableTracing);
debugAgentRecompile(J9VMThread* vmThread, J9JITExceptionTable *jitMethod, IDATA lastOptIndex, IDATA lastOptSubIndex, BOOLEAN enableTracing, BOOLEAN goodLog);

extern J9_CFUNC BOOLEAN
debugAgentEnd(J9VMThread* vmThread);
Expand Down
6 changes: 3 additions & 3 deletions runtime/jcl/common/jithelpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ Java_com_ibm_jit_JITHelpers_debugAgentRun(JNIEnv *env, jclass ignored, jobject m
IDATA lastOptSubIndex = 1024;

for (IDATA lastOptIndex = 100; lastOptIndex >= 0; --lastOptIndex) {
jitConfig->debugAgentRecompile(vmThread, (J9JITExceptionTable*)jitMethod, lastOptIndex, lastOptSubIndex, 0);
jitConfig->debugAgentRecompile(vmThread, (J9JITExceptionTable*)jitMethod, lastOptIndex, lastOptSubIndex, 0, 0);

fprintf(stderr, "Rerunning test\n");
(*env)->CallObjectMethod(env, ma, jdk_internal_reflect_MethodAccessor_invoke, obj, args);
Expand All @@ -513,7 +513,7 @@ Java_com_ibm_jit_JITHelpers_debugAgentRun(JNIEnv *env, jclass ignored, jobject m
} else {
fprintf(stderr, "LastOptIndex = %ld is the potential culprit\n", lastOptIndex + 1);

jitConfig->debugAgentRecompile(vmThread, (J9JITExceptionTable*)jitMethod, lastOptIndex, lastOptSubIndex, 1);
jitConfig->debugAgentRecompile(vmThread, (J9JITExceptionTable*)jitMethod, lastOptIndex, lastOptSubIndex, 1, 1);

fprintf(stderr, "Rerunning test expecting it to pass\n");
(*env)->CallObjectMethod(env, ma, jdk_internal_reflect_MethodAccessor_invoke, obj, args);
Expand All @@ -525,7 +525,7 @@ Java_com_ibm_jit_JITHelpers_debugAgentRun(JNIEnv *env, jclass ignored, jobject m
fprintf(stderr, "Test passed\n");
}

jitConfig->debugAgentRecompile(vmThread, (J9JITExceptionTable*)jitMethod, lastOptIndex + 1, lastOptSubIndex, 1);
jitConfig->debugAgentRecompile(vmThread, (J9JITExceptionTable*)jitMethod, lastOptIndex + 1, lastOptSubIndex, 1, 0);

fprintf(stderr, "Rerunning test expecting it to fail\n");
(*env)->CallObjectMethod(env, ma, jdk_internal_reflect_MethodAccessor_invoke, obj, args);
Expand Down
2 changes: 1 addition & 1 deletion runtime/oti/j9nonbuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -4263,7 +4263,7 @@ typedef struct J9JITConfig {
BOOLEAN (*debugAgentStart)(struct J9VMThread *vmThread);
BOOLEAN (*debugAgentGetAllJitMethods)(struct J9VMThread *vmThread, jobject jitMethods);
BOOLEAN (*debugAgentRevertToInterpreter)(struct J9VMThread *vmThread, J9JITExceptionTable *jitMethod);
BOOLEAN (*debugAgentRecompile)(struct J9VMThread *vmThread, J9JITExceptionTable *jitMethod, IDATA lastOptIndex, IDATA lastOptSubIndex, BOOLEAN enableTracing);
BOOLEAN (*debugAgentRecompile)(struct J9VMThread *vmThread, J9JITExceptionTable *jitMethod, IDATA lastOptIndex, IDATA lastOptSubIndex, BOOLEAN enableTracing, BOOLEAN goodLog);
BOOLEAN (*debugAgentEnd)(struct J9VMThread *vmThread);
#if defined(J9VM_OPT_JITSERVER)
int32_t (*startJITServer)(struct J9JITConfig *jitConfig);
Expand Down

0 comments on commit f7396f1

Please sign in to comment.