Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
9c15c1f
Allocate Type objects on Frozen Heap
EgorBo Sep 13, 2022
232033b
Mitigate perf regressions
EgorBo Sep 13, 2022
f63c941
clean up
EgorBo Sep 13, 2022
841e9c7
fix build issue?
EgorBo Sep 14, 2022
f168d13
Fix eeGetCPString for string literals in JitDisasm
EgorBo Sep 14, 2022
2f50121
Merge branch 'main' of github.com:dotnet/runtime into foh-type-objects
EgorBo Sep 14, 2022
3e6d3ba
clean up
EgorBo Sep 14, 2022
c939027
Merge branch 'main' of github.com:dotnet/runtime into foh-type-objects
EgorBo Sep 14, 2022
c8512a9
Update src/coreclr/jit/compiler.h
EgorBo Sep 17, 2022
bad7cc4
Merge branch 'main' of github.com:dotnet/runtime into foh-type-objects
EgorBo Sep 17, 2022
9d8526e
Address some of the feedback [WIP]
EgorBo Sep 17, 2022
18e1cd4
Address feedback
EgorBo Sep 17, 2022
a7fea6d
Fix compilation
EgorBo Sep 17, 2022
f2afedc
Introduce `objectToString` JIT-EE API
EgorBo Sep 17, 2022
6a8cedf
Update src/coreclr/vm/methodtable.cpp
EgorBo Sep 17, 2022
677f94b
check for unloadability in GetPinnedManagedClassObjectIfExists
EgorBo Sep 17, 2022
15bcad1
Merge branch 'foh-type-objects' of github.com:EgorBo/runtime-1 into f…
EgorBo Sep 17, 2022
81bacbb
Since I still have to check CanUnload I guess I don't need the bit test
EgorBo Sep 17, 2022
b5b7c98
Address feedback
EgorBo Sep 17, 2022
608e6c9
Add more temp debug checks for ci
EgorBo Sep 17, 2022
be063b8
Check if it reproduces because of jit
EgorBo Sep 18, 2022
59af88b
Check if it reproduces because of jit
EgorBo Sep 18, 2022
a8e0786
Ah, facepalm
EgorBo Sep 18, 2022
1f9a348
Clean up
EgorBo Sep 18, 2022
2fd4384
Address Jan's feedback
EgorBo Sep 18, 2022
8f2a767
Oops, a typo
EgorBo Sep 18, 2022
b4b7128
Share logic to extract OBJECTREF from m_hExposedClassObject
EgorBo Sep 18, 2022
a2ca5b1
Merge branch 'main' of github.com:dotnet/runtime into foh-type-objects
EgorBo Sep 19, 2022
fd099a2
Produce better asm code for JIT_GetRuntimeType
EgorBo Sep 19, 2022
64e7171
Merge branch 'main' of github.com:dotnet/runtime into foh-type-objects
EgorBo Sep 20, 2022
ac405a1
Merge branch 'main' of github.com:dotnet/runtime into foh-type-objects
EgorBo Sep 20, 2022
7ab7bd1
Address feedback
EgorBo Sep 20, 2022
895e9f5
Update src/coreclr/vm/jitinterface.cpp
EgorBo Sep 20, 2022
bcd47b1
Address feedback
EgorBo Sep 20, 2022
c217579
Update src/coreclr/vm/methodtable.cpp
EgorBo Sep 21, 2022
253747e
Address feedback: the bit is always there so we can do ` - 1`
EgorBo Sep 21, 2022
ca6c69a
Address feedback
EgorBo Sep 21, 2022
93ef525
Update src/coreclr/vm/methodtable.cpp
jkotas Sep 21, 2022
7394e1e
Update src/coreclr/jit/ee_il_dll.cpp
EgorBo Sep 21, 2022
f6055b9
remove null-termination from api
EgorBo Sep 21, 2022
57b1477
address feedback
EgorBo Sep 21, 2022
e9a396f
Address feedback
EgorBo Sep 21, 2022
4fbb894
Pass utf8 string in objectToString
EgorBo Sep 21, 2022
7476a68
remove char16_t left over
EgorBo Sep 21, 2022
bc2292b
fix compilation warning
EgorBo Sep 22, 2022
7bf7e0e
Update gentree.cpp
EgorBo Sep 22, 2022
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
Next Next commit
Allocate Type objects on Frozen Heap
  • Loading branch information
EgorBo committed Sep 13, 2022
commit 9c15c1f95d8f880513dc73cbd5fab42fd215b614
4 changes: 4 additions & 0 deletions src/coreclr/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2475,6 +2475,10 @@ class ICorStaticInfo
CORINFO_CLASS_HANDLE cls
) = 0;

