Skip to content

Commit a4719f7

Browse files
committed
Update default limits for profiling interpreter to prevent jitting too aggressively
Also move all the code to get default configs into their own functions to abstract away differences in defaults between normal functions and coroutines
1 parent eb7b34d commit a4719f7

File tree

2 files changed

+53
-19
lines changed

2 files changed

+53
-19
lines changed

lib/Runtime/Base/FunctionExecutionStateMachine.cpp

Lines changed: 45 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,32 @@ namespace Js
3333
{
3434
}
3535

36+
uint16 FunctionExecutionStateMachine::GetDefaultAutoProfilingInterpreter0Limit(bool isCoroutine) const {
37+
return isCoroutine ? 0 : static_cast<uint16>(Configuration::Global.flags.AutoProfilingInterpreter0Limit);
38+
}
39+
40+
uint16 FunctionExecutionStateMachine::GetDefaultProfilingInterpreter0Limit(bool isCoroutine) const {
41+
if (isCoroutine)
42+
{
43+
return static_cast<uint16>(Configuration::Global.flags.AutoProfilingInterpreter0Limit) +
44+
static_cast<uint16>(Configuration::Global.flags.AutoProfilingInterpreter1Limit);
45+
}
46+
47+
return static_cast<uint16>(Configuration::Global.flags.ProfilingInterpreter0Limit);
48+
}
49+
50+
uint16 FunctionExecutionStateMachine::GetDefaultAutoProfilingInterpreter1Limit(bool isCoroutine) const {
51+
return isCoroutine ? 0 : static_cast<uint16>(Configuration::Global.flags.AutoProfilingInterpreter1Limit);
52+
}
53+
54+
uint16 FunctionExecutionStateMachine::GetDefaultSimpleJitLimit(bool isCoroutine) const {
55+
return static_cast<uint16>(Configuration::Global.flags.SimpleJitLimit);
56+
}
57+
58+
uint16 FunctionExecutionStateMachine::GetDefaultProfilingInterpreter1Limit(bool isCoroutine) const {
59+
return static_cast<uint16>(Configuration::Global.flags.ProfilingInterpreter1Limit);
60+
}
61+
3662
void FunctionExecutionStateMachine::InitializeExecutionModeAndLimits(FunctionBody* functionBody)
3763
{
3864
#if DBG
@@ -48,20 +74,17 @@ namespace Js
4874
Assert(owner == nullptr || owner == functionBody);
4975
owner = functionBody;
5076

51-
const ConfigFlagsTable &configFlags = Configuration::Global.flags;
52-
5377
// AutoProfilingInterpreter might decide to not profile on the first run. For generator
5478
// functions, that means we will miss the profiling information on the first run when we resume
55-
// back to the function. This might result in lots of BailOnNoProfile even though we should have
56-
// profiling information. So always collect profile data for generators
57-
const bool skipAutoProfileForGenerator = functionBody->SkipAutoProfileForCoroutine();
79+
// back to the function.
80+
const bool isCoroutine = functionBody->SkipAutoProfileForCoroutine();
5881

59-
interpreterLimit = 0;
60-
autoProfilingInterpreter0Limit = skipAutoProfileForGenerator ? 0 : static_cast<uint16>(configFlags.AutoProfilingInterpreter0Limit);
61-
profilingInterpreter0Limit = static_cast<uint16>(configFlags.ProfilingInterpreter0Limit);
62-
autoProfilingInterpreter1Limit = skipAutoProfileForGenerator ? 0 : static_cast<uint16>(configFlags.AutoProfilingInterpreter1Limit);
63-
simpleJitLimit = static_cast<uint16>(configFlags.SimpleJitLimit);
64-
profilingInterpreter1Limit = static_cast<uint16>(configFlags.ProfilingInterpreter1Limit);
82+
interpreterLimit = 0;
83+
autoProfilingInterpreter0Limit = GetDefaultAutoProfilingInterpreter0Limit(isCoroutine);
84+
profilingInterpreter0Limit = GetDefaultProfilingInterpreter0Limit(isCoroutine);
85+
autoProfilingInterpreter1Limit = GetDefaultAutoProfilingInterpreter1Limit(isCoroutine);
86+
simpleJitLimit = GetDefaultSimpleJitLimit(isCoroutine);
87+
profilingInterpreter1Limit = GetDefaultProfilingInterpreter1Limit(isCoroutine);
6588

6689
// Based on which execution modes are disabled, calculate the number of additional iterations that need to be covered by
6790
// the execution mode that will scale with the full JIT threshold
@@ -109,14 +132,8 @@ namespace Js
109132
profilingInterpreter1Limit = 0;
110133
}
111134

112-
uint16 fullJitThresholdConfig =
113-
static_cast<uint16>(
114-
(skipAutoProfileForGenerator ? 0 : configFlags.AutoProfilingInterpreter0Limit) +
115-
configFlags.ProfilingInterpreter0Limit +
116-
(skipAutoProfileForGenerator ? 0 : configFlags.AutoProfilingInterpreter1Limit) +
117-
configFlags.SimpleJitLimit +
118-
configFlags.ProfilingInterpreter1Limit);
119-
if (!configFlags.EnforceExecutionModeLimits)
135+
uint16 fullJitThresholdConfig = GetDefaultFullJitThreshold(isCoroutine);
136+
if (!Configuration::Global.flags.EnforceExecutionModeLimits)
120137
{
121138
/*
122139
Scale the full JIT threshold based on some heuristics:
@@ -166,6 +183,15 @@ namespace Js
166183
TryTransitionToNextInterpreterExecutionMode();
167184
}
168185

186+
uint16 FunctionExecutionStateMachine::GetDefaultFullJitThreshold(bool isCoroutine) const
187+
{
188+
return GetDefaultAutoProfilingInterpreter0Limit(isCoroutine) +
189+
GetDefaultProfilingInterpreter0Limit(isCoroutine) +
190+
GetDefaultAutoProfilingInterpreter1Limit(isCoroutine) +
191+
GetDefaultSimpleJitLimit(isCoroutine) +
192+
GetDefaultProfilingInterpreter1Limit(isCoroutine);
193+
}
194+
169195
void FunctionExecutionStateMachine::ReinitializeExecutionModeAndLimits(FunctionBody* functionBody)
170196
{
171197
#if DBG

lib/Runtime/Base/FunctionExecutionStateMachine.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ namespace Js
115115
// Used to detect when interpretedCount changed from a particular call
116116
FieldWithBarrier(uint32) lastInterpretedCount;
117117

118+
inline uint16 GetDefaultAutoProfilingInterpreter0Limit(bool isCoroutine) const;
119+
inline uint16 GetDefaultProfilingInterpreter0Limit(bool isCoroutine) const;
120+
inline uint16 GetDefaultAutoProfilingInterpreter1Limit(bool isCoroutine) const;
121+
inline uint16 GetDefaultSimpleJitLimit(bool isCoroutine) const;
122+
inline uint16 GetDefaultProfilingInterpreter1Limit(bool isCoroutine) const;
123+
124+
inline uint16 GetDefaultFullJitThreshold(bool isCoroutine) const;
125+
118126
#if DBG
119127
FieldWithBarrier(bool) initializedExecutionModeAndLimits;
120128
// Temporary debug flags for automation

0 commit comments

Comments
 (0)