Class TypeAnalysis
java.lang.Object
edu.umd.cs.findbugs.ba.BasicAbstractDataflowAnalysis<TypeFrame>
edu.umd.cs.findbugs.ba.AbstractDataflowAnalysis<TypeFrame>
edu.umd.cs.findbugs.ba.ForwardDataflowAnalysis<TypeFrame>
edu.umd.cs.findbugs.ba.FrameDataflowAnalysis<org.apache.bcel.generic.Type, TypeFrame>
edu.umd.cs.findbugs.ba.type.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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classRepository of information about thrown exceptions computed for a basic block and its outgoing exception edges.(package private) static classCached information about an instanceof check. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CFGstatic final booleanprivate final ExceptionSetFactorystatic final booleanForce computation of accurate exceptions.private final Map<BasicBlock, TypeAnalysis.InstanceOfCheck> private final RepositoryLookupFailureCallbackprivate final org.apache.bcel.classfile.Methodprotected org.apache.bcel.generic.MethodGenprivate final Map<BasicBlock, TypeAnalysis.CachedExceptionSet> private final TypeMergerprivate ValueNumberDataflowprivate final TypeFrameModelingVisitorFields inherited from interface EdgeTypes
BACKEDGE_SOURCE_EDGE, BACKEDGE_TARGET_EDGE, CHECKED_EXCEPTIONS_FLAG, EXIT_EDGE, EXPLICIT_EXCEPTIONS_FLAG, FALL_THROUGH_EDGE, GOTO_EDGE, HANDLED_EXCEPTION_EDGE, IFCMP_EDGE, JSR_EDGE, RET_EDGE, RETURN_EDGE, START_EDGE, SWITCH_DEFAULT_EDGE, SWITCH_EDGE, UNHANDLED_EXCEPTION_EDGE, UNKNOWN_EDGE -
Constructor Summary
ConstructorsConstructorDescriptionTypeAnalysis(org.apache.bcel.classfile.Method method, org.apache.bcel.generic.MethodGen methodGen, CFG cfg, DepthFirstSearch dfs, RepositoryLookupFailureCallback lookupFailureCallback, ExceptionSetFactory exceptionSetFactory) Constructor which uses StandardTypeMerger.TypeAnalysis(org.apache.bcel.classfile.Method method, org.apache.bcel.generic.MethodGen methodGen, CFG cfg, DepthFirstSearch dfs, TypeMerger typeMerger, RepositoryLookupFailureCallback lookupFailureCallback, ExceptionSetFactory exceptionSetFactory) Constructor.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. -
Method Summary
Modifier and TypeMethodDescriptionprivate TypeAnalysis.CachedExceptionSetcomputeBlockExceptionSet(BasicBlock basicBlock, TypeFrame result) Compute the set of exceptions that can be thrown from the given basic block.private ExceptionSetcomputeEdgeExceptionSet(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.private ExceptionSetcomputeThrownExceptionTypes(BasicBlock basicBlock) Compute the set of exception types that can be thrown by given basic block.private voidcomputeThrownExceptionTypes(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle end, TypeFrame result) voidCopy dataflow facts.Create empty (uninitialized) dataflow facts for one program point.private TypeAnalysis.CachedExceptionSetgetCachedExceptionSet(BasicBlock basicBlock) Get the cached set of exceptions that can be thrown from given basic block.getEdgeExceptionSet(Edge edge) Get the set of exceptions that can be thrown on given edge.private TypeFramehandleInstanceOfBranch(TypeFrame fact, TypeFrame tmpFact, Edge edge) private booleanhandlerBlockCatches(org.apache.bcel.generic.ObjectType catchType, org.apache.bcel.generic.ObjectType thrownType) voidinitEntryFact(TypeFrame result) Initialize the "entry" fact for the graph.booleanisFactValid(TypeFrame fact) Determine whether the given fact is valid (neither top nor bottom).booleanisImpliedByGenericTypes(org.apache.bcel.generic.ReferenceType t) voidmakeFactTop(TypeFrame fact) Make given fact the top value.voidMeet a dataflow fact associated with an incoming edge into another fact.protected voidmergeValues(TypeFrame otherFrame, TypeFrame resultFrame, int slot) Merge the values contained in a given slot of two Frames.booleanAre given dataflow facts the same?voidSet the FieldStoreTypeDatabase.voidsetValueNumberDataflow(ValueNumberDataflow valueNumberDataflow) Set the ValueNumberDataflow for the method being analyzed.toString()voidtransfer(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle end, TypeFrame start, TypeFrame result) Transfer function for the analysis.voidtransferInstruction(org.apache.bcel.generic.InstructionHandle handle, BasicBlock basicBlock, TypeFrame fact) Transfer function for a single instruction.Methods inherited from class FrameDataflowAnalysis
getFactAtPC, getFactBeforeExceptionCheck, getLastUpdateTimestamp, isTop, mergeInto, modifyFrame, setLastUpdateTimestampMethods inherited from class ForwardDataflowAnalysis
getBlockOrder, getDepthFirstSearch, isForwardsMethods inherited from class AbstractDataflowAnalysis
getFactAfterLocation, getFactAtLocationMethods inherited from class BasicAbstractDataflowAnalysis
edgeTransfer, factToString, finishIteration, getFactOnEdge, getResultFact, getStartFact, resultFactIterator, startIteration
-
Field Details
-
DEBUG
public static final boolean DEBUG -
FORCE_ACCURATE_EXCEPTIONS
public static final boolean FORCE_ACCURATE_EXCEPTIONSForce computation of accurate exceptions. -
methodGen
protected org.apache.bcel.generic.MethodGen methodGen -
method
private final org.apache.bcel.classfile.Method method -
cfg
-
typeMerger
-
visitor
-
thrownExceptionSetMap
-
lookupFailureCallback
-
exceptionSetFactory
-
valueNumberDataflow
-
instanceOfCheckMap
-
-
Constructor Details
-
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- TODOmethodGen- the MethodGen whose CFG we'll be analyzingcfg- the control flow graphdfs- DepthFirstSearch of the methodtypeMerger- object to merge typesvisitor- a TypeFrameModelingVisitor to use to model the effect of instructionslookupFailureCallback- lookup failure callbackexceptionSetFactory- 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- TODOmethodGen- the MethodGen whose CFG we'll be analyzingcfg- the control flow graphdfs- DepthFirstSearch of the methodtypeMerger- object to merge typeslookupFailureCallback- lookup failure callbackexceptionSetFactory- 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- TODOmethodGen- the MethodGen whose CFG we'll be analyzingcfg- the control flow graphdfs- DepthFirstSearch of the methodlookupFailureCallback- callback for Repository lookup failuresexceptionSetFactory- factory for creating ExceptionSet objects
-
-
Method Details
-
setValueNumberDataflow
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
Set the FieldStoreTypeDatabase. This can be used to get more accurate types for values loaded from fields.- Parameters:
database- the FieldStoreTypeDatabase
-
getEdgeExceptionSet
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
-
createFact
Description copied from interface:DataflowAnalysisCreate empty (uninitialized) dataflow facts for one program point. A valid value will be copied into it before it is used.- Specified by:
createFactin interfaceDataflowAnalysis<TypeFrame>
-
initEntryFact
Description copied from interface:DataflowAnalysisInitialize the "entry" fact for the graph.- Specified by:
initEntryFactin interfaceDataflowAnalysis<TypeFrame>
-
copy
Description copied from interface:DataflowAnalysisCopy dataflow facts.- Specified by:
copyin interfaceDataflowAnalysis<TypeFrame>- Overrides:
copyin classFrameDataflowAnalysis<org.apache.bcel.generic.Type, TypeFrame>
-
makeFactTop
Description copied from interface:DataflowAnalysisMake given fact the top value.- Specified by:
makeFactTopin interfaceDataflowAnalysis<TypeFrame>- Overrides:
makeFactTopin classFrameDataflowAnalysis<org.apache.bcel.generic.Type, TypeFrame>
-
isFactValid
Description copied from class:AbstractDataflowAnalysisDetermine whether the given fact is valid (neither top nor bottom).- Overrides:
isFactValidin classFrameDataflowAnalysis<org.apache.bcel.generic.Type, TypeFrame>
-
same
Description copied from interface:DataflowAnalysisAre given dataflow facts the same?- Specified by:
samein interfaceDataflowAnalysis<TypeFrame>- Overrides:
samein classFrameDataflowAnalysis<org.apache.bcel.generic.Type, TypeFrame>
-
transferInstruction
public void transferInstruction(org.apache.bcel.generic.InstructionHandle handle, BasicBlock basicBlock, TypeFrame fact) throws DataflowAnalysisException Description copied from class:AbstractDataflowAnalysisTransfer function for a single instruction.- Specified by:
transferInstructionin classAbstractDataflowAnalysis<TypeFrame>- Parameters:
handle- the instructionbasicBlock- the BasicBlock containing the instruction; needed to disambiguate instructions in inlined JSR subroutinesfact- which should be modified based on the instruction- Throws:
DataflowAnalysisException
-
transfer
public void transfer(BasicBlock basicBlock, @CheckForNull org.apache.bcel.generic.InstructionHandle end, TypeFrame start, TypeFrame result) throws DataflowAnalysisException Description copied from interface:DataflowAnalysisTransfer 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:
transferin interfaceDataflowAnalysis<TypeFrame>- Overrides:
transferin classAbstractDataflowAnalysis<TypeFrame>- Parameters:
basicBlock- the basic blockend- if nonnull, stop before considering this instruction; otherwise, consider all of the instructions in the basic blockstart- 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
-
computeThrownExceptionTypes
private void computeThrownExceptionTypes(BasicBlock basicBlock, @CheckForNull org.apache.bcel.generic.InstructionHandle end, TypeFrame result) throws DataflowAnalysisException - Throws:
DataflowAnalysisException
-
meetInto
Description copied from interface:DataflowAnalysisMeet a dataflow fact associated with an incoming edge into another fact. This is used to determine the start fact for a basic block.- Specified by:
meetIntoin interfaceDataflowAnalysis<TypeFrame>- Parameters:
fact- the predecessor fact (incoming edge)edge- the edge from the predecessorresult- the result fact- Throws:
DataflowAnalysisException
-
handleInstanceOfBranch
-
mergeValues
protected void mergeValues(TypeFrame otherFrame, TypeFrame resultFrame, int slot) throws DataflowAnalysisException Description copied from class:FrameDataflowAnalysisMerge the values contained in a given slot of two Frames.- Specified by:
mergeValuesin classFrameDataflowAnalysis<org.apache.bcel.generic.Type, TypeFrame>- Parameters:
otherFrame- a FrameresultFrame- a Frame which will contain the resulting merged valueslot- a slot in both frames- Throws:
DataflowAnalysisException
-
getCachedExceptionSet
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 blockresult- 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
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 edgethrownExceptionSet- 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
-
handlerBlockCatches
private boolean handlerBlockCatches(org.apache.bcel.generic.ObjectType catchType, org.apache.bcel.generic.ObjectType thrownType) throws ClassNotFoundException - Returns:
trueif the block catchingcatchType(which might be a multi-catch block) is catching exceptions of typethrownType- Throws:
ClassNotFoundException
-
computeThrownExceptionTypes
private ExceptionSet computeThrownExceptionTypes(BasicBlock basicBlock) throws DataflowAnalysisException Compute the set of exception types that can be thrown by given basic block.- Parameters:
basicBlock- the basic block- Returns:
- the set of exceptions that can be thrown by the block
- Throws:
DataflowAnalysisException
-
toString
-
isImpliedByGenericTypes
public boolean isImpliedByGenericTypes(org.apache.bcel.generic.ReferenceType t)
-