Bug 1532421 - Use ValueType in BaselineIC's TypeCheckPrimitiveSetStub. r=mgaudet
authorTom Schuster <evilpies@gmail.com>
Thu, 07 Mar 2019 16:39:01 +0000
changeset 521176 cce35becf71943cab026b822c2ee6836db21150a
parent 521175 cfa16385f4156dbc162ae2fc302d4a0c24e2c9ed
child 521177 64e2378a756b10054fc197bced32f8a587bee8f5
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmgaudet
bugs1532421
milestone67.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 1532421 - Use ValueType in BaselineIC's TypeCheckPrimitiveSetStub. r=mgaudet This also makes sure that ValueType::PrivateGCThing isn't used, similar to ValueType::Magic. Differential Revision: https://phabricator.services.mozilla.com/D22007
js/src/jit/BaselineIC.cpp
js/src/jit/BaselineIC.h
--- a/js/src/jit/BaselineIC.cpp
+++ b/js/src/jit/BaselineIC.cpp
@@ -1231,18 +1231,17 @@ bool ICTypeMonitor_Fallback::addMonitorS
             stub);
     addOptimizedMonitorStub(stub);
 
   } else if (val.isPrimitive() || types->unknownObject()) {
     if (val.isMagic(JS_UNINITIALIZED_LEXICAL)) {
       return true;
     }
     MOZ_ASSERT(!val.isMagic());
-    JSValueType type =
-        val.isDouble() ? JSVAL_TYPE_DOUBLE : val.extractNonDoubleType();
+    ValueType type = val.type();
 
     // Check for existing TypeMonitor stub.
     ICTypeMonitor_PrimitiveSet* existingStub = nullptr;
     for (ICStubConstIterator iter(firstMonitorStub()); !iter.atEnd(); iter++) {
       if (iter->isTypeMonitor_PrimitiveSet()) {
         existingStub = iter->toTypeMonitor_PrimitiveSet();
         if (existingStub->containsType(type)) {
           return true;
@@ -1277,18 +1276,19 @@ bool ICTypeMonitor_Fallback::addMonitorS
         existingStub ? compiler.updateStub()
                      : compiler.getStub(compiler.getStubSpace(frame->script()));
     if (!stub) {
       ReportOutOfMemory(cx);
       return false;
     }
 
     JitSpew(JitSpew_BaselineIC,
-            "  %s TypeMonitor stub %p for primitive type %d",
-            existingStub ? "Modified existing" : "Created new", stub, type);
+            "  %s TypeMonitor stub %p for primitive type %u",
+            existingStub ? "Modified existing" : "Created new", stub,
+            static_cast<uint8_t>(type));
 
     if (!existingStub) {
       MOZ_ASSERT(!hasStub(TypeMonitor_PrimitiveSet));
       addOptimizedMonitorStub(stub);
     }
 
   } else if (val.toObject().isSingleton()) {
     RootedObject obj(cx, &val.toObject());
@@ -1436,50 +1436,50 @@ bool ICTypeMonitor_Fallback::Compiler::g
   masm.pushBaselineFramePtr(BaselineFrameReg, R0.scratchReg());
 
   return tailCallVM(DoTypeMonitorFallbackInfo, masm);
 }
 
 bool ICTypeMonitor_PrimitiveSet::Compiler::generateStubCode(
     MacroAssembler& masm) {
   Label success;
-  if ((flags_ & TypeToFlag(JSVAL_TYPE_INT32)) &&
-      !(flags_ & TypeToFlag(JSVAL_TYPE_DOUBLE))) {
+  if ((flags_ & TypeToFlag(ValueType::Int32)) &&
+      !(flags_ & TypeToFlag(ValueType::Double))) {
     masm.branchTestInt32(Assembler::Equal, R0, &success);
   }
 
-  if (flags_ & TypeToFlag(JSVAL_TYPE_DOUBLE)) {
+  if (flags_ & TypeToFlag(ValueType::Double)) {
     masm.branchTestNumber(Assembler::Equal, R0, &success);
   }
 
-  if (flags_ & TypeToFlag(JSVAL_TYPE_UNDEFINED)) {
+  if (flags_ & TypeToFlag(ValueType::Undefined)) {
     masm.branchTestUndefined(Assembler::Equal, R0, &success);
   }
 
-  if (flags_ & TypeToFlag(JSVAL_TYPE_BOOLEAN)) {
+  if (flags_ & TypeToFlag(ValueType::Boolean)) {
     masm.branchTestBoolean(Assembler::Equal, R0, &success);
   }
 
-  if (flags_ & TypeToFlag(JSVAL_TYPE_STRING)) {
+  if (flags_ & TypeToFlag(ValueType::String)) {
     masm.branchTestString(Assembler::Equal, R0, &success);
   }
 
-  if (flags_ & TypeToFlag(JSVAL_TYPE_SYMBOL)) {
+  if (flags_ & TypeToFlag(ValueType::Symbol)) {
     masm.branchTestSymbol(Assembler::Equal, R0, &success);
   }
 
-  if (flags_ & TypeToFlag(JSVAL_TYPE_BIGINT)) {
+  if (flags_ & TypeToFlag(ValueType::BigInt)) {
     masm.branchTestBigInt(Assembler::Equal, R0, &success);
   }
 
-  if (flags_ & TypeToFlag(JSVAL_TYPE_OBJECT)) {
+  if (flags_ & TypeToFlag(ValueType::Object)) {
     masm.branchTestObject(Assembler::Equal, R0, &success);
   }
 
-  if (flags_ & TypeToFlag(JSVAL_TYPE_NULL)) {
+  if (flags_ & TypeToFlag(ValueType::Null)) {
     masm.branchTestNull(Assembler::Equal, R0, &success);
   }
 
   EmitStubGuardFailure(masm);
 
   masm.bind(&success);
   EmitReturnFromIC(masm);
   return true;
@@ -1600,18 +1600,17 @@ bool ICUpdatedStub::addUpdateStubForValu
       return false;
     }
 
     JitSpew(JitSpew_BaselineIC, "  Added TypeUpdate stub %p for any value",
             stub);
     addOptimizedUpdateStub(stub);
 
   } else if (val.isPrimitive() || unknownObject) {
-    JSValueType type =
-        val.isDouble() ? JSVAL_TYPE_DOUBLE : val.extractNonDoubleType();
+    ValueType type = val.type();
 
     // Check for existing TypeUpdate stub.
     ICTypeUpdate_PrimitiveSet* existingStub = nullptr;
     for (ICStubConstIterator iter(firstUpdateStub_); !iter.atEnd(); iter++) {
       if (iter->isTypeUpdate_PrimitiveSet()) {
         existingStub = iter->toTypeUpdate_PrimitiveSet();
         MOZ_ASSERT(!existingStub->containsType(type));
       }
@@ -1633,17 +1632,18 @@ bool ICUpdatedStub::addUpdateStubForValu
       return false;
     }
     if (!existingStub) {
       MOZ_ASSERT(!hasTypeUpdateStub(TypeUpdate_PrimitiveSet));
       addOptimizedUpdateStub(stub);
     }
 
     JitSpew(JitSpew_BaselineIC, "  %s TypeUpdate stub %p for primitive type %d",
-            existingStub ? "Modified existing" : "Created new", stub, type);
+            existingStub ? "Modified existing" : "Created new", stub,
+            static_cast<uint8_t>(type));
 
   } else if (val.toObject().isSingleton()) {
     RootedObject obj(cx, &val.toObject());
 
 #ifdef DEBUG
     // We should not have a stub for this object.
     for (ICStubConstIterator iter(firstUpdateStub_); !iter.atEnd(); iter++) {
       MOZ_ASSERT_IF(iter->isTypeUpdate_SingleObject(),
@@ -1780,50 +1780,50 @@ bool ICTypeUpdate_Fallback::Compiler::ge
   masm.move32(Imm32(0), R1.scratchReg());
   EmitReturnFromIC(masm);
   return true;
 }
 
 bool ICTypeUpdate_PrimitiveSet::Compiler::generateStubCode(
     MacroAssembler& masm) {
   Label success;
-  if ((flags_ & TypeToFlag(JSVAL_TYPE_INT32)) &&
-      !(flags_ & TypeToFlag(JSVAL_TYPE_DOUBLE))) {
+  if ((flags_ & TypeToFlag(ValueType::Int32)) &&
+      !(flags_ & TypeToFlag(ValueType::Double))) {
     masm.branchTestInt32(Assembler::Equal, R0, &success);
   }
 
-  if (flags_ & TypeToFlag(JSVAL_TYPE_DOUBLE)) {
+  if (flags_ & TypeToFlag(ValueType::Double)) {
     masm.branchTestNumber(Assembler::Equal, R0, &success);
   }
 
-  if (flags_ & TypeToFlag(JSVAL_TYPE_UNDEFINED)) {
+  if (flags_ & TypeToFlag(ValueType::Undefined)) {
     masm.branchTestUndefined(Assembler::Equal, R0, &success);
   }
 
-  if (flags_ & TypeToFlag(JSVAL_TYPE_BOOLEAN)) {
+  if (flags_ & TypeToFlag(ValueType::Boolean)) {
     masm.branchTestBoolean(Assembler::Equal, R0, &success);
   }
 
-  if (flags_ & TypeToFlag(JSVAL_TYPE_STRING)) {
+  if (flags_ & TypeToFlag(ValueType::String)) {
     masm.branchTestString(Assembler::Equal, R0, &success);
   }
 
-  if (flags_ & TypeToFlag(JSVAL_TYPE_SYMBOL)) {
+  if (flags_ & TypeToFlag(ValueType::Symbol)) {
     masm.branchTestSymbol(Assembler::Equal, R0, &success);
   }
 
-  if (flags_ & TypeToFlag(JSVAL_TYPE_BIGINT)) {
+  if (flags_ & TypeToFlag(ValueType::BigInt)) {
     masm.branchTestBigInt(Assembler::Equal, R0, &success);
   }
 
-  if (flags_ & TypeToFlag(JSVAL_TYPE_OBJECT)) {
+  if (flags_ & TypeToFlag(ValueType::Object)) {
     masm.branchTestObject(Assembler::Equal, R0, &success);
   }
 
-  if (flags_ & TypeToFlag(JSVAL_TYPE_NULL)) {
+  if (flags_ & TypeToFlag(ValueType::Null)) {
     masm.branchTestNull(Assembler::Equal, R0, &success);
   }
 
   EmitStubGuardFailure(masm);
 
   // Type matches, load true into R1.scratchReg() and return.
   masm.bind(&success);
   masm.mov(ImmWord(1), R1.scratchReg());
--- a/js/src/jit/BaselineIC.h
+++ b/js/src/jit/BaselineIC.h
@@ -1130,23 +1130,24 @@ class ICMonitoredFallbackStub : public I
 // TypeCheckPrimitiveSetStub
 //   Base class for IC stubs (TypeUpdate or TypeMonitor) that check that a given
 //   value's type falls within a set of primitive types.
 
 class TypeCheckPrimitiveSetStub : public ICStub {
   friend class ICStubSpace;
 
  protected:
-  inline static uint16_t TypeToFlag(JSValueType type) {
+  inline static uint16_t TypeToFlag(ValueType type) {
     return 1u << static_cast<unsigned>(type);
   }
 
   inline static uint16_t ValidFlags() {
-    return ((TypeToFlag(JSVAL_TYPE_OBJECT) << 1) - 1) &
-           ~TypeToFlag(JSVAL_TYPE_MAGIC);
+    return ((TypeToFlag(ValueType::Object) << 1) - 1) &
+           ~(TypeToFlag(ValueType::Magic) |
+             TypeToFlag(ValueType::PrivateGCThing));
   }
 
   TypeCheckPrimitiveSetStub(Kind kind, JitCode* stubCode, uint16_t flags)
       : ICStub(kind, stubCode) {
     MOZ_ASSERT(kind == TypeMonitor_PrimitiveSet ||
                kind == TypeUpdate_PrimitiveSet);
     MOZ_ASSERT(flags && !(flags & ~ValidFlags()));
     extra_ = flags;
@@ -1160,19 +1161,18 @@ class TypeCheckPrimitiveSetStub : public
     extra_ = flags;
     updateCode(code);
     return this;
   }
 
  public:
   uint16_t typeFlags() const { return extra_; }
 
-  bool containsType(JSValueType type) const {
-    MOZ_ASSERT(type <= JSVAL_TYPE_OBJECT);
-    MOZ_ASSERT(type != JSVAL_TYPE_MAGIC);
+  bool containsType(ValueType type) const {
+    MOZ_ASSERT(type != ValueType::Magic && type != ValueType::PrivateGCThing);
     return extra_ & TypeToFlag(type);
   }
 
   ICTypeMonitor_PrimitiveSet* toMonitorStub() {
     return toTypeMonitor_PrimitiveSet();
   }
 
   ICTypeUpdate_PrimitiveSet* toUpdateStub() {
@@ -1185,17 +1185,17 @@ class TypeCheckPrimitiveSetStub : public
     uint16_t flags_;
 
     virtual int32_t getKey() const override {
       return static_cast<int32_t>(kind) | (static_cast<int32_t>(flags_) << 16);
     }
 
    public:
     Compiler(JSContext* cx, Kind kind, TypeCheckPrimitiveSetStub* existingStub,
-             JSValueType type)
+             ValueType type)
         : ICStubCompiler(cx, kind),
           existingStub_(existingStub),
           flags_((existingStub ? existingStub->typeFlags() : 0) |
                  TypeToFlag(type)) {
       MOZ_ASSERT_IF(existingStub_, flags_ != existingStub_->typeFlags());
     }
 
     TypeCheckPrimitiveSetStub* updateStub() {
@@ -1377,17 +1377,17 @@ class ICTypeMonitor_PrimitiveSet : publi
 
  public:
   class Compiler : public TypeCheckPrimitiveSetStub::Compiler {
    protected:
     MOZ_MUST_USE bool generateStubCode(MacroAssembler& masm) override;
 
    public:
     Compiler(JSContext* cx, ICTypeMonitor_PrimitiveSet* existingStub,
-             JSValueType type)
+             ValueType type)
         : TypeCheckPrimitiveSetStub::Compiler(cx, TypeMonitor_PrimitiveSet,
                                               existingStub, type) {}
 
     ICTypeMonitor_PrimitiveSet* updateStub() {
       TypeCheckPrimitiveSetStub* stub =
           this->TypeCheckPrimitiveSetStub::Compiler::updateStub();
       if (!stub) {
         return nullptr;
@@ -1517,17 +1517,17 @@ class ICTypeUpdate_PrimitiveSet : public
 
  public:
   class Compiler : public TypeCheckPrimitiveSetStub::Compiler {
    protected:
     MOZ_MUST_USE bool generateStubCode(MacroAssembler& masm) override;
 
    public:
     Compiler(JSContext* cx, ICTypeUpdate_PrimitiveSet* existingStub,
-             JSValueType type)
+             ValueType type)
         : TypeCheckPrimitiveSetStub::Compiler(cx, TypeUpdate_PrimitiveSet,
                                               existingStub, type) {}
 
     ICTypeUpdate_PrimitiveSet* updateStub() {
       TypeCheckPrimitiveSetStub* stub =
           this->TypeCheckPrimitiveSetStub::Compiler::updateStub();
       if (!stub) {
         return nullptr;