Jode 1.90-CVS
Build Aug 6, 2004

net.sf.jode.bytecode
Class Instruction

java.lang.Object
  extended bynet.sf.jode.bytecode.Instruction
All Implemented Interfaces:
Opcodes

public class Instruction
extends java.lang.Object
implements Opcodes

This class represents an instruction in the byte code. Instructions can be created with the static forOpcode(int) methods.

We only allow a subset of opcodes. Other opcodes are mapped to their simpler version. Don't worry about this, when writing the bytecode the shortest possible bytecode is produced.

The opcodes we map are:
 [iflda]load_x           -> [iflda]load
 [iflda]store_x          -> [iflda]store
 [ifa]const_xx, ldc_w    -> ldc
 [dl]const_xx            -> ldc2_w
 wide opcode             -> opcode
 tableswitch             -> lookupswitch
 [a]newarray             -> multianewarray
 


Field Summary
 
Fields inherited from interface net.sf.jode.bytecode.Opcodes
constants, newArrayTypes, 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_athrow, 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_impdep1, opc_impdep2, 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_putstatic, opc_ret, opc_return, opc_saload, opc_sastore, opc_sipush, opc_swap, opc_tableswitch, opc_wide, opc_xxxunusedxxx, opcodeString
 
Method Summary
 boolean doesAlwaysJump()
          Checks whether this instruction always changes program flow.
static Instruction forOpcode(int opcode)
          Creates a new simple Instruction with no parameters.
static Instruction forOpcode(int opcode, int[] values)
          Creates a new switch Instruction.
static Instruction forOpcode(int opcode, LocalVariableInfo lvi)
          Creates a new Instruction with a local variable as parameter.
static Instruction forOpcode(int opcode, LocalVariableInfo lvi, int increment)
          Creates a new increment Instruction.
static Instruction forOpcode(int opcode, java.lang.Object constant)
          Creates a new ldc Instruction.
static Instruction forOpcode(int opcode, Reference reference)
          Creates a new Instruction with reference as parameter.
static Instruction forOpcode(int opcode, java.lang.String typeSig)
          Creates a new Instruction with type signature as parameter.
static Instruction forOpcode(int opcode, java.lang.String typeSig, int dimension)
          Creates a new Instruction with type signature and a dimension as parameter.
 java.lang.String getClazzType()
          Gets the class type this instruction uses, e.g if its a class cast.
 java.lang.Object getConstant()
          Gets the constant for a opc_ldc or opc_ldc2_w opcode.
 java.lang.String getDescription()
          Gets a printable representation of the opcode with its parameters.
 int getDimensions()
          Gets the dimensions for an opc_multianewarray opcode.
 int getIncrement()
          Gets the increment for an opc_iinc instruction.
 int getLineNr()
          Gets the line number of this instruction.
 LocalVariableInfo getLocalInfo()
          Gets the information of the local this instruction accesses.
 int getLocalSlot()
          Gets the slot number of the local this instruction accesses.
 int getOpcode()
          Gets the opcode of the instruction.
 Reference getReference()
          Gets the reference of the field or method this instruction accesses.
 void getStackPopPush(int[] poppush)
          This returns the number of stack entries this instruction pushes and pops from the stack.
 int[] getValues()
          Gets the values of a opc_lookupswitch opcode.
 boolean hasLineNr()
          Tells whether there is a line number information for this instruction.
 boolean hasLocal()
          Checks whether this instruction accesses a local slot.
 boolean isStore()
          Checks whether this instruction is a local store instruction, i.e.
 void setClazzType(java.lang.String type)
          Sets the class type this instruction uses, e.g if its a class cast.
 void setConstant(java.lang.Object constant)
          Sets the constant for a opc_ldc or opc_ldc2_w opcode.
 void setDimensions(int dims)
          Sets the dimensions for an opc_multianewarray opcode.
 void setIncrement(int incr)
          Sets the increment for an opc_iinc instruction.
 void setLineNr(int nr)
          Sets the line number of this instruction.
 void setLocalInfo(LocalVariableInfo info)
          Sets the information of the local this instruction accesses.
 void setLocalSlot(int slot)
          Sets the slot of the local this instruction accesses.
 void setReference(Reference ref)
          Sets the reference of the field or method this instruction accesses.
 void setValues(int[] values)
          Sets the values of a opc_lookupswitch opcode.
 java.lang.String toString()
          Gets a printable representation of the opcode with its parameters.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

