diff options
author | Michal Strehovský <MichalStrehovsky@users.noreply.github.com> | 2017-01-18 03:12:43 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-18 03:12:43 +0300 |
commit | f7a6c331eddabcbe9ec852b126240ae3642c96f1 (patch) | |
tree | acd4866faf18806a33a9ea52e25a80065db790cc | |
parent | d06f5d39a0cf028b713d13d4bbef725db78c644b (diff) | |
parent | 2b801186a2a037fdcd9ba88d3375be8e4d9ce2fc (diff) |
Merge pull request #2524 from dotnet/nmirror
Merge nmirror to master
9 files changed, 45 insertions, 88 deletions
diff --git a/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj b/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj index 15ea8ef11..baf7c70b5 100644 --- a/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj +++ b/src/System.Private.CoreLib/src/System.Private.CoreLib.csproj @@ -222,6 +222,7 @@ <Compile Include="System\BadImageFormatException.cs" /> <Compile Include="System\Boolean.cs" /> <Compile Include="System\Buffer.cs" /> + <Compile Include="System\ByReference.cs" /> <Compile Include="System\Byte.cs" /> <Compile Include="System\Char.cs" /> <Compile Include="System\CharEnumerator.cs" /> diff --git a/src/System.Private.CoreLib/src/System/ByReference.cs b/src/System.Private.CoreLib/src/System/ByReference.cs new file mode 100644 index 000000000..d0129c2ee --- /dev/null +++ b/src/System.Private.CoreLib/src/System/ByReference.cs @@ -0,0 +1,41 @@ +// 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.Runtime.CompilerServices; + +namespace System +{ + // ByReference<T> is meant to be used to represent "ref T" fields. It is working + // around lack of first class support for byref fields in C# and IL. The JIT and + // type loader have special handling for it that turns it into a thin wrapper around ref T. + [StackOnly] + internal struct ByReference<T> + { + // CS0169: The private field '{blah}' is never used +#pragma warning disable 169 + private IntPtr _value; +#pragma warning restore + + [Intrinsic] + public ByReference(ref T value) + { + // Implemented as a JIT intrinsic - This default implementation is for + // completeness and to provide a concrete error if called via reflection + // or if intrinsic is missed. + throw new System.PlatformNotSupportedException(); + } + + public ref T Value + { + [Intrinsic] + get + { + // Implemented as a JIT intrinsic - This default implementation is for + // completeness and to provide a concrete error if called via reflection + // or if the intrinsic is missed. + throw new System.PlatformNotSupportedException(); + } + } + } +} diff --git a/src/System.Private.CoreLib/src/System/Environment.cs b/src/System.Private.CoreLib/src/System/Environment.cs index 274c4e2a4..41d5dc038 100644 --- a/src/System.Private.CoreLib/src/System/Environment.cs +++ b/src/System.Private.CoreLib/src/System/Environment.cs @@ -33,9 +33,6 @@ namespace System Machine = 2, } - // Environment is marked as Eager to allow Lock to read the current - // thread ID, since Lock is used in ClassConstructorRunner.Cctor.GetCctor - [EagerOrderedStaticConstructor(EagerStaticConstructorOrder.SystemEnvironment)] public static partial class Environment { /*==================================TickCount=================================== diff --git a/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/ClassConstructorRunner.cs b/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/ClassConstructorRunner.cs index 1b917fb94..f2f9ff581 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/ClassConstructorRunner.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/ClassConstructorRunner.cs @@ -13,9 +13,6 @@ using Internal.Runtime.CompilerHelpers; namespace System.Runtime.CompilerServices { - // Marked [EagerOrderedStaticConstructor] because Cctor.GetCctor - // uses _cctorGlobalLock - [EagerOrderedStaticConstructor(EagerStaticConstructorOrder.CompilerServicesClassConstructorRunner)] internal static partial class ClassConstructorRunner { //============================================================================================================== @@ -482,17 +479,7 @@ namespace System.Runtime.CompilerServices private static int s_cctorArraysCount; private static int s_count; - // - // CoreRT calls Initialize directly for all types its needs that typically have EagerOrderedStaticConstructor - // attributes. To retain compatibility, please ensure static initialization is not done inline, and instead - // added to Initialize. - // -#if !CORERT - static ClassConstructorRunner() - { - Initialize(); - } -#endif + // Eager construction called from LibraryInitialize Cctor.GetCctor uses _cctorGlobalLock. internal static void Initialize() { s_cctorArrays = new Cctor[10][]; diff --git a/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/EagerOrderedStaticConstructorAttribute.cs b/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/EagerOrderedStaticConstructorAttribute.cs index ba4279c43..f3a699b17 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/EagerOrderedStaticConstructorAttribute.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/EagerOrderedStaticConstructorAttribute.cs @@ -22,19 +22,6 @@ namespace System.Runtime.CompilerServices public enum EagerStaticConstructorOrder : int { - // System.Private.CoreLib - SystemString, - SystemPreallocatedOutOfMemoryException, - SystemEnvironment, // ClassConstructorRunner.Cctor.GetCctor use Lock which inturn use current threadID , so System.Environment - // should come before CompilerServicesClassConstructorRunnerCctor - CompilerServicesClassConstructorRunnerCctor, - CompilerServicesClassConstructorRunner, - - // System.Private.TypeLoader - RuntimeTypeHandleEqualityComparer, - TypeLoaderEnvironment, - SystemRuntimeTypeLoaderExports, - // Interop InteropHeap, VtableIUnknown, diff --git a/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/InternalCompilerAttributes.cs b/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/InternalCompilerAttributes.cs index 298b4e466..3ad095e91 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/InternalCompilerAttributes.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/InternalCompilerAttributes.cs @@ -21,21 +21,4 @@ namespace System.Runtime.CompilerServices [AttributeUsage(AttributeTargets.Struct)] public sealed class StackOnlyAttribute : Attribute { } - -#if false // Unused right now. It is likely going to be useful for Span<T> implementation. - // This is a dummy class to be replaced by the compiler with a ref T - // It has to be a dummy class to avoid complicated type substitution - // and other complications in the compiler. - public sealed class ByReference<T> - { - // - // Managed pointer creation - // - [Intrinsic] - public static extern ByReference<T> FromRef(ref T source); - - [Intrinsic] - public static extern ref T ToRef(ByReference<T> source); - } -#endif } diff --git a/src/System.Private.CoreLib/src/System/Runtime/TypeLoaderExports.cs b/src/System.Private.CoreLib/src/System/Runtime/TypeLoaderExports.cs index 57e8efd79..64b50165e 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/TypeLoaderExports.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/TypeLoaderExports.cs @@ -11,8 +11,6 @@ using System.Runtime.InteropServices; namespace System.Runtime { - // Initialize the cache eagerly to avoid null checks - [EagerOrderedStaticConstructor(EagerStaticConstructorOrder.SystemRuntimeTypeLoaderExports)] public static class TypeLoaderExports { [RuntimeExport("GetThreadStaticsForDynamicType")] @@ -80,18 +78,6 @@ namespace System.Runtime private volatile static IntPtr[] s_resolutionFunctionPointers; private static int s_nextResolutionFunctionPointerIndex; - // - // CoreRT calls Initialize directly for all types its needs that typically have EagerOrderedStaticConstructor - // attributes. To retain compatibility, please ensure static initialization is not done inline, and instead - // added to Initialize. - // -#if !CORERT - static TypeLoaderExports() - { - Initialize(); - } -#endif - internal static void Initialize() { s_cache = new Entry[1]; diff --git a/src/System.Private.CoreLib/src/System/RuntimeExceptionHelpers.cs b/src/System.Private.CoreLib/src/System/RuntimeExceptionHelpers.cs index c53f1a251..1a47b20a7 100644 --- a/src/System.Private.CoreLib/src/System/RuntimeExceptionHelpers.cs +++ b/src/System.Private.CoreLib/src/System/RuntimeExceptionHelpers.cs @@ -13,24 +13,11 @@ using Internal.Runtime.Augments; namespace System { - // Eagerly preallocate instance of out of memory exception to avoid infinite recursion once we run out of memory - [EagerOrderedStaticConstructor(EagerStaticConstructorOrder.SystemPreallocatedOutOfMemoryException)] internal class PreallocatedOutOfMemoryException { public static OutOfMemoryException Instance { get; private set; } - // - // CoreRT calls Initialize directly for all types its needs that typically have EagerOrderedStaticConstructor - // attributes. To retain compatibility, please ensure static initialization is not done inline, and instead - // added to Initialize. - // -#if !CORERT - static PreallocatedOutOfMemoryException() - { - Initialize(); - } -#endif - + // Eagerly preallocate instance of out of memory exception to avoid infinite recursion once we run out of memory internal static void Initialize() { Instance = new OutOfMemoryException(message: null); // Cannot call the nullary constructor as that triggers non-trivial resource manager logic. diff --git a/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.cs b/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.cs index b6309bd22..addf2ed12 100644 --- a/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.cs +++ b/src/System.Private.TypeLoader/src/Internal/Runtime/TypeLoader/TypeLoaderEnvironment.cs @@ -86,7 +86,6 @@ namespace Internal.Runtime.TypeLoader } } - [EagerOrderedStaticConstructor(EagerStaticConstructorOrder.TypeLoaderEnvironment)] public sealed partial class TypeLoaderEnvironment { [ThreadStatic] @@ -107,18 +106,7 @@ namespace Internal.Runtime.TypeLoader [ThreadStatic] private static LowLevelDictionary<IntPtr, NativeReader> t_moduleNativeReaders; - // - // CoreRT calls Initialize directly for all types its needs that typically have EagerOrderedStaticConstructor - // attributes. To retain compatibility, please ensure static initialization is not done inline, and instead - // added to Initialize. - // -#if !CORERT - static TypeLoaderEnvironment() - { - Initialize(); - } -#endif - + // Eager initialization called from LibraryInitializer for the assembly. internal static void Initialize() { Instance = new TypeLoaderEnvironment(); |