1 package Analysis.Pointer;
5 import Analysis.Pointer.BasicBlock.BBlock;
6 import Analysis.Pointer.AllocFactory.AllocNode;
10 HashMap<FlatMethod, BasicBlock> blockMap;
11 HashMap<BBlock, Graph> bbgraphMap;
12 HashMap<FlatNode, Graph> graphMap;
13 HashMap<FlatCall, Set<BBlock>> callMap;
14 HashMap<BBlock, Set<PPoint>> returnMap;
18 AllocFactory allocFactory;
19 LinkedList<Delta> toprocess;
20 TempDescriptor returntmp;
23 public Pointer(State state, TypeUtil typeUtil) {
25 this.blockMap=new HashMap<FlatMethod, BasicBlock>();
26 this.bbgraphMap=new HashMap<BBlock, Graph>();
27 this.graphMap=new HashMap<FlatNode, Graph>();
28 this.callMap=new HashMap<FlatCall, Set<BBlock>>();
29 this.returnMap=new HashMap<BBlock, Set<PPoint>>();
30 this.typeUtil=typeUtil;
31 this.allocFactory=new AllocFactory(state, typeUtil);
32 this.toprocess=new LinkedList<Delta>();
33 ClassDescriptor stringcd=typeUtil.getClass(TypeUtil.ObjectClass);
34 this.returntmp=new TempDescriptor("RETURNVAL", stringcd);
37 public BasicBlock getBBlock(FlatMethod fm) {
38 if (!blockMap.containsKey(fm))
39 blockMap.put(fm, BasicBlock.getBBlock(fm));
40 return blockMap.get(fm);
43 Delta buildInitialContext() {
44 MethodDescriptor md=typeUtil.getMain();
45 FlatMethod fm=state.getMethodFlat(md);
46 BasicBlock bb=getBBlock(fm);
47 BBlock start=bb.getStart();
48 Delta delta=new Delta(new PPoint(start), true);
49 MySet<Edge> arrayset=new MySet<Edge>();
50 MySet<Edge> varset=new MySet<Edge>();
51 Edge arrayedge=new Edge(allocFactory.StringArray, null, allocFactory.Strings);
52 Edge stringedge=new Edge(fm.getParameter(0), allocFactory.StringArray);
53 delta.addHeapEdge(arrayedge);
54 delta.addVarEdge(stringedge);
59 public void doAnalysis() {
60 toprocess.add(buildInitialContext());
61 while(!toprocess.isEmpty()) {
62 Delta delta=toprocess.remove();
63 PPoint ppoint=delta.getBlock();
64 BBlock bblock=ppoint.getBBlock();
65 Vector<FlatNode> nodes=bblock.nodes();
67 System.out.println("BB BEGIN");
70 if (ppoint.getIndex()==-1) {
71 //Build base graph for entrance to this basic block
72 System.out.println("INIT");
73 delta=applyInitDelta(delta, bblock);
75 System.out.println("CALL");
76 startindex=ppoint.getIndex()+1;
77 delta=applyCallDelta(delta, bblock);
79 Graph graph=bbgraphMap.get(bblock);
81 //Compute delta at exit of each node
82 for(int i=startindex; i<nodes.size();i++) {
83 FlatNode currNode=nodes.get(i);
84 System.out.println("["+plotcount+"]");
85 System.out.println(currNode);
88 if (!graphMap.containsKey(currNode)) {
89 graphMap.put(currNode, new Graph(graph));
91 nodeGraph=graphMap.get(currNode);
92 plotGraph(nodeGraph,"S"+plotcount+currNode);
93 delta=processNode(bblock, i, currNode, delta, nodeGraph);
94 plotGraph(nodeGraph,"N"+plotcount+currNode);
97 System.out.println("LOOPEXIT");
99 generateFinalDelta(bblock, delta, nodeGraph);
104 for(Map.Entry<BBlock, Graph> e:bbgraphMap.entrySet()) {
105 Graph g=e.getValue();
106 plotGraph(g,"BB"+debugindex);
110 for(Map.Entry<FlatNode, Graph> e:graphMap.entrySet()) {
111 FlatNode fn=e.getKey();
112 Graph g=e.getValue();
113 plotGraph(g,"FN"+fn.toString()+debugindex);
116 for(FlatMethod fm:blockMap.keySet()) {
121 void plotGraph(Graph g, String name) {
123 PrintWriter pw=new PrintWriter(new FileWriter(name.toString().replace(' ','_')+".dot"));
124 g.printGraph(pw, name);
126 } catch (Exception ex) {
127 ex.printStackTrace();
132 /* This function builds the last delta for a basic block. It
133 * handles the case for the first time the basic block is
136 void buildInitDelta(Graph graph, Delta newDelta) {
137 //First compute the set of temps
138 HashSet<TempDescriptor> tmpSet=new HashSet<TempDescriptor>();
139 tmpSet.addAll(graph.varMap.keySet());
140 tmpSet.addAll(graph.parent.varMap.keySet());
142 //Next build the temp map part of the delta
143 for(TempDescriptor tmp:tmpSet) {
144 MySet<Edge> edgeSet=new MySet<Edge>();
146 if (graph.varMap.containsKey(tmp))
147 edgeSet.addAll(graph.varMap.get(tmp));
149 edgeSet.addAll(graph.parent.varMap.get(tmp));
150 newDelta.varedgeadd.put(tmp, edgeSet);
153 //Next compute the set of src allocnodes
154 HashSet<AllocNode> nodeSet=new HashSet<AllocNode>();
155 nodeSet.addAll(graph.nodeMap.keySet());
156 nodeSet.addAll(graph.parent.nodeMap.keySet());
158 for(AllocNode node:nodeSet) {
159 MySet<Edge> edgeSet=new MySet<Edge>();
161 if (graph.nodeMap.containsKey(node))
162 edgeSet.addAll(graph.nodeMap.get(node));
164 edgeSet.addAll(graph.parent.nodeMap.get(node));
165 newDelta.heapedgeadd.put(node, edgeSet);
168 if (graph.nodeAges.contains(node))
169 newDelta.addNodeAges.add(node);
170 else if (graph.parent.nodeAges.contains(node))
171 newDelta.addNodeAges.add(node);
174 if (graph.oldNodes.containsKey(node)) {
175 if (graph.oldNodes.get(node).booleanValue())
176 newDelta.addOldNodes.put(node, Boolean.TRUE);
177 } else if (graph.parent.oldNodes.containsKey(node)) {
178 //parent graphs only contain true...no need to check
179 newDelta.addOldNodes.put(node, Boolean.TRUE);
184 /* This function build the delta for the exit of a basic block. */
186 void generateFinalDelta(BBlock bblock, Delta delta, Graph graph) {
187 Delta newDelta=new Delta(null, false);
188 if (delta.getInit()) {
189 buildInitDelta(graph, newDelta);
191 /* We can break the old delta...it is done being used */
192 /* First we will build variable edges */
193 HashSet<TempDescriptor> tmpSet=new HashSet<TempDescriptor>();
194 tmpSet.addAll(delta.basevaredge.keySet());
195 tmpSet.addAll(delta.varedgeadd.keySet());
196 System.out.println(tmpSet);
197 for(TempDescriptor tmp:tmpSet) {
198 /* Start with the new incoming edges */
199 MySet<Edge> newbaseedge=delta.basevaredge.get(tmp);
200 /* Remove the remove set */
201 if (newbaseedge==null)
202 newbaseedge=new MySet<Edge>();
203 newbaseedge.removeAll(delta.varedgeremove.get(tmp));
204 /* Add in the new set*/
205 newbaseedge.addAll(delta.varedgeadd.get(tmp));
206 /* Store the results */
207 newDelta.varedgeadd.put(tmp, newbaseedge);
209 delta.basevaredge.clear();
211 /* Next we build heap edges */
212 HashSet<AllocNode> nodeSet=new HashSet<AllocNode>();
213 nodeSet.addAll(delta.baseheapedge.keySet());
214 nodeSet.addAll(delta.heapedgeadd.keySet());
215 nodeSet.addAll(delta.heapedgeremove.keySet());
216 for(AllocNode node:nodeSet) {
217 /* Start with the new incoming edges */
218 MySet<Edge> newheapedge=new MySet<Edge>(delta.baseheapedge.get(node));
219 /* Remove the remove set */
220 MySet<Edge> removeset=delta.heapedgeremove.get(node);
223 newheapedge.removeAll(removeset);
225 /* Add in the add set */
226 MySet<Edge> settoadd=delta.heapedgeadd.get(node);
228 newheapedge.addAll(settoadd);
229 newDelta.heapedgeadd.put(node, newheapedge);
231 /* Remove the newly created edges..no need to propagate a diff for those */
232 if (removeset!=null) {
233 removeset.removeAll(delta.baseheapedge.get(node));
234 newDelta.heapedgeremove.put(node, removeset);
238 /* Compute new ages */
239 newDelta.addNodeAges.addAll(delta.baseNodeAges);
240 newDelta.addNodeAges.addAll(delta.addNodeAges);
241 HashSet<AllocNode> oldNodes=new HashSet<AllocNode>();
243 /* Compute whether old nodes survive */
244 oldNodes.addAll(delta.baseOldNodes.keySet());
245 oldNodes.addAll(delta.addOldNodes.keySet());
246 for(AllocNode node:oldNodes) {
247 if (delta.addOldNodes.containsKey(node)) {
248 if (delta.addOldNodes.get(node).booleanValue()) {
249 newDelta.addOldNodes.put(node, Boolean.TRUE);
252 if (delta.baseOldNodes.get(node).booleanValue()) {
253 newDelta.addOldNodes.put(node, Boolean.TRUE);
258 System.out.println("FINAL");
261 /* Now we need to propagate newdelta */
262 if (!newDelta.heapedgeadd.isEmpty()||!newDelta.heapedgeremove.isEmpty()||!newDelta.varedgeadd.isEmpty()||!newDelta.addNodeAges.isEmpty()||!newDelta.addOldNodes.isEmpty()) {
263 /* We have a delta to propagate */
264 if (returnMap.containsKey(bblock)) {
268 for(PPoint caller:returnMap.get(bblock)) {
270 newDelta.setBlock(caller);
271 toprocess.add(newDelta);
274 Delta d=newDelta.diffBlock(caller);
280 Vector<BBlock> blockvector=bblock.next();
281 for(int i=0;i<blockvector.size();i++) {
283 newDelta.setBlock(new PPoint(blockvector.get(i)));
284 toprocess.add(newDelta);
286 Delta d=newDelta.diffBlock(new PPoint(blockvector.get(i)));
294 Delta processNode(BBlock bblock, int index, FlatNode node, Delta delta, Graph newgraph) {
295 switch(node.kind()) {
297 return processNewNode((FlatNew)node, delta, newgraph);
298 case FKind.FlatFieldNode:
299 case FKind.FlatElementNode:
300 return processFieldElementNode(node, delta, newgraph);
301 case FKind.FlatCastNode:
302 case FKind.FlatOpNode:
303 case FKind.FlatReturnNode:
304 return processCopyNode(node, delta, newgraph);
305 case FKind.FlatSetFieldNode:
306 case FKind.FlatSetElementNode:
307 return processSetFieldElementNode(node, delta, newgraph);
308 case FKind.FlatMethod:
310 case FKind.FlatBackEdge:
311 case FKind.FlatGenReachNode:
312 return processFlatNop(node, delta, newgraph);
314 return processFlatCall(bblock, index, (FlatCall) node, delta, newgraph);
315 case FKind.FlatSESEEnterNode:
316 case FKind.FlatSESEExitNode:
317 throw new Error("Unimplemented node:"+node);
319 throw new Error("Unrecognized node:"+node);
323 /* This function compute the edges for the this variable for a
324 * callee if it exists. */
326 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) {
327 //Handle the this temp
329 MySet<Edge> edges=(oldnodeset!=null)?GraphManip.getDiffEdges(delta, tmpthis):GraphManip.getEdges(graph, delta, tmpthis);
330 newDelta.varedgeadd.put(tmpthis, (MySet<Edge>) edges.clone());
331 edgeset.addAll(edges);
333 AllocNode dstnode=e.dst;
334 if (!nodeset.contains(dstnode)&&(oldnodeset==null||!oldnodeset.contains(dstnode))) {
335 TypeDescriptor type=dstnode.getType();
336 if (!type.isArray()) {
337 targetSet.add(type.getClassDesc());
339 //arrays don't have code
340 targetSet.add(typeUtil.getClass(TypeUtil.ObjectClass));
342 nodeset.add(dstnode);
343 tovisit.add(dstnode);
349 /* This function compute the edges for a call's parameters. */
351 void processParams(Graph graph, Delta delta, Delta newDelta, HashSet<AllocNode> nodeset, Stack<AllocNode> tovisit, MySet<Edge> edgeset, FlatCall fcall, boolean diff) {
352 //Go through each temp
353 for(int i=0;i<fcall.numArgs();i++) {
354 TempDescriptor tmp=fcall.getArg(i);
355 MySet<Edge> edges=diff?GraphManip.getDiffEdges(delta, tmp):GraphManip.getEdges(graph, delta, tmp);
356 newDelta.varedgeadd.put(tmp, (MySet<Edge>) edges.clone());
357 edgeset.addAll(edges);
359 if (!nodeset.contains(e.dst)) {
367 /* This function computes the reachable nodes for a callee. */
369 void computeReachableNodes(Graph graph, Delta delta, Delta newDelta, HashSet<AllocNode> nodeset, Stack<AllocNode> tovisit, MySet<Edge> edgeset, HashSet<AllocNode> oldnodeset) {
370 while(!tovisit.isEmpty()) {
371 AllocNode node=tovisit.pop();
372 MySet<Edge> edges=GraphManip.getEdges(graph, delta, node);
373 newDelta.heapedgeadd.put(node, edges);
374 edgeset.addAll(edges);
376 if (!nodeset.contains(e.dst)&&(oldnodeset==null||!oldnodeset.contains(e.dst))) {
384 HashSet<MethodDescriptor> computeTargets(FlatCall fcall, Delta newDelta) {
385 TempDescriptor tmpthis=fcall.getThis();
386 MethodDescriptor md=fcall.getMethod();
387 HashSet<MethodDescriptor> targets=new HashSet<MethodDescriptor>();
392 for(Edge e:newDelta.varedgeadd.get(tmpthis)) {
393 AllocNode node=e.dst;
394 ClassDescriptor cd=node.getType().getClassDesc();
395 //Figure out exact method called and add to set
396 targets.add(cd.getCalledMethod(md));
402 void fixMapping(FlatCall fcall, HashSet<MethodDescriptor> targets, MySet<Edge> oldedgeset, Delta newDelta, BBlock callblock, int callindex) {
403 Delta basedelta=null;
404 TempDescriptor tmpthis=fcall.getThis();
406 for(MethodDescriptor calledmd:targets) {
407 FlatMethod fm=state.getMethodFlat(calledmd);
408 boolean newmethod=false;
411 HashMap<TempDescriptor, TempDescriptor> tmpMap=new HashMap<TempDescriptor, TempDescriptor>();
414 tmpMap.put(tmpthis, fm.getParameter(offset++));
416 for(int i=0;i<fcall.numArgs();i++) {
417 TempDescriptor tmp=fcall.getArg(i);
418 tmpMap.put(tmp,fm.getParameter(i+offset));
421 //Get basicblock for the method
422 BasicBlock block=getBBlock(fm);
425 if (!callMap.containsKey(fcall)) {
426 callMap.put(fcall, new HashSet<BBlock>());
429 Delta returnDelta=null;
430 if (!callMap.get(fcall).contains(block.getStart())) {
431 callMap.get(fcall).add(block.getStart());
435 if (!returnMap.containsKey(block.getExit())) {
436 returnMap.put(block.getExit(), new HashSet<PPoint>());
438 returnMap.get(block.getExit()).add(new PPoint(callblock, callindex));
440 if (bbgraphMap.containsKey(block.getExit())) {
441 //Need to push existing results to current node
442 if (returnDelta==null) {
443 returnDelta=new Delta(null, false);
444 Vector<FlatNode> exitblocknodes=block.getExit().nodes();
445 FlatExit fexit=(FlatExit)exitblocknodes.get(exitblocknodes.size()-1);
446 buildInitDelta(graphMap.get(fexit), returnDelta);
447 if (!returnDelta.heapedgeadd.isEmpty()||!returnDelta.heapedgeremove.isEmpty()||!returnDelta.varedgeadd.isEmpty()) {
448 returnDelta.setBlock(new PPoint(callblock, callindex));
449 toprocess.add(returnDelta);
452 if (!returnDelta.heapedgeadd.isEmpty()||!returnDelta.heapedgeremove.isEmpty()||!returnDelta.varedgeadd.isEmpty()) {
453 toprocess.add(returnDelta.diffBlock(new PPoint(callblock, callindex)));
459 if (oldedgeset==null) {
460 //First build of this graph
461 //Build and enqueue delta...safe to just use existing delta
462 Delta d=newDelta.changeParams(tmpMap, new PPoint(block.getStart()));
464 } else if (newmethod) {
465 if (basedelta==null) {
466 basedelta=newDelta.buildBase(oldedgeset);
468 //Build and enqueue delta
469 Delta d=basedelta.changeParams(tmpMap, new PPoint(block.getStart()));
472 //Build and enqueue delta
473 Delta d=newDelta.changeParams(tmpMap, new PPoint(block.getStart()));
480 /* This function computes all edges that start outside of the callee context and go into the callee context */
482 void computeExternalEdges(Graph graph, Delta delta, HashSet<AllocNode> nodeset, HashSet<AllocNode> deltaset, MySet<Edge> externaledgeset) {
483 //Do heap edges first
484 HashSet<AllocNode> externalnodes=new HashSet<AllocNode>();
485 externalnodes.addAll(delta.baseheapedge.keySet());
486 externalnodes.addAll(delta.heapedgeadd.keySet());
487 externalnodes.addAll(delta.heapedgeremove.keySet());
488 //remove allinternal nodes
489 externalnodes.removeAll(nodeset);
490 for(AllocNode extNode:externalnodes) {
491 //Compute set of edges from given node
492 MySet<Edge> edges=new MySet<Edge>(delta.baseheapedge.get(extNode));
493 edges.removeAll(delta.heapedgeremove.get(extNode));
494 edges.addAll(delta.heapedgeadd.get(extNode));
497 if (nodeset.contains(e.dst))
498 externaledgeset.add(e);
502 //Do heap edges first
503 HashSet<TempDescriptor> temps=new HashSet<TempDescriptor>();
504 temps.addAll(delta.basevaredge.keySet());
505 temps.addAll(delta.varedgeadd.keySet());
506 temps.addAll(delta.varedgeremove.keySet());
507 //remove allinternal nodes
508 temps.removeAll(nodeset);
510 for(TempDescriptor tmp:temps) {
511 //Compute set of edges from given node
512 MySet<Edge> edges=new MySet<Edge>(delta.basevaredge.get(tmp));
514 edges.removeAll(delta.varedgeremove.get(tmp));
515 edges.addAll(delta.varedgeadd.get(tmp));
518 if (nodeset.contains(e.dst))
519 externaledgeset.add(e);
524 /* This function removes the caller reachable edges from the
527 void removeEdges(Delta delta, HashSet<AllocNode> nodeset, MySet<Edge> edgeset, MySet<Edge> externaledgeset) {
528 //Want to remove the set of internal edges
529 for(Edge e:edgeset) {
531 delta.removeHeapEdge(e);
535 //Want to remove the set of external edges
536 for(Edge e:externaledgeset) {
537 //want to remove the set of internal edges
542 Delta processFlatCall(BBlock callblock, int callindex, FlatCall fcall, Delta delta, Graph graph) {
543 Delta newDelta=new Delta(null, false);
545 if (delta.getInit()) {
546 MySet<Edge> edgeset=new MySet<Edge>();
547 MySet<Edge> externaledgeset=new MySet<Edge>();
548 HashSet<AllocNode> nodeset=new HashSet<AllocNode>();
549 HashSet<ClassDescriptor> targetSet=new HashSet<ClassDescriptor>();
550 Stack<AllocNode> tovisit=new Stack<AllocNode>();
551 TempDescriptor tmpthis=fcall.getThis();
553 //Handle the this temp
554 processThisTargets(targetSet, graph, delta, newDelta, nodeset, tovisit, edgeset, tmpthis, null);
556 //Go through each temp
557 processParams(graph, delta, newDelta, nodeset, tovisit, edgeset, fcall, false);
559 //Traverse all reachable nodes
560 computeReachableNodes(graph, delta, newDelta, nodeset, tovisit, edgeset, null);
562 //Compute call targets
563 HashSet<MethodDescriptor> targets=computeTargets(fcall, newDelta);
566 fixMapping(fcall, targets, null, newDelta, callblock, callindex);
568 //Compute edges into region to splice out
569 computeExternalEdges(graph, delta, nodeset, null, externaledgeset);
571 //Splice out internal edges
572 removeEdges(delta, nodeset, edgeset, externaledgeset);
574 //store data structures
575 graph.externalEdgeSet=externaledgeset;
576 graph.reachNode=nodeset;
577 graph.reachEdge=edgeset;
579 graph.callNodeAges=new HashSet<AllocNode>();
580 graph.callOldNodes=new HashSet<AllocNode>();
582 //Apply diffs to graph
583 applyDiffs(graph, delta, true);
585 MySet<Edge> edgeset=new MySet<Edge>();
586 MySet<Edge> externaledgeset=new MySet<Edge>();
587 HashSet<AllocNode> nodeset=new HashSet<AllocNode>();
588 MySet<Edge> oldedgeset=graph.reachEdge;
589 HashSet<AllocNode> oldnodeset=graph.reachNode;
591 HashSet<ClassDescriptor> targetSet=new HashSet<ClassDescriptor>();
592 Stack<AllocNode> tovisit=new Stack<AllocNode>();
593 TempDescriptor tmpthis=fcall.getThis();
595 //Handle the this temp
596 processThisTargets(targetSet, graph, delta, newDelta, nodeset, tovisit, edgeset, tmpthis, oldnodeset);
598 //Go through each temp
599 processParams(graph, delta, newDelta, nodeset, tovisit, edgeset, fcall, true);
601 //Go through each new heap edge that starts from old node
602 MySet<Edge> newedges=GraphManip.getDiffEdges(delta, oldnodeset);
603 edgeset.addAll(newedges);
604 for(Edge e:newedges) {
605 if (!nodeset.contains(e.dst)&&!oldnodeset.contains(e.dst)) {
611 //Traverse all reachable nodes
612 computeReachableNodes(graph, delta, newDelta, nodeset, tovisit, edgeset, oldnodeset);
614 //Compute call targets
615 HashSet<MethodDescriptor> targets=computeTargets(fcall, newDelta);
617 //add in new nodeset and edgeset
618 oldnodeset.addAll(nodeset);
619 oldedgeset.addAll(edgeset);
622 fixMapping(fcall, targets, oldedgeset, newDelta, callblock, callindex);
624 //Compute edges into region to splice out
625 computeExternalEdges(graph, delta, oldnodeset, nodeset, externaledgeset);
627 //Splice out internal edges
628 removeEdges(delta, nodeset, edgeset, externaledgeset);
630 //Add in new external edges
631 graph.externalEdgeSet.addAll(externaledgeset);
633 //Apply diffs to graph
634 applyDiffs(graph, delta);
639 /* This function applies callee deltas to the caller heap. */
641 Delta applyCallDelta(Delta delta, BBlock bblock) {
642 Delta newDelta=new Delta(null, false);
643 Vector<FlatNode> nodes=bblock.nodes();
644 PPoint ppoint=delta.getBlock();
645 FlatCall fcall=(FlatCall)nodes.get(ppoint.getIndex());
646 Graph graph=graphMap.get(fcall);
647 Graph oldgraph=(ppoint.getIndex()==0)?
648 bbgraphMap.get(bblock):
649 graphMap.get(nodes.get(ppoint.getIndex()-1));
651 //Age outside nodes if necessary
652 for(Iterator<AllocNode> nodeit=delta.addNodeAges.iterator();nodeit.hasNext();) {
653 AllocNode node=nodeit.next();
654 if (!graph.callNodeAges.contains(node)) {
655 graph.callNodeAges.add(node);
659 if (!graph.reachNode.contains(node)&&!node.isSummary()) {
660 /* Need to age node in existing graph*/
661 summarizeInGraph(graph, newDelta, node);
665 for(Map.Entry<AllocNode, MySet<Edge>> entry:delta.heapedgeadd.entrySet()) {
666 for(Edge e:entry.getValue()) {
667 boolean addedge=false;
669 if (e.statuspredicate==Edge.NEW) {
672 Edge origEdgeKey=e.makeStatus(allocFactory);
673 if (oldgraph.nodeMap.containsKey(origEdgeKey.src)&&
674 oldgraph.nodeMap.get(origEdgeKey.src).contains(origEdgeKey)) {
675 Edge origEdge=oldgraph.nodeMap.get(origEdgeKey.src).get(origEdgeKey);
677 origEdgeKey.statuspredicate=origEdge.statuspredicate;
678 edgetoadd=origEdgeKey;
681 mergeEdge(graph, newDelta, edgetoadd);
684 //Add external edges in
685 for(Edge e:graph.externalEdgeSet) {
686 //First did we age the source
687 Edge newedge=e.copy();
688 if (newedge.src!=null&&!e.src.isSummary()&&graph.callNodeAges.contains(e.src)) {
689 AllocNode summaryNode=allocFactory.getAllocNode(newedge.src, true);
690 newedge.src=summaryNode;
693 if (graph.callNodeAges.contains(e.dst)&&!e.dst.isSummary()) {
694 if (graph.callOldNodes.contains(e.dst)) {
696 Edge copy=newedge.copy();
697 mergeEdge(graph, newDelta, copy);
699 //Now add summarized node
700 newedge.dst=allocFactory.getAllocNode(newedge.dst, true);
701 mergeEdge(graph, newDelta, newedge);
703 //Add edge to single node
704 mergeEdge(graph, newDelta, newedge);
707 //Add edge for return value
708 if (fcall.getReturnTemp()!=null) {
709 MySet<Edge> returnedge=delta.varedgeadd.get(returntmp);
710 if (returnedge!=null)
711 for(Edge e:returnedge) {
712 Edge newedge=e.copy();
713 newedge.srcvar=fcall.getReturnTemp();
714 if (graph.getEdges(fcall.getReturnTemp())==null||!graph.getEdges(fcall.getReturnTemp()).contains(newedge))
715 newDelta.addEdge(newedge);
718 applyDiffs(graph, newDelta);
722 public void mergeEdge(Graph graph, Delta newDelta, Edge edgetoadd) {
723 if (edgetoadd!=null) {
724 Edge match=graph.getMatch(edgetoadd);
726 if (match==null||!match.subsumes(edgetoadd)) {
727 Edge mergededge=edgetoadd.merge(match);
728 newDelta.addEdge(mergededge);
734 /* Summarizes out of context nodes in graph */
735 void summarizeInGraph(Graph graph, Delta newDelta, AllocNode singleNode) {
736 AllocNode summaryNode=allocFactory.getAllocNode(singleNode, true);
738 //Handle outgoing heap edges
739 MySet<Edge> edgeset=graph.getEdges(singleNode);
741 for(Edge e:edgeset) {
742 Edge rewrite=e.rewrite(singleNode, summaryNode);
744 newDelta.removeHeapEdge(e);
745 mergeEdge(graph, newDelta, rewrite);
748 //Handle incoming edges
749 MySet<Edge> backedges=graph.getBackEdges(singleNode);
750 for(Edge e:backedges) {
751 if (e.dst==singleNode) {
752 //Need to get original edge so that predicate will be correct
753 Edge match=graph.getMatch(e);
754 Edge rewrite=match.rewrite(singleNode, summaryNode);
755 newDelta.removeEdge(match);
756 mergeEdge(graph, newDelta, rewrite);
761 void applyDiffs(Graph graph, Delta delta) {
762 applyDiffs(graph, delta, false);
765 void applyDiffs(Graph graph, Delta delta, boolean genbackwards) {
766 //build backwards map if requested
767 if (genbackwards&&graph.backMap==null) {
768 graph.backMap=new HashMap<AllocNode, MySet<Edge>>();
769 if (graph.parent.backMap==null) {
770 graph.parent.backMap=new HashMap<AllocNode, MySet<Edge>>();
771 for(Map.Entry<AllocNode, MySet<Edge>> entry:graph.nodeMap.entrySet()) {
772 for(Edge e:entry.getValue()) {
773 if (!graph.parent.backMap.containsKey(e.dst))
774 graph.parent.backMap.put(e.dst, new MySet<Edge>());
775 graph.parent.backMap.get(e.dst).add(e);
778 for(Map.Entry<TempDescriptor, MySet<Edge>> entry:graph.varMap.entrySet()) {
779 for(Edge e:entry.getValue()) {
780 if (!graph.parent.backMap.containsKey(e.dst))
781 graph.parent.backMap.put(e.dst, new MySet<Edge>());
782 graph.parent.backMap.get(e.dst).add(e);
788 //Add hidden base edges
789 for(Map.Entry<AllocNode, MySet<Edge>> e: delta.baseheapedge.entrySet()) {
790 AllocNode node=e.getKey();
791 MySet<Edge> edges=e.getValue();
792 if (graph.nodeMap.containsKey(node)) {
793 MySet<Edge> nodeEdges=graph.nodeMap.get(node);
794 nodeEdges.addAll(edges);
799 for(Map.Entry<AllocNode, MySet<Edge>> e: delta.heapedgeremove.entrySet()) {
800 AllocNode node=e.getKey();
801 MySet<Edge> edgestoremove=e.getValue();
802 if (graph.nodeMap.containsKey(node)) {
803 //Just apply diff to current map
804 graph.nodeMap.get(node).removeAll(edgestoremove);
806 //Generate diff from parent graph
807 MySet<Edge> parentedges=graph.parent.nodeMap.get(node);
808 if (parentedges!=null) {
809 MySet<Edge> newedgeset=Util.setSubtract(parentedges, edgestoremove);
810 graph.nodeMap.put(node, newedgeset);
816 for(Map.Entry<AllocNode, MySet<Edge>> e: delta.heapedgeadd.entrySet()) {
817 AllocNode node=e.getKey();
818 MySet<Edge> edgestoadd=e.getValue();
819 //If we have not done a subtract, then
820 if (!graph.nodeMap.containsKey(node)) {
821 //Copy the parent entry
822 if (graph.parent.nodeMap.containsKey(node))
823 graph.nodeMap.put(node, (MySet<Edge>)graph.parent.nodeMap.get(node).clone());
825 graph.nodeMap.put(node, new MySet<Edge>());
827 graph.nodeMap.get(node).addAll(edgestoadd);
829 for(Edge eadd:edgestoadd) {
830 if (!graph.backMap.containsKey(eadd.dst))
831 graph.backMap.put(eadd.dst, new MySet<Edge>());
832 graph.backMap.get(eadd.dst).add(eadd);
838 for(Map.Entry<TempDescriptor, MySet<Edge>> e: delta.varedgeremove.entrySet()) {
839 TempDescriptor tmp=e.getKey();
840 MySet<Edge> edgestoremove=e.getValue();
842 if (graph.varMap.containsKey(tmp)) {
843 //Just apply diff to current map
844 graph.varMap.get(tmp).removeAll(edgestoremove);
845 } else if (graph.parent.varMap.containsKey(tmp)) {
846 //Generate diff from parent graph
847 MySet<Edge> parentedges=graph.parent.varMap.get(tmp);
848 MySet<Edge> newedgeset=Util.setSubtract(parentedges, edgestoremove);
849 graph.varMap.put(tmp, newedgeset);
854 for(Map.Entry<TempDescriptor, MySet<Edge>> e: delta.varedgeadd.entrySet()) {
855 TempDescriptor tmp=e.getKey();
856 MySet<Edge> edgestoadd=e.getValue();
857 graph.varMap.put(tmp, (MySet<Edge>) edgestoadd.clone());
859 for(Edge eadd:edgestoadd) {
860 if (!graph.backMap.containsKey(eadd.dst))
861 graph.backMap.put(eadd.dst, new MySet<Edge>());
862 graph.backMap.get(eadd.dst).add(eadd);
868 for(AllocNode node:delta.addNodeAges) {
869 graph.nodeAges.add(node);
872 for(Map.Entry<AllocNode, Boolean> nodeentry:delta.addOldNodes.entrySet()) {
873 AllocNode node=nodeentry.getKey();
874 Boolean ispresent=nodeentry.getValue();
875 graph.oldNodes.put(node, ispresent);
879 Delta processSetFieldElementNode(FlatNode node, Delta delta, Graph graph) {
883 if (node.kind()==FKind.FlatSetElementNode) {
884 FlatSetElementNode fen=(FlatSetElementNode) node;
889 FlatSetFieldNode ffn=(FlatSetFieldNode) node;
894 if (delta.getInit()) {
895 HashSet<AllocNode> srcNodes=GraphManip.getNodes(graph, delta, src);
896 HashSet<AllocNode> dstNodes=GraphManip.getNodes(graph, delta, dst);
897 MySet<Edge> edgesToAdd=GraphManip.genEdges(dstNodes, fd, srcNodes);
898 MySet<Edge> edgesToRemove=null;
899 if (dstNodes.size()==1&&!dstNodes.iterator().next().isSummary()&&fd!=null) {
900 /* Can do a strong update */
901 edgesToRemove=GraphManip.getEdges(graph, delta, dstNodes, fd);
902 graph.strongUpdateSet=edgesToRemove;
904 graph.strongUpdateSet=new MySet<Edge>();
906 updateHeapDelta(graph, delta, edgesToAdd, edgesToRemove);
907 applyDiffs(graph, delta);
909 /* First look at new sources */
910 MySet<Edge> edgesToAdd=new MySet<Edge>();
911 HashSet<AllocNode> newSrcNodes=GraphManip.getDiffNodes(delta, src);
912 HashSet<AllocNode> srcNodes=GraphManip.getNodes(graph, delta, src);
913 HashSet<AllocNode> dstNodes=GraphManip.getNodes(graph, delta, dst);
914 HashSet<AllocNode> newDstNodes=GraphManip.getDiffNodes(delta, dst);
917 MySet<Edge> edgesToRemove=null;
918 if (newDstNodes.size()!=0) {
919 if (dstNodes.size()>1&&!dstNodes.iterator().next().isSummary()&&fd!=null) {
920 /* Need to undo strong update */
921 if (graph.strongUpdateSet!=null) {
922 edgesToAdd.addAll(graph.strongUpdateSet);
923 graph.strongUpdateSet=null; //Prevent future strong updates
925 } else if (dstNodes.size()==1&&newDstNodes.size()==1&&!newDstNodes.iterator().next().isSummary()&&graph.strongUpdateSet!=null&&fd!=null) {
926 edgesToRemove=GraphManip.getEdges(graph, delta, dstNodes, fd);
927 graph.strongUpdateSet.addAll(edgesToRemove);
929 edgesToAdd.addAll(GraphManip.genEdges(newDstNodes, fd, srcNodes));
933 if (graph.strongUpdateSet!=null&&fd!=null) {
934 MySet<Edge> otherEdgesToRemove=GraphManip.getDiffEdges(delta, dstNodes);
935 if (edgesToRemove!=null)
936 edgesToRemove.addAll(otherEdgesToRemove);
938 edgesToRemove=otherEdgesToRemove;
939 graph.strongUpdateSet.addAll(otherEdgesToRemove);
942 //Next look at new destinations
943 edgesToAdd.addAll(GraphManip.genEdges(dstNodes, fd, newSrcNodes));
946 updateHeapDelta(graph, delta, edgesToAdd, edgesToRemove);
947 applyDiffs(graph, delta);
952 Delta processCopyNode(FlatNode node, Delta delta, Graph graph) {
955 if (node.kind()==FKind.FlatOpNode) {
956 FlatOpNode fon=(FlatOpNode) node;
959 } else if (node.kind()==FKind.FlatReturnNode) {
960 FlatReturnNode frn=(FlatReturnNode)node;
961 src=frn.getReturnTemp();
963 if (src==null||!src.getType().isPtr()) {
965 applyDiffs(graph, delta);
969 FlatCastNode fcn=(FlatCastNode) node;
973 if (delta.getInit()) {
974 HashSet<AllocNode> srcnodes=GraphManip.getNodes(graph, delta, src);
975 MySet<Edge> edgesToAdd=GraphManip.genEdges(dst, srcnodes);
976 MySet<Edge> edgesToRemove=GraphManip.getEdges(graph, delta, dst);
977 updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
978 applyDiffs(graph, delta);
980 /* First compute new src nodes */
981 HashSet<AllocNode> newSrcNodes=GraphManip.getDiffNodes(delta, src);
983 /* Compute the union, and then the set of edges */
984 MySet<Edge> edgesToAdd=GraphManip.genEdges(dst, newSrcNodes);
986 /* Compute set of edges to remove */
987 MySet<Edge> edgesToRemove=GraphManip.getDiffEdges(delta, dst);
990 updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
991 applyDiffs(graph, delta);
996 Delta processFieldElementNode(FlatNode node, Delta delta, Graph graph) {
1000 if (node.kind()==FKind.FlatElementNode) {
1001 FlatElementNode fen=(FlatElementNode) node;
1006 FlatFieldNode ffn=(FlatFieldNode) node;
1011 if (delta.getInit()) {
1012 HashSet<AllocNode> srcnodes=GraphManip.getNodes(graph, delta, src);
1013 HashSet<AllocNode> fdnodes=GraphManip.getNodes(graph, delta, srcnodes, fd);
1014 MySet<Edge> edgesToAdd=GraphManip.genEdges(dst, fdnodes);
1015 MySet<Edge> edgesToRemove=GraphManip.getEdges(graph, delta, dst);
1016 updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
1017 applyDiffs(graph, delta);
1019 /* First compute new objects we read fields of */
1020 HashSet<AllocNode> allsrcnodes=GraphManip.getNodes(graph, delta, src);
1021 HashSet<AllocNode> difffdnodes=GraphManip.getDiffNodes(delta, allsrcnodes, fd);
1022 /* Next compute new targets of fields */
1023 HashSet<AllocNode> newsrcnodes=GraphManip.getDiffNodes(delta, src);
1024 HashSet<AllocNode> newfdnodes=GraphManip.getNodes(graph, delta, newsrcnodes, fd);
1025 /* Compute the union, and then the set of edges */
1026 HashSet<AllocNode> newTargets=new HashSet<AllocNode>();
1027 newTargets.addAll(newfdnodes);
1028 newTargets.addAll(difffdnodes);
1029 MySet<Edge> edgesToAdd=GraphManip.genEdges(dst, newTargets);
1031 /* Compute set of edges to remove */
1032 MySet<Edge> edgesToRemove=GraphManip.getDiffEdges(delta, dst);
1035 updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
1036 applyDiffs(graph, delta);
1041 static void updateVarDelta(Graph graph, Delta delta, TempDescriptor tmp, MySet<Edge> edgestoAdd, MySet<Edge> edgestoRemove) {
1042 MySet<Edge> edgeAdd=delta.varedgeadd.get(tmp);
1043 MySet<Edge> edgeRemove=delta.varedgeremove.get(tmp);
1044 MySet<Edge> existingEdges=graph.getEdges(tmp);
1045 for(Edge e: edgestoRemove) {
1046 //remove edge from delta
1049 //if the edge is already in the graph, add an explicit remove to the delta
1050 if (existingEdges.contains(e))
1051 delta.removeVarEdge(e);
1053 for(Edge e: edgestoAdd) {
1054 //Remove the edge from the remove set
1055 if (edgeRemove!=null)
1056 edgeRemove.remove(e);
1057 //Explicitly add it to the add set unless it is already in the graph
1058 if (!existingEdges.contains(e))
1059 delta.addVarEdge(e);
1063 static void updateHeapDelta(Graph graph, Delta delta, MySet<Edge> edgestoAdd, MySet<Edge> edgestoRemove) {
1064 if (edgestoRemove!=null)
1065 for(Edge e: edgestoRemove) {
1066 AllocNode src=e.src;
1067 MySet<Edge> edgeAdd=delta.heapedgeadd.get(src);
1068 MySet<Edge> existingEdges=graph.getEdges(src);
1069 //remove edge from delta
1071 //if the edge is already in the graph, add an explicit remove to the delta
1072 if (existingEdges.contains(e)) {
1073 delta.removeHeapEdge(e);
1076 if (edgestoAdd!=null)
1077 for(Edge e: edgestoAdd) {
1078 AllocNode src=e.src;
1079 MySet<Edge> edgeRemove=delta.heapedgeremove.get(src);
1080 MySet<Edge> existingEdges=graph.getEdges(src);
1081 //Remove the edge from the remove set
1082 if (edgeRemove!=null)
1083 edgeRemove.remove(e);
1084 //Explicitly add it to the add set unless it is already in the graph
1085 if (!existingEdges.contains(e)||!existingEdges.get(e).isNew()) {
1086 delta.addHeapEdge(e);
1091 Delta processFlatNop(FlatNode node, Delta delta, Graph graph) {
1092 applyDiffs(graph, delta);
1096 Delta processNewNode(FlatNew node, Delta delta, Graph graph) {
1097 AllocNode summary=allocFactory.getAllocNode(node, true);
1098 AllocNode single=allocFactory.getAllocNode(node, false);
1099 TempDescriptor tmp=node.getDst();
1101 if (delta.getInit()) {
1102 /* We don't have to deal with summarization here... The
1103 * intuition is that this is the only place where we generate
1104 * nodes for this allocation site and this is the first time
1105 * we've analyzed this site */
1108 Edge e=new Edge(tmp, single);
1109 //Build new Edge set
1110 MySet<Edge> newedges=new MySet<Edge>();
1112 //Add it into the diffs
1113 delta.varedgeadd.put(tmp, newedges);
1114 //Remove the old edges
1115 delta.varedgeremove.put(tmp, (MySet<Edge>) graph.getEdges(tmp).clone());
1116 //Apply incoming diffs to graph
1117 applyDiffs(graph, delta);
1118 //Note that we create a single node
1119 delta.addNodeAges.add(single);
1121 if (delta.addOldNodes.containsKey(single)||delta.baseOldNodes.containsKey(single)) {
1122 delta.addOldNodes.put(single, Boolean.FALSE);
1125 /* 1. Fix up the variable edge additions */
1127 for(Iterator<Map.Entry<TempDescriptor, MySet<Edge>>> entryIt=delta.varedgeadd.entrySet().iterator();entryIt.hasNext();) {
1128 Map.Entry<TempDescriptor, MySet<Edge>> entry=entryIt.next();
1130 if (entry.getKey()==tmp) {
1131 /* Check if this is the tmp we overwrite */
1134 /* Otherwise, check if the target of the edge is changed... */
1135 summarizeSet(entry.getValue(), graph.varMap.get(entry.getKey()), single, summary);
1139 /* 2. Fix up the base variable edges */
1141 for(Iterator<Map.Entry<TempDescriptor, MySet<Edge>>> entryIt=delta.basevaredge.entrySet().iterator();entryIt.hasNext();) {
1142 Map.Entry<TempDescriptor, MySet<Edge>> entry=entryIt.next();
1143 TempDescriptor entrytmp=entry.getKey();
1144 if (entrytmp==tmp) {
1145 /* Check is this is the tmp we overwrite, if so add to remove set */
1146 Util.relationUpdate(delta.varedgeremove, tmp, null, entry.getValue());
1148 /* Check if the target of the edge is changed */
1149 MySet<Edge> newset=(MySet<Edge>)entry.getValue().clone();
1150 MySet<Edge> removeset=shrinkSet(newset, graph.varMap.get(entrytmp), single, summary);
1151 Util.relationUpdate(delta.varedgeremove, entrytmp, newset, removeset);
1152 Util.relationUpdate(delta.varedgeadd, entrytmp, null, newset);
1157 /* 3. Fix up heap edge additions */
1159 HashMap<AllocNode, MySet<Edge>> addheapedge=new HashMap<AllocNode, MySet<Edge>>();
1160 for(Iterator<Map.Entry<AllocNode, MySet<Edge>>> entryIt=delta.heapedgeadd.entrySet().iterator();entryIt.hasNext();) {
1161 Map.Entry<AllocNode, MySet<Edge>> entry=entryIt.next();
1162 MySet<Edge> edgeset=entry.getValue();
1163 AllocNode allocnode=entry.getKey();
1164 if (allocnode==single) {
1166 summarizeSet(edgeset, graph.nodeMap.get(summary), single, summary);
1167 addheapedge.put(summary, edgeset);
1169 summarizeSet(edgeset, graph.nodeMap.get(allocnode), single, summary);
1173 /* Merge in diffs */
1175 for(Map.Entry<AllocNode, MySet<Edge>> entry:addheapedge.entrySet()) {
1176 AllocNode allocnode=entry.getKey();
1177 Util.relationUpdate(delta.heapedgeadd, allocnode, null, entry.getValue());
1180 /* 4. Fix up the base heap edges */
1182 for(Iterator<Map.Entry<AllocNode, MySet<Edge>>> entryIt=delta.baseheapedge.entrySet().iterator();entryIt.hasNext();) {
1183 Map.Entry<AllocNode, MySet<Edge>> entry=entryIt.next();
1184 MySet<Edge> edgeset=entry.getValue();
1185 AllocNode allocnode=entry.getKey();
1186 if (allocnode==single) {
1189 AllocNode addnode=(allocnode==single)?summary:allocnode;
1191 MySet<Edge> newset=(MySet<Edge>) edgeset.clone();
1192 MySet<Edge> removeset=shrinkSet(newset, graph.nodeMap.get(addnode), single, summary);
1193 Util.relationUpdate(delta.heapedgeadd, addnode, null, newset);
1194 Util.relationUpdate(delta.heapedgeremove, allocnode, null, removeset);
1197 /* Update Node Ages...If the base or addNodeAges set contains a
1198 * single node, it now should also contain a summary node... No
1199 * need to generate a single node as that has already been
1201 if (delta.baseNodeAges.contains(single)||delta.addNodeAges.contains(single)) {
1202 delta.addNodeAges.add(summary);
1205 //Kill the old node if someone tries to add it
1206 if (delta.addOldNodes.containsKey(single)||delta.baseOldNodes.containsKey(single)) {
1207 delta.addOldNodes.put(single, Boolean.FALSE);
1210 //Apply incoming diffs to graph
1211 applyDiffs(graph, delta);
1216 /* This function builds a new edge set where oldnode is summarized into new node */
1218 void summarizeSet(MySet<Edge> edgeset, MySet<Edge> oldedgeset, AllocNode oldnode, AllocNode sumnode) {
1219 MySet<Edge> newSet=null;
1220 for(Iterator<Edge> edgeit=edgeset.iterator();edgeit.hasNext();) {
1221 Edge e=edgeit.next();
1222 if (e.dst==oldnode||e.src==oldnode) {
1224 newSet=new MySet<Edge>();
1229 if (e.dst==oldnode) {
1232 if (e.src==oldnode) {
1235 if (oldedgeset==null||!oldedgeset.contains(e))
1240 edgeset.addAll(newSet);
1243 /* Shrinks the incoming set to just include rewritten values.
1244 * Returns a set of the original rewritten values */
1246 MySet<Edge> shrinkSet(MySet<Edge> edgeset, MySet<Edge> oldedgeset, AllocNode oldnode, AllocNode newnode) {
1247 MySet<Edge> newSet=null;
1248 MySet<Edge> removeSet=null;
1249 for(Iterator<Edge> edgeit=edgeset.iterator();edgeit.hasNext();) {
1250 Edge e=edgeit.next();
1252 if (e.dst==oldnode||e.src==oldnode) {
1254 newSet=new MySet<Edge>();
1255 removeSet=new MySet<Edge>();
1258 removeSet.add(e.copy());
1263 if (oldedgeset==null||!oldedgeset.contains(e))
1268 edgeset.addAll(newSet);
1272 /* This function returns a completely new Delta... It is safe to
1275 Delta applyInitDelta(Delta delta, BBlock block) {
1276 //Apply delta to graph
1277 boolean newGraph=false;
1278 if (!bbgraphMap.containsKey(block)) {
1279 bbgraphMap.put(block, new Graph(null));
1283 Graph graph=bbgraphMap.get(block);
1286 newdelta=new Delta(null, true);
1287 //Add in heap edges and throw away original diff
1288 graph.nodeMap.putAll(delta.heapedgeadd);
1289 //Add in var edges and throw away original diff
1290 graph.varMap.putAll(delta.varedgeadd);
1291 //Record that this is initial set...
1292 graph.nodeAges.addAll(delta.addNodeAges);
1294 for(Map.Entry<AllocNode, Boolean> oldentry:delta.addOldNodes.entrySet()) {
1295 if (oldentry.getValue().booleanValue()) {
1296 graph.oldNodes.put(oldentry.getKey(), Boolean.TRUE);
1300 newdelta=new Delta(null, false);
1301 //merge in heap edges and variables
1302 mergeHeapEdges(graph, delta, newdelta);
1303 mergeVarEdges(graph, delta, newdelta);
1304 mergeAges(graph, delta, newdelta);
1310 /* This function merges in the heap edges. It updates delta to be
1313 void mergeHeapEdges(Graph graph, Delta delta, Delta newdelta) {
1315 for(Map.Entry<AllocNode, MySet<Edge>> heapedge:delta.heapedgeadd.entrySet()) {
1316 AllocNode nsrc=heapedge.getKey();
1317 MySet<Edge> edges=heapedge.getValue();
1319 if (graph.backMap!=null) {
1321 if (!graph.backMap.containsKey(e.dst))
1322 graph.backMap.put(e.dst, new MySet<Edge>());
1323 graph.backMap.get(e.dst).add(e);
1327 if (!graph.nodeMap.containsKey(nsrc)) {
1328 graph.nodeMap.put(nsrc, new MySet<Edge>());
1330 MySet<Edge> dstedges=graph.nodeMap.get(nsrc);
1331 MySet<Edge> diffedges=new MySet<Edge>();
1333 if (!dstedges.contains(e)) {
1334 //We have a new edge
1338 Edge origedge=dstedges.get(e);
1339 if (!origedge.subsumes(e)) {
1340 Edge mergededge=origedge.merge(e);
1341 diffedges.add(mergededge);
1342 dstedges.add(mergededge);
1346 //Done with edge set...
1347 if (diffedges.size()>0) {
1349 newdelta.baseheapedge.put(nsrc, diffedges);
1354 /* This function merges in the var edges. It updates delta to be
1357 void mergeVarEdges(Graph graph, Delta delta, Delta newdelta) {
1359 for(Map.Entry<TempDescriptor, MySet<Edge>> varedge:delta.varedgeadd.entrySet()) {
1360 TempDescriptor tmpsrc=varedge.getKey();
1361 MySet<Edge> edges=varedge.getValue();
1362 if (graph.backMap!=null) {
1364 if (!graph.backMap.containsKey(e.dst))
1365 graph.backMap.put(e.dst, new MySet<Edge>());
1366 graph.backMap.get(e.dst).add(e);
1370 if (!graph.varMap.containsKey(tmpsrc)) {
1371 graph.varMap.put(tmpsrc, new MySet<Edge>());
1373 MySet<Edge> dstedges=graph.varMap.get(tmpsrc);
1374 MySet<Edge> diffedges=new MySet<Edge>();
1376 if (!dstedges.contains(e)) {
1377 //We have a new edge
1382 //Done with edge set...
1383 if (diffedges.size()>0) {
1385 newdelta.basevaredge.put(tmpsrc,diffedges);
1390 void mergeAges(Graph graph, Delta delta, Delta newDelta) {
1392 for(AllocNode node:delta.addNodeAges) {
1393 if (!graph.nodeAges.contains(node)) {
1394 graph.nodeAges.add(node);
1395 newDelta.baseNodeAges.add(node);
1398 for(Map.Entry<AllocNode, Boolean> oldentry:delta.addOldNodes.entrySet()) {
1399 AllocNode node=oldentry.getKey();
1400 boolean ispresent=oldentry.getValue().booleanValue();
1401 if (ispresent&&!graph.oldNodes.containsKey(node)) {
1402 graph.oldNodes.put(node, Boolean.TRUE);
1403 newDelta.baseOldNodes.put(node, Boolean.TRUE);