Skip to content

Commit db21365

Browse files
authored
Delete AppDomainIterator (#78078)
1 parent 059285b commit db21365

File tree

13 files changed

+89
-404
lines changed

13 files changed

+89
-404
lines changed

src/coreclr/debug/daccess/daccess.cpp

Lines changed: 23 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -543,32 +543,13 @@ MetaEnum::NextDomainToken(AppDomain** appDomain,
543543
return NextToken(token, NULL, NULL);
544544
}
545545

546-
//
547-
// Splay tokens across all app domains.
548-
//
549-
550-
while (true)
546+
// Need to fetch a token.
547+
if ((status = NextToken(token, NULL, NULL)) != S_OK)
551548
{
552-
if (m_lastToken == mdTokenNil)
553-
{
554-
// Need to fetch a token.
555-
if ((status = NextToken(token, NULL, NULL)) != S_OK)
556-
{
557-
return status;
558-
}
559-
560-
m_domainIter.Init();
561-
}
562-
563-
if (m_domainIter.Next())
564-
{
565-
break;
566-
}
567-
568-
m_lastToken = mdTokenNil;
549+
return status;
569550
}
570551

571-
*appDomain = m_domainIter.GetDomain();
552+
*appDomain = AppDomain::GetCurrentDomain();
572553
*token = m_lastToken;
573554

574555
return S_OK;
@@ -622,33 +603,14 @@ MetaEnum::NextDomainTokenByName(_In_opt_ LPCUTF8 namespaceName,
622603
return NextTokenByName(namespaceName, name, nameFlags, token);
623604
}
624605

625-
//
626-
// Splay tokens across all app domains.
627-
//
628-
629-
while (true)
606+
// Need to fetch a token.
607+
if ((status = NextTokenByName(namespaceName, name, nameFlags,
608+
token)) != S_OK)
630609
{
631-
if (m_lastToken == mdTokenNil)
632-
{
633-
// Need to fetch a token.
634-
if ((status = NextTokenByName(namespaceName, name, nameFlags,
635-
token)) != S_OK)
636-
{
637-
return status;
638-
}
639-
640-
m_domainIter.Init();
641-
}
642-
643-
if (m_domainIter.Next())
644-
{
645-
break;
646-
}
647-
648-
m_lastToken = mdTokenNil;
610+
return status;
649611
}
650612

651-
*appDomain = m_domainIter.GetDomain();
613+
*appDomain = AppDomain::GetCurrentDomain();
652614
*token = m_lastToken;
653615

654616
return S_OK;
@@ -1366,35 +1328,16 @@ SplitName::CdNextDomainField(ClrDataAccess* dac,
13661328
0, NULL, NULL, NULL, NULL);
13671329
}
13681330

1369-
//
1370-
// Splay fields across all app domains.
1371-
//
1372-
1373-
while (true)
1331+
// Need to fetch a field.
1332+
if ((status = CdNextField(dac, handle, NULL, NULL, NULL,
1333+
0, NULL, NULL, NULL, NULL)) != S_OK)
13741334
{
1375-
if (!split->m_lastField)
1376-
{
1377-
// Need to fetch a field.
1378-
if ((status = CdNextField(dac, handle, NULL, NULL, NULL,
1379-
0, NULL, NULL, NULL, NULL)) != S_OK)
1380-
{
1381-
return status;
1382-
}
1383-
1384-
split->m_metaEnum.m_domainIter.Init();
1385-
}
1386-
1387-
if (split->m_metaEnum.m_domainIter.Next())
1388-
{
1389-
break;
1390-
}
1391-
1392-
split->m_lastField = NULL;
1335+
return status;
13931336
}
13941337

