Fix shutdown A/V issue when IBC logging with the Music Store app
authorBrian Sullivan <briansul@microsoft.com>
Fri, 7 Apr 2017 00:36:15 +0000 (17:36 -0700)
committerBrian Sullivan <briansul@microsoft.com>
Fri, 7 Apr 2017 00:36:15 +0000 (17:36 -0700)
This app continues to run managed code on other threads after the Main thread exits and enters shutdown.
We now block IBC logging during the time that we are writing out the IBC data.

Commit migrated from https://github.com/dotnet/coreclr/commit/ded541455690dbd7707ed281388bcaa314c76f9f

src/coreclr/src/vm/ceeload.cpp
src/coreclr/src/vm/ceemain.cpp

index 0845d86..5de7114 100644 (file)
@@ -3586,8 +3586,21 @@ void Module::StartUnload()
     }
 #endif // PROFILING_SUPPORTED
 #ifdef FEATURE_PREJIT 
-    // Write out the method profile data
-    /*hr=*/WriteMethodProfileDataLogFile(true);
+    if (g_IBCLogger.InstrEnabled())
+    {
+        Thread * pThread = GetThread();
+        ThreadLocalIBCInfo* pInfo = pThread->GetIBCInfo();
+
+        // Acquire the Crst lock before creating the IBCLoggingDisabler object.
+        // Only one thread at a time can be processing an IBC logging event.
+        CrstHolder lock(g_IBCLogger.GetSync());
+        {
+            IBCLoggingDisabler disableLogging( pInfo );  // runs IBCLoggingDisabler::DisableLogging
+
+            // Write out the method profile data
+            /*hr=*/WriteMethodProfileDataLogFile(true);
+        }
+    }
 #endif // FEATURE_PREJIT
     SetBeingUnloaded();
 }
index dd8438e..522a298 100644 (file)
@@ -1721,8 +1721,19 @@ void STDMETHODCALLTYPE EEShutDownHelper(BOOL fIsDllUnloading)
             if (!fIBCLoggingDone)
             {
                 if (g_IBCLogger.InstrEnabled())
-                    Module::WriteAllModuleProfileData(true);
+                {
+                    Thread * pThread = GetThread();
+                    ThreadLocalIBCInfo* pInfo = pThread->GetIBCInfo();
 
+                    // Acquire the Crst lock before creating the IBCLoggingDisabler object.
+                    // Only one thread at a time can be processing an IBC logging event.
+                    CrstHolder lock(g_IBCLogger.GetSync());
+                    {
+                        IBCLoggingDisabler disableLogging( pInfo );  // runs IBCLoggingDisabler::DisableLogging
+                        
+                        Module::WriteAllModuleProfileData(true);
+                    }
+                }
                 fIBCLoggingDone = TRUE;
             }
         }