From 586ae74cd13ab24327cf7bc088e30e9161ca746c Mon Sep 17 00:00:00 2001 From: bdemsky Date: Fri, 4 Mar 2011 07:15:39 +0000 Subject: [PATCH] changes --- Robust/src/Analysis/Pointer/AllocFactory.java | 7 ++ Robust/src/Analysis/Pointer/Delta.java | 52 ++++++++ Robust/src/Analysis/Pointer/Graph.java | 43 +++++++ Robust/src/Analysis/Pointer/Pointer.java | 116 ++++++------------ 4 files changed, 141 insertions(+), 77 deletions(-) diff --git a/Robust/src/Analysis/Pointer/AllocFactory.java b/Robust/src/Analysis/Pointer/AllocFactory.java index 46c8c6bd..8a12bd23 100644 --- a/Robust/src/Analysis/Pointer/AllocFactory.java +++ b/Robust/src/Analysis/Pointer/AllocFactory.java @@ -35,6 +35,13 @@ public class AllocFactory { } return false; } + + public String getID() { + if (summary) + return "SUM"+allocsite; + else + return "SING"+allocsite; + } } public AllocFactory(State state, TypeUtil typeUtil) { diff --git a/Robust/src/Analysis/Pointer/Delta.java b/Robust/src/Analysis/Pointer/Delta.java index 4c91420b..a910c2f1 100644 --- a/Robust/src/Analysis/Pointer/Delta.java +++ b/Robust/src/Analysis/Pointer/Delta.java @@ -105,6 +105,58 @@ public class Delta { return init; } + public void addEdge(Edge e) { + if (e.src!=null) { + addHeapEdge(e); + } else { + addVarEdge(e); + } + } + + public void addHeapEdge(Edge e) { + if (!heapedgeadd.containsKey(e.src)) + heapedgeadd.put(e.src, new MySet(e)); + else + heapedgeadd.get(e.src).add(e); + } + + public void addVarEdge(Edge e) { + if (!varedgeadd.containsKey(e.srcvar)) + varedgeadd.put(e.srcvar, new MySet(e)); + else + varedgeadd.get(e.srcvar).add(e); + } + + public void removeEdge(Edge e) { + if (e.src!=null) { + removeHeapEdge(e); + } else { + removeVarEdge(e); + } + } + + public void removeHeapEdge(Edge e) { + if (heapedgeadd.containsKey(e.src)&&heapedgeadd.get(e.src).contains(e)) + heapedgeadd.get(e.src).remove(e); + else { + if (!heapedgeremove.containsKey(e.src)) + heapedgeremove.put(e.src, new MySet(e)); + else + heapedgeremove.get(e.src).add(e); + } + } + + public void removeVarEdge(Edge e) { + if (varedgeadd.containsKey(e.src)&&varedgeadd.get(e.src).contains(e)) + varedgeadd.get(e.src).remove(e); + else { + if (!varedgeremove.containsKey(e.srcvar)) + varedgeremove.put(e.srcvar, new MySet(e)); + else + varedgeremove.get(e.srcvar).add(e); + } + } + public void setInit(boolean init) { this.init=init; } diff --git a/Robust/src/Analysis/Pointer/Graph.java b/Robust/src/Analysis/Pointer/Graph.java index a5b2d708..4460bf07 100644 --- a/Robust/src/Analysis/Pointer/Graph.java +++ b/Robust/src/Analysis/Pointer/Graph.java @@ -3,6 +3,7 @@ import java.util.*; import Analysis.Disjoint.PointerMethod; import Analysis.Pointer.AllocFactory.AllocNode; import IR.Flat.*; +import java.io.PrintWriter; public class Graph { /* This is field is set is this Graph is just a delta on the parent @@ -13,8 +14,11 @@ public class Graph { HashMap> varMap; HashMap> backMap; MySet strongUpdateSet; + + /* Need this information for mapping in callee results */ MySet reachEdge; HashSet reachNode; + MySet externalEdgeSet; /* Need this information for mapping in callee results */ HashSet nodeAges; @@ -60,4 +64,43 @@ public class Graph { } public static MySet emptySet=new MySet(); + + public void printGraph(PrintWriter output) { + output.println("digraph graph {"); + output.println("\tnode [fontsize=10,height=\"0.1\", width=\"0.1\"];"); + output.println("\tedge [fontsize=6];"); + outputTempEdges(output, varMap, null); + if (parent!=null) + outputTempEdges(output, parent.varMap, varMap); + outputHeapEdges(output, nodeMap, null); + if (parent!=null) + outputHeapEdges(output, parent.nodeMap, nodeMap); + output.println("}\n"); + } + + private void outputTempEdges(PrintWriter output, HashMap> varMap, + HashMap> childvarMap) { + for(Map.Entry> entry:varMap.entrySet()) { + TempDescriptor tmp=entry.getKey(); + if (childvarMap!=null&&childvarMap.containsKey(tmp)) + continue; + for(Edge e:entry.getValue()) { + AllocNode n=e.dst; + output.println("\t"+tmp.getSymbol()+"->"+n.getID()+";"); + } + } + } + + private void outputHeapEdges(PrintWriter output, HashMap> nodeMap, + HashMap> childNodeMap) { + for(Map.Entry> entry:nodeMap.entrySet()) { + AllocNode node=entry.getKey(); + if (childNodeMap!=null&&childNodeMap.containsKey(node)) + continue; + for(Edge e:entry.getValue()) { + AllocNode n=e.dst; + output.println("\t"+node.getID()+"->"+n.getID()+"[label=\""+e.fd.getSymbol()+"\";"); + } + } + } } \ No newline at end of file diff --git a/Robust/src/Analysis/Pointer/Pointer.java b/Robust/src/Analysis/Pointer/Pointer.java index 1d1d30c5..c9705232 100644 --- a/Robust/src/Analysis/Pointer/Pointer.java +++ b/Robust/src/Analysis/Pointer/Pointer.java @@ -47,11 +47,10 @@ public class Pointer { MySet arrayset=new MySet(); MySet varset=new MySet(); Edge arrayedge=new Edge(allocFactory.StringArray, null, allocFactory.Strings); - arrayset.add(arrayedge); Edge stringedge=new Edge(fm.getParameter(0), allocFactory.StringArray); - varset.add(stringedge); - delta.heapedgeadd.put(allocFactory.StringArray, arrayset); - delta.varedgeadd.put(fm.getParameter(0), varset); + delta.addHeapEdge(arrayedge); + delta.addVarEdge(stringedge); + return delta; } @@ -241,7 +240,6 @@ public class Pointer { } } - void processThisTargets(HashSet targetSet, Graph graph, Delta delta, Delta newDelta, HashSet nodeset, Stack tovisit, MySet edgeset, TempDescriptor tmpthis, HashSet oldnodeset) { //Handle the this temp if (tmpthis!=null) { @@ -314,9 +312,6 @@ public class Pointer { return targets; } - - - void fixMapping(FlatCall fcall, HashSet targets, MySet oldedgeset, Delta newDelta, BBlock callblock, int callindex) { Delta basedelta=null; TempDescriptor tmpthis=fcall.getThis(); @@ -440,42 +435,14 @@ public class Pointer { //Want to remove the set of internal edges for(Edge e:edgeset) { if (e.src!=null) { - if (delta.heapedgeadd.containsKey(e.src)&&delta.heapedgeadd.get(e.src).contains(e)) { - //remove edge if it is in the add set - delta.heapedgeadd.get(e.src).remove(e); - } else { - //add edge to to the remove set - if (!delta.heapedgeremove.containsKey(e.src)) - delta.heapedgeremove.put(e.src, new MySet()); - delta.heapedgeremove.get(e.src).add(e); - } + delta.removeHeapEdge(e); } } //Want to remove the set of external edges for(Edge e:externaledgeset) { //want to remove the set of internal edges - if (e.src!=null) { - if (delta.heapedgeadd.containsKey(e.src)&&delta.heapedgeadd.get(e.src).contains(e)) { - //remove edge if it is in the add set - delta.heapedgeadd.get(e.src).remove(e); - } else { - //add edge to to the remove set - if (!delta.heapedgeremove.containsKey(e.src)) - delta.heapedgeremove.put(e.src, new MySet()); - delta.heapedgeremove.get(e.src).add(e); - } - } else { - if (delta.varedgeadd.containsKey(e.srcvar)&&delta.varedgeadd.get(e.srcvar).contains(e)) { - //remove edge if it is in the add set - delta.varedgeadd.get(e.srcvar).remove(e); - } else { - //add edge to to the remove set - if (!delta.varedgeremove.containsKey(e.srcvar)) - delta.varedgeremove.put(e.srcvar,new MySet()); - delta.varedgeremove.get(e.srcvar).add(e); - } - } + delta.removeEdge(e); } } @@ -512,6 +479,8 @@ public class Pointer { //Splice out internal edges removeEdges(delta, nodeset, edgeset, externaledgeset); + //store data structures + graph.externalEdgeSet=externaledgeset; graph.reachNode=nodeset; graph.reachEdge=edgeset; @@ -566,6 +535,9 @@ public class Pointer { //Splice out internal edges removeEdges(delta, nodeset, edgeset, externaledgeset); + //Add in new external edges + graph.externalEdgeSet.addAll(externaledgeset); + //Apply diffs to graph applyDiffs(graph, delta); } @@ -616,14 +588,34 @@ public class Pointer { } } if (edgetoadd!=null) { - if (newDelta.heapedgeadd.containsKey(edgetoadd.src)) - newDelta.heapedgeadd.put(edgetoadd.src, new MySet(edgetoadd)); - else - newDelta.heapedgeadd.get(edgetoadd.src).add(edgetoadd); + newDelta.addHeapEdge(edgetoadd); } } } - + + //Add external edges in + for(Edge e:graph.externalEdgeSet) { + //First did we age the source + Edge newedge=e.copy(); + if (newedge.src!=null&&!e.src.isSummary()&&graph.callNodeAges.contains(e.src)) { + AllocNode summaryNode=allocFactory.getAllocNode(newedge.src, true); + newedge.src=summaryNode; + } + //Compute target + if (graph.callNodeAges.contains(e.dst)&&!e.dst.isSummary()) { + if (graph.callOldNodes.contains(e.dst)) { + //Need two edges + Edge copy=newedge.copy(); + newDelta.addEdge(copy); + } + //Now add summarized node + newedge.dst=allocFactory.getAllocNode(newedge.dst, true); + newDelta.addEdge(newedge); + } else { + //Add edge to single node + newDelta.addEdge(newedge); + } + } return newDelta; } @@ -638,16 +630,8 @@ public class Pointer { for(Edge e:edgeset) { Edge rewrite=e.rewrite(singleNode, summaryNode); //Remove old edge - if (!newDelta.heapedgeremove.containsKey(singleNode)) - newDelta.heapedgeremove.put(singleNode, new MySet(e)); - else - newDelta.heapedgeremove.get(singleNode).add(e); - - //Add new edge - if (!newDelta.heapedgeremove.containsKey(summaryNode)) - newDelta.heapedgeremove.put(summaryNode, new MySet(rewrite)); - else - newDelta.heapedgeremove.get(summaryNode).add(rewrite); + newDelta.removeHeapEdge(e); + newDelta.addHeapEdge(rewrite); } //Handle incoming edges @@ -655,30 +639,8 @@ public class Pointer { for(Edge e:backedges) { if (e.dst==singleNode) { Edge rewrite=e.rewrite(singleNode, summaryNode); - if (e.src!=null) { - //Have heap edge - if (!newDelta.heapedgeremove.containsKey(e.src)) - newDelta.heapedgeremove.put(e.src, new MySet(e)); - else - newDelta.heapedgeremove.get(e.src).add(e); - - if (!newDelta.heapedgeadd.containsKey(summaryNode)) - newDelta.heapedgeadd.put(summaryNode, new MySet(rewrite)); - else - newDelta.heapedgeadd.get(summaryNode).add(rewrite); - - } else { - //Have var edge - if (!newDelta.varedgeremove.containsKey(e.srcvar)) - newDelta.varedgeremove.put(e.srcvar, new MySet(e)); - else - newDelta.varedgeremove.get(e.srcvar).add(e); - - if (!newDelta.varedgeadd.containsKey(e.srcvar)) - newDelta.varedgeadd.put(e.srcvar, new MySet(rewrite)); - else - newDelta.varedgeadd.get(e.srcvar).add(rewrite); - } + newDelta.removeEdge(e); + newDelta.addEdge(rewrite); } } } -- 2.34.1