KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > dava > toolkits > base > misc > MonitorConverter


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 Jerome Miecznikowski
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.dava.toolkits.base.misc;
21
22 import soot.*;
23 import soot.util.*;
24 import java.util.*;
25 import soot.dava.*;
26 import soot.jimple.*;
27 import soot.grimp.internal.*;
28 import soot.dava.internal.asg.*;
29 import soot.dava.internal.javaRep.*;
30
31 public class MonitorConverter
32 {
33     public MonitorConverter( Singletons.Global g )
34     {
35     SootClass davaMonitor = new SootClass(
36                 "soot.dava.toolkits.base.DavaMonitor.DavaMonitor",
37                 Modifier.PUBLIC );
38         davaMonitor.setSuperclass(
39                 Scene.v().loadClassAndSupport("java.lang.Object"));
40
41         LinkedList objectSingleton = new LinkedList();
42         objectSingleton.add( RefType.v("java.lang.Object") );
43     v = new SootMethod(
44                 "v",
45                 new LinkedList(),
46                 RefType.v("soot.dava.toolkits.base.DavaMonitor.DavaMonitor"),
47                 Modifier.PUBLIC | Modifier.STATIC );
48     enter = new SootMethod(
49                 "enter",
50                 objectSingleton,
51                 VoidType.v(),
52                 Modifier.PUBLIC | Modifier.SYNCHRONIZED );
53     exit = new SootMethod(
54                 "exit",
55                 objectSingleton,
56                 VoidType.v(),
57                 Modifier.PUBLIC | Modifier.SYNCHRONIZED );
58         davaMonitor.addMethod( v );
59         davaMonitor.addMethod( enter );
60         davaMonitor.addMethod( exit );
61
62         Scene.v().addClass( davaMonitor );
63     }
64
65     public static MonitorConverter v() { return G.v().soot_dava_toolkits_base_misc_MonitorConverter(); }
66
67     private SootMethod v, enter, exit;
68
69     public void convert( DavaBody body)
70     {
71     Iterator mfit = body.get_MonitorFacts().iterator();
72     while (mfit.hasNext()) {
73         AugmentedStmt mas = (AugmentedStmt) mfit.next();
74         MonitorStmt ms = (MonitorStmt) mas.get_Stmt();
75
76         body.addPackage( "soot.dava.toolkits.base.DavaMonitor");
77         
78         ArrayList arg = new ArrayList();
79         arg.add( ms.getOp());
80
81         if (ms instanceof EnterMonitorStmt)
82         mas.set_Stmt( new GInvokeStmt( new DVirtualInvokeExpr( new DStaticInvokeExpr( v.makeRef(), new ArrayList()), enter.makeRef(), arg, new HashSet())));
83         else
84         mas.set_Stmt( new GInvokeStmt( new DVirtualInvokeExpr( new DStaticInvokeExpr( v.makeRef(), new ArrayList()), exit.makeRef(), arg, new HashSet())));
85     }
86     }
87 }
88
Popular Tags