Class TypeAnalysis

  • All Implemented Interfaces:
    DataflowAnalysis<TypeFrame>, EdgeTypes
    Direct Known Subclasses:
    FindRefComparison.SpecialTypeAnalysis

    public class TypeAnalysis
    extends FrameDataflowAnalysis<org.apache.bcel.generic.Type,​TypeFrame>
    implements EdgeTypes

    A forward dataflow analysis to determine the types of all values in the Java stack frame at all points in a Java method. The values include local variables and values on the Java operand stack.

    As a side effect, the analysis computes the exception set throwable on each exception edge in the CFG. This information can be used to prune infeasible exception edges, and mark exception edges which propagate only implicit exceptions.

    See Also:
    Dataflow, DataflowAnalysis, TypeFrame
    • Constructor Detail

      • TypeAnalysis

        public TypeAnalysis​(org.apache.bcel.classfile.Method method,
                            org.apache.bcel.generic.MethodGen methodGen,
                            CFG cfg,
                            DepthFirstSearch dfs,
                            TypeMerger typeMerger,
                            TypeFrameModelingVisitor visitor,
                            RepositoryLookupFailureCallback lookupFailureCallback,
                            ExceptionSetFactory exceptionSetFactory)
        Constructor.
        Parameters:
        method - TODO
        methodGen - the MethodGen whose CFG we'll be analyzing
        cfg - the control flow graph
        dfs - DepthFirstSearch of the method
        typeMerger - object to merge types
        visitor - a TypeFrameModelingVisitor to use to model the effect of instructions
        lookupFailureCallback - lookup failure callback
        exceptionSetFactory - factory for creating ExceptionSet objects
      • TypeAnalysis

        public TypeAnalysis​(org.apache.bcel.classfile.Method method,
                            org.apache.bcel.generic.MethodGen methodGen,
                            CFG cfg,
                            DepthFirstSearch dfs,
                            TypeMerger typeMerger,
                            RepositoryLookupFailureCallback lookupFailureCallback,
                            ExceptionSetFactory exceptionSetFactory)
        Constructor.
        Parameters:
        method - TODO
        methodGen - the MethodGen whose CFG we'll be analyzing
        cfg - the control flow graph
        dfs - DepthFirstSearch of the method
        typeMerger - object to merge types
        lookupFailureCallback - lookup failure callback
        exceptionSetFactory - factory for creating ExceptionSet objects
      • TypeAnalysis

        public TypeAnalysis​(org.apache.bcel.classfile.Method method,
                            org.apache.bcel.generic.MethodGen methodGen,
                            CFG cfg,
                            DepthFirstSearch dfs,
                            RepositoryLookupFailureCallback lookupFailureCallback,
                            ExceptionSetFactory exceptionSetFactory)
        Constructor which uses StandardTypeMerger.
        Parameters:
        method - TODO
        methodGen - the MethodGen whose CFG we'll be analyzing
        cfg - the control flow graph
        dfs - DepthFirstSearch of the method
        lookupFailureCallback - callback for Repository lookup failures
        exceptionSetFactory - factory for creating ExceptionSet objects
    • Method Detail

      • setValueNumberDataflow

        public void setValueNumberDataflow​(ValueNumberDataflow valueNumberDataflow)
        Set the ValueNumberDataflow for the method being analyzed. This is optional; if set, it will be used to make instanceof instructions more precise.
        Parameters:
        valueNumberDataflow - the ValueNumberDataflow
      • setFieldStoreTypeDatabase

        public void setFieldStoreTypeDatabase​(FieldStoreTypeDatabase database)
        Set the FieldStoreTypeDatabase. This can be used to get more accurate types for values loaded from fields.
        Parameters:
        database - the FieldStoreTypeDatabase
      • getEdgeExceptionSet

        public ExceptionSet getEdgeExceptionSet​(Edge edge)
        Get the set of exceptions that can be thrown on given edge. This should only be called after the analysis completes.
        Parameters:
        edge - the Edge
        Returns:
        the ExceptionSet
      • transfer

        public void transfer​(BasicBlock basicBlock,
                             @CheckForNull
                             org.apache.bcel.generic.InstructionHandle end,
                             TypeFrame start,
                             TypeFrame result)
                      throws DataflowAnalysisException
        Description copied from interface: DataflowAnalysis
        Transfer function for the analysis. Taking dataflow facts at start (which might be either the entry or exit of the block, depending on whether the analysis is forwards or backwards), modify result to be the facts at the other end of the block.
        Specified by:
        transfer in interface DataflowAnalysis<TypeFrame>
        Overrides:
        transfer in class AbstractDataflowAnalysis<TypeFrame>
        Parameters:
        basicBlock - the basic block
        end - if nonnull, stop before considering this instruction; otherwise, consider all of the instructions in the basic block
        start - dataflow facts at beginning of block (if forward analysis) or end of block (if backwards analysis)
        result - resulting dataflow facts at other end of block
        Throws:
        DataflowAnalysisException
      • getCachedExceptionSet

        private TypeAnalysis.CachedExceptionSet getCachedExceptionSet​(BasicBlock basicBlock)
        Get the cached set of exceptions that can be thrown from given basic block. If this information hasn't been computed yet, then an empty exception set is returned.
        Parameters:
        basicBlock - the block to get the cached exception set for
        Returns:
        the CachedExceptionSet for the block
      • computeBlockExceptionSet

        private TypeAnalysis.CachedExceptionSet computeBlockExceptionSet​(BasicBlock basicBlock,
                                                                         TypeFrame result)
                                                                  throws DataflowAnalysisException
        Compute the set of exceptions that can be thrown from the given basic block. This should only be called if the existing cached exception set is out of date.
        Parameters:
        basicBlock - the basic block
        result - the result fact for the block; this is used to determine whether or not the cached exception set is up to date
        Returns:
        the cached exception set for the block
        Throws:
        DataflowAnalysisException
      • computeEdgeExceptionSet

        private ExceptionSet computeEdgeExceptionSet​(Edge edge,
                                                     ExceptionSet thrownExceptionSet)
        Based on the set of exceptions that can be thrown from the source basic block, compute the set of exceptions that can propagate along given exception edge. This method should be called for each outgoing exception edge in sequence, so the caught exceptions can be removed from the thrown exception set as needed.
        Parameters:
        edge - the exception edge
        thrownExceptionSet - current set of exceptions that can be thrown, taking earlier (higher priority) exception edges into account
        Returns:
        the set of exceptions that can propagate along this edge
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • isImpliedByGenericTypes

        public boolean isImpliedByGenericTypes​(org.apache.bcel.generic.ReferenceType t)