Class CodeIterator

java.lang.Object
  |
  +--CodeIterator

class CodeIterator
extends java.lang.Object
implements JVM


Field Summary
(package private)  byte[] code
          the code array
(package private)  int nextIndex
          the index into the 'code' array where the next instruction begins.
(package private)  int opcode
          the current opcode.
(package private)  int opcodeIndex
          the index into the 'code' array where we find the current opcode.
(package private)  int operandIndex
          the index into the 'code' array where we find the first operand.
(package private)  ConstantPool pool
          the constant pool of my class.
(package private)  boolean wide
          a flag telling that the current opcode is wide-modified.
 
Constructor Summary
(package private) CodeIterator(byte[] code, ConstantPool pool)
          make a code iterator that traverses a given array of bytecodes.
 
Method Summary
(package private)  java.lang.String disassemble()
          disassemble the current instruction.
(package private)  int getSignedInteger(int offset, int size)
          get a variable-length signed integer from the code array.
(package private)  int getUnsignedInteger(int offset, int size)
          get a variable-length unsigned integer from the code array.
(package private)  boolean iterate()
          go to the next instruction.
(package private)  CodeIterator makeChild(int target)
          construct a new iterator, starting at the given target index.
(package private)  java.lang.String stringFilter(java.lang.String s)
          get an abbreviated, one-line version of a string without any dangerous characters, suitable for disassembled arguments.
(package private)  boolean toTarget(int target)
          go to a given instruction.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

code

byte[] code
the code array

pool

ConstantPool pool
the constant pool of my class.

wide

boolean wide
a flag telling that the current opcode is wide-modified. The opcode 'op_wide' itself is handled inside the iterator and not shown to the user as an individual instruction.

opcode

int opcode
the current opcode.

opcodeIndex

int opcodeIndex
the index into the 'code' array where we find the current opcode.

operandIndex

int operandIndex
the index into the 'code' array where we find the first operand. For most instructions, this is opcodeIndex+1, except for 'tableswitch' and 'lookupswitch', which contain padding bytes.

nextIndex

int nextIndex
the index into the 'code' array where the next instruction begins.
Constructor Detail

CodeIterator

CodeIterator(byte[] code,
             ConstantPool pool)
make a code iterator that traverses a given array of bytecodes.
Method Detail

iterate

boolean iterate()
go to the next instruction. All fields of the iterator are updated to correctly represent the next instruction. When the end of the code array is reached, the method returns 'false' and the contents of the iterator's fields are invalid.

toTarget

boolean toTarget(int target)
go to a given instruction. All fields of the iterator are updated to correctly represent this target instruction. When the end of the code array is reached, the method returns 'false' and the contents of the iterator's fields are invalid.
Parameters:
target - the index of the target op-code.

makeChild

CodeIterator makeChild(int target)
construct a new iterator, starting at the given target index.
Parameters:
target - the index of the target op-code.

disassemble

java.lang.String disassemble()
disassemble the current instruction.

getUnsignedInteger

int getUnsignedInteger(int offset,
                       int size)
get a variable-length unsigned integer from the code array.
Parameters:
offset - the offset of the integer's first byte from the first operand position of the current instruction.
size - the length of the integer in bytes.
Returns:
the unsigned integer from the code array

getSignedInteger

int getSignedInteger(int offset,
                     int size)
get a variable-length signed integer from the code array.
Parameters:
offset - the offset of the integer's first byte from the first operand position of the current instruction.
size - the length of the integer in bytes.
Returns:
the signed integer from code[index] to code[index+size-1]

stringFilter

java.lang.String stringFilter(java.lang.String s)
get an abbreviated, one-line version of a string without any dangerous characters, suitable for disassembled arguments.