edu.umd.cs.findbugs.ba
Class ClassContext

java.lang.Object
  extended by edu.umd.cs.findbugs.ba.ClassContext
All Implemented Interfaces:
AnalysisFeatures

public class ClassContext
extends java.lang.Object
implements AnalysisFeatures

A ClassContext caches all of the auxiliary objects used to analyze the methods of a class. That way, these objects don't need to be created over and over again.

Author:
David Hovemeyer

Nested Class Summary
private  class ClassContext.AnalysisFactory<Analysis>
          Abstract factory class for creating analysis objects.
private static class ClassContext.AnalysisResult<Analysis>
          An AnalysisResult stores the result of requesting an analysis from an AnalysisFactory.
private  class ClassContext.CFGFactory
           
private  class ClassContext.NoDataflowAnalysisFactory<AnalysisResult>
           
private  class ClassContext.NoExceptionAnalysisFactory<AnalysisResult>
           
 
Field Summary
private  AnalysisContext analysisContext
           
private  AssertionMethods assertionMethods
           
private  AssignedFieldMap assignedFieldMap
           
private  ClassContext.AnalysisFactory<Dataflow<BlockType,BlockTypeAnalysis>> blockTypeDataflowFactory
           
private static java.util.Set<java.lang.String> busyCFGSet
           
private  ClassContext.NoExceptionAnalysisFactory<java.util.BitSet> bytecodeSetFactory
           
private  ClassContext.CFGFactory cfgFactory
           
private  org.apache.bcel.generic.ClassGen classGen
           
static boolean DEBUG
           
private static boolean DEBUG_CFG
           
private static int depth
           
private  ClassContext.NoDataflowAnalysisFactory<DepthFirstSearch> dfsFactory
           
private  ClassContext.NoExceptionAnalysisFactory<ExceptionSetFactory> exceptionSetFactoryFactory
           
private static java.util.BitSet fieldInstructionOpcodeSet
           
private  ClassContext.AnalysisFactory<IsNullValueDataflow> invDataflowFactory
           
private  org.apache.bcel.classfile.JavaClass jclass
           
private  ClassContext.AnalysisFactory<LiveLocalStoreDataflow> liveLocalStoreDataflowFactory
           
private  ClassContext.NoExceptionAnalysisFactory<LoadedFieldSet> loadedFieldSetFactory
          Factory to determine which fields are loaded and stored by the instructions in a method, and the overall method.
private  ClassContext.AnalysisFactory<LockDataflow> lockDataflowFactory
           
private  ClassContext.NoExceptionAnalysisFactory<org.apache.bcel.generic.MethodGen> methodGenFactory
           
private  ClassContext.AnalysisFactory<DominatorsAnalysis> nonExceptionDominatorsAnalysisFactory
           
private  ClassContext.AnalysisFactory<PostDominatorsAnalysis> nonExceptionPostDominatorsAnalysisFactory
           
private  ClassContext.NoExceptionAnalysisFactory<java.lang.String[]> parameterSignatureListFactory
           
static boolean PRUNE_INFEASIBLE_EXCEPTION_EDGES
          We only do pruning of infeasible exception edges if the WORK_HARD analysis feature is enabled.
static boolean PRUNE_UNCONDITIONAL_EXCEPTION_THROWER_EDGES
          Only try to determine unconditional exception throwers if we're not trying to conserve space.
private static int PRUNED_INFEASIBLE_EXCEPTIONS
           
private static int PRUNED_UNCONDITIONAL_THROWERS
           
private  ClassContext.NoDataflowAnalysisFactory<ReverseDepthFirstSearch> rdfsFactory
           
private  ClassContext.AnalysisFactory<ReturnPathDataflow> returnPathDataflowFactory
           
private static boolean TIME_ANALYSES
           
private  ClassContext.AnalysisFactory<TypeDataflow> typeDataflowFactory
           
