Skip to content

Commit 34b41f8

Browse files
Make acquiring the loader module for a FnPtrTypeDesc a simple operation instead of a complex algorithm (#106299)
Add the loader module as a simple field instead of requiring the logic to compute a loader module from first principles.
1 parent 7812a92 commit 34b41f8

File tree

4 files changed

+11
-13
lines changed

4 files changed

+11
-13
lines changed

src/coreclr/debug/runtimeinfo/datadescriptor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ CDAC_TYPE_INDETERMINATE(FnPtrTypeDesc)
289289
CDAC_TYPE_FIELD(FnPtrTypeDesc, /*uint32*/, NumArgs, cdac_data<FnPtrTypeDesc>::NumArgs)
290290
CDAC_TYPE_FIELD(FnPtrTypeDesc, /*uint32*/, CallConv, cdac_data<FnPtrTypeDesc>::CallConv)
291291
CDAC_TYPE_FIELD(FnPtrTypeDesc, /*uint32*/, RetAndArgTypes, cdac_data<FnPtrTypeDesc>::RetAndArgTypes)
292+
CDAC_TYPE_FIELD(FnPtrTypeDesc, /*pointer*/, LoaderModule, cdac_data<FnPtrTypeDesc>::LoaderModule)
292293
CDAC_TYPE_END(FnPtrTypeDesc)
293294

294295
CDAC_TYPE_BEGIN(DynamicMetadata)

src/coreclr/vm/clsload.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2695,7 +2695,7 @@ TypeHandle ClassLoader::CreateTypeHandleForTypeKey(const TypeKey* pKey, AllocMem
26952695
DWORD numArgs = pKey->GetNumArgs();
26962696
BYTE* mem = (BYTE*) pamTracker->Track(pLoaderModule->GetAssembly()->GetLowFrequencyHeap()->AllocMem(S_SIZE_T(sizeof(FnPtrTypeDesc)) + S_SIZE_T(sizeof(TypeHandle)) * S_SIZE_T(numArgs)));
26972697

2698-
typeHnd = TypeHandle(new(mem) FnPtrTypeDesc(pKey->GetCallConv(), numArgs, pKey->GetRetAndArgTypes()));
2698+
typeHnd = TypeHandle(new(mem) FnPtrTypeDesc(pKey->GetCallConv(), numArgs, pKey->GetRetAndArgTypes(), pLoaderModule));
26992699
}
27002700
else
27012701
{

src/coreclr/vm/typedesc.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,7 @@ PTR_Module TypeDesc::GetLoaderModule()
7474
}
7575
else
7676
{
77-
PTR_Module retVal = NULL;
78-
BOOL fFail = FALSE;
79-
80-
_ASSERTE(GetInternalCorElementType() == ELEMENT_TYPE_FNPTR);
81-
PTR_FnPtrTypeDesc asFnPtr = dac_cast<PTR_FnPtrTypeDesc>(this);
82-
if (!fFail)
83-
{
84-
retVal = ClassLoader::ComputeLoaderModuleForFunctionPointer(asFnPtr->GetRetAndArgTypesPointer(), asFnPtr->GetNumArgs()+1);
85-
}
86-
return retVal;
77+
return dac_cast<PTR_FnPtrTypeDesc>(this)->GetLoaderModule();
8778
}
8879
}
8980

src/coreclr/vm/typedesc.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,8 @@ class FnPtrTypeDesc : public TypeDesc
415415

416416
public:
417417
#ifndef DACCESS_COMPILE
418-
FnPtrTypeDesc(BYTE callConv, DWORD numArgs, TypeHandle * retAndArgTypes)
419-
: TypeDesc(ELEMENT_TYPE_FNPTR), m_NumArgs(numArgs), m_CallConv(callConv)
418+
FnPtrTypeDesc(BYTE callConv, DWORD numArgs, TypeHandle * retAndArgTypes, PTR_Module pLoaderModule)
419+
: TypeDesc(ELEMENT_TYPE_FNPTR), m_pLoaderModule(pLoaderModule), m_NumArgs(numArgs), m_CallConv(callConv)
420420
{
421421
LIMITED_METHOD_CONTRACT;
422422
for (DWORD i = 0; i <= numArgs; i++)
@@ -469,6 +469,8 @@ class FnPtrTypeDesc : public TypeDesc
469469
BOOL IsExternallyVisible() const;
470470
#endif //DACCESS_COMPILE
471471

472+
PTR_Module GetLoaderModule() const { LIMITED_METHOD_DAC_CONTRACT; return m_pLoaderModule; }
473+
472474
#ifdef DACCESS_COMPILE
473475
static ULONG32 DacSize(TADDR addr)
474476
{
@@ -481,6 +483,9 @@ class FnPtrTypeDesc : public TypeDesc
481483
#endif //DACCESS_COMPILE
482484

483485
protected:
486+
// LoaderModule of the TypeDesc
487+
PTR_Module m_pLoaderModule;
488+
484489
// Number of arguments
485490
DWORD m_NumArgs;
486491

@@ -499,6 +504,7 @@ struct cdac_data<FnPtrTypeDesc>
499504
static constexpr size_t NumArgs = offsetof(FnPtrTypeDesc, m_NumArgs);
500505
static constexpr size_t RetAndArgTypes = offsetof(FnPtrTypeDesc, m_RetAndArgTypes);
501506
static constexpr size_t CallConv = offsetof(FnPtrTypeDesc, m_CallConv);
507+
static constexpr size_t LoaderModule = offsetof(FnPtrTypeDesc, m_pLoaderModule);
502508
};
503509

504510
#endif // TYPEDESC_H

0 commit comments

Comments
 (0)