Skip to content

Commit 1844293

Browse files
elinor-fungpull[bot]
authored andcommitted
Move handle store and remaining crsts from BaseDomain to AppDomain (#107208)
- The handle store was always the global handle store - Make all the `Create*Handle` functions go through the `AppDomain` - `m_crstLoaderAllocatorReferences` is only used for collectible loader allocators - so only assembly loader allocators (which correspond to `AppDomain`), not the global loader allocator (which corresponds to `SystemDomain`) - Remove unnecessary `BaseDomain` on `PinnedHeapHandleTable`
1 parent af03d87 commit 1844293

File tree

6 files changed

+114
-176
lines changed

6 files changed

+114
-176
lines changed

src/coreclr/vm/appdomain.cpp

Lines changed: 17 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,6 @@ SPTR_IMPL(SystemDomain, SystemDomain, m_pSystemDomain);
9090

9191
#ifndef DACCESS_COMPILE
9292

93-
// Base Domain Statics
94-
CrstStatic BaseDomain::m_MethodTableExposedClassObjectCrst;
95-
9693
// System Domain Statics
9794
GlobalStringLiteralMap* SystemDomain::m_pGlobalStringLiteralMap = NULL;
9895
FrozenObjectHeapManager* SystemDomain::m_FrozenObjectHeapManager = NULL;
@@ -104,7 +101,7 @@ CrstStatic SystemDomain::m_SystemDomainCrst;
104101
CrstStatic SystemDomain::m_DelayedUnloadCrst;
105102

106103
// Constructor for the PinnedHeapHandleBucket class.
107-
PinnedHeapHandleBucket::PinnedHeapHandleBucket(PinnedHeapHandleBucket *pNext, PTRARRAYREF pinnedHandleArrayObj, DWORD size, BaseDomain *pDomain)
104+
PinnedHeapHandleBucket::PinnedHeapHandleBucket(PinnedHeapHandleBucket *pNext, PTRARRAYREF pinnedHandleArrayObj, DWORD size)
108105
: m_pNext(pNext)
109106
, m_ArraySize(size)
110107
, m_CurrentPos(0)
@@ -115,7 +112,6 @@ PinnedHeapHandleBucket::PinnedHeapHandleBucket(PinnedHeapHandleBucket *pNext, PT
115112
THROWS;
116113
GC_NOTRIGGER;
117114
MODE_COOPERATIVE;
118-
PRECONDITION(CheckPointer(pDomain));
119115
INJECT_FAULT(COMPlusThrowOM(););
120116
}
121117
CONTRACTL_END;
@@ -125,7 +121,7 @@ PinnedHeapHandleBucket::PinnedHeapHandleBucket(PinnedHeapHandleBucket *pNext, PT
125121
m_pArrayDataPtr = (OBJECTREF *)pinnedHandleArrayObj->GetDataPtr();
126122

127123
// Store the array in a strong handle to keep it alive.
128-
m_hndHandleArray = pDomain->CreateStrongHandle((OBJECTREF)pinnedHandleArrayObj);
124+
m_hndHandleArray = AppDomain::GetCurrentDomain()->CreateStrongHandle((OBJECTREF)pinnedHandleArrayObj);
129125
}
130126

131127

@@ -215,9 +211,8 @@ void PinnedHeapHandleBucket::EnumStaticGCRefs(promote_func* fn, ScanContext* sc)
215211
#define MAX_BUCKETSIZE (16384 - 4)
216212

217213
// Constructor for the PinnedHeapHandleTable class.
218-
PinnedHeapHandleTable::PinnedHeapHandleTable(BaseDomain *pDomain, DWORD InitialBucketSize)
214+
PinnedHeapHandleTable::PinnedHeapHandleTable(DWORD InitialBucketSize)
219215
: m_pHead(NULL)
220-
, m_pDomain(pDomain)
221216
, m_NextBucketSize(InitialBucketSize)
222217
, m_pFreeSearchHint(NULL)
223218
, m_cEmbeddedFree(0)
@@ -227,7 +222,6 @@ PinnedHeapHandleTable::PinnedHeapHandleTable(BaseDomain *pDomain, DWORD InitialB
227222
THROWS;
228223
GC_TRIGGERS;
229224
MODE_COOPERATIVE;
230-
PRECONDITION(CheckPointer(pDomain));
231225
INJECT_FAULT(COMPlusThrowOM(););
232226
}
233227
CONTRACTL_END;
@@ -359,7 +353,7 @@ OBJECTREF* PinnedHeapHandleTable::AllocateHandles(DWORD nRequested)
359353
m_pHead->ConsumeRemaining();
360354
}
361355

