Skip to content

Commit 6092b21

Browse files
authored
Move pinned heap handle table from BaseDomain to AppDomain and make callers go through the AppDomain (#107420)
- Move the pinned heap handle table to `AppDomain` - This does make the current use in the `GlobalLoaderAllocator` (went through `SystemDomain`) and in EnC adding a static field (went through `AppDomain`) use the same table. They have the same lifetime. - Move `GetLoaderAllocator` (it already always returns the global one), `IsStringInterned`, `GetOrInternString` functions from `BaseDomain` to `AppDomain`
1 parent ad430a1 commit 6092b21

File tree

6 files changed

+61
-92
lines changed

6 files changed

+61
-92
lines changed

src/coreclr/debug/daccess/dacdbiimpl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3672,7 +3672,7 @@ HRESULT DacDbiInterfaceImpl::GetLoaderHeapMemoryRanges(DacDbiArrayList<COR_MEMOR
36723672
// it's own LoaderAllocator, but there's no easy way of getting a hand at them other than going through
36733673
// the heap, getting a managed LoaderAllocators, from there getting a Scout, and from there getting a native
36743674
// pointer to the LoaderAllocator tos enumerate.
3675-
PTR_LoaderAllocator pGlobalAllocator = SystemDomain::System()->GetLoaderAllocator();
3675+
PTR_LoaderAllocator pGlobalAllocator = SystemDomain::GetGlobalLoaderAllocator();
36763676
_ASSERTE(pGlobalAllocator);
36773677
EnumerateMemRangesForLoaderAllocator(pGlobalAllocator, &memoryRanges);
36783678

src/coreclr/debug/daccess/enummem.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ HRESULT ClrDataAccess::EnumMemDumpAppDomainInfo(CLRDataEnumMemoryFlags flags)
743743

744744
if (flags == CLRDATA_ENUM_MEM_HEAP2)
745745
{
746-
SystemDomain::System()->GetLoaderAllocator()->EnumMemoryRegions(flags);
746+
SystemDomain::GetGlobalLoaderAllocator()->EnumMemoryRegions(flags);
747747
}
748748

749749
AppDomain* appDomain = AppDomain::GetCurrentDomain();

src/coreclr/debug/daccess/request.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2838,7 +2838,7 @@ ClrDataAccess::GetAppDomainData(CLRDATA_ADDRESS addr, struct DacpAppDomainData *
28382838

28392839
ZeroMemory(appdomainData, sizeof(DacpAppDomainData));
28402840
appdomainData->AppDomainPtr = PTR_CDADDR(pBaseDomain);
2841-
PTR_LoaderAllocator pLoaderAllocator = pBaseDomain->GetLoaderAllocator();
2841+
PTR_LoaderAllocator pLoaderAllocator = SystemDomain::GetGlobalLoaderAllocator();
28422842
appdomainData->pHighFrequencyHeap = HOST_CDADDR(pLoaderAllocator->GetHighFrequencyHeap());
28432843
appdomainData->pLowFrequencyHeap = HOST_CDADDR(pLoaderAllocator->GetLowFrequencyHeap());
28442844
appdomainData->pStubHeap = HOST_CDADDR(pLoaderAllocator->GetStubHeap());
@@ -4065,8 +4065,7 @@ ClrDataAccess::TraverseVirtCallStubHeap(CLRDATA_ADDRESS pAppDomain, VCSHeapType
40654065

40664066
SOSDacEnter();
40674067

4068-
BaseDomain* pBaseDomain = PTR_BaseDomain(TO_TADDR(pAppDomain));
4069-
VirtualCallStubManager *pVcsMgr = pBaseDomain->GetLoaderAllocator()->GetVirtualCallStubManager();
4068+
VirtualCallStubManager *pVcsMgr = SystemDomain::GetGlobalLoaderAllocator()->GetVirtualCallStubManager();
40704069
if (!pVcsMgr)
40714070
{
40724071
hr = E_POINTER;
@@ -4111,8 +4110,8 @@ HRESULT ClrDataAccess::GetDomainLoaderAllocator(CLRDATA_ADDRESS domainAddress, C
41114110

41124111
SOSDacEnter();
41134112

4114-
PTR_BaseDomain pDomain = PTR_BaseDomain(TO_TADDR(domainAddress));
4115-
*pLoaderAllocator = pDomain != nullptr ? HOST_CDADDR(pDomain->GetLoaderAllocator()) : 0;
4113+
// The one and only app domain uses the global loader allocator
4114+
*pLoaderAllocator = HOST_CDADDR(SystemDomain::GetGlobalLoaderAllocator());
41164115

41174116
SOSDacLeave();
41184117
return hr;

src/coreclr/vm/appdomain.cpp

Lines changed: 31 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -430,27 +430,6 @@ void PinnedHeapHandleTable::EnumStaticGCRefs(promote_func* fn, ScanContext* sc)
430430
}
431431
}
432432

433-
//*****************************************************************************
434-
// BaseDomain
435-
//*****************************************************************************
436-
437-
BaseDomain::BaseDomain()
438-
{
439-
// initialize fields so the domain can be safely destructed
440-
// shouldn't call anything that can fail here - use ::Init instead
441-
CONTRACTL
442-
{
443-
THROWS;
444-
GC_TRIGGERS;
445-
MODE_ANY;
446-
FORBID_FAULT;
447-
}
448-
CONTRACTL_END;
449-
450-
// Make sure the container is set to NULL so that it gets loaded when it is used.
451-
m_pPinnedHeapHandleTable = NULL;
452-
} //BaseDomain::BaseDomain
453-
454433
#undef LOADERHEAP_PROFILE_COUNTER
455434

456435
void AppDomain::ClearBinderContext()
@@ -573,7 +552,7 @@ void AppDomain::SetNativeDllSearchDirectories(LPCWSTR wszNativeDllSearchDirector
573552
}
574553
}
575554

576-
OBJECTREF* BaseDomain::AllocateObjRefPtrsInLargeTable(int nRequested, DynamicStaticsInfo* pStaticsInfo, MethodTable *pMTToFillWithStaticBoxes, bool isClassInitdeByUpdatingStaticPointer)
555+
OBJECTREF* AppDomain::AllocateObjRefPtrsInLargeTable(int nRequested, DynamicStaticsInfo* pStaticsInfo, MethodTable *pMTToFillWithStaticBoxes, bool isClassInitdeByUpdatingStaticPointer)
577556
{
578557
CONTRACTL
579558
{
@@ -661,7 +640,7 @@ OBJECTREF AppDomain::GetMissingObject()
661640
#ifndef DACCESS_COMPILE
662641

663642

664-
STRINGREF *BaseDomain::IsStringInterned(STRINGREF *pString)
643+
STRINGREF* AppDomain::IsStringInterned(STRINGREF *pString)
665644
{
666645
CONTRACTL
667646
{
@@ -676,7 +655,7 @@ STRINGREF *BaseDomain::IsStringInterned(STRINGREF *pString)
676655
return GetLoaderAllocator()->IsStringInterned(pString);
677656
}
678657

679-
STRINGREF *BaseDomain::GetOrInternString(STRINGREF *pString)
658+
STRINGREF* AppDomain::GetOrInternString(STRINGREF *pString)
680659
{
681660
CONTRACTL
682661
{
@@ -691,7 +670,7 @@ STRINGREF *BaseDomain::GetOrInternString(STRINGREF *pString)
691670
return GetLoaderAllocator()->GetOrInternString(pString);
692671
}
693672

694-
void BaseDomain::InitPinnedHeapHandleTable()
673+
void AppDomain::InitPinnedHeapHandleTable()
695674
{
696675
CONTRACTL
697676
{
@@ -1622,6 +1601,30 @@ HRESULT SystemDomain::NotifyProfilerShutdown()
16221601
#endif // PROFILING_SUPPORTED
16231602

16241603
AppDomain::AppDomain()
1604+
: m_handleStore{NULL}
1605+
, m_pPinnedHeapHandleTable{NULL}
1606+
, m_pDefaultBinder{NULL}
1607+
, m_pRefClassFactHash{NULL}
1608+
#ifdef FEATURE_COMINTEROP
1609+
, m_pRefDispIDCache{NULL}
1610+
, m_hndMissing{NULL}
1611+
#endif //FEATURE_COMINTEROP
1612+
, m_pDelayedLoaderAllocatorUnloadList{NULL}
1613+
, m_pRootAssembly{NULL}
1614+
, m_dwFlags{0}
1615+
, m_cRef{1}
1616+
#ifdef FEATURE_COMINTEROP
1617+
, m_pRCWCache{NULL}
1618+
#endif //FEATURE_COMINTEROP
1619+
#ifdef FEATURE_COMWRAPPERS
1620+
, m_pRCWRefCache{NULL}
1621+
#endif // FEATURE_COMWRAPPERS
1622+
, m_Stage{STAGE_CREATING}
1623+
, m_MemoryPressure{0}
1624+
, m_ForceTrivialWaitOperations{false}
1625+
#ifdef FEATURE_TYPEEQUIVALENCE
1626+
, m_pTypeEquivalenceTable{NULL}
1627+
#endif // FEATURE_TYPEEQUIVALENCE
16251628
{
16261629
// initialize fields so the appdomain can be safely destructed
16271630
// shouldn't call anything that can fail here - use ::Init instead
@@ -1634,45 +1637,16 @@ AppDomain::AppDomain()
16341637
}
16351638
CONTRACTL_END;
16361639

1637-
m_cRef=1;
1638-
16391640
m_JITLock.PreInit();
16401641
m_ClassInitLock.PreInit();
16411642
m_ILStubGenLock.PreInit();
16421643
m_NativeTypeLoadLock.PreInit();
16431644
m_FileLoadLock.PreInit();
16441645

1645-
m_pDefaultBinder = NULL;
1646-
m_pRootAssembly = NULL;
1647-
1648-
m_dwFlags = 0;
1649-
#ifdef FEATURE_COMINTEROP
1650-
m_pRCWCache = NULL;
1651-
#endif //FEATURE_COMINTEROP
1652-
#ifdef FEATURE_COMWRAPPERS
1653-
m_pRCWRefCache = NULL;
1654-
#endif // FEATURE_COMWRAPPERS
1655-
1656-
m_handleStore = NULL;
1657-
16581646
#ifdef _DEBUG
16591647
m_Assemblies.Debug_SetAppDomain(this);
16601648
#endif // _DEBUG
16611649

1662-
#ifdef FEATURE_COMINTEROP
1663-
m_pRefDispIDCache = NULL;
1664-
m_hndMissing = NULL;
1665-
#endif
1666-
1667-
m_pRefClassFactHash = NULL;
1668-
1669-
m_ForceTrivialWaitOperations = false;
1670-
m_Stage=STAGE_CREATING;
1671-
1672-
#ifdef FEATURE_TYPEEQUIVALENCE
1673-
m_pTypeEquivalenceTable = NULL;
1674-
#endif // FEATURE_TYPEEQUIVALENCE
1675-
16761650
} // AppDomain::AppDomain
16771651

16781652
AppDomain::~AppDomain()
@@ -1696,13 +1670,10 @@ void AppDomain::Init()
16961670
CONTRACTL
16971671
{
16981672
STANDARD_VM_CHECK;
1673+
PRECONDITION(m_Stage == STAGE_CREATING);
16991674
}
17001675
CONTRACTL_END;
17011676

1702-
m_pDelayedLoaderAllocatorUnloadList = NULL;
1703-
1704-
SetStage( STAGE_CREATING);
1705-
17061677
//
17071678
// The JIT lock and the CCtor locks are at the same level (and marked as
17081679
// UNSAFE_SAME_LEVEL) because they are all part of the same deadlock detection mechanism. We
@@ -1729,8 +1700,6 @@ void AppDomain::Init()
17291700
// Set up the binding caches
17301701
m_AssemblyCache.Init(&m_DomainCacheCrst, GetHighFrequencyHeap());
17311702

1732-
m_MemoryPressure = 0;
1733-
17341703
m_handleStore = GCHandleUtilities::GetGCHandleManager()->GetGlobalHandleStore();
17351704
if (!m_handleStore)
17361705
{
@@ -4057,7 +4026,7 @@ void AppDomain::EnumStaticGCRefs(promote_func* fn, ScanContext* sc)
40574026
#endif // !DACCESS_COMPILE
40584027

40594028
//------------------------------------------------------------------------
4060-
PTR_LoaderAllocator BaseDomain::GetLoaderAllocator()
4029+
PTR_LoaderAllocator AppDomain::GetLoaderAllocator()
40614030
{
40624031
WRAPPER_NO_CONTRACT;
40634032
return SystemDomain::GetGlobalLoaderAllocator(); // The one and only domain is not unloadable
@@ -4536,7 +4505,7 @@ SystemDomain::EnumMemoryRegions(CLRDataEnumMemoryFlags flags, bool enumThis)
45364505

45374506
if (flags == CLRDATA_ENUM_MEM_HEAP2)
45384507
{
4539-
GetLoaderAllocator()->EnumMemoryRegions(flags);
4508+
GetGlobalLoaderAllocator()->EnumMemoryRegions(flags);
45404509
}
45414510
if (m_pSystemPEAssembly.IsValid())
45424511
{

src/coreclr/vm/appdomain.hpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -457,37 +457,18 @@ class BaseDomain
457457
//
458458
// Initialization/shutdown routines for every instance of an BaseDomain.
459459

460-
BaseDomain();
460+
BaseDomain() = default;
461461
virtual ~BaseDomain() {}
462462

463463
virtual BOOL IsAppDomain() { LIMITED_METHOD_DAC_CONTRACT; return FALSE; }
464464

465-
PTR_LoaderAllocator GetLoaderAllocator();
466465
virtual PTR_AppDomain AsAppDomain()
467466
{
468467
LIMITED_METHOD_CONTRACT;
469468
_ASSERTE(!"Not an AppDomain");
470469
return NULL;
471470
}
472471

473-
STRINGREF *IsStringInterned(STRINGREF *pString);
474-
STRINGREF *GetOrInternString(STRINGREF *pString);
475-
476-
// Returns an array of OBJECTREF* that can be used to store domain specific data.
477-
// Statics and reflection info (Types, MemberInfo,..) are stored this way
478-
// If pStaticsInfo != 0, allocation will only take place if GC statics in the DynamicStaticsInfo are NULL (and the allocation
479-
// will be properly serialized)
480-
OBJECTREF *AllocateObjRefPtrsInLargeTable(int nRequested, DynamicStaticsInfo* pStaticsInfo = NULL, MethodTable *pMTToFillWithStaticBoxes = NULL, bool isClassInitdeByUpdatingStaticPointer = false);
481-
482-
protected:
483-
484-
//****************************************************************************************
485-
// Helper method to initialize the large heap handle table.
486-
void InitPinnedHeapHandleTable();
487-
488-
// The pinned heap handle table.
489-
PinnedHeapHandleTable *m_pPinnedHeapHandleTable;
490-
491472
#ifdef DACCESS_COMPILE
492473
public:
493474
virtual void EnumMemoryRegions(CLRDataEnumMemoryFlags flags, bool enumThis) = 0;
@@ -752,6 +733,11 @@ class AppDomain : public BaseDomain
752733
virtual BOOL IsAppDomain() { LIMITED_METHOD_DAC_CONTRACT; return TRUE; }
753734
virtual PTR_AppDomain AsAppDomain() { LIMITED_METHOD_CONTRACT; return dac_cast<PTR_AppDomain>(this); }
754735

736+
PTR_LoaderAllocator GetLoaderAllocator();
737+
738+
STRINGREF *IsStringInterned(STRINGREF *pString);
739+
STRINGREF *GetOrInternString(STRINGREF *pString);
740+
755741
OBJECTREF GetRawExposedObject() { LIMITED_METHOD_CONTRACT; return NULL; }
756742
OBJECTHANDLE GetRawExposedObjectHandleForDebugger() { LIMITED_METHOD_DAC_CONTRACT; return (OBJECTHANDLE)NULL; }
757743

@@ -1256,6 +1242,12 @@ class AppDomain : public BaseDomain
12561242
void NotifyDebuggerUnload();
12571243
#endif // DEBUGGING_SUPPORTED
12581244

1245+
public:
1246+
// Returns an array of OBJECTREF* that can be used to store domain specific data.
1247+
// Statics and reflection info (Types, MemberInfo,..) are stored this way
1248+
// If pStaticsInfo != 0, allocation will only take place if GC statics in the DynamicStaticsInfo are NULL (and the allocation
1249+
// will be properly serialized)
1250+
OBJECTREF *AllocateObjRefPtrsInLargeTable(int nRequested, DynamicStaticsInfo* pStaticsInfo = NULL, MethodTable *pMTToFillWithStaticBoxes = NULL, bool isClassInitdeByUpdatingStaticPointer = false);
12591251
#ifndef DACCESS_COMPILE
12601252
OBJECTREF* AllocateStaticFieldObjRefPtrs(int nRequested)
12611253
{
@@ -1265,7 +1257,16 @@ class AppDomain : public BaseDomain
12651257
}
12661258
#endif // DACCESS_COMPILE
12671259

1268-
void EnumStaticGCRefs(promote_func* fn, ScanContext* sc);
1260+
private:
1261+
// Helper method to initialize the large heap handle table.
1262+
void InitPinnedHeapHandleTable();
1263+
1264+
private:
1265+
// The pinned heap handle table.
1266+
PinnedHeapHandleTable *m_pPinnedHeapHandleTable;
1267+
1268+
public:
1269+
void EnumStaticGCRefs(promote_func* fn, ScanContext* sc);
12691270

12701271
void SetupSharedStatics();
12711272

src/coreclr/vm/loaderallocator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ LOADERHANDLE LoaderAllocator::AllocateHandle(OBJECTREF value)
844844
}
845845
else
846846
{
847-
OBJECTREF* pRef = GetDomain()->AllocateObjRefPtrsInLargeTable(1);
847+
OBJECTREF* pRef = AppDomain::GetCurrentDomain()->AllocateObjRefPtrsInLargeTable(1);
848848
SetObjectReference(pRef, gc.value);
849849
retVal = (((UINT_PTR)pRef) + 1);
850850
}
@@ -2384,7 +2384,7 @@ void LoaderAllocator::AllocateGCHandlesBytesForStaticVariables(DynamicStaticsInf
23842384
}
23852385
else
23862386
{
2387-
GetDomain()->AllocateObjRefPtrsInLargeTable(cSlots, pStaticsInfo, pMTToFillWithStaticBoxes, isClassInitedByUpdatingStaticPointer);
2387+
AppDomain::GetCurrentDomain()->AllocateObjRefPtrsInLargeTable(cSlots, pStaticsInfo, pMTToFillWithStaticBoxes, isClassInitedByUpdatingStaticPointer);
23882388
}
23892389
}
23902390
#endif // !DACCESS_COMPILE

0 commit comments

Comments
 (0)