Bug 1342497 - Baldr: store current frame, not previous frame, in wasm::FrameIterator (r=yury)
authorLuke Wagner <luke@mozilla.com>
Fri, 24 Feb 2017 21:52:35 -0600
changeset 373953 4c67f9e2c412af99c07874b1ffa9e10dd62b613a
parent 373952 01bd2d505daa10f606a06ed6103ddcb9c1df0ebf
child 373954 5144d2aa92af110e8fdf3ea377524a201990f882
push id10863
push userjlorenzo@mozilla.com
push dateMon, 06 Mar 2017 23:02:23 +0000
treeherdermozilla-aurora@0931190cd725 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersyury
bugs1342497
milestone54.0a1
Bug 1342497 - Baldr: store current frame, not previous frame, in wasm::FrameIterator (r=yury) MozReview-Commit-ID: 98mKbra2ehf
js/src/wasm/WasmFrameIterator.cpp
js/src/wasm/WasmFrameIterator.h
--- a/js/src/wasm/WasmFrameIterator.cpp
+++ b/js/src/wasm/WasmFrameIterator.cpp
@@ -53,44 +53,41 @@ TlsDataFromFP(void *fp)
 }
 
 FrameIterator::FrameIterator()
   : activation_(nullptr),
     code_(nullptr),
     callsite_(nullptr),
     codeRange_(nullptr),
     fp_(nullptr),
-    pc_(nullptr),
     unwind_(Unwind::False),
     missingFrameMessage_(false)
 {
     MOZ_ASSERT(done());
 }
 
 FrameIterator::FrameIterator(WasmActivation* activation, Unwind unwind)
   : activation_(activation),
     code_(nullptr),
     callsite_(nullptr),
     codeRange_(nullptr),
     fp_(activation->fp()),
