From: Brian Sullivan Date: Fri, 7 Apr 2017 00:36:15 +0000 (-0700) Subject: Fix shutdown A/V issue when IBC logging with the Music Store app X-Git-Tag: submit/tizen/20210909.063632~11030^2~7383^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ddb2f862fba5c4fb7719d18c51b6df204d10caf2;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Fix shutdown A/V issue when IBC logging with the Music Store app 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 --- diff --git a/src/coreclr/src/vm/ceeload.cpp b/src/coreclr/src/vm/ceeload.cpp index 0845d86..5de7114 100644 --- a/src/coreclr/src/vm/ceeload.cpp +++ b/src/coreclr/src/vm/ceeload.cpp @@ -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(); } diff --git a/src/coreclr/src/vm/ceemain.cpp b/src/coreclr/src/vm/ceemain.cpp index dd8438e..522a298 100644 --- a/src/coreclr/src/vm/ceemain.cpp +++ b/src/coreclr/src/vm/ceemain.cpp @@ -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; } }