Skip to content

Commit 2c94c02

Browse files
committed
Implemented feedback.
1 parent 917988c commit 2c94c02

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/BenchmarkDotNet/Engines/Engine.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ private ClockSpan Measure(Action<long> action, long invokeCount)
225225
var exceptionsStats = new ExceptionsStats(); // allocates
226226
exceptionsStats.StartListening(); // this method might allocate
227227

228-
if (RuntimeInformation.IsNetCore && Environment.Version.Major is >= 3 and <= 6 && Environment.GetEnvironmentVariable("COMPlus_TieredCompilation") != "0")
228+
if (RuntimeInformation.IsNetCore && Environment.Version.Major is >= 3 and <= 6 && RuntimeInformation.IsTieredJitEnabled)
229229
{
230230
// #1542
231231
// We put the current thread to sleep so tiered jit can kick in, compile its stuff,

src/BenchmarkDotNet/Engines/GcStats.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public int GetCollectionsCount(int generation)
107107
return AllocatedBytes <= AllocationQuantum ? 0L : AllocatedBytes;
108108
}
109109

110-
// Make sure tier0 jit doesn't cause any unexpected allocations in this method.
110+
// Skip tier0 jit to make sure we don't get any unexpected allocations in this method.
111111
[MethodImpl(CodeGenHelper.AggressiveOptimizationOption)]
112112
public static GcStats ReadInitial()
113113
{
@@ -121,7 +121,7 @@ public static GcStats ReadInitial()
121121
0);
122122
}
123123

124-
// Make sure tier0 jit doesn't cause any unexpected allocations in this method.
124+
// Skip tier0 jit to make sure we don't get any unexpected allocations in this method.
125125
[MethodImpl(CodeGenHelper.AggressiveOptimizationOption)]
126126
public static GcStats ReadFinal()
127127
{
@@ -137,7 +137,7 @@ public static GcStats ReadFinal()
137137
public static GcStats FromForced(int forcedFullGarbageCollections)
138138
=> new GcStats(forcedFullGarbageCollections, forcedFullGarbageCollections, forcedFullGarbageCollections, 0, 0);
139139

140-
// Make sure tier0 jit doesn't cause any unexpected allocations in this method.
140+
// Skip tier0 jit to make sure we don't get any unexpected allocations in this method.
141141
[MethodImpl(CodeGenHelper.AggressiveOptimizationOption)]
142142
private static long? GetAllocatedBytes()
143143
{

src/BenchmarkDotNet/Portability/RuntimeInformation.cs

+12
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,18 @@ private static bool IsAotMethod()
8585
public static readonly bool IsAot = !System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeCompiled;
8686
#endif
8787

88+
public static readonly bool IsTieredJitEnabled =
89+
IsNetCore
90+
&& (Environment.Version.Major < 3
91+
// Disabled by default in netcoreapp2.X, check if it's enabled.
92+
? Environment.GetEnvironmentVariable("COMPlus_TieredCompilation") == "1"
93+
|| Environment.GetEnvironmentVariable("DOTNET_TieredCompilation") == "1"
94+
|| (AppContext.TryGetSwitch("System.Runtime.TieredCompilation", out bool isEnabled) && isEnabled)
95+
// Enabled by default in netcoreapp3.0+, check if it's disabled.
96+
: Environment.GetEnvironmentVariable("COMPlus_TieredCompilation") != "0"
97+
&& Environment.GetEnvironmentVariable("DOTNET_TieredCompilation") != "0"
98+
&& (!AppContext.TryGetSwitch("System.Runtime.TieredCompilation", out isEnabled) || isEnabled));
99+
88100
public static bool IsRunningInContainer => string.Equals(Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER"), "true");
89101

90102
internal static string ExecutableExtension => IsWindows() ? ".exe" : string.Empty;

0 commit comments

Comments
 (0)