Skip to content

Commit f9cf3c8

Browse files
simonferqueljkotas
andauthored
Make COR_PRF_DISABLE_OPTIMIZATIONS Allowable After Attach and non immutable (#113924)
* Make COR_PRF_DISABLE_OPTIMIZATIONS and COR_PRF_DISABLE_INLINING mutable flags * On module initialization, capture the profiler JIT flags so they apply consistently on that module * Change old macro usages and make them call Module::AreJITOptimizationsDisabled() instead * Test for dynamic assignment of COR_PRF_DISABLE_OPTIMIZATIONS and COR_PRF_DISABLE_INLINING * Update src/coreclr/vm/ceeload.cpp Co-authored-by: Jan Kotas <[email protected]> --------- Co-authored-by: Jan Kotas <[email protected]>
1 parent ff18c30 commit f9cf3c8

21 files changed

+469
-78
lines changed

src/coreclr/debug/daccess/dacdbiimpl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,8 +667,7 @@ void DacDbiInterfaceImpl::GetCompilerFlags (
667667

668668
// Get the underlying module - none of this is AppDomain specific
669669
Module * pModule = pDomainAssembly->GetAssembly()->GetModule();
670-
DWORD dwBits = pModule->GetDebuggerInfoBits();
671-
*pfAllowJITOpts = !CORDisableJITOptimizations(dwBits);
670+
*pfAllowJITOpts = !pModule->AreJITOptimizationsDisabled();
672671
*pfEnableEnC = pModule->IsEditAndContinueEnabled();
673672

674673

src/coreclr/debug/ee/debugger.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3301,7 +3301,7 @@ void Debugger::getBoundaries(MethodDesc * md,
33013301
// lives in, then don't grab specific boundaries from the symbol
33023302
// store since any boundaries we give the JIT will be pretty much
33033303
// ignored anyway.
3304-
if (!CORDisableJITOptimizations(md->GetModule()->GetDebuggerInfoBits()))
3304+
if (!md->GetModule()->AreJITOptimizationsDisabled())
33053305
{
33063306
*implicitBoundaries = ICorDebugInfo::BoundaryTypes(ICorDebugInfo::STACK_EMPTY_BOUNDARIES |
33073307
ICorDebugInfo::CALL_SITE_BOUNDARIES);
@@ -3379,13 +3379,10 @@ void Debugger::getVars(MethodDesc * md, ULONG32 *cVars, ICorDebugInfo::ILVarInfo
33793379
// free to ignore *extendOthers
33803380
*extendOthers = true;
33813381

3382-
DWORD bits = md->GetModule()->GetDebuggerInfoBits();
3383-
33843382
if (CORDBUnrecoverableError(this))
33853383
goto Exit;
33863384

3387-
if (CORDisableJITOptimizations(bits))
3388-
// if (!CORDebuggerAllowJITOpts(bits))
3385+
if (md->GetModule()->AreJITOptimizationsDisabled())
33893386
{
33903387
//
33913388
// @TODO: Do we really need this code since *extendOthers==true?

src/coreclr/debug/ee/debugger.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -481,8 +481,6 @@ class DebuggerModule
481481
PTR_Module m_pRuntimeModule;
482482
PTR_DomainAssembly m_pRuntimeDomainAssembly;
483483

484-
bool m_fHasOptimizedCode;
485-
486484
// Can we change jit flags on the module?
487485
// This is true during the Module creation
488486
bool m_fCanChangeJitFlags;

src/coreclr/debug/ee/debugger.inl

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ inline DebuggerModule::DebuggerModule(Module * pRuntimeModule,
6060
LOG((LF_CORDB,LL_INFO10000, "DM::DM this:0x%x Module:0x%x DF:0x%x\n",
6161
this, pRuntimeModule, pDomainAssembly));
6262

63-
// Do we have any optimized code?
64-
DWORD dwDebugBits = pRuntimeModule->GetDebuggerInfoBits();
65-
m_fHasOptimizedCode = CORDebuggerAllowJITOpts(dwDebugBits);
66-
6763
// Dynamic modules must receive ClassLoad callbacks in order to receive metadata updates as the module
6864
// evolves. So we force this on here and refuse to change it for all dynamic modules.
6965
if (pRuntimeModule->IsReflectionEmit())
@@ -83,8 +79,7 @@ inline bool DebuggerModule::HasAnyOptimizedCode()
8379
{
8480
LIMITED_METHOD_CONTRACT;
8581
Module * pModule = GetRuntimeModule();
86-
DWORD dwDebugBits = pModule->GetDebuggerInfoBits();
87-
return CORDebuggerAllowJITOpts(dwDebugBits);
82+
return !pModule->AreJITOptimizationsDisabled();
8883
}
8984

9085
//-----------------------------------------------------------------------------

src/coreclr/inc/corprof.idl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -592,6 +592,8 @@ typedef enum
592592
COR_PRF_MONITOR_CLASS_LOADS |
593593
COR_PRF_MONITOR_EXCEPTIONS |
594594
COR_PRF_MONITOR_JIT_COMPILATION |
595+
COR_PRF_DISABLE_INLINING |
596+
COR_PRF_DISABLE_OPTIMIZATIONS |
595597
COR_PRF_ENABLE_REJIT,
596598

597599
COR_PRF_ALLOWABLE_NOTIFICATION_PROFILER
@@ -625,8 +627,6 @@ typedef enum
625627
COR_PRF_MONITOR_REMOTING_ASYNC |
626628
COR_PRF_ENABLE_INPROC_DEBUGGING |
627629
COR_PRF_ENABLE_JIT_MAPS |
628-
COR_PRF_DISABLE_OPTIMIZATIONS |
629-
COR_PRF_DISABLE_INLINING |
630630
COR_PRF_ENABLE_OBJECT_ALLOCATED |
631631
COR_PRF_ENABLE_FUNCTION_ARGS |
632632
COR_PRF_ENABLE_FUNCTION_RETVAL |
@@ -4292,10 +4292,10 @@ interface ICorProfilerInfo14 : ICorProfilerInfo13
42924292
[out, size_is(cObjectRanges), length_is(*pcObjectRanges)] COR_PRF_NONGC_HEAP_RANGE ranges[]);
42934293

42944294

4295-
// EventPipeCreateProvider2 allows you to pass in a callback which will be called whenever a
4295+
// EventPipeCreateProvider2 allows you to pass in a callback which will be called whenever a
42964296
// session enables your provider. The behavior of the callback matches the ETW behavior which
4297-
// can be counter intuitive. You will get a callback any time a session changes with the updated
4298-
// global keywords enabled for your session. The is_enabled parameter will be true if any
4297+
// can be counter intuitive. You will get a callback any time a session changes with the updated
4298+
// global keywords enabled for your session. The is_enabled parameter will be true if any
42994299
// session has your provider enabled. The source_id parameter will be a valid id if the callback
43004300
// was triggered due to a session enabling and it will be NULL if it was triggered due to a session
43014301
// disabling.

src/coreclr/pal/prebuilt/inc/corprof.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,9 +583,9 @@ enum __MIDL___MIDL_itf_corprof_0000_0000_0005
583583
COR_PRF_DISABLE_ALL_NGEN_IMAGES = 0x80000000,
584584
COR_PRF_ALL = 0x8fffffff,
585585
COR_PRF_REQUIRE_PROFILE_IMAGE = ( ( COR_PRF_USE_PROFILE_IMAGES | COR_PRF_MONITOR_CODE_TRANSITIONS ) | COR_PRF_MONITOR_ENTERLEAVE ) ,
586-
COR_PRF_ALLOWABLE_AFTER_ATTACH = ( ( ( ( ( ( ( ( ( ( COR_PRF_MONITOR_THREADS | COR_PRF_MONITOR_MODULE_LOADS ) | COR_PRF_MONITOR_ASSEMBLY_LOADS ) | COR_PRF_MONITOR_APPDOMAIN_LOADS ) | COR_PRF_ENABLE_STACK_SNAPSHOT ) | COR_PRF_MONITOR_GC ) | COR_PRF_MONITOR_SUSPENDS ) | COR_PRF_MONITOR_CLASS_LOADS ) | COR_PRF_MONITOR_EXCEPTIONS ) | COR_PRF_MONITOR_JIT_COMPILATION ) | COR_PRF_ENABLE_REJIT ) ,
586+
COR_PRF_ALLOWABLE_AFTER_ATTACH = ( ( ( ( ( ( ( ( ( ( ( ( COR_PRF_MONITOR_THREADS | COR_PRF_MONITOR_MODULE_LOADS ) | COR_PRF_MONITOR_ASSEMBLY_LOADS ) | COR_PRF_MONITOR_APPDOMAIN_LOADS ) | COR_PRF_ENABLE_STACK_SNAPSHOT ) | COR_PRF_MONITOR_GC ) | COR_PRF_MONITOR_SUSPENDS ) | COR_PRF_MONITOR_CLASS_LOADS ) | COR_PRF_MONITOR_EXCEPTIONS ) | COR_PRF_MONITOR_JIT_COMPILATION ) | COR_PRF_DISABLE_INLINING ) | COR_PRF_DISABLE_OPTIMIZATIONS ) | COR_PRF_ENABLE_REJIT ) ,
587587
COR_PRF_ALLOWABLE_NOTIFICATION_PROFILER = ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( COR_PRF_MONITOR_FUNCTION_UNLOADS | COR_PRF_MONITOR_CLASS_LOADS ) | COR_PRF_MONITOR_MODULE_LOADS ) | COR_PRF_MONITOR_ASSEMBLY_LOADS ) | COR_PRF_MONITOR_APPDOMAIN_LOADS ) | COR_PRF_MONITOR_JIT_COMPILATION ) | COR_PRF_MONITOR_EXCEPTIONS ) | COR_PRF_MONITOR_OBJECT_ALLOCATED ) | COR_PRF_MONITOR_THREADS ) | COR_PRF_MONITOR_CODE_TRANSITIONS ) | COR_PRF_MONITOR_CCW ) | COR_PRF_MONITOR_SUSPENDS ) | COR_PRF_MONITOR_CACHE_SEARCHES ) | COR_PRF_DISABLE_INLINING ) | COR_PRF_DISABLE_OPTIMIZATIONS ) | COR_PRF_ENABLE_OBJECT_ALLOCATED ) | COR_PRF_MONITOR_CLR_EXCEPTIONS ) | COR_PRF_ENABLE_STACK_SNAPSHOT ) | COR_PRF_USE_PROFILE_IMAGES ) | COR_PRF_DISABLE_ALL_NGEN_IMAGES ) ,
588-
COR_PRF_MONITOR_IMMUTABLE = ( ( ( ( ( ( ( ( ( ( ( ( ( ( COR_PRF_MONITOR_CODE_TRANSITIONS | COR_PRF_MONITOR_REMOTING ) | COR_PRF_MONITOR_REMOTING_COOKIE ) | COR_PRF_MONITOR_REMOTING_ASYNC ) | COR_PRF_ENABLE_INPROC_DEBUGGING ) | COR_PRF_ENABLE_JIT_MAPS ) | COR_PRF_DISABLE_OPTIMIZATIONS ) | COR_PRF_DISABLE_INLINING ) | COR_PRF_ENABLE_OBJECT_ALLOCATED ) | COR_PRF_ENABLE_FUNCTION_ARGS ) | COR_PRF_ENABLE_FUNCTION_RETVAL ) | COR_PRF_ENABLE_FRAME_INFO ) | COR_PRF_USE_PROFILE_IMAGES ) | COR_PRF_DISABLE_TRANSPARENCY_CHECKS_UNDER_FULL_TRUST ) | COR_PRF_DISABLE_ALL_NGEN_IMAGES )
588+
COR_PRF_MONITOR_IMMUTABLE = ( ( ( ( ( ( ( ( ( ( ( ( COR_PRF_MONITOR_CODE_TRANSITIONS | COR_PRF_MONITOR_REMOTING ) | COR_PRF_MONITOR_REMOTING_COOKIE ) | COR_PRF_MONITOR_REMOTING_ASYNC ) | COR_PRF_ENABLE_INPROC_DEBUGGING ) | COR_PRF_ENABLE_JIT_MAPS ) | COR_PRF_ENABLE_OBJECT_ALLOCATED ) | COR_PRF_ENABLE_FUNCTION_ARGS ) | COR_PRF_ENABLE_FUNCTION_RETVAL ) | COR_PRF_ENABLE_FRAME_INFO ) | COR_PRF_USE_PROFILE_IMAGES ) | COR_PRF_DISABLE_TRANSPARENCY_CHECKS_UNDER_FULL_TRUST ) | COR_PRF_DISABLE_ALL_NGEN_IMAGES )
589589
} COR_PRF_MONITOR;
590590

