From 62947562bb27e14d7489be004590f8f7c1ca0e76 Mon Sep 17 00:00:00 2001 From: Gleb Balykov Date: Tue, 5 Apr 2022 13:03:17 +0300 Subject: [PATCH] Check MultiCoreJit code cache before trying to jit method in mcj thread This is needed when multiple profiles are played and same methods exist in them. Without this change, if method was not yet requested in main thread, it will be jitted as many times in mcj thread as it appears in all profiles. --- src/coreclr/vm/multicorejit.h | 2 ++ src/coreclr/vm/multicorejitplayer.cpp | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/coreclr/vm/multicorejit.h b/src/coreclr/vm/multicorejit.h index 58656ec..39f6f1c 100644 --- a/src/coreclr/vm/multicorejit.h +++ b/src/coreclr/vm/multicorejit.h @@ -165,6 +165,8 @@ public: void StoreMethodCode(MethodDesc * pMethod, MulticoreJitCodeInfo codeInfo); + bool LookupMethodCode(MethodDesc * pMethod); + MulticoreJitCodeInfo QueryAndRemoveMethodCode(MethodDesc * pMethod); inline unsigned GetRemainingMethodCount() const diff --git a/src/coreclr/vm/multicorejitplayer.cpp b/src/coreclr/vm/multicorejitplayer.cpp index a26e981..0094ba0 100644 --- a/src/coreclr/vm/multicorejitplayer.cpp +++ b/src/coreclr/vm/multicorejitplayer.cpp @@ -104,6 +104,20 @@ void MulticoreJitCodeStorage::StoreMethodCode(MethodDesc * pMD, MulticoreJitCode } +// Check if method is already compiled and stored +bool MulticoreJitCodeStorage::LookupMethodCode(MethodDesc * pMethod) +{ + STANDARD_VM_CONTRACT; + + MulticoreJitCodeInfo codeInfo; + + { + CrstHolder holder(& m_crstCodeMap); + return m_nativeCodeMap.Lookup(pMethod, &codeInfo); + } +} + + // Query from MakeJitWorker: Lookup stored JITted methods MulticoreJitCodeInfo MulticoreJitCodeStorage::QueryAndRemoveMethodCode(MethodDesc * pMethod) { @@ -979,7 +993,7 @@ void MulticoreJitProfilePlayer::CompileMethodInfoRecord(Module *pModule, MethodD } } - if (pMethod->GetNativeCode() == NULL) + if (pMethod->GetNativeCode() == NULL && !GetAppDomain()->GetMulticoreJitManager().GetMulticoreJitCodeStorage().LookupMethodCode(pMethod)) { if (CompileMethodDesc(pModule, pMethod)) { -- 2.7.4