Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Implement the QCall
  • Loading branch information
huoyaoyuan committed Jan 27, 2024
commit 580f969cef319d6adec94352fb013f26e6b023b8
4 changes: 3 additions & 1 deletion src/coreclr/System.Private.CoreLib/src/System/ValueType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ ref RuntimeHelpers.GetRawData(obj),
return true;
}

// Return true if the valuetype does not contain pointer, is tightly packed,
// does not have floating point number field and does not override Equals method.
private static unsafe bool CanCompareBits(object obj)
{
MethodTable* pMT = RuntimeHelpers.GetMethodTable(obj);
Expand All @@ -86,7 +88,7 @@ private static unsafe bool CanCompareBits(object obj)
return result;
}

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ValueType_CanCompareBitsOrUseFastGetHashCode")]
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "MethodTable_CanCompareBitsOrUseFastGetHashCode")]
[return: MarshalAs(UnmanagedType.Bool)]
private static unsafe partial bool CanCompareBitsOrUseFastGetHashCode(MethodTable* pMT);

Expand Down
34 changes: 5 additions & 29 deletions src/coreclr/vm/comutilnative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1681,44 +1681,20 @@ BOOL CanCompareBitsOrUseFastGetHashCode(MethodTable* mt)
return canCompareBitsOrUseFastGetHashCode;
}

NOINLINE static FC_BOOL_RET CanCompareBitsHelper(MethodTable* mt, OBJECTREF objRef)
extern "C" BOOL QCALLTYPE MethodTable_CanCompareBitsOrUseFastGetHashCode(MethodTable * mt)
{
FC_INNER_PROLOG(ValueTypeHelper::CanCompareBits);

_ASSERTE(mt != NULL);
_ASSERTE(objRef != NULL);
QCALL_CONTRACT;

BOOL ret = FALSE;

HELPER_METHOD_FRAME_BEGIN_RET_ATTRIB_1(Frame::FRAME_ATTR_EXACT_DEPTH|Frame::FRAME_ATTR_CAPTURE_DEPTH_2, objRef);
BEGIN_QCALL;

ret = CanCompareBitsOrUseFastGetHashCode(mt);

HELPER_METHOD_FRAME_END();
FC_INNER_EPILOG();

FC_RETURN_BOOL(ret);
}

// Return true if the valuetype does not contain pointer, is tightly packed,
// does not have floating point number field and does not override Equals method.
FCIMPL1(FC_BOOL_RET, ValueTypeHelper::CanCompareBits, Object* obj)
{
FCALL_CONTRACT;

_ASSERTE(obj != NULL);
MethodTable* mt = obj->GetMethodTable();

if (mt->HasCheckedCanCompareBitsOrUseFastGetHashCode())
{
FC_RETURN_BOOL(mt->CanCompareBitsOrUseFastGetHashCode());
}

OBJECTREF objRef(obj);
END_QCALL;

FC_INNER_RETURN(FC_BOOL_RET, CanCompareBitsHelper(mt, objRef));
return ret;
}
FCIMPLEND

static INT32 FastGetValueTypeHashCodeHelper(MethodTable *mt, void *pObjRef)
{
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/comutilnative.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ extern "C" void QCALLTYPE Interlocked_MemoryBarrierProcessWide();

class ValueTypeHelper {
public:
static FCDECL1(FC_BOOL_RET, CanCompareBits, Object* obj);
static FCDECL1(INT32, GetHashCode, Object* objRef);
};

Expand All @@ -257,6 +256,7 @@ class MethodTableNative {
};

extern "C" BOOL QCALLTYPE MethodTable_AreTypesEquivalent(MethodTable* mta, MethodTable* mtb);
extern "C" BOOL QCALLTYPE MethodTable_CanCompareBitsOrUseFastGetHashCode(MethodTable* mt);

class StreamNative {
public:
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/vm/ecalllist.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ FCFuncStart(gStringFuncs)
FCFuncEnd()

FCFuncStart(gValueTypeFuncs)
FCFuncElement("CanCompareBits", ValueTypeHelper::CanCompareBits)
FCFuncElement("GetHashCode", ValueTypeHelper::GetHashCode)
FCFuncEnd()

Expand Down
1 change: 1 addition & 0 deletions src/coreclr/vm/qcallentrypoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ static const Entry s_QCall[] =
DllImportEntry(QCall_GetGCHandleForTypeHandle)
DllImportEntry(QCall_FreeGCHandleForTypeHandle)
DllImportEntry(MethodTable_AreTypesEquivalent)
DllImportEntry(MethodTable_CanCompareBitsOrUseFastGetHashCode)
DllImportEntry(RuntimeTypeHandle_MakePointer)
DllImportEntry(RuntimeTypeHandle_MakeByRef)
DllImportEntry(RuntimeTypeHandle_MakeSZArray)
Expand Down