Skip to content

Instantly share code, notes, and snippets.

@feO2x
Last active February 6, 2018 19:51
Show Gist options
  • Save feO2x/d7959d0939c540a7b4cdde4da3650b80 to your computer and use it in GitHub Desktop.
Save feO2x/d7959d0939c540a7b4cdde4da3650b80 to your computer and use it in GitHub Desktop.
MustHaveValue JIT
00007ff8`6020ec10 ThrowMethodInlined.Benchmarks.IntBenchmarks.MustHaveValueBaseVersion()
00007ff8`6020ec15 488d4108 lea rax,[rcx+8]
00007ff8`6020ec19 0fb610 movzx edx,byte ptr [rax]
00007ff8`6020ec1c 8b4004 mov eax,dword ptr [rax+4]
00007ff8`6020ec1f 84d2 test dl,dl
00007ff8`6020ec21 740a je 00007ff8`6020ec2d
00007ff8`6020ec23 488b4108 mov rax,qword ptr [rcx+8]
00007ff8`6020ec27 4883c420 add rsp,20h
00007ff8`6020ec2b 5e pop rsi
00007ff8`6020ec2c c3 ret
00007ff8`6020ec2d 48b9584e3560f87f0000 mov rcx,7FF860354E58h
00007ff8`6020ec37 e8f417b05f call coreclr!coreclr_execute_assembly+0x18180 (00007ff8`bfd10430)
not managed method
00007ff8`6020ec3c 488bf0 mov rsi,rax
00007ff8`6020ec3f b901000000 mov ecx,1
00007ff8`6020ec44 48ba78f62a60f87f0000 mov rdx,7FF8602AF678h
00007ff8`6020ec4e e86d39ae5f call coreclr!MetaDataGetDispenser+0x16bf0 (00007ff8`bfcf25c0)
not managed method
00007ff8`6020ec53 488bd0 mov rdx,rax
00007ff8`6020ec56 488bce mov rcx,rsi
00007ff8`6020ec59 4533c0 xor r8d,r8d
00007ff8`6020ec5c e81ff9b45d call System_Private_CoreLib+0x5fe580 (00007ff8`bdd5e580)
ctor
00007ff8`6020ec61 488bce mov rcx,rsi
00007ff8`6020ec64 e85705aa5f call coreclr+0xdf1c0 (00007ff8`bfcaf1c0)
not managed method
00007ff8`6020ec69 cc int 3
00007ff8`6020ec6a 0000 add byte ptr [rax],al
00007ff8`6020ec6c 190502000532 sbb dword ptr [00007ff8`9225ec74],eax
00007ff8`6020ec72 016040 add dword ptr [rax+40h],esp
00007ff8`6020ec75 0000 add byte ptr [rax],al
00007ff8`6020ec77 00f8 add al,bh
00007ff8`6020ec79 0936 or dword ptr [rsi],esi
00007ff8`6020ec7b 60 ???
00007ff8`6020ec7c f8 clc
00007ff8`6020ec7d 7f00 jg 00007ff8`6020ec7f
00007ff8`6020ec7f 00c3 add bl,al
00007ff8`bdd5e580 System.ArgumentNullException..ctor(System.String, System.String)
00007ff8`bdd5e590 488bce mov rcx,rsi
00007ff8`bdd5e593 e8e8230100 call System_Private_CoreLib+0x610980 (00007ff8`bdd70980)
System.Exception.Init()
00007ff8`bdd5e598 488d4e18 lea rcx,[rsi+18h]
00007ff8`bdd5e59c 488bd3 mov rdx,rbx
00007ff8`bdd5e59f e86ccacbff call System_Private_CoreLib+0x2bb010 (00007ff8`bda1b010)
not managed method
00007ff8`bdd5e5a4 c7467c01151380 mov dword ptr [rsi+7Ch],80131501h
00007ff8`bdd5e5ab 488d8e88000000 lea rcx,[rsi+88h]
00007ff8`bdd5e5b2 488bd7 mov rdx,rdi
00007ff8`bdd5e5b5 e856cacbff call System_Private_CoreLib+0x2bb010 (00007ff8`bda1b010)
not managed method
00007ff8`bdd5e5ba c7467c57000780 mov dword ptr [rsi+7Ch],80070057h
00007ff8`bdd5e5c1 c7467c03400080 mov dword ptr [rsi+7Ch],80004003h
00007ff8`bdd5e5c8 4883c420 add rsp,20h
No ILOffsetMap found
ThrowMethodInlined.Benchmarks.NullableHasNoValueException..ctor(System.String, System.String)
00007ff8`6021ec10 ThrowMethodInlined.Benchmarks.IntBenchmarks.MustHaveValueExtensionMethod()
00007ff8`6021ec14 4883c108 add rcx,8
00007ff8`6021ec18 0fb611 movzx edx,byte ptr [rcx]
00007ff8`6021ec1b 88542430 mov byte ptr [rsp+30h],dl
00007ff8`6021ec1f 8b4904 mov ecx,dword ptr [rcx+4]
00007ff8`6021ec22 894c2434 mov dword ptr [rsp+34h],ecx
00007ff8`6021ec26 c644242800 mov byte ptr [rsp+28h],0
00007ff8`6021ec2b 33c9 xor ecx,ecx
00007ff8`6021ec2d 894c242c mov dword ptr [rsp+2Ch],ecx
00007ff8`6021ec31 807c243000 cmp byte ptr [rsp+30h],0
00007ff8`6021ec36 7407 je 00007ff8`6021ec3f
00007ff8`6021ec38 488b442430 mov rax,qword ptr [rsp+30h]
00007ff8`6021ec3d eb24 jmp 00007ff8`6021ec63
00007ff8`6021ec3f 48b9a8333577c0020000 mov rcx,2C0773533A8h
00007ff8`6021ec49 488b09 mov rcx,qword ptr [rcx]
00007ff8`6021ec4c 33d2 xor edx,edx
00007ff8`6021ec4e e8add7ffff call 00007ff8`6021c400
ThrowMethodInlined.Benchmarks.Throw.NullableHasNoValue(System.String, System.String)
00007ff8`6021ec53 c644242800 mov byte ptr [rsp+28h],0
00007ff8`6021ec58 33c0 xor eax,eax
00007ff8`6021ec5a 8944242c mov dword ptr [rsp+2Ch],eax
00007ff8`6021ec5e 488b442428 mov rax,qword ptr [rsp+28h]
No ILOffsetMap found
ThrowMethodInlined.Benchmarks.Throw.NullableHasNoValue(System.String, System.String)
namespace MustHaveValueBenchmark
{
[CoreJob]
[MemoryDiagnoser]
[DisassemblyDiagnoser]
public class IntBenchmarks
{
public readonly int? NullableWithValue = 42;
[Benchmark(Baseline = true)]
public int? MustHaveValueBaseVersion()
{
if (NullableWithValue.HasValue == false) throw new NullableHasNoValueException(nameof(NullableWithValue));
return NullableWithValue;
}
[Benchmark]
public int? MustHaveValueExtensionMethod()
{
return NullableWithValue.MustHaveValue(nameof(NullableWithValue));
}
}
public static class AssertionMethods
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T? MustHaveValue<T>(this T? parameter, string parameterName = null, string message = null) where T : struct
{
if (parameter.HasValue == false)
Throw.NullableHasNoValue(parameterName, message);
return parameter;
}
}
public static class Throw
{
[MethodImpl(MethodImplOptions.NoInlining)]
public static void NullableHasNoValue(string parameterName = null, string message = null)
{
throw new NullableHasNoValueException(parameterName, message ?? $"{parameterName ?? "The nullable"} must have a value, but it actually is null.");
}
}
[Serializable]
public class NullableHasNoValueException : ArgumentNullException
{
public NullableHasNoValueException(string parameterName = null, string message = null)
: base(parameterName, message) { }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment