Bug 1541404 part 24 - Fix JSScript::resetWarmUpCounter() calls to not affect Baseline. r=tcampbell

Most of the script->resetWarmUpCounter() calls are heuristics to delay Ion compilation.
This patch adds resetWarmUpCounterToDelayIonCompilation to make that more explicit.

This method does nothing if the script is not warm enough for Baseline compilation, to
ensure scripts never get stuck in the (Baseline) interpreter.

Differential Revision: https://phabricator.services.mozilla.com/D29990

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jan de Mooij 2019-05-08 10:04:19 +00:00
parent bda6300874
commit fc5d7b6e60
7 changed files with 27 additions and 14 deletions

View File

@ -241,7 +241,7 @@ void Zone::discardJitCode(FreeOp* fop,
// Warm-up counter for scripts are reset on GC. After discarding code we
// need to let it warm back up to get information such as which
// opcodes are setting array holes or accessing getter properties.
script->resetWarmUpCounter();
script->resetWarmUpCounterForGC();
// Clear the BaselineScript's control flow graph. The LifoAlloc is purged
// below.

View File

@ -56,8 +56,8 @@ var Opts_IonEagerNoOffthreadCompilation =
var Opts_Ion2NoOffthreadCompilation =
{
'ion.enable': 1,
'ion.warmup.trigger': 2,
'ion.full.warmup.trigger': 2,
'ion.warmup.trigger': 3,
'ion.full.warmup.trigger': 3,
'baseline.enable': 1,
'baseline.warmup.trigger': 1,
'offthread-compilation.enable': 0

View File

@ -2252,7 +2252,7 @@ static MethodStatus Compile(JSContext* cx, HandleScript script,
}
if (!CanLikelyAllocateMoreExecutableMemory()) {
script->resetWarmUpCounter();
script->resetWarmUpCounterToDelayIonCompilation();
return Method_Skipped;
}
@ -2513,7 +2513,7 @@ bool jit::IonCompileScriptForBaseline(JSContext* cx, BaselineFrame* frame,
// TODO: ASSERT that ion-compilation-disabled checker stub doesn't exist.
// TODO: Clear all optimized stubs.
// TODO: Add a ion-compilation-disabled checker IC stub
script->resetWarmUpCounter();
script->resetWarmUpCounterToDelayIonCompilation();
return true;
}
@ -2576,7 +2576,7 @@ bool jit::IonCompileScriptForBaseline(JSContext* cx, BaselineFrame* frame,
" Reset WarmUpCounter cantCompile=%s bailoutExpected=%s!",
stat == Method_CantCompile ? "yes" : "no",
bailoutExpected ? "yes" : "no");
script->resetWarmUpCounter();
script->resetWarmUpCounterToDelayIonCompilation();
}
return true;
}
@ -2799,7 +2799,7 @@ static void ClearIonScriptAfterInvalidation(JSContext* cx, JSScript* script,
// compile, unless we are recompiling *because* a script got hot
// (resetUses is false).
if (resetUses) {
script->resetWarmUpCounter();
script->resetWarmUpCounterToDelayIonCompilation();
}
}

View File

@ -215,7 +215,7 @@ static void HandleExceptionIon(JSContext* cx, const InlineFrameIterator& frame,
// Ion can compile try-catch, but bailing out to catch
// exceptions is slow. Reset the warm-up counter so that if we
// catch many exceptions we won't Ion-compile the script.
script->resetWarmUpCounter();
script->resetWarmUpCounterToDelayIonCompilation();
if (*hitBailoutException) {
break;
@ -373,7 +373,7 @@ static bool ProcessTryNotesBaseline(JSContext* cx, const JSJitFrameIter& frame,
// Ion can compile try-catch, but bailing out to catch
// exceptions is slow. Reset the warm-up counter so that if we
// catch many exceptions we won't Ion-compile the script.
script->resetWarmUpCounter();
script->resetWarmUpCounterToDelayIonCompilation();
// Resume at the start of the catch block.
rfe->kind = ResumeFromException::RESUME_CATCH;

View File

@ -36,6 +36,7 @@
#include "jit/BaselineJIT.h"
#include "jit/Ion.h"
#include "jit/IonCode.h"
#include "jit/JitOptions.h"
#include "jit/JitRealm.h"
#include "js/CompileOptions.h"
#include "js/MemoryMetrics.h"
@ -5465,6 +5466,18 @@ bool JSScript::mayReadFrameArgsDirectly() {
return argumentsHasVarBinding() || hasRest();
}
void JSScript::resetWarmUpCounterToDelayIonCompilation() {
// Reset the warm-up count only if it's greater than the BaselineCompiler
// threshold. We do this to ensure this has no effect on Baseline compilation
// because we don't want scripts to get stuck in the (Baseline) interpreter in
// pathological cases.
if (warmUpCount > jit::JitOptions.baselineWarmUpThreshold) {
incWarmUpResetCounter();
warmUpCount = jit::JitOptions.baselineWarmUpThreshold;
}
}
void JSScript::AutoDelazify::holdScript(JS::HandleFunction fun) {
if (fun) {
if (fun->realm()->isSelfHostingRealm()) {

View File

@ -2662,11 +2662,13 @@ class JSScript : public js::gc::TenuredCell {
static size_t offsetOfWarmUpCounter() {
return offsetof(JSScript, warmUpCount);
}
void resetWarmUpCounter() {
void resetWarmUpCounterForGC() {
incWarmUpResetCounter();
warmUpCount = 0;
}
void resetWarmUpCounterToDelayIonCompilation();
unsigned getWarmUpResetCount() const {
constexpr uint32_t MASK = uint32_t(MutableFlags::WarmupResets_MASK);
return mutableFlags_ & MASK;

View File

@ -1569,7 +1569,7 @@ bool js::FinishCompilation(JSContext* cx, HandleScript script,
}
if (!succeeded) {
script->resetWarmUpCounter();
script->resetWarmUpCounterToDelayIonCompilation();
*isValidOut = false;
return true;
}
@ -2679,9 +2679,7 @@ void TypeZone::addPendingRecompile(JSContext* cx, JSScript* script) {
CancelOffThreadIonCompile(script);
// Let the script warm up again before attempting another compile.
if (jit::IsBaselineEnabled(cx)) {
script->resetWarmUpCounter();
}
script->resetWarmUpCounterToDelayIonCompilation();
if (script->hasIonScript()) {
addPendingRecompile(