1 19 20 package soot.jimple.spark.fieldrw; 21 import soot.tagkit.*; 22 import soot.*; 23 import soot.util.*; 24 import java.util.*; 25 import soot.toolkits.graph.*; 26 import soot.jimple.toolkits.callgraph.*; 27 import soot.jimple.*; 28 import java.io.*; 29 30 public class FieldTagger extends BodyTransformer 31 { 32 public FieldTagger( Singletons.Global g ) {} 33 public static FieldTagger v() { return G.v().soot_jimple_spark_fieldrw_FieldTagger(); } 34 35 private HashSet processedMethods = new HashSet(); 36 private HashMultiMap methodToWrite = new HashMultiMap(); 37 private HashMultiMap methodToRead = new HashMultiMap(); 38 39 protected void ensureProcessed( SootMethod m ) { 40 if( processedMethods.contains(m) ) return; 41 processedMethods.add(m); 42 if( !m.isConcrete() ) return; 43 if( m.isPhantom() ) return; 44 for( Iterator sIt = m.retrieveActiveBody().getUnits().iterator(); sIt.hasNext(); ) { 45 final Stmt s = (Stmt) sIt.next(); 46 if( s instanceof AssignStmt ) { 47 AssignStmt as = (AssignStmt) s; 48 Value l = as.getLeftOp(); 49 if( l instanceof FieldRef ) { 50 methodToWrite.put( m, ((FieldRef) l).getField() ); 51 } 52 Value r = as.getRightOp(); 53 if( r instanceof FieldRef ) { 54 methodToRead.put( m, ((FieldRef) r).getField() ); 55 } 56 } 57 } 58 } 59 protected void internalTransform(Body body, String phaseName, Map options) 60 { 61 int threshold = PhaseOptions.getInt( options, "threshold" ); 62 63 ensureProcessed( body.getMethod() ); 64 65 CallGraph cg = Scene.v().getCallGraph(); 66 TransitiveTargets tt = new TransitiveTargets( cg ); 67 statement: for( Iterator sIt = body.getUnits().iterator(); sIt.hasNext(); ) { final Stmt s = (Stmt) sIt.next(); 68 HashSet read = new HashSet(); 69 HashSet write = new HashSet(); 70 Iterator it = tt.iterator( s ); 71 while( it.hasNext() ) { 72 SootMethod target = (SootMethod) it.next(); 73 ensureProcessed( target ); 74 if( target.isNative() ) continue statement; 75 if( target.isPhantom() ) continue statement; 76 read.addAll( methodToRead.get( target ) ); 77 write.addAll( methodToWrite.get( target ) ); 78 if( read.size() + write.size() > threshold ) { 79 continue statement; 80 } 81 } 82 s.addTag( new FieldReadTag( read ) ); 83 s.addTag( new FieldWriteTag( write ) ); 84 } 85 } 86 } 87 88 89 | Popular Tags |