Skip to content

Commit

Permalink
Implemented feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
timcassell committed Apr 23, 2024
1 parent 917988c commit 2c94c02
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/BenchmarkDotNet/Engines/Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ private ClockSpan Measure(Action<long> action, long invokeCount)
var exceptionsStats = new ExceptionsStats(); // allocates
exceptionsStats.StartListening(); // this method might allocate

if (RuntimeInformation.IsNetCore && Environment.Version.Major is >= 3 and <= 6 && Environment.GetEnvironmentVariable("COMPlus_TieredCompilation") != "0")
if (RuntimeInformation.IsNetCore && Environment.Version.Major is >= 3 and <= 6 && RuntimeInformation.IsTieredJitEnabled)
{
// #1542
// We put the current thread to sleep so tiered jit can kick in, compile its stuff,
Expand Down
6 changes: 3 additions & 3 deletions src/BenchmarkDotNet/Engines/GcStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public int GetCollectionsCount(int generation)
return AllocatedBytes <= AllocationQuantum ? 0L : AllocatedBytes;
}

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

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

// Make sure tier0 jit doesn't cause any unexpected allocations in this method.
// Skip tier0 jit to make sure we don't get any unexpected allocations in this method.
[MethodImpl(CodeGenHelper.AggressiveOptimizationOption)]
private static long? GetAllocatedBytes()
{
Expand Down
12 changes: 12 additions & 0 deletions src/BenchmarkDotNet/Portability/RuntimeInformation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,18 @@ private static bool IsAotMethod()
public static readonly bool IsAot = !System.Runtime.CompilerServices.RuntimeFeature.IsDynamicCodeCompiled;
#endif

public static readonly bool IsTieredJitEnabled =
IsNetCore
&& (Environment.Version.Major < 3
// Disabled by default in netcoreapp2.X, check if it's enabled.
? Environment.GetEnvironmentVariable("COMPlus_TieredCompilation") == "1"
|| Environment.GetEnvironmentVariable("DOTNET_TieredCompilation") == "1"
|| (AppContext.TryGetSwitch("System.Runtime.TieredCompilation", out bool isEnabled) && isEnabled)
// Enabled by default in netcoreapp3.0+, check if it's disabled.
: Environment.GetEnvironmentVariable("COMPlus_TieredCompilation") != "0"
&& Environment.GetEnvironmentVariable("DOTNET_TieredCompilation") != "0"
&& (!AppContext.TryGetSwitch("System.Runtime.TieredCompilation", out isEnabled) || isEnabled));

public static bool IsRunningInContainer => string.Equals(Environment.GetEnvironmentVariable("DOTNET_RUNNING_IN_CONTAINER"), "true");

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

0 comments on commit 2c94c02

Please sign in to comment.