public final class BytecodeArray
extends java.lang.Object
Code attribute.| Modifier and Type | Class and Description |
|---|---|
static class |
BytecodeArray.BaseVisitor
Base implementation of
BytecodeArray.Visitor, which has empty method
bodies for all methods. |
static interface |
BytecodeArray.Visitor
Instruction visitor interface.
|
| Modifier and Type | Field and Description |
|---|---|
static BytecodeArray.Visitor |
EMPTY_VISITOR
convenient no-op implementation of
BytecodeArray.Visitor |
| Constructor and Description |
|---|
BytecodeArray(ByteArray bytes,
ConstantPool pool)
Constructs an instance.
|
| Modifier and Type | Method and Description |
|---|---|
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.
|
public static final BytecodeArray.Visitor EMPTY_VISITOR
BytecodeArray.Visitorpublic BytecodeArray(ByteArray bytes, ConstantPool pool)
bytes - non-null; underlying bytespool - non-null; constant pool to use when
resolving constant pool indicespublic ByteArray getBytes()
non-null; the byte arraypublic int size()
>= 0; the length of the bytecode arraypublic int byteLength()
Code attribute. The returned value includes the
array size plus four bytes for code_length.>= 4; the total length, in bytespublic void forEach(BytecodeArray.Visitor visitor)
visitor - null-ok; visitor to call back to for
each instructionpublic int[] getInstructionOffsets()
non-null; appropriately constructed bit setBitspublic void processWorkSet(int[] workSet,
BytecodeArray.Visitor visitor)
workSet - non-null; the work set to processvisitor - non-null; visitor to call back to for
each instructionpublic int parseInstruction(int offset,
BytecodeArray.Visitor visitor)
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:
ldc.
E.g., fconst_0, sipush, and
lconst_0 qualify for this treatment.aconst_null becomes ldc of a
"known null."aload_2 becomes aload.goto_w and jsr_w become goto
and jsr (respectively).ldc_w becomes ldc.tableswitch becomes lookupswitch.
int variant opcode, with the type
argument set to indicate the actual type. E.g.,
fadd becomes iadd, but
type is passed as Type.FLOAT in that
case. Similarly, areturn becomes
ireturn. (However, return remains
unchanged.int
variant opcode, with the type argument set to indicate
the actual type. E.g., aload becomes iload,
but type is passed as Type.OBJECT in
that case.i2l, etc.) are left alone
to avoid too much confustion, but their type is
the pushed type. E.g., i2b gets type
Type.INT, and f2d gets type
Type.DOUBLE. Other unaltered opcodes also get
their pushed type. E.g., arraylength gets type
Type.INT.offset - >= 0, < bytes.size(); offset to the start of the
instructionvisitor - null-ok; visitor to call back toCopyright © 2020. All Rights Reserved.