Skip to content

Commit

Permalink
Make acquiring the loader module for a FnPtrTypeDesc a simple operati…
Browse files Browse the repository at this point in the history
…on instead of a complex algorithm (dotnet#106299)

Add the loader module as a simple field instead of requiring the logic to compute a loader module from first principles.
  • Loading branch information
davidwrighton committed Aug 13, 2024
1 parent 7812a92 commit 34b41f8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 13 deletions.
1 change: 1 addition & 0 deletions src/coreclr/debug/runtimeinfo/datadescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ CDAC_TYPE_INDETERMINATE(FnPtrTypeDesc)
CDAC_TYPE_FIELD(FnPtrTypeDesc, /*uint32*/, NumArgs, cdac_data<FnPtrTypeDesc>::NumArgs)
CDAC_TYPE_FIELD(FnPtrTypeDesc, /*uint32*/, CallConv, cdac_data<FnPtrTypeDesc>::CallConv)
CDAC_TYPE_FIELD(FnPtrTypeDesc, /*uint32*/, RetAndArgTypes, cdac_data<FnPtrTypeDesc>::RetAndArgTypes)
CDAC_TYPE_FIELD(FnPtrTypeDesc, /*pointer*/, LoaderModule, cdac_data<FnPtrTypeDesc>::LoaderModule)
CDAC_TYPE_END(FnPtrTypeDesc)

CDAC_TYPE_BEGIN(DynamicMetadata)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/clsload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2695,7 +2695,7 @@ TypeHandle ClassLoader::CreateTypeHandleForTypeKey(const TypeKey* pKey, AllocMem
DWORD numArgs = pKey->GetNumArgs();
BYTE* mem = (BYTE*) pamTracker->Track(pLoaderModule->GetAssembly()->GetLowFrequencyHeap()->AllocMem(S_SIZE_T(sizeof(FnPtrTypeDesc)) + S_SIZE_T(sizeof(TypeHandle)) * S_SIZE_T(numArgs)));

typeHnd = TypeHandle(new(mem) FnPtrTypeDesc(pKey->GetCallConv(), numArgs, pKey->GetRetAndArgTypes()));
typeHnd = TypeHandle(new(mem) FnPtrTypeDesc(pKey->GetCallConv(), numArgs, pKey->GetRetAndArgTypes(), pLoaderModule));
}
else
{
Expand Down
11 changes: 1 addition & 10 deletions src/coreclr/vm/typedesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,7 @@ PTR_Module TypeDesc::GetLoaderModule()
}
else
{
PTR_Module retVal = NULL;
BOOL fFail = FALSE;

_ASSERTE(GetInternalCorElementType() == ELEMENT_TYPE_FNPTR);
PTR_FnPtrTypeDesc asFnPtr = dac_cast<PTR_FnPtrTypeDesc>(this);
if (!fFail)
{
retVal = ClassLoader::ComputeLoaderModuleForFunctionPointer(asFnPtr->GetRetAndArgTypesPointer(), asFnPtr->GetNumArgs()+1);
}
return retVal;
return dac_cast<PTR_FnPtrTypeDesc>(this)->GetLoaderModule();
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/coreclr/vm/typedesc.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@ class FnPtrTypeDesc : public TypeDesc

public:
#ifndef DACCESS_COMPILE
FnPtrTypeDesc(BYTE callConv, DWORD numArgs, TypeHandle * retAndArgTypes)
: TypeDesc(ELEMENT_TYPE_FNPTR), m_NumArgs(numArgs), m_CallConv(callConv)
FnPtrTypeDesc(BYTE callConv, DWORD numArgs, TypeHandle * retAndArgTypes, PTR_Module pLoaderModule)
: TypeDesc(ELEMENT_TYPE_FNPTR), m_pLoaderModule(pLoaderModule), m_NumArgs(numArgs), m_CallConv(callConv)
{
LIMITED_METHOD_CONTRACT;
for (DWORD i = 0; i <= numArgs; i++)
Expand Down Expand Up @@ -469,6 +469,8 @@ class FnPtrTypeDesc : public TypeDesc
BOOL IsExternallyVisible() const;
#endif //DACCESS_COMPILE

PTR_Module GetLoaderModule() const { LIMITED_METHOD_DAC_CONTRACT; return m_pLoaderModule; }

#ifdef DACCESS_COMPILE
static ULONG32 DacSize(TADDR addr)
{
Expand All @@ -481,6 +483,9 @@ class FnPtrTypeDesc : public TypeDesc
#endif //DACCESS_COMPILE

protected:
// LoaderModule of the TypeDesc
PTR_Module m_pLoaderModule;

// Number of arguments
DWORD m_NumArgs;

Expand All @@ -499,6 +504,7 @@ struct cdac_data<FnPtrTypeDesc>
static constexpr size_t NumArgs = offsetof(FnPtrTypeDesc, m_NumArgs);
static constexpr size_t RetAndArgTypes = offsetof(FnPtrTypeDesc, m_RetAndArgTypes);
static constexpr size_t CallConv = offsetof(FnPtrTypeDesc, m_CallConv);
static constexpr size_t LoaderModule = offsetof(FnPtrTypeDesc, m_pLoaderModule);
};

#endif // TYPEDESC_H

0 comments on commit 34b41f8

Please sign in to comment.