From 67a66156d0307b49522a13618522d289268bc1f9 Mon Sep 17 00:00:00 2001 From: David Mason Date: Mon, 23 Oct 2017 16:21:28 -0700 Subject: [PATCH] Fix for #12609 - add option to disable tiered compilation for profilers (#14643) add option to disable tiered compilation for profilers --- src/inc/corprof.idl | 4 +++- src/inc/profilepriv.inl | 16 ++++++++++++++++ src/pal/prebuilt/inc/corprof.h | 3 ++- src/vm/eetoprofinterfaceimpl.cpp | 18 +++++++++++------- src/vm/method.hpp | 3 ++- 5 files changed, 34 insertions(+), 10 deletions(-) diff --git a/src/inc/corprof.idl b/src/inc/corprof.idl index db67b3c..7ec0172 100644 --- a/src/inc/corprof.idl +++ b/src/inc/corprof.idl @@ -623,6 +623,8 @@ typedef enum COR_PRF_HIGH_MONITOR_DYNAMIC_FUNCTION_UNLOADS = 0x00000004, + COR_PRF_HIGH_DISABLE_TIERED_COMPILATION = 0x00000008, + COR_PRF_HIGH_REQUIRE_PROFILE_IMAGE = 0, COR_PRF_HIGH_ALLOWABLE_AFTER_ATTACH = COR_PRF_HIGH_IN_MEMORY_SYMBOLS_UPDATED | COR_PRF_HIGH_MONITOR_DYNAMIC_FUNCTION_UNLOADS, @@ -630,7 +632,7 @@ typedef enum // MONITOR_IMMUTABLE represents all flags that may only be set during initialization. // Trying to change any of these flags elsewhere will result in a // failed HRESULT. - COR_PRF_HIGH_MONITOR_IMMUTABLE = 0, + COR_PRF_HIGH_MONITOR_IMMUTABLE = COR_PRF_HIGH_DISABLE_TIERED_COMPILATION, } COR_PRF_HIGH_MONITOR; diff --git a/src/inc/profilepriv.inl b/src/inc/profilepriv.inl index d334e10..1af2914 100644 --- a/src/inc/profilepriv.inl +++ b/src/inc/profilepriv.inl @@ -751,6 +751,22 @@ inline BOOL CORProfilerIsMonitoringDynamicFunctionUnloads() ((&g_profControlBlock)->dwEventMaskHigh & COR_PRF_HIGH_MONITOR_DYNAMIC_FUNCTION_UNLOADS)); } +inline BOOL CORProfilerDisableTieredCompilation() +{ + CONTRACTL + { + NOTHROW; + GC_NOTRIGGER; + CANNOT_TAKE_LOCK; + SO_NOT_MAINLINE; + } + CONTRACTL_END; + + + return (CORProfilerPresent() && + ((&g_profControlBlock)->dwEventMaskHigh & COR_PRF_HIGH_DISABLE_TIERED_COMPILATION)); +} + #if defined(PROFILING_SUPPORTED) && !defined(CROSSGEN_COMPILE) #if defined(FEATURE_PROFAPI_ATTACH_DETACH) diff --git a/src/pal/prebuilt/inc/corprof.h b/src/pal/prebuilt/inc/corprof.h index befa45a..46e3bb7 100644 --- a/src/pal/prebuilt/inc/corprof.h +++ b/src/pal/prebuilt/inc/corprof.h @@ -514,9 +514,10 @@ enum __MIDL___MIDL_itf_corprof_0000_0000_0006 COR_PRF_HIGH_ADD_ASSEMBLY_REFERENCES = 0x1, COR_PRF_HIGH_IN_MEMORY_SYMBOLS_UPDATED = 0x2, COR_PRF_HIGH_MONITOR_DYNAMIC_FUNCTION_UNLOADS = 0x4, + COR_PRF_HIGH_DISABLE_TIERED_COMPILATION = 0x8, COR_PRF_HIGH_REQUIRE_PROFILE_IMAGE = 0, COR_PRF_HIGH_ALLOWABLE_AFTER_ATTACH = ( COR_PRF_HIGH_IN_MEMORY_SYMBOLS_UPDATED | COR_PRF_HIGH_MONITOR_DYNAMIC_FUNCTION_UNLOADS ) , - COR_PRF_HIGH_MONITOR_IMMUTABLE = 0 + COR_PRF_HIGH_MONITOR_IMMUTABLE = ( COR_PRF_HIGH_DISABLE_TIERED_COMPILATION ) } COR_PRF_HIGH_MONITOR; typedef /* [public] */ diff --git a/src/vm/eetoprofinterfaceimpl.cpp b/src/vm/eetoprofinterfaceimpl.cpp index 75f4a02..3f32b5a 100644 --- a/src/vm/eetoprofinterfaceimpl.cpp +++ b/src/vm/eetoprofinterfaceimpl.cpp @@ -2006,7 +2006,8 @@ HRESULT EEToProfInterfaceImpl::EnsureProfilerDetachable() { LIMITED_METHOD_CONTRACT; - if ((g_profControlBlock.dwEventMask & COR_PRF_MONITOR_IMMUTABLE) != 0) + if (((g_profControlBlock.dwEventMask & COR_PRF_MONITOR_IMMUTABLE) != 0) || + ((g_profControlBlock.dwEventMaskHigh & COR_PRF_HIGH_MONITOR_IMMUTABLE) != 0)) { LOG(( LF_CORPROF, @@ -2268,12 +2269,14 @@ HRESULT EEToProfInterfaceImpl::SetEventMask(DWORD dwEventMask, DWORD dwEventMask if (g_profControlBlock.curProfStatus.Get() != kProfStatusInitializingForStartupLoad) { #ifdef _DEBUG - if ((dwEventMask & dwImmutableEventFlags) != - (g_profControlBlock.dwEventMask & dwImmutableEventFlags)) + if (((dwEventMask & dwImmutableEventFlags) != + (g_profControlBlock.dwEventMask & dwImmutableEventFlags)) || #else //!_DEBUG - if ((dwEventMask & COR_PRF_MONITOR_IMMUTABLE) != - (g_profControlBlock.dwEventMask & COR_PRF_MONITOR_IMMUTABLE)) + if (((dwEventMask & COR_PRF_MONITOR_IMMUTABLE) != + (g_profControlBlock.dwEventMask & COR_PRF_MONITOR_IMMUTABLE)) || #endif //_DEBUG + ((dwEventMaskHigh & COR_PRF_HIGH_MONITOR_IMMUTABLE) != + (g_profControlBlock.dwEventMaskHigh & COR_PRF_HIGH_MONITOR_IMMUTABLE))) { // FUTURE: Should we have a dedicated HRESULT for setting immutable flag? return E_FAIL; @@ -2284,10 +2287,11 @@ HRESULT EEToProfInterfaceImpl::SetEventMask(DWORD dwEventMask, DWORD dwEventMask // allowable after an attach if (m_fLoadedViaAttach && #ifdef _DEBUG - ((dwEventMask & (~dwAllowableAfterAttachEventFlags)) != 0)) + (((dwEventMask & (~dwAllowableAfterAttachEventFlags)) != 0) || #else //!_DEBUG - ((dwEventMask & (~COR_PRF_ALLOWABLE_AFTER_ATTACH)) != 0)) + (((dwEventMask & (~COR_PRF_ALLOWABLE_AFTER_ATTACH)) != 0) || #endif //_DEBUG + (dwEventMaskHigh & (~COR_PRF_HIGH_ALLOWABLE_AFTER_ATTACH)))) { return CORPROF_E_UNSUPPORTED_FOR_ATTACHING_PROFILER; } diff --git a/src/vm/method.hpp b/src/vm/method.hpp index c69896b..fba688c 100644 --- a/src/vm/method.hpp +++ b/src/vm/method.hpp @@ -1240,7 +1240,8 @@ public: !IsUnboxingStub() && !IsInstantiatingStub() && !IsDynamicMethod() && - !CORDisableJITOptimizations(GetModule()->GetDebuggerInfoBits()); + !CORDisableJITOptimizations(GetModule()->GetDebuggerInfoBits()) && + !CORProfilerDisableTieredCompilation(); } #endif -- 2.7.4