changes.
authoryeom <yeom>
Thu, 24 Jun 2010 16:52:25 +0000 (16:52 +0000)
committeryeom <yeom>
Thu, 24 Jun 2010 16:52:25 +0000 (16:52 +0000)
Robust/src/Analysis/Disjoint/EffectSet.java [new file with mode: 0644]
Robust/src/Analysis/Disjoint/EffectsAnalysis.java

diff --git a/Robust/src/Analysis/Disjoint/EffectSet.java b/Robust/src/Analysis/Disjoint/EffectSet.java
new file mode 100644 (file)
index 0000000..cbddc2a
--- /dev/null
@@ -0,0 +1,34 @@
+package Analysis.Disjoint;
+
+import java.util.HashSet;
+import java.util.Hashtable;
+
+import IR.Flat.TempDescriptor;
+
+public class EffectSet {
+
+  private Hashtable<Integer, HashSet<Effect>> methodEffectSet;
+  private Hashtable<TempDescriptor, HashSet<Effect>> rblockEffectSet;
+
+  public EffectSet() {
+    methodEffectSet = new Hashtable<Integer, HashSet<Effect>>();
+  }
+
+  public void addMethodEffect(Integer paramIdx, Effect e) {
+    HashSet<Effect> effectSet = methodEffectSet.get(paramIdx);
+    if (effectSet == null) {
+      effectSet = new HashSet<Effect>();
+    }
+    effectSet.add(e);
+    methodEffectSet.put(paramIdx, effectSet);
+  }
+
+  public String toString() {
+    if (methodEffectSet != null) {
+      return methodEffectSet.toString();
+    } else {
+      return rblockEffectSet.toString();
+    }
+  }
+
+}
index eaef2a764b882e790322dc34d7a54e1caa64eb06..043d6ddee0aa8dc6824e89a83903da4eb8a2bdb8 100644 (file)
@@ -1,17 +1,11 @@
 package Analysis.Disjoint;
 
-import java.io.BufferedWriter;
-import java.io.FileWriter;
-import java.io.IOException;
 import java.util.Hashtable;
 import java.util.Iterator;
-import java.util.Set;
 
 import IR.FieldDescriptor;
-import IR.MethodDescriptor;
-import IR.TypeDescriptor;
 import IR.Flat.FlatCall;
-import IR.Flat.FlatSetElementNode;
+import IR.Flat.FlatMethod;
 import IR.Flat.TempDescriptor;
 
 /////////////////////////////////////////////
