Top Description Fields Constructors Methods
org.objectweb.asm.tree.analysis

public Class Frame<V extends Value>

extends Object
Class Inheritance
Type Parameters
<V>
type of the Value used for the analysis.
Imports
java.util.ArrayList, .List, org.objectweb.asm.Opcodes, .Type, org.objectweb.asm.tree.AbstractInsnNode, .IincInsnNode, .InvokeDynamicInsnNode, .LabelNode, .MethodInsnNode, .MultiANewArrayInsnNode, .VarInsnNode

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.

Author
Eric Bruneton

Field Summary

Modifier and TypeField and Description
private static final int
MAX_STACK_SIZE

The maximum size of the operand stack of any method.

private int
maxStack

The maximum number of elements in the operand stack.

private int
numLocals

The number of local variables of this frame.

private int
numStack

The number of elements in the operand stack.

private V
returnValue

The expected return type of the analyzed method, or null if the method returns void.

private V[]
values

The local variables and the operand stack of this frame.

Constructor Summary

AccessConstructor and Description
public
Frame(final int
the number of local variables of the frame. Long and double values are represented with two elements.
numLocals
,
final int
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.
maxStack
)

Constructs a new frame with the given size.

public
Frame(final Frame<? extends V>
a frame.
frame
)

Constructs a copy of the given Frame.

Method Summary

Modifier and TypeMethod and Description
public void
clearStack()

Clears the operand stack of this frame.

public void
execute(final AbstractInsnNode
the instruction to execute.
insn
,
final Interpreter<V>
the interpreter to use to compute values from other values.
interpreter
)

Simulates the execution of the given instruction on this execution stack frame.

private boolean
executeDupX2(final AbstractInsnNode insn, final V value1, final Interpreter<V> interpreter)

private void
executeInvokeInsn(final AbstractInsnNode insn, final String methodDescriptor, final Interpreter<V> interpreter)

public V

Returns:

the value of the given local variable.
getLocal
(final int
a local variable index.
index
)

Returns the value of the given local variable.

public int

Returns:

the maximum number of local variables of this frame.
getLocals
()

Returns the maximum number of local variables of this frame.

public int

Returns:

the maximum number of elements in the operand stack of this frame.
getMaxStackSize
()

Returns the maximum number of elements in the operand stack of this frame.

public V

Returns:

the value of the given operand stack slot.
getStack
(final int
the index of an operand stack slot.
index
)

Returns the value of the given operand stack slot.

public int

Returns:

the number of elements in the operand stack of this frame.
getStackSize
()

Returns the number of elements in the operand stack of this frame.

public Frame<V>

Returns:

this frame.
init
(final Frame<? extends V>
a frame.
frame
)

Copies the state of the given frame into this frame.

public void
initJumpTarget(final int
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.
opcode
,
final LabelNode
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).
target
)

Initializes a frame corresponding to the target or to the successor of a jump instruction.

public boolean

Returns:

true if this frame has been changed as a result of the merge operation, or false otherwise.
merge
(final Frame<? extends V>
a frame. This frame is left unchanged by this method.
frame
,
final Interpreter<V>
the interpreter used to merge values.
interpreter
)

Merges the given frame into this frame.

public boolean

Returns:

true if this frame has been changed as a result of the merge operation, or false otherwise.
merge
(final Frame<? extends V>
a frame. This frame is left unchanged by this method.
frame
,
final boolean[]
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.
localsUsed
)

Merges the given frame into this frame (case of a subroutine).

public V

Returns:

the value that has been popped from the stack.
pop
()

Pops a value from the operand stack of this frame.

public void
push(final V
the value that must be pushed into the stack.
value
)

Pushes a value into the operand stack of this frame.

public void
setLocal(final int
a local variable index.
index
,
final V
the new value of this local variable.
value
)

Sets the value of the given local variable.

public void
setReturn(final V
the expected return type of the analyzed method, or null if the method returns void.
v
)

Sets the expected return type of the analyzed method.

public void
setStack(final int
the index of an operand stack slot.
index
,
final V
the new value of the stack slot.
value
)

Sets the value of the given stack slot.

public String

Returns:

a string representation of this frame.
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of this frame.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

MAX_STACK_SIZEback to summary
private static final int MAX_STACK_SIZE

The maximum size of the operand stack of any method.

maxStackback to summary
private int maxStack

The maximum number of elements in the operand stack. Long and double values are represented with a single element.

numLocalsback to summary
private int numLocals

The number of local variables of this frame. Long and double values are represented with two elements.

numStackback to summary
private int numStack

The number of elements in the operand stack. Long and double values are represented with a single element.

returnValueback to summary
private V returnValue

The expected return type of the analyzed method, or null if the method returns void.

valuesback to summary
private V[] values

