Class IsNullValueAnalysis
java.lang.Object
edu.umd.cs.findbugs.ba.BasicAbstractDataflowAnalysis<IsNullValueFrame>
edu.umd.cs.findbugs.ba.AbstractDataflowAnalysis<IsNullValueFrame>
edu.umd.cs.findbugs.ba.ForwardDataflowAnalysis<IsNullValueFrame>
edu.umd.cs.findbugs.ba.FrameDataflowAnalysis<IsNullValue, IsNullValueFrame>
edu.umd.cs.findbugs.ba.npe.IsNullValueAnalysis
- All Implemented Interfaces:
DataflowAnalysis<IsNullValueFrame>, EdgeTypes, IsNullValueAnalysisFeatures
public class IsNullValueAnalysis
extends FrameDataflowAnalysis<IsNullValue, IsNullValueFrame>
implements EdgeTypes, IsNullValueAnalysisFeatures
A dataflow analysis to detect potential null pointer dereferences.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class(package private) static enum -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate IsNullValueFrameprivate final CFGprivate JavaClassAndMethod(package private) static final booleanprivate IsNullValueFrameprivate IsNullValueFrameprivate final Set<LocationWhereValueBecomesNull> private final org.apache.bcel.generic.MethodGenprivate static final BitSetprivate final IsNullValueAnalysis.PointerEqualityCheckprivate final booleanprivate final IsNullValueFrameModelingVisitorprivate final ValueNumberDataflowFields 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_EDGEFields inherited from interface IsNullValueAnalysisFeatures
NCP_EXTRA_BRANCH, NO_SPLIT_DOWNGRADE_NSP, NO_SWITCH_DEFAULT_AS_EXCEPTION, UNKNOWN_VALUES_ARE_NSP, USE_TYPE_QUALIFIERS -
Constructor Summary
ConstructorsConstructorDescriptionIsNullValueAnalysis(MethodDescriptor descriptor, org.apache.bcel.generic.MethodGen methodGen, CFG cfg, ValueNumberDataflow vnaDataflow, TypeDataflow typeDataflow, DepthFirstSearch dfs, AssertionMethods assertionMethods) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLocationWhereValueBecomesNull(LocationWhereValueBecomesNull locationWhereValueBecomesNull) Create empty (uninitialized) dataflow facts for one program point.voidendTransfer(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle end, IsNullValueFrame result) private IsNullConditionDecisiongetDecision(BasicBlock basicBlock, IsNullValueFrame lastFrame) Determine if the given basic block ends in a redundant null comparison.getFactAtMidEdge(Edge edge) getForPointerEqualityCheck(CFG cfg, ValueNumberDataflow vna) private ValueNumbergetKnownNonnullDueToPointerDisequality(ValueNumber knownNull, int pc) private IsNullConditionDecisionhandleIfNull(IsNullValue tos, ValueNumber prevTopValue, boolean ifnull) voidinitEntryFact(IsNullValueFrame result) Initialize the "entry" fact for the graph.voidmeetInto(IsNullValueFrame fact, Edge edge, IsNullValueFrame result) Meet a dataflow fact associated with an incoming edge into another fact.voidmeetInto(IsNullValueFrame fact, Edge edge, IsNullValueFrame result, boolean propagatePhiNodeInformation) protected voidmergeInto(IsNullValueFrame other, IsNullValueFrame result) Merge one frame into another.protected voidmergeValues(IsNullValueFrame otherFrame, IsNullValueFrame resultFrame, int slot) Merge the values contained in a given slot of two Frames.private IsNullValueFramereplaceValues(IsNullValueFrame origFrame, IsNullValueFrame frame, ValueNumber replaceMe, ValueNumberFrame prevVnaFrame, ValueNumberFrame targetVnaFrame, IsNullValue replacementValue) Update is-null information at a branch target based on information gained at a null comparison branch.voidsetClassAndMethod(JavaClassAndMethod classAndMethod) voidCalled before beginning an iteration of analysis.voidvoidtransfer(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle end, IsNullValueFrame start, IsNullValueFrame result) Transfer function for the analysis.voidtransferInstruction(org.apache.bcel.generic.InstructionHandle handle, BasicBlock basicBlock, IsNullValueFrame fact) Transfer function for a single instruction.Methods inherited from class FrameDataflowAnalysis
copy, getFactAtPC, getFactBeforeExceptionCheck, getLastUpdateTimestamp, isFactValid, isTop, makeFactTop, modifyFrame, same, 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
-
Field Details
-
DEBUG
static final boolean DEBUG -
methodGen
private final org.apache.bcel.generic.MethodGen methodGen -
visitor
-
vnaDataflow
-
cfg
-
locationWhereValueBecomesNullSet
-
trackValueNumbers
private final boolean trackValueNumbers -
lastFrame
-
instanceOfFrame
-
cachedEntryFact
-
classAndMethod
-
pointerEqualityCheck
-
nullComparisonInstructionSet
-
-
Constructor Details
-
IsNullValueAnalysis
public IsNullValueAnalysis(MethodDescriptor descriptor, org.apache.bcel.generic.MethodGen methodGen, CFG cfg, ValueNumberDataflow vnaDataflow, TypeDataflow typeDataflow, DepthFirstSearch dfs, AssertionMethods assertionMethods)
-
-
Method Details
-
getForPointerEqualityCheck
@CheckForNull public static IsNullValueAnalysis.PointerEqualityCheck getForPointerEqualityCheck(CFG cfg, ValueNumberDataflow vna) -
getKnownNonnullDueToPointerDisequality
@CheckForNull private ValueNumber getKnownNonnullDueToPointerDisequality(ValueNumber knownNull, int pc) -
setClassAndMethod
-
getClassAndMethod
-
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<IsNullValueFrame>
-
initEntryFact
Description copied from interface:DataflowAnalysisInitialize the "entry" fact for the graph.- Specified by:
initEntryFactin interfaceDataflowAnalysis<IsNullValueFrame>
-
transfer
public void transfer(BasicBlock basicBlock, @CheckForNull org.apache.bcel.generic.InstructionHandle end, IsNullValueFrame start, IsNullValueFrame 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<IsNullValueFrame>- Overrides:
transferin classAbstractDataflowAnalysis<IsNullValueFrame>- 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
-
startTransfer
public void startTransfer() -
endTransfer
public void endTransfer(BasicBlock basicBlock, @CheckForNull org.apache.bcel.generic.InstructionHandle end, IsNullValueFrame result) throws DataflowAnalysisException - Throws:
DataflowAnalysisException
-
transferInstruction
public void transferInstruction(org.apache.bcel.generic.InstructionHandle handle, BasicBlock basicBlock, IsNullValueFrame fact) throws DataflowAnalysisException Description copied from class:AbstractDataflowAnalysisTransfer function for a single instruction.- Specified by:
transferInstructionin classAbstractDataflowAnalysis<IsNullValueFrame>- 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
-
meetInto
public void meetInto(IsNullValueFrame fact, Edge edge, IsNullValueFrame result) throws DataflowAnalysisException 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<IsNullValueFrame>- Parameters:
fact- the predecessor fact (incoming edge)edge- the edge from the predecessorresult- the result fact- Throws:
DataflowAnalysisException
-
meetInto
public void meetInto(IsNullValueFrame fact, Edge edge, IsNullValueFrame result, boolean propagatePhiNodeInformation) throws DataflowAnalysisException - Throws:
DataflowAnalysisException
-
mergeInto
protected void mergeInto(IsNullValueFrame other, IsNullValueFrame result) throws DataflowAnalysisException Description copied from class:FrameDataflowAnalysisMerge one frame into another.- Overrides:
mergeIntoin classFrameDataflowAnalysis<IsNullValue, IsNullValueFrame>- Parameters:
other- the frame to merge with the resultresult- the result frame, which is modified to be the merge of the two frames- Throws:
DataflowAnalysisException
-
startIteration
public void startIteration()Description copied from interface:DataflowAnalysisCalled before beginning an iteration of analysis. Each iteration visits every basic block in the CFG.- Specified by:
startIterationin interfaceDataflowAnalysis<IsNullValueFrame>- Overrides:
startIterationin classBasicAbstractDataflowAnalysis<IsNullValueFrame>
-
addLocationWhereValueBecomesNull
public void addLocationWhereValueBecomesNull(LocationWhereValueBecomesNull locationWhereValueBecomesNull) -
getLocationWhereValueBecomesNullSet
-
mergeValues
protected void mergeValues(IsNullValueFrame otherFrame, IsNullValueFrame resultFrame, int slot) throws DataflowAnalysisException Description copied from class:FrameDataflowAnalysisMerge the values contained in a given slot of two Frames.- Specified by:
mergeValuesin classFrameDataflowAnalysis<IsNullValue, IsNullValueFrame>- Parameters:
otherFrame- a FrameresultFrame- a Frame which will contain the resulting merged valueslot- a slot in both frames- Throws:
DataflowAnalysisException
-
getDecision
private IsNullConditionDecision getDecision(BasicBlock basicBlock, IsNullValueFrame lastFrame) throws DataflowAnalysisException Determine if the given basic block ends in a redundant null comparison.- Parameters:
basicBlock- the basic blocklastFrame- the IsNullValueFrame representing values at the final instruction of the block- Returns:
- an IsNullConditionDecision object representing the is-null information gained about the compared value, or null if no information is gained
- Throws:
DataflowAnalysisException
-
handleIfNull
private IsNullConditionDecision handleIfNull(IsNullValue tos, ValueNumber prevTopValue, boolean ifnull) -
replaceValues
private IsNullValueFrame replaceValues(IsNullValueFrame origFrame, IsNullValueFrame frame, ValueNumber replaceMe, ValueNumberFrame prevVnaFrame, ValueNumberFrame targetVnaFrame, IsNullValue replacementValue) Update is-null information at a branch target based on information gained at a null comparison branch.- Parameters:
origFrame- the original is-null frame at entry to basic blockframe- the modified version of the is-null entry frame; null if the entry frame has not been modified yetreplaceMe- the ValueNumber in the value number frame at the if comparison whose is-null information will be updatedprevVnaFrame- the ValueNumberFrame at the if comparisontargetVnaFrame- the ValueNumberFrame at entry to the basic blockreplacementValue- the IsNullValue representing the updated is-null information- Returns:
- a modified IsNullValueFrame with updated is-null information
-
getFactAtMidEdge
- Throws:
DataflowAnalysisException
-