Bug 989759 part 2 - Dispatch base on the instruction identifier. r=jandem
authorNicolas B. Pierron <nicolas.b.pierron@mozilla.com>
Tue, 08 Apr 2014 07:21:19 -0700
changeset 177583 0c4295f019eb8a9aab2de7c4f1f42357d25b68de
parent 177582 ebcdd5ea79abb620927ea176205852d5565f36d5
child 177584 b756fe5f27d8ae3a3d6b4ca08b8fdc23426f2703
push id26556
push userryanvm@gmail.com
push dateTue, 08 Apr 2014 22:16:57 +0000
treeherdermozilla-central@5811efc11011 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs989759
milestone31.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 989759 part 2 - Dispatch base on the instruction identifier. r=jandem
js/src/jit/IonFrameIterator.h
js/src/jit/IonFrames.cpp
js/src/jit/Recover.cpp
js/src/jit/Recover.h
js/src/jit/Snapshots.cpp
js/src/jit/Snapshots.h
--- a/js/src/jit/IonFrameIterator.h
+++ b/js/src/jit/IonFrameIterator.h
@@ -239,16 +239,18 @@ class IonFrameIterator
     void dump() const;
 
     inline BaselineFrame *baselineFrame() const;
 };
 
 class IonJSFrameLayout;
 class IonBailoutIterator;
 
+class RResumePoint;
+
 // Reads frame information in snapshot-encoding order (that is, outermost frame
 // to innermost frame).
 class SnapshotIterator
 {
     SnapshotReader snapshot_;
     RecoverReader recover_;
     IonJSFrameLayout *fp_;
     MachineState machine_;
@@ -286,18 +288,19 @@ class SnapshotIterator
         MOZ_ASSERT(moreAllocations());
         return snapshot_.readAllocation();
     }
     Value skip() {
         readAllocation();
         return UndefinedValue();
     }
 
-    const RResumePoint *resumePoint() const {
-        return recover_.resumePoint();
+    const RResumePoint *resumePoint() const;
+    const RInstruction *instruction() const {
+        return recover_.instruction();
     }
 
     uint32_t numAllocations() const;
     inline bool moreAllocations() const {
         return snapshot_.numAllocationsRead() < numAllocations();
     }
 
   public:
--- a/js/src/jit/IonFrames.cpp
+++ b/js/src/jit/IonFrames.cpp
@@ -1494,16 +1494,22 @@ SnapshotIterator::allocationValue(const 
       }
 #endif
 
       default:
         MOZ_ASSUME_UNREACHABLE("huh?");
     }
 }
 
+const RResumePoint *
+SnapshotIterator::resumePoint() const
+{
+    return instruction()->toResumePoint();
+}
+
 uint32_t
 SnapshotIterator::numAllocations() const
 {
     return resumePoint()->numOperands();
 }
 
 uint32_t
 SnapshotIterator::pcOffset() const
--- a/js/src/jit/Recover.cpp
+++ b/js/src/jit/Recover.cpp
@@ -8,20 +8,34 @@
 
 #include "jit/IonSpewer.h"
 #include "jit/MIR.h"
 #include "jit/MIRGraph.h"
 
 using namespace js;
 using namespace js::jit;
 
