jaxp/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/GOTO.java
changeset 46174 5611d2529b49
parent 44797 8b3b3b911b8a
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/GOTO.java	Tue Aug 08 22:52:41 2017 +0000
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/GOTO.java	Sun Aug 13 21:10:40 2017 -0700
@@ -21,69 +21,83 @@
 
 package com.sun.org.apache.bcel.internal.generic;
 
-import java.io.*;
+import java.io.DataOutputStream;
+import java.io.IOException;
 
 /**
  * GOTO - Branch always (to relative offset, not absolute address)
  *
- * @author  <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
+ * @version $Id: GOTO.java 1749603 2016-06-21 20:50:19Z ggregory $
  */
 public class GOTO extends GotoInstruction implements VariableLengthInstruction {
-  /**
-   * Empty constructor needed for the Class.newInstance() statement in
-   * Instruction.readInstruction(). Not to be used otherwise.
-   */
-  GOTO() {}
 
-  public GOTO(InstructionHandle target) {
-    super(com.sun.org.apache.bcel.internal.Constants.GOTO, target);
-  }
+    /**
+     * Empty constructor needed for the Class.newInstance() statement in
+     * Instruction.readInstruction(). Not to be used otherwise.
+     */
+    GOTO() {
+    }
+
+
+    public GOTO(final InstructionHandle target) {
+        super(com.sun.org.apache.bcel.internal.Const.GOTO, target);
+    }
+
 
-  /**
-   * Dump instruction as byte code to stream out.
-   * @param out Output stream
-   */
-  public void dump(DataOutputStream out) throws IOException {
-    index = getTargetOffset();
-    if(opcode == com.sun.org.apache.bcel.internal.Constants.GOTO)
-      super.dump(out);
-    else { // GOTO_W
-      index = getTargetOffset();
-      out.writeByte(opcode);
-      out.writeInt(index);
-    }
-  }
-
-  /** Called in pass 2 of InstructionList.setPositions() in order to update
-   * the branch target, that may shift due to variable length instructions.
-   */
-  protected int updatePosition(int offset, int max_offset) {
-    int i = getTargetOffset(); // Depending on old position value
-
-    position += offset; // Position may be shifted by preceding expansions
-
-    if(Math.abs(i) >= (32767 - max_offset)) { // to large for short (estimate)
-      opcode = com.sun.org.apache.bcel.internal.Constants.GOTO_W;
-      length = 5;
-      return 2; // 5 - 3
+    /**
+     * Dump instruction as byte code to stream out.
+     * @param out Output stream
+     */
+    @Override
+    public void dump( final DataOutputStream out ) throws IOException {
+        super.setIndex(getTargetOffset());
+        final short _opcode = getOpcode();
+        if (_opcode == com.sun.org.apache.bcel.internal.Const.GOTO) {
+            super.dump(out);
+        } else { // GOTO_W
+            super.setIndex(getTargetOffset());
+            out.writeByte(_opcode);
+            out.writeInt(super.getIndex());
+        }
     }
 
-    return 0;
-  }
 
-  /**
-   * Call corresponding visitor method(s). The order is:
-   * Call visitor methods of implemented interfaces first, then
-   * call methods according to the class hierarchy in descending order,
-   * i.e., the most specific visitXXX() call comes last.
-   *
-   * @param v Visitor object
-   */
-  public void accept(Visitor v) {
-    v.visitVariableLengthInstruction(this);
-    v.visitUnconditionalBranch(this);
-    v.visitBranchInstruction(this);
-    v.visitGotoInstruction(this);
-    v.visitGOTO(this);
-  }
+    /**
+     * Called in pass 2 of InstructionList.setPositions() in order to update
+     * the branch target, that may shift due to variable length instructions.
+     *
+     * @param offset additional offset caused by preceding (variable length) instructions
+     * @param max_offset the maximum offset that may be caused by these instructions
+     * @return additional offset caused by possible change of this instruction's length
+     */
+    @Override
+    protected int updatePosition( final int offset, final int max_offset ) {
+        final int i = getTargetOffset(); // Depending on old position value
+        setPosition(getPosition() + offset); // Position may be shifted by preceding expansions
+        if (Math.abs(i) >= (Short.MAX_VALUE - max_offset)) { // to large for short (estimate)
+            super.setOpcode(com.sun.org.apache.bcel.internal.Const.GOTO_W);
+            final short old_length = (short) super.getLength();
+            super.setLength(5);
+            return super.getLength() - old_length;
+        }
+        return 0;
+    }
+
+
+    /**
+     * Call corresponding visitor method(s). The order is:
+     * Call visitor methods of implemented interfaces first, then
+     * call methods according to the class hierarchy in descending order,
+     * i.e., the most specific visitXXX() call comes last.
+     *
+     * @param v Visitor object
+     */
+    @Override
+    public void accept( final Visitor v ) {
+        v.visitVariableLengthInstruction(this);
+        v.visitUnconditionalBranch(this);
+        v.visitBranchInstruction(this);
+        v.visitGotoInstruction(this);
+        v.visitGOTO(this);
+    }
 }