Bug 1505689 part 9 - Use static const values instead of macros for magic BASELINE_*_SCRIPT and ION_*_SCRIPT values. r=tcampbell
authorJan de Mooij <jdemooij@mozilla.com>
Thu, 15 Aug 2019 16:14:26 +0000
changeset 488281 d024bd1f20c28bbf183decce5582427eff6f8785
parent 488280 11d01998d8f72baa0994f4a967dbe259fe7d55d1
child 488282 36da938c155282e93753e0d0db8c61bcf1ddd04a
push id36440
push userncsoregi@mozilla.com
push dateFri, 16 Aug 2019 03:57:48 +0000
treeherdermozilla-central@a58b7dc85887 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerstcampbell
bugs1505689
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1505689 part 9 - Use static const values instead of macros for magic BASELINE_*_SCRIPT and ION_*_SCRIPT values. r=tcampbell This defines both |constexpr uintptr_t| and |const pointer| values. reinterpret_cast in constexpr is not allowed and this way we can still use these values in static_asserts. Differential Revision: https://phabricator.services.mozilla.com/D42109
js/src/jit/BaselineCodeGen.cpp
js/src/jit/JitScript.cpp
js/src/jit/JitScript.h
js/src/vm/JSScript-inl.h
--- a/js/src/jit/BaselineCodeGen.cpp
+++ b/js/src/jit/BaselineCodeGen.cpp
@@ -1309,19 +1309,19 @@ bool BaselineCompilerCodeGen::emitWarmUp
   uint32_t warmUpThreshold = info->compilerWarmUpThreshold(script, pc);
   masm.branch32(Assembler::LessThan, countReg, Imm32(warmUpThreshold),
                 &skipCall);
 
   // Do nothing if Ion is already compiling this script off-thread or if Ion has
   // been disabled for this script.
   masm.movePtr(ImmPtr(script->jitScript()), scriptReg);
   masm.loadPtr(Address(scriptReg, JitScript::offsetOfIonScript()), scriptReg);