13951338
return ClrDataValue::
13961339
NewFromFieldDesc(dac,
1397-
split->m_metaEnum.m_domainIter.GetDomain(),
1340+
AppDomain::GetCurrentDomain(),
13981341
split->m_fieldEnum.IsFieldFromParentClass() ?
13991342
CLRDATA_VALUE_IS_INHERITED : 0,
14001343
split->m_lastField,
@@ -3730,16 +3673,9 @@ ClrDataAccess::StartEnumAppDomains(
37303673

37313674
EX_TRY
37323675
{
3733-
AppDomainIterator* iter = new (nothrow) AppDomainIterator(FALSE);
3734-
if (iter)
3735-
{
3736-
*handle = TO_CDENUM(iter);
3737-
status = S_OK;
3738-
}
3739-
else
3740-
{
3741-
status = E_OUTOFMEMORY;
3742-
}
3676+
// Only one app domain - use 1 to indicate there there is a next value
3677+
*handle = 1;
3678+
status = S_OK;
37433679
}
37443680
EX_CATCH
37453681
{
@@ -3765,12 +3701,12 @@ ClrDataAccess::EnumAppDomain(
37653701

37663702
EX_TRY
37673703
{
3768-
AppDomainIterator* iter = FROM_CDENUM(AppDomainIterator, *handle);
3769-
if (iter->Next())
3704+
if (*handle == 1)
37703705
{
37713706
*appDomain = new (nothrow)
3772-
ClrDataAppDomain(this, iter->GetDomain());
3707+
ClrDataAppDomain(this, AppDomain::GetCurrentDomain());
37733708
status = *appDomain ? S_OK : E_OUTOFMEMORY;
3709+
*handle = 0;
37743710
}
37753711
else
37763712
{
@@ -3800,8 +3736,7 @@ ClrDataAccess::EndEnumAppDomains(
38003736

38013737
EX_TRY
38023738
{
3803-
AppDomainIterator* iter = FROM_CDENUM(AppDomainIterator, handle);
3804-
delete iter;
3739+
// Nothing to do - we don't actually create an iterator for app domains
38053740
status = S_OK;
38063741
}
38073742
EX_CATCH
@@ -4462,8 +4397,7 @@ ClrDataAccess::TranslateExceptionRecordToNotification(
44624397
else
44634398
{
44644399
// Find a likely domain, because it's the shared domain.
4465-
AppDomainIterator adi(FALSE);
4466-
appDomain = adi.GetDomain();
4400+
appDomain = AppDomain::GetCurrentDomain();
44674401
}
44684402

44694403
pubMethodInst =
@@ -4527,8 +4461,7 @@ ClrDataAccess::TranslateExceptionRecordToNotification(
45274461
else
45284462
{
45294463
// Find a likely domain, because it's the shared domain.
4530-
AppDomainIterator adi(FALSE);
4531-
appDomain = adi.GetDomain();
4464+
appDomain = AppDomain::GetCurrentDomain();
45324465
}
45334466

45344467
pubMethodInst =

src/coreclr/debug/daccess/dacdbiimpl.cpp

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4457,23 +4457,13 @@ void DacDbiInterfaceImpl::EnumerateAppDomains(
44574457

44584458
_ASSERTE(fpCallback != NULL);
44594459

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

4466-
while(iterator.Next())
4467-
{
4468-
// It's critical that we don't yield appdomains after the unload event has been sent.
4469-
// See code:IDacDbiInterface#Enumeration for details.
4470-
AppDomain * pAppDomain = iterator.GetDomain();
4471-
4472-
VMPTR_AppDomain vmAppDomain = VMPTR_AppDomain::NullPtr();
4473-
vmAppDomain.SetHostPtr(pAppDomain);
4474-
4475-
fpCallback(vmAppDomain, pUserData);
4476-
}
4464+
VMPTR_AppDomain vmAppDomain = VMPTR_AppDomain::NullPtr();
4465+
vmAppDomain.SetHostPtr(pAppDomain);
4466+
fpCallback(vmAppDomain, pUserData);
44774467
}
44784468

44794469
// Enumerate all Assemblies in an appdomain.

src/coreclr/debug/daccess/dacimpl.h

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,6 @@ class MetaEnum
279279
{
280280
public:
281281
MetaEnum(void)
282-
: m_domainIter(FALSE)
283282
{
284283
Clear();
285284
m_appDomain = NULL;
@@ -355,7 +354,6 @@ class MetaEnum
355354
ULONG32 m_kind;
356355
HENUMInternal m_enum;
357356
AppDomain* m_appDomain;
358-
AppDomainIterator m_domainIter;
359357
mdToken m_lastToken;
360358

361359
static HRESULT New(Module* mod,
@@ -502,13 +500,11 @@ class SplitName
502500

503501
struct ProcessModIter
504502
{
505-
AppDomainIterator m_domainIter;
506503
bool m_nextDomain;
507504
AppDomain::AssemblyIterator m_assemIter;
508505
Assembly* m_curAssem;
509506

510507
ProcessModIter(void)
511-
: m_domainIter(FALSE)
512508
{
513509
SUPPORTS_DAC;
514510
m_nextDomain = true;
@@ -518,33 +514,24 @@ struct ProcessModIter
518514
Assembly * NextAssem()
519515
{
520516
SUPPORTS_DAC;
521-
for (;;)
522-
{
523-
if (m_nextDomain)
524-
{
525-
if (!m_domainIter.Next())
526-
{
527-
break;
528-
}
529-
530-
m_nextDomain = false;
531517

532-
m_assemIter = m_domainIter.GetDomain()->IterateAssembliesEx((AssemblyIterationFlags)(
533-
kIncludeLoaded | kIncludeExecution));
534-
}
518+
if (m_nextDomain)
519+
{
520+
m_nextDomain = false;
535521

536-
CollectibleAssemblyHolder<DomainAssembly *> pDomainAssembly;
537-
if (!m_assemIter.Next(pDomainAssembly.This()))
538-
{
539-
m_nextDomain = true;
540-
continue;
541-
}
522+
m_assemIter = AppDomain::GetCurrentDomain()->IterateAssembliesEx((AssemblyIterationFlags)(
523+
kIncludeLoaded | kIncludeExecution));
524+
}
542525

543-
// Note: DAC doesn't need to keep the assembly alive - see code:CollectibleAssemblyHolder#CAH_DAC
544-
CollectibleAssemblyHolder<Assembly *> pAssembly = pDomainAssembly->GetAssembly();
545-
return pAssembly;
526+
CollectibleAssemblyHolder<DomainAssembly *> pDomainAssembly;
527+
if (!m_assemIter.Next(pDomainAssembly.This()))
528+
{
529+
return NULL;
546530
}
547-
return NULL;
531+
532+
// Note: DAC doesn't need to keep the assembly alive - see code:CollectibleAssemblyHolder#CAH_DAC
533+
CollectibleAssemblyHolder<Assembly *> pAssembly = pDomainAssembly->GetAssembly();
534+
return pAssembly;
548535
}
549536

550537
Module* NextModule(void)
@@ -3948,9 +3935,7 @@ class EnumMethodInstances
39483935
static HRESULT CdEnd(CLRDATA_ENUM handle);
39493936

39503937
MethodDesc* m_methodDesc;
3951-
AppDomain* m_givenAppDomain;
3952-
bool m_givenAppDomainUsed;
3953-
AppDomainIterator m_domainIter;
3938+
bool m_appDomainUsed;
39543939
AppDomain* m_appDomain;
39553940
LoadedMethodDescIterator m_methodIter;
39563941
};

src/coreclr/debug/daccess/enummem.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -702,18 +702,18 @@ HRESULT ClrDataAccess::EnumMemDumpAppDomainInfo(CLRDataEnumMemoryFlags flags)
702702
SystemDomain::System()->GetLoaderAllocator()->EnumMemoryRegions(flags);
703703
}
704704

705-
AppDomainIterator adIter(FALSE);
705+
AppDomain* appDomain = AppDomain::GetCurrentDomain();
706+
if (appDomain == NULL)
707+
return S_OK;
708+
706709
EX_TRY
707710
{
708-
while (adIter.Next())
709-
{
710-
CATCH_ALL_EXCEPT_RETHROW_COR_E_OPERATIONCANCELLED
711-
(
712-
// Note that the flags being CLRDATA_ENUM_MEM_MINI prevents
713-
// you from pulling entire files loaded into memory into the dump.
714-
adIter.GetDomain()->EnumMemoryRegions(flags, true);
715-
);
716-
}
711+
CATCH_ALL_EXCEPT_RETHROW_COR_E_OPERATIONCANCELLED
712+
(
713+
// Note that the flags being CLRDATA_ENUM_MEM_MINI prevents
714+
// you from pulling entire files loaded into memory into the dump.
715+
appDomain->EnumMemoryRegions(flags, true);
716+
);
717717
}
718718
EX_CATCH_RETHROW_ONLY_COR_E_OPERATIONCANCELLED
719719

src/coreclr/debug/daccess/request.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2214,13 +2214,14 @@ HRESULT ClrDataAccess::GetAppDomainList(unsigned int count, CLRDATA_ADDRESS valu
22142214
{
22152215
SOSDacEnter();
22162216

2217-
AppDomainIterator ai(FALSE);
2217+
AppDomain* appDomain = AppDomain::GetCurrentDomain();
22182218
unsigned int i = 0;
2219-
while (ai.Next() && (i < count))
2219+
if (appDomain != NULL && i < count)
22202220
{
22212221
if (values)
2222-
values[i] = HOST_CDADDR(ai.GetDomain());
2223-
i++;
2222+
values[0] = HOST_CDADDR(appDomain);
2223+
2224+
i = 1;
22242225
}
22252226

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

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

22472247
SOSDacLeave();

0 commit comments

Comments
 (0)