Bug 1477621 - Part 2: Add source note field constants for try. r=jandem
authorTooru Fujisawa <arai_a@mac.com>
Wed, 25 Jul 2018 17:01:49 +0900
changeset 428222 7cabc189feb9c32b870183b8096ca8702f518f61
parent 428221 5f7b22fe0124b332ea410e44b94afa11d29b254a
child 428223 d18e67f75339c713ce1aadc54631898b5af5df3d
push id105651
push userarai_a@mac.com
push dateWed, 25 Jul 2018 08:02:10 +0000
treeherdermozilla-inbound@e3600583e49a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjandem
bugs1477621
milestone63.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 1477621 - Part 2: Add source note field constants for try. r=jandem
js/src/frontend/SourceNotes.h
js/src/frontend/TryEmitter.cpp
js/src/jit/BytecodeAnalysis.cpp
js/src/jit/IonControlFlow.cpp
js/src/shell/js.cpp
--- a/js/src/frontend/SourceNotes.h
+++ b/js/src/frontend/SourceNotes.h
@@ -65,16 +65,26 @@ class SrcNote {
       public:
         enum Fields {
             // Offset of the next JSOP_CASE from this JSOP_CASE.  This field is
             // 0 if this is the last JSOP_CASE.
             NextCaseOffset,
             Count
         };
     };
+    // SRC_TRY: Source note for JSOP_TRY.
+    class Try {
+      public:
+        enum Fields {
+            // The offset of the JSOP_GOTO at the end of the try block from
+            // JSOP_TRY.
+            EndOfTryJumpOffset,
+            Count
+        };
+    };
 };
 
 #define FOR_EACH_SRC_NOTE_TYPE(M)                                                                  \
     M(SRC_NULL,         "null",        0)  /* Terminates a note vector. */                         \
     M(SRC_IF,           "if",          0)  /* JSOP_IFEQ bytecode is from an if-then. */            \
     M(SRC_IF_ELSE,      "if-else",     0)  /* JSOP_IFEQ bytecode is from an if-then-else. */       \
     M(SRC_COND,         "cond",        0)  /* JSOP_IFEQ is from conditional ?: operator. */        \
     M(SRC_FOR,          "for",         3)  /* JSOP_NOP or JSOP_POP in for(;;) loop head. */        \
@@ -89,18 +99,17 @@ class SrcNote {
     M(SRC_BREAK2LABEL,  "break2label", 0)  /* JSOP_GOTO for 'break label'. */                      \
     M(SRC_SWITCHBREAK,  "switchbreak", 0)  /* JSOP_GOTO is a break in a switch. */                 \
     M(SRC_TABLESWITCH,  "tableswitch", SrcNote::TableSwitch::Count) \
     M(SRC_CONDSWITCH,   "condswitch",  SrcNote::CondSwitch::Count) \
     M(SRC_NEXTCASE,     "nextcase",    SrcNote::NextCase::Count) \
     M(SRC_ASSIGNOP,     "assignop",    0)  /* += or another assign-op follows. */                  \
     M(SRC_CLASS_SPAN,   "class",       2)  /* The starting and ending offsets for the class, used  \
                                               for toString correctness for default ctors. */       \
-    M(SRC_TRY,          "try",         1)  /* JSOP_TRY, offset points to goto at the end of the    \
-                                              try block. */                                        \
+    M(SRC_TRY,          "try",         SrcNote::Try::Count) \
     /* All notes above here are "gettable".  See SN_IS_GETTABLE below. */                          \
     M(SRC_COLSPAN,      "colspan",     1)  /* Number of columns this opcode spans. */              \
     M(SRC_NEWLINE,      "newline",     0)  /* Bytecode follows a source newline. */                \
     M(SRC_SETLINE,      "setline",     1)  /* A file-absolute source line number note. */          \
     M(SRC_UNUSED21,     "unused21",    0)  /* Unused. */                                           \
     M(SRC_UNUSED22,     "unused22",    0)  /* Unused. */                                           \
     M(SRC_UNUSED23,     "unused23",    0)  /* Unused. */                                           \
     M(SRC_XDELTA,       "xdelta",      0)  /* 24-31 are for extended delta notes. */
--- a/js/src/frontend/TryEmitter.cpp
+++ b/js/src/frontend/TryEmitter.cpp
@@ -76,18 +76,21 @@ TryEmitter::emitTryEnd()
 
     // GOSUB to finally, if present.
     if (hasFinally() && controlInfo_) {
         if (!bce_->emitJump(JSOP_GOSUB, &controlInfo_->gosubs))
             return false;
     }
 
     // Source note points to the jump at the end of the try block.
-    if (!bce_->setSrcNoteOffset(noteIndex_, 0, bce_->offset() - tryStart_ + JSOP_TRY_LENGTH))
+    if (!bce_->setSrcNoteOffset(noteIndex_, SrcNote::Try::EndOfTryJumpOffset,
+                                bce_->offset() - tryStart_ + JSOP_TRY_LENGTH))
+    {
         return false;
+    }
 
     // Emit jump over catch and/or finally.
     if (!bce_->emitJump(JSOP_GOTO, &catchAndFinallyJump_))
         return false;
 
     if (!bce_->emitJumpTarget(&tryEnd_))
         return false;
 
--- a/js/src/jit/BytecodeAnalysis.cpp
+++ b/js/src/jit/BytecodeAnalysis.cpp
@@ -128,17 +128,17 @@ BytecodeAnalysis::init(TempAllocator& al
                 }
             }
 
             // Get the pc of the last instruction in the try block. It's a JSOP_GOTO to
             // jump over the catch/finally blocks.
             jssrcnote* sn = GetSrcNote(gsn, script_, pc);
             MOZ_ASSERT(SN_TYPE(sn) == SRC_TRY);
 
