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<Edge>(e));
+ else
+ heapedgeadd.get(e.src).add(e);
+ }
+
+ public void addVarEdge(Edge e) {
+ if (!varedgeadd.containsKey(e.srcvar))
+ varedgeadd.put(e.srcvar, new MySet<Edge>(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<Edge>(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<Edge>(e));
+ else
+ varedgeremove.get(e.srcvar).add(e);
+ }
+ }
+
public void setInit(boolean init) {
this.init=init;
}
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
HashMap<TempDescriptor, MySet<Edge>> varMap;
HashMap<AllocNode, MySet<Edge>> backMap;
MySet<Edge> strongUpdateSet;
+
+ /* Need this information for mapping in callee results */
MySet<Edge> reachEdge;
HashSet<AllocNode> reachNode;
+ MySet<Edge> externalEdgeSet;
/* Need this information for mapping in callee results */
HashSet<AllocNode> nodeAges;
}
public static MySet<Edge> emptySet=new MySet<Edge>();
+
+ 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<TempDescriptor, MySet<Edge>> varMap,
+ HashMap<TempDescriptor, MySet<Edge>> childvarMap) {
+ for(Map.Entry<TempDescriptor, MySet<Edge>> 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<AllocNode, MySet<Edge>> nodeMap,
+ HashMap<AllocNode, MySet<Edge>> childNodeMap) {
+ for(Map.Entry<AllocNode, MySet<Edge>> 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
MySet<Edge> arrayset=new MySet<Edge>();
MySet<Edge> varset=new MySet<Edge>();
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;
}
}
}
-
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) {
return targets;
}
-
-
-
void fixMapping(FlatCall fcall, HashSet<MethodDescriptor> targets, MySet<Edge> oldedgeset, Delta newDelta, BBlock callblock, int callindex) {
Delta basedelta=null;
TempDescriptor tmpthis=fcall.getThis();
//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<Edge>());
- 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<Edge>());
- 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<Edge>());
- delta.varedgeremove.get(e.srcvar).add(e);
- }
- }
+ delta.removeEdge(e);
}
}
//Splice out internal edges
removeEdges(delta, nodeset, edgeset, externaledgeset);
+ //store data structures
+ graph.externalEdgeSet=externaledgeset;
graph.reachNode=nodeset;
graph.reachEdge=edgeset;
//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);
}
}
}
if (edgetoadd!=null) {
- if (newDelta.heapedgeadd.containsKey(edgetoadd.src))
- newDelta.heapedgeadd.put(edgetoadd.src, new MySet<Edge>(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;
}
for(Edge e:edgeset) {
Edge rewrite=e.rewrite(singleNode, summaryNode);
//Remove old edge
- if (!newDelta.heapedgeremove.containsKey(singleNode))
- newDelta.heapedgeremove.put(singleNode, new MySet<Edge>(e));
- else
- newDelta.heapedgeremove.get(singleNode).add(e);
-
- //Add new edge
- if (!newDelta.heapedgeremove.containsKey(summaryNode))
- newDelta.heapedgeremove.put(summaryNode, new MySet<Edge>(rewrite));
- else
- newDelta.heapedgeremove.get(summaryNode).add(rewrite);
+ newDelta.removeHeapEdge(e);
+ newDelta.addHeapEdge(rewrite);
}
//Handle incoming edges
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<Edge>(e));
- else
- newDelta.heapedgeremove.get(e.src).add(e);
-
- if (!newDelta.heapedgeadd.containsKey(summaryNode))
- newDelta.heapedgeadd.put(summaryNode, new MySet<Edge>(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<Edge>(e));
- else
- newDelta.varedgeremove.get(e.srcvar).add(e);
-
- if (!newDelta.varedgeadd.containsKey(e.srcvar))
- newDelta.varedgeadd.put(e.srcvar, new MySet<Edge>(rewrite));
- else
- newDelta.varedgeadd.get(e.srcvar).add(rewrite);
- }
+ newDelta.removeEdge(e);
+ newDelta.addEdge(rewrite);
}
}
}