1 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 |