Skip to content

Commit

Permalink
Replace vlogAcquire()/vlogRelease() pairs with CriticalSection
Browse files Browse the repository at this point in the history
TR_VerboseLog::CriticalSection should be preferred whenever it is
straightforward to use.
  • Loading branch information
jdmpapin committed Nov 16, 2021
1 parent 38d242b commit 04bcb60
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 33 deletions.
3 changes: 1 addition & 2 deletions compiler/compile/OMRCompilation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1124,7 +1124,7 @@ int32_t OMR::Compilation::compile()
{
int32_t jittedBodyHash = strHash(self()->signature());
char callerBuf[501], calleeBuf[501];
TR_VerboseLog::vlogAcquire();
TR_VerboseLog::CriticalSection vlogLock;
TR_VerboseLog::writeLine(TR_Vlog_INL, "%d methods inlined into %x %s @ %p", self()->getNumInlinedCallSites(), jittedBodyHash, self()->signature(), self()->cg()->getCodeStart());
for (int32_t i = 0; i < self()->getNumInlinedCallSites(); i++)
{
Expand Down Expand Up @@ -1182,7 +1182,6 @@ int32_t OMR::Compilation::compile()
}
}
}
TR_VerboseLog::vlogRelease();
}
#endif
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/control/CompileMethod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ compileMethodFromDetails(
if (TR::Options::isAnyVerboseOptionSet(TR_VerboseCompileEnd, TR_VerbosePerformance))
{
const char *signature = compilee.signature(&trMemory);
TR_VerboseLog::vlogAcquire();
TR_VerboseLog::CriticalSection vlogLock;
TR_VerboseLog::write(TR_Vlog_COMP, "(%s) %s @ " POINTER_PRINTF_FORMAT "-" POINTER_PRINTF_FORMAT,
compiler.getHotnessName(compiler.getMethodHotness()),
signature,
Expand All @@ -394,7 +394,6 @@ compileMethodFromDetails(
}

trfflush(jitConfig->options.vLogFile);
TR_VerboseLog::vlogRelease();
}

if (
Expand Down
9 changes: 3 additions & 6 deletions compiler/control/OMROptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2236,7 +2236,7 @@ OMR::Options::jitLatePostProcess(TR::OptionSet *optionSet, void * jitConfig)

if (self()->getOption(TR_MimicInterpreterFrameShape))
{
TR_VerboseLog::vlogAcquire();
TR_VerboseLog::CriticalSection vlogLock;
if (self()->getFixedOptLevel() != -1 && self()->getFixedOptLevel() != noOpt)
TR_VerboseLog::writeLine(TR_Vlog_FSD, "Ignoring user specified optLevel");
if (_countString)
Expand All @@ -2255,7 +2255,6 @@ OMR::Options::jitLatePostProcess(TR::OptionSet *optionSet, void * jitConfig)
}
}
_countString = 0;
TR_VerboseLog::vlogRelease();
}

if (TR::Options::isAnyVerboseOptionSet(TR_VerboseOptimizer)
Expand Down Expand Up @@ -3093,12 +3092,11 @@ OMR::Options::validateOptionsTables(void *feBase, TR_FrontEnd *fe)
}
if (_numJitEntries > 0 && stricmp_ignore_locale((opt-1)->name, opt->name) >= 0)
{
TR_VerboseLog::vlogAcquire();
TR_VerboseLog::CriticalSection vlogLock;
TR_VerboseLog::write(TR_Vlog_FAILURE, "JIT option table entries out of order: ");
TR_VerboseLog::write((opt-1)->name);
TR_VerboseLog::write(", ");
TR_VerboseLog::writeLine(opt->name);
TR_VerboseLog::vlogRelease();
return false;
}
#endif
Expand All @@ -3120,12 +3118,11 @@ OMR::Options::validateOptionsTables(void *feBase, TR_FrontEnd *fe)
}
if (_numVmEntries > 0 && stricmp_ignore_locale((opt-1)->name, opt->name) >= 0)
{
TR_VerboseLog::vlogAcquire();
TR_VerboseLog::CriticalSection vlogLock;
TR_VerboseLog::writeLine(TR_Vlog_FAILURE,"FE option table entries out of order: ");
TR_VerboseLog::write((opt-1)->name);
TR_VerboseLog::write(", ");
TR_VerboseLog::write(opt->name);
TR_VerboseLog::vlogRelease();
return false;
}
#endif
Expand Down
3 changes: 1 addition & 2 deletions compiler/env/CompileTimeProfiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class CompileTimeProfiler
// Dump the options
if (TR::Options::getVerboseOption(TR_VerbosePerformance))
{
TR_VerboseLog::vlogAcquire();
TR_VerboseLog::CriticalSection vlogLock;
TR_VerboseLog::write("Profiling %s compile time with:", comp->signature());
char **iter = options;
while (*iter)
Expand All @@ -109,7 +109,6 @@ class CompileTimeProfiler
iter++;
}
TR_VerboseLog::writeLine("");
TR_VerboseLog::vlogRelease();
}

