Bug 1382650 part 2 - Store Ion warmup threshold only in JitOptions. r=nbp a=pascalc
authorJan de Mooij <jdemooij@mozilla.com>
Wed, 27 Mar 2019 12:30:10 +0000
changeset 526038 2e6bccd461f45dc46e328e2ad0254df2faa20736
parent 526037 2f6ee802781a28f8e41c905da2d0f5d7ca3e1380
child 526039 7d87558da81f21659d5ba11df5564142f88e4703
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnbp, pascalc
bugs1382650
milestone67.0
Bug 1382650 part 2 - Store Ion warmup threshold only in JitOptions. r=nbp a=pascalc Storing this also in IonOptimizationLevels.h/cpp is more complicated than necessary. Differential Revision: https://phabricator.services.mozilla.com/D24154
js/src/jit/IonOptimizationLevels.cpp
js/src/jit/IonOptimizationLevels.h
js/src/jit/JitOptions.cpp
js/src/jit/JitOptions.h
js/src/jsapi.cpp
--- a/js/src/jit/IonOptimizationLevels.cpp
+++ b/js/src/jit/IonOptimizationLevels.cpp
@@ -12,19 +12,16 @@
 using namespace js;
 using namespace js::jit;
 
 namespace js {
 namespace jit {
 
 const OptimizationLevelInfo IonOptimizations;
 
-// Duplicated in all.js - ensure both match.
-const uint32_t OptimizationInfo::CompilerWarmupThreshold = 1000;
-
 void OptimizationInfo::initNormalOptimizationInfo() {
   level_ = OptimizationLevel::Normal;
 
   autoTruncate_ = true;
   eaa_ = true;
   edgeCaseAnalysis_ = true;
   eliminateRedundantChecks_ = true;
   inlineInterpreted_ = true;
@@ -41,17 +38,16 @@ void OptimizationInfo::initNormalOptimiz
   inlineMaxBytecodePerCallSiteMainThread_ = 550;
   inlineMaxBytecodePerCallSiteHelperThread_ = 1100;
   inlineMaxCalleeInlinedBytecodeLength_ = 3550;
   inlineMaxTotalBytecodeLength_ = 85000;
   inliningMaxCallerBytecodeLength_ = 1600;
   maxInlineDepth_ = 3;
   scalarReplacement_ = true;
   smallFunctionMaxInlineDepth_ = 10;
-  compilerWarmUpThreshold_ = CompilerWarmupThreshold;
   inliningWarmUpThresholdFactor_ = 0.125;
   inliningRecompileThresholdFactor_ = 4;
 }
 
 void OptimizationInfo::initWasmOptimizationInfo() {
   // The Wasm optimization level
   // Disables some passes that don't work well with wasm.
 
@@ -73,18 +69,17 @@ uint32_t OptimizationInfo::compilerWarmU
                                                    jsbytecode* pc) const {
   MOZ_ASSERT(pc == nullptr || pc == script->code() ||
              JSOp(*pc) == JSOP_LOOPENTRY);
 
   if (pc == script->code()) {
     pc = nullptr;
   }
 
-  uint32_t warmUpThreshold = JitOptions.forcedDefaultIonWarmUpThreshold.valueOr(
-      compilerWarmUpThreshold_);
+  uint32_t warmUpThreshold = baseCompilerWarmUpThreshold();
 
   // If the script is too large to compile on the main thread, we can still
   // compile it off thread. In these cases, increase the warm-up counter
   // threshold to improve the compilation's type information and hopefully
   // avoid later recompilation.
 
   if (script->length() > MAX_MAIN_THREAD_SCRIPT_SIZE) {
     warmUpThreshold *= (script->length() / double(MAX_MAIN_THREAD_SCRIPT_SIZE));
--- a/js/src/jit/IonOptimizationLevels.h
+++ b/js/src/jit/IonOptimizationLevels.h
@@ -29,18 +29,18 @@ inline const char* OptimizationLevelStri
     case OptimizationLevel::Wasm:
       return "Optimization_Wasm";
     case OptimizationLevel::Count:;
   }
   MOZ_CRASH("Invalid OptimizationLevel");
 }
 #endif
 
+// Class representing the Ion optimization settings for an OptimizationLevel.
 class OptimizationInfo {
- public:
   OptimizationLevel level_;
 
   // Toggles whether Effective Address Analysis is performed.
   bool eaa_;
 
   // Toggles whether Alignment Mask Analysis is performed.
   bool ama_;
 
@@ -106,32 +106,38 @@ class OptimizationInfo {
   // The maximum inlining depth for functions.
   //
   // Inlining small functions has almost no compiling overhead
   // and removes the otherwise needed call overhead.
   // The value is currently very low.
   // Actually it is only needed to make sure we don't blow out the stack.
   uint32_t smallFunctionMaxInlineDepth_;
 
-  // How many invocations or loop iterations are needed before functions
-  // are compiled.
-  uint32_t compilerWarmUpThreshold_;
-
-  // Default compiler warmup threshold, unless it is overridden.
-  static const uint32_t CompilerWarmupThreshold;
-
   // How many invocations or loop iterations are needed before calls
   // are inlined, as a fraction of compilerWarmUpThreshold.
   double inliningWarmUpThresholdFactor_;
 
   // How many invocations or loop iterations are needed before a function
   // is hot enough to recompile the outerScript to inline that function,
   // as a multiplication of inliningWarmUpThreshold.
   uint32_t inliningRecompileThresholdFactor_;
 
+  uint32_t baseCompilerWarmUpThreshold() const {
+    switch (level_) {
+      case OptimizationLevel::Normal:
+        return JitOptions.normalIonWarmUpThreshold;
+      case OptimizationLevel::DontCompile:
+      case OptimizationLevel::Wasm:
+      case OptimizationLevel::Count:
+        break;
+    }
+    MOZ_CRASH("Unexpected optimization level");
+  }
+
+ public:
   constexpr OptimizationInfo()
       : level_(OptimizationLevel::Normal),
         eaa_(false),
         ama_(false),
         edgeCaseAnalysis_(false),
         eliminateRedundantChecks_(false),
         inlineInterpreted_(false),
         inlineNative_(false),
@@ -146,17 +152,16 @@ class OptimizationInfo {
         inlineMaxBytecodePerCallSiteHelperThread_(0),
         inlineMaxBytecodePerCallSiteMainThread_(0),
         inlineMaxCalleeInlinedBytecodeLength_(0),
         inlineMaxTotalBytecodeLength_(0),
         inliningMaxCallerBytecodeLength_(0),
         maxInlineDepth_(0),
         scalarReplacement_(false),
         smallFunctionMaxInlineDepth_(0),
-        compilerWarmUpThreshold_(0),
         inliningWarmUpThresholdFactor_(0.0),
         inliningRecompileThresholdFactor_(0) {}
 
   void initNormalOptimizationInfo();
   void initWasmOptimizationInfo();
 
   OptimizationLevel level() const { return level_; }
 
@@ -233,20 +238,17 @@ class OptimizationInfo {
     return inlineMaxTotalBytecodeLength_;
   }
 
   uint32_t inliningMaxCallerBytecodeLength() const {
     return inliningMaxCallerBytecodeLength_;
   }
 
   uint32_t inliningWarmUpThreshold() const {
-    uint32_t compilerWarmUpThreshold =
-        JitOptions.forcedDefaultIonWarmUpThreshold.valueOr(
-            compilerWarmUpThreshold_);
-    return compilerWarmUpThreshold * inliningWarmUpThresholdFactor_;
+    return baseCompilerWarmUpThreshold() * inliningWarmUpThresholdFactor_;
   }
 
   uint32_t inliningRecompileThreshold() const {
     return inliningWarmUpThreshold() * inliningRecompileThresholdFactor_;
   }
 };
 
 class OptimizationLevelInfo {
--- a/js/src/jit/JitOptions.cpp
+++ b/js/src/jit/JitOptions.cpp
@@ -151,16 +151,21 @@ DefaultJitOptions::DefaultJitOptions() {
   // Whether to enable extra code to perform dynamic validations.
   SET_DEFAULT(runExtraChecks, false);
 
   // How many invocations or loop iterations are needed before functions
   // are compiled with the baseline compiler.
   // Duplicated in all.js - ensure both match.
   SET_DEFAULT(baselineWarmUpThreshold, 10);
 
+  // How many invocations or loop iterations are needed before functions
+  // are compiled with the Ion compiler at OptimizationLevel::Normal.
+  // Duplicated in all.js - ensure both match.
+  SET_DEFAULT(normalIonWarmUpThreshold, 1000);
+
   // Number of exception bailouts (resuming into catch/finally block) before
   // we invalidate and forbid Ion compilation.
   SET_DEFAULT(exceptionBailoutThreshold, 10);
 
   // Number of bailouts without invalidation before we set
   // JSScript::hadFrequentBailouts and invalidate.
   // Duplicated in all.js - ensure both match.
   SET_DEFAULT(frequentBailoutThreshold, 10);
@@ -189,30 +194,16 @@ DefaultJitOptions::DefaultJitOptions() {
   // score is compared against a threshold to prevent a branch from being
   // removed.
   SET_DEFAULT(branchPruningHitCountFactor, 1);
   SET_DEFAULT(branchPruningInstFactor, 10);
   SET_DEFAULT(branchPruningBlockSpanFactor, 100);
   SET_DEFAULT(branchPruningEffectfulInstFactor, 3500);
   SET_DEFAULT(branchPruningThreshold, 4000);
 
-  // Force how many invocation or loop iterations are needed before compiling
-  // a function with the highest ionmonkey optimization level.
-  // (i.e. OptimizationLevel_Normal)
-  const char* forcedDefaultIonWarmUpThresholdEnv =
-      "JIT_OPTION_forcedDefaultIonWarmUpThreshold";
-  if (const char* env = getenv(forcedDefaultIonWarmUpThresholdEnv)) {
-    Maybe<int> value = ParseInt(env);
-    if (value.isSome()) {
-      forcedDefaultIonWarmUpThreshold.emplace(value.ref());
-    } else {
-      Warn(forcedDefaultIonWarmUpThresholdEnv, env);
-    }
-  }
-
   // Force the used register allocator instead of letting the optimization
   // pass decide.
   const char* forcedRegisterAllocatorEnv = "JIT_OPTION_forcedRegisterAllocator";
   if (const char* env = getenv(forcedRegisterAllocatorEnv)) {
     forcedRegisterAllocator = LookupRegisterAllocator(env);
     if (!forcedRegisterAllocator.isSome()) {
       Warn(forcedRegisterAllocatorEnv, env);
     }
@@ -274,37 +265,35 @@ bool DefaultJitOptions::isSmallFunction(
   return script->length() <= smallFunctionMaxBytecodeLength_;
 }
 
 void DefaultJitOptions::enableGvn(bool enable) { disableGvn = !enable; }
 
 void DefaultJitOptions::setEagerCompilation() {
   eagerCompilation = true;
   baselineWarmUpThreshold = 0;
-  forcedDefaultIonWarmUpThreshold.reset();
-  forcedDefaultIonWarmUpThreshold.emplace(0);
+  normalIonWarmUpThreshold = 0;
 }
 
 void DefaultJitOptions::setCompilerWarmUpThreshold(uint32_t warmUpThreshold) {
-  forcedDefaultIonWarmUpThreshold.reset();
-  forcedDefaultIonWarmUpThreshold.emplace(warmUpThreshold);
+  normalIonWarmUpThreshold = warmUpThreshold;
 
   // Undo eager compilation
   if (eagerCompilation && warmUpThreshold != 0) {
     jit::DefaultJitOptions defaultValues;
     eagerCompilation = false;
     baselineWarmUpThreshold = defaultValues.baselineWarmUpThreshold;
   }
 }
 
 void DefaultJitOptions::resetCompilerWarmUpThreshold() {
-  forcedDefaultIonWarmUpThreshold.reset();
+  jit::DefaultJitOptions defaultValues;
+  normalIonWarmUpThreshold = defaultValues.normalIonWarmUpThreshold;
 
   // Undo eager compilation
   if (eagerCompilation) {
-    jit::DefaultJitOptions defaultValues;
     eagerCompilation = false;
     baselineWarmUpThreshold = defaultValues.baselineWarmUpThreshold;
   }
 }
 
 }  // namespace jit
 }  // namespace js
--- a/js/src/jit/JitOptions.h
+++ b/js/src/jit/JitOptions.h
@@ -78,30 +78,30 @@ struct DefaultJitOptions {
 #ifdef WASM_CODEGEN_DEBUG
   bool enableWasmJitExit;
   bool enableWasmJitEntry;
   bool enableWasmIonFastCalls;
   bool enableWasmImportCallSpew;
   bool enableWasmFuncCallSpew;
 #endif
   uint32_t baselineWarmUpThreshold;
+  uint32_t normalIonWarmUpThreshold;
   uint32_t exceptionBailoutThreshold;
   uint32_t frequentBailoutThreshold;
   uint32_t maxStackArgs;
   uint32_t osrPcMismatchesBeforeRecompile;
   uint32_t smallFunctionMaxBytecodeLength_;
   uint32_t jumpThreshold;
   uint32_t branchPruningHitCountFactor;
   uint32_t branchPruningInstFactor;
   uint32_t branchPruningBlockSpanFactor;
   uint32_t branchPruningEffectfulInstFactor;
   uint32_t branchPruningThreshold;
   uint32_t wasmBatchIonThreshold;
   uint32_t wasmBatchBaselineThreshold;
-  mozilla::Maybe<uint32_t> forcedDefaultIonWarmUpThreshold;
   mozilla::Maybe<IonRegisterAllocator> forcedRegisterAllocator;
 
   // Spectre mitigation flags. Each mitigation has its own flag in order to
   // measure the effectiveness of each mitigation with various proof of
   // concept.
   bool spectreIndexMasking;
   bool spectreObjectMitigationsBarriers;
   bool spectreObjectMitigationsMisc;
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -5605,18 +5605,17 @@ JS_PUBLIC_API bool JS_GetGlobalJitCompil
   MOZ_ASSERT(valueOut);
 #ifndef JS_CODEGEN_NONE
   JSRuntime* rt = cx->runtime();
   switch (opt) {
     case JSJITCOMPILER_BASELINE_WARMUP_TRIGGER:
       *valueOut = jit::JitOptions.baselineWarmUpThreshold;
       break;
     case JSJITCOMPILER_ION_WARMUP_TRIGGER:
-      *valueOut = jit::JitOptions.forcedDefaultIonWarmUpThreshold.valueOr(
-          jit::OptimizationInfo::CompilerWarmupThreshold);
+      *valueOut = jit::JitOptions.normalIonWarmUpThreshold;
       break;
     case JSJITCOMPILER_ION_FORCE_IC:
       *valueOut = jit::JitOptions.forceInlineCaches;
       break;
     case JSJITCOMPILER_ION_CHECK_RANGE_ANALYSIS:
       *valueOut = jit::JitOptions.checkRangeAnalysis;
       break;
     case JSJITCOMPILER_ION_ENABLE: