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");
220 effectsAnalysis.buildStateMachines.writeStateMachines();
221 State.logEvent("Done Writing State Machines");
223 if( state.OOODEBUG ) {
224 effectsAnalysis.writeEffects("effects.txt");
225 State.logEvent("Done Writing Effects");
230 void plotGraph(Graph g, String name) {
232 PrintWriter pw=new PrintWriter(new FileWriter(name.toString().replace(' ','_')+".dot"));
233 g.printGraph(pw, name);
235 } catch (Exception ex) {
236 ex.printStackTrace();
241 /* This function builds the last delta for a basic block. It
242 * handles the case for the first time the basic block is
245 void buildInitDelta(Graph graph, Delta newDelta) {
246 //First compute the set of temps
247 HashSet<TempDescriptor> tmpSet=new HashSet<TempDescriptor>();
248 tmpSet.addAll(graph.varMap.keySet());
249 tmpSet.addAll(graph.parent.varMap.keySet());
251 //Next build the temp map part of the delta
252 for(TempDescriptor tmp : tmpSet) {
253 MySet<Edge> edgeSet=new MySet<Edge>();
255 if (graph.varMap.containsKey(tmp))
256 edgeSet.addAll(graph.varMap.get(tmp));
258 edgeSet.addAll(graph.parent.varMap.get(tmp));
259 newDelta.varedgeadd.put(tmp, edgeSet);
262 //Next compute the set of src allocnodes
263 HashSet<AllocNode> nodeSet=new HashSet<AllocNode>();
264 nodeSet.addAll(graph.nodeMap.keySet());
265 nodeSet.addAll(graph.parent.nodeMap.keySet());
267 for(AllocNode node : nodeSet) {
268 MySet<Edge> edgeSet=new MySet<Edge>();
270 if (graph.nodeMap.containsKey(node))
271 edgeSet.addAll(graph.nodeMap.get(node));
273 edgeSet.addAll(graph.parent.nodeMap.get(node));
274 newDelta.heapedgeadd.put(node, edgeSet);
277 if (graph.oldNodes.containsKey(node)) {
278 if (graph.oldNodes.get(node).booleanValue())
279 newDelta.addOldNodes.put(node, Boolean.TRUE);
280 } else if (graph.parent.oldNodes.containsKey(node)) {
281 //parent graphs only contain true...no need to check
282 newDelta.addOldNodes.put(node, Boolean.TRUE);
286 newDelta.addNodeAges.addAll(graph.nodeAges);
287 newDelta.addNodeAges.addAll(graph.parent.nodeAges);
290 /* This function build the delta for the exit of a basic block. */
292 void generateFinalDelta(BBlock bblock, Delta delta, Graph graph) {
293 Delta newDelta=new Delta(null, false);
294 if (delta.getInit()) {
295 buildInitDelta(graph, newDelta);
297 /* We can break the old delta...it is done being used */
298 /* First we will build variable edges */
299 HashSet<TempDescriptor> tmpSet=new HashSet<TempDescriptor>();
300 tmpSet.addAll(delta.basevaredge.keySet());
301 tmpSet.addAll(delta.varedgeadd.keySet());
302 for(TempDescriptor tmp : tmpSet) {
303 /* Start with the new incoming edges */
304 MySet<Edge> newbaseedge=delta.basevaredge.get(tmp);
305 /* Remove the remove set */
306 if (newbaseedge==null)
307 newbaseedge=new MySet<Edge>();
308 newbaseedge.removeAll(delta.varedgeremove.get(tmp));
309 /* Add in the new set*/
310 newbaseedge.addAll(delta.varedgeadd.get(tmp));
311 /* Store the results */
312 newDelta.varedgeadd.put(tmp, newbaseedge);
314 delta.basevaredge.clear();
316 /* Next we build heap edges */
317 HashSet<AllocNode> nodeSet=new HashSet<AllocNode>();
318 nodeSet.addAll(delta.baseheapedge.keySet());
319 nodeSet.addAll(delta.heapedgeadd.keySet());
320 nodeSet.addAll(delta.heapedgeremove.keySet());
321 for(AllocNode node : nodeSet) {
322 /* Start with the new incoming edges */
323 MySet<Edge> newheapedge=new MySet<Edge>(delta.baseheapedge.get(node));
324 /* Remove the remove set */
325 MySet<Edge> removeset=delta.heapedgeremove.get(node);
328 newheapedge.removeAll(removeset);
330 /* Add in the add set */
331 MySet<Edge> settoadd=delta.heapedgeadd.get(node);
333 newheapedge.addAll(settoadd);
334 newDelta.heapedgeadd.put(node, newheapedge);
336 /* Remove the newly created edges..no need to propagate a diff for those */
337 if (removeset!=null) {
338 removeset.removeAll(delta.baseheapedge.get(node));
339 newDelta.heapedgeremove.put(node, removeset);
343 /* Compute new ages */
344 newDelta.addNodeAges.addAll(delta.baseNodeAges);
345 newDelta.addNodeAges.addAll(delta.addNodeAges);
346 HashSet<AllocNode> oldNodes=new HashSet<AllocNode>();
348 /* Compute whether old nodes survive */
349 oldNodes.addAll(delta.baseOldNodes.keySet());
350 oldNodes.addAll(delta.addOldNodes.keySet());
351 for(AllocNode node : oldNodes) {
352 if (delta.addOldNodes.containsKey(node)) {
353 if (delta.addOldNodes.get(node).booleanValue()) {
354 newDelta.addOldNodes.put(node, Boolean.TRUE);
357 if (delta.baseOldNodes.get(node).booleanValue()) {
358 newDelta.addOldNodes.put(node, Boolean.TRUE);
364 if (returnMap.containsKey(bblock)) {
365 //clear everything but our return temp!
366 MySet<Edge> edges=newDelta.varedgeadd.get(returntmp);
367 newDelta.varedgeadd.clear();
368 newDelta.varedgeadd.put(returntmp, edges);
371 /* Now we need to propagate newdelta */
372 if (!newDelta.heapedgeadd.isEmpty()||!newDelta.heapedgeremove.isEmpty()||!newDelta.varedgeadd.isEmpty()||!newDelta.addNodeAges.isEmpty()||!newDelta.addOldNodes.isEmpty()) {
373 /* We have a delta to propagate */
374 if (returnMap.containsKey(bblock)) {
378 for(PPoint caller : returnMap.get(bblock)) {
379 //System.out.println("Sending Return BBlock to "+caller.getBBlock().nodes.get(caller.getIndex()).toString().replace(' ','_'));
382 newDelta.setBlock(caller);
383 toprocess.add(newDelta);
386 Delta d=newDelta.diffBlock(caller);
392 Vector<BBlock> blockvector=bblock.next();
393 for(int i=0; i<blockvector.size(); i++) {
394 //System.out.println("Sending BBlock to "+blockvector.get(i).nodes.get(0).toString().replace(' ','_'));
397 newDelta.setBlock(new PPoint(blockvector.get(i)));
398 toprocess.add(newDelta);
400 Delta d=newDelta.diffBlock(new PPoint(blockvector.get(i)));
406 //System.out.println("EMPTY DELTA");
407 //System.out.println("delta");
409 //System.out.println("newDelta");
414 boolean isNEEDED(FlatNode node) {
415 switch(node.kind()) {
416 case FKind.FlatSetFieldNode: {
417 FlatSetFieldNode n=(FlatSetFieldNode)node;
418 return n.getSrc().getType().isPtr();
421 case FKind.FlatSetElementNode: {
422 FlatSetElementNode n=(FlatSetElementNode)node;
423 return n.getSrc().getType().isPtr();
426 case FKind.FlatFieldNode: {
427 FlatFieldNode n=(FlatFieldNode)node;
428 return n.getDst().getType().isPtr();
431 case FKind.FlatElementNode: {
432 FlatElementNode n=(FlatElementNode)node;
433 return n.getDst().getType().isPtr();
439 Delta processNode(BBlock bblock, int index, FlatNode node, Delta delta, Graph newgraph) {
440 switch(node.kind()) {
442 return processNewNode((FlatNew)node, delta, newgraph);
444 case FKind.FlatFieldNode:
445 case FKind.FlatElementNode:
446 return processFieldElementNode(node, delta, newgraph);
448 case FKind.FlatCastNode:
449 case FKind.FlatOpNode:
450 case FKind.FlatReturnNode:
451 return processCopyNode(node, delta, newgraph);
453 case FKind.FlatSetFieldNode:
454 case FKind.FlatSetElementNode:
455 return processSetFieldElementNode(node, delta, newgraph);
457 case FKind.FlatSESEEnterNode:
458 return processSESEEnterNode((FlatSESEEnterNode) node, delta, newgraph);
460 case FKind.FlatSESEExitNode:
461 return processSESEExitNode((FlatSESEExitNode) node, delta, newgraph);
463 case FKind.FlatMethod:
465 case FKind.FlatBackEdge:
466 case FKind.FlatGenReachNode:
467 return processFlatNop(node, delta, newgraph);
470 return processFlatCall(bblock, index, (FlatCall) node, delta, newgraph);
473 throw new Error("Unrecognized node:"+node);
477 Delta processSESEEnterNode(FlatSESEEnterNode sese, Delta delta, Graph graph) {
479 return processFlatNop(sese, delta, graph);
480 if (delta.getInit()) {
481 removeInitTaints(null, delta, graph);
482 for (TempDescriptor tmp : sese.getInVarSet()) {
483 Taint taint=Taint.factory(sese, null, tmp, AllocFactory.dummySite, null, ReachGraph.predsEmpty);
484 MySet<Edge> edges=GraphManip.getEdges(graph, delta, tmp);
485 for(Edge e : edges) {
486 Edge newe=e.addTaint(taint);
487 delta.addVarEdge(newe);
491 removeDiffTaints(null, delta);
492 for (TempDescriptor tmp : sese.getInVarSet()) {
493 Taint taint=Taint.factory(sese, null, tmp, AllocFactory.dummySite, null, ReachGraph.predsEmpty);
494 MySet<Edge> edges=GraphManip.getDiffEdges(delta, tmp);
495 for(Edge e : edges) {
496 Edge newe=e.addTaint(taint);
497 delta.addVarEdge(newe);
503 applyDiffs(graph, delta);
507 private boolean isRecursive(FlatSESEEnterNode sese) {
508 MethodDescriptor md=sese.getmdEnclosing();
509 boolean isrecursive=callGraph.getCalleeSet(md).contains(md);
513 Delta processSESEExitNode(FlatSESEExitNode seseexit, Delta delta, Graph graph) {
515 return processFlatNop(seseexit, delta, graph);
516 FlatSESEEnterNode sese=seseexit.getFlatEnter();
517 //Strip Taints from this SESE
518 if (delta.getInit()) {
519 removeInitTaints(isRecursive(sese)?null:sese, delta, graph);
521 removeDiffTaints(isRecursive(sese)?null:sese, delta);
523 applyDiffs(graph, delta);
527 void removeDiffTaints(FlatSESEEnterNode sese, Delta delta) {
528 //Start with variable edges
530 MySet<Edge> edgestoadd=new MySet<Edge>();
531 MySet<Edge> edgestoremove=new MySet<Edge>();
533 //Process base diff edges
534 processEdgeMap(sese, delta.basevaredge, null, delta.varedgeremove, edgestoremove, edgestoadd);
535 //Process delta edges
536 processEdgeMap(sese, delta.varedgeadd, null, null, edgestoremove, edgestoadd);
537 for(Edge e : edgestoremove) {
538 delta.removeVarEdge(e);
540 for(Edge e : edgestoadd) {
547 MySet<Edge> edgestoadd=new MySet<Edge>();
548 MySet<Edge> edgestoremove=new MySet<Edge>();
550 //Process base diff edges
551 processEdgeMap(sese, delta.baseheapedge, null, delta.heapedgeremove, edgestoremove, edgestoadd);
552 //Process delta edges
553 processEdgeMap(sese, delta.heapedgeadd, null, null, edgestoremove, edgestoadd);
554 for(Edge e : edgestoremove) {
555 delta.removeHeapEdge(e);
557 for(Edge e : edgestoadd) {
558 delta.addHeapEdge(e);
563 void removeInitTaints(FlatSESEEnterNode sese, Delta delta, Graph graph) {
564 //Start with variable edges
566 MySet<Edge> edgestoadd=new MySet<Edge>();
567 MySet<Edge> edgestoremove=new MySet<Edge>();
569 //Process parent edges
570 processEdgeMap(sese, graph.parent.varMap, graph.varMap, delta.varedgeremove, edgestoremove, edgestoadd);
571 //Process graph edges
572 processEdgeMap(sese, graph.varMap, null, delta.varedgeremove, edgestoremove, edgestoadd);
573 //Process delta edges
574 processEdgeMap(sese, delta.varedgeadd, null, null, edgestoremove, edgestoadd);
575 for(Edge e : edgestoremove) {
576 delta.removeVarEdge(e);
578 for(Edge e : edgestoadd) {
585 MySet<Edge> edgestoadd=new MySet<Edge>();
586 MySet<Edge> edgestoremove=new MySet<Edge>();
588 //Process parent edges
589 processEdgeMap(sese, graph.parent.nodeMap, graph.nodeMap, delta.heapedgeremove, edgestoremove, edgestoadd);
590 //Process graph edges
591 processEdgeMap(sese, graph.nodeMap, null, delta.heapedgeremove, edgestoremove, edgestoadd);
592 //Process delta edges
593 processEdgeMap(sese, delta.heapedgeadd, null, null, edgestoremove, edgestoadd);
594 for(Edge e : edgestoremove) {
595 delta.removeHeapEdge(e);
597 for(Edge e : edgestoadd) {
598 delta.addHeapEdge(e);
603 void processEdgeMap(FlatSESEEnterNode sese, HashMap<?, MySet<Edge>> edgemap, HashMap<?, MySet<Edge>> childmap, HashMap<?, MySet<Edge>> removemap, MySet<Edge> edgestoremove, MySet<Edge> edgestoadd) {
604 for(Map.Entry<?, MySet<Edge>> entry:edgemap.entrySet()) {
605 //If the parent map exists and overrides this entry, skip it
606 if (childmap!=null&&childmap.containsKey(entry.getKey()))
608 for(Edge e:entry.getValue()) {
609 //check whether this edge has been removed
610 if (removemap!=null&&removemap.containsKey(entry.getKey())&&
611 removemap.get(entry.getKey()).contains(e))
614 TaintSet ts=e.getTaints();
616 //update non-null taint set
618 newts=Canonical.removeInContextTaintsNP(ts, sese);
619 if (newts!=null&&newts!=ts) {
620 edgestoremove.add(e);
621 edgestoadd.add(e.changeTaintSet(newts));
627 /* This function compute the edges for the this variable for a
628 * callee if it exists. */
630 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) {
631 //Handle the this temp
633 MySet<Edge> edges=(oldnodeset!=null)?GraphManip.getDiffEdges(delta, tmpthis):GraphManip.getEdges(graph, delta, tmpthis);
634 newDelta.varedgeadd.put(tmpthis, (MySet<Edge>)edges.clone());
635 edgeset.addAll(edges);
637 AllocNode dstnode=e.dst;
638 if (!nodeset.contains(dstnode)&&(oldnodeset==null||!oldnodeset.contains(dstnode))) {
639 TypeDescriptor type=dstnode.getType();
640 if (!type.isArray()) {
641 targetSet.add(type.getClassDesc());
643 //arrays don't have code
644 targetSet.add(typeUtil.getClass(TypeUtil.ObjectClass));
646 nodeset.add(dstnode);
647 tovisit.add(dstnode);
653 /* This function compute the edges for a call's parameters. */
655 void processParams(Graph graph, Delta delta, Delta newDelta, HashSet<AllocNode> nodeset, Stack<AllocNode> tovisit, MySet<Edge> edgeset, FlatCall fcall, boolean diff) {
656 //Go through each temp
657 for(int i=0; i<fcall.numArgs(); i++) {
658 TempDescriptor tmp=fcall.getArg(i);
659 MySet<Edge> edges=diff?GraphManip.getDiffEdges(delta, tmp):GraphManip.getEdges(graph, delta, tmp);
660 newDelta.varedgeadd.put(tmp, (MySet<Edge>)edges.clone());
661 edgeset.addAll(edges);
663 if (!nodeset.contains(e.dst)) {
671 /* This function computes the reachable nodes for a callee. */
673 void computeReachableNodes(Graph graph, Delta delta, Delta newDelta, HashSet<AllocNode> nodeset, Stack<AllocNode> tovisit, MySet<Edge> edgeset, HashSet<AllocNode> oldnodeset) {
674 while(!tovisit.isEmpty()) {
675 AllocNode node=tovisit.pop();
676 MySet<Edge> edges=GraphManip.getEdges(graph, delta, node);
677 if (!edges.isEmpty()) {
678 newDelta.heapedgeadd.put(node, Edge.makeOld(edges));
679 edgeset.addAll(edges);
680 for(Edge e : edges) {
681 if (!nodeset.contains(e.dst)&&(oldnodeset==null||!oldnodeset.contains(e.dst))) {
690 HashSet<MethodDescriptor> computeTargets(FlatCall fcall, Delta newDelta) {
691 TempDescriptor tmpthis=fcall.getThis();
692 MethodDescriptor md=fcall.getMethod();
693 HashSet<MethodDescriptor> targets=new HashSet<MethodDescriptor>();
694 if (md.isStatic()||fcall.getSuper()) {
698 for(Edge e : newDelta.varedgeadd.get(tmpthis)) {
699 AllocNode node=e.dst;
700 ClassDescriptor cd=node.getType().getClassDesc();
701 //Figure out exact method called and add to set
702 MethodDescriptor calledmd=cd.getCalledMethod(md);
703 targets.add(calledmd);
709 void fixMapping(FlatCall fcall, HashSet<MethodDescriptor> targets, MySet<Edge> oldedgeset, Delta newDelta, BBlock callblock, int callindex) {
710 Delta basedelta=null;
711 TempDescriptor tmpthis=fcall.getThis();
713 for(MethodDescriptor calledmd : targets) {
714 FlatMethod fm=state.getMethodFlat(calledmd);
715 boolean newmethod=false;
718 HashMap<TempDescriptor, TempDescriptor> tmpMap=new HashMap<TempDescriptor, TempDescriptor>();
721 tmpMap.put(tmpthis, fm.getParameter(offset++));
723 for(int i=0; i<fcall.numArgs(); i++) {
724 TempDescriptor tmp=fcall.getArg(i);
725 tmpMap.put(tmp,fm.getParameter(i+offset));
728 //Get basicblock for the method
729 BasicBlock block=getBBlock(fm);
732 if (!callMap.containsKey(fcall)) {
733 callMap.put(fcall, new HashSet<BBlock>());
736 Delta returnDelta=null;
737 if (!callMap.get(fcall).contains(block.getStart())) {
738 callMap.get(fcall).add(block.getStart());
742 if (!returnMap.containsKey(block.getExit())) {
743 returnMap.put(block.getExit(), new HashSet<PPoint>());
745 returnMap.get(block.getExit()).add(new PPoint(callblock, callindex));
747 if (bbgraphMap.containsKey(block.getExit())) {
748 //Need to push existing results to current node
749 if (returnDelta==null) {
750 returnDelta=new Delta(null, false);
751 Vector<FlatNode> exitblocknodes=block.getExit().nodes();
752 FlatExit fexit=(FlatExit)exitblocknodes.get(exitblocknodes.size()-1);
753 buildInitDelta(graphMap.get(fexit), returnDelta);
754 if (!returnDelta.heapedgeadd.isEmpty()||!returnDelta.heapedgeremove.isEmpty()||!returnDelta.varedgeadd.isEmpty()) {
755 returnDelta.setBlock(new PPoint(callblock, callindex));
756 toprocess.add(returnDelta);
759 if (!returnDelta.heapedgeadd.isEmpty()||!returnDelta.heapedgeremove.isEmpty()||!returnDelta.varedgeadd.isEmpty()) {
760 toprocess.add(returnDelta.diffBlock(new PPoint(callblock, callindex)));
766 if (oldedgeset==null) {
767 //First build of this graph
768 //Build and enqueue delta...safe to just use existing delta
769 Delta d=newDelta.changeParams(tmpMap, new PPoint(block.getStart()));
770 //System.out.println("AProcessing "+block.getStart().nodes.get(0).toString().replace(' ','_'));
773 } else if (newmethod) {
774 if (basedelta==null) {
775 basedelta=newDelta.buildBase(oldedgeset);
777 //Build and enqueue delta
778 Delta d=basedelta.changeParams(tmpMap, new PPoint(block.getStart()));
779 //System.out.println("BProcessing "+block.getStart().nodes.get(0).toString().replace(' ','_'));
783 //Build and enqueue delta
784 Delta d=newDelta.changeParams(tmpMap, new PPoint(block.getStart()));
785 //System.out.println("CProcessing "+block.getStart().nodes.get(0).toString().replace(' ','_'));
793 /* This function computes all edges that start outside of the callee
794 * context and go into the callee context */
796 void computeExternalEdges(Graph graph, Delta delta, HashSet<AllocNode> nodeset, HashSet<AllocNode> deltaset, MySet<Edge> externaledgeset) {
797 //Do heap edges first
798 HashSet<AllocNode> externalnodes=new HashSet<AllocNode>();
799 externalnodes.addAll(delta.baseheapedge.keySet());
800 externalnodes.addAll(delta.heapedgeadd.keySet());
801 externalnodes.addAll(delta.heapedgeremove.keySet());
802 //remove allinternal nodes
803 externalnodes.removeAll(nodeset);
804 for(AllocNode extNode : externalnodes) {
805 //Compute set of edges from given node
806 MySet<Edge> edges=new MySet<Edge>(delta.baseheapedge.get(extNode));
807 edges.removeAll(delta.heapedgeremove.get(extNode));
808 edges.addAll(delta.heapedgeadd.get(extNode));
810 for(Edge e : edges) {
811 if (nodeset.contains(e.dst))
812 externaledgeset.add(e);
817 HashSet<TempDescriptor> temps=new HashSet<TempDescriptor>();
818 temps.addAll(delta.basevaredge.keySet());
819 temps.addAll(delta.varedgeadd.keySet());
820 temps.addAll(delta.varedgeremove.keySet());
821 //remove allinternal nodes
822 temps.removeAll(nodeset);
824 for(TempDescriptor tmp : temps) {
825 //Compute set of edges from given node
826 MySet<Edge> edges=new MySet<Edge>(delta.basevaredge.get(tmp));
828 edges.removeAll(delta.varedgeremove.get(tmp));
829 edges.addAll(delta.varedgeadd.get(tmp));
831 for(Edge e : edges) {
832 if (nodeset.contains(e.dst))
833 externaledgeset.add(e);
838 /* This function removes the caller reachable edges from the
841 void removeEdges(Graph graph, Delta delta, HashSet<AllocNode> nodeset, MySet<Edge> edgeset, MySet<Edge> externaledgeset) {
842 //Want to remove the set of internal edges
843 for(Edge e : edgeset) {
844 if (e.src!=null&&!graph.callerEdges.contains(e)) {
845 delta.removeHeapEdge(e);
849 //Want to remove the set of external edges
850 for(Edge e : externaledgeset) {
851 //want to remove the set of internal edges
852 if (!graph.callerEdges.contains(e))
857 Delta processFlatCall(BBlock callblock, int callindex, FlatCall fcall, Delta delta, Graph graph) {
858 Delta newDelta=new Delta(null, false);
860 if (delta.getInit()) {
861 MySet<Edge> edgeset=new MySet<Edge>();
862 MySet<Edge> externaledgeset=new MySet<Edge>();
863 HashSet<AllocNode> nodeset=new HashSet<AllocNode>();
864 HashSet<ClassDescriptor> targetSet=new HashSet<ClassDescriptor>();
865 Stack<AllocNode> tovisit=new Stack<AllocNode>();
866 TempDescriptor tmpthis=fcall.getThis();
867 graph.callerEdges=new MySet<Edge>();
869 //Handle the this temp
870 processThisTargets(targetSet, graph, delta, newDelta, nodeset, tovisit, edgeset, tmpthis, null);
872 //Go through each temp
873 processParams(graph, delta, newDelta, nodeset, tovisit, edgeset, fcall, false);
875 //Traverse all reachable nodes
876 computeReachableNodes(graph, delta, newDelta, nodeset, tovisit, edgeset, null);
878 //Compute call targets
879 HashSet<MethodDescriptor> newtargets=computeTargets(fcall, newDelta);
882 fixMapping(fcall, newtargets, null, newDelta, callblock, callindex);
884 //Compute edges into region to splice out
885 computeExternalEdges(graph, delta, nodeset, null, externaledgeset);
887 //Splice out internal edges
888 removeEdges(graph, delta, nodeset, edgeset, externaledgeset);
890 //store data structures
891 graph.externalEdgeSet=externaledgeset;
892 graph.reachNode=nodeset;
893 graph.reachEdge=edgeset;
895 graph.callTargets=newtargets;
896 graph.callNodeAges=new HashSet<AllocNode>();
897 graph.callOldNodes=new HashSet<AllocNode>();
898 graph.callNewEdges=new HashMap<AllocNode, MySet<Edge>>();
899 graph.callOldEdges=new HashMap<Edge,MySet<Edge>>();
901 //Apply diffs to graph
902 applyDiffs(graph, delta, true);
904 MySet<Edge> edgeset=new MySet<Edge>();
905 MySet<Edge> externaledgeset=new MySet<Edge>();
906 HashSet<AllocNode> nodeset=new HashSet<AllocNode>();
907 MySet<Edge> oldedgeset=graph.reachEdge;
908 HashSet<AllocNode> oldnodeset=graph.reachNode;
910 HashSet<ClassDescriptor> targetSet=new HashSet<ClassDescriptor>();
911 Stack<AllocNode> tovisit=new Stack<AllocNode>();
912 TempDescriptor tmpthis=fcall.getThis();
913 //Fix up delta to get rid of unnecessary heap edge removals
914 for(Map.Entry<AllocNode, MySet<Edge>> entry : delta.heapedgeremove.entrySet()) {
915 for(Iterator<Edge> eit=entry.getValue().iterator(); eit.hasNext(); ) {
917 if (graph.callerEdges.contains(e))
922 //Fix up delta to get rid of unnecessary var edge removals
923 for(Map.Entry<TempDescriptor, MySet<Edge>> entry : delta.varedgeremove.entrySet()) {
924 for(Iterator<Edge> eit=entry.getValue().iterator(); eit.hasNext(); ) {
926 if (graph.callerEdges.contains(e))
931 //Handle the this temp
932 processThisTargets(targetSet, graph, delta, newDelta, nodeset, tovisit, edgeset, tmpthis, oldnodeset);
934 //Go through each temp
935 processParams(graph, delta, newDelta, nodeset, tovisit, edgeset, fcall, true);
936 //Go through each new heap edge that starts from old node
937 MySet<Edge> newedges=GraphManip.getDiffEdges(delta, oldnodeset);
938 edgeset.addAll(newedges);
939 for(Edge e : newedges) {
940 //Add new edges that start from old node to newDelta
942 if (!newDelta.heapedgeadd.containsKey(src)) {
943 newDelta.heapedgeadd.put(src, new MySet<Edge>());
945 newDelta.heapedgeadd.get(src).add(e.makeOld());
946 if (!nodeset.contains(e.dst)&&!oldnodeset.contains(e.dst)) {
952 //Traverse all reachable nodes
953 computeReachableNodes(graph, delta, newDelta, nodeset, tovisit, edgeset, oldnodeset);
954 //Compute call targets
955 HashSet<MethodDescriptor> newtargets=computeTargets(fcall, newDelta);
956 graph.callTargets.addAll(newtargets);
958 //add in new nodeset and edgeset
959 oldnodeset.addAll(nodeset);
960 oldedgeset.addAll(edgeset);
962 fixMapping(fcall, graph.callTargets, oldedgeset, newDelta, callblock, callindex);
963 //Compute edges into region to splice out
964 computeExternalEdges(graph, delta, oldnodeset, nodeset, externaledgeset);
966 //Splice out internal edges
967 removeEdges(graph, delta, nodeset, edgeset, externaledgeset);
969 //Add external edges back in
970 processCallExternal(graph, delta, externaledgeset);
972 //Move new edges that should be summarized
973 processSummarization(graph, delta);
975 Set<FlatSESEEnterNode> seseCallers=OoOJava?taskAnalysis.getTransitiveExecutingRBlocks(fcall):null;
976 //Check if the new nodes allow us to insert a new edge
977 for(AllocNode node : nodeset) {
978 if (graph.callNewEdges.containsKey(node)) {
979 for(Iterator<Edge> eit=graph.callNewEdges.get(node).iterator(); eit.hasNext(); ) {
981 if ((graph.callNodeAges.contains(e.src)||graph.reachNode.contains(e.src))&&
982 (graph.callNodeAges.contains(e.dst)||graph.reachNode.contains(e.dst))) {
983 Edge edgetoadd=e.copy(); //we need our own copy to modify below
985 if (seseCallers!=null)
986 edgetoadd.taintModify(seseCallers);
987 mergeCallEdge(graph, delta, edgetoadd);
993 for(Edge e : edgeset) {
994 //See if these edges would allow an old edge to be added
995 if (graph.callOldEdges.containsKey(e)) {
996 for(Edge adde : graph.callOldEdges.get(e)) {
997 Edge ecopy=adde.copy();
998 ecopy.statuspredicate=e.statuspredicate;
999 mergeCallEdge(graph, delta, ecopy);
1004 //Add in new external edges
1005 graph.externalEdgeSet.addAll(externaledgeset);
1006 //Apply diffs to graph
1007 applyDiffs(graph, delta);
1012 void processSummarization(Graph graph, Delta delta) {
1013 processSumHeapEdgeSet(delta.heapedgeadd, delta, graph);
1014 processSumHeapEdgeSet(delta.baseheapedge, delta, graph);
1015 processSumVarEdgeSet(delta.varedgeadd, delta, graph);
1016 processSumVarEdgeSet(delta.basevaredge, delta, graph);
1019 void processSumVarEdgeSet(HashMap<TempDescriptor, MySet<Edge>> map, Delta delta, Graph graph) {
1020 MySet<Edge> edgestoadd=new MySet<Edge>();
1021 MySet<Edge> edgestoremove=new MySet<Edge>();
1022 for(Iterator<Map.Entry<TempDescriptor, MySet<Edge>>> eit=map.entrySet().iterator(); eit.hasNext(); ) {
1023 Map.Entry<TempDescriptor, MySet<Edge>> entry=eit.next();
1024 MySet<Edge> edgeset=entry.getValue();
1026 for(Edge e : edgeset) {
1028 boolean rewrite=false;
1029 if (copy.dst!=null&&graph.callNodeAges.contains(copy.dst)) {
1030 copy.dst=allocFactory.getAllocNode(copy.dst, true);
1034 edgestoremove.add(e);
1035 edgestoadd.add(copy);
1039 for(Edge e : edgestoremove) {
1040 if (!graph.callerEdges.contains(e))
1041 delta.removeVarEdge(e);
1043 for(Edge e : edgestoadd) {
1044 delta.addVarEdge(e);
1048 public Alloc getAllocationSiteFromFlatNew(FlatNew node) {
1049 return allocFactory.getAllocNode(node, false).getAllocSite();
1052 void processSumHeapEdgeSet(HashMap<AllocNode, MySet<Edge>> map, Delta delta, Graph graph) {
1053 MySet<Edge> edgestoadd=new MySet<Edge>();
1054 MySet<Edge> edgestoremove=new MySet<Edge>();
1055 for(Iterator<Map.Entry<AllocNode, MySet<Edge>>> eit=map.entrySet().iterator(); eit.hasNext(); ) {
1056 Map.Entry<AllocNode, MySet<Edge>> entry=eit.next();
1057 AllocNode node=entry.getKey();
1058 MySet<Edge> edgeset=entry.getValue();
1060 for(Edge e : edgeset) {
1062 boolean rewrite=false;
1063 if (copy.src!=null&&graph.callNodeAges.contains(copy.src)) {
1064 copy.src=allocFactory.getAllocNode(copy.src, true);
1067 if (copy.dst!=null&&graph.callNodeAges.contains(copy.dst)) {
1068 copy.dst=allocFactory.getAllocNode(copy.dst, true);
1072 edgestoremove.add(e);
1073 edgestoadd.add(copy);
1077 for(Edge e : edgestoremove) {
1078 if (!graph.callerEdges.contains(e))
1079 delta.removeHeapEdge(e);
1081 for(Edge e : edgestoadd) {
1082 delta.addHeapEdge(e);
1086 //Handle external edges
1087 void processCallExternal(Graph graph, Delta newDelta, MySet<Edge> externalEdgeSet) {
1088 //Add external edges in
1089 for(Edge e : externalEdgeSet) {
1090 //First did we age the source
1091 Edge newedge=e.copy();
1092 if (newedge.src!=null&&!e.src.isSummary()&&graph.callNodeAges.contains(e.src)) {
1093 AllocNode summaryNode=allocFactory.getAllocNode(newedge.src, true);
1094 newedge.src=summaryNode;
1097 if (graph.callNodeAges.contains(e.dst)&&!e.dst.isSummary()) {
1098 if (graph.callOldNodes.contains(e.dst)) {
1100 Edge copy=newedge.copy();
1101 mergeEdge(graph, newDelta, copy);
1103 //Now add summarized node
1104 newedge.dst=allocFactory.getAllocNode(newedge.dst, true);
1105 mergeCallEdge(graph, newDelta, newedge);
1107 //Add edge to single node
1108 mergeEdge(graph, newDelta, newedge);
1113 /* This function applies callee deltas to the caller heap. */
1115 Delta applyCallDelta(Delta delta, BBlock bblock) {
1116 Delta newDelta=new Delta(null, false);
1117 Vector<FlatNode> nodes=bblock.nodes();
1118 PPoint ppoint=delta.getBlock();
1119 FlatCall fcall=(FlatCall)nodes.get(ppoint.getIndex());
1120 Graph graph=graphMap.get(fcall);
1121 Graph oldgraph=(ppoint.getIndex()==0)?
1122 bbgraphMap.get(bblock):
1123 graphMap.get(nodes.get(ppoint.getIndex()-1));
1124 Set<FlatSESEEnterNode> seseCallers=OoOJava?taskAnalysis.getTransitiveExecutingRBlocks(fcall):null;
1126 //Age outside nodes if necessary
1127 for(Iterator<AllocNode> nodeit=delta.addNodeAges.iterator(); nodeit.hasNext(); ) {
1128 AllocNode node=nodeit.next();
1129 if (!graph.callNodeAges.contains(node)) {
1130 graph.callNodeAges.add(node);
1131 newDelta.addNodeAges.add(node);
1133 AllocNode summaryAdd=null;
1134 if (!graph.reachNode.contains(node)&&!node.isSummary()) {
1135 /* Need to age node in existing graph*/
1137 AllocNode summaryNode=allocFactory.getAllocNode(node, true);
1139 if (!graph.callNodeAges.contains(summaryNode)) {
1140 graph.callNodeAges.add(summaryNode);
1141 newDelta.addNodeAges.add(summaryNode);
1142 summaryAdd=summaryNode;
1144 summarizeInGraph(graph, newDelta, node);
1147 if (graph.callNewEdges.containsKey(node)) {
1148 for(Iterator<Edge> eit=graph.callNewEdges.get(node).iterator(); eit.hasNext(); ) {
1150 if ((graph.callNodeAges.contains(e.src)||graph.reachNode.contains(e.src))&&
1151 (graph.callNodeAges.contains(e.dst)||graph.reachNode.contains(e.dst))) {
1152 Edge edgetoadd=e.copy(); //we need our own copy to modify below
1154 if (seseCallers!=null)
1155 edgetoadd.taintModify(seseCallers);
1156 mergeCallEdge(graph, newDelta, edgetoadd);
1160 //do the summary node if we added that also...
1163 } while(node!=null);
1167 for(Map.Entry<AllocNode, MySet<Edge>> entry : delta.heapedgeadd.entrySet()) {
1168 for(Edge e : entry.getValue()) {
1169 boolean addedge=false;
1170 Edge edgetoadd=null;
1171 if (e.statuspredicate==Edge.NEW) {
1172 if ((graph.callNodeAges.contains(e.src)||graph.reachNode.contains(e.src))&&
1173 (graph.callNodeAges.contains(e.dst)||graph.reachNode.contains(e.dst))) {
1174 edgetoadd=e.copy(); //we need our own copy to modify below
1176 graph.addCallEdge(e);
1179 Edge[] edgeArray=e.makeStatus(allocFactory);
1181 int statuspredicate=0;
1182 for(int i=0; i<edgeArray.length; i++) {
1183 Edge origEdgeKey=edgeArray[i];
1184 if (graph.reachEdge.contains(origEdgeKey)) {
1185 Edge origEdge=graph.reachEdge.get(origEdgeKey);
1186 //copy the predicate
1187 statuspredicate=statuspredicate|origEdge.statuspredicate;
1189 if (!graph.callOldEdges.containsKey(origEdgeKey)) {
1190 graph.callOldEdges.put(origEdgeKey, new MySet<Edge>());
1192 if (graph.callOldEdges.get(origEdgeKey).contains(e)) {
1193 Edge olde=graph.callOldEdges.get(origEdgeKey).get(e);
1194 graph.callOldEdges.get(origEdgeKey).add(olde.merge(e));
1196 graph.callOldEdges.get(origEdgeKey).add(e);
1199 if (statuspredicate!=0) {
1201 newe.statuspredicate=statuspredicate;
1205 if (seseCallers!=null&&edgetoadd!=null)
1206 edgetoadd.taintModify(seseCallers);
1207 mergeCallEdge(graph, newDelta, edgetoadd);
1211 processCallExternal(graph, newDelta, graph.externalEdgeSet);
1213 //Add edge for return value
1214 if (fcall.getReturnTemp()!=null) {
1215 MySet<Edge> returnedge=delta.varedgeadd.get(returntmp);
1216 if (returnedge!=null)
1217 for(Edge e : returnedge) {
1218 //skip the edge if types don't allow it...
1219 if (!typeUtil.isSuperorType(fcall.getReturnTemp().getType(), e.dst.getType()))
1221 Edge newedge=e.copy();
1222 newedge.srcvar=fcall.getReturnTemp();
1223 if (seseCallers!=null)
1224 newedge.taintModify(seseCallers);
1225 mergeEdge(graph, newDelta, newedge);
1228 applyDiffs(graph, newDelta);
1232 public void mergeEdge(Graph graph, Delta newDelta, Edge edgetoadd) {
1233 if (edgetoadd!=null) {
1234 Edge match=graph.getMatch(edgetoadd);
1236 if (match==null||!match.subsumes(edgetoadd)) {
1237 Edge mergededge=edgetoadd.merge(match);
1238 newDelta.addEdge(mergededge);
1243 /* This is a call produced edge...need to remember this */
1245 public void mergeCallEdge(Graph graph, Delta newDelta, Edge edgetoadd) {
1246 if (edgetoadd!=null) {
1247 newDelta.addEdgeClear(edgetoadd);
1249 Edge match=graph.getMatch(edgetoadd);
1251 if (match==null||!match.subsumes(edgetoadd)) {
1252 Edge mergededge=edgetoadd.merge(match);
1253 newDelta.addEdge(mergededge);
1254 graph.callerEdges.add(mergededge);
1260 /* Summarizes out of context nodes in graph */
1261 void summarizeInGraph(Graph graph, Delta newDelta, AllocNode singleNode) {
1262 AllocNode summaryNode=allocFactory.getAllocNode(singleNode, true);
1264 //Handle outgoing heap edges
1265 MySet<Edge> edgeset=graph.getEdges(singleNode);
1267 for(Edge e : edgeset) {
1268 Edge rewrite=e.rewrite(singleNode, summaryNode);
1270 newDelta.removeHeapEdge(e);
1271 mergeCallEdge(graph, newDelta, rewrite);
1274 //Handle incoming edges
1275 MySet<Edge> backedges=graph.getBackEdges(singleNode);
1276 for(Edge e : backedges) {
1277 if (e.dst==singleNode) {
1278 //Need to get original edge so that predicate will be correct
1279 Edge match=graph.getMatch(e);
1281 Edge rewrite=match.rewrite(singleNode, summaryNode);
1282 newDelta.removeEdge(match);
1283 mergeCallEdge(graph, newDelta, rewrite);
1289 void applyDiffs(Graph graph, Delta delta) {
1290 applyDiffs(graph, delta, false);
1293 void applyDiffs(Graph graph, Delta delta, boolean genbackwards) {
1294 //build backwards map if requested
1295 if (genbackwards&&graph.backMap==null) {
1296 graph.backMap=new HashMap<AllocNode, MySet<Edge>>();
1297 if (graph.parent.backMap==null) {
1298 graph.parent.backMap=new HashMap<AllocNode, MySet<Edge>>();
1299 for(Map.Entry<AllocNode, MySet<Edge>> entry : graph.nodeMap.entrySet()) {
1300 for(Edge e : entry.getValue()) {
1301 if (!graph.parent.backMap.containsKey(e.dst))
1302 graph.parent.backMap.put(e.dst, new MySet<Edge>());
1303 graph.parent.backMap.get(e.dst).add(e);
1306 for(Map.Entry<TempDescriptor, MySet<Edge>> entry : graph.varMap.entrySet()) {
1307 for(Edge e : entry.getValue()) {
1308 if (!graph.parent.backMap.containsKey(e.dst))
1309 graph.parent.backMap.put(e.dst, new MySet<Edge>());
1310 graph.parent.backMap.get(e.dst).add(e);
1316 //Add hidden base edges
1317 for(Map.Entry<AllocNode, MySet<Edge>> e : delta.baseheapedge.entrySet()) {
1318 AllocNode node=e.getKey();
1319 MySet<Edge> edges=e.getValue();
1320 if (graph.nodeMap.containsKey(node)) {
1321 MySet<Edge> nodeEdges=graph.nodeMap.get(node);
1322 nodeEdges.addAll(edges);
1327 for(Map.Entry<AllocNode, MySet<Edge>> e : delta.heapedgeremove.entrySet()) {
1328 AllocNode node=e.getKey();
1329 MySet<Edge> edgestoremove=e.getValue();
1330 if (graph.nodeMap.containsKey(node)) {
1331 //Just apply diff to current map
1332 graph.nodeMap.get(node).removeAll(edgestoremove);
1334 //Generate diff from parent graph
1335 MySet<Edge> parentedges=graph.parent.nodeMap.get(node);
1336 if (parentedges!=null) {
1337 MySet<Edge> newedgeset=Util.setSubtract(parentedges, edgestoremove);
1338 graph.nodeMap.put(node, newedgeset);
1344 for(Map.Entry<AllocNode, MySet<Edge>> e : delta.heapedgeadd.entrySet()) {
1345 AllocNode node=e.getKey();
1346 MySet<Edge> edgestoadd=e.getValue();
1347 //If we have not done a subtract, then
1348 if (!graph.nodeMap.containsKey(node)) {
1349 //Copy the parent entry
1350 if (graph.parent.nodeMap.containsKey(node))
1351 graph.nodeMap.put(node, (MySet<Edge>)graph.parent.nodeMap.get(node).clone());
1353 graph.nodeMap.put(node, new MySet<Edge>());
1355 Edge.mergeEdgesInto(graph.nodeMap.get(node),edgestoadd);
1357 for(Edge eadd : edgestoadd) {
1358 if (!graph.backMap.containsKey(eadd.dst))
1359 graph.backMap.put(eadd.dst, new MySet<Edge>());
1360 graph.backMap.get(eadd.dst).add(eadd);
1366 for(Map.Entry<TempDescriptor, MySet<Edge>> e : delta.varedgeremove.entrySet()) {
1367 TempDescriptor tmp=e.getKey();
1368 MySet<Edge> edgestoremove=e.getValue();
1370 if (graph.varMap.containsKey(tmp)) {
1371 //Just apply diff to current map
1372 graph.varMap.get(tmp).removeAll(edgestoremove);
1373 } else if (graph.parent.varMap.containsKey(tmp)) {
1374 //Generate diff from parent graph
1375 MySet<Edge> parentedges=graph.parent.varMap.get(tmp);
1376 MySet<Edge> newedgeset=Util.setSubtract(parentedges, edgestoremove);
1377 graph.varMap.put(tmp, newedgeset);
1382 for(Map.Entry<TempDescriptor, MySet<Edge>> e : delta.varedgeadd.entrySet()) {
1383 TempDescriptor tmp=e.getKey();
1384 MySet<Edge> edgestoadd=e.getValue();
1385 if (graph.varMap.containsKey(tmp)) {
1386 Edge.mergeEdgesInto(graph.varMap.get(tmp), edgestoadd);
1387 } else if (graph.parent.varMap.containsKey(tmp)) {
1388 graph.varMap.put(tmp, new MySet<Edge>(graph.parent.varMap.get(tmp)));
1389 Edge.mergeEdgesInto(graph.varMap.get(tmp), edgestoadd);
1391 graph.varMap.put(tmp, (MySet<Edge>)edgestoadd.clone());
1393 for(Edge eadd : edgestoadd) {
1394 if (!graph.backMap.containsKey(eadd.dst))
1395 graph.backMap.put(eadd.dst, new MySet<Edge>());
1396 graph.backMap.get(eadd.dst).add(eadd);
1401 //Add node additions
1402 for(AllocNode node : delta.addNodeAges) {
1403 graph.nodeAges.add(node);
1406 for(Map.Entry<AllocNode, Boolean> nodeentry : delta.addOldNodes.entrySet()) {
1407 AllocNode node=nodeentry.getKey();
1408 Boolean ispresent=nodeentry.getValue();
1409 graph.oldNodes.put(node, ispresent);
1413 boolean isINACC(FlatNode node) {
1416 switch(node.kind()) {
1417 case FKind.FlatSetFieldNode: {
1418 FlatSetFieldNode n=(FlatSetFieldNode)node;
1419 return !accessible.isAccessible(n, n.getDst());
1422 case FKind.FlatSetElementNode: {
1423 FlatSetElementNode n=(FlatSetElementNode)node;
1424 return !accessible.isAccessible(n, n.getDst());
1427 case FKind.FlatFieldNode: {
1428 FlatFieldNode n=(FlatFieldNode)node;
1429 return !accessible.isAccessible(n, n.getSrc());
1432 case FKind.FlatElementNode: {
1433 FlatElementNode n=(FlatElementNode)node;
1434 return !accessible.isAccessible(n, n.getSrc());
1440 Delta processSetFieldElementNode(FlatNode node, Delta delta, Graph graph) {
1444 if (node.kind()==FKind.FlatSetElementNode) {
1445 FlatSetElementNode fen=(FlatSetElementNode) node;
1450 FlatSetFieldNode ffn=(FlatSetFieldNode) node;
1456 if (delta.getInit()) {
1457 MySet<Edge> dstEdges=GraphManip.getEdges(graph, delta, dst);
1459 if (OoOJava&&!accessible.isAccessible(node, dst)) {
1460 Taint dstStallTaint=Taint.factory(node, dst, AllocFactory.dummySite, null, ReachGraph.predsEmpty);
1461 dstEdges=Edge.taintAll(dstEdges, dstStallTaint);
1462 updateVarDelta(graph, delta, dst, dstEdges, null);
1465 effectsAnalysis.analyzeFlatSetFieldNode(dstEdges, fd, node);
1468 //Do nothing for non pointers
1469 if (!src.getType().isPtr()) {
1470 if (mustProcess.contains(node)) {
1471 applyDiffs(graph, delta);
1476 MySet<Edge> srcEdges=GraphManip.getEdges(graph, delta, src);
1477 if (OoOJava&&!accessible.isAccessible(node, src)) {
1478 Taint srcStallTaint=Taint.factory(node, src, AllocFactory.dummySite, null, ReachGraph.predsEmpty);
1479 srcEdges=Edge.taintAll(srcEdges, srcStallTaint);
1480 updateVarDelta(graph, delta, src, srcEdges, null);
1483 MySet<Edge> edgesToAdd=GraphManip.genEdges(dstEdges, fd, srcEdges);
1484 MySet<Edge> edgesToRemove=null;
1485 if (dstEdges.size()==1&&!dstEdges.iterator().next().dst.isSummary()&&fd!=null) {
1486 /* Can do a strong update */
1487 edgesToRemove=GraphManip.getEdges(graph, delta, dstEdges, fd);
1488 graph.strongUpdateSet=edgesToRemove;
1490 graph.strongUpdateSet=new MySet<Edge>();
1493 updateHeapDelta(graph, delta, edgesToAdd, edgesToRemove);
1494 applyDiffs(graph, delta);
1496 MySet<Edge> newDstEdges=GraphManip.getDiffEdges(delta, dst);
1498 if (OoOJava&&!accessible.isAccessible(node, dst)) {
1499 Taint dstStallTaint=Taint.factory(node, dst, AllocFactory.dummySite, null, ReachGraph.predsEmpty);
1500 newDstEdges=Edge.taintAll(newDstEdges, dstStallTaint);
1501 updateVarDelta(graph, delta, dst, newDstEdges, null);
1505 effectsAnalysis.analyzeFlatSetFieldNode(newDstEdges, fd, node);
1508 if (!src.getType().isPtr()) {
1509 if (mustProcess.contains(node)) {
1510 applyDiffs(graph, delta);
1515 /* Next look at new sources */
1517 MySet<Edge> edgesToAdd=new MySet<Edge>();
1518 MySet<Edge> newSrcEdges=GraphManip.getDiffEdges(delta, src);
1519 MySet<Edge> srcEdges=GraphManip.getEdges(graph, delta, src);
1520 HashSet<AllocNode> dstNodes=GraphManip.getNodes(graph, delta, dst);
1522 if (OoOJava&&!accessible.isAccessible(node, src)) {
1523 Taint srcStallTaint=Taint.factory(node, src, AllocFactory.dummySite, null, ReachGraph.predsEmpty);
1524 newSrcEdges=Edge.taintAll(newSrcEdges, srcStallTaint);
1525 updateVarDelta(graph, delta, src, newSrcEdges, null);
1528 MySet<Edge> edgesToRemove=null;
1529 if (newDstEdges.size()!=0) {
1530 if (dstNodes.size()>1&&!dstNodes.iterator().next().isSummary()&&fd!=null) {
1531 /* Need to undo strong update */
1532 if (graph.strongUpdateSet!=null) {
1533 edgesToAdd.addAll(graph.strongUpdateSet);
1534 graph.strongUpdateSet=null; //Prevent future strong updates
1536 } else if (dstNodes.size()==1&&newDstEdges.size()==1&&!newDstEdges.iterator().next().dst.isSummary()&&graph.strongUpdateSet!=null&&fd!=null) {
1537 edgesToRemove=GraphManip.getEdges(graph, delta, dstNodes, fd);
1538 graph.strongUpdateSet.addAll(edgesToRemove);
1540 Edge.mergeEdgesInto(edgesToAdd, GraphManip.genEdges(newDstEdges, fd, srcEdges));
1544 if (graph.strongUpdateSet!=null&&fd!=null) {
1545 MySet<Edge> otherEdgesToRemove=GraphManip.getDiffEdges(delta, dstNodes, fd);
1546 if (edgesToRemove!=null)
1547 edgesToRemove.addAll(otherEdgesToRemove);
1549 edgesToRemove=otherEdgesToRemove;
1550 graph.strongUpdateSet.addAll(otherEdgesToRemove);
1553 //Next look at new destinations
1554 Edge.mergeEdgesInto(edgesToAdd, GraphManip.genEdges(dstNodes, fd, newSrcEdges));
1557 updateHeapDelta(graph, delta, edgesToAdd, edgesToRemove);
1558 applyDiffs(graph, delta);
1563 Delta processCopyNode(FlatNode node, Delta delta, Graph graph) {
1567 if (node.kind()==FKind.FlatOpNode) {
1568 FlatOpNode fon=(FlatOpNode) node;
1571 } else if (node.kind()==FKind.FlatReturnNode) {
1572 FlatReturnNode frn=(FlatReturnNode)node;
1573 src=frn.getReturnTemp();
1575 if (src==null||!src.getType().isPtr()) {
1577 applyDiffs(graph, delta);
1581 FlatCastNode fcn=(FlatCastNode) node;
1585 if (delta.getInit()) {
1586 MySet<Edge> srcedges=GraphManip.getEdges(graph, delta, src);
1587 MySet<Edge> edgesToAdd=GraphManip.genEdges(dst, srcedges);
1588 MySet<Edge> edgesToRemove=GraphManip.getEdges(graph, delta, dst);
1589 updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
1590 applyDiffs(graph, delta);
1592 /* First compute new src nodes */
1593 MySet<Edge> newSrcEdges=GraphManip.getDiffEdges(delta, src);
1595 /* Compute the union, and then the set of edges */
1596 MySet<Edge> edgesToAdd=GraphManip.genEdges(dst, newSrcEdges);
1598 /* Compute set of edges to remove */
1599 MySet<Edge> edgesToRemove=GraphManip.getDiffEdges(delta, dst);
1602 updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
1603 applyDiffs(graph, delta);
1608 Delta processFieldElementNode(FlatNode node, Delta delta, Graph graph) {
1612 TaintSet taint=null;
1614 if (node.kind()==FKind.FlatElementNode) {
1615 FlatElementNode fen=(FlatElementNode) node;
1620 FlatFieldNode ffn=(FlatFieldNode) node;
1625 if (OoOJava&&!accessible.isAccessible(node, src)) {
1626 taint=TaintSet.factory(Taint.factory(node, src, AllocFactory.dummySite, null, ReachGraph.predsEmpty));
1629 //Do nothing for non pointers
1630 if (delta.getInit()) {
1631 MySet<Edge> srcedges=GraphManip.getEdges(graph, delta, src);
1634 srcedges=Edge.taintAll(srcedges, taint);
1635 updateVarDelta(graph, delta, src, srcedges, null);
1637 effectsAnalysis.analyzeFlatFieldNode(srcedges, fd, node);
1639 if (!dst.getType().isPtr()) {
1640 if (mustProcess.contains(node)) {
1641 applyDiffs(graph, delta);
1646 MySet<Edge> edgesToAdd=GraphManip.dereference(graph, delta, dst, srcedges, fd, node);
1647 MySet<Edge> edgesToRemove=GraphManip.getEdges(graph, delta, dst);
1649 updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
1650 applyDiffs(graph, delta);
1652 MySet<Edge> newsrcedges=GraphManip.getDiffEdges(delta, src);
1655 newsrcedges=Edge.taintAll(newsrcedges, taint);
1656 updateVarDelta(graph, delta, src, newsrcedges, null);
1658 effectsAnalysis.analyzeFlatFieldNode(newsrcedges, fd, node);
1660 if (!dst.getType().isPtr()) {
1661 if (mustProcess.contains(node)) {
1662 applyDiffs(graph, delta);
1666 /* First compute new objects we read fields of */
1667 MySet<Edge> allsrcedges=GraphManip.getEdges(graph, delta, src);
1668 MySet<Edge> edgesToAdd=GraphManip.diffDereference(delta, dst, allsrcedges, fd, node);
1669 /* Next compute new targets of fields */
1670 MySet<Edge> newfdedges=GraphManip.dereference(graph, delta, dst, newsrcedges, fd, node);
1672 /* Compute the union, and then the set of edges */
1673 Edge.mergeEdgesInto(edgesToAdd, newfdedges);
1675 /* Compute set of edges to remove */
1676 MySet<Edge> edgesToRemove=GraphManip.getDiffEdges(delta, dst);
1680 updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
1681 applyDiffs(graph, delta);
1687 void updateVarDelta(Graph graph, Delta delta, TempDescriptor tmp, MySet<Edge> edgestoAdd, MySet<Edge> edgestoRemove) {
1688 MySet<Edge> edgeAdd=delta.varedgeadd.get(tmp);
1689 MySet<Edge> edgeRemove=delta.varedgeremove.get(tmp);
1690 MySet<Edge> existingEdges=graph.getEdges(tmp);
1691 if (edgestoRemove!=null)
1692 for(Edge e : edgestoRemove) {
1693 //remove edge from delta
1696 //if the edge is already in the graph, add an explicit remove to the delta
1697 if (existingEdges.contains(e))
1698 delta.removeVarEdge(e);
1700 for(Edge e : edgestoAdd) {
1701 //Remove the edge from the remove set
1702 if (edgeRemove!=null)
1703 edgeRemove.remove(e);
1704 //Explicitly add it to the add set unless it is already in the graph
1705 if (typeUtil.isSuperorType(tmp.getType(), e.dst.getType())) {
1706 if (!existingEdges.contains(e)) {
1707 delta.addVarEdge(e);
1709 //See if the old edge subsumes the new one
1710 Edge olde=existingEdges.get(e);
1711 if (!olde.subsumes(e)) {
1712 delta.addVarEdge(olde.merge(e));
1719 void updateHeapDelta(Graph graph, Delta delta, MySet<Edge> edgestoAdd, MySet<Edge> edgestoRemove) {
1720 if (edgestoRemove!=null)
1721 for(Edge e : edgestoRemove) {
1722 AllocNode src=e.src;
1723 MySet<Edge> edgeAdd=delta.heapedgeadd.get(src);
1724 MySet<Edge> existingEdges=graph.getEdges(src);
1725 //remove edge from delta
1728 //if the edge is already in the graph, add an explicit remove to the delta
1729 if (existingEdges.contains(e)) {
1730 delta.removeHeapEdge(e);
1733 if (edgestoAdd!=null)
1734 for(Edge e : edgestoAdd) {
1735 AllocNode src=e.src;
1736 MySet<Edge> edgeRemove=delta.heapedgeremove.get(src);
1737 MySet<Edge> existingEdges=graph.getEdges(src);
1738 //Remove the edge from the remove set
1739 if (edgeRemove!=null)
1740 edgeRemove.remove(e);
1741 //Explicitly add it to the add set unless it is already in the graph
1742 if (!existingEdges.contains(e)) {
1743 delta.addHeapEdge(e);
1745 //See if the old edge subsumes the new one
1746 Edge olde=existingEdges.get(e);
1747 if (!olde.subsumes(e)) {
1748 delta.addHeapEdge(olde.merge(e));
1754 Delta processFlatNop(FlatNode node, Delta delta, Graph graph) {
1755 applyDiffs(graph, delta);
1759 Delta processNewNode(FlatNew node, Delta delta, Graph graph) {
1760 AllocNode summary=allocFactory.getAllocNode(node, true);
1761 AllocNode single=allocFactory.getAllocNode(node, false);
1762 TempDescriptor tmp=node.getDst();
1764 if (delta.getInit()) {
1765 /* We don't have to deal with summarization here... The
1766 * intuition is that this is the only place where we generate
1767 * nodes for this allocation site and this is the first time
1768 * we've analyzed this site */
1771 Edge e=new Edge(tmp, single);
1772 //Build new Edge set
1773 MySet<Edge> newedges=new MySet<Edge>();
1775 //Add it into the diffs
1776 delta.varedgeadd.put(tmp, newedges);
1777 //Remove the old edges
1778 MySet<Edge> oldedges=graph.getEdges(tmp);
1779 if (!oldedges.isEmpty())
1780 delta.varedgeremove.put(tmp, (MySet<Edge>)oldedges);
1781 //Note that we create a single node
1782 delta.addNodeAges.add(single);
1784 if (delta.addOldNodes.containsKey(single)||delta.baseOldNodes.containsKey(single)) {
1785 delta.addOldNodes.put(single, Boolean.FALSE);
1788 /* 1. Fix up the variable edge additions */
1789 for(Iterator<Map.Entry<TempDescriptor, MySet<Edge>>> entryIt=delta.varedgeadd.entrySet().iterator(); entryIt.hasNext(); ) {
1790 Map.Entry<TempDescriptor, MySet<Edge>> entry=entryIt.next();
1792 if (entry.getKey()==tmp) {
1793 /* Check if this is the tmp we overwrite */
1796 /* Otherwise, check if the target of the edge is changed... */
1797 summarizeSet(entry.getValue(), graph.varMap.get(entry.getKey()), single, summary);
1801 /* 2. Fix up the base variable edges */
1803 for(Iterator<Map.Entry<TempDescriptor, MySet<Edge>>> entryIt=delta.basevaredge.entrySet().iterator(); entryIt.hasNext(); ) {
1804 Map.Entry<TempDescriptor, MySet<Edge>> entry=entryIt.next();
1805 TempDescriptor entrytmp=entry.getKey();
1806 if (entrytmp==tmp) {
1807 /* Check is this is the tmp we overwrite, if so add to remove set */
1808 Util.relationUpdate(delta.varedgeremove, tmp, null, entry.getValue());
1809 } else if (graph.varMap.containsKey(entrytmp)) {
1810 /* Check if the target of the edge is changed */
1811 MySet<Edge> newset=(MySet<Edge>)entry.getValue().clone();
1812 MySet<Edge> removeset=shrinkSet(newset, graph.varMap.get(entrytmp), single, summary);
1813 Util.relationUpdate(delta.varedgeremove, entrytmp, newset, removeset);
1814 Util.relationUpdate(delta.varedgeadd, entrytmp, null, newset);
1816 /* Check if the target of the edge is changed */
1817 MySet<Edge> newset=(MySet<Edge>)entry.getValue().clone();
1818 MySet<Edge> removeset=shrinkSet(newset, graph.parent.varMap.get(entrytmp), single, summary);
1819 Util.relationUpdate(delta.varedgeremove, entrytmp, newset, removeset);
1820 Util.relationUpdate(delta.varedgeadd, entrytmp, null, newset);
1825 /* 3. Fix up heap edge additions */
1827 HashMap<AllocNode, MySet<Edge>> addheapedge=new HashMap<AllocNode, MySet<Edge>>();
1828 for(Iterator<Map.Entry<AllocNode, MySet<Edge>>> entryIt=delta.heapedgeadd.entrySet().iterator(); entryIt.hasNext(); ) {
1829 Map.Entry<AllocNode, MySet<Edge>> entry=entryIt.next();
1830 MySet<Edge> edgeset=entry.getValue();
1831 AllocNode allocnode=entry.getKey();
1832 if (allocnode==single) {
1834 summarizeSet(edgeset, graph.nodeMap.get(summary), single, summary);
1835 addheapedge.put(summary, edgeset);
1837 summarizeSet(edgeset, graph.nodeMap.get(allocnode), single, summary);
1841 /* Merge in diffs */
1843 for(Map.Entry<AllocNode, MySet<Edge>> entry : addheapedge.entrySet()) {
1844 AllocNode allocnode=entry.getKey();
1845 Util.relationUpdate(delta.heapedgeadd, allocnode, null, entry.getValue());
1848 /* 4. Fix up the base heap edges */
1850 for(Iterator<Map.Entry<AllocNode, MySet<Edge>>> entryIt=delta.baseheapedge.entrySet().iterator(); entryIt.hasNext(); ) {
1851 Map.Entry<AllocNode, MySet<Edge>> entry=entryIt.next();
1852 MySet<Edge> edgeset=entry.getValue();
1853 AllocNode allocnode=entry.getKey();
1854 if (allocnode==single) {
1857 AllocNode addnode=(allocnode==single)?summary:allocnode;
1859 MySet<Edge> newset=(MySet<Edge>)edgeset.clone();
1860 MySet<Edge> removeset=shrinkSet(newset, graph.nodeMap.get(addnode), single, summary);
1861 Util.relationUpdate(delta.heapedgeadd, addnode, null, newset);
1862 Util.relationUpdate(delta.heapedgeremove, allocnode, null, removeset);
1865 /* Update Node Ages...If the base or addNodeAges set contains a
1866 * single node, it now should also contain a summary node... No
1867 * need to generate a single node as that has already been
1869 if (delta.baseNodeAges.contains(single)||delta.addNodeAges.contains(single)) {
1870 delta.addNodeAges.add(summary);
1873 //Kill the old node if someone tries to add it
1874 if (delta.addOldNodes.containsKey(single)||delta.baseOldNodes.containsKey(single)) {
1875 delta.addOldNodes.put(single, Boolean.FALSE);
1879 //Apply incoming diffs to graph
1880 applyDiffs(graph, delta);
1885 /* This function builds a new edge set where oldnode is summarized into new node */
1887 void summarizeSet(MySet<Edge> edgeset, MySet<Edge> oldedgeset, AllocNode oldnode, AllocNode sumnode) {
1888 MySet<Edge> newSet=null;
1889 for(Iterator<Edge> edgeit=edgeset.iterator(); edgeit.hasNext(); ) {
1890 Edge e=edgeit.next();
1891 if (e.dst==oldnode||e.src==oldnode) {
1893 newSet=new MySet<Edge>();
1898 if (e.dst==oldnode) {
1901 if (e.src==oldnode) {
1904 if (oldedgeset==null||!oldedgeset.contains(e))
1909 edgeset.addAll(newSet);
1912 /* Shrinks the incoming set to just include rewritten values.
1913 * Returns a set of the original rewritten values */
1915 MySet<Edge> shrinkSet(MySet<Edge> edgeset, MySet<Edge> oldedgeset, AllocNode oldnode, AllocNode newnode) {
1916 MySet<Edge> newSet=null;
1917 MySet<Edge> removeSet=null;
1918 for(Iterator<Edge> edgeit=edgeset.iterator(); edgeit.hasNext(); ) {
1919 Edge e=edgeit.next();
1921 if (e.dst==oldnode||e.src==oldnode) {
1923 newSet=new MySet<Edge>();
1924 removeSet=new MySet<Edge>();
1933 if (oldedgeset==null||!oldedgeset.contains(e))
1938 edgeset.addAll(newSet);
1942 /* This function returns a completely new Delta... It is safe to
1945 Delta applyInitDelta(Delta delta, BBlock block) {
1946 //Apply delta to graph
1947 boolean newGraph=false;
1948 if (!bbgraphMap.containsKey(block)) {
1949 bbgraphMap.put(block, new Graph(null));
1952 Graph graph=bbgraphMap.get(block);
1955 Delta newdelta=new Delta(null, true);
1956 //Add in heap edges and throw away original diff
1958 for(Map.Entry<AllocNode, MySet<Edge>> entry : delta.heapedgeadd.entrySet()) {
1959 graph.nodeMap.put(entry.getKey(), new MySet<Edge>(entry.getValue()));
1961 //Add in var edges and throw away original diff
1962 Set<TempDescriptor> livetemps=bblivetemps.get(block);
1964 for(Map.Entry<TempDescriptor, MySet<Edge>> entry : delta.varedgeadd.entrySet()) {
1965 if (livetemps.contains(entry.getKey()))
1966 graph.varMap.put(entry.getKey(), new MySet<Edge>(entry.getValue()));
1968 //Record that this is initial set...
1969 graph.nodeAges.addAll(delta.addNodeAges);
1971 for(Map.Entry<AllocNode, Boolean> oldentry : delta.addOldNodes.entrySet()) {
1972 if (oldentry.getValue().booleanValue()) {
1973 graph.oldNodes.put(oldentry.getKey(), Boolean.TRUE);
1978 Delta newdelta=new Delta(null, false);
1979 //merge in heap edges and variables
1980 mergeHeapEdges(graph, delta, newdelta);
1981 mergeVarEdges(graph, delta, newdelta, block);
1982 mergeAges(graph, delta, newdelta);
1987 /* This function merges in the heap edges. It updates delta to be
1990 void mergeHeapEdges(Graph graph, Delta delta, Delta newdelta) {
1992 for(Map.Entry<AllocNode, MySet<Edge>> heapedge : delta.heapedgeadd.entrySet()) {
1993 AllocNode nsrc=heapedge.getKey();
1994 MySet<Edge> edges=heapedge.getValue();
1996 if (graph.backMap!=null) {
1997 for(Edge e : edges) {
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.nodeMap.containsKey(nsrc)) {
2005 graph.nodeMap.put(nsrc, new MySet<Edge>());
2007 MySet<Edge> dstedges=graph.nodeMap.get(nsrc);
2008 MySet<Edge> diffedges=new MySet<Edge>();
2009 for(Edge e : edges) {
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.baseheapedge.put(nsrc, diffedges);
2031 /* This function merges in the var edges. It updates delta to be
2034 void mergeVarEdges(Graph graph, Delta delta, Delta newdelta, BBlock block) {
2036 Set<TempDescriptor> livetemps=bblivetemps.get(block);
2038 for(Map.Entry<TempDescriptor, MySet<Edge>> varedge : delta.varedgeadd.entrySet()) {
2039 TempDescriptor tmpsrc=varedge.getKey();
2040 if (livetemps.contains(tmpsrc)) {
2041 MySet<Edge> edges=varedge.getValue();
2042 if (graph.backMap!=null) {
2043 for(Edge e : edges) {
2044 if (!graph.backMap.containsKey(e.dst))
2045 graph.backMap.put(e.dst, new MySet<Edge>());
2046 graph.backMap.get(e.dst).add(e);
2050 if (!graph.varMap.containsKey(tmpsrc)) {
2051 graph.varMap.put(tmpsrc, new MySet<Edge>());
2053 MySet<Edge> dstedges=graph.varMap.get(tmpsrc);
2054 MySet<Edge> diffedges=new MySet<Edge>();
2055 for(Edge e : edges) {
2056 if (!dstedges.contains(e)) {
2057 //We have a new edge
2061 Edge origedge=dstedges.get(e);
2062 if (!origedge.subsumes(e)) {
2063 Edge mergededge=origedge.merge(e);
2064 diffedges.add(mergededge);
2065 dstedges.add(mergededge);
2069 //Done with edge set...
2070 if (diffedges.size()>0) {
2072 newdelta.basevaredge.put(tmpsrc,diffedges);
2078 void mergeAges(Graph graph, Delta delta, Delta newDelta) {
2080 for(AllocNode node : delta.addNodeAges) {
2081 if (!graph.nodeAges.contains(node)) {
2082 graph.nodeAges.add(node);
2083 newDelta.baseNodeAges.add(node);
2086 for(Map.Entry<AllocNode, Boolean> oldentry : delta.addOldNodes.entrySet()) {
2087 AllocNode node=oldentry.getKey();
2088 boolean ispresent=oldentry.getValue().booleanValue();
2089 if (ispresent&&!graph.oldNodes.containsKey(node)) {
2090 graph.oldNodes.put(node, Boolean.TRUE);
2091 newDelta.baseOldNodes.put(node, Boolean.TRUE);
2099 public Alloc getCmdLineArgsAlloc() {
2102 public Alloc getCmdLineArgAlloc() {
2105 public Alloc getCmdLineArgBytesAlloc() {
2108 public Alloc getNewStringLiteralAlloc() {
2111 public Alloc getNewStringLiteralBytesAlloc() {
2115 public Set<Alloc> canPointToAt( TempDescriptor x,
2116 FlatNode programPoint ) {
2120 public Set<Alloc> canPointToAfter( TempDescriptor x,
2121 FlatNode programPoint ) {
2125 public Hashtable< Alloc, Set<Alloc> > canPointToAt( TempDescriptor x,
2127 FlatNode programPoint ) {
2131 public Hashtable< Alloc, Set<Alloc> > canPointToAtElement( TempDescriptor x,
2132 FlatNode programPoint ) {