Skip to content

Commit

Permalink
Remove HMFs from JIT helpers (#111088)
Browse files Browse the repository at this point in the history
Remove unused JIT_StressGC.
Convert JIT_GetRuntimeFieldStub and JIT_GetRuntimeMethodStub to C#.
  • Loading branch information
AaronRobinsonMSFT authored Jan 4, 2025
1 parent 0f6c3d8 commit dae8909
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ internal void InitializeSourceInfo(bool fNeedFileInfo, Exception? exception)
if (mh == IntPtr.Zero)
return null;

IRuntimeMethodInfo? mhReal = RuntimeMethodHandle.GetTypicalMethodDefinition(new RuntimeMethodInfoStub(mh, this));
IRuntimeMethodInfo? mhReal = RuntimeMethodHandle.GetTypicalMethodDefinition(new RuntimeMethodInfoStub(new RuntimeMethodHandleInternal(mh), this));

return RuntimeType.GetMethodBase(mhReal);
}
Expand Down
26 changes: 20 additions & 6 deletions src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -904,12 +904,6 @@ public RuntimeMethodInfoStub(RuntimeMethodHandleInternal methodHandleValue, obje
m_value = methodHandleValue;
}

public RuntimeMethodInfoStub(IntPtr methodHandleValue, object keepalive)
{
m_keepalive = keepalive;
m_value = new RuntimeMethodHandleInternal(methodHandleValue);
}

private readonly object m_keepalive;

// These unused variables are used to ensure that this class has the same layout as RuntimeMethodInfo
Expand All @@ -927,6 +921,16 @@ public RuntimeMethodInfoStub(IntPtr methodHandleValue, object keepalive)
public RuntimeMethodHandleInternal m_value;

RuntimeMethodHandleInternal IRuntimeMethodInfo.Value => m_value;

// implementation of CORINFO_HELP_METHODDESC_TO_STUBRUNTIMEMETHOD
[StackTraceHidden]
[DebuggerStepThrough]
[DebuggerHidden]
internal static object FromPtr(IntPtr pMD)
{
RuntimeMethodHandleInternal handle = new(pMD);
return new RuntimeMethodInfoStub(handle, RuntimeMethodHandle.GetLoaderAllocator(handle));
}
}

internal interface IRuntimeMethodInfo
Expand Down Expand Up @@ -1385,6 +1389,16 @@ public RuntimeFieldInfoStub(RuntimeFieldHandleInternal fieldHandle, object keepa
#pragma warning restore 414, 169, IDE0044

RuntimeFieldHandleInternal IRuntimeFieldInfo.Value => m_fieldHandle;

// implementation of CORINFO_HELP_FIELDDESC_TO_STUBRUNTIMEFIELD
[StackTraceHidden]
[DebuggerStepThrough]
[DebuggerHidden]
internal static object FromPtr(IntPtr pFD)
{
RuntimeFieldHandleInternal handle = new(pFD);
return new RuntimeFieldInfoStub(handle, RuntimeFieldHandle.GetLoaderAllocator(handle));
}
}

[NonVersionable]
Expand Down
3 changes: 1 addition & 2 deletions src/coreclr/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,6 @@ enum CorInfoHelpFunc
CORINFO_HELP_STOP_FOR_GC, // Call GC (force a GC)
CORINFO_HELP_POLL_GC, // Ask GC if it wants to collect

CORINFO_HELP_STRESS_GC, // Force a GC, but then update the JITTED code to be a noop call
CORINFO_HELP_CHECK_OBJ, // confirm that ECX is a valid object pointer (debugging only)

/* GC Write barrier support */
Expand Down Expand Up @@ -2326,7 +2325,7 @@ class ICorStaticInfo
CORINFO_CLASS_HANDLE cls
) = 0;

