Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Helper Method Frames (HMF) from Reflection #110377

Merged
merged 8 commits into from
Dec 5, 2024
Next Next commit
Remove HMF from RuntimeFieldHandle.GetLoaderAllocator()
and RuntimeMethodHandle.GetLoaderAllocator().
AaronRobinsonMSFT committed Dec 3, 2024
commit 19f7cd135fd5a7b7bfb240a1ebf5b541259cffad
24 changes: 22 additions & 2 deletions src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs
Original file line number Diff line number Diff line change
@@ -1213,7 +1213,17 @@ internal static IRuntimeMethodInfo StripMethodInstantiation(IRuntimeMethodInfo m
internal static extern bool IsConstructor(RuntimeMethodHandleInternal method);

[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern LoaderAllocator GetLoaderAllocator(RuntimeMethodHandleInternal method);
private static extern LoaderAllocator GetLoaderAllocatorInternal(RuntimeMethodHandleInternal method);

internal static LoaderAllocator GetLoaderAllocator(RuntimeMethodHandleInternal method)
{
if (method.IsNullHandle())
{
throw new ArgumentNullException(SR.Arg_InvalidHandle);
}

return GetLoaderAllocatorInternal(method);
}
}

// This type is used to remove the expense of having a managed reference object that is dynamically
@@ -1519,7 +1529,17 @@ internal static void SetValueDirect(RtFieldInfo field, RuntimeType fieldType, Ty
internal static extern bool AcquiresContextFromThis(RuntimeFieldHandleInternal field);

[MethodImpl(MethodImplOptions.InternalCall)]
internal static extern LoaderAllocator GetLoaderAllocator(RuntimeFieldHandleInternal method);
private static extern LoaderAllocator GetLoaderAllocatorInternal(RuntimeFieldHandleInternal field);

internal static LoaderAllocator GetLoaderAllocator(RuntimeFieldHandleInternal field)
{
if (field.IsNullHandle())
{
throw new ArgumentNullException(SR.Arg_InvalidHandle);
}

return GetLoaderAllocatorInternal(field);
}

// ISerializable interface
[Obsolete(Obsoletions.LegacyFormatterImplMessage, DiagnosticId = Obsoletions.LegacyFormatterImplDiagId, UrlFormat = Obsoletions.SharedUrlFormat)]
4 changes: 2 additions & 2 deletions src/coreclr/vm/ecalllist.h
Original file line number Diff line number Diff line change
@@ -162,7 +162,7 @@ FCFuncStart(gRuntimeMethodHandle)
FCFuncElement("GetMethodBody", RuntimeMethodHandle::GetMethodBody)
FCFuncElement("IsConstructor", RuntimeMethodHandle::IsConstructor)
FCFuncElement("GetResolver", RuntimeMethodHandle::GetResolver)
FCFuncElement("GetLoaderAllocator", RuntimeMethodHandle::GetLoaderAllocator)
FCFuncElement("GetLoaderAllocatorInternal", RuntimeMethodHandle::GetLoaderAllocatorInternal)
FCFuncEnd()

FCFuncStart(gCOMFieldHandleNewFuncs)
@@ -172,7 +172,7 @@ FCFuncStart(gCOMFieldHandleNewFuncs)
FCFuncElement("GetToken", RuntimeFieldHandle::GetToken)
FCFuncElement("GetStaticFieldForGenericType", RuntimeFieldHandle::GetStaticFieldForGenericType)
FCFuncElement("AcquiresContextFromThis", RuntimeFieldHandle::AcquiresContextFromThis)
FCFuncElement("GetLoaderAllocator", RuntimeFieldHandle::GetLoaderAllocator)
FCFuncElement("GetLoaderAllocatorInternal", RuntimeFieldHandle::GetLoaderAllocatorInternal)
FCFuncElement("IsFastPathSupported", RuntimeFieldHandle::IsFastPathSupported)
FCFuncElement("GetInstanceFieldOffset", RuntimeFieldHandle::GetInstanceFieldOffset)
FCFuncElement("GetStaticFieldAddress", RuntimeFieldHandle::GetStaticFieldAddress)
36 changes: 10 additions & 26 deletions src/coreclr/vm/runtimehandles.cpp
Original file line number Diff line number Diff line change
@@ -271,25 +271,17 @@ FCIMPL1(FC_BOOL_RET, RuntimeFieldHandle::AcquiresContextFromThis, FieldDesc* pFi
}
FCIMPLEND

FCIMPL1(Object*, RuntimeFieldHandle::GetLoaderAllocator, FieldDesc* pField)
FCIMPL1(Object*, RuntimeFieldHandle::GetLoaderAllocatorInternal, FieldDesc* pField)
{
CONTRACTL {
CONTRACTL
{
FCALL_CHECK;
PRECONDITION(pField != NULL);
}
CONTRACTL_END;

OBJECTREF loaderAllocator = NULL;

if (!pField)
FCThrowRes(kArgumentNullException, W("Arg_InvalidHandle"));

HELPER_METHOD_FRAME_BEGIN_RET_PROTECT(loaderAllocator);

LoaderAllocator *pLoaderAllocator = pField->GetApproxEnclosingMethodTable()->GetLoaderAllocator();
loaderAllocator = pLoaderAllocator->GetExposedObject();

HELPER_METHOD_FRAME_END();

OBJECTREF loaderAllocator = pLoaderAllocator->GetExposedObject();
return OBJECTREFToObject(loaderAllocator);
}
FCIMPLEND
@@ -2364,25 +2356,17 @@ FCIMPL1(FC_BOOL_RET, RuntimeMethodHandle::IsConstructor, MethodDesc *pMethod)
}
FCIMPLEND

FCIMPL1(Object*, RuntimeMethodHandle::GetLoaderAllocator, MethodDesc *pMethod)
FCIMPL1(Object*, RuntimeMethodHandle::GetLoaderAllocatorInternal, MethodDesc *pMethod)
{
CONTRACTL {
CONTRACTL
{
FCALL_CHECK;
PRECONDITION(pMethod != NULL);
}
CONTRACTL_END;

OBJECTREF loaderAllocator = NULL;

if (!pMethod)
FCThrowRes(kArgumentNullException, W("Arg_InvalidHandle"));

HELPER_METHOD_FRAME_BEGIN_RET_PROTECT(loaderAllocator);

LoaderAllocator *pLoaderAllocator = pMethod->GetLoaderAllocator();
loaderAllocator = pLoaderAllocator->GetExposedObject();

HELPER_METHOD_FRAME_END();

OBJECTREF loaderAllocator = pLoaderAllocator->GetExposedObject();
return OBJECTREFToObject(loaderAllocator);
}
FCIMPLEND
4 changes: 2 additions & 2 deletions src/coreclr/vm/runtimehandles.h
Original file line number Diff line number Diff line change
@@ -232,7 +232,7 @@ class RuntimeMethodHandle

static FCDECL1(FC_BOOL_RET, IsConstructor, MethodDesc *pMethod);

static FCDECL1(Object*, GetLoaderAllocator, MethodDesc *pMethod);
static FCDECL1(Object*, GetLoaderAllocatorInternal, MethodDesc *pMethod);
};

extern "C" MethodDesc* QCALLTYPE MethodBase_GetCurrentMethod(QCall::StackCrawlMarkHandle stackMark);
@@ -272,7 +272,7 @@ class RuntimeFieldHandle
static FCDECL1(INT32, GetToken, FieldDesc* pField);
static FCDECL2(FieldDesc*, GetStaticFieldForGenericType, FieldDesc *pField, ReflectClassBaseObject *pDeclaringType);
static FCDECL1(FC_BOOL_RET, AcquiresContextFromThis, FieldDesc *pField);
static FCDECL1(Object*, GetLoaderAllocator, FieldDesc *pField);
static FCDECL1(Object*, GetLoaderAllocatorInternal, FieldDesc *pField);
};

extern "C" void QCALLTYPE RuntimeFieldHandle_GetValue(FieldDesc* fieldDesc, QCall::ObjectHandleOnStack instance, QCall::TypeHandle fieldType, QCall::TypeHandle declaringType, BOOL *pIsClassInitialized, QCall::ObjectHandleOnStack result);