Bug 1535994 - Part 3: Move lastTarget to BytecodeSection class. r=jorendorff
☠☠ backed out by 7fb3acf38591 ☠ ☠
authorTooru Fujisawa <arai_a@mac.com>
Wed, 10 Apr 2019 08:26:48 +0000
changeset 468738 ee3359178d5f37c951dd146926c4035d6245299f
parent 468737 b77efa8567a299f90c926f5623a6f07325fcfa32
child 468739 4f5084424c22603d3d6f87e9d283c6bf4421558f
push id35850
push userdvarga@mozilla.com
push dateWed, 10 Apr 2019 21:52:56 +0000
treeherdermozilla-central@9d3dbe3fef26 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs1535994
milestone68.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 1535994 - Part 3: Move lastTarget to BytecodeSection class. r=jorendorff Differential Revision: https://phabricator.services.mozilla.com/D25733
js/src/frontend/BytecodeEmitter.cpp
js/src/frontend/BytecodeEmitter.h
js/src/frontend/LabelEmitter.cpp
js/src/frontend/SwitchEmitter.cpp
--- a/js/src/frontend/BytecodeEmitter.cpp
+++ b/js/src/frontend/BytecodeEmitter.cpp
@@ -366,23 +366,24 @@ bool BytecodeEmitter::emitJumpTargetOp(J
   SET_ICINDEX(bytecodeSection().code(*off), numEntries);
   return true;
 }
 
 bool BytecodeEmitter::emitJumpTarget(JumpTarget* target) {
   ptrdiff_t off = bytecodeSection().offset();
 
   // Alias consecutive jump targets.
-  if (off == lastTarget.offset + ptrdiff_t(JSOP_JUMPTARGET_LENGTH)) {
-    target->offset = lastTarget.offset;
+  if (off == bytecodeSection().lastTargetOffset() +
+                 ptrdiff_t(JSOP_JUMPTARGET_LENGTH)) {
+    target->offset = bytecodeSection().lastTargetOffset();
     return true;
   }
 
   target->offset = off;
-  lastTarget.offset = off;
+  bytecodeSection().setLastTargetOffset(off);
 
   ptrdiff_t opOff;
   return emitJumpTargetOp(JSOP_JUMPTARGET, &opOff);
 }
 
 bool BytecodeEmitter::emitJumpNoFallthrough(JSOp op, JumpList* jump) {
   ptrdiff_t offset;
   if (!emitCheck(op, 5, &offset)) {
--- a/js/src/frontend/BytecodeEmitter.h
+++ b/js/src/frontend/BytecodeEmitter.h
@@ -141,29 +141,52 @@ struct MOZ_STACK_CLASS BytecodeEmitter {
     // ---- Source notes ----
 
     SrcNotesVector& notes() { return notes_; }
     const SrcNotesVector& notes() const { return notes_; }
 
     ptrdiff_t lastNoteOffset() const { return lastNoteOffset_; }
     void setLastNoteOffset(ptrdiff_t offset) { lastNoteOffset_ = offset; }
 
+    // ---- Jump ----
+
+    ptrdiff_t lastTargetOffset() const { return lastTarget_.offset; }
+    void setLastTargetOffset(ptrdiff_t offset) { lastTarget_.offset = offset; }
+
+    // Check if the last emitted opcode is a jump target.
+    bool lastOpcodeIsJumpTarget() const {
+      return offset() - lastTarget_.offset == ptrdiff_t(JSOP_JUMPTARGET_LENGTH);
+    }
+
+    // JumpTarget should not be part of the emitted statement, as they can be
+    // aliased by multiple statements. If we included the jump target as part of
+    // the statement we might have issues where the enclosing statement might
+    // not contain all the opcodes of the enclosed statements.
+    ptrdiff_t lastNonJumpTargetOffset() const {
+      return lastOpcodeIsJumpTarget() ? lastTarget_.offset : offset();
+    }
+
    private:
     // ---- Bytecode ----
 
     // Bytecode.
     BytecodeVector code_;
 
     // ---- Source notes ----
 
     // Source notes
     SrcNotesVector notes_;
 
     // Code offset for last source note
     ptrdiff_t lastNoteOffset_ = 0;
+
+    // ---- Jump ----
+
+    // Last jump target emitted.
+    JumpTarget lastTarget_ = {-1 - ptrdiff_t(JSOP_JUMPTARGET_LENGTH)};
   };
 
   BytecodeSection bytecodeSection_;
 
  public:
   BytecodeSection& bytecodeSection() { return bytecodeSection_; }
   const BytecodeSection& bytecodeSection() const { return bytecodeSection_; }
 
@@ -187,19 +210,16 @@ struct MOZ_STACK_CLASS BytecodeEmitter {
 
   // switchToMain sets this to the bytecode offset of the main section.
   mozilla::Maybe<uint32_t> mainOffset_ = {};
 
   /* field info for enclosing class */
   const FieldInitializers fieldInitializers_;
 
  public:
-  // Last jump target emitted.
-  JumpTarget lastTarget = {-1 - ptrdiff_t(JSOP_JUMPTARGET_LENGTH)};
-
   // Private storage for parser wrapper. DO NOT REFERENCE INTERNALLY. May not be
   // initialized. Use |parser| instead.
   mozilla::Maybe<EitherParser> ep_ = {};
   BCEParserHandle* parser = nullptr;
 
   PooledMapPtr<AtomIndexMap> atomIndices; /* literals indexed for mapping */
   unsigned firstLine = 0; /* first line, for JSScript::initFromEmitter */
 
@@ -449,31 +469,16 @@ struct MOZ_STACK_CLASS BytecodeEmitter {
 
   unsigned currentLine() const { return currentLine_; }
 
   void setCurrentLine(uint32_t line) {
     currentLine_ = line;
     lastColumn_ = 0;
   }
 
-  // Check if the last emitted opcode is a jump target.
-  bool lastOpcodeIsJumpTarget() const {
-    return bytecodeSection().offset() - lastTarget.offset ==
-           ptrdiff_t(JSOP_JUMPTARGET_LENGTH);
-  }
-
-  // JumpTarget should not be part of the emitted statement, as they can be
-  // aliased by multiple statements. If we included the jump target as part of
-  // the statement we might have issues where the enclosing statement might
-  // not contain all the opcodes of the enclosed statements.
-  ptrdiff_t lastNonJumpTargetOffset() const {
-    return lastOpcodeIsJumpTarget() ? lastTarget.offset
-                                    : bytecodeSection().offset();
-  }
-
   void setFunctionBodyEndPos(uint32_t pos) {
     functionBodyEndPos = mozilla::Some(pos);
   }
 
   void setScriptStartOffsetIfUnset(uint32_t pos) {
     if (scriptStartOffset.isNothing()) {
       scriptStartOffset = mozilla::Some(pos);
     }
--- a/js/src/frontend/LabelEmitter.cpp
+++ b/js/src/frontend/LabelEmitter.cpp
@@ -35,17 +35,17 @@ bool LabelEmitter::emitLabel(JSAtom* nam
   return true;
 }
 
 bool LabelEmitter::emitEnd() {
   MOZ_ASSERT(state_ == State::Label);
 
   // Patch the JSOP_LABEL offset.
   jsbytecode* labelpc = bce_->bytecodeSection().code(top_);
-  int32_t offset = bce_->lastNonJumpTargetOffset() - top_;
+  int32_t offset = bce_->bytecodeSection().lastNonJumpTargetOffset() - top_;
   MOZ_ASSERT(*labelpc == JSOP_LABEL);
   SET_CODE_OFFSET(labelpc, offset);
 
   // Patch the break/continue to this label.
   if (!controlInfo_->patchBreaks(bce_)) {
     return false;
   }
 
--- a/js/src/frontend/SwitchEmitter.cpp
+++ b/js/src/frontend/SwitchEmitter.cpp
@@ -404,18 +404,19 @@ bool SwitchEmitter::emitEnd() {
     pc += JUMP_OFFSET_LEN;
   }
 
   // Set the SRC_SWITCH note's offset operand to tell end of switch.
   // This code is shared between table switch and cond switch.
   static_assert(unsigned(SrcNote::TableSwitch::EndOffset) ==
                     unsigned(SrcNote::CondSwitch::EndOffset),
                 "{TableSwitch,CondSwitch}::EndOffset should be same");
-  if (!bce_->setSrcNoteOffset(noteIndex_, SrcNote::TableSwitch::EndOffset,
-                              bce_->lastNonJumpTargetOffset() - top_)) {
+  if (!bce_->setSrcNoteOffset(
+          noteIndex_, SrcNote::TableSwitch::EndOffset,
+          bce_->bytecodeSection().lastNonJumpTargetOffset() - top_)) {
     return false;
   }
 
   if (kind_ == Kind::Table) {
     // Skip over the already-initialized switch bounds.
     pc += 2 * JUMP_OFFSET_LEN;
 
     // Use the 'default' offset for missing cases.