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,-1);
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);
472 case FKind.FlatLiteralNode:
473 // jjenista - the heap analysis abstraction---when used to verify points-to
474 // analysis results against runtime pointers---will eventually need this to
475 // model that a flat literal node can result in a pointer to an implicitly
476 // allocated string. For now it will pass through like Pointer used to, but
477 // the checks versus runtime pointers will fail for string literals.
481 throw new Error("Unrecognized node:"+node + " of kind " + node.kind());
485 Delta processSESEEnterNode(FlatSESEEnterNode sese, Delta delta, Graph graph) {
487 return processFlatNop(sese, delta, graph);
488 if (delta.getInit()) {
489 removeInitTaints(null, delta, graph);
490 for (TempDescriptor tmp : sese.getInVarSet()) {
491 Taint taint=Taint.factory(sese, null, tmp, AllocFactory.dummySite, null, ReachGraph.predsEmpty);
492 MySet<Edge> edges=GraphManip.getEdges(graph, delta, tmp);
493 for(Edge e : edges) {
494 Edge newe=e.addTaint(taint);
495 delta.addVarEdge(newe);
499 removeDiffTaints(null, delta);
500 for (TempDescriptor tmp : sese.getInVarSet()) {
501 Taint taint=Taint.factory(sese, null, tmp, AllocFactory.dummySite, null, ReachGraph.predsEmpty);
502 MySet<Edge> edges=GraphManip.getDiffEdges(delta, tmp);
503 for(Edge e : edges) {
504 Edge newe=e.addTaint(taint);
505 delta.addVarEdge(newe);
511 applyDiffs(graph, delta);
515 private boolean isRecursive(FlatSESEEnterNode sese) {
516 MethodDescriptor md=sese.getmdEnclosing();
517 boolean isrecursive=callGraph.getCalleeSet(md).contains(md);
521 Delta processSESEExitNode(FlatSESEExitNode seseexit, Delta delta, Graph graph) {
523 return processFlatNop(seseexit, delta, graph);
524 FlatSESEEnterNode sese=seseexit.getFlatEnter();
525 //Strip Taints from this SESE
526 if (delta.getInit()) {
527 removeInitTaints(isRecursive(sese)?null:sese, delta, graph);
529 removeDiffTaints(isRecursive(sese)?null:sese, delta);
531 applyDiffs(graph, delta);
535 void removeDiffTaints(FlatSESEEnterNode sese, Delta delta) {
536 //Start with variable edges
538 MySet<Edge> edgestoadd=new MySet<Edge>();
539 MySet<Edge> edgestoremove=new MySet<Edge>();
541 //Process base diff edges
542 processEdgeMap(sese, delta.basevaredge, null, delta.varedgeremove, edgestoremove, edgestoadd);
543 //Process delta edges
544 processEdgeMap(sese, delta.varedgeadd, null, null, edgestoremove, edgestoadd);
545 for(Edge e : edgestoremove) {
546 delta.removeVarEdge(e);
548 for(Edge e : edgestoadd) {
555 MySet<Edge> edgestoadd=new MySet<Edge>();
556 MySet<Edge> edgestoremove=new MySet<Edge>();
558 //Process base diff edges
559 processEdgeMap(sese, delta.baseheapedge, null, delta.heapedgeremove, edgestoremove, edgestoadd);
560 //Process delta edges
561 processEdgeMap(sese, delta.heapedgeadd, null, null, edgestoremove, edgestoadd);
562 for(Edge e : edgestoremove) {
563 delta.removeHeapEdge(e);
565 for(Edge e : edgestoadd) {
566 delta.addHeapEdge(e);
571 void removeInitTaints(FlatSESEEnterNode sese, Delta delta, Graph graph) {
572 //Start with variable edges
574 MySet<Edge> edgestoadd=new MySet<Edge>();
575 MySet<Edge> edgestoremove=new MySet<Edge>();
577 //Process parent edges
578 processEdgeMap(sese, graph.parent.varMap, graph.varMap, delta.varedgeremove, edgestoremove, edgestoadd);
579 //Process graph edges
580 processEdgeMap(sese, graph.varMap, null, delta.varedgeremove, edgestoremove, edgestoadd);
581 //Process delta edges
582 processEdgeMap(sese, delta.varedgeadd, null, null, edgestoremove, edgestoadd);
583 for(Edge e : edgestoremove) {
584 delta.removeVarEdge(e);
586 for(Edge e : edgestoadd) {
593 MySet<Edge> edgestoadd=new MySet<Edge>();
594 MySet<Edge> edgestoremove=new MySet<Edge>();
596 //Process parent edges
597 processEdgeMap(sese, graph.parent.nodeMap, graph.nodeMap, delta.heapedgeremove, edgestoremove, edgestoadd);
598 //Process graph edges
599 processEdgeMap(sese, graph.nodeMap, null, delta.heapedgeremove, edgestoremove, edgestoadd);
600 //Process delta edges
601 processEdgeMap(sese, delta.heapedgeadd, null, null, edgestoremove, edgestoadd);
602 for(Edge e : edgestoremove) {
603 delta.removeHeapEdge(e);
605 for(Edge e : edgestoadd) {
606 delta.addHeapEdge(e);
611 void processEdgeMap(FlatSESEEnterNode sese, HashMap<?, MySet<Edge>> edgemap, HashMap<?, MySet<Edge>> childmap, HashMap<?, MySet<Edge>> removemap, MySet<Edge> edgestoremove, MySet<Edge> edgestoadd) {
612 for(Map.Entry<?, MySet<Edge>> entry:edgemap.entrySet()) {
613 //If the parent map exists and overrides this entry, skip it
614 if (childmap!=null&&childmap.containsKey(entry.getKey()))
616 for(Edge e:entry.getValue()) {
617 //check whether this edge has been removed
618 if (removemap!=null&&removemap.containsKey(entry.getKey())&&
619 removemap.get(entry.getKey()).contains(e))
622 TaintSet ts=e.getTaints();
624 //update non-null taint set
626 newts=Canonical.removeInContextTaintsNP(ts, sese);
627 if (newts!=null&&newts!=ts) {
628 edgestoremove.add(e);
629 edgestoadd.add(e.changeTaintSet(newts));
635 /* This function compute the edges for the this variable for a
636 * callee if it exists. */
638 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) {
639 //Handle the this temp
641 MySet<Edge> edges=(oldnodeset!=null)?GraphManip.getDiffEdges(delta, tmpthis):GraphManip.getEdges(graph, delta, tmpthis);
642 newDelta.varedgeadd.put(tmpthis, (MySet<Edge>)edges.clone());
643 edgeset.addAll(edges);
645 AllocNode dstnode=e.dst;
646 if (!nodeset.contains(dstnode)&&(oldnodeset==null||!oldnodeset.contains(dstnode))) {
647 TypeDescriptor type=dstnode.getType();
648 if (!type.isArray()) {
649 targetSet.add(type.getClassDesc());
651 //arrays don't have code
652 targetSet.add(typeUtil.getClass(TypeUtil.ObjectClass));
654 nodeset.add(dstnode);
655 tovisit.add(dstnode);
661 /* This function compute the edges for a call's parameters. */
663 void processParams(Graph graph, Delta delta, Delta newDelta, HashSet<AllocNode> nodeset, Stack<AllocNode> tovisit, MySet<Edge> edgeset, FlatCall fcall, boolean diff) {
664 //Go through each temp
665 for(int i=0; i<fcall.numArgs(); i++) {
666 TempDescriptor tmp=fcall.getArg(i);
667 MySet<Edge> edges=diff?GraphManip.getDiffEdges(delta, tmp):GraphManip.getEdges(graph, delta, tmp);
668 newDelta.varedgeadd.put(tmp, (MySet<Edge>)edges.clone());
669 edgeset.addAll(edges);
671 if (!nodeset.contains(e.dst)) {
679 /* This function computes the reachable nodes for a callee. */
681 void computeReachableNodes(Graph graph, Delta delta, Delta newDelta, HashSet<AllocNode> nodeset, Stack<AllocNode> tovisit, MySet<Edge> edgeset, HashSet<AllocNode> oldnodeset) {
682 while(!tovisit.isEmpty()) {
683 AllocNode node=tovisit.pop();
684 MySet<Edge> edges=GraphManip.getEdges(graph, delta, node);
685 if (!edges.isEmpty()) {
686 newDelta.heapedgeadd.put(node, Edge.makeOld(edges));
687 edgeset.addAll(edges);
688 for(Edge e : edges) {
689 if (!nodeset.contains(e.dst)&&(oldnodeset==null||!oldnodeset.contains(e.dst))) {
698 HashSet<MethodDescriptor> computeTargets(FlatCall fcall, Delta newDelta) {
699 TempDescriptor tmpthis=fcall.getThis();
700 MethodDescriptor md=fcall.getMethod();
701 HashSet<MethodDescriptor> targets=new HashSet<MethodDescriptor>();
702 if (md.isStatic()||fcall.getSuper()) {
706 for(Edge e : newDelta.varedgeadd.get(tmpthis)) {
707 AllocNode node=e.dst;
708 ClassDescriptor cd=node.getType().getClassDesc();
709 //Figure out exact method called and add to set
710 MethodDescriptor calledmd=cd.getCalledMethod(md);
711 targets.add(calledmd);
717 void fixMapping(FlatCall fcall, HashSet<MethodDescriptor> targets, MySet<Edge> oldedgeset, Delta newDelta, BBlock callblock, int callindex) {
718 Delta basedelta=null;
719 TempDescriptor tmpthis=fcall.getThis();
721 for(MethodDescriptor calledmd : targets) {
722 FlatMethod fm=state.getMethodFlat(calledmd);
723 boolean newmethod=false;
726 HashMap<TempDescriptor, TempDescriptor> tmpMap=new HashMap<TempDescriptor, TempDescriptor>();
729 tmpMap.put(tmpthis, fm.getParameter(offset++));
731 for(int i=0; i<fcall.numArgs(); i++) {
732 TempDescriptor tmp=fcall.getArg(i);
733 tmpMap.put(tmp,fm.getParameter(i+offset));
736 //Get basicblock for the method
737 BasicBlock block=getBBlock(fm);
740 if (!callMap.containsKey(fcall)) {
741 callMap.put(fcall, new HashSet<BBlock>());
744 Delta returnDelta=null;
745 if (!callMap.get(fcall).contains(block.getStart())) {
746 callMap.get(fcall).add(block.getStart());
750 if (!returnMap.containsKey(block.getExit())) {
751 returnMap.put(block.getExit(), new HashSet<PPoint>());
753 returnMap.get(block.getExit()).add(new PPoint(callblock, callindex));
755 if (bbgraphMap.containsKey(block.getExit())) {
756 //Need to push existing results to current node
757 if (returnDelta==null) {
758 returnDelta=new Delta(null, false);
759 Vector<FlatNode> exitblocknodes=block.getExit().nodes();
760 FlatExit fexit=(FlatExit)exitblocknodes.get(exitblocknodes.size()-1);
761 buildInitDelta(graphMap.get(fexit), returnDelta);
762 if (!returnDelta.heapedgeadd.isEmpty()||!returnDelta.heapedgeremove.isEmpty()||!returnDelta.varedgeadd.isEmpty()) {
763 returnDelta.setBlock(new PPoint(callblock, callindex));
764 toprocess.add(returnDelta);
767 if (!returnDelta.heapedgeadd.isEmpty()||!returnDelta.heapedgeremove.isEmpty()||!returnDelta.varedgeadd.isEmpty()) {
768 toprocess.add(returnDelta.diffBlock(new PPoint(callblock, callindex)));
774 if (oldedgeset==null) {
775 //First build of this graph
776 //Build and enqueue delta...safe to just use existing delta
777 Delta d=newDelta.changeParams(tmpMap, new PPoint(block.getStart()));
778 //System.out.println("AProcessing "+block.getStart().nodes.get(0).toString().replace(' ','_'));
781 } else if (newmethod) {
782 if (basedelta==null) {
783 basedelta=newDelta.buildBase(oldedgeset);
785 //Build and enqueue delta
786 Delta d=basedelta.changeParams(tmpMap, new PPoint(block.getStart()));
787 //System.out.println("BProcessing "+block.getStart().nodes.get(0).toString().replace(' ','_'));
791 //Build and enqueue delta
792 Delta d=newDelta.changeParams(tmpMap, new PPoint(block.getStart()));
793 //System.out.println("CProcessing "+block.getStart().nodes.get(0).toString().replace(' ','_'));
801 /* This function computes all edges that start outside of the callee
802 * context and go into the callee context */
804 void computeExternalEdges(Graph graph, Delta delta, HashSet<AllocNode> nodeset, HashSet<AllocNode> deltaset, MySet<Edge> externaledgeset) {
805 //Do heap edges first
806 HashSet<AllocNode> externalnodes=new HashSet<AllocNode>();
807 externalnodes.addAll(delta.baseheapedge.keySet());
808 externalnodes.addAll(delta.heapedgeadd.keySet());
809 externalnodes.addAll(delta.heapedgeremove.keySet());
810 //remove allinternal nodes
811 externalnodes.removeAll(nodeset);
812 for(AllocNode extNode : externalnodes) {
813 //Compute set of edges from given node
814 MySet<Edge> edges=new MySet<Edge>(delta.baseheapedge.get(extNode));
815 edges.removeAll(delta.heapedgeremove.get(extNode));
816 edges.addAll(delta.heapedgeadd.get(extNode));
818 for(Edge e : edges) {
819 if (nodeset.contains(e.dst))
820 externaledgeset.add(e);
825 HashSet<TempDescriptor> temps=new HashSet<TempDescriptor>();
826 temps.addAll(delta.basevaredge.keySet());
827 temps.addAll(delta.varedgeadd.keySet());
828 temps.addAll(delta.varedgeremove.keySet());
829 //remove allinternal nodes
830 temps.removeAll(nodeset);
832 for(TempDescriptor tmp : temps) {
833 //Compute set of edges from given node
834 MySet<Edge> edges=new MySet<Edge>(delta.basevaredge.get(tmp));
836 edges.removeAll(delta.varedgeremove.get(tmp));
837 edges.addAll(delta.varedgeadd.get(tmp));
839 for(Edge e : edges) {
840 if (nodeset.contains(e.dst))
841 externaledgeset.add(e);
846 /* This function removes the caller reachable edges from the
849 void removeEdges(Graph graph, Delta delta, HashSet<AllocNode> nodeset, MySet<Edge> edgeset, MySet<Edge> externaledgeset) {
850 //Want to remove the set of internal edges
851 for(Edge e : edgeset) {
852 if (e.src!=null&&!graph.callerEdges.contains(e)) {
853 delta.removeHeapEdge(e);
857 //Want to remove the set of external edges
858 for(Edge e : externaledgeset) {
859 //want to remove the set of internal edges
860 if (!graph.callerEdges.contains(e))
865 Delta processFlatCall(BBlock callblock, int callindex, FlatCall fcall, Delta delta, Graph graph) {
866 Delta newDelta=new Delta(null, false);
868 if (delta.getInit()) {
869 MySet<Edge> edgeset=new MySet<Edge>();
870 MySet<Edge> externaledgeset=new MySet<Edge>();
871 HashSet<AllocNode> nodeset=new HashSet<AllocNode>();
872 HashSet<ClassDescriptor> targetSet=new HashSet<ClassDescriptor>();
873 Stack<AllocNode> tovisit=new Stack<AllocNode>();
874 TempDescriptor tmpthis=fcall.getThis();
875 graph.callerEdges=new MySet<Edge>();
877 //Handle the this temp
878 processThisTargets(targetSet, graph, delta, newDelta, nodeset, tovisit, edgeset, tmpthis, null);
880 //Go through each temp
881 processParams(graph, delta, newDelta, nodeset, tovisit, edgeset, fcall, false);
883 //Traverse all reachable nodes
884 computeReachableNodes(graph, delta, newDelta, nodeset, tovisit, edgeset, null);
886 //Compute call targets
887 HashSet<MethodDescriptor> newtargets=computeTargets(fcall, newDelta);
890 fixMapping(fcall, newtargets, null, newDelta, callblock, callindex);
892 //Compute edges into region to splice out
893 computeExternalEdges(graph, delta, nodeset, null, externaledgeset);
895 //Splice out internal edges
896 removeEdges(graph, delta, nodeset, edgeset, externaledgeset);
898 //store data structures
899 graph.externalEdgeSet=externaledgeset;
900 graph.reachNode=nodeset;
901 graph.reachEdge=edgeset;
903 graph.callTargets=newtargets;
904 graph.callNodeAges=new HashSet<AllocNode>();
905 graph.callOldNodes=new HashSet<AllocNode>();
906 graph.callNewEdges=new HashMap<AllocNode, MySet<Edge>>();
907 graph.callOldEdges=new HashMap<Edge,MySet<Edge>>();
909 //Apply diffs to graph
910 applyDiffs(graph, delta, true);
912 MySet<Edge> edgeset=new MySet<Edge>();
913 MySet<Edge> externaledgeset=new MySet<Edge>();
914 HashSet<AllocNode> nodeset=new HashSet<AllocNode>();
915 MySet<Edge> oldedgeset=graph.reachEdge;
916 HashSet<AllocNode> oldnodeset=graph.reachNode;
918 HashSet<ClassDescriptor> targetSet=new HashSet<ClassDescriptor>();
919 Stack<AllocNode> tovisit=new Stack<AllocNode>();
920 TempDescriptor tmpthis=fcall.getThis();
921 //Fix up delta to get rid of unnecessary heap edge removals
922 for(Map.Entry<AllocNode, MySet<Edge>> entry : delta.heapedgeremove.entrySet()) {
923 for(Iterator<Edge> eit=entry.getValue().iterator(); eit.hasNext(); ) {
925 if (graph.callerEdges.contains(e))
930 //Fix up delta to get rid of unnecessary var edge removals
931 for(Map.Entry<TempDescriptor, MySet<Edge>> entry : delta.varedgeremove.entrySet()) {
932 for(Iterator<Edge> eit=entry.getValue().iterator(); eit.hasNext(); ) {
934 if (graph.callerEdges.contains(e))
939 //Handle the this temp
940 processThisTargets(targetSet, graph, delta, newDelta, nodeset, tovisit, edgeset, tmpthis, oldnodeset);
942 //Go through each temp
943 processParams(graph, delta, newDelta, nodeset, tovisit, edgeset, fcall, true);
944 //Go through each new heap edge that starts from old node
945 MySet<Edge> newedges=GraphManip.getDiffEdges(delta, oldnodeset);
946 edgeset.addAll(newedges);
947 for(Edge e : newedges) {
948 //Add new edges that start from old node to newDelta
950 if (!newDelta.heapedgeadd.containsKey(src)) {
951 newDelta.heapedgeadd.put(src, new MySet<Edge>());
953 newDelta.heapedgeadd.get(src).add(e.makeOld());
954 if (!nodeset.contains(e.dst)&&!oldnodeset.contains(e.dst)) {
960 //Traverse all reachable nodes
961 computeReachableNodes(graph, delta, newDelta, nodeset, tovisit, edgeset, oldnodeset);
962 //Compute call targets
963 HashSet<MethodDescriptor> newtargets=computeTargets(fcall, newDelta);
964 graph.callTargets.addAll(newtargets);
966 //add in new nodeset and edgeset
967 oldnodeset.addAll(nodeset);
968 oldedgeset.addAll(edgeset);
970 fixMapping(fcall, graph.callTargets, oldedgeset, newDelta, callblock, callindex);
971 //Compute edges into region to splice out
972 computeExternalEdges(graph, delta, oldnodeset, nodeset, externaledgeset);
974 //Splice out internal edges
975 removeEdges(graph, delta, nodeset, edgeset, externaledgeset);
977 //Add external edges back in
978 processCallExternal(graph, delta, externaledgeset);
980 //Move new edges that should be summarized
981 processSummarization(graph, delta);
983 Set<FlatSESEEnterNode> seseCallers=OoOJava?taskAnalysis.getTransitiveExecutingRBlocks(fcall):null;
984 //Check if the new nodes allow us to insert a new edge
985 for(AllocNode node : nodeset) {
986 if (graph.callNewEdges.containsKey(node)) {
987 for(Iterator<Edge> eit=graph.callNewEdges.get(node).iterator(); eit.hasNext(); ) {
989 if ((graph.callNodeAges.contains(e.src)||graph.reachNode.contains(e.src))&&
990 (graph.callNodeAges.contains(e.dst)||graph.reachNode.contains(e.dst))) {
991 Edge edgetoadd=e.copy(); //we need our own copy to modify below
993 if (seseCallers!=null)
994 edgetoadd.taintModify(seseCallers);
995 mergeCallEdge(graph, delta, edgetoadd);
1001 for(Edge e : edgeset) {
1002 //See if these edges would allow an old edge to be added
1003 if (graph.callOldEdges.containsKey(e)) {
1004 for(Edge adde : graph.callOldEdges.get(e)) {
1005 Edge ecopy=adde.copy();
1006 ecopy.statuspredicate=e.statuspredicate;
1007 mergeCallEdge(graph, delta, ecopy);
1012 //Add in new external edges
1013 graph.externalEdgeSet.addAll(externaledgeset);
1014 //Apply diffs to graph
1015 applyDiffs(graph, delta);
1020 void processSummarization(Graph graph, Delta delta) {
1021 processSumHeapEdgeSet(delta.heapedgeadd, delta, graph);
1022 processSumHeapEdgeSet(delta.baseheapedge, delta, graph);
1023 processSumVarEdgeSet(delta.varedgeadd, delta, graph);
1024 processSumVarEdgeSet(delta.basevaredge, delta, graph);
1027 void processSumVarEdgeSet(HashMap<TempDescriptor, MySet<Edge>> map, Delta delta, Graph graph) {
1028 MySet<Edge> edgestoadd=new MySet<Edge>();
1029 MySet<Edge> edgestoremove=new MySet<Edge>();
1030 for(Iterator<Map.Entry<TempDescriptor, MySet<Edge>>> eit=map.entrySet().iterator(); eit.hasNext(); ) {
1031 Map.Entry<TempDescriptor, MySet<Edge>> entry=eit.next();
1032 MySet<Edge> edgeset=entry.getValue();
1034 for(Edge e : edgeset) {
1036 boolean rewrite=false;
1037 if (copy.dst!=null&&graph.callNodeAges.contains(copy.dst)) {
1038 copy.dst=allocFactory.getAllocNode(copy.dst, true);
1042 edgestoremove.add(e);
1043 edgestoadd.add(copy);
1047 for(Edge e : edgestoremove) {
1048 if (!graph.callerEdges.contains(e))
1049 delta.removeVarEdge(e);
1051 for(Edge e : edgestoadd) {
1052 delta.addVarEdge(e);
1056 public Alloc getAllocationSiteFromFlatNew(FlatNew node) {
1057 return allocFactory.getAllocNode(node, false).getAllocSite();
1060 void processSumHeapEdgeSet(HashMap<AllocNode, MySet<Edge>> map, Delta delta, Graph graph) {
1061 MySet<Edge> edgestoadd=new MySet<Edge>();
1062 MySet<Edge> edgestoremove=new MySet<Edge>();
1063 for(Iterator<Map.Entry<AllocNode, MySet<Edge>>> eit=map.entrySet().iterator(); eit.hasNext(); ) {
1064 Map.Entry<AllocNode, MySet<Edge>> entry=eit.next();
1065 AllocNode node=entry.getKey();
1066 MySet<Edge> edgeset=entry.getValue();
1068 for(Edge e : edgeset) {
1070 boolean rewrite=false;
1071 if (copy.src!=null&&graph.callNodeAges.contains(copy.src)) {
1072 copy.src=allocFactory.getAllocNode(copy.src, true);
1075 if (copy.dst!=null&&graph.callNodeAges.contains(copy.dst)) {
1076 copy.dst=allocFactory.getAllocNode(copy.dst, true);
1080 edgestoremove.add(e);
1081 edgestoadd.add(copy);
1085 for(Edge e : edgestoremove) {
1086 if (!graph.callerEdges.contains(e))
1087 delta.removeHeapEdge(e);
1089 for(Edge e : edgestoadd) {
1090 delta.addHeapEdge(e);
1094 //Handle external edges
1095 void processCallExternal(Graph graph, Delta newDelta, MySet<Edge> externalEdgeSet) {
1096 //Add external edges in
1097 for(Edge e : externalEdgeSet) {
1098 //First did we age the source
1099 Edge newedge=e.copy();
1100 if (newedge.src!=null&&!e.src.isSummary()&&graph.callNodeAges.contains(e.src)) {
1101 AllocNode summaryNode=allocFactory.getAllocNode(newedge.src, true);
1102 newedge.src=summaryNode;
1105 if (graph.callNodeAges.contains(e.dst)&&!e.dst.isSummary()) {
1106 if (graph.callOldNodes.contains(e.dst)) {
1108 Edge copy=newedge.copy();
1109 mergeEdge(graph, newDelta, copy);
1111 //Now add summarized node
1112 newedge.dst=allocFactory.getAllocNode(newedge.dst, true);
1113 mergeCallEdge(graph, newDelta, newedge);
1115 //Add edge to single node
1116 mergeEdge(graph, newDelta, newedge);
1121 /* This function applies callee deltas to the caller heap. */
1123 Delta applyCallDelta(Delta delta, BBlock bblock) {
1124 Delta newDelta=new Delta(null, false);
1125 Vector<FlatNode> nodes=bblock.nodes();
1126 PPoint ppoint=delta.getBlock();
1127 FlatCall fcall=(FlatCall)nodes.get(ppoint.getIndex());
1128 Graph graph=graphMap.get(fcall);
1129 Graph oldgraph=(ppoint.getIndex()==0)?
1130 bbgraphMap.get(bblock):
1131 graphMap.get(nodes.get(ppoint.getIndex()-1));
1132 Set<FlatSESEEnterNode> seseCallers=OoOJava?taskAnalysis.getTransitiveExecutingRBlocks(fcall):null;
1134 //Age outside nodes if necessary
1135 for(Iterator<AllocNode> nodeit=delta.addNodeAges.iterator(); nodeit.hasNext(); ) {
1136 AllocNode node=nodeit.next();
1137 if (!graph.callNodeAges.contains(node)) {
1138 graph.callNodeAges.add(node);
1139 newDelta.addNodeAges.add(node);
1141 AllocNode summaryAdd=null;
1142 if (!graph.reachNode.contains(node)&&!node.isSummary()) {
1143 /* Need to age node in existing graph*/
1145 AllocNode summaryNode=allocFactory.getAllocNode(node, true);
1147 if (!graph.callNodeAges.contains(summaryNode)) {
1148 graph.callNodeAges.add(summaryNode);
1149 newDelta.addNodeAges.add(summaryNode);
1150 summaryAdd=summaryNode;
1152 summarizeInGraph(graph, newDelta, node);
1155 if (graph.callNewEdges.containsKey(node)) {
1156 for(Iterator<Edge> eit=graph.callNewEdges.get(node).iterator(); eit.hasNext(); ) {
1158 if ((graph.callNodeAges.contains(e.src)||graph.reachNode.contains(e.src))&&
1159 (graph.callNodeAges.contains(e.dst)||graph.reachNode.contains(e.dst))) {
1160 Edge edgetoadd=e.copy(); //we need our own copy to modify below
1162 if (seseCallers!=null)
1163 edgetoadd.taintModify(seseCallers);
1164 mergeCallEdge(graph, newDelta, edgetoadd);
1168 //do the summary node if we added that also...
1171 } while(node!=null);
1175 for(Map.Entry<AllocNode, MySet<Edge>> entry : delta.heapedgeadd.entrySet()) {
1176 for(Edge e : entry.getValue()) {
1177 boolean addedge=false;
1178 Edge edgetoadd=null;
1179 if (e.statuspredicate==Edge.NEW) {
1180 if ((graph.callNodeAges.contains(e.src)||graph.reachNode.contains(e.src))&&
1181 (graph.callNodeAges.contains(e.dst)||graph.reachNode.contains(e.dst))) {
1182 edgetoadd=e.copy(); //we need our own copy to modify below
1184 graph.addCallEdge(e);
1187 Edge[] edgeArray=e.makeStatus(allocFactory);
1189 int statuspredicate=0;
1190 for(int i=0; i<edgeArray.length; i++) {
1191 Edge origEdgeKey=edgeArray[i];
1192 if (graph.reachEdge.contains(origEdgeKey)) {
1193 Edge origEdge=graph.reachEdge.get(origEdgeKey);
1194 //copy the predicate
1195 statuspredicate=statuspredicate|origEdge.statuspredicate;
1197 if (!graph.callOldEdges.containsKey(origEdgeKey)) {
1198 graph.callOldEdges.put(origEdgeKey, new MySet<Edge>());
1200 if (graph.callOldEdges.get(origEdgeKey).contains(e)) {
1201 Edge olde=graph.callOldEdges.get(origEdgeKey).get(e);
1202 graph.callOldEdges.get(origEdgeKey).add(olde.merge(e));
1204 graph.callOldEdges.get(origEdgeKey).add(e);
1207 if (statuspredicate!=0) {
1209 newe.statuspredicate=statuspredicate;
1213 if (seseCallers!=null&&edgetoadd!=null)
1214 edgetoadd.taintModify(seseCallers);
1215 mergeCallEdge(graph, newDelta, edgetoadd);
1219 processCallExternal(graph, newDelta, graph.externalEdgeSet);
1221 //Add edge for return value
1222 if (fcall.getReturnTemp()!=null) {
1223 MySet<Edge> returnedge=delta.varedgeadd.get(returntmp);
1224 if (returnedge!=null)
1225 for(Edge e : returnedge) {
1226 //skip the edge if types don't allow it...
1227 if (!typeUtil.isSuperorType(fcall.getReturnTemp().getType(), e.dst.getType()))
1229 Edge newedge=e.copy();
1230 newedge.srcvar=fcall.getReturnTemp();
1231 if (seseCallers!=null)
1232 newedge.taintModify(seseCallers);
1233 mergeEdge(graph, newDelta, newedge);
1236 applyDiffs(graph, newDelta);
1240 public void mergeEdge(Graph graph, Delta newDelta, Edge edgetoadd) {
1241 if (edgetoadd!=null) {
1242 Edge match=graph.getMatch(edgetoadd);
1244 if (match==null||!match.subsumes(edgetoadd)) {
1245 Edge mergededge=edgetoadd.merge(match);
1246 newDelta.addEdge(mergededge);
1251 /* This is a call produced edge...need to remember this */
1253 public void mergeCallEdge(Graph graph, Delta newDelta, Edge edgetoadd) {
1254 if (edgetoadd!=null) {
1255 newDelta.addEdgeClear(edgetoadd);
1257 Edge match=graph.getMatch(edgetoadd);
1259 if (match==null||!match.subsumes(edgetoadd)) {
1260 Edge mergededge=edgetoadd.merge(match);
1261 newDelta.addEdge(mergededge);
1262 graph.callerEdges.add(mergededge);
1268 /* Summarizes out of context nodes in graph */
1269 void summarizeInGraph(Graph graph, Delta newDelta, AllocNode singleNode) {
1270 AllocNode summaryNode=allocFactory.getAllocNode(singleNode, true);
1272 //Handle outgoing heap edges
1273 MySet<Edge> edgeset=graph.getEdges(singleNode);
1275 for(Edge e : edgeset) {
1276 Edge rewrite=e.rewrite(singleNode, summaryNode);
1278 newDelta.removeHeapEdge(e);
1279 mergeCallEdge(graph, newDelta, rewrite);
1282 //Handle incoming edges
1283 MySet<Edge> backedges=graph.getBackEdges(singleNode);
1284 for(Edge e : backedges) {
1285 if (e.dst==singleNode) {
1286 //Need to get original edge so that predicate will be correct
1287 Edge match=graph.getMatch(e);
1289 Edge rewrite=match.rewrite(singleNode, summaryNode);
1290 newDelta.removeEdge(match);
1291 mergeCallEdge(graph, newDelta, rewrite);
1297 void applyDiffs(Graph graph, Delta delta) {
1298 applyDiffs(graph, delta, false);
1301 void applyDiffs(Graph graph, Delta delta, boolean genbackwards) {
1302 //build backwards map if requested
1303 if (genbackwards&&graph.backMap==null) {
1304 graph.backMap=new HashMap<AllocNode, MySet<Edge>>();
1305 if (graph.parent.backMap==null) {
1306 graph.parent.backMap=new HashMap<AllocNode, MySet<Edge>>();
1307 for(Map.Entry<AllocNode, MySet<Edge>> entry : graph.nodeMap.entrySet()) {
1308 for(Edge e : entry.getValue()) {
1309 if (!graph.parent.backMap.containsKey(e.dst))
1310 graph.parent.backMap.put(e.dst, new MySet<Edge>());
1311 graph.parent.backMap.get(e.dst).add(e);
1314 for(Map.Entry<TempDescriptor, MySet<Edge>> entry : graph.varMap.entrySet()) {
1315 for(Edge e : entry.getValue()) {
1316 if (!graph.parent.backMap.containsKey(e.dst))
1317 graph.parent.backMap.put(e.dst, new MySet<Edge>());
1318 graph.parent.backMap.get(e.dst).add(e);
1324 //Add hidden base edges
1325 for(Map.Entry<AllocNode, MySet<Edge>> e : delta.baseheapedge.entrySet()) {
1326 AllocNode node=e.getKey();
1327 MySet<Edge> edges=e.getValue();
1328 if (graph.nodeMap.containsKey(node)) {
1329 MySet<Edge> nodeEdges=graph.nodeMap.get(node);
1330 nodeEdges.addAll(edges);
1335 for(Map.Entry<AllocNode, MySet<Edge>> e : delta.heapedgeremove.entrySet()) {
1336 AllocNode node=e.getKey();
1337 MySet<Edge> edgestoremove=e.getValue();
1338 if (graph.nodeMap.containsKey(node)) {
1339 //Just apply diff to current map
1340 graph.nodeMap.get(node).removeAll(edgestoremove);
1342 //Generate diff from parent graph
1343 MySet<Edge> parentedges=graph.parent.nodeMap.get(node);
1344 if (parentedges!=null) {
1345 MySet<Edge> newedgeset=Util.setSubtract(parentedges, edgestoremove);
1346 graph.nodeMap.put(node, newedgeset);
1352 for(Map.Entry<AllocNode, MySet<Edge>> e : delta.heapedgeadd.entrySet()) {
1353 AllocNode node=e.getKey();
1354 MySet<Edge> edgestoadd=e.getValue();
1355 //If we have not done a subtract, then
1356 if (!graph.nodeMap.containsKey(node)) {
1357 //Copy the parent entry
1358 if (graph.parent.nodeMap.containsKey(node))
1359 graph.nodeMap.put(node, (MySet<Edge>)graph.parent.nodeMap.get(node).clone());
1361 graph.nodeMap.put(node, new MySet<Edge>());
1363 Edge.mergeEdgesInto(graph.nodeMap.get(node),edgestoadd);
1365 for(Edge eadd : edgestoadd) {
1366 if (!graph.backMap.containsKey(eadd.dst))
1367 graph.backMap.put(eadd.dst, new MySet<Edge>());
1368 graph.backMap.get(eadd.dst).add(eadd);
1374 for(Map.Entry<TempDescriptor, MySet<Edge>> e : delta.varedgeremove.entrySet()) {
1375 TempDescriptor tmp=e.getKey();
1376 MySet<Edge> edgestoremove=e.getValue();
1378 if (graph.varMap.containsKey(tmp)) {
1379 //Just apply diff to current map
1380 graph.varMap.get(tmp).removeAll(edgestoremove);
1381 } else if (graph.parent.varMap.containsKey(tmp)) {
1382 //Generate diff from parent graph
1383 MySet<Edge> parentedges=graph.parent.varMap.get(tmp);
1384 MySet<Edge> newedgeset=Util.setSubtract(parentedges, edgestoremove);
1385 graph.varMap.put(tmp, newedgeset);
1390 for(Map.Entry<TempDescriptor, MySet<Edge>> e : delta.varedgeadd.entrySet()) {
1391 TempDescriptor tmp=e.getKey();
1392 MySet<Edge> edgestoadd=e.getValue();
1393 if (graph.varMap.containsKey(tmp)) {
1394 Edge.mergeEdgesInto(graph.varMap.get(tmp), edgestoadd);
1395 } else if (graph.parent.varMap.containsKey(tmp)) {
1396 graph.varMap.put(tmp, new MySet<Edge>(graph.parent.varMap.get(tmp)));
1397 Edge.mergeEdgesInto(graph.varMap.get(tmp), edgestoadd);
1399 graph.varMap.put(tmp, (MySet<Edge>)edgestoadd.clone());
1401 for(Edge eadd : edgestoadd) {
1402 if (!graph.backMap.containsKey(eadd.dst))
1403 graph.backMap.put(eadd.dst, new MySet<Edge>());
1404 graph.backMap.get(eadd.dst).add(eadd);
1409 //Add node additions
1410 for(AllocNode node : delta.addNodeAges) {
1411 graph.nodeAges.add(node);
1414 for(Map.Entry<AllocNode, Boolean> nodeentry : delta.addOldNodes.entrySet()) {
1415 AllocNode node=nodeentry.getKey();
1416 Boolean ispresent=nodeentry.getValue();
1417 graph.oldNodes.put(node, ispresent);
1421 boolean isINACC(FlatNode node) {
1424 switch(node.kind()) {
1425 case FKind.FlatSetFieldNode: {
1426 FlatSetFieldNode n=(FlatSetFieldNode)node;
1427 return !accessible.isAccessible(n, n.getDst());
1430 case FKind.FlatSetElementNode: {
1431 FlatSetElementNode n=(FlatSetElementNode)node;
1432 return !accessible.isAccessible(n, n.getDst());
1435 case FKind.FlatFieldNode: {
1436 FlatFieldNode n=(FlatFieldNode)node;
1437 return !accessible.isAccessible(n, n.getSrc());
1440 case FKind.FlatElementNode: {
1441 FlatElementNode n=(FlatElementNode)node;
1442 return !accessible.isAccessible(n, n.getSrc());
1448 Delta processSetFieldElementNode(FlatNode node, Delta delta, Graph graph) {
1452 if (node.kind()==FKind.FlatSetElementNode) {
1453 FlatSetElementNode fen=(FlatSetElementNode) node;
1458 FlatSetFieldNode ffn=(FlatSetFieldNode) node;
1464 if (delta.getInit()) {
1465 MySet<Edge> dstEdges=GraphManip.getEdges(graph, delta, dst);
1467 if (OoOJava&&!accessible.isAccessible(node, dst)) {
1468 Taint dstStallTaint=Taint.factory(node, dst, AllocFactory.dummySite, null, ReachGraph.predsEmpty);
1469 dstEdges=Edge.taintAll(dstEdges, dstStallTaint);
1470 updateVarDelta(graph, delta, dst, dstEdges, null);
1473 effectsAnalysis.analyzeFlatSetFieldNode(dstEdges, fd, node);
1476 //Do nothing for non pointers
1477 if (!src.getType().isPtr()) {
1478 if (mustProcess.contains(node)) {
1479 applyDiffs(graph, delta);
1484 MySet<Edge> srcEdges=GraphManip.getEdges(graph, delta, src);
1485 if (OoOJava&&!accessible.isAccessible(node, src)) {
1486 Taint srcStallTaint=Taint.factory(node, src, AllocFactory.dummySite, null, ReachGraph.predsEmpty);
1487 srcEdges=Edge.taintAll(srcEdges, srcStallTaint);
1488 updateVarDelta(graph, delta, src, srcEdges, null);
1491 MySet<Edge> edgesToAdd=GraphManip.genEdges(dstEdges, fd, srcEdges);
1492 MySet<Edge> edgesToRemove=null;
1493 if (dstEdges.size()==1&&!dstEdges.iterator().next().dst.isSummary()&&fd!=null) {
1494 /* Can do a strong update */
1495 edgesToRemove=GraphManip.getEdges(graph, delta, dstEdges, fd);
1496 graph.strongUpdateSet=edgesToRemove;
1498 graph.strongUpdateSet=new MySet<Edge>();
1501 updateHeapDelta(graph, delta, edgesToAdd, edgesToRemove);
1502 applyDiffs(graph, delta);
1504 MySet<Edge> newDstEdges=GraphManip.getDiffEdges(delta, dst);
1506 if (OoOJava&&!accessible.isAccessible(node, dst)) {
1507 Taint dstStallTaint=Taint.factory(node, dst, AllocFactory.dummySite, null, ReachGraph.predsEmpty);
1508 newDstEdges=Edge.taintAll(newDstEdges, dstStallTaint);
1509 updateVarDelta(graph, delta, dst, newDstEdges, null);
1513 effectsAnalysis.analyzeFlatSetFieldNode(newDstEdges, fd, node);
1516 if (!src.getType().isPtr()) {
1517 if (mustProcess.contains(node)) {
1518 applyDiffs(graph, delta);
1523 /* Next look at new sources */
1525 MySet<Edge> edgesToAdd=new MySet<Edge>();
1526 MySet<Edge> newSrcEdges=GraphManip.getDiffEdges(delta, src);
1527 MySet<Edge> srcEdges=GraphManip.getEdges(graph, delta, src);
1528 HashSet<AllocNode> dstNodes=GraphManip.getNodes(graph, delta, dst);
1530 if (OoOJava&&!accessible.isAccessible(node, src)) {
1531 Taint srcStallTaint=Taint.factory(node, src, AllocFactory.dummySite, null, ReachGraph.predsEmpty);
1532 newSrcEdges=Edge.taintAll(newSrcEdges, srcStallTaint);
1533 updateVarDelta(graph, delta, src, newSrcEdges, null);
1536 MySet<Edge> edgesToRemove=null;
1537 if (newDstEdges.size()!=0) {
1538 if (dstNodes.size()>1&&!dstNodes.iterator().next().isSummary()&&fd!=null) {
1539 /* Need to undo strong update */
1540 if (graph.strongUpdateSet!=null) {
1541 edgesToAdd.addAll(graph.strongUpdateSet);
1542 graph.strongUpdateSet=null; //Prevent future strong updates
1544 } else if (dstNodes.size()==1&&newDstEdges.size()==1&&!newDstEdges.iterator().next().dst.isSummary()&&graph.strongUpdateSet!=null&&fd!=null) {
1545 edgesToRemove=GraphManip.getEdges(graph, delta, dstNodes, fd);
1546 graph.strongUpdateSet.addAll(edgesToRemove);
1548 Edge.mergeEdgesInto(edgesToAdd, GraphManip.genEdges(newDstEdges, fd, srcEdges));
1552 if (graph.strongUpdateSet!=null&&fd!=null) {
1553 MySet<Edge> otherEdgesToRemove=GraphManip.getDiffEdges(delta, dstNodes, fd);
1554 if (edgesToRemove!=null)
1555 edgesToRemove.addAll(otherEdgesToRemove);
1557 edgesToRemove=otherEdgesToRemove;
1558 graph.strongUpdateSet.addAll(otherEdgesToRemove);
1561 //Next look at new destinations
1562 Edge.mergeEdgesInto(edgesToAdd, GraphManip.genEdges(dstNodes, fd, newSrcEdges));
1565 updateHeapDelta(graph, delta, edgesToAdd, edgesToRemove);
1566 applyDiffs(graph, delta);
1571 Delta processCopyNode(FlatNode node, Delta delta, Graph graph) {
1575 if (node.kind()==FKind.FlatOpNode) {
1576 FlatOpNode fon=(FlatOpNode) node;
1579 } else if (node.kind()==FKind.FlatReturnNode) {
1580 FlatReturnNode frn=(FlatReturnNode)node;
1581 src=frn.getReturnTemp();
1583 if (src==null||!src.getType().isPtr()) {
1585 applyDiffs(graph, delta);
1589 FlatCastNode fcn=(FlatCastNode) node;
1593 if (delta.getInit()) {
1594 MySet<Edge> srcedges=GraphManip.getEdges(graph, delta, src);
1595 MySet<Edge> edgesToAdd=GraphManip.genEdges(dst, srcedges);
1596 MySet<Edge> edgesToRemove=GraphManip.getEdges(graph, delta, dst);
1597 updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
1598 applyDiffs(graph, delta);
1600 /* First compute new src nodes */
1601 MySet<Edge> newSrcEdges=GraphManip.getDiffEdges(delta, src);
1603 /* Compute the union, and then the set of edges */
1604 MySet<Edge> edgesToAdd=GraphManip.genEdges(dst, newSrcEdges);
1606 /* Compute set of edges to remove */
1607 MySet<Edge> edgesToRemove=GraphManip.getDiffEdges(delta, dst);
1610 updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
1611 applyDiffs(graph, delta);
1616 Delta processFieldElementNode(FlatNode node, Delta delta, Graph graph) {
1620 TaintSet taint=null;
1622 if (node.kind()==FKind.FlatElementNode) {
1623 FlatElementNode fen=(FlatElementNode) node;
1628 FlatFieldNode ffn=(FlatFieldNode) node;
1633 if (OoOJava&&!accessible.isAccessible(node, src)) {
1634 taint=TaintSet.factory(Taint.factory(node, src, AllocFactory.dummySite, null, ReachGraph.predsEmpty));
1637 //Do nothing for non pointers
1638 if (delta.getInit()) {
1639 MySet<Edge> srcedges=GraphManip.getEdges(graph, delta, src);
1642 srcedges=Edge.taintAll(srcedges, taint);
1643 updateVarDelta(graph, delta, src, srcedges, null);
1645 effectsAnalysis.analyzeFlatFieldNode(srcedges, fd, node);
1647 if (!dst.getType().isPtr()) {
1648 if (mustProcess.contains(node)) {
1649 applyDiffs(graph, delta);
1654 MySet<Edge> edgesToAdd=GraphManip.dereference(graph, delta, dst, srcedges, fd, node);
1655 MySet<Edge> edgesToRemove=GraphManip.getEdges(graph, delta, dst);
1657 updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
1658 applyDiffs(graph, delta);
1660 MySet<Edge> newsrcedges=GraphManip.getDiffEdges(delta, src);
1663 newsrcedges=Edge.taintAll(newsrcedges, taint);
1664 updateVarDelta(graph, delta, src, newsrcedges, null);
1666 effectsAnalysis.analyzeFlatFieldNode(newsrcedges, fd, node);
1668 if (!dst.getType().isPtr()) {
1669 if (mustProcess.contains(node)) {
1670 applyDiffs(graph, delta);
1674 /* First compute new objects we read fields of */
1675 MySet<Edge> allsrcedges=GraphManip.getEdges(graph, delta, src);
1676 MySet<Edge> edgesToAdd=GraphManip.diffDereference(delta, dst, allsrcedges, fd, node);
1677 /* Next compute new targets of fields */
1678 MySet<Edge> newfdedges=GraphManip.dereference(graph, delta, dst, newsrcedges, fd, node);
1680 /* Compute the union, and then the set of edges */
1681 Edge.mergeEdgesInto(edgesToAdd, newfdedges);
1683 /* Compute set of edges to remove */
1684 MySet<Edge> edgesToRemove=GraphManip.getDiffEdges(delta, dst);
1688 updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
1689 applyDiffs(graph, delta);
1695 void updateVarDelta(Graph graph, Delta delta, TempDescriptor tmp, MySet<Edge> edgestoAdd, MySet<Edge> edgestoRemove) {
1696 MySet<Edge> edgeAdd=delta.varedgeadd.get(tmp);
1697 MySet<Edge> edgeRemove=delta.varedgeremove.get(tmp);
1698 MySet<Edge> existingEdges=graph.getEdges(tmp);
1699 if (edgestoRemove!=null)
1700 for(Edge e : edgestoRemove) {
1701 //remove edge from delta
1704 //if the edge is already in the graph, add an explicit remove to the delta
1705 if (existingEdges.contains(e))
1706 delta.removeVarEdge(e);
1708 for(Edge e : edgestoAdd) {
1709 //Remove the edge from the remove set
1710 if (edgeRemove!=null)
1711 edgeRemove.remove(e);
1712 //Explicitly add it to the add set unless it is already in the graph
1713 if (typeUtil.isSuperorType(tmp.getType(), e.dst.getType())) {
1714 if (!existingEdges.contains(e)) {
1715 delta.addVarEdge(e);
1717 //See if the old edge subsumes the new one
1718 Edge olde=existingEdges.get(e);
1719 if (!olde.subsumes(e)) {
1720 delta.addVarEdge(olde.merge(e));
1727 void updateHeapDelta(Graph graph, Delta delta, MySet<Edge> edgestoAdd, MySet<Edge> edgestoRemove) {
1728 if (edgestoRemove!=null)
1729 for(Edge e : edgestoRemove) {
1730 AllocNode src=e.src;
1731 MySet<Edge> edgeAdd=delta.heapedgeadd.get(src);
1732 MySet<Edge> existingEdges=graph.getEdges(src);
1733 //remove edge from delta
1736 //if the edge is already in the graph, add an explicit remove to the delta
1737 if (existingEdges.contains(e)) {
1738 delta.removeHeapEdge(e);
1741 if (edgestoAdd!=null)
1742 for(Edge e : edgestoAdd) {
1743 AllocNode src=e.src;
1744 MySet<Edge> edgeRemove=delta.heapedgeremove.get(src);
1745 MySet<Edge> existingEdges=graph.getEdges(src);
1746 //Remove the edge from the remove set
1747 if (edgeRemove!=null)
1748 edgeRemove.remove(e);
1749 //Explicitly add it to the add set unless it is already in the graph
1750 if (!existingEdges.contains(e)) {
1751 delta.addHeapEdge(e);
1753 //See if the old edge subsumes the new one
1754 Edge olde=existingEdges.get(e);
1755 if (!olde.subsumes(e)) {
1756 delta.addHeapEdge(olde.merge(e));
1762 Delta processFlatNop(FlatNode node, Delta delta, Graph graph) {
1763 applyDiffs(graph, delta);
1767 Delta processNewNode(FlatNew node, Delta delta, Graph graph) {
1768 AllocNode summary=allocFactory.getAllocNode(node, true);
1769 AllocNode single=allocFactory.getAllocNode(node, false);
1770 TempDescriptor tmp=node.getDst();
1772 if (delta.getInit()) {
1773 /* We don't have to deal with summarization here... The
1774 * intuition is that this is the only place where we generate
1775 * nodes for this allocation site and this is the first time
1776 * we've analyzed this site */
1779 Edge e=new Edge(tmp, single);
1780 //Build new Edge set
1781 MySet<Edge> newedges=new MySet<Edge>();
1783 //Add it into the diffs
1784 delta.varedgeadd.put(tmp, newedges);
1785 //Remove the old edges
1786 MySet<Edge> oldedges=graph.getEdges(tmp);
1787 if (!oldedges.isEmpty())
1788 delta.varedgeremove.put(tmp, (MySet<Edge>)oldedges);
1789 //Note that we create a single node
1790 delta.addNodeAges.add(single);
1792 if (delta.addOldNodes.containsKey(single)||delta.baseOldNodes.containsKey(single)) {
1793 delta.addOldNodes.put(single, Boolean.FALSE);
1796 /* 1. Fix up the variable edge additions */
1797 for(Iterator<Map.Entry<TempDescriptor, MySet<Edge>>> entryIt=delta.varedgeadd.entrySet().iterator(); entryIt.hasNext(); ) {
1798 Map.Entry<TempDescriptor, MySet<Edge>> entry=entryIt.next();
1800 if (entry.getKey()==tmp) {
1801 /* Check if this is the tmp we overwrite */
1804 /* Otherwise, check if the target of the edge is changed... */
1805 summarizeSet(entry.getValue(), graph.varMap.get(entry.getKey()), single, summary);
1809 /* 2. Fix up the base variable edges */
1811 for(Iterator<Map.Entry<TempDescriptor, MySet<Edge>>> entryIt=delta.basevaredge.entrySet().iterator(); entryIt.hasNext(); ) {
1812 Map.Entry<TempDescriptor, MySet<Edge>> entry=entryIt.next();
1813 TempDescriptor entrytmp=entry.getKey();
1814 if (entrytmp==tmp) {
1815 /* Check is this is the tmp we overwrite, if so add to remove set */
1816 Util.relationUpdate(delta.varedgeremove, tmp, null, entry.getValue());
1817 } else if (graph.varMap.containsKey(entrytmp)) {
1818 /* Check if the target of the edge is changed */
1819 MySet<Edge> newset=(MySet<Edge>)entry.getValue().clone();
1820 MySet<Edge> removeset=shrinkSet(newset, graph.varMap.get(entrytmp), single, summary);
1821 Util.relationUpdate(delta.varedgeremove, entrytmp, newset, removeset);
1822 Util.relationUpdate(delta.varedgeadd, entrytmp, null, newset);
1824 /* Check if the target of the edge is changed */
1825 MySet<Edge> newset=(MySet<Edge>)entry.getValue().clone();
1826 MySet<Edge> removeset=shrinkSet(newset, graph.parent.varMap.get(entrytmp), single, summary);
1827 Util.relationUpdate(delta.varedgeremove, entrytmp, newset, removeset);
1828 Util.relationUpdate(delta.varedgeadd, entrytmp, null, newset);
1833 /* 3. Fix up heap edge additions */
1835 HashMap<AllocNode, MySet<Edge>> addheapedge=new HashMap<AllocNode, MySet<Edge>>();
1836 for(Iterator<Map.Entry<AllocNode, MySet<Edge>>> entryIt=delta.heapedgeadd.entrySet().iterator(); entryIt.hasNext(); ) {
1837 Map.Entry<AllocNode, MySet<Edge>> entry=entryIt.next();
1838 MySet<Edge> edgeset=entry.getValue();
1839 AllocNode allocnode=entry.getKey();
1840 if (allocnode==single) {
1842 summarizeSet(edgeset, graph.nodeMap.get(summary), single, summary);
1843 addheapedge.put(summary, edgeset);
1845 summarizeSet(edgeset, graph.nodeMap.get(allocnode), single, summary);
1849 /* Merge in diffs */
1851 for(Map.Entry<AllocNode, MySet<Edge>> entry : addheapedge.entrySet()) {
1852 AllocNode allocnode=entry.getKey();
1853 Util.relationUpdate(delta.heapedgeadd, allocnode, null, entry.getValue());
1856 /* 4. Fix up the base heap edges */
1858 for(Iterator<Map.Entry<AllocNode, MySet<Edge>>> entryIt=delta.baseheapedge.entrySet().iterator(); entryIt.hasNext(); ) {
1859 Map.Entry<AllocNode, MySet<Edge>> entry=entryIt.next();
1860 MySet<Edge> edgeset=entry.getValue();
1861 AllocNode allocnode=entry.getKey();
1862 if (allocnode==single) {
1865 AllocNode addnode=(allocnode==single)?summary:allocnode;
1867 MySet<Edge> newset=(MySet<Edge>)edgeset.clone();
1868 MySet<Edge> removeset=shrinkSet(newset, graph.nodeMap.get(addnode), single, summary);
1869 Util.relationUpdate(delta.heapedgeadd, addnode, null, newset);
1870 Util.relationUpdate(delta.heapedgeremove, allocnode, null, removeset);
1873 /* Update Node Ages...If the base or addNodeAges set contains a
1874 * single node, it now should also contain a summary node... No
1875 * need to generate a single node as that has already been
1877 if (delta.baseNodeAges.contains(single)||delta.addNodeAges.contains(single)) {
1878 delta.addNodeAges.add(summary);
1881 //Kill the old node if someone tries to add it
1882 if (delta.addOldNodes.containsKey(single)||delta.baseOldNodes.containsKey(single)) {
1883 delta.addOldNodes.put(single, Boolean.FALSE);
1887 //Apply incoming diffs to graph
1888 applyDiffs(graph, delta);
1893 /* This function builds a new edge set where oldnode is summarized into new node */
1895 void summarizeSet(MySet<Edge> edgeset, MySet<Edge> oldedgeset, AllocNode oldnode, AllocNode sumnode) {
1896 MySet<Edge> newSet=null;
1897 for(Iterator<Edge> edgeit=edgeset.iterator(); edgeit.hasNext(); ) {
1898 Edge e=edgeit.next();
1899 if (e.dst==oldnode||e.src==oldnode) {
1901 newSet=new MySet<Edge>();
1906 if (e.dst==oldnode) {
1909 if (e.src==oldnode) {
1912 if (oldedgeset==null||!oldedgeset.contains(e))
1917 edgeset.addAll(newSet);
1920 /* Shrinks the incoming set to just include rewritten values.
1921 * Returns a set of the original rewritten values */
1923 MySet<Edge> shrinkSet(MySet<Edge> edgeset, MySet<Edge> oldedgeset, AllocNode oldnode, AllocNode newnode) {
1924 MySet<Edge> newSet=null;
1925 MySet<Edge> removeSet=null;
1926 for(Iterator<Edge> edgeit=edgeset.iterator(); edgeit.hasNext(); ) {
1927 Edge e=edgeit.next();
1929 if (e.dst==oldnode||e.src==oldnode) {
1931 newSet=new MySet<Edge>();
1932 removeSet=new MySet<Edge>();
1941 if (oldedgeset==null||!oldedgeset.contains(e))
1946 edgeset.addAll(newSet);
1950 /* This function returns a completely new Delta... It is safe to
1953 Delta applyInitDelta(Delta delta, BBlock block) {
1954 //Apply delta to graph
1955 boolean newGraph=false;
1956 if (!bbgraphMap.containsKey(block)) {
1957 bbgraphMap.put(block, new Graph(null));
1960 Graph graph=bbgraphMap.get(block);
1963 Delta newdelta=new Delta(null, true);
1964 //Add in heap edges and throw away original diff
1966 for(Map.Entry<AllocNode, MySet<Edge>> entry : delta.heapedgeadd.entrySet()) {
1967 graph.nodeMap.put(entry.getKey(), new MySet<Edge>(entry.getValue()));
1969 //Add in var edges and throw away original diff
1970 Set<TempDescriptor> livetemps=bblivetemps.get(block);
1972 for(Map.Entry<TempDescriptor, MySet<Edge>> entry : delta.varedgeadd.entrySet()) {
1973 if (livetemps.contains(entry.getKey()))
1974 graph.varMap.put(entry.getKey(), new MySet<Edge>(entry.getValue()));
1976 //Record that this is initial set...
1977 graph.nodeAges.addAll(delta.addNodeAges);
1979 for(Map.Entry<AllocNode, Boolean> oldentry : delta.addOldNodes.entrySet()) {
1980 if (oldentry.getValue().booleanValue()) {
1981 graph.oldNodes.put(oldentry.getKey(), Boolean.TRUE);
1986 Delta newdelta=new Delta(null, false);
1987 //merge in heap edges and variables
1988 mergeHeapEdges(graph, delta, newdelta);
1989 mergeVarEdges(graph, delta, newdelta, block);
1990 mergeAges(graph, delta, newdelta);
1995 /* This function merges in the heap edges. It updates delta to be
1998 void mergeHeapEdges(Graph graph, Delta delta, Delta newdelta) {
2000 for(Map.Entry<AllocNode, MySet<Edge>> heapedge : delta.heapedgeadd.entrySet()) {
2001 AllocNode nsrc=heapedge.getKey();
2002 MySet<Edge> edges=heapedge.getValue();
2004 if (graph.backMap!=null) {
2005 for(Edge e : edges) {
2006 if (!graph.backMap.containsKey(e.dst))
2007 graph.backMap.put(e.dst, new MySet<Edge>());
2008 graph.backMap.get(e.dst).add(e);
2012 if (!graph.nodeMap.containsKey(nsrc)) {
2013 graph.nodeMap.put(nsrc, new MySet<Edge>());
2015 MySet<Edge> dstedges=graph.nodeMap.get(nsrc);
2016 MySet<Edge> diffedges=new MySet<Edge>();
2017 for(Edge e : edges) {
2018 if (!dstedges.contains(e)) {
2019 //We have a new edge
2023 Edge origedge=dstedges.get(e);
2024 if (!origedge.subsumes(e)) {
2025 Edge mergededge=origedge.merge(e);
2026 diffedges.add(mergededge);
2027 dstedges.add(mergededge);
2031 //Done with edge set...
2032 if (diffedges.size()>0) {
2034 newdelta.baseheapedge.put(nsrc, diffedges);
2039 /* This function merges in the var edges. It updates delta to be
2042 void mergeVarEdges(Graph graph, Delta delta, Delta newdelta, BBlock block) {
2044 Set<TempDescriptor> livetemps=bblivetemps.get(block);
2046 for(Map.Entry<TempDescriptor, MySet<Edge>> varedge : delta.varedgeadd.entrySet()) {
2047 TempDescriptor tmpsrc=varedge.getKey();
2048 if (livetemps.contains(tmpsrc)) {
2049 MySet<Edge> edges=varedge.getValue();
2050 if (graph.backMap!=null) {
2051 for(Edge e : edges) {
2052 if (!graph.backMap.containsKey(e.dst))
2053 graph.backMap.put(e.dst, new MySet<Edge>());
2054 graph.backMap.get(e.dst).add(e);
2058 if (!graph.varMap.containsKey(tmpsrc)) {
2059 graph.varMap.put(tmpsrc, new MySet<Edge>());
2061 MySet<Edge> dstedges=graph.varMap.get(tmpsrc);
2062 MySet<Edge> diffedges=new MySet<Edge>();
2063 for(Edge e : edges) {
2064 if (!dstedges.contains(e)) {
2065 //We have a new edge
2069 Edge origedge=dstedges.get(e);
2070 if (!origedge.subsumes(e)) {
2071 Edge mergededge=origedge.merge(e);
2072 diffedges.add(mergededge);
2073 dstedges.add(mergededge);
2077 //Done with edge set...
2078 if (diffedges.size()>0) {
2080 newdelta.basevaredge.put(tmpsrc,diffedges);
2086 void mergeAges(Graph graph, Delta delta, Delta newDelta) {
2088 for(AllocNode node : delta.addNodeAges) {
2089 if (!graph.nodeAges.contains(node)) {
2090 graph.nodeAges.add(node);
2091 newDelta.baseNodeAges.add(node);
2094 for(Map.Entry<AllocNode, Boolean> oldentry : delta.addOldNodes.entrySet()) {
2095 AllocNode node=oldentry.getKey();
2096 boolean ispresent=oldentry.getValue().booleanValue();
2097 if (ispresent&&!graph.oldNodes.containsKey(node)) {
2098 graph.oldNodes.put(node, Boolean.TRUE);
2099 newDelta.baseOldNodes.put(node, Boolean.TRUE);
2107 public Alloc getCmdLineArgsAlloc() {
2110 public Alloc getCmdLineArgAlloc() {
2113 public Alloc getCmdLineArgBytesAlloc() {
2116 public Alloc getNewStringLiteralAlloc() {
2119 public Alloc getNewStringLiteralBytesAlloc() {
2123 public Set<Alloc> canPointToAt( TempDescriptor x,
2124 FlatNode programPoint ) {
2128 public Hashtable< Alloc, Set<Alloc> > canPointToAt( TempDescriptor x,
2130 FlatNode programPoint ) {
2134 public Hashtable< Alloc, Set<Alloc> > canPointToAtElement( TempDescriptor x,
2135 FlatNode programPoint ) {
2139 public Set<Alloc> canPointToAfter( TempDescriptor x,
2140 FlatNode programPoint ) {
2144 public Hashtable< Alloc, Set<Alloc> > canPointToAfter( TempDescriptor x,
2146 FlatNode programPoint ) {
2150 public Hashtable< Alloc, Set<Alloc> > canPointToAfterElement( TempDescriptor x, // x[i]
2151 FlatNode programPoint ) {