From 0c33c6f384bad6cdeb302d30f7b2ebbc6401d99f Mon Sep 17 00:00:00 2001 From: Elinor Fung Date: Mon, 9 Sep 2024 08:21:16 -0700 Subject: [PATCH] Fix module being set as tenured too early (#107489) --- src/coreclr/vm/appdomain.cpp | 5 +++++ src/coreclr/vm/assembly.cpp | 1 + src/coreclr/vm/domainassembly.cpp | 1 - 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/coreclr/vm/appdomain.cpp b/src/coreclr/vm/appdomain.cpp index 8d3395cd8ebbd..4478a450df9d5 100644 --- a/src/coreclr/vm/appdomain.cpp +++ b/src/coreclr/vm/appdomain.cpp @@ -2481,6 +2481,9 @@ DomainAssembly *AppDomain::LoadDomainAssemblyInternal(AssemblySpec* pIdentity, fileLock = FileLoadLock::Create(lock, pPEAssembly, pDomainAssembly); pDomainAssembly.SuppressRelease(); pamTracker->SuppressRelease(); + + // Set the assembly module to be tenured now that we know it won't be deleted + pDomainAssembly->GetAssembly()->SetIsTenured(); if (pDomainAssembly->IsCollectible()) { // We add the assembly to the LoaderAllocator only when we are sure that it can be added @@ -2516,7 +2519,9 @@ DomainAssembly *AppDomain::LoadDomainAssemblyInternal(AssemblySpec* pIdentity, } } else + { result->EnsureLoadLevel(targetLevel); + } // Cache result in all cases, since found pPEAssembly could be from a different AssemblyRef than pIdentity if (pIdentity == NULL) diff --git a/src/coreclr/vm/assembly.cpp b/src/coreclr/vm/assembly.cpp index bf744fccfb0a9..0d344df01297b 100644 --- a/src/coreclr/vm/assembly.cpp +++ b/src/coreclr/vm/assembly.cpp @@ -531,6 +531,7 @@ Assembly *Assembly::CreateDynamic(AssemblyBinder* pBinder, NativeAssemblyNamePar pLoaderAllocator.SuppressRelease(); } + // Set the assembly module to be tenured now that we know it won't be deleted pAssem->SetIsTenured(); pRetVal = pAssem; } diff --git a/src/coreclr/vm/domainassembly.cpp b/src/coreclr/vm/domainassembly.cpp index 5827236697166..64fb98569f10f 100644 --- a/src/coreclr/vm/domainassembly.cpp +++ b/src/coreclr/vm/domainassembly.cpp @@ -56,7 +56,6 @@ DomainAssembly::DomainAssembly(PEAssembly* pPEAssembly, LoaderAllocator* pLoader // Create the Assembly NewHolder assembly = Assembly::Create(GetPEAssembly(), GetDebuggerInfoBits(), IsCollectible(), memTracker, IsCollectible() ? GetLoaderAllocator() : NULL); - assembly->SetIsTenured(); m_pAssembly = assembly.Extract(); m_pModule = m_pAssembly->GetModule();