jef.dna.instructions.impl
Class LookupSwitch
java.lang.Object
jef.dna.instructions.impl.InstructionAncestor
jef.dna.instructions.impl.LookupSwitch
- All Implemented Interfaces:
- java.lang.Cloneable, Instruction, BytesCountable
public class LookupSwitch
- extends InstructionAncestor
This class maps the LOOKUPSWITCH
bytecode instruction.
A lookupswitch is a variable-length instruction. Immediately after the lookupswitch opcode,
between zero and three null bytes (zeroed bytes, not the null object) are inserted as padding.
The number of null bytes is chosen so that the defaultbyte1 begins at an address that is a
multiple of four bytes from the start of the current method (the opcode of its first
instruction).
Immediately after the padding follow a series of signed 32-bit values: default, npairs, and then
npairs pairs of signed 32-bit values. The npairs must be greater than or equal to 0. Each of the
npairs pairs consists of an int match and a signed 32-bit offset. Each of these signed 32-bit
values is constructed from four unsigned bytes as (byte1 << 24) | (byte2 << 16) | (byte3 << 8) |
byte4. The table match-offset pairs of the lookupswitch instruction must be sorted in increasing
numerical order by match.
The key must be of type int and is popped from the operand stack. The key is compared against the
match values. If it is equal to one of them, then a target address is calculated by adding the
corresponding offset to the address of the opcode of this lookupswitch instruction.
If the key does not match any of the match values, the target address is calculated by adding
default to the address of the opcode of this lookupswitch instruction. Execution then continues
at the target address. The target address that can be calculated from the offset of each
match-offset pair, as well as the one calculated from default, must be the address of an opcode
of an instruction within the method that contains this lookupswitch instruction.
- Author:
- ggiovanzana
Constructor Summary |
LookupSwitch()
Creates a new instance of LookupSwitch |
Method Summary |
void |
setOperandsCountPosticipated(int[] bytecode,
int startFrom)
This method should be implemented by those classes wrapping JVM instructions whose number of
operands is variable. |
int |
updateRefs(int offset)
This method must implement the logic necessary to update all the references to constant pool
table's entries contained within the bytecode instruction. |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
LookupSwitch
public LookupSwitch()
- Creates a new instance of LookupSwitch
setOperandsCountPosticipated
public void setOperandsCountPosticipated(int[] bytecode,
int startFrom)
- This method should be implemented by those classes wrapping JVM instructions whose number of
operands is variable. This method is called by the
fromArray
method defined in
the InstructionAncestor
class. InstructionAncestor
already
contains an empty implementation of this method, useful for those classes exposing a prefixed
number of operands. In such a case there is no need to override the
setOperandsCountPosticipated
method,
- Specified by:
setOperandsCountPosticipated
in interface Instruction
- Overrides:
setOperandsCountPosticipated
in class InstructionAncestor
- Parameters:
bytecode
- The method's bytecodestartFrom
- The index of the current instruction's mnemonic (opcode)
updateRefs
public int updateRefs(int offset)
- This method must implement the logic necessary to update all the references to constant pool
table's entries contained within the bytecode instruction.
- Specified by:
updateRefs
in interface Instruction
- Overrides:
updateRefs
in class InstructionAncestor
- Parameters:
offset
- The offset used for updating expressed as number of cpt's entries to be skipped
- Returns:
- int The number of processed words within the current bytecode instruction