From f7396f114c206dfdae4744455076ec91d75a3f11 Mon Sep 17 00:00:00 2001 From: Qasim Khawaja Date: Fri, 1 Oct 2021 00:43:08 +0000 Subject: [PATCH] fix: generate "good" and "bad" trace log files. * Log files where the test last passed will be named goodJitCompilationLog_opt_index_.log * Log files where the test fail will be named badJitCompilationLog_opt_index_.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 --- runtime/compiler/control/DebugAgent.cpp | 25 +++++++++++++++++++++++-- runtime/compiler/control/DebugAgent.hpp | 2 +- runtime/jcl/common/jithelpers.c | 6 +++--- runtime/oti/j9nonbuilder.h | 2 +- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/runtime/compiler/control/DebugAgent.cpp b/runtime/compiler/control/DebugAgent.cpp index 37a56ff3d8..13412a7f76 100644 --- a/runtime/compiler/control/DebugAgent.cpp +++ b/runtime/compiler/control/DebugAgent.cpp @@ -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) @@ -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); @@ -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); diff --git a/runtime/compiler/control/DebugAgent.hpp b/runtime/compiler/control/DebugAgent.hpp index 23ddc116a5..eee64f0f12 100644 --- a/runtime/compiler/control/DebugAgent.hpp +++ b/runtime/compiler/control/DebugAgent.hpp @@ -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); diff --git a/runtime/jcl/common/jithelpers.c b/runtime/jcl/common/jithelpers.c index 120c2c56e1..c15c3487c0 100644 --- a/runtime/jcl/common/jithelpers.c +++ b/runtime/jcl/common/jithelpers.c @@ -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); @@ -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); @@ -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); diff --git a/runtime/oti/j9nonbuilder.h b/runtime/oti/j9nonbuilder.h index d1ab0a26c6..21f462d70c 100644 --- a/runtime/oti/j9nonbuilder.h +++ b/runtime/oti/j9nonbuilder.h @@ -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);