forOpcode

public static Instruction forOpcode(int opcode)
Creates a new simple Instruction with no parameters. We map some opcodes, so you must always use the mapped opcode.

Parameters:
opcode - the opcode of this instruction.
Throws:
java.lang.IllegalArgumentException - if opcode is not in our subset or if opcode needs a parameter.

forOpcode

public static Instruction forOpcode(int opcode,
                                    java.lang.Object constant)
Creates a new ldc Instruction.

Parameters:
opcode - the opcode of this instruction.
constant - the constant parameter.
Throws:
java.lang.IllegalArgumentException - if opcode is not opc_ldc or opc_ldc2_w.

forOpcode

public static Instruction forOpcode(int opcode,
                                    LocalVariableInfo lvi)
Creates a new Instruction with a local variable as parameter.

Parameters:
opcode - the opcode of this instruction.
lvi - the local variable parameter.
Throws:
java.lang.IllegalArgumentException - if opcode is not in our subset or if opcode doesn't need a single local variable as parameter.

forOpcode

public static Instruction forOpcode(int opcode,
                                    Reference reference)
Creates a new Instruction with reference as parameter.

Parameters:
opcode - the opcode of this instruction.
reference - the reference parameter.
Throws:
java.lang.IllegalArgumentException - if opcode is not in our subset or if opcode doesn't need a reference as parameter.

forOpcode

public static Instruction forOpcode(int opcode,
                                    java.lang.String typeSig)
Creates a new Instruction with type signature as parameter.

Parameters:
opcode - the opcode of this instruction.
typeSig - the type signature parameter.
Throws:
java.lang.IllegalArgumentException - if opcode is not in our subset or if opcode doesn't need a type signature as parameter.

forOpcode

public static Instruction forOpcode(int opcode,
                                    int[] values)
Creates a new switch Instruction.

Parameters:
opcode - the opcode of this instruction must be opc_lookupswitch.
values - an array containing the different cases.
Throws:
java.lang.IllegalArgumentException - if opcode is not opc_lookupswitch.

forOpcode

public static Instruction forOpcode(int opcode,
                                    LocalVariableInfo lvi,
                                    int increment)
Creates a new increment Instruction.

Parameters:
opcode - the opcode of this instruction.
lvi - the local variable parameter.
increment - the increment parameter.
Throws:
java.lang.IllegalArgumentException - if opcode is not opc_iinc.

forOpcode

public static Instruction forOpcode(int opcode,
                                    java.lang.String typeSig,
                                    int dimension)
Creates a new Instruction with type signature and a dimension as parameter.

Parameters:
opcode - the opcode of this instruction.
typeSig - the type signature parameter.
dimension - the array dimension parameter.
Throws:
java.lang.IllegalArgumentException - if opcode is not opc_multianewarray.

getOpcode

public final int getOpcode()
Gets the opcode of the instruction.

Returns:
the opcode of the instruction.

hasLineNr

public final boolean hasLineNr()
Tells whether there is a line number information for this instruction.

Returns:
true if there is a line number information for this instruction.

getLineNr

public final int getLineNr()
Gets the line number of this instruction.

Returns:
the line number, or -1 if there isn't one.

setLineNr

public final void setLineNr(int nr)
Sets the line number of this instruction.

Parameters:
nr - the line number; use -1 to clear it.

isStore

public boolean isStore()
Checks whether this instruction is a local store instruction, i.e. one of astore, istore, lstore, fstore or dstore.


hasLocal

public boolean hasLocal()
Checks whether this instruction accesses a local slot.


getLocalSlot

public int getLocalSlot()
Gets the slot number of the local this instruction accesses.

