Check MultiCoreJit code cache before trying to jit method in mcj thread
authorGleb Balykov <g.balykov@samsung.com>
Tue, 5 Apr 2022 10:03:17 +0000 (13:03 +0300)
committerGleb Balykov <g.balykov@samsung.com>
Tue, 27 Sep 2022 12:50:22 +0000 (15:50 +0300)
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 58656ec..39f6f1c 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 a26e981..0094ba0 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)
 {
@@ -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))
             {