virtual void* getRuntimeTypePointer(
CORINFO_CLASS_HANDLE cls
) = 0;

virtual bool getReadyToRunHelper(
CORINFO_RESOLVED_TOKEN * pResolvedToken,
CORINFO_LOOKUP_KIND * pGenericLookupKind,
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/inc/icorjitinfoimpl_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ CorInfoHelpFunc getBoxHelper(
CorInfoHelpFunc getUnBoxHelper(
CORINFO_CLASS_HANDLE cls) override;

void* getRuntimeTypePointer(
CORINFO_CLASS_HANDLE cls) override;

bool getReadyToRunHelper(
CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_LOOKUP_KIND* pGenericLookupKind,
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 = { /* 0cd8b9d4-04f4-45a7-b16b-7f24b7c0a454 */
0x0cd8b9d4,
0x04f4,
0x45a7,
{0xb1, 0x6b, 0x7f, 0x24, 0xb7, 0xc0, 0xa4, 0x54}
constexpr GUID JITEEVersionIdentifier = { /* 104b5beb-d585-4d52-b08a-d5c6938603fc */
0x104b5beb,
0xd585,
0x4d52,
{0xb0, 0x8a, 0xd5, 0xc6, 0x93, 0x86, 0x3, 0xfc}
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/ICorJitInfo_API_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ DEF_CLR_API(getSharedCCtorHelper)
DEF_CLR_API(getTypeForBox)
DEF_CLR_API(getBoxHelper)
DEF_CLR_API(getUnBoxHelper)
DEF_CLR_API(getRuntimeTypePointer)
DEF_CLR_API(getReadyToRunHelper)
DEF_CLR_API(getReadyToRunDelegateCtorHelper)
DEF_CLR_API(getHelperName)
Expand Down
9 changes: 9 additions & 0 deletions src/coreclr/jit/ICorJitInfo_API_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,15 @@ CorInfoHelpFunc WrapICorJitInfo::getUnBoxHelper(
return temp;
}

void* WrapICorJitInfo::getRuntimeTypePointer(
CORINFO_CLASS_HANDLE cls)
{
API_ENTER(getRuntimeTypePointer);
void* temp = wrapHnd->getRuntimeTypePointer(cls);
API_LEAVE(getRuntimeTypePointer);
return temp;
}

bool WrapICorJitInfo::getReadyToRunHelper(
CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_LOOKUP_KIND* pGenericLookupKind,
Expand Down
17 changes: 16 additions & 1 deletion src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4046,7 +4046,22 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis,
op1 = impPopStack().val;
// Replace helper with a more specialized helper that returns RuntimeType
if (typeHandleHelper == CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPEHANDLE)
{
{
CORINFO_CLASS_HANDLE hClass =
gtGetHelperArgClassHandle(op1->AsCall()->gtArgs.GetArgByIndex(0)->GetEarlyNode());
if (!opts.IsReadyToRun() && (hClass != NO_CLASS_HANDLE))
{
void* ptr = info.compCompHnd->getRuntimeTypePointer(hClass);
if (ptr != nullptr)
{
// Temp Hack: pretend we're a string literal :-)
setMethodHasFrozenString();
retNode = gtNewIconEmbHndNode(ptr, nullptr, GTF_ICON_STR_HDL, nullptr);
retNode->gtType = TYP_REF;
INDEBUG(retNode->AsIntCon()->gtTargetHandle = (size_t)ptr);
break;
}
}
typeHandleHelper = CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE;
}
else
Expand Down
237 changes: 127 additions & 110 deletions src/coreclr/tools/Common/JitInterface/CorInfoBase.cs

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2304,6 +2304,13 @@ private CorInfoHelpFunc getUnBoxHelper(CORINFO_CLASS_STRUCT_* cls)
return type.IsNullable ? CorInfoHelpFunc.CORINFO_HELP_UNBOX_NULLABLE : CorInfoHelpFunc.CORINFO_HELP_UNBOX;
}

#pragma warning disable CA1822 // Mark members as static
private void* getRuntimeTypePointer(CORINFO_CLASS_STRUCT_* cls)
#pragma warning restore CA1822 // Mark members as static
{
return (void*)IntPtr.Zero;
}

private byte* getHelperName(CorInfoHelpFunc helpFunc)
{
return (byte*)GetPin(StringToUTF8(helpFunc.ToString()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ FUNCTIONS
CORINFO_CLASS_HANDLE getTypeForBox(CORINFO_CLASS_HANDLE cls)
CorInfoHelpFunc getBoxHelper(CORINFO_CLASS_HANDLE cls)
CorInfoHelpFunc getUnBoxHelper(CORINFO_CLASS_HANDLE cls)
void* getRuntimeTypePointer(CORINFO_CLASS_HANDLE cls)
bool getReadyToRunHelper(CORINFO_RESOLVED_TOKEN * pResolvedToken, CORINFO_LOOKUP_KIND * pGenericLookupKind, CorInfoHelpFunc id, CORINFO_CONST_LOOKUP *pLookup)
void getReadyToRunDelegateCtorHelper(CORINFO_RESOLVED_TOKEN * pTargetMethod, mdToken targetConstraint, CORINFO_CLASS_HANDLE delegateType, CORINFO_LOOKUP *pLookup)
const char* getHelperName(CorInfoHelpFunc helpFunc)
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/tools/aot/jitinterface/jitinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ struct JitInterfaceCallbacks
CORINFO_CLASS_HANDLE (* getTypeForBox)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE cls);
CorInfoHelpFunc (* getBoxHelper)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE cls);
CorInfoHelpFunc (* getUnBoxHelper)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE cls);
void* (* getRuntimeTypePointer)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE cls);
bool (* getReadyToRunHelper)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_RESOLVED_TOKEN* pResolvedToken, CORINFO_LOOKUP_KIND* pGenericLookupKind, CorInfoHelpFunc id, CORINFO_CONST_LOOKUP* pLookup);
void (* getReadyToRunDelegateCtorHelper)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_RESOLVED_TOKEN* pTargetMethod, unsigned int targetConstraint, CORINFO_CLASS_HANDLE delegateType, CORINFO_LOOKUP* pLookup);
const char* (* getHelperName)(void * thisHandle, CorInfoExceptionClass** ppException, CorInfoHelpFunc helpFunc);
Expand Down Expand Up @@ -841,6 +842,15 @@ class JitInterfaceWrapper : public ICorJitInfo
return temp;
}

virtual void* getRuntimeTypePointer(
CORINFO_CLASS_HANDLE cls)
{
CorInfoExceptionClass* pException = nullptr;
void* temp = _callbacks->getRuntimeTypePointer(_thisHandle, &pException, cls);
if (pException != nullptr) throw pException;
return temp;
}

virtual bool getReadyToRunHelper(
CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_LOOKUP_KIND* pGenericLookupKind,
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ LWM(GetTypeForPrimitiveValueClass, DWORDLONG, DWORD)
LWM(GetTypeForPrimitiveNumericClass, DWORDLONG, DWORD)
LWM(GetUnboxedEntry, DWORDLONG, DLD);
LWM(GetUnBoxHelper, DWORDLONG, DWORD)
LWM(GetRuntimeTypePointer, DWORDLONG, DWORDLONG)
LWM(GetVarArgsHandle, GetVarArgsHandleValue, DLDL)
LWM(GetVars, DWORDLONG, Agnostic_GetVars)
LWM(InitClass, Agnostic_InitClass, DWORD)
Expand Down
23 changes: 23 additions & 0 deletions src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2186,6 +2186,29 @@ CorInfoHelpFunc MethodContext::repGetUnBoxHelper(CORINFO_CLASS_HANDLE cls)
return result;
}

void MethodContext::recGetRuntimeTypePointer(CORINFO_CLASS_HANDLE cls, void* result)
{
if (GetRuntimeTypePointer == nullptr)
GetRuntimeTypePointer = new LightWeightMap<DWORDLONG, DWORDLONG>();

DWORDLONG key = CastHandle(cls);
DWORDLONG value = (DWORDLONG)result;
GetRuntimeTypePointer->Add(key, value);
DEBUG_REC(dmpGetRuntimeTypePointer(key, value));
}
void MethodContext::dmpGetRuntimeTypePointer(DWORDLONG key, DWORDLONG value)
{
printf("GetRuntimeTypePointer key cls-%016llX, value res-%016llX", key, value);
}
void* MethodContext::repGetRuntimeTypePointer(CORINFO_CLASS_HANDLE cls)
{
DWORDLONG key = CastHandle(cls);
AssertMapAndKeyExist(GetRuntimeTypePointer, key, ": key %016llX", key);
DWORDLONG value = GetRuntimeTypePointer->Get(key);
DEBUG_REP(dmpGetRuntimeTypePointer(key, value));
return (void*)value;
}

void MethodContext::recGetReadyToRunHelper(CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_LOOKUP_KIND* pGenericLookupKind,
CorInfoHelpFunc id,
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,10 @@ class MethodContext
void dmpGetUnBoxHelper(DWORDLONG key, DWORD value);
CorInfoHelpFunc repGetUnBoxHelper(CORINFO_CLASS_HANDLE cls);

void recGetRuntimeTypePointer(CORINFO_CLASS_HANDLE cls, void* result);
void dmpGetRuntimeTypePointer(DWORDLONG key, DWORDLONG value);
void* repGetRuntimeTypePointer(CORINFO_CLASS_HANDLE cls);

void recGetReadyToRunHelper(CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_LOOKUP_KIND* pGenericLookupKind,
CorInfoHelpFunc id,
Expand Down Expand Up @@ -1129,6 +1133,7 @@ enum mcPackets
Packet_UpdateEntryPointForTailCall = 193,
Packet_GetLoongArch64PassStructInRegisterFlags = 194,
Packet_GetExactClasses = 195,
Packet_GetRuntimeTypePointer = 196,
};

void SetDebugDumpVariables();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,14 @@ CorInfoHelpFunc interceptor_ICJI::getUnBoxHelper(CORINFO_CLASS_HANDLE cls)
return temp;
}

void* interceptor_ICJI::getRuntimeTypePointer(CORINFO_CLASS_HANDLE cls)
{
mc->cr->AddCall("getRuntimeTypePointer");
void* temp = original_ICorJitInfo->getRuntimeTypePointer(cls);
mc->recGetRuntimeTypePointer(cls, temp);
return temp;
}

bool interceptor_ICJI::getReadyToRunHelper(CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_LOOKUP_KIND* pGenericLookupKind,
CorInfoHelpFunc id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,13 @@ CorInfoHelpFunc interceptor_ICJI::getUnBoxHelper(
return original_ICorJitInfo->getUnBoxHelper(cls);
}

void* interceptor_ICJI::getRuntimeTypePointer(
CORINFO_CLASS_HANDLE cls)
{
mcs->AddCall("getRuntimeTypePointer");
return original_ICorJitInfo->getRuntimeTypePointer(cls);
}

bool interceptor_ICJI::getReadyToRunHelper(
CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_LOOKUP_KIND* pGenericLookupKind,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,12 @@ CorInfoHelpFunc interceptor_ICJI::getUnBoxHelper(
return original_ICorJitInfo->getUnBoxHelper(cls);
}

void* interceptor_ICJI::getRuntimeTypePointer(
CORINFO_CLASS_HANDLE cls)
{
return original_ICorJitInfo->getRuntimeTypePointer(cls);
}

bool interceptor_ICJI::getReadyToRunHelper(
CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_LOOKUP_KIND* pGenericLookupKind,
Expand Down
7 changes: 7 additions & 0 deletions src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,13 @@ CorInfoHelpFunc MyICJI::getUnBoxHelper(CORINFO_CLASS_HANDLE cls)
return result;
}

void* MyICJI::getRuntimeTypePointer(CORINFO_CLASS_HANDLE cls)
{
jitInstance->mc->cr->AddCall("getRuntimeTypePointer");
void* result = jitInstance->mc->repGetRuntimeTypePointer(cls);
return result;
}

bool MyICJI::getReadyToRunHelper(CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_LOOKUP_KIND* pGenericLookupKind,
CorInfoHelpFunc id,
Expand Down
9 changes: 9 additions & 0 deletions src/coreclr/vm/frozenobjectheap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,15 @@ Object* FrozenObjectHeapManager::TryAllocateObject(PTR_MethodTable type, size_t
#endif // !FEATURE_BASICFREEZE
}

// Does object belong to a frozen segment?
bool FrozenObjectHeapManager::IsFromFrozenSegment(Object* object)
{
#ifdef FEATURE_BASICFREEZE
return GCHeapUtilities::GetGCHeap()->IsInFrozenSegment(object);
#else
return false;
#endif
}

FrozenObjectSegment::FrozenObjectSegment():
m_pStart(nullptr),
Expand Down
1 change: 1 addition & 0 deletions src/coreclr/vm/frozenobjectheap.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class FrozenObjectHeapManager
public:
FrozenObjectHeapManager();
Object* TryAllocateObject(PTR_MethodTable type, size_t objectSize);
bool IsFromFrozenSegment(Object* object);

private:
Crst m_Crst;
Expand Down
32 changes: 32 additions & 0 deletions src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5945,6 +5945,38 @@ CorInfoHelpFunc CEEInfo::getUnBoxHelper(CORINFO_CLASS_HANDLE clsHnd)
return CORINFO_HELP_UNBOX;
}

/***********************************************************************/
void* CEEInfo::getRuntimeTypePointer(CORINFO_CLASS_HANDLE clsHnd)
{
LIMITED_METHOD_CONTRACT;

void* pointer = nullptr;

JIT_TO_EE_TRANSITION();

GCX_COOP();

TypeHandle typeHnd(clsHnd);
if (!typeHnd.IsNull() && !typeHnd.IsTypeDesc() && typeHnd.IsFullyLoaded())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to do this optimization for TypeDescs too.

Also, IsFullyLoaded check should not be needed. Types handed back to the JIT are always fully loaded.

{
MethodTable* pMT = typeHnd.AsMethodTable();
if (!typeHnd.IsCanonicalSubtype())
{
// We probably don't want to allocate a RuntimeHelper as part of this query
// hence, use IfExists
bool isPinned;
Object* obj = OBJECTREFToObject(pMT->GetManagedClassObjectIfExists(&isPinned));
if (obj != nullptr && isPinned)
{
pointer = (void*)obj;
}
}
}
EE_TO_JIT_TRANSITION();

return pointer;
}

/***********************************************************************/
bool CEEInfo::getReadyToRunHelper(
CORINFO_RESOLVED_TOKEN * pResolvedToken,
Expand Down
15 changes: 13 additions & 2 deletions src/coreclr/vm/methodtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4222,9 +4222,20 @@ OBJECTREF MethodTable::GetManagedClassObject()

REFLECTCLASSBASEREF refClass = NULL;
GCPROTECT_BEGIN(refClass);
refClass = (REFLECTCLASSBASEREF) AllocateObject(g_pRuntimeTypeClass);

LoaderAllocator *pLoaderAllocator = GetLoaderAllocator();
LoaderAllocator* pLoaderAllocator = GetLoaderAllocator();
if (!pLoaderAllocator->CanUnload())
{
// Allocate RuntimeType on a frozen segment
FrozenObjectHeapManager* foh = SystemDomain::GetFrozenObjectHeapManager();
size_t objSize = g_pRuntimeTypeClass->GetBaseSize();
refClass = ObjectToOBJECTREF(foh->TryAllocateObject(g_pRuntimeTypeClass, objSize));
}

if (refClass == NULL)
{
refClass = (REFLECTCLASSBASEREF)AllocateObject(g_pRuntimeTypeClass);
}

((ReflectClassBaseObject*)OBJECTREFToObject(refClass))->SetType(TypeHandle(this));
((ReflectClassBaseObject*)OBJECTREFToObject(refClass))->SetKeepAlive(pLoaderAllocator->GetExposedObject());
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/methodtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -2716,7 +2716,7 @@ class MethodTable
// method will get the class object. If it doesn't exist it will be created.
// GetManagedClassObjectIfExists() will return null if the Type object doesn't exist.
OBJECTREF GetManagedClassObject();
OBJECTREF GetManagedClassObjectIfExists();
OBJECTREF GetManagedClassObjectIfExists(bool* pIsPinned = nullptr);


// ------------------------------------------------------------------
Expand Down
12 changes: 11 additions & 1 deletion src/coreclr/vm/methodtable.inl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "methodtable.h"
#include "genericdict.h"
#include "threadstatics.h"
#include "frozenobjectheap.h"

//==========================================================================================
FORCEINLINE PTR_EEClass MethodTable::GetClass_NoLogging()
Expand Down Expand Up @@ -1335,7 +1336,7 @@ inline OBJECTHANDLE MethodTable::GetLoaderAllocatorObjectHandle()
}

//==========================================================================================
FORCEINLINE OBJECTREF MethodTable::GetManagedClassObjectIfExists()
FORCEINLINE OBJECTREF MethodTable::GetManagedClassObjectIfExists(bool* pIsPinned)
{
LIMITED_METHOD_CONTRACT;

Expand All @@ -1353,6 +1354,15 @@ FORCEINLINE OBJECTREF MethodTable::GetManagedClassObjectIfExists()
}

COMPILER_ASSUME(retVal != NULL);

#ifndef DACCESS_COMPILE
if (pIsPinned != nullptr)
{
FrozenObjectHeapManager* foh = SystemDomain::GetFrozenObjectHeapManager();
*pIsPinned = foh->IsFromFrozenSegment(OBJECTREFToObject(retVal));
}
#endif

return retVal;
}

Expand Down