bug fixes...
authorbdemsky <bdemsky>
Thu, 10 Mar 2011 07:40:55 +0000 (07:40 +0000)
committerbdemsky <bdemsky>
Thu, 10 Mar 2011 07:40:55 +0000 (07:40 +0000)
Robust/src/Analysis/Pointer/Delta.java
Robust/src/Analysis/Pointer/Graph.java
Robust/src/Analysis/Pointer/MySet.java
Robust/src/Analysis/Pointer/Pointer.java

index 9419412b60ae0047a07dc053414b7862b696a253..7c3e37b756a3d9b8270f3e5b633af99d11a5bb8f 100644 (file)
@@ -16,6 +16,16 @@ public class Delta {
   HashMap<AllocNode, Boolean> baseOldNodes;
   HashMap<AllocNode, Boolean> addOldNodes;
 
+  public Delta check() {
+    for(Map.Entry<AllocNode, MySet<Edge>> entry:heapedgeadd.entrySet()) {
+      AllocNode node=entry.getKey();
+      for(Edge e:entry.getValue())
+       if (e.src!=node)
+         throw new Error(e.src+" is not equal to "+node);
+    }
+    return this;
+  }
+
 
   boolean init;
   PPoint block;
index 55ecd9afd59db416d34b61f21b3eead3aab8963d..265153c969691109e56e87492b70eb87cd54be39 100644 (file)
@@ -15,6 +15,21 @@ public class Graph {
   HashMap<AllocNode, MySet<Edge>> backMap;
   MySet<Edge> strongUpdateSet;
 
+  public void check() {
+    for(Map.Entry<AllocNode, MySet<Edge>> entry:nodeMap.entrySet()) {
+      AllocNode node=entry.getKey();
+      for(Edge e:entry.getValue())
+       if (e.src!=node)
+         throw new Error();
+    }
+    for(Map.Entry<TempDescriptor, MySet<Edge>> entry:varMap.entrySet()) {
+      TempDescriptor tmp=entry.getKey();
+      for(Edge e:entry.getValue())
+       if (e.srcvar!=tmp)
+         throw new Error();
+    }
+  }
+
   /* Need this information for mapping in callee results */
   MySet<Edge> reachEdge;
   HashSet<AllocNode> reachNode;
@@ -61,8 +76,6 @@ public class Graph {
     }
   }
   
-  
-
   public MySet<Edge> getEdges(TempDescriptor tmp) {
     if (varMap.containsKey(tmp))
       return varMap.get(tmp);
@@ -79,7 +92,7 @@ public class Graph {
     else return emptySet;
   }
 
-  public static MySet<Edge> emptySet=new MySet<Edge>();
+  public static MySet<Edge> emptySet=new MySet<Edge>(true);
 
   public void printGraph(PrintWriter output, String name) {
     output.println("digraph \""+name+"\" {");
@@ -101,6 +114,8 @@ public class Graph {
       if (childvarMap!=null&&childvarMap.containsKey(tmp))
        continue;
       for(Edge e:entry.getValue()) {
+       if (e.srcvar!=tmp)
+         throw new Error(e.srcvar +" is not equal to "+tmp);
        AllocNode n=e.dst;
        output.println("\t"+tmp.getSymbol()+"->"+n.getID()+";");
       }
@@ -114,6 +129,8 @@ public class Graph {
       if (childNodeMap!=null&&childNodeMap.containsKey(node))
        continue;
       for(Edge e:entry.getValue()) {
+       if (e.src!=node)
+         throw new Error(e.src+" is not equal to "+node);
        AllocNode n=e.dst;
        String src=node.getID();
        String dst=n.getID();
index 7e1400b9b5dfde0e85dc8581f4ae75f2f14680c0..a3d523bf21fde0291e9f9eb421c80f5c9677abf1 100644 (file)
@@ -3,6 +3,12 @@ import java.util.*;
 
 public class MySet<T> extends AbstractSet<T> {
   HashMap<T,T> map;
+  boolean locked;
+  public MySet(boolean locked) {
+    this.locked=locked;
+    map=new HashMap<T,T>();
+  }
+
   public MySet() {
     map=new HashMap<T,T>();
   }
@@ -27,10 +33,14 @@ public class MySet<T> extends AbstractSet<T> {
   }
 
   public boolean remove(Object obj) {
+    if (locked)
+      throw new Error();
     return map.remove(obj)!=null; 
   }
   
   public boolean add(T obj) {
+    if (locked)
+      throw new Error();
     return map.put(obj, obj)==null;
   }
 
index 4afeae91e9b977f58265ef40d07775caedb85c88..102e2ab8df2c980076beee8b067c977d45b89000 100644 (file)
@@ -112,7 +112,9 @@ public class Pointer {
       }
       debugindex++;
     }
-
+    for(FlatMethod fm:blockMap.keySet()) {
+      fm.printMethod();
+    }
   }
 
   /* This function builds the last delta for a basic block.  It
@@ -247,7 +249,8 @@ public class Pointer {
          newDelta.setBlock(new PPoint(blockvector.get(i)));
          toprocess.add(newDelta);
        } else {
-         toprocess.add(newDelta.diffBlock(new PPoint(blockvector.get(i))));
+         Delta d=newDelta.diffBlock(new PPoint(blockvector.get(i)));
+         toprocess.add(d);
        }
       }
     }
@@ -857,7 +860,9 @@ public class Pointer {
       if (srcNodes.size()==1&&!srcNodes.iterator().next().isSummary()) {
        /* Can do a strong update */
        edgesToRemove=GraphManip.getEdges(graph, delta, srcNodes, fd);
-      }
+       graph.strongUpdateSet=edgesToRemove;
+      } else
+       graph.strongUpdateSet=new MySet<Edge>();
       /* Update diff */
       updateHeapDelta(graph, delta, edgesToAdd, edgesToRemove);
       applyDiffs(graph, delta);
@@ -872,18 +877,29 @@ public class Pointer {
 
       MySet<Edge> edgesToRemove=null;
       if (newSrcNodes.size()!=0) {
-       if (srcNodes.size()==1&&!srcNodes.iterator().next().isSummary()) {
+       if (srcNodes.size()>1&&!srcNodes.iterator().next().isSummary()) {
          /* Need to undo strong update */
          if (graph.strongUpdateSet!=null) {
            edgesToAdd.addAll(graph.strongUpdateSet);
-           graph.strongUpdateSet.clear();
+           graph.strongUpdateSet=null; //Prevent future strong updates
          }
-       } else if (srcNodes.size()==0&&newSrcNodes.size()==1&&!newSrcNodes.iterator().next().isSummary()&&graph.strongUpdateSet==null) {
+       } else if (srcNodes.size()==1&&newSrcNodes.size()==1&&!newSrcNodes.iterator().next().isSummary()&&graph.strongUpdateSet!=null) {
          edgesToRemove=GraphManip.getEdges(graph, delta, srcNodes, fd);
+         graph.strongUpdateSet.addAll(edgesToRemove);
        }
        edgesToAdd.addAll(GraphManip.genEdges(newSrcNodes, fd, dstNodes));
       }
 
+      //Kill new edges
+      if (graph.strongUpdateSet!=null) {
+       MySet<Edge> otherEdgesToRemove=GraphManip.getDiffEdges(delta, srcNodes);
+       if (edgesToRemove!=null)
+         edgesToRemove.addAll(otherEdgesToRemove);
+       else
+         edgesToRemove=otherEdgesToRemove;
+       graph.strongUpdateSet.addAll(otherEdgesToRemove);
+      }
+
       //Next look at new destinations
       edgesToAdd.addAll(GraphManip.genEdges(srcNodes, fd, newDstNodes));
 
@@ -905,7 +921,7 @@ public class Pointer {
       FlatReturnNode frn=(FlatReturnNode)node;
       src=frn.getReturnTemp();
       dst=returntmp;
-      if (src==null) {
+      if (src==null||!src.getType().isPtr()) {
        //This is a NOP
        applyDiffs(graph, delta);
        return delta;
@@ -917,7 +933,7 @@ public class Pointer {
     }
     if (delta.getInit()) {
       HashSet<AllocNode> srcnodes=GraphManip.getNodes(graph, delta, src);
-      MySet<Edge> edgesToAdd=GraphManip.genEdges(src, srcnodes);
+      MySet<Edge> edgesToAdd=GraphManip.genEdges(dst, srcnodes);
       MySet<Edge> edgesToRemove=GraphManip.getEdges(graph, delta, dst);
       updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
       applyDiffs(graph, delta);
@@ -926,7 +942,7 @@ public class Pointer {
       HashSet<AllocNode> newSrcNodes=GraphManip.getDiffNodes(delta, src);
 
       /* Compute the union, and then the set of edges */
-      MySet<Edge> edgesToAdd=GraphManip.genEdges(src, newSrcNodes);
+      MySet<Edge> edgesToAdd=GraphManip.genEdges(dst, newSrcNodes);
       
       /* Compute set of edges to remove */
       MySet<Edge> edgesToRemove=GraphManip.getDiffEdges(delta, dst);      
@@ -956,7 +972,7 @@ public class Pointer {
     if (delta.getInit()) {
       HashSet<AllocNode> srcnodes=GraphManip.getNodes(graph, delta, src);
       HashSet<AllocNode> fdnodes=GraphManip.getNodes(graph, delta, srcnodes, fd);
-      MySet<Edge> edgesToAdd=GraphManip.genEdges(src, fdnodes);
+      MySet<Edge> edgesToAdd=GraphManip.genEdges(dst, fdnodes);
       MySet<Edge> edgesToRemove=GraphManip.getEdges(graph, delta, dst);
       updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
       applyDiffs(graph, delta);
@@ -971,7 +987,7 @@ public class Pointer {
       HashSet<AllocNode> newTargets=new HashSet<AllocNode>();
       newTargets.addAll(newfdnodes);
       newTargets.addAll(difffdnodes);
-      MySet<Edge> edgesToAdd=GraphManip.genEdges(src, newTargets);      
+      MySet<Edge> edgesToAdd=GraphManip.genEdges(dst, newTargets);      
       
       /* Compute set of edges to remove */
       MySet<Edge> edgesToRemove=GraphManip.getDiffEdges(delta, dst);      
@@ -1057,7 +1073,7 @@ public class Pointer {
       //Add it into the diffs
       delta.varedgeadd.put(tmp, newedges);
       //Remove the old edges
-      delta.varedgeremove.put(tmp, graph.getEdges(tmp));
+      delta.varedgeremove.put(tmp, (MySet<Edge>) graph.getEdges(tmp).clone());
       //Apply incoming diffs to graph
       applyDiffs(graph, delta);
       //Note that we create a single node