jaxp/src/com/sun/org/apache/bcel/internal/generic/BranchInstruction.java
author dfuchs
Fri, 17 May 2013 10:40:21 +0200
changeset 17538 d8d911c4e5d4
parent 12457 c348e06f0e82
permissions -rw-r--r--
8013900: More warnings compiling jaxp. Summary: Some internal implementation classes in Jaxp were redefining equals() without redefining hashCode(). This patch adds hashCode() methods that are consistent with equals(). Reviewed-by: chegar, joehw
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
package com.sun.org.apache.bcel.internal.generic;
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
/* ====================================================================
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * The Apache Software License, Version 1.1
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * Copyright (c) 2001 The Apache Software Foundation.  All rights
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 * reserved.
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 * Redistribution and use in source and binary forms, with or without
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * modification, are permitted provided that the following conditions
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * are met:
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * 1. Redistributions of source code must retain the above copyright
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 *    notice, this list of conditions and the following disclaimer.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
 * 2. Redistributions in binary form must reproduce the above copyright
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 *    notice, this list of conditions and the following disclaimer in
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 *    the documentation and/or other materials provided with the
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
 *    distribution.
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
 * 3. The end-user documentation included with the redistribution,
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
 *    if any, must include the following acknowledgment:
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
 *       "This product includes software developed by the
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
 *        Apache Software Foundation (http://www.apache.org/)."
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
 *    Alternately, this acknowledgment may appear in the software itself,
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
 *    if and wherever such third-party acknowledgments normally appear.
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
 * 4. The names "Apache" and "Apache Software Foundation" and
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
 *    "Apache BCEL" must not be used to endorse or promote products
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
 *    derived from this software without prior written permission. For
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
 *    written permission, please contact apache@apache.org.
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 * 5. Products derived from this software may not be called "Apache",
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
 *    "Apache BCEL", nor may "Apache" appear in their name, without
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 *    prior written permission of the Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
 * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
 * SUCH DAMAGE.
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
 * ====================================================================
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
 * This software consists of voluntary contributions made by many
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
 * individuals on behalf of the Apache Software Foundation.  For more
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
 * information on the Apache Software Foundation, please see
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
 * <http://www.apache.org/>.
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
import java.io.*;
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
import com.sun.org.apache.bcel.internal.util.ByteSequence;
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
 * Abstract super class for branching instructions like GOTO, IFEQ, etc..
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
 * Branch instructions may have a variable length, namely GOTO, JSR,
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
 * LOOKUPSWITCH and TABLESWITCH.
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
 * @see InstructionList
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
 * @author  <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
public abstract class BranchInstruction extends Instruction implements InstructionTargeter {
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
  protected int               index;    // Branch target relative to this instruction
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
  protected InstructionHandle target;   // Target object in instruction list
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
  protected int               position; // Byte code offset
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
   * Empty constructor needed for the Class.newInstance() statement in
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
   * Instruction.readInstruction(). Not to be used otherwise.
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
  BranchInstruction() {}
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
  /** Common super constructor
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
   * @param opcodee Instruction opcode
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
   * @param target instruction to branch to
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
  protected BranchInstruction(short opcode, InstructionHandle target) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
    super(opcode, (short)3);
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
    setTarget(target);
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
   * Dump instruction as byte code to stream out.
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
   * @param out Output stream
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
   */
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
    96
  @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
  public void dump(DataOutputStream out) throws IOException {
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
    out.writeByte(opcode);
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
    index = getTargetOffset();
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
    if(Math.abs(index) >= 32767) // too large for short
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
      throw new ClassGenException("Branch target offset too large for short");
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
    out.writeShort(index); // May be negative, i.e., point backwards
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
   * @param target branch target
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
   * @return the offset to  `target' relative to this instruction
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
  protected int getTargetOffset(InstructionHandle target) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
    if(target == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
      throw new ClassGenException("Target of " + super.toString(true) +
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
                                  " is invalid null handle");
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
    int t = target.getPosition();
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
    if(t < 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
      throw new ClassGenException("Invalid branch target position offset for " +
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
                                  super.toString(true) + ":" + t + ":" + target);
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
    return t - position;
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
   * @return the offset to this instruction's target
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
  protected int getTargetOffset() { return getTargetOffset(target); }
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
   * Called by InstructionList.setPositions when setting the position for every
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
   * instruction. In the presence of variable length instructions `setPositions'
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
   * performs multiple passes over the instruction list to calculate the
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
   * correct (byte) positions and offsets by calling this function.
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
   * @param offset additional offset caused by preceding (variable length) instructions
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
   * @param max_offset the maximum offset that may be caused by these instructions
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
   * @return additional offset caused by possible change of this instruction's length
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
  protected int updatePosition(int offset, int max_offset) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
    position += offset;
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
    return 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
   * Long output format:
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
   * &lt;position in byte code&gt;
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
   * &lt;name of opcode&gt; "["&lt;opcode number&gt;"]"
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
   * "("&lt;length of instruction&gt;")"
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
   * "&lt;"&lt;target instruction&gt;"&gt;" "@"&lt;branch target offset&gt;
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
   * @param verbose long/short format switch
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
   * @return mnemonic for instruction
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
   */
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   157
  @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
  public String toString(boolean verbose) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
    String s = super.toString(verbose);
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
    String t = "null";
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
    if(verbose) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
      if(target != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
        if(target.getInstruction() == this)
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
          t = "<points to itself>";
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
        else if(target.getInstruction() == null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
          t = "<null instruction!!!?>";
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
          t = target.getInstruction().toString(false); // Avoid circles
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
    } else {
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
      if(target != null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
        index = getTargetOffset();
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
        t = "" + (index + position);
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
    return s + " -> " + t;
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
   * Read needed data (e.g. index) from file. Conversion to a InstructionHandle
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
   * is done in InstructionList(byte[]).
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
   * @param bytes input stream
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
   * @param wide wide prefix?
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
   * @see InstructionList
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
   */
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   189
  @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
  protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
    length = 3;
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
    index  = bytes.readShort();
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
   * @return target offset in byte code
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
  public final int getIndex() { return index; }
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
   * @return target of branch instruction
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
  public InstructionHandle getTarget() { return target; }
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
   * Set branch target
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
   * @param target branch target
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
   */
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   210
  public final void setTarget(InstructionHandle target) {
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   211
    notifyTargetChanging(this.target, this);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
    this.target = target;
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   213
    notifyTargetChanged(this.target, this);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
  /**
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   217
   * Used by BranchInstruction, LocalVariableGen, CodeExceptionGen.
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   218
   * Must be called before the target is actually changed in the
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   219
   * InstructionTargeter.
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
   */
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   221
  static void notifyTargetChanging(InstructionHandle old_ih,
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
                                 InstructionTargeter t) {
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   223
    if(old_ih != null) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
      old_ih.removeTargeter(t);
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   225
    }
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   226
  }
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   227
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   228
  /**
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   229
   * Used by BranchInstruction, LocalVariableGen, CodeExceptionGen.
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   230
   * Must be called after the target is actually changed in the
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   231
   * InstructionTargeter.
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   232
   */
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   233
  static void notifyTargetChanged(InstructionHandle new_ih,
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   234
                                 InstructionTargeter t) {
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   235
    if(new_ih != null) {
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
      new_ih.addTargeter(t);
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   237
    }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
   * @param old_ih old target
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
   * @param new_ih new target
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
   */
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   244
  @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
  public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
    if(target == old_ih)
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
      setTarget(new_ih);
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
      throw new ClassGenException("Not targeting " + old_ih + ", but " + target);
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
   * @return true, if ih is target of this instruction
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
   */
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   255
  @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
  public boolean containsTarget(InstructionHandle ih) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
    return (target == ih);
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
   * Inform target that it's not targeted anymore.
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
   */
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   263
  @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
  void dispose() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
    setTarget(null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
    index=-1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
    position=-1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
}