private  ClassContext.AnalysisFactory<ValueNumberDataflow> vnaDataflowFactory
           
 
Fields inherited from interface edu.umd.cs.findbugs.ba.AnalysisFeatures
CONSERVE_SPACE, WORK_HARD
 
Constructor Summary
ClassContext(org.apache.bcel.classfile.JavaClass jclass, AnalysisContext analysisContext)
          Constructor.
 
Method Summary
 AnalysisContext getAnalysisContext()
          Get the AnalysisContext.
 AssertionMethods getAssertionMethods()
          Get AssertionMethods for class.
 AssignedFieldMap getAssignedFieldMap()
          Get the assigned field map for the class.
 Dataflow<BlockType,BlockTypeAnalysis> getBlockTypeDataflow(org.apache.bcel.classfile.Method method)
          Get BlockType dataflow for given method.
 java.util.BitSet getBytecodeSet(org.apache.bcel.classfile.Method method)
          Get a BitSet representing the bytecodes that are used in the given method.
 CFG getCFG(org.apache.bcel.classfile.Method method)
          Get a CFG for given method.
 org.apache.bcel.generic.ConstantPoolGen getConstantPoolGen()
          Get the ConstantPoolGen used to create the MethodGens for this class.
 DepthFirstSearch getDepthFirstSearch(org.apache.bcel.classfile.Method method)
          Get a DepthFirstSearch for given method.
 ExceptionSetFactory getExceptionSetFactory(org.apache.bcel.classfile.Method method)
          Get ExceptionSetFactory for given method.
 IsNullValueDataflow getIsNullValueDataflow(org.apache.bcel.classfile.Method method)
          Get an IsNullValueDataflow for given method.
 org.apache.bcel.classfile.JavaClass getJavaClass()
          Get the JavaClass.
 LiveLocalStoreDataflow getLiveLocalStoreDataflow(org.apache.bcel.classfile.Method method)
          Get LiveLocalStoreAnalysis dataflow for given method.
 LoadedFieldSet getLoadedFieldSet(org.apache.bcel.classfile.Method method)
          Get the set of fields loaded by given method.
 LockDataflow getLockDataflow(org.apache.bcel.classfile.Method method)
          Get dataflow for LockAnalysis for given method.
 RepositoryLookupFailureCallback getLookupFailureCallback()
          Get the RepositoryLookupFailureCallback.
 org.apache.bcel.generic.MethodGen getMethodGen(org.apache.bcel.classfile.Method method)
          Get a MethodGen object for given method.
 DominatorsAnalysis getNonExceptionDominatorsAnalysis(org.apache.bcel.classfile.Method method)
          Get DominatorsAnalysis for given method, where exception edges are ignored.
 PostDominatorsAnalysis getNonExceptionPostDominatorsAnalysis(org.apache.bcel.classfile.Method method)
          Get PostDominatorsAnalysis for given method, where exception edges are ignored.
 java.lang.String[] getParameterSignatureList(org.apache.bcel.classfile.Method method)
          Get array of type signatures of parameters for given method.
 CFG getRawCFG(org.apache.bcel.classfile.Method method)
          Get a "raw" CFG for given method.
 ReturnPathDataflow getReturnPathDataflow(org.apache.bcel.classfile.Method method)
          Get ReturnPathDataflow for method.
 ReverseDepthFirstSearch getReverseDepthFirstSearch(org.apache.bcel.classfile.Method method)
          Get a ReverseDepthFirstSearch for given method.
 TypeDataflow getTypeDataflow(org.apache.bcel.classfile.Method method)
          Get a TypeDataflow for given method.
 ValueNumberDataflow getValueNumberDataflow(org.apache.bcel.classfile.Method method)
          Get a ValueNumberDataflow for given method.
private static void indent()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PRUNE_INFEASIBLE_EXCEPTION_EDGES

public static final boolean PRUNE_INFEASIBLE_EXCEPTION_EDGES
We only do pruning of infeasible exception edges if the WORK_HARD analysis feature is enabled.


