Bug 1415920 - make better use of Maybe for computing jit warm up thresholds; r=jandem
authorNathan Froyd <froydnj@mozilla.com>
Tue, 14 Nov 2017 13:46:16 -0500
changeset 436238 b567889382a5cc42c0e878d860937b7d6061cc2b
parent 436237 309536e6c69c7d2bcb0db255edfd8687afe48d64
child 436239 e963baf002da6cc591edaa0ad6917b95188c337c
push id117
push userfmarier@mozilla.com
push dateTue, 28 Nov 2017 20:17:16 +0000
reviewersjandem
bugs1415920
milestone59.0a1
Bug 1415920 - make better use of Maybe for computing jit warm up thresholds; r=jandem `Maybe` has some nice utility functions that can replace conditionals; let's use those instead of nested conditionals.
js/src/jit/IonOptimizationLevels.cpp
js/src/jit/IonOptimizationLevels.h
js/src/jsapi.cpp
--- a/js/src/jit/IonOptimizationLevels.cpp
+++ b/js/src/jit/IonOptimizationLevels.cpp
@@ -13,16 +13,19 @@
 using namespace js;
 using namespace js::jit;
 
 namespace js {
 namespace jit {
 
 OptimizationLevelInfo IonOptimizations;
 
+const uint32_t OptimizationInfo::CompilerWarmupThreshold = 1000;
+const uint32_t OptimizationInfo::CompilerSmallFunctionWarmupThreshold = CompilerWarmupThreshold;
+
 void
 OptimizationInfo::initNormalOptimizationInfo()
 {
     level_ = OptimizationLevel::Normal;
 
     autoTruncate_ = true;
     eaa_ = true;
     eagerSimdUnbox_ = true;
@@ -78,24 +81,22 @@ OptimizationInfo::initWasmOptimizationIn
 uint32_t
 OptimizationInfo::compilerWarmUpThreshold(JSScript* script, jsbytecode* pc) const
 {
     MOZ_ASSERT(pc == nullptr || pc == script->code() || JSOp(*pc) == JSOP_LOOPENTRY);
 
     if (pc == script->code())
         pc = nullptr;
 
-    uint32_t warmUpThreshold = compilerWarmUpThreshold_;
-    if (JitOptions.forcedDefaultIonWarmUpThreshold.isSome())
-        warmUpThreshold = JitOptions.forcedDefaultIonWarmUpThreshold.ref();
+    uint32_t warmUpThreshold = JitOptions.forcedDefaultIonWarmUpThreshold
+        .valueOr(compilerWarmUpThreshold_);
 
     if (JitOptions.isSmallFunction(script)) {
-        warmUpThreshold = compilerSmallFunctionWarmUpThreshold_;
-        if (JitOptions.forcedDefaultIonSmallFunctionWarmUpThreshold.isSome())
-            warmUpThreshold = JitOptions.forcedDefaultIonSmallFunctionWarmUpThreshold.ref();
+        warmUpThreshold = JitOptions.forcedDefaultIonSmallFunctionWarmUpThreshold
+            .valueOr(compilerSmallFunctionWarmUpThreshold_);
     }
 
     // If the script is too large to compile on the active 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_ACTIVE_THREAD_SCRIPT_SIZE)
--- a/js/src/jit/IonOptimizationLevels.h
+++ b/js/src/jit/IonOptimizationLevels.h
@@ -127,24 +127,24 @@ class OptimizationInfo
     // 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 = 1000;
+    static const uint32_t CompilerWarmupThreshold;
 
     // How many invocations or loop iterations are needed before small functions
     // are compiled.
     uint32_t compilerSmallFunctionWarmUpThreshold_;
 
     // Default small function compiler warmup threshold, unless it is overridden.
-    static const uint32_t CompilerSmallFunctionWarmupThreshold = CompilerWarmupThreshold;
+    static const uint32_t CompilerSmallFunctionWarmupThreshold;
 
     // 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.
@@ -222,19 +222,18 @@ class OptimizationInfo
         return eliminateRedundantChecks_;
     }
 
     bool flowAliasAnalysisEnabled() const {
         return !JitOptions.disableFlowAA;
     }
 
     IonRegisterAllocator registerAllocator() const {
-        if (JitOptions.forcedRegisterAllocator.isSome())
-            return JitOptions.forcedRegisterAllocator.ref();
-        return registerAllocator_;
+        return JitOptions.forcedRegisterAllocator
+            .valueOr(registerAllocator_);
     }
 
     bool scalarReplacementEnabled() const {
         return scalarReplacement_ && !JitOptions.disableScalarReplacement;
     }
 
     uint32_t smallFunctionMaxInlineDepth() const {
         return smallFunctionMaxInlineDepth_;
@@ -260,19 +259,18 @@ class OptimizationInfo
         return inlineMaxTotalBytecodeLength_;
     }
 
     uint32_t inliningMaxCallerBytecodeLength() const {
         return inliningMaxCallerBytecodeLength_;
     }
 
     uint32_t inliningWarmUpThreshold() const {
-        uint32_t compilerWarmUpThreshold = compilerWarmUpThreshold_;
-        if (JitOptions.forcedDefaultIonWarmUpThreshold.isSome())
-            compilerWarmUpThreshold = JitOptions.forcedDefaultIonWarmUpThreshold.ref();
+        uint32_t compilerWarmUpThreshold = JitOptions.forcedDefaultIonWarmUpThreshold
+            .valueOr(compilerWarmUpThreshold_);
         return compilerWarmUpThreshold * inliningWarmUpThresholdFactor_;
     }
 
     uint32_t inliningRecompileThreshold() const {
         return inliningWarmUpThreshold() * inliningRecompileThresholdFactor_;
     }
 };
 
--- a/js/src/jsapi.cpp
+++ b/js/src/jsapi.cpp
@@ -7277,19 +7277,18 @@ JS_GetGlobalJitCompilerOption(JSContext*
     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.isSome()
-                  ? jit::JitOptions.forcedDefaultIonWarmUpThreshold.ref()
-                  : jit::OptimizationInfo::CompilerWarmupThreshold;
+        *valueOut = jit::JitOptions.forcedDefaultIonWarmUpThreshold
+            .valueOr(jit::OptimizationInfo::CompilerWarmupThreshold);
         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: