edu.umd.cs.findbugs.ba
Class IsNullValueAnalysis

java.lang.Object
  extended by edu.umd.cs.findbugs.ba.AbstractDataflowAnalysis<Fact>
      extended by edu.umd.cs.findbugs.ba.ForwardDataflowAnalysis<FrameType>
          extended by edu.umd.cs.findbugs.ba.FrameDataflowAnalysis<IsNullValue,IsNullValueFrame>
              extended by edu.umd.cs.findbugs.ba.IsNullValueAnalysis
All Implemented Interfaces:
DataflowAnalysis<IsNullValueFrame>, EdgeTypes

public class IsNullValueAnalysis
extends FrameDataflowAnalysis<IsNullValue,IsNullValueFrame>
implements EdgeTypes

A dataflow analysis to detect potential null pointer dereferences.

Author:
David Hovemeyer
See Also:
IsNullValue, IsNullValueFrame, IsNullValueFrameModelingVisitor

Field Summary
private static boolean DEBUG
           
private  IsNullValueFrame lastFrame
           
private  org.apache.bcel.generic.MethodGen methodGen
           
private static boolean NO_SPLIT_DOWNGRADE_NSP
           
private static boolean NO_SWITCH_DEFAULT_AS_EXCEPTION
           
private static java.util.BitSet nullComparisonInstructionSet
           
private  int[] numNonExceptionSuccessorMap
           
