diff options
author | Marek Safar <marek.safar@gmail.com> | 2019-03-09 06:32:53 +0100 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2019-03-08 21:32:53 -0800 |
commit | ed505143f888a16402d0ce891412cdf4f2cb4724 (patch) | |
tree | 32f0a1fbd16859666d928de78e95c5cd338f88b6 | |
parent | c194074a82ee35f31b1e55233b43256713b26467 (diff) | |
download | coreclr-ed505143f888a16402d0ce891412cdf4f2cb4724.tar.gz coreclr-ed505143f888a16402d0ce891412cdf4f2cb4724.tar.bz2 coreclr-ed505143f888a16402d0ce891412cdf4f2cb4724.zip |
Move part of RuntimeHelpers to shared partition (#23130)
* Move part of RuntimeHelpers to shared partition
* Remove FormatterServices.cs
7 files changed, 76 insertions, 144 deletions
diff --git a/src/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/System.Private.CoreLib/System.Private.CoreLib.csproj index 816d3cef33..836eb00fe9 100644 --- a/src/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -239,7 +239,6 @@ <Compile Include="$(BclSourcesRoot)\System\Runtime\InteropServices\NativeLibrary.cs" /> <Compile Include="$(BclSourcesRoot)\System\Runtime\Loader\AssemblyDependencyResolver.cs" /> <Compile Include="$(BclSourcesRoot)\System\Runtime\Loader\AssemblyLoadContext.CoreCLR.cs" /> - <Compile Include="$(BclSourcesRoot)\System\Runtime\Serialization\FormatterServices.cs" /> <Compile Include="$(BclSourcesRoot)\System\Runtime\Versioning\CompatibilitySwitch.cs" /> <Compile Include="$(BclSourcesRoot)\System\RuntimeArgumentHandle.cs" /> <Compile Include="$(BclSourcesRoot)\System\RuntimeHandles.cs" /> diff --git a/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems b/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems index a168f09a01..c03b8b1ea8 100644 --- a/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems +++ b/src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems @@ -575,6 +575,7 @@ <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\ReferenceAssemblyAttribute.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RuntimeCompatibilityAttribute.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RuntimeFeature.cs" /> + <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RuntimeHelpers.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\RuntimeWrappedException.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\SpecialNameAttribute.cs" /> <Compile Include="$(MSBuildThisFileDirectory)System\Runtime\CompilerServices\StateMachineAttribute.cs" /> diff --git a/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeHelpers.cs b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeHelpers.cs new file mode 100644 index 0000000000..fcb69eceec --- /dev/null +++ b/src/System.Private.CoreLib/shared/System/Runtime/CompilerServices/RuntimeHelpers.cs @@ -0,0 +1,66 @@ +// 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.Serialization; + +namespace System.Runtime.CompilerServices +{ + public static partial class RuntimeHelpers + { + public delegate void TryCode(object userData); + + public delegate void CleanupCode(object userData, bool exceptionThrown); + + /// <summary> + /// GetSubArray helper method for the compiler to slice an array using a range. + /// </summary> + public static T[] GetSubArray<T>(T[] array, Range range) + { + Type elementType = array.GetType().GetElementType(); + Span<T> source = array.AsSpan(range); + + if (elementType.IsValueType) + { + return source.ToArray(); + } + else + { + T[] newArray = (T[])Array.CreateInstance(elementType, source.Length); + source.CopyTo(newArray); + return newArray; + } + } + + public static object GetUninitializedObject(Type type) + { + if (type is null) + { + throw new ArgumentNullException(nameof(type), SR.ArgumentNull_Type); + } + + if (!type.IsRuntimeImplemented()) + { + throw new SerializationException(SR.Format(SR.Serialization_InvalidType, type.ToString())); + } + + return GetUninitializedObjectInternal(type); + } + + public static void PrepareContractedDelegate(Delegate d) + { + } + + public static void ProbeForSufficientStack() + { + } + + public static void PrepareConstrainedRegions() + { + } + + public static void PrepareConstrainedRegionsNoOP() + { + } + } +}
\ No newline at end of file diff --git a/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs b/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs index 94a6379f5f..1851d9fb2b 100644 --- a/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs +++ b/src/System.Private.CoreLib/src/System/Runtime/CompilerServices/RuntimeHelpers.cs @@ -2,37 +2,14 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -//////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// -// -// RuntimeHelpers -// This class defines a set of static methods that provide support for compilers. -// -// +using System.Diagnostics; +using System.Runtime.InteropServices; +using Internal.Runtime.CompilerServices; namespace System.Runtime.CompilerServices { - using System; - using System.Diagnostics; - using System.Security; - using System.Runtime; - using System.Runtime.CompilerServices; - using System.Runtime.InteropServices; - using System.Runtime.ConstrainedExecution; - using System.Runtime.Serialization; - using System.Threading; - using System.Runtime.Versioning; - using Internal.Runtime.CompilerServices; - - public static class RuntimeHelpers + public static partial class RuntimeHelpers { - // Exposed here as a more appropriate place than on FormatterServices itself, - // which is a high level reflection heavy type. - public static object GetUninitializedObject(Type type) - { - return FormatterServices.GetUninitializedObject(type); - } - [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern void InitializeArray(Array array, RuntimeFieldHandle fldHandle); @@ -113,8 +90,6 @@ namespace System.Runtime.CompilerServices } } - public static void PrepareContractedDelegate(Delegate d) { } - [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern void PrepareDelegate(Delegate d); @@ -160,27 +135,6 @@ namespace System.Runtime.CompilerServices [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern bool TryEnsureSufficientExecutionStack(); - public static void ProbeForSufficientStack() - { - } - - // This method is a marker placed immediately before a try clause to mark the corresponding catch and finally blocks as - // constrained. There's no code here other than the probe because most of the work is done at JIT time when we spot a call to this routine. - public static void PrepareConstrainedRegions() - { - ProbeForSufficientStack(); - } - - // When we detect a CER with no calls, we can point the JIT to this non-probing version instead - // as we don't need to probe. - public static void PrepareConstrainedRegionsNoOP() - { - } - - public delegate void TryCode(object userData); - - public delegate void CleanupCode(object userData, bool exceptionThrown); - [MethodImplAttribute(MethodImplOptions.InternalCall)] public static extern void ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, object userData); @@ -197,26 +151,6 @@ namespace System.Runtime.CompilerServices throw new InvalidOperationException(); } - /// <summary> - /// GetSubArray helper method for the compiler to slice an array using a range. - /// </summary> - public static T[] GetSubArray<T>(T[] array, Range range) - { - Type elementType = array.GetType().GetElementType(); - Span<T> source = array.AsSpan(range); - - if (elementType.IsValueType) - { - return source.ToArray(); - } - else - { - T[] newArray = (T[])Array.CreateInstance(elementType, source.Length); - source.CopyTo(newArray); - return newArray; - } - } - // Returns true iff the object has a component size; // i.e., is variable length like System.String or Array. [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -256,5 +190,9 @@ namespace System.Runtime.CompilerServices // Ideally this would just be a single dereference: // mov tmp, qword ptr [rax] ; rax = obj ref, tmp = MethodTable* pointer } + + [MethodImplAttribute(MethodImplOptions.InternalCall)] + private static extern object GetUninitializedObjectInternal(Type type); + } } diff --git a/src/System.Private.CoreLib/src/System/Runtime/Serialization/FormatterServices.cs b/src/System.Private.CoreLib/src/System/Runtime/Serialization/FormatterServices.cs deleted file mode 100644 index 9da385bbf4..0000000000 --- a/src/System.Private.CoreLib/src/System/Runtime/Serialization/FormatterServices.cs +++ /dev/null @@ -1,64 +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. - -/*============================================================ -** -** -** -** Purpose: Provides some static methods to aid with the implementation -** of a Formatter for Serialization. -** -** -============================================================*/ - -using System; -using System.Reflection; -using System.Collections; -using System.Collections.Generic; -using System.Security; -using System.Runtime.CompilerServices; -using System.Runtime.Versioning; -using System.Threading; -using System.IO; -using System.Text; -using System.Globalization; -using System.Diagnostics; - -namespace System.Runtime.Serialization -{ - // This class duplicates a class on CoreFX. We are keeping it here -- just this one method -- - // as it was widely invoked by reflection to workaround it being missing in .NET Core 1.0 - internal static class FormatterServices - { - // Gets a new instance of the object. The entire object is initalized to 0 and no - // constructors have been run. **THIS MEANS THAT THE OBJECT MAY NOT BE IN A STATE - // CONSISTENT WITH ITS INTERNAL REQUIREMENTS** This method should only be used for - // deserialization when the user intends to immediately populate all fields. This method - // will not create an unitialized string because it is non-sensical to create an empty - // instance of an immutable type. - // - public static object GetUninitializedObject(Type type) - { - if ((object)type == null) - { - throw new ArgumentNullException(nameof(type)); - } - - if (!(type is RuntimeType)) - { - throw new SerializationException(SR.Format(SR.Serialization_InvalidType, type)); - } - - return nativeGetUninitializedObject((RuntimeType)type); - } - - [MethodImplAttribute(MethodImplOptions.InternalCall)] - private static extern object nativeGetUninitializedObject(RuntimeType type); - } -} - - - - - diff --git a/src/vm/ecalllist.h b/src/vm/ecalllist.h index 0298939dbf..b4f9895301 100644 --- a/src/vm/ecalllist.h +++ b/src/vm/ecalllist.h @@ -163,10 +163,6 @@ FCFuncStart(gEnvironmentFuncs) FCFuncElementSig("FailFast", &gsig_SM_Str_Exception_Str_RetVoid, SystemNative::FailFastWithExceptionAndSource) FCFuncEnd() -FCFuncStart(gSerializationFuncs) - FCFuncElement("nativeGetUninitializedObject", ReflectionSerialization::GetUninitializedObject) -FCFuncEnd() - FCFuncStart(gExceptionFuncs) FCFuncElement("IsImmutableAgileException", ExceptionNative::IsImmutableAgileException) FCFuncElement("nIsTransient", ExceptionNative::IsTransient) @@ -919,6 +915,7 @@ FCFuncStart(gRuntimeHelpers) FCFuncElement("Equals", ObjectNative::Equals) FCFuncElement("EnsureSufficientExecutionStack", ReflectionInvocation::EnsureSufficientExecutionStack) FCFuncElement("TryEnsureSufficientExecutionStack", ReflectionInvocation::TryEnsureSufficientExecutionStack) + FCFuncElement("GetUninitializedObjectInternal", ReflectionSerialization::GetUninitializedObject) FCFuncEnd() FCFuncStart(gContextSynchronizationFuncs) @@ -1196,7 +1193,6 @@ FCClassElement("EventPipeInternal", "System.Diagnostics.Tracing", gEventPipeInte #endif // FEATURE_PERFTRACING FCClassElement("Exception", "System", gExceptionFuncs) FCClassElement("FileLoadException", "System.IO", gFileLoadExceptionFuncs) -FCClassElement("FormatterServices", "System.Runtime.Serialization", gSerializationFuncs) FCClassElement("GC", "System", gGCInterfaceFuncs) FCClassElement("GCHandle", "System.Runtime.InteropServices", gGCHandleFuncs) FCClassElement("GCSettings", "System.Runtime", gGCSettingsFuncs) diff --git a/src/vm/reflectioninvocation.cpp b/src/vm/reflectioninvocation.cpp index a69f5439c2..1f8aa04593 100644 --- a/src/vm/reflectioninvocation.cpp +++ b/src/vm/reflectioninvocation.cpp @@ -2581,10 +2581,6 @@ FCIMPL1(Object*, ReflectionSerialization::GetUninitializedObject, ReflectClassBa HELPER_METHOD_FRAME_BEGIN_RET_NOPOLL(); - if (objType == NULL) { - COMPlusThrowArgumentNull(W("type"), W("ArgumentNull_Type")); - } - TypeHandle type = objType->GetType(); // Don't allow arrays, pointers, byrefs or function pointers. |