Package serp.bytecode
Class TableSwitchInstruction
java.lang.Object
serp.bytecode.CodeEntry
serp.bytecode.Instruction
serp.bytecode.JumpInstruction
serp.bytecode.TableSwitchInstruction
- All Implemented Interfaces:
BCEntity
,InstructionPtr
,VisitAcceptor
The
tableswitch
instruction.-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
acceptVisit
(BCVisitor visit) Accept a visit from aBCVisitor
, calling the appropriate methods to notify the visitor that it has entered this entity, and to provide it with the proper callbacks for each sub-entity owned by this one.addTarget
(Instruction target) Add a target to this switch.private Instruction
findTarget
(int jumpByteIndex, List inss) int
Synonymous withJumpInstruction.getOffset()
.Synonymous withJumpInstruction.getTarget()
.int
getHigh()
(package private) int
Return the length in bytes of this opcode, including all arguments.int
getLow()
int[]
Returns the current byte offsets for the different switch cases in this Instruction.int
Return the number of stack positions this instruction pushes or pops during its execution.Return the targets for this switch, or empty array if not set.(package private) void
Read the arguments for this opcode from the given stream.(package private) void
read
(Instruction orig) Copy the given instruction data.void
replaceTarget
(Instruction oldTarget, Instruction newTarget) Replace the given old, likely invalid, target with a new target.setDefaultOffset
(int offset) Synonymous withJumpInstruction.setOffset(int)
.Synonymous withJumpInstruction.setTarget(serp.bytecode.Instruction)
.setHigh
(int high) setLow
(int low) void
setOffsets
(int[] offsets) Sets the offsets for the instructions representing the different switch statement cases.setTargets
(Instruction[] targets) Set the jump points for this switch.void
Use the byte indexes read from the class file to calculate and set references to the target instruction(s) for this ptr.(package private) void
write
(DataOutput out) Write the arguments for this opcode to the given stream.Methods inherited from class serp.bytecode.JumpInstruction
equalsInstruction, getOffset, getTarget, setOffset, setTarget
Methods inherited from class serp.bytecode.Instruction
getByteIndex, getClassLoader, getCode, getLineNumber, getLogicalStackChange, getName, getOpcode, getPool, getProject, invalidate, invalidateByteIndexes, isValid, setOpcode
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface serp.bytecode.InstructionPtr
getCode
-
Field Details
-
_low
private int _low -
_high
private int _high -
_cases
-
-
Constructor Details
-
TableSwitchInstruction
TableSwitchInstruction(Code owner)
-
-
Method Details
-
getOffsets
public int[] getOffsets()Returns the current byte offsets for the different switch cases in this Instruction. -
setOffsets
public void setOffsets(int[] offsets) Sets the offsets for the instructions representing the different switch statement cases. WARNING: these offsets will not be changed in the event that the code is modified following this call. It is typically a good idea to follow this call with a call to updateTargets as soon as the instructions at the given offsets are valid, at which point the Instructions themselves will be used as the targets and the offsets will be updated as expected. -
getLength
int getLength()Description copied from class:Instruction
Return the length in bytes of this opcode, including all arguments. For many opcodes this method relies on an up-to-date byte index.- Overrides:
getLength
in classInstruction
-
getDefaultTarget
Synonymous withJumpInstruction.getTarget()
. -
setDefaultTarget
Synonymous withJumpInstruction.setTarget(serp.bytecode.Instruction)
. -
getDefaultOffset
public int getDefaultOffset()Synonymous withJumpInstruction.getOffset()
. -
setDefaultOffset
Synonymous withJumpInstruction.setOffset(int)
. -
getLow
public int getLow() -
setLow
-
getHigh
public int getHigh() -
setHigh
-
getTargets
Return the targets for this switch, or empty array if not set. -
setTargets
Set the jump points for this switch.- Returns:
- this instruction, for method chaining
-
addTarget
Add a target to this switch.- Returns:
- this instruction, for method chaining
-
getStackChange
public int getStackChange()Description copied from class:Instruction
Return the number of stack positions this instruction pushes or pops during its execution.- Overrides:
getStackChange
in classInstruction
- Returns:
- 0 if the stack is not affected by this instruction, a positive number if it pushes onto the stack, and a negative number if it pops from the stack
-
findTarget
-
updateTargets
public void updateTargets()Description copied from interface:InstructionPtr
Use the byte indexes read from the class file to calculate and set references to the target instruction(s) for this ptr. This method will be called after the byte code has been read in for the first time and before it is written after modification.- Specified by:
updateTargets
in interfaceInstructionPtr
- Overrides:
updateTargets
in classJumpInstruction
-
replaceTarget
Description copied from interface:InstructionPtr
Replace the given old, likely invalid, target with a new target. The new target Instruction is guaranteed to be in the same code block as this InstructionPtr.- Specified by:
replaceTarget
in interfaceInstructionPtr
- Overrides:
replaceTarget
in classJumpInstruction
-
acceptVisit
Description copied from interface:VisitAcceptor
Accept a visit from aBCVisitor
, calling the appropriate methods to notify the visitor that it has entered this entity, and to provide it with the proper callbacks for each sub-entity owned by this one.- Specified by:
acceptVisit
in interfaceVisitAcceptor
- Overrides:
acceptVisit
in classJumpInstruction
-
read
Description copied from class:Instruction
Copy the given instruction data.- Overrides:
read
in classJumpInstruction
-
read
Description copied from class:Instruction
Read the arguments for this opcode from the given stream. This method should be overridden by opcodes that take arguments.- Overrides:
read
in classJumpInstruction
- Throws:
IOException
-
write
Description copied from class:Instruction
Write the arguments for this opcode to the given stream. This method should be overridden by opcodes that take arguments.- Overrides:
write
in classJumpInstruction
- Throws:
IOException
-