From 011d3296d1e91533bdac6ff596ad466503f3cb36 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Tue, 27 Aug 2024 09:56:45 -0700 Subject: [PATCH] Move some members only needed for `AppDomain` off of `BaseDomain` (#107015) - Move default binder, code version managed, and type ID map to `AppDomain` (such that `SystemDomain` won't unnecessarily have them) - Remove unnecessarily stored `BaseDomain` on `VirtualCallStubManager` --- src/coreclr/vm/appdomain.cpp | 31 +++++----------- src/coreclr/vm/appdomain.hpp | 59 +++++++++++++----------------- src/coreclr/vm/assembly.cpp | 2 +- src/coreclr/vm/assemblynative.cpp | 2 +- src/coreclr/vm/loaderallocator.cpp | 4 +- src/coreclr/vm/loaderallocator.hpp | 2 +- src/coreclr/vm/virtualcallstub.cpp | 5 +-- src/coreclr/vm/virtualcallstub.h | 6 +-- 8 files changed, 41 insertions(+), 70 deletions(-) diff --git a/src/coreclr/vm/appdomain.cpp b/src/coreclr/vm/appdomain.cpp index 8d31bbb25c43d..8ea1b4d2c8280 100644 --- a/src/coreclr/vm/appdomain.cpp +++ b/src/coreclr/vm/appdomain.cpp @@ -459,8 +459,6 @@ BaseDomain::BaseDomain() } CONTRACTL_END; - m_pDefaultBinder = NULL; - // Make sure the container is set to NULL so that it gets loaded when it is used. m_pPinnedHeapHandleTable = NULL; @@ -494,16 +492,7 @@ void BaseDomain::Init() #undef LOADERHEAP_PROFILE_COUNTER -void BaseDomain::InitVSD() -{ - STANDARD_VM_CONTRACT; - - m_typeIDMap.Init(); - - GetLoaderAllocator()->InitVirtualCallStubManager(this); -} - -void BaseDomain::ClearBinderContext() +void AppDomain::ClearBinderContext() { CONTRACTL { @@ -862,7 +851,6 @@ void SystemDomain::DetachEnd() if(m_pSystemDomain) { GCX_PREEMP(); - m_pSystemDomain->ClearBinderContext(); AppDomain* pAppDomain = GetAppDomain(); if (pAppDomain) pAppDomain->ClearBinderContext(); @@ -1586,9 +1574,6 @@ void AppDomain::Create() pDomain->Init(); - // allocate a Virtual Call Stub Manager for the default domain - pDomain->InitVSD(); - pDomain->SetStage(AppDomain::STAGE_OPEN); pDomain->CreateDefaultBinder(); @@ -1727,6 +1712,7 @@ AppDomain::AppDomain() m_NativeTypeLoadLock.PreInit(); m_FileLoadLock.PreInit(); + m_pDefaultBinder = NULL; m_pRootAssembly = NULL; m_dwFlags = 0; @@ -1823,7 +1809,6 @@ void AppDomain::Init() COMPlusThrowOM(); } - #ifdef FEATURE_TYPEEQUIVALENCE m_TypeEquivalenceCrst.Init(CrstTypeEquivalenceMap); #endif @@ -1833,12 +1818,14 @@ void AppDomain::Init() SetStage(STAGE_READYFORMANAGEDCODE); - #ifdef FEATURE_TIERED_COMPILATION m_tieredCompilationManager.Init(); #endif m_nativeImageLoadCrst.Init(CrstNativeImageLoad); + + m_typeIDMap.Init(); + GetLoaderAllocator()->InitVirtualCallStubManager(); } // AppDomain::Init void AppDomain::Stop() @@ -4148,7 +4135,7 @@ PTR_LoaderAllocator BaseDomain::GetLoaderAllocator() } //------------------------------------------------------------------------ -UINT32 BaseDomain::GetTypeID(PTR_MethodTable pMT) { +UINT32 AppDomain::GetTypeID(PTR_MethodTable pMT) { CONTRACTL { THROWS; GC_TRIGGERS; @@ -4159,7 +4146,7 @@ UINT32 BaseDomain::GetTypeID(PTR_MethodTable pMT) { //------------------------------------------------------------------------ // Returns the ID of the type if found. If not found, returns INVALID_TYPE_ID -UINT32 BaseDomain::LookupTypeID(PTR_MethodTable pMT) +UINT32 AppDomain::LookupTypeID(PTR_MethodTable pMT) { CONTRACTL { NOTHROW; @@ -4170,7 +4157,7 @@ UINT32 BaseDomain::LookupTypeID(PTR_MethodTable pMT) } //------------------------------------------------------------------------ -PTR_MethodTable BaseDomain::LookupType(UINT32 id) { +PTR_MethodTable AppDomain::LookupType(UINT32 id) { CONTRACTL { NOTHROW; WRAPPER(GC_TRIGGERS); @@ -4186,7 +4173,7 @@ PTR_MethodTable BaseDomain::LookupType(UINT32 id) { #ifndef DACCESS_COMPILE //--------------------------------------------------------------------------------------- -void BaseDomain::RemoveTypesFromTypeIDMap(LoaderAllocator* pLoaderAllocator) +void AppDomain::RemoveTypesFromTypeIDMap(LoaderAllocator* pLoaderAllocator) { CONTRACTL { NOTHROW; diff --git a/src/coreclr/vm/appdomain.hpp b/src/coreclr/vm/appdomain.hpp index c616d739c3034..1c59073cf30bd 100644 --- a/src/coreclr/vm/appdomain.hpp +++ b/src/coreclr/vm/appdomain.hpp @@ -466,7 +466,6 @@ class BaseDomain BaseDomain(); virtual ~BaseDomain() {} void Init(); - void Stop(); virtual BOOL IsAppDomain() { LIMITED_METHOD_DAC_CONTRACT; return FALSE; } @@ -580,8 +579,6 @@ class BaseDomain #endif // DACCESS_COMPILE - DefaultAssemblyBinder *GetDefaultBinder() {LIMITED_METHOD_CONTRACT; return m_pDefaultBinder; } - CrstExplicitInit * GetLoaderAllocatorReferencesLock() { LIMITED_METHOD_CONTRACT; @@ -603,8 +600,6 @@ class BaseDomain // Used to protect the reference lists in the collectible loader allocators attached to this appdomain CrstExplicitInit m_crstLoaderAllocatorReferences; - DefaultAssemblyBinder *m_pDefaultBinder; // Reference to the binding context that holds TPA list details - IGCHandleStore* m_handleStore; // The pinned heap handle table. @@ -613,26 +608,6 @@ class BaseDomain // Protects allocation of slot IDs for thread statics static CrstStatic m_MethodTableExposedClassObjectCrst; -public: - // Only call this routine when you can guarantee there are no - // loads in progress. - void ClearBinderContext(); - - void InitVSD(); - -private: - TypeIDMap m_typeIDMap; - -public: - - - UINT32 GetTypeID(PTR_MethodTable pMT); - UINT32 LookupTypeID(PTR_MethodTable pMT); - PTR_MethodTable LookupType(UINT32 id); -#ifndef DACCESS_COMPILE - void RemoveTypesFromTypeIDMap(LoaderAllocator* pLoaderAllocator); -#endif // DACCESS_COMPILE - private: // I have yet to figure out an efficient way to get the number of handles // of a particular type that's currently used by the process without @@ -659,14 +634,6 @@ class BaseDomain return m_dwSizedRefHandles; } -#ifdef FEATURE_CODE_VERSIONING -private: - CodeVersionManager m_codeVersionManager; - -public: - CodeVersionManager* GetCodeVersionManager() { return &m_codeVersionManager; } -#endif //FEATURE_CODE_VERSIONING - #ifdef DACCESS_COMPILE public: virtual void EnumMemoryRegions(CLRDataEnumMemoryFlags flags, bool enumThis) = 0; @@ -1397,6 +1364,10 @@ class AppDomain : public BaseDomain #endif // FEATURE_COMWRAPPERS DefaultAssemblyBinder *CreateDefaultBinder(); + DefaultAssemblyBinder *GetDefaultBinder() {LIMITED_METHOD_CONTRACT; return m_pDefaultBinder; } + + // Only call this routine when you can guarantee there are no loads in progress. + void ClearBinderContext(); void SetIgnoreUnhandledExceptions() { @@ -1440,16 +1411,28 @@ class AppDomain : public BaseDomain Assembly* RaiseAssemblyResolveEvent(AssemblySpec *pSpec); private: + DefaultAssemblyBinder *m_pDefaultBinder; // Reference to the binding context that holds TPA list details + CrstExplicitInit m_ReflectionCrst; CrstExplicitInit m_RefClassFactCrst; - EEClassFactoryInfoHashTable *m_pRefClassFactHash; // Hash table that maps a class factory info to a COM comp. #ifdef FEATURE_COMINTEROP DispIDCache *m_pRefDispIDCache; OBJECTHANDLE m_hndMissing; //Handle points to Missing.Value Object which is used for [Optional] arg scenario during IDispatch CCW Call #endif // FEATURE_COMINTEROP +public: + UINT32 GetTypeID(PTR_MethodTable pMT); + UINT32 LookupTypeID(PTR_MethodTable pMT); + PTR_MethodTable LookupType(UINT32 id); +#ifndef DACCESS_COMPILE + void RemoveTypesFromTypeIDMap(LoaderAllocator* pLoaderAllocator); +#endif // DACCESS_COMPILE + +private: + TypeIDMap m_typeIDMap; + public: CrstBase *GetRefClassFactCrst() @@ -1758,6 +1741,14 @@ class AppDomain : public BaseDomain SHash m_unmanagedCache; +#ifdef FEATURE_CODE_VERSIONING +private: + CodeVersionManager m_codeVersionManager; + +public: + CodeVersionManager* GetCodeVersionManager() { return &m_codeVersionManager; } +#endif //FEATURE_CODE_VERSIONING + #ifdef FEATURE_TYPEEQUIVALENCE private: VolatilePtr m_pTypeEquivalenceTable; diff --git a/src/coreclr/vm/assembly.cpp b/src/coreclr/vm/assembly.cpp index 721bd43750882..bfe9144257e3d 100644 --- a/src/coreclr/vm/assembly.cpp +++ b/src/coreclr/vm/assembly.cpp @@ -504,7 +504,7 @@ Assembly *Assembly::CreateDynamic(AssemblyBinder* pBinder, NativeAssemblyNamePar { // Initializing the virtual call stub manager is delayed to remove the need for the LoaderAllocator destructor to properly handle // uninitializing the VSD system. (There is a need to suspend the runtime, and that's tricky) - pLoaderAllocator->InitVirtualCallStubManager(pDomain); + pLoaderAllocator->InitVirtualCallStubManager(); } } diff --git a/src/coreclr/vm/assemblynative.cpp b/src/coreclr/vm/assemblynative.cpp index ed6f24b06a7fb..f248ce9d6ea2c 100644 --- a/src/coreclr/vm/assemblynative.cpp +++ b/src/coreclr/vm/assemblynative.cpp @@ -1225,7 +1225,7 @@ extern "C" INT_PTR QCALLTYPE AssemblyNative_InitializeAssemblyLoadContext(INT_PT // Some of the initialization functions are not virtual. Call through the derived class // to prevent calling the base class version. loaderAllocator->Init(pCurDomain); - loaderAllocator->InitVirtualCallStubManager(pCurDomain); + loaderAllocator->InitVirtualCallStubManager(); // Setup the managed proxy now, but do not actually transfer ownership to it. // Once everything is setup and nothing can fail anymore, the ownership will be diff --git a/src/coreclr/vm/loaderallocator.cpp b/src/coreclr/vm/loaderallocator.cpp index 9a7eabbbf2b1b..1ed751ed22dd8 100644 --- a/src/coreclr/vm/loaderallocator.cpp +++ b/src/coreclr/vm/loaderallocator.cpp @@ -1621,14 +1621,14 @@ DispatchToken LoaderAllocator::GetDispatchToken( return DispatchToken::CreateDispatchToken(typeId, slotNumber); } -void LoaderAllocator::InitVirtualCallStubManager(BaseDomain * pDomain) +void LoaderAllocator::InitVirtualCallStubManager() { STANDARD_VM_CONTRACT; NewHolder pMgr(new VirtualCallStubManager()); // Init the manager, including all heaps and such. - pMgr->Init(pDomain, this); + pMgr->Init(this); m_pVirtualCallStubManager = pMgr; diff --git a/src/coreclr/vm/loaderallocator.hpp b/src/coreclr/vm/loaderallocator.hpp index 0bf475e33d5fa..82f24813cb8d1 100644 --- a/src/coreclr/vm/loaderallocator.hpp +++ b/src/coreclr/vm/loaderallocator.hpp @@ -776,7 +776,7 @@ class LoaderAllocator STRINGREF *GetOrInternString(STRINGREF *pString); void CleanupStringLiteralMap(); - void InitVirtualCallStubManager(BaseDomain *pDomain); + void InitVirtualCallStubManager(); void UninitVirtualCallStubManager(); inline PTR_VirtualCallStubManager GetVirtualCallStubManager() diff --git a/src/coreclr/vm/virtualcallstub.cpp b/src/coreclr/vm/virtualcallstub.cpp index 44bbb7e15d861..4ead0cadb8b5b 100644 --- a/src/coreclr/vm/virtualcallstub.cpp +++ b/src/coreclr/vm/virtualcallstub.cpp @@ -478,17 +478,14 @@ void VirtualCallStubManager::ResetCache() } -void VirtualCallStubManager::Init(BaseDomain *pDomain, LoaderAllocator *pLoaderAllocator) +void VirtualCallStubManager::Init(LoaderAllocator *pLoaderAllocator) { CONTRACTL { THROWS; GC_TRIGGERS; - PRECONDITION(CheckPointer(pDomain)); INJECT_FAULT(COMPlusThrowOM();); } CONTRACTL_END; - // Record the parent domain - parentDomain = pDomain; m_loaderAllocator = pLoaderAllocator; // diff --git a/src/coreclr/vm/virtualcallstub.h b/src/coreclr/vm/virtualcallstub.h index da7583ecdab01..7638f2aec1eb2 100644 --- a/src/coreclr/vm/virtualcallstub.h +++ b/src/coreclr/vm/virtualcallstub.h @@ -239,7 +239,7 @@ class VirtualCallStubManager : public StubManager static void LogFinalStats(); // Per instance initialization - called during AppDomain::Init and ::Uninit and for collectible loader allocators - void Init(BaseDomain* pDomain, LoaderAllocator *pLoaderAllocator); + void Init(LoaderAllocator *pLoaderAllocator); void Uninit(); //@TODO: the logging should be tied into the VMs normal logging mechanisms, @@ -262,7 +262,6 @@ class VirtualCallStubManager : public StubManager VirtualCallStubManager() : StubManager(), cache_entry_rangeList(), - parentDomain(NULL), m_loaderAllocator(NULL), m_initialReservedMemForHeaps(NULL), m_FreeIndCellList(NULL), @@ -486,9 +485,6 @@ class VirtualCallStubManager : public StubManager TraceDestination *trace); private: - // The parent domain of this manager - PTR_BaseDomain parentDomain; - PTR_LoaderAllocator m_loaderAllocator; BYTE * m_initialReservedMemForHeaps;