| 1 19 20 package soot.jimple.toolkits.pointer; 21 import soot.tagkit.*; 22 import soot.*; 23 import java.util.*; 24 import soot.toolkits.graph.*; 25 import soot.jimple.toolkits.callgraph.*; 26 import soot.jimple.*; 27 import java.io.*; 28 29 public class FieldRWTagger extends BodyTransformer 30 { 31 public FieldRWTagger( Singletons.Global g ) {} 32 public static FieldRWTagger v() { return G.v().soot_jimple_toolkits_pointer_FieldRWTagger(); } 33 34 public int numRWs = 0; 35 public int numWRs = 0; 36 public int numRRs = 0; 37 public int numWWs = 0; 38 public int numNatives = 0; 39 public Date startTime = null; 40 boolean optionDontTag = false; 41 boolean optionNaive = false; 42 private CallGraph cg; 43 44 protected class UniqueRWSets { 45 protected ArrayList l = new ArrayList(); 46 RWSet getUnique( RWSet s ) { 47 if( s == null ) return s; 48 for( Iterator retIt = l.iterator(); retIt.hasNext(); ) { 49 final RWSet ret = (RWSet) retIt.next(); 50 if( ret.isEquivTo( s ) ) return ret; 51 } 52 l.add( s ); 53 return s; 54 } 55 Iterator iterator() { 56 return l.iterator(); 57 } 58 short indexOf( RWSet s ) { 59 short i = 0; 60 for( Iterator retIt = l.iterator(); retIt.hasNext(); ) { 61 final RWSet ret = (RWSet) retIt.next(); 62 if( ret.isEquivTo( s ) ) return i; 63 i++; 64 } 65 return -1; 66 } 67 } 68 69 protected void initializationStuff( String phaseName ) { 70 if( G.v().Union_factory == null ) { 71 G.v().Union_factory = new UnionFactory() { 72 public Union newUnion() { return FullObjectSet.v(); } 73 }; 74 } 75 if( startTime == null ) { 76 startTime = new Date(); 77 } 78 cg = Scene.v().getCallGraph(); 79 } 80 protected Object keyFor( Stmt s ) { 81 if( s.containsInvokeExpr() ) { 82 if( optionNaive ) throw new RuntimeException ( "shouldn't get here" ); 83 Iterator it = cg.edgesOutOf( s ); 84 if( !it.hasNext() ) { 85 return Collections.EMPTY_LIST; 86 } 87 ArrayList ret = new ArrayList(); 88 while( it.hasNext() ) { 89 ret.add( it.next() ); 90 } 91 return ret; 92 } else { 93 return s; 94 } 95 } 96 protected void internalTransform(Body body, String phaseName, Map options) 97 { 98 initializationStuff( phaseName ); 99 SideEffectAnalysis sea = new SideEffectAnalysis( 100 DumbPointerAnalysis.v(), Scene.v().getCallGraph() ); 101 sea.findNTRWSets( body.getMethod() ); 102 HashMap stmtToReadSet = new HashMap(); 103 HashMap stmtToWriteSet = new HashMap(); 104 UniqueRWSets sets = new UniqueRWSets(); 105 optionDontTag = PhaseOptions.getBoolean( options, "dont-tag" ); 106 boolean justDoTotallyConservativeThing = 107 body.getMethod().getName().equals( "<clinit>" ); 108 for( Iterator stmtIt = body.getUnits().iterator(); stmtIt.hasNext(); ) { 109 final Stmt stmt = (Stmt) stmtIt.next(); 110 if( !stmt.containsInvokeExpr() ) continue; 111 if( justDoTotallyConservativeThing ) { 112 stmtToReadSet.put( stmt, sets.getUnique( new FullRWSet() ) ); 113 stmtToWriteSet.put( stmt, sets.getUnique( new FullRWSet() ) ); 114 continue; 115 } 116 Object key = keyFor( stmt ); 117 if( !stmtToReadSet.containsKey( key ) ) { 118 stmtToReadSet.put( key, 119 sets.getUnique( sea.readSet( body.getMethod(), stmt ) ) ); 120 stmtToWriteSet.put( key, 121 sets.getUnique( sea.writeSet( body.getMethod(), stmt ) ) ); 122 } 123 } 124 190 } 191 } 192 193 194 | Popular Tags |