Patch in effects analysis hooks....have to add new accessor methods...add interface...
authorbdemsky <bdemsky>
Fri, 18 Mar 2011 05:23:19 +0000 (05:23 +0000)
committerbdemsky <bdemsky>
Fri, 18 Mar 2011 05:23:19 +0000 (05:23 +0000)
Robust/src/Analysis/Disjoint/Alloc.java
Robust/src/Analysis/Disjoint/AllocSite.java
Robust/src/Analysis/Disjoint/Effect.java
Robust/src/Analysis/Disjoint/EffectsAnalysis.java
Robust/src/Analysis/Pointer/AllocFactory.java
Robust/src/Analysis/Pointer/Edge.java
Robust/src/Analysis/Pointer/GraphManip.java
Robust/src/Analysis/Pointer/Pointer.java

index 5ad2fc65edfc1e5a7e619902f369fad50abb0e22..42206ca7264cda461880d336429f730fa0d77474 100644 (file)
@@ -1,6 +1,8 @@
 package Analysis.Disjoint;
+import IR.Flat.FlatNew;
 
 public interface Alloc {
-  
+  public FlatNew getFlatNew();
   public String toStringBrief();
+  public int getUniqueAllocSiteID();
 }
\ No newline at end of file
index 282162cfcb595fcdaef93891d1fd16d6880c381e..f5e1ca34d80cac51b28cbf12d269af99da00e95f 100644 (file)
@@ -23,7 +23,7 @@ import java.util.*;
 // are Canonical, but specifically so an AllocSite can
 // be an operand to a CanonicalOp
 