-    pc_(nullptr),
     unwind_(unwind),
     missingFrameMessage_(false)
 {
     if (fp_) {
         settle();
         return;
     }
 
     void* pc = activation_->resumePC();
     if (!pc) {
         MOZ_ASSERT(done());
         return;
     }
-    pc_ = (uint8_t*)pc;
 
     code_ = activation_->compartment()->wasm.lookupCode(pc);
     MOZ_ASSERT(code_);
 
     const CodeRange* codeRange = code_->lookupRange(pc);
     MOZ_ASSERT(codeRange);
 
     if (codeRange->kind() == CodeRange::Function)
@@ -107,65 +104,63 @@ FrameIterator::done() const
     return !codeRange_ && !missingFrameMessage_;
 }
 
 void
 FrameIterator::operator++()
 {
     MOZ_ASSERT(!done());
     if (fp_) {
-        DebugOnly<uint8_t*> oldfp = fp_;
-        fp_ += callsite_->stackDepth();
-        MOZ_ASSERT_IF(code_->profilingEnabled(), fp_ == CallerFPFromFP(oldfp));
         settle();
     } else if (codeRange_) {
-        MOZ_ASSERT(codeRange_);
         codeRange_ = nullptr;
         missingFrameMessage_ = true;
     } else {
         MOZ_ASSERT(missingFrameMessage_);
         missingFrameMessage_ = false;
     }
 }
 
 void
 FrameIterator::settle()
 {
+    if (unwind_ == Unwind::True)
+        activation_->unwindFP(fp_);
+
     void* returnAddress = ReturnAddressFromFP(fp_);
 
     code_ = activation_->compartment()->wasm.lookupCode(returnAddress);
     MOZ_ASSERT(code_);
 
     codeRange_ = code_->lookupRange(returnAddress);
     MOZ_ASSERT(codeRange_);
 
-    switch (codeRange_->kind()) {
-      case CodeRange::Function:
-        pc_ = (uint8_t*)returnAddress;
-        callsite_ = code_->lookupCallSite(returnAddress);
-        MOZ_ASSERT(callsite_);
-        break;
-      case CodeRange::Entry:
+    if (codeRange_->kind() == CodeRange::Entry) {
         fp_ = nullptr;
-        pc_ = nullptr;
         code_ = nullptr;
         codeRange_ = nullptr;
+        callsite_ = nullptr;
+
+        if (unwind_ == Unwind::True)
+            activation_->unwindFP(nullptr);
+
         MOZ_ASSERT(done());
-        break;
-      case CodeRange::ImportJitExit:
-      case CodeRange::ImportInterpExit:
-      case CodeRange::TrapExit:
-      case CodeRange::DebugTrap:
-      case CodeRange::Inline:
-      case CodeRange::FarJumpIsland:
-        MOZ_CRASH("Should not encounter an exit during iteration");
+        return;
     }
 
-    if (unwind_ == Unwind::True)
-        activation_->unwindFP(fp_);
+    MOZ_RELEASE_ASSERT(codeRange_->kind() == CodeRange::Function);
+
+    callsite_ = code_->lookupCallSite(returnAddress);
+    MOZ_ASSERT(callsite_);
+
+    DebugOnly<uint8_t*> oldfp = fp_;
+    fp_ += callsite_->stackDepth();
+    MOZ_ASSERT_IF(code_->profilingEnabled(), fp_ == CallerFPFromFP(oldfp));
+
+    MOZ_ASSERT(!done());
 }
 
 const char*
 FrameIterator::filename() const
 {
     MOZ_ASSERT(!done());
     return code_->metadata().filename.get();
 }
@@ -221,17 +216,17 @@ FrameIterator::lineOrBytecode() const
     return callsite_ ? callsite_->lineOrBytecode()
                      : (codeRange_ ? codeRange_->funcLineOrBytecode() : 0);
 }
 
 Instance*
 FrameIterator::instance() const
 {
     MOZ_ASSERT(!done() && debugEnabled());
-    return TlsDataFromFP(fp_ + callsite_->stackDepth())->instance;
+    return TlsDataFromFP(fp_)->instance;
 }
 
 bool
 FrameIterator::debugEnabled() const
 {
     MOZ_ASSERT(!done() && code_);
     MOZ_ASSERT_IF(!missingFrameMessage_, codeRange_->kind() == CodeRange::Function);
     // Only non-imported functions can have debug frames.
@@ -239,17 +234,17 @@ FrameIterator::debugEnabled() const
            codeRange_->funcIndex() >= code_->metadata().funcImports.length();
 }
 
 DebugFrame*
 FrameIterator::debugFrame() const
 {
     MOZ_ASSERT(!done() && debugEnabled());
     // The fp() points to wasm::Frame.
-    void* buf = static_cast<uint8_t*>(fp_ + callsite_->stackDepth()) - DebugFrame::offsetOfFrame();
+    void* buf = static_cast<uint8_t*>(fp_) - DebugFrame::offsetOfFrame();
     return static_cast<DebugFrame*>(buf);
 }
 
 const CallSite*
 FrameIterator::debugTrapCallsite() const
 {
     MOZ_ASSERT(!done() && debugEnabled());
     MOZ_ASSERT(callsite_->kind() == CallSite::EnterFrame || callsite_->kind() == CallSite::LeaveFrame ||
--- a/js/src/wasm/WasmFrameIterator.h
+++ b/js/src/wasm/WasmFrameIterator.h
@@ -55,17 +55,16 @@ class FrameIterator
     enum class Unwind { True, False };
 
   private:
     WasmActivation* activation_;
     const Code* code_;
     const CallSite* callsite_;
     const CodeRange* codeRange_;
     uint8_t* fp_;
-    uint8_t* pc_;
     Unwind unwind_;
     bool missingFrameMessage_;
 
     void settle();
 
   public:
     explicit FrameIterator();
     explicit FrameIterator(WasmActivation* activation, Unwind unwind = Unwind::False);