KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > toolkits > annotation > purity > PurityAnalysis


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2005 Antoine Mine
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

19
20 /**
21  * Implementation of the paper "A Combined Pointer and Purity Analysis for
22  * Java Programs" by Alexandru Salcianu and Martin Rinard, within the
23  * Soot Optimization Framework.
24  *
25  * by Antoine Mine, 2005/01/24
26  */

27
28
29 package soot.jimple.toolkits.annotation.purity;
30 import java.util.*;
31 import soot.*;
32 import soot.util.*;
33 import soot.jimple.*;
34 import soot.jimple.toolkits.callgraph.*;
35 import soot.options.PurityOptions;
36
37 /**
38  * Purity analysis phase.
39  */

40
41 /**
42  * TODO:
43  * - test, test, and test (and correct the potentially infinite bugs)
44  * - optimise PurityGraph, especially methodCall)
45  * - find a better abstraction for exceptions (throw & catch)
46  * - output nicer graphs (especially clusters!)
47  */

48
49 public class PurityAnalysis extends SceneTransformer
50 {
51     Singletons.Global g;
52
53     public PurityAnalysis(Singletons.Global g ) { this.g = g; }
54
55     public static PurityAnalysis v()
56     {
57     return G.v().soot_jimple_toolkits_annotation_purity_PurityAnalysis();
58     }
59
60     protected void internalTransform(String JavaDoc phaseName, Map options)
61     {
62     PurityOptions opts = new PurityOptions(options);
63
64     G.v().out.println("[AM] Analysing purity");
65
66     CallGraph cg = Scene.v().getCallGraph();
67
68     // Find main methods
69
List heads = new LinkedList();
70     Iterator getClassesIt = Scene.v().getApplicationClasses().iterator();
71     while (getClassesIt.hasNext()) {
72         SootClass appClass = (SootClass)getClassesIt.next();
73         Iterator getMethodsIt = appClass.getMethods().iterator();
74         while (getMethodsIt.hasNext()) {
75         SootMethod method = (SootMethod) getMethodsIt.next();
76         if (method.getName().equals("main")) {
77             heads.add(method);
78             G.v().out.println(" |- will treat "+appClass.getName()+
79                       "."+method.getName());
80         }
81         }
82     }
83
84     // launch the analysis
85
PurityInterproceduralAnalysis p =
86         new PurityInterproceduralAnalysis(cg, heads.iterator(), opts);
87     }
88 }
89
Popular Tags