soot.jimple.toolkits.annotation.nullcheck
Class NullnessAnalysis

java.lang.Object
  extended bysoot.toolkits.scalar.AbstractFlowAnalysis
      extended bysoot.toolkits.scalar.BranchedFlowAnalysis
          extended bysoot.toolkits.scalar.ForwardBranchedFlowAnalysis
              extended bysoot.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

Nested Class Summary
protected static 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 Object BOTTOM
           
protected static Object NON_NULL
           
protected static Object NULL
           
protected static Object TOP
           
 
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. 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.
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
customizeInitialFlowGraph, getFlowBefore, merge, 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 Object BOTTOM

NULL

protected static final Object NULL

NON_NULL

protected static final Object NON_NULL

TOP

protected static final Object TOP
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