KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > toolkits > callgraph > ClinitElimAnalysis


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Jennifer Lhotak
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 package soot.jimple.toolkits.callgraph;
21
22 import soot.*;
23 import soot.util.*;
24 import java.util.*;
25 import soot.jimple.*;
26 import soot.toolkits.graph.*;
27 import soot.toolkits.scalar.*;
28
29 public class ClinitElimAnalysis extends ForwardFlowAnalysis {
30     
31     private UnitGraph g;
32
33     public ClinitElimAnalysis(UnitGraph g) {
34         super(g);
35         this.g = g;
36
37         doAnalysis();
38     }
39
40     public void merge(Object JavaDoc in1, Object JavaDoc in2, Object JavaDoc out) {
41         
42         FlowSet inSet1 = (FlowSet) in1;
43         FlowSet inSet2 = (FlowSet) in2;
44         FlowSet outSet = (FlowSet) out;
45
46         inSet1.intersection(inSet2, outSet);
47     }
48
49     public void copy(Object JavaDoc src, Object JavaDoc dest) {
50         
51         FlowSet srcIn = (FlowSet) src;
52         FlowSet destOut = (FlowSet) dest;
53
54         srcIn.copy(destOut);
55     }
56
57     
58     // out(s) = in(s) intersect { target methods of s where edge kind is clinit}
59
protected void flowThrough(Object JavaDoc inVal, Object JavaDoc stmt, Object JavaDoc outVal) {
60         FlowSet in = (FlowSet) inVal;
61         FlowSet out = (FlowSet) outVal;
62         Stmt s = (Stmt) stmt;
63         
64         in.copy(out);
65
66         CallGraph cg = Scene.v().getCallGraph();
67
68         Iterator edges = cg.edgesOutOf(s);
69
70         while (edges.hasNext()){
71             Edge e = (Edge)edges.next();
72             if (e.isClinit()) {
73                 out.add(e.tgt());
74             }
75         }
76     }
77
78     protected Object JavaDoc entryInitialFlow(){
79         
80         return new ArraySparseSet();
81         
82         
83     }
84
85     protected Object JavaDoc newInitialFlow(){
86         ArraySparseSet set = new ArraySparseSet();
87         CallGraph cg = Scene.v().getCallGraph();
88
89         Iterator mIt = cg.edgesOutOf(g.getBody().getMethod());
90         while (mIt.hasNext()){
91             Edge edge = (Edge)mIt.next();
92             if (edge.isClinit()){
93                 set.add(edge.tgt());
94             }
95         }
96
97         return set;
98     }
99 }
100
Popular Tags