langtools/src/share/classes/com/sun/tools/classfile/Instruction.java
author jjg
Thu, 10 Jun 2010 16:08:01 -0700
changeset 5847 1908176fd6e3
parent 5520 86e4b9a9da40
child 9303 eae35c201e19
permissions -rw-r--r--
6944312: Potential rebranding issues in openjdk/langtools repository sources Reviewed-by: darcy
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2512
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
     1
/*
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4411
diff changeset
     2
 * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved.
2512
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
     4
 *
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4411
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2512
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4411
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2512
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    10
 *
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    15
 * accompanied this code).
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    16
 *
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4411
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4411
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 4411
diff changeset
    23
 * questions.
2512
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    24
 */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    25
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    26
package com.sun.tools.classfile;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    27
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    28
/**
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    29
 * See JVMS3, chapter 6.
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    30
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    31
 *  <p><b>This is NOT part of any supported API.
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5520
diff changeset
    32
 *  If you write code that depends on this, you do so at your own risk.
2512
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    33
 *  This code and its internal interfaces are subject to change or
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    34
 *  deletion without notice.</b>
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    35
 *
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    36
 * @see Code_attribute#getInstructions
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    37
 */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    38
public class Instruction {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    39
    /** The kind of an instruction, as determined by the position, size and
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    40
     *  types of its operands. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    41
    public static enum Kind {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    42
        /** Opcode is not followed by any operands. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    43
        NO_OPERANDS(1),
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    44
        /** Opcode is followed by a byte indicating a type. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    45
        ATYPE(2),
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    46
        /** Opcode is followed by a 2-byte branch offset. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    47
        BRANCH(3),
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    48
        /** Opcode is followed by a 4-byte branch offset. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    49
        BRANCH_W(5),
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    50
        /** Opcode is followed by a signed byte value. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    51
        BYTE(2),
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    52
        /** Opcode is followed by a 1-byte index into the constant pool. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    53
        CPREF(2),
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    54
        /** Opcode is followed by a 2-byte index into the constant pool. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    55
        CPREF_W(3),
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    56
        /** Opcode is followed by a 2-byte index into the constant pool,
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    57
         *  an unsigned byte value. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    58
        CPREF_W_UBYTE(4),
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    59
        /** Opcode is followed by a 2-byte index into the constant pool.,
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    60
         *  an unsigned byte value, and a zero byte. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    61
        CPREF_W_UBYTE_ZERO(5),
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    62
        /** Opcode is followed by variable number of operands, depending
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    63
         * on the instruction.*/
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    64
        DYNAMIC(-1),
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    65
        /** Opcode is followed by a 1-byte reference to a local variable. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    66
        LOCAL(2),
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    67
        /** Opcode is followed by a 1-byte reference to a local variable,
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    68
         *  and a signed byte value. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    69
        LOCAL_BYTE(3),
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    70
        /** Opcode is followed by a signed short value. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    71
        SHORT(3),
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    72
        /** Wide opcode is not followed by any operands. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    73
        WIDE_NO_OPERANDS(2),
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    74
        /** Wide opcode is followed by a 2-byte index into the constant pool. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    75
        WIDE_CPREF_W(4),
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    76
        /** Wide opcode is followed by a 2-byte index into the constant pool,
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    77
         *  and a signed short value. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    78
        WIDE_CPREF_W_SHORT(6),
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    79
        /** Opcode was not recognized. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    80
        UNKNOWN(1);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    81
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    82
        Kind(int length) {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    83
            this.length = length;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    84
        }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    85
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    86
        /** The length, in bytes, of this kind of instruction, or -1 is the
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    87
         *  length depends on the specific instruction. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    88
        public final int length;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    89
    };
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    90
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    91
    /** A utility visitor to help decode the operands of an instruction.
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    92
     *  @see Instruction#accept */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    93
    public interface KindVisitor<R,P> {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    94
        /** See {@link Kind#NO_OPERANDS}, {@link Kind#WIDE_NO_OPERANDS}. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    95
        R visitNoOperands(Instruction instr, P p);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    96
        /** See {@link Kind#ATYPE}. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    97
        R visitArrayType(Instruction instr, TypeKind kind, P p);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    98
        /** See {@link Kind#BRANCH}, {@link Kind#BRANCH_W}. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
    99
        R visitBranch(Instruction instr, int offset, P p);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   100
        /** See {@link Kind#CPREF}, {@link Kind#CPREF_W}, {@link Kind#WIDE_CPREF_W}. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   101
        R visitConstantPoolRef(Instruction instr, int index, P p);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   102
        /** See {@link Kind#CPREF_W_UBYTE}, {@link Kind#CPREF_W_UBYTE_ZERO}, {@link Kind#WIDE_CPREF_W_SHORT}. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   103
        R visitConstantPoolRefAndValue(Instruction instr, int index, int value, P p);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   104
        /** See {@link Kind#LOCAL}. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   105
        R visitLocal(Instruction instr, int index, P p);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   106
        /** See {@link Kind#LOCAL_UBYTE}. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   107
        R visitLocalAndValue(Instruction instr, int index, int value, P p);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   108
        /** See {@link Kind#DYNAMIC}. */
4411
84c397e2ee67 6902264: fix indentation of tableswitch and lookupswitch
jjg
parents: 2512
diff changeset
   109
        R visitLookupSwitch(Instruction instr, int default_, int npairs, int[] matches, int[] offsets, P p);
2512
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   110
        /** See {@link Kind#DYNAMIC}. */
4411
84c397e2ee67 6902264: fix indentation of tableswitch and lookupswitch
jjg
parents: 2512
diff changeset
   111
        R visitTableSwitch(Instruction instr, int default_, int low, int high, int[] offsets, P p);
2512
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   112
        /** See {@link Kind#BYTE}, {@link Kind#SHORT}. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   113
        R visitValue(Instruction instr, int value, P p);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   114
        /** Instruction is unrecognized. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   115
        R visitUnknown(Instruction instr, P p);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   116
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   117
    }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   118
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   119
    /** The kind of primitive array type to create.
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   120
     *  See JVMS chapter 6, newarray. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   121
    public static enum TypeKind {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   122
        T_BOOLEAN(4, "boolean"),
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   123
        T_CHAR(5, "char"),
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   124
        T_FLOAT(6, "float"),
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   125
        T_DOUBLE(7, "double"),
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   126
        T_BYTE(8, "byte"),
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   127
        T_SHORT(9, "short"),
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   128
        T_INT (10, "int"),
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   129
        T_LONG (11, "long");
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   130
        TypeKind(int value, String name) {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   131
            this.value = value;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   132
            this.name = name;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   133
        }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   134
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   135
        public static TypeKind get(int value) {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   136
            switch (value) {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   137
                case  4: return T_BOOLEAN;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   138
                case  5: return T_CHAR;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   139
                case  6: return T_FLOAT;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   140
                case  7: return T_DOUBLE;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   141
                case  8: return T_BYTE;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   142
                case  9: return T_SHORT;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   143
                case  10: return T_INT;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   144
                case  11: return T_LONG;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   145
                default: return null;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   146
            }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   147
        }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   148
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   149
        public final int value;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   150
        public final String name;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   151
    }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   152
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   153
    /** An instruction is defined by its position in a bytecode array. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   154
    public Instruction(byte[] bytes, int pc) {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   155
        this.bytes = bytes;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   156
        this.pc = pc;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   157
    }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   158
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   159
    /** Get the position of the instruction within the bytecode array. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   160
    public int getPC() {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   161
        return pc;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   162
    }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   163
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   164
    /** Get a byte value, relative to the start of this instruction. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   165
    public int getByte(int offset) {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   166
        return bytes[pc + offset];
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   167
    }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   168
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   169
    /** Get an unsigned byte value, relative to the start of this instruction. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   170
    public int getUnsignedByte(int offset) {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   171
        return getByte(offset) & 0xff;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   172
    }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   173
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   174
    /** Get a 2-byte value, relative to the start of this instruction. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   175
    public int getShort(int offset) {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   176
        return (getByte(offset) << 8) | getUnsignedByte(offset + 1);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   177
    }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   178
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   179
    /** Get a unsigned 2-byte value, relative to the start of this instruction. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   180
    public int getUnsignedShort(int offset) {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   181
        return getShort(offset) & 0xFFFF;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   182
    }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   183
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   184
    /** Get a 4-byte value, relative to the start of this instruction. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   185
    public int getInt(int offset) {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   186
        return (getShort(offset) << 16) | (getUnsignedShort(offset + 2));
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   187
    }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   188
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   189
    /** Get the Opcode for this instruction, or null if the instruction is
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   190
     * unrecognized. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   191
    public Opcode getOpcode() {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   192
        int b = getUnsignedByte(0);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   193
        switch (b) {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   194
            case Opcode.NONPRIV:
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   195
            case Opcode.PRIV:
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   196
            case Opcode.WIDE:
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   197
                return Opcode.get(b, getUnsignedByte(1));
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   198
        }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   199
        return Opcode.get(b);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   200
    }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   201
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   202
    /** Get the mnemonic for this instruction, or a default string if the
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   203
     * instruction is unrecognized. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   204
    public String getMnemonic() {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   205
        Opcode opcode = getOpcode();
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   206
        if (opcode == null)
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   207
            return "bytecode " + getUnsignedByte(0);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   208
        else
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   209
            return opcode.toString().toLowerCase();
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   210
    }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   211
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   212
    /** Get the length, in bytes, of this instruction, including the opcode
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   213
     * and all its operands. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   214
    public int length() {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   215
        Opcode opcode = getOpcode();
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   216
        if (opcode == null)
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   217
            return 1;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   218
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   219
        switch (opcode) {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   220
            case TABLESWITCH: {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   221
                int pad = align(pc + 1) - pc;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   222
                int low = getInt(pad + 4);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   223
                int high = getInt(pad + 8);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   224
                return pad + 12 + 4 * (high - low + 1);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   225
            }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   226
            case LOOKUPSWITCH: {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   227
                int pad = align(pc + 1) - pc;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   228
                int npairs = getInt(pad + 4);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   229
                return pad + 8 + 8 * npairs;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   230
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   231
            }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   232
            default:
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   233
                return opcode.kind.length;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   234
        }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   235
    }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   236
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   237
    /** Get the {@link Kind} of this instruction. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   238
    public Kind getKind() {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   239
        Opcode opcode = getOpcode();
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   240
        return (opcode != null ? opcode.kind : Kind.UNKNOWN);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   241
    }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   242
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   243
    /** Invoke a method on the visitor according to the kind of this
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   244
     * instruction, passing in the decoded operands for the instruction. */
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   245
    public <R,P> R accept(KindVisitor<R,P> visitor, P p) {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   246
        switch (getKind()) {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   247
            case NO_OPERANDS:
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   248
                return visitor.visitNoOperands(this, p);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   249
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   250
            case ATYPE:
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   251
                return visitor.visitArrayType(
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   252
                        this, TypeKind.get(getUnsignedByte(1)), p);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   253
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   254
            case BRANCH:
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   255
                return visitor.visitBranch(this, getShort(1), p);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   256
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   257
            case BRANCH_W:
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   258
                return visitor.visitBranch(this, getInt(1), p);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   259
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   260
            case BYTE:
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   261
                return visitor.visitValue(this, getByte(1), p);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   262
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   263
            case CPREF:
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   264
                return visitor.visitConstantPoolRef(this, getUnsignedByte(1), p);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   265
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   266
            case CPREF_W:
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   267
                return visitor.visitConstantPoolRef(this, getUnsignedShort(1), p);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   268
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   269
            case CPREF_W_UBYTE:
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   270
            case CPREF_W_UBYTE_ZERO:
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   271
                return visitor.visitConstantPoolRefAndValue(
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   272
                        this, getUnsignedShort(1), getUnsignedByte(3), p);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   273
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   274
            case DYNAMIC: {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   275
                switch (getOpcode()) {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   276
                    case TABLESWITCH: {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   277
                        int pad = align(pc + 1) - pc;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   278
                        int default_ = getInt(pad);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   279
                        int low = getInt(pad + 4);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   280
                        int high = getInt(pad + 8);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   281
                        int[] values = new int[high - low + 1];
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   282
                        for (int i = 0; i < values.length; i++)
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   283
                            values[i] = getInt(pad + 12 + 4 * i);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   284
                        return visitor.visitTableSwitch(
4411
84c397e2ee67 6902264: fix indentation of tableswitch and lookupswitch
jjg
parents: 2512
diff changeset
   285
                                this, default_, low, high, values, p);
2512
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   286
                    }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   287
                    case LOOKUPSWITCH: {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   288
                        int pad = align(pc + 1) - pc;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   289
                        int default_ = getInt(pad);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   290
                        int npairs = getInt(pad + 4);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   291
                        int[] matches = new int[npairs];
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   292
                        int[] offsets = new int[npairs];
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   293
                        for (int i = 0; i < npairs; i++) {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   294
                            matches[i] = getInt(pad +  8 + i * 8);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   295
                            offsets[i] = getInt(pad + 12 + i * 8);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   296
                        }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   297
                        return visitor.visitLookupSwitch(
4411
84c397e2ee67 6902264: fix indentation of tableswitch and lookupswitch
jjg
parents: 2512
diff changeset
   298
                                this, default_, npairs, matches, offsets, p);
2512
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   299
                    }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   300
                    default:
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   301
                        throw new IllegalStateException();
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   302
                }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   303
            }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   304
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   305
            case LOCAL:
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   306
                return visitor.visitLocal(this, getUnsignedByte(1), p);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   307
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   308
            case LOCAL_BYTE:
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   309
                return visitor.visitLocalAndValue(
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   310
                        this, getUnsignedByte(1), getByte(2), p);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   311
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   312
            case SHORT:
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   313
                return visitor.visitValue(this, getShort(1), p);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   314
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   315
            case WIDE_NO_OPERANDS:
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   316
                return visitor.visitNoOperands(this, p);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   317
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   318
            case WIDE_CPREF_W:
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   319
                return visitor.visitConstantPoolRef(this, getUnsignedShort(2), p);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   320
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   321
            case WIDE_CPREF_W_SHORT:
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   322
                return visitor.visitConstantPoolRefAndValue(
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   323
                        this, getUnsignedShort(2), getUnsignedByte(4), p);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   324
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   325
            case UNKNOWN:
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   326
                return visitor.visitUnknown(this, p);
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   327
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   328
            default:
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   329
                throw new IllegalStateException();
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   330
        }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   331
    }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   332
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   333
    private static int align(int n) {
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   334
        return (n + 3) & ~3;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   335
    }
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   336
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   337
    private byte[] bytes;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   338
    private int pc;
70eb5f17c5f8 6819246: improve support for decoding instructions in classfile library
jjg
parents:
diff changeset
   339
}