From 7c28ffd5f751822936791f10de61262aaf4072b7 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Thu, 3 Mar 2011 09:10:19 +0000 Subject: [PATCH] more code changes --- Robust/src/Analysis/Pointer/AllocFactory.java | 10 ++ Robust/src/Analysis/Pointer/Edge.java | 17 +++ Robust/src/Analysis/Pointer/Graph.java | 11 ++ Robust/src/Analysis/Pointer/MySet.java | 5 + Robust/src/Analysis/Pointer/Pointer.java | 107 +++++++++++++++++- 5 files changed, 149 insertions(+), 1 deletion(-) diff --git a/Robust/src/Analysis/Pointer/AllocFactory.java b/Robust/src/Analysis/Pointer/AllocFactory.java index 67f426ed..46c8c6bd 100644 --- a/Robust/src/Analysis/Pointer/AllocFactory.java +++ b/Robust/src/Analysis/Pointer/AllocFactory.java @@ -66,6 +66,16 @@ public class AllocFactory { return allocNodeMap.get(key); } + public AllocNode getAllocNode(AllocNode node, boolean isSummary) { + int site=node.allocsite; + AllocNode key=new AllocNode(site, node.getType(), isSummary); + if (!allocNodeMap.containsKey(key)) { + allocNodeMap.put(key, key); + return key; + } else + return allocNodeMap.get(key); + } + HashMap allocNodeMap; HashMap allocMap; TypeUtil typeUtil; diff --git a/Robust/src/Analysis/Pointer/Edge.java b/Robust/src/Analysis/Pointer/Edge.java index 41d79bb0..49884471 100644 --- a/Robust/src/Analysis/Pointer/Edge.java +++ b/Robust/src/Analysis/Pointer/Edge.java @@ -76,11 +76,28 @@ public class Edge { return e; } + public Edge rewrite(AllocNode single, AllocNode summary) { + Edge e=copy(); + if (e.src==single) + e.src=summary; + if (e.dst==single) + e.dst=summary; + return e; + } + public boolean statusDominates(Edge other) { return (statuspredicate==NEW)|| ((other.statuspredicate|statuspredicate)==statuspredicate); } + public Edge makeStatus(AllocFactory factory) { + Edge e=new Edge(); + e.fd=fd; + e.src=factory.getAllocNode(src, (statuspredicate|3)==0); + e.dst=factory.getAllocNode(dst, (statuspredicate|5)==0); + return e; + } + public Edge makeOld() { Edge e=new Edge(); e.fd=fd; diff --git a/Robust/src/Analysis/Pointer/Graph.java b/Robust/src/Analysis/Pointer/Graph.java index 0efc690f..a5b2d708 100644 --- a/Robust/src/Analysis/Pointer/Graph.java +++ b/Robust/src/Analysis/Pointer/Graph.java @@ -20,6 +20,10 @@ public class Graph { HashSet nodeAges; HashMap oldNodes; + /* Need this information for mapping in callee results */ + HashSet callNodeAges; + HashSet callOldNodes; + public Graph(Graph parent) { nodeMap=new HashMap>(); varMap=new HashMap>(); @@ -28,6 +32,13 @@ public class Graph { this.parent=parent; } + public MySet getBackEdges(AllocNode node) { + MySet edgeset=new MySet(); + edgeset.addAll(backMap.get(node)); + edgeset.addAll(parent.backMap.get(node)); + return edgeset; + } + public boolean containsNode(AllocNode node) { return nodeAges.contains(node)||parent!=null&&parent.nodeAges.contains(node); } diff --git a/Robust/src/Analysis/Pointer/MySet.java b/Robust/src/Analysis/Pointer/MySet.java index 3b813f19..32b1bef4 100644 --- a/Robust/src/Analysis/Pointer/MySet.java +++ b/Robust/src/Analysis/Pointer/MySet.java @@ -7,6 +7,11 @@ public class MySet extends AbstractSet { map=new HashMap(); } + public MySet(T obj) { + map=new HashMap(); + add(obj); + } + public MySet(MySet base) { map=new HashMap(); addAll(base); diff --git a/Robust/src/Analysis/Pointer/Pointer.java b/Robust/src/Analysis/Pointer/Pointer.java index ceca50bd..1d1d30c5 100644 --- a/Robust/src/Analysis/Pointer/Pointer.java +++ b/Robust/src/Analysis/Pointer/Pointer.java @@ -314,6 +314,8 @@ public class Pointer { return targets; } + + void fixMapping(FlatCall fcall, HashSet targets, MySet oldedgeset, Delta newDelta, BBlock callblock, int callindex) { Delta basedelta=null; @@ -513,6 +515,9 @@ public class Pointer { graph.reachNode=nodeset; graph.reachEdge=edgeset; + graph.callNodeAges=new HashSet(); + graph.callOldNodes=new HashSet(); + //Apply diffs to graph applyDiffs(graph, delta, true); } else { @@ -567,15 +572,115 @@ public class Pointer { return delta; } + + Delta applyCallDelta(Delta delta, BBlock bblock) { + Delta newDelta=new Delta(null, false); Vector nodes=bblock.nodes(); PPoint ppoint=delta.getBlock(); FlatCall fcall=(FlatCall)nodes.get(ppoint.getIndex()); Graph graph=graphMap.get(fcall); + Graph oldgraph=(ppoint.getIndex()==0)? + bbgraphMap.get(bblock): + graphMap.get(nodes.get(ppoint.getIndex()-1)); + + //Age outside edges if necessary + for(Iterator nodeit=delta.addNodeAges.iterator();nodeit.hasNext();) { + AllocNode node=nodeit.next(); + if (!graph.callNodeAges.contains(node)) { + graph.callNodeAges.add(node); + } else { + nodeit.remove(); + } + if (!graph.reachNode.contains(node)&&!node.isSummary()) { + /* Need to age node in existing graph*/ + summarizeInGraph(graph, newDelta, node); + } + } + + //Add heap edges in + for(Map.Entry> entry:delta.heapedgeadd.entrySet()) { + for(Edge e:entry.getValue()) { + boolean addedge=false; + Edge edgetoadd=null; + if (e.statuspredicate==Edge.NEW) { + edgetoadd=e; + } else { + Edge origEdgeKey=e.makeStatus(allocFactory); + if (oldgraph.nodeMap.containsKey(origEdgeKey.src)&& + oldgraph.nodeMap.get(origEdgeKey.src).contains(origEdgeKey)) { + Edge origEdge=oldgraph.nodeMap.get(origEdgeKey.src).get(origEdgeKey); + //copy the predicate + origEdgeKey.statuspredicate=origEdge.statuspredicate; + edgetoadd=origEdgeKey; + } + } + 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); + } + } + } + + return newDelta; + } + + /* Summarizes out of context nodes in graph */ + void summarizeInGraph(Graph graph, Delta newDelta, AllocNode singleNode) { + AllocNode summaryNode=allocFactory.getAllocNode(singleNode, true); + + //Handle outgoing heap edges + MySet edgeset=graph.getEdges(singleNode); + + 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); + } + + //Handle incoming edges + MySet backedges=graph.getBackEdges(singleNode); + 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); - return null; + } 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); + } + } + } } void applyDiffs(Graph graph, Delta delta) { -- 2.34.1