diff --git a/src/coreclr/jit/compiler.cpp b/src/coreclr/jit/compiler.cpp
index dd0e41fe9852d..ac7cad00b2a0b 100644
--- a/src/coreclr/jit/compiler.cpp
+++ b/src/coreclr/jit/compiler.cpp
@@ -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
diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h
index d1b52ab79e947..2d0bf69a28180 100644
--- a/src/coreclr/jit/compiler.h
+++ b/src/coreclr/jit/compiler.h
@@ -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;
diff --git a/src/coreclr/jit/fgprofile.cpp b/src/coreclr/jit/fgprofile.cpp
index bf3e77fc78405..39190c6a48fa6 100644
--- a/src/coreclr/jit/fgprofile.cpp
+++ b/src/coreclr/jit/fgprofile.cpp
@@ -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;
@@ -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;
@@ -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;
diff --git a/src/coreclr/jit/jitconfigvalues.h b/src/coreclr/jit/jitconfigvalues.h
index efd5adf017c7d..2c15b310b1a91 100644
--- a/src/coreclr/jit/jitconfigvalues.h
+++ b/src/coreclr/jit/jitconfigvalues.h
@@ -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)
diff --git a/src/coreclr/vm/jithelpers.cpp b/src/coreclr/vm/jithelpers.cpp
index e2b23d5c5dfae..86503f3d0efa5 100644
--- a/src/coreclr/vm/jithelpers.cpp
+++ b/src/coreclr/vm/jithelpers.cpp
@@ -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();
diff --git a/src/tests/Common/testenvironment.proj b/src/tests/Common/testenvironment.proj
index f60eb9b8394ac..afa5bbecf7b68 100644
--- a/src/tests/Common/testenvironment.proj
+++ b/src/tests/Common/testenvironment.proj
@@ -66,6 +66,7 @@
COMPlus_JitRandomGuardedDevirtualization;
COMPlus_JitRandomEdgeCounts;
COMPlus_JitRandomOnStackReplacement;
+ COMPlus_JitRandomlyCollect64BitCounts;
COMPlus_JitForceControlFlowGuard;
COMPlus_JitCFGUseDispatcher;
RunningIlasmRoundTrip
@@ -209,10 +210,10 @@
-
-
-
-
+
+
+
+