com.ibm.wala.shrikeBT
Class Instruction

java.lang.Object
  extended by com.ibm.wala.shrikeBT.Instruction
All Implemented Interfaces:
Constants, IInstruction, java.lang.Cloneable
Direct Known Subclasses:
ArrayLengthInstruction, ArrayLoadInstruction, ArrayStoreInstruction, BinaryOpInstruction, CheckCastInstruction, ComparisonInstruction, ConditionalBranchInstruction, ConstantInstruction, ConversionInstruction, DupInstruction, GetInstruction, GotoInstruction, InstanceofInstruction, InvokeInstruction, LoadInstruction, MonitorInstruction, NewInstruction, PopInstruction, PutInstruction, ReturnInstruction, ShiftInstruction, StoreInstruction, SwapInstruction, SwitchInstruction, ThrowInstruction, UnaryOpInstruction

public abstract class Instruction
extends java.lang.Object
implements Constants, java.lang.Cloneable, IInstruction

Instructions are immutable objects. It is always legal to take a reference to an instruction and use it in any other context. You never need to copy instructions. It is often a good idea to keep references to frequently used instructions cached in static fields. To generate an Instruction, locate the class for the instruction you want to generate, and invoke the appropriate "make" static method on that class. The Util class has convenience methods for creating some of the more complex instructions using reflection to fill in some of the needed information (e.g., makeGet, makePut, makeInvoke). We simplify the bytecode instruction set a bit using some preprocessing and postprocessing: There is no 'iinc' instruction. 'iinc' instructions are expanded to 'iload; bipush; iadd; istore' during decoding and reassembled during compilation. There are no 'jsr' or 'ret' instructions. Bytecode subroutines are expanded inline during decoding. There are no 'ifeq', 'ifne', 'ifgt', 'ifge', 'iflt', 'ifle' instructions. These instructions are expanded to 'bipush 0; if_icmp' during decoding and reassembled during compilation. There are no 'ifnull' or 'ifnonnull' instructions. These instructions are expanded to 'aconst_null; if_acmp' during decoding and reassembled during compilation. All Java values, including longs and doubles, occupy just one word on the stack. Places where the JVM assumes differently are fixed up during compilation. However, longs and double still take up two local variable slots (this usually doesn't matter to instrumentation). Control transfer instructions refer to target instructions using integers. These integers are usually indices into an array of instructions.


Nested Class Summary
static class Instruction.Visitor
          This class is used by Instruction.visit to dispatch based on the instruction type.
 
Field Summary
 
Fields inherited from interface com.ibm.wala.shrikeBT.Constants
ACC_ABSTRACT, ACC_FINAL, ACC_INTERFACE, ACC_NATIVE, ACC_PRIVATE, ACC_PROTECTED, ACC_PUBLIC, ACC_STATIC, ACC_STRICT, ACC_SUPER, ACC_SYNCHRONIZED, ACC_TRANSIENT, ACC_VOLATILE, CONSTANT_Class, CONSTANT_Double, CONSTANT_FieldRef, CONSTANT_Float, CONSTANT_Integer, CONSTANT_InterfaceMethodRef, CONSTANT_Long, CONSTANT_MethodRef, CONSTANT_NameAndType, CONSTANT_String, CONSTANT_Utf8, indexedTypes, indexedTypes_T, MAYBE, NO, OP_aaload, OP_aastore, OP_aconst_null, OP_aload, OP_aload_0, OP_aload_1, OP_aload_2, OP_aload_3, OP_anewarray, OP_areturn, OP_arraylength, OP_astore, OP_astore_0, OP_astore_1, OP_astore_2, OP_astore_3, OP_athrow, OP_baload, OP_bastore, OP_bipush, OP_caload, OP_castore, OP_checkcast, OP_d2f, OP_d2i, OP_d2l, OP_dadd, OP_daload, OP_dastore, OP_dcmpg, OP_dcmpl, OP_dconst_0, OP_dconst_1, OP_ddiv, OP_dload, OP_dload_0, OP_dload_1, OP_dload_2, OP_dload_3, OP_dmul, OP_dneg, OP_drem, OP_dreturn, OP_dstore, OP_dstore_0, OP_dstore_1, OP_dstore_2, OP_dstore_3, OP_dsub, OP_dup, OP_dup_x1, OP_dup_x2, OP_dup2, OP_dup2_x1, OP_dup2_x2, OP_f2d, OP_f2i, OP_f2l, OP_fadd, OP_faload, OP_fastore, OP_fcmpg, OP_fcmpl, OP_fconst_0, OP_fconst_1, OP_fconst_2, OP_fdiv, OP_fload, OP_fload_0, OP_fload_1, OP_fload_2, OP_fload_3, OP_fmul, OP_fneg, OP_frem, OP_freturn, OP_fstore, OP_fstore_0, OP_fstore_1, OP_fstore_2, OP_fstore_3, OP_fsub, OP_getfield, OP_getstatic, OP_goto, OP_goto_w, OP_i2b, OP_i2c, OP_i2d, OP_i2f, OP_i2l, OP_i2s, OP_iadd, OP_iaload, OP_iand, OP_iastore, OP_iconst_0, OP_iconst_1, OP_iconst_2, OP_iconst_3, OP_iconst_4, OP_iconst_5, OP_iconst_m1, OP_idiv, OP_if_acmpeq, OP_if_acmpne, OP_if_icmpeq, OP_if_icmpge, OP_if_icmpgt, OP_if_icmple, OP_if_icmplt, OP_if_icmpne, OP_ifeq, OP_ifge, OP_ifgt, OP_ifle, OP_iflt, OP_ifne, OP_ifnonnull, OP_ifnull, OP_iinc, OP_iload, OP_iload_0, OP_iload_1, OP_iload_2, OP_iload_3, OP_imul, OP_ineg, OP_instanceof, OP_invokeinterface, OP_invokespecial, OP_invokestatic, OP_invokevirtual, OP_ior, OP_irem, OP_ireturn, OP_ishl, OP_ishr, OP_istore, OP_istore_0, OP_istore_1, OP_istore_2, OP_istore_3, OP_isub, OP_iushr, OP_ixor, OP_jsr, OP_jsr_w, OP_l2d, OP_l2f, OP_l2i, OP_ladd, OP_laload, OP_land, OP_lastore, OP_lcmp, OP_lconst_0, OP_lconst_1, OP_ldc, OP_ldc_w, OP_ldc2_w, OP_ldiv, OP_lload, OP_lload_0, OP_lload_1, OP_lload_2, OP_lload_3, OP_lmul, OP_lneg, OP_lookupswitch, OP_lor, OP_lrem, OP_lreturn, OP_lshl, OP_lshr, OP_lstore, OP_lstore_0, OP_lstore_1, OP_lstore_2, OP_lstore_3, OP_lsub, OP_lushr, OP_lxor, OP_monitorenter, OP_monitorexit, OP_multianewarray, OP_new, OP_newarray, OP_nop, OP_pop, OP_pop2, OP_putfield, OP_putstatic, OP_ret, OP_return, OP_saload, OP_sastore, OP_sipush, OP_swap, OP_tableswitch, OP_wide, OP_xxxunusedxxx, T_BOOLEAN, T_BYTE, T_CHAR, T_DOUBLE, T_FLOAT, T_INT, T_LONG, T_SHORT, TYPE_boolean, TYPE_boolean_index, TYPE_byte, TYPE_byte_index, TYPE_char, TYPE_char_index, TYPE_Class, TYPE_double, TYPE_double_index, TYPE_Error, TYPE_Exception, TYPE_float, TYPE_float_index, TYPE_int, TYPE_int_index, TYPE_long, TYPE_long_index, TYPE_null, TYPE_Object, TYPE_Object_index, TYPE_RuntimeException, TYPE_short, TYPE_short_index, TYPE_String, TYPE_Throwable, TYPE_unknown, TYPE_void, YES
 
Method Summary
 java.lang.Object clone()
          We're immutable so there's no need to clone any Instruction object.
 int[] getBranchTargets()
           
 short getOpcode()
           
 int getPoppedCount()
           
 java.lang.String getPushedType(java.lang.String[] poppedTypesToCheck)
          Computes the type of data pushed onto the stack, or null if none is pushed.
 byte getPushedWordSize()
           
 boolean isFallThrough()
           
 Instruction redirectTargets(int[] targetMap)
           
abstract  java.lang.String toString()
          Subclasses must implement toString.
abstract  void visit(Instruction.Visitor v)
          Apply a Visitor to this instruction.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.ibm.wala.shrikeBT.IInstruction
isPEI
 

Method Detail

isFallThrough

public boolean isFallThrough()
Returns:
true if the instruction can "fall through" to the following instruction

getBranchTargets

public int[] getBranchTargets()
Returns:
an array containing the labels this instruction can branch to (not including the following instruction if this instruction 'falls through')

redirectTargets

public Instruction redirectTargets(int[] targetMap)
Returns:
an Instruction equivalent to this one but with any branch labels updated by looking them up in the targetMap array

getPoppedCount

public int getPoppedCount()
Returns:
the number of values this instruction pops off the working stack

getOpcode

public final short getOpcode()
Returns:
the opcode selected for this instruction, or -1 if we don't know it yet

getPushedType

public java.lang.String getPushedType(java.lang.String[] poppedTypesToCheck)
Computes the type of data pushed onto the stack, or null if none is pushed.

Parameters:
poppedTypesToCheck - the types of the data popped off the stack by this instruction; if poppedTypes is null, then we don't know the incoming stack types and the result of this method may be less accurate

getPushedWordSize

public byte getPushedWordSize()
Returns:
the JVM word size of the value this instruction pushes onto the stack, or 0 if this instruction doesn't push anything onto the stack.

visit

public abstract void visit(Instruction.Visitor v)
Apply a Visitor to this instruction. We invoke the appropriate Visitor method according to the type of this instruction.


toString

public abstract java.lang.String toString()
Subclasses must implement toString.

Overrides:
toString in class java.lang.Object

clone

public final java.lang.Object clone()
We're immutable so there's no need to clone any Instruction object.

Overrides:
clone in class java.lang.Object