1 package Analysis.Pointer;
5 import Analysis.Liveness;
6 import Analysis.Pointer.BasicBlock.BBlock;
7 import Analysis.Pointer.AllocFactory.AllocNode;
8 import Analysis.Disjoint.Alloc;
9 import Analysis.Disjoint.Taint;
10 import Analysis.Disjoint.TaintSet;
11 import Analysis.Disjoint.Canonical;
12 import Analysis.Disjoint.HeapAnalysis;
13 import Analysis.CallGraph.CallGraph;
14 import Analysis.OoOJava.RBlockRelationAnalysis;
15 import Analysis.OoOJava.Accessible;
16 import Analysis.Disjoint.ExistPred;
17 import Analysis.Disjoint.ReachGraph;
18 import Analysis.Disjoint.EffectsAnalysis;
19 import Analysis.Disjoint.BuildStateMachines;
23 public class Pointer implements HeapAnalysis{
24 HashMap<FlatMethod, BasicBlock> blockMap;
25 HashMap<BBlock, Graph> bbgraphMap;
26 HashMap<FlatNode, Graph> graphMap;
27 HashMap<FlatCall, Set<BBlock>> callMap;
28 HashMap<BBlock, Set<PPoint>> returnMap;
29 HashMap<BBlock, Set<TempDescriptor>> bblivetemps;
30 HashSet<FlatNode> mustProcess;
32 private boolean OoOJava=false;
36 AllocFactory allocFactory;
37 LinkedList<Delta> toprocess;
38 TempDescriptor returntmp;
39 RBlockRelationAnalysis taskAnalysis;
40 EffectsAnalysis effectsAnalysis;
41 Accessible accessible;
43 public Pointer(State state, TypeUtil typeUtil, CallGraph callGraph, RBlockRelationAnalysis taskAnalysis, Liveness liveness, BuildStateMachines bsm) {
44 this(state, typeUtil);
45 this.callGraph=callGraph;
47 this.taskAnalysis=taskAnalysis;
48 this.effectsAnalysis=new EffectsAnalysis();
49 effectsAnalysis.state=state;
50 effectsAnalysis.buildStateMachines=bsm;
51 accessible=new Accessible(state, callGraph, taskAnalysis, liveness);
52 accessible.doAnalysis();
53 State.logEvent("Done Writing Accessible Analysis");
56 public Pointer(State state, TypeUtil typeUtil) {
58 this.blockMap=new HashMap<FlatMethod, BasicBlock>();
59 this.bbgraphMap=new HashMap<BBlock, Graph>();
60 this.bblivetemps=new HashMap<BBlock, Set<TempDescriptor>>();
61 this.graphMap=new HashMap<FlatNode, Graph>();
62 this.callMap=new HashMap<FlatCall, Set<BBlock>>();
63 this.returnMap=new HashMap<BBlock, Set<PPoint>>();
64 this.typeUtil=typeUtil;
65 this.allocFactory=new AllocFactory(state, typeUtil);
66 this.toprocess=new LinkedList<Delta>();
67 ClassDescriptor stringcd=typeUtil.getClass(TypeUtil.ObjectClass);
68 this.returntmp=new TempDescriptor("RETURNVAL", stringcd);
69 this.mustProcess=new HashSet<FlatNode>();
72 public EffectsAnalysis getEffectsAnalysis() {
73 return effectsAnalysis;
76 public BasicBlock getBBlock(FlatMethod fm) {
77 if (!blockMap.containsKey(fm)) {
78 blockMap.put(fm, BasicBlock.getBBlock(fm));
79 Hashtable<FlatNode, Set<TempDescriptor>> livemap=Liveness.computeLiveTemps(fm);
80 for(BBlock bblock:blockMap.get(fm).getBlocks()) {
81 FlatNode fn=bblock.nodes.get(0);
83 HashSet<TempDescriptor> fmset=new HashSet<TempDescriptor>();
84 fmset.addAll((List<TempDescriptor>)Arrays.asList(fm.writesTemps()));
85 bblivetemps.put(bblock, fmset);
87 Set<TempDescriptor> livetemps=livemap.get(fn);
88 bblivetemps.put(bblock, livetemps);
89 livetemps.add(returntmp);
93 return blockMap.get(fm);
96 Delta buildInitialContext() {
97 MethodDescriptor md=typeUtil.getMain();
98 FlatMethod fm=state.getMethodFlat(md);
99 BasicBlock bb=getBBlock(fm);
100 BBlock start=bb.getStart();
101 Delta delta=new Delta(new PPoint(start), true);
102 MySet<Edge> arrayset=new MySet<Edge>();
103 MySet<Edge> varset=new MySet<Edge>();
104 Edge arrayedge=new Edge(allocFactory.StringArray, null, allocFactory.Strings);
105 Edge stringedge=new Edge(fm.getParameter(0), allocFactory.StringArray);
106 delta.addHeapEdge(arrayedge);
107 delta.addVarEdge(stringedge);
113 public Graph getGraph(FlatNode fn) {
114 return graphMap.get(fn);
117 public void doAnalysis() {
119 toprocess.add(buildInitialContext());
121 while(!toprocess.isEmpty()) {
122 Delta delta=toprocess.remove();
123 PPoint ppoint=delta.getBlock();
124 BBlock bblock=ppoint.getBBlock();
125 Vector<FlatNode> nodes=bblock.nodes();
128 if (ppoint.getIndex()==-1) {
129 //Build base graph for entrance to this basic block
130 //System.out.println("Processing "+bblock.nodes.get(0).toString().replace(' ','_'));
132 delta=applyInitDelta(delta, bblock);
133 //System.out.println("Generating:");
136 //System.out.println("Processing Call "+bblock.nodes.get(ppoint.getIndex()).toString().replace(' ','_'));
139 startindex=ppoint.getIndex()+1;
140 delta=applyCallDelta(delta, bblock);
141 //System.out.println("Generating:");
144 Graph graph=bbgraphMap.get(bblock);
145 Graph nodeGraph=null;
146 boolean init=delta.getInit();
147 if (!init&&delta.isEmpty())
151 //Compute delta at exit of each node
152 for(int i=startindex; i<nodes.size();i++) {
153 FlatNode currNode=nodes.get(i);
154 //System.out.println("Start Processing "+currNode);
156 if (!graphMap.containsKey(currNode)) {
157 if (isNEEDED(currNode)) {
158 graphMap.put(currNode, new Graph(graph));
160 boolean fallthru=true;
161 if (isINACC(currNode)&&((lasti==-1)||(lasti==i))) {
163 for(lasti=nodes.size()-1;lasti>=i;lasti--) {
164 FlatNode scurrNode=nodes.get(lasti);
165 if (isNEEDED(scurrNode)||isINACC(scurrNode)) {
171 mustProcess.add(currNode);
172 graphMap.put(currNode, new Graph(graph));
178 //base graph works for us
179 graphMap.put(currNode, new Graph(graph));
181 //just use previous graph
182 graphMap.put(currNode, graphMap.get(nodes.get(i-1)));
188 nodeGraph=graphMap.get(currNode);
189 delta=processNode(bblock, i, currNode, delta, nodeGraph);
190 //System.out.println("Processing "+currNode+" and generating delta:");
193 generateFinalDelta(bblock, delta, nodeGraph);
199 for(Map.Entry<BBlock, Graph> e:bbgraphMap.entrySet()) {
200 Graph g=e.getValue();
201 plotGraph(g,"BB"+e.getKey().nodes.get(0).toString().replace(' ','_'));
205 for(FlatMethod fm:blockMap.keySet()) {
206 System.out.println(fm.printMethod());
208 for(Map.Entry<FlatNode, Graph> e:graphMap.entrySet()) {
209 FlatNode fn=e.getKey();
210 Graph g=e.getValue();
211 plotGraph(g,"FN"+fn.toString()+debugindex);
216 State.logEvent("Done With Pointer Analysis");
220 effectsAnalysis.buildStateMachines.writeStateMachines();
221 State.logEvent("Done Writing State Machines");
225 void plotGraph(Graph g, String name) {
227 PrintWriter pw=new PrintWriter(new FileWriter(name.toString().replace(' ','_')+".dot"));
228 g.printGraph(pw, name);
230 } catch (Exception ex) {
231 ex.printStackTrace();
236 /* This function builds the last delta for a basic block. It
237 * handles the case for the first time the basic block is
240 void buildInitDelta(Graph graph, Delta newDelta) {
241 //First compute the set of temps
242 HashSet<TempDescriptor> tmpSet=new HashSet<TempDescriptor>();
243 tmpSet.addAll(graph.varMap.keySet());
244 tmpSet.addAll(graph.parent.varMap.keySet());
246 //Next build the temp map part of the delta
247 for(TempDescriptor tmp:tmpSet) {
248 MySet<Edge> edgeSet=new MySet<Edge>();
250 if (graph.varMap.containsKey(tmp))
251 edgeSet.addAll(graph.varMap.get(tmp));
253 edgeSet.addAll(graph.parent.varMap.get(tmp));
254 newDelta.varedgeadd.put(tmp, edgeSet);
257 //Next compute the set of src allocnodes
258 HashSet<AllocNode> nodeSet=new HashSet<AllocNode>();
259 nodeSet.addAll(graph.nodeMap.keySet());
260 nodeSet.addAll(graph.parent.nodeMap.keySet());
262 for(AllocNode node:nodeSet) {
263 MySet<Edge> edgeSet=new MySet<Edge>();
265 if (graph.nodeMap.containsKey(node))
266 edgeSet.addAll(graph.nodeMap.get(node));
268 edgeSet.addAll(graph.parent.nodeMap.get(node));
269 newDelta.heapedgeadd.put(node, edgeSet);
272 if (graph.oldNodes.containsKey(node)) {
273 if (graph.oldNodes.get(node).booleanValue())
274 newDelta.addOldNodes.put(node, Boolean.TRUE);
275 } else if (graph.parent.oldNodes.containsKey(node)) {
276 //parent graphs only contain true...no need to check
277 newDelta.addOldNodes.put(node, Boolean.TRUE);
281 newDelta.addNodeAges.addAll(graph.nodeAges);
282 newDelta.addNodeAges.addAll(graph.parent.nodeAges);
285 /* This function build the delta for the exit of a basic block. */
287 void generateFinalDelta(BBlock bblock, Delta delta, Graph graph) {
288 Delta newDelta=new Delta(null, false);
289 if (delta.getInit()) {
290 buildInitDelta(graph, newDelta);
292 /* We can break the old delta...it is done being used */
293 /* First we will build variable edges */
294 HashSet<TempDescriptor> tmpSet=new HashSet<TempDescriptor>();
295 tmpSet.addAll(delta.basevaredge.keySet());
296 tmpSet.addAll(delta.varedgeadd.keySet());
297 for(TempDescriptor tmp:tmpSet) {
298 /* Start with the new incoming edges */
299 MySet<Edge> newbaseedge=delta.basevaredge.get(tmp);
300 /* Remove the remove set */
301 if (newbaseedge==null)
302 newbaseedge=new MySet<Edge>();
303 newbaseedge.removeAll(delta.varedgeremove.get(tmp));
304 /* Add in the new set*/
305 newbaseedge.addAll(delta.varedgeadd.get(tmp));
306 /* Store the results */
307 newDelta.varedgeadd.put(tmp, newbaseedge);
309 delta.basevaredge.clear();
311 /* Next we build heap edges */
312 HashSet<AllocNode> nodeSet=new HashSet<AllocNode>();
313 nodeSet.addAll(delta.baseheapedge.keySet());
314 nodeSet.addAll(delta.heapedgeadd.keySet());
315 nodeSet.addAll(delta.heapedgeremove.keySet());
316 for(AllocNode node:nodeSet) {
317 /* Start with the new incoming edges */
318 MySet<Edge> newheapedge=new MySet<Edge>(delta.baseheapedge.get(node));
319 /* Remove the remove set */
320 MySet<Edge> removeset=delta.heapedgeremove.get(node);
323 newheapedge.removeAll(removeset);
325 /* Add in the add set */
326 MySet<Edge> settoadd=delta.heapedgeadd.get(node);
328 newheapedge.addAll(settoadd);
329 newDelta.heapedgeadd.put(node, newheapedge);
331 /* Remove the newly created edges..no need to propagate a diff for those */
332 if (removeset!=null) {
333 removeset.removeAll(delta.baseheapedge.get(node));
334 newDelta.heapedgeremove.put(node, removeset);
338 /* Compute new ages */
339 newDelta.addNodeAges.addAll(delta.baseNodeAges);
340 newDelta.addNodeAges.addAll(delta.addNodeAges);
341 HashSet<AllocNode> oldNodes=new HashSet<AllocNode>();
343 /* Compute whether old nodes survive */
344 oldNodes.addAll(delta.baseOldNodes.keySet());
345 oldNodes.addAll(delta.addOldNodes.keySet());
346 for(AllocNode node:oldNodes) {
347 if (delta.addOldNodes.containsKey(node)) {
348 if (delta.addOldNodes.get(node).booleanValue()) {
349 newDelta.addOldNodes.put(node, Boolean.TRUE);
352 if (delta.baseOldNodes.get(node).booleanValue()) {
353 newDelta.addOldNodes.put(node, Boolean.TRUE);
359 /* Now we need to propagate newdelta */
360 if (!newDelta.heapedgeadd.isEmpty()||!newDelta.heapedgeremove.isEmpty()||!newDelta.varedgeadd.isEmpty()||!newDelta.addNodeAges.isEmpty()||!newDelta.addOldNodes.isEmpty()) {
361 /* We have a delta to propagate */
362 if (returnMap.containsKey(bblock)) {
366 for(PPoint caller:returnMap.get(bblock)) {
367 //System.out.println("Sending Return BBlock to "+caller.getBBlock().nodes.get(caller.getIndex()).toString().replace(' ','_'));
370 newDelta.setBlock(caller);
371 toprocess.add(newDelta);
374 Delta d=newDelta.diffBlock(caller);
380 Vector<BBlock> blockvector=bblock.next();
381 for(int i=0;i<blockvector.size();i++) {
382 //System.out.println("Sending BBlock to "+blockvector.get(i).nodes.get(0).toString().replace(' ','_'));
385 newDelta.setBlock(new PPoint(blockvector.get(i)));
386 toprocess.add(newDelta);
388 Delta d=newDelta.diffBlock(new PPoint(blockvector.get(i)));
394 //System.out.println("EMPTY DELTA");
395 //System.out.println("delta");
397 //System.out.println("newDelta");
402 boolean isNEEDED(FlatNode node) {
403 switch(node.kind()) {
404 case FKind.FlatSetFieldNode: {
405 FlatSetFieldNode n=(FlatSetFieldNode)node;
406 return n.getSrc().getType().isPtr();
408 case FKind.FlatSetElementNode: {
409 FlatSetElementNode n=(FlatSetElementNode)node;
410 return n.getSrc().getType().isPtr();
412 case FKind.FlatFieldNode: {
413 FlatFieldNode n=(FlatFieldNode)node;
414 return n.getDst().getType().isPtr();
416 case FKind.FlatElementNode: {
417 FlatElementNode n=(FlatElementNode)node;
418 return n.getDst().getType().isPtr();
424 Delta processNode(BBlock bblock, int index, FlatNode node, Delta delta, Graph newgraph) {
425 switch(node.kind()) {
427 return processNewNode((FlatNew)node, delta, newgraph);
428 case FKind.FlatFieldNode:
429 case FKind.FlatElementNode:
430 return processFieldElementNode(node, delta, newgraph);
431 case FKind.FlatCastNode:
432 case FKind.FlatOpNode:
433 case FKind.FlatReturnNode:
434 return processCopyNode(node, delta, newgraph);
435 case FKind.FlatSetFieldNode:
436 case FKind.FlatSetElementNode:
437 return processSetFieldElementNode(node, delta, newgraph);
438 case FKind.FlatSESEEnterNode:
439 return processSESEEnterNode((FlatSESEEnterNode) node, delta, newgraph);
440 case FKind.FlatSESEExitNode:
441 return processSESEExitNode((FlatSESEExitNode) node, delta, newgraph);
442 case FKind.FlatMethod:
444 case FKind.FlatBackEdge:
445 case FKind.FlatGenReachNode:
446 return processFlatNop(node, delta, newgraph);
448 return processFlatCall(bblock, index, (FlatCall) node, delta, newgraph);
450 throw new Error("Unrecognized node:"+node);
454 Delta processSESEEnterNode(FlatSESEEnterNode sese, Delta delta, Graph graph) {
456 return processFlatNop(sese, delta, graph);
457 if (delta.getInit()) {
458 removeInitTaints(null, delta, graph);
459 for (TempDescriptor tmp:sese.getInVarSet()) {
460 Taint taint=Taint.factory(sese, null, tmp, AllocFactory.dummySite, null, ReachGraph.predsEmpty);
461 MySet<Edge> edges=GraphManip.getEdges(graph, delta, tmp);
463 Edge newe=e.addTaint(taint);
464 delta.addVarEdge(newe);
468 removeDiffTaints(null, delta);
469 for (TempDescriptor tmp:sese.getInVarSet()) {
470 Taint taint=Taint.factory(sese, null, tmp, AllocFactory.dummySite, null, ReachGraph.predsEmpty);
471 MySet<Edge> edges=GraphManip.getDiffEdges(delta, tmp);
473 Edge newe=e.addTaint(taint);
474 delta.addVarEdge(newe);
480 applyDiffs(graph, delta);
484 private boolean isRecursive(FlatSESEEnterNode sese) {
485 MethodDescriptor md=sese.getmdEnclosing();
486 boolean isrecursive=callGraph.getCalleeSet(md).contains(md);
490 Delta processSESEExitNode(FlatSESEExitNode seseexit, Delta delta, Graph graph) {
492 return processFlatNop(seseexit, delta, graph);
493 FlatSESEEnterNode sese=seseexit.getFlatEnter();
494 //Strip Taints from this SESE
495 if (delta.getInit()) {
496 removeInitTaints(isRecursive(sese)?null:sese, delta, graph);
498 removeDiffTaints(isRecursive(sese)?null:sese, delta);
500 applyDiffs(graph, delta);
504 void removeDiffTaints(FlatSESEEnterNode sese, Delta delta) {
505 //Start with variable edges
507 MySet<Edge> edgestoadd=new MySet<Edge>();
508 MySet<Edge> edgestoremove=new MySet<Edge>();
510 //Process base diff edges
511 processEdgeMap(sese, delta.basevaredge, null, delta.varedgeremove, edgestoremove, edgestoadd);
512 //Process delta edges
513 processEdgeMap(sese, delta.varedgeadd, null, null, edgestoremove, edgestoadd);
514 for(Edge e:edgestoremove) {
515 delta.removeVarEdge(e);
517 for(Edge e:edgestoadd) {
524 MySet<Edge> edgestoadd=new MySet<Edge>();
525 MySet<Edge> edgestoremove=new MySet<Edge>();
527 //Process base diff edges
528 processEdgeMap(sese, delta.baseheapedge, null, delta.heapedgeremove, edgestoremove, edgestoadd);
529 //Process delta edges
530 processEdgeMap(sese, delta.heapedgeadd, null, null, edgestoremove, edgestoadd);
531 for(Edge e:edgestoremove) {
532 delta.removeHeapEdge(e);
534 for(Edge e:edgestoadd) {
535 delta.addHeapEdge(e);
540 void removeInitTaints(FlatSESEEnterNode sese, Delta delta, Graph graph) {
541 //Start with variable edges
543 MySet<Edge> edgestoadd=new MySet<Edge>();
544 MySet<Edge> edgestoremove=new MySet<Edge>();
546 //Process parent edges
547 processEdgeMap(sese, graph.parent.varMap, graph.varMap, delta.varedgeremove, edgestoremove, edgestoadd);
548 //Process graph edges
549 processEdgeMap(sese, graph.varMap, null, delta.varedgeremove, edgestoremove, edgestoadd);
550 //Process delta edges
551 processEdgeMap(sese, delta.varedgeadd, null, null, edgestoremove, edgestoadd);
552 for(Edge e:edgestoremove) {
553 delta.removeVarEdge(e);
555 for(Edge e:edgestoadd) {
562 MySet<Edge> edgestoadd=new MySet<Edge>();
563 MySet<Edge> edgestoremove=new MySet<Edge>();
565 //Process parent edges
566 processEdgeMap(sese, graph.parent.nodeMap, graph.nodeMap, delta.heapedgeremove, edgestoremove, edgestoadd);
567 //Process graph edges
568 processEdgeMap(sese, graph.nodeMap, null, delta.heapedgeremove, edgestoremove, edgestoadd);
569 //Process delta edges
570 processEdgeMap(sese, delta.heapedgeadd, null, null, edgestoremove, edgestoadd);
571 for(Edge e:edgestoremove) {
572 delta.removeHeapEdge(e);
574 for(Edge e:edgestoadd) {
575 delta.addHeapEdge(e);
580 void processEdgeMap(FlatSESEEnterNode sese, HashMap<?, MySet<Edge>> edgemap, HashMap<?, MySet<Edge>> childmap, HashMap<?, MySet<Edge>> removemap, MySet<Edge> edgestoremove, MySet<Edge> edgestoadd) {
581 for(Map.Entry<?, MySet<Edge>> entry:edgemap.entrySet()) {
582 //If the parent map exists and overrides this entry, skip it
583 if (childmap!=null&&childmap.containsKey(entry.getKey()))
585 for(Edge e:entry.getValue()) {
586 //check whether this edge has been removed
587 if (removemap!=null&&removemap.containsKey(entry.getKey())&&
588 removemap.get(entry.getKey()).contains(e))
591 TaintSet ts=e.getTaints();
593 //update non-null taint set
595 newts=Canonical.removeInContextTaintsNP(ts, sese);
597 edgestoremove.add(e);
598 edgestoadd.add(e.changeTaintSet(newts));
604 /* This function compute the edges for the this variable for a
605 * callee if it exists. */
607 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) {
608 //Handle the this temp
610 MySet<Edge> edges=(oldnodeset!=null)?GraphManip.getDiffEdges(delta, tmpthis):GraphManip.getEdges(graph, delta, tmpthis);
611 newDelta.varedgeadd.put(tmpthis, (MySet<Edge>) edges.clone());
612 edgeset.addAll(edges);
614 AllocNode dstnode=e.dst;
615 if (!nodeset.contains(dstnode)&&(oldnodeset==null||!oldnodeset.contains(dstnode))) {
616 TypeDescriptor type=dstnode.getType();
617 if (!type.isArray()) {
618 targetSet.add(type.getClassDesc());
620 //arrays don't have code
621 targetSet.add(typeUtil.getClass(TypeUtil.ObjectClass));
623 nodeset.add(dstnode);
624 tovisit.add(dstnode);
630 /* This function compute the edges for a call's parameters. */
632 void processParams(Graph graph, Delta delta, Delta newDelta, HashSet<AllocNode> nodeset, Stack<AllocNode> tovisit, MySet<Edge> edgeset, FlatCall fcall, boolean diff) {
633 //Go through each temp
634 for(int i=0;i<fcall.numArgs();i++) {
635 TempDescriptor tmp=fcall.getArg(i);
636 MySet<Edge> edges=diff?GraphManip.getDiffEdges(delta, tmp):GraphManip.getEdges(graph, delta, tmp);
637 newDelta.varedgeadd.put(tmp, (MySet<Edge>) edges.clone());
638 edgeset.addAll(edges);
640 if (!nodeset.contains(e.dst)) {
648 /* This function computes the reachable nodes for a callee. */
650 void computeReachableNodes(Graph graph, Delta delta, Delta newDelta, HashSet<AllocNode> nodeset, Stack<AllocNode> tovisit, MySet<Edge> edgeset, HashSet<AllocNode> oldnodeset) {
651 while(!tovisit.isEmpty()) {
652 AllocNode node=tovisit.pop();
653 MySet<Edge> edges=GraphManip.getEdges(graph, delta, node);
654 if (!edges.isEmpty()) {
655 newDelta.heapedgeadd.put(node, Edge.makeOld(edges));
656 edgeset.addAll(edges);
658 if (!nodeset.contains(e.dst)&&(oldnodeset==null||!oldnodeset.contains(e.dst))) {
667 HashSet<MethodDescriptor> computeTargets(FlatCall fcall, Delta newDelta) {
668 TempDescriptor tmpthis=fcall.getThis();
669 MethodDescriptor md=fcall.getMethod();
670 HashSet<MethodDescriptor> targets=new HashSet<MethodDescriptor>();
671 if (md.isStatic()||fcall.getSuper()) {
675 for(Edge e:newDelta.varedgeadd.get(tmpthis)) {
676 AllocNode node=e.dst;
677 ClassDescriptor cd=node.getType().getClassDesc();
678 //Figure out exact method called and add to set
679 MethodDescriptor calledmd=cd.getCalledMethod(md);
680 targets.add(calledmd);
686 void fixMapping(FlatCall fcall, HashSet<MethodDescriptor> targets, MySet<Edge> oldedgeset, Delta newDelta, BBlock callblock, int callindex) {
687 Delta basedelta=null;
688 TempDescriptor tmpthis=fcall.getThis();
690 for(MethodDescriptor calledmd:targets) {
691 FlatMethod fm=state.getMethodFlat(calledmd);
692 boolean newmethod=false;
695 HashMap<TempDescriptor, TempDescriptor> tmpMap=new HashMap<TempDescriptor, TempDescriptor>();
698 tmpMap.put(tmpthis, fm.getParameter(offset++));
700 for(int i=0;i<fcall.numArgs();i++) {
701 TempDescriptor tmp=fcall.getArg(i);
702 tmpMap.put(tmp,fm.getParameter(i+offset));
705 //Get basicblock for the method
706 BasicBlock block=getBBlock(fm);
709 if (!callMap.containsKey(fcall)) {
710 callMap.put(fcall, new HashSet<BBlock>());
713 Delta returnDelta=null;
714 if (!callMap.get(fcall).contains(block.getStart())) {
715 callMap.get(fcall).add(block.getStart());
719 if (!returnMap.containsKey(block.getExit())) {
720 returnMap.put(block.getExit(), new HashSet<PPoint>());
722 returnMap.get(block.getExit()).add(new PPoint(callblock, callindex));
724 if (bbgraphMap.containsKey(block.getExit())) {
725 //Need to push existing results to current node
726 if (returnDelta==null) {
727 returnDelta=new Delta(null, false);
728 Vector<FlatNode> exitblocknodes=block.getExit().nodes();
729 FlatExit fexit=(FlatExit)exitblocknodes.get(exitblocknodes.size()-1);
730 buildInitDelta(graphMap.get(fexit), returnDelta);
731 if (!returnDelta.heapedgeadd.isEmpty()||!returnDelta.heapedgeremove.isEmpty()||!returnDelta.varedgeadd.isEmpty()) {
732 returnDelta.setBlock(new PPoint(callblock, callindex));
733 toprocess.add(returnDelta);
736 if (!returnDelta.heapedgeadd.isEmpty()||!returnDelta.heapedgeremove.isEmpty()||!returnDelta.varedgeadd.isEmpty()) {
737 toprocess.add(returnDelta.diffBlock(new PPoint(callblock, callindex)));
743 if (oldedgeset==null) {
744 //First build of this graph
745 //Build and enqueue delta...safe to just use existing delta
746 Delta d=newDelta.changeParams(tmpMap, new PPoint(block.getStart()));
747 //System.out.println("AProcessing "+block.getStart().nodes.get(0).toString().replace(' ','_'));
750 } else if (newmethod) {
751 if (basedelta==null) {
752 basedelta=newDelta.buildBase(oldedgeset);
754 //Build and enqueue delta
755 Delta d=basedelta.changeParams(tmpMap, new PPoint(block.getStart()));
756 //System.out.println("BProcessing "+block.getStart().nodes.get(0).toString().replace(' ','_'));
760 //Build and enqueue delta
761 Delta d=newDelta.changeParams(tmpMap, new PPoint(block.getStart()));
762 //System.out.println("CProcessing "+block.getStart().nodes.get(0).toString().replace(' ','_'));
770 /* This function computes all edges that start outside of the callee
771 * context and go into the callee context */
773 void computeExternalEdges(Graph graph, Delta delta, HashSet<AllocNode> nodeset, HashSet<AllocNode> deltaset, MySet<Edge> externaledgeset) {
774 //Do heap edges first
775 HashSet<AllocNode> externalnodes=new HashSet<AllocNode>();
776 externalnodes.addAll(delta.baseheapedge.keySet());
777 externalnodes.addAll(delta.heapedgeadd.keySet());
778 externalnodes.addAll(delta.heapedgeremove.keySet());
779 //remove allinternal nodes
780 externalnodes.removeAll(nodeset);
781 for(AllocNode extNode:externalnodes) {
782 //Compute set of edges from given node
783 MySet<Edge> edges=new MySet<Edge>(delta.baseheapedge.get(extNode));
784 edges.removeAll(delta.heapedgeremove.get(extNode));
785 edges.addAll(delta.heapedgeadd.get(extNode));
788 if (nodeset.contains(e.dst))
789 externaledgeset.add(e);
794 HashSet<TempDescriptor> temps=new HashSet<TempDescriptor>();
795 temps.addAll(delta.basevaredge.keySet());
796 temps.addAll(delta.varedgeadd.keySet());
797 temps.addAll(delta.varedgeremove.keySet());
798 //remove allinternal nodes
799 temps.removeAll(nodeset);
801 for(TempDescriptor tmp:temps) {
802 //Compute set of edges from given node
803 MySet<Edge> edges=new MySet<Edge>(delta.basevaredge.get(tmp));
805 edges.removeAll(delta.varedgeremove.get(tmp));
806 edges.addAll(delta.varedgeadd.get(tmp));
809 if (nodeset.contains(e.dst))
810 externaledgeset.add(e);
815 /* This function removes the caller reachable edges from the
818 void removeEdges(Graph graph, Delta delta, HashSet<AllocNode> nodeset, MySet<Edge> edgeset, MySet<Edge> externaledgeset) {
819 //Want to remove the set of internal edges
820 for(Edge e:edgeset) {
821 if (e.src!=null&&!graph.callerEdges.contains(e)) {
822 delta.removeHeapEdge(e);
826 //Want to remove the set of external edges
827 for(Edge e:externaledgeset) {
828 //want to remove the set of internal edges
829 if (!graph.callerEdges.contains(e))
834 Delta processFlatCall(BBlock callblock, int callindex, FlatCall fcall, Delta delta, Graph graph) {
835 Delta newDelta=new Delta(null, false);
837 if (delta.getInit()) {
838 MySet<Edge> edgeset=new MySet<Edge>();
839 MySet<Edge> externaledgeset=new MySet<Edge>();
840 HashSet<AllocNode> nodeset=new HashSet<AllocNode>();
841 HashSet<ClassDescriptor> targetSet=new HashSet<ClassDescriptor>();
842 Stack<AllocNode> tovisit=new Stack<AllocNode>();
843 TempDescriptor tmpthis=fcall.getThis();
844 graph.callerEdges=new MySet<Edge>();
846 //Handle the this temp
847 processThisTargets(targetSet, graph, delta, newDelta, nodeset, tovisit, edgeset, tmpthis, null);
849 //Go through each temp
850 processParams(graph, delta, newDelta, nodeset, tovisit, edgeset, fcall, false);
852 //Traverse all reachable nodes
853 computeReachableNodes(graph, delta, newDelta, nodeset, tovisit, edgeset, null);
855 //Compute call targets
856 HashSet<MethodDescriptor> newtargets=computeTargets(fcall, newDelta);
859 fixMapping(fcall, newtargets, null, newDelta, callblock, callindex);
861 //Compute edges into region to splice out
862 computeExternalEdges(graph, delta, nodeset, null, externaledgeset);
864 //Splice out internal edges
865 removeEdges(graph, delta, nodeset, edgeset, externaledgeset);
867 //store data structures
868 graph.externalEdgeSet=externaledgeset;
869 graph.reachNode=nodeset;
870 graph.reachEdge=edgeset;
872 graph.callTargets=newtargets;
873 graph.callNodeAges=new HashSet<AllocNode>();
874 graph.callOldNodes=new HashSet<AllocNode>();
875 graph.callNewEdges=new HashMap<AllocNode, MySet<Edge>>();
876 graph.callOldEdges=new HashMap<Edge,MySet<Edge>>();
878 //Apply diffs to graph
879 applyDiffs(graph, delta, true);
881 MySet<Edge> edgeset=new MySet<Edge>();
882 MySet<Edge> externaledgeset=new MySet<Edge>();
883 HashSet<AllocNode> nodeset=new HashSet<AllocNode>();
884 MySet<Edge> oldedgeset=graph.reachEdge;
885 HashSet<AllocNode> oldnodeset=graph.reachNode;
887 HashSet<ClassDescriptor> targetSet=new HashSet<ClassDescriptor>();
888 Stack<AllocNode> tovisit=new Stack<AllocNode>();
889 TempDescriptor tmpthis=fcall.getThis();
890 //Fix up delta to get rid of unnecessary heap edge removals
891 for(Map.Entry<AllocNode, MySet<Edge>> entry:delta.heapedgeremove.entrySet()) {
892 for(Iterator<Edge> eit=entry.getValue().iterator();eit.hasNext();) {
894 if (graph.callerEdges.contains(e))
899 //Fix up delta to get rid of unnecessary var edge removals
900 for(Map.Entry<TempDescriptor, MySet<Edge>> entry:delta.varedgeremove.entrySet()) {
901 for(Iterator<Edge> eit=entry.getValue().iterator();eit.hasNext();) {
903 if (graph.callerEdges.contains(e))
908 //Handle the this temp
909 processThisTargets(targetSet, graph, delta, newDelta, nodeset, tovisit, edgeset, tmpthis, oldnodeset);
911 //Go through each temp
912 processParams(graph, delta, newDelta, nodeset, tovisit, edgeset, fcall, true);
913 //Go through each new heap edge that starts from old node
914 MySet<Edge> newedges=GraphManip.getDiffEdges(delta, oldnodeset);
915 edgeset.addAll(newedges);
916 for(Edge e:newedges) {
917 //Add new edges that start from old node to newDelta
919 if (!newDelta.heapedgeadd.containsKey(src)) {
920 newDelta.heapedgeadd.put(src, new MySet<Edge>());
922 newDelta.heapedgeadd.get(src).add(e.makeOld());
923 if (!nodeset.contains(e.dst)&&!oldnodeset.contains(e.dst)) {
929 //Traverse all reachable nodes
930 computeReachableNodes(graph, delta, newDelta, nodeset, tovisit, edgeset, oldnodeset);
931 //Compute call targets
932 HashSet<MethodDescriptor> newtargets=computeTargets(fcall, newDelta);
933 graph.callTargets.addAll(newtargets);
935 //add in new nodeset and edgeset
936 oldnodeset.addAll(nodeset);
937 oldedgeset.addAll(edgeset);
939 fixMapping(fcall, graph.callTargets, oldedgeset, newDelta, callblock, callindex);
940 //Compute edges into region to splice out
941 computeExternalEdges(graph, delta, oldnodeset, nodeset, externaledgeset);
943 //Splice out internal edges
944 removeEdges(graph, delta, nodeset, edgeset, externaledgeset);
946 //Add external edges back in
947 processCallExternal(graph, delta, externaledgeset);
949 //Move new edges that should be summarized
950 processSummarization(graph, delta);
952 Set<FlatSESEEnterNode> seseCallers=OoOJava?taskAnalysis.getTransitiveExecutingRBlocks(fcall):null;
953 //Check if the new nodes allow us to insert a new edge
954 for(AllocNode node:nodeset) {
955 if (graph.callNewEdges.containsKey(node)) {
956 for(Iterator<Edge> eit=graph.callNewEdges.get(node).iterator();eit.hasNext();) {
958 if ((graph.callNodeAges.contains(e.src)||graph.reachNode.contains(e.src))&&
959 (graph.callNodeAges.contains(e.dst)||graph.reachNode.contains(e.dst))) {
960 Edge edgetoadd=e.copy();//we need our own copy to modify below
962 if (seseCallers!=null)
963 edgetoadd.taintModify(seseCallers);
964 mergeCallEdge(graph, delta, edgetoadd);
970 for(Edge e:edgeset) {
971 //See if these edges would allow an old edge to be added
972 if (graph.callOldEdges.containsKey(e)) {
973 for(Edge adde:graph.callOldEdges.get(e)) {
974 Edge ecopy=adde.copy();
975 ecopy.statuspredicate=e.statuspredicate;
976 mergeCallEdge(graph, delta, ecopy);
981 //Add in new external edges
982 graph.externalEdgeSet.addAll(externaledgeset);
983 //Apply diffs to graph
984 applyDiffs(graph, delta);
989 void processSummarization(Graph graph, Delta delta) {
990 processSumHeapEdgeSet(delta.heapedgeadd, delta, graph);
991 processSumHeapEdgeSet(delta.baseheapedge, delta, graph);
992 processSumVarEdgeSet(delta.varedgeadd, delta, graph);
993 processSumVarEdgeSet(delta.basevaredge, delta, graph);
996 void processSumVarEdgeSet(HashMap<TempDescriptor, MySet<Edge>> map, Delta delta, Graph graph) {
997 MySet<Edge> edgestoadd=new MySet<Edge>();
998 MySet<Edge> edgestoremove=new MySet<Edge>();
999 for(Iterator<Map.Entry<TempDescriptor, MySet<Edge>>> eit=map.entrySet().iterator();eit.hasNext();) {
1000 Map.Entry<TempDescriptor, MySet<Edge>> entry=eit.next();
1001 MySet<Edge> edgeset=entry.getValue();
1003 for(Edge e:edgeset) {
1005 boolean rewrite=false;
1006 if (copy.dst!=null&&graph.callNodeAges.contains(copy.dst)) {
1007 copy.dst=allocFactory.getAllocNode(copy.dst, true);
1011 edgestoremove.add(e);
1012 edgestoadd.add(copy);
1016 for(Edge e:edgestoremove) {
1017 if (!graph.callerEdges.contains(e))
1018 delta.removeVarEdge(e);
1020 for(Edge e:edgestoadd) {
1021 delta.addVarEdge(e);
1025 public Alloc getAllocationSiteFromFlatNew(FlatNew node) {
1026 return allocFactory.getAllocNode(node, false).getAllocSite();
1029 void processSumHeapEdgeSet(HashMap<AllocNode, MySet<Edge>> map, Delta delta, Graph graph) {
1030 MySet<Edge> edgestoadd=new MySet<Edge>();
1031 MySet<Edge> edgestoremove=new MySet<Edge>();
1032 for(Iterator<Map.Entry<AllocNode, MySet<Edge>>> eit=map.entrySet().iterator();eit.hasNext();) {
1033 Map.Entry<AllocNode, MySet<Edge>> entry=eit.next();
1034 AllocNode node=entry.getKey();
1035 MySet<Edge> edgeset=entry.getValue();
1037 for(Edge e:edgeset) {
1039 boolean rewrite=false;
1040 if (copy.src!=null&&graph.callNodeAges.contains(copy.src)) {
1041 copy.src=allocFactory.getAllocNode(copy.src, true);
1044 if (copy.dst!=null&&graph.callNodeAges.contains(copy.dst)) {
1045 copy.dst=allocFactory.getAllocNode(copy.dst, true);
1049 edgestoremove.add(e);
1050 edgestoadd.add(copy);
1054 for(Edge e:edgestoremove) {
1055 if (!graph.callerEdges.contains(e))
1056 delta.removeHeapEdge(e);
1058 for(Edge e:edgestoadd) {
1059 delta.addHeapEdge(e);
1063 //Handle external edges
1064 void processCallExternal(Graph graph, Delta newDelta, MySet<Edge> externalEdgeSet) {
1065 //Add external edges in
1066 for(Edge e:externalEdgeSet) {
1067 //First did we age the source
1068 Edge newedge=e.copy();
1069 if (newedge.src!=null&&!e.src.isSummary()&&graph.callNodeAges.contains(e.src)) {
1070 AllocNode summaryNode=allocFactory.getAllocNode(newedge.src, true);
1071 newedge.src=summaryNode;
1074 if (graph.callNodeAges.contains(e.dst)&&!e.dst.isSummary()) {
1075 if (graph.callOldNodes.contains(e.dst)) {
1077 Edge copy=newedge.copy();
1078 mergeEdge(graph, newDelta, copy);
1080 //Now add summarized node
1081 newedge.dst=allocFactory.getAllocNode(newedge.dst, true);
1082 mergeCallEdge(graph, newDelta, newedge);
1084 //Add edge to single node
1085 mergeEdge(graph, newDelta, newedge);
1090 /* This function applies callee deltas to the caller heap. */
1092 Delta applyCallDelta(Delta delta, BBlock bblock) {
1093 Delta newDelta=new Delta(null, false);
1094 Vector<FlatNode> nodes=bblock.nodes();
1095 PPoint ppoint=delta.getBlock();
1096 FlatCall fcall=(FlatCall)nodes.get(ppoint.getIndex());
1097 Graph graph=graphMap.get(fcall);
1098 Graph oldgraph=(ppoint.getIndex()==0)?
1099 bbgraphMap.get(bblock):
1100 graphMap.get(nodes.get(ppoint.getIndex()-1));
1101 Set<FlatSESEEnterNode> seseCallers=OoOJava?taskAnalysis.getTransitiveExecutingRBlocks(fcall):null;
1103 //Age outside nodes if necessary
1104 for(Iterator<AllocNode> nodeit=delta.addNodeAges.iterator();nodeit.hasNext();) {
1105 AllocNode node=nodeit.next();
1106 if (!graph.callNodeAges.contains(node)) {
1107 graph.callNodeAges.add(node);
1108 newDelta.addNodeAges.add(node);
1110 if (!graph.reachNode.contains(node)&&!node.isSummary()) {
1111 /* Need to age node in existing graph*/
1112 summarizeInGraph(graph, newDelta, node);
1114 if (graph.callNewEdges.containsKey(node)) {
1115 for(Iterator<Edge> eit=graph.callNewEdges.get(node).iterator();eit.hasNext();) {
1117 if ((graph.callNodeAges.contains(e.src)||graph.reachNode.contains(e.src))&&
1118 (graph.callNodeAges.contains(e.dst)||graph.reachNode.contains(e.dst))) {
1119 Edge edgetoadd=e.copy();//we need our own copy to modify below
1121 if (seseCallers!=null)
1122 edgetoadd.taintModify(seseCallers);
1123 mergeCallEdge(graph, newDelta, edgetoadd);
1130 for(Map.Entry<AllocNode, MySet<Edge>> entry:delta.heapedgeadd.entrySet()) {
1131 for(Edge e:entry.getValue()) {
1132 boolean addedge=false;
1133 Edge edgetoadd=null;
1134 if (e.statuspredicate==Edge.NEW) {
1135 if ((graph.callNodeAges.contains(e.src)||graph.reachNode.contains(e.src))&&
1136 (graph.callNodeAges.contains(e.dst)||graph.reachNode.contains(e.dst))) {
1137 edgetoadd=e.copy();//we need our own copy to modify below
1139 graph.addCallEdge(e);
1142 Edge[] edgeArray=e.makeStatus(allocFactory);
1144 int statuspredicate=0;
1145 for(int i=0;i<edgeArray.length;i++) {
1146 Edge origEdgeKey=edgeArray[i];
1147 if (graph.reachEdge.contains(origEdgeKey)) {
1148 Edge origEdge=graph.reachEdge.get(origEdgeKey);
1149 //copy the predicate
1150 statuspredicate=statuspredicate|origEdge.statuspredicate;
1152 if (!graph.callOldEdges.containsKey(origEdgeKey)) {
1153 graph.callOldEdges.put(origEdgeKey, new MySet<Edge>());
1155 if (graph.callOldEdges.get(origEdgeKey).contains(e)) {
1156 Edge olde=graph.callOldEdges.get(origEdgeKey).get(e);
1157 graph.callOldEdges.get(origEdgeKey).add(olde.merge(e));
1159 graph.callOldEdges.get(origEdgeKey).add(e);
1162 if (statuspredicate!=0) {
1164 newe.statuspredicate=statuspredicate;
1168 if (seseCallers!=null&&edgetoadd!=null)
1169 edgetoadd.taintModify(seseCallers);
1170 mergeCallEdge(graph, newDelta, edgetoadd);
1174 processCallExternal(graph, newDelta, graph.externalEdgeSet);
1176 //Add edge for return value
1177 if (fcall.getReturnTemp()!=null) {
1178 MySet<Edge> returnedge=delta.varedgeadd.get(returntmp);
1179 if (returnedge!=null)
1180 for(Edge e:returnedge) {
1181 //skip the edge if types don't allow it...
1182 if (!typeUtil.isSuperorType(fcall.getReturnTemp().getType(), e.dst.getType()))
1184 Edge newedge=e.copy();
1185 newedge.srcvar=fcall.getReturnTemp();
1186 if (seseCallers!=null)
1187 newedge.taintModify(seseCallers);
1188 if (graph.getEdges(fcall.getReturnTemp())==null||!graph.getEdges(fcall.getReturnTemp()).contains(newedge))
1189 newDelta.addEdge(newedge);
1192 applyDiffs(graph, newDelta);
1196 public void mergeEdge(Graph graph, Delta newDelta, Edge edgetoadd) {
1197 if (edgetoadd!=null) {
1198 Edge match=graph.getMatch(edgetoadd);
1200 if (match==null||!match.subsumes(edgetoadd)) {
1201 Edge mergededge=edgetoadd.merge(match);
1202 newDelta.addEdge(mergededge);
1207 /* This is a call produced edge...need to remember this */
1209 public void mergeCallEdge(Graph graph, Delta newDelta, Edge edgetoadd) {
1210 if (edgetoadd!=null) {
1211 newDelta.addEdgeClear(edgetoadd);
1213 Edge match=graph.getMatch(edgetoadd);
1215 if (match==null||!match.subsumes(edgetoadd)) {
1216 Edge mergededge=edgetoadd.merge(match);
1217 newDelta.addEdge(mergededge);
1218 graph.callerEdges.add(mergededge);
1224 /* Summarizes out of context nodes in graph */
1225 void summarizeInGraph(Graph graph, Delta newDelta, AllocNode singleNode) {
1226 AllocNode summaryNode=allocFactory.getAllocNode(singleNode, true);
1228 //Handle outgoing heap edges
1229 MySet<Edge> edgeset=graph.getEdges(singleNode);
1231 for(Edge e:edgeset) {
1232 Edge rewrite=e.rewrite(singleNode, summaryNode);
1234 newDelta.removeHeapEdge(e);
1235 mergeCallEdge(graph, newDelta, rewrite);
1238 //Handle incoming edges
1239 MySet<Edge> backedges=graph.getBackEdges(singleNode);
1240 for(Edge e:backedges) {
1241 if (e.dst==singleNode) {
1242 //Need to get original edge so that predicate will be correct
1243 Edge match=graph.getMatch(e);
1245 Edge rewrite=match.rewrite(singleNode, summaryNode);
1246 newDelta.removeEdge(match);
1247 mergeCallEdge(graph, newDelta, rewrite);
1253 void applyDiffs(Graph graph, Delta delta) {
1254 applyDiffs(graph, delta, false);
1257 void applyDiffs(Graph graph, Delta delta, boolean genbackwards) {
1258 //build backwards map if requested
1259 if (genbackwards&&graph.backMap==null) {
1260 graph.backMap=new HashMap<AllocNode, MySet<Edge>>();
1261 if (graph.parent.backMap==null) {
1262 graph.parent.backMap=new HashMap<AllocNode, MySet<Edge>>();
1263 for(Map.Entry<AllocNode, MySet<Edge>> entry:graph.nodeMap.entrySet()) {
1264 for(Edge e:entry.getValue()) {
1265 if (!graph.parent.backMap.containsKey(e.dst))
1266 graph.parent.backMap.put(e.dst, new MySet<Edge>());
1267 graph.parent.backMap.get(e.dst).add(e);
1270 for(Map.Entry<TempDescriptor, MySet<Edge>> entry:graph.varMap.entrySet()) {
1271 for(Edge e:entry.getValue()) {
1272 if (!graph.parent.backMap.containsKey(e.dst))
1273 graph.parent.backMap.put(e.dst, new MySet<Edge>());
1274 graph.parent.backMap.get(e.dst).add(e);
1280 //Add hidden base edges
1281 for(Map.Entry<AllocNode, MySet<Edge>> e: delta.baseheapedge.entrySet()) {
1282 AllocNode node=e.getKey();
1283 MySet<Edge> edges=e.getValue();
1284 if (graph.nodeMap.containsKey(node)) {
1285 MySet<Edge> nodeEdges=graph.nodeMap.get(node);
1286 nodeEdges.addAll(edges);
1291 for(Map.Entry<AllocNode, MySet<Edge>> e: delta.heapedgeremove.entrySet()) {
1292 AllocNode node=e.getKey();
1293 MySet<Edge> edgestoremove=e.getValue();
1294 if (graph.nodeMap.containsKey(node)) {
1295 //Just apply diff to current map
1296 graph.nodeMap.get(node).removeAll(edgestoremove);
1298 //Generate diff from parent graph
1299 MySet<Edge> parentedges=graph.parent.nodeMap.get(node);
1300 if (parentedges!=null) {
1301 MySet<Edge> newedgeset=Util.setSubtract(parentedges, edgestoremove);
1302 graph.nodeMap.put(node, newedgeset);
1308 for(Map.Entry<AllocNode, MySet<Edge>> e: delta.heapedgeadd.entrySet()) {
1309 AllocNode node=e.getKey();
1310 MySet<Edge> edgestoadd=e.getValue();
1311 //If we have not done a subtract, then
1312 if (!graph.nodeMap.containsKey(node)) {
1313 //Copy the parent entry
1314 if (graph.parent.nodeMap.containsKey(node))
1315 graph.nodeMap.put(node, (MySet<Edge>)graph.parent.nodeMap.get(node).clone());
1317 graph.nodeMap.put(node, new MySet<Edge>());
1319 Edge.mergeEdgesInto(graph.nodeMap.get(node),edgestoadd);
1321 for(Edge eadd:edgestoadd) {
1322 if (!graph.backMap.containsKey(eadd.dst))
1323 graph.backMap.put(eadd.dst, new MySet<Edge>());
1324 graph.backMap.get(eadd.dst).add(eadd);
1330 for(Map.Entry<TempDescriptor, MySet<Edge>> e: delta.varedgeremove.entrySet()) {
1331 TempDescriptor tmp=e.getKey();
1332 MySet<Edge> edgestoremove=e.getValue();
1334 if (graph.varMap.containsKey(tmp)) {
1335 //Just apply diff to current map
1336 graph.varMap.get(tmp).removeAll(edgestoremove);
1337 } else if (graph.parent.varMap.containsKey(tmp)) {
1338 //Generate diff from parent graph
1339 MySet<Edge> parentedges=graph.parent.varMap.get(tmp);
1340 MySet<Edge> newedgeset=Util.setSubtract(parentedges, edgestoremove);
1341 graph.varMap.put(tmp, newedgeset);
1346 for(Map.Entry<TempDescriptor, MySet<Edge>> e: delta.varedgeadd.entrySet()) {
1347 TempDescriptor tmp=e.getKey();
1348 MySet<Edge> edgestoadd=e.getValue();
1349 if (graph.varMap.containsKey(tmp)) {
1350 Edge.mergeEdgesInto(graph.varMap.get(tmp), edgestoadd);
1352 graph.varMap.put(tmp, (MySet<Edge>) edgestoadd.clone());
1354 for(Edge eadd:edgestoadd) {
1355 if (!graph.backMap.containsKey(eadd.dst))
1356 graph.backMap.put(eadd.dst, new MySet<Edge>());
1357 graph.backMap.get(eadd.dst).add(eadd);
1362 //Add node additions
1363 for(AllocNode node:delta.addNodeAges) {
1364 graph.nodeAges.add(node);
1367 for(Map.Entry<AllocNode, Boolean> nodeentry:delta.addOldNodes.entrySet()) {
1368 AllocNode node=nodeentry.getKey();
1369 Boolean ispresent=nodeentry.getValue();
1370 graph.oldNodes.put(node, ispresent);
1374 boolean isINACC(FlatNode node) {
1377 switch(node.kind()) {
1378 case FKind.FlatSetFieldNode: {
1379 FlatSetFieldNode n=(FlatSetFieldNode)node;
1380 return !accessible.isAccessible(n, n.getDst());
1382 case FKind.FlatSetElementNode: {
1383 FlatSetElementNode n=(FlatSetElementNode)node;
1384 return !accessible.isAccessible(n, n.getDst());
1386 case FKind.FlatFieldNode: {
1387 FlatFieldNode n=(FlatFieldNode)node;
1388 return !accessible.isAccessible(n, n.getSrc());
1390 case FKind.FlatElementNode: {
1391 FlatElementNode n=(FlatElementNode)node;
1392 return !accessible.isAccessible(n, n.getSrc());
1398 Delta processSetFieldElementNode(FlatNode node, Delta delta, Graph graph) {
1402 if (node.kind()==FKind.FlatSetElementNode) {
1403 FlatSetElementNode fen=(FlatSetElementNode) node;
1408 FlatSetFieldNode ffn=(FlatSetFieldNode) node;
1414 if (delta.getInit()) {
1415 MySet<Edge> dstEdges=GraphManip.getEdges(graph, delta, dst);
1417 if (OoOJava&&!accessible.isAccessible(node, dst)) {
1418 Taint dstStallTaint=Taint.factory(node, dst, AllocFactory.dummySite, null, ReachGraph.predsEmpty);
1419 dstEdges=Edge.taintAll(dstEdges, dstStallTaint);
1420 updateVarDelta(graph, delta, dst, dstEdges, null);
1423 effectsAnalysis.analyzeFlatSetFieldNode(dstEdges, fd, node);
1426 //Do nothing for non pointers
1427 if (!src.getType().isPtr()) {
1428 if (mustProcess.contains(node)) {
1429 applyDiffs(graph, delta);
1434 MySet<Edge> srcEdges=GraphManip.getEdges(graph, delta, src);
1435 if (OoOJava&&!accessible.isAccessible(node, src)) {
1436 Taint srcStallTaint=Taint.factory(node, src, AllocFactory.dummySite, null, ReachGraph.predsEmpty);
1437 srcEdges=Edge.taintAll(srcEdges, srcStallTaint);
1438 updateVarDelta(graph, delta, src, srcEdges, null);
1441 MySet<Edge> edgesToAdd=GraphManip.genEdges(dstEdges, fd, srcEdges);
1442 MySet<Edge> edgesToRemove=null;
1443 if (dstEdges.size()==1&&!dstEdges.iterator().next().dst.isSummary()&&fd!=null) {
1444 /* Can do a strong update */
1445 edgesToRemove=GraphManip.getEdges(graph, delta, dstEdges, fd);
1446 graph.strongUpdateSet=edgesToRemove;
1448 graph.strongUpdateSet=new MySet<Edge>();
1451 updateHeapDelta(graph, delta, edgesToAdd, edgesToRemove);
1452 applyDiffs(graph, delta);
1454 MySet<Edge> newDstEdges=GraphManip.getDiffEdges(delta, dst);
1456 if (OoOJava&&!accessible.isAccessible(node, dst)) {
1457 Taint dstStallTaint=Taint.factory(node, dst, AllocFactory.dummySite, null, ReachGraph.predsEmpty);
1458 newDstEdges=Edge.taintAll(newDstEdges, dstStallTaint);
1459 updateVarDelta(graph, delta, dst, newDstEdges, null);
1463 effectsAnalysis.analyzeFlatSetFieldNode(newDstEdges, fd, node);
1466 if (!src.getType().isPtr()) {
1467 if (mustProcess.contains(node)) {
1468 applyDiffs(graph, delta);
1473 /* Next look at new sources */
1475 MySet<Edge> edgesToAdd=new MySet<Edge>();
1476 MySet<Edge> newSrcEdges=GraphManip.getDiffEdges(delta, src);
1477 MySet<Edge> srcEdges=GraphManip.getEdges(graph, delta, src);
1478 HashSet<AllocNode> dstNodes=GraphManip.getNodes(graph, delta, dst);
1480 if (OoOJava&&!accessible.isAccessible(node, src)) {
1481 Taint srcStallTaint=Taint.factory(node, src, AllocFactory.dummySite, null, ReachGraph.predsEmpty);
1482 newSrcEdges=Edge.taintAll(newSrcEdges, srcStallTaint);
1483 updateVarDelta(graph, delta, src, newSrcEdges, null);
1486 MySet<Edge> edgesToRemove=null;
1487 if (newDstEdges.size()!=0) {
1488 if (dstNodes.size()>1&&!dstNodes.iterator().next().isSummary()&&fd!=null) {
1489 /* Need to undo strong update */
1490 if (graph.strongUpdateSet!=null) {
1491 edgesToAdd.addAll(graph.strongUpdateSet);
1492 graph.strongUpdateSet=null; //Prevent future strong updates
1494 } else if (dstNodes.size()==1&&newDstEdges.size()==1&&!newDstEdges.iterator().next().dst.isSummary()&&graph.strongUpdateSet!=null&&fd!=null) {
1495 edgesToRemove=GraphManip.getEdges(graph, delta, dstNodes, fd);
1496 graph.strongUpdateSet.addAll(edgesToRemove);
1498 Edge.mergeEdgesInto(edgesToAdd, GraphManip.genEdges(newDstEdges, fd, srcEdges));
1502 if (graph.strongUpdateSet!=null&&fd!=null) {
1503 MySet<Edge> otherEdgesToRemove=GraphManip.getDiffEdges(delta, dstNodes, fd);
1504 if (edgesToRemove!=null)
1505 edgesToRemove.addAll(otherEdgesToRemove);
1507 edgesToRemove=otherEdgesToRemove;
1508 graph.strongUpdateSet.addAll(otherEdgesToRemove);
1511 //Next look at new destinations
1512 Edge.mergeEdgesInto(edgesToAdd, GraphManip.genEdges(dstNodes, fd, newSrcEdges));
1515 updateHeapDelta(graph, delta, edgesToAdd, edgesToRemove);
1516 applyDiffs(graph, delta);
1521 Delta processCopyNode(FlatNode node, Delta delta, Graph graph) {
1524 if (node.kind()==FKind.FlatOpNode) {
1525 FlatOpNode fon=(FlatOpNode) node;
1528 } else if (node.kind()==FKind.FlatReturnNode) {
1529 FlatReturnNode frn=(FlatReturnNode)node;
1530 src=frn.getReturnTemp();
1532 if (src==null||!src.getType().isPtr()) {
1534 applyDiffs(graph, delta);
1538 FlatCastNode fcn=(FlatCastNode) node;
1542 if (delta.getInit()) {
1543 MySet<Edge> srcedges=GraphManip.getEdges(graph, delta, src);
1544 MySet<Edge> edgesToAdd=GraphManip.genEdges(dst, srcedges);
1545 MySet<Edge> edgesToRemove=GraphManip.getEdges(graph, delta, dst);
1546 updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
1547 applyDiffs(graph, delta);
1549 /* First compute new src nodes */
1550 MySet<Edge> newSrcEdges=GraphManip.getDiffEdges(delta, src);
1552 /* Compute the union, and then the set of edges */
1553 MySet<Edge> edgesToAdd=GraphManip.genEdges(dst, newSrcEdges);
1555 /* Compute set of edges to remove */
1556 MySet<Edge> edgesToRemove=GraphManip.getDiffEdges(delta, dst);
1559 updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
1560 applyDiffs(graph, delta);
1565 Delta processFieldElementNode(FlatNode node, Delta delta, Graph graph) {
1569 TaintSet taint=null;
1571 if (node.kind()==FKind.FlatElementNode) {
1572 FlatElementNode fen=(FlatElementNode) node;
1577 FlatFieldNode ffn=(FlatFieldNode) node;
1582 if (OoOJava&&!accessible.isAccessible(node, src)) {
1583 taint=TaintSet.factory(Taint.factory(node, src, AllocFactory.dummySite, null, ReachGraph.predsEmpty));
1586 //Do nothing for non pointers
1587 if (delta.getInit()) {
1588 MySet<Edge> srcedges=GraphManip.getEdges(graph, delta, src);
1591 srcedges=Edge.taintAll(srcedges, taint);
1592 updateVarDelta(graph, delta, src, srcedges, null);
1594 effectsAnalysis.analyzeFlatFieldNode(srcedges, fd, node);
1596 if (!dst.getType().isPtr()) {
1597 if (mustProcess.contains(node)) {
1598 applyDiffs(graph, delta);
1603 MySet<Edge> edgesToAdd=GraphManip.dereference(graph, delta, dst, srcedges, fd, node);
1604 MySet<Edge> edgesToRemove=GraphManip.getEdges(graph, delta, dst);
1606 updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
1607 applyDiffs(graph, delta);
1609 MySet<Edge> newsrcedges=GraphManip.getDiffEdges(delta, src);
1612 newsrcedges=Edge.taintAll(newsrcedges, taint);
1613 updateVarDelta(graph, delta, src, newsrcedges, null);
1615 effectsAnalysis.analyzeFlatFieldNode(newsrcedges, fd, node);
1617 if (!dst.getType().isPtr()) {
1618 if (mustProcess.contains(node)) {
1619 applyDiffs(graph, delta);
1623 /* First compute new objects we read fields of */
1624 MySet<Edge> allsrcedges=GraphManip.getEdges(graph, delta, src);
1625 MySet<Edge> edgesToAdd=GraphManip.diffDereference(delta, dst, allsrcedges, fd, node);
1626 /* Next compute new targets of fields */
1627 MySet<Edge> newfdedges=GraphManip.dereference(graph, delta, dst, newsrcedges, fd, node);
1629 /* Compute the union, and then the set of edges */
1630 Edge.mergeEdgesInto(edgesToAdd, newfdedges);
1632 /* Compute set of edges to remove */
1633 MySet<Edge> edgesToRemove=GraphManip.getDiffEdges(delta, dst);
1637 updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
1638 applyDiffs(graph, delta);
1644 void updateVarDelta(Graph graph, Delta delta, TempDescriptor tmp, MySet<Edge> edgestoAdd, MySet<Edge> edgestoRemove) {
1645 MySet<Edge> edgeAdd=delta.varedgeadd.get(tmp);
1646 MySet<Edge> edgeRemove=delta.varedgeremove.get(tmp);
1647 MySet<Edge> existingEdges=graph.getEdges(tmp);
1648 if (edgestoRemove!=null)
1649 for(Edge e: edgestoRemove) {
1650 //remove edge from delta
1653 //if the edge is already in the graph, add an explicit remove to the delta
1654 if (existingEdges.contains(e))
1655 delta.removeVarEdge(e);
1657 for(Edge e: edgestoAdd) {
1658 //Remove the edge from the remove set
1659 if (edgeRemove!=null)
1660 edgeRemove.remove(e);
1661 //Explicitly add it to the add set unless it is already in the graph
1662 if (typeUtil.isSuperorType(tmp.getType(), e.dst.getType())) {
1663 if (!existingEdges.contains(e)) {
1664 delta.addVarEdge(e);
1666 //See if the old edge subsumes the new one
1667 Edge olde=existingEdges.get(e);
1668 if (!olde.subsumes(e)) {
1669 delta.addVarEdge(olde.merge(e));
1676 void updateHeapDelta(Graph graph, Delta delta, MySet<Edge> edgestoAdd, MySet<Edge> edgestoRemove) {
1677 if (edgestoRemove!=null)
1678 for(Edge e: edgestoRemove) {
1679 AllocNode src=e.src;
1680 MySet<Edge> edgeAdd=delta.heapedgeadd.get(src);
1681 MySet<Edge> existingEdges=graph.getEdges(src);
1682 //remove edge from delta
1685 //if the edge is already in the graph, add an explicit remove to the delta
1686 if (existingEdges.contains(e)) {
1687 delta.removeHeapEdge(e);
1690 if (edgestoAdd!=null)
1691 for(Edge e: edgestoAdd) {
1692 AllocNode src=e.src;
1693 MySet<Edge> edgeRemove=delta.heapedgeremove.get(src);
1694 MySet<Edge> existingEdges=graph.getEdges(src);
1695 //Remove the edge from the remove set
1696 if (edgeRemove!=null)
1697 edgeRemove.remove(e);
1698 //Explicitly add it to the add set unless it is already in the graph
1699 if (!existingEdges.contains(e)) {
1700 delta.addHeapEdge(e);
1702 //See if the old edge subsumes the new one
1703 Edge olde=existingEdges.get(e);
1704 if (!olde.subsumes(e)) {
1705 delta.addHeapEdge(olde.merge(e));
1711 Delta processFlatNop(FlatNode node, Delta delta, Graph graph) {
1712 applyDiffs(graph, delta);
1716 Delta processNewNode(FlatNew node, Delta delta, Graph graph) {
1717 AllocNode summary=allocFactory.getAllocNode(node, true);
1718 AllocNode single=allocFactory.getAllocNode(node, false);
1719 TempDescriptor tmp=node.getDst();
1721 if (delta.getInit()) {
1722 /* We don't have to deal with summarization here... The
1723 * intuition is that this is the only place where we generate
1724 * nodes for this allocation site and this is the first time
1725 * we've analyzed this site */
1728 Edge e=new Edge(tmp, single);
1729 //Build new Edge set
1730 MySet<Edge> newedges=new MySet<Edge>();
1732 //Add it into the diffs
1733 delta.varedgeadd.put(tmp, newedges);
1734 //Remove the old edges
1735 MySet<Edge> oldedges=graph.getEdges(tmp);
1736 if (!oldedges.isEmpty())
1737 delta.varedgeremove.put(tmp, (MySet<Edge>) oldedges);
1738 //Apply incoming diffs to graph
1739 applyDiffs(graph, delta);
1740 //Note that we create a single node
1741 delta.addNodeAges.add(single);
1743 if (delta.addOldNodes.containsKey(single)||delta.baseOldNodes.containsKey(single)) {
1744 delta.addOldNodes.put(single, Boolean.FALSE);
1747 /* 1. Fix up the variable edge additions */
1749 for(Iterator<Map.Entry<TempDescriptor, MySet<Edge>>> entryIt=delta.varedgeadd.entrySet().iterator();entryIt.hasNext();) {
1750 Map.Entry<TempDescriptor, MySet<Edge>> entry=entryIt.next();
1752 if (entry.getKey()==tmp) {
1753 /* Check if this is the tmp we overwrite */
1756 /* Otherwise, check if the target of the edge is changed... */
1757 summarizeSet(entry.getValue(), graph.varMap.get(entry.getKey()), single, summary);
1761 /* 2. Fix up the base variable edges */
1763 for(Iterator<Map.Entry<TempDescriptor, MySet<Edge>>> entryIt=delta.basevaredge.entrySet().iterator();entryIt.hasNext();) {
1764 Map.Entry<TempDescriptor, MySet<Edge>> entry=entryIt.next();
1765 TempDescriptor entrytmp=entry.getKey();
1766 if (entrytmp==tmp) {
1767 /* Check is this is the tmp we overwrite, if so add to remove set */
1768 Util.relationUpdate(delta.varedgeremove, tmp, null, entry.getValue());
1770 /* Check if the target of the edge is changed */
1771 MySet<Edge> newset=(MySet<Edge>)entry.getValue().clone();
1772 MySet<Edge> removeset=shrinkSet(newset, graph.varMap.get(entrytmp), single, summary);
1773 Util.relationUpdate(delta.varedgeremove, entrytmp, newset, removeset);
1774 Util.relationUpdate(delta.varedgeadd, entrytmp, null, newset);
1779 /* 3. Fix up heap edge additions */
1781 HashMap<AllocNode, MySet<Edge>> addheapedge=new HashMap<AllocNode, MySet<Edge>>();
1782 for(Iterator<Map.Entry<AllocNode, MySet<Edge>>> entryIt=delta.heapedgeadd.entrySet().iterator();entryIt.hasNext();) {
1783 Map.Entry<AllocNode, MySet<Edge>> entry=entryIt.next();
1784 MySet<Edge> edgeset=entry.getValue();
1785 AllocNode allocnode=entry.getKey();
1786 if (allocnode==single) {
1788 summarizeSet(edgeset, graph.nodeMap.get(summary), single, summary);
1789 addheapedge.put(summary, edgeset);
1791 summarizeSet(edgeset, graph.nodeMap.get(allocnode), single, summary);
1795 /* Merge in diffs */
1797 for(Map.Entry<AllocNode, MySet<Edge>> entry:addheapedge.entrySet()) {
1798 AllocNode allocnode=entry.getKey();
1799 Util.relationUpdate(delta.heapedgeadd, allocnode, null, entry.getValue());
1802 /* 4. Fix up the base heap edges */
1804 for(Iterator<Map.Entry<AllocNode, MySet<Edge>>> entryIt=delta.baseheapedge.entrySet().iterator();entryIt.hasNext();) {
1805 Map.Entry<AllocNode, MySet<Edge>> entry=entryIt.next();
1806 MySet<Edge> edgeset=entry.getValue();
1807 AllocNode allocnode=entry.getKey();
1808 if (allocnode==single) {
1811 AllocNode addnode=(allocnode==single)?summary:allocnode;
1813 MySet<Edge> newset=(MySet<Edge>) edgeset.clone();
1814 MySet<Edge> removeset=shrinkSet(newset, graph.nodeMap.get(addnode), single, summary);
1815 Util.relationUpdate(delta.heapedgeadd, addnode, null, newset);
1816 Util.relationUpdate(delta.heapedgeremove, allocnode, null, removeset);
1819 /* Update Node Ages...If the base or addNodeAges set contains a
1820 * single node, it now should also contain a summary node... No
1821 * need to generate a single node as that has already been
1823 if (delta.baseNodeAges.contains(single)||delta.addNodeAges.contains(single)) {
1824 delta.addNodeAges.add(summary);
1827 //Kill the old node if someone tries to add it
1828 if (delta.addOldNodes.containsKey(single)||delta.baseOldNodes.containsKey(single)) {
1829 delta.addOldNodes.put(single, Boolean.FALSE);
1833 //Apply incoming diffs to graph
1834 applyDiffs(graph, delta);
1839 /* This function builds a new edge set where oldnode is summarized into new node */
1841 void summarizeSet(MySet<Edge> edgeset, MySet<Edge> oldedgeset, AllocNode oldnode, AllocNode sumnode) {
1842 MySet<Edge> newSet=null;
1843 for(Iterator<Edge> edgeit=edgeset.iterator();edgeit.hasNext();) {
1844 Edge e=edgeit.next();
1845 if (e.dst==oldnode||e.src==oldnode) {
1847 newSet=new MySet<Edge>();
1852 if (e.dst==oldnode) {
1855 if (e.src==oldnode) {
1858 if (oldedgeset==null||!oldedgeset.contains(e))
1863 edgeset.addAll(newSet);
1866 /* Shrinks the incoming set to just include rewritten values.
1867 * Returns a set of the original rewritten values */
1869 MySet<Edge> shrinkSet(MySet<Edge> edgeset, MySet<Edge> oldedgeset, AllocNode oldnode, AllocNode newnode) {
1870 MySet<Edge> newSet=null;
1871 MySet<Edge> removeSet=null;
1872 for(Iterator<Edge> edgeit=edgeset.iterator();edgeit.hasNext();) {
1873 Edge e=edgeit.next();
1875 if (e.dst==oldnode||e.src==oldnode) {
1877 newSet=new MySet<Edge>();
1878 removeSet=new MySet<Edge>();
1887 if (oldedgeset==null||!oldedgeset.contains(e))
1892 edgeset.addAll(newSet);
1896 /* This function returns a completely new Delta... It is safe to
1899 Delta applyInitDelta(Delta delta, BBlock block) {
1900 //Apply delta to graph
1901 boolean newGraph=false;
1902 if (!bbgraphMap.containsKey(block)) {
1903 bbgraphMap.put(block, new Graph(null));
1906 Graph graph=bbgraphMap.get(block);
1909 Delta newdelta=new Delta(null, true);
1910 //Add in heap edges and throw away original diff
1912 for(Map.Entry<AllocNode, MySet<Edge>> entry:delta.heapedgeadd.entrySet()) {
1913 graph.nodeMap.put(entry.getKey(), new MySet<Edge>(entry.getValue()));
1915 //Add in var edges and throw away original diff
1916 Set<TempDescriptor> livetemps=bblivetemps.get(block);
1918 for(Map.Entry<TempDescriptor, MySet<Edge>> entry:delta.varedgeadd.entrySet()) {
1919 if (livetemps.contains(entry.getKey()))
1920 graph.varMap.put(entry.getKey(), new MySet<Edge>(entry.getValue()));
1922 //Record that this is initial set...
1923 graph.nodeAges.addAll(delta.addNodeAges);
1925 for(Map.Entry<AllocNode, Boolean> oldentry:delta.addOldNodes.entrySet()) {
1926 if (oldentry.getValue().booleanValue()) {
1927 graph.oldNodes.put(oldentry.getKey(), Boolean.TRUE);
1932 Delta newdelta=new Delta(null, false);
1933 //merge in heap edges and variables
1934 mergeHeapEdges(graph, delta, newdelta);
1935 mergeVarEdges(graph, delta, newdelta, block);
1936 mergeAges(graph, delta, newdelta);
1941 /* This function merges in the heap edges. It updates delta to be
1944 void mergeHeapEdges(Graph graph, Delta delta, Delta newdelta) {
1946 for(Map.Entry<AllocNode, MySet<Edge>> heapedge:delta.heapedgeadd.entrySet()) {
1947 AllocNode nsrc=heapedge.getKey();
1948 MySet<Edge> edges=heapedge.getValue();
1950 if (graph.backMap!=null) {
1952 if (!graph.backMap.containsKey(e.dst))
1953 graph.backMap.put(e.dst, new MySet<Edge>());
1954 graph.backMap.get(e.dst).add(e);
1958 if (!graph.nodeMap.containsKey(nsrc)) {
1959 graph.nodeMap.put(nsrc, new MySet<Edge>());
1961 MySet<Edge> dstedges=graph.nodeMap.get(nsrc);
1962 MySet<Edge> diffedges=new MySet<Edge>();
1964 if (!dstedges.contains(e)) {
1965 //We have a new edge
1969 Edge origedge=dstedges.get(e);
1970 if (!origedge.subsumes(e)) {
1971 Edge mergededge=origedge.merge(e);
1972 diffedges.add(mergededge);
1973 dstedges.add(mergededge);
1977 //Done with edge set...
1978 if (diffedges.size()>0) {
1980 newdelta.baseheapedge.put(nsrc, diffedges);
1985 /* This function merges in the var edges. It updates delta to be
1988 void mergeVarEdges(Graph graph, Delta delta, Delta newdelta, BBlock block) {
1990 Set<TempDescriptor> livetemps=bblivetemps.get(block);
1992 for(Map.Entry<TempDescriptor, MySet<Edge>> varedge:delta.varedgeadd.entrySet()) {
1993 TempDescriptor tmpsrc=varedge.getKey();
1994 if (livetemps.contains(tmpsrc)) {
1995 MySet<Edge> edges=varedge.getValue();
1996 if (graph.backMap!=null) {
1998 if (!graph.backMap.containsKey(e.dst))
1999 graph.backMap.put(e.dst, new MySet<Edge>());
2000 graph.backMap.get(e.dst).add(e);
2004 if (!graph.varMap.containsKey(tmpsrc)) {
2005 graph.varMap.put(tmpsrc, new MySet<Edge>());
2007 MySet<Edge> dstedges=graph.varMap.get(tmpsrc);
2008 MySet<Edge> diffedges=new MySet<Edge>();
2010 if (!dstedges.contains(e)) {
2011 //We have a new edge
2015 Edge origedge=dstedges.get(e);
2016 if (!origedge.subsumes(e)) {
2017 Edge mergededge=origedge.merge(e);
2018 diffedges.add(mergededge);
2019 dstedges.add(mergededge);
2023 //Done with edge set...
2024 if (diffedges.size()>0) {
2026 newdelta.basevaredge.put(tmpsrc,diffedges);
2032 void mergeAges(Graph graph, Delta delta, Delta newDelta) {
2034 for(AllocNode node:delta.addNodeAges) {
2035 if (!graph.nodeAges.contains(node)) {
2036 graph.nodeAges.add(node);
2037 newDelta.baseNodeAges.add(node);
2040 for(Map.Entry<AllocNode, Boolean> oldentry:delta.addOldNodes.entrySet()) {
2041 AllocNode node=oldentry.getKey();
2042 boolean ispresent=oldentry.getValue().booleanValue();
2043 if (ispresent&&!graph.oldNodes.containsKey(node)) {
2044 graph.oldNodes.put(node, Boolean.TRUE);
2045 newDelta.baseOldNodes.put(node, Boolean.TRUE);