Skip to content

Commit

Permalink
JIT: Optimize JitStressOnly (dotnet#91815)
Browse files Browse the repository at this point in the history
Calling MethodSet::Contains on every invocation to compStressCompile is
very expensive since it requires multiple JIT-EE calls to print the full
method name. This merges the logic with the existing cached bool.
  • Loading branch information
jakobbotsch authored Sep 22, 2023
1 parent d59a99e commit 24ead90
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
33 changes: 11 additions & 22 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1790,7 +1790,7 @@ void Compiler::compInit(ArenaAllocator* pAlloc,
info.compClassHnd = compHnd->getMethodClass(methodHnd);

#ifdef DEBUG
bRangeAllowStress = false;
compAllowStress = true;

// set this early so we can use it without relying on random memory values
verbose = compIsForInlining() ? impInlineInfo->InlinerCompiler->verbose : false;
Expand Down Expand Up @@ -1830,7 +1830,11 @@ void Compiler::compInit(ArenaAllocator* pAlloc,
static ConfigMethodRange fJitStressRange;
fJitStressRange.EnsureInit(JitConfig.JitStressRange());
assert(!fJitStressRange.Error());
bRangeAllowStress = fJitStressRange.Contains(info.compMethodHash());
compAllowStress =
fJitStressRange.Contains(info.compMethodHash()) &&
(JitConfig.JitStressOnly().isEmpty() ||
JitConfig.JitStressOnly().contains(info.compMethodHnd, info.compClassHnd, &info.compMethodInfo->args));

#endif // DEBUG

eeInfoInitialized = false;
Expand Down Expand Up @@ -3522,13 +3526,7 @@ unsigned Compiler::compStressAreaHash(compStressArea area)
//
bool Compiler::compStressCompileHelper(compStressArea stressArea, unsigned weight)
{
if (!bRangeAllowStress)
{
return false;
}

if (!JitConfig.JitStressOnly().isEmpty() &&
!JitConfig.JitStressOnly().contains(info.compMethodHnd, info.compClassHnd, &info.compMethodInfo->args))
if (!compAllowStress)
{
return false;
}
Expand Down Expand Up @@ -4323,23 +4321,14 @@ const char* Compiler::compGetStressMessage() const
if ((JitConfig.JitStressModeNames() != nullptr) || (getJitStressLevel() > 0))
{
// Is the method being jitted excluded from stress via range?
if (bRangeAllowStress)
if (compAllowStress)
{
// Or is it excluded via name?
if (!JitConfig.JitStressOnly().isEmpty() ||
!JitConfig.JitStressOnly().contains(info.compMethodHnd, info.compClassHnd, &info.compMethodInfo->args))
{
// Not excluded -- stress can happen
stressMessage = " JitStress";
}
else
{
stressMessage = " NoJitStress(Only)";
}
// Not excluded -- stress can happen
stressMessage = " JitStress";
}
else
{
stressMessage = " NoJitStress(Range)";
stressMessage = " NoJitStress";
}
}
#endif // DEBUG
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9355,7 +9355,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// State information - which phases have completed?
// These are kept together for easy discoverability

bool bRangeAllowStress;
bool compAllowStress;
bool compCodeGenDone;
int64_t compNumStatementLinksTraversed; // # of links traversed while doing debug checks
bool fgNormalizeEHDone; // Has the flowgraph EH normalization phase been done?
Expand Down

0 comments on commit 24ead90

Please sign in to comment.