Skip to content

Commit

Permalink
Delete AppDomainIterator (#78078)
Browse files Browse the repository at this point in the history
  • Loading branch information
elinor-fung committed Nov 10, 2022
1 parent 059285b commit db21365
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 404 deletions.
113 changes: 23 additions & 90 deletions src/coreclr/debug/daccess/daccess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -543,32 +543,13 @@ MetaEnum::NextDomainToken(AppDomain** appDomain,
return NextToken(token, NULL, NULL);
}

//
// Splay tokens across all app domains.
//

while (true)
// Need to fetch a token.
if ((status = NextToken(token, NULL, NULL)) != S_OK)
{
if (m_lastToken == mdTokenNil)
{
// Need to fetch a token.
if ((status = NextToken(token, NULL, NULL)) != S_OK)
{
return status;
}

m_domainIter.Init();
}

if (m_domainIter.Next())
{
break;
}

m_lastToken = mdTokenNil;
return status;
}

*appDomain = m_domainIter.GetDomain();
*appDomain = AppDomain::GetCurrentDomain();
*token = m_lastToken;

return S_OK;
Expand Down Expand Up @@ -622,33 +603,14 @@ MetaEnum::NextDomainTokenByName(_In_opt_ LPCUTF8 namespaceName,
return NextTokenByName(namespaceName, name, nameFlags, token);
}

//
// Splay tokens across all app domains.
//

while (true)
// Need to fetch a token.
if ((status = NextTokenByName(namespaceName, name, nameFlags,
token)) != S_OK)
{
if (m_lastToken == mdTokenNil)
{
// Need to fetch a token.
if ((status = NextTokenByName(namespaceName, name, nameFlags,
token)) != S_OK)
{
return status;
}

m_domainIter.Init();
}

if (m_domainIter.Next())
{
break;
}

m_lastToken = mdTokenNil;
return status;
}

*appDomain = m_domainIter.GetDomain();
*appDomain = AppDomain::GetCurrentDomain();
*token = m_lastToken;

return S_OK;
Expand Down Expand Up @@ -1366,35 +1328,16 @@ SplitName::CdNextDomainField(ClrDataAccess* dac,
0, NULL, NULL, NULL, NULL);
}

//
// Splay fields across all app domains.
//

while (true)
// Need to fetch a field.
if ((status = CdNextField(dac, handle, NULL, NULL, NULL,
0, NULL, NULL, NULL, NULL)) != S_OK)
{
if (!split->m_lastField)
{
// Need to fetch a field.
if ((status = CdNextField(dac, handle, NULL, NULL, NULL,
0, NULL, NULL, NULL, NULL)) != S_OK)
{
return status;
}

split->m_metaEnum.m_domainIter.Init();
}

if (split->m_metaEnum.m_domainIter.Next())
{
break;
}

split->m_lastField = NULL;
return status;
}