The local variables and the operand stack of this frame. The first numLocals elements correspond to the local variables. The following numStack 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.

Constructor Detail

Frameback to summary
public Frame(final int numLocals, final int maxStack)

Constructs a new frame with the given size.

Parameters
numLocals:int

the number of local variables of the frame. Long and double values are represented with two elements.

maxStack:int

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.

Annotations
@SuppressWarnings:unchecked
Frameback to summary
public Frame(final Frame<? extends V> frame)

Constructs a copy of the given Frame.

Parameters
frame:Frame<? extends V>

a frame.

Method Detail

clearStackback to summary
public void clearStack()

Clears the operand stack of this frame.

executeback to summary
public void execute(final AbstractInsnNode insn, final Interpreter<V> interpreter) throws AnalyzerException

Simulates the execution of the given instruction on this execution stack frame.

Parameters
insn:AbstractInsnNode

the instruction to execute.

interpreter:Interpreter<V>

the interpreter to use to compute values from other values.

Exceptions
AnalyzerException:
if the instruction cannot be executed on this execution frame (e.g. a POP on an empty operand stack).
executeDupX2back to summary
private boolean executeDupX2(final AbstractInsnNode insn, final V value1, final Interpreter<V> interpreter) throws AnalyzerException
executeInvokeInsnback to summary
private void executeInvokeInsn(final AbstractInsnNode insn, final String methodDescriptor, final Interpreter<V> interpreter) throws AnalyzerException
getLocalback to summary
public V getLocal(final int index)

Returns the value of the given local variable. Long and double values are represented with two variables.

Parameters
index:int

a local variable index.

Returns:V

the value of the given local variable.

Exceptions
IndexOutOfBoundsException:
if the variable does not exist.
getLocalsback to summary
public int getLocals()

Returns the maximum number of local variables of this frame. Long and double values are represented with two variables.

Returns:int

the maximum number of local variables of this frame.

getMaxStackSizeback to summary
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:int

the maximum number of elements in the operand stack of this frame.

getStackback to summary
public V getStack(final int index)

Returns the value of the given operand stack slot.

Parameters
index:int

the index of an operand stack slot.

Returns:V

the value of the given operand stack slot.

Exceptions
IndexOutOfBoundsException:
if the operand stack slot does not exist.
getStackSizeback to summary
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:int

the number of elements in the operand stack of this frame.

initback to summary
public Frame<V> init(final Frame<? extends V> frame)

Copies the state of the given frame into this frame.

Parameters
frame:Frame<? extends V>

a frame.

Returns:Frame<V>

this frame.

initJumpTargetback to summary
public void initJumpTarget(final int opcode, final LabelNode target)

Initializes a frame corresponding to the target or to the successor of a jump instruction. This method is called by Analyzer#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:int

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:LabelNode

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).

mergeback to summary
public boolean merge(final Frame<? extends V> frame, final Interpreter<V> interpreter) throws AnalyzerException

Merges the given frame into this frame.

Parameters
frame:Frame<? extends V>

a frame. This frame is left unchanged by this method.

interpreter:Interpreter<V>

the interpreter used to merge values.

Returns:boolean

true if this frame has been changed as a result of the merge operation, or false otherwise.

Exceptions
AnalyzerException:
if the frames have incompatible sizes.
mergeback to summary
public boolean merge(final Frame<? extends V> frame, final boolean[] localsUsed)

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:Frame<? extends V>

a frame. This frame is left unchanged by this method.

localsUsed:boolean[]

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:boolean

true if this frame has been changed as a result of the merge operation, or false otherwise.

popback to summary
public V pop()

Pops a value from the operand stack of this frame.

Returns:V

the value that has been popped from the stack.

Exceptions
IndexOutOfBoundsException:
if the operand stack is empty.
pushback to summary
public void push(final V value)

Pushes a value into the operand stack of this frame.

Parameters
value:V

the value that must be pushed into the stack.

Annotations
@SuppressWarnings:unchecked
Exceptions
IndexOutOfBoundsException:
if the operand stack is full.
setLocalback to summary
public void setLocal(final int index, final V value)

Sets the value of the given local variable. Long and double values are represented with two variables.

Parameters
index:int

a local variable index.

value:V

the new value of this local variable.

Exceptions
IndexOutOfBoundsException:
if the variable does not exist.
setReturnback to summary
public void setReturn(final V v)

Sets the expected return type of the analyzed method.

Parameters
v:V

the expected return type of the analyzed method, or null if the method returns void.

setStackback to summary
public void setStack(final int index, final V value)

Sets the value of the given stack slot.

Parameters
index:int

the index of an operand stack slot.

value:V

the new value of the stack slot.

Exceptions
IndexOutOfBoundsException:
if the stack slot does not exist.
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of this frame.

Returns:String

a string representation of this frame.

Annotations
@Override