From: Stephen Toub Date: Tue, 9 Oct 2018 18:52:34 +0000 (-0400) Subject: Avoid building DebugFinalizableAsyncStateMachineBox unless necessary (dotnet/coreclr... X-Git-Tag: submit/tizen/20210909.063632~11030^2~3741 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=499c9a5e2d29283ceb67a1f9a4c7cd8cb1db3dd4;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Avoid building DebugFinalizableAsyncStateMachineBox unless necessary (dotnet/coreclr#20318) Commit migrated from https://github.com/dotnet/coreclr/commit/efe3c451fbd2a788f51340c28cd36777ef60b49d --- diff --git a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilder.cs b/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilder.cs index fc37ca7..acfbd14 100644 --- a/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilder.cs +++ b/src/coreclr/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilder.cs @@ -485,7 +485,7 @@ namespace System.Runtime.CompilerServices // object's identity to track this specific builder/state machine. As such, we proceed to // overwrite whatever's there anyway, even if it's non-null. var box = AsyncMethodBuilderCore.TrackAsyncMethodCompletion ? - new DebugFinalizableAsyncStateMachineBox() : + CreateDebugFinalizableAsyncStateMachineBox() : new AsyncStateMachineBox(); m_task = box; // important: this must be done before storing stateMachine into box.StateMachine! box.StateMachine = stateMachine; @@ -493,6 +493,12 @@ namespace System.Runtime.CompilerServices return box; } + // Avoid forcing the JIT to build DebugFinalizableAsyncStateMachineBox unless it's actually needed. + [MethodImpl(MethodImplOptions.NoInlining)] + private static AsyncStateMachineBox CreateDebugFinalizableAsyncStateMachineBox() + where TStateMachine : IAsyncStateMachine => + new DebugFinalizableAsyncStateMachineBox(); + /// /// Provides an async state machine box with a finalizer that will fire an EventSource /// event about the state machine if it's being finalized without having been completed. @@ -617,7 +623,7 @@ namespace System.Runtime.CompilerServices { Debug.Assert(m_task == null); return (m_task = AsyncMethodBuilderCore.TrackAsyncMethodCompletion ? - new DebugFinalizableAsyncStateMachineBox() : + CreateDebugFinalizableAsyncStateMachineBox() : new AsyncStateMachineBox()); }