Skip to content

Commit

Permalink
[release/7.0] Fix signature for 64-bit delegate profiling helper (#74743
Browse files Browse the repository at this point in the history
)

* Fix signature for 64-bit delegate profiling helper

I missed updating the signature of the 64-bit variant here when the
vtable and delegate profiling helpers were originally split up.

Fix #74295

* JIT: Randomly collect 64-bit counts

Add some testing.

* Disable collecting 64 bit counters on 32-bit

This needs some work so disable it for now.

Co-authored-by: Jakob Botsch Nielsen <[email protected]>
  • Loading branch information
github-actions[bot] and jakobbotsch authored Aug 29, 2022
1 parent dff9c90 commit 6fa754e
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 9 deletions.
15 changes: 15 additions & 0 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3211,6 +3211,21 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
#endif
}

#ifdef TARGET_64BIT
opts.compCollect64BitCounts = JitConfig.JitCollect64BitCounts() != 0;

#ifdef DEBUG
if (JitConfig.JitRandomlyCollect64BitCounts() != 0)
{
CLRRandom rng;
rng.Init(info.compMethodHash() ^ JitConfig.JitRandomlyCollect64BitCounts() ^ 0x3485e20e);
opts.compCollect64BitCounts = rng.Next(2) == 0;
}
#endif
#else
opts.compCollect64BitCounts = false;
#endif

#ifdef DEBUG

// Now, set compMaxUncheckedOffsetForNullObject for STRESS_NULL_OBJECT_CHECK
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -9291,6 +9291,9 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
// Use early multi-dimensional array operator expansion (expand after loop optimizations; before lowering).
bool compJitEarlyExpandMDArrays;

// Collect 64 bit counts for PGO data.
bool compCollect64BitCounts;

} opts;

