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.

public class Frame<V extends Value> extends Object
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.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Frame(int numLocals, int maxStack)
    Constructs a new frame with the given size.
    Frame(Frame<? extends V> frame)
    Constructs a copy of the given Frame.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    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.
    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.
    init(Frame<? extends V> 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
    merge(Frame<? extends V> frame, boolean[] localsUsed)
    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
    push(V value)
    Pushes a value into the operand stack of this frame.
    void
    setLocal(int index, V value)
    Sets the value of the given local variable.
    void
    Sets the expected return type of the analyzed method.
    void
    setStack(int index, V value)
    Sets the value of the given stack slot.
    Returns a string representation of this frame.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • 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

      public Frame(Frame<? extends V> frame)
      Constructs a copy of the given Frame.
      Parameters:
      frame - a frame.
  • Method Details

    • init

      public Frame<V> init(Frame<? extends V> frame)
      Copies the state of the given frame into this frame.
      Parameters:
      frame - a frame.
      Returns:
      this frame.
    • initJumpTarget

      public void initJumpTarget(int opcode, 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 - 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

      public void setReturn(V v)
      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

      public V getLocal(int index)
      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

      public void setLocal(int index, V value)
      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

      public V getStack(int index)
      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

      public void setStack(int index, V value)
      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

      public V 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

      public void push(V value)
      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

      public void execute(AbstractInsnNode insn, Interpreter<V> interpreter) throws AnalyzerException
      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).
    • merge

      public boolean merge(Frame<? extends V> frame, Interpreter<V> interpreter) throws AnalyzerException
      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

      public boolean merge(Frame<? extends V> frame, 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 - 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

      public String toString()
      Returns a string representation of this frame.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this frame.