Class Instruction
java.lang.Object
EDU.purdue.cs.bloat.editor.Instruction
- All Implemented Interfaces:
Opcode
Instruction represents a single instruction in the JVM. All
Instructions known their opcode. Some instructions have an
operand. Operands are integers, floats, or one of the special classes that
represent multiple operands such as IncOperand and Switch.
- See Also:
-
Field Summary
Fields inherited from interface Opcode
opc_aaload, opc_aastore, opc_aconst_null, opc_aload, opc_aload_0, opc_aload_1, opc_aload_2, opc_aload_3, opc_anewarray, opc_areturn, opc_arraylength, opc_astore, opc_astore_0, opc_astore_1, opc_astore_2, opc_astore_3, opc_aswizzle, opc_aswrange, opc_athrow, opc_aupdate, opc_baload, opc_bastore, opc_bipush, opc_breakpoint, opc_caload, opc_castore, opc_checkcast, opc_d2f, opc_d2i, opc_d2l, opc_dadd, opc_daload, opc_dastore, opc_dcmpg, opc_dcmpl, opc_dconst_0, opc_dconst_1, opc_ddiv, opc_dload, opc_dload_0, opc_dload_1, opc_dload_2, opc_dload_3, opc_dmul, opc_dneg, opc_drem, opc_dreturn, opc_dstore, opc_dstore_0, opc_dstore_1, opc_dstore_2, opc_dstore_3, opc_dsub, opc_dup, opc_dup_x1, opc_dup_x2, opc_dup2, opc_dup2_x1, opc_dup2_x2, opc_f2d, opc_f2i, opc_f2l, opc_fadd, opc_faload, opc_fastore, opc_fcmpg, opc_fcmpl, opc_fconst_0, opc_fconst_1, opc_fconst_2, opc_fdiv, opc_fload, opc_fload_0, opc_fload_1, opc_fload_2, opc_fload_3, opc_fmul, opc_fneg, opc_frem, opc_freturn, opc_fstore, opc_fstore_0, opc_fstore_1, opc_fstore_2, opc_fstore_3, opc_fsub, opc_getfield, opc_getstatic, opc_goto, opc_goto_w, opc_i2b, opc_i2c, opc_i2d, opc_i2f, opc_i2l, opc_i2s, opc_iadd, opc_iaload, opc_iand, opc_iastore, opc_iconst_0, opc_iconst_1, opc_iconst_2, opc_iconst_3, opc_iconst_4, opc_iconst_5, opc_iconst_m1, opc_idiv, opc_if_acmpeq, opc_if_acmpne, opc_if_icmpeq, opc_if_icmpge, opc_if_icmpgt, opc_if_icmple, opc_if_icmplt, opc_if_icmpne, opc_ifeq, opc_ifge, opc_ifgt, opc_ifle, opc_iflt, opc_ifne, opc_ifnonnull, opc_ifnull, opc_iinc, opc_iload, opc_iload_0, opc_iload_1, opc_iload_2, opc_iload_3, opc_imul, opc_ineg, opc_instanceof, opc_invokeinterface, opc_invokespecial, opc_invokestatic, opc_invokevirtual, opc_ior, opc_irem, opc_ireturn, opc_ishl, opc_ishr, opc_istore, opc_istore_0, opc_istore_1, opc_istore_2, opc_istore_3, opc_isub, opc_iushr, opc_ixor, opc_jsr, opc_jsr_w, opc_l2d, opc_l2f, opc_l2i, opc_ladd, opc_laload, opc_land, opc_lastore, opc_lcmp, opc_lconst_0, opc_lconst_1, opc_ldc, opc_ldc_w, opc_ldc2_w, opc_ldiv, opc_lload, opc_lload_0, opc_lload_1, opc_lload_2, opc_lload_3, opc_lmul, opc_lneg, opc_lookupswitch, opc_lor, opc_lrem, opc_lreturn, opc_lshl, opc_lshr, opc_lstore, opc_lstore_0, opc_lstore_1, opc_lstore_2, opc_lstore_3, opc_lsub, opc_lushr, opc_lxor, opc_monitorenter, opc_monitorexit, opc_multianewarray, opc_new, opc_newarray, opc_nop, opc_pop, opc_pop2, opc_putfield, opc_putfield_nowb, opc_putstatic, opc_putstatic_nowb, opc_rc, opc_ret, opc_return, opc_saload, opc_sastore, opc_sipush, opc_supdate, opc_swap, opc_tableswitch, opc_wide, opc_xxxunusedxxx, opcNames, opcSize, opcx_aaload, opcx_aastore, opcx_aload, opcx_areturn, opcx_arraylength, opcx_astore, opcx_aswizzle, opcx_aswrange, opcx_athrow, opcx_aupdate, opcx_baload, opcx_bastore, opcx_caload, opcx_castore, opcx_checkcast, opcx_d2f, opcx_d2i, opcx_d2l, opcx_dadd, opcx_daload, opcx_dastore, opcx_dcmpg, opcx_dcmpl, opcx_ddiv, opcx_dload, opcx_dmul, opcx_dneg, opcx_drem, opcx_dreturn, opcx_dstore, opcx_dsub, opcx_dup, opcx_dup_x1, opcx_dup_x2, opcx_dup2, opcx_dup2_x1, opcx_dup2_x2, opcx_f2d, opcx_f2i, opcx_f2l, opcx_fadd, opcx_faload, opcx_fastore, opcx_fcmpg, opcx_fcmpl, opcx_fdiv, opcx_fload, opcx_fmul, opcx_fneg, opcx_frem, opcx_freturn, opcx_fstore, opcx_fsub, opcx_getfield, opcx_getstatic, opcx_goto, opcx_i2b, opcx_i2c, opcx_i2d, opcx_i2f, opcx_i2l, opcx_i2s, opcx_iadd, opcx_iaload, opcx_iand, opcx_iastore, opcx_idiv, opcx_if_acmpeq, opcx_if_acmpne, opcx_if_icmpeq, opcx_if_icmpge, opcx_if_icmpgt, opcx_if_icmple, opcx_if_icmplt, opcx_if_icmpne, opcx_ifeq, opcx_ifge, opcx_ifgt, opcx_ifle, opcx_iflt, opcx_ifne, opcx_ifnonnull, opcx_ifnull, opcx_iinc, opcx_iload, opcx_imul, opcx_ineg, opcx_instanceof, opcx_invokeinterface, opcx_invokespecial, opcx_invokestatic, opcx_invokevirtual, opcx_ior, opcx_irem, opcx_ireturn, opcx_ishl, opcx_ishr, opcx_istore, opcx_isub, opcx_iushr, opcx_ixor, opcx_jsr, opcx_l2d, opcx_l2f, opcx_l2i, opcx_ladd, opcx_laload, opcx_land, opcx_lastore, opcx_lcmp, opcx_ldc, opcx_ldiv, opcx_lload, opcx_lmul, opcx_lneg, opcx_lor, opcx_lrem, opcx_lreturn, opcx_lshl, opcx_lshr, opcx_lstore, opcx_lsub, opcx_lushr, opcx_lxor, opcx_monitorenter, opcx_monitorexit, opcx_multianewarray, opcx_new, opcx_newarray, opcx_nop, opcx_pop, opcx_pop2, opcx_putfield, opcx_putfield_nowb, opcx_putstatic, opcx_putstatic_nowb, opcx_rc, opcx_ret, opcx_return, opcx_saload, opcx_sastore, opcx_supdate, opcx_swap, opcx_switch, opcXMap, VARIABLE -
Constructor Summary
ConstructorsConstructorDescriptionInstruction(byte[] code, int index, int[] targets, int[] lookups, LocalVariable[] locals, ConstantPool constants) Constructor.Instruction(int opcode) Constructor.Instruction(int opcode, Object operand) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionintcategory()Returns the category of this instruction.booleanCheck if the instruction is a conditional jump.booleanisGoto()Check if the instruction is a goto.booleanisInc()Check if the instruction is an increment.booleanisInvoke()Returns true if this instruction invokes a method.booleanisJsr()Check if the instruction is a jsr.booleanisJump()Check if the instruction is a jump.booleanisLoad()Check if the instruction is a load.booleanisRet()Check if the instruction is a subroutine return instruction.booleanisReturn()Returns true if the instruction returns from a method.booleanisStore()Check if the instruction is a store.booleanisSwitch()Check if the instruction is a switch.booleanisThrow()Check if the instruction is an exception throw instruction.intGet the opcode class of the instruction.operand()Get the operand of the instruction.intReturns the original (non-mapped) opcode used to create this Instruction.voidsetOpcodeClass(int opcode) Set the opcode class of the instruction.voidsetOperand(Object operand) Set the operand of the instruction.voidsetUseSlow(boolean useSlow) Sets a flag that determines whether or not the "slow" version of the instruction should be generated.protected static inttoInt(byte b1, byte b2, byte b3, byte b4) Utility function to join 4 bytes into an signed int.protected static shorttoShort(byte b1, byte b2) Utility function to join 2 bytes into an signed short.toString()Convert the instruction to a string.protected static inttoUByte(byte b) Utility function to convert a byte into an unsigned byte.protected static inttoUShort(byte b1, byte b2) Utility function to join 2 bytes into an unsigned short.booleanuseSlow()Returns whether or not the "slow" version of this instruction is generated.voidvisit(InstructionVisitor visitor) Big switch statement to call the appropriate method of an instruction visitor.
-
Constructor Details
-
Instruction
public Instruction(int opcode) Constructor.- Parameters:
opcode- The opcode class of the instruction.
-
Instruction
Constructor.- Parameters:
opcode- The opcode class of the instruction.operand- The operand of the instruction, or null.
-
Instruction
public Instruction(byte[] code, int index, int[] targets, int[] lookups, LocalVariable[] locals, ConstantPool constants) Constructor.- Parameters:
code- The raw byte code array of the method.index- This index into the byte array of the instruction.targets- Indices of the branch targets of the instruction.lookups- Values of the switch lookups of the instruction.locals- The local variables defined at this index.constants- The constant pool for the class.
-
-
Method Details
-
origOpcode
public int origOpcode()Returns the original (non-mapped) opcode used to create this Instruction. -
setUseSlow
public void setUseSlow(boolean useSlow) Sets a flag that determines whether or not the "slow" version of the instruction should be generated. For example, if useSlow is true, "iload 2" is generated instead of "iload_2". -
useSlow
public boolean useSlow()Returns whether or not the "slow" version of this instruction is generated. -
isLoad
public boolean isLoad()Check if the instruction is a load.- Returns:
- true if the instruction is a load, false if not.
-
isStore
public boolean isStore()Check if the instruction is a store.- Returns:
- true if the instruction is a store, false if not.
-
isInc
public boolean isInc()Check if the instruction is an increment.- Returns:
- true if the instruction is an increment, false if not.
-
isThrow
public boolean isThrow()Check if the instruction is an exception throw instruction.- Returns:
- true if the instruction is a throw, false if not.
-
isInvoke
public boolean isInvoke()Returns true if this instruction invokes a method. -
isRet
public boolean isRet()Check if the instruction is a subroutine return instruction.- Returns:
- true if the instruction is a ret, false if not.
-
isReturn
public boolean isReturn()Returns true if the instruction returns from a method. -
isSwitch
public boolean isSwitch()Check if the instruction is a switch.- Returns:
- true if the instruction is a switch, false if not.
-
isJump
public boolean isJump()Check if the instruction is a jump.- Returns:
- true if the instruction is a jump, false if not.
-
isJsr
public boolean isJsr()Check if the instruction is a jsr.- Returns:
- true if the instruction is a jsr, false if not.
-
isGoto
public boolean isGoto()Check if the instruction is a goto.- Returns:
- true if the instruction is a goto, false if not.
-
isConditionalJump
public boolean isConditionalJump()Check if the instruction is a conditional jump.- Returns:
- true if the instruction is a conditional jump, false if not.
-
opcodeClass
public int opcodeClass()Get the opcode class of the instruction.- Returns:
- The opcode class of the instruction.
-
setOpcodeClass
public void setOpcodeClass(int opcode) Set the opcode class of the instruction.- Parameters:
opcode- The opcode class of the instruction.
-
setOperand
Set the operand of the instruction.- Parameters:
operand- The operand of the instruction.
-
operand
Get the operand of the instruction.- Returns:
- The operand of the instruction.
-
toString
-
toUShort
protected static int toUShort(byte b1, byte b2) Utility function to join 2 bytes into an unsigned short.- Parameters:
b1- The upper byte.b2- The lower byte.- Returns:
- The unsigned short.
-
toShort
protected static short toShort(byte b1, byte b2) Utility function to join 2 bytes into an signed short.- Parameters:
b1- The upper byte.b2- The lower byte.- Returns:
- The signed short.
-
toInt
protected static int toInt(byte b1, byte b2, byte b3, byte b4) Utility function to join 4 bytes into an signed int.- Parameters:
b1- The upper byte.b2- The next-to-upper byte.b3- The next-to-lower byte.b4- The lower byte.- Returns:
- The signed int.
-
toUByte
protected static int toUByte(byte b) Utility function to convert a byte into an unsigned byte.- Parameters:
b- The byte.- Returns:
- The unsigned byte.
-
category
public int category()Returns the category of this instruction. An instruction's category is basically the width of the value the instruction places on the stack. Types long and double are Category 2. All other types are Category 1. -
visit
Big switch statement to call the appropriate method of an instruction visitor.- Parameters:
visitor- The instruction visitor.
-