@@ -32,136 +26,157 @@ import IR.Flat.TempDescriptor;
 
 public class EffectsAnalysis {
 
-  //private Hashtable<MethodContext, MethodEffects> mapMethodContextToMethodEffects;
-  //   boolean methodeffects = false;
+  private Hashtable<FlatMethod, EffectSet> mapFlatmethodToEffectset;
 
-  public EffectsAnalysis( boolean methodeffects ) {
-    //this.methodeffects = methodeffects;
-    //mapMethodContextToMethodEffects = new Hashtable<MethodContext, MethodEffects>();
+  // private Hashtable<MethodContext, MethodEffects>
+  // mapMethodContextToMethodEffects;
+  // boolean methodeffects = false;
+
+  public EffectsAnalysis(boolean methodeffects) {
+    mapFlatmethodToEffectset = new Hashtable<FlatMethod, EffectSet>();
+  }
+
+  public void analyzeFlatFieldNode(FlatMethod fmContaining, ReachGraph rg, TempDescriptor rhs, FieldDescriptor fld) {
+
+    VariableNode vn = rg.td2vn.get(rhs);
+
+    EffectSet effectSet = mapFlatmethodToEffectset.get(fmContaining);
+    if (effectSet == null) {
+      effectSet = new EffectSet();
+    }
+
+    for (Iterator<RefEdge> iterator = vn.iteratorToReferencees(); iterator.hasNext();) {
+      RefEdge edge = iterator.next();
+      TaintSet taintSet = edge.getTaints();
+      AllocSite affectedAlloc = edge.getDst().getAllocSite();
+      for (Iterator<Taint> taintSetIter = taintSet.iterator(); taintSetIter.hasNext();) {
+        Taint taint = taintSetIter.next();
+
+//        Effect effect = new Effect(taint.getParamIndex(), taint.getAllocSite(), affectedAlloc, Effect.read, fld);
+//        effectSet.addMethodEffect(taint.getParamIndex(), effect);
+
+      }
+    }
+
+    mapFlatmethodToEffectset.put(fmContaining, effectSet);
+
+  }
+
+  public void analyzeFlatSetFieldNode(FlatMethod fmContaining, ReachGraph rg, TempDescriptor lhs, FieldDescriptor fld) {
+
+    VariableNode vn = rg.td2vn.get(lhs);
+
+    EffectSet effectSet = mapFlatmethodToEffectset.get(fmContaining);
+    if (effectSet == null) {
+      effectSet = new EffectSet();
+    }
+
+    for (Iterator<RefEdge> iterator = vn.iteratorToReferencees(); iterator.hasNext();) {
+      RefEdge edge = iterator.next();
+      TaintSet taintSet = edge.getTaints();
+      AllocSite affectedAlloc = edge.getDst().getAllocSite();
+      for (Iterator<Taint> taintSetIter = taintSet.iterator(); taintSetIter.hasNext();) {
+        Taint taint = taintSetIter.next();
+
+//        Effect effect = new Effect(taint.getParamIndex(), taint.getAllocSite(), affectedAlloc, Effect.write, fld);
+//        effectSet.addMethodEffect(taint.getParamIndex(), effect);
+
+      }
+    }
+
+    mapFlatmethodToEffectset.put(fmContaining, effectSet);
+    
+  }
+
+  public EffectSet getEffectSet(FlatMethod fm) {
+    return mapFlatmethodToEffectset.get(fm);
   }
 
   /*
-  public MethodEffects getMethodEffectsByMethodContext(MethodContext mc){
-               return mapMethodContextToMethodEffects.get(mc);
-       }
-
-       public void createNewMapping(MethodContext mcNew) {
-               if(!methodeffects) return;
-               if (!mapMethodContextToMethodEffects.containsKey(mcNew)) {
-                       MethodEffects meNew = new MethodEffects();
-                       mapMethodContextToMethodEffects.put(mcNew, meNew);
-               }
-       }
-  */
+   * public MethodEffects getMethodEffectsByMethodContext(MethodContext mc){
+   * return mapMethodContextToMethodEffects.get(mc); }
+   * 
+   * public void createNewMapping(MethodContext mcNew) { if(!methodeffects)
+   * return; if (!mapMethodContextToMethodEffects.containsKey(mcNew)) {
+   * MethodEffects meNew = new MethodEffects();
+   * mapMethodContextToMethodEffects.put(mcNew, meNew); } }
+   */
 
   /*
-       public void analyzeFlatCall(OwnershipGraph calleeOG,
-                       MethodContext calleeMC, MethodContext callerMC, FlatCall fc) {
-               if(!methodeffects) return;
-               MethodEffects me = mapMethodContextToMethodEffects.get(callerMC);
-               MethodEffects meFlatCall = mapMethodContextToMethodEffects
-                               .get(calleeMC);
-               me.analyzeFlatCall(calleeOG, fc, callerMC, meFlatCall);
-               mapMethodContextToMethodEffects.put(callerMC, me);
-       }
-  */
+   * public void analyzeFlatCall(OwnershipGraph calleeOG, MethodContext
+   * calleeMC, MethodContext callerMC, FlatCall fc) { if(!methodeffects) return;
+   * MethodEffects me = mapMethodContextToMethodEffects.get(callerMC);
+   * MethodEffects meFlatCall = mapMethodContextToMethodEffects .get(calleeMC);
+   * me.analyzeFlatCall(calleeOG, fc, callerMC, meFlatCall);
+   * mapMethodContextToMethodEffects.put(callerMC, me); }
+   */
 
   /*
-       public void analyzeFlatFieldNode(MethodContext mc, OwnershipGraph og,
-                       TempDescriptor srcDesc, FieldDescriptor fieldDesc) {
-               if(!methodeffects) return;
-               MethodEffects me = mapMethodContextToMethodEffects.get(mc);
-               me.analyzeFlatFieldNode(og, srcDesc, fieldDesc);
-               mapMethodContextToMethodEffects.put(mc, me);
-       }
-
-       public void analyzeFlatSetFieldNode(MethodContext mc, OwnershipGraph og,
-                       TempDescriptor dstDesc, FieldDescriptor fieldDesc) {
-               if(!methodeffects) return;
-               MethodEffects me = mapMethodContextToMethodEffects.get(mc);
-               me.analyzeFlatSetFieldNode(og, dstDesc, fieldDesc);
-               mapMethodContextToMethodEffects.put(mc, me);
-       }
-       
-       public void analyzeFlatSetElementNode(MethodContext mc, OwnershipGraph og,
-                       TempDescriptor dstDesc, FieldDescriptor fieldDesc) {
-               if(!methodeffects) return;
-               MethodEffects me = mapMethodContextToMethodEffects.get(mc);
-               me.analyzeFlatSetElementNode(og, dstDesc, fieldDesc);
-               mapMethodContextToMethodEffects.put(mc, me);
-       }
-       
-       public void analyzeFlatElementNode(MethodContext mc, OwnershipGraph og,
-                       TempDescriptor dstDesc, FieldDescriptor fieldDesc) {
-               if(!methodeffects) return;
-               MethodEffects me = mapMethodContextToMethodEffects.get(mc);
-               me.analyzeFlatElementNode(og, dstDesc, fieldDesc);
-               mapMethodContextToMethodEffects.put(mc, me);
-       }
-       
-
-       public void writeMethodEffectsResult() throws IOException {
-
-               try {
-                       BufferedWriter bw = new BufferedWriter(new FileWriter(
-                                       "MethodEffects_report.txt"));
-
-                       Set<MethodContext> mcSet = mapMethodContextToMethodEffects.keySet();
-                       Iterator<MethodContext> mcIter = mcSet.iterator();
-                       while (mcIter.hasNext()) {
-                               MethodContext mc = mcIter.next();
-                               MethodDescriptor md = (MethodDescriptor) mc.getDescriptor();
-
-                               int startIdx = 0;
-                               if (!md.isStatic()) {
-                                       startIdx = 1;
-                               }
-
-                               MethodEffects me = mapMethodContextToMethodEffects.get(mc);
-                               EffectsSet effectsSet = me.getEffects();
-
-                               bw.write("Method " + mc + " :\n");
-                               for (int i = startIdx; i < md.numParameters() + startIdx; i++) {
-
-                                       String paramName = md.getParamName(i - startIdx);
-
-                                       Set<EffectsKey> effectSet = effectsSet.getReadingSet(i);
-                                       String keyStr = "{";
-                                       if (effectSet != null) {
-                                               Iterator<EffectsKey> effectIter = effectSet.iterator();
-                                               while (effectIter.hasNext()) {
-                                                       EffectsKey key = effectIter.next();
-                                                       keyStr += " " + key;
-                                               }
-                                       }
-                                       keyStr += " }";
-                                       bw.write("  Paramter " + paramName + " ReadingSet="
-                                                       + keyStr + "\n");
-
-                                       effectSet = effectsSet.getWritingSet(new Integer(i));
-                                       keyStr = "{";
-                                       if (effectSet != null) {
-                                               Iterator<EffectsKey> effectIter = effectSet.iterator();
-                                               while (effectIter.hasNext()) {
-                                                       EffectsKey key = effectIter.next();
-                                                       keyStr += " " + key;
-                                               }
-                                       }
-
-                                       keyStr += " }";
-                                       bw.write("  Paramter " + paramName + " WritingngSet="
-                                                       + keyStr + "\n");
-
-                               }
-                               bw.write("\n");
-
-                       }
-
-                       bw.close();
-               } catch (IOException e) {
-                       System.err.println(e);
-               }
-
-       }
-  */
+   * public void analyzeFlatFieldNode(MethodContext mc, OwnershipGraph og,
+   * TempDescriptor srcDesc, FieldDescriptor fieldDesc) { if(!methodeffects)
+   * return; MethodEffects me = mapMethodContextToMethodEffects.get(mc);
+   * me.analyzeFlatFieldNode(og, srcDesc, fieldDesc);
+   * mapMethodContextToMethodEffects.put(mc, me); }
+   * 
+   * public void analyzeFlatSetFieldNode(MethodContext mc, OwnershipGraph og,
+   * TempDescriptor dstDesc, FieldDescriptor fieldDesc) { if(!methodeffects)
+   * return; MethodEffects me = mapMethodContextToMethodEffects.get(mc);
+   * me.analyzeFlatSetFieldNode(og, dstDesc, fieldDesc);
+   * mapMethodContextToMethodEffects.put(mc, me); }
+   * 
+   * public void analyzeFlatSetElementNode(MethodContext mc, OwnershipGraph og,
+   * TempDescriptor dstDesc, FieldDescriptor fieldDesc) { if(!methodeffects)
+   * return; MethodEffects me = mapMethodContextToMethodEffects.get(mc);
+   * me.analyzeFlatSetElementNode(og, dstDesc, fieldDesc);
+   * mapMethodContextToMethodEffects.put(mc, me); }
+   * 
+   * public void analyzeFlatElementNode(MethodContext mc, OwnershipGraph og,
+   * TempDescriptor dstDesc, FieldDescriptor fieldDesc) { if(!methodeffects)
+   * return; MethodEffects me = mapMethodContextToMethodEffects.get(mc);
+   * me.analyzeFlatElementNode(og, dstDesc, fieldDesc);
+   * mapMethodContextToMethodEffects.put(mc, me); }
+   * 
+   * 
+   * public void writeMethodEffectsResult() throws IOException {
+   * 
+   * try { BufferedWriter bw = new BufferedWriter(new FileWriter(
+   * "MethodEffects_report.txt"));
+   * 
+   * Set<MethodContext> mcSet = mapMethodContextToMethodEffects.keySet();
+   * Iterator<MethodContext> mcIter = mcSet.iterator(); while (mcIter.hasNext())
+   * { MethodContext mc = mcIter.next(); MethodDescriptor md =
+   * (MethodDescriptor) mc.getDescriptor();
+   * 
+   * int startIdx = 0; if (!md.isStatic()) { startIdx = 1; }
+   * 
+   * MethodEffects me = mapMethodContextToMethodEffects.get(mc); EffectsSet
+   * effectsSet = me.getEffects();
+   * 
+   * bw.write("Method " + mc + " :\n"); for (int i = startIdx; i <
+   * md.numParameters() + startIdx; i++) {
+   * 
+   * String paramName = md.getParamName(i - startIdx);
+   * 
+   * Set<EffectsKey> effectSet = effectsSet.getReadingSet(i); String keyStr =
+   * "{"; if (effectSet != null) { Iterator<EffectsKey> effectIter =
+   * effectSet.iterator(); while (effectIter.hasNext()) { EffectsKey key =
+   * effectIter.next(); keyStr += " " + key; } } keyStr += " }";
+   * bw.write("  Paramter " + paramName + " ReadingSet=" + keyStr + "\n");
+   * 
+   * effectSet = effectsSet.getWritingSet(new Integer(i)); keyStr = "{"; if
+   * (effectSet != null) { Iterator<EffectsKey> effectIter =
+   * effectSet.iterator(); while (effectIter.hasNext()) { EffectsKey key =
+   * effectIter.next(); keyStr += " " + key; } }
+   * 
+   * keyStr += " }"; bw.write("  Paramter " + paramName + " WritingngSet=" +
+   * keyStr + "\n");
+   * 
+   * } bw.write("\n");
+   * 
+   * }
+   * 
+   * bw.close(); } catch (IOException e) { System.err.println(e); }
+   * 
+   * }
+   */
 }