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;
22 public Pointer(State state, TypeUtil typeUtil) {
24 this.blockMap=new HashMap<FlatMethod, BasicBlock>();
25 this.bbgraphMap=new HashMap<BBlock, Graph>();
26 this.graphMap=new HashMap<FlatNode, Graph>();
27 this.callMap=new HashMap<FlatCall, Set<BBlock>>();
28 this.returnMap=new HashMap<BBlock, Set<PPoint>>();
29 this.typeUtil=typeUtil;
30 this.allocFactory=new AllocFactory(state, typeUtil);
31 this.toprocess=new LinkedList<Delta>();
32 ClassDescriptor stringcd=typeUtil.getClass(TypeUtil.ObjectClass);
33 this.returntmp=new TempDescriptor("RETURNVAL", stringcd);
36 public BasicBlock getBBlock(FlatMethod fm) {
37 if (!blockMap.containsKey(fm))
38 blockMap.put(fm, BasicBlock.getBBlock(fm));
39 return blockMap.get(fm);
42 Delta buildInitialContext() {
43 MethodDescriptor md=typeUtil.getMain();
44 FlatMethod fm=state.getMethodFlat(md);
45 BasicBlock bb=getBBlock(fm);
46 BBlock start=bb.getStart();
47 Delta delta=new Delta(new PPoint(start), true);
48 MySet<Edge> arrayset=new MySet<Edge>();
49 MySet<Edge> varset=new MySet<Edge>();
50 Edge arrayedge=new Edge(allocFactory.StringArray, null, allocFactory.Strings);
51 Edge stringedge=new Edge(fm.getParameter(0), allocFactory.StringArray);
52 delta.addHeapEdge(arrayedge);
53 delta.addVarEdge(stringedge);
58 public void doAnalysis() {
59 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 if (ppoint.getIndex()==-1) {
68 //Build base graph for entrance to this basic block
69 delta=applyInitDelta(delta, bblock);
71 startindex=ppoint.getIndex()+1;
72 delta=applyCallDelta(delta, bblock);
75 Graph graph=bbgraphMap.get(bblock);
77 //Compute delta at exit of each node
78 for(int i=startindex; i<nodes.size();i++) {
79 FlatNode currNode=nodes.get(i);
80 if (!graphMap.containsKey(currNode)) {
81 graphMap.put(currNode, new Graph(graph));
83 nodeGraph=graphMap.get(currNode);
84 delta=processNode(bblock, i, currNode, delta, nodeGraph);
86 generateFinalDelta(bblock, delta, nodeGraph);
91 for(Map.Entry<BBlock, Graph> e:bbgraphMap.entrySet()) {
94 PrintWriter pw=new PrintWriter(new FileWriter("BB"+debugindex+".dot"));
95 g.printGraph(pw, "BB");
97 } catch (Exception ex) {
103 for(Map.Entry<FlatNode, Graph> e:graphMap.entrySet()) {
104 FlatNode fn=e.getKey();
105 Graph g=e.getValue();
107 PrintWriter pw=new PrintWriter(new FileWriter("FN"+fn.toString().replace(' ','_')+".dot"));
108 g.printGraph(pw, fn.toString());
110 } catch (Exception ex) {
111 ex.printStackTrace();
115 for(FlatMethod fm:blockMap.keySet()) {
120 /* This function builds the last delta for a basic block. It
121 * handles the case for the first time the basic block is
124 void buildInitDelta(Graph graph, Delta newDelta) {
125 //First compute the set of temps
126 HashSet<TempDescriptor> tmpSet=new HashSet<TempDescriptor>();
127 tmpSet.addAll(graph.varMap.keySet());
128 tmpSet.addAll(graph.parent.varMap.keySet());
130 //Next build the temp map part of the delta
131 for(TempDescriptor tmp:tmpSet) {
132 MySet<Edge> edgeSet=new MySet<Edge>();
134 if (graph.varMap.containsKey(tmp))
135 edgeSet.addAll(graph.varMap.get(tmp));
137 edgeSet.addAll(graph.parent.varMap.get(tmp));
138 newDelta.varedgeadd.put(tmp, edgeSet);
141 //Next compute the set of src allocnodes
142 HashSet<AllocNode> nodeSet=new HashSet<AllocNode>();
143 nodeSet.addAll(graph.nodeMap.keySet());
144 nodeSet.addAll(graph.parent.nodeMap.keySet());
146 for(AllocNode node:nodeSet) {
147 MySet<Edge> edgeSet=new MySet<Edge>();
149 if (graph.nodeMap.containsKey(node))
150 edgeSet.addAll(graph.nodeMap.get(node));
152 edgeSet.addAll(graph.parent.nodeMap.get(node));
153 newDelta.heapedgeadd.put(node, edgeSet);
156 if (graph.nodeAges.contains(node))
157 newDelta.addNodeAges.add(node);
158 else if (graph.parent.nodeAges.contains(node))
159 newDelta.addNodeAges.add(node);
162 if (graph.oldNodes.containsKey(node)) {
163 if (graph.oldNodes.get(node).booleanValue())
164 newDelta.addOldNodes.put(node, Boolean.TRUE);
165 } else if (graph.parent.oldNodes.containsKey(node)) {
166 //parent graphs only contain true...no need to check
167 newDelta.addOldNodes.put(node, Boolean.TRUE);
172 /* This function build the delta for the exit of a basic block. */
174 void generateFinalDelta(BBlock bblock, Delta delta, Graph graph) {
175 Delta newDelta=new Delta(null, false);
176 if (delta.getInit()) {
177 buildInitDelta(graph, newDelta);
179 /* We can break the old delta...it is done being used */
180 /* First we will build variable edges */
181 HashSet<TempDescriptor> tmpSet=new HashSet<TempDescriptor>();
182 tmpSet.addAll(delta.basevaredge.keySet());
183 tmpSet.addAll(delta.varedgeadd.keySet());
184 for(TempDescriptor tmp:tmpSet) {
185 /* Start with the new incoming edges */
186 MySet<Edge> newbaseedge=delta.basevaredge.get(tmp);
187 /* Remove the remove set */
188 newbaseedge.removeAll(delta.varedgeremove.get(tmp));
189 /* Add in the new set*/
190 newbaseedge.addAll(delta.varedgeadd.get(tmp));
191 /* Store the results */
192 newDelta.varedgeadd.put(tmp, newbaseedge);
194 delta.basevaredge.clear();
196 /* Next we build heap edges */
197 HashSet<AllocNode> nodeSet=new HashSet<AllocNode>();
198 nodeSet.addAll(delta.baseheapedge.keySet());
199 nodeSet.addAll(delta.heapedgeadd.keySet());
200 nodeSet.addAll(delta.heapedgeremove.keySet());
201 for(AllocNode node:nodeSet) {
202 /* Start with the new incoming edges */
203 MySet<Edge> newheapedge=(MySet<Edge>) delta.baseheapedge.get(node).clone();
204 /* Remove the remove set */
205 MySet<Edge> removeset=delta.heapedgeremove.get(node);
208 newheapedge.removeAll(removeset);
210 /* Add in the add set */
211 MySet<Edge> settoadd=delta.heapedgeadd.get(node);
213 newheapedge.addAll(settoadd);
214 newDelta.heapedgeadd.put(node, newheapedge);
216 /* Remove the newly created edges..no need to propagate a diff for those */
217 if (removeset!=null) {
218 removeset.removeAll(delta.baseheapedge.get(node));
219 newDelta.heapedgeremove.put(node, removeset);
223 /* Compute new ages */
224 newDelta.addNodeAges.addAll(delta.baseNodeAges);
225 newDelta.addNodeAges.addAll(delta.addNodeAges);
226 HashSet<AllocNode> oldNodes=new HashSet<AllocNode>();
228 /* Compute whether old nodes survive */
229 oldNodes.addAll(delta.baseOldNodes.keySet());
230 oldNodes.addAll(delta.addOldNodes.keySet());
231 for(AllocNode node:oldNodes) {
232 if (delta.addOldNodes.containsKey(node)) {
233 if (delta.addOldNodes.get(node).booleanValue()) {
234 newDelta.addOldNodes.put(node, Boolean.TRUE);
237 if (delta.baseOldNodes.get(node).booleanValue()) {
238 newDelta.addOldNodes.put(node, Boolean.TRUE);
244 /* Now we need to propagate newdelta */
245 if (!newDelta.heapedgeadd.isEmpty()||!newDelta.heapedgeremove.isEmpty()||!newDelta.varedgeadd.isEmpty()||!newDelta.addNodeAges.isEmpty()||!newDelta.addOldNodes.isEmpty()) {
246 /* We have a delta to propagate */
247 Vector<BBlock> blockvector=bblock.next();
248 for(int i=0;i<blockvector.size();i++) {
250 newDelta.setBlock(new PPoint(blockvector.get(i)));
251 toprocess.add(newDelta);
253 Delta d=newDelta.diffBlock(new PPoint(blockvector.get(i)));
260 Delta processNode(BBlock bblock, int index, FlatNode node, Delta delta, Graph newgraph) {
261 switch(node.kind()) {
263 return processNewNode((FlatNew)node, delta, newgraph);
264 case FKind.FlatFieldNode:
265 case FKind.FlatElementNode:
266 return processFieldElementNode(node, delta, newgraph);
267 case FKind.FlatCastNode:
268 case FKind.FlatOpNode:
269 case FKind.FlatReturnNode:
270 return processCopyNode(node, delta, newgraph);
271 case FKind.FlatSetFieldNode:
272 case FKind.FlatSetElementNode:
273 return processSetFieldElementNode(node, delta, newgraph);
274 case FKind.FlatMethod:
276 return processFlatNop(node, delta, newgraph);
278 return processFlatCall(bblock, index, (FlatCall) node, delta, newgraph);
279 case FKind.FlatSESEEnterNode:
280 case FKind.FlatSESEExitNode:
281 throw new Error("Unimplemented node:"+node);
283 throw new Error("Unrecognized node:"+node);
287 /* This function compute the edges for the this variable for a
288 * callee if it exists. */
290 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) {
291 //Handle the this temp
293 MySet<Edge> edges=(oldnodeset!=null)?GraphManip.getDiffEdges(delta, tmpthis):GraphManip.getEdges(graph, delta, tmpthis);
294 newDelta.varedgeadd.put(tmpthis, (MySet<Edge>) edges.clone());
295 edgeset.addAll(edges);
297 AllocNode dstnode=e.dst;
298 if (!nodeset.contains(dstnode)&&(oldnodeset==null||!oldnodeset.contains(dstnode))) {
299 TypeDescriptor type=dstnode.getType();
300 if (!type.isArray()) {
301 targetSet.add(type.getClassDesc());
303 //arrays don't have code
304 targetSet.add(typeUtil.getClass(TypeUtil.ObjectClass));
306 nodeset.add(dstnode);
307 tovisit.add(dstnode);
313 /* This function compute the edges for a call's parameters. */
315 void processParams(Graph graph, Delta delta, Delta newDelta, HashSet<AllocNode> nodeset, Stack<AllocNode> tovisit, MySet<Edge> edgeset, FlatCall fcall, boolean diff) {
316 //Go through each temp
317 for(int i=0;i<fcall.numArgs();i++) {
318 TempDescriptor tmp=fcall.getArg(i);
319 MySet<Edge> edges=diff?GraphManip.getDiffEdges(delta, tmp):GraphManip.getEdges(graph, delta, tmp);
320 newDelta.varedgeadd.put(tmp, (MySet<Edge>) edges.clone());
321 edgeset.addAll(edges);
323 if (!nodeset.contains(e.dst)) {
331 /* This function computes the reachable nodes for a callee. */
333 void computeReachableNodes(Graph graph, Delta delta, Delta newDelta, HashSet<AllocNode> nodeset, Stack<AllocNode> tovisit, MySet<Edge> edgeset, HashSet<AllocNode> oldnodeset) {
334 while(!tovisit.isEmpty()) {
335 AllocNode node=tovisit.pop();
336 MySet<Edge> edges=GraphManip.getEdges(graph, delta, node);
337 newDelta.heapedgeadd.put(node, edges);
338 edgeset.addAll(edges);
340 if (!nodeset.contains(e.dst)&&(oldnodeset==null||!oldnodeset.contains(e.dst))) {
348 HashSet<MethodDescriptor> computeTargets(FlatCall fcall, Delta newDelta) {
349 TempDescriptor tmpthis=fcall.getThis();
350 MethodDescriptor md=fcall.getMethod();
351 HashSet<MethodDescriptor> targets=new HashSet<MethodDescriptor>();
356 for(Edge e:newDelta.varedgeadd.get(tmpthis)) {
357 AllocNode node=e.dst;
358 ClassDescriptor cd=node.getType().getClassDesc();
359 //Figure out exact method called and add to set
360 targets.add(cd.getCalledMethod(md));
366 void fixMapping(FlatCall fcall, HashSet<MethodDescriptor> targets, MySet<Edge> oldedgeset, Delta newDelta, BBlock callblock, int callindex) {
367 Delta basedelta=null;
368 TempDescriptor tmpthis=fcall.getThis();
370 for(MethodDescriptor calledmd:targets) {
371 FlatMethod fm=state.getMethodFlat(calledmd);
372 boolean newmethod=false;
375 HashMap<TempDescriptor, TempDescriptor> tmpMap=new HashMap<TempDescriptor, TempDescriptor>();
378 tmpMap.put(tmpthis, fm.getParameter(offset++));
380 for(int i=0;i<fcall.numArgs();i++) {
381 TempDescriptor tmp=fcall.getArg(i);
382 tmpMap.put(tmp,fm.getParameter(i+offset));
385 //Get basicblock for the method
386 BasicBlock block=getBBlock(fm);
389 if (!callMap.containsKey(fcall)) {
390 callMap.put(fcall, new HashSet<BBlock>());
393 Delta returnDelta=null;
394 if (!callMap.get(fcall).contains(block.getStart())) {
395 callMap.get(fcall).add(block.getStart());
399 if (!returnMap.containsKey(block.getExit())) {
400 returnMap.put(block.getExit(), new HashSet<PPoint>());
402 returnMap.get(block.getExit()).add(new PPoint(callblock, callindex));
404 if (bbgraphMap.containsKey(block.getExit())) {
405 //Need to push existing results to current node
406 if (returnDelta==null) {
407 returnDelta=new Delta(null, false);
408 buildInitDelta(bbgraphMap.get(block.getExit()), returnDelta);
409 if (!returnDelta.heapedgeadd.isEmpty()||!returnDelta.heapedgeremove.isEmpty()||!returnDelta.varedgeadd.isEmpty()) {
410 returnDelta.setBlock(new PPoint(callblock, callindex));
411 toprocess.add(returnDelta);
414 if (!returnDelta.heapedgeadd.isEmpty()||!returnDelta.heapedgeremove.isEmpty()||!returnDelta.varedgeadd.isEmpty()) {
415 toprocess.add(returnDelta.diffBlock(new PPoint(callblock, callindex)));
421 if (oldedgeset==null) {
422 //First build of this graph
423 //Build and enqueue delta...safe to just use existing delta
424 Delta d=newDelta.changeParams(tmpMap, new PPoint(block.getStart()));
426 } else if (newmethod) {
427 if (basedelta==null) {
428 basedelta=newDelta.buildBase(oldedgeset);
430 //Build and enqueue delta
431 Delta d=basedelta.changeParams(tmpMap, new PPoint(block.getStart()));
434 //Build and enqueue delta
435 Delta d=newDelta.changeParams(tmpMap, new PPoint(block.getStart()));
442 /* This function computes all edges that start outside of the callee context and go into the callee context */
444 void computeExternalEdges(Graph graph, Delta delta, HashSet<AllocNode> nodeset, HashSet<AllocNode> deltaset, MySet<Edge> externaledgeset) {
445 //Do heap edges first
446 HashSet<AllocNode> externalnodes=new HashSet<AllocNode>();
447 externalnodes.addAll(delta.baseheapedge.keySet());
448 externalnodes.addAll(delta.heapedgeadd.keySet());
449 externalnodes.addAll(delta.heapedgeremove.keySet());
450 //remove allinternal nodes
451 externalnodes.removeAll(nodeset);
452 for(AllocNode extNode:externalnodes) {
453 //Compute set of edges from given node
454 MySet<Edge> edges=new MySet<Edge>(delta.baseheapedge.get(extNode));
455 edges.removeAll(delta.heapedgeremove.get(extNode));
456 edges.addAll(delta.heapedgeadd.get(extNode));
459 if (nodeset.contains(e.dst))
460 externaledgeset.add(e);
464 //Do heap edges first
465 HashSet<TempDescriptor> temps=new HashSet<TempDescriptor>();
466 temps.addAll(delta.basevaredge.keySet());
467 temps.addAll(delta.varedgeadd.keySet());
468 temps.addAll(delta.varedgeremove.keySet());
469 //remove allinternal nodes
470 temps.removeAll(nodeset);
472 for(TempDescriptor tmp:temps) {
473 //Compute set of edges from given node
474 MySet<Edge> edges=new MySet<Edge>(delta.basevaredge.get(tmp));
476 edges.removeAll(delta.varedgeremove.get(tmp));
477 edges.addAll(delta.varedgeadd.get(tmp));
480 if (nodeset.contains(e.dst))
481 externaledgeset.add(e);
486 /* This function removes the caller reachable edges from the
489 void removeEdges(Delta delta, HashSet<AllocNode> nodeset, MySet<Edge> edgeset, MySet<Edge> externaledgeset) {
490 //Want to remove the set of internal edges
491 for(Edge e:edgeset) {
493 delta.removeHeapEdge(e);
497 //Want to remove the set of external edges
498 for(Edge e:externaledgeset) {
499 //want to remove the set of internal edges
505 Delta processFlatCall(BBlock callblock, int callindex, FlatCall fcall, Delta delta, Graph graph) {
506 Delta newDelta=new Delta(null, false);
508 if (delta.getInit()) {
509 MySet<Edge> edgeset=new MySet<Edge>();
510 MySet<Edge> externaledgeset=new MySet<Edge>();
511 HashSet<AllocNode> nodeset=new HashSet<AllocNode>();
512 HashSet<ClassDescriptor> targetSet=new HashSet<ClassDescriptor>();
513 Stack<AllocNode> tovisit=new Stack<AllocNode>();
514 TempDescriptor tmpthis=fcall.getThis();
516 //Handle the this temp
517 processThisTargets(targetSet, graph, delta, newDelta, nodeset, tovisit, edgeset, tmpthis, null);
519 //Go through each temp
520 processParams(graph, delta, newDelta, nodeset, tovisit, edgeset, fcall, false);
522 //Traverse all reachable nodes
523 computeReachableNodes(graph, delta, newDelta, nodeset, tovisit, edgeset, null);
525 //Compute call targets
526 HashSet<MethodDescriptor> targets=computeTargets(fcall, newDelta);
529 fixMapping(fcall, targets, null, newDelta, callblock, callindex);
531 //Compute edges into region to splice out
532 computeExternalEdges(graph, delta, nodeset, null, externaledgeset);
534 //Splice out internal edges
535 removeEdges(delta, nodeset, edgeset, externaledgeset);
537 //store data structures
538 graph.externalEdgeSet=externaledgeset;
539 graph.reachNode=nodeset;
540 graph.reachEdge=edgeset;
542 graph.callNodeAges=new HashSet<AllocNode>();
543 graph.callOldNodes=new HashSet<AllocNode>();
545 //Apply diffs to graph
546 applyDiffs(graph, delta, true);
548 MySet<Edge> edgeset=new MySet<Edge>();
549 MySet<Edge> externaledgeset=new MySet<Edge>();
550 HashSet<AllocNode> nodeset=new HashSet<AllocNode>();
551 MySet<Edge> oldedgeset=graph.reachEdge;
552 HashSet<AllocNode> oldnodeset=graph.reachNode;
554 HashSet<ClassDescriptor> targetSet=new HashSet<ClassDescriptor>();
555 Stack<AllocNode> tovisit=new Stack<AllocNode>();
556 TempDescriptor tmpthis=fcall.getThis();
558 //Handle the this temp
559 processThisTargets(targetSet, graph, delta, newDelta, nodeset, tovisit, edgeset, tmpthis, oldnodeset);
561 //Go through each temp
562 processParams(graph, delta, newDelta, nodeset, tovisit, edgeset, fcall, true);
564 //Go through each new heap edge that starts from old node
565 MySet<Edge> newedges=GraphManip.getDiffEdges(delta, oldnodeset);
566 edgeset.addAll(newedges);
567 for(Edge e:newedges) {
568 if (!nodeset.contains(e.dst)&&!oldnodeset.contains(e.dst)) {
574 //Traverse all reachable nodes
575 computeReachableNodes(graph, delta, newDelta, nodeset, tovisit, edgeset, oldnodeset);
577 //Compute call targets
578 HashSet<MethodDescriptor> targets=computeTargets(fcall, newDelta);
580 //add in new nodeset and edgeset
581 oldnodeset.addAll(nodeset);
582 oldedgeset.addAll(edgeset);
585 fixMapping(fcall, targets, oldedgeset, newDelta, callblock, callindex);
587 //Compute edges into region to splice out
588 computeExternalEdges(graph, delta, oldnodeset, nodeset, externaledgeset);
590 //Splice out internal edges
591 removeEdges(delta, nodeset, edgeset, externaledgeset);
593 //Add in new external edges
594 graph.externalEdgeSet.addAll(externaledgeset);
596 //Apply diffs to graph
597 applyDiffs(graph, delta);
602 /* This function applies callee deltas to the caller heap. */
604 Delta applyCallDelta(Delta delta, BBlock bblock) {
605 Delta newDelta=new Delta(null, false);
606 Vector<FlatNode> nodes=bblock.nodes();
607 PPoint ppoint=delta.getBlock();
608 FlatCall fcall=(FlatCall)nodes.get(ppoint.getIndex());
609 Graph graph=graphMap.get(fcall);
610 Graph oldgraph=(ppoint.getIndex()==0)?
611 bbgraphMap.get(bblock):
612 graphMap.get(nodes.get(ppoint.getIndex()-1));
614 //Age outside nodes if necessary
615 for(Iterator<AllocNode> nodeit=delta.addNodeAges.iterator();nodeit.hasNext();) {
616 AllocNode node=nodeit.next();
617 if (!graph.callNodeAges.contains(node)) {
618 graph.callNodeAges.add(node);
622 if (!graph.reachNode.contains(node)&&!node.isSummary()) {
623 /* Need to age node in existing graph*/
624 summarizeInGraph(graph, newDelta, node);
629 for(Map.Entry<AllocNode, MySet<Edge>> entry:delta.heapedgeadd.entrySet()) {
630 for(Edge e:entry.getValue()) {
631 boolean addedge=false;
633 if (e.statuspredicate==Edge.NEW) {
636 Edge origEdgeKey=e.makeStatus(allocFactory);
637 if (oldgraph.nodeMap.containsKey(origEdgeKey.src)&&
638 oldgraph.nodeMap.get(origEdgeKey.src).contains(origEdgeKey)) {
639 Edge origEdge=oldgraph.nodeMap.get(origEdgeKey.src).get(origEdgeKey);
641 origEdgeKey.statuspredicate=origEdge.statuspredicate;
642 edgetoadd=origEdgeKey;
645 mergeEdge(graph, newDelta, edgetoadd);
649 //Add external edges in
650 for(Edge e:graph.externalEdgeSet) {
651 //First did we age the source
652 Edge newedge=e.copy();
653 if (newedge.src!=null&&!e.src.isSummary()&&graph.callNodeAges.contains(e.src)) {
654 AllocNode summaryNode=allocFactory.getAllocNode(newedge.src, true);
655 newedge.src=summaryNode;
658 if (graph.callNodeAges.contains(e.dst)&&!e.dst.isSummary()) {
659 if (graph.callOldNodes.contains(e.dst)) {
661 Edge copy=newedge.copy();
662 mergeEdge(graph, newDelta, copy);
664 //Now add summarized node
665 newedge.dst=allocFactory.getAllocNode(newedge.dst, true);
666 mergeEdge(graph, newDelta, newedge);
668 //Add edge to single node
669 mergeEdge(graph, newDelta, newedge);
672 //Add edge for return value
673 if (fcall.getReturnTemp()!=null) {
674 MySet<Edge> returnedge=newDelta.varedgeadd.get(returntmp);
675 for(Edge e:returnedge) {
676 Edge newedge=e.copy();
677 newedge.srcvar=fcall.getReturnTemp();
678 if (graph.getEdges(fcall.getReturnTemp())==null||!graph.getEdges(fcall.getReturnTemp()).contains(newedge))
679 newDelta.addEdge(newedge);
683 applyDiffs(graph, newDelta);
687 public void mergeEdge(Graph graph, Delta newDelta, Edge edgetoadd) {
688 if (edgetoadd!=null) {
689 Edge match=graph.getMatch(edgetoadd);
691 if (match==null||!match.subsumes(edgetoadd)) {
692 Edge mergededge=edgetoadd.merge(match);
693 newDelta.addHeapEdge(mergededge);
699 /* Summarizes out of context nodes in graph */
700 void summarizeInGraph(Graph graph, Delta newDelta, AllocNode singleNode) {
701 AllocNode summaryNode=allocFactory.getAllocNode(singleNode, true);
703 //Handle outgoing heap edges
704 MySet<Edge> edgeset=graph.getEdges(singleNode);
706 for(Edge e:edgeset) {
707 Edge rewrite=e.rewrite(singleNode, summaryNode);
709 newDelta.removeHeapEdge(e);
710 mergeEdge(graph, newDelta, rewrite);
713 //Handle incoming edges
714 MySet<Edge> backedges=graph.getBackEdges(singleNode);
715 for(Edge e:backedges) {
716 if (e.dst==singleNode) {
717 //Need to get original edge so that predicate will be correct
718 Edge match=graph.getMatch(e);
719 Edge rewrite=match.rewrite(singleNode, summaryNode);
720 newDelta.removeEdge(match);
721 mergeEdge(graph, newDelta, rewrite);
726 void applyDiffs(Graph graph, Delta delta) {
727 applyDiffs(graph, delta, false);
730 void applyDiffs(Graph graph, Delta delta, boolean genbackwards) {
731 //build backwards map if requested
732 if (genbackwards&&graph.backMap==null) {
733 graph.backMap=new HashMap<AllocNode, MySet<Edge>>();
734 if (graph.parent.backMap==null) {
735 graph.parent.backMap=new HashMap<AllocNode, MySet<Edge>>();
736 for(Map.Entry<AllocNode, MySet<Edge>> entry:graph.nodeMap.entrySet()) {
737 for(Edge e:entry.getValue()) {
738 if (!graph.parent.backMap.containsKey(e.dst))
739 graph.parent.backMap.put(e.dst, new MySet<Edge>());
740 graph.parent.backMap.get(e.dst).add(e);
743 for(Map.Entry<TempDescriptor, MySet<Edge>> entry:graph.varMap.entrySet()) {
744 for(Edge e:entry.getValue()) {
745 if (!graph.parent.backMap.containsKey(e.dst))
746 graph.parent.backMap.put(e.dst, new MySet<Edge>());
747 graph.parent.backMap.get(e.dst).add(e);
753 //Add hidden base edges
754 for(Map.Entry<AllocNode, MySet<Edge>> e: delta.baseheapedge.entrySet()) {
755 AllocNode node=e.getKey();
756 MySet<Edge> edges=e.getValue();
757 if (graph.nodeMap.containsKey(node)) {
758 MySet<Edge> nodeEdges=graph.nodeMap.get(node);
759 nodeEdges.addAll(edges);
764 for(Map.Entry<AllocNode, MySet<Edge>> e: delta.heapedgeremove.entrySet()) {
765 AllocNode node=e.getKey();
766 MySet<Edge> edgestoremove=e.getValue();
767 if (graph.nodeMap.containsKey(node)) {
768 //Just apply diff to current map
769 graph.nodeMap.get(node).removeAll(edgestoremove);
771 //Generate diff from parent graph
772 MySet<Edge> parentedges=graph.parent.nodeMap.get(node);
773 MySet<Edge> newedgeset=Util.setSubtract(parentedges, edgestoremove);
774 graph.nodeMap.put(node, newedgeset);
779 for(Map.Entry<AllocNode, MySet<Edge>> e: delta.heapedgeadd.entrySet()) {
780 AllocNode node=e.getKey();
781 MySet<Edge> edgestoadd=e.getValue();
782 //If we have not done a subtract, then
783 if (!graph.nodeMap.containsKey(node)) {
784 //Copy the parent entry
785 if (graph.parent.nodeMap.containsKey(node))
786 graph.nodeMap.put(node, (MySet<Edge>)graph.parent.nodeMap.get(node).clone());
788 graph.nodeMap.put(node, new MySet<Edge>());
790 graph.nodeMap.get(node).addAll(edgestoadd);
792 for(Edge eadd:edgestoadd) {
793 if (!graph.backMap.containsKey(eadd.dst))
794 graph.backMap.put(eadd.dst, new MySet<Edge>());
795 graph.backMap.get(eadd.dst).add(eadd);
801 for(Map.Entry<TempDescriptor, MySet<Edge>> e: delta.varedgeremove.entrySet()) {
802 TempDescriptor tmp=e.getKey();
803 MySet<Edge> edgestoremove=e.getValue();
805 if (graph.varMap.containsKey(tmp)) {
806 //Just apply diff to current map
807 graph.varMap.get(tmp).removeAll(edgestoremove);
808 } else if (graph.parent.varMap.containsKey(tmp)) {
809 //Generate diff from parent graph
810 MySet<Edge> parentedges=graph.parent.varMap.get(tmp);
811 MySet<Edge> newedgeset=Util.setSubtract(parentedges, edgestoremove);
812 graph.varMap.put(tmp, newedgeset);
817 for(Map.Entry<TempDescriptor, MySet<Edge>> e: delta.varedgeadd.entrySet()) {
818 TempDescriptor tmp=e.getKey();
819 MySet<Edge> edgestoadd=e.getValue();
820 graph.varMap.put(tmp, (MySet<Edge>) edgestoadd.clone());
822 for(Edge eadd:edgestoadd) {
823 if (!graph.backMap.containsKey(eadd.dst))
824 graph.backMap.put(eadd.dst, new MySet<Edge>());
825 graph.backMap.get(eadd.dst).add(eadd);
831 for(AllocNode node:delta.addNodeAges) {
832 graph.nodeAges.add(node);
835 for(Map.Entry<AllocNode, Boolean> nodeentry:delta.addOldNodes.entrySet()) {
836 AllocNode node=nodeentry.getKey();
837 Boolean ispresent=nodeentry.getValue();
838 graph.oldNodes.put(node, ispresent);
842 Delta processSetFieldElementNode(FlatNode node, Delta delta, Graph graph) {
846 if (node.kind()==FKind.FlatSetElementNode) {
847 FlatSetElementNode fen=(FlatSetElementNode) node;
852 FlatSetFieldNode ffn=(FlatSetFieldNode) node;
857 if (delta.getInit()) {
858 HashSet<AllocNode> srcNodes=GraphManip.getNodes(graph, delta, src);
859 HashSet<AllocNode> dstNodes=GraphManip.getNodes(graph, delta, dst);
860 MySet<Edge> edgesToAdd=GraphManip.genEdges(dstNodes, fd, srcNodes);
861 MySet<Edge> edgesToRemove=null;
862 if (dstNodes.size()==1&&!dstNodes.iterator().next().isSummary()) {
863 /* Can do a strong update */
864 edgesToRemove=GraphManip.getEdges(graph, delta, dstNodes, fd);
865 graph.strongUpdateSet=edgesToRemove;
867 graph.strongUpdateSet=new MySet<Edge>();
869 updateHeapDelta(graph, delta, edgesToAdd, edgesToRemove);
870 applyDiffs(graph, delta);
872 /* First look at new sources */
873 MySet<Edge> edgesToAdd=new MySet<Edge>();
874 HashSet<AllocNode> newSrcNodes=GraphManip.getDiffNodes(delta, src);
875 HashSet<AllocNode> srcNodes=GraphManip.getNodes(graph, delta, src);
876 HashSet<AllocNode> dstNodes=GraphManip.getNodes(graph, delta, dst);
877 HashSet<AllocNode> newDstNodes=GraphManip.getDiffNodes(delta, dst);
880 MySet<Edge> edgesToRemove=null;
881 if (newDstNodes.size()!=0) {
882 if (dstNodes.size()>1&&!dstNodes.iterator().next().isSummary()) {
883 /* Need to undo strong update */
884 if (graph.strongUpdateSet!=null) {
885 edgesToAdd.addAll(graph.strongUpdateSet);
886 graph.strongUpdateSet=null; //Prevent future strong updates
888 } else if (dstNodes.size()==1&&newDstNodes.size()==1&&!newDstNodes.iterator().next().isSummary()&&graph.strongUpdateSet!=null) {
889 edgesToRemove=GraphManip.getEdges(graph, delta, dstNodes, fd);
890 graph.strongUpdateSet.addAll(edgesToRemove);
892 edgesToAdd.addAll(GraphManip.genEdges(newDstNodes, fd, srcNodes));
896 if (graph.strongUpdateSet!=null) {
897 MySet<Edge> otherEdgesToRemove=GraphManip.getDiffEdges(delta, dstNodes);
898 if (edgesToRemove!=null)
899 edgesToRemove.addAll(otherEdgesToRemove);
901 edgesToRemove=otherEdgesToRemove;
902 graph.strongUpdateSet.addAll(otherEdgesToRemove);
905 //Next look at new destinations
906 edgesToAdd.addAll(GraphManip.genEdges(dstNodes, fd, newSrcNodes));
909 updateHeapDelta(graph, delta, edgesToAdd, edgesToRemove);
910 applyDiffs(graph, delta);
915 Delta processCopyNode(FlatNode node, Delta delta, Graph graph) {
918 if (node.kind()==FKind.FlatOpNode) {
919 FlatOpNode fon=(FlatOpNode) node;
922 } else if (node.kind()==FKind.FlatReturnNode) {
923 FlatReturnNode frn=(FlatReturnNode)node;
924 src=frn.getReturnTemp();
926 if (src==null||!src.getType().isPtr()) {
928 applyDiffs(graph, delta);
932 FlatCastNode fcn=(FlatCastNode) node;
936 if (delta.getInit()) {
937 HashSet<AllocNode> srcnodes=GraphManip.getNodes(graph, delta, src);
938 MySet<Edge> edgesToAdd=GraphManip.genEdges(dst, srcnodes);
939 MySet<Edge> edgesToRemove=GraphManip.getEdges(graph, delta, dst);
940 updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
941 applyDiffs(graph, delta);
943 /* First compute new src nodes */
944 HashSet<AllocNode> newSrcNodes=GraphManip.getDiffNodes(delta, src);
946 /* Compute the union, and then the set of edges */
947 MySet<Edge> edgesToAdd=GraphManip.genEdges(dst, newSrcNodes);
949 /* Compute set of edges to remove */
950 MySet<Edge> edgesToRemove=GraphManip.getDiffEdges(delta, dst);
953 updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
954 applyDiffs(graph, delta);
959 Delta processFieldElementNode(FlatNode node, Delta delta, Graph graph) {
963 if (node.kind()==FKind.FlatElementNode) {
964 FlatElementNode fen=(FlatElementNode) node;
969 FlatFieldNode ffn=(FlatFieldNode) node;
974 if (delta.getInit()) {
975 HashSet<AllocNode> srcnodes=GraphManip.getNodes(graph, delta, src);
976 HashSet<AllocNode> fdnodes=GraphManip.getNodes(graph, delta, srcnodes, fd);
977 MySet<Edge> edgesToAdd=GraphManip.genEdges(dst, fdnodes);
978 MySet<Edge> edgesToRemove=GraphManip.getEdges(graph, delta, dst);
979 updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
980 applyDiffs(graph, delta);
982 /* First compute new objects we read fields of */
983 HashSet<AllocNode> allsrcnodes=GraphManip.getNodes(graph, delta, src);
984 HashSet<AllocNode> difffdnodes=GraphManip.getDiffNodes(delta, allsrcnodes, fd);
985 /* Next compute new targets of fields */
986 HashSet<AllocNode> newsrcnodes=GraphManip.getDiffNodes(delta, src);
987 HashSet<AllocNode> newfdnodes=GraphManip.getNodes(graph, delta, newsrcnodes, fd);
988 /* Compute the union, and then the set of edges */
989 HashSet<AllocNode> newTargets=new HashSet<AllocNode>();
990 newTargets.addAll(newfdnodes);
991 newTargets.addAll(difffdnodes);
992 MySet<Edge> edgesToAdd=GraphManip.genEdges(dst, newTargets);
994 /* Compute set of edges to remove */
995 MySet<Edge> edgesToRemove=GraphManip.getDiffEdges(delta, dst);
998 updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
999 applyDiffs(graph, delta);
1004 static void updateVarDelta(Graph graph, Delta delta, TempDescriptor tmp, MySet<Edge> edgestoAdd, MySet<Edge> edgestoRemove) {
1005 MySet<Edge> edgeAdd=delta.varedgeadd.get(tmp);
1006 MySet<Edge> edgeRemove=delta.varedgeremove.get(tmp);
1007 MySet<Edge> existingEdges=graph.getEdges(tmp);
1008 for(Edge e: edgestoRemove) {
1009 //remove edge from delta
1012 //if the edge is already in the graph, add an explicit remove to the delta
1013 if (existingEdges.contains(e))
1014 delta.removeVarEdge(e);
1016 for(Edge e: edgestoAdd) {
1017 //Remove the edge from the remove set
1018 if (edgeRemove!=null)
1019 edgeRemove.remove(e);
1020 //Explicitly add it to the add set unless it is already in the graph
1021 if (!existingEdges.contains(e))
1022 delta.addVarEdge(e);
1026 static void updateHeapDelta(Graph graph, Delta delta, MySet<Edge> edgestoAdd, MySet<Edge> edgestoRemove) {
1027 if (edgestoRemove!=null)
1028 for(Edge e: edgestoRemove) {
1029 AllocNode src=e.src;
1030 MySet<Edge> edgeAdd=delta.heapedgeadd.get(src);
1031 MySet<Edge> existingEdges=graph.getEdges(src);
1032 //remove edge from delta
1034 //if the edge is already in the graph, add an explicit remove to the delta
1035 if (existingEdges.contains(e)) {
1036 delta.removeHeapEdge(e);
1039 if (edgestoAdd!=null)
1040 for(Edge e: edgestoAdd) {
1041 AllocNode src=e.src;
1042 MySet<Edge> edgeRemove=delta.heapedgeremove.get(src);
1043 MySet<Edge> existingEdges=graph.getEdges(src);
1044 //Remove the edge from the remove set
1045 if (edgeRemove!=null)
1046 edgeRemove.remove(e);
1047 //Explicitly add it to the add set unless it is already in the graph
1048 if (!existingEdges.contains(e)||!existingEdges.get(e).isNew()) {
1049 delta.addHeapEdge(e);
1054 Delta processFlatNop(FlatNode node, Delta delta, Graph graph) {
1055 applyDiffs(graph, delta);
1059 Delta processNewNode(FlatNew node, Delta delta, Graph graph) {
1060 AllocNode summary=allocFactory.getAllocNode(node, true);
1061 AllocNode single=allocFactory.getAllocNode(node, false);
1062 TempDescriptor tmp=node.getDst();
1064 if (delta.getInit()) {
1065 /* We don't have to deal with summarization here... The
1066 * intuition is that this is the only place where we generate
1067 * nodes for this allocation site and this is the first time
1068 * we've analyzed this site */
1071 Edge e=new Edge(tmp, single);
1072 //Build new Edge set
1073 MySet<Edge> newedges=new MySet<Edge>();
1075 //Add it into the diffs
1076 delta.varedgeadd.put(tmp, newedges);
1077 //Remove the old edges
1078 delta.varedgeremove.put(tmp, (MySet<Edge>) graph.getEdges(tmp).clone());
1079 //Apply incoming diffs to graph
1080 applyDiffs(graph, delta);
1081 //Note that we create a single node
1082 delta.addNodeAges.add(single);
1084 if (delta.addOldNodes.containsKey(single)||delta.baseOldNodes.containsKey(single)) {
1085 delta.addOldNodes.put(single, Boolean.FALSE);
1088 /* 1. Fix up the variable edge additions */
1090 for(Iterator<Map.Entry<TempDescriptor, MySet<Edge>>> entryIt=delta.varedgeadd.entrySet().iterator();entryIt.hasNext();) {
1091 Map.Entry<TempDescriptor, MySet<Edge>> entry=entryIt.next();
1093 if (entry.getKey()==tmp) {
1094 /* Check if this is the tmp we overwrite */
1097 /* Otherwise, check if the target of the edge is changed... */
1098 summarizeSet(entry.getValue(), graph.varMap.get(entry.getKey()), single, summary);
1102 /* 2. Fix up the base variable edges */
1104 for(Iterator<Map.Entry<TempDescriptor, MySet<Edge>>> entryIt=delta.basevaredge.entrySet().iterator();entryIt.hasNext();) {
1105 Map.Entry<TempDescriptor, MySet<Edge>> entry=entryIt.next();
1106 TempDescriptor entrytmp=entry.getKey();
1107 if (entrytmp==tmp) {
1108 /* Check is this is the tmp we overwrite, if so add to remove set */
1109 Util.relationUpdate(delta.varedgeremove, tmp, null, entry.getValue());
1111 /* Check if the target of the edge is changed */
1112 MySet<Edge> newset=(MySet<Edge>)entry.getValue().clone();
1113 MySet<Edge> removeset=shrinkSet(newset, graph.varMap.get(entrytmp), single, summary);
1114 Util.relationUpdate(delta.varedgeremove, entrytmp, newset, removeset);
1115 Util.relationUpdate(delta.varedgeadd, entrytmp, null, newset);
1120 /* 3. Fix up heap edge additions */
1122 HashMap<AllocNode, MySet<Edge>> addheapedge=new HashMap<AllocNode, MySet<Edge>>();
1123 for(Iterator<Map.Entry<AllocNode, MySet<Edge>>> entryIt=delta.heapedgeadd.entrySet().iterator();entryIt.hasNext();) {
1124 Map.Entry<AllocNode, MySet<Edge>> entry=entryIt.next();
1125 MySet<Edge> edgeset=entry.getValue();
1126 AllocNode allocnode=entry.getKey();
1127 if (allocnode==single) {
1129 summarizeSet(edgeset, graph.nodeMap.get(summary), single, summary);
1130 addheapedge.put(summary, edgeset);
1132 summarizeSet(edgeset, graph.nodeMap.get(allocnode), single, summary);
1136 /* Merge in diffs */
1138 for(Map.Entry<AllocNode, MySet<Edge>> entry:addheapedge.entrySet()) {
1139 AllocNode allocnode=entry.getKey();
1140 Util.relationUpdate(delta.heapedgeadd, allocnode, null, entry.getValue());
1143 /* 4. Fix up the base heap edges */
1145 for(Iterator<Map.Entry<AllocNode, MySet<Edge>>> entryIt=delta.baseheapedge.entrySet().iterator();entryIt.hasNext();) {
1146 Map.Entry<AllocNode, MySet<Edge>> entry=entryIt.next();
1147 MySet<Edge> edgeset=entry.getValue();
1148 AllocNode allocnode=entry.getKey();
1149 if (allocnode==single) {
1152 AllocNode addnode=(allocnode==single)?summary:allocnode;
1154 MySet<Edge> newset=(MySet<Edge>) edgeset.clone();
1155 MySet<Edge> removeset=shrinkSet(newset, graph.nodeMap.get(addnode), single, summary);
1156 Util.relationUpdate(delta.heapedgeadd, addnode, null, newset);
1157 Util.relationUpdate(delta.heapedgeremove, allocnode, null, removeset);
1160 /* Update Node Ages...If the base or addNodeAges set contains a
1161 * single node, it now should also contain a summary node... No
1162 * need to generate a single node as that has already been
1164 if (delta.baseNodeAges.contains(single)||delta.addNodeAges.contains(single)) {
1165 delta.addNodeAges.add(summary);
1168 //Kill the old node if someone tries to add it
1169 if (delta.addOldNodes.containsKey(single)||delta.baseOldNodes.containsKey(single)) {
1170 delta.addOldNodes.put(single, Boolean.FALSE);
1173 //Apply incoming diffs to graph
1174 applyDiffs(graph, delta);
1179 /* This function builds a new edge set where oldnode is summarized into new node */
1181 void summarizeSet(MySet<Edge> edgeset, MySet<Edge> oldedgeset, AllocNode oldnode, AllocNode sumnode) {
1182 MySet<Edge> newSet=null;
1183 for(Iterator<Edge> edgeit=edgeset.iterator();edgeit.hasNext();) {
1184 Edge e=edgeit.next();
1185 if (e.dst==oldnode||e.src==oldnode) {
1187 newSet=new MySet<Edge>();
1192 if (e.dst==oldnode) {
1195 if (e.src==oldnode) {
1198 if (oldedgeset==null||!oldedgeset.contains(e))
1203 edgeset.addAll(newSet);
1206 /* Shrinks the incoming set to just include rewritten values.
1207 * Returns a set of the original rewritten values */
1209 MySet<Edge> shrinkSet(MySet<Edge> edgeset, MySet<Edge> oldedgeset, AllocNode oldnode, AllocNode newnode) {
1210 MySet<Edge> newSet=null;
1211 MySet<Edge> removeSet=null;
1212 for(Iterator<Edge> edgeit=edgeset.iterator();edgeit.hasNext();) {
1213 Edge e=edgeit.next();
1215 if (e.dst==oldnode||e.src==oldnode) {
1217 newSet=new MySet<Edge>();
1218 removeSet=new MySet<Edge>();
1221 removeSet.add(e.copy());
1226 if (oldedgeset==null||!oldedgeset.contains(e))
1231 edgeset.addAll(newSet);
1235 /* This function returns a completely new Delta... It is safe to
1238 Delta applyInitDelta(Delta delta, BBlock block) {
1239 //Apply delta to graph
1240 boolean newGraph=false;
1241 if (!bbgraphMap.containsKey(block)) {
1242 bbgraphMap.put(block, new Graph(null));
1246 Graph graph=bbgraphMap.get(block);
1249 newdelta=new Delta(null, true);
1250 //Add in heap edges and throw away original diff
1251 graph.nodeMap.putAll(delta.heapedgeadd);
1252 //Add in var edges and throw away original diff
1253 graph.varMap.putAll(delta.varedgeadd);
1254 //Record that this is initial set...
1255 graph.nodeAges.addAll(delta.addNodeAges);
1257 for(Map.Entry<AllocNode, Boolean> oldentry:delta.addOldNodes.entrySet()) {
1258 if (oldentry.getValue().booleanValue()) {
1259 graph.oldNodes.put(oldentry.getKey(), Boolean.TRUE);
1263 newdelta=new Delta(null, false);
1264 //merge in heap edges and variables
1265 mergeHeapEdges(graph, delta, newdelta);
1266 mergeVarEdges(graph, delta, newdelta);
1267 mergeAges(graph, delta, newdelta);
1273 /* This function merges in the heap edges. It updates delta to be
1276 void mergeHeapEdges(Graph graph, Delta delta, Delta newdelta) {
1278 for(Map.Entry<AllocNode, MySet<Edge>> heapedge:delta.heapedgeadd.entrySet()) {
1279 AllocNode nsrc=heapedge.getKey();
1280 MySet<Edge> edges=heapedge.getValue();
1282 if (graph.backMap!=null) {
1284 if (!graph.backMap.containsKey(e.dst))
1285 graph.backMap.put(e.dst, new MySet<Edge>());
1286 graph.backMap.get(e.dst).add(e);
1290 if (!graph.nodeMap.containsKey(nsrc)) {
1291 graph.nodeMap.put(nsrc, new MySet<Edge>());
1293 MySet<Edge> dstedges=graph.nodeMap.get(nsrc);
1294 MySet<Edge> diffedges=new MySet<Edge>();
1296 if (!dstedges.contains(e)) {
1297 //We have a new edge
1301 Edge origedge=dstedges.get(e);
1302 if (!origedge.subsumes(e)) {
1303 Edge mergededge=origedge.merge(e);
1304 diffedges.add(mergededge);
1305 dstedges.add(mergededge);
1309 //Done with edge set...
1310 if (diffedges.size()>0) {
1312 newdelta.baseheapedge.put(nsrc, diffedges);
1317 /* This function merges in the var edges. It updates delta to be
1320 void mergeVarEdges(Graph graph, Delta delta, Delta newdelta) {
1322 for(Map.Entry<TempDescriptor, MySet<Edge>> varedge:delta.varedgeadd.entrySet()) {
1323 TempDescriptor tmpsrc=varedge.getKey();
1324 MySet<Edge> edges=varedge.getValue();
1325 if (graph.backMap!=null) {
1327 if (!graph.backMap.containsKey(e.dst))
1328 graph.backMap.put(e.dst, new MySet<Edge>());
1329 graph.backMap.get(e.dst).add(e);
1333 if (!graph.varMap.containsKey(tmpsrc)) {
1334 graph.varMap.put(tmpsrc, new MySet<Edge>());
1336 MySet<Edge> dstedges=graph.varMap.get(tmpsrc);
1337 MySet<Edge> diffedges=new MySet<Edge>();
1339 if (!dstedges.contains(e)) {
1340 //We have a new edge
1345 //Done with edge set...
1346 if (diffedges.size()>=0) {
1348 newdelta.basevaredge.put(tmpsrc,diffedges);
1353 void mergeAges(Graph graph, Delta delta, Delta newDelta) {
1355 for(AllocNode node:delta.addNodeAges) {
1356 if (!graph.nodeAges.contains(node)) {
1357 graph.nodeAges.add(node);
1358 newDelta.baseNodeAges.add(node);
1361 for(Map.Entry<AllocNode, Boolean> oldentry:delta.addOldNodes.entrySet()) {
1362 AllocNode node=oldentry.getKey();
1363 boolean ispresent=oldentry.getValue().booleanValue();
1364 if (ispresent&&!graph.oldNodes.containsKey(node)) {
1365 graph.oldNodes.put(node, Boolean.TRUE);
1366 newDelta.baseOldNodes.put(node, Boolean.TRUE);