From d03738f94a8b20c39988cdc78b6ee2bca3717826 Mon Sep 17 00:00:00 2001 From: Adeel <3840695+am11@users.noreply.github.com> Date: Sat, 5 Oct 2024 20:30:38 +0300 Subject: [PATCH] Move more helpers from DomainAssembly to Assembly --- src/coreclr/debug/daccess/dacdbiimpl.cpp | 26 +++++----- src/coreclr/debug/ee/debugger.cpp | 12 ++--- src/coreclr/vm/appdomain.cpp | 4 +- src/coreclr/vm/appdomain.hpp | 4 +- src/coreclr/vm/assembly.cpp | 2 +- src/coreclr/vm/ceeload.cpp | 6 +-- src/coreclr/vm/domainassembly.cpp | 44 +---------------- src/coreclr/vm/domainassembly.h | 62 ------------------------ src/coreclr/vm/eventtrace.cpp | 2 +- src/coreclr/vm/loaderallocator.cpp | 4 +- 10 files changed, 30 insertions(+), 136 deletions(-) diff --git a/src/coreclr/debug/daccess/dacdbiimpl.cpp b/src/coreclr/debug/daccess/dacdbiimpl.cpp index 770e81a9480e14..4788dd322d2e1e 100644 --- a/src/coreclr/debug/daccess/dacdbiimpl.cpp +++ b/src/coreclr/debug/daccess/dacdbiimpl.cpp @@ -672,7 +672,7 @@ void DacDbiInterfaceImpl::GetCompilerFlags ( } // Get the underlying module - none of this is AppDomain specific - Module * pModule = pDomainAssembly->GetModule(); + Module * pModule = pDomainAssembly->GetAssembly()->GetModule(); DWORD dwBits = pModule->GetDebuggerInfoBits(); *pfAllowJITOpts = !CORDisableJITOptimizations(dwBits); *pfEnableEnC = pModule->IsEditAndContinueEnabled(); @@ -721,7 +721,7 @@ HRESULT DacDbiInterfaceImpl::SetCompilerFlags(VMPTR_DomainAssembly vmDomainAssem DWORD dwBits = 0; DomainAssembly * pDomainAssembly = vmDomainAssembly.GetDacPtr(); - Module * pModule = pDomainAssembly->GetModule(); + Module * pModule = pDomainAssembly->GetAssembly()->GetModule(); HRESULT hr = S_OK; @@ -821,7 +821,7 @@ SIZE_T DacDbiInterfaceImpl::GetArgCount(MethodDesc * pMD) return 0; } - MetaSig msig(pCallSig, cbCallSigSize, pMD->GetModule(), NULL, MetaSig::sigMember); + MetaSig msig(pCallSig, cbCallSigSize, pMD->GetAssembly()->GetModule(), NULL, MetaSig::sigMember); // Get the arg count. UINT32 NumArguments = msig.NumFixedArgs(); @@ -1019,7 +1019,7 @@ void DacDbiInterfaceImpl::GetSequencePoints(MethodDesc * pMethodDesc, #endif // if there is a profiler load-time mapping and not a rejit mapping, apply that instead InstrumentedILOffsetMapping loadTimeMapping = - pMethodDesc->GetModule()->GetInstrumentedILOffsetMapping(pMethodDesc->GetMemberDef()); + pMethodDesc->GetAssembly()->GetModule()->GetInstrumentedILOffsetMapping(pMethodDesc->GetMemberDef()); ComposeMapping(&loadTimeMapping, mapCopy, &entryCount); #ifdef FEATURE_REJIT } @@ -1091,7 +1091,7 @@ void DacDbiInterfaceImpl::GetILCodeAndSig(VMPTR_DomainAssembly vmDomainAssembly, DD_ENTER_MAY_THROW; DomainAssembly * pDomainAssembly = vmDomainAssembly.GetDacPtr(); - Module * pModule = pDomainAssembly->GetModule(); + Module * pModule = pDomainAssembly->GetAssembly()->GetModule(); RVA methodRVA = 0; DWORD implFlags; @@ -1330,7 +1330,7 @@ void DacDbiInterfaceImpl::GetNativeCodeInfo(VMPTR_DomainAssembly vmDomai pCodeInfo->Clear(); DomainAssembly * pDomainAssembly = vmDomainAssembly.GetDacPtr(); - Module * pModule = pDomainAssembly->GetModule(); + Module * pModule = pDomainAssembly->GetAssembly()->GetModule(); MethodDesc* pMethodDesc = FindLoadedMethodRefOrDef(pModule, functionToken); pCodeInfo->vmNativeCodeMethodDescToken.SetHostPtr(pMethodDesc); @@ -2866,7 +2866,7 @@ TypeHandle DacDbiInterfaceImpl::GetClassOrValueTypeHandle(DebuggerIPCE_BasicType else { DomainAssembly * pDomainAssembly = pData->vmDomainAssembly.GetDacPtr(); - Module * pModule = pDomainAssembly->GetModule(); + Module * pModule = pDomainAssembly->GetAssembly()->GetModule(); typeHandle = ClassLoader::LookupTypeDefOrRefInModule(pModule, pData->metadataToken); if (typeHandle.IsNull()) @@ -3842,7 +3842,7 @@ FieldDesc * DacDbiInterfaceImpl::GetEnCFieldDesc(const EnCHangingFieldInfo * pEn FieldDesc * pFD = NULL; DomainAssembly * pDomainAssembly = pEnCFieldInfo->GetObjectTypeData().vmDomainAssembly.GetDacPtr(); - Module * pModule = pDomainAssembly->GetModule(); + Module * pModule = pDomainAssembly->GetAssembly()->GetModule(); // get the type handle for the object TypeHandle typeHandle = ClassLoader::LookupTypeDefOrRefInModule(pModule, @@ -3881,7 +3881,7 @@ PTR_CBYTE DacDbiInterfaceImpl::GetPtrToEnCField(FieldDesc * pFD, const EnCHangin PTR_EditAndContinueModule pEnCModule; DomainAssembly * pDomainAssembly = pEnCFieldInfo->GetObjectTypeData().vmDomainAssembly.GetDacPtr(); - Module * pModule = pDomainAssembly->GetModule(); + Module * pModule = pDomainAssembly->GetAssembly()->GetModule(); // make sure we actually have an EditAndContinueModule _ASSERTE(pModule->IsEditAndContinueCapable()); @@ -4053,7 +4053,7 @@ void DacDbiInterfaceImpl::ResolveTypeReference(const TypeRefData * pTypeRefInfo, { DD_ENTER_MAY_THROW; DomainAssembly * pDomainAssembly = pTypeRefInfo->vmDomainAssembly.GetDacPtr(); - Module * pReferencingModule = pDomainAssembly->GetModule(); + Module * pReferencingModule = pDomainAssembly->GetAssembly()->GetModule(); BOOL fSuccess = FALSE; // Resolve the type ref @@ -4317,7 +4317,7 @@ void DacDbiInterfaceImpl::GetModuleForDomainAssembly(VMPTR_DomainAssembly vmDoma _ASSERTE(pModule != NULL); DomainAssembly * pDomainAssembly = vmDomainAssembly.GetDacPtr(); - pModule->SetHostPtr(pDomainAssembly->GetModule()); + pModule->SetHostPtr(pDomainAssembly->GetAssembly()->GetModule()); } @@ -4446,7 +4446,7 @@ void DacDbiInterfaceImpl::EnumerateModulesInAssembly( DomainAssembly * pDomainAssembly = vmAssembly.GetDacPtr(); // Debugger isn't notified of Resource / Inspection-only modules. - if (pDomainAssembly->GetModule()->IsVisibleToDebugger()) + if (pDomainAssembly->GetAssembly()->GetModule()->IsVisibleToDebugger()) { // If domain assembly isn't yet loaded, just return if (!pDomainAssembly->GetAssembly()->IsLoaded()) @@ -4469,7 +4469,7 @@ VMPTR_DomainAssembly DacDbiInterfaceImpl::ResolveAssembly( DomainAssembly * pDomainAssembly = vmScope.GetDacPtr(); - Module * pModule = pDomainAssembly->GetModule(); + Module * pModule = pDomainAssembly->GetAssembly()->GetModule(); VMPTR_DomainAssembly vmDomainAssembly = VMPTR_DomainAssembly::NullPtr(); diff --git a/src/coreclr/debug/ee/debugger.cpp b/src/coreclr/debug/ee/debugger.cpp index 9159080ded6dd6..7015d6010f1664 100644 --- a/src/coreclr/debug/ee/debugger.cpp +++ b/src/coreclr/debug/ee/debugger.cpp @@ -5134,8 +5134,8 @@ DebuggerModule * Debugger::LookupOrCreateModule(DomainAssembly * pDomainAssembly { _ASSERTE(pDomainAssembly != NULL); LOG((LF_CORDB, LL_INFO1000, "D::LOCM df=%p\n", pDomainAssembly)); - DebuggerModule * pDModule = LookupOrCreateModule(pDomainAssembly->GetModule()); - LOG((LF_CORDB, LL_INFO1000, "D::LOCM m=%p ad=%p -> dm=%p\n", pDomainAssembly->GetModule(), AppDomain::GetCurrentDomain(), pDModule)); + DebuggerModule * pDModule = LookupOrCreateModule(pDomainAssembly->GetAssembly()->GetModule()); + LOG((LF_CORDB, LL_INFO1000, "D::LOCM m=%p ad=%p -> dm=%p\n", pDomainAssembly->GetAssembly()->GetModule(), AppDomain::GetCurrentDomain(), pDModule)); _ASSERTE(pDModule != NULL); _ASSERTE(pDModule->GetDomainAssembly() == pDomainAssembly); @@ -5235,7 +5235,7 @@ DebuggerModule* Debugger::AddDebuggerModule(DomainAssembly * pDomainAssembly) LOG((LF_CORDB, LL_INFO1000, "D::ADM df=0x%x\n", pDomainAssembly)); DebuggerDataLockHolder chInfo(this); - Module * pRuntimeModule = pDomainAssembly->GetModule(); + Module * pRuntimeModule = pDomainAssembly->GetAssembly()->GetModule(); HRESULT hr = CheckInitModuleTable(); IfFailThrow(hr); @@ -8041,7 +8041,7 @@ BOOL Debugger::ShouldSendCustomNotification(DomainAssembly *pAssembly, mdTypeDef } CONTRACTL_END; - Module *pModule = pAssembly->GetModule(); + Module *pModule = pAssembly->GetAssembly()->GetModule(); TypeInModule tim(pModule, typeDef); return !(m_pCustomNotificationTable->Lookup(tim).IsNull()); } @@ -9402,7 +9402,7 @@ void Debugger::LoadModule(Module* pRuntimeModule, // We should simply things when we actually get rid of DebuggerModule, possibly by just passing the // DomainAssembly around. _ASSERTE(module->GetDomainAssembly() == pDomainAssembly); - _ASSERTE(module->GetRuntimeModule() == pDomainAssembly->GetModule()); + _ASSERTE(module->GetRuntimeModule() == pDomainAssembly->GetAssembly()->GetModule()); // Send a load module event to the Right Side. ipce = m_pRCThread->GetIPCEventSendBuffer(); @@ -10830,7 +10830,7 @@ bool Debugger::HandleIPCEvent(DebuggerIPCEvent * pEvent) // unexpected in an OOM situation. Quickly just sanity check them. // Thread * pThread = pEvent->SetIP.vmThreadToken.GetRawPtr(); - Module * pModule = pEvent->SetIP.vmDomainAssembly.GetRawPtr()->GetModule(); + Module * pModule = pEvent->SetIP.vmDomainAssembly.GetRawPtr()->GetAssembly()->GetModule(); // Get the DJI for this function DebuggerMethodInfo * pDMI = GetOrCreateMethodInfo(pModule, pEvent->SetIP.mdMethod); diff --git a/src/coreclr/vm/appdomain.cpp b/src/coreclr/vm/appdomain.cpp index 34f1f6b0dea8a5..ce933c43739a11 100644 --- a/src/coreclr/vm/appdomain.cpp +++ b/src/coreclr/vm/appdomain.cpp @@ -2472,7 +2472,7 @@ Assembly *AppDomain::LoadAssemblyInternal(AssemblySpec* pIdentity, // Set the assembly module to be tenured now that we know it won't be deleted pDomainAssembly->GetAssembly()->SetIsTenured(); - if (pDomainAssembly->IsCollectible()) + if (pDomainAssembly->GetAssembly()->IsCollectible()) { // We add the assembly to the LoaderAllocator only when we are sure that it can be added // and won't be deleted in case of a concurrent load from the same ALC @@ -4427,7 +4427,7 @@ AppDomain::EnumMemoryRegions(CLRDataEnumMemoryFlags flags, bool enumThis) while (assem.Next(pAssembly.This())) { - pAssembly->GetDomainAssembly()->EnumMemoryRegions(flags); + pAssembly->EnumMemoryRegions(flags); } } diff --git a/src/coreclr/vm/appdomain.hpp b/src/coreclr/vm/appdomain.hpp index 248d37f203a104..b5938414511b6f 100644 --- a/src/coreclr/vm/appdomain.hpp +++ b/src/coreclr/vm/appdomain.hpp @@ -544,12 +544,12 @@ class CollectibleAssemblyHolderBase LoaderAllocator * GetLoaderAllocator(DomainAssembly * pDomainAssembly) { WRAPPER_NO_CONTRACT; - return pDomainAssembly->GetLoaderAllocator(); + return pDomainAssembly->GetAssembly()->GetLoaderAllocator(); } BOOL IsCollectible(DomainAssembly * pDomainAssembly) { WRAPPER_NO_CONTRACT; - return pDomainAssembly->IsCollectible(); + return pDomainAssembly->GetAssembly()->IsCollectible(); } LoaderAllocator * GetLoaderAllocator(Assembly * pAssembly) { diff --git a/src/coreclr/vm/assembly.cpp b/src/coreclr/vm/assembly.cpp index 9c2b72036df4c5..5be3c89c3c9d63 100644 --- a/src/coreclr/vm/assembly.cpp +++ b/src/coreclr/vm/assembly.cpp @@ -490,7 +490,7 @@ Assembly *Assembly::CreateDynamic(AssemblyBinder* pBinder, NativeAssemblyNamePar pDomainAssembly = new DomainAssembly(pPEAssembly, pLoaderAllocator, pamTracker); pAssem = pDomainAssembly->GetAssembly(); pAssem->m_isDynamic = true; - if (pDomainAssembly->IsCollectible()) + if (pAssem->IsCollectible()) { // We add the assembly to the LoaderAllocator only when we are sure that it can be added // and won't be deleted in case of a concurrent load from the same ALC diff --git a/src/coreclr/vm/ceeload.cpp b/src/coreclr/vm/ceeload.cpp index 1932bb14d71e00..f4d075b126e139 100644 --- a/src/coreclr/vm/ceeload.cpp +++ b/src/coreclr/vm/ceeload.cpp @@ -2917,7 +2917,7 @@ BOOL Module::NotifyDebuggerLoad(DomainAssembly * pDomainAssembly, int flags, BOO // Always capture metadata, even if no debugger is attached. If a debugger later attaches, it will use // this data. { - Module * pModule = pDomainAssembly->GetModule(); + Module * pModule = pDomainAssembly->GetAssembly()->GetModule(); pModule->UpdateDynamicMetadataIfNeeded(); } @@ -4502,10 +4502,6 @@ void Module::EnumMemoryRegions(CLRDataEnumMemoryFlags flags, EMEM_OUT(("MEM: %p Module\n", dac_cast(this))); } - if (m_pDomainAssembly.IsValid()) - { - m_pDomainAssembly->EnumMemoryRegions(flags); - } if (m_pPEAssembly.IsValid()) { m_pPEAssembly->EnumMemoryRegions(flags); diff --git a/src/coreclr/vm/domainassembly.cpp b/src/coreclr/vm/domainassembly.cpp index 0dfa2d8a90b99a..de252dbe6d5c64 100644 --- a/src/coreclr/vm/domainassembly.cpp +++ b/src/coreclr/vm/domainassembly.cpp @@ -26,11 +26,6 @@ #ifndef DACCESS_COMPILE DomainAssembly::DomainAssembly(PEAssembly* pPEAssembly, LoaderAllocator* pLoaderAllocator, AllocMemTracker* memTracker) : m_pAssembly(NULL) - , m_pPEAssembly(pPEAssembly) - , m_pModule(NULL) - , m_fCollectible(pLoaderAllocator->IsCollectible()) - , m_NextDomainAssemblyInSameALC(NULL) - , m_pLoaderAllocator(pLoaderAllocator) { CONTRACTL { @@ -48,12 +43,11 @@ DomainAssembly::DomainAssembly(PEAssembly* pPEAssembly, LoaderAllocator* pLoader NewHolder assembly = Assembly::Create(pPEAssembly, memTracker, pLoaderAllocator); m_pAssembly = assembly.Extract(); - m_pModule = m_pAssembly->GetModule(); m_pAssembly->SetDomainAssembly(this); // Creating the Assembly should have ensured the PEAssembly is loaded - _ASSERT(GetPEAssembly()->IsLoaded()); + _ASSERT(m_pAssembly->GetPEAssembly()->IsLoaded()); } DomainAssembly::~DomainAssembly() @@ -67,8 +61,6 @@ DomainAssembly::~DomainAssembly() } CONTRACTL_END; - m_pPEAssembly->Release(); - if (m_pAssembly != NULL) { delete m_pAssembly; @@ -648,7 +640,7 @@ BOOL Assembly::NotifyDebuggerLoad(int flags, BOOL attaching) if( ShouldNotifyDebugger()) { - result|=m_pModule->NotifyDebuggerLoad(GetDomainAssembly(), ATTACH_MODULE_LOAD, attaching); + result |= m_pModule->NotifyDebuggerLoad(GetDomainAssembly(), ATTACH_MODULE_LOAD, attaching); SetDebuggerNotified(); } @@ -670,35 +662,3 @@ void Assembly::NotifyDebuggerUnload() } #endif // #ifndef DACCESS_COMPILE - -#ifdef DACCESS_COMPILE - -void DomainAssembly::EnumMemoryRegions(CLRDataEnumMemoryFlags flags) -{ - SUPPORTS_DAC; - - DAC_ENUM_DTHIS(); - - // Modules are needed for all minidumps, but they are enumerated elsewhere - // so we don't need to duplicate effort; thus we do noting with m_pModule. - - // For MiniDumpNormal, we only want the file name. - if (m_pPEAssembly.IsValid()) - { - m_pPEAssembly->EnumMemoryRegions(flags); - } - - if (flags == CLRDATA_ENUM_MEM_HEAP2) - { - GetLoaderAllocator()->EnumMemoryRegions(flags); - } - else if (flags != CLRDATA_ENUM_MEM_MINI && flags != CLRDATA_ENUM_MEM_TRIAGE) - { - if (m_pAssembly.IsValid()) - { - m_pAssembly->EnumMemoryRegions(flags); - } - } -} - -#endif // #ifdef DACCESS_COMPILE diff --git a/src/coreclr/vm/domainassembly.h b/src/coreclr/vm/domainassembly.h index d776edba627392..fe82bff39108ac 100644 --- a/src/coreclr/vm/domainassembly.h +++ b/src/coreclr/vm/domainassembly.h @@ -18,7 +18,6 @@ // Forward class declarations // -------------------------------------------------------------------------------- class AppDomain; -class DomainAssembly; class Assembly; class Module; class DynamicMethodTable; @@ -69,12 +68,6 @@ class DomainAssembly final DomainAssembly() {LIMITED_METHOD_CONTRACT;}; #endif - PEAssembly *GetPEAssembly() - { - LIMITED_METHOD_DAC_CONTRACT; - return PTR_PEAssembly(m_pPEAssembly); - } - Assembly* GetAssembly() { LIMITED_METHOD_DAC_CONTRACT; @@ -82,46 +75,6 @@ class DomainAssembly final return m_pAssembly; } - Module* GetModule() - { - LIMITED_METHOD_CONTRACT; - - return m_pModule; - } - - LPCUTF8 GetSimpleName() - { - WRAPPER_NO_CONTRACT; - return GetPEAssembly()->GetSimpleName(); - } - -#ifdef LOGGING - LPCUTF8 GetDebugName() - { - WRAPPER_NO_CONTRACT; - return GetPEAssembly()->GetDebugName(); - } -#endif - - BOOL IsCollectible() - { - LIMITED_METHOD_CONTRACT; - return m_fCollectible; - } - - // ------------------------------------------------------------ - // Other public APIs - // ------------------------------------------------------------ - -#ifndef DACCESS_COMPILE - BOOL Equals(DomainAssembly *pAssembly) { WRAPPER_NO_CONTRACT; return GetPEAssembly()->Equals(pAssembly->GetPEAssembly()); } - BOOL Equals(PEAssembly *pPEAssembly) { WRAPPER_NO_CONTRACT; return GetPEAssembly()->Equals(pPEAssembly); } -#endif // DACCESS_COMPILE - -#ifdef DACCESS_COMPILE - void EnumMemoryRegions(CLRDataEnumMemoryFlags flags); -#endif - DomainAssembly* GetNextDomainAssemblyInSameALC() { return m_NextDomainAssemblyInSameALC; @@ -133,12 +86,6 @@ class DomainAssembly final m_NextDomainAssemblyInSameALC = domainAssembly; } - LoaderAllocator* GetLoaderAllocator() - { - LIMITED_METHOD_CONTRACT; - return m_pLoaderAllocator; - } - private: // ------------------------------------------------------------ // Loader API @@ -150,17 +97,8 @@ class DomainAssembly final DomainAssembly(PEAssembly* pPEAssembly, LoaderAllocator* pLoaderAllocator, AllocMemTracker* memTracker); private: - // ------------------------------------------------------------ - // Instance data - // ------------------------------------------------------------ - PTR_Assembly m_pAssembly; - PTR_PEAssembly m_pPEAssembly; - PTR_Module m_pModule; - - BOOL m_fCollectible; DomainAssembly* m_NextDomainAssemblyInSameALC; - PTR_LoaderAllocator m_pLoaderAllocator; }; #endif // _DOMAINASSEMBLY_H_ diff --git a/src/coreclr/vm/eventtrace.cpp b/src/coreclr/vm/eventtrace.cpp index 726205a15e7bc9..535a44f96dffb7 100644 --- a/src/coreclr/vm/eventtrace.cpp +++ b/src/coreclr/vm/eventtrace.cpp @@ -5438,7 +5438,7 @@ VOID ETW::EnumerationLog::IterateCollectibleLoaderAllocator(AssemblyLoaderAlloca { Assembly *pAssembly = domainAssemblyIt->GetAssembly(); // TODO: handle iterator - Module* pModule = domainAssemblyIt->GetModule(); + Module* pModule = domainAssemblyIt->GetAssembly()->GetModule(); ETW::EnumerationLog::IterateModule(pModule, enumerationOptions); if (enumerationOptions & ETW::EnumerationLog::EnumerationStructs::DomainAssemblyModuleUnload) diff --git a/src/coreclr/vm/loaderallocator.cpp b/src/coreclr/vm/loaderallocator.cpp index 3611ee834d8c49..250663fadc769b 100644 --- a/src/coreclr/vm/loaderallocator.cpp +++ b/src/coreclr/vm/loaderallocator.cpp @@ -469,9 +469,9 @@ LoaderAllocator * LoaderAllocator::GCLoaderAllocators_RemoveAssemblies(AppDomain if (!domainAssemblyToRemove->GetAssembly()->IsDynamic()) { - pAppDomain->RemoveFileFromCache(domainAssemblyToRemove->GetPEAssembly()); + pAppDomain->RemoveFileFromCache(domainAssemblyToRemove->GetAssembly()->GetPEAssembly()); AssemblySpec spec; - spec.InitializeSpec(domainAssemblyToRemove->GetPEAssembly()); + spec.InitializeSpec(domainAssemblyToRemove->GetAssembly()->GetPEAssembly()); VERIFY(pAppDomain->RemoveAssemblyFromCache(domainAssemblyToRemove->GetAssembly())); }