Returns:
the slot number.
Throws:
java.lang.IllegalArgumentException - if this instruction doesn't access a local slot.

getLocalInfo

public LocalVariableInfo getLocalInfo()
Gets the information of the local this instruction accesses.

Returns:
the local variable info.
Throws:
java.lang.IllegalArgumentException - if this instruction doesn't access a local.

setLocalInfo

public void setLocalInfo(LocalVariableInfo info)
Sets the information of the local this instruction accesses.

Parameters:
info - the local variable info.
Throws:
java.lang.IllegalArgumentException - if this instruction doesn't access a local.

setLocalSlot

public void setLocalSlot(int slot)
Sets the slot of the local this instruction accesses.

Parameters:
slot - the local slot
Throws:
java.lang.IllegalArgumentException - if this instruction doesn't access a local.

getIncrement

public int getIncrement()
Gets the increment for an opc_iinc instruction.

Throws:
java.lang.IllegalArgumentException - if this instruction doesn't support this.

setIncrement

public void setIncrement(int incr)
Sets the increment for an opc_iinc instruction.

Throws:
java.lang.IllegalArgumentException - if this instruction doesn't support this.

getDimensions

public int getDimensions()
Gets the dimensions for an opc_multianewarray opcode.

Throws:
java.lang.IllegalArgumentException - if this instruction doesn't support this.

setDimensions

public void setDimensions(int dims)
Sets the dimensions for an opc_multianewarray opcode.

Throws:
java.lang.IllegalArgumentException - if this instruction doesn't support this.

getConstant

public java.lang.Object getConstant()
Gets the constant for a opc_ldc or opc_ldc2_w opcode.

Throws:
java.lang.IllegalArgumentException - if this instruction doesn't support this.

setConstant

public void setConstant(java.lang.Object constant)
Sets the constant for a opc_ldc or opc_ldc2_w opcode.

Throws:
java.lang.IllegalArgumentException - if this instruction doesn't support this.

getReference

public Reference getReference()
Gets the reference of the field or method this instruction accesses.

Throws:
java.lang.IllegalArgumentException - if this instruction doesn't support this.

setReference

public void setReference(Reference ref)
Sets the reference of the field or method this instruction accesses.

Throws:
java.lang.IllegalArgumentException - if this instruction doesn't support this.

getClazzType

public java.lang.String getClazzType()
Gets the class type this instruction uses, e.g if its a class cast.

Throws:
java.lang.IllegalArgumentException - if this instruction doesn't support this.

setClazzType

public void setClazzType(java.lang.String type)
Sets the class type this instruction uses, e.g if its a class cast.

Throws:
java.lang.IllegalArgumentException - if this instruction doesn't support this.

getValues

public int[] getValues()
Gets the values of a opc_lookupswitch opcode.

Throws:
java.lang.IllegalArgumentException - if this instruction doesn't support this.

setValues

public void setValues(int[] values)
Sets the values of a opc_lookupswitch opcode.

Throws:
java.lang.IllegalArgumentException - if this instruction doesn't support this.

doesAlwaysJump

public final boolean doesAlwaysJump()
Checks whether this instruction always changes program flow. Returns false for opc_jsr it.

Returns:
true if this instruction always changes flow, i.e. if its an unconditional jump, a return, a throw, a ret or a switch.

getStackPopPush

public void getStackPopPush(int[] poppush)
This returns the number of stack entries this instruction pushes and pops from the stack. The result fills the given array.

Parameters:
poppush - an array of two ints. The first element will get the number of pops, the second the number of pushes.

getDescription

public final java.lang.String getDescription()
Gets a printable representation of the opcode with its parameters. This will not include the destination for jump instructions, since this information is not stored inside the instruction.


toString

public java.lang.String toString()
Gets a printable representation of the opcode with its parameters. This will not include the destination for jump instructions, since this information is not stored inside the instruction.


Jode 1.90-CVS
Build Aug 6, 2004

Copyright © 1998-2004 by Jochen Hoenicke.