diff --git a/src/BenchmarkDotNet/Engines/Engine.cs b/src/BenchmarkDotNet/Engines/Engine.cs index f271783590..018994a526 100644 --- a/src/BenchmarkDotNet/Engines/Engine.cs +++ b/src/BenchmarkDotNet/Engines/Engine.cs @@ -225,15 +225,18 @@ private ClockSpan Measure(Action action, long invokeCount) var exceptionsStats = new ExceptionsStats(); // allocates exceptionsStats.StartListening(); // this method might allocate +#if !NET7_0_OR_GREATER 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, // and NOT allocate anything on the background thread when we are measuring allocations. - // This is only an issue on netcoreapp3.0 to net6.0. Tiered jit allocations were fixed in net7.0, + // This is only an issue on netcoreapp3.0 to net6.0. Tiered jit allocations were "fixed" in net7.0 + // (maybe not completely eliminated forever, but at least reduced to a point where measurements are much more stable), // and netcoreapp2.X uses only GetAllocatedBytesForCurrentThread which doesn't capture the tiered jit allocations. Thread.Sleep(TimeSpan.FromMilliseconds(500)); } +#endif // GC collect before measuring allocations. ForceGcCollect(); diff --git a/tests/BenchmarkDotNet.IntegrationTests/MemoryDiagnoserTests.cs b/tests/BenchmarkDotNet.IntegrationTests/MemoryDiagnoserTests.cs index 6562c95f2b..a3567eca55 100755 --- a/tests/BenchmarkDotNet.IntegrationTests/MemoryDiagnoserTests.cs +++ b/tests/BenchmarkDotNet.IntegrationTests/MemoryDiagnoserTests.cs @@ -29,7 +29,7 @@ namespace BenchmarkDotNet.IntegrationTests public class MemoryDiagnoserTests { // TODO: re-enable allocating tests after https://github.com/dotnet/runtime/issues/101536 is fixed. - private const string AllocatingSkipReason = "System.Runtime.InteropServices.RuntimeInformation allocates during GC collect"; + private const string AllocatingSkipReason = "GC collect causes allocations on finalizer thread"; private readonly ITestOutputHelper output;