-public class AllocSite extends Canonical {
+public class AllocSite extends Canonical implements Alloc {
 
   static protected int uniqueIDcount = 0;
 
index 658c648283f02ac389bfd0c4ed37e53463c85ca3..7084b869b1a2ac5bbdc13453202053f9dc123261 100644 (file)
@@ -11,7 +11,7 @@ public class Effect {
   public static final int strongupdate = 3;
 
   // identify an allocation site of affected object
-  protected AllocSite affectedAllocSite;
+  protected Alloc affectedAllocSite;
 
   // identify operation type
   protected int type;
@@ -19,17 +19,17 @@ public class Effect {
   // identify a field
   protected FieldDescriptor field;
 
-  public Effect(AllocSite affectedAS, int type, FieldDescriptor field) {
+  public Effect(Alloc affectedAS, int type, FieldDescriptor field) {
     this.affectedAllocSite = affectedAS;
     this.type = type;
     this.field = field;
   }
 
-  public AllocSite getAffectedAllocSite() {
+  public Alloc getAffectedAllocSite() {
     return affectedAllocSite;
   }
 
-  public void setAffectedAllocSite(AllocSite affectedAllocSite) {
+  public void setAffectedAllocSite(Alloc affectedAllocSite) {
     this.affectedAllocSite = affectedAllocSite;
   }
 
index bb1331164151c6e445264beeaf860ef365a6c620..07abff412bdf388b351eb5f63bcaa11fb554b475 100644 (file)
@@ -6,6 +6,7 @@ import java.io.*;
 
 import IR.*;
 import IR.Flat.*;
+import Analysis.Pointer.Edge;
 
 /////////////////////////////////////////////
 // 
@@ -144,6 +145,19 @@ public class EffectsAnalysis {
     }
   }
 
+  public void analyzeFlatFieldNode(Set<Edge> sources, FieldDescriptor fld, FlatNode currentProgramPoint) {
+    for (Edge edge:sources) {
+      TaintSet  taintSet      = edge.getTaints();
+      Alloc     affectedAlloc = edge.getDst();
+      Effect    effect        = new Effect(affectedAlloc, Effect.read, fld);
+
+      for (Iterator<Taint> taintSetIter = taintSet.iterator(); taintSetIter.hasNext();) {
+        Taint taint = taintSetIter.next();        
+        add(taint, effect, currentProgramPoint);
+      }
+    }
+  }
+
   public void analyzeFlatSetFieldNode(ReachGraph rg, TempDescriptor lhs, FieldDescriptor fld, FlatNode currentProgramPoint, boolean strongUpdate) {
 
     VariableNode vn = rg.td2vn.get(lhs);
@@ -174,6 +188,20 @@ public class EffectsAnalysis {
   }
 
 
+  public void analyzeFlatSetFieldNode(Set<Edge> dstedges, FieldDescriptor fld, FlatNode currentProgramPoint) {
+
+    for (Edge edge:dstedges) {
+      TaintSet  taintSet      = edge.getTaints();
+      Alloc affectedAlloc = edge.getDst();
+      Effect    effect        = new Effect(affectedAlloc, Effect.write, fld);       
+      for (Iterator<Taint> taintSetIter = taintSet.iterator(); taintSetIter.hasNext();) {
+        Taint taint = taintSetIter.next();
+        add( taint, effect, currentProgramPoint );
+      }
+    }
+  }
+
+
   public String toString() {
     return taint2effects.toString();    
   }
index 7a281315cb09bd9c3db97a3adbe67150d87363d8..f55ad02a513b08366c9c7f35146b7896484fb79c 100644 (file)
@@ -1,23 +1,32 @@
 package Analysis.Pointer;
 
+import Analysis.Disjoint.Alloc;
 import java.util.*;
 import IR.*;
 import IR.Flat.*;
 
 public class AllocFactory {
-  public static class AllocNode {
+  public static class AllocNode implements Alloc {
     int allocsite;
     boolean summary;
-    TypeDescriptor type;
+    FlatNew node;
     
-    public AllocNode(int allocsite, TypeDescriptor type, boolean summary) {
+    public AllocNode(int allocsite, FlatNew node, boolean summary) {
       this.allocsite=allocsite;
       this.summary=summary;
-      this.type=type;
+      this.node=node;
     }
 
     public TypeDescriptor getType() {
-      return type;
+      return node.getType();
+    }
+
+    public FlatNew getFlatNew() {
+      return node;
+    }
+
+    public int getUniqueAllocSiteID() {
+      return allocsite;
     }
 
     public boolean isSummary() {
@@ -36,6 +45,10 @@ public class AllocFactory {
       return false;
     }
 
+    public String toStringBrief() {
+      return getID();
+    }
+    
     public String toString() {
       return getID();
     }
@@ -55,8 +68,8 @@ public class AllocFactory {
     ClassDescriptor stringcd=typeUtil.getClass(TypeUtil.StringClass);
     TypeDescriptor stringtd=new TypeDescriptor(stringcd);
     TypeDescriptor stringarraytd=stringtd.makeArray(state);
-    StringArray=new AllocNode(0, stringarraytd, false);
-    Strings=new AllocNode(1, stringtd, true);
+    StringArray=new AllocNode(0, new FlatNew(stringarraytd, null, false), false);
+    Strings=new AllocNode(1, new FlatNew(stringtd, null, false), true);
   }
 
   public int getSiteNumber(FlatNew node) {
@@ -69,7 +82,7 @@ public class AllocFactory {
 
   public AllocNode getAllocNode(FlatNew node, boolean isSummary) {
     int site=getSiteNumber(node);
-    AllocNode key=new AllocNode(site, node.getType(), isSummary);
+    AllocNode key=new AllocNode(site, node, isSummary);
     if (!allocNodeMap.containsKey(key)) {
       allocNodeMap.put(key, key);
       return key;
@@ -79,7 +92,7 @@ public class AllocFactory {
 
   public AllocNode getAllocNode(AllocNode node, boolean isSummary) {
     int site=node.allocsite;
-    AllocNode key=new AllocNode(site, node.getType(), isSummary);
+    AllocNode key=new AllocNode(site, node.node, isSummary);
     if (!allocNodeMap.containsKey(key)) {
       allocNodeMap.put(key, key);
       return key;
index 4100d5009c6f164d7ce2ddacb8cd18f3a20fceea..21c27b932c794f11def31544d0869b360d829be6 100644 (file)
@@ -61,6 +61,10 @@ public class Edge {
     this.dst=dst;
   }
   
+  public AllocNode getDst() {
+    return dst;
+  }
+
   public int hashCode() {
     int hashcode=dst.hashCode();
     if (fd!=null) {
index d36617f014521782a9eedcdacc7fa13cc8dbaed9..b5a1aa083092032272f32349b577aa8066a5c15d 100644 (file)
@@ -33,6 +33,16 @@ public class GraphManip {
     return edgeset;
   }
 
+  static MySet<Edge> genEdges(MySet<Edge> srcSet, FieldDescriptor fd, MySet<Edge> dstSet) {
+    MySet<Edge> edgeset=new MySet<Edge>();
+    for(Edge srcedge:srcSet) {
+      for(Edge dstedge:dstSet) {
+       edgeset.add(dstedge.changeSrc(fd, srcedge.dst));
+      }
+    }
+    return edgeset;
+  }
+
   static MySet<Edge> genEdges(HashSet<AllocNode> srcSet, FieldDescriptor fd, MySet<Edge> dstSet) {
     MySet<Edge> edgeset=new MySet<Edge>();
     for(AllocNode srcnode:srcSet) {
@@ -76,6 +86,23 @@ public class GraphManip {
     return edges;
   }
 
+  static MySet<Edge> getEdges(Graph graph, Delta delta, MySet<Edge> srcNodes, FieldDescriptor fd) {
+    MySet<Edge> nodes=new MySet<Edge>();
+    for(Edge node:srcNodes) {
+      MySet<Edge> removeedges=delta.heapedgeremove.get(node.dst);
+      for(Edge e:graph.getEdges(node.dst)) {
+       if (e.fd==fd&&(removeedges==null||!removeedges.contains(e)))
+         nodes.add(e);
+      }
+      if (delta.heapedgeadd.containsKey(node.dst))
+       for(Edge e:delta.heapedgeadd.get(node.dst)) {
+         if (e.fd==fd)
+           nodes.add(e);
+       }
+    }
+    return nodes;
+  }
+
   static MySet<Edge> getEdges(Graph graph, Delta delta, HashSet<AllocNode> srcNodes, FieldDescriptor fd) {
     MySet<Edge> nodes=new MySet<Edge>();
     for(AllocNode node:srcNodes) {
@@ -184,7 +211,6 @@ public class GraphManip {
     return newedges;
   }
 
-
   static MySet<Edge> getDiffEdges(Delta delta, HashSet<AllocNode> srcNodes, FieldDescriptor fd) {
     MySet<Edge> newedges=new MySet<Edge>();
     for(Map.Entry<AllocNode, MySet<Edge>> entry:delta.baseheapedge.entrySet()) {
index 932c4b9ac4aa1e948a0fe4252e9b5e68a87d193b..607812bcbd331c16d446d26c996802418d7031f9 100644 (file)
@@ -10,6 +10,8 @@ import Analysis.Disjoint.TaintSet;
 import Analysis.Disjoint.Canonical;
 import Analysis.CallGraph.CallGraph;
 import Analysis.OoOJava.RBlockRelationAnalysis;
+import Analysis.Disjoint.EffectsAnalysis;
+import Analysis.Disjoint.BuildStateMachines;
 import java.io.*;
 
 
@@ -29,12 +31,17 @@ public class Pointer {
   LinkedList<Delta> toprocess;
   TempDescriptor returntmp;
   RBlockRelationAnalysis taskAnalysis;
+  EffectsAnalysis effectsAnalysis;
+  BuildStateMachines buildStateMachines;
 
   public Pointer(State state, TypeUtil typeUtil, CallGraph callGraph, RBlockRelationAnalysis taskAnalysis) {
     this(state, typeUtil);
     this.callGraph=callGraph;
     this.OoOJava=true;
     this.taskAnalysis=taskAnalysis;
+    this.effectsAnalysis=new EffectsAnalysis();
+    effectsAnalysis.state=state;
+    effectsAnalysis.buildStateMachines=new BuildStateMachines();
   }
 
   public Pointer(State state, TypeUtil typeUtil) {
@@ -1271,15 +1278,20 @@ public class Pointer {
 
     if (delta.getInit()) {
       MySet<Edge> srcEdges=GraphManip.getEdges(graph, delta, src);
-      HashSet<AllocNode> dstNodes=GraphManip.getNodes(graph, delta, dst);
-      MySet<Edge> edgesToAdd=GraphManip.genEdges(dstNodes, fd, srcEdges);
+      MySet<Edge> dstEdges=GraphManip.getEdges(graph, delta, dst);
+      MySet<Edge> edgesToAdd=GraphManip.genEdges(dstEdges, fd, srcEdges);
       MySet<Edge> edgesToRemove=null;
-      if (dstNodes.size()==1&&!dstNodes.iterator().next().isSummary()&&fd!=null) {
+      if (dstEdges.size()==1&&!dstEdges.iterator().next().dst.isSummary()&&fd!=null) {
        /* Can do a strong update */
-       edgesToRemove=GraphManip.getEdges(graph, delta, dstNodes, fd);
+       edgesToRemove=GraphManip.getEdges(graph, delta, dstEdges, fd);
        graph.strongUpdateSet=edgesToRemove;
       } else
        graph.strongUpdateSet=new MySet<Edge>();
+
+      if (OoOJava) {
+       effectsAnalysis.analyzeFlatSetFieldNode(dstEdges, fd, node);
+      }
+
       /* Update diff */
       updateHeapDelta(graph, delta, edgesToAdd, edgesToRemove);
       applyDiffs(graph, delta);
@@ -1289,22 +1301,25 @@ public class Pointer {
       MySet<Edge> newSrcEdges=GraphManip.getDiffEdges(delta, src);
       MySet<Edge> srcEdges=GraphManip.getEdges(graph, delta, src);
       HashSet<AllocNode> dstNodes=GraphManip.getNodes(graph, delta, dst);
-      HashSet<AllocNode> newDstNodes=GraphManip.getDiffNodes(delta, dst);
+      MySet<Edge> newDstEdges=GraphManip.getDiffEdges(delta, dst);
 
+      if (OoOJava) {
+       effectsAnalysis.analyzeFlatSetFieldNode(newDstEdges, fd, node);
+      }
 
       MySet<Edge> edgesToRemove=null;
-      if (newDstNodes.size()!=0) {
+      if (newDstEdges.size()!=0) {
        if (dstNodes.size()>1&&!dstNodes.iterator().next().isSummary()&&fd!=null) {
          /* Need to undo strong update */
          if (graph.strongUpdateSet!=null) {
            edgesToAdd.addAll(graph.strongUpdateSet);
            graph.strongUpdateSet=null; //Prevent future strong updates
          }
-       } else if (dstNodes.size()==1&&newDstNodes.size()==1&&!newDstNodes.iterator().next().isSummary()&&graph.strongUpdateSet!=null&&fd!=null) {
+       } else if (dstNodes.size()==1&&newDstEdges.size()==1&&!newDstEdges.iterator().next().dst.isSummary()&&graph.strongUpdateSet!=null&&fd!=null) {
          edgesToRemove=GraphManip.getEdges(graph, delta, dstNodes, fd);
          graph.strongUpdateSet.addAll(edgesToRemove);
        }
-       Edge.mergeEdgesInto(edgesToAdd, GraphManip.genEdges(newDstNodes, fd, srcEdges));
+       Edge.mergeEdgesInto(edgesToAdd, GraphManip.genEdges(newDstEdges, fd, srcEdges));
       }
 
       //Kill new edges
@@ -1399,6 +1414,9 @@ public class Pointer {
       MySet<Edge> srcedges=GraphManip.getEdges(graph, delta, src);
       MySet<Edge> edgesToAdd=GraphManip.dereference(graph, delta, dst, srcedges, fd, node, taint);
       MySet<Edge> edgesToRemove=GraphManip.getEdges(graph, delta, dst);
+      if (OoOJava)
+       effectsAnalysis.analyzeFlatFieldNode(srcedges, fd, node);
+
       updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
       applyDiffs(graph, delta);
     } else {
@@ -1415,10 +1433,14 @@ public class Pointer {
       /* Compute set of edges to remove */
       MySet<Edge> edgesToRemove=GraphManip.getDiffEdges(delta, dst);      
 
+      if (OoOJava)
+       effectsAnalysis.analyzeFlatFieldNode(newsrcedges, fd, node);
+      
       /* Update diff */
       updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
       applyDiffs(graph, delta);
     }
+
     return delta;
   }