PRUNE_UNCONDITIONAL_EXCEPTION_THROWER_EDGES

public static final boolean PRUNE_UNCONDITIONAL_EXCEPTION_THROWER_EDGES
Only try to determine unconditional exception throwers if we're not trying to conserve space.


DEBUG

public static final boolean DEBUG

PRUNED_INFEASIBLE_EXCEPTIONS

private static final int PRUNED_INFEASIBLE_EXCEPTIONS
See Also:
Constant Field Values

PRUNED_UNCONDITIONAL_THROWERS

private static final int PRUNED_UNCONDITIONAL_THROWERS
See Also:
Constant Field Values

TIME_ANALYSES

private static final boolean TIME_ANALYSES

DEBUG_CFG

private static final boolean DEBUG_CFG

depth

private static int depth

busyCFGSet

private static final java.util.Set<java.lang.String> busyCFGSet

jclass

private org.apache.bcel.classfile.JavaClass jclass

analysisContext

private AnalysisContext analysisContext

methodGenFactory

private ClassContext.NoExceptionAnalysisFactory<org.apache.bcel.generic.MethodGen> methodGenFactory

cfgFactory

private ClassContext.CFGFactory cfgFactory

vnaDataflowFactory

private ClassContext.AnalysisFactory<ValueNumberDataflow> vnaDataflowFactory

invDataflowFactory

private ClassContext.AnalysisFactory<IsNullValueDataflow> invDataflowFactory

typeDataflowFactory

private ClassContext.AnalysisFactory<TypeDataflow> typeDataflowFactory

dfsFactory

private ClassContext.NoDataflowAnalysisFactory<DepthFirstSearch> dfsFactory

rdfsFactory

private ClassContext.NoDataflowAnalysisFactory<ReverseDepthFirstSearch> rdfsFactory

bytecodeSetFactory

private ClassContext.NoExceptionAnalysisFactory<java.util.BitSet> bytecodeSetFactory

lockDataflowFactory

private ClassContext.AnalysisFactory<LockDataflow> lockDataflowFactory

returnPathDataflowFactory

private ClassContext.AnalysisFactory<ReturnPathDataflow> returnPathDataflowFactory

nonExceptionDominatorsAnalysisFactory

private ClassContext.AnalysisFactory<DominatorsAnalysis> nonExceptionDominatorsAnalysisFactory

nonExceptionPostDominatorsAnalysisFactory

private ClassContext.AnalysisFactory<PostDominatorsAnalysis> nonExceptionPostDominatorsAnalysisFactory

exceptionSetFactoryFactory

private ClassContext.NoExceptionAnalysisFactory<ExceptionSetFactory> exceptionSetFactoryFactory

parameterSignatureListFactory

private ClassContext.NoExceptionAnalysisFactory<java.lang.String[]> parameterSignatureListFactory

fieldInstructionOpcodeSet

private static final java.util.BitSet fieldInstructionOpcodeSet

loadedFieldSetFactory

private ClassContext.NoExceptionAnalysisFactory<LoadedFieldSet> loadedFieldSetFactory
Factory to determine which fields are loaded and stored by the instructions in a method, and the overall method. The main purpose is to support efficient redundant load elimination and forward substitution in ValueNumberAnalysis (there is no need to remember stores of fields that are never read, or loads of fields that are only loaded in one location). However, it might be useful for other kinds of analysis.

The tricky part is that in addition to fields loaded and stored with get/putfield and get/putstatic, we also try to figure out field accessed through calls to inner-class access methods.


liveLocalStoreDataflowFactory

private ClassContext.AnalysisFactory<LiveLocalStoreDataflow> liveLocalStoreDataflowFactory

blockTypeDataflowFactory

private ClassContext.AnalysisFactory<Dataflow<BlockType,BlockTypeAnalysis>> blockTypeDataflowFactory

classGen

private org.apache.bcel.generic.ClassGen classGen

assignedFieldMap

private AssignedFieldMap assignedFieldMap

assertionMethods

