Skip to content

Commit

Permalink
Remove BaseDomain use in LoaderAllocator and event tracing helpers (
Browse files Browse the repository at this point in the history
dotnet#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
  • Loading branch information
elinor-fung committed Sep 9, 2024
1 parent 62133e0 commit 2fb3629
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 138 deletions.
22 changes: 10 additions & 12 deletions src/coreclr/inc/eventtracebase.h
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,6 @@ class Module;
class Assembly;
class MethodDesc;
class MethodTable;
class BaseDomain;
class AppDomain;
class SString;
class CrawlFrame;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions src/coreclr/vm/appdomain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2014,7 +2014,7 @@ class SystemDomain : public BaseDomain

m_pDelayedUnloadListOfLoaderAllocators=NULL;

m_GlobalAllocator.Init(this);
m_GlobalAllocator.Init();
}
#endif

Expand All @@ -2023,7 +2023,6 @@ class SystemDomain : public BaseDomain

GlobalLoaderAllocator m_GlobalAllocator;


InlineSString<100> m_BaseLibrary;

InlineSString<100> m_SystemDirectory;
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 @@ -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
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 @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/vm/corhost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading

0 comments on commit 2fb3629

Please sign in to comment.