From: Ben Adams Date: Sat, 3 Feb 2018 05:29:30 +0000 (+0000) Subject: Remove AsyncMethodBuilder from shared partition (#16149) X-Git-Tag: accepted/tizen/unified/20190422.045933~3089 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=67feb5e680e4e94756e0133744da2c7150565666;p=platform%2Fupstream%2Fcoreclr.git Remove AsyncMethodBuilder from shared partition (#16149) * Remove AsyncMethodBuilder from shared partition * AsyncMethodBuilder => AsyncMethodBuilderCore --- diff --git a/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems b/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems index 0ae7972..b41cce1 100644 --- a/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems +++ b/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems @@ -364,7 +364,6 @@ - diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/AsyncMethodBuilder.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/AsyncMethodBuilder.cs deleted file mode 100644 index 8fa5b54..0000000 --- a/src/mscorlib/shared/System/Runtime/CompilerServices/AsyncMethodBuilder.cs +++ /dev/null @@ -1,68 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. -// See the LICENSE file in the project root for more information. - -using System; -using System.Diagnostics; -using System.Threading; - -namespace System.Runtime.CompilerServices -{ - internal static partial class AsyncMethodBuilder - { - /// Initiates the builder's execution with the associated state machine. - /// Specifies the type of the state machine. - /// The state machine instance, passed by reference. - [DebuggerStepThrough] - public static void Start(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine - { - if (stateMachine == null) // TStateMachines are generally non-nullable value types, so this check will be elided - { - ThrowHelper.ThrowArgumentNullException(ExceptionArgument.stateMachine); - } - - // enregistrer variables with 0 post-fix so they can be used in registers without EH forcing them to stack - // Capture references to Thread Contexts - Thread currentThread0 = Thread.CurrentThread; - Thread currentThread = currentThread0; - ExecutionContext previousExecutionCtx0 = currentThread0.ExecutionContext; - - // Store current ExecutionContext and SynchronizationContext as "previousXxx". - // This allows us to restore them and undo any Context changes made in stateMachine.MoveNext - // so that they won't "leak" out of the first await. - ExecutionContext previousExecutionCtx = previousExecutionCtx0; - SynchronizationContext previousSyncCtx = currentThread0.SynchronizationContext; - - try - { - stateMachine.MoveNext(); - } - finally - { - // Re-enregistrer variables post EH with 1 post-fix so they can be used in registers rather than from stack - SynchronizationContext previousSyncCtx1 = previousSyncCtx; - Thread currentThread1 = currentThread; - // The common case is that these have not changed, so avoid the cost of a write barrier if not needed. - if (previousSyncCtx1 != currentThread1.SynchronizationContext) - { - // Restore changed SynchronizationContext back to previous - currentThread1.SynchronizationContext = previousSyncCtx1; - } - - ExecutionContext previousExecutionCtx1 = previousExecutionCtx; - ExecutionContext currentExecutionCtx1 = currentThread1.ExecutionContext; - if (previousExecutionCtx1 != currentExecutionCtx1) - { - // Restore changed ExecutionContext back to previous - currentThread1.ExecutionContext = previousExecutionCtx1; - if ((currentExecutionCtx1 != null && currentExecutionCtx1.HasChangeNotifications) || - (previousExecutionCtx1 != null && previousExecutionCtx1.HasChangeNotifications)) - { - // There are change notifications; trigger any affected - ExecutionContext.OnValuesChanged(currentExecutionCtx1, previousExecutionCtx1); - } - } - } - } - } -} diff --git a/src/mscorlib/shared/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilder.cs b/src/mscorlib/shared/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilder.cs index ac9886a..49cdacc 100644 --- a/src/mscorlib/shared/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilder.cs +++ b/src/mscorlib/shared/System/Runtime/CompilerServices/AsyncValueTaskMethodBuilder.cs @@ -44,7 +44,7 @@ namespace System.Runtime.CompilerServices #if netstandard _methodBuilder.Start(ref stateMachine); #else - AsyncMethodBuilder.Start(ref stateMachine); // will provide the right ExecutionContext semantics + AsyncMethodBuilderCore.Start(ref stateMachine); #endif /// Associates the builder with the specified state machine. diff --git a/src/mscorlib/src/System/Runtime/CompilerServices/AsyncMethodBuilder.cs b/src/mscorlib/src/System/Runtime/CompilerServices/AsyncMethodBuilder.cs index de38583..ebb9363 100644 --- a/src/mscorlib/src/System/Runtime/CompilerServices/AsyncMethodBuilder.cs +++ b/src/mscorlib/src/System/Runtime/CompilerServices/AsyncMethodBuilder.cs @@ -51,7 +51,7 @@ namespace System.Runtime.CompilerServices [DebuggerStepThrough] [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Start(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine => - AsyncMethodBuilder.Start(ref stateMachine); + AsyncMethodBuilderCore.Start(ref stateMachine); /// Associates the builder with the state machine it represents. /// The heap-allocated state machine object. @@ -201,7 +201,7 @@ namespace System.Runtime.CompilerServices [DebuggerStepThrough] [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Start(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine => - AsyncMethodBuilder.Start(ref stateMachine); + AsyncMethodBuilderCore.Start(ref stateMachine); /// Associates the builder with the state machine it represents. /// The heap-allocated state machine object. @@ -316,7 +316,7 @@ namespace System.Runtime.CompilerServices [DebuggerStepThrough] [MethodImpl(MethodImplOptions.AggressiveInlining)] public void Start(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine => - AsyncMethodBuilder.Start(ref stateMachine); + AsyncMethodBuilderCore.Start(ref stateMachine); /// Associates the builder with the state machine it represents. /// The heap-allocated state machine object. @@ -894,6 +894,61 @@ namespace System.Runtime.CompilerServices /// Shared helpers for manipulating state related to async state machines. internal static class AsyncMethodBuilderCore // debugger depends on this exact name { + /// Initiates the builder's execution with the associated state machine. + /// Specifies the type of the state machine. + /// The state machine instance, passed by reference. + [DebuggerStepThrough] + public static void Start(ref TStateMachine stateMachine) where TStateMachine : IAsyncStateMachine + { + if (stateMachine == null) // TStateMachines are generally non-nullable value types, so this check will be elided + { + ThrowHelper.ThrowArgumentNullException(ExceptionArgument.stateMachine); + } + + // enregistrer variables with 0 post-fix so they can be used in registers without EH forcing them to stack + // Capture references to Thread Contexts + Thread currentThread0 = Thread.CurrentThread; + Thread currentThread = currentThread0; + ExecutionContext previousExecutionCtx0 = currentThread0.ExecutionContext; + + // Store current ExecutionContext and SynchronizationContext as "previousXxx". + // This allows us to restore them and undo any Context changes made in stateMachine.MoveNext + // so that they won't "leak" out of the first await. + ExecutionContext previousExecutionCtx = previousExecutionCtx0; + SynchronizationContext previousSyncCtx = currentThread0.SynchronizationContext; + + try + { + stateMachine.MoveNext(); + } + finally + { + // Re-enregistrer variables post EH with 1 post-fix so they can be used in registers rather than from stack + SynchronizationContext previousSyncCtx1 = previousSyncCtx; + Thread currentThread1 = currentThread; + // The common case is that these have not changed, so avoid the cost of a write barrier if not needed. + if (previousSyncCtx1 != currentThread1.SynchronizationContext) + { + // Restore changed SynchronizationContext back to previous + currentThread1.SynchronizationContext = previousSyncCtx1; + } + + ExecutionContext previousExecutionCtx1 = previousExecutionCtx; + ExecutionContext currentExecutionCtx1 = currentThread1.ExecutionContext; + if (previousExecutionCtx1 != currentExecutionCtx1) + { + // Restore changed ExecutionContext back to previous + currentThread1.ExecutionContext = previousExecutionCtx1; + if ((currentExecutionCtx1 != null && currentExecutionCtx1.HasChangeNotifications) || + (previousExecutionCtx1 != null && previousExecutionCtx1.HasChangeNotifications)) + { + // There are change notifications; trigger any affected + ExecutionContext.OnValuesChanged(currentExecutionCtx1, previousExecutionCtx1); + } + } + } + } + /// Gets whether we should be tracking async method completions for eventing. internal static bool TrackAsyncMethodCompletion {