From 0d2befb308682e28d2a178891ff413f690b83f66 Mon Sep 17 00:00:00 2001 From: Woongsuk Cho Date: Thu, 7 Jul 2022 16:13:07 +0900 Subject: [PATCH] Re-create profile data on profile-use-only mode Activate multicorejit recorder to re-create the profile data when the multicorejit player cannot be executed due to BADIMAGEFORMAT error on profile-use-only mode --- src/coreclr/vm/multicorejit.cpp | 12 +++++------- src/coreclr/vm/multicorejitimpl.h | 18 +++++++++--------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/coreclr/vm/multicorejit.cpp b/src/coreclr/vm/multicorejit.cpp index 380a007c78085..a1821efcaf411 100644 --- a/src/coreclr/vm/multicorejit.cpp +++ b/src/coreclr/vm/multicorejit.cpp @@ -1202,16 +1202,13 @@ void MulticoreJitManager::StartProfile(AppDomain * pDomain, ICLRPrivBinder *pBin if ((pProfile != NULL) && (pProfile[0] != 0)) // Ignore empty file name, just same as StopProfile { - bool gatherProfile = (int)CLRConfig::GetConfigValue(CLRConfig::INTERNAL_MultiCoreJitNoProfileGather) == 0; - MulticoreJitRecorder * pRecorder = new (nothrow) MulticoreJitRecorder( pDomain, - pBinderContext, - gatherProfile); + pBinderContext); if (pRecorder != NULL) { - gatherProfile = pRecorder->CanGatherProfile(); + bool gatherProfile = (int)CLRConfig::GetConfigValue(CLRConfig::INTERNAL_MultiCoreJitNoProfileGather) == 0; m_pMulticoreJitRecorder = pRecorder; @@ -1221,9 +1218,10 @@ void MulticoreJitManager::StartProfile(AppDomain * pDomain, ICLRPrivBinder *pBin MulticoreJitTrace(("MulticoreJitRecorder session %d created: %x", sessionID, hr)); - if ((hr == COR_E_BADIMAGEFORMAT) || SUCCEEDED(hr)) // Ignore COR_E_BADIMAGEFORMAT, always record new profile + if ((hr == COR_E_BADIMAGEFORMAT) || (SUCCEEDED(hr) && gatherProfile)) // Ignore COR_E_BADIMAGEFORMAT, always record new profile { - m_fRecorderActive = gatherProfile; + m_pMulticoreJitRecorder->Activate(); + m_fRecorderActive = m_pMulticoreJitRecorder->CanGatherProfile(); } _FireEtwMulticoreJit(W("STARTPROFILE"), W("Recorder"), m_fRecorderActive, hr, 0); diff --git a/src/coreclr/vm/multicorejitimpl.h b/src/coreclr/vm/multicorejitimpl.h index d1f05816788f2..3a0d3b4eed060 100644 --- a/src/coreclr/vm/multicorejitimpl.h +++ b/src/coreclr/vm/multicorejitimpl.h @@ -655,7 +655,7 @@ class MulticoreJitRecorder public: - MulticoreJitRecorder(AppDomain * pDomain, ICLRPrivBinder * pBinderContext, bool fRecorderActive) + MulticoreJitRecorder(AppDomain * pDomain, ICLRPrivBinder * pBinderContext) : m_stats(pDomain->GetMulticoreJitManager().GetStats()) , m_ModuleList(nullptr) , m_JitInfoArray(nullptr) @@ -665,18 +665,10 @@ class MulticoreJitRecorder m_pDomain = pDomain; m_pBinderContext = pBinderContext; - if (fRecorderActive) - { - m_ModuleList = new (nothrow) RecorderModuleInfo[MAX_MODULES]; - } m_ModuleCount = 0; m_ModuleDepCount = 0; - if (fRecorderActive) - { - m_JitInfoArray = new (nothrow) RecorderInfo[MAX_METHODS]; - } m_JitInfoCount = 0; m_fFirstMethod = true; @@ -726,6 +718,14 @@ class MulticoreJitRecorder (m_ModuleCount >= MAX_MODULES); } + void Activate() + { + LIMITED_METHOD_CONTRACT; + + m_ModuleList = new (nothrow) RecorderModuleInfo[MAX_MODULES]; + m_JitInfoArray = new (nothrow) RecorderInfo[MAX_METHODS]; + } + void RecordMethodJitOrLoad(MethodDesc * pMethod, bool application); MulticoreJitCodeInfo RequestMethodCode(MethodDesc * pMethod, MulticoreJitManager * pManager);