jaxp/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/JSR.java
changeset 46174 5611d2529b49
parent 44797 8b3b3b911b8a
equal deleted inserted replaced
46173:5546b5710844 46174:5611d2529b49
    19  * limitations under the License.
    19  * limitations under the License.
    20  */
    20  */
    21 
    21 
    22 package com.sun.org.apache.bcel.internal.generic;
    22 package com.sun.org.apache.bcel.internal.generic;
    23 
    23 
    24 import java.io.*;
    24 import java.io.DataOutputStream;
       
    25 import java.io.IOException;
    25 
    26 
    26 /**
    27 /**
    27  * JSR - Jump to subroutine
    28  * JSR - Jump to subroutine
    28  *
    29  *
    29  * @author  <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
    30  * @version $Id: JSR.java 1749603 2016-06-21 20:50:19Z ggregory $
    30  */
    31  */
    31 public class JSR extends JsrInstruction implements VariableLengthInstruction {
    32 public class JSR extends JsrInstruction implements VariableLengthInstruction {
    32   /**
       
    33    * Empty constructor needed for the Class.newInstance() statement in
       
    34    * Instruction.readInstruction(). Not to be used otherwise.
       
    35    */
       
    36   JSR() {}
       
    37 
    33 
    38   public JSR(InstructionHandle target) {
    34     /**
    39     super(com.sun.org.apache.bcel.internal.Constants.JSR, target);
    35      * Empty constructor needed for the Class.newInstance() statement in
    40   }
    36      * Instruction.readInstruction(). Not to be used otherwise.
    41 
    37      */
    42   /**
    38     JSR() {
    43    * Dump instruction as byte code to stream out.
       
    44    * @param out Output stream
       
    45    */
       
    46   public void dump(DataOutputStream out) throws IOException {
       
    47     index = getTargetOffset();
       
    48     if(opcode == com.sun.org.apache.bcel.internal.Constants.JSR)
       
    49       super.dump(out);
       
    50     else { // JSR_W
       
    51       index = getTargetOffset();
       
    52       out.writeByte(opcode);
       
    53       out.writeInt(index);
       
    54     }
       
    55   }
       
    56 
       
    57   protected int updatePosition(int offset, int max_offset) {
       
    58     int i = getTargetOffset(); // Depending on old position value
       
    59 
       
    60     position += offset; // Position may be shifted by preceding expansions
       
    61 
       
    62     if(Math.abs(i) >= (32767 - max_offset)) { // to large for short (estimate)
       
    63       opcode  = com.sun.org.apache.bcel.internal.Constants.JSR_W;
       
    64       length = 5;
       
    65       return 2; // 5 - 3
       
    66     }
    39     }
    67 
    40 
    68     return 0;
       
    69   }
       
    70 
    41 
    71   /**
    42     public JSR(final InstructionHandle target) {
    72    * Call corresponding visitor method(s). The order is:
    43         super(com.sun.org.apache.bcel.internal.Const.JSR, target);
    73    * Call visitor methods of implemented interfaces first, then
    44     }
    74    * call methods according to the class hierarchy in descending order,
    45 
    75    * i.e., the most specific visitXXX() call comes last.
    46 
    76    *
    47     /**
    77    * @param v Visitor object
    48      * Dump instruction as byte code to stream out.
    78    */
    49      * @param out Output stream
    79   public void accept(Visitor v) {
    50      */
    80     v.visitStackProducer(this);
    51     @Override
    81     v.visitVariableLengthInstruction(this);
    52     public void dump( final DataOutputStream out ) throws IOException {
    82     v.visitBranchInstruction(this);
    53         super.setIndex(getTargetOffset());
    83     v.visitJsrInstruction(this);
    54         if (super.getOpcode() == com.sun.org.apache.bcel.internal.Const.JSR) {
    84     v.visitJSR(this);
    55             super.dump(out);
    85   }
    56         } else { // JSR_W
       
    57             super.setIndex(getTargetOffset());
       
    58             out.writeByte(super.getOpcode());
       
    59             out.writeInt(super.getIndex());
       
    60         }
       
    61     }
       
    62 
       
    63 
       
    64     @Override
       
    65     protected int updatePosition( final int offset, final int max_offset ) {
       
    66         final int i = getTargetOffset(); // Depending on old position value
       
    67         setPosition(getPosition() + offset); // Position may be shifted by preceding expansions
       
    68         if (Math.abs(i) >= (Short.MAX_VALUE - max_offset)) { // to large for short (estimate)
       
    69             super.setOpcode(com.sun.org.apache.bcel.internal.Const.JSR_W);
       
    70             final short old_length = (short) super.getLength();
       
    71             super.setLength(5);
       
    72             return super.getLength() - old_length;
       
    73         }
       
    74         return 0;
       
    75     }
       
    76 
       
    77 
       
    78     /**
       
    79      * Call corresponding visitor method(s). The order is:
       
    80      * Call visitor methods of implemented interfaces first, then
       
    81      * call methods according to the class hierarchy in descending order,
       
    82      * i.e., the most specific visitXXX() call comes last.
       
    83      *
       
    84      * @param v Visitor object
       
    85      */
       
    86     @Override
       
    87     public void accept( final Visitor v ) {
       
    88         v.visitStackProducer(this);
       
    89         v.visitVariableLengthInstruction(this);
       
    90         v.visitBranchInstruction(this);
       
    91         v.visitJsrInstruction(this);
       
    92         v.visitJSR(this);
       
    93     }
    86 }
    94 }