code cleanup
authorbdemsky <bdemsky>
Wed, 2 Mar 2011 22:53:45 +0000 (22:53 +0000)
committerbdemsky <bdemsky>
Wed, 2 Mar 2011 22:53:45 +0000 (22:53 +0000)
Robust/src/Analysis/Pointer/Pointer.java

index aaa3e20749d38ce5721018d74dc17bd24cfd4690..aae36b2c636489ca0f97c2794c379cccf5f164bc 100644 (file)
@@ -211,80 +211,100 @@ public class Pointer {
     }
   }
 
-  Delta processFlatCall(BBlock callblock, int callindex, FlatCall fcall, Delta delta, Graph graph) {
-    Delta newDelta=new Delta(null, false);
 
-    if (delta.getInit()) {
-      MySet<Edge> edgeset=new MySet<Edge>();
-      HashSet<AllocNode> nodeset=new HashSet<AllocNode>();
-      HashSet<ClassDescriptor> targetSet=new HashSet<ClassDescriptor>();
-      Stack<AllocNode> tovisit=new Stack<AllocNode>();
-      TempDescriptor tmpthis=fcall.getThis();
-
-      //Handle the this temp
-      if (tmpthis!=null) {
-       MySet<Edge> edges=GraphManip.getEdges(graph, delta, tmpthis);
-       newDelta.varedgeadd.put(tmpthis, (MySet<Edge>) edges.clone());
-       edgeset.addAll(edges);
-       for(Edge e:edges) {
-         AllocNode dstnode=e.dst;
-         if (!nodeset.contains(dstnode)) {
-           TypeDescriptor type=dstnode.getType();
-           if (!type.isArray()) {
-             targetSet.add(type.getClassDesc());
-           } else {
-             //arrays don't have code
-             targetSet.add(typeUtil.getClass(TypeUtil.ObjectClass));
-           }
-           nodeset.add(dstnode);
-           tovisit.add(dstnode);
+  void processThisTargets(HashSet<ClassDescriptor> targetSet, Graph graph, Delta delta, Delta newDelta, HashSet<AllocNode> nodeset, Stack<AllocNode> tovisit, MySet<Edge> edgeset, TempDescriptor tmpthis, HashSet<AllocNode> oldnodeset) {
+    //Handle the this temp
+    if (tmpthis!=null) {
+      MySet<Edge> edges=(oldnodeset!=null)?GraphManip.getDiffEdges(delta, tmpthis):GraphManip.getEdges(graph, delta, tmpthis);
+      newDelta.varedgeadd.put(tmpthis, (MySet<Edge>) edges.clone());
+      edgeset.addAll(edges);
+      for(Edge e:edges) {
+       AllocNode dstnode=e.dst;
+       if (!nodeset.contains(dstnode)&&(oldnodeset==null||!oldnodeset.contains(dstnode))) {
+         TypeDescriptor type=dstnode.getType();
+         if (!type.isArray()) {
+           targetSet.add(type.getClassDesc());
+         } else {
+           //arrays don't have code
+           targetSet.add(typeUtil.getClass(TypeUtil.ObjectClass));
          }
+         nodeset.add(dstnode);
+         tovisit.add(dstnode);
        }
       }
+    }
+  }
 
-      //Go through each temp
-      for(int i=0;i<fcall.numArgs();i++) {
-       TempDescriptor tmp=fcall.getArg(i);
-       MySet<Edge> edges=GraphManip.getEdges(graph, delta, tmp);
-       newDelta.varedgeadd.put(tmp, (MySet<Edge>) edges.clone());
-       edgeset.addAll(edges);
-       for(Edge e:edges) {
-         if (!nodeset.contains(e.dst)) {
-           nodeset.add(e.dst);
-           tovisit.add(e.dst);
-         }
+  void processParams(Graph graph, Delta delta, Delta newDelta, HashSet<AllocNode> nodeset, Stack<AllocNode> tovisit, MySet<Edge> edgeset, FlatCall fcall, boolean diff) {
+    //Go through each temp
+    for(int i=0;i<fcall.numArgs();i++) {
+      TempDescriptor tmp=fcall.getArg(i);
+      MySet<Edge> edges=diff?GraphManip.getDiffEdges(delta, tmp):GraphManip.getEdges(graph, delta, tmp);
+      newDelta.varedgeadd.put(tmp, (MySet<Edge>) edges.clone());
+      edgeset.addAll(edges);
+      for(Edge e:edges) {
+       if (!nodeset.contains(e.dst)) {
+         nodeset.add(e.dst);
+         tovisit.add(e.dst);
        }
       }
-      
-      //Traverse all reachable nodes
+    }
+  }
+
+  void computeReachableNodes(Graph graph, Delta delta, Delta newDelta, HashSet<AllocNode> nodeset, Stack<AllocNode> tovisit, MySet<Edge> edgeset, HashSet<AllocNode> oldnodeset) {
       while(!tovisit.isEmpty()) {
        AllocNode node=tovisit.pop();
        MySet<Edge> edges=GraphManip.getEdges(graph, delta, node);
        newDelta.heapedgeadd.put(node, edges);
        edgeset.addAll(edges);
        for(Edge e:edges) {
-         if (!nodeset.contains(e.dst)) {
+         if (!nodeset.contains(e.dst)&&(oldnodeset==null||!oldnodeset.contains(e.dst))) {
            nodeset.add(e.dst);
            tovisit.add(e.dst);
          }
        }
       }
+  }
 
-      //Compute call targets
-      MethodDescriptor md=fcall.getMethod();
-      HashSet<MethodDescriptor> targets=new HashSet<MethodDescriptor>();
-      if (md.isStatic()) {
-       targets.add(md);
-      } else {
-       //Compute Edges
-       for(Edge e:newDelta.varedgeadd.get(tmpthis)) {
-         AllocNode node=e.dst;
-         ClassDescriptor cd=node.getType().getClassDesc();
-         //Figure out exact method called and add to set
-         targets.add(cd.getCalledMethod(md));
-       }
+  HashSet<MethodDescriptor> computeTargets(FlatCall fcall, Delta newDelta) {
+    TempDescriptor tmpthis=fcall.getThis();
+    MethodDescriptor md=fcall.getMethod();
+    HashSet<MethodDescriptor> targets=new HashSet<MethodDescriptor>();
+    if (md.isStatic()) {
+      targets.add(md);
+    } else {
+      //Compute Edges
+      for(Edge e:newDelta.varedgeadd.get(tmpthis)) {
+       AllocNode node=e.dst;
+       ClassDescriptor cd=node.getType().getClassDesc();
+       //Figure out exact method called and add to set
+       targets.add(cd.getCalledMethod(md));
       }
+    }
+    return targets;
+  }
 
+  Delta processFlatCall(BBlock callblock, int callindex, FlatCall fcall, Delta delta, Graph graph) {
+    Delta newDelta=new Delta(null, false);
+
+    if (delta.getInit()) {
+      MySet<Edge> edgeset=new MySet<Edge>();
+      HashSet<AllocNode> nodeset=new HashSet<AllocNode>();
+      HashSet<ClassDescriptor> targetSet=new HashSet<ClassDescriptor>();
+      Stack<AllocNode> tovisit=new Stack<AllocNode>();
+      TempDescriptor tmpthis=fcall.getThis();
+
+      //Handle the this temp
+      processThisTargets(targetSet, graph, delta, newDelta, nodeset, tovisit, edgeset, tmpthis, null);
+
+      //Go through each temp
+      processParams(graph, delta, newDelta, nodeset, tovisit, edgeset, fcall, false);
+      
+      //Traverse all reachable nodes
+      computeReachableNodes(graph, delta, newDelta, nodeset, tovisit, edgeset, null);
+
+      //Compute call targets
+      HashSet<MethodDescriptor> targets=computeTargets(fcall, newDelta);
 
       //Fix mapping
       for(MethodDescriptor calledmd:targets) {
@@ -355,39 +375,10 @@ public class Pointer {
       TempDescriptor tmpthis=fcall.getThis();
 
       //Handle the this temp
-      if (tmpthis!=null) {
-       MySet<Edge> edges=GraphManip.getDiffEdges(delta, tmpthis);
-       newDelta.varedgeadd.put(tmpthis, (MySet<Edge>) edges.clone());
-       edgeset.addAll(edges);
-       for(Edge e:edges) {
-         AllocNode dstnode=e.dst;
-         if (!nodeset.contains(dstnode)&&!oldnodeset.contains(dstnode)) {
-           TypeDescriptor type=dstnode.getType();
-           if (!type.isArray()) {
-             targetSet.add(type.getClassDesc());
-           } else {
-             //arrays don't have code
-             targetSet.add(typeUtil.getClass(TypeUtil.ObjectClass));
-           }
-           nodeset.add(dstnode);
-           tovisit.add(dstnode);
-         }
-       }
-      }
+      processThisTargets(targetSet, graph, delta, newDelta, nodeset, tovisit, edgeset, tmpthis, oldnodeset);
 
       //Go through each temp
-      for(int i=0;i<fcall.numArgs();i++) {
-       TempDescriptor tmp=fcall.getArg(i);
-       MySet<Edge> edges=GraphManip.getDiffEdges(delta, tmp);
-       newDelta.varedgeadd.put(tmp, (MySet<Edge>) edges.clone());
-       edgeset.addAll(edges);
-       for(Edge e:edges) {
-         if (!nodeset.contains(e.dst)&&!oldnodeset.contains(e.dst)) {
-           nodeset.add(e.dst);
-           tovisit.add(e.dst);
-         }
-       }
-      }
+      processParams(graph, delta, newDelta, nodeset, tovisit, edgeset, fcall, true);
 
       //Go through each new heap edge that starts from old node
       MySet<Edge> newedges=GraphManip.getDiffEdges(delta, oldnodeset);
@@ -400,34 +391,10 @@ public class Pointer {
       }
       
       //Traverse all reachable nodes
-      while(!tovisit.isEmpty()) {
-       AllocNode node=tovisit.pop();
-       MySet<Edge> edges=GraphManip.getEdges(graph, delta, node);
-
-       newDelta.heapedgeadd.put(node, edges);
-       edgeset.addAll(edges);
-       for(Edge e:edges) {
-         if (!nodeset.contains(e.dst)&&!oldnodeset.contains(e.dst)) {
-           nodeset.add(e.dst);
-           tovisit.add(e.dst);
-         }
-       }
-      }
+      computeReachableNodes(graph, delta, newDelta, nodeset, tovisit, edgeset, oldnodeset);
 
       //Compute call targets
-      MethodDescriptor md=fcall.getMethod();
-      HashSet<MethodDescriptor> targets=new HashSet<MethodDescriptor>();
-      if (md.isStatic()) {
-       targets.add(md);
-      } else {
-       //Compute Edges
-       for(Edge e:newDelta.varedgeadd.get(tmpthis)) {
-         AllocNode node=e.dst;
-         ClassDescriptor cd=node.getType().getClassDesc();
-         //Figure out exact method called and add to set
-         targets.add(cd.getCalledMethod(md));
-       }
-      }
+      HashSet<MethodDescriptor> targets=computeTargets(fcall, newDelta);
 
       //add in new nodeset and edgeset
       oldnodeset.addAll(nodeset);