(package private) static boolean UNKNOWN_VALUES_ARE_NSP
          If this property is true, then we assume parameters and return values can be null (but aren't definitely null).
private  IsNullValueFrameModelingVisitor visitor
           
private  ValueNumberDataflow vnaDataflow
           
 
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
IsNullValueAnalysis(org.apache.bcel.generic.MethodGen methodGen, CFG cfg, ValueNumberDataflow vnaDataflow, DepthFirstSearch dfs, AssertionMethods assertionMethods)
           
 
Method Summary
 IsNullValueFrame createFact()
          Create empty (uninitialized) dataflow facts for one program point.
 void endTransfer(BasicBlock basicBlock, org.apache.bcel.generic.InstructionHandle end, java.lang.Object result_)
          Subclasses may override this.
private  IsNullConditionDecision getDecision(BasicBlock basicBlock, IsNullValueFrame lastFrame)
          Determine if the given basic block ends in a redundant null comparison.
 void initEntryFact(IsNullValueFrame result)
          Initialize the "entry" fact for the graph.
static void main(java.lang.String[] argv)
          Test driver.
 void meetInto(IsNullValueFrame fact, Edge edge, IsNullValueFrame result)
          Meet a dataflow fact associated with an incoming edge into another fact.
protected  IsNullValue mergeValues(IsNullValueFrame frame, int slot, IsNullValue a, IsNullValue b)
          Merge two values in a particular slot of a Frame.
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.
 void startTransfer(BasicBlock basicBlock, java.lang.Object start_)
          Subclasses may override this.
 void transferInstruction(org.apache.bcel.generic.InstructionHandle handle, BasicBlock basicBlock, IsNullValueFrame fact)
          Transfer function for a single instruction.
 
Methods inherited from class edu.umd.cs.findbugs.ba.FrameDataflowAnalysis
copy, initResultFact, isFactValid, makeFactTop, mergeInto, modifyFrame, same
 
Methods inherited from class edu.umd.cs.findbugs.ba.ForwardDataflowAnalysis
getBlockOrder, getDepthFirstSearch, isForwards
 
Methods inherited from class edu.umd.cs.findbugs.ba.AbstractDataflowAnalysis
factToString, getFactAfterLocation, getFactAtLocation, getResultFact, getStartFact, resultFactIterator, transfer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG

private static final boolean DEBUG

NO_SPLIT_DOWNGRADE_NSP

private static final boolean NO_SPLIT_DOWNGRADE_NSP

NO_SWITCH_DEFAULT_AS_EXCEPTION

private static final boolean NO_SWITCH_DEFAULT_AS_EXCEPTION

UNKNOWN_VALUES_ARE_NSP

static final boolean UNKNOWN_VALUES_ARE_NSP
If this property is true, then we assume parameters and return values can be null (but aren't definitely null).


methodGen

private org.apache.bcel.generic.MethodGen methodGen

visitor

private IsNullValueFrameModelingVisitor visitor

vnaDataflow

private ValueNumberDataflow vnaDataflow

numNonExceptionSuccessorMap

private int[] numNonExceptionSuccessorMap

lastFrame

private IsNullValueFrame lastFrame

nullComparisonInstructionSet

private static final java.util.BitSet nullComparisonInstructionSet
Constructor Detail

IsNullValueAnalysis

public IsNullValueAnalysis(org.apache.bcel.generic.MethodGen methodGen,
                           CFG cfg,
                           ValueNumberDataflow vnaDataflow,
                           DepthFirstSearch dfs,
                           AssertionMethods assertionMethods)
Method Detail

createFact

public IsNullValueFrame 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 interface DataflowAnalysis<IsNullValueFrame>

initEntryFact

public void initEntryFact(IsNullValueFrame result)
Description copied from interface: DataflowAnalysis
Initialize the "entry" fact for the graph.

Specified by:
initEntryFact in interface DataflowAnalysis<IsNullValueFrame>

startTransfer

public void startTransfer(BasicBlock basicBlock,
                          java.lang.Object start_)
                   throws DataflowAnalysisException
Description copied from class: AbstractDataflowAnalysis
Subclasses may override this. Due to a bug in the 2.2 version of the generics-enabled javac, it is not possible to directly override the transfer() method. This method will be called immediately upon entry to transfer().

Overrides:
startTransfer in class AbstractDataflowAnalysis<IsNullValueFrame>
Parameters:
basicBlock - the basic block
start_ - the start fact for the block
Throws:
DataflowAnalysisException

endTransfer

public void endTransfer(BasicBlock basicBlock,
                        org.apache.bcel.generic.InstructionHandle end,
                        java.lang.Object result_)
                 throws DataflowAnalysisException
Description copied from class: AbstractDataflowAnalysis
Subclasses may override this. Due to a bug in the 2.2 version of the generics-enabled javac, it is not possible to directly override the transfer() method. This method will be called just before exiting transfer().

Overrides:
endTransfer in class AbstractDataflowAnalysis<IsNullValueFrame>
Parameters:
basicBlock - the basic block
end - last instruction analyzed (null if entire block was analyzed)
result_ - the result fact for the block
Throws:
DataflowAnalysisException

transferInstruction

public void transferInstruction(org.apache.bcel.generic.InstructionHandle handle,
                                BasicBlock basicBlock,
                                IsNullValueFrame fact)
                         throws DataflowAnalysisException
Description copied from class: AbstractDataflowAnalysis
Transfer function for a single instruction.

Specified by:
transferInstruction in class AbstractDataflowAnalysis<IsNullValueFrame>
Parameters:
handle - the instruction
basicBlock - the BasicBlock containing the instruction; needed to disambiguate instructions in inlined JSR subroutines
fact - 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: 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 interface DataflowAnalysis<IsNullValueFrame>
Parameters:
fact - the predecessor fact (incoming edge)
edge - the edge from the predecessor
result - the result fact
Throws:
DataflowAnalysisException

mergeValues

protected IsNullValue mergeValues(IsNullValueFrame frame,
                                  int slot,
                                  IsNullValue a,
                                  IsNullValue b)
                           throws DataflowAnalysisException
Description copied from class: FrameDataflowAnalysis
Merge two values in a particular slot of a Frame.

Specified by:
mergeValues in class FrameDataflowAnalysis<IsNullValue,IsNullValueFrame>
Parameters:
frame - the Frame
slot - the slot of the Frame
a - a value
b - another value
Returns:
the merged value
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 block
lastFrame - 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

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 block
frame - the modified version of the is-null entry frame; null if the entry frame has not been modified yet
replaceMe - the ValueNumber in the value number frame at the if comparison whose is-null information will be updated
prevVnaFrame - the ValueNumberFrame at the if comparison
targetVnaFrame - the ValueNumberFrame at entry to the basic block
replacementValue - the IsNullValue representing the updated is-null information
Returns:
a modified IsNullValueFrame with updated is-null information

main

public static void main(java.lang.String[] argv)
                 throws java.lang.Exception
Test driver.

Throws:
java.lang.Exception