_pid = fork();
Expand Down
3 changes: 1 addition & 2 deletions compiler/env/TRPersistentMemory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,10 @@ TR_PersistentMemory::printMemStats()
void
TR_PersistentMemory::printMemStatsToVlog()
{
TR_VerboseLog::vlogAcquire();
TR_VerboseLog::CriticalSection vlogLock;
TR_VerboseLog::writeLine(TR_Vlog_MEMORY, "TR_PersistentMemory Stats:");
for (uint32_t i = 0; i < TR_MemoryBase::NumObjectTypes; i++)
{
TR_VerboseLog::writeLine(TR_Vlog_MEMORY, "\t_totalPersistentAllocations[%s]=%lu", objectName[i], (unsigned long)_totalPersistentAllocations[i]);
}
TR_VerboseLog::vlogRelease();
}
3 changes: 1 addition & 2 deletions compiler/env/VerboseLog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,14 @@ void TR_VerboseLog::writeLine(const char *format, ...)
void TR_VerboseLog::writeLineLocked(TR_VlogTag tag, const char *format, ...)
{
TR_ASSERT(tag != TR_Vlog_null, "TR_Vlog_null is not a valid Vlog tag");
vlogAcquire();
CriticalSection lock;
va_list args;
va_start(args, format);
writeTimeStamp();
write(_vlogTable[tag]);
vwrite(format, args);
write("\n");
va_end(args);
vlogRelease();
}

void TR_VerboseLog::write(const char *format, ...)
Expand Down
9 changes: 3 additions & 6 deletions compiler/infra/SimpleRegex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,13 +393,12 @@ bool SimpleRegex::match(const char *s, bool isCaseSensitive, bool useLocale)

void SimpleRegex::print(bool negate)
{
TR_VerboseLog::vlogAcquire();
TR_VerboseLog::CriticalSection vlogLock;
TR_VerboseLog::write("{");
if (negate ^ _negate)
TR_VerboseLog::write("^");
_regex->print();
TR_VerboseLog::write("}");
TR_VerboseLog::vlogRelease();
}


Expand All @@ -409,17 +408,16 @@ void SimpleRegex::Regex::print()
simple->print();
if (remainder)
{
TR_VerboseLog::vlogAcquire();
TR_VerboseLog::CriticalSection vlogLock;
TR_VerboseLog::write("|");
TR_VerboseLog::vlogRelease();
remainder->print();
}
}


void SimpleRegex::Simple::print()
{
TR_VerboseLog::vlogAcquire();
TR_VerboseLog::CriticalSection vlogLock;
int32_t i;
switch (component->type)
{
Expand Down Expand Up @@ -458,7 +456,6 @@ void SimpleRegex::Simple::print()
}
if (remainder)
remainder->print();
TR_VerboseLog::vlogRelease();
}


Expand Down
10 changes: 3 additions & 7 deletions compiler/ras/LimitFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,14 +786,14 @@ void TR_FilterBST::insert(TR_FilterBST *node)
void
TR_Debug::print(TR_FilterBST * filter)
{
TR_VerboseLog::CriticalSection vlogLock;
/*
if (filter->_optionSet)
TR_VerboseLog::write(" {%d}", filter->_optionSet);
if (filter->_lineNumber)
TR_VerboseLog::write(" [%d]", filter->_lineNumber);
*/
TR_VerboseLog::vlogAcquire();

switch (filter->_filterType)
{
Expand Down Expand Up @@ -861,8 +861,6 @@ TR_Debug::print(TR_FilterBST * filter)
printFilters(filter->subGroup);
TR_VerboseLog::write(" ]\n");
}

TR_VerboseLog::vlogRelease();
}