private AssertionMethods assertionMethods
Constructor Detail

ClassContext

public ClassContext(org.apache.bcel.classfile.JavaClass jclass,
                    AnalysisContext analysisContext)
Constructor.

Parameters:
jclass - the JavaClass
Method Detail

indent

private static void indent()

getJavaClass

public org.apache.bcel.classfile.JavaClass getJavaClass()
Get the JavaClass.


getAnalysisContext

public AnalysisContext getAnalysisContext()
Get the AnalysisContext.


getLookupFailureCallback

public RepositoryLookupFailureCallback getLookupFailureCallback()
Get the RepositoryLookupFailureCallback.

Returns:
the RepositoryLookupFailureCallback

getMethodGen

public org.apache.bcel.generic.MethodGen getMethodGen(org.apache.bcel.classfile.Method method)
Get a MethodGen object for given method.

Parameters:
method - the method
Returns:
the MethodGen object for the method, or null if the method has no Code attribute (and thus cannot be analyzed)

getRawCFG

public CFG getRawCFG(org.apache.bcel.classfile.Method method)
              throws CFGBuilderException
Get a "raw" CFG for given method. No pruning is done, although the CFG may already be pruned.

Parameters:
method - the method
Returns:
the raw CFG
Throws:
CFGBuilderException

getCFG

public CFG getCFG(org.apache.bcel.classfile.Method method)
           throws CFGBuilderException
Get a CFG for given method. If pruning options are in effect, pruning will be done. Because the CFG pruning can involve interprocedural analysis, it is done on a best-effort basis, so the CFG returned might not actually be pruned.

Parameters:
method - the method
Returns:
the CFG
Throws:
CFGBuilderException - if a CFG cannot be constructed for the method

getConstantPoolGen

public org.apache.bcel.generic.ConstantPoolGen getConstantPoolGen()
Get the ConstantPoolGen used to create the MethodGens for this class.

Returns:
the ConstantPoolGen

getValueNumberDataflow

public ValueNumberDataflow getValueNumberDataflow(org.apache.bcel.classfile.Method method)
                                           throws DataflowAnalysisException,
                                                  CFGBuilderException
Get a ValueNumberDataflow for given method.

Parameters:
method - the method
Returns:
the ValueNumberDataflow
Throws:
DataflowAnalysisException
CFGBuilderException

getIsNullValueDataflow

public IsNullValueDataflow getIsNullValueDataflow(org.apache.bcel.classfile.Method method)
                                           throws DataflowAnalysisException,
                                                  CFGBuilderException
Get an IsNullValueDataflow for given method.

Parameters:
method - the method
Returns:
the IsNullValueDataflow
Throws:
DataflowAnalysisException
CFGBuilderException

getTypeDataflow

public TypeDataflow getTypeDataflow(org.apache.bcel.classfile.Method method)
                             throws DataflowAnalysisException,
                                    CFGBuilderException
Get a TypeDataflow for given method.

Parameters:
method - the method
Returns:
the TypeDataflow
Throws:
DataflowAnalysisException
CFGBuilderException

getDepthFirstSearch

public DepthFirstSearch getDepthFirstSearch(org.apache.bcel.classfile.Method method)
                                     throws CFGBuilderException
Get a DepthFirstSearch for given method.

Parameters:
method - the method
Returns:
the DepthFirstSearch
Throws:
CFGBuilderException

getReverseDepthFirstSearch

public ReverseDepthFirstSearch getReverseDepthFirstSearch(org.apache.bcel.classfile.Method method)
                                                   throws CFGBuilderException
Get a ReverseDepthFirstSearch for given method.

Parameters:
method - the method
Returns:
the ReverseDepthFirstSearch
Throws:
CFGBuilderException

getBytecodeSet

public java.util.BitSet getBytecodeSet(org.apache.bcel.classfile.Method method)
Get a BitSet representing the bytecodes that are used in the given method. This is useful for prescreening a method for the existence of particular instructions. Because this step doesn't require building a MethodGen, it is very fast and memory-efficient. It may allow a Detector to avoid some very expensive analysis, which is a Big Win for the user.