// Returns the assembly name of the class "cls", or nullptr if there is none.
// Returns the assembly name of the class "cls", or nullptr if there is none.
virtual const char* getClassAssemblyName (
CORINFO_CLASS_HANDLE cls
) = 0;
Expand Down
10 changes: 5 additions & 5 deletions src/coreclr/inc/jiteeversionguid.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ typedef const GUID *LPCGUID;
#define GUID_DEFINED
#endif // !GUID_DEFINED

constexpr GUID JITEEVersionIdentifier = { /* 64146448-11b1-4f94-b1f2-edce91fbcb33 */
0x64146448,
0x11b1,
0x4f94,
{0xb1, 0xf2, 0xed, 0xce, 0x91, 0xfb, 0xcb, 0x33}
constexpr GUID JITEEVersionIdentifier = { /* cc0e7adf-e397-40b6-9d14-a7149815c991 */
0xcc0e7adf,
0xe397,
0x40b6,
{0x9d, 0x14, 0xa7, 0x14, 0x98, 0x15, 0xc9, 0x91}
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
15 changes: 7 additions & 8 deletions src/coreclr/inc/jithelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@
// GC support
DYNAMICJITHELPER(CORINFO_HELP_STOP_FOR_GC, JIT_RareDisableHelper, METHOD__NIL)
JITHELPER(CORINFO_HELP_POLL_GC, JIT_PollGC, METHOD__NIL)
JITHELPER(CORINFO_HELP_STRESS_GC, JIT_StressGC, METHOD__NIL)

JITHELPER(CORINFO_HELP_CHECK_OBJ, JIT_CheckObj, METHOD__NIL)

Expand Down Expand Up @@ -221,18 +220,18 @@
DYNAMICJITHELPER(CORINFO_HELP_INIT_PINVOKE_FRAME, NULL, METHOD__NIL)
#endif

DYNAMICJITHELPER(CORINFO_HELP_MEMSET, NULL, METHOD__SPAN_HELPERS__MEMSET)
DYNAMICJITHELPER(CORINFO_HELP_MEMZERO, NULL, METHOD__SPAN_HELPERS__MEMZERO)
DYNAMICJITHELPER(CORINFO_HELP_MEMCPY, NULL, METHOD__SPAN_HELPERS__MEMCOPY)
DYNAMICJITHELPER(CORINFO_HELP_MEMSET, NULL, METHOD__SPAN_HELPERS__MEMSET)
DYNAMICJITHELPER(CORINFO_HELP_MEMZERO, NULL, METHOD__SPAN_HELPERS__MEMZERO)
DYNAMICJITHELPER(CORINFO_HELP_MEMCPY, NULL, METHOD__SPAN_HELPERS__MEMCOPY)
JITHELPER(CORINFO_HELP_NATIVE_MEMSET, Jit_NativeMemSet, METHOD__NIL)

// Generics
DYNAMICJITHELPER(CORINFO_HELP_RUNTIMEHANDLE_METHOD, NULL, METHOD__GENERICSHELPERS__METHOD)
DYNAMICJITHELPER(CORINFO_HELP_RUNTIMEHANDLE_CLASS, NULL, METHOD__GENERICSHELPERS__CLASS)
JITHELPER(CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE, JIT_GetRuntimeType, METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_RUNTIMEHANDLE_CLASS, NULL, METHOD__GENERICSHELPERS__CLASS)
JITHELPER(CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE, JIT_GetRuntimeType, METHOD__NIL)
JITHELPER(CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE_MAYBENULL, JIT_GetRuntimeType_MaybeNull, METHOD__NIL)
JITHELPER(CORINFO_HELP_METHODDESC_TO_STUBRUNTIMEMETHOD, JIT_GetRuntimeMethodStub,METHOD__NIL)
JITHELPER(CORINFO_HELP_FIELDDESC_TO_STUBRUNTIMEFIELD, JIT_GetRuntimeFieldStub, METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_METHODDESC_TO_STUBRUNTIMEMETHOD, NULL, METHOD__STUBMETHODINFO__FROMPTR)
DYNAMICJITHELPER(CORINFO_HELP_FIELDDESC_TO_STUBRUNTIMEFIELD, NULL, METHOD__STUBFIELDINFO__FROMPTR)
JITHELPER(CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPEHANDLE, JIT_GetRuntimeType, METHOD__NIL)
JITHELPER(CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPEHANDLE_MAYBENULL, JIT_GetRuntimeType_MaybeNull, METHOD__NIL)

Expand Down
1 change: 0 additions & 1 deletion src/coreclr/tools/Common/JitInterface/CorInfoHelpFunc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ which is the right helper to use to allocate an object of a given type. */
CORINFO_HELP_STOP_FOR_GC, // Call GC (force a GC)
CORINFO_HELP_POLL_GC, // Ask GC if it wants to collect

CORINFO_HELP_STRESS_GC, // Force a GC, but then update the JITTED code to be a noop call
CORINFO_HELP_CHECK_OBJ, // confirm that ECX is a valid object pointer (debugging only)

/* GC Write barrier support */
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/vm/corelib.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ DEFINE_CLASS_U(System, RuntimeMethodInfoStub, ReflectMethodO
DEFINE_FIELD_U(m_value, ReflectMethodObject, m_pMD)
DEFINE_CLASS(STUBMETHODINFO, System, RuntimeMethodInfoStub)
DEFINE_FIELD(STUBMETHODINFO, HANDLE, m_value)
DEFINE_METHOD(STUBMETHODINFO, FROMPTR, FromPtr, SM_IntPtr_RetObj)

DEFINE_CLASS(CONSTRUCTOR_INFO, Reflection, ConstructorInfo)

Expand Down Expand Up @@ -360,6 +361,7 @@ DEFINE_FIELD(RT_FIELD_INFO, HANDLE, m_fieldHandle)
DEFINE_CLASS_U(System, RuntimeFieldInfoStub, ReflectFieldObject)
DEFINE_FIELD_U(m_fieldHandle, ReflectFieldObject, m_pFD)
DEFINE_CLASS(STUBFIELDINFO, System, RuntimeFieldInfoStub)
DEFINE_METHOD(STUBFIELDINFO, FROMPTR, FromPtr, SM_IntPtr_RetObj)
#ifdef FOR_ILLINK
DEFINE_METHOD(STUBFIELDINFO, CTOR, .ctor, IM_RetVoid)
#endif // FOR_ILLINK
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ TypeHandle FieldDesc::GetExactFieldType(TypeHandle owner)
}

#if !defined(DACCESS_COMPILE)
REFLECTFIELDREF FieldDesc::GetStubFieldInfo()
REFLECTFIELDREF FieldDesc::AllocateStubFieldInfo()
{
CONTRACTL
{
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ class FieldDesc
#endif

#ifndef DACCESS_COMPILE
REFLECTFIELDREF GetStubFieldInfo();
REFLECTFIELDREF AllocateStubFieldInfo();
#endif
};

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/frames.h
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ class Frame : public FrameBase
friend class TailCallFrame;
friend class AppDomain;
friend VOID RealCOMPlusThrow(OBJECTREF);
friend FCDECL0(VOID, JIT_StressGC);

#ifdef _DEBUG
friend LONG WINAPI CLRVectoredExceptionHandlerShim(PEXCEPTION_POINTERS pExceptionInfo);
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/interpreter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6542,7 +6542,7 @@ void Interpreter::LdToken()
else if (tok.hField != NULL)
{
FieldDesc * pField = (FieldDesc *)tok.hField;
Object* objPtr = OBJECTREFToObject((OBJECTREF)pField->GetStubFieldInfo());
Object* objPtr = OBJECTREFToObject((OBJECTREF)pField->AllocateStubFieldInfo());
OpStackSet<Object*>(m_curStackHt, objPtr);
}
else
Expand Down
77 changes: 0 additions & 77 deletions src/coreclr/vm/jithelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1508,41 +1508,6 @@ HCIMPL3(void, Jit_NativeMemSet, void* pDest, int value, size_t length)
}
HCIMPLEND

HCIMPL1(Object*, JIT_GetRuntimeFieldStub, CORINFO_FIELD_HANDLE field)
{
FCALL_CONTRACT;

OBJECTREF stubRuntimeField = NULL;

HELPER_METHOD_FRAME_BEGIN_RET_0(); // Set up a frame

FieldDesc *pField = (FieldDesc *)field;
stubRuntimeField = (OBJECTREF)pField->GetStubFieldInfo();

HELPER_METHOD_FRAME_END();

return (OBJECTREFToObject(stubRuntimeField));
}
HCIMPLEND

HCIMPL1(Object*, JIT_GetRuntimeMethodStub, CORINFO_METHOD_HANDLE method)
{
FCALL_CONTRACT;

OBJECTREF stubRuntimeMethod = NULL;

HELPER_METHOD_FRAME_BEGIN_RET_0(); // Set up a frame

MethodDesc *pMethod = (MethodDesc *)method;
stubRuntimeMethod = (OBJECTREF)pMethod->AllocateStubMethodInfo();

HELPER_METHOD_FRAME_END();

return (OBJECTREFToObject(stubRuntimeMethod));
}
HCIMPLEND


NOINLINE HCIMPL1(Object*, JIT_GetRuntimeType_Framed, CORINFO_CLASS_HANDLE type)
{
FCALL_CONTRACT;
Expand Down Expand Up @@ -2394,47 +2359,6 @@ HCIMPL0(void, JIT_RareDisableHelper)
}
HCIMPLEND

/*********************************************************************/
// This is called by the JIT after every instruction in fully interruptible
// code to make certain our GC tracking is OK
HCIMPL0(VOID, JIT_StressGC_NOP)
{
FCALL_CONTRACT;
}
HCIMPLEND


HCIMPL0(VOID, JIT_StressGC)
{
FCALL_CONTRACT;

#ifdef _DEBUG
HELPER_METHOD_FRAME_BEGIN_0(); // Set up a frame

bool fSkipGC = false;

if (!fSkipGC)
GCHeapUtilities::GetGCHeap()->GarbageCollect();

// <TODO>@TODO: the following ifdef is in error, but if corrected the
// compiler complains about the *__ms->pRetAddr() saying machine state
// doesn't allow -></TODO>
#ifdef _X86
// Get the machine state, (from HELPER_METHOD_FRAME_BEGIN)
// and wack our return address to a nop function
BYTE* retInstrs = ((BYTE*) *__ms->pRetAddr()) - 4;
_ASSERTE(retInstrs[-1] == 0xE8); // it is a call instruction
// Wack it to point to the JITStressGCNop instead
InterlockedExchange((LONG*) retInstrs), (LONG) JIT_StressGC_NOP);
#endif // _X86

HELPER_METHOD_FRAME_END();
#endif // _DEBUG
}
HCIMPLEND



FCIMPL0(INT32, JIT_GetCurrentManagedThreadId)
{
FCALL_CONTRACT;
Expand All @@ -2446,7 +2370,6 @@ FCIMPL0(INT32, JIT_GetCurrentManagedThreadId)
}
FCIMPLEND


/*********************************************************************/
/* we don't use HCIMPL macros because we don't want the overhead even in debug mode */

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/runtimehandles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2312,7 +2312,7 @@ extern "C" void QCALLTYPE ModuleHandle_ResolveField(QCall::ModuleHandle pModule,
SigTypeContext typeContext(Instantiation(typeArgs, typeArgsCount), Instantiation(methodArgs, methodArgsCount));
pField = MemberLoader::GetFieldDescFromMemberDefOrRef(pModule, tkMemberRef, &typeContext, FALSE);
GCX_COOP();
retField.Set(pField->GetStubFieldInfo());
retField.Set(pField->AllocateStubFieldInfo());

END_QCALL;

Expand Down

0 comments on commit dae8909

Please sign in to comment.