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;
148 //Compute delta at exit of each node
149 for(int i=startindex; i<nodes.size();i++) {
150 FlatNode currNode=nodes.get(i);
151 //System.out.println("Start Processing "+currNode);
152 boolean init=delta.getInit();
153 if (!init&&delta.isEmpty())
157 if (!graphMap.containsKey(currNode)) {
158 if (isNEEDED(currNode)) {
159 graphMap.put(currNode, new Graph(graph));
161 boolean fallthru=true;
162 if (isINACC(currNode)&&((lasti==-1)||(lasti==i))) {
164 for(lasti=nodes.size()-1;lasti>=i;lasti--) {
165 FlatNode scurrNode=nodes.get(lasti);
166 if (isNEEDED(scurrNode)||isINACC(scurrNode)) {
172 mustProcess.add(currNode);
173 graphMap.put(currNode, new Graph(graph));
179 //base graph works for us
180 graphMap.put(currNode, new Graph(graph));
182 //just use previous graph
183 graphMap.put(currNode, graphMap.get(nodes.get(i-1)));
189 nodeGraph=graphMap.get(currNode);
190 delta=processNode(bblock, i, currNode, delta, nodeGraph);
191 //System.out.println("Processing "+currNode+" and generating delta:");
194 generateFinalDelta(bblock, delta, nodeGraph);
200 for(Map.Entry<BBlock, Graph> e:bbgraphMap.entrySet()) {
201 Graph g=e.getValue();
202 plotGraph(g,"BB"+e.getKey().nodes.get(0).toString().replace(' ','_'));
206 for(FlatMethod fm:blockMap.keySet()) {
207 System.out.println(fm.printMethod());
209 for(Map.Entry<FlatNode, Graph> e:graphMap.entrySet()) {
210 FlatNode fn=e.getKey();
211 Graph g=e.getValue();
212 plotGraph(g,"FN"+fn.toString()+debugindex);
217 State.logEvent("Done With Pointer Analysis");
221 effectsAnalysis.buildStateMachines.writeStateMachines();
222 State.logEvent("Done Writing State Machines");
226 void plotGraph(Graph g, String name) {
228 PrintWriter pw=new PrintWriter(new FileWriter(name.toString().replace(' ','_')+".dot"));
229 g.printGraph(pw, name);
231 } catch (Exception ex) {
232 ex.printStackTrace();
237 /* This function builds the last delta for a basic block. It
238 * handles the case for the first time the basic block is
241 void buildInitDelta(Graph graph, Delta newDelta) {
242 //First compute the set of temps
243 HashSet<TempDescriptor> tmpSet=new HashSet<TempDescriptor>();
244 tmpSet.addAll(graph.varMap.keySet());
245 tmpSet.addAll(graph.parent.varMap.keySet());
247 //Next build the temp map part of the delta
248 for(TempDescriptor tmp:tmpSet) {
249 MySet<Edge> edgeSet=new MySet<Edge>();
251 if (graph.varMap.containsKey(tmp))
252 edgeSet.addAll(graph.varMap.get(tmp));
254 edgeSet.addAll(graph.parent.varMap.get(tmp));
255 newDelta.varedgeadd.put(tmp, edgeSet);
258 //Next compute the set of src allocnodes
259 HashSet<AllocNode> nodeSet=new HashSet<AllocNode>();
260 nodeSet.addAll(graph.nodeMap.keySet());
261 nodeSet.addAll(graph.parent.nodeMap.keySet());
263 for(AllocNode node:nodeSet) {
264 MySet<Edge> edgeSet=new MySet<Edge>();
266 if (graph.nodeMap.containsKey(node))
267 edgeSet.addAll(graph.nodeMap.get(node));
269 edgeSet.addAll(graph.parent.nodeMap.get(node));
270 newDelta.heapedgeadd.put(node, edgeSet);
273 if (graph.oldNodes.containsKey(node)) {
274 if (graph.oldNodes.get(node).booleanValue())
275 newDelta.addOldNodes.put(node, Boolean.TRUE);
276 } else if (graph.parent.oldNodes.containsKey(node)) {
277 //parent graphs only contain true...no need to check
278 newDelta.addOldNodes.put(node, Boolean.TRUE);
282 newDelta.addNodeAges.addAll(graph.nodeAges);
283 newDelta.addNodeAges.addAll(graph.parent.nodeAges);
286 /* This function build the delta for the exit of a basic block. */
288 void generateFinalDelta(BBlock bblock, Delta delta, Graph graph) {
289 Delta newDelta=new Delta(null, false);
290 if (delta.getInit()) {
291 buildInitDelta(graph, newDelta);
293 /* We can break the old delta...it is done being used */
294 /* First we will build variable edges */
295 HashSet<TempDescriptor> tmpSet=new HashSet<TempDescriptor>();
296 tmpSet.addAll(delta.basevaredge.keySet());
297 tmpSet.addAll(delta.varedgeadd.keySet());
298 for(TempDescriptor tmp:tmpSet) {
299 /* Start with the new incoming edges */
300 MySet<Edge> newbaseedge=delta.basevaredge.get(tmp);
301 /* Remove the remove set */
302 if (newbaseedge==null)
303 newbaseedge=new MySet<Edge>();
304 newbaseedge.removeAll(delta.varedgeremove.get(tmp));
305 /* Add in the new set*/
306 newbaseedge.addAll(delta.varedgeadd.get(tmp));
307 /* Store the results */
308 newDelta.varedgeadd.put(tmp, newbaseedge);
310 delta.basevaredge.clear();
312 /* Next we build heap edges */
313 HashSet<AllocNode> nodeSet=new HashSet<AllocNode>();
314 nodeSet.addAll(delta.baseheapedge.keySet());
315 nodeSet.addAll(delta.heapedgeadd.keySet());
316 nodeSet.addAll(delta.heapedgeremove.keySet());
317 for(AllocNode node:nodeSet) {
318 /* Start with the new incoming edges */
319 MySet<Edge> newheapedge=new MySet<Edge>(delta.baseheapedge.get(node));
320 /* Remove the remove set */
321 MySet<Edge> removeset=delta.heapedgeremove.get(node);
324 newheapedge.removeAll(removeset);
326 /* Add in the add set */
327 MySet<Edge> settoadd=delta.heapedgeadd.get(node);
329 newheapedge.addAll(settoadd);
330 newDelta.heapedgeadd.put(node, newheapedge);
332 /* Remove the newly created edges..no need to propagate a diff for those */
333 if (removeset!=null) {
334 removeset.removeAll(delta.baseheapedge.get(node));
335 newDelta.heapedgeremove.put(node, removeset);
339 /* Compute new ages */
340 newDelta.addNodeAges.addAll(delta.baseNodeAges);
341 newDelta.addNodeAges.addAll(delta.addNodeAges);
342 HashSet<AllocNode> oldNodes=new HashSet<AllocNode>();
344 /* Compute whether old nodes survive */
345 oldNodes.addAll(delta.baseOldNodes.keySet());
346 oldNodes.addAll(delta.addOldNodes.keySet());
347 for(AllocNode node:oldNodes) {
348 if (delta.addOldNodes.containsKey(node)) {
349 if (delta.addOldNodes.get(node).booleanValue()) {
350 newDelta.addOldNodes.put(node, Boolean.TRUE);
353 if (delta.baseOldNodes.get(node).booleanValue()) {
354 newDelta.addOldNodes.put(node, Boolean.TRUE);
360 if (returnMap.containsKey(bblock)) {
361 //clear everything but our return temp!
362 MySet<Edge> edges=newDelta.varedgeadd.get(returntmp);
363 newDelta.varedgeadd.clear();
364 newDelta.varedgeadd.put(returntmp, edges);
367 /* Now we need to propagate newdelta */
368 if (!newDelta.heapedgeadd.isEmpty()||!newDelta.heapedgeremove.isEmpty()||!newDelta.varedgeadd.isEmpty()||!newDelta.addNodeAges.isEmpty()||!newDelta.addOldNodes.isEmpty()) {
369 /* We have a delta to propagate */
370 if (returnMap.containsKey(bblock)) {
374 for(PPoint caller:returnMap.get(bblock)) {
375 //System.out.println("Sending Return BBlock to "+caller.getBBlock().nodes.get(caller.getIndex()).toString().replace(' ','_'));
378 newDelta.setBlock(caller);
379 toprocess.add(newDelta);
382 Delta d=newDelta.diffBlock(caller);
388 Vector<BBlock> blockvector=bblock.next();
389 for(int i=0;i<blockvector.size();i++) {
390 //System.out.println("Sending BBlock to "+blockvector.get(i).nodes.get(0).toString().replace(' ','_'));
393 newDelta.setBlock(new PPoint(blockvector.get(i)));
394 toprocess.add(newDelta);
396 Delta d=newDelta.diffBlock(new PPoint(blockvector.get(i)));
402 //System.out.println("EMPTY DELTA");
403 //System.out.println("delta");
405 //System.out.println("newDelta");
410 boolean isNEEDED(FlatNode node) {
411 switch(node.kind()) {
412 case FKind.FlatSetFieldNode: {
413 FlatSetFieldNode n=(FlatSetFieldNode)node;
414 return n.getSrc().getType().isPtr();
416 case FKind.FlatSetElementNode: {
417 FlatSetElementNode n=(FlatSetElementNode)node;
418 return n.getSrc().getType().isPtr();
420 case FKind.FlatFieldNode: {
421 FlatFieldNode n=(FlatFieldNode)node;
422 return n.getDst().getType().isPtr();
424 case FKind.FlatElementNode: {
425 FlatElementNode n=(FlatElementNode)node;
426 return n.getDst().getType().isPtr();
432 Delta processNode(BBlock bblock, int index, FlatNode node, Delta delta, Graph newgraph) {
433 switch(node.kind()) {
435 return processNewNode((FlatNew)node, delta, newgraph);
436 case FKind.FlatFieldNode:
437 case FKind.FlatElementNode:
438 return processFieldElementNode(node, delta, newgraph);
439 case FKind.FlatCastNode:
440 case FKind.FlatOpNode:
441 case FKind.FlatReturnNode:
442 return processCopyNode(node, delta, newgraph);
443 case FKind.FlatSetFieldNode:
444 case FKind.FlatSetElementNode:
445 return processSetFieldElementNode(node, delta, newgraph);
446 case FKind.FlatSESEEnterNode:
447 return processSESEEnterNode((FlatSESEEnterNode) node, delta, newgraph);
448 case FKind.FlatSESEExitNode:
449 return processSESEExitNode((FlatSESEExitNode) node, delta, newgraph);
450 case FKind.FlatMethod:
452 case FKind.FlatBackEdge:
453 case FKind.FlatGenReachNode:
454 return processFlatNop(node, delta, newgraph);
456 return processFlatCall(bblock, index, (FlatCall) node, delta, newgraph);
458 throw new Error("Unrecognized node:"+node);
462 Delta processSESEEnterNode(FlatSESEEnterNode sese, Delta delta, Graph graph) {
464 return processFlatNop(sese, delta, graph);
465 if (delta.getInit()) {
466 removeInitTaints(null, delta, graph);
467 for (TempDescriptor tmp:sese.getInVarSet()) {
468 Taint taint=Taint.factory(sese, null, tmp, AllocFactory.dummySite, null, ReachGraph.predsEmpty);
469 MySet<Edge> edges=GraphManip.getEdges(graph, delta, tmp);
471 Edge newe=e.addTaint(taint);
472 delta.addVarEdge(newe);
476 removeDiffTaints(null, delta);
477 for (TempDescriptor tmp:sese.getInVarSet()) {
478 Taint taint=Taint.factory(sese, null, tmp, AllocFactory.dummySite, null, ReachGraph.predsEmpty);
479 MySet<Edge> edges=GraphManip.getDiffEdges(delta, tmp);
481 Edge newe=e.addTaint(taint);
482 delta.addVarEdge(newe);
488 applyDiffs(graph, delta);
492 private boolean isRecursive(FlatSESEEnterNode sese) {
493 MethodDescriptor md=sese.getmdEnclosing();
494 boolean isrecursive=callGraph.getCalleeSet(md).contains(md);
498 Delta processSESEExitNode(FlatSESEExitNode seseexit, Delta delta, Graph graph) {
500 return processFlatNop(seseexit, delta, graph);
501 FlatSESEEnterNode sese=seseexit.getFlatEnter();
502 //Strip Taints from this SESE
503 if (delta.getInit()) {
504 removeInitTaints(isRecursive(sese)?null:sese, delta, graph);
506 removeDiffTaints(isRecursive(sese)?null:sese, delta);
508 applyDiffs(graph, delta);
512 void removeDiffTaints(FlatSESEEnterNode sese, Delta delta) {
513 //Start with variable edges
515 MySet<Edge> edgestoadd=new MySet<Edge>();
516 MySet<Edge> edgestoremove=new MySet<Edge>();
518 //Process base diff edges
519 processEdgeMap(sese, delta.basevaredge, null, delta.varedgeremove, edgestoremove, edgestoadd);
520 //Process delta edges
521 processEdgeMap(sese, delta.varedgeadd, null, null, edgestoremove, edgestoadd);
522 for(Edge e:edgestoremove) {
523 delta.removeVarEdge(e);
525 for(Edge e:edgestoadd) {
532 MySet<Edge> edgestoadd=new MySet<Edge>();
533 MySet<Edge> edgestoremove=new MySet<Edge>();
535 //Process base diff edges
536 processEdgeMap(sese, delta.baseheapedge, null, delta.heapedgeremove, edgestoremove, edgestoadd);
537 //Process delta edges
538 processEdgeMap(sese, delta.heapedgeadd, null, null, edgestoremove, edgestoadd);
539 for(Edge e:edgestoremove) {
540 delta.removeHeapEdge(e);
542 for(Edge e:edgestoadd) {
543 delta.addHeapEdge(e);
548 void removeInitTaints(FlatSESEEnterNode sese, Delta delta, Graph graph) {
549 //Start with variable edges
551 MySet<Edge> edgestoadd=new MySet<Edge>();
552 MySet<Edge> edgestoremove=new MySet<Edge>();
554 //Process parent edges
555 processEdgeMap(sese, graph.parent.varMap, graph.varMap, delta.varedgeremove, edgestoremove, edgestoadd);
556 //Process graph edges
557 processEdgeMap(sese, graph.varMap, null, delta.varedgeremove, edgestoremove, edgestoadd);
558 //Process delta edges
559 processEdgeMap(sese, delta.varedgeadd, null, null, edgestoremove, edgestoadd);
560 for(Edge e:edgestoremove) {
561 delta.removeVarEdge(e);
563 for(Edge e:edgestoadd) {
570 MySet<Edge> edgestoadd=new MySet<Edge>();
571 MySet<Edge> edgestoremove=new MySet<Edge>();
573 //Process parent edges
574 processEdgeMap(sese, graph.parent.nodeMap, graph.nodeMap, delta.heapedgeremove, edgestoremove, edgestoadd);
575 //Process graph edges
576 processEdgeMap(sese, graph.nodeMap, null, delta.heapedgeremove, edgestoremove, edgestoadd);
577 //Process delta edges
578 processEdgeMap(sese, delta.heapedgeadd, null, null, edgestoremove, edgestoadd);
579 for(Edge e:edgestoremove) {
580 delta.removeHeapEdge(e);
582 for(Edge e:edgestoadd) {
583 delta.addHeapEdge(e);
588 void processEdgeMap(FlatSESEEnterNode sese, HashMap<?, MySet<Edge>> edgemap, HashMap<?, MySet<Edge>> childmap, HashMap<?, MySet<Edge>> removemap, MySet<Edge> edgestoremove, MySet<Edge> edgestoadd) {
589 for(Map.Entry<?, MySet<Edge>> entry:edgemap.entrySet()) {
590 //If the parent map exists and overrides this entry, skip it
591 if (childmap!=null&&childmap.containsKey(entry.getKey()))
593 for(Edge e:entry.getValue()) {
594 //check whether this edge has been removed
595 if (removemap!=null&&removemap.containsKey(entry.getKey())&&
596 removemap.get(entry.getKey()).contains(e))
599 TaintSet ts=e.getTaints();
601 //update non-null taint set
603 newts=Canonical.removeInContextTaintsNP(ts, sese);
604 if (newts!=null&&newts!=ts) {
605 edgestoremove.add(e);
606 edgestoadd.add(e.changeTaintSet(newts));
612 /* This function compute the edges for the this variable for a
613 * callee if it exists. */
615 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) {
616 //Handle the this temp
618 MySet<Edge> edges=(oldnodeset!=null)?GraphManip.getDiffEdges(delta, tmpthis):GraphManip.getEdges(graph, delta, tmpthis);
619 newDelta.varedgeadd.put(tmpthis, (MySet<Edge>) edges.clone());
620 edgeset.addAll(edges);
622 AllocNode dstnode=e.dst;
623 if (!nodeset.contains(dstnode)&&(oldnodeset==null||!oldnodeset.contains(dstnode))) {
624 TypeDescriptor type=dstnode.getType();
625 if (!type.isArray()) {
626 targetSet.add(type.getClassDesc());
628 //arrays don't have code
629 targetSet.add(typeUtil.getClass(TypeUtil.ObjectClass));
631 nodeset.add(dstnode);
632 tovisit.add(dstnode);
638 /* This function compute the edges for a call's parameters. */
640 void processParams(Graph graph, Delta delta, Delta newDelta, HashSet<AllocNode> nodeset, Stack<AllocNode> tovisit, MySet<Edge> edgeset, FlatCall fcall, boolean diff) {
641 //Go through each temp
642 for(int i=0;i<fcall.numArgs();i++) {
643 TempDescriptor tmp=fcall.getArg(i);
644 MySet<Edge> edges=diff?GraphManip.getDiffEdges(delta, tmp):GraphManip.getEdges(graph, delta, tmp);
645 newDelta.varedgeadd.put(tmp, (MySet<Edge>) edges.clone());
646 edgeset.addAll(edges);
648 if (!nodeset.contains(e.dst)) {
656 /* This function computes the reachable nodes for a callee. */
658 void computeReachableNodes(Graph graph, Delta delta, Delta newDelta, HashSet<AllocNode> nodeset, Stack<AllocNode> tovisit, MySet<Edge> edgeset, HashSet<AllocNode> oldnodeset) {
659 while(!tovisit.isEmpty()) {
660 AllocNode node=tovisit.pop();
661 MySet<Edge> edges=GraphManip.getEdges(graph, delta, node);
662 if (!edges.isEmpty()) {
663 newDelta.heapedgeadd.put(node, Edge.makeOld(edges));
664 edgeset.addAll(edges);
666 if (!nodeset.contains(e.dst)&&(oldnodeset==null||!oldnodeset.contains(e.dst))) {
675 HashSet<MethodDescriptor> computeTargets(FlatCall fcall, Delta newDelta) {
676 TempDescriptor tmpthis=fcall.getThis();
677 MethodDescriptor md=fcall.getMethod();
678 HashSet<MethodDescriptor> targets=new HashSet<MethodDescriptor>();
679 if (md.isStatic()||fcall.getSuper()) {
683 for(Edge e:newDelta.varedgeadd.get(tmpthis)) {
684 AllocNode node=e.dst;
685 ClassDescriptor cd=node.getType().getClassDesc();
686 //Figure out exact method called and add to set
687 MethodDescriptor calledmd=cd.getCalledMethod(md);
688 targets.add(calledmd);
694 void fixMapping(FlatCall fcall, HashSet<MethodDescriptor> targets, MySet<Edge> oldedgeset, Delta newDelta, BBlock callblock, int callindex) {
695 Delta basedelta=null;
696 TempDescriptor tmpthis=fcall.getThis();
698 for(MethodDescriptor calledmd:targets) {
699 FlatMethod fm=state.getMethodFlat(calledmd);
700 boolean newmethod=false;
703 HashMap<TempDescriptor, TempDescriptor> tmpMap=new HashMap<TempDescriptor, TempDescriptor>();
706 tmpMap.put(tmpthis, fm.getParameter(offset++));
708 for(int i=0;i<fcall.numArgs();i++) {
709 TempDescriptor tmp=fcall.getArg(i);
710 tmpMap.put(tmp,fm.getParameter(i+offset));
713 //Get basicblock for the method
714 BasicBlock block=getBBlock(fm);
717 if (!callMap.containsKey(fcall)) {
718 callMap.put(fcall, new HashSet<BBlock>());
721 Delta returnDelta=null;
722 if (!callMap.get(fcall).contains(block.getStart())) {
723 callMap.get(fcall).add(block.getStart());
727 if (!returnMap.containsKey(block.getExit())) {
728 returnMap.put(block.getExit(), new HashSet<PPoint>());
730 returnMap.get(block.getExit()).add(new PPoint(callblock, callindex));
732 if (bbgraphMap.containsKey(block.getExit())) {
733 //Need to push existing results to current node
734 if (returnDelta==null) {
735 returnDelta=new Delta(null, false);
736 Vector<FlatNode> exitblocknodes=block.getExit().nodes();
737 FlatExit fexit=(FlatExit)exitblocknodes.get(exitblocknodes.size()-1);
738 buildInitDelta(graphMap.get(fexit), returnDelta);
739 if (!returnDelta.heapedgeadd.isEmpty()||!returnDelta.heapedgeremove.isEmpty()||!returnDelta.varedgeadd.isEmpty()) {
740 returnDelta.setBlock(new PPoint(callblock, callindex));
741 toprocess.add(returnDelta);
744 if (!returnDelta.heapedgeadd.isEmpty()||!returnDelta.heapedgeremove.isEmpty()||!returnDelta.varedgeadd.isEmpty()) {
745 toprocess.add(returnDelta.diffBlock(new PPoint(callblock, callindex)));
751 if (oldedgeset==null) {
752 //First build of this graph
753 //Build and enqueue delta...safe to just use existing delta
754 Delta d=newDelta.changeParams(tmpMap, new PPoint(block.getStart()));
755 //System.out.println("AProcessing "+block.getStart().nodes.get(0).toString().replace(' ','_'));
758 } else if (newmethod) {
759 if (basedelta==null) {
760 basedelta=newDelta.buildBase(oldedgeset);
762 //Build and enqueue delta
763 Delta d=basedelta.changeParams(tmpMap, new PPoint(block.getStart()));
764 //System.out.println("BProcessing "+block.getStart().nodes.get(0).toString().replace(' ','_'));
768 //Build and enqueue delta
769 Delta d=newDelta.changeParams(tmpMap, new PPoint(block.getStart()));
770 //System.out.println("CProcessing "+block.getStart().nodes.get(0).toString().replace(' ','_'));
778 /* This function computes all edges that start outside of the callee
779 * context and go into the callee context */
781 void computeExternalEdges(Graph graph, Delta delta, HashSet<AllocNode> nodeset, HashSet<AllocNode> deltaset, MySet<Edge> externaledgeset) {
782 //Do heap edges first
783 HashSet<AllocNode> externalnodes=new HashSet<AllocNode>();
784 externalnodes.addAll(delta.baseheapedge.keySet());
785 externalnodes.addAll(delta.heapedgeadd.keySet());
786 externalnodes.addAll(delta.heapedgeremove.keySet());
787 //remove allinternal nodes
788 externalnodes.removeAll(nodeset);
789 for(AllocNode extNode:externalnodes) {
790 //Compute set of edges from given node
791 MySet<Edge> edges=new MySet<Edge>(delta.baseheapedge.get(extNode));
792 edges.removeAll(delta.heapedgeremove.get(extNode));
793 edges.addAll(delta.heapedgeadd.get(extNode));
796 if (nodeset.contains(e.dst))
797 externaledgeset.add(e);
802 HashSet<TempDescriptor> temps=new HashSet<TempDescriptor>();
803 temps.addAll(delta.basevaredge.keySet());
804 temps.addAll(delta.varedgeadd.keySet());
805 temps.addAll(delta.varedgeremove.keySet());
806 //remove allinternal nodes
807 temps.removeAll(nodeset);
809 for(TempDescriptor tmp:temps) {
810 //Compute set of edges from given node
811 MySet<Edge> edges=new MySet<Edge>(delta.basevaredge.get(tmp));
813 edges.removeAll(delta.varedgeremove.get(tmp));
814 edges.addAll(delta.varedgeadd.get(tmp));
817 if (nodeset.contains(e.dst))
818 externaledgeset.add(e);
823 /* This function removes the caller reachable edges from the
826 void removeEdges(Graph graph, Delta delta, HashSet<AllocNode> nodeset, MySet<Edge> edgeset, MySet<Edge> externaledgeset) {
827 //Want to remove the set of internal edges
828 for(Edge e:edgeset) {
829 if (e.src!=null&&!graph.callerEdges.contains(e)) {
830 delta.removeHeapEdge(e);
834 //Want to remove the set of external edges
835 for(Edge e:externaledgeset) {
836 //want to remove the set of internal edges
837 if (!graph.callerEdges.contains(e))
842 Delta processFlatCall(BBlock callblock, int callindex, FlatCall fcall, Delta delta, Graph graph) {
843 Delta newDelta=new Delta(null, false);
845 if (delta.getInit()) {
846 MySet<Edge> edgeset=new MySet<Edge>();
847 MySet<Edge> externaledgeset=new MySet<Edge>();
848 HashSet<AllocNode> nodeset=new HashSet<AllocNode>();
849 HashSet<ClassDescriptor> targetSet=new HashSet<ClassDescriptor>();
850 Stack<AllocNode> tovisit=new Stack<AllocNode>();
851 TempDescriptor tmpthis=fcall.getThis();
852 graph.callerEdges=new MySet<Edge>();
854 //Handle the this temp
855 processThisTargets(targetSet, graph, delta, newDelta, nodeset, tovisit, edgeset, tmpthis, null);
857 //Go through each temp
858 processParams(graph, delta, newDelta, nodeset, tovisit, edgeset, fcall, false);
860 //Traverse all reachable nodes
861 computeReachableNodes(graph, delta, newDelta, nodeset, tovisit, edgeset, null);
863 //Compute call targets
864 HashSet<MethodDescriptor> newtargets=computeTargets(fcall, newDelta);
867 fixMapping(fcall, newtargets, null, newDelta, callblock, callindex);
869 //Compute edges into region to splice out
870 computeExternalEdges(graph, delta, nodeset, null, externaledgeset);
872 //Splice out internal edges
873 removeEdges(graph, delta, nodeset, edgeset, externaledgeset);
875 //store data structures
876 graph.externalEdgeSet=externaledgeset;
877 graph.reachNode=nodeset;
878 graph.reachEdge=edgeset;
880 graph.callTargets=newtargets;
881 graph.callNodeAges=new HashSet<AllocNode>();
882 graph.callOldNodes=new HashSet<AllocNode>();
883 graph.callNewEdges=new HashMap<AllocNode, MySet<Edge>>();
884 graph.callOldEdges=new HashMap<Edge,MySet<Edge>>();
886 //Apply diffs to graph
887 applyDiffs(graph, delta, true);
889 MySet<Edge> edgeset=new MySet<Edge>();
890 MySet<Edge> externaledgeset=new MySet<Edge>();
891 HashSet<AllocNode> nodeset=new HashSet<AllocNode>();
892 MySet<Edge> oldedgeset=graph.reachEdge;
893 HashSet<AllocNode> oldnodeset=graph.reachNode;
895 HashSet<ClassDescriptor> targetSet=new HashSet<ClassDescriptor>();
896 Stack<AllocNode> tovisit=new Stack<AllocNode>();
897 TempDescriptor tmpthis=fcall.getThis();
898 //Fix up delta to get rid of unnecessary heap edge removals
899 for(Map.Entry<AllocNode, MySet<Edge>> entry:delta.heapedgeremove.entrySet()) {
900 for(Iterator<Edge> eit=entry.getValue().iterator();eit.hasNext();) {
902 if (graph.callerEdges.contains(e))
907 //Fix up delta to get rid of unnecessary var edge removals
908 for(Map.Entry<TempDescriptor, MySet<Edge>> entry:delta.varedgeremove.entrySet()) {
909 for(Iterator<Edge> eit=entry.getValue().iterator();eit.hasNext();) {
911 if (graph.callerEdges.contains(e))
916 //Handle the this temp
917 processThisTargets(targetSet, graph, delta, newDelta, nodeset, tovisit, edgeset, tmpthis, oldnodeset);
919 //Go through each temp
920 processParams(graph, delta, newDelta, nodeset, tovisit, edgeset, fcall, true);
921 //Go through each new heap edge that starts from old node
922 MySet<Edge> newedges=GraphManip.getDiffEdges(delta, oldnodeset);
923 edgeset.addAll(newedges);
924 for(Edge e:newedges) {
925 //Add new edges that start from old node to newDelta
927 if (!newDelta.heapedgeadd.containsKey(src)) {
928 newDelta.heapedgeadd.put(src, new MySet<Edge>());
930 newDelta.heapedgeadd.get(src).add(e.makeOld());
931 if (!nodeset.contains(e.dst)&&!oldnodeset.contains(e.dst)) {
937 //Traverse all reachable nodes
938 computeReachableNodes(graph, delta, newDelta, nodeset, tovisit, edgeset, oldnodeset);
939 //Compute call targets
940 HashSet<MethodDescriptor> newtargets=computeTargets(fcall, newDelta);
941 graph.callTargets.addAll(newtargets);
943 //add in new nodeset and edgeset
944 oldnodeset.addAll(nodeset);
945 oldedgeset.addAll(edgeset);
947 fixMapping(fcall, graph.callTargets, oldedgeset, newDelta, callblock, callindex);
948 //Compute edges into region to splice out
949 computeExternalEdges(graph, delta, oldnodeset, nodeset, externaledgeset);
951 //Splice out internal edges
952 removeEdges(graph, delta, nodeset, edgeset, externaledgeset);
954 //Add external edges back in
955 processCallExternal(graph, delta, externaledgeset);
957 //Move new edges that should be summarized
958 processSummarization(graph, delta);
960 Set<FlatSESEEnterNode> seseCallers=OoOJava?taskAnalysis.getTransitiveExecutingRBlocks(fcall):null;
961 //Check if the new nodes allow us to insert a new edge
962 for(AllocNode node:nodeset) {
963 if (graph.callNewEdges.containsKey(node)) {
964 for(Iterator<Edge> eit=graph.callNewEdges.get(node).iterator();eit.hasNext();) {
966 if ((graph.callNodeAges.contains(e.src)||graph.reachNode.contains(e.src))&&
967 (graph.callNodeAges.contains(e.dst)||graph.reachNode.contains(e.dst))) {
968 Edge edgetoadd=e.copy();//we need our own copy to modify below
970 if (seseCallers!=null)
971 edgetoadd.taintModify(seseCallers);
972 mergeCallEdge(graph, delta, edgetoadd);
978 for(Edge e:edgeset) {
979 //See if these edges would allow an old edge to be added
980 if (graph.callOldEdges.containsKey(e)) {
981 for(Edge adde:graph.callOldEdges.get(e)) {
982 Edge ecopy=adde.copy();
983 ecopy.statuspredicate=e.statuspredicate;
984 mergeCallEdge(graph, delta, ecopy);
989 //Add in new external edges
990 graph.externalEdgeSet.addAll(externaledgeset);
991 //Apply diffs to graph
992 applyDiffs(graph, delta);
997 void processSummarization(Graph graph, Delta delta) {
998 processSumHeapEdgeSet(delta.heapedgeadd, delta, graph);
999 processSumHeapEdgeSet(delta.baseheapedge, delta, graph);
1000 processSumVarEdgeSet(delta.varedgeadd, delta, graph);
1001 processSumVarEdgeSet(delta.basevaredge, delta, graph);
1004 void processSumVarEdgeSet(HashMap<TempDescriptor, MySet<Edge>> map, Delta delta, Graph graph) {
1005 MySet<Edge> edgestoadd=new MySet<Edge>();
1006 MySet<Edge> edgestoremove=new MySet<Edge>();
1007 for(Iterator<Map.Entry<TempDescriptor, MySet<Edge>>> eit=map.entrySet().iterator();eit.hasNext();) {
1008 Map.Entry<TempDescriptor, MySet<Edge>> entry=eit.next();
1009 MySet<Edge> edgeset=entry.getValue();
1011 for(Edge e:edgeset) {
1013 boolean rewrite=false;
1014 if (copy.dst!=null&&graph.callNodeAges.contains(copy.dst)) {
1015 copy.dst=allocFactory.getAllocNode(copy.dst, true);
1019 edgestoremove.add(e);
1020 edgestoadd.add(copy);
1024 for(Edge e:edgestoremove) {
1025 if (!graph.callerEdges.contains(e))
1026 delta.removeVarEdge(e);
1028 for(Edge e:edgestoadd) {
1029 delta.addVarEdge(e);
1033 public Alloc getAllocationSiteFromFlatNew(FlatNew node) {
1034 return allocFactory.getAllocNode(node, false).getAllocSite();
1037 void processSumHeapEdgeSet(HashMap<AllocNode, MySet<Edge>> map, Delta delta, Graph graph) {
1038 MySet<Edge> edgestoadd=new MySet<Edge>();
1039 MySet<Edge> edgestoremove=new MySet<Edge>();
1040 for(Iterator<Map.Entry<AllocNode, MySet<Edge>>> eit=map.entrySet().iterator();eit.hasNext();) {
1041 Map.Entry<AllocNode, MySet<Edge>> entry=eit.next();
1042 AllocNode node=entry.getKey();
1043 MySet<Edge> edgeset=entry.getValue();
1045 for(Edge e:edgeset) {
1047 boolean rewrite=false;
1048 if (copy.src!=null&&graph.callNodeAges.contains(copy.src)) {
1049 copy.src=allocFactory.getAllocNode(copy.src, true);
1052 if (copy.dst!=null&&graph.callNodeAges.contains(copy.dst)) {
1053 copy.dst=allocFactory.getAllocNode(copy.dst, true);
1057 edgestoremove.add(e);
1058 edgestoadd.add(copy);
1062 for(Edge e:edgestoremove) {
1063 if (!graph.callerEdges.contains(e))
1064 delta.removeHeapEdge(e);
1066 for(Edge e:edgestoadd) {
1067 delta.addHeapEdge(e);
1071 //Handle external edges
1072 void processCallExternal(Graph graph, Delta newDelta, MySet<Edge> externalEdgeSet) {
1073 //Add external edges in
1074 for(Edge e:externalEdgeSet) {
1075 //First did we age the source
1076 Edge newedge=e.copy();
1077 if (newedge.src!=null&&!e.src.isSummary()&&graph.callNodeAges.contains(e.src)) {
1078 AllocNode summaryNode=allocFactory.getAllocNode(newedge.src, true);
1079 newedge.src=summaryNode;
1082 if (graph.callNodeAges.contains(e.dst)&&!e.dst.isSummary()) {
1083 if (graph.callOldNodes.contains(e.dst)) {
1085 Edge copy=newedge.copy();
1086 mergeEdge(graph, newDelta, copy);
1088 //Now add summarized node
1089 newedge.dst=allocFactory.getAllocNode(newedge.dst, true);
1090 mergeCallEdge(graph, newDelta, newedge);
1092 //Add edge to single node
1093 mergeEdge(graph, newDelta, newedge);
1098 /* This function applies callee deltas to the caller heap. */
1100 Delta applyCallDelta(Delta delta, BBlock bblock) {
1101 Delta newDelta=new Delta(null, false);
1102 Vector<FlatNode> nodes=bblock.nodes();
1103 PPoint ppoint=delta.getBlock();
1104 FlatCall fcall=(FlatCall)nodes.get(ppoint.getIndex());
1105 Graph graph=graphMap.get(fcall);
1106 Graph oldgraph=(ppoint.getIndex()==0)?
1107 bbgraphMap.get(bblock):
1108 graphMap.get(nodes.get(ppoint.getIndex()-1));
1109 Set<FlatSESEEnterNode> seseCallers=OoOJava?taskAnalysis.getTransitiveExecutingRBlocks(fcall):null;
1111 //Age outside nodes if necessary
1112 for(Iterator<AllocNode> nodeit=delta.addNodeAges.iterator();nodeit.hasNext();) {
1113 AllocNode node=nodeit.next();
1114 if (!graph.callNodeAges.contains(node)) {
1115 graph.callNodeAges.add(node);
1116 newDelta.addNodeAges.add(node);
1118 AllocNode summaryAdd=null;
1119 if (!graph.reachNode.contains(node)&&!node.isSummary()) {
1120 /* Need to age node in existing graph*/
1122 AllocNode summaryNode=allocFactory.getAllocNode(node, true);
1124 if (!graph.callNodeAges.contains(summaryNode)) {
1125 graph.callNodeAges.add(summaryNode);
1126 newDelta.addNodeAges.add(summaryNode);
1127 summaryAdd=summaryNode;
1129 summarizeInGraph(graph, newDelta, node);
1132 if (graph.callNewEdges.containsKey(node)) {
1133 for(Iterator<Edge> eit=graph.callNewEdges.get(node).iterator();eit.hasNext();) {
1135 if ((graph.callNodeAges.contains(e.src)||graph.reachNode.contains(e.src))&&
1136 (graph.callNodeAges.contains(e.dst)||graph.reachNode.contains(e.dst))) {
1137 Edge edgetoadd=e.copy();//we need our own copy to modify below
1139 if (seseCallers!=null)
1140 edgetoadd.taintModify(seseCallers);
1141 mergeCallEdge(graph, newDelta, edgetoadd);
1145 //do the summary node if we added that also...
1148 } while(node!=null);
1152 for(Map.Entry<AllocNode, MySet<Edge>> entry:delta.heapedgeadd.entrySet()) {
1153 for(Edge e:entry.getValue()) {
1154 boolean addedge=false;
1155 Edge edgetoadd=null;
1156 if (e.statuspredicate==Edge.NEW) {
1157 if ((graph.callNodeAges.contains(e.src)||graph.reachNode.contains(e.src))&&
1158 (graph.callNodeAges.contains(e.dst)||graph.reachNode.contains(e.dst))) {
1159 edgetoadd=e.copy();//we need our own copy to modify below
1161 graph.addCallEdge(e);
1164 Edge[] edgeArray=e.makeStatus(allocFactory);
1166 int statuspredicate=0;
1167 for(int i=0;i<edgeArray.length;i++) {
1168 Edge origEdgeKey=edgeArray[i];
1169 if (graph.reachEdge.contains(origEdgeKey)) {
1170 Edge origEdge=graph.reachEdge.get(origEdgeKey);
1171 //copy the predicate
1172 statuspredicate=statuspredicate|origEdge.statuspredicate;
1174 if (!graph.callOldEdges.containsKey(origEdgeKey)) {
1175 graph.callOldEdges.put(origEdgeKey, new MySet<Edge>());
1177 if (graph.callOldEdges.get(origEdgeKey).contains(e)) {
1178 Edge olde=graph.callOldEdges.get(origEdgeKey).get(e);
1179 graph.callOldEdges.get(origEdgeKey).add(olde.merge(e));
1181 graph.callOldEdges.get(origEdgeKey).add(e);
1184 if (statuspredicate!=0) {
1186 newe.statuspredicate=statuspredicate;
1190 if (seseCallers!=null&&edgetoadd!=null)
1191 edgetoadd.taintModify(seseCallers);
1192 mergeCallEdge(graph, newDelta, edgetoadd);
1196 processCallExternal(graph, newDelta, graph.externalEdgeSet);
1198 //Add edge for return value
1199 if (fcall.getReturnTemp()!=null) {
1200 MySet<Edge> returnedge=delta.varedgeadd.get(returntmp);
1201 if (returnedge!=null)
1202 for(Edge e:returnedge) {
1203 //skip the edge if types don't allow it...
1204 if (!typeUtil.isSuperorType(fcall.getReturnTemp().getType(), e.dst.getType()))
1206 Edge newedge=e.copy();
1207 newedge.srcvar=fcall.getReturnTemp();
1208 if (seseCallers!=null)
1209 newedge.taintModify(seseCallers);
1210 mergeEdge(graph, newDelta, newedge);
1213 applyDiffs(graph, newDelta);
1217 public void mergeEdge(Graph graph, Delta newDelta, Edge edgetoadd) {
1218 if (edgetoadd!=null) {
1219 Edge match=graph.getMatch(edgetoadd);
1221 if (match==null||!match.subsumes(edgetoadd)) {
1222 Edge mergededge=edgetoadd.merge(match);
1223 newDelta.addEdge(mergededge);
1228 /* This is a call produced edge...need to remember this */
1230 public void mergeCallEdge(Graph graph, Delta newDelta, Edge edgetoadd) {
1231 if (edgetoadd!=null) {
1232 newDelta.addEdgeClear(edgetoadd);
1234 Edge match=graph.getMatch(edgetoadd);
1236 if (match==null||!match.subsumes(edgetoadd)) {
1237 Edge mergededge=edgetoadd.merge(match);
1238 newDelta.addEdge(mergededge);
1239 graph.callerEdges.add(mergededge);
1245 /* Summarizes out of context nodes in graph */
1246 void summarizeInGraph(Graph graph, Delta newDelta, AllocNode singleNode) {
1247 AllocNode summaryNode=allocFactory.getAllocNode(singleNode, true);
1249 //Handle outgoing heap edges
1250 MySet<Edge> edgeset=graph.getEdges(singleNode);
1252 for(Edge e:edgeset) {
1253 Edge rewrite=e.rewrite(singleNode, summaryNode);
1255 newDelta.removeHeapEdge(e);
1256 mergeCallEdge(graph, newDelta, rewrite);
1259 //Handle incoming edges
1260 MySet<Edge> backedges=graph.getBackEdges(singleNode);
1261 for(Edge e:backedges) {
1262 if (e.dst==singleNode) {
1263 //Need to get original edge so that predicate will be correct
1264 Edge match=graph.getMatch(e);
1266 Edge rewrite=match.rewrite(singleNode, summaryNode);
1267 newDelta.removeEdge(match);
1268 mergeCallEdge(graph, newDelta, rewrite);
1274 void applyDiffs(Graph graph, Delta delta) {
1275 applyDiffs(graph, delta, false);
1278 void applyDiffs(Graph graph, Delta delta, boolean genbackwards) {
1279 //build backwards map if requested
1280 if (genbackwards&&graph.backMap==null) {
1281 graph.backMap=new HashMap<AllocNode, MySet<Edge>>();
1282 if (graph.parent.backMap==null) {
1283 graph.parent.backMap=new HashMap<AllocNode, MySet<Edge>>();
1284 for(Map.Entry<AllocNode, MySet<Edge>> entry:graph.nodeMap.entrySet()) {
1285 for(Edge e:entry.getValue()) {
1286 if (!graph.parent.backMap.containsKey(e.dst))
1287 graph.parent.backMap.put(e.dst, new MySet<Edge>());
1288 graph.parent.backMap.get(e.dst).add(e);
1291 for(Map.Entry<TempDescriptor, MySet<Edge>> entry:graph.varMap.entrySet()) {
1292 for(Edge e:entry.getValue()) {
1293 if (!graph.parent.backMap.containsKey(e.dst))
1294 graph.parent.backMap.put(e.dst, new MySet<Edge>());
1295 graph.parent.backMap.get(e.dst).add(e);
1301 //Add hidden base edges
1302 for(Map.Entry<AllocNode, MySet<Edge>> e: delta.baseheapedge.entrySet()) {
1303 AllocNode node=e.getKey();
1304 MySet<Edge> edges=e.getValue();
1305 if (graph.nodeMap.containsKey(node)) {
1306 MySet<Edge> nodeEdges=graph.nodeMap.get(node);
1307 nodeEdges.addAll(edges);
1312 for(Map.Entry<AllocNode, MySet<Edge>> e: delta.heapedgeremove.entrySet()) {
1313 AllocNode node=e.getKey();
1314 MySet<Edge> edgestoremove=e.getValue();
1315 if (graph.nodeMap.containsKey(node)) {
1316 //Just apply diff to current map
1317 graph.nodeMap.get(node).removeAll(edgestoremove);
1319 //Generate diff from parent graph
1320 MySet<Edge> parentedges=graph.parent.nodeMap.get(node);
1321 if (parentedges!=null) {
1322 MySet<Edge> newedgeset=Util.setSubtract(parentedges, edgestoremove);
1323 graph.nodeMap.put(node, newedgeset);
1329 for(Map.Entry<AllocNode, MySet<Edge>> e: delta.heapedgeadd.entrySet()) {
1330 AllocNode node=e.getKey();
1331 MySet<Edge> edgestoadd=e.getValue();
1332 //If we have not done a subtract, then
1333 if (!graph.nodeMap.containsKey(node)) {
1334 //Copy the parent entry
1335 if (graph.parent.nodeMap.containsKey(node))
1336 graph.nodeMap.put(node, (MySet<Edge>)graph.parent.nodeMap.get(node).clone());
1338 graph.nodeMap.put(node, new MySet<Edge>());
1340 Edge.mergeEdgesInto(graph.nodeMap.get(node),edgestoadd);
1342 for(Edge eadd:edgestoadd) {
1343 if (!graph.backMap.containsKey(eadd.dst))
1344 graph.backMap.put(eadd.dst, new MySet<Edge>());
1345 graph.backMap.get(eadd.dst).add(eadd);
1351 for(Map.Entry<TempDescriptor, MySet<Edge>> e: delta.varedgeremove.entrySet()) {
1352 TempDescriptor tmp=e.getKey();
1353 MySet<Edge> edgestoremove=e.getValue();
1355 if (graph.varMap.containsKey(tmp)) {
1356 //Just apply diff to current map
1357 graph.varMap.get(tmp).removeAll(edgestoremove);
1358 } else if (graph.parent.varMap.containsKey(tmp)) {
1359 //Generate diff from parent graph
1360 MySet<Edge> parentedges=graph.parent.varMap.get(tmp);
1361 MySet<Edge> newedgeset=Util.setSubtract(parentedges, edgestoremove);
1362 graph.varMap.put(tmp, newedgeset);
1367 for(Map.Entry<TempDescriptor, MySet<Edge>> e: delta.varedgeadd.entrySet()) {
1368 TempDescriptor tmp=e.getKey();
1369 MySet<Edge> edgestoadd=e.getValue();
1370 if (graph.varMap.containsKey(tmp)) {
1371 Edge.mergeEdgesInto(graph.varMap.get(tmp), edgestoadd);
1372 } else if (graph.parent.varMap.containsKey(tmp)) {
1373 graph.varMap.put(tmp, new MySet<Edge>(graph.parent.varMap.get(tmp)));
1374 Edge.mergeEdgesInto(graph.varMap.get(tmp), edgestoadd);
1376 graph.varMap.put(tmp, (MySet<Edge>) edgestoadd.clone());
1378 for(Edge eadd:edgestoadd) {
1379 if (!graph.backMap.containsKey(eadd.dst))
1380 graph.backMap.put(eadd.dst, new MySet<Edge>());
1381 graph.backMap.get(eadd.dst).add(eadd);
1386 //Add node additions
1387 for(AllocNode node:delta.addNodeAges) {
1388 graph.nodeAges.add(node);
1391 for(Map.Entry<AllocNode, Boolean> nodeentry:delta.addOldNodes.entrySet()) {
1392 AllocNode node=nodeentry.getKey();
1393 Boolean ispresent=nodeentry.getValue();
1394 graph.oldNodes.put(node, ispresent);
1398 boolean isINACC(FlatNode node) {
1401 switch(node.kind()) {
1402 case FKind.FlatSetFieldNode: {
1403 FlatSetFieldNode n=(FlatSetFieldNode)node;
1404 return !accessible.isAccessible(n, n.getDst());
1406 case FKind.FlatSetElementNode: {
1407 FlatSetElementNode n=(FlatSetElementNode)node;
1408 return !accessible.isAccessible(n, n.getDst());
1410 case FKind.FlatFieldNode: {
1411 FlatFieldNode n=(FlatFieldNode)node;
1412 return !accessible.isAccessible(n, n.getSrc());
1414 case FKind.FlatElementNode: {
1415 FlatElementNode n=(FlatElementNode)node;
1416 return !accessible.isAccessible(n, n.getSrc());
1422 Delta processSetFieldElementNode(FlatNode node, Delta delta, Graph graph) {
1426 if (node.kind()==FKind.FlatSetElementNode) {
1427 FlatSetElementNode fen=(FlatSetElementNode) node;
1432 FlatSetFieldNode ffn=(FlatSetFieldNode) node;
1438 if (delta.getInit()) {
1439 MySet<Edge> dstEdges=GraphManip.getEdges(graph, delta, dst);
1441 if (OoOJava&&!accessible.isAccessible(node, dst)) {
1442 Taint dstStallTaint=Taint.factory(node, dst, AllocFactory.dummySite, null, ReachGraph.predsEmpty);
1443 dstEdges=Edge.taintAll(dstEdges, dstStallTaint);
1444 updateVarDelta(graph, delta, dst, dstEdges, null);
1447 effectsAnalysis.analyzeFlatSetFieldNode(dstEdges, fd, node);
1450 //Do nothing for non pointers
1451 if (!src.getType().isPtr()) {
1452 if (mustProcess.contains(node)) {
1453 applyDiffs(graph, delta);
1458 MySet<Edge> srcEdges=GraphManip.getEdges(graph, delta, src);
1459 if (OoOJava&&!accessible.isAccessible(node, src)) {
1460 Taint srcStallTaint=Taint.factory(node, src, AllocFactory.dummySite, null, ReachGraph.predsEmpty);
1461 srcEdges=Edge.taintAll(srcEdges, srcStallTaint);
1462 updateVarDelta(graph, delta, src, srcEdges, null);
1465 MySet<Edge> edgesToAdd=GraphManip.genEdges(dstEdges, fd, srcEdges);
1466 MySet<Edge> edgesToRemove=null;
1467 if (dstEdges.size()==1&&!dstEdges.iterator().next().dst.isSummary()&&fd!=null) {
1468 /* Can do a strong update */
1469 edgesToRemove=GraphManip.getEdges(graph, delta, dstEdges, fd);
1470 graph.strongUpdateSet=edgesToRemove;
1472 graph.strongUpdateSet=new MySet<Edge>();
1475 updateHeapDelta(graph, delta, edgesToAdd, edgesToRemove);
1476 applyDiffs(graph, delta);
1478 MySet<Edge> newDstEdges=GraphManip.getDiffEdges(delta, dst);
1480 if (OoOJava&&!accessible.isAccessible(node, dst)) {
1481 Taint dstStallTaint=Taint.factory(node, dst, AllocFactory.dummySite, null, ReachGraph.predsEmpty);
1482 newDstEdges=Edge.taintAll(newDstEdges, dstStallTaint);
1483 updateVarDelta(graph, delta, dst, newDstEdges, null);
1487 effectsAnalysis.analyzeFlatSetFieldNode(newDstEdges, fd, node);
1490 if (!src.getType().isPtr()) {
1491 if (mustProcess.contains(node)) {
1492 applyDiffs(graph, delta);
1497 /* Next look at new sources */
1499 MySet<Edge> edgesToAdd=new MySet<Edge>();
1500 MySet<Edge> newSrcEdges=GraphManip.getDiffEdges(delta, src);
1501 MySet<Edge> srcEdges=GraphManip.getEdges(graph, delta, src);
1502 HashSet<AllocNode> dstNodes=GraphManip.getNodes(graph, delta, dst);
1504 if (OoOJava&&!accessible.isAccessible(node, src)) {
1505 Taint srcStallTaint=Taint.factory(node, src, AllocFactory.dummySite, null, ReachGraph.predsEmpty);
1506 newSrcEdges=Edge.taintAll(newSrcEdges, srcStallTaint);
1507 updateVarDelta(graph, delta, src, newSrcEdges, null);
1510 MySet<Edge> edgesToRemove=null;
1511 if (newDstEdges.size()!=0) {
1512 if (dstNodes.size()>1&&!dstNodes.iterator().next().isSummary()&&fd!=null) {
1513 /* Need to undo strong update */
1514 if (graph.strongUpdateSet!=null) {
1515 edgesToAdd.addAll(graph.strongUpdateSet);
1516 graph.strongUpdateSet=null; //Prevent future strong updates
1518 } else if (dstNodes.size()==1&&newDstEdges.size()==1&&!newDstEdges.iterator().next().dst.isSummary()&&graph.strongUpdateSet!=null&&fd!=null) {
1519 edgesToRemove=GraphManip.getEdges(graph, delta, dstNodes, fd);
1520 graph.strongUpdateSet.addAll(edgesToRemove);
1522 Edge.mergeEdgesInto(edgesToAdd, GraphManip.genEdges(newDstEdges, fd, srcEdges));
1526 if (graph.strongUpdateSet!=null&&fd!=null) {
1527 MySet<Edge> otherEdgesToRemove=GraphManip.getDiffEdges(delta, dstNodes, fd);
1528 if (edgesToRemove!=null)
1529 edgesToRemove.addAll(otherEdgesToRemove);
1531 edgesToRemove=otherEdgesToRemove;
1532 graph.strongUpdateSet.addAll(otherEdgesToRemove);
1535 //Next look at new destinations
1536 Edge.mergeEdgesInto(edgesToAdd, GraphManip.genEdges(dstNodes, fd, newSrcEdges));
1539 updateHeapDelta(graph, delta, edgesToAdd, edgesToRemove);
1540 applyDiffs(graph, delta);
1545 Delta processCopyNode(FlatNode node, Delta delta, Graph graph) {
1549 if (node.kind()==FKind.FlatOpNode) {
1550 FlatOpNode fon=(FlatOpNode) node;
1553 } else if (node.kind()==FKind.FlatReturnNode) {
1554 FlatReturnNode frn=(FlatReturnNode)node;
1555 src=frn.getReturnTemp();
1557 if (src==null||!src.getType().isPtr()) {
1559 applyDiffs(graph, delta);
1563 FlatCastNode fcn=(FlatCastNode) node;
1567 if (delta.getInit()) {
1568 MySet<Edge> srcedges=GraphManip.getEdges(graph, delta, src);
1569 MySet<Edge> edgesToAdd=GraphManip.genEdges(dst, srcedges);
1570 MySet<Edge> edgesToRemove=GraphManip.getEdges(graph, delta, dst);
1571 updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
1572 applyDiffs(graph, delta);
1574 /* First compute new src nodes */
1575 MySet<Edge> newSrcEdges=GraphManip.getDiffEdges(delta, src);
1577 /* Compute the union, and then the set of edges */
1578 MySet<Edge> edgesToAdd=GraphManip.genEdges(dst, newSrcEdges);
1580 /* Compute set of edges to remove */
1581 MySet<Edge> edgesToRemove=GraphManip.getDiffEdges(delta, dst);
1584 updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
1585 applyDiffs(graph, delta);
1590 Delta processFieldElementNode(FlatNode node, Delta delta, Graph graph) {
1594 TaintSet taint=null;
1596 if (node.kind()==FKind.FlatElementNode) {
1597 FlatElementNode fen=(FlatElementNode) node;
1602 FlatFieldNode ffn=(FlatFieldNode) node;
1607 if (OoOJava&&!accessible.isAccessible(node, src)) {
1608 taint=TaintSet.factory(Taint.factory(node, src, AllocFactory.dummySite, null, ReachGraph.predsEmpty));
1611 //Do nothing for non pointers
1612 if (delta.getInit()) {
1613 MySet<Edge> srcedges=GraphManip.getEdges(graph, delta, src);
1616 srcedges=Edge.taintAll(srcedges, taint);
1617 updateVarDelta(graph, delta, src, srcedges, null);
1619 effectsAnalysis.analyzeFlatFieldNode(srcedges, fd, node);
1621 if (!dst.getType().isPtr()) {
1622 if (mustProcess.contains(node)) {
1623 applyDiffs(graph, delta);
1628 MySet<Edge> edgesToAdd=GraphManip.dereference(graph, delta, dst, srcedges, fd, node);
1629 MySet<Edge> edgesToRemove=GraphManip.getEdges(graph, delta, dst);
1631 updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
1632 applyDiffs(graph, delta);
1634 MySet<Edge> newsrcedges=GraphManip.getDiffEdges(delta, src);
1637 newsrcedges=Edge.taintAll(newsrcedges, taint);
1638 updateVarDelta(graph, delta, src, newsrcedges, null);
1640 effectsAnalysis.analyzeFlatFieldNode(newsrcedges, fd, node);
1642 if (!dst.getType().isPtr()) {
1643 if (mustProcess.contains(node)) {
1644 applyDiffs(graph, delta);
1648 /* First compute new objects we read fields of */
1649 MySet<Edge> allsrcedges=GraphManip.getEdges(graph, delta, src);
1650 MySet<Edge> edgesToAdd=GraphManip.diffDereference(delta, dst, allsrcedges, fd, node);
1651 /* Next compute new targets of fields */
1652 MySet<Edge> newfdedges=GraphManip.dereference(graph, delta, dst, newsrcedges, fd, node);
1654 /* Compute the union, and then the set of edges */
1655 Edge.mergeEdgesInto(edgesToAdd, newfdedges);
1657 /* Compute set of edges to remove */
1658 MySet<Edge> edgesToRemove=GraphManip.getDiffEdges(delta, dst);
1662 updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
1663 applyDiffs(graph, delta);
1669 void updateVarDelta(Graph graph, Delta delta, TempDescriptor tmp, MySet<Edge> edgestoAdd, MySet<Edge> edgestoRemove) {
1670 MySet<Edge> edgeAdd=delta.varedgeadd.get(tmp);
1671 MySet<Edge> edgeRemove=delta.varedgeremove.get(tmp);
1672 MySet<Edge> existingEdges=graph.getEdges(tmp);
1673 if (edgestoRemove!=null)
1674 for(Edge e: edgestoRemove) {
1675 //remove edge from delta
1678 //if the edge is already in the graph, add an explicit remove to the delta
1679 if (existingEdges.contains(e))
1680 delta.removeVarEdge(e);
1682 for(Edge e: edgestoAdd) {
1683 //Remove the edge from the remove set
1684 if (edgeRemove!=null)
1685 edgeRemove.remove(e);
1686 //Explicitly add it to the add set unless it is already in the graph
1687 if (typeUtil.isSuperorType(tmp.getType(), e.dst.getType())) {
1688 if (!existingEdges.contains(e)) {
1689 delta.addVarEdge(e);
1691 //See if the old edge subsumes the new one
1692 Edge olde=existingEdges.get(e);
1693 if (!olde.subsumes(e)) {
1694 delta.addVarEdge(olde.merge(e));
1701 void updateHeapDelta(Graph graph, Delta delta, MySet<Edge> edgestoAdd, MySet<Edge> edgestoRemove) {
1702 if (edgestoRemove!=null)
1703 for(Edge e: edgestoRemove) {
1704 AllocNode src=e.src;
1705 MySet<Edge> edgeAdd=delta.heapedgeadd.get(src);
1706 MySet<Edge> existingEdges=graph.getEdges(src);
1707 //remove edge from delta
1710 //if the edge is already in the graph, add an explicit remove to the delta
1711 if (existingEdges.contains(e)) {
1712 delta.removeHeapEdge(e);
1715 if (edgestoAdd!=null)
1716 for(Edge e: edgestoAdd) {
1717 AllocNode src=e.src;
1718 MySet<Edge> edgeRemove=delta.heapedgeremove.get(src);
1719 MySet<Edge> existingEdges=graph.getEdges(src);
1720 //Remove the edge from the remove set
1721 if (edgeRemove!=null)
1722 edgeRemove.remove(e);
1723 //Explicitly add it to the add set unless it is already in the graph
1724 if (!existingEdges.contains(e)) {
1725 delta.addHeapEdge(e);
1727 //See if the old edge subsumes the new one
1728 Edge olde=existingEdges.get(e);
1729 if (!olde.subsumes(e)) {
1730 delta.addHeapEdge(olde.merge(e));
1736 Delta processFlatNop(FlatNode node, Delta delta, Graph graph) {
1737 applyDiffs(graph, delta);
1741 Delta processNewNode(FlatNew node, Delta delta, Graph graph) {
1742 AllocNode summary=allocFactory.getAllocNode(node, true);
1743 AllocNode single=allocFactory.getAllocNode(node, false);
1744 TempDescriptor tmp=node.getDst();
1746 if (delta.getInit()) {
1747 /* We don't have to deal with summarization here... The
1748 * intuition is that this is the only place where we generate
1749 * nodes for this allocation site and this is the first time
1750 * we've analyzed this site */
1753 Edge e=new Edge(tmp, single);
1754 //Build new Edge set
1755 MySet<Edge> newedges=new MySet<Edge>();
1757 //Add it into the diffs
1758 delta.varedgeadd.put(tmp, newedges);
1759 //Remove the old edges
1760 MySet<Edge> oldedges=graph.getEdges(tmp);
1761 if (!oldedges.isEmpty())
1762 delta.varedgeremove.put(tmp, (MySet<Edge>) oldedges);
1763 //Note that we create a single node
1764 delta.addNodeAges.add(single);
1766 if (delta.addOldNodes.containsKey(single)||delta.baseOldNodes.containsKey(single)) {
1767 delta.addOldNodes.put(single, Boolean.FALSE);
1770 /* 1. Fix up the variable edge additions */
1771 for(Iterator<Map.Entry<TempDescriptor, MySet<Edge>>> entryIt=delta.varedgeadd.entrySet().iterator();entryIt.hasNext();) {
1772 Map.Entry<TempDescriptor, MySet<Edge>> entry=entryIt.next();
1774 if (entry.getKey()==tmp) {
1775 /* Check if this is the tmp we overwrite */
1778 /* Otherwise, check if the target of the edge is changed... */
1779 summarizeSet(entry.getValue(), graph.varMap.get(entry.getKey()), single, summary);
1783 /* 2. Fix up the base variable edges */
1785 for(Iterator<Map.Entry<TempDescriptor, MySet<Edge>>> entryIt=delta.basevaredge.entrySet().iterator();entryIt.hasNext();) {
1786 Map.Entry<TempDescriptor, MySet<Edge>> entry=entryIt.next();
1787 TempDescriptor entrytmp=entry.getKey();
1788 if (entrytmp==tmp) {
1789 /* Check is this is the tmp we overwrite, if so add to remove set */
1790 Util.relationUpdate(delta.varedgeremove, tmp, null, entry.getValue());
1791 } else if (graph.varMap.containsKey(entrytmp)) {
1792 /* Check if the target of the edge is changed */
1793 MySet<Edge> newset=(MySet<Edge>)entry.getValue().clone();
1794 MySet<Edge> removeset=shrinkSet(newset, graph.varMap.get(entrytmp), single, summary);
1795 Util.relationUpdate(delta.varedgeremove, entrytmp, newset, removeset);
1796 Util.relationUpdate(delta.varedgeadd, entrytmp, null, newset);
1798 /* Check if the target of the edge is changed */
1799 MySet<Edge> newset=(MySet<Edge>)entry.getValue().clone();
1800 MySet<Edge> removeset=shrinkSet(newset, graph.parent.varMap.get(entrytmp), single, summary);
1801 Util.relationUpdate(delta.varedgeremove, entrytmp, newset, removeset);
1802 Util.relationUpdate(delta.varedgeadd, entrytmp, null, newset);
1807 /* 3. Fix up heap edge additions */
1809 HashMap<AllocNode, MySet<Edge>> addheapedge=new HashMap<AllocNode, MySet<Edge>>();
1810 for(Iterator<Map.Entry<AllocNode, MySet<Edge>>> entryIt=delta.heapedgeadd.entrySet().iterator();entryIt.hasNext();) {
1811 Map.Entry<AllocNode, MySet<Edge>> entry=entryIt.next();
1812 MySet<Edge> edgeset=entry.getValue();
1813 AllocNode allocnode=entry.getKey();
1814 if (allocnode==single) {
1816 summarizeSet(edgeset, graph.nodeMap.get(summary), single, summary);
1817 addheapedge.put(summary, edgeset);
1819 summarizeSet(edgeset, graph.nodeMap.get(allocnode), single, summary);
1823 /* Merge in diffs */
1825 for(Map.Entry<AllocNode, MySet<Edge>> entry:addheapedge.entrySet()) {
1826 AllocNode allocnode=entry.getKey();
1827 Util.relationUpdate(delta.heapedgeadd, allocnode, null, entry.getValue());
1830 /* 4. Fix up the base heap edges */
1832 for(Iterator<Map.Entry<AllocNode, MySet<Edge>>> entryIt=delta.baseheapedge.entrySet().iterator();entryIt.hasNext();) {
1833 Map.Entry<AllocNode, MySet<Edge>> entry=entryIt.next();
1834 MySet<Edge> edgeset=entry.getValue();
1835 AllocNode allocnode=entry.getKey();
1836 if (allocnode==single) {
1839 AllocNode addnode=(allocnode==single)?summary:allocnode;
1841 MySet<Edge> newset=(MySet<Edge>) edgeset.clone();
1842 MySet<Edge> removeset=shrinkSet(newset, graph.nodeMap.get(addnode), single, summary);
1843 Util.relationUpdate(delta.heapedgeadd, addnode, null, newset);
1844 Util.relationUpdate(delta.heapedgeremove, allocnode, null, removeset);
1847 /* Update Node Ages...If the base or addNodeAges set contains a
1848 * single node, it now should also contain a summary node... No
1849 * need to generate a single node as that has already been
1851 if (delta.baseNodeAges.contains(single)||delta.addNodeAges.contains(single)) {
1852 delta.addNodeAges.add(summary);
1855 //Kill the old node if someone tries to add it
1856 if (delta.addOldNodes.containsKey(single)||delta.baseOldNodes.containsKey(single)) {
1857 delta.addOldNodes.put(single, Boolean.FALSE);
1861 //Apply incoming diffs to graph
1862 applyDiffs(graph, delta);
1867 /* This function builds a new edge set where oldnode is summarized into new node */
1869 void summarizeSet(MySet<Edge> edgeset, MySet<Edge> oldedgeset, AllocNode oldnode, AllocNode sumnode) {
1870 MySet<Edge> newSet=null;
1871 for(Iterator<Edge> edgeit=edgeset.iterator();edgeit.hasNext();) {
1872 Edge e=edgeit.next();
1873 if (e.dst==oldnode||e.src==oldnode) {
1875 newSet=new MySet<Edge>();
1880 if (e.dst==oldnode) {
1883 if (e.src==oldnode) {
1886 if (oldedgeset==null||!oldedgeset.contains(e))
1891 edgeset.addAll(newSet);
1894 /* Shrinks the incoming set to just include rewritten values.
1895 * Returns a set of the original rewritten values */
1897 MySet<Edge> shrinkSet(MySet<Edge> edgeset, MySet<Edge> oldedgeset, AllocNode oldnode, AllocNode newnode) {
1898 MySet<Edge> newSet=null;
1899 MySet<Edge> removeSet=null;
1900 for(Iterator<Edge> edgeit=edgeset.iterator();edgeit.hasNext();) {
1901 Edge e=edgeit.next();
1903 if (e.dst==oldnode||e.src==oldnode) {
1905 newSet=new MySet<Edge>();
1906 removeSet=new MySet<Edge>();
1915 if (oldedgeset==null||!oldedgeset.contains(e))
1920 edgeset.addAll(newSet);
1924 /* This function returns a completely new Delta... It is safe to
1927 Delta applyInitDelta(Delta delta, BBlock block) {
1928 //Apply delta to graph
1929 boolean newGraph=false;
1930 if (!bbgraphMap.containsKey(block)) {
1931 bbgraphMap.put(block, new Graph(null));
1934 Graph graph=bbgraphMap.get(block);
1937 Delta newdelta=new Delta(null, true);
1938 //Add in heap edges and throw away original diff
1940 for(Map.Entry<AllocNode, MySet<Edge>> entry:delta.heapedgeadd.entrySet()) {
1941 graph.nodeMap.put(entry.getKey(), new MySet<Edge>(entry.getValue()));
1943 //Add in var edges and throw away original diff
1944 Set<TempDescriptor> livetemps=bblivetemps.get(block);
1946 for(Map.Entry<TempDescriptor, MySet<Edge>> entry:delta.varedgeadd.entrySet()) {
1947 if (livetemps.contains(entry.getKey()))
1948 graph.varMap.put(entry.getKey(), new MySet<Edge>(entry.getValue()));
1950 //Record that this is initial set...
1951 graph.nodeAges.addAll(delta.addNodeAges);
1953 for(Map.Entry<AllocNode, Boolean> oldentry:delta.addOldNodes.entrySet()) {
1954 if (oldentry.getValue().booleanValue()) {
1955 graph.oldNodes.put(oldentry.getKey(), Boolean.TRUE);
1960 Delta newdelta=new Delta(null, false);
1961 //merge in heap edges and variables
1962 mergeHeapEdges(graph, delta, newdelta);
1963 mergeVarEdges(graph, delta, newdelta, block);
1964 mergeAges(graph, delta, newdelta);
1969 /* This function merges in the heap edges. It updates delta to be
1972 void mergeHeapEdges(Graph graph, Delta delta, Delta newdelta) {
1974 for(Map.Entry<AllocNode, MySet<Edge>> heapedge:delta.heapedgeadd.entrySet()) {
1975 AllocNode nsrc=heapedge.getKey();
1976 MySet<Edge> edges=heapedge.getValue();
1978 if (graph.backMap!=null) {
1980 if (!graph.backMap.containsKey(e.dst))
1981 graph.backMap.put(e.dst, new MySet<Edge>());
1982 graph.backMap.get(e.dst).add(e);
1986 if (!graph.nodeMap.containsKey(nsrc)) {
1987 graph.nodeMap.put(nsrc, new MySet<Edge>());
1989 MySet<Edge> dstedges=graph.nodeMap.get(nsrc);
1990 MySet<Edge> diffedges=new MySet<Edge>();
1992 if (!dstedges.contains(e)) {
1993 //We have a new edge
1997 Edge origedge=dstedges.get(e);
1998 if (!origedge.subsumes(e)) {
1999 Edge mergededge=origedge.merge(e);
2000 diffedges.add(mergededge);
2001 dstedges.add(mergededge);
2005 //Done with edge set...
2006 if (diffedges.size()>0) {
2008 newdelta.baseheapedge.put(nsrc, diffedges);
2013 /* This function merges in the var edges. It updates delta to be
2016 void mergeVarEdges(Graph graph, Delta delta, Delta newdelta, BBlock block) {
2018 Set<TempDescriptor> livetemps=bblivetemps.get(block);
2020 for(Map.Entry<TempDescriptor, MySet<Edge>> varedge:delta.varedgeadd.entrySet()) {
2021 TempDescriptor tmpsrc=varedge.getKey();
2022 if (livetemps.contains(tmpsrc)) {
2023 MySet<Edge> edges=varedge.getValue();
2024 if (graph.backMap!=null) {
2026 if (!graph.backMap.containsKey(e.dst))
2027 graph.backMap.put(e.dst, new MySet<Edge>());
2028 graph.backMap.get(e.dst).add(e);
2032 if (!graph.varMap.containsKey(tmpsrc)) {
2033 graph.varMap.put(tmpsrc, new MySet<Edge>());
2035 MySet<Edge> dstedges=graph.varMap.get(tmpsrc);
2036 MySet<Edge> diffedges=new MySet<Edge>();
2038 if (!dstedges.contains(e)) {
2039 //We have a new edge
2043 Edge origedge=dstedges.get(e);
2044 if (!origedge.subsumes(e)) {
2045 Edge mergededge=origedge.merge(e);
2046 diffedges.add(mergededge);
2047 dstedges.add(mergededge);
2051 //Done with edge set...
2052 if (diffedges.size()>0) {
2054 newdelta.basevaredge.put(tmpsrc,diffedges);
2060 void mergeAges(Graph graph, Delta delta, Delta newDelta) {
2062 for(AllocNode node:delta.addNodeAges) {
2063 if (!graph.nodeAges.contains(node)) {
2064 graph.nodeAges.add(node);
2065 newDelta.baseNodeAges.add(node);
2068 for(Map.Entry<AllocNode, Boolean> oldentry:delta.addOldNodes.entrySet()) {
2069 AllocNode node=oldentry.getKey();
2070 boolean ispresent=oldentry.getValue().booleanValue();
2071 if (ispresent&&!graph.oldNodes.containsKey(node)) {
2072 graph.oldNodes.put(node, Boolean.TRUE);
2073 newDelta.baseOldNodes.put(node, Boolean.TRUE);