Package serp.bytecode
Class JumpInstruction
- java.lang.Object
-
- serp.bytecode.CodeEntry
-
- serp.bytecode.Instruction
-
- serp.bytecode.JumpInstruction
-
- All Implemented Interfaces:
BCEntity
,InstructionPtr
,VisitAcceptor
- Direct Known Subclasses:
GotoInstruction
,IfInstruction
,LookupSwitchInstruction
,SwitchInstruction
,TableSwitchInstruction
public abstract class JumpInstruction extends Instruction implements InstructionPtr
An instruction that specifies a position in the code block to jump to. Examples includego2, jsr
, etc.
-
-
Constructor Summary
Constructors Constructor Description JumpInstruction(Code owner, int opcode)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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.boolean
equalsInstruction(Instruction other)
JumpInstructions are equal if they represent the same operation and the instruction they jump to is the same, or if the jump Instruction of either is unset.int
getOffset()
Instruction
getTarget()
Get the current target instruction to jump to, if it has been set.(package private) void
read(java.io.DataInput in)
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.void
setOffset(int offset)
JumpInstruction
setTarget(Instruction instruction)
Set the instruction to jump to; the instruction must already be added to the code block.void
updateTargets()
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(java.io.DataOutput out)
Write the arguments for this opcode to the given stream.-
Methods inherited from class serp.bytecode.Instruction
getByteIndex, getClassLoader, getCode, getLength, getLineNumber, getLogicalStackChange, getName, getOpcode, getPool, getProject, getStackChange, 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 Detail
-
_target
private InstructionPtrStrategy _target
-
-
Constructor Detail
-
JumpInstruction
JumpInstruction(Code owner, int opcode)
-
-
Method Detail
-
getTarget
public Instruction getTarget()
Get the current target instruction to jump to, if it has been set.
-
setTarget
public JumpInstruction setTarget(Instruction instruction)
Set the instruction to jump to; the instruction must already be added to the code block.- Returns:
- this instruction, for method chaining
-
equalsInstruction
public boolean equalsInstruction(Instruction other)
JumpInstructions are equal if they represent the same operation and the instruction they jump to is the same, or if the jump Instruction of either is unset.- Overrides:
equalsInstruction
in classInstruction
-
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
-
replaceTarget
public void replaceTarget(Instruction oldTarget, Instruction newTarget)
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
-
acceptVisit
public void acceptVisit(BCVisitor visit)
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 classInstruction
-
read
void read(Instruction orig)
Description copied from class:Instruction
Copy the given instruction data.- Overrides:
read
in classInstruction
-
read
void read(java.io.DataInput in) throws java.io.IOException
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 classInstruction
- Throws:
java.io.IOException
-
write
void write(java.io.DataOutput out) throws java.io.IOException
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 classInstruction
- Throws:
java.io.IOException
-
setOffset
public void setOffset(int offset)
-
getOffset
public int getOffset()
-
-