soot.jimple.toolkits.annotation.nullcheck
Class NullnessAssumptionAnalysis

java.lang.Object
  extended by soot.toolkits.scalar.AbstractFlowAnalysis<N,A>
      extended by soot.toolkits.scalar.FlowAnalysis<N,A>
          extended by soot.toolkits.scalar.BackwardFlowAnalysis
              extended by soot.jimple.toolkits.annotation.nullcheck.NullnessAssumptionAnalysis

public class NullnessAssumptionAnalysis
extends BackwardFlowAnalysis

An intraprocedural nullness assumption analysis that computes for each location and each value in a method if the value (before or after that location) is treated as definetely null, definetely non-null or neither. This information could be useful in deciding whether or not to insert code that accesses a potentially null object. If the original program assumes a value is non-null, then adding a use of that value will not introduce any NEW nullness errors into the program. This code may be buggy, or just plain wrong. It has not been checked.

Author:
Richard L. Halpert Adapted from Eric Bodden's NullnessAnalysis

Nested Class Summary
protected static class NullnessAssumptionAnalysis.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.FlowAnalysis
filterUnitToAfterFlow, unitToAfterFlow
 
Fields inherited from class soot.toolkits.scalar.AbstractFlowAnalysis
filterUnitToBeforeFlow, graph, unitToBeforeFlow
 
Constructor Summary
NullnessAssumptionAnalysis(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 inValue, Object unit, Object outValue)
          Given the merge of the out sets, compute the in set for s (or in to out, depending on direction).
protected  boolean isAlwaysNonNull(Value v)
          This can be overridden by sublasses to mark a certain value as constantly non-null.
 boolean isAssumedNonNullBefore(Unit s, Immediate i)
          Returns true if the analysis could determine that i is always treated as non-null after and including the statement s.
 boolean isAssumedNullBefore(Unit s, Immediate i)
          Returns true if the analysis could determine that i is always treated as null after and including 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.BackwardFlowAnalysis
constructWorklist, doAnalysis, isForward
 
Methods inherited from class soot.toolkits.scalar.FlowAnalysis
constructOrderer, getFlowAfter
 
Methods inherited from class soot.toolkits.scalar.AbstractFlowAnalysis
getFlowBefore, 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 Object BOTTOM

NULL

protected static final Object NULL

NON_NULL

protected static final Object NON_NULL

TOP

protected static final Object TOP
Constructor Detail

NullnessAssumptionAnalysis

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

Parameters:
graph - any unit graph
Method Detail

flowThrough

protected void flowThrough(Object inValue,
                           Object unit,
                           Object outValue)
Given the merge of the out sets, compute the in set for s (or in to out, depending on direction). This function often causes confusion, because the same interface is used for both forward and backward flow analyses. The first parameter is always the argument to the flow function (i.e. it is the "in" set in a forward analysis and the "out" set in a backward analysis), and the third parameter is always the result of the flow function (i.e. it is the "out" set in a forward analysis and the "in" set in a backward analysis).

Specified by:
flowThrough in class FlowAnalysis

isAlwaysNonNull

protected boolean isAlwaysNonNull(Value v)
This can be overridden 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

isAssumedNullBefore

public boolean isAssumedNullBefore(Unit s,
                                   Immediate i)
Returns true if the analysis could determine that i is always treated as null after and including 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

isAssumedNonNullBefore

public boolean isAssumedNonNullBefore(Unit s,
                                      Immediate i)
Returns true if the analysis could determine that i is always treated as non-null after and including 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