From 8dd3543e00d011ad86d58da6466a23cb8bb1223f Mon Sep 17 00:00:00 2001 From: Adeel Mujahid <3840695+am11@users.noreply.github.com> Date: Tue, 9 Feb 2021 00:50:53 +0200 Subject: [PATCH] Move common corelib code to shared partition (#47956) * Move common corelib code to shared partition * Inline SetCustomAttributeNoLock method --- .../System.Private.CoreLib.csproj | 12 +- .../src/System/Reflection/Emit/AssemblyBuilder.cs | 152 ++++------------- .../System/Reflection/Emit/AssemblyBuilderData.cs | 6 +- .../src/System/Reflection/RuntimeMethodBody.cs | 27 +-- .../src/System.Private.CoreLib.Shared.projitems | 6 + .../src/System/Reflection/Emit/AssemblyBuilder.cs | 38 +++++ .../src/System/Reflection/RuntimeMethodBody.cs | 27 +++ .../src/System/Threading/StackCrawlMark.cs | 0 .../System.Private.CoreLib.csproj | 4 +- .../src/System/NotImplemented.cs | 27 --- .../System/Reflection/Emit/AssemblyBuilder.Mono.cs | 181 +++------------------ .../src/System/Reflection/RuntimeMethodBody.cs | 32 +--- .../src/System/Threading/StackCrawlMark.cs | 16 -- 13 files changed, 148 insertions(+), 380 deletions(-) create mode 100644 src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs create mode 100644 src/libraries/System.Private.CoreLib/src/System/Reflection/RuntimeMethodBody.cs rename src/{coreclr => libraries}/System.Private.CoreLib/src/System/Threading/StackCrawlMark.cs (100%) delete mode 100644 src/mono/System.Private.CoreLib/src/System/NotImplemented.cs delete mode 100644 src/mono/System.Private.CoreLib/src/System/Threading/StackCrawlMark.cs diff --git a/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj index 6a9e316..24c4b35 100644 --- a/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/coreclr/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -14,7 +14,7 @@ x64;x86;arm;arm64 true - + true $(IntermediateOutputPath)System.Private.CoreLib.xml $(MSBuildThisFileDirectory)src\ILLink\ @@ -231,7 +231,6 @@ - @@ -296,17 +295,12 @@ - - - Common\System\NotImplemented.cs - - - + - + diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs index a2b88b6..6f2f862 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs @@ -116,7 +116,7 @@ namespace System.Reflection.Emit #endregion } - public sealed class AssemblyBuilder : Assembly + public sealed partial class AssemblyBuilder : Assembly { [MethodImpl(MethodImplOptions.InternalCall)] private static extern RuntimeModule GetInMemoryAssemblyModule(RuntimeAssembly assembly); @@ -192,7 +192,7 @@ namespace System.Reflection.Emit ObjectHandleOnStack.Create(ref retAssembly)); _internalAssemblyBuilder = (InternalAssemblyBuilder)retAssembly!; - _assemblyData = new AssemblyBuilderData(_internalAssemblyBuilder, access); + _assemblyData = new AssemblyBuilderData(access); // Make sure that ManifestModule is properly initialized // We need to do this before setting any CustomAttribute @@ -287,16 +287,12 @@ namespace System.Reflection.Emit /// a transient module. /// [DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod. - public ModuleBuilder DefineDynamicModule(string name) - { - return DefineDynamicModuleInternal(name, emitSymbolInfo: false); - } + public ModuleBuilder DefineDynamicModule(string name) => + DefineDynamicModuleInternal(name, emitSymbolInfo: false); [DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod. - public ModuleBuilder DefineDynamicModule(string name, bool emitSymbolInfo) - { - return DefineDynamicModuleInternal(name, emitSymbolInfo); - } + public ModuleBuilder DefineDynamicModule(string name, bool emitSymbolInfo) => + DefineDynamicModuleInternal(name, emitSymbolInfo); private ModuleBuilder DefineDynamicModuleInternal(string name, bool emitSymbolInfo) { @@ -406,88 +402,29 @@ namespace System.Reflection.Emit public override int GetHashCode() => InternalAssembly.GetHashCode(); #region ICustomAttributeProvider Members - public override object[] GetCustomAttributes(bool inherit) - { - return InternalAssembly.GetCustomAttributes(inherit); - } + public override object[] GetCustomAttributes(bool inherit) => + InternalAssembly.GetCustomAttributes(inherit); - public override object[] GetCustomAttributes(Type attributeType, bool inherit) - { - return InternalAssembly.GetCustomAttributes(attributeType, inherit); - } + public override object[] GetCustomAttributes(Type attributeType, bool inherit) => + InternalAssembly.GetCustomAttributes(attributeType, inherit); - public override bool IsDefined(Type attributeType, bool inherit) - { - return InternalAssembly.IsDefined(attributeType, inherit); - } + public override bool IsDefined(Type attributeType, bool inherit) => + InternalAssembly.IsDefined(attributeType, inherit); - public override IList GetCustomAttributesData() - { - return InternalAssembly.GetCustomAttributesData(); - } + public override IList GetCustomAttributesData() => + InternalAssembly.GetCustomAttributesData(); #endregion #region Assembly overrides - /// The names of all the resources. - public override string[] GetManifestResourceNames() - { - return InternalAssembly.GetManifestResourceNames(); - } - - public override FileStream GetFile(string name) - { - return InternalAssembly.GetFile(name); - } - - public override FileStream[] GetFiles(bool getResourceModules) - { - return InternalAssembly.GetFiles(getResourceModules); - } - - public override Stream? GetManifestResourceStream(Type type, string name) - { - return InternalAssembly.GetManifestResourceStream(type, name); - } - - public override Stream? GetManifestResourceStream(string name) - { - return InternalAssembly.GetManifestResourceStream(name); - } - - public override ManifestResourceInfo? GetManifestResourceInfo(string resourceName) - { - return InternalAssembly.GetManifestResourceInfo(resourceName); - } - - public override string Location => InternalAssembly.Location; - - public override string ImageRuntimeVersion => InternalAssembly.ImageRuntimeVersion; - - public override string? CodeBase => InternalAssembly.CodeBase; - - /// - /// Override the EntryPoint method on Assembly. - /// This doesn't need to be synchronized because it is simple enough. - /// - public override MethodInfo? EntryPoint => _assemblyData._entryPointMethod; - - /// - /// Get an array of all the public types defined in this assembly. - /// - [RequiresUnreferencedCode("Types might be removed")] - public override Type[] GetExportedTypes() => InternalAssembly.GetExportedTypes(); - public override AssemblyName GetName(bool copiedName) => InternalAssembly.GetName(copiedName); public override string? FullName => InternalAssembly.FullName; [RequiresUnreferencedCode("Types might be removed")] - public override Type? GetType(string name, bool throwOnError, bool ignoreCase) - { - return InternalAssembly.GetType(name, throwOnError, ignoreCase); - } + public override Type? GetType(string name, bool throwOnError, bool ignoreCase) => + InternalAssembly.GetType(name, throwOnError, ignoreCase); public override Module ManifestModule => _manifestModuleBuilder.InternalModule; @@ -496,40 +433,25 @@ namespace System.Reflection.Emit public override Module? GetModule(string name) => InternalAssembly.GetModule(name); [RequiresUnreferencedCode("Assembly references might be removed")] - public override AssemblyName[] GetReferencedAssemblies() - { - return InternalAssembly.GetReferencedAssemblies(); - } - - [Obsolete(Obsoletions.GlobalAssemblyCacheMessage, DiagnosticId = Obsoletions.GlobalAssemblyCacheDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] - public override bool GlobalAssemblyCache => InternalAssembly.GlobalAssemblyCache; + public override AssemblyName[] GetReferencedAssemblies() => + InternalAssembly.GetReferencedAssemblies(); public override long HostContext => InternalAssembly.HostContext; - public override Module[] GetModules(bool getResourceModules) - { - return InternalAssembly.GetModules(getResourceModules); - } + public override Module[] GetModules(bool getResourceModules) => + InternalAssembly.GetModules(getResourceModules); - public override Module[] GetLoadedModules(bool getResourceModules) - { - return InternalAssembly.GetLoadedModules(getResourceModules); - } + public override Module[] GetLoadedModules(bool getResourceModules) => + InternalAssembly.GetLoadedModules(getResourceModules); - public override Assembly GetSatelliteAssembly(CultureInfo culture) - { - return InternalAssembly.GetSatelliteAssembly(culture, null); - } + public override Assembly GetSatelliteAssembly(CultureInfo culture) => + InternalAssembly.GetSatelliteAssembly(culture, null); /// /// Useful for binding to a very specific version of a satellite assembly /// - public override Assembly GetSatelliteAssembly(CultureInfo culture, Version? version) - { - return InternalAssembly.GetSatelliteAssembly(culture, version); - } - - public override bool IsDynamic => true; + public override Assembly GetSatelliteAssembly(CultureInfo culture, Version? version) => + InternalAssembly.GetSatelliteAssembly(culture, version); public override bool IsCollectible => InternalAssembly.IsCollectible; @@ -584,19 +506,14 @@ namespace System.Reflection.Emit lock (SyncRoot) { - SetCustomAttributeNoLock(con, binaryAttribute); + TypeBuilder.DefineCustomAttribute( + _manifestModuleBuilder, // pass in the in-memory assembly module + AssemblyBuilderData.AssemblyDefToken, + _manifestModuleBuilder.GetConstructorToken(con), + binaryAttribute); } } - private void SetCustomAttributeNoLock(ConstructorInfo con, byte[] binaryAttribute) - { - TypeBuilder.DefineCustomAttribute( - _manifestModuleBuilder, // pass in the in-memory assembly module - AssemblyBuilderData.AssemblyDefToken, - _manifestModuleBuilder.GetConstructorToken(con), - binaryAttribute); - } - /// /// Use this function if client wishes to build CustomAttribute using CustomAttributeBuilder. /// @@ -609,13 +526,8 @@ namespace System.Reflection.Emit lock (SyncRoot) { - SetCustomAttributeNoLock(customBuilder); + customBuilder.CreateCustomAttribute(_manifestModuleBuilder, AssemblyBuilderData.AssemblyDefToken); } } - - private void SetCustomAttributeNoLock(CustomAttributeBuilder customBuilder) - { - customBuilder.CreateCustomAttribute(_manifestModuleBuilder, AssemblyBuilderData.AssemblyDefToken); - } } } diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilderData.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilderData.cs index 1f94816..4b44a4d 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilderData.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilderData.cs @@ -16,13 +16,9 @@ namespace System.Reflection.Emit public readonly List _moduleBuilderList; public readonly AssemblyBuilderAccess _access; - public MethodInfo? _entryPointMethod; - private readonly InternalAssemblyBuilder _assembly; - - internal AssemblyBuilderData(InternalAssemblyBuilder assembly, AssemblyBuilderAccess access) + internal AssemblyBuilderData(AssemblyBuilderAccess access) { - _assembly = assembly; _access = access; _moduleBuilderList = new List(); } diff --git a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeMethodBody.cs b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeMethodBody.cs index 8be4480..3227a7e 100644 --- a/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeMethodBody.cs +++ b/src/coreclr/System.Private.CoreLib/src/System/Reflection/RuntimeMethodBody.cs @@ -1,28 +1,17 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.Collections.Generic; - namespace System.Reflection { - internal sealed class RuntimeMethodBody : MethodBody + internal sealed partial class RuntimeMethodBody : MethodBody { // This class can only be created from inside the EE. - private RuntimeMethodBody() { } - - private byte[] _IL = null!; - private ExceptionHandlingClause[] _exceptionHandlingClauses = null!; - private LocalVariableInfo[] _localVariables = null!; - internal MethodBase _methodBase = null!; - private int _localSignatureMetadataToken; - private int _maxStackSize; - private bool _initLocals; - - public override int LocalSignatureMetadataToken => _localSignatureMetadataToken; - public override IList LocalVariables => Array.AsReadOnly(_localVariables); - public override int MaxStackSize => _maxStackSize; - public override bool InitLocals => _initLocals; - public override byte[] GetILAsByteArray() => _IL; - public override IList ExceptionHandlingClauses => Array.AsReadOnly(_exceptionHandlingClauses); + private RuntimeMethodBody() + { + _IL = null!; + _exceptionHandlingClauses = null!; + _localVariables = null!; + _methodBase = null!; + } } } diff --git a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems index 39f915e..a21bf72 100644 --- a/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems +++ b/src/libraries/System.Private.CoreLib/src/System.Private.CoreLib.Shared.projitems @@ -533,6 +533,7 @@ + @@ -587,6 +588,7 @@ + @@ -958,6 +960,7 @@ + @@ -1123,6 +1126,9 @@ Common\System\HResults.cs + + Common\System\NotImplemented.cs + Common\System\Obsoletions.cs diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs new file mode 100644 index 0000000..7013362 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.cs @@ -0,0 +1,38 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Diagnostics.CodeAnalysis; +using System.IO; + +namespace System.Reflection.Emit +{ + public sealed partial class AssemblyBuilder : Assembly + { + public override string? CodeBase => throw new NotSupportedException(SR.NotSupported_DynamicAssembly); + public override string Location => throw new NotSupportedException(SR.NotSupported_DynamicAssembly); + public override MethodInfo? EntryPoint => null; + public override bool IsDynamic => true; + + [RequiresUnreferencedCode("Types might be removed")] + public override Type[] GetExportedTypes() => + throw new NotSupportedException(SR.NotSupported_DynamicAssembly); + + public override FileStream GetFile(string name) => + throw new NotSupportedException(SR.NotSupported_DynamicAssembly); + + public override FileStream[] GetFiles(bool getResourceModules) => + throw new NotSupportedException(SR.NotSupported_DynamicAssembly); + + public override ManifestResourceInfo? GetManifestResourceInfo(string resourceName) => + throw new NotSupportedException(SR.NotSupported_DynamicAssembly); + + public override string[] GetManifestResourceNames() => + throw new NotSupportedException(SR.NotSupported_DynamicAssembly); + + public override Stream? GetManifestResourceStream(string name) => + throw new NotSupportedException(SR.NotSupported_DynamicAssembly); + + public override Stream? GetManifestResourceStream(Type type, string name) => + throw new NotSupportedException(SR.NotSupported_DynamicAssembly); + } +} diff --git a/src/libraries/System.Private.CoreLib/src/System/Reflection/RuntimeMethodBody.cs b/src/libraries/System.Private.CoreLib/src/System/Reflection/RuntimeMethodBody.cs new file mode 100644 index 0000000..30a15c7 --- /dev/null +++ b/src/libraries/System.Private.CoreLib/src/System/Reflection/RuntimeMethodBody.cs @@ -0,0 +1,27 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Collections.Generic; + +namespace System.Reflection +{ + internal sealed partial class RuntimeMethodBody : MethodBody + { + private byte[] _IL; + private ExceptionHandlingClause[] _exceptionHandlingClauses; + private LocalVariableInfo[] _localVariables; +#if CORECLR + internal MethodBase _methodBase; +#endif + private int _localSignatureMetadataToken; + private int _maxStackSize; + private bool _initLocals; + + public override int LocalSignatureMetadataToken => _localSignatureMetadataToken; + public override IList LocalVariables => Array.AsReadOnly(_localVariables); + public override int MaxStackSize => _maxStackSize; + public override bool InitLocals => _initLocals; + public override byte[] GetILAsByteArray() => _IL; + public override IList ExceptionHandlingClauses => Array.AsReadOnly(_exceptionHandlingClauses); + } +} diff --git a/src/coreclr/System.Private.CoreLib/src/System/Threading/StackCrawlMark.cs b/src/libraries/System.Private.CoreLib/src/System/Threading/StackCrawlMark.cs similarity index 100% rename from src/coreclr/System.Private.CoreLib/src/System/Threading/StackCrawlMark.cs rename to src/libraries/System.Private.CoreLib/src/System/Threading/StackCrawlMark.cs diff --git a/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj b/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj index efd199d..68887b4 100644 --- a/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj +++ b/src/mono/System.Private.CoreLib/System.Private.CoreLib.csproj @@ -14,7 +14,7 @@ $(RuntimeBinDir)IL/ Debug;Release;Checked x64;x86;arm;arm64;wasm - + true @@ -160,7 +160,6 @@ - @@ -251,7 +250,6 @@ - diff --git a/src/mono/System.Private.CoreLib/src/System/NotImplemented.cs b/src/mono/System.Private.CoreLib/src/System/NotImplemented.cs deleted file mode 100644 index 244fba7..0000000 --- a/src/mono/System.Private.CoreLib/src/System/NotImplemented.cs +++ /dev/null @@ -1,27 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace System -{ - // - // This simple class enables one to throw a NotImplementedException using the following - // idiom: - // - // throw NotImplemented.ByDesign; - // - // Used by methods whose intended implementation is to throw a NotImplementedException (typically - // virtual methods in public abstract classes that intended to be subclassed by third parties.) - // - // This makes it distinguishable both from human eyes and CCI from NYI's that truly represent undone work. - // - internal static class NotImplemented - { - internal static Exception ByDesign - { - get - { - return new NotImplementedException(); - } - } - } -} diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.Mono.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.Mono.cs index 32d869b..bdebf80 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.Mono.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/Emit/AssemblyBuilder.Mono.cs @@ -34,11 +34,11 @@ // #if MONO_FEATURE_SRE -using System.IO; -using System.Globalization; -using System.Runtime.CompilerServices; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; +using System.Globalization; +using System.IO; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace System.Reflection.Emit @@ -171,7 +171,7 @@ namespace System.Reflection.Emit } [StructLayout(LayoutKind.Sequential)] - public sealed class AssemblyBuilder : Assembly + public sealed partial class AssemblyBuilder : Assembly { // // AssemblyBuilder inherits from Assembly, but the runtime thinks its layout inherits from RuntimeAssembly @@ -229,27 +229,6 @@ namespace System.Reflection.Emit modules = new ModuleBuilder[] { manifest_module }; } - public override string? CodeBase - { - get { throw not_supported(); } - } - - public override MethodInfo? EntryPoint - { - get - { - return null; - } - } - - public override string Location - { - get - { - throw not_supported(); - } - } - public override bool ReflectionOnly { get { return base.ReflectionOnly; } @@ -275,10 +254,7 @@ namespace System.Reflection.Emit return ab; } - public ModuleBuilder DefineDynamicModule(string name) - { - return DefineDynamicModule(name, false); - } + public ModuleBuilder DefineDynamicModule(string name) => DefineDynamicModule(name, false); public ModuleBuilder DefineDynamicModule(string name, bool emitSymbolInfo) { @@ -309,49 +285,7 @@ namespace System.Reflection.Emit return null; } - [RequiresUnreferencedCode("Types might be removed")] - public override Type[] GetExportedTypes() - { - throw not_supported(); - } - - public override FileStream GetFile(string name) - { - throw not_supported(); - } - - public override FileStream[] GetFiles(bool getResourceModules) - { - throw not_supported(); - } - - public override ManifestResourceInfo? GetManifestResourceInfo(string resourceName) - { - throw not_supported(); - } - - public override string[] GetManifestResourceNames() - { - throw not_supported(); - } - - public override Stream? GetManifestResourceStream(string name) - { - throw not_supported(); - } - - public override Stream? GetManifestResourceStream(Type type, string name) - { - throw not_supported(); - } - - public override bool IsCollectible - { - get - { - return access == (uint)AssemblyBuilderAccess.RunAndCollect; - } - } + public override bool IsCollectible => access == (uint)AssemblyBuilderAccess.RunAndCollect; public void SetCustomAttribute(CustomAttributeBuilder customBuilder) { @@ -385,17 +319,9 @@ namespace System.Reflection.Emit SetCustomAttribute(new CustomAttributeBuilder(con, binaryAttribute)); } - private static Exception not_supported() - { - // Strange message but this is what MS.NET prints... - return new NotSupportedException("The invoked member is not supported in a dynamic module."); - } - /*Warning, @typeArguments must be a mscorlib internal array. So make a copy before passing it in*/ - internal static Type MakeGenericType(Type gtd, Type[] typeArguments) - { - return new TypeBuilderInstantiation(gtd, typeArguments); - } + internal static Type MakeGenericType(Type gtd, Type[] typeArguments) => + new TypeBuilderInstantiation(gtd, typeArguments); [RequiresUnreferencedCode("Types might be removed")] public override Type? GetType(string name, bool throwOnError, bool ignoreCase) @@ -434,97 +360,40 @@ namespace System.Reflection.Emit return null; } - public override Module[] GetModules(bool getResourceModules) - { - return (Module[])modules.Clone(); - } + public override Module[] GetModules(bool getResourceModules) => (Module[])modules.Clone(); - public override AssemblyName GetName(bool copiedName) - { - return AssemblyName.Create(_mono_assembly, null); - } + public override AssemblyName GetName(bool copiedName) => AssemblyName.Create(_mono_assembly, null); [RequiresUnreferencedCode("Assembly references might be removed")] - public override AssemblyName[] GetReferencedAssemblies() => RuntimeAssembly.GetReferencedAssemblies (this); + public override AssemblyName[] GetReferencedAssemblies() => RuntimeAssembly.GetReferencedAssemblies(this); - public override Module[] GetLoadedModules(bool getResourceModules) - { - return GetModules(getResourceModules); - } + public override Module[] GetLoadedModules(bool getResourceModules) => GetModules(getResourceModules); //FIXME MS has issues loading satelite assemblies from SRE [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod - public override Assembly GetSatelliteAssembly(CultureInfo culture) - { - return GetSatelliteAssembly(culture, null); - } + public override Assembly GetSatelliteAssembly(CultureInfo culture) => GetSatelliteAssembly(culture, null); //FIXME MS has issues loading satelite assemblies from SRE [System.Security.DynamicSecurityMethod] // Methods containing StackCrawlMark local var has to be marked DynamicSecurityMethod - public override Assembly GetSatelliteAssembly(CultureInfo culture, Version? version) - { - return RuntimeAssembly.InternalGetSatelliteAssembly(this, culture, version, true)!; - } + public override Assembly GetSatelliteAssembly(CultureInfo culture, Version? version) => + RuntimeAssembly.InternalGetSatelliteAssembly(this, culture, version, true)!; - public override Module ManifestModule - { - get - { - return manifest_module; - } - } + public override Module ManifestModule => manifest_module; + public override string? FullName => aname.ToString(); - [Obsolete(Obsoletions.GlobalAssemblyCacheMessage, DiagnosticId = Obsoletions.GlobalAssemblyCacheDiagId, UrlFormat = Obsoletions.SharedUrlFormat)] - public override bool GlobalAssemblyCache - { - get - { - return false; - } - } + public override bool Equals(object? obj) => base.Equals(obj); - public override bool IsDynamic - { - get { return true; } - } + public override int GetHashCode() => base.GetHashCode(); - public override bool Equals(object? obj) - { - return base.Equals(obj); - } + public override bool IsDefined(Type attributeType, bool inherit) => + CustomAttribute.IsDefined(this, attributeType, inherit); - public override int GetHashCode() - { - return base.GetHashCode(); - } + public override object[] GetCustomAttributes(bool inherit) => CustomAttribute.GetCustomAttributes(this, inherit); - public override bool IsDefined(Type attributeType, bool inherit) - { - return CustomAttribute.IsDefined(this, attributeType, inherit); - } + public override object[] GetCustomAttributes(Type attributeType, bool inherit) => + CustomAttribute.GetCustomAttributes(this, attributeType, inherit); - public override object[] GetCustomAttributes(bool inherit) - { - return CustomAttribute.GetCustomAttributes(this, inherit); - } - - public override object[] GetCustomAttributes(Type attributeType, bool inherit) - { - return CustomAttribute.GetCustomAttributes(this, attributeType, inherit); - } - - public override IList GetCustomAttributesData() - { - return CustomAttributeData.GetCustomAttributes(this); - } - - public override string? FullName - { - get - { - return aname.ToString(); - } - } + public override IList GetCustomAttributesData() => CustomAttributeData.GetCustomAttributes(this); } } #endif diff --git a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodBody.cs b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodBody.cs index e580b0c..dff80e1 100644 --- a/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodBody.cs +++ b/src/mono/System.Private.CoreLib/src/System/Reflection/RuntimeMethodBody.cs @@ -1,38 +1,20 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. -using System.Collections.Generic; - namespace System.Reflection { - - internal sealed class RuntimeMethodBody : MethodBody + internal sealed partial class RuntimeMethodBody : MethodBody { - private ExceptionHandlingClause[] clauses; - private LocalVariableInfo[] locals; - private byte[] il; - private bool init_locals; - private int sig_token; - private int max_stack; - // Called by the runtime internal RuntimeMethodBody(ExceptionHandlingClause[] clauses, LocalVariableInfo[] locals, byte[] il, bool init_locals, int sig_token, int max_stack) { - this.clauses = clauses; - this.locals = locals; - this.il = il; - this.init_locals = init_locals; - this.sig_token = sig_token; - this.max_stack = max_stack; + _exceptionHandlingClauses = clauses; + _localVariables = locals; + _IL = il; + _initLocals = init_locals; + _localSignatureMetadataToken = sig_token; + _maxStackSize = max_stack; } - - public override int LocalSignatureMetadataToken => sig_token; - public override IList LocalVariables => Array.AsReadOnly(locals); - public override int MaxStackSize => max_stack; - public override bool InitLocals => init_locals; - public override byte[] GetILAsByteArray() => il; - public override IList ExceptionHandlingClauses => Array.AsReadOnly(clauses); } - } diff --git a/src/mono/System.Private.CoreLib/src/System/Threading/StackCrawlMark.cs b/src/mono/System.Private.CoreLib/src/System/Threading/StackCrawlMark.cs deleted file mode 100644 index a4634a8..0000000 --- a/src/mono/System.Private.CoreLib/src/System/Threading/StackCrawlMark.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Licensed to the .NET Foundation under one or more agreements. -// The .NET Foundation licenses this file to you under the MIT license. - -namespace System.Threading -{ - // declaring a local var of this enum type and passing it by ref into a function that needs to do a - // stack crawl will both prevent inlining of the calle and pass an ESP point to stack crawl to - // Declaring these in EH clauses is illegal; they must declared in the main method body - internal enum StackCrawlMark - { - LookForMe = 0, - LookForMyCaller = 1, - LookForMyCallersCaller = 2, - LookForThread = 3 - } -} -- 2.7.4