+void
+RInstruction::readRecoverData(CompactBufferReader &reader, RInstructionStorage *raw)
+{
+    uint32_t op = reader.readUnsigned();
+    switch (Opcode(op)) {
+      case Recover_ResumePoint:
+        new (raw->addr()) RResumePoint(reader);
+        break;
+      default:
+        MOZ_ASSUME_UNREACHABLE("Bad decoding of the previous instruction?");
+        break;
+    }
+}
+
 bool
 MResumePoint::writeRecoverData(CompactBufferWriter &writer) const
 {
-    writer.writeUnsigned(uint32_t(Recover_ResumePoint));
+    writer.writeUnsigned(uint32_t(RInstruction::Recover_ResumePoint));
 
     MBasicBlock *bb = block();
     JSFunction *fun = bb->info().funMaybeLazy();
     JSScript *script = bb->info().script();
     uint32_t exprStack = stackDepth() - bb->info().ninvoke();
 
 #ifdef DEBUG
     // Ensure that all snapshot which are encoded can safely be used for
@@ -89,16 +103,8 @@ RResumePoint::RResumePoint(CompactBuffer
 {
     static_assert(sizeof(*this) <= sizeof(RInstructionStorage),
                   "Storage space is too small to decode this recover instruction.");
     pcOffset_ = reader.readUnsigned();
     numOperands_ = reader.readUnsigned();
     IonSpew(IonSpew_Snapshots, "Read RResumePoint (pc offset %u, nslots %u)",
             pcOffset_, numOperands_);
 }
-
-void
-RResumePoint::readRecoverData(CompactBufferReader &reader, RInstructionStorage *raw)
-{
-    mozilla::DebugOnly<uint32_t> op = reader.readUnsigned();
-    MOZ_ASSERT(op == uint32_t(Recover_ResumePoint));
-    new (raw->addr()) RResumePoint(reader);
-}
--- a/js/src/jit/Recover.h
+++ b/js/src/jit/Recover.h
@@ -2,41 +2,70 @@
  * vim: set ts=8 sts=4 et sw=4 tw=99:
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef jit_Recover_h
 #define jit_Recover_h
 
+#include "mozilla/Attributes.h"
+
 #include "jit/Snapshots.h"
 
 namespace js {
 namespace jit {
 
-enum RecoverOpcode
+class RResumePoint;
+
+class RInstruction
 {
-    Recover_ResumePoint = 0
+  public:
+    enum Opcode
+    {
+        Recover_ResumePoint = 0
+    };
+
+    virtual Opcode opcode() const = 0;
+
+    bool isResumePoint() const {
+        return opcode() == Recover_ResumePoint;
+    }
+    inline const RResumePoint *toResumePoint() const;
+
+    virtual uint32_t numOperands() const = 0;
+
+    static void readRecoverData(CompactBufferReader &reader, RInstructionStorage *raw);
 };
 
-class RResumePoint
+class RResumePoint MOZ_FINAL : public RInstruction
 {
   private:
     uint32_t pcOffset_;           // Offset from script->code.
     uint32_t numOperands_;        // Number of slots.
 
+    friend class RInstruction;
     RResumePoint(CompactBufferReader &reader);
 
   public:
-    static void readRecoverData(CompactBufferReader &reader, RInstructionStorage *raw);
+    virtual Opcode opcode() const {
+        return Recover_ResumePoint;
+    }
 
     uint32_t pcOffset() const {
         return pcOffset_;
     }
-    uint32_t numOperands() const {
+    virtual uint32_t numOperands() const {
         return numOperands_;
     }
 };
 
+const RResumePoint *
+RInstruction::toResumePoint() const
+{
+    MOZ_ASSERT(isResumePoint());
+    return static_cast<const RResumePoint *>(this);
+}
+
 }
 }
 
 #endif /* jit_Recover_h */
--- a/js/src/jit/Snapshots.cpp
+++ b/js/src/jit/Snapshots.cpp
@@ -575,17 +575,17 @@ RecoverReader::readRecoverHeader()
     IonSpew(IonSpew_Snapshots, "Read recover header with frameCount %u (ra: %d)",
             frameCount_, resumeAfter_);
 }
 
 void
 RecoverReader::readFrame()
 {
     JS_ASSERT(moreFrames());
-    RResumePoint::readRecoverData(reader_, &rawData_);
+    RInstruction::readRecoverData(reader_, &rawData_);
     framesRead_++;
 }
 
 SnapshotOffset
 SnapshotWriter::startSnapshot(RecoverOffset recoverOffset, BailoutKind kind)
 {
     lastStart_ = writer_.length();
     allocWritten_ = 0;
--- a/js/src/jit/Snapshots.h
+++ b/js/src/jit/Snapshots.h
@@ -436,18 +436,18 @@ class SnapshotReader
     uint32_t numAllocationsRead() const {
         return allocRead_;
     }
     void resetNumAllocationsRead() {
         allocRead_ = 0;
     }
 };
 
-typedef mozilla::AlignedStorage<2 * sizeof(uint32_t)> RInstructionStorage;
-class RResumePoint;
+typedef mozilla::AlignedStorage<4 * sizeof(uint32_t)> RInstructionStorage;
+class RInstruction;
 
 class RecoverReader
 {
     CompactBufferReader reader_;
 
     uint32_t frameCount_;
     uint32_t framesRead_;         // Number of frame headers that have been read.
     bool resumeAfter_;
@@ -468,18 +468,18 @@ class RecoverReader
     }
     void nextFrame() {
         readFrame();
     }
     uint32_t frameCount() const {
         return frameCount_;
     }
 
-    const RResumePoint *resumePoint() const {
-        return reinterpret_cast<const RResumePoint *>(rawData_.addr());
+    const RInstruction *instruction() const {
+        return reinterpret_cast<const RInstruction *>(rawData_.addr());
     }
 
     bool resumeAfter() const {
         return resumeAfter_;
     }
 };
 
 }