Package edu.umd.cs.findbugs.ba.deref
Class UnconditionalValueDerefAnalysis
- java.lang.Object
-
- edu.umd.cs.findbugs.ba.BasicAbstractDataflowAnalysis<Fact>
-
- edu.umd.cs.findbugs.ba.AbstractDataflowAnalysis<Fact>
-
- edu.umd.cs.findbugs.ba.BackwardDataflowAnalysis<UnconditionalValueDerefSet>
-
- edu.umd.cs.findbugs.ba.deref.UnconditionalValueDerefAnalysis
-
- All Implemented Interfaces:
DataflowAnalysis<UnconditionalValueDerefSet>
public class UnconditionalValueDerefAnalysis extends BackwardDataflowAnalysis<UnconditionalValueDerefSet>
Dataflow analysis to find values unconditionally dereferenced in the future.
-
-
Field Summary
Fields Modifier and Type Field Description private AssertionMethods
assertionMethods
static boolean
ASSUME_NONZERO_TRIP_LOOPS
private CFG
cfg
static boolean
CHECK_ANNOTATIONS
static boolean
CHECK_CALLS
static boolean
DEBUG
static boolean
DEBUG_CHECK_CALLS
static boolean
IGNORE_DEREF_OF_NCP
private IsNullValueDataflow
invDataflow
private org.apache.bcel.classfile.Method
method
private org.apache.bcel.generic.MethodGen
methodGen
private static int[]
NULLCHECK1
private static int[]
NULLCHECK2
private TypeDataflow
typeDataflow
static boolean
VERBOSE_NULLARG_DEBUG
private ValueNumberDataflow
vnaDataflow
-
Constructor Summary
Constructors Constructor Description UnconditionalValueDerefAnalysis(ReverseDepthFirstSearch rdfs, DepthFirstSearch dfs, CFG cfg, org.apache.bcel.classfile.Method method, org.apache.bcel.generic.MethodGen methodGen, ValueNumberDataflow vnaDataflow, AssertionMethods assertionMethods)
Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static boolean
check(org.apache.bcel.generic.InstructionHandle h, int[] opcodes)
static java.util.Set<ValueNumber>
checkAllNonNullParams(Location location, ValueNumberFrame vnaFrame, org.apache.bcel.generic.ConstantPoolGen constantPool, org.apache.bcel.classfile.Method method, IsNullValueDataflow invDataflow, TypeDataflow typeDataflow)
private void
checkInstance(Location location, ValueNumberFrame vnaFrame, UnconditionalValueDerefSet fact)
Check to see if the instruction has a null check associated with it, and if so, add a dereference.private void
checkNonNullParams(Location location, ValueNumberFrame vnaFrame, UnconditionalValueDerefSet fact)
If this is a method call instruction, check to see if any of the parameters are @NonNull, and treat them as dereferences.static java.util.Set<ValueNumber>
checkNonNullParams(Location location, ValueNumberFrame vnaFrame, org.apache.bcel.generic.ConstantPoolGen constantPool, org.apache.bcel.classfile.Method method, IsNullValueFrame invFrame)
private void
checkNonNullPutField(Location location, ValueNumberFrame vnaFrame, UnconditionalValueDerefSet fact)
If this is a putfield or putstatic instruction, check to see if the field is @NonNull, and treat it as dereferences.private void
checkNonNullReturnValue(XMethod thisMethod, Location location, ValueNumberFrame vnaFrame, UnconditionalValueDerefSet fact)
If this is a method call instruction, check to see if any of the parameters are @NonNull, and treat them as dereferences.private void
checkUnconditionalDerefDatabase(Location location, ValueNumberFrame vnaFrame, UnconditionalValueDerefSet fact)
Check method call at given location to see if it unconditionally dereferences a parameter.static java.util.Set<ValueNumber>
checkUnconditionalDerefDatabase(Location location, ValueNumberFrame vnaFrame, org.apache.bcel.generic.ConstantPoolGen constantPool, IsNullValueFrame invFrame, TypeDataflow typeDataflow)
void
clearDerefsOnNonNullBranches(IsNullValueDataflow invDataflow)
HACK: use the given is-null dataflow to clear deref sets for values that are known to be definitely non-null on a branch.void
copy(UnconditionalValueDerefSet source, UnconditionalValueDerefSet dest)
Copy dataflow facts.UnconditionalValueDerefSet
createFact()
Create empty (uninitialized) dataflow facts for one program point.private UnconditionalValueDerefSet
duplicateFact(UnconditionalValueDerefSet fact)
Return a duplicate of given dataflow fact.private ValueNumber
findValueKnownNonnullOnBranch(UnconditionalValueDerefSet fact, Edge edge)
Clear deref sets of values if this edge is the non-null branch of an if comparison.int
getLastUpdateTimestamp(UnconditionalValueDerefSet fact)
private void
handleNullCheck(Location location, ValueNumberFrame vnaFrame, UnconditionalValueDerefSet fact)
void
initEntryFact(UnconditionalValueDerefSet result)
Initialize the "entry" fact for the graph.private boolean
isAssertion(org.apache.bcel.generic.InstructionHandle handle)
Return whether or not given instruction is an assertion.private boolean
isExceptionEdge(Edge edge)
Determine whether dataflow should be propagated on given edge.boolean
isFactValid(UnconditionalValueDerefSet fact)
Determine whether the given fact is valid (neither top nor bottom).static boolean
isNullCheck(org.apache.bcel.generic.InstructionHandle h, org.apache.bcel.generic.ConstantPoolGen cpg)
boolean
isTop(UnconditionalValueDerefSet fact)
Is the given fact the top value.void
makeFactTop(UnconditionalValueDerefSet fact)
Make given fact the top value.void
meetInto(UnconditionalValueDerefSet fact, Edge edge, UnconditionalValueDerefSet result)
Meet a dataflow fact associated with an incoming edge into another fact.void
meetInto(UnconditionalValueDerefSet fact, Edge edge, UnconditionalValueDerefSet result, boolean onlyEdge)
private UnconditionalValueDerefSet
propagateDerefSetsToMergeInputValues(UnconditionalValueDerefSet fact, Edge edge)
Find out if any VNs in the source block contribute to unconditionally dereferenced VNs in the target block.private static boolean
reportDereference(IsNullValue value)
private static boolean
reportDereference(IsNullValueFrame invFrameAtNullCheck, int instance)
static boolean
reportPotentialDereference(Location location, IsNullValueFrame invFrame)
boolean
same(UnconditionalValueDerefSet fact1, UnconditionalValueDerefSet fact2)
Are given dataflow facts the same?void
setLastUpdateTimestamp(UnconditionalValueDerefSet fact, int lastUpdate)
void
setTypeDataflow(TypeDataflow typeDataflow)
void
startIteration()
Called before beginning an iteration of analysis.java.lang.String
toString()
void
transferInstruction(org.apache.bcel.generic.InstructionHandle handle, BasicBlock basicBlock, UnconditionalValueDerefSet fact)
Transfer function for a single instruction.-
Methods inherited from class edu.umd.cs.findbugs.ba.BackwardDataflowAnalysis
getBlockOrder, getReverseDepthFirstSearch, isForwards
-
Methods inherited from class edu.umd.cs.findbugs.ba.AbstractDataflowAnalysis
getFactAfterLocation, getFactAtLocation, transfer
-
Methods inherited from class edu.umd.cs.findbugs.ba.BasicAbstractDataflowAnalysis
edgeTransfer, factToString, finishIteration, getFactOnEdge, getResultFact, getStartFact, resultFactIterator
-
-
-
-
Field Detail
-
DEBUG
public static final boolean DEBUG
-
ASSUME_NONZERO_TRIP_LOOPS
public static final boolean ASSUME_NONZERO_TRIP_LOOPS
-
IGNORE_DEREF_OF_NCP
public static final boolean IGNORE_DEREF_OF_NCP
-
CHECK_ANNOTATIONS
public static final boolean CHECK_ANNOTATIONS
-
CHECK_CALLS
public static final boolean CHECK_CALLS
-
DEBUG_CHECK_CALLS
public static final boolean DEBUG_CHECK_CALLS
-
NULLCHECK1
private static final int[] NULLCHECK1
-
NULLCHECK2
private static final int[] NULLCHECK2
-
cfg
private final CFG cfg
-
method
private final org.apache.bcel.classfile.Method method
-
methodGen
private final org.apache.bcel.generic.MethodGen methodGen
-
vnaDataflow
private final ValueNumberDataflow vnaDataflow
-
assertionMethods
private final AssertionMethods assertionMethods
-
invDataflow
private IsNullValueDataflow invDataflow
-
typeDataflow
private TypeDataflow typeDataflow
-
VERBOSE_NULLARG_DEBUG
public static final boolean VERBOSE_NULLARG_DEBUG
-
-
Constructor Detail
-
UnconditionalValueDerefAnalysis
public UnconditionalValueDerefAnalysis(ReverseDepthFirstSearch rdfs, DepthFirstSearch dfs, CFG cfg, org.apache.bcel.classfile.Method method, org.apache.bcel.generic.MethodGen methodGen, ValueNumberDataflow vnaDataflow, AssertionMethods assertionMethods)
Constructor.- Parameters:
rdfs
- the reverse depth-first-search (for the block order)cfg
- the CFG for the methodmethodGen
- the MethodGen for the methodvnaDataflow
-assertionMethods
- AssertionMethods for the analyzed class
-
-
Method Detail
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
clearDerefsOnNonNullBranches
public void clearDerefsOnNonNullBranches(IsNullValueDataflow invDataflow)
HACK: use the given is-null dataflow to clear deref sets for values that are known to be definitely non-null on a branch.- Parameters:
invDataflow
- the IsNullValueDataflow to use
-
setTypeDataflow
public void setTypeDataflow(TypeDataflow typeDataflow)
-
isFactValid
public boolean isFactValid(UnconditionalValueDerefSet fact)
Description copied from class:AbstractDataflowAnalysis
Determine whether the given fact is valid (neither top nor bottom).- Specified by:
isFactValid
in classAbstractDataflowAnalysis<UnconditionalValueDerefSet>
-
check
private static boolean check(org.apache.bcel.generic.InstructionHandle h, int[] opcodes)
-
isNullCheck
public static boolean isNullCheck(org.apache.bcel.generic.InstructionHandle h, org.apache.bcel.generic.ConstantPoolGen cpg)
-
handleNullCheck
private void handleNullCheck(Location location, ValueNumberFrame vnaFrame, UnconditionalValueDerefSet fact) throws DataflowAnalysisException
- Throws:
DataflowAnalysisException
-
reportPotentialDereference
public static boolean reportPotentialDereference(Location location, IsNullValueFrame invFrame) throws DataflowAnalysisException
- Throws:
DataflowAnalysisException
-
transferInstruction
public void transferInstruction(org.apache.bcel.generic.InstructionHandle handle, BasicBlock basicBlock, UnconditionalValueDerefSet fact) throws DataflowAnalysisException
Description copied from class:AbstractDataflowAnalysis
Transfer function for a single instruction.- Specified by:
transferInstruction
in classAbstractDataflowAnalysis<UnconditionalValueDerefSet>
- 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
-
checkUnconditionalDerefDatabase
private void checkUnconditionalDerefDatabase(Location location, ValueNumberFrame vnaFrame, UnconditionalValueDerefSet fact) throws DataflowAnalysisException
Check method call at given location to see if it unconditionally dereferences a parameter. Mark any such arguments as derefs.- Parameters:
location
- the Location of the method callvnaFrame
- ValueNumberFrame at the Locationfact
- the dataflow value to modify- Throws:
DataflowAnalysisException
-
checkUnconditionalDerefDatabase
public static java.util.Set<ValueNumber> checkUnconditionalDerefDatabase(Location location, ValueNumberFrame vnaFrame, org.apache.bcel.generic.ConstantPoolGen constantPool, @CheckForNull IsNullValueFrame invFrame, TypeDataflow typeDataflow) throws DataflowAnalysisException
- Throws:
DataflowAnalysisException
-
checkNonNullReturnValue
private void checkNonNullReturnValue(XMethod thisMethod, Location location, ValueNumberFrame vnaFrame, UnconditionalValueDerefSet fact) throws DataflowAnalysisException
If this is a method call instruction, check to see if any of the parameters are @NonNull, and treat them as dereferences.- Parameters:
location
- the Location of the instructionvnaFrame
- the ValueNumberFrame at the Location of the instructionfact
- the dataflow value to modify- Throws:
DataflowAnalysisException
-
checkNonNullPutField
private void checkNonNullPutField(Location location, ValueNumberFrame vnaFrame, UnconditionalValueDerefSet fact) throws DataflowAnalysisException
If this is a putfield or putstatic instruction, check to see if the field is @NonNull, and treat it as dereferences.- Parameters:
location
- the Location of the instructionvnaFrame
- the ValueNumberFrame at the Location of the instructionfact
- the dataflow value to modify- Throws:
DataflowAnalysisException
-
checkNonNullParams
private void checkNonNullParams(Location location, ValueNumberFrame vnaFrame, UnconditionalValueDerefSet fact) throws DataflowAnalysisException
If this is a method call instruction, check to see if any of the parameters are @NonNull, and treat them as dereferences.- Parameters:
location
- the Location of the instructionvnaFrame
- the ValueNumberFrame at the Location of the instructionfact
- the dataflow value to modify- Throws:
DataflowAnalysisException
-
checkAllNonNullParams
public static java.util.Set<ValueNumber> checkAllNonNullParams(Location location, ValueNumberFrame vnaFrame, org.apache.bcel.generic.ConstantPoolGen constantPool, @CheckForNull org.apache.bcel.classfile.Method method, @CheckForNull IsNullValueDataflow invDataflow, TypeDataflow typeDataflow) throws DataflowAnalysisException
- Throws:
DataflowAnalysisException
-
checkNonNullParams
public static java.util.Set<ValueNumber> checkNonNullParams(Location location, ValueNumberFrame vnaFrame, org.apache.bcel.generic.ConstantPoolGen constantPool, @CheckForNull org.apache.bcel.classfile.Method method, @CheckForNull IsNullValueFrame invFrame) throws DataflowAnalysisException
- Throws:
DataflowAnalysisException
-
checkInstance
private void checkInstance(Location location, ValueNumberFrame vnaFrame, UnconditionalValueDerefSet fact) throws DataflowAnalysisException
Check to see if the instruction has a null check associated with it, and if so, add a dereference.- Parameters:
location
- the Location of the instructionvnaFrame
- ValueNumberFrame at the Location of the instructionfact
- the dataflow value to modify- Throws:
DataflowAnalysisException
-
reportDereference
private static boolean reportDereference(IsNullValueFrame invFrameAtNullCheck, int instance)
-
reportDereference
private static boolean reportDereference(IsNullValue value)
-
isAssertion
private boolean isAssertion(org.apache.bcel.generic.InstructionHandle handle)
Return whether or not given instruction is an assertion.- Parameters:
handle
- the instruction- Returns:
- true if instruction is an assertion, false otherwise
-
copy
public void copy(UnconditionalValueDerefSet source, UnconditionalValueDerefSet dest)
Description copied from interface:DataflowAnalysis
Copy dataflow facts.
-
createFact
public UnconditionalValueDerefSet 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.
-
initEntryFact
public void initEntryFact(UnconditionalValueDerefSet result) throws DataflowAnalysisException
Description copied from interface:DataflowAnalysis
Initialize the "entry" fact for the graph.- Throws:
DataflowAnalysisException
-
makeFactTop
public void makeFactTop(UnconditionalValueDerefSet fact)
Description copied from interface:DataflowAnalysis
Make given fact the top value.
-
isTop
public boolean isTop(UnconditionalValueDerefSet fact)
Description copied from interface:DataflowAnalysis
Is the given fact the top value.
-
meetInto
public void meetInto(UnconditionalValueDerefSet fact, Edge edge, UnconditionalValueDerefSet 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.- Parameters:
fact
- the predecessor fact (incoming edge)edge
- the edge from the predecessorresult
- the result fact- Throws:
DataflowAnalysisException
-
meetInto
public void meetInto(UnconditionalValueDerefSet fact, Edge edge, UnconditionalValueDerefSet result, boolean onlyEdge)
-
propagateDerefSetsToMergeInputValues
private UnconditionalValueDerefSet propagateDerefSetsToMergeInputValues(UnconditionalValueDerefSet fact, Edge edge)
Find out if any VNs in the source block contribute to unconditionally dereferenced VNs in the target block. If so, the VN in the source block is also unconditionally dereferenced, and we must propagate the target VN's dereferences.- Parameters:
fact
- a dataflow valueedge
- edge to check for merge input values- Returns:
- possibly-modified dataflow value
-
duplicateFact
private UnconditionalValueDerefSet duplicateFact(UnconditionalValueDerefSet fact)
Return a duplicate of given dataflow fact.- Parameters:
fact
- a dataflow fact- Returns:
- a duplicate of the input dataflow fact
-
findValueKnownNonnullOnBranch
@CheckForNull private ValueNumber findValueKnownNonnullOnBranch(UnconditionalValueDerefSet fact, Edge edge)
Clear deref sets of values if this edge is the non-null branch of an if comparison.- Parameters:
fact
- a datflow factedge
- edge to check- Returns:
- possibly-modified dataflow fact
-
isExceptionEdge
private boolean isExceptionEdge(Edge edge)
Determine whether dataflow should be propagated on given edge.- Parameters:
edge
- the edge- Returns:
- true if dataflow should be propagated on the edge, false otherwise
-
same
public boolean same(UnconditionalValueDerefSet fact1, UnconditionalValueDerefSet fact2)
Description copied from interface:DataflowAnalysis
Are given dataflow facts the same?
-
startIteration
public void startIteration()
Description copied from interface:DataflowAnalysis
Called before beginning an iteration of analysis. Each iteration visits every basic block in the CFG.- Specified by:
startIteration
in interfaceDataflowAnalysis<UnconditionalValueDerefSet>
- Overrides:
startIteration
in classBasicAbstractDataflowAnalysis<UnconditionalValueDerefSet>
-
getLastUpdateTimestamp
public int getLastUpdateTimestamp(UnconditionalValueDerefSet fact)
- Specified by:
getLastUpdateTimestamp
in interfaceDataflowAnalysis<UnconditionalValueDerefSet>
- Overrides:
getLastUpdateTimestamp
in classBasicAbstractDataflowAnalysis<UnconditionalValueDerefSet>
-
setLastUpdateTimestamp
public void setLastUpdateTimestamp(UnconditionalValueDerefSet fact, int lastUpdate)
- Specified by:
setLastUpdateTimestamp
in interfaceDataflowAnalysis<UnconditionalValueDerefSet>
- Overrides:
setLastUpdateTimestamp
in classBasicAbstractDataflowAnalysis<UnconditionalValueDerefSet>
-
-