From 4e9ff76d3bc5cd04e2413105f867239b3e694b37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Rylek?= Date: Fri, 4 Mar 2022 11:51:57 +0100 Subject: Only register composite R2R native image code range once (#65623) As David Wrighton noticed during an independent investigation, today CoreCLR runtime logic ends up registering composite image code range with the execution manager the number of times equal to the number of component modules of the composite image accessed at runtime, i.e. ultimately up to over 200 times in case of the composite framework. This change fixes that by slightly shuffling the initialization housekeeping chores. Thanks Tomas Fixes: https://github.com/dotnet/runtime/issues/65481 --- src/coreclr/inc/CrstTypes.def | 1 + src/coreclr/inc/crsttypes.h | 2 +- src/coreclr/vm/ceeload.cpp | 8 ++++++++ src/coreclr/vm/domainassembly.cpp | 8 -------- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/coreclr/inc/CrstTypes.def b/src/coreclr/inc/CrstTypes.def index 0335e4965f1..279118f3012 100644 --- a/src/coreclr/inc/CrstTypes.def +++ b/src/coreclr/inc/CrstTypes.def @@ -206,6 +206,7 @@ Crst ExecutableAllocatorLock End Crst ExecuteManRangeLock + AcquiredAfter NativeImageEagerFixups End Crst FCall diff --git a/src/coreclr/inc/crsttypes.h b/src/coreclr/inc/crsttypes.h index d462cbd3c88..815b2636466 100644 --- a/src/coreclr/inc/crsttypes.h +++ b/src/coreclr/inc/crsttypes.h @@ -216,7 +216,7 @@ int g_rgCrstLevelMap[] = 4, // CrstModuleLookupTable 0, // CrstMulticoreJitHash 13, // CrstMulticoreJitManager - 0, // CrstNativeImageEagerFixups + 3, // CrstNativeImageEagerFixups 0, // CrstNativeImageLoad 0, // CrstNls 0, // CrstNotifyGdb diff --git a/src/coreclr/vm/ceeload.cpp b/src/coreclr/vm/ceeload.cpp index c48f2fcb596..aeb4868ee2a 100644 --- a/src/coreclr/vm/ceeload.cpp +++ b/src/coreclr/vm/ceeload.cpp @@ -4703,6 +4703,14 @@ void Module::RunEagerFixupsUnlocked() } } } + + TADDR base = dac_cast(pNativeImage->GetBase()); + + ExecutionManager::AddCodeRange( + base, base + (TADDR)pNativeImage->GetVirtualSize(), + ExecutionManager::GetReadyToRunJitManager(), + RangeSection::RANGE_SECTION_READYTORUN, + this /* pHeapListOrZapModule */); } #endif // !DACCESS_COMPILE diff --git a/src/coreclr/vm/domainassembly.cpp b/src/coreclr/vm/domainassembly.cpp index b8b19bb08b1..47c0fd53a74 100644 --- a/src/coreclr/vm/domainassembly.cpp +++ b/src/coreclr/vm/domainassembly.cpp @@ -532,14 +532,6 @@ void DomainAssembly::EagerFixups() { GetModule()->RunEagerFixups(); - PEImageLayout * pLayout = GetModule()->GetReadyToRunInfo()->GetImage(); - - TADDR base = dac_cast(pLayout->GetBase()); - - ExecutionManager::AddCodeRange(base, base + (TADDR)pLayout->GetVirtualSize(), - ExecutionManager::GetReadyToRunJitManager(), - RangeSection::RANGE_SECTION_READYTORUN, - GetModule() /* (void *)pLayout */); } #endif // FEATURE_READYTORUN } -- cgit v1.2.3