591591
typedef /* [public] */

src/coreclr/vm/ceeload.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,14 +478,25 @@ void Module::Initialize(AllocMemTracker *pamTracker, LPCWSTR szName)
478478
m_dwTypeCount = 0;
479479
m_dwExportedTypeCount = 0;
480480
m_dwCustomAttributeCount = 0;
481+
#ifdef PROFILING_SUPPORTED
482+
// set profiler related JIT flags
483+
if (CORProfilerDisableInlining())
484+
{
485+
m_dwTransientFlags |= PROF_DISABLE_INLINING;
486+
}
487+
if (CORProfilerDisableOptimizations())
488+
{
489+
m_dwTransientFlags |= PROF_DISABLE_OPTIMIZATIONS;
490+
}
481491

482-
#if defined(PROFILING_SUPPORTED) && !defined(DACCESS_COMPILE)
492+
#if !defined(DACCESS_COMPILE)
483493
m_pJitInlinerTrackingMap = NULL;
484494
if (ReJitManager::IsReJITInlineTrackingEnabled())
485495
{
486496
m_pJitInlinerTrackingMap = new JITInlineTrackingMap(GetLoaderAllocator());
487497
}
488-
#endif // defined (PROFILING_SUPPORTED) &&!defined(DACCESS_COMPILE)
498+
#endif // !defined(DACCESS_COMPILE)
499+
#endif // PROFILING_SUPPORTED
489500

