From 2fb362909e34d5d28a6e2f6f3de0c62b5b0dd4d8 Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Mon, 9 Sep 2024 08:03:27 -0700 Subject: [PATCH] Remove `BaseDomain` use in `LoaderAllocator` and event tracing helpers (#107481) - Remove `BaseDomain` member on `LoaderAllocator` - Add asserts in functions using `AppDomain` that the loader allocator is collectible and the type is `LAT_Assembly` (so `AssemblyLoaderAllocator` which always had `AppDomain`) - Remove unnecessary `BaseDomain`/`AppDomain` parameters from event tracing helpers - They were always being called with the current app domain --- src/coreclr/inc/eventtracebase.h | 22 ++--- src/coreclr/vm/appdomain.hpp | 3 +- src/coreclr/vm/assembly.cpp | 2 +- src/coreclr/vm/assemblynative.cpp | 2 +- src/coreclr/vm/corhost.cpp | 4 +- src/coreclr/vm/eventtrace.cpp | 144 +++++++++-------------------- src/coreclr/vm/loaderallocator.cpp | 22 ++--- src/coreclr/vm/loaderallocator.hpp | 9 +- src/coreclr/vm/loaderallocator.inl | 4 +- 9 files changed, 74 insertions(+), 138 deletions(-) diff --git a/src/coreclr/inc/eventtracebase.h b/src/coreclr/inc/eventtracebase.h index 316104f649a1d..38868fe528f79 100644 --- a/src/coreclr/inc/eventtracebase.h +++ b/src/coreclr/inc/eventtracebase.h @@ -689,7 +689,6 @@ class Module; class Assembly; class MethodDesc; class MethodTable; -class BaseDomain; class AppDomain; class SString; class CrawlFrame; @@ -750,12 +749,11 @@ namespace ETW #ifdef FEATURE_EVENT_TRACE static VOID SendThreadRundownEvent(); static VOID SendGCRundownEvent(); - static VOID IterateDomain(BaseDomain *pDomain, DWORD enumerationOptions); - static VOID IterateAppDomain(AppDomain * pAppDomain, DWORD enumerationOptions); + static VOID IterateAppDomain(DWORD enumerationOptions); static VOID IterateCollectibleLoaderAllocator(AssemblyLoaderAllocator *pLoaderAllocator, DWORD enumerationOptions); static VOID IterateAssembly(Assembly *pAssembly, DWORD enumerationOptions); static VOID IterateModule(Module *pModule, DWORD enumerationOptions); - static VOID EnumerationHelper(Module *moduleFilter, BaseDomain *domainFilter, DWORD enumerationOptions); + static VOID EnumerationHelper(Module *moduleFilter, DWORD enumerationOptions); static DWORD GetEnumerationOptionsFromRuntimeKeywords(); public: typedef union _EnumerationStructs @@ -839,7 +837,7 @@ namespace ETW static VOID SendModuleEvent(Module *pModule, DWORD dwEventOptions, BOOL bFireDomainModuleEvents=FALSE); static ULONG SendModuleRange(_In_ Module *pModule, _In_ DWORD dwEventOptions); static VOID SendAssemblyEvent(Assembly *pAssembly, DWORD dwEventOptions); - static VOID SendDomainEvent(BaseDomain *pBaseDomain, DWORD dwEventOptions, LPCWSTR wszFriendlyName=NULL); + static VOID SendDomainEvent(DWORD dwEventOptions, LPCWSTR wszFriendlyName=NULL); public: typedef union _LoaderStructs { @@ -877,23 +875,23 @@ namespace ETW }LoaderStructs; - static VOID DomainLoadReal(BaseDomain *pDomain, _In_opt_ LPWSTR wszFriendlyName=NULL); + static VOID DomainLoadReal(_In_opt_ LPWSTR wszFriendlyName=NULL); - static VOID DomainLoad(BaseDomain *pDomain, _In_opt_ LPWSTR wszFriendlyName = NULL) + static VOID DomainLoad(_In_opt_ LPWSTR wszFriendlyName = NULL) { if (ETW_PROVIDER_ENABLED(MICROSOFT_WINDOWS_DOTNETRUNTIME_PROVIDER)) { - DomainLoadReal(pDomain, wszFriendlyName); + DomainLoadReal(wszFriendlyName); } } - static VOID DomainUnload(AppDomain *pDomain); + static VOID DomainUnload(); static VOID CollectibleLoaderAllocatorUnload(AssemblyLoaderAllocator *pLoaderAllocator); static VOID ModuleLoad(Module *pModule, LONG liReportedSharedModule); #else public: - static VOID DomainLoad(BaseDomain *pDomain, _In_opt_ LPWSTR wszFriendlyName=NULL) {}; - static VOID DomainUnload(AppDomain *pDomain) {}; + static VOID DomainLoad(_In_opt_ LPWSTR wszFriendlyName=NULL) {}; + static VOID DomainUnload() {}; static VOID CollectibleLoaderAllocatorUnload(AssemblyLoaderAllocator *pLoaderAllocator) {}; static VOID ModuleLoad(Module *pModule, LONG liReportedSharedModule) {}; #endif // FEATURE_EVENT_TRACE @@ -904,7 +902,7 @@ namespace ETW { friend class ETW::EnumerationLog; #ifdef FEATURE_EVENT_TRACE - static VOID SendEventsForJitMethods(BaseDomain *pDomainFilter, LoaderAllocator *pLoaderAllocatorFilter, DWORD dwEventOptions); + static VOID SendEventsForJitMethods(BOOL getCodeVersionIds, LoaderAllocator *pLoaderAllocatorFilter, DWORD dwEventOptions); static VOID SendEventsForJitMethodsHelper( LoaderAllocator *pLoaderAllocatorFilter, DWORD dwEventOptions, diff --git a/src/coreclr/vm/appdomain.hpp b/src/coreclr/vm/appdomain.hpp index b357f6e1a512a..ef026a3704de7 100644 --- a/src/coreclr/vm/appdomain.hpp +++ b/src/coreclr/vm/appdomain.hpp @@ -2014,7 +2014,7 @@ class SystemDomain : public BaseDomain m_pDelayedUnloadListOfLoaderAllocators=NULL; - m_GlobalAllocator.Init(this); + m_GlobalAllocator.Init(); } #endif @@ -2023,7 +2023,6 @@ class SystemDomain : public BaseDomain GlobalLoaderAllocator m_GlobalAllocator; - InlineSString<100> m_BaseLibrary; InlineSString<100> m_SystemDirectory; diff --git a/src/coreclr/vm/assembly.cpp b/src/coreclr/vm/assembly.cpp index 9c4209c268bcf..bf744fccfb0a9 100644 --- a/src/coreclr/vm/assembly.cpp +++ b/src/coreclr/vm/assembly.cpp @@ -456,7 +456,7 @@ Assembly *Assembly::CreateDynamic(AssemblyBinder* pBinder, NativeAssemblyNamePar // Some of the initialization functions are not virtual. Call through the derived class // to prevent calling the base class version. - pCollectibleLoaderAllocator->Init(pDomain); + pCollectibleLoaderAllocator->Init(); // 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/assemblynative.cpp b/src/coreclr/vm/assemblynative.cpp index 94220a1e35bad..02ba71a51c323 100644 --- a/src/coreclr/vm/assemblynative.cpp +++ b/src/coreclr/vm/assemblynative.cpp @@ -1205,7 +1205,7 @@ extern "C" INT_PTR QCALLTYPE AssemblyNative_InitializeAssemblyLoadContext(INT_PT GCX_PREEMP(); // Some of the initialization functions are not virtual. Call through the derived class // to prevent calling the base class version. - loaderAllocator->Init(pCurDomain); + loaderAllocator->Init(); loaderAllocator->InitVirtualCallStubManager(); // Setup the managed proxy now, but do not actually transfer ownership to it. diff --git a/src/coreclr/vm/corhost.cpp b/src/coreclr/vm/corhost.cpp index 35c724e10a9ca..990eb02b00dc8 100644 --- a/src/coreclr/vm/corhost.cpp +++ b/src/coreclr/vm/corhost.cpp @@ -559,11 +559,11 @@ HRESULT CorHost2::CreateAppDomainWithManager( BEGIN_EXTERNAL_ENTRYPOINT(&hr); - AppDomain* pDomain = SystemDomain::System()->DefaultDomain(); + AppDomain* pDomain = AppDomain::GetCurrentDomain(); pDomain->SetFriendlyName(wszFriendlyName); - ETW::LoaderLog::DomainLoad(pDomain, (LPWSTR)wszFriendlyName); + ETW::LoaderLog::DomainLoad((LPWSTR)wszFriendlyName); if (dwFlags & APPDOMAIN_IGNORE_UNHANDLED_EXCEPTIONS) pDomain->SetIgnoreUnhandledExceptions(); diff --git a/src/coreclr/vm/eventtrace.cpp b/src/coreclr/vm/eventtrace.cpp index 79c3043a24964..4f563dd5b2744 100644 --- a/src/coreclr/vm/eventtrace.cpp +++ b/src/coreclr/vm/eventtrace.cpp @@ -1926,7 +1926,7 @@ VOID ETW::EnumerationLog::ModuleRangeRundown() TRACE_LEVEL_INFORMATION, CLR_PERFTRACK_PRIVATE_KEYWORD)) { - ETW::EnumerationLog::EnumerationHelper(NULL, NULL, ETW::EnumerationLog::EnumerationStructs::ModuleRangeLoadPrivate); + ETW::EnumerationLog::EnumerationHelper(NULL, ETW::EnumerationLog::EnumerationStructs::ModuleRangeLoadPrivate); } } EX_CATCH { } EX_END_CATCH(SwallowAllExceptions); } @@ -2037,7 +2037,7 @@ VOID ETW::EnumerationLog::StartRundown() enumerationOptions |= ETW::EnumerationLog::EnumerationStructs::JittedMethodRichDebugInfo; } - ETW::EnumerationLog::EnumerationHelper(NULL, NULL, enumerationOptions); + ETW::EnumerationLog::EnumerationHelper(NULL, enumerationOptions); if (bIsThreadingRundownEnabled) { @@ -2124,9 +2124,8 @@ VOID ETW::EnumerationLog::EnumerateForCaptureState() { DWORD enumerationOptions = GetEnumerationOptionsFromRuntimeKeywords(); - // Send unload events for all remaining domains, including shared domain and - // default domain. - ETW::EnumerationLog::EnumerationHelper(NULL /* module filter */, NULL /* domain filter */, enumerationOptions); + // Send unload events for all remaining modules + ETW::EnumerationLog::EnumerationHelper(NULL /* module filter */, enumerationOptions); // Send thread created events for all currently active threads, if requested if (ETW_TRACING_CATEGORY_ENABLED(MICROSOFT_WINDOWS_DOTNETRUNTIME_PROVIDER_DOTNET_Context, @@ -2227,7 +2226,7 @@ VOID ETW::EnumerationLog::EndRundown() enumerationOptions |= ETW::EnumerationLog::EnumerationStructs::JittedMethodRichDebugInfo; } - ETW::EnumerationLog::EnumerationHelper(NULL, NULL, enumerationOptions); + ETW::EnumerationLog::EnumerationHelper(NULL, enumerationOptions); if (bIsThreadingRundownEnabled) { @@ -2964,7 +2963,7 @@ VOID ETW::ExceptionLog::ExceptionFilterEnd() /****************************************************************************/ /* This is called by the runtime when a domain is loaded */ /****************************************************************************/ -VOID ETW::LoaderLog::DomainLoadReal(BaseDomain *pDomain, _In_opt_ LPWSTR wszFriendlyName) +VOID ETW::LoaderLog::DomainLoadReal(_In_opt_ LPWSTR wszFriendlyName) { CONTRACTL { NOTHROW; @@ -2978,7 +2977,7 @@ VOID ETW::LoaderLog::DomainLoadReal(BaseDomain *pDomain, _In_opt_ LPWSTR wszFrie CLR_LOADER_KEYWORD)) { DWORD dwEventOptions = ETW::EnumerationLog::EnumerationStructs::DomainAssemblyModuleLoad; - ETW::LoaderLog::SendDomainEvent(pDomain, dwEventOptions, wszFriendlyName); + ETW::LoaderLog::SendDomainEvent(dwEventOptions, wszFriendlyName); } } EX_CATCH { } EX_END_CATCH(SwallowAllExceptions); } @@ -2986,7 +2985,7 @@ VOID ETW::LoaderLog::DomainLoadReal(BaseDomain *pDomain, _In_opt_ LPWSTR wszFrie /****************************************************************************/ /* This is called by the runtime when an AppDomain is unloaded */ /****************************************************************************/ -VOID ETW::LoaderLog::DomainUnload(AppDomain *pDomain) +VOID ETW::LoaderLog::DomainUnload() { CONTRACTL { NOTHROW; @@ -3009,7 +3008,7 @@ VOID ETW::LoaderLog::DomainUnload(AppDomain *pDomain) enumerationOptions |= ETW::EnumerationLog::EnumerationStructs::TypeUnload; } - ETW::EnumerationLog::EnumerationHelper(NULL, pDomain, enumerationOptions); + ETW::EnumerationLog::EnumerationHelper(NULL, enumerationOptions); } } EX_CATCH { } EX_END_CATCH(SwallowAllExceptions); } @@ -3873,7 +3872,7 @@ VOID ETW::LoaderLog::ModuleLoad(Module *pModule, LONG liReportedSharedModule) if(bTraceFlagLoaderSet || bTraceFlagPerfTrackSet) ETW::LoaderLog::SendModuleEvent(pModule, ETW::EnumerationLog::EnumerationStructs::DomainAssemblyModuleLoad | ETW::EnumerationLog::EnumerationStructs::ModuleRangeLoad); - ETW::EnumerationLog::EnumerationHelper(pModule, NULL, enumerationOptions); + ETW::EnumerationLog::EnumerationHelper(pModule, enumerationOptions); } // we want to report domainmodule events whenever they are loaded in any AppDomain @@ -3910,9 +3909,8 @@ VOID ETW::EnumerationLog::ProcessShutdown() { DWORD enumerationOptions = GetEnumerationOptionsFromRuntimeKeywords(); - // Send unload events for all remaining domains, including shared domain and - // default domain. - ETW::EnumerationLog::EnumerationHelper(NULL /* module filter */, NULL /* domain filter */, enumerationOptions); + // Send unload events for all remaining modules + ETW::EnumerationLog::EnumerationHelper(NULL /* module filter */, enumerationOptions); } } EX_CATCH { } EX_END_CATCH(SwallowAllExceptions); } @@ -3926,20 +3924,20 @@ VOID ETW::EnumerationLog::ProcessShutdown() /****************************************************************************/ /* This routine is used to send a domain load/unload or rundown event */ /****************************************************************************/ -VOID ETW::LoaderLog::SendDomainEvent(BaseDomain *pBaseDomain, DWORD dwEventOptions, LPCWSTR wszFriendlyName) +VOID ETW::LoaderLog::SendDomainEvent(DWORD dwEventOptions, LPCWSTR wszFriendlyName) { CONTRACTL { THROWS; GC_TRIGGERS; + PRECONDITION(AppDomain::GetCurrentDomain() != NULL); } CONTRACTL_END; - if(!pBaseDomain) - return; + AppDomain* pDomain = AppDomain::GetCurrentDomain(); PCWSTR szDtraceOutput1=W(""); - BOOL bIsAppDomain = pBaseDomain->IsAppDomain(); + BOOL bIsAppDomain = TRUE; - ULONGLONG ullDomainId = (ULONGLONG)pBaseDomain; + ULONGLONG ullDomainId = (ULONGLONG)pDomain; ULONG ulDomainFlags = ETW::LoaderLog::LoaderStructs::DefaultDomain | ETW::LoaderLog::LoaderStructs::ExecutableDomain; LPCWSTR wsEmptyString = W(""); @@ -3949,7 +3947,7 @@ VOID ETW::LoaderLog::SendDomainEvent(BaseDomain *pBaseDomain, DWORD dwEventOptio if(wszFriendlyName) lpswzDomainName = (PWCHAR)wszFriendlyName; else - lpswzDomainName = (PWCHAR)pBaseDomain->AsAppDomain()->GetFriendlyName(); + lpswzDomainName = (PWCHAR)pDomain->GetFriendlyName(); /* prepare events args for ETW and ETM */ szDtraceOutput1 = (PCWSTR)lpswzDomainName; @@ -5238,12 +5236,9 @@ VOID ETW::MethodLog::SendEventsForJitMethodsHelper(LoaderAllocator *pLoaderAlloc /****************************************************************************/ /* This routine sends back method events of type 'dwEventOptions', for all JITed methods in either a given LoaderAllocator (if pLoaderAllocatorFilter is non NULL) - or in a given Domain (if pDomainFilter is non NULL) or for - all methods (if both filters are null) */ + or all methods (if pLoaderAllocatorFilter is null) */ /****************************************************************************/ -// Code review indicates this method is never called with both filters NULL. Ideally we would -// assert this and change the comment above, but given I am making a change late in the release I am being cautious -VOID ETW::MethodLog::SendEventsForJitMethods(BaseDomain *pDomainFilter, LoaderAllocator *pLoaderAllocatorFilter, DWORD dwEventOptions) +VOID ETW::MethodLog::SendEventsForJitMethods(BOOL getCodeVersionIds, LoaderAllocator *pLoaderAllocatorFilter, DWORD dwEventOptions) { CONTRACTL { NOTHROW; @@ -5303,9 +5298,8 @@ VOID ETW::MethodLog::SendEventsForJitMethods(BaseDomain *pDomainFilter, LoaderAl // table lock that corresponds to the domain or module we're currently iterating over. // - // We only support getting rejit IDs when filtering by domain. #ifdef FEATURE_CODE_VERSIONING - if (pDomainFilter) + if (getCodeVersionIds) { CodeVersionManager::LockHolder codeVersioningLockHolder; SendEventsForJitMethodsHelper( @@ -5337,21 +5331,24 @@ VOID ETW::MethodLog::SendEventsForJitMethods(BaseDomain *pDomainFilter, LoaderAl //--------------------------------------------------------------------------------------- // -// Wrapper around IterateDomain, which locks the AppDomain to be < -// STAGE_FINALIZED until the iteration is complete. +// This routine fires ETW events for +// Domain +// Assemblies in them +// Modules in them +// JIT methods in them +// R2R methods in them +// based on enumeration options // // Arguments: -// pAppDomain - AppDomain to iterate -// enumerationOptions - Flags indicating what to enumerate. Just passed -// straight through to IterateDomain +// enumerationOptions - Flags indicating what to enumerate. // -VOID ETW::EnumerationLog::IterateAppDomain(AppDomain * pAppDomain, DWORD enumerationOptions) +VOID ETW::EnumerationLog::IterateAppDomain(DWORD enumerationOptions) { CONTRACTL { THROWS; GC_TRIGGERS; - PRECONDITION(pAppDomain != NULL); + PRECONDITION(AppDomain::GetCurrentDomain() != NULL); } CONTRACTL_END; @@ -5359,54 +5356,22 @@ VOID ETW::EnumerationLog::IterateAppDomain(AppDomain * pAppDomain, DWORD enumera // ensure the App Domain does not get finalized until we're all done SystemDomain::LockHolder lh; - // Now it's safe to do the iteration - IterateDomain(pAppDomain, enumerationOptions); -} - -/********************************************************************************/ -/* This routine fires ETW events for - Domain, - Assemblies in them, - DomainModule's in them, - Modules in them, - JIT methods in them, - and the NGEN methods in them - based on enumerationOptions.*/ -/********************************************************************************/ -VOID ETW::EnumerationLog::IterateDomain(BaseDomain *pDomain, DWORD enumerationOptions) -{ - CONTRACTL { - THROWS; - GC_TRIGGERS; - PRECONDITION(pDomain != NULL); - } CONTRACTL_END; - -#if defined(_DEBUG) && !defined(DACCESS_COMPILE) - // Do not call IterateDomain() directly with an AppDomain. Use - // IterateAppDomain(), which wraps this function with a hold on the - // SystemDomain lock, which ensures pDomain's type data doesn't disappear - // on us. - if (pDomain->IsAppDomain()) - { - _ASSERTE(SystemDomain::IsUnderDomainLock()); - } -#endif // defined(_DEBUG) && !defined(DACCESS_COMPILE) - + AppDomain* pDomain = AppDomain::GetCurrentDomain(); EX_TRY { // DC Start events for Domain if(enumerationOptions & ETW::EnumerationLog::EnumerationStructs::DomainAssemblyModuleDCStart) { - ETW::LoaderLog::SendDomainEvent(pDomain, enumerationOptions); + ETW::LoaderLog::SendDomainEvent(enumerationOptions); } // DC End or Unload Jit Method events if (enumerationOptions & ETW::EnumerationLog::EnumerationStructs::JitMethodUnloadOrDCEndAny) { - ETW::MethodLog::SendEventsForJitMethods(pDomain, NULL, enumerationOptions); + ETW::MethodLog::SendEventsForJitMethods(TRUE /*getCodeVersionIds*/, NULL, enumerationOptions); } - AppDomain::AssemblyIterator assemblyIterator = pDomain->AsAppDomain()->IterateAssembliesEx( + AppDomain::AssemblyIterator assemblyIterator = pDomain->IterateAssembliesEx( (AssemblyIterationFlags)(kIncludeLoaded | kIncludeExecution)); CollectibleAssemblyHolder pDomainAssembly; while (assemblyIterator.Next(pDomainAssembly.This())) @@ -5430,14 +5395,14 @@ VOID ETW::EnumerationLog::IterateDomain(BaseDomain *pDomain, DWORD enumerationOp // DC Start or Load Jit Method events if (enumerationOptions & ETW::EnumerationLog::EnumerationStructs::JitMethodLoadOrDCStartAny) { - ETW::MethodLog::SendEventsForJitMethods(pDomain, NULL, enumerationOptions); + ETW::MethodLog::SendEventsForJitMethods(TRUE /*getCodeVersionIds*/, NULL, enumerationOptions); } // DC End or Unload events for Domain if((enumerationOptions & ETW::EnumerationLog::EnumerationStructs::DomainAssemblyModuleDCEnd) || (enumerationOptions & ETW::EnumerationLog::EnumerationStructs::DomainAssemblyModuleUnload)) { - ETW::LoaderLog::SendDomainEvent(pDomain, enumerationOptions); + ETW::LoaderLog::SendDomainEvent(enumerationOptions); } } EX_CATCH { } EX_END_CATCH(SwallowAllExceptions); } @@ -5465,7 +5430,7 @@ VOID ETW::EnumerationLog::IterateCollectibleLoaderAllocator(AssemblyLoaderAlloca // Unload Jit Method events if (enumerationOptions & ETW::EnumerationLog::EnumerationStructs::JitMethodUnload) { - ETW::MethodLog::SendEventsForJitMethods(NULL, pLoaderAllocator, enumerationOptions); + ETW::MethodLog::SendEventsForJitMethods(FALSE /*getCodeVersionIds*/, pLoaderAllocator, enumerationOptions); } // Iterate on all DomainAssembly loaded from the same AssemblyLoaderAllocator @@ -5488,7 +5453,7 @@ VOID ETW::EnumerationLog::IterateCollectibleLoaderAllocator(AssemblyLoaderAlloca // Load Jit Method events if (enumerationOptions & ETW::EnumerationLog::EnumerationStructs::JitMethodLoad) { - ETW::MethodLog::SendEventsForJitMethods(NULL, pLoaderAllocator, enumerationOptions); + ETW::MethodLog::SendEventsForJitMethods(FALSE /*getCodeVersionIds*/, pLoaderAllocator, enumerationOptions); } } EX_CATCH { } EX_END_CATCH(SwallowAllExceptions); } @@ -5593,17 +5558,12 @@ VOID ETW::EnumerationLog::IterateModule(Module *pModule, DWORD enumerationOption // // Arguments: // * moduleFilter - if non-NULL, events from only moduleFilter module are reported -// * domainFilter - if non-NULL, events from only domainFilter domain are reported // * enumerationOptions - Flags from ETW::EnumerationLog::EnumerationStructs which // describe which events should be sent. // -// Notes: -// * if all filter args are NULL, events from all domains are reported -// -// // static -VOID ETW::EnumerationLog::EnumerationHelper(Module *moduleFilter, BaseDomain *domainFilter, DWORD enumerationOptions) +VOID ETW::EnumerationLog::EnumerationHelper(Module *moduleFilter, DWORD enumerationOptions) { CONTRACTL { THROWS; @@ -5625,36 +5585,18 @@ VOID ETW::EnumerationLog::EnumerationHelper(Module *moduleFilter, BaseDomain *do // DC End or Unload Jit Method events from all Domains if (enumerationOptions & ETW::EnumerationLog::EnumerationStructs::JitMethodUnloadOrDCEndAny) { - ETW::MethodLog::SendEventsForJitMethods(NULL, NULL, enumerationOptions); + ETW::MethodLog::SendEventsForJitMethods(FALSE /*getCodeVersionIds*/, NULL, enumerationOptions); } // DC Start or Load Jit Method events from all Domains if (enumerationOptions & ETW::EnumerationLog::EnumerationStructs::JitMethodLoadOrDCStartAny) { - ETW::MethodLog::SendEventsForJitMethods(NULL, NULL, enumerationOptions); + ETW::MethodLog::SendEventsForJitMethods(FALSE /*getCodeVersionIds*/, NULL, enumerationOptions); } } else { - if(domainFilter) - { - if(domainFilter->IsAppDomain()) - { - ETW::EnumerationLog::IterateAppDomain(domainFilter->AsAppDomain(), enumerationOptions); - } - else - { - ETW::EnumerationLog::IterateDomain(domainFilter, enumerationOptions); - } - } - else - { - AppDomain *pDomain = AppDomain::GetCurrentDomain(); - if (pDomain != NULL) - { - ETW::EnumerationLog::IterateAppDomain(pDomain, enumerationOptions); - } - } + ETW::EnumerationLog::IterateAppDomain(enumerationOptions); } } diff --git a/src/coreclr/vm/loaderallocator.cpp b/src/coreclr/vm/loaderallocator.cpp index ff6506b76292a..dde9db0f76a00 100644 --- a/src/coreclr/vm/loaderallocator.cpp +++ b/src/coreclr/vm/loaderallocator.cpp @@ -62,7 +62,6 @@ LoaderAllocator::LoaderAllocator(bool collectible) : m_fUnloaded = false; m_fMarked = false; m_pLoaderAllocatorDestroyNext = NULL; - m_pDomain = NULL; m_pCodeHeapInitialAlloc = NULL; m_pVSDHeapInitialAlloc = NULL; m_pLastUsedCodeHeap = NULL; @@ -506,13 +505,16 @@ void LoaderAllocator::GCLoaderAllocators(LoaderAllocator* pOriginalLoaderAllocat THROWS; GC_TRIGGERS; MODE_PREEMPTIVE; + PRECONDITION(pOriginalLoaderAllocator != NULL); + PRECONDITION(pOriginalLoaderAllocator->IsCollectible()); + PRECONDITION(pOriginalLoaderAllocator->Id()->GetType() == LAT_Assembly); } CONTRACTL_END; // List of LoaderAllocators being deleted LoaderAllocator * pFirstDestroyedLoaderAllocator = NULL; - AppDomain* pAppDomain = (AppDomain*)pOriginalLoaderAllocator->GetDomain(); + AppDomain* pAppDomain = AppDomain::GetCurrentDomain(); // Collect all LoaderAllocators that don't have anymore DomainAssemblies alive // Note: that it may not collect our pOriginalLoaderAllocator in case this @@ -1059,12 +1061,10 @@ void LoaderAllocator::ActivateManagedTracking() #define COLLECTIBLE_CODEHEAP_SIZE (10 * GetOsPageSize()) #define COLLECTIBLE_VIRTUALSTUBDISPATCH_HEAP_SPACE (2 * GetOsPageSize()) -void LoaderAllocator::Init(BaseDomain *pDomain, BYTE *pExecutableHeapMemory) +void LoaderAllocator::Init(BYTE *pExecutableHeapMemory) { STANDARD_VM_CONTRACT; - m_pDomain = pDomain; - m_crstLoaderAllocator.Init(CrstLoaderAllocator, (CrstFlags)CRST_UNSAFE_COOPGC); m_crstLoaderAllocatorHandleTable.Init(CrstLeafLock, (CrstFlags)CRST_UNSAFE_COOPGC); m_InteropDataCrst.Init(CrstInteropData, CRST_REENTRANCY); @@ -1446,7 +1446,6 @@ void LoaderAllocator::Terminate() m_pFuncPtrStubs = NULL; } - // This was the block reserved by BaseDomain::Init for the loaderheaps. if (m_InitialReservedMemForLoaderHeaps) { ExecutableAllocator::Instance()->Release(m_InitialReservedMemForLoaderHeaps); @@ -1725,7 +1724,7 @@ void DomainAssemblyIterator::operator++() #ifndef DACCESS_COMPILE -void AssemblyLoaderAllocator::Init(AppDomain* pAppDomain) +void AssemblyLoaderAllocator::Init() { m_Id.Init(); @@ -1733,7 +1732,7 @@ void AssemblyLoaderAllocator::Init(AppDomain* pAppDomain) // GC mode, in case the caller requires that m_dependentHandleToNativeObjectSetCrst.Init(CrstLeafLock, CRST_UNSAFE_ANYMODE); - LoaderAllocator::Init((BaseDomain *)pAppDomain); + LoaderAllocator::Init(NULL /*pExecutableHeapMemory*/); if (IsCollectible()) { // TODO: the ShuffleThunkCache should really be using the m_pStubHeap, however the unloadability support @@ -1933,10 +1932,11 @@ void AssemblyLoaderAllocator::CleanupHandles() NOTHROW; MODE_ANY; CAN_TAKE_LOCK; + PRECONDITION(IsCollectible()); + PRECONDITION(Id()->GetType() == LAT_Assembly); } CONTRACTL_END; - _ASSERTE(GetDomain()->IsAppDomain()); if (m_hLoaderAllocatorObjectHandle != NULL) { @@ -2058,12 +2058,12 @@ void LoaderAllocator::CleanupFailedTypeInit() return; } - _ASSERTE(GetDomain()->IsAppDomain()); + _ASSERTE(Id()->GetType() == LAT_Assembly); // This method doesn't take a lock around loader allocator state access, because // it's supposed to be called only during cleanup. However, the domain-level state // might be accessed by multiple threads. - ListLock *pLock = ((AppDomain*)GetDomain())->GetClassInitLock(); + ListLock *pLock = AppDomain::GetCurrentDomain()->GetClassInitLock(); while (!m_failedTypeInitCleanupList.IsEmpty()) { diff --git a/src/coreclr/vm/loaderallocator.hpp b/src/coreclr/vm/loaderallocator.hpp index 82f24813cb8d1..6b3b63301cec9 100644 --- a/src/coreclr/vm/loaderallocator.hpp +++ b/src/coreclr/vm/loaderallocator.hpp @@ -360,8 +360,6 @@ class LoaderAllocator BYTE *GetVSDHeapInitialBlock(DWORD *pSize); BYTE *GetCodeHeapInitialBlock(const BYTE * loAddr, const BYTE * hiAddr, DWORD minimumSize, DWORD *pSize); - BaseDomain *m_pDomain; - // ExecutionManager caches void * m_pLastUsedCodeHeap; void * m_pLastUsedDynamicCodeHeap; @@ -735,9 +733,8 @@ class LoaderAllocator LoaderAllocator(bool collectible); virtual ~LoaderAllocator(); - BaseDomain *GetDomain() { LIMITED_METHOD_CONTRACT; return m_pDomain; } virtual BOOL CanUnload() = 0; - void Init(BaseDomain *pDomain, BYTE *pExecutableHeapMemory = NULL); + void Init(BYTE *pExecutableHeapMemory); void Terminate(); virtual void ReleaseManagedAssemblyLoadContext() {} @@ -887,7 +884,7 @@ class GlobalLoaderAllocator : public LoaderAllocator LoaderAllocatorID m_Id; public: - void Init(BaseDomain *pDomain); + void Init(); GlobalLoaderAllocator() : LoaderAllocator(false), m_Id(LAT_Global, (void*)1) { LIMITED_METHOD_CONTRACT;}; virtual LoaderAllocatorID* Id(); virtual BOOL CanUnload(); @@ -913,7 +910,7 @@ class AssemblyLoaderAllocator : public LoaderAllocator , m_binderToRelease(NULL) #endif { LIMITED_METHOD_CONTRACT; } - void Init(AppDomain *pAppDomain); + void Init(); virtual BOOL CanUnload(); void AddDomainAssembly(DomainAssembly *pDomainAssembly) diff --git a/src/coreclr/vm/loaderallocator.inl b/src/coreclr/vm/loaderallocator.inl index d839a4632277f..195ad5ca02f92 100644 --- a/src/coreclr/vm/loaderallocator.inl +++ b/src/coreclr/vm/loaderallocator.inl @@ -24,9 +24,9 @@ inline bool LoaderAllocator::IsExposedObjectLive() return !ObjectHandleIsNull(m_hLoaderAllocatorObjectHandle); } -inline void GlobalLoaderAllocator::Init(BaseDomain *pDomain) +inline void GlobalLoaderAllocator::Init() { - LoaderAllocator::Init(pDomain, m_ExecutableHeapInstance); + LoaderAllocator::Init(m_ExecutableHeapInstance); } inline BOOL LoaderAllocatorID::Equals(LoaderAllocatorID *pId)