Package org.objectweb.asm.tree.analysis
Class Frame<V extends Value>
java.lang.Object
org.objectweb.asm.tree.analysis.Frame<V>
- Type Parameters:
V
- type of the Value used for the analysis.
A symbolic execution stack frame. A stack frame contains a set of local variable slots, and an
operand stack. Warning: long and double values are represented with two slots in local
variables, and with one slot in the operand stack.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final int
The maximum size of the operand stack of any method.private int
The maximum number of elements in the operand stack.private int
The number of local variables of this frame.private int
The number of elements in the operand stack.private V
The expected return type of the analyzed method, or null if the method returns void.private V[]
The local variables and the operand stack of this frame. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Clears the operand stack of this frame.void
execute
(AbstractInsnNode insn, Interpreter<V> interpreter) Simulates the execution of the given instruction on this execution stack frame.private boolean
executeDupX2
(AbstractInsnNode insn, V value1, Interpreter<V> interpreter) private void
executeInvokeInsn
(AbstractInsnNode insn, String methodDescriptor, Interpreter<V> interpreter) getLocal
(int index) Returns the value of the given local variable.int
Returns the maximum number of local variables of this frame.int
Returns the maximum number of elements in the operand stack of this frame.getStack
(int index) Returns the value of the given operand stack slot.int
Returns the number of elements in the operand stack of this frame.Copies the state of the given frame into this frame.void
initJumpTarget
(int opcode, LabelNode target) Initializes a frame corresponding to the target or to the successor of a jump instruction.boolean
Merges the given frame into this frame (case of a subroutine).boolean
merge
(Frame<? extends V> frame, Interpreter<V> interpreter) Merges the given frame into this frame.pop()
Pops a value from the operand stack of this frame.void
Pushes a value into the operand stack of this frame.void
Sets the value of the given local variable.void
Sets the expected return type of the analyzed method.void
Sets the value of the given stack slot.toString()
Returns a string representation of this frame.
-
Field Details
-
MAX_STACK_SIZE
private static final int MAX_STACK_SIZEThe maximum size of the operand stack of any method.- See Also:
-
returnValue
The expected return type of the analyzed method, or null if the method returns void. -
values
The local variables and the operand stack of this frame. The firstnumLocals
elements correspond to the local variables. The followingnumStack
elements correspond to the operand stack. Long and double values are represented with two elements in the local variables section, and with one element in the operand stack section. -
numLocals
private int numLocalsThe number of local variables of this frame. Long and double values are represented with two elements. -
numStack
private int numStackThe number of elements in the operand stack. Long and double values are represented with a single element. -
maxStack
private int maxStackThe maximum number of elements in the operand stack. Long and double values are represented with a single element.
-
-
Constructor Details
-
Frame
public Frame(int numLocals, int maxStack) Constructs a new frame with the given size.- Parameters:
numLocals
- the number of local variables of the frame. Long and double values are represented with two elements.maxStack
- the maximum number of elements in the operand stack, or -1 if there is no maximum value. Long and double values are represented with a single element.
-
Frame
Constructs a copy of the given Frame.- Parameters:
frame
- a frame.
-
-
Method Details
-
init
Copies the state of the given frame into this frame.- Parameters:
frame
- a frame.- Returns:
- this frame.
-
initJumpTarget
Initializes a frame corresponding to the target or to the successor of a jump instruction. This method is called byAnalyzer.analyze(String, org.objectweb.asm.tree.MethodNode)
while interpreting jump instructions. It is called once for each possible target of the jump instruction, and once for its successor instruction (except for GOTO and JSR), before the frame is merged with the existing frame at this location. The default implementation of this method does nothing.Overriding this method and changing the frame values allows implementing branch-sensitive analyses.
- Parameters:
opcode
- the opcode of the jump instruction. Can be IFEQ, IFNE, IFLT, IFGE, IFGT, IFLE, IF_ICMPEQ, IF_ICMPNE, IF_ICMPLT, IF_ICMPGE, IF_ICMPGT, IF_ICMPLE, IF_ACMPEQ, IF_ACMPNE, GOTO, JSR, IFNULL, IFNONNULL, TABLESWITCH or LOOKUPSWITCH.target
- a target of the jump instruction this frame corresponds to, or null if this frame corresponds to the successor of the jump instruction (i.e. the next instruction in the instructions sequence).
-
setReturn
Sets the expected return type of the analyzed method.- Parameters:
v
- the expected return type of the analyzed method, or null if the method returns void.
-
getLocals
public int getLocals()Returns the maximum number of local variables of this frame. Long and double values are represented with two variables.- Returns:
- the maximum number of local variables of this frame.
-
getMaxStackSize
public int getMaxStackSize()Returns the maximum number of elements in the operand stack of this frame. Long and double values are represented with a single element.- Returns:
- the maximum number of elements in the operand stack of this frame.
-
getLocal
Returns the value of the given local variable. Long and double values are represented with two variables.- Parameters:
index
- a local variable index.- Returns:
- the value of the given local variable.
- Throws:
IndexOutOfBoundsException
- if the variable does not exist.
-
setLocal
Sets the value of the given local variable. Long and double values are represented with two variables.- Parameters:
index
- a local variable index.value
- the new value of this local variable.- Throws:
IndexOutOfBoundsException
- if the variable does not exist.
-
getStackSize
public int getStackSize()Returns the number of elements in the operand stack of this frame. Long and double values are represented with a single element.- Returns:
- the number of elements in the operand stack of this frame.
-
getStack
Returns the value of the given operand stack slot.- Parameters:
index
- the index of an operand stack slot.- Returns:
- the value of the given operand stack slot.
- Throws:
IndexOutOfBoundsException
- if the operand stack slot does not exist.
-
setStack
Sets the value of the given stack slot.- Parameters:
index
- the index of an operand stack slot.value
- the new value of the stack slot.- Throws:
IndexOutOfBoundsException
- if the stack slot does not exist.
-
clearStack
public void clearStack()Clears the operand stack of this frame. -
pop
Pops a value from the operand stack of this frame.- Returns:
- the value that has been popped from the stack.
- Throws:
IndexOutOfBoundsException
- if the operand stack is empty.
-
push
Pushes a value into the operand stack of this frame.- Parameters:
value
- the value that must be pushed into the stack.- Throws:
IndexOutOfBoundsException
- if the operand stack is full.
-
execute
Simulates the execution of the given instruction on this execution stack frame.- Parameters:
insn
- the instruction to execute.interpreter
- the interpreter to use to compute values from other values.- Throws:
AnalyzerException
- if the instruction cannot be executed on this execution frame (e.g. a POP on an empty operand stack).
-
executeDupX2
private boolean executeDupX2(AbstractInsnNode insn, V value1, Interpreter<V> interpreter) throws AnalyzerException - Throws:
AnalyzerException
-
executeInvokeInsn
private void executeInvokeInsn(AbstractInsnNode insn, String methodDescriptor, Interpreter<V> interpreter) throws AnalyzerException - Throws:
AnalyzerException
-
merge
Merges the given frame into this frame.- Parameters:
frame
- a frame. This frame is left unchanged by this method.interpreter
- the interpreter used to merge values.- Returns:
- true if this frame has been changed as a result of the merge operation, or false otherwise.
- Throws:
AnalyzerException
- if the frames have incompatible sizes.
-
merge
Merges the given frame into this frame (case of a subroutine). The operand stacks are not merged, and only the local variables that have not been used by the subroutine are merged.- Parameters:
frame
- a frame. This frame is left unchanged by this method.localsUsed
- the local variables that are read or written by the subroutine. The i-th element is true if and only if the local variable at index i is read or written by the subroutine.- Returns:
- true if this frame has been changed as a result of the merge operation, or false otherwise.
-
toString
Returns a string representation of this frame.
-