Parameters:
method - the method
Returns:
the BitSet containing the opcodes which appear in the method

getLockDataflow

public LockDataflow getLockDataflow(org.apache.bcel.classfile.Method method)
                             throws CFGBuilderException,
                                    DataflowAnalysisException
Get dataflow for LockAnalysis for given method.

Parameters:
method - the method
Returns:
the LockDataflow
Throws:
CFGBuilderException
DataflowAnalysisException

getReturnPathDataflow

public ReturnPathDataflow getReturnPathDataflow(org.apache.bcel.classfile.Method method)
                                         throws CFGBuilderException,
                                                DataflowAnalysisException
Get ReturnPathDataflow for method.

Parameters:
method - the method
Returns:
the ReturnPathDataflow
Throws:
CFGBuilderException
DataflowAnalysisException

getNonExceptionDominatorsAnalysis

public DominatorsAnalysis getNonExceptionDominatorsAnalysis(org.apache.bcel.classfile.Method method)
                                                     throws CFGBuilderException,
                                                            DataflowAnalysisException
Get DominatorsAnalysis for given method, where exception edges are ignored.

Parameters:
method - the method
Returns:
the DominatorsAnalysis
Throws:
CFGBuilderException
DataflowAnalysisException

getNonExceptionPostDominatorsAnalysis

public PostDominatorsAnalysis getNonExceptionPostDominatorsAnalysis(org.apache.bcel.classfile.Method method)
                                                             throws CFGBuilderException,
                                                                    DataflowAnalysisException
Get PostDominatorsAnalysis for given method, where exception edges are ignored.

Parameters:
method - the method
Returns:
the PostDominatorsAnalysis
Throws:
CFGBuilderException
DataflowAnalysisException

getExceptionSetFactory

public ExceptionSetFactory getExceptionSetFactory(org.apache.bcel.classfile.Method method)
Get ExceptionSetFactory for given method.

Parameters:
method - the method
Returns:
the ExceptionSetFactory

getParameterSignatureList

public java.lang.String[] getParameterSignatureList(org.apache.bcel.classfile.Method method)
Get array of type signatures of parameters for given method.

Parameters:
method - the method
Returns:
an array of type signatures indicating the types of the method's parameters

getLoadedFieldSet

public LoadedFieldSet getLoadedFieldSet(org.apache.bcel.classfile.Method method)
Get the set of fields loaded by given method.

Parameters:
method - the method
Returns:
the set of fields loaded by the method

getLiveLocalStoreDataflow

public LiveLocalStoreDataflow getLiveLocalStoreDataflow(org.apache.bcel.classfile.Method method)
                                                 throws DataflowAnalysisException,
                                                        CFGBuilderException
Get LiveLocalStoreAnalysis dataflow for given method.

Parameters:
method - the method
Returns:
the Dataflow object for LiveLocalStoreAnalysis on the method
Throws:
DataflowAnalysisException
CFGBuilderException

getBlockTypeDataflow

public Dataflow<BlockType,BlockTypeAnalysis> getBlockTypeDataflow(org.apache.bcel.classfile.Method method)
                                                           throws DataflowAnalysisException,
                                                                  CFGBuilderException
Get BlockType dataflow for given method.

Parameters:
method - the method
Returns:
the Dataflow object for BlockTypeAnalysis on the method
Throws:
DataflowAnalysisException
CFGBuilderException

getAssignedFieldMap

public AssignedFieldMap getAssignedFieldMap()
                                     throws java.lang.ClassNotFoundException
Get the assigned field map for the class.

Returns:
the AssignedFieldMap
Throws:
java.lang.ClassNotFoundException - if a class lookup prevents the class's superclasses from being searched for assignable fields

getAssertionMethods

public AssertionMethods getAssertionMethods()
Get AssertionMethods for class.

Returns:
the AssertionMethods