-            jsbytecode* endOfTry = pc + GetSrcNoteOffset(sn, 0);
+            jsbytecode* endOfTry = pc + GetSrcNoteOffset(sn, SrcNote::Try::EndOfTryJumpOffset);
             MOZ_ASSERT(JSOp(*endOfTry) == JSOP_GOTO);
 
             jsbytecode* afterTry = endOfTry + GET_JUMP_OFFSET(endOfTry);
             MOZ_ASSERT(afterTry > endOfTry);
 
             // Ensure the code following the try-block is always marked as
             // reachable, to simplify Ion's ControlFlowGenerator.
             uint32_t afterTryOffset = script_->pcToOffset(afterTry);
--- a/js/src/jit/IonControlFlow.cpp
+++ b/js/src/jit/IonControlFlow.cpp
@@ -541,17 +541,17 @@ ControlFlowGenerator::processTry()
         checkedTryFinally_ = true;
     }
 
     jssrcnote* sn = GetSrcNote(gsn, script, pc);
     MOZ_ASSERT(SN_TYPE(sn) == SRC_TRY);
 
     // Get the pc of the last instruction in the try block. It's a JSOP_GOTO to
     // jump over the catch block.
-    jsbytecode* endpc = pc + GetSrcNoteOffset(sn, 0);
+    jsbytecode* endpc = pc + GetSrcNoteOffset(sn, SrcNote::Try::EndOfTryJumpOffset);
     MOZ_ASSERT(JSOp(*endpc) == JSOP_GOTO);
     MOZ_ASSERT(GetJumpOffset(endpc) > 0);
 
     jsbytecode* afterTry = endpc + GetJumpOffset(endpc);
 
     // If controlflow in the try body is terminated (by a return or throw
     // statement), the code after the try-statement may still be reachable
     // via the catch block (which we don't compile) and OSR can enter it.
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -2797,18 +2797,21 @@ SrcNotes(JSContext* cx, HandleScript scr
             }
             UpdateSwitchTableBounds(cx, script, offset,
                                     &switchTableStart, &switchTableEnd);
             break;
           }
 
           case SRC_TRY:
             MOZ_ASSERT(JSOp(script->code()[offset]) == JSOP_TRY);
-            if (!sp->jsprintf(" offset to jump %u", unsigned(GetSrcNoteOffset(sn, 0))))
+            if (!sp->jsprintf(" offset to jump %u",
+                              unsigned(GetSrcNoteOffset(sn, SrcNote::Try::EndOfTryJumpOffset))))
+            {
                 return false;
+            }
             break;
 
           case SRC_CLASS_SPAN: {
             unsigned startOffset = GetSrcNoteOffset(sn, 0);
             unsigned endOffset = GetSrcNoteOffset(sn, 1);
             if (!sp->jsprintf(" %u %u", startOffset, endOffset))
                 return false;
             break;