Skip to content

Commit c2cee25

Browse files
Fix the CI
* Fix pointer-returning benchmarks support for InProcessToolchain * add UIntPtr, nint and unint support * disable TieredJit so it's background allocations don't show up in allocated memory reported by MemoryDiagnoser tests Co-authored-by: Adam Sitnik <[email protected]>
1 parent 6f453ba commit c2cee25

File tree

6 files changed

+61
-6
lines changed

6 files changed

+61
-6
lines changed

build/common.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
</PropertyGroup>
2929

3030
<PropertyGroup Condition=" '$(IsVisualBasic)' != 'true' AND '$(IsFsharp)' != 'true' ">
31-
<LangVersion>7.3</LangVersion>
31+
<LangVersion>9.0</LangVersion>
3232

3333
<Major>0</Major>
3434
<Minor>13</Minor>

src/BenchmarkDotNet/Engines/Consumer.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ private static readonly HashSet<Type> SupportedTypes
3333
private string stringHolder;
3434
private object objectHolder;
3535
private IntPtr ptrHolder;
36+
private UIntPtr uptrHolder;
3637

3738
[MethodImpl(MethodImplOptions.AggressiveInlining)]
3839
[PublicAPI]
@@ -81,6 +82,14 @@ private static readonly HashSet<Type> SupportedTypes
8182
[PublicAPI]
8283
public void Consume(long longValue) => Volatile.Write(ref longHolder, longValue);
8384

85+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
86+
[PublicAPI]
87+
public void Consume(IntPtr intPtrValue) => Volatile.Write(ref ptrHolder, intPtrValue);
88+
89+
[MethodImpl(MethodImplOptions.AggressiveInlining)]
90+
[PublicAPI]
91+
public void Consume(UIntPtr uintPtrValue) => Volatile.Write(ref uptrHolder, uintPtrValue);
92+
8493
[CLSCompliant(false)]
8594
[MethodImpl(MethodImplOptions.AggressiveInlining)]
8695
[PublicAPI]

src/BenchmarkDotNet/Toolchains/InProcess.Emit.Implementation/Emitters/ConsumableConsumeEmitter.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,18 @@ private static MethodInfo GetConsumeMethod(Type consumableType)
2020
{
2121
consumeMethod = typeof(Consumer)
2222
.GetMethods()
23-
.Single(m => m.Name == nameof(Consumer.Consume) && m.IsGenericMethodDefinition
24-
&& m.GetParameterTypes().First().IsByRef == false);
25-
consumeMethod = consumeMethod?.MakeGenericMethod(consumableType);
23+
.Single(m =>
24+
{
25+
Type argType = m.GetParameterTypes().FirstOrDefault();
26+
27+
return m.Name == nameof(Consumer.Consume) && m.IsGenericMethodDefinition
28+
&& !argType.IsByRef // we are not interested in "Consume<T>(in T value)"
29+
&& argType.IsPointer == consumableType.IsPointer; // use "Consume<T>(T objectValue) where T : class" or "Consume<T>(T* ptrValue) where T: unmanaged"
30+
});
31+
32+
consumeMethod = consumableType.IsPointer
33+
? consumeMethod.MakeGenericMethod(consumableType.GetElementType()) // consumableType is T*, we need T for Consume<T>(T* ptrValue)
34+
: consumeMethod.MakeGenericMethod(consumableType);
2635
}
2736
else
2837
{

tests/BenchmarkDotNet.IntegrationTests/MemoryDiagnoserTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ private IConfig CreateConfig(IToolchain toolchain)
293293
.WithWarmupCount(0) // don't run warmup to save some time for our CI runs
294294
.WithIterationCount(1) // single iteration is enough for us
295295
.WithGcForce(false)
296+
.WithEnvironmentVariable("COMPlus_TieredCompilation", "0") // Tiered JIT can allocate some memory on a background thread, let's disable it to make our tests less flaky (#1542)
296297
.WithToolchain(toolchain))
297298
.AddColumnProvider(DefaultColumnProviders.Instance)
298299
.AddDiagnoser(MemoryDiagnoser.Default)

tests/BenchmarkDotNet.IntegrationTests/ValuesReturnedByBenchmarkTest.cs

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Collections.Immutable;
34
using BenchmarkDotNet.Attributes;
5+
using BenchmarkDotNet.Configs;
46
using BenchmarkDotNet.Environments;
7+
using BenchmarkDotNet.Jobs;
8+
using BenchmarkDotNet.Toolchains;
9+
using BenchmarkDotNet.Toolchains.InProcess.Emit;
510
using Xunit;
611
using Xunit.Abstractions;
712

@@ -11,8 +16,14 @@ public class ValuesReturnedByBenchmarkTest : BenchmarkTestExecutor
1116
{
1217
public ValuesReturnedByBenchmarkTest(ITestOutputHelper output) : base(output) { }
1318

14-
[Fact]
15-
public void AnyValueCanBeReturned() => CanExecute<ValuesReturnedByBenchmark>();
19+
public static IEnumerable<object[]> GetToolchains() => new[]
20+
{
21+
new object[] { Job.Default.GetToolchain() },
22+
new object[] { InProcessEmitToolchain.Instance },
23+
};
24+
25+
[Theory, MemberData(nameof(GetToolchains))]
26+
public void AnyValueCanBeReturned(IToolchain toolchain) => CanExecute<ValuesReturnedByBenchmark>(ManualConfig.CreateEmpty().AddJob(Job.Dry.WithToolchain(toolchain)));
1627

1728
public class ValuesReturnedByBenchmark
1829
{
@@ -93,6 +104,24 @@ public class Job { }
93104

94105
[Benchmark]
95106
public NoNamespace TypeWithoutNamespace() => new NoNamespace();
107+
108+
[Benchmark]
109+
public unsafe void* PointerToAnything() => System.IntPtr.Zero.ToPointer();
110+
111+
[Benchmark]
112+
public unsafe int* PointerToUnmanagedType() => (int*)System.IntPtr.Zero.ToPointer();
113+
114+
[Benchmark]
115+
public System.IntPtr IntPtr() => System.IntPtr.Zero;
116+
117+
[Benchmark]
118+
public System.UIntPtr UIntPtr() => System.UIntPtr.Zero;
119+
120+
[Benchmark]
121+
public nint NativeSizeInteger() => 0;
122+
123+
[Benchmark]
124+
public nuint UnsignedNativeSizeInteger() => 0;
96125
}
97126
}
98127
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"runtimeOptions": {
3+
"configProperties": {
4+
"System.Runtime.TieredCompilation": false
5+
}
6+
}
7+
}

0 commit comments

Comments
 (0)