362-
m_pHead = new PinnedHeapHandleBucket(m_pHead, pinnedHandleArrayObj, newBucketSize, m_pDomain);
356+
m_pHead = new PinnedHeapHandleBucket(m_pHead, pinnedHandleArrayObj, newBucketSize);
363357

364358
// we already computed nextBucketSize to be double the previous size above, but it is possible that
365359
// other threads increased m_NextBucketSize while the lock was unheld. We want to ensure
@@ -439,10 +433,6 @@ void PinnedHeapHandleTable::EnumStaticGCRefs(promote_func* fn, ScanContext* sc)
439433
//*****************************************************************************
440434
// BaseDomain
441435
//*****************************************************************************
442-
void BaseDomain::Attach()
443-
{
444-
m_MethodTableExposedClassObjectCrst.Init(CrstMethodTableExposedObject);
445-
}
446436

447437
BaseDomain::BaseDomain()
448438
{
@@ -459,29 +449,8 @@ BaseDomain::BaseDomain()
459449

460450
// Make sure the container is set to NULL so that it gets loaded when it is used.
461451
m_pPinnedHeapHandleTable = NULL;
462-
463-
// Note that m_handleStore is overridden by app domains
464-
m_handleStore = GCHandleUtilities::GetGCHandleManager()->GetGlobalHandleStore();
465452
} //BaseDomain::BaseDomain
466453

467-
//*****************************************************************************
468-
void BaseDomain::Init()
469-
{
470-
CONTRACTL
471-
{
472-
THROWS;
473-
GC_TRIGGERS;
474-
MODE_ANY;
475-
INJECT_FAULT(COMPlusThrowOM(););
476-
}
477-
CONTRACTL_END;
478-
479-
//
480-
// Initialize the domain locks
481-
//
482-
m_crstLoaderAllocatorReferences.Init(CrstLoaderAllocatorReferences);
483-
}
484-
485454
#undef LOADERHEAP_PROFILE_COUNTER
486455

487456
void AppDomain::ClearBinderContext()
@@ -733,7 +702,7 @@ void BaseDomain::InitPinnedHeapHandleTable()
733702
}
734703
CONTRACTL_END;
735704

736-
PinnedHeapHandleTable* pTable = new PinnedHeapHandleTable(this, STATIC_OBJECT_TABLE_BUCKET_SIZE);
705+
PinnedHeapHandleTable* pTable = new PinnedHeapHandleTable(STATIC_OBJECT_TABLE_BUCKET_SIZE);
737706
if(InterlockedCompareExchangeT<PinnedHeapHandleTable*>(&m_pPinnedHeapHandleTable, pTable, NULL) != NULL)
738707
{
739708
// another thread beat us to initializing the field, delete our copy
@@ -797,9 +766,6 @@ void SystemDomain::Attach()
797766
"Created system domain at %p\n",
798767
m_pSystemDomain));
799768

800-
// We need to initialize the memory pools etc. for the system domain.
801-
m_pSystemDomain->BaseDomain::Init(); // Setup the memory heaps
802-
803769
// Create the one and only app domain
804770
AppDomain::Create();
805771

@@ -869,7 +835,7 @@ void SystemDomain::PreallocateSpecialObjects()
869835
_ASSERTE(g_pPreallocatedSentinelObject == NULL);
870836

871837
OBJECTREF pPreallocatedSentinelObject = AllocateObject(g_pObjectClass);
872-
g_pPreallocatedSentinelObject = CreatePinningHandle( pPreallocatedSentinelObject );
838+
g_pPreallocatedSentinelObject = AppDomain::GetCurrentDomain()->CreatePinningHandle( pPreallocatedSentinelObject );
873839
}
874840

875841
void SystemDomain::CreatePreallocatedExceptions()
@@ -887,27 +853,30 @@ void SystemDomain::CreatePreallocatedExceptions()
887853
pOutOfMemory->SetHResult(COR_E_OUTOFMEMORY);
888854
pOutOfMemory->SetXCode(EXCEPTION_COMPLUS);
889855
_ASSERTE(g_pPreallocatedOutOfMemoryException == NULL);
890-
g_pPreallocatedOutOfMemoryException = CreateHandle(pOutOfMemory);
856+
g_pPreallocatedOutOfMemoryException = AppDomain::GetCurrentDomain()->CreateHandle(pOutOfMemory);
891857

