Bug 1460126 - Part 3: Make TryEmitter::State debug only. r=jwalden
authorTooru Fujisawa <arai_a@mac.com>
Thu, 31 May 2018 15:15:51 +0900
changeset 420672 325ac4e5f005b00b3a9ec68b59cdb22180eb5725
parent 420671 e2aabb9c50162fc250cabbbfe9c6c69ecdede6b9
child 420673 05084c58cd39f65c141e39d2d28528be29056e96
push id34077
push usernerli@mozilla.com
push dateThu, 31 May 2018 21:51:59 +0000
treeherdermozilla-central@42880a726964 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjwalden
bugs1460126
milestone62.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 1460126 - Part 3: Make TryEmitter::State debug only. r=jwalden
js/src/frontend/BytecodeEmitter.cpp
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -1634,16 +1634,17 @@ class MOZ_STACK_CLASS TryEmitter
     JumpList catchAndFinallyJump_;
 
     // The offset of JSOP_GOTO at the end of the try block.
     JumpTarget tryEnd_;
 
     // The offset of JSOP_JUMPTARGET at the beginning of the finally block.
     JumpTarget finallyStart_;
 
+#ifdef DEBUG
     // The state of this emitter.
     //
     // +-------+ emitTry +-----+   emitCatch +-------+      emitEnd  +-----+
     // | Start |-------->| Try |-+---------->| Catch |-+->+--------->| End |
     // +-------+         +-----+ |           +-------+ |  ^          +-----+
     //                           |                     |  |
     //                           |  +------------------+  +----+
     //                           |  |                          |
@@ -1662,33 +1663,36 @@ class MOZ_STACK_CLASS TryEmitter
 
         // After calling emitFinally.
         Finally,
 
         // After calling emitEnd.
         End
     };
     State state_;
+#endif
 
     bool hasCatch() const {
         return kind_ == Kind::TryCatch || kind_ == Kind::TryCatchFinally;
     }
     bool hasFinally() const {
         return kind_ == Kind::TryCatchFinally || kind_ == Kind::TryFinally;
     }
 
   public:
     TryEmitter(BytecodeEmitter* bce, Kind kind, ControlKind controlKind)
       : bce_(bce),
         kind_(kind),
         controlKind_(controlKind),
         depth_(0),
         noteIndex_(0),
-        tryStart_(0),
-        state_(State::Start)
+        tryStart_(0)
+#ifdef DEBUG
+      , state_(State::Start)
+#endif
     {
         if (controlKind_ == ControlKind::Syntactic)
             controlInfo_.emplace(bce_, hasFinally() ? StatementKind::Finally : StatementKind::Try);
         finallyStart_.offset = 0;
     }
 
     // Emits JSOP_GOTO to the end of try-catch-finally.
     // Used in `yield*`.
@@ -1712,17 +1716,19 @@ class MOZ_STACK_CLASS TryEmitter
 
         // Record the try location, then emit the try block.
         if (!bce_->newSrcNote(SRC_TRY, &noteIndex_))
             return false;
         if (!bce_->emit1(JSOP_TRY))
             return false;
         tryStart_ = bce_->offset();
 
+#ifdef DEBUG
         state_ = State::Try;
+#endif
         return true;
     }
 
   private:
     bool emitTryEnd() {
         MOZ_ASSERT(state_ == State::Try);
         MOZ_ASSERT(depth_ == bce_->stackDepth);
 
@@ -1760,17 +1766,19 @@ class MOZ_STACK_CLASS TryEmitter
             //
             //   eval("try { 1; throw 2 } catch(e) {}"); // undefined, not 1
             if (!bce_->emit1(JSOP_UNDEFINED))
                 return false;
             if (!bce_->emit1(JSOP_SETRVAL))
                 return false;
         }
 
+#ifdef DEBUG
         state_ = State::Catch;
+#endif
         return true;
     }
 
   private:
     bool emitCatchEnd() {
         MOZ_ASSERT(state_ == State::Catch);
 
         if (!controlInfo_)
@@ -1804,17 +1812,18 @@ class MOZ_STACK_CLASS TryEmitter
         // blocks emit no GOSUBs.
         if (!controlInfo_) {
             if (kind_ == Kind::TryCatch)
                 kind_ = Kind::TryCatchFinally;
         } else {
             MOZ_ASSERT(hasFinally());
         }
 
-        if (state_ == State::Try) {
+        if (!hasCatch()) {
+            MOZ_ASSERT(state_ == State::Try);
             if (!emitTryEnd())
                 return false;
         } else {
             MOZ_ASSERT(state_ == State::Catch);
             if (!emitCatchEnd())
                 return false;
         }
 
@@ -1847,17 +1856,19 @@ class MOZ_STACK_CLASS TryEmitter
             //
             //   eval("x: try { 1 } finally { break x; }"); // undefined, not 1
             if (!bce_->emit1(JSOP_UNDEFINED))
                 return false;
             if (!bce_->emit1(JSOP_SETRVAL))
                 return false;
         }
 
+#ifdef DEBUG
         state_ = State::Finally;
+#endif
         return true;
     }
 
   private:
     bool emitFinallyEnd() {
         MOZ_ASSERT(state_ == State::Finally);
 
         if (controlKind_ == ControlKind::Syntactic) {
@@ -1869,23 +1880,22 @@ class MOZ_STACK_CLASS TryEmitter
             return false;
 
         bce_->hasTryFinally = true;
         return true;
     }
 
   public:
     bool emitEnd() {
-        if (state_ == State::Catch) {
-            MOZ_ASSERT(!hasFinally());
+        if (!hasFinally()) {
+            MOZ_ASSERT(state_ == State::Catch);
             if (!emitCatchEnd())
                 return false;
         } else {
             MOZ_ASSERT(state_ == State::Finally);
-            MOZ_ASSERT(hasFinally());
             if (!emitFinallyEnd())
                 return false;
         }
 
         MOZ_ASSERT(bce_->stackDepth == depth_);
 
         // ReconstructPCStack needs a NOP here to mark the end of the last
         // catch block.
@@ -1906,17 +1916,19 @@ class MOZ_STACK_CLASS TryEmitter
         // If we've got a finally, mark try+catch region with additional
         // trynote to catch exceptions (re)thrown from a catch block or
         // for the try{}finally{} case.
         if (hasFinally()) {
             if (!bce_->tryNoteList.append(JSTRY_FINALLY, depth_, tryStart_, finallyStart_.offset))
                 return false;
         }
 
+#ifdef DEBUG
         state_ = State::End;
+#endif
         return true;
     }
 };
 
 // Class for emitting bytecode for blocks like if-then-else.
 //
 // This class can be used to emit single if-then-else block, or cascading
 // else-if blocks.