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 HMFs from JIT helpers #111034

Merged
merged 3 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/coreclr/System.Private.CoreLib/src/System/Array.CoreCLR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,20 @@ private static unsafe Array InternalCreateFromArrayType(RuntimeType arrayType, i
return retArray!;
}

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "Array_CreateInstanceMDArray")]
private static unsafe partial void CreateInstanceMDArray(nint typeHandle, uint dwNumArgs, void* pArgList, ObjectHandleOnStack retArray);

// implementation of CORINFO_HELP_NEW_MDARR and CORINFO_HELP_NEW_MDARR_RARE.
[StackTraceHidden]
[DebuggerStepThrough]
[DebuggerHidden]
internal static unsafe object CreateInstanceMDArray(nint typeHandle, uint dwNumArgs, void* pArgList)
{
Array? arr = null;
CreateInstanceMDArray(typeHandle, dwNumArgs, pArgList, ObjectHandleOnStack.Create(ref arr));
return arr!;
}

private static unsafe void CopyImpl(Array sourceArray, int sourceIndex, Array destinationArray, int destinationIndex, int length, bool reliable)
{
if (sourceArray == null)
Expand Down
28 changes: 28 additions & 0 deletions src/coreclr/System.Private.CoreLib/src/System/RuntimeHandles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,34 @@ public void GetObjectData(SerializationInfo info, StreamingContext context)
{
throw new PlatformNotSupportedException();
}

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "RuntimeFieldHandle_GetEnCFieldAddr")]
private static partial void* GetEnCFieldAddr(ObjectHandleOnStack tgt, void* pFD);

// implementation of CORINFO_HELP_GETFIELDADDR
[StackTraceHidden]
[DebuggerStepThrough]
[DebuggerHidden]
internal static unsafe void* GetFieldAddr(object tgt, void* pFD)
{
void* addr = GetEnCFieldAddr(ObjectHandleOnStack.Create(ref tgt), pFD);
if (addr == null)
throw new NullReferenceException();
return addr;
}

// implementation of CORINFO_HELP_GETSTATICFIELDADDR
[StackTraceHidden]
[DebuggerStepThrough]
[DebuggerHidden]
internal static unsafe void* GetStaticFieldAddr(void* pFD)
{
object? nullTarget = null;
void* addr = GetEnCFieldAddr(ObjectHandleOnStack.Create(ref nullTarget), pFD);
if (addr == null)
throw new NullReferenceException();
return addr;
}
}

public unsafe partial struct ModuleHandle : IEquatable<ModuleHandle>
Expand Down
19 changes: 18 additions & 1 deletion src/coreclr/classlibnative/bcltype/arraynative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ static void CheckElementType(TypeHandle elementType)
}
}