490501
LOG((LF_CLASSLOADER, LL_INFO10, "Loaded pModule: \"%s\".\n", GetDebugName()));
491502
}
@@ -507,7 +518,7 @@ void Module::SetDebuggerInfoBits(DebuggerAssemblyControlFlags newBits)
507518
#ifdef DEBUGGING_SUPPORTED
508519
if (IsEditAndContinueCapable())
509520
{
510-
BOOL setEnC = (newBits & DACF_ENC_ENABLED) != 0 || g_pConfig->ForceEnc() || (g_pConfig->DebugAssembliesModifiable() && CORDisableJITOptimizations(GetDebuggerInfoBits()));
521+
BOOL setEnC = (newBits & DACF_ENC_ENABLED) != 0 || g_pConfig->ForceEnc() || (g_pConfig->DebugAssembliesModifiable() && AreJITOptimizationsDisabled());
511522
if (setEnC)
512523
{
513524
EnableEditAndContinue();

src/coreclr/vm/ceeload.h

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,8 @@ class Module : public ModuleBase
627627
IS_ETW_NOTIFIED = 0x00000020,
628628

629629
IS_REFLECTION_EMIT = 0x00000040,
630+
PROF_DISABLE_OPTIMIZATIONS = 0x00000080, // indicates if Profiler disabled JIT optimization event mask was set when loaded
631+
PROF_DISABLE_INLINING = 0x00000100, // indicates if Profiler disabled JIT Inlining event mask was set when loaded
630632

631633
//
632634
// Note: The values below must match the ones defined in
@@ -915,6 +917,39 @@ class Module : public ModuleBase
915917
return (m_dwTransientFlags & IS_EDIT_AND_CONTINUE) != 0;
916918
}
917919

920+
BOOL IsInliningDisabledByProfiler() const
921+
{
922+
WRAPPER_NO_CONTRACT;
923+
SUPPORTS_DAC;
924+
925+
return (m_dwTransientFlags & PROF_DISABLE_INLINING) != 0;
926+
}
927+
928+
BOOL AreJITOptimizationsDisabled() const
929+
{
930+
WRAPPER_NO_CONTRACT;
931+
SUPPORTS_DAC;
932+
933+
#ifdef DEBUGGING_SUPPORTED
934+
// check if debugger has disallowed JIT optimizations
935+
auto dwDebuggerBits = GetDebuggerInfoBits();
936+
if (!CORDebuggerAllowJITOpts(dwDebuggerBits))
937+
{
938+
return TRUE;
939+
}
940+
#endif // DEBUGGING_SUPPORTED
941+
942+
#if defined(PROFILING_SUPPORTED) || defined(PROFILING_SUPPORTED_DATA)
943+
// check if profiler had disabled JIT optimizations when module was loaded
944+
if (m_dwTransientFlags & PROF_DISABLE_OPTIMIZATIONS)
945+
{
946+
return TRUE;
947+
}
948+
#endif // defined(PROFILING_SUPPORTED) || defined(PROFILING_SUPPORTED_DATA)
949+
950+
return FALSE;
951+
}
952+
918953
#ifdef FEATURE_METADATA_UPDATER
919954
// Holds a table of EnCEEClassData object for classes in this module that have been modified
920955
CUnorderedArray<EnCEEClassData*, 5> m_ClassList;
@@ -1339,7 +1374,7 @@ class Module : public ModuleBase
13391374

13401375
void SetDebuggerInfoBits(DebuggerAssemblyControlFlags newBits);
13411376

1342-
DebuggerAssemblyControlFlags GetDebuggerInfoBits(void)
1377+
DebuggerAssemblyControlFlags GetDebuggerInfoBits(void) const
13431378
{
13441379
LIMITED_METHOD_CONTRACT;
13451380
SUPPORTS_DAC;

src/coreclr/vm/jitinterface.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7891,6 +7891,13 @@ CorInfoInline CEEInfo::canInline (CORINFO_METHOD_HANDLE hCaller,
78917891
}
78927892

78937893
#ifdef PROFILING_SUPPORTED
7894+
if (pOrigCallerModule->IsInliningDisabledByProfiler())
7895+
{
7896+
result = INLINE_FAIL;
7897+
szFailReason = "Inlining is disabled in the compiled method's module by a profiler";
7898+
goto exit;
7899+
}
7900+
78947901
if (CORProfilerPresent())
78957902
{
78967903
// #rejit
@@ -7905,15 +7912,6 @@ CorInfoInline CEEInfo::canInline (CORINFO_METHOD_HANDLE hCaller,
79057912
goto exit;
79067913
}
79077914

7908-
// If the profiler has set a mask preventing inlining, always return
7909-
// false to the jit.
7910-
if (CORProfilerDisableInlining())
7911-
{
7912-
result = INLINE_FAIL;
7913-
szFailReason = "Profiler disabled inlining globally";
7914-
goto exit;
7915-
}
7916-
79177915
#if defined(FEATURE_REJIT) && !defined(DACCESS_COMPILE)
79187916
if (CORProfilerEnableRejit())
79197917
{
@@ -9569,7 +9567,7 @@ CorInfoTypeWithMod CEEInfo::getArgType (
95699567

95709568
case ELEMENT_TYPE_PTR:
95719569
// Load the type eagerly under debugger to make the eval work
9572-
if (CORDisableJITOptimizations(pModule->GetDebuggerInfoBits()))
9570+
if (pModule->AreJITOptimizationsDisabled())
95739571
{
95749572
// NOTE: in some IJW cases, when the type pointed at is unmanaged,
95759573
// the GetTypeHandle may fail, because there is no TypeDef for such type.
@@ -12898,7 +12896,7 @@ CORJIT_FLAGS GetDebuggerCompileFlags(Module* pModule, CORJIT_FLAGS flags)
1289812896
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_DEBUG_INFO);
1289912897
#endif // DEBUGGING_SUPPORTED
1290012898

12901-
if (CORDisableJITOptimizations(pModule->GetDebuggerInfoBits()))
12899+
if (pModule->AreJITOptimizationsDisabled())
1290212900
{
1290312901
flags.Set(CORJIT_FLAGS::CORJIT_FLAG_DEBUG_CODE);
1290412902
}

src/coreclr/vm/method.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2888,7 +2888,7 @@ bool MethodDesc::IsJitOptimizationDisabledForAllMethodsInChunk()
28882888
return
28892889
g_pConfig->JitMinOpts() ||
28902890
g_pConfig->GenDebuggableCode() ||
2891-
CORDisableJITOptimizations(GetModule()->GetDebuggerInfoBits());
2891+
GetModule()->AreJITOptimizationsDisabled();
28922892
}
28932893

28942894
#ifndef DACCESS_COMPILE

0 commit comments

Comments
 (0)