Class Frame<ValueType>

java.lang.Object
edu.umd.cs.findbugs.ba.Frame<ValueType>
Direct Known Subclasses:
ConstantFrame, IsNullValueFrame, ResourceValueFrame, TypeFrame, ValueNumberFrame

public abstract class Frame<ValueType> extends Object

Generic class for representing a Java stack frame as a dataflow value. A frame consists of "slots", which represent the local variables and values on the Java operand stack. Slots 0 .. getNumLocals() - 1 represent the local variables. Slots getNumLocals() .. getNumSlots() - 1 represent the Java operand stack.

Frame is parametized by "ValueType", which is the type of value to be stored in the Frame's slots. This type must form a lattice, according to the abstract mergeValues() operation in the corresponding analysis class (which should be derived from FrameDataflowAnalysis). When a Frame is constructed, all of its slots will contain null. The analysis is responsible for initializing created Frames with default values at the appropriate time. Typically, only initEntryFact() will need to do this.

A Frame may have the special "TOP" value. Such frames serve as the identity element for the meet operation operation.

A Frame may have the special "BOTTOM" value. The result of merging any frame with BOTTOM is BOTTOM.

Author:
David Hovemeyer
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    Frame(int numLocals)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
     
    void
    Clear the Java operand stack.
    boolean
     
    void
    Make this Frame exactly the same as the one given as a parameter.
    getArgument(org.apache.bcel.generic.InvokeInstruction ins, org.apache.bcel.generic.ConstantPoolGen cpg, int i, int numArguments)
    Deprecated.
    getArgument(org.apache.bcel.generic.InvokeInstruction ins, org.apache.bcel.generic.ConstantPoolGen cpg, int i, SignatureParser sigParser)
    Get the ith argument passed to given method invocation.
    getArgumentSet(org.apache.bcel.generic.InvokeInstruction invokeInstruction, org.apache.bcel.generic.ConstantPoolGen cpg, DataflowValueChooser<ValueType> chooser)
    Get set of arguments passed to a method invocation which match given predicate.
    int
    getArgumentSlot(int i, int numArguments)
    Get the stack slot that will contain given method argument.
    getInstance(org.apache.bcel.generic.Instruction ins, org.apache.bcel.generic.ConstantPoolGen cpg)
    Get the value corresponding to the object instance used in the given instruction.
    int
    getInstanceSlot(org.apache.bcel.generic.Instruction ins, org.apache.bcel.generic.ConstantPoolGen cpg)
    Get the slot the object instance referred to by given instruction is located in.
    int
    getInstanceStackLocation(org.apache.bcel.generic.Instruction ins, org.apache.bcel.generic.ConstantPoolGen cpg)
    Get the stack location (counting down from top of stack, starting at 0) containing the object instance referred to by given instruction.
    int
     
    int
    getNumArguments(org.apache.bcel.generic.InvokeInstruction ins, org.apache.bcel.generic.ConstantPoolGen cpg)
    Get the number of arguments passed to given method invocation.
    int
    getNumArgumentsIncludingObjectInstance(org.apache.bcel.generic.InvokeInstruction ins, org.apache.bcel.generic.ConstantPoolGen cpg)
    Get the number of arguments passed to given method invocation, including the object instance if the call is to an instance method.
    int
    Get the number of locals.
    int
    Get the number of slots (locals plus stack values).
    getOperand(org.apache.bcel.generic.StackConsumer ins, org.apache.bcel.generic.ConstantPoolGen cpg, int i)
    Get the ith operand used by given instruction.
    int
    Get the depth of the Java operand stack.
    int
    Get a the location in the frame of a value on the operand stack.
    getStackValue(int loc)
    Get a value on the operand stack.
    void
    Get the values on the top of the Java operand stack.
    Get the value on the top of the Java operand stack.
    getValue(int n)
    Get the value at the nth slot.
    boolean
    Return whether or not this object is the special "BOTTOM" value for Frames.
    boolean
    Return whether or not this object the special "TOP" value for Frames.
    boolean
    Is the frame valid (meaning it is not TOP or BOTTOM)?
    Pop a value off of the Java operand stack.
    void
    Push a value onto the Java operand stack.
    boolean
    Return true if this stack frame is the same as the one given as a parameter.
    void
    Make this Frame the special "BOTTOM" value.
    void
    setLastUpdateTimestamp(int lastUpdateTimestamp)
     
    void
    Make this frame the special "TOP" value.
    void
    Set the Frame to be valid (neither TOP nor BOTTOM).
    void
    setValue(int n, ValueType value)
    Set the value at the nth slot.
    Convert to string.
    protected String
    Subclasses may override this if they want to do something special to convert Value objects to Strings.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • Frame

      public Frame(int numLocals)
      Constructor. This version of the constructor is for subclasses for which it is always safe to call getDefaultValue(), even when the object is not fully initialized.
      Parameters:
      numLocals - number of local variable slots in the method
  • Method Details

    • isTop

      public boolean isTop()
      Return whether or not this object the special "TOP" value for Frames. Such Frames are the identity element of the meet operation.
    • setTop

      public void setTop()
      Make this frame the special "TOP" value. Such Frames are the identity element of the meet operation.
    • isBottom

      public boolean isBottom()
      Return whether or not this object is the special "BOTTOM" value for Frames. Such Frames arise when merging two frames of different size.
    • setBottom

      public void setBottom()
      Make this Frame the special "BOTTOM" value. Such Frames arise when merging two frames of different size.
    • setValid

      public void setValid()
      Set the Frame to be valid (neither TOP nor BOTTOM).
    • isValid

      public boolean isValid()
      Is the frame valid (meaning it is not TOP or BOTTOM)?
    • pushValue

      public void pushValue(ValueType value)
      Push a value onto the Java operand stack.
      Parameters:
      value - the ValueType to push
    • popValue

      public ValueType popValue() throws DataflowAnalysisException
      Pop a value off of the Java operand stack.
      Returns:
      the value that was popped
      Throws:
      DataflowAnalysisException - if the Java operand stack is empty
    • getTopValue

      public ValueType getTopValue() throws DataflowAnalysisException
      Get the value on the top of the Java operand stack.
      Throws:
      DataflowAnalysisException - if the Java operand stack is empty
    • getTopStackWords

      public void getTopStackWords(ValueType[] valueList) throws DataflowAnalysisException
      Get the values on the top of the Java operand stack. The top stack item is placed at the end of the array, so that to restore the values to the stack, you would push them in the order they appear in the array.
      Throws:
      DataflowAnalysisException
    • getStackValue

      public ValueType getStackValue(int loc) throws DataflowAnalysisException
      Get a value on the operand stack.
      Parameters:
      loc - the stack location, counting downwards from the top (location 0)
      Throws:
      DataflowAnalysisException
    • getStackLocation

      public int getStackLocation(int loc) throws DataflowAnalysisException
      Get a the location in the frame of a value on the operand stack.
      Parameters:
      loc - the stack location, counting downwards from the top (location 0)
      Throws:
      DataflowAnalysisException
    • getInstance

      public ValueType getInstance(org.apache.bcel.generic.Instruction ins, org.apache.bcel.generic.ConstantPoolGen cpg) throws DataflowAnalysisException
      Get the value corresponding to the object instance used in the given instruction. This relies on the observation that in instructions which use an object instance (such as getfield, invokevirtual, etc.), the object instance is the first operand used by the instruction.
      Parameters:
      ins - the instruction
      cpg - the ConstantPoolGen for the method
      Throws:
      DataflowAnalysisException
    • getInstanceStackLocation

      public int getInstanceStackLocation(org.apache.bcel.generic.Instruction ins, org.apache.bcel.generic.ConstantPoolGen cpg) throws DataflowAnalysisException
      Get the stack location (counting down from top of stack, starting at 0) containing the object instance referred to by given instruction. This relies on the observation that in instructions which use an object instance (such as getfield, invokevirtual, etc.), the object instance is the first operand used by the instruction.

      The value returned may be passed to getStackValue(int).

      Parameters:
      ins - the Instruction
      cpg - the ConstantPoolGen for the method
      Returns:
      stack location (counting down from top of stack, starting at 0) containing the object instance
      Throws:
      DataflowAnalysisException
    • getInstanceSlot

      public int getInstanceSlot(org.apache.bcel.generic.Instruction ins, org.apache.bcel.generic.ConstantPoolGen cpg) throws DataflowAnalysisException
      Get the slot the object instance referred to by given instruction is located in.
      Parameters:
      ins - the Instruction
      cpg - the ConstantPoolGen for the method
      Returns:
      stack slot the object instance is in
      Throws:
      DataflowAnalysisException
    • getNumArguments

      public int getNumArguments(org.apache.bcel.generic.InvokeInstruction ins, org.apache.bcel.generic.ConstantPoolGen cpg)
      Get the number of arguments passed to given method invocation.
      Parameters:
      ins - the method invocation instruction
      cpg - the ConstantPoolGen for the class containing the method
      Returns:
      number of arguments; note that this excludes the object instance for instance methods
    • getNumArgumentsIncludingObjectInstance

      public int getNumArgumentsIncludingObjectInstance(org.apache.bcel.generic.InvokeInstruction ins, org.apache.bcel.generic.ConstantPoolGen cpg) throws DataflowAnalysisException
      Get the number of arguments passed to given method invocation, including the object instance if the call is to an instance method.
      Parameters:
      ins - the method invocation instruction
      cpg - the ConstantPoolGen for the class containing the method
      Returns:
      number of arguments, including object instance if appropriate
      Throws:
      DataflowAnalysisException
    • getArgument

      @Deprecated public ValueType getArgument(org.apache.bcel.generic.InvokeInstruction ins, org.apache.bcel.generic.ConstantPoolGen cpg, int i, int numArguments) throws DataflowAnalysisException
      Deprecated.
      Get the ith argument passed to given method invocation.
      Parameters:
      ins - the method invocation instruction
      cpg - the ConstantPoolGen for the class containing the method
      i - index of the argument; 0 for the first argument, etc.
      numArguments - total number of arguments to the method
      Returns:
      the ith argument
      Throws:
      DataflowAnalysisException
    • getArgument

      public ValueType getArgument(org.apache.bcel.generic.InvokeInstruction ins, org.apache.bcel.generic.ConstantPoolGen cpg, int i, SignatureParser sigParser) throws DataflowAnalysisException
      Get the ith argument passed to given method invocation.
      Parameters:
      ins - the method invocation instruction
      cpg - the ConstantPoolGen for the class containing the method
      i - index of the argument; 0 for the first argument, etc.
      Returns:
      the ith argument
      Throws:
      DataflowAnalysisException
    • getArgumentSlot

      public int getArgumentSlot(int i, int numArguments)
      Get the stack slot that will contain given method argument. Assumes that this frame is at the location (just before) a method invocation instruction.
      Parameters:
      i - the argument index: 0 for first arg, etc.
      numArguments - total number of arguments to the called method
      Returns:
      slot containing the argument value
    • getOperand

      public ValueType getOperand(org.apache.bcel.generic.StackConsumer ins, org.apache.bcel.generic.ConstantPoolGen cpg, int i) throws DataflowAnalysisException
      Get the ith operand used by given instruction.
      Parameters:
      ins - the instruction, which must be a StackConsumer
      cpg - the ConstantPoolGen
      i - index of operand to get: 0 for the first operand, etc.
      Returns:
      the ith operand used by the given instruction
      Throws:
      DataflowAnalysisException
    • getArgumentSet

      public BitSet getArgumentSet(org.apache.bcel.generic.InvokeInstruction invokeInstruction, org.apache.bcel.generic.ConstantPoolGen cpg, DataflowValueChooser<ValueType> chooser) throws DataflowAnalysisException
      Get set of arguments passed to a method invocation which match given predicate.
      Parameters:
      invokeInstruction - the InvokeInstruction
      cpg - the ConstantPoolGen
      chooser - predicate to choose which argument values should be in the returned set
      Returns:
      BitSet specifying which arguments match the predicate, indexed by argument number (starting from 0)
      Throws:
      DataflowAnalysisException
    • clearStack

      public void clearStack()
      Clear the Java operand stack. Only local variable slots will remain in the frame.
    • getStackDepth

      public int getStackDepth()
      Get the depth of the Java operand stack.
    • getNumLocals

      public int getNumLocals()
      Get the number of locals.
    • getNumSlots

      public int getNumSlots()
      Get the number of slots (locals plus stack values).
    • contains

      public boolean contains(ValueType value)
    • getValue

      public ValueType getValue(int n)
      Get the value at the nth slot.
      Parameters:
      n - the slot to get the value of
      Returns:
      the value in the slot
    • setValue

      public void setValue(int n, ValueType value)
      Set the value at the nth slot.
      Parameters:
      n - the slot in which to set a new value
      value - the value to set
    • sameAs

      public boolean sameAs(Frame<ValueType> other)
      Return true if this stack frame is the same as the one given as a parameter.
      Parameters:
      other - the other Frame
      Returns:
      true if the frames are the same, false otherwise
    • copyFrom

      public void copyFrom(Frame<ValueType> other)
      Make this Frame exactly the same as the one given as a parameter.
      Parameters:
      other - the Frame to make this object the same as
    • toString

      public String toString()
      Convert to string.
      Overrides:
      toString in class Object
    • valueToString

      protected String valueToString(ValueType value)
      Subclasses may override this if they want to do something special to convert Value objects to Strings. By default, we just call toString() on the values.
    • allSlots

      public Collection<ValueType> allSlots()
      Returns:
      an unmodifiable Collection of the local variable and operand stack slots
    • setLastUpdateTimestamp

      public void setLastUpdateTimestamp(int lastUpdateTimestamp)
      Parameters:
      lastUpdateTimestamp - The lastUpdateTimestamp to set.
    • getLastUpdateTimestamp

      public int getLastUpdateTimestamp()
      Returns:
      Returns the lastUpdateTimestamp.