From 4fe82ad2734a61ab7072e292ed3d0b507e42edae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Fri, 22 Jan 2021 17:52:16 +0100 Subject: [PATCH] Delete RuntimeTypeHandle.GetValueInternal (#577) GetValueInternal may or may not go away from RyuJIT at some point. We originally used this to implement EETypePtrOf, but the IL-based implementation had problems with generic inlining so we replaced it in https://github.com/dotnet/corert/pull/3814. The fallback IL was probably still used for CppCodegen at that time so it wasn't deleted. --- .../src/System/RuntimeTypeHandle.cs | 6 --- .../src/System/EETypePtr.cs | 5 +-- .../src/System/RuntimeTypeHandle.cs | 6 --- .../Common/TypeSystem/IL/CoreRTILProvider.cs | 6 --- .../IL/Stubs/EETypePtrOfIntrinsic.cs | 45 ------------------- .../IL/ILImporter.Scanner.cs | 28 +----------- .../ILCompiler.Compiler.csproj | 3 -- 7 files changed, 2 insertions(+), 97 deletions(-) delete mode 100644 src/coreclr/tools/Common/TypeSystem/IL/Stubs/EETypePtrOfIntrinsic.cs diff --git a/src/coreclr/nativeaot/Runtime.Base/src/System/RuntimeTypeHandle.cs b/src/coreclr/nativeaot/Runtime.Base/src/System/RuntimeTypeHandle.cs index 0918a6048bc5..85f880035e90 100644 --- a/src/coreclr/nativeaot/Runtime.Base/src/System/RuntimeTypeHandle.cs +++ b/src/coreclr/nativeaot/Runtime.Base/src/System/RuntimeTypeHandle.cs @@ -19,11 +19,5 @@ public class Type public struct RuntimeTypeHandle { private EETypePtr _pEEType; - - [Intrinsic] - internal static unsafe IntPtr GetValueInternal(RuntimeTypeHandle handle) - { - return (IntPtr)handle._pEEType.ToPointer(); - } } } diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/EETypePtr.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/EETypePtr.cs index 376c395ca017..6f830df6a5a0 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/EETypePtr.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/EETypePtr.cs @@ -427,10 +427,7 @@ internal ref T GetWritableData() where T : unmanaged internal static EETypePtr EETypePtrOf() { // Compilers are required to provide a low level implementation of this method. - // This can be achieved by optimizing away the reflection part of this implementation - // by optimizing typeof(!!0).TypeHandle into "ldtoken !!0", or by - // completely replacing the body of this method. - return typeof(T).TypeHandle.ToEETypePtr(); + throw new NotImplementedException(); } public struct InterfaceCollection diff --git a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs index a3abe4d9242b..4f6e408c823c 100644 --- a/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs +++ b/src/coreclr/nativeaot/System.Private.CoreLib/src/System/RuntimeTypeHandle.cs @@ -148,12 +148,6 @@ internal string LastResortToString } } - [Intrinsic] - internal static IntPtr GetValueInternal(RuntimeTypeHandle handle) - { - return handle.RawValue; - } - internal IntPtr RawValue { get diff --git a/src/coreclr/tools/Common/TypeSystem/IL/CoreRTILProvider.cs b/src/coreclr/tools/Common/TypeSystem/IL/CoreRTILProvider.cs index 1f116733e2da..34ed6bff9b2c 100644 --- a/src/coreclr/tools/Common/TypeSystem/IL/CoreRTILProvider.cs +++ b/src/coreclr/tools/Common/TypeSystem/IL/CoreRTILProvider.cs @@ -76,12 +76,6 @@ private MethodIL TryGetIntrinsicMethodIL(MethodDesc method) return new ILStubMethodIL(method, new byte[] { (byte)ILOpcode.break_, (byte)ILOpcode.ret }, Array.Empty(), null); } break; - case "EETypePtr": - { - if (owningType.Namespace == "System" && method.Name == "EETypePtrOf") - return EETypePtrOfIntrinsic.EmitIL(method); - } - break; case "RuntimeAugments": { if (owningType.Namespace == "Internal.Runtime.Augments" && method.Name == "GetCanonType") diff --git a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/EETypePtrOfIntrinsic.cs b/src/coreclr/tools/Common/TypeSystem/IL/Stubs/EETypePtrOfIntrinsic.cs deleted file mode 100644 index b8831595b761..000000000000 --- a/src/coreclr/tools/Common/TypeSystem/IL/Stubs/EETypePtrOfIntrinsic.cs +++ /dev/null @@ -1,45 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -using System; -using Internal.TypeSystem; -using Debug = System.Diagnostics.Debug; - -namespace Internal.IL.Stubs -{ - /// - /// Provides method bodies for EETypePtrOf intrinsic. The intrinsic works around the inability to express the raw - /// "ldtoken type" instruction in C#. The intrinsic method returns the pointer to the EEType for the type passed - /// as the generic argument. - /// - public static class EETypePtrOfIntrinsic - { - public static MethodIL EmitIL(MethodDesc target) - { - Debug.Assert(target.Name == "EETypePtrOf"); - Debug.Assert(target.Signature.Length == 0 - && target.Signature.ReturnType == target.OwningType); - Debug.Assert(target.Instantiation.Length == 1); - - ILEmitter emitter = new ILEmitter(); - var codeStream = emitter.NewCodeStream(); - - TypeSystemContext context = target.Context; - TypeDesc runtimeTypeHandleType = context.GetWellKnownType(WellKnownType.RuntimeTypeHandle); - MethodDesc getValueInternalMethod = runtimeTypeHandleType.GetKnownMethod("GetValueInternal", null); - MethodDesc eetypePtrCtorMethod = context.SystemModule - .GetKnownType("System", "EETypePtr") - .GetKnownMethod(".ctor", new MethodSignature(0, 0, context.GetWellKnownType(WellKnownType.Void), - new TypeDesc[] { context.GetWellKnownType(WellKnownType.IntPtr) })); - - // The sequence of these instructions is important. JIT is able to optimize out - // the LDTOKEN+GetValueInternal call into "load EEType pointer onto the evaluation stack". - codeStream.Emit(ILOpcode.ldtoken, emitter.NewToken(context.GetSignatureVariable(0, true))); - codeStream.Emit(ILOpcode.call, emitter.NewToken(getValueInternalMethod)); - codeStream.Emit(ILOpcode.newobj, emitter.NewToken(eetypePtrCtorMethod)); - codeStream.Emit(ILOpcode.ret); - - return emitter.Link(target); - } - } -} diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs index 1083e4fdd2b9..84d85824be3a 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/IL/ILImporter.Scanner.cs @@ -345,12 +345,6 @@ private void ImportCall(ILOpcode opcode, int token) return; } - if (IsRuntimeTypeHandleGetValueInternal(method)) - { - if (_previousInstructionOffset >= 0 && _ilBytes[_previousInstructionOffset] == (byte)ILOpcode.ldtoken) - return; - } - if (IsActivatorDefaultConstructorOf(method)) { if (runtimeDeterminedMethod.IsRuntimeDeterminedExactMethod) @@ -804,7 +798,6 @@ private void ImportLdToken(int token) } _dependencies.Add(reference, "ldtoken"); - // If this is a ldtoken Type / GetValueInternal sequence, we're done. // If this is a ldtoken Type / Type.GetTypeFromHandle sequence, we need one more helper. BasicBlock nextBasicBlock = _basicBlocks[_currentOffset]; if (nextBasicBlock == null) @@ -813,12 +806,7 @@ private void ImportLdToken(int token) { int methodToken = ReadILTokenAt(_currentOffset + 1); var method = (MethodDesc)_methodIL.GetObject(methodToken); - if (IsRuntimeTypeHandleGetValueInternal(method)) - { - // Codegen expands this and doesn't do the normal ldtoken. - return; - } - else if (IsTypeGetTypeFromHandle(method)) + if (IsTypeGetTypeFromHandle(method)) { // Codegen will swap this one for GetRuntimeTypeHandle when optimizing _dependencies.Add(GetHelperEntrypoint(ReadyToRunHelper.GetRuntimeType), "ldtoken"); @@ -1115,20 +1103,6 @@ private bool IsRuntimeHelpersInitializeArray(MethodDesc method) return false; } - private bool IsRuntimeTypeHandleGetValueInternal(MethodDesc method) - { - if (method.IsIntrinsic && method.Name == "GetValueInternal") - { - MetadataType owningType = method.OwningType as MetadataType; - if (owningType != null) - { - return owningType.Name == "RuntimeTypeHandle" && owningType.Namespace == "System"; - } - } - - return false; - } - private bool IsTypeGetTypeFromHandle(MethodDesc method) { if (method.IsIntrinsic && method.Name == "GetTypeFromHandle") diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/ILCompiler.Compiler.csproj b/src/coreclr/tools/aot/ILCompiler.Compiler/ILCompiler.Compiler.csproj index be1cd5ede0cf..d09acf0b2875 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/ILCompiler.Compiler.csproj +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/ILCompiler.Compiler.csproj @@ -96,9 +96,6 @@ IL\Stubs\DelegateMethodILEmitter.cs - - IL\Stubs\EETypePtrOfIntrinsic.cs - IL\Stubs\MethodBaseGetCurrentMethodThunk.Sorting.cs