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

Make acquiring the loader module for a FnPtrTypeDesc a simple operation instead of a complex algorithm #106299

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions src/coreclr/debug/runtimeinfo/datadescriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,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
Loading