soot.jimple.toolkits.annotation.nullcheck
Class NullnessAnalysis

java.lang.Object
  extended by soot.toolkits.scalar.AbstractFlowAnalysis<N,A>
      extended by soot.toolkits.scalar.BranchedFlowAnalysis<Unit,A>
          extended by soot.toolkits.scalar.ForwardBranchedFlowAnalysis
              extended by soot.jimple.toolkits.annotation.nullcheck.NullnessAnalysis

public class NullnessAnalysis
extends ForwardBranchedFlowAnalysis

An intraprocedural nullness analysis that computes for each location and each value in a method if the value is (before or after that location) definetely null, definetely non-null or neither. This class replaces BranchedRefVarsAnalysis which is known to have bugs.

Author:
Eric Bodden, Julian Tibble

Nested Class Summary
protected  class NullnessAnalysis.AnalysisInfo
          The analysis info is a simple mapping of type Value to any of the constants BOTTOM, NON_NULL, NULL or TOP.
 
Field Summary
protected static int BOTTOM
           
protected static int NON_NULL
           
protected static int NULL
           
protected static int TOP
           
protected  int used
           
protected  HashMap<Value,Integer> valueToIndex
           
 
Fields inherited from class soot.toolkits.scalar.BranchedFlowAnalysis
unitToAfterBranchFlow, unitToAfterFallFlow
 
Fields inherited from class soot.toolkits.scalar.AbstractFlowAnalysis
filterUnitToBeforeFlow, graph, unitToBeforeFlow
 
Constructor Summary
NullnessAnalysis(UnitGraph graph)
          Creates a new analysis for the given graph/
 
Method Summary
protected  void copy(Object source, Object dest)
          Creates a copy of the source flow object in dest.
protected  Object entryInitialFlow()
          Returns the initial flow value for entry/exit graph nodes.
protected  void flowThrough(Object flowin, Unit u, List fallOut, List branchOuts)
          Given the merge of the in sets, compute the fallOut and branchOuts set for s.
protected  boolean isAlwaysNonNull(Value v)
          This can be overwritten by sublasses to mark a certain value as constantly non-null.
 boolean isAlwaysNonNullBefore(Unit s, Immediate i)
          Returns true if the analysis could determine that i is always non-null before the statement s.
 boolean isAlwaysNullBefore(Unit s, Immediate i)
          Returns true if the analysis could determine that i is always null before the statement s.
protected  void merge(Object in1, Object in2, Object out)
          Compute the merge of the in1 and in2 sets, putting the result into out.
protected  Object newInitialFlow()
          Returns the flow object corresponding to the initial values for each graph node.
 
Methods inherited from class soot.toolkits.scalar.ForwardBranchedFlowAnalysis
doAnalysis, isForward
 
Methods inherited from class soot.toolkits.scalar.BranchedFlowAnalysis
getBranchFlowAfter, getFallFlowAfter, getFlowBefore
 
Methods inherited from class soot.toolkits.scalar.AbstractFlowAnalysis
merge, mergeInto, treatTrapHandlersAsEntries
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BOTTOM

protected static final int BOTTOM
See Also:
Constant Field Values

NULL

protected static final int NULL
See Also:
Constant Field Values

NON_NULL

protected static final int NON_NULL
See Also:
Constant Field Values

TOP

protected static final int TOP
See Also:
Constant Field Values

valueToIndex

protected final HashMap<Value,Integer> valueToIndex

used

protected int used
Constructor Detail

NullnessAnalysis

public NullnessAnalysis(UnitGraph graph)
Creates a new analysis for the given graph/

Parameters:
graph - any unit graph
Method Detail

flowThrough

protected void flowThrough(Object flowin,
                           Unit u,
                           List fallOut,
                           List branchOuts)
Given the merge of the in sets, compute the fallOut and branchOuts set for s.

Specified by:
flowThrough in class BranchedFlowAnalysis

isAlwaysNonNull

protected boolean isAlwaysNonNull(Value v)
This can be overwritten by sublasses to mark a certain value as constantly non-null.

Parameters:
v - any value
Returns:
true if it is known that this value (e.g. a method return value) is never null

copy

protected void copy(Object source,
                    Object dest)
Creates a copy of the source flow object in dest.

Specified by:
copy in class AbstractFlowAnalysis

entryInitialFlow

protected Object entryInitialFlow()
Returns the initial flow value for entry/exit graph nodes.

Specified by:
entryInitialFlow in class AbstractFlowAnalysis

merge

protected void merge(Object in1,
                     Object in2,
                     Object out)
Compute the merge of the in1 and in2 sets, putting the result into out. The behavior of this function depends on the implementation ( it may be necessary to check whether in1 and in2 are equal or aliased ). Used by the doAnalysis method.

Specified by:
merge in class AbstractFlowAnalysis

newInitialFlow

protected Object newInitialFlow()
Returns the flow object corresponding to the initial values for each graph node.

Specified by:
newInitialFlow in class AbstractFlowAnalysis

isAlwaysNullBefore

public boolean isAlwaysNullBefore(Unit s,
                                  Immediate i)
Returns true if the analysis could determine that i is always null before the statement s.

Parameters:
s - a statement of the respective body
i - a local or constant of that body
Returns:
true if i is always null right before this statement

isAlwaysNonNullBefore

public boolean isAlwaysNonNullBefore(Unit s,
                                     Immediate i)
Returns true if the analysis could determine that i is always non-null before the statement s.

Parameters:
s - a statement of the respective body
i - a local of that body
Returns:
true if i is always non-null right before this statement