void
Expand Down Expand Up @@ -895,7 +893,7 @@ TR_Debug::printFilters(TR::CompilationFilters * filters)
void
TR_Debug::printFilters()
{
TR_VerboseLog::vlogAcquire();
TR_VerboseLog::CriticalSection vlogLock;
TR_VerboseLog::writeLine("<compilationFilters>");
printFilters(_compilationFilters);
TR_VerboseLog::writeLine("</compilationFilters>");
Expand All @@ -907,7 +905,6 @@ TR_Debug::printFilters()
TR_VerboseLog::writeLine("<inlineFilters>");
printFilters(_inlineFilters);
TR_VerboseLog::writeLine("</inlineFilters>");
TR_VerboseLog::vlogRelease();
}

void
Expand Down Expand Up @@ -1250,7 +1247,7 @@ TR_Debug::methodCanBeRelocated(TR_Memory *trMemory, TR_ResolvedMethod *method, T
int32_t *
TR_Debug::loadCustomStrategy(char *fileName)
{
TR_VerboseLog::vlogAcquire();
TR_VerboseLog::CriticalSection vlogLock;
int32_t *customStrategy = NULL;
FILE *optFile = fopen(fileName, "r");
if (optFile)
Expand Down Expand Up @@ -1308,6 +1305,5 @@ TR_Debug::loadCustomStrategy(char *fileName)
{
TR_VerboseLog::writeLine(TR_Vlog_INFO, "optFile not found: '%s'", fileName);
}
TR_VerboseLog::vlogRelease();
return customStrategy;
}
7 changes: 3 additions & 4 deletions compiler/ras/OptionsDebug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ static bool regexExcludes(TR::SimpleRegex *regex, const char *string)

void TR_Debug::dumpOptionHelp(TR::OptionTable * firstOjit, TR::OptionTable * firstOfe, TR::SimpleRegex *nameFilter)
{
TR_VerboseLog::vlogAcquire();
static int optionLineWidth=0;

if (!optionLineWidth)
Expand All @@ -162,6 +161,7 @@ void TR_Debug::dumpOptionHelp(TR::OptionTable * firstOjit, TR::OptionTable * fir

TR::OptionTable * entry;

TR_VerboseLog::CriticalSection vlogLock;
TR_VerboseLog::writeLine(TR_Vlog_INFO,"Usage: -Xjit:option([,option]*)\n");

for (int32_t cat = 0; optionCategories[cat]; cat++)
Expand Down Expand Up @@ -276,7 +276,6 @@ void TR_Debug::dumpOptionHelp(TR::OptionTable * firstOjit, TR::OptionTable * fir
}
TR_VerboseLog::writeLine("");
TR_VerboseLog::writeLine(TR_Vlog_INFO, "");
TR_VerboseLog::vlogRelease();
}

void
Expand All @@ -290,7 +289,6 @@ TR_Debug::dumpOptions(
void * feBase,
TR_FrontEnd *fe)
{
TR_VerboseLog::vlogAcquire();
TR::OptionTable *entry;
char *base;
TR::Compilation* comp = TR::comp();
Expand All @@ -301,6 +299,8 @@ TR_Debug::dumpOptions(
TR_J9VMBase *fej9 = (TR_J9VMBase *)fe;
#endif

TR_VerboseLog::CriticalSection vlogLock;

if(!vmCounter)
TR_VerboseLog::writeLine(TR_Vlog_INFO,"_______________________________________");

Expand Down Expand Up @@ -512,5 +512,4 @@ TR_Debug::dumpOptions(
TR_VerboseLog::writeLine(TR_Vlog_INFO, " compressedRefs shiftAmount=%d", TR::Compiler->om.compressedReferenceShift());
}
#endif
TR_VerboseLog::vlogRelease();
}

0 comments on commit 04bcb60

Please sign in to comment.