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

Convert HELPER_METHOD_FRAME in objectnative.cpp to QCall #97641

Merged
merged 17 commits into from
Feb 26, 2024
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
Use GetTypeFromHandleUnsafe instead to reduce code duplication
  • Loading branch information
huoyaoyuan committed Jan 29, 2024
commit 62fa6732826b70d91c17e86e8649326a320cac5a
18 changes: 1 addition & 17 deletions src/coreclr/System.Private.CoreLib/src/System/Object.CoreCLR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

namespace System
{
Expand All @@ -15,26 +14,11 @@ public unsafe Type GetType()
{
// Throws NullReferenceException as expected
MethodTable* pMT = RuntimeHelpers.GetMethodTable(this);

Type? type = GetTypeIfExists(pMT);

if (type is not null)
return type;

GetTypeHelper(pMT, ObjectHandleOnStack.Create(ref type));

Debug.Assert(type is not null);
Type type = Type.GetTypeFromHandleUnsafe((IntPtr)pMT);
GC.KeepAlive(this);

return type;
}

[MethodImpl(MethodImplOptions.InternalCall)]
private static extern unsafe Type? GetTypeIfExists(MethodTable* pMT);

[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ObjectNative_GetClassHelper")]
private static unsafe partial void GetTypeHelper(MethodTable* pMT, ObjectHandleOnStack ret);

// Returns a new object instance that is a memberwise copy of this
// object. This is always a shallow copy of the instance. The method is protected
// so that other object may only call this method on themselves. It is intended to
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/classlibnative/bcltype/objectnative.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ class ObjectNative
public:

static FCDECL1(INT32, TryGetHashCode, Object* vThisRef);
static FCDECL1(Object*, GetClassIfExists, MethodTable* pMT);
static FCDECL1(FC_BOOL_RET, IsLockHeld, Object* pThisUNSAFE);
};

extern "C" INT32 QCALLTYPE ObjectNative_GetHashCodeHelper(QCall::ObjectHandleOnStack objHandle);
extern "C" void QCALLTYPE ObjectNative_GetClassHelper(MethodTable* pMT, QCall::ObjectHandleOnStack ret);
extern "C" void QCALLTYPE ObjectNative_AllocateUninitializedClone(QCall::ObjectHandleOnStack objHandle);
extern "C" BOOL QCALLTYPE Monitor_Wait(QCall::ObjectHandleOnStack pThis, INT32 Timeout);
extern "C" void QCALLTYPE Monitor_Pulse(QCall::ObjectHandleOnStack pThis);
Expand Down
5 changes: 0 additions & 5 deletions src/coreclr/vm/ecalllist.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ FCFuncStart(gEnumFuncs)
FCFuncElement("InternalBoxEnum", ReflectionEnum::InternalBoxEnum)
FCFuncEnd()

FCFuncStart(gObjectFuncs)
FCFuncElement("GetTypeIfExists", ObjectNative::GetClassIfExists)
FCFuncEnd()

FCFuncStart(gStringFuncs)
FCDynamic("FastAllocateString", ECall::FastAllocateString)
FCDynamicSig(COR_CTOR_METHOD_NAME, &gsig_IM_ArrChar_RetVoid, ECall::CtorCharArrayManaged)
Expand Down Expand Up @@ -639,7 +635,6 @@ FCClassElement("MngdSafeArrayMarshaler", "System.StubHelpers", gMngdSafeArrayMar
#endif // FEATURE_COMINTEROP
FCClassElement("ModuleHandle", "System", gCOMModuleHandleFuncs)
FCClassElement("Monitor", "System.Threading", gMonitorFuncs)
FCClassElement("Object", "System", gObjectFuncs)

FCClassElement("RuntimeAssembly", "System.Reflection", gRuntimeAssemblyFuncs)
FCClassElement("RuntimeFieldHandle", "System", gCOMFieldHandleNewFuncs)
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/vm/qcallentrypoints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,6 @@ static const Entry s_QCall[] =
DllImportEntry(FileLoadException_GetMessageForHR)
DllImportEntry(Interlocked_MemoryBarrierProcessWide)
DllImportEntry(ObjectNative_GetHashCodeHelper)
DllImportEntry(ObjectNative_GetClassHelper)
DllImportEntry(ObjectNative_AllocateUninitializedClone)
DllImportEntry(Monitor_Wait)
DllImportEntry(Monitor_Pulse)
Expand Down