To directly read or edit a bytecode sequence, call byteAt(int), s16bitAt(int),
writeByte(int, int), write16bit(int, int), and other methods.
For example, if method refers to a CtMethod object,
the following code substitutes the NOP instruction for the first
instruction of the method:
CodeAttribute ca = method.getMethodInfo().getCodeAttribute(); CodeIterator ci = ca.iterator(); ci.writeByte(Opcode.NOP, 0);
To visit every instruction, call next() on a CodeIterator.
It returns the index of the first byte of the next instruction.
If there are multiple CodeIterators referring to the
same Code_attribute, then inserting a gap by one
CodeIterator will break the other
CodeIterator.
This iterator does not provide remove().
If a piece of code in a Code_attribute is unnecessary,
it should be overwritten with NOP.
CodeAttribute#iterator()
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | |
| pack-priv abstract static class | |
| pack-priv abstract static class | |
| public static class | CodeIterator.
An inserted gap. |
| pack-priv static class | |
| pack-priv static class | |
| pack-priv static class | |
| pack-priv static class | |
| pack-priv static class | |
| pack-priv static class | |
| pack-priv abstract static class | |
| pack-priv static class |
| Modifier and Type | Field and Description |
|---|---|
| protected byte[] | |
| protected CodeAttribute | |
| protected int | |
| protected int | |
| protected int | |
| protected int | |
| private static final int[] |
| Access | Constructor and Description |
|---|---|
| protected |
| Modifier and Type | Method and Description |
|---|---|
| private static void | |
| public int | Returns: the position of the first byte of the appended bytecode.the bytecode appended. code)Appends the given bytecode sequence at the end. |
| public void | append(ExceptionTable et, int
the value added to the code positions included
in the entries. offset)Copies and appends the entries in the given exception table at the end of the exception table in the code attribute edited by this object. |
| public void | |
| public void | |
| public int | |
| pack-priv static byte[] | |
| private static int | |
| public CodeAttribute | |
| public int | |
| public int | Returns: the index of the position.Gets the index of the position of the mark set by
|
| public int | Returns: the index of the position.Gets the index of the position of the mark set by
|
| public boolean | |
| public int | Returns: the index indicating the first byte of the inserted byte sequence.inserted bytecode sequence. code)Inserts the given bytecode sequence
before the next instruction that would be returned by
|
| public void | insert(int
the index at which a byte sequence is inserted. pos, byte[] inserted bytecode sequence. code)Inserts the given bytecode sequence
before the instruction at the given index |
| public void | insert(ExceptionTable et, int
the value added to the code positions included
in the entries. offset)Copies and inserts the entries in the given exception table at the beginning of the exception table in the code attribute edited by this object. |
| private int | Returns: the index indicating the first byte of the inserted byte sequence.
|
| public int | Returns: the index indicating the first byte of the inserted byte sequence, which might be different from pos.the index at which a byte sequence is inserted. pos, byte[] inserted bytecode sequence. code)Inserts the given bytecode sequence
before the instruction at the given index |
| public int | Returns: the index indicating the first byte of the inserted byte sequence.inserted bytecode sequence. code)Inserts the given bytecode sequence exclusively
before the next instruction that would be returned by
|
| public void | insertEx(int
the index at which a byte sequence is inserted. pos, byte[] inserted bytecode sequence. code)Inserts the given bytecode sequence exclusively
before the instruction at the given index |
| public int | Returns: the index indicating the first byte of the inserted byte sequence, which might be different from pos.the index at which a byte sequence is inserted. pos, byte[] inserted bytecode sequence. code)Inserts the given bytecode sequence exclusively
before the instruction at the given index |
| public int | Returns: the index indicating the first byte of the inserted gap.gap length length)Inserts an exclusive gap
before the next instruction that would be returned by
|
| public int | Returns: the length of the inserted gap. It might be bigger thanlength.the index at which a gap is inserted. pos, int gap length. length)Inserts an exclusive gap in front of the instruction at the given
index |
| public int | Returns: the index indicating the first byte of the inserted gap.gap length length)Inserts a gap
before the next instruction that would be returned by
|
| public int | Returns: the length of the inserted gap. It might be bigger thanlength.the index at which a gap is inserted. pos, int gap length. length)Inserts a gap in front of the instruction at the given
index |
| private static void | |
| private static byte[] | insertGap2w(byte[] code, int where, int gapLength, boolean exclusive, List<CodeIterator.
|
| public CodeIterator. | Returns: the position and the length of the inserted gap.the index at which a gap is inserted. pos, int gap length. length, boolean true if exclusive, otherwise false. exclusive)Inserts an inclusive or exclusive gap in front of the instruction
at the given index |
| pack-priv static byte[] | insertGapCore0(byte[] code, int
It must indicate the first byte of an opcode. where, int gapLength, boolean exclusive, ExceptionTable etable, CodeAttribute ca)insertGapCore0() inserts a gap (some NOPs). |
| private byte[] | insertGapCore0w(byte[] code, int where, int gapLength, boolean exclusive, ExceptionTable etable, CodeAttribute ca, CodeIterator.
|
| private static byte[] | insertGapCore1(byte[] code, int where, int gapLength, boolean exclusive, ExceptionTable etable, CodeAttribute ca)
|
| public int | |
| private static byte[] | |
| private static List | |
| public void | |
| private static int | |
| public int | |
| pack-priv static int | |
| public int | |
| public int | |
| public void | |
| public void | |
| public int | |
| public int | Returns: the index of the INVOKESPECIAL instruction, or -1 if a constructor invocation is not found.Moves to the instruction for
either |
| public int | Returns: the index of the INVOKESPECIAL instruction, or -1 if a super constructor invocation is not found butthis() is found.Moves to the instruction for |
| private int | |
| public int | Returns: the index of the INVOKESPECIAL instruction, or -1 if a explicit constructor invocation is not found butsuper() is found.Moves to the instruction for |
| public int | |
| protected void | updateCursors(int
the position where a gap is inserted. pos, int the length of the gap. length)Is called when a gap is inserted. |
| public void | |
| public void | |
| public void | |
| public void |