Fix for #12609 - add option to disable tiered compilation for profilers (#14643)
authorDavid Mason <davmason@microsoft.com>
Mon, 23 Oct 2017 23:21:28 +0000 (16:21 -0700)
committerGitHub <noreply@github.com>
Mon, 23 Oct 2017 23:21:28 +0000 (16:21 -0700)
add option to disable tiered compilation for profilers

src/inc/corprof.idl
src/inc/profilepriv.inl
src/pal/prebuilt/inc/corprof.h
src/vm/eetoprofinterfaceimpl.cpp
src/vm/method.hpp

index db67b3c..7ec0172 100644 (file)
@@ -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;
 
index d334e10..1af2914 100644 (file)
@@ -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)
index befa45a..46e3bb7 100644 (file)
@@ -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] */ 
index 75f4a02..3f32b5a 100644 (file)
@@ -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;
     }
index c69896b..fba688c 100644 (file)
@@ -1240,7 +1240,8 @@ public:
             !IsUnboxingStub() &&
             !IsInstantiatingStub() &&
             !IsDynamicMethod() &&
-            !CORDisableJITOptimizations(GetModule()->GetDebuggerInfoBits());
+            !CORDisableJITOptimizations(GetModule()->GetDebuggerInfoBits()) &&
+            !CORProfilerDisableTieredCompilation();
     }
 #endif