return ClrDataValue::
NewFromFieldDesc(dac,
split->m_metaEnum.m_domainIter.GetDomain(),
AppDomain::GetCurrentDomain(),
split->m_fieldEnum.IsFieldFromParentClass() ?
CLRDATA_VALUE_IS_INHERITED : 0,
split->m_lastField,
Expand Down Expand Up @@ -3730,16 +3673,9 @@ ClrDataAccess::StartEnumAppDomains(

EX_TRY
{
AppDomainIterator* iter = new (nothrow) AppDomainIterator(FALSE);
if (iter)
{
*handle = TO_CDENUM(iter);
status = S_OK;
}
else
{
status = E_OUTOFMEMORY;
}
// Only one app domain - use 1 to indicate there there is a next value
*handle = 1;
status = S_OK;
}
EX_CATCH
{
Expand All @@ -3765,12 +3701,12 @@ ClrDataAccess::EnumAppDomain(

EX_TRY
{
AppDomainIterator* iter = FROM_CDENUM(AppDomainIterator, *handle);
if (iter->Next())
if (*handle == 1)
{
*appDomain = new (nothrow)
ClrDataAppDomain(this, iter->GetDomain());
ClrDataAppDomain(this, AppDomain::GetCurrentDomain());
status = *appDomain ? S_OK : E_OUTOFMEMORY;
*handle = 0;
}
else
{
Expand Down Expand Up @@ -3800,8 +3736,7 @@ ClrDataAccess::EndEnumAppDomains(

EX_TRY
{
AppDomainIterator* iter = FROM_CDENUM(AppDomainIterator, handle);
delete iter;
// Nothing to do - we don't actually create an iterator for app domains
status = S_OK;
}
EX_CATCH
Expand Down Expand Up @@ -4462,8 +4397,7 @@ ClrDataAccess::TranslateExceptionRecordToNotification(
else
{
// Find a likely domain, because it's the shared domain.
AppDomainIterator adi(FALSE);
appDomain = adi.GetDomain();
appDomain = AppDomain::GetCurrentDomain();
}

pubMethodInst =
Expand Down Expand Up @@ -4527,8 +4461,7 @@ ClrDataAccess::TranslateExceptionRecordToNotification(
else
{
// Find a likely domain, because it's the shared domain.
AppDomainIterator adi(FALSE);
appDomain = adi.GetDomain();
appDomain = AppDomain::GetCurrentDomain();
}

pubMethodInst =
Expand Down
22 changes: 6 additions & 16 deletions src/coreclr/debug/daccess/dacdbiimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4457,23 +4457,13 @@ void DacDbiInterfaceImpl::EnumerateAppDomains(

_ASSERTE(fpCallback != NULL);

// Only include active appdomains in the enumeration.
// This includes appdomains sent before the AD load event,
// and does not include appdomains that are in shutdown after the AD exit event.
const BOOL bOnlyActive = TRUE;
AppDomainIterator iterator(bOnlyActive);
// It's critical that we don't yield appdomains after the unload event has been sent.
// See code:IDacDbiInterface#Enumeration for details.
AppDomain * pAppDomain = AppDomain::GetCurrentDomain();

while(iterator.Next())
{
// It's critical that we don't yield appdomains after the unload event has been sent.
// See code:IDacDbiInterface#Enumeration for details.
AppDomain * pAppDomain = iterator.GetDomain();

VMPTR_AppDomain vmAppDomain = VMPTR_AppDomain::NullPtr();
vmAppDomain.SetHostPtr(pAppDomain);

fpCallback(vmAppDomain, pUserData);
}
VMPTR_AppDomain vmAppDomain = VMPTR_AppDomain::NullPtr();
vmAppDomain.SetHostPtr(pAppDomain);
fpCallback(vmAppDomain, pUserData);
}

// Enumerate all Assemblies in an appdomain.
Expand Down
45 changes: 15 additions & 30 deletions src/coreclr/debug/daccess/dacimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,6 @@ class MetaEnum
{
public:
MetaEnum(void)
: m_domainIter(FALSE)
{
Clear();
m_appDomain = NULL;
Expand Down Expand Up @@ -355,7 +354,6 @@ class MetaEnum
ULONG32 m_kind;
HENUMInternal m_enum;
AppDomain* m_appDomain;
AppDomainIterator m_domainIter;
mdToken m_lastToken;

static HRESULT New(Module* mod,
Expand Down Expand Up @@ -502,13 +500,11 @@ class SplitName

struct ProcessModIter
{
AppDomainIterator m_domainIter;
bool m_nextDomain;
AppDomain::AssemblyIterator m_assemIter;
Assembly* m_curAssem;

ProcessModIter(void)
: m_domainIter(FALSE)
{
SUPPORTS_DAC;
m_nextDomain = true;
Expand All @@ -518,33 +514,24 @@ struct ProcessModIter
Assembly * NextAssem()
{
SUPPORTS_DAC;
for (;;)
{
if (m_nextDomain)
{
if (!m_domainIter.Next())
{
break;
}

m_nextDomain = false;

m_assemIter = m_domainIter.GetDomain()->IterateAssembliesEx((AssemblyIterationFlags)(
kIncludeLoaded | kIncludeExecution));
}
if (m_nextDomain)
{
m_nextDomain = false;

CollectibleAssemblyHolder<DomainAssembly *> pDomainAssembly;
if (!m_assemIter.Next(pDomainAssembly.This()))
{
m_nextDomain = true;
continue;
}
m_assemIter = AppDomain::GetCurrentDomain()->IterateAssembliesEx((AssemblyIterationFlags)(
kIncludeLoaded | kIncludeExecution));
}

// Note: DAC doesn't need to keep the assembly alive - see code:CollectibleAssemblyHolder#CAH_DAC
CollectibleAssemblyHolder<Assembly *> pAssembly = pDomainAssembly->GetAssembly();
return pAssembly;
CollectibleAssemblyHolder<DomainAssembly *> pDomainAssembly;
if (!m_assemIter.Next(pDomainAssembly.This()))
{
return NULL;
}
return NULL;

// Note: DAC doesn't need to keep the assembly alive - see code:CollectibleAssemblyHolder#CAH_DAC
CollectibleAssemblyHolder<Assembly *> pAssembly = pDomainAssembly->GetAssembly();
return pAssembly;
}

Module* NextModule(void)
Expand Down Expand Up @@ -3948,9 +3935,7 @@ class EnumMethodInstances
static HRESULT CdEnd(CLRDATA_ENUM handle);

MethodDesc* m_methodDesc;
AppDomain* m_givenAppDomain;
bool m_givenAppDomainUsed;
AppDomainIterator m_domainIter;
bool m_appDomainUsed;
AppDomain* m_appDomain;
LoadedMethodDescIterator m_methodIter;
};
Expand Down
20 changes: 10 additions & 10 deletions src/coreclr/debug/daccess/enummem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,18 +702,18 @@ HRESULT ClrDataAccess::EnumMemDumpAppDomainInfo(CLRDataEnumMemoryFlags flags)
SystemDomain::System()->GetLoaderAllocator()->EnumMemoryRegions(flags);
}

AppDomainIterator adIter(FALSE);
AppDomain* appDomain = AppDomain::GetCurrentDomain();
if (appDomain == NULL)
return S_OK;

EX_TRY
{
while (adIter.Next())
{
CATCH_ALL_EXCEPT_RETHROW_COR_E_OPERATIONCANCELLED
(
// Note that the flags being CLRDATA_ENUM_MEM_MINI prevents
// you from pulling entire files loaded into memory into the dump.
adIter.GetDomain()->EnumMemoryRegions(flags, true);
);
}
CATCH_ALL_EXCEPT_RETHROW_COR_E_OPERATIONCANCELLED
(
// Note that the flags being CLRDATA_ENUM_MEM_MINI prevents
// you from pulling entire files loaded into memory into the dump.
appDomain->EnumMemoryRegions(flags, true);
);
}
EX_CATCH_RETHROW_ONLY_COR_E_OPERATIONCANCELLED

Expand Down
12 changes: 6 additions & 6 deletions src/coreclr/debug/daccess/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2214,13 +2214,14 @@ HRESULT ClrDataAccess::GetAppDomainList(unsigned int count, CLRDATA_ADDRESS valu
{
SOSDacEnter();

AppDomainIterator ai(FALSE);
AppDomain* appDomain = AppDomain::GetCurrentDomain();
unsigned int i = 0;
while (ai.Next() && (i < count))
if (appDomain != NULL && i < count)
{
if (values)
values[i] = HOST_CDADDR(ai.GetDomain());
i++;
values[0] = HOST_CDADDR(appDomain);

i = 1;
}

if (fetched)
Expand All @@ -2240,8 +2241,7 @@ ClrDataAccess::GetAppDomainStoreData(struct DacpAppDomainStoreData *adsData)

// Get an accurate count of appdomains.
adsData->DomainCount = 0;
AppDomainIterator ai(FALSE);
while (ai.Next())
if (AppDomain::GetCurrentDomain() != NULL)
adsData->DomainCount++;

SOSDacLeave();
Expand Down
Loading

0 comments on commit db21365

Please sign in to comment.