diff --git a/src/coreclr/vm/multicorejit.cpp b/src/coreclr/vm/multicorejit.cpp index 9a9ec83684080f..1feb731a68ac0a 100644 --- a/src/coreclr/vm/multicorejit.cpp +++ b/src/coreclr/vm/multicorejit.cpp @@ -1496,16 +1496,7 @@ void MulticoreJitManager::WriteMulticoreJitProfiler() CONTRACTL_END; CrstHolder hold(& m_playerLock); - - // Avoid saving after MulticoreJitRecorder is deleted, and saving twice - if (!MulticoreJitRecorder::CloseTimer()) - { - return; - } - if (m_pMulticoreJitRecorder != NULL) - { - m_pMulticoreJitRecorder->StopProfile(false); - } + StopProfile(false); } #endif // !TARGET_UNIX diff --git a/src/coreclr/vm/multicorejitimpl.h b/src/coreclr/vm/multicorejitimpl.h index 35ea8a3dc8a269..cd00e6f9832f71 100644 --- a/src/coreclr/vm/multicorejitimpl.h +++ b/src/coreclr/vm/multicorejitimpl.h @@ -678,20 +678,15 @@ class MulticoreJitRecorder } #ifndef TARGET_UNIX - static bool CloseTimer() + static void CloseTimer() { LIMITED_METHOD_CONTRACT; TP_TIMER * pTimer = InterlockedExchangeT(& s_delayedWriteTimer, NULL); - - if (pTimer == NULL) + if (pTimer != NULL) { - return false; + CloseThreadpoolTimer(pTimer); } - - CloseThreadpoolTimer(pTimer); - - return true; } ~MulticoreJitRecorder() diff --git a/src/tests/baseservices/TieredCompilation/McjRecorderTimeoutBeforeStop.cs b/src/tests/baseservices/TieredCompilation/McjRecorderTimeoutBeforeStop.cs new file mode 100644 index 00000000000000..14ecd4785f1471 --- /dev/null +++ b/src/tests/baseservices/TieredCompilation/McjRecorderTimeoutBeforeStop.cs @@ -0,0 +1,33 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Runtime; +using System.Runtime.CompilerServices; +using System.Threading; + +public static class BasicTest +{ + private static int Main() + { + const int Pass = 100; + + ProfileOptimization.SetProfileRoot(Environment.CurrentDirectory); + ProfileOptimization.StartProfile("profile.mcj"); + + // Record a method + Foo(); + + // Let the multi-core JIT recorder time out. The timeout is set to 1 s in the test project. + Thread.Sleep(2000); + + // Stop the profile again after timeout (just verifying that it works) + ProfileOptimization.StartProfile(null); + return Pass; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static void Foo() + { + } +} diff --git a/src/tests/baseservices/TieredCompilation/McjRecorderTimeoutBeforeStop.csproj b/src/tests/baseservices/TieredCompilation/McjRecorderTimeoutBeforeStop.csproj new file mode 100644 index 00000000000000..05feffa608c91b --- /dev/null +++ b/src/tests/baseservices/TieredCompilation/McjRecorderTimeoutBeforeStop.csproj @@ -0,0 +1,21 @@ + + + Exe + true + true + 0 + + + + + + + + +