892858

893859
EXCEPTIONREF pStackOverflow = (EXCEPTIONREF)AllocateObject(g_pStackOverflowExceptionClass);
894860
pStackOverflow->SetHResult(COR_E_STACKOVERFLOW);
895861
pStackOverflow->SetXCode(EXCEPTION_COMPLUS);
896862
_ASSERTE(g_pPreallocatedStackOverflowException == NULL);
897-
g_pPreallocatedStackOverflowException = CreateHandle(pStackOverflow);
863+
g_pPreallocatedStackOverflowException = AppDomain::GetCurrentDomain()->CreateHandle(pStackOverflow);
898864

899865

900866
EXCEPTIONREF pExecutionEngine = (EXCEPTIONREF)AllocateObject(g_pExecutionEngineExceptionClass);
901867
pExecutionEngine->SetHResult(COR_E_EXECUTIONENGINE);
902868
pExecutionEngine->SetXCode(EXCEPTION_COMPLUS);
903869
_ASSERTE(g_pPreallocatedExecutionEngineException == NULL);
904-
g_pPreallocatedExecutionEngineException = CreateHandle(pExecutionEngine);
870+
g_pPreallocatedExecutionEngineException = AppDomain::GetCurrentDomain()->CreateHandle(pExecutionEngine);
905871
}
906872

907873
void SystemDomain::Init()
908874
{
909875
STANDARD_VM_CONTRACT;
910876

877+
// The AppDomain should have already been created
878+
_ASSERTE(AppDomain::GetCurrentDomain() != NULL);
879+
911880
HRESULT hr = S_OK;
912881

913882
#ifdef _DEBUG
@@ -927,10 +896,6 @@ void SystemDomain::Init()
927896
));
928897
#endif // _DEBUG
929898

930-
// The base domain is initialized in SystemDomain::Attach()
931-
// to allow stub caches to use the memory pool. Do not
932-
// initialize it here!
933-
934899
m_pSystemPEAssembly = NULL;
935900
m_pSystemAssembly = NULL;
936901

@@ -1537,16 +1502,14 @@ void AppDomain::Create()
15371502
{
15381503
STANDARD_VM_CONTRACT;
15391504

1540-
AppDomainRefHolder pDomain(new AppDomain());
1505+
_ASSERTE(m_pTheAppDomain == NULL);
15411506

1507+
AppDomainRefHolder pDomain(new AppDomain());
15421508
pDomain->Init();
1543-
15441509
pDomain->SetStage(AppDomain::STAGE_OPEN);
15451510
pDomain->CreateDefaultBinder();
15461511

1547-
pDomain.SuppressRelease();
1548-
1549-
m_pTheAppDomain = pDomain;
1512+
m_pTheAppDomain = pDomain.Extract();
15501513

15511514
LOG((LF_CLASSLOADER | LF_CORDB,
15521515
LL_INFO10,
@@ -1760,17 +1723,15 @@ void AppDomain::Init()
17601723
m_crstAssemblyList.Init(CrstAssemblyList, CrstFlags(
17611724
CRST_GC_NOTRIGGER_WHEN_TAKEN | CRST_DEBUGGER_THREAD | CRST_TAKEN_DURING_SHUTDOWN));
17621725

1763-
BaseDomain::Init();
1726+
m_crstLoaderAllocatorReferences.Init(CrstLoaderAllocatorReferences);
1727+
m_MethodTableExposedClassObjectCrst.Init(CrstMethodTableExposedObject);
17641728

17651729
// Set up the binding caches
17661730
m_AssemblyCache.Init(&m_DomainCacheCrst, GetHighFrequencyHeap());
17671731

17681732
m_MemoryPressure = 0;
17691733

1770-
1771-
// Default domain reuses the handletablemap that was created during EEStartup
17721734
m_handleStore = GCHandleUtilities::GetGCHandleManager()->GetGlobalHandleStore();
1773-
17741735
if (!m_handleStore)
17751736
{
17761737
COMPlusThrowOM();

0 commit comments

Comments
 (0)