-  masm.branchPtr(Assembler::Equal, scriptReg, ImmPtr(ION_COMPILING_SCRIPT),
+  masm.branchPtr(Assembler::Equal, scriptReg, ImmPtr(IonCompilingScriptPtr),
                  &skipCall);
-  masm.branchPtr(Assembler::Equal, scriptReg, ImmPtr(ION_DISABLED_SCRIPT),
+  masm.branchPtr(Assembler::Equal, scriptReg, ImmPtr(IonDisabledScriptPtr),
                  &skipCall);
 
   // Try to compile and/or finish a compilation.
   if (JSOp(*pc) == JSOP_LOOPENTRY) {
     // During the loop entry we can try to OSR into ion.
     // The ic has logic for this.
     if (!emitNextIC()) {
       return false;
@@ -1362,17 +1362,17 @@ bool BaselineInterpreterCodeGen::emitWar
   // If the script is warm enough for Baseline compilation, call into the VM to
   // compile it.
   Label done;
   masm.branch32(Assembler::BelowOrEqual, countReg,
                 Imm32(JitOptions.baselineJitWarmUpThreshold), &done);
   masm.loadPtr(Address(scriptReg, JSScript::offsetOfJitScript()), scriptReg);
   masm.branchPtr(Assembler::Equal,
                  Address(scriptReg, JitScript::offsetOfBaselineScript()),
-                 ImmPtr(BASELINE_DISABLED_SCRIPT), &done);
+                 ImmPtr(BaselineDisabledScriptPtr), &done);
   {
     prepareVMCall();
 
     masm.PushBaselineFramePtr(BaselineFrameReg, R0.scratchReg());
 
     using Fn = bool (*)(JSContext*, BaselineFrame*, uint8_t**);
     if (!callVM<Fn, BaselineCompileFromBaselineInterpreter>()) {
       return false;
@@ -5982,21 +5982,25 @@ void BaselineInterpreterCodeGen::emitJum
   masm.jump(handler.interpretOpLabel());
 }
 
 template <typename Handler>
 bool BaselineCodeGen<Handler>::emitEnterGeneratorCode(Register script,
                                                       Register resumeIndex,
                                                       Register scratch) {
   // Resume in either the BaselineScript (if present) or Baseline Interpreter.
+
+  static_assert(BaselineDisabledScript == 0x1,
+                "Comparison below requires specific sentinel encoding");
+
   Label noBaselineScript;
   masm.loadPtr(Address(script, JSScript::offsetOfJitScript()), scratch);
   masm.loadPtr(Address(scratch, JitScript::offsetOfBaselineScript()), scratch);
   masm.branchPtr(Assembler::BelowOrEqual, scratch,
-                 ImmPtr(BASELINE_DISABLED_SCRIPT), &noBaselineScript);
+                 ImmPtr(BaselineDisabledScriptPtr), &noBaselineScript);
   masm.load32(Address(scratch, BaselineScript::offsetOfResumeEntriesOffset()),
               script);
   masm.addPtr(scratch, script);
   masm.loadPtr(
       BaseIndex(script, resumeIndex, ScaleFromElemWidth(sizeof(uintptr_t))),
       scratch);
   masm.jump(scratch);
 
--- a/js/src/jit/JitScript.cpp
+++ b/js/src/jit/JitScript.cpp
@@ -53,20 +53,20 @@ JitScript::JitScript(JSScript* script, u
   setTypesGeneration(script->zone()->types.generation);
 
   uint8_t* base = reinterpret_cast<uint8_t*>(this);
   DefaultInitializeElements<StackTypeSet>(base + typeSetOffset, numTypeSets());
 
   // Ensure the baselineScript_ and ionScript_ fields match the BaselineDisabled
   // and IonDisabled script flags.
   if (!script->canBaselineCompile()) {
-    setBaselineScriptImpl(script, BASELINE_DISABLED_SCRIPT);
+    setBaselineScriptImpl(script, BaselineDisabledScriptPtr);
   }
   if (!script->canIonCompile()) {
-    setIonScriptImpl(script, ION_DISABLED_SCRIPT);
+    setIonScriptImpl(script, IonDisabledScriptPtr);
   }
 }
 
 bool JSScript::createJitScript(JSContext* cx) {
   MOZ_ASSERT(!jitScript_);
   cx->check(this);
 
   // Scripts with a JitScript can run in the Baseline Interpreter. Make sure
@@ -600,17 +600,17 @@ void JitScript::setBaselineScriptImpl(JS
                                       BaselineScript* baselineScript) {
   if (hasBaselineScript()) {
     BaselineScript::writeBarrierPre(script->zone(), baselineScript_);
     fop->removeCellMemory(script, baselineScript_->allocBytes(),
                           MemoryUse::BaselineScript);
     baselineScript_ = nullptr;
   }
 
-  MOZ_ASSERT(!ionScript_ || ionScript_ == ION_DISABLED_SCRIPT);
+  MOZ_ASSERT(ionScript_ == nullptr || ionScript_ == IonDisabledScriptPtr);
 
   baselineScript_ = baselineScript;
   if (hasBaselineScript()) {
     AddCellMemory(script, baselineScript_->allocBytes(),
                   MemoryUse::BaselineScript);
   }
 
   script->resetWarmUpResetCounter();
@@ -619,17 +619,17 @@ void JitScript::setBaselineScriptImpl(JS
 
 void JitScript::setIonScriptImpl(JSScript* script, IonScript* ionScript) {
   JSRuntime* rt = script->runtimeFromMainThread();
   setIonScriptImpl(rt->defaultFreeOp(), script, ionScript);
 }
 
 void JitScript::setIonScriptImpl(JSFreeOp* fop, JSScript* script,
                                  IonScript* ionScript) {
-  MOZ_ASSERT_IF(ionScript != ION_DISABLED_SCRIPT,
+  MOZ_ASSERT_IF(ionScript != IonDisabledScriptPtr,
                 !baselineScript()->hasPendingIonBuilder());
 
   if (hasIonScript()) {
     IonScript::writeBarrierPre(script->zone(), ionScript_);
     fop->removeCellMemory(script, ionScript_->allocBytes(),
                           MemoryUse::IonScript);
     ionScript_ = nullptr;
   }
--- a/js/src/jit/JitScript.h
+++ b/js/src/jit/JitScript.h
@@ -31,22 +31,30 @@ struct DependentWasmImport {
 // Information about a script's bytecode, used by IonBuilder. This is cached
 // in JitScript.
 struct IonBytecodeInfo {
   bool usesEnvironmentChain = false;
   bool modifiesArguments = false;
 };
 
 // Magic BaselineScript value indicating Baseline compilation has been disabled.
-#define BASELINE_DISABLED_SCRIPT ((js::jit::BaselineScript*)0x1)
+static constexpr uintptr_t BaselineDisabledScript = 0x1;
+
+static BaselineScript* const BaselineDisabledScriptPtr =
+    reinterpret_cast<BaselineScript*>(BaselineDisabledScript);
 
 // Magic IonScript values indicating Ion compilation has been disabled or the
 // script is being Ion-compiled off-thread.
-#define ION_DISABLED_SCRIPT ((js::jit::IonScript*)0x1)
-#define ION_COMPILING_SCRIPT ((js::jit::IonScript*)0x2)
+static constexpr uintptr_t IonDisabledScript = 0x1;
+static constexpr uintptr_t IonCompilingScript = 0x2;
+
+static IonScript* const IonDisabledScriptPtr =
+    reinterpret_cast<IonScript*>(IonDisabledScript);
+static IonScript* const IonCompilingScriptPtr =
+    reinterpret_cast<IonScript*>(IonCompilingScript);
 
 // [SMDOC] JitScript
 //
 // JitScript stores type inference data, Baseline ICs and other JIT-related data
 // for a script. Scripts with a JitScript can run in the Baseline Interpreter.
 //
 // IC Data
 // =======
@@ -157,22 +165,22 @@ class alignas(uintptr_t) JitScript final
 
     CachedIonData(const CachedIonData&) = delete;
     void operator=(const CachedIonData&) = delete;
 
     void trace(JSTracer* trc);
   };
   js::UniquePtr<CachedIonData> cachedIonData_;
 
-  // Baseline code for the script. Either nullptr, BASELINE_DISABLED_SCRIPT or
+  // Baseline code for the script. Either nullptr, BaselineDisabledScriptPtr or
   // a valid BaselineScript*.
   BaselineScript* baselineScript_ = nullptr;
 
-  // Ion code for this script. Either nullptr, ION_DISABLED_SCRIPT,
-  // ION_COMPILING_SCRIPT or a valid IonScript*.
+  // Ion code for this script. Either nullptr, IonDisabledScriptPtr,
+  // IonCompilingScriptPtr or a valid IonScript*.
   IonScript* ionScript_ = nullptr;
 
   // Offset of the StackTypeSet array.
   uint32_t typeSetOffset_ = 0;
 
   // Offset of the bytecode type map.
   uint32_t bytecodeTypeMapOffset_ = 0;
 
@@ -483,25 +491,25 @@ class alignas(uintptr_t) JitScript final
     if (len > UINT16_MAX) {
       len = UINT16_MAX;
     }
     cachedIonData().inlinedBytecodeLength = len;
   }
 
  private:
   // Methods to set baselineScript_ to a BaselineScript*, nullptr, or
-  // BASELINE_DISABLED_SCRIPT.
+  // BaselineDisabledScriptPtr.
   void setBaselineScriptImpl(JSScript* script, BaselineScript* baselineScript);
   void setBaselineScriptImpl(JSFreeOp* fop, JSScript* script,
                              BaselineScript* baselineScript);
 
  public:
   // Methods for getting/setting/clearing a BaselineScript*.
   bool hasBaselineScript() const {
-    bool res = baselineScript_ && baselineScript_ != BASELINE_DISABLED_SCRIPT;
+    bool res = baselineScript_ && baselineScript_ != BaselineDisabledScriptPtr;
     MOZ_ASSERT_IF(!res, !hasIonScript());
     return res;
   }
   BaselineScript* baselineScript() const {
     MOZ_ASSERT(hasBaselineScript());
     return baselineScript_;
   }
   void setBaselineScript(JSScript* script, BaselineScript* baselineScript) {
@@ -513,25 +521,25 @@ class alignas(uintptr_t) JitScript final
                                                    JSScript* script) {
     BaselineScript* baseline = baselineScript();
     setBaselineScriptImpl(fop, script, nullptr);
     return baseline;
   }
 
  private:
   // Methods to set ionScript_ to an IonScript*, nullptr, or one of the special
-  // ION_{DISABLED,COMPILING}_SCRIPT values.
+  // Ion{Disabled,Compiling}ScriptPtr values.
   void setIonScriptImpl(JSFreeOp* fop, JSScript* script, IonScript* ionScript);
   void setIonScriptImpl(JSScript* script, IonScript* ionScript);
 
  public:
   // Methods for getting/setting/clearing an IonScript*.
   bool hasIonScript() const {
-    bool res = ionScript_ && ionScript_ != ION_DISABLED_SCRIPT &&
-               ionScript_ != ION_COMPILING_SCRIPT;
+    bool res = ionScript_ && ionScript_ != IonDisabledScriptPtr &&
+               ionScript_ != IonCompilingScriptPtr;
     MOZ_ASSERT_IF(res, baselineScript_);
     return res;
   }
   IonScript* ionScript() const {
     MOZ_ASSERT(hasIonScript());
     return ionScript_;
   }
   void setIonScript(JSScript* script, IonScript* ionScript) {
@@ -542,21 +550,21 @@ class alignas(uintptr_t) JitScript final
   MOZ_MUST_USE IonScript* clearIonScript(JSFreeOp* fop, JSScript* script) {
     IonScript* ion = ionScript();
     setIonScriptImpl(fop, script, nullptr);
     return ion;
   }
 
   // Methods for off-thread compilation.
   bool isIonCompilingOffThread() const {
-    return ionScript_ == ION_COMPILING_SCRIPT;
+    return ionScript_ == IonCompilingScriptPtr;
   }
   void setIsIonCompilingOffThread(JSScript* script) {
     MOZ_ASSERT(ionScript_ == nullptr);
-    setIonScriptImpl(script, ION_COMPILING_SCRIPT);
+    setIonScriptImpl(script, IonCompilingScriptPtr);
   }
   void clearIsIonCompilingOffThread(JSScript* script) {
     MOZ_ASSERT(isIonCompilingOffThread());
     setIonScriptImpl(script, nullptr);
   }
 };
 
 // Ensures no JitScripts are purged in the current zone.
--- a/js/src/vm/JSScript-inl.h
+++ b/js/src/vm/JSScript-inl.h
@@ -183,46 +183,47 @@ inline bool JSScript::isIonCompilingOffT
   return jitScript_ && jitScript_->isIonCompilingOffThread();
 }
 
 inline bool JSScript::canBaselineCompile() const {
   bool disabled = hasFlag(MutableFlags::BaselineDisabled);
 #ifdef DEBUG
   if (jitScript_) {
     bool jitScriptDisabled =
-        jitScript_->baselineScript_ == BASELINE_DISABLED_SCRIPT;
+        jitScript_->baselineScript_ == js::jit::BaselineDisabledScriptPtr;
     MOZ_ASSERT(disabled == jitScriptDisabled);
   }
 #endif
   return !disabled;
 }
 
 inline bool JSScript::canIonCompile() const {
   bool disabled = hasFlag(MutableFlags::IonDisabled);
 #ifdef DEBUG
   if (jitScript_) {
-    bool jitScriptDisabled = jitScript_->ionScript_ == ION_DISABLED_SCRIPT;
+    bool jitScriptDisabled =
+        jitScript_->ionScript_ == js::jit::IonDisabledScriptPtr;
     MOZ_ASSERT(disabled == jitScriptDisabled);
   }
 #endif
   return !disabled;
 }
 
 inline void JSScript::disableBaselineCompile() {
   MOZ_ASSERT(!hasBaselineScript());
   setFlag(MutableFlags::BaselineDisabled);
   if (jitScript_) {
-    jitScript_->setBaselineScriptImpl(this, BASELINE_DISABLED_SCRIPT);
+    jitScript_->setBaselineScriptImpl(this, js::jit::BaselineDisabledScriptPtr);
   }
 }
 
 inline void JSScript::disableIon() {
   setFlag(MutableFlags::IonDisabled);
   if (jitScript_) {
-    jitScript_->setIonScriptImpl(this, ION_DISABLED_SCRIPT);
+    jitScript_->setIonScriptImpl(this, js::jit::IonDisabledScriptPtr);
   }
 }
 
 inline js::jit::BaselineScript* JSScript::baselineScript() const {
   return jitScript_->baselineScript();
 }
 
 inline js::jit::IonScript* JSScript::ionScript() const {