Class BytecodeStream
java.lang.Object
com.ibm.wala.core.util.bytecode.BytecodeStream
- All Implemented Interfaces:
BytecodeConstants
Provides minimal abstraction layer to a stream of bytecodes from the code attribute of a method.
-
Field Summary
Fields inherited from interface com.ibm.wala.shrike.shrikeBT.BytecodeConstants
JBC_aaload, JBC_aastore, JBC_aconst_null, JBC_aload, JBC_aload_0, JBC_aload_1, JBC_aload_2, JBC_aload_3, JBC_anewarray, JBC_areturn, JBC_arraylength, JBC_astore, JBC_astore_0, JBC_astore_1, JBC_astore_2, JBC_astore_3, JBC_athrow, JBC_baload, JBC_bastore, JBC_bipush, JBC_caload, JBC_castore, JBC_checkcast, JBC_d2f, JBC_d2i, JBC_d2l, JBC_dadd, JBC_daload, JBC_dastore, JBC_dcmpg, JBC_dcmpl, JBC_dconst_0, JBC_dconst_1, JBC_ddiv, JBC_dload, JBC_dload_0, JBC_dload_1, JBC_dload_2, JBC_dload_3, JBC_dmul, JBC_dneg, JBC_drem, JBC_dreturn, JBC_dstore, JBC_dstore_0, JBC_dstore_1, JBC_dstore_2, JBC_dstore_3, JBC_dsub, JBC_dup, JBC_dup_x1, JBC_dup_x2, JBC_dup2, JBC_dup2_x1, JBC_dup2_x2, JBC_f2d, JBC_f2i, JBC_f2l, JBC_fadd, JBC_faload, JBC_fastore, JBC_fcmpg, JBC_fcmpl, JBC_fconst_0, JBC_fconst_1, JBC_fconst_2, JBC_fdiv, JBC_fload, JBC_fload_0, JBC_fload_1, JBC_fload_2, JBC_fload_3, JBC_fmul, JBC_fneg, JBC_frem, JBC_freturn, JBC_fstore, JBC_fstore_0, JBC_fstore_1, JBC_fstore_2, JBC_fstore_3, JBC_fsub, JBC_getfield, JBC_getstatic, JBC_goto, JBC_goto_w, JBC_i2d, JBC_i2f, JBC_i2l, JBC_iadd, JBC_iaload, JBC_iand, JBC_iastore, JBC_iconst_0, JBC_iconst_1, JBC_iconst_2, JBC_iconst_3, JBC_iconst_4, JBC_iconst_5, JBC_iconst_m1, JBC_idiv, JBC_if_acmpeq, JBC_if_acmpne, JBC_if_icmpeq, JBC_if_icmpge, JBC_if_icmpgt, JBC_if_icmple, JBC_if_icmplt, JBC_if_icmpne, JBC_ifeq, JBC_ifge, JBC_ifgt, JBC_ifle, JBC_iflt, JBC_ifne, JBC_ifnonnull, JBC_ifnull, JBC_iinc, JBC_iload, JBC_iload_0, JBC_iload_1, JBC_iload_2, JBC_iload_3, JBC_impdep1, JBC_impdep2, JBC_imul, JBC_ineg, JBC_instanceof, JBC_int2byte, JBC_int2char, JBC_int2short, JBC_invokeinterface, JBC_invokespecial, JBC_invokestatic, JBC_invokevirtual, JBC_ior, JBC_irem, JBC_ireturn, JBC_ishl, JBC_ishr, JBC_istore, JBC_istore_0, JBC_istore_1, JBC_istore_2, JBC_istore_3, JBC_isub, JBC_iushr, JBC_ixor, JBC_jsr, JBC_jsr_w, JBC_l2d, JBC_l2f, JBC_l2i, JBC_ladd, JBC_laload, JBC_land, JBC_lastore, JBC_lcmp, JBC_lconst_0, JBC_lconst_1, JBC_ldc, JBC_ldc_w, JBC_ldc2_w, JBC_ldiv, JBC_length, JBC_lload, JBC_lload_0, JBC_lload_1, JBC_lload_2, JBC_lload_3, JBC_lmul, JBC_lneg, JBC_lookupswitch, JBC_lor, JBC_lrem, JBC_lreturn, JBC_lshl, JBC_lshr, JBC_lstore, JBC_lstore_0, JBC_lstore_1, JBC_lstore_2, JBC_lstore_3, JBC_lsub, JBC_lushr, JBC_lxor, JBC_monitorenter, JBC_monitorexit, JBC_multianewarray, JBC_name, JBC_new, JBC_newarray, JBC_nop, JBC_pop, JBC_pop2, JBC_putfield, JBC_putstatic, JBC_ret, JBC_return, JBC_saload, JBC_sastore, JBC_sipush, JBC_swap, JBC_tableswitch, JBC_wide, JBC_xxxunusedxxx
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
Skips the extra stuff after an invokeinterface instruction Used for invokeinterfacefinal void
Skips the padding of a switch instruction Used for tableswitch, lookupswitchfinal int
computeLookupSwitchOffset
(int value, int num) Returns the offset for a given value of the lookupswitch (as a signed int) or 0 if the value is not in the table.final int
computeTableSwitchOffset
(int value, int low, int high) Returns the offset for a given value of the tableswitch (as a signed int) or 0 if the value is out of range.final IClass
Returns the declaring class that this bytecode stream is fromfinal int
Returns the dimension of the array (as an unsigned byte) Used for multianewarrayfinal int
Returns the element type (primitive) of the array (as an unsigned byte) Used for newarrayfinal int
Returns the offset of the branch (as a signed short) Used for if<cond>, ificmp<cond>, ifacmp<cond>, goto, jsrfinal int
Returns a signed byte value Used for bipushfinal int
Returns the constant pool index of a constant (as an unsigned byte) Used for ldcfinal int
Returns the default offset of the switch (as a signed int) Used for tableswitch, lookupswitchfinal int
Returns the highest value of the tableswitch (as a signed int) Used for tableswitchfinal int
Returns an increment value (as a signed byte) Used for iincfinal int
Returns the number of the local (as an unsigned byte) Used for iload, lload, fload, dload, aload, istore, lstore, fstore, dstore, astore, iinc, retfinal int
getLookupSwitchOffset
(int num) Returns the numbered offset of the lookupswitch (as a signed int) Used for lookupswitch The "cursor" has to be positioned at the start of the pair table NOTE: Will NOT advance cursorfinal int
getLookupSwitchValue
(int num) Returns the numbered value of the lookupswitch (as a signed int) Used for lookupswitch The "cursor" has to be positioned at the start of the pair table NOTE: Will NOT advance cursorfinal int
Returns the lowest value of the tableswitch (as a signed int) Used for tableswitchfinal int
Returns the opcode of the current instruction in the sequence Note: if skipInstruction has been called, but nextInstruction has not, this method will return the opcode of the skipped instruction!final int
Returns a signed short value Used for sipushfinal int
Returns the number of match-offset pairs in the lookupswitch (as a signed int) Used for lookupswitchfinal int
getTableSwitchOffset
(int num) Returns the numbered offset of the tableswitch (as a signed int) Used for tableswitch The "cursor" has to be positioned at the start of the offset table NOTE: Will NOT advance cursorfinal int
Returns the wide offset of the branch (as a signed int) Used for goto_w, jsr_wfinal int
Returns the wide constant pool index of a constant (as an unsigned short) Used for ldc_w, ldc2_wfinal int
Returns an increment value (as a signed short) Used for iinc prefixed by widefinal int
Returns the wide number of the local (as an unsigned short) Used for iload, lload, fload, dload, aload, istore, lstore, fstore, dstore, astore, iinc prefixed by widefinal int
Returns the opcode of the wide instruction Used for wide Can be one of iload, lload, fload, dload, aload, istore, lstore, fstore, dstore, astore, iincfinal boolean
Does the stream have more bytecodes in it?final int
index()
Returns the current bytecode indexfinal boolean
isWide()
Are we currently processing a wide instruction?final int
length()
Returns the length of the bytecode stream Returns 0 if the method doesn't have any bytecodes (i.e.final IMethod
method()
Returns the method that this bytecode stream is fromfinal int
Sets up the next instruction in the sequencefinal int
Returns the opcode of the next instruction in the sequence without advancing to itfinal void
reset()
Resets the stream to the beginningfinal void
reset
(int index) Resets the stream to a given position Use with cautionfinal void
Skips the current instructionfinal void
skipInstruction
(int opc, boolean w) Skips the current instruction (without using the opcode field) A slightly optimized version of skipInstruction()final void
skipLookupSwitchPairs
(int num) Skips the match-offset pairs of a lookupswitch instruction Used for lookupswitchfinal void
skipTableSwitchOffsets
(int num) Skips the offsets of a tableswitch instruction Used for tableswitch
-
Constructor Details
-
BytecodeStream
- Parameters:
m
- the method containing the bytecodesbc
- the array of bytecodes- Throws:
IllegalArgumentException
- if bc is nullIllegalArgumentException
- if m is null
-
-
Method Details
-
method
Returns the method that this bytecode stream is from -
declaringClass
Returns the declaring class that this bytecode stream is from -
length
public final int length()Returns the length of the bytecode stream Returns 0 if the method doesn't have any bytecodes (i.e. is abstract or native) -
index
public final int index()Returns the current bytecode index -
reset
public final void reset()Resets the stream to the beginning -
reset
public final void reset(int index) Resets the stream to a given position Use with caution- Parameters:
index
- the position to reset the stream to
-
hasMoreBytecodes
public final boolean hasMoreBytecodes()Does the stream have more bytecodes in it? -
peekNextOpcode
public final int peekNextOpcode()Returns the opcode of the next instruction in the sequence without advancing to it- Returns:
- the opcode of the next instruction
- See Also:
-
nextInstruction
public final int nextInstruction()Sets up the next instruction in the sequence- Returns:
- the opcode of the next instruction
- See Also:
-
getOpcode
public final int getOpcode()Returns the opcode of the current instruction in the sequence Note: if skipInstruction has been called, but nextInstruction has not, this method will return the opcode of the skipped instruction!- Returns:
- the opcode of the current instruction
- See Also:
-
isWide
public final boolean isWide()Are we currently processing a wide instruction?- Returns:
- true if current instruction is wide
- See Also:
-
skipInstruction
public final void skipInstruction()Skips the current instruction- See Also:
-
skipInstruction
public final void skipInstruction(int opc, boolean w) Skips the current instruction (without using the opcode field) A slightly optimized version of skipInstruction()- Parameters:
opc
- current opcodew
- whether current instruction follows wide- See Also:
-
getByteValue
public final int getByteValue()Returns a signed byte value Used for bipush- Returns:
- signed byte value
-
getShortValue
public final int getShortValue()Returns a signed short value Used for sipush- Returns:
- signed short value
-
getLocalNumber
public final int getLocalNumber()Returns the number of the local (as an unsigned byte) Used for iload, lload, fload, dload, aload, istore, lstore, fstore, dstore, astore, iinc, ret- Returns:
- local number
- See Also:
-
getWideLocalNumber
public final int getWideLocalNumber()Returns the wide number of the local (as an unsigned short) Used for iload, lload, fload, dload, aload, istore, lstore, fstore, dstore, astore, iinc prefixed by wide- Returns:
- wide local number
- See Also:
-
getIncrement
public final int getIncrement()Returns an increment value (as a signed byte) Used for iinc- Returns:
- increment
- See Also:
-
getWideIncrement
public final int getWideIncrement()Returns an increment value (as a signed short) Used for iinc prefixed by wide- Returns:
- wide increment
- See Also:
-
getBranchOffset
public final int getBranchOffset()Returns the offset of the branch (as a signed short) Used for if<cond>, ificmp<cond>, ifacmp<cond>, goto, jsr- Returns:
- branch offset
- See Also:
-
getWideBranchOffset
public final int getWideBranchOffset()Returns the wide offset of the branch (as a signed int) Used for goto_w, jsr_w- Returns:
- wide branch offset
- See Also:
-
alignSwitch
public final void alignSwitch()Skips the padding of a switch instruction Used for tableswitch, lookupswitch -
getDefaultSwitchOffset
public final int getDefaultSwitchOffset()Returns the default offset of the switch (as a signed int) Used for tableswitch, lookupswitch- Returns:
- default switch offset
-
getLowSwitchValue
public final int getLowSwitchValue()Returns the lowest value of the tableswitch (as a signed int) Used for tableswitch- Returns:
- lowest switch value
- See Also:
-
getHighSwitchValue
public final int getHighSwitchValue()Returns the highest value of the tableswitch (as a signed int) Used for tableswitch- Returns:
- highest switch value
- See Also:
-
skipTableSwitchOffsets
public final void skipTableSwitchOffsets(int num) Skips the offsets of a tableswitch instruction Used for tableswitch- Parameters:
num
- the number of offsets to skip- See Also:
-
getTableSwitchOffset
public final int getTableSwitchOffset(int num) Returns the numbered offset of the tableswitch (as a signed int) Used for tableswitch The "cursor" has to be positioned at the start of the offset table NOTE: Will NOT advance cursor- Parameters:
num
- the number of the offset to retrieve- Returns:
- switch offset
-
computeTableSwitchOffset
public final int computeTableSwitchOffset(int value, int low, int high) Returns the offset for a given value of the tableswitch (as a signed int) or 0 if the value is out of range. Used for tableswitch The "cursor" has to be positioned at the start of the offset table NOTE: Will NOT advance cursor- Parameters:
value
- the value to retrieve offset forlow
- the lowest value of the tableswitchhigh
- the highest value of the tableswitch- Returns:
- switch offset
-
getSwitchLength
public final int getSwitchLength()Returns the number of match-offset pairs in the lookupswitch (as a signed int) Used for lookupswitch- Returns:
- number of switch pairs
-
skipLookupSwitchPairs
public final void skipLookupSwitchPairs(int num) Skips the match-offset pairs of a lookupswitch instruction Used for lookupswitch- Parameters:
num
- the number of match-offset pairs to skip- See Also:
-
getLookupSwitchOffset
public final int getLookupSwitchOffset(int num) Returns the numbered offset of the lookupswitch (as a signed int) Used for lookupswitch The "cursor" has to be positioned at the start of the pair table NOTE: Will NOT advance cursor- Parameters:
num
- the number of the offset to retrieve- Returns:
- switch offset
- See Also:
-
getLookupSwitchValue
public final int getLookupSwitchValue(int num) Returns the numbered value of the lookupswitch (as a signed int) Used for lookupswitch The "cursor" has to be positioned at the start of the pair table NOTE: Will NOT advance cursor- Parameters:
num
- the number of the value to retrieve- Returns:
- switch value
- See Also:
-
computeLookupSwitchOffset
public final int computeLookupSwitchOffset(int value, int num) Returns the offset for a given value of the lookupswitch (as a signed int) or 0 if the value is not in the table. Used for lookupswitch The "cursor" has to be positioned at the start of the offset table NOTE: Will NOT advance cursor WARNING: Uses LINEAR search. Whoever has time on their hands can re-implement this as a binary search.- Parameters:
value
- the value to retrieve offset fornum
- the number of match-offset pairs in the lookupswitch- Returns:
- switch offset
-
alignInvokeInterface
public final void alignInvokeInterface()Skips the extra stuff after an invokeinterface instruction Used for invokeinterface -
getArrayElementType
public final int getArrayElementType()Returns the element type (primitive) of the array (as an unsigned byte) Used for newarray- Returns:
- array element type
-
getArrayDimension
public final int getArrayDimension()Returns the dimension of the array (as an unsigned byte) Used for multianewarray- Returns:
- array dimension
-
getWideOpcode
public final int getWideOpcode()Returns the opcode of the wide instruction Used for wide Can be one of iload, lload, fload, dload, aload, istore, lstore, fstore, dstore, astore, iinc- Returns:
- the opcode of the wide instruction
-
getConstantIndex
public final int getConstantIndex()Returns the constant pool index of a constant (as an unsigned byte) Used for ldc- Returns:
- constant index
- See Also:
-
getWideConstantIndex
public final int getWideConstantIndex()Returns the wide constant pool index of a constant (as an unsigned short) Used for ldc_w, ldc2_w- Returns:
- wide constant index
- See Also:
-