void QCALLTYPE Array_CreateInstance(QCall::TypeHandle pTypeHnd, INT32 rank, INT32* pLengths, INT32* pLowerBounds, BOOL createFromArrayType, QCall::ObjectHandleOnStack retArray)
extern "C" void QCALLTYPE Array_CreateInstance(QCall::TypeHandle pTypeHnd, INT32 rank, INT32* pLengths, INT32* pLowerBounds, BOOL createFromArrayType, QCall::ObjectHandleOnStack retArray)
{
CONTRACTL {
QCALL_CHECK;
Expand Down Expand Up @@ -205,3 +205,20 @@ void QCALLTYPE Array_CreateInstance(QCall::TypeHandle pTypeHnd, INT32 rank, INT3
Done: ;
END_QCALL;
}

extern "C" void QCALLTYPE Array_CreateInstanceMDArray(EnregisteredTypeHandle typeHandle, UINT32 dwNumArgs, INT32* pArgList, QCall::ObjectHandleOnStack retArray)
{
QCALL_CONTRACT;

BEGIN_QCALL;

GCX_COOP();

TypeHandle typeHnd = TypeHandle::FromPtr(typeHandle);
_ASSERTE(typeHnd.IsFullyLoaded());
_ASSERTE(typeHnd.GetMethodTable()->IsArray());

retArray.Set(AllocateArrayEx(typeHnd, pArgList, dwNumArgs));

END_QCALL;
}
3 changes: 2 additions & 1 deletion src/coreclr/classlibnative/bcltype/arraynative.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class ArrayNative
static FCDECL1(INT32, GetCorElementTypeOfElementType, ArrayBase* arrayUNSAFE);
};

extern "C" void QCALLTYPE Array_CreateInstance(QCall::TypeHandle pTypeHnd, INT32 rank, INT32* pLengths, INT32* pBounds, BOOL createFromArrayType, QCall::ObjectHandleOnStack retArray);
extern "C" PCODE QCALLTYPE Array_GetElementConstructorEntrypoint(QCall::TypeHandle pArrayTypeHnd);
extern "C" void QCALLTYPE Array_CreateInstance(QCall::TypeHandle pTypeHnd, INT32 rank, INT32* pLengths, INT32* pBounds, BOOL createFromArrayType, QCall::ObjectHandleOnStack retArray);
extern "C" void QCALLTYPE Array_CreateInstanceMDArray(EnregisteredTypeHandle typeHandle, UINT32 dwNumArgs, INT32* pArgList, QCall::ObjectHandleOnStack retArray);

#endif // _ARRAYNATIVE_H_
10 changes: 5 additions & 5 deletions src/coreclr/inc/jithelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@
DYNAMICJITHELPER(CORINFO_HELP_NEWSFAST_ALIGN8, JIT_New, METHOD__NIL)
JITHELPER(CORINFO_HELP_NEWSFAST_ALIGN8_VC, NULL, METHOD__NIL)
JITHELPER(CORINFO_HELP_NEWSFAST_ALIGN8_FINALIZE, NULL, METHOD__NIL)
JITHELPER(CORINFO_HELP_NEW_MDARR, JIT_NewMDArr,METHOD__NIL)
JITHELPER(CORINFO_HELP_NEW_MDARR_RARE, JIT_NewMDArr,METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_NEW_MDARR, NULL, METHOD__ARRAY__CREATEINSTANCEMDARRAY)
DYNAMICJITHELPER(CORINFO_HELP_NEW_MDARR_RARE, NULL, METHOD__ARRAY__CREATEINSTANCEMDARRAY)
JITHELPER(CORINFO_HELP_NEWARR_1_DIRECT, JIT_NewArr1,METHOD__NIL)
JITHELPER(CORINFO_HELP_NEWARR_1_MAYBEFROZEN, JIT_NewArr1MaybeFrozen,METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_NEWARR_1_OBJ, JIT_NewArr1,METHOD__NIL)
Expand Down Expand Up @@ -164,9 +164,9 @@

// Accessing fields

JITHELPER(CORINFO_HELP_GETFIELDADDR, JIT_GetFieldAddr,METHOD__NIL)
JITHELPER(CORINFO_HELP_GETSTATICFIELDADDR, JIT_GetStaticFieldAddr,METHOD__NIL)
JITHELPER(CORINFO_HELP_GETSTATICFIELDADDR_TLS, NULL, METHOD__NIL)
DYNAMICJITHELPER(CORINFO_HELP_GETFIELDADDR, NULL, METHOD__FIELD_HANDLE__GETFIELDADDR)
DYNAMICJITHELPER(CORINFO_HELP_GETSTATICFIELDADDR, NULL, METHOD__FIELD_HANDLE__GETSTATICFIELDADDR)
JITHELPER(CORINFO_HELP_GETSTATICFIELDADDR_TLS, NULL, METHOD__NIL)

DYNAMICJITHELPER(CORINFO_HELP_GET_GCSTATIC_BASE, JIT_GetGCStaticBase, METHOD__STATICSHELPERS__GET_GC_STATIC)
DYNAMICJITHELPER(CORINFO_HELP_GET_NONGCSTATIC_BASE, JIT_GetNonGCStaticBase, METHOD__STATICSHELPERS__GET_NONGC_STATIC)
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/jit/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1817,7 +1817,6 @@ void HelperCallProperties::init()
case CORINFO_HELP_MON_ENTER:
case CORINFO_HELP_MON_EXIT:
case CORINFO_HELP_JIT_REVERSE_PINVOKE_EXIT:
case CORINFO_HELP_GETFIELDADDR:
case CORINFO_HELP_JIT_PINVOKE_BEGIN:
case CORINFO_HELP_JIT_PINVOKE_END:
noThrow = true;
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/vm/corelib.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ DEFINE_METHOD(ARG_ITERATOR, CTOR2, .ctor,
DEFINE_CLASS(ARGUMENT_HANDLE, System, RuntimeArgumentHandle)

DEFINE_CLASS(ARRAY, System, Array)
DEFINE_METHOD(ARRAY, CREATEINSTANCEMDARRAY, CreateInstanceMDArray, SM_IntPtr_UInt_VoidPtr_RetObj)

DEFINE_CLASS(ARRAY_WITH_OFFSET, Interop, ArrayWithOffset)
DEFINE_FIELD(ARRAY_WITH_OFFSET, M_ARRAY, m_array)
Expand Down Expand Up @@ -367,6 +368,8 @@ DEFINE_CLASS(FIELD, Reflection, RuntimeFieldInfo)

DEFINE_CLASS(FIELD_HANDLE, System, RuntimeFieldHandle)
DEFINE_FIELD(FIELD_HANDLE, M_FIELD, m_ptr)
DEFINE_METHOD(FIELD_HANDLE, GETFIELDADDR, GetFieldAddr, SM_Obj_VoidPtr_RetVoidPtr)
DEFINE_METHOD(FIELD_HANDLE, GETSTATICFIELDADDR, GetStaticFieldAddr, SM_VoidPtr_RetVoidPtr)

DEFINE_CLASS(I_RT_FIELD_INFO, System, IRuntimeFieldInfo)

Expand Down
19 changes: 0 additions & 19 deletions src/coreclr/vm/field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,25 +474,6 @@ void *FieldDesc::GetInstanceAddress(OBJECTREF o)
return (void *) (dac_cast<TADDR>(o->GetData()) + dwOffset);
}

// And here's the equivalent, when you are guaranteed that the enclosing instance of
// the field is in the GC Heap. So if the enclosing instance is a value type, it had
// better be boxed. We ASSERT this.
void *FieldDesc::GetAddressGuaranteedInHeap(void *o)
{
CONTRACTL
{
NOTHROW;
GC_NOTRIGGER;
MODE_COOPERATIVE;
}
CONTRACTL_END;

_ASSERTE(!IsEnCNew());

return ((BYTE*)(o)) + sizeof(Object) + m_dwOffset;
}


DWORD FieldDesc::GetValue32(OBJECTREF o)
{
WRAPPER_NO_CONTRACT;
Expand Down
3 changes: 1 addition & 2 deletions src/coreclr/vm/field.h
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ class FieldDesc
SetOffset(FIELD_OFFSET_NEW_ENC);
}

BOOL IsCollectible()
BOOL IsCollectible()
{
LIMITED_METHOD_DAC_CONTRACT;

Expand Down Expand Up @@ -340,7 +340,6 @@ class FieldDesc
PTR_VOID GetAddress(PTR_VOID o);

PTR_VOID GetAddressNoThrowNoGC(PTR_VOID o);
void* GetAddressGuaranteedInHeap(void *o);

void* GetValuePtr(OBJECTREF o);
VOID SetValuePtr(OBJECTREF o, void* pValue);
Expand Down
91 changes: 0 additions & 91 deletions src/coreclr/vm/jithelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,78 +462,6 @@ HCIMPLEND

#include <optdefault.h>


//========================================================================
//
// INSTANCE FIELD HELPERS
//
//========================================================================

/*********************************************************************/
// Returns the address of the instance field in the object (This is an interior
// pointer and the caller has to use it appropriately) or a static field.
// obj can be either a reference or a byref
HCIMPL2(void*, JIT_GetFieldAddr_Framed, Object *obj, FieldDesc* pFD)
{
CONTRACTL {
FCALL_CHECK;
PRECONDITION(CheckPointer(pFD));
} CONTRACTL_END;

void * fldAddr = NULL;
OBJECTREF objRef = ObjectToOBJECTREF(obj);

HELPER_METHOD_FRAME_BEGIN_RET_1(objRef);

if (!pFD->IsStatic() && objRef == NULL)
COMPlusThrow(kNullReferenceException);

fldAddr = pFD->GetAddress(OBJECTREFToObject(objRef));

HELPER_METHOD_FRAME_END();

return fldAddr;
}
HCIMPLEND

#include <optsmallperfcritical.h>
HCIMPL2(void*, JIT_GetFieldAddr, Object *obj, FieldDesc* pFD)
{
CONTRACTL {
FCALL_CHECK;
PRECONDITION(CheckPointer(pFD));
} CONTRACTL_END;

if (obj == NULL || pFD->IsEnCNew())
{
ENDFORBIDGC();
return HCCALL2(JIT_GetFieldAddr_Framed, obj, pFD);
}

return pFD->GetAddressGuaranteedInHeap(obj);
}
HCIMPLEND
#include <optdefault.h>

#include <optsmallperfcritical.h>
HCIMPL1(void*, JIT_GetStaticFieldAddr, FieldDesc* pFD)
{
CONTRACTL {
FCALL_CHECK;
PRECONDITION(CheckPointer(pFD));
} CONTRACTL_END;

// [TODO] Only handling EnC for now
_ASSERTE(pFD->IsEnCNew());

{
ENDFORBIDGC();
return HCCALL2(JIT_GetFieldAddr_Framed, NULL, pFD);
}
}
HCIMPLEND
#include <optdefault.h>

// Helper for the managed InitClass implementations
extern "C" void QCALLTYPE InitClassHelper(MethodTable* pMT)
{
Expand Down Expand Up @@ -1232,25 +1160,6 @@ HCIMPL2(Object*, JIT_NewArr1MaybeFrozen, CORINFO_CLASS_HANDLE arrayMT, INT_PTR s
}
HCIMPLEND

/*************************************************************/
HCIMPL3(Object*, JIT_NewMDArr, CORINFO_CLASS_HANDLE classHnd, unsigned dwNumArgs, INT32 * pArgList)
{
FCALL_CONTRACT;

OBJECTREF ret = 0;
HELPER_METHOD_FRAME_BEGIN_RET_1(ret); // Set up a frame

TypeHandle typeHnd(classHnd);
_ASSERTE(typeHnd.IsFullyLoaded());
_ASSERTE(typeHnd.GetMethodTable()->IsArray());

ret = AllocateArrayEx(typeHnd, pArgList, dwNumArgs);

HELPER_METHOD_FRAME_END();
return OBJECTREFToObject(ret);
}
HCIMPLEND

#include <optdefault.h>

//========================================================================
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/vm/metasig.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,10 @@ DEFINE_METASIG_T(SM(Int_IntPtr_Obj_RetException, i I j, C(EXCEPTION)))
DEFINE_METASIG_T(SM(Type_CharPtr_RuntimeAssembly_Bool_Bool_RetRuntimeType, P(u) C(ASSEMBLY) F F, C(CLASS)))
DEFINE_METASIG_T(SM(Type_RetIntPtr, C(TYPE), I))
DEFINE_METASIG(SM(RefIntPtr_IntPtr_IntPtr_Int_RetObj, r(I) I I i, j))
DEFINE_METASIG(SM(IntPtr_UInt_VoidPtr_RetObj, I K P(v), j))
DEFINE_METASIG(SM(Obj_IntPtr_RetIntPtr, j I, I))
DEFINE_METASIG(SM(VoidPtr_RetVoidPtr, P(v), P(v)))
DEFINE_METASIG(SM(Obj_VoidPtr_RetVoidPtr, j P(v), P(v)))
DEFINE_METASIG(SM(Obj_IntPtr_RetObj, j I, j))
DEFINE_METASIG(SM(Obj_RefIntPtr_RetVoid, j r(I), v))
DEFINE_METASIG(SM(Obj_IntPtr_RetVoid, j I, v))
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/vm/qcallentrypoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ static const Entry s_QCall[] =
DllImportEntry(RuntimeFieldHandle_SetValue)
DllImportEntry(RuntimeFieldHandle_GetValueDirect)
DllImportEntry(RuntimeFieldHandle_SetValueDirect)
DllImportEntry(RuntimeFieldHandle_GetEnCFieldAddr)
DllImportEntry(RuntimeFieldHandle_GetRVAFieldInfo)
DllImportEntry(RuntimeFieldHandle_GetFieldDataReference)
DllImportEntry(StackTrace_GetStackFramesInternal)
Expand Down Expand Up @@ -217,6 +218,7 @@ static const Entry s_QCall[] =
DllImportEntry(TypeBuilder_DefineCustomAttribute)
DllImportEntry(MdUtf8String_EqualsCaseInsensitive)
DllImportEntry(Array_CreateInstance)
DllImportEntry(Array_CreateInstanceMDArray)
DllImportEntry(Array_GetElementConstructorEntrypoint)
DllImportEntry(AssemblyName_InitializeAssemblySpec)
DllImportEntry(AssemblyNative_GetFullName)
Expand Down
29 changes: 29 additions & 0 deletions src/coreclr/vm/reflectioninvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,35 @@ FCIMPL1(void*, RuntimeFieldHandle::GetStaticFieldAddress, ReflectFieldObject *pF
}
FCIMPLEND

// Returns the address of the EnC instance field in the object (This is an interior
// pointer and the caller has to use it appropriately) or an EnC static field.
extern "C" void* QCALLTYPE RuntimeFieldHandle_GetEnCFieldAddr(QCall::ObjectHandleOnStack target, FieldDesc* pFD)
{
CONTRACTL
{
QCALL_CHECK;
PRECONDITION(pFD != NULL);
}
CONTRACTL_END;

void* ret = NULL;

BEGIN_QCALL;

GCX_COOP();

// Only handling EnC
_ASSERTE(pFD->IsEnCNew());

// If the field is static, or if the object is non-null, get the address of the field.
if (pFD->IsStatic() || target.Get() != NULL)
ret = pFD->GetAddress(OBJECTREFToObject(target.Get()));

END_QCALL;

return ret;
}

extern "C" BOOL QCALLTYPE RuntimeFieldHandle_GetRVAFieldInfo(FieldDesc* pField, void** address, UINT* size)
{
QCALL_CONTRACT;
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/vm/runtimehandles.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ extern "C" void QCALLTYPE RuntimeFieldHandle_GetValue(FieldDesc* fieldDesc, QCal
extern "C" void QCALLTYPE RuntimeFieldHandle_SetValue(FieldDesc* fieldDesc, QCall::ObjectHandleOnStack instance, QCall::ObjectHandleOnStack value, QCall::TypeHandle fieldType, QCall::TypeHandle declaringType, BOOL* pIsClassInitialized);
extern "C" void QCALLTYPE RuntimeFieldHandle_GetValueDirect(FieldDesc* fieldDesc, TypedByRef *pTarget, QCall::TypeHandle fieldTypeHandle, QCall::TypeHandle declaringTypeHandle, QCall::ObjectHandleOnStack result);
extern "C" void QCALLTYPE RuntimeFieldHandle_SetValueDirect(FieldDesc* fieldDesc, TypedByRef *pTarget, QCall::ObjectHandleOnStack newValue, QCall::TypeHandle fieldType, QCall::TypeHandle declaringType);
extern "C" void* QCALLTYPE RuntimeFieldHandle_GetEnCFieldAddr(QCall::ObjectHandleOnStack target, FieldDesc* pFD);
extern "C" BOOL QCALLTYPE RuntimeFieldHandle_GetRVAFieldInfo(FieldDesc* pField, void** address, UINT* size);
extern "C" void QCALLTYPE RuntimeFieldHandle_GetFieldDataReference(FieldDesc* pField, QCall::ObjectHandleOnStack instance, QCall::ByteRefOnStack offset);

Expand Down
Loading