soot.jimple.toolkits.annotation.purity
Class AbstractInterproceduralAnalysis

java.lang.Object
  extended by soot.jimple.toolkits.annotation.purity.AbstractInterproceduralAnalysis
Direct Known Subclasses:
PurityInterproceduralAnalysis

public abstract class AbstractInterproceduralAnalysis
extends Object

Inter-procedural iterator skeleton for summary-based analysis A "summary" is an abstract element associated to each method that fully models the effect of calling the method. In a summary-based analysis, the summary of a method can be computed using solely the summary of all methods it calls: the summary does not depend upon the context in which a method is called. The inter-procedural analysis interacts with a intra-procedural analysis that is able to compute the summary of one method, given the summary of all the method it calls. The inter-procedural analysis calls the intra-procedural analysis in a reverse topological order of method dependencies to resolve unknown summaries. It iterates over recursively dependant methods. Generally, the intra-procedural works by maintaining an abstract value that represent the effect of the method from its entry point and up to the current point. At the entry point, this value is empty. The summary of the method is then the merge of the abstract values at all its return points. You can provide off-the-shelf summaries for methods you do not which to analyse. Any method using these "filtered-out" methods will use the off-the-shelf summary instead of performing an intra-procedural analysis. This is useful for native methods, incremental analysis, or when you hand-made summary. Methods that are called solely by filtered-out ones will never be analysed, effectively triming the call-graph dependencies. This class tries to use the same abstract methods and data managnment policy as regular FlowAnalysis classes.


Field Summary
protected  CallGraph cg
           
protected  Map data
           
protected  DirectedGraph dg
           
static boolean doCheck
           
protected  Map<Object,Integer> order
           
protected  Map unanalysed
           
 
Constructor Summary
AbstractInterproceduralAnalysis(CallGraph cg, SootMethodFilter filter, Iterator heads, boolean verbose)
          The constructor performs some preprocessing, but you have to call doAnalysis to preform the real stuff.
 
Method Summary
protected  void analyseCall(Object src, Stmt callStmt, Object dst)
          Analyse the call callStmt in the context src, and put the resul into dst.
protected abstract  void analyseMethod(SootMethod method, Object dst)
          Compute the summary for a method by analysing its body.
protected abstract  void applySummary(Object src, Stmt callStmt, Object summary, Object dst)
          Interprocedural analysis will call applySummary repeatidly as a consequence to analyseCall.
protected abstract  void copy(Object sr, Object dst)
          Copy src into dst.
protected  void doAnalysis(boolean verbose)
          Carry out the analysis.
 void drawAsManyDot(String prefix, boolean drawUnanalysed)
          Dump the each summary computed by the interprocedural analysis as a seperate graph.
 void drawAsOneDot(String name)
          Dump the interprocedural analysis result as a graph.
protected  void fillDotGraph(String prefix, Object o, DotGraph out)
          Called by drawAsOneDot to fill dot subgraph out with the contents of summary o.
 Iterator getAnalysedMethods()
          Get an iterator over the list of SootMethod with an associated summary.
 Object getSummaryFor(SootMethod m)
          Query the analysis result.
protected abstract  void merge(Object in1, Object in2, Object out)
          Merge in1 and in2 into out.
protected abstract  Object newInitialSummary()
          Initial summary value for analysed funtions.
protected abstract  Object summaryOfUnanalysedMethod(SootMethod method)
          Whenever the analyse requires the summary of a method you filtered-out, this function is called instead of analyseMethod.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

doCheck

public static final boolean doCheck
See Also:
Constant Field Values

cg

protected CallGraph cg

dg

protected DirectedGraph dg

data

protected Map data

order

protected Map<Object,Integer> order

unanalysed

protected Map unanalysed
Constructor Detail

AbstractInterproceduralAnalysis

public AbstractInterproceduralAnalysis(CallGraph cg,
                                       SootMethodFilter filter,
                                       Iterator heads,
                                       boolean verbose)
The constructor performs some preprocessing, but you have to call doAnalysis to preform the real stuff.

Method Detail

newInitialSummary

protected abstract Object newInitialSummary()
Initial summary value for analysed funtions.


summaryOfUnanalysedMethod

protected abstract Object summaryOfUnanalysedMethod(SootMethod method)
Whenever the analyse requires the summary of a method you filtered-out, this function is called instead of analyseMethod.

Note: This function is called at most once per filtered-out method. It is the equivalent of entryInitialFlow!


analyseMethod

protected abstract void analyseMethod(SootMethod method,
                                      Object dst)
Compute the summary for a method by analysing its body. Will be called only on methods not filtered-out.

Parameters:
method - is the method to be analysed
dst - is where to put the computed method summary

applySummary

protected abstract void applySummary(Object src,
                                     Stmt callStmt,
                                     Object summary,
                                     Object dst)
Interprocedural analysis will call applySummary repeatidly as a consequence to analyseCall. Once for each possible target method of the callStmt statement, provided with its summary.

Parameters:
src - summary valid before the call statement
callStmt - a statement containing a InvokeStmt or InvokeExpr
summary - summary of the possible target of callStmt considered here
dst - where to put the result
See Also:
analyseCall

merge

protected abstract void merge(Object in1,
                              Object in2,
                              Object out)
Merge in1 and in2 into out.

Note: in1 or in2 can be aliased to out (e.g., analyseCall).


copy

protected abstract void copy(Object sr,
                             Object dst)
Copy src into dst.


fillDotGraph

protected void fillDotGraph(String prefix,
                            Object o,
                            DotGraph out)
Called by drawAsOneDot to fill dot subgraph out with the contents of summary o.

Parameters:
prefix - gives you a unique string to prefix your node names and avoid name-clash

analyseCall

protected void analyseCall(Object src,
                           Stmt callStmt,
                           Object dst)
Analyse the call callStmt in the context src, and put the resul into dst. This will repeatidly calling summaryOfUnanalysedMethod and applySummary, and then merging the results using merge.

See Also:
summaryOfUnanalysedMethod, applySummary

drawAsOneDot

public void drawAsOneDot(String name)
Dump the interprocedural analysis result as a graph. One node / subgraph for each analysed method that contains the method summary, and call-to edges.

Note: this graph does not show filtered-out methods for which a conservative summary was asked via summaryOfUnanalysedMethod.

Parameters:
name - output filename
See Also:
fillDotGraph

drawAsManyDot

public void drawAsManyDot(String prefix,
                          boolean drawUnanalysed)
Dump the each summary computed by the interprocedural analysis as a seperate graph.

Parameters:
prefix - is prepended before method name in output filename
drawUnanalysed - do you also want info for the unanalysed methods required by the analysis via summaryOfUnanalysedMethod ?
See Also:
fillDotGraph

getSummaryFor

public Object getSummaryFor(SootMethod m)
Query the analysis result.


getAnalysedMethods

public Iterator getAnalysedMethods()
Get an iterator over the list of SootMethod with an associated summary. (Does not contain filtered-out or native methods.)


doAnalysis

protected void doAnalysis(boolean verbose)
Carry out the analysis. Call this from your InterproceduralAnalysis constructor, just after super(cg). Then , you will be able to call drawAsDot, for instance.