Package edu.umd.cs.findbugs.ba.type
Class TypeAnalysis
- java.lang.Object
-
- edu.umd.cs.findbugs.ba.BasicAbstractDataflowAnalysis<Fact>
-
- edu.umd.cs.findbugs.ba.AbstractDataflowAnalysis<Fact>
-
- edu.umd.cs.findbugs.ba.ForwardDataflowAnalysis<FrameType>
-
- 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
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.
- Author:
- David Hovemeyer
- See Also:
Dataflow
,DataflowAnalysis
,TypeFrame
-
-
Field Summary
Fields Modifier and Type Field Description protected CFG
cfg
static boolean
DEBUG
static boolean
FORCE_ACCURATE_EXCEPTIONS
Force computation of accurate exceptions.protected org.apache.bcel.generic.MethodGen
methodGen
-
Fields inherited from interface edu.umd.cs.findbugs.ba.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
Constructors Constructor Description 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.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
copy(TypeFrame source, TypeFrame dest)
Copy dataflow facts.TypeFrame
createFact()
Create empty (uninitialized) dataflow facts for one program point.ExceptionSet
getEdgeExceptionSet(Edge edge)
Get the set of exceptions that can be thrown on given edge.void
initEntryFact(TypeFrame result)
Initialize the "entry" fact for the graph.boolean
isFactValid(TypeFrame fact)
Determine whether the given fact is valid (neither top nor bottom).boolean
isImpliedByGenericTypes(org.apache.bcel.generic.ReferenceType t)
void
makeFactTop(TypeFrame fact)
Make given fact the top value.void
meetInto(TypeFrame fact, Edge edge, TypeFrame result)
Meet a dataflow fact associated with an incoming edge into another fact.protected void
mergeValues(TypeFrame otherFrame, TypeFrame resultFrame, int slot)
Merge the values contained in a given slot of two Frames.boolean
same(TypeFrame fact1, TypeFrame fact2)
Are given dataflow facts the same?void
setFieldStoreTypeDatabase(FieldStoreTypeDatabase database)
Set the FieldStoreTypeDatabase.void
setValueNumberDataflow(ValueNumberDataflow valueNumberDataflow)
Set the ValueNumberDataflow for the method being analyzed.java.lang.String
toString()
void
transfer(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle end, TypeFrame start, TypeFrame result)
Transfer function for the analysis.void
transferInstruction(org.apache.bcel.generic.InstructionHandle handle, BasicBlock basicBlock, TypeFrame fact)
Transfer function for a single instruction.-
Methods inherited from class edu.umd.cs.findbugs.ba.FrameDataflowAnalysis
getFactAtPC, getFactBeforeExceptionCheck, getLastUpdateTimestamp, isTop, mergeInto, modifyFrame, setLastUpdateTimestamp
-
Methods inherited from class edu.umd.cs.findbugs.ba.ForwardDataflowAnalysis
getBlockOrder, getDepthFirstSearch, isForwards
-
Methods inherited from class edu.umd.cs.findbugs.ba.AbstractDataflowAnalysis
getFactAfterLocation, getFactAtLocation
-
Methods inherited from class edu.umd.cs.findbugs.ba.BasicAbstractDataflowAnalysis
edgeTransfer, factToString, finishIteration, getFactOnEdge, getResultFact, getStartFact, resultFactIterator, startIteration
-
-
-
-
Field Detail
-
DEBUG
public static final boolean DEBUG
-
FORCE_ACCURATE_EXCEPTIONS
public static final boolean FORCE_ACCURATE_EXCEPTIONS
Force computation of accurate exceptions.
-
methodGen
protected org.apache.bcel.generic.MethodGen methodGen
-
cfg
protected CFG cfg
-
-
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
- 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 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
-
createFact
public TypeFrame createFact()
Description copied from interface:DataflowAnalysis
Create empty (uninitialized) dataflow facts for one program point. A valid value will be copied into it before it is used.- Specified by:
createFact
in interfaceDataflowAnalysis<TypeFrame>
-
initEntryFact
public void initEntryFact(TypeFrame result)
Description copied from interface:DataflowAnalysis
Initialize the "entry" fact for the graph.- Specified by:
initEntryFact
in interfaceDataflowAnalysis<TypeFrame>
-
copy
public void copy(TypeFrame source, TypeFrame dest)
Description copied from interface:DataflowAnalysis
Copy dataflow facts.- Specified by:
copy
in interfaceDataflowAnalysis<TypeFrame>
- Overrides:
copy
in classFrameDataflowAnalysis<org.apache.bcel.generic.Type,TypeFrame>
-
makeFactTop
public void makeFactTop(TypeFrame fact)
Description copied from interface:DataflowAnalysis
Make given fact the top value.- Specified by:
makeFactTop
in interfaceDataflowAnalysis<TypeFrame>
- Overrides:
makeFactTop
in classFrameDataflowAnalysis<org.apache.bcel.generic.Type,TypeFrame>
-
isFactValid
public boolean isFactValid(TypeFrame fact)
Description copied from class:AbstractDataflowAnalysis
Determine whether the given fact is valid (neither top nor bottom).- Overrides:
isFactValid
in classFrameDataflowAnalysis<org.apache.bcel.generic.Type,TypeFrame>
-
same
public boolean same(TypeFrame fact1, TypeFrame fact2)
Description copied from interface:DataflowAnalysis
Are given dataflow facts the same?- Specified by:
same
in interfaceDataflowAnalysis<TypeFrame>
- Overrides:
same
in 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:AbstractDataflowAnalysis
Transfer function for a single instruction.- Specified by:
transferInstruction
in 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: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 interfaceDataflowAnalysis<TypeFrame>
- Overrides:
transfer
in 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
-
meetInto
public void meetInto(TypeFrame fact, Edge edge, TypeFrame result) throws DataflowAnalysisException
Description copied from interface:DataflowAnalysis
Meet 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:
meetInto
in interfaceDataflowAnalysis<TypeFrame>
- Parameters:
fact
- the predecessor fact (incoming edge)edge
- the edge from the predecessorresult
- the result fact- Throws:
DataflowAnalysisException
-
mergeValues
protected void mergeValues(TypeFrame otherFrame, TypeFrame resultFrame, int slot) throws DataflowAnalysisException
Description copied from class:FrameDataflowAnalysis
Merge the values contained in a given slot of two Frames.- Specified by:
mergeValues
in 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
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
isImpliedByGenericTypes
public boolean isImpliedByGenericTypes(org.apache.bcel.generic.ReferenceType t)
-
-