jaxp/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/JSR.java
changeset 46174 5611d2529b49
parent 44797 8b3b3b911b8a
--- a/jaxp/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/JSR.java	Tue Aug 08 22:52:41 2017 +0000
+++ b/jaxp/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/JSR.java	Sun Aug 13 21:10:40 2017 -0700
@@ -21,66 +21,74 @@
 
 package com.sun.org.apache.bcel.internal.generic;
 
-import java.io.*;
+import java.io.DataOutputStream;
+import java.io.IOException;
 
 /**
  * JSR - Jump to subroutine
  *
- * @author  <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
+ * @version $Id: JSR.java 1749603 2016-06-21 20:50:19Z ggregory $
  */
 public class JSR extends JsrInstruction implements VariableLengthInstruction {
-  /**
-   * Empty constructor needed for the Class.newInstance() statement in
-   * Instruction.readInstruction(). Not to be used otherwise.
-   */
-  JSR() {}
 
-  public JSR(InstructionHandle target) {
-    super(com.sun.org.apache.bcel.internal.Constants.JSR, target);
-  }
+    /**
+     * Empty constructor needed for the Class.newInstance() statement in
+     * Instruction.readInstruction(). Not to be used otherwise.
+     */
+    JSR() {
+    }
+
+
+    public JSR(final InstructionHandle target) {
+        super(com.sun.org.apache.bcel.internal.Const.JSR, 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.JSR)
-      super.dump(out);
-    else { // JSR_W
-      index = getTargetOffset();
-      out.writeByte(opcode);
-      out.writeInt(index);
-    }
-  }
-
-  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.JSR_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());
+        if (super.getOpcode() == com.sun.org.apache.bcel.internal.Const.JSR) {
+            super.dump(out);
+        } else { // JSR_W
+            super.setIndex(getTargetOffset());
+            out.writeByte(super.getOpcode());
+            out.writeInt(super.getIndex());
+        }
     }
 
-    return 0;
-  }
+
+    @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.JSR_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
-   */
-  public void accept(Visitor v) {
-    v.visitStackProducer(this);
-    v.visitVariableLengthInstruction(this);
-    v.visitBranchInstruction(this);
-    v.visitJsrInstruction(this);
-    v.visitJSR(this);
-  }
+    /**
+     * 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.visitStackProducer(this);
+        v.visitVariableLengthInstruction(this);
+        v.visitBranchInstruction(this);
+        v.visitJsrInstruction(this);
+        v.visitJSR(this);
+    }
 }