Check MultiCoreJit code cache before trying to jit method in mcj thread (#67579)
authorGleb Balykov <g.balykov@samsung.com>
Sat, 23 Apr 2022 20:19:34 +0000 (23:19 +0300)
committerGitHub <noreply@github.com>
Sat, 23 Apr 2022 20:19:34 +0000 (13:19 -0700)
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
src/coreclr/vm/multicorejitplayer.cpp

index f4e38c6..7a61c22 100644 (file)
@@ -165,6 +165,8 @@ public:
 
     void StoreMethodCode(MethodDesc * pMethod, MulticoreJitCodeInfo codeInfo);
 
+    bool LookupMethodCode(MethodDesc * pMethod);
+
     MulticoreJitCodeInfo QueryAndRemoveMethodCode(MethodDesc * pMethod);
 
     inline unsigned GetRemainingMethodCount() const
index 7aae1da..7e65ecb 100644 (file)
@@ -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)
 {
@@ -958,7 +972,7 @@ void MulticoreJitProfilePlayer::CompileMethodInfoRecord(Module *pModule, MethodD
             }
         }
 
-        if (pMethod->GetNativeCode() == NULL)
+        if (pMethod->GetNativeCode() == NULL && !GetAppDomain()->GetMulticoreJitManager().GetMulticoreJitCodeStorage().LookupMethodCode(pMethod))
         {
             if (CompileMethodDesc(pModule, pMethod))
             {