jaxp/src/java.xml/share/classes/com/sun/org/apache/bcel/internal/generic/Select.java
author chegar
Sun, 17 Aug 2014 15:51:56 +0100
changeset 25868 686eef1e7a79
parent 17538 jaxp/src/com/sun/org/apache/bcel/internal/generic/Select.java@d8d911c4e5d4
child 44797 8b3b3b911b8a
permissions -rw-r--r--
8054834: Modular Source Code Reviewed-by: alanb, chegar, ihse, mduigou Contributed-by: alan.bateman@oracle.com, alex.buckley@oracle.com, chris.hegarty@oracle.com, erik.joelsson@oracle.com, jonathan.gibbons@oracle.com, karen.kinnear@oracle.com, magnus.ihse.bursie@oracle.com, mandy.chung@oracle.com, mark.reinhold@oracle.com, paul.sandoz@oracle.com
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
import java.io.*;
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
import com.sun.org.apache.bcel.internal.util.ByteSequence;
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
 * Select - Abstract super class for LOOKUPSWITCH and TABLESWITCH instructions.
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
 * @author  <A HREF="mailto:markus.dahm@berlin.de">M. Dahm</A>
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
 * @see LOOKUPSWITCH
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
 * @see TABLESWITCH
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
 * @see InstructionList
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
public abstract class Select extends BranchInstruction
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
  implements VariableLengthInstruction, StackProducer
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
  protected int[]               match;        // matches, i.e., case 1: ...
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
  protected int[]               indices;      // target offsets
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
  protected InstructionHandle[] targets;      // target objects in instruction list
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
  protected int                 fixed_length; // fixed length defined by subclasses
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
  protected int                 match_length; // number of cases
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
  protected int                 padding = 0;  // number of pad bytes for alignment
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
   * Empty constructor needed for the Class.newInstance() statement in
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
   * Instruction.readInstruction(). Not to be used otherwise.
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
  Select() {}
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
   * (Match, target) pairs for switch.
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
   * `Match' and `targets' must have the same length of course.
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
   * @param match array of matching values
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
   * @param targets instruction targets
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
   * @param target default instruction target
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
  Select(short opcode, int[] match, InstructionHandle[] targets,
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
         InstructionHandle target) {
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
    super(opcode, target);
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
    this.targets = targets;
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   100
    for(int i=0; i < targets.length; i++) {
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   101
      BranchInstruction.notifyTargetChanged(targets[i], this);
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   102
    }
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
    this.match = match;
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
    if((match_length = match.length) != targets.length)
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
      throw new ClassGenException("Match and target array have not the same length");
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
    indices = new int[match_length];
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
   * Since this is a variable length instruction, it may shift the following
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
   * instructions which then need to update their position.
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
   * Called by InstructionList.setPositions when setting the position for every
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
   * instruction. In the presence of variable length instructions `setPositions'
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
   * performs multiple passes over the instruction list to calculate the
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
   * correct (byte) positions and offsets by calling this function.
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
   * @param offset additional offset caused by preceding (variable length) instructions
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
   * @param max_offset the maximum offset that may be caused by these instructions
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
   * @return additional offset caused by possible change of this instruction's length
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
   */
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   125
  @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
  protected int updatePosition(int offset, int max_offset) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
    position += offset; // Additional offset caused by preceding SWITCHs, GOTOs, etc.
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
    short old_length = length;
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
    /* Alignment on 4-byte-boundary, + 1, because of tag byte.
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
    padding = (4 - ((position + 1) % 4)) % 4;
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
    length  = (short)(fixed_length + padding); // Update length
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
    return length - old_length;
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
   * Dump instruction as byte code to stream out.
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
   * @param out Output stream
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
   */
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   143
  @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
  public void dump(DataOutputStream out) throws IOException {
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
    out.writeByte(opcode);
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
    for(int i=0; i < padding; i++) // Padding bytes
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
      out.writeByte(0);
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
    index = getTargetOffset();     // Write default target offset
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
    out.writeInt(index);
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
   * Read needed data (e.g. index) from file.
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
  protected void initFromFile(ByteSequence bytes, boolean wide) throws IOException
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
    padding = (4 - (bytes.getIndex() % 4)) % 4; // Compute number of pad bytes
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
    for(int i=0; i < padding; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
      bytes.readByte();
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
    // Default branch target common for both cases (TABLESWITCH, LOOKUPSWITCH)
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
    index = bytes.readInt();
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
   * @return mnemonic for instruction
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
   */
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   173
  @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
  public String toString(boolean verbose) {
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   175
    final StringBuilder buf = new StringBuilder(super.toString(verbose));
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
    if(verbose) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
      for(int i=0; i < match_length; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
        String s = "null";
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
        if(targets[i] != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
          s = targets[i].getInstruction().toString();
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   184
          buf.append("(").append(match[i]).append(", ")
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   185
             .append(s).append(" = {").append(indices[i]).append("})");
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
      buf.append(" ...");
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
    return buf.toString();
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
   * Set branch target for `i'th case
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
   */
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   197
  public final void setTarget(int i, InstructionHandle target) {
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   198
    notifyTargetChanging(targets[i], this);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
    targets[i] = target;
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   200
    notifyTargetChanged(targets[i], this);
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
   * @param old_ih old target
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
   * @param new_ih new target
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
   */
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   207
  @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
  public void updateTarget(InstructionHandle old_ih, InstructionHandle new_ih) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
    boolean targeted = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
    if(target == old_ih) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
      targeted = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
      setTarget(new_ih);
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
    for(int i=0; i < targets.length; i++) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
      if(targets[i] == old_ih) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
        targeted = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
        setTarget(i, new_ih);
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
    if(!targeted)
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
      throw new ClassGenException("Not targeting " + old_ih);
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
   * @return true, if ih is target of this instruction
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
   */
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   230
  @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
  public boolean containsTarget(InstructionHandle ih) {
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
    if(target == ih)
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
      return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
    for(int i=0; i < targets.length; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
      if(targets[i] == ih)
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
        return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
    return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
   * Inform targets that they're not targeted anymore.
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
   */
17538
d8d911c4e5d4 8013900: More warnings compiling jaxp.
dfuchs
parents: 12457
diff changeset
   245
  @Override
6
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
  void dispose() {
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
    super.dispose();
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
    for(int i=0; i < targets.length; i++)
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
      targets[i].removeTargeter(this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
   * @return array of match indices
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
  public int[] getMatchs() { return match; }
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
   * @return array of match target offsets
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
  public int[] getIndices() { return indices; }
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
   * @return array of match targets
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
  public InstructionHandle[] getTargets() { return targets; }
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
}