Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move some members only needed for AppDomain off of BaseDomain #107015

Merged
merged 4 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 9 additions & 22 deletions src/coreclr/vm/appdomain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -862,7 +851,6 @@ void SystemDomain::DetachEnd()
if(m_pSystemDomain)
{
GCX_PREEMP();
m_pSystemDomain->ClearBinderContext();
AppDomain* pAppDomain = GetAppDomain();
if (pAppDomain)
pAppDomain->ClearBinderContext();
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -1727,6 +1712,7 @@ AppDomain::AppDomain()
m_NativeTypeLoadLock.PreInit();
m_FileLoadLock.PreInit();

m_pDefaultBinder = NULL;
m_pRootAssembly = NULL;

m_dwFlags = 0;
Expand Down Expand Up @@ -1823,7 +1809,6 @@ void AppDomain::Init()
COMPlusThrowOM();
}


#ifdef FEATURE_TYPEEQUIVALENCE
m_TypeEquivalenceCrst.Init(CrstTypeEquivalenceMap);
#endif
Expand All @@ -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()
Expand Down Expand Up @@ -4148,7 +4135,7 @@ PTR_LoaderAllocator BaseDomain::GetLoaderAllocator()
}

//------------------------------------------------------------------------
UINT32 BaseDomain::GetTypeID(PTR_MethodTable pMT) {
UINT32 AppDomain::GetTypeID(PTR_MethodTable pMT) {
CONTRACTL {
THROWS;
GC_TRIGGERS;
Expand All @@ -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;
Expand All @@ -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);
Expand All @@ -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;
Expand Down
59 changes: 25 additions & 34 deletions src/coreclr/vm/appdomain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,6 @@ class BaseDomain
BaseDomain();
virtual ~BaseDomain() {}
void Init();
void Stop();

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

Expand Down Expand Up @@ -580,8 +579,6 @@ class BaseDomain

#endif // DACCESS_COMPILE

DefaultAssemblyBinder *GetDefaultBinder() {LIMITED_METHOD_CONTRACT; return m_pDefaultBinder; }

CrstExplicitInit * GetLoaderAllocatorReferencesLock()
{
LIMITED_METHOD_CONTRACT;
Expand All @@ -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.
Expand All @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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()
{
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -1758,6 +1741,14 @@ class AppDomain : public BaseDomain

SHash<UnmanagedImageCacheTraits> 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<TypeEquivalenceHashTable> m_pTypeEquivalenceTable;
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/assembly.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/assemblynative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/vm/loaderallocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1621,14 +1621,14 @@ DispatchToken LoaderAllocator::GetDispatchToken(
return DispatchToken::CreateDispatchToken(typeId, slotNumber);
}

void LoaderAllocator::InitVirtualCallStubManager(BaseDomain * pDomain)
void LoaderAllocator::InitVirtualCallStubManager()
{
STANDARD_VM_CONTRACT;

NewHolder<VirtualCallStubManager> pMgr(new VirtualCallStubManager());

// Init the manager, including all heaps and such.
pMgr->Init(pDomain, this);
pMgr->Init(this);

m_pVirtualCallStubManager = pMgr;

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/loaderallocator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ class LoaderAllocator
STRINGREF *GetOrInternString(STRINGREF *pString);
void CleanupStringLiteralMap();

void InitVirtualCallStubManager(BaseDomain *pDomain);
void InitVirtualCallStubManager();
void UninitVirtualCallStubManager();

inline PTR_VirtualCallStubManager GetVirtualCallStubManager()
Expand Down
5 changes: 1 addition & 4 deletions src/coreclr/vm/virtualcallstub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

//
Expand Down
6 changes: 1 addition & 5 deletions src/coreclr/vm/virtualcallstub.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -262,7 +262,6 @@ class VirtualCallStubManager : public StubManager
VirtualCallStubManager()
: StubManager(),
cache_entry_rangeList(),
parentDomain(NULL),
m_loaderAllocator(NULL),
m_initialReservedMemForHeaps(NULL),
m_FreeIndCellList(NULL),
Expand Down Expand Up @@ -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;
Expand Down
Loading