com.android.dx.cf.code
Class BytecodeArray

java.lang.Object
  extended by com.android.dx.cf.code.BytecodeArray

public final class BytecodeArray
extends Object

Bytecode array, which is part of a standard Code attribute.


Nested Class Summary
static class BytecodeArray.BaseVisitor
          Base implementation of BytecodeArray.Visitor, which has empty method bodies for all methods.
static interface BytecodeArray.Visitor
          Instruction visitor interface.
 
Field Summary
static BytecodeArray.Visitor EMPTY_VISITOR
          convenient no-op implementation of BytecodeArray.Visitor
 
Constructor Summary
BytecodeArray(ByteArray bytes, ConstantPool pool)
          Constructs an instance.
 
Method Summary
 int byteLength()
          Gets the total length of this structure in bytes, when included in a Code attribute.
 void forEach(BytecodeArray.Visitor visitor)
          Parses each instruction in the array, in order.
 ByteArray getBytes()
          Gets the underlying byte array.
 int[] getInstructionOffsets()
          Finds the offset to each instruction in the bytecode array.
 int parseInstruction(int offset, BytecodeArray.Visitor visitor)
          Parses the instruction at the indicated offset.
 void processWorkSet(int[] workSet, BytecodeArray.Visitor visitor)
          Processes the given "work set" by repeatedly finding the lowest bit in the set, clearing it, and parsing and visiting the instruction at the indicated offset (that is, the bit index), repeating until the work set is empty.
 int size()
          Gets the size of the bytecode array, per se.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_VISITOR

public static final BytecodeArray.Visitor EMPTY_VISITOR
convenient no-op implementation of BytecodeArray.Visitor

Constructor Detail

BytecodeArray

public BytecodeArray(ByteArray bytes,
                     ConstantPool pool)
Constructs an instance.

Parameters:
bytes - non-null; underlying bytes
pool - non-null; constant pool to use when resolving constant pool indices
Method Detail

getBytes

public ByteArray getBytes()
Gets the underlying byte array.

Returns:
non-null; the byte array

size

public int size()
Gets the size of the bytecode array, per se.

Returns:
>= 0; the length of the bytecode array

byteLength

public int byteLength()
Gets the total length of this structure in bytes, when included in a Code attribute. The returned value includes the array size plus four bytes for code_length.

Returns:
>= 4; the total length, in bytes

forEach

public void forEach(BytecodeArray.Visitor visitor)
Parses each instruction in the array, in order.

Parameters:
visitor - null-ok; visitor to call back to for each instruction

getInstructionOffsets

public int[] getInstructionOffsets()
Finds the offset to each instruction in the bytecode array. The result is a bit set with the offset of each opcode-per-se flipped on.

Returns:
non-null; appropriately constructed bit set
See Also:
Bits

processWorkSet

public void processWorkSet(int[] workSet,
                           BytecodeArray.Visitor visitor)
Processes the given "work set" by repeatedly finding the lowest bit in the set, clearing it, and parsing and visiting the instruction at the indicated offset (that is, the bit index), repeating until the work set is empty. It is expected that the visitor will regularly set new bits in the work set during the process.

Parameters:
workSet - non-null; the work set to process
visitor - non-null; visitor to call back to for each instruction

parseInstruction

public int parseInstruction(int offset,
                            BytecodeArray.Visitor visitor)
Parses the instruction at the indicated offset. Indicate the result by calling the visitor if supplied and by returning the number of bytes consumed by the instruction.

In order to simplify further processing, the opcodes passed to the visitor are canonicalized, altering the opcode to a more universal one and making formerly implicit arguments explicit. In particular:

Parameters:
offset - >= 0, < bytes.size(); offset to the start of the instruction
visitor - null-ok; visitor to call back to
Returns:
the length of the instruction, in bytes


Copyright © 2015. All rights reserved.