static bool s_pAltJitExcludeAssembliesListInitialized;
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/jit/fgprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ void BlockCountInstrumentor::BuildSchemaElements(BasicBlock* block, Schema& sche
ICorJitInfo::PgoInstrumentationSchema schemaElem;
schemaElem.Count = 1;
schemaElem.Other = 0;
schemaElem.InstrumentationKind = JitConfig.JitCollect64BitCounts()
schemaElem.InstrumentationKind = m_comp->opts.compCollect64BitCounts
? ICorJitInfo::PgoInstrumentationKind::BasicBlockLongCount
: ICorJitInfo::PgoInstrumentationKind::BasicBlockIntCount;
schemaElem.ILOffset = offset;
Expand Down Expand Up @@ -1314,7 +1314,7 @@ void EfficientEdgeCountInstrumentor::BuildSchemaElements(BasicBlock* block, Sche
ICorJitInfo::PgoInstrumentationSchema schemaElem;
schemaElem.Count = 1;
schemaElem.Other = targetKey;
schemaElem.InstrumentationKind = JitConfig.JitCollect64BitCounts()
schemaElem.InstrumentationKind = m_comp->opts.compCollect64BitCounts
? ICorJitInfo::PgoInstrumentationKind::EdgeLongCount
: ICorJitInfo::PgoInstrumentationKind::EdgeIntCount;
schemaElem.ILOffset = sourceKey;
Expand Down Expand Up @@ -1503,7 +1503,7 @@ class BuildHandleHistogramProbeSchemaGen
schemaElem.Other |= ICorJitInfo::HandleHistogram32::DELEGATE_FLAG;
}

schemaElem.InstrumentationKind = JitConfig.JitCollect64BitCounts()
schemaElem.InstrumentationKind = compiler->opts.compCollect64BitCounts
? ICorJitInfo::PgoInstrumentationKind::HandleHistogramLongCount
: ICorJitInfo::PgoInstrumentationKind::HandleHistogramIntCount;
schemaElem.ILOffset = (int32_t)call->gtHandleHistogramProfileCandidateInfo->ilOffset;
Expand Down
4 changes: 3 additions & 1 deletion src/coreclr/jit/jitconfigvalues.h
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,9 @@ CONFIG_STRING(JitEnablePgoRange, W("JitEnablePgoRange")) // Enable pgo d
CONFIG_INTEGER(JitRandomEdgeCounts, W("JitRandomEdgeCounts"), 0) // Substitute random values for edge counts
CONFIG_INTEGER(JitCrossCheckDevirtualizationAndPGO, W("JitCrossCheckDevirtualizationAndPGO"), 0)
CONFIG_INTEGER(JitNoteFailedExactDevirtualization, W("JitNoteFailedExactDevirtualization"), 0)
#endif // debug
CONFIG_INTEGER(JitRandomlyCollect64BitCounts, W("JitRandomlyCollect64BitCounts"), 0) // Collect 64-bit counts randomly
// for some methods.
#endif // debug

// Devirtualize virtual calls with getExactClasses (NativeAOT only for now)
CONFIG_INTEGER(JitEnableExactDevirtualization, W("JitEnableExactDevirtualization"), 1)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/jithelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5571,7 +5571,7 @@ HCIMPL2(void, JIT_DelegateProfile32, Object *obj, ICorJitInfo::HandleHistogram32
HCIMPLEND

// Version of helper above used when the count is 64-bit
HCIMPL3(void, JIT_DelegateProfile64, Object *obj, CORINFO_METHOD_HANDLE baseMethod, ICorJitInfo::HandleHistogram64* methodProfile)
HCIMPL2(void, JIT_DelegateProfile64, Object *obj, ICorJitInfo::HandleHistogram64* methodProfile)
{
FCALL_CONTRACT;
FC_GC_POLL_NOT_NEEDED();
Expand Down
9 changes: 5 additions & 4 deletions src/tests/Common/testenvironment.proj
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
COMPlus_JitRandomGuardedDevirtualization;
COMPlus_JitRandomEdgeCounts;
COMPlus_JitRandomOnStackReplacement;
COMPlus_JitRandomlyCollect64BitCounts;
COMPlus_JitForceControlFlowGuard;
COMPlus_JitCFGUseDispatcher;
RunningIlasmRoundTrip
Expand Down Expand Up @@ -209,10 +210,10 @@
<TestEnvironment Include="dynamicpgo" TieredPGO="1" TieredCompilation="1" TC_QuickJitForLoops="1" />
<TestEnvironment Include="fullpgo" TieredPGO="1" TieredCompilation="1" TC_QuickJitForLoops="1" ReadyToRun="0"/>
<TestEnvironment Include="fullpgo_methodprofiling" TieredPGO="1" TieredCompilation="1" TC_QuickJitForLoops="1" ReadyToRun="0" JitDelegateProfiling="1" JitVTableProfiling="1" />
<TestEnvironment Include="fullpgo_random_gdv" TieredPGO="1" TieredCompilation="1" TC_QuickJitForLoops="1" ReadyToRun="0" JitRandomGuardedDevirtualization="1"/>
<TestEnvironment Include="fullpgo_random_gdv_methodprofiling_only" TieredPGO="1" TieredCompilation="1" TC_QuickJitForLoops="1" ReadyToRun="0" JitRandomGuardedDevirtualization="1" JitClassProfiling="0" JitDelegateProfiling="1" JitVTableProfiling="1" />
<TestEnvironment Include="fullpgo_random_edge" TieredPGO="1" TieredCompilation="1" TC_QuickJitForLoops="1" ReadyToRun="0" JitRandomEdgeCounts="1"/>
<TestEnvironment Include="fullpgo_random_gdv_edge" TieredPGO="1" TieredCompilation="1" TC_QuickJitForLoops="1" ReadyToRun="0" JitRandomGuardedDevirtualization="1" JitRandomEdgeCounts="1"/>
<TestEnvironment Include="fullpgo_random_gdv" TieredPGO="1" TieredCompilation="1" TC_QuickJitForLoops="1" ReadyToRun="0" JitRandomGuardedDevirtualization="1" JitRandomlyCollect64BitCounts="1" />
<TestEnvironment Include="fullpgo_random_gdv_methodprofiling_only" TieredPGO="1" TieredCompilation="1" TC_QuickJitForLoops="1" ReadyToRun="0" JitRandomGuardedDevirtualization="1" JitClassProfiling="0" JitDelegateProfiling="1" JitVTableProfiling="1" JitRandomlyCollect64BitCounts="1" />
<TestEnvironment Include="fullpgo_random_edge" TieredPGO="1" TieredCompilation="1" TC_QuickJitForLoops="1" ReadyToRun="0" JitRandomEdgeCounts="1" JitRandomlyCollect64BitCounts="1" />
<TestEnvironment Include="fullpgo_random_gdv_edge" TieredPGO="1" TieredCompilation="1" TC_QuickJitForLoops="1" ReadyToRun="0" JitRandomGuardedDevirtualization="1" JitRandomEdgeCounts="1" JitRandomlyCollect64BitCounts="1" />
<TestEnvironment Include="gcstandalone" Condition="'$(TargetsWindows)' == 'true'" GCName="clrgc.dll"/>
<TestEnvironment Include="gcstandalone" Condition="'$(TargetsWindows)' != 'true'" GCName="libclrgc.so"/>
<TestEnvironment Include="gcstandaloneserver" Condition="'$(TargetsWindows)' == 'true'" gcServer="1" GCName="clrgc.dll"/>
Expand Down

0 comments on commit 6fa754e

Please sign in to comment.