From b53d00dcc24149ee84ad8cfa9c23b253d8cf65e0 Mon Sep 17 00:00:00 2001 From: John Salem Date: Wed, 28 Nov 2018 22:34:48 -0800 Subject: [PATCH] Add IsCollectible property to Memberinfo and MethodInfo (#21155) --- .../shared/System/Reflection/MemberInfo.cs | 2 +- src/System.Private.CoreLib/shared/System/Type.cs | 2 -- .../src/System/Reflection/RuntimeFieldInfo.cs | 1 + .../src/System/Reflection/RuntimeMethodInfo.cs | 2 ++ .../src/System/Reflection/RuntimePropertyInfo.cs | 1 + src/System.Private.CoreLib/src/System/RuntimeHandles.cs | 4 ++++ src/vm/ecalllist.h | 1 + src/vm/runtimehandles.cpp | 15 +++++++++++++++ src/vm/runtimehandles.h | 2 ++ 9 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/System.Private.CoreLib/shared/System/Reflection/MemberInfo.cs b/src/System.Private.CoreLib/shared/System/Reflection/MemberInfo.cs index d8a7458..c61198d 100644 --- a/src/System.Private.CoreLib/shared/System/Reflection/MemberInfo.cs +++ b/src/System.Private.CoreLib/shared/System/Reflection/MemberInfo.cs @@ -38,7 +38,7 @@ namespace System.Reflection public virtual IEnumerable CustomAttributes => GetCustomAttributesData(); public virtual IList GetCustomAttributesData() { throw NotImplemented.ByDesign; } - + public virtual bool IsCollectible => true; public virtual int MetadataToken { get { throw new InvalidOperationException(); } } public override bool Equals(object obj) => base.Equals(obj); diff --git a/src/System.Private.CoreLib/shared/System/Type.cs b/src/System.Private.CoreLib/shared/System/Type.cs index c78d988..8b19fbc 100644 --- a/src/System.Private.CoreLib/shared/System/Type.cs +++ b/src/System.Private.CoreLib/shared/System/Type.cs @@ -102,8 +102,6 @@ namespace System public bool IsContextful => IsContextfulImpl(); protected virtual bool IsContextfulImpl() => false; - public virtual bool IsCollectible => true; - public virtual bool IsEnum => IsSubclassOf(typeof(Enum)); public bool IsMarshalByRef => IsMarshalByRefImpl(); protected virtual bool IsMarshalByRefImpl() => false; diff --git a/src/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs b/src/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs index 7b35cd7..c90d72c 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/RuntimeFieldInfo.cs @@ -68,6 +68,7 @@ namespace System.Reflection public sealed override bool HasSameMetadataDefinitionAs(MemberInfo other) => HasSameMetadataDefinitionAsCore(other); public override Module Module { get { return GetRuntimeModule(); } } + public override bool IsCollectible => m_declaringType.IsCollectible; #endregion #region Object Overrides diff --git a/src/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs b/src/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs index d3b0969..68caf30 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/RuntimeMethodInfo.cs @@ -525,6 +525,8 @@ namespace System.Reflection } } + public override bool IsCollectible => RuntimeMethodHandle.GetIsCollectible(new RuntimeMethodHandleInternal(m_handle)); + public override MethodInfo GetBaseDefinition() { if (!IsVirtual || IsStatic || m_declaringType == null || m_declaringType.IsInterface) diff --git a/src/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs b/src/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs index 7f118d3..313dcc5 100644 --- a/src/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs +++ b/src/System.Private.CoreLib/src/System/Reflection/RuntimePropertyInfo.cs @@ -220,6 +220,7 @@ namespace System.Reflection public override Module Module { get { return GetRuntimeModule(); } } internal RuntimeModule GetRuntimeModule() { return m_declaringType.GetRuntimeModule(); } + public override bool IsCollectible => m_declaringType.IsCollectible; #endregion #region PropertyInfo Overrides diff --git a/src/System.Private.CoreLib/src/System/RuntimeHandles.cs b/src/System.Private.CoreLib/src/System/RuntimeHandles.cs index bb1a010..29b3fe3 100644 --- a/src/System.Private.CoreLib/src/System/RuntimeHandles.cs +++ b/src/System.Private.CoreLib/src/System/RuntimeHandles.cs @@ -791,6 +791,10 @@ namespace System } [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] + [return: MarshalAs(UnmanagedType.Bool)] + internal static extern bool GetIsCollectible(RuntimeMethodHandleInternal handle); + + [DllImport(JitHelpers.QCall, CharSet = CharSet.Unicode)] internal static extern bool IsCAVisibleFromDecoratedType( RuntimeTypeHandle attrTypeHandle, IRuntimeMethodInfo attrCtor, diff --git a/src/vm/ecalllist.h b/src/vm/ecalllist.h index 5ee6173..91ca5e0 100644 --- a/src/vm/ecalllist.h +++ b/src/vm/ecalllist.h @@ -317,6 +317,7 @@ FCFuncStart(gRuntimeMethodHandle) FCFuncElement("_GetCurrentMethod", RuntimeMethodHandle::GetCurrentMethod) FCFuncElement("InvokeMethod", RuntimeMethodHandle::InvokeMethod) QCFuncElement("GetFunctionPointer", RuntimeMethodHandle::GetFunctionPointer) + QCFuncElement("GetIsCollectible", RuntimeMethodHandle::GetIsCollectible) FCFuncElement("GetImplAttributes", RuntimeMethodHandle::GetImplAttributes) FCFuncElement("GetAttributes", RuntimeMethodHandle::GetAttributes) FCFuncElement("GetDeclaringType", RuntimeMethodHandle::GetDeclaringType) diff --git a/src/vm/runtimehandles.cpp b/src/vm/runtimehandles.cpp index 722603c..8f2d8ef 100644 --- a/src/vm/runtimehandles.cpp +++ b/src/vm/runtimehandles.cpp @@ -1732,6 +1732,21 @@ void * QCALLTYPE RuntimeMethodHandle::GetFunctionPointer(MethodDesc * pMethod) return funcPtr; } + +BOOL QCALLTYPE RuntimeMethodHandle::GetIsCollectible(MethodDesc * pMethod) +{ + QCALL_CONTRACT; + + BOOL isCollectible = FALSE; + + BEGIN_QCALL; + + isCollectible = pMethod->GetLoaderAllocator()->IsCollectible(); + + END_QCALL; + + return isCollectible; +} FCIMPL1(LPCUTF8, RuntimeMethodHandle::GetUtf8Name, MethodDesc *pMethod) { CONTRACTL { diff --git a/src/vm/runtimehandles.h b/src/vm/runtimehandles.h index e1f265d..739eb24 100644 --- a/src/vm/runtimehandles.h +++ b/src/vm/runtimehandles.h @@ -313,6 +313,8 @@ public: static void * QCALLTYPE GetFunctionPointer(MethodDesc * pMethod); + static BOOL QCALLTYPE GetIsCollectible(MethodDesc * pMethod); + static FCDECL1(INT32, GetAttributes, MethodDesc *pMethod); static FCDECL1(INT32, GetImplAttributes, ReflectMethodObject *pMethodUNSAFE); static FCDECL1(ReflectClassBaseObject*, GetDeclaringType, MethodDesc *pMethod); -- 2.7.4