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

More cleanups in assembly loader area #63157

Merged
merged 25 commits into from
Jan 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
144 changes: 66 additions & 78 deletions src/coreclr/debug/daccess/dacdbiimpl.cpp

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions src/coreclr/debug/daccess/dacdbiimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,15 @@ class DacDbiInterfaceImpl :
IStringHolder * pStrName);

// Get the values of the JIT Optimization and EnC flags.
void GetCompilerFlags (VMPTR_DomainFile vmDomainFile,
void GetCompilerFlags (VMPTR_DomainAssembly vmDomainAssembly,
BOOL * pfAllowJITOpts,
BOOL * pfEnableEnC);

// Helper function for SetCompilerFlags to set EnC status
bool CanSetEnCBits(Module * pModule);

// Set the values of the JIT optimization and EnC flags.
HRESULT SetCompilerFlags(VMPTR_DomainFile vmDomainFile,
HRESULT SetCompilerFlags(VMPTR_DomainAssembly vmDomainAssembly,
BOOL fAllowJitOpts,
BOOL fEnableEnC);

Expand Down Expand Up @@ -133,7 +133,7 @@ class DacDbiInterfaceImpl :

bool IsValidObject(CORDB_ADDRESS obj);

bool GetAppDomainForObject(CORDB_ADDRESS obj, OUT VMPTR_AppDomain * pApp, OUT VMPTR_Module *pModule, OUT VMPTR_DomainFile *mod);
bool GetAppDomainForObject(CORDB_ADDRESS obj, OUT VMPTR_AppDomain * pApp, OUT VMPTR_Module *pModule, OUT VMPTR_DomainAssembly *mod);



Expand Down Expand Up @@ -218,7 +218,7 @@ class DacDbiInterfaceImpl :
// a module and a token. The info will come from a MethodDesc, if
// one exists or from metadata.
//
void GetILCodeAndSig(VMPTR_DomainFile vmDomainFile,
void GetILCodeAndSig(VMPTR_DomainAssembly vmDomainAssembly,
mdToken functionToken,
TargetBuffer * pCodeInfo,
mdToken * pLocalSigToken);
Expand All @@ -229,7 +229,7 @@ class DacDbiInterfaceImpl :
// whether it's an instantiated generic
// its EnC version number
// hot and cold region information.
void GetNativeCodeInfo(VMPTR_DomainFile vmDomainFile,
void GetNativeCodeInfo(VMPTR_DomainAssembly vmDomainAssembly,
mdToken functionToken,
NativeCodeFunctionData * pCodeInfo);

Expand Down Expand Up @@ -260,7 +260,7 @@ class DacDbiInterfaceImpl :
ClassInfo * pData);

// get field information and object size for an instantiated generic type
void GetInstantiationFieldInfo (VMPTR_DomainFile vmDomainFile,
void GetInstantiationFieldInfo (VMPTR_DomainAssembly vmDomainAssembly,
VMPTR_TypeHandle vmThExact,
VMPTR_TypeHandle vmThApprox,
DacDbiArrayList<FieldData> * pFieldList,
Expand Down Expand Up @@ -336,7 +336,7 @@ class DacDbiInterfaceImpl :
CorElementType simpleType,
mdTypeDef * pMetadataToken,
VMPTR_Module * pVmModule,
VMPTR_DomainFile * pVmDomainFile);
VMPTR_DomainAssembly * pVmDomainAssembly);

BOOL IsExceptionObject(VMPTR_Object vmObject);

Expand All @@ -352,7 +352,7 @@ class DacDbiInterfaceImpl :
HRESULT GetDelegateFunctionData(
DelegateType delegateType,
VMPTR_Object delegateObject,
OUT VMPTR_DomainFile *ppFunctionDomainFile,
OUT VMPTR_DomainAssembly *ppFunctionDomainAssembly,
OUT mdMethodDef *pMethodDef);

HRESULT GetDelegateTargetObject(
Expand Down Expand Up @@ -730,10 +730,10 @@ class DacDbiInterfaceImpl :
// Gets properties for a module
void GetModuleData(VMPTR_Module vmModule, ModuleInfo * pData);

// Gets properties for a domainfile
void GetDomainFileData(VMPTR_DomainFile vmDomainFile, DomainFileInfo * pData);
// Gets properties for a domain assembly
void GetDomainAssemblyData(VMPTR_DomainAssembly vmDomainAssembly, DomainAssemblyInfo * pData);

void GetModuleForDomainFile(VMPTR_DomainFile vmDomainFile, OUT VMPTR_Module * pModule);
void GetModuleForDomainAssembly(VMPTR_DomainAssembly vmDomainAssembly, OUT VMPTR_Module * pModule);

// Yields true if the address is a CLR stub.
BOOL IsTransitionStub(CORDB_ADDRESS address);
Expand Down Expand Up @@ -829,8 +829,8 @@ class DacDbiInterfaceImpl :
// Return the current appdomain the specified thread is in.
VMPTR_AppDomain GetCurrentAppDomain(VMPTR_Thread vmThread);

// Given an assembly ref token and metadata scope (via the DomainFile), resolve the assembly.
VMPTR_DomainAssembly ResolveAssembly(VMPTR_DomainFile vmScope, mdToken tkAssemblyRef);
// Given an assembly ref token and metadata scope (via the DomainAssembly), resolve the assembly.
VMPTR_DomainAssembly ResolveAssembly(VMPTR_DomainAssembly vmScope, mdToken tkAssemblyRef);


// Hijack the thread
Expand Down
16 changes: 8 additions & 8 deletions src/coreclr/debug/daccess/dacdbiimplstackwalk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,22 +514,22 @@ void DacDbiInterfaceImpl::EnumerateInternalFrames(VMPTR_Thread
#endif // FEATURE_COMINTEROP

Module * pModule = (pMD ? pMD->GetModule() : NULL);
DomainFile * pDomainFile = (pModule ? pModule->GetDomainFile() : NULL);
DomainAssembly * pDomainAssembly = (pModule ? pModule->GetDomainAssembly() : NULL);

if (frameData.stubFrame.frameType == STUBFRAME_FUNC_EVAL)
{
FuncEvalFrame * pFEF = dac_cast<PTR_FuncEvalFrame>(pFrame);
DebuggerEval * pDE = pFEF->GetDebuggerEval();

frameData.stubFrame.funcMetadataToken = pDE->m_methodToken;
frameData.stubFrame.vmDomainFile.SetHostPtr(
pDE->m_debuggerModule ? pDE->m_debuggerModule->GetDomainFile() : NULL);
frameData.stubFrame.vmDomainAssembly.SetHostPtr(
pDE->m_debuggerModule ? pDE->m_debuggerModule->GetDomainAssembly() : NULL);
frameData.stubFrame.vmMethodDesc = VMPTR_MethodDesc::NullPtr();
}
else
{
frameData.stubFrame.funcMetadataToken = (pMD == NULL ? NULL : pMD->GetMemberDef());
frameData.stubFrame.vmDomainFile.SetHostPtr(pDomainFile);
frameData.stubFrame.vmDomainAssembly.SetHostPtr(pDomainAssembly);
frameData.stubFrame.vmMethodDesc.SetHostPtr(pMD);
}

Expand Down Expand Up @@ -702,11 +702,11 @@ void DacDbiInterfaceImpl::InitFrameData(StackFrameIterator * pIter,
// Although MiniDumpNormal tries to dump all AppDomains, it's possible
// target corruption will keep one from being present. This should mean
// we'll just fail later, but struggle on for now.
DomainFile *pDomainFile = NULL;
DomainAssembly *pDomainAssembly = NULL;
EX_TRY_ALLOW_DATATARGET_MISSING_MEMORY
{
pDomainFile = (pModule ? pModule->GetDomainFile() : NULL);
_ASSERTE(pDomainFile != NULL);
pDomainAssembly = (pModule ? pModule->GetDomainAssembly() : NULL);
_ASSERTE(pDomainAssembly != NULL);
}
EX_END_CATCH_ALLOW_DATATARGET_MISSING_MEMORY

Expand Down Expand Up @@ -783,7 +783,7 @@ void DacDbiInterfaceImpl::InitFrameData(StackFrameIterator * pIter,
//

pFuncData->funcMetadataToken = pMD->GetMemberDef();
pFuncData->vmDomainFile.SetHostPtr(pDomainFile);
pFuncData->vmDomainAssembly.SetHostPtr(pDomainAssembly);

// PERF: this is expensive to get so I stopped fetching it eagerly
// It is only needed if we haven't already got a cached copy
Expand Down
27 changes: 6 additions & 21 deletions src/coreclr/debug/daccess/dacimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,6 @@ struct ProcessModIter
bool m_nextDomain;
AppDomain::AssemblyIterator m_assemIter;
Assembly* m_curAssem;
Assembly::ModuleIterator m_modIter;

ProcessModIter(void)
: m_domainIter(FALSE)
Expand Down Expand Up @@ -545,7 +544,7 @@ struct ProcessModIter
}

// Note: DAC doesn't need to keep the assembly alive - see code:CollectibleAssemblyHolder#CAH_DAC
CollectibleAssemblyHolder<Assembly *> pAssembly = pDomainAssembly->GetLoadedAssembly();
CollectibleAssemblyHolder<Assembly *> pAssembly = pDomainAssembly->GetAssembly();
return pAssembly;
}
return NULL;
Expand All @@ -554,27 +553,13 @@ struct ProcessModIter
Module* NextModule(void)
{
SUPPORTS_DAC;
for (;;)
m_curAssem = NextAssem();
elinor-fung marked this conversation as resolved.
Show resolved Hide resolved
if (!m_curAssem)
{
if (!m_curAssem)
{
m_curAssem = NextAssem();
if (!m_curAssem)
{
return NULL;
}

m_modIter = m_curAssem->IterateModules();
}

if (!m_modIter.Next())
{
m_curAssem = NULL;
continue;
}

return m_modIter.GetModule();
return NULL;
}

return m_curAssem->GetModule();
}
};

Expand Down
30 changes: 10 additions & 20 deletions src/coreclr/debug/daccess/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2607,10 +2607,7 @@ ClrDataAccess::GetAssemblyData(CLRDATA_ADDRESS cdBaseDomainPtr, CLRDATA_ADDRESS
assemblyData->ModuleCount = 0;
assemblyData->isDomainNeutral = FALSE;

pAssembly->GetManifestFile();

ModuleIterator mi = pAssembly->IterateModules();
while (mi.Next())
if (pAssembly->GetModule())
{
assemblyData->ModuleCount++;
}
Expand All @@ -2628,17 +2625,17 @@ ClrDataAccess::GetAssemblyName(CLRDATA_ADDRESS assembly, unsigned int count, _In
if (name)
name[0] = 0;

if (!pAssembly->GetManifestFile()->GetPath().IsEmpty())
if (!pAssembly->GetPEAssembly()->GetPath().IsEmpty())
{
if (!pAssembly->GetManifestFile()->GetPath().DacGetUnicode(count, name, pNeeded))
if (!pAssembly->GetPEAssembly()->GetPath().DacGetUnicode(count, name, pNeeded))
hr = E_FAIL;
else if (name)
name[count-1] = 0;
}
else if (!pAssembly->GetManifestFile()->IsDynamic())
else if (!pAssembly->GetPEAssembly()->IsDynamic())
{
StackSString displayName;
pAssembly->GetManifestFile()->GetDisplayName(displayName, 0);
pAssembly->GetPEAssembly()->GetDisplayName(displayName, 0);

const WCHAR *val = displayName.GetUnicode();

Expand Down Expand Up @@ -2673,9 +2670,9 @@ ClrDataAccess::GetAssemblyLocation(CLRDATA_ADDRESS assembly, int count, _Inout_u
Assembly* pAssembly = PTR_Assembly(TO_TADDR(assembly));

// Turn from bytes to wide characters
if (!pAssembly->GetManifestFile()->GetPath().IsEmpty())
if (!pAssembly->GetPEAssembly()->GetPath().IsEmpty())
{
if (!pAssembly->GetManifestFile()->GetPath().
if (!pAssembly->GetPEAssembly()->GetPath().
DacGetUnicode(count, location, pNeeded))
{
hr = E_FAIL;
Expand Down Expand Up @@ -2703,21 +2700,14 @@ ClrDataAccess::GetAssemblyModuleList(CLRDATA_ADDRESS assembly, unsigned int coun
SOSDacEnter();

Assembly* pAssembly = PTR_Assembly(TO_TADDR(assembly));
ModuleIterator mi = pAssembly->IterateModules();
unsigned int n = 0;
if (modules)
{
while (mi.Next() && n < count)
modules[n++] = HOST_CDADDR(mi.GetModule());
}
else
{
while (mi.Next())
n++;
if (pAssembly->GetModule() && count > 0)
modules[0] = HOST_CDADDR(pAssembly->GetModule());
}

if (pNeeded)
*pNeeded = n;
*pNeeded = 1;

SOSDacLeave();
return hr;
Expand Down
24 changes: 14 additions & 10 deletions src/coreclr/debug/daccess/task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -948,6 +948,11 @@ ClrDataAssembly::Release(THIS)
return newRefs;
}

struct TrivialModuleIterator
{
Module* m_module;
};

HRESULT STDMETHODCALLTYPE
ClrDataAssembly::StartEnumModules(
/* [out] */ CLRDATA_ENUM* handle)
Expand All @@ -958,11 +963,10 @@ ClrDataAssembly::StartEnumModules(

EX_TRY
{
Assembly::ModuleIterator* iter = new (nothrow)
Assembly::ModuleIterator;
TrivialModuleIterator* iter = new (nothrow) TrivialModuleIterator;
if (iter)
{
*iter = m_assembly->IterateModules();
iter->m_module = m_assembly->GetModule();
*handle = TO_CDENUM(iter);
status = S_OK;
}
Expand Down Expand Up @@ -995,12 +999,13 @@ ClrDataAssembly::EnumModule(

EX_TRY
{
Assembly::ModuleIterator* iter =
FROM_CDENUM(Assembly::ModuleIterator, *handle);
if (iter->Next())
TrivialModuleIterator* iter = FROM_CDENUM(TrivialModuleIterator, *handle);
if (iter->m_module)
{
*mod = new (nothrow)
ClrDataModule(m_dac, iter->GetModule());
ClrDataModule(m_dac, iter->m_module);

iter->m_module = NULL;
status = *mod ? S_OK : E_OUTOFMEMORY;
}
else
Expand Down Expand Up @@ -1031,8 +1036,7 @@ ClrDataAssembly::EndEnumModules(

EX_TRY
{
Assembly::ModuleIterator* iter =
FROM_CDENUM(Assembly::ModuleIterator, handle);
TrivialModuleIterator* iter = FROM_CDENUM(TrivialModuleIterator, handle);
delete iter;
status = S_OK;
}
Expand Down Expand Up @@ -1170,7 +1174,7 @@ ClrDataAssembly::GetFileName(
{
COUNT_T _nameLen;

if (m_assembly->GetManifestFile()->GetPath().
if (m_assembly->GetPEAssembly()->GetPath().
DacGetUnicode(bufLen, name, &_nameLen))
{
if (nameLen)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/debug/di/breakpoint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ HRESULT CordbFunctionBreakpoint::Activate(BOOL fActivate)
pProcess->InitIPCEvent(pEvent, DB_IPCE_BREAKPOINT_ADD, true, pAppDomain->GetADToken());

pEvent->BreakpointData.funcMetadataToken = m_code->GetMetadataToken();
pEvent->BreakpointData.vmDomainFile = m_code->GetModule()->GetRuntimeDomainFile();
pEvent->BreakpointData.vmDomainAssembly = m_code->GetModule()->GetRuntimeDomainAssembly();
pEvent->BreakpointData.encVersion = m_code->GetVersion();

BOOL codeIsIL = m_code->IsIL();
Expand Down
10 changes: 5 additions & 5 deletions src/coreclr/debug/di/divalue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2464,7 +2464,7 @@ HRESULT CordbObjectValue::EnumerateExceptionCallStack(ICorDebugExceptionObjectCa
CorDebugExceptionObjectStackFrame& currentStackFrame = pStackFrames[index];

CordbAppDomain* pAppDomain = GetProcess()->LookupOrCreateAppDomain(currentDacFrame.vmAppDomain);
CordbModule* pModule = pAppDomain->LookupOrCreateModule(currentDacFrame.vmDomainFile);
CordbModule* pModule = pAppDomain->LookupOrCreateModule(currentDacFrame.vmDomainAssembly);

hr = pModule->QueryInterface(IID_ICorDebugModule, reinterpret_cast<void**>(&currentStackFrame.pModule));
_ASSERTE(SUCCEEDED(hr));
Expand Down Expand Up @@ -2653,18 +2653,18 @@ HRESULT CordbObjectValue::GetFunctionHelper(ICorDebugFunction **ppFunction)
return hr;

mdMethodDef functionMethodDef = 0;
VMPTR_DomainFile functionDomainFile;
VMPTR_DomainAssembly functionDomainAssembly;
NativeCodeFunctionData nativeCodeForDelFunc;

hr = pDAC->GetDelegateFunctionData(delType, pDelegateObj, &functionDomainFile, &functionMethodDef);
hr = pDAC->GetDelegateFunctionData(delType, pDelegateObj, &functionDomainAssembly, &functionMethodDef);
if (hr != S_OK)
return hr;

// TODO: How to ensure results are sanitized?
// Also, this is expensive. Do we really care that much about this?
pDAC->GetNativeCodeInfo(functionDomainFile, functionMethodDef, &nativeCodeForDelFunc);
pDAC->GetNativeCodeInfo(functionDomainAssembly, functionMethodDef, &nativeCodeForDelFunc);

RSSmartPtr<CordbModule> funcModule(GetProcess()->LookupOrCreateModule(functionDomainFile));
RSSmartPtr<CordbModule> funcModule(GetProcess()->LookupOrCreateModule(functionDomainAssembly));
RSSmartPtr<CordbFunction> func;
{
RSLockHolder lockHolder(GetProcess()->GetProcessLock());
Expand Down
Loading