/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* See JVMS, chapter 6.
*
* <p><b>This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
* This code and its internal interfaces are subject to change or
* deletion without notice.</b>
*
* @see Code_attribute#getInstructions
*/
public class Instruction {
/** The kind of an instruction, as determined by the position, size and
* types of its operands. */
public static enum Kind {
/** Opcode is not followed by any operands. */
/** Opcode is followed by a byte indicating a type. */
/** Opcode is followed by a 2-byte branch offset. */
/** Opcode is followed by a 4-byte branch offset. */
/** Opcode is followed by a signed byte value. */
/** Opcode is followed by a 1-byte index into the constant pool. */
/** Opcode is followed by a 2-byte index into the constant pool. */
/** Opcode is followed by a 2-byte index into the constant pool,
* an unsigned byte value. */
/** Opcode is followed by a 2-byte index into the constant pool.,
* an unsigned byte value, and a zero byte. */
/** Opcode is followed by variable number of operands, depending
* on the instruction.*/
/** Opcode is followed by a 1-byte reference to a local variable. */
/** Opcode is followed by a 1-byte reference to a local variable,
* and a signed byte value. */
/** Opcode is followed by a signed short value. */
/** Wide opcode is not followed by any operands. */
/** Wide opcode is followed by a 2-byte index into the constant pool. */
/** Wide opcode is followed by a 2-byte index into the constant pool,
* and a signed short value. */
/** Opcode was not recognized. */
}
/** The length, in bytes, of this kind of instruction, or -1 is the
* length depends on the specific instruction. */
public final int length;
};
/** A utility visitor to help decode the operands of an instruction.
* @see Instruction#accept */
public interface KindVisitor<R,P> {
/** See {@link Kind#NO_OPERANDS}, {@link Kind#WIDE_NO_OPERANDS}. */
/** See {@link Kind#ATYPE}. */
/** See {@link Kind#BRANCH}, {@link Kind#BRANCH_W}. */
/** See {@link Kind#CPREF}, {@link Kind#CPREF_W}, {@link Kind#WIDE_CPREF_W}. */
/** See {@link Kind#CPREF_W_UBYTE}, {@link Kind#CPREF_W_UBYTE_ZERO}, {@link Kind#WIDE_CPREF_W_SHORT}. */
/** See {@link Kind#LOCAL}. */
/** See {@link Kind#LOCAL_UBYTE}. */
/** See {@link Kind#DYNAMIC}. */
R visitLookupSwitch(Instruction instr, int default_, int npairs, int[] matches, int[] offsets, P p);
/** See {@link Kind#DYNAMIC}. */
/** See {@link Kind#BYTE}, {@link Kind#SHORT}. */
/** Instruction is unrecognized. */
}
/** The kind of primitive array type to create.
* See JVMS chapter 6, newarray. */
public static enum TypeKind {
}
switch (value) {
case 4: return T_BOOLEAN;
case 5: return T_CHAR;
case 6: return T_FLOAT;
case 7: return T_DOUBLE;
case 8: return T_BYTE;
case 9: return T_SHORT;
case 10: return T_INT;
case 11: return T_LONG;
default: return null;
}
}
public final int value;
}
/** An instruction is defined by its position in a bytecode array. */
}
/** Get the position of the instruction within the bytecode array. */
public int getPC() {
return pc;
}
/** Get a byte value, relative to the start of this instruction. */
}
/** Get an unsigned byte value, relative to the start of this instruction. */
}
/** Get a 2-byte value, relative to the start of this instruction. */
}
/** Get a unsigned 2-byte value, relative to the start of this instruction. */
}
/** Get a 4-byte value, relative to the start of this instruction. */
}
/** Get the Opcode for this instruction, or null if the instruction is
* unrecognized. */
int b = getUnsignedByte(0);
switch (b) {
}
}
/** Get the mnemonic for this instruction, or a default string if the
* instruction is unrecognized. */
else
}
/** Get the length, in bytes, of this instruction, including the opcode
* and all its operands. */
public int length() {
return 1;
switch (opcode) {
case TABLESWITCH: {
}
case LOOKUPSWITCH: {
}
default:
}
}
/** Get the {@link Kind} of this instruction. */
}
/** Invoke a method on the visitor according to the kind of this
* instruction, passing in the decoded operands for the instruction. */
switch (getKind()) {
case NO_OPERANDS:
return visitor.visitNoOperands(this, p);
case ATYPE:
return visitor.visitArrayType(
case BRANCH:
case BRANCH_W:
case BYTE:
case CPREF:
case CPREF_W:
case CPREF_W_UBYTE:
case CPREF_W_UBYTE_ZERO:
return visitor.visitConstantPoolRefAndValue(
case DYNAMIC: {
switch (getOpcode()) {
case TABLESWITCH: {
return visitor.visitTableSwitch(
}
case LOOKUPSWITCH: {
for (int i = 0; i < npairs; i++) {
}
return visitor.visitLookupSwitch(
}
default:
throw new IllegalStateException();
}
}
case LOCAL:
case LOCAL_BYTE:
return visitor.visitLocalAndValue(
case SHORT:
case WIDE_NO_OPERANDS:
return visitor.visitNoOperands(this, p);
case WIDE_CPREF_W:
case WIDE_CPREF_W_SHORT:
return visitor.visitConstantPoolRefAndValue(
case UNKNOWN:
return visitor.visitUnknown(this, p);
default:
throw new IllegalStateException();
}
}
private static int align(int n) {
return (n + 3) & ~3;
}
private byte[] bytes;
private int pc;
}