From: Stephen Toub Date: Tue, 9 Oct 2018 18:52:34 +0000 (-0400) Subject: Avoid building DebugFinalizableAsyncStateMachineBox unless necessary (#20318) X-Git-Tag: accepted/tizen/unified/20190422.045933~1045 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=efe3c451fbd2a788f51340c28cd36777ef60b49d;p=platform%2Fupstream%2Fcoreclr.git Avoid building DebugFinalizableAsyncStateMachineBox unless necessary (#20318) --- diff --git a/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilder.cs b/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilder.cs index fc37ca7..acfbd14 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/AsyncMethodBuilder.cs +++ b/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()); }