1 package Analysis.Pointer;
5 import Analysis.Pointer.BasicBlock.BBlock;
6 import Analysis.Pointer.AllocFactory.AllocNode;
9 HashMap<FlatMethod, BasicBlock> blockMap;
10 HashMap<BBlock, Graph> bbgraphMap;
11 HashMap<FlatNode, Graph> graphMap;
14 AllocFactory allocFactory;
15 LinkedList<Delta> toprocess;
16 TempDescriptor returntmp;
18 public Pointer(State state, TypeUtil typeUtil) {
20 this.blockMap=new HashMap<FlatMethod, BasicBlock>();
21 this.bbgraphMap=new HashMap<BBlock, Graph>();
22 this.graphMap=new HashMap<FlatNode, Graph>();
23 this.typeUtil=typeUtil;
24 this.allocFactory=new AllocFactory(state, typeUtil);
25 this.toprocess=new LinkedList<Delta>();
26 ClassDescriptor stringcd=typeUtil.getClass(TypeUtil.ObjectClass);
27 this.returntmp=new TempDescriptor("RETURNVAL", stringcd);
30 public BasicBlock getBBlock(FlatMethod fm) {
31 if (!blockMap.containsKey(fm))
32 blockMap.put(fm, BasicBlock.getBBlock(fm, true));
33 return blockMap.get(fm);
36 Delta buildInitialContext() {
37 MethodDescriptor md=typeUtil.getMain();
38 FlatMethod fm=state.getMethodFlat(md);
39 BasicBlock bb=getBBlock(fm);
40 BBlock start=bb.getStart();
41 Delta delta=new Delta(start, true);
42 HashSet<Edge> arrayset=new HashSet<Edge>();
43 HashSet<Edge> varset=new HashSet<Edge>();
44 arrayset.add(new Edge(allocFactory.StringArray, null, allocFactory.Strings));
45 varset.add(new Edge(fm.getParameter(0), allocFactory.StringArray));
46 delta.heapedgeadd.put(allocFactory.StringArray, arrayset);
47 delta.varedgeadd.put(fm.getParameter(0), varset);
51 public void doAnalysis() {
52 toprocess.add(buildInitialContext());
54 while(!toprocess.isEmpty()) {
55 Delta delta=toprocess.remove();
56 BBlock bblock=delta.getBlock();
57 Vector<FlatNode> nodes=bblock.nodes();
59 //Build base graph for entrance to this basic block
60 delta=applyInitDelta(delta, bblock);
61 Graph graph=bbgraphMap.get(bblock);
64 //Compute delta at exit of each node
65 for(int i=0; i<nodes.size();i++) {
66 FlatNode currNode=nodes.get(i);
67 if (!graphMap.containsKey(currNode)) {
68 graphMap.put(currNode, new Graph(graph));
70 nodeGraph=graphMap.get(currNode);
71 delta=processNode(currNode, delta, nodeGraph);
73 generateFinalDelta(bblock, delta, nodeGraph);
77 void generateFinalDelta(BBlock bblock, Delta delta, Graph graph) {
78 Delta newDelta=new Delta(null, false);
79 if (delta.getInit()) {
80 //First compute the set of temps
81 HashSet<TempDescriptor> tmpSet=new HashSet<TempDescriptor>();
82 tmpSet.addAll(graph.varMap.keySet());
83 tmpSet.addAll(graph.parent.varMap.keySet());
85 //Next build the temp map part of the delta
86 for(TempDescriptor tmp:tmpSet) {
87 HashSet<Edge> edgeSet=new HashSet<Edge>();
89 if (graph.varMap.containsKey(tmp))
90 edgeSet.addAll(graph.varMap.get(tmp));
92 edgeSet.addAll(graph.parent.varMap.get(tmp));
93 newDelta.varedgeadd.put(tmp, edgeSet);
96 //Next compute the set of src allocnodes
97 HashSet<AllocNode> nodeSet=new HashSet<AllocNode>();
98 nodeSet.addAll(graph.nodeMap.keySet());
99 nodeSet.addAll(graph.parent.nodeMap.keySet());
101 for(AllocNode node:nodeSet) {
102 HashSet<Edge> edgeSet=new HashSet<Edge>();
104 if (graph.nodeMap.containsKey(node))
105 edgeSet.addAll(graph.nodeMap.get(node));
107 edgeSet.addAll(graph.parent.nodeMap.get(node));
108 newDelta.heapedgeadd.put(node, edgeSet);
111 /* We can break the old delta...it is done being used */
112 /* First we will build variable edges */
113 HashSet<TempDescriptor> tmpSet=new HashSet<TempDescriptor>();
114 tmpSet.addAll(delta.basevaredge.keySet());
115 tmpSet.addAll(delta.varedgeadd.keySet());
116 for(TempDescriptor tmp:tmpSet) {
117 /* Start with the new incoming edges */
118 HashSet<Edge> newbaseedge=delta.basevaredge.get(tmp);
119 /* Remove the remove set */
120 newbaseedge.removeAll(delta.varedgeremove.get(tmp));
121 /* Add in the new set*/
122 newbaseedge.addAll(delta.varedgeadd.get(tmp));
123 /* Store the results */
124 newDelta.varedgeadd.put(tmp, newbaseedge);
127 /* Next we build heap edges */
128 HashSet<AllocNode> nodeSet=new HashSet<AllocNode>();
129 nodeSet.addAll(delta.baseheapedge.keySet());
130 nodeSet.addAll(delta.heapedgeadd.keySet());
131 nodeSet.addAll(delta.heapedgeremove.keySet());
132 for(AllocNode node:nodeSet) {
133 /* Start with the new incoming edges */
134 HashSet<Edge> newheapedge=(HashSet<Edge>) delta.baseheapedge.get(node).clone();
135 /* Remove the remove set */
136 newheapedge.removeAll(delta.heapedgeremove.get(node));
137 /* Add in the add set */
138 newheapedge.addAll(delta.heapedgeadd.get(node));
139 newDelta.heapedgeadd.put(node, newheapedge);
141 /* Also need to subtract off some edges */
142 HashSet<Edge> removeset=delta.heapedgeremove.get(node);
143 /* Remove the newly created edges..no need to propagate a diff for those */
144 removeset.removeAll(delta.baseheapedge.get(node));
145 newDelta.heapedgeremove.put(node, removeset);
148 /* Now we need to propagate newdelta */
149 if (!newDelta.heapedgeadd.isEmpty()||!newDelta.heapedgeremove.isEmpty()||!newDelta.varedgeadd.isEmpty()) {
150 /* We have a delta to propagate */
151 Vector<BBlock> blockvector=bblock.next();
152 for(int i=0;i<blockvector.size();i++) {
154 newDelta.setBlock(blockvector.get(i));
155 toprocess.add(newDelta);
157 toprocess.add(newDelta.diffBlock(blockvector.get(i)));
163 Delta processNode(FlatNode node, Delta delta, Graph newgraph) {
164 switch(node.kind()) {
166 return processNewNode((FlatNew)node, delta, newgraph);
167 case FKind.FlatFieldNode:
168 case FKind.FlatElementNode:
169 return processFieldElementNode(node, delta, newgraph);
170 case FKind.FlatCastNode:
171 case FKind.FlatOpNode:
172 case FKind.FlatReturnNode:
173 return processCopyNode(node, delta, newgraph);
174 case FKind.FlatSetFieldNode:
175 case FKind.FlatSetElementNode:
176 return processSetFieldElementNode(node, delta, newgraph);
177 case FKind.FlatMethod:
179 return processFlatNop(node, delta, newgraph);
181 return processFlatCall((FlatCall) node, delta, newgraph);
182 case FKind.FlatSESEEnterNode:
183 case FKind.FlatSESEExitNode:
184 throw new Error("Unimplemented node:"+node);
186 throw new Error("Unrecognized node:"+node);
190 Delta processFlatCall(FlatCall fcall, Delta delta, Graph newgraph) {
191 Delta newDelta=new Delta(null, false);
193 if (delta.getInit()) {
194 HashSet<Edge> edgeset=new HashSet<Edge>();
195 HashSet<AllocNode> nodeset=new HashSet<AllocNode>();
196 HashSet<ClassDescriptor> targetSet=new HashSet<ClassDescriptor>();
197 Stack<AllocNode> tovisit=new Stack<AllocNode>();
198 TempDescriptor tmpthis=fc.getThis();
200 //Handle the this temp
202 HashSet<Edge> edges=GraphManip.getEdges(graph, delta, tmpthis);
203 newdelta.varedgeadd.put(tmpthis, (HashSet<Edge>) edges.clone());
204 edgeset.addAll(edges);
206 AllocNode dstnode=e.dst;
207 if (!nodeset.contains(dstnode)) {
208 TypeDescriptor type=dstnode.getType();
209 if (!type.isArray()) {
210 targetSet.add(type.getClassDesc());
212 //arrays don't have code
213 targetSet.add(typeUtil.getClass(TypeUtil.ObjectClass));
215 nodeset.add(dstnode);
216 tovisit.add(dstnode);
221 //Go through each temp
222 for(int i=0;i<fc.numArgs();i++) {
223 TempDescriptor tmp=fc.getArg(i);
224 HashSet<Edge> edges=GraphManip.getEdges(graph, delta, tmp);
225 newdelta.varedgeadd.put(tmp, (HashSet<Edge>) edges.clone());
226 edgeset.addAll(edges);
228 if (!nodeset.contains(e.dst)) {
235 //Traverse all reachable nodes
236 while(!tovisit.isEmpty()) {
237 AllocNode node=tovisit.pop();
238 HashSet<Edge> edges=GraphManip.getEdges(graph, delta, node);
239 newdelta.heapedgeadd.put(node, (HashSet<Edge>) edges.clone());
240 edgeset.addAll(edges);
242 if (!nodeset.contains(e.dst)) {
249 //Apply diffs to graph
250 applyDiffs(graph, delta);
253 //Apply diffs to graph
254 applyDiffs(graph, delta);
258 void applyDiffs(Graph graph, Delta delta) {
259 //Add hidden base edges
260 for(Map.Entry<AllocNode, HashSet<Edge>> e: delta.baseheapedge.entrySet()) {
261 AllocNode node=e.getKey();
262 HashSet<Edge> edges=e.getValue();
263 if (graph.nodeMap.containsKey(node)) {
264 HashSet<Edge> nodeEdges=graph.nodeMap.get(node);
265 nodeEdges.addAll(edges);
270 for(Map.Entry<AllocNode, HashSet<Edge>> e: delta.heapedgeremove.entrySet()) {
271 AllocNode node=e.getKey();
272 HashSet<Edge> edgestoremove=e.getValue();
273 if (graph.nodeMap.containsKey(node)) {
274 //Just apply diff to current map
275 graph.nodeMap.get(node).removeAll(edgestoremove);
277 //Generate diff from parent graph
278 HashSet<Edge> parentedges=graph.parent.nodeMap.get(node);
279 HashSet<Edge> newedgeset=Util.setSubtract(parentedges, edgestoremove);
280 graph.nodeMap.put(node, newedgeset);
285 for(Map.Entry<AllocNode, HashSet<Edge>> e: delta.heapedgeadd.entrySet()) {
286 AllocNode node=e.getKey();
287 HashSet<Edge> edgestoadd=e.getValue();
288 //If we have not done a subtract, then
289 if (!graph.nodeMap.containsKey(node)) {
290 //Copy the parent entry
291 graph.nodeMap.put(node, (HashSet<Edge>)graph.parent.nodeMap.get(node).clone());
293 graph.nodeMap.get(node).addAll(edgestoadd);
297 for(Map.Entry<TempDescriptor, HashSet<Edge>> e: delta.varedgeremove.entrySet()) {
298 TempDescriptor tmp=e.getKey();
299 HashSet<Edge> edgestoremove=e.getValue();
301 if (graph.varMap.containsKey(tmp)) {
302 //Just apply diff to current map
303 graph.varMap.get(tmp).removeAll(edgestoremove);
305 //Generate diff from parent graph
306 HashSet<Edge> parentedges=graph.parent.varMap.get(tmp);
307 HashSet<Edge> newedgeset=Util.setSubtract(parentedges, edgestoremove);
308 graph.varMap.put(tmp, newedgeset);
313 for(Map.Entry<TempDescriptor, HashSet<Edge>> e: delta.varedgeadd.entrySet()) {
314 TempDescriptor tmp=e.getKey();
315 HashSet<Edge> edgestoadd=e.getValue();
316 graph.varMap.put(tmp, (HashSet<Edge>) edgestoadd.clone());
320 Delta processSetFieldElementNode(FlatNode node, Delta delta, Graph graph) {
324 if (node.kind()==FKind.FlatSetElementNode) {
325 FlatSetElementNode fen=(FlatSetElementNode) node;
330 FlatSetFieldNode ffn=(FlatSetFieldNode) node;
335 if (delta.getInit()) {
336 HashSet<AllocNode> srcNodes=GraphManip.getNodes(graph, delta, src);
337 HashSet<AllocNode> dstNodes=GraphManip.getNodes(graph, delta, dst);
338 HashSet<Edge> edgesToAdd=GraphManip.genEdges(srcNodes, fd, dstNodes);
339 HashSet<Edge> edgesToRemove=null;
340 if (dstNodes.size()==1&&!dstNodes.iterator().next().isSummary()) {
341 /* Can do a strong update */
342 edgesToRemove=GraphManip.getEdges(graph, delta, dstNodes, fd);
345 updateHeapDelta(graph, delta, edgesToAdd, edgesToRemove);
346 applyDiffs(graph, delta);
348 /* First look at new sources */
349 HashSet<Edge> edgesToAdd=new HashSet<Edge>();
350 HashSet<AllocNode> newSrcNodes=GraphManip.getDiffNodes(delta, src);
351 HashSet<AllocNode> dstNodes=GraphManip.getDiffNodes(delta, dst);
352 edgesToAdd.addAll(GraphManip.genEdges(newSrcNodes, fd, dstNodes));
353 HashSet<AllocNode> newDstNodes=GraphManip.getDiffNodes(delta, dst);
354 HashSet<Edge> edgesToRemove=null;
355 if (newDstNodes.size()!=0) {
356 if (dstNodes.size()==1&&!dstNodes.iterator().next().isSummary()) {
357 /* Need to undo strong update */
358 if (graph.strongUpdateSet!=null) {
359 edgesToAdd.addAll(graph.strongUpdateSet);
360 graph.strongUpdateSet.clear();
362 } else if (dstNodes.size()==0&&newDstNodes.size()==1&&!newDstNodes.iterator().next().isSummary()&&graph.strongUpdateSet==null) {
363 edgesToRemove=GraphManip.getEdges(graph, delta, dstNodes, fd);
365 HashSet<AllocNode> srcNodes=GraphManip.getDiffNodes(delta, src);
366 edgesToAdd.addAll(GraphManip.genEdges(srcNodes, fd, newDstNodes));
369 updateHeapDelta(graph, delta, edgesToAdd, edgesToRemove);
370 applyDiffs(graph, delta);
375 Delta processCopyNode(FlatNode node, Delta delta, Graph graph) {
378 if (node.kind()==FKind.FlatOpNode) {
379 FlatOpNode fon=(FlatOpNode) node;
382 } else if (node.kind()==FKind.FlatReturnNode) {
383 FlatReturnNode frn=(FlatReturnNode)node;
384 src=frn.getReturnTemp();
387 FlatCastNode fcn=(FlatCastNode) node;
391 if (delta.getInit()) {
392 HashSet<AllocNode> srcnodes=GraphManip.getNodes(graph, delta, src);
393 HashSet<Edge> edgesToAdd=GraphManip.genEdges(src, srcnodes);
394 HashSet<Edge> edgesToRemove=GraphManip.getEdges(graph, delta, dst);
395 updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
396 applyDiffs(graph, delta);
398 /* First compute new src nodes */
399 HashSet<AllocNode> newSrcNodes=GraphManip.getDiffNodes(delta, src);
401 /* Compute the union, and then the set of edges */
402 HashSet<Edge> edgesToAdd=GraphManip.genEdges(src, newSrcNodes);
404 /* Compute set of edges to remove */
405 HashSet<Edge> edgesToRemove=GraphManip.getDiffEdges(delta, dst);
408 updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
409 applyDiffs(graph, delta);
414 Delta processFieldElementNode(FlatNode node, Delta delta, Graph graph) {
418 if (node.kind()==FKind.FlatElementNode) {
419 FlatElementNode fen=(FlatElementNode) node;
424 FlatFieldNode ffn=(FlatFieldNode) node;
429 if (delta.getInit()) {
430 HashSet<AllocNode> srcnodes=GraphManip.getNodes(graph, delta, src);
431 HashSet<AllocNode> fdnodes=GraphManip.getNodes(graph, delta, srcnodes, fd);
432 HashSet<Edge> edgesToAdd=GraphManip.genEdges(src, fdnodes);
433 HashSet<Edge> edgesToRemove=GraphManip.getEdges(graph, delta, dst);
434 updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
435 applyDiffs(graph, delta);
437 /* First compute new objects we read fields of */
438 HashSet<AllocNode> allsrcnodes=GraphManip.getNodes(graph, delta, src);
439 HashSet<AllocNode> difffdnodes=GraphManip.getDiffNodes(delta, allsrcnodes, fd);
440 /* Next compute new targets of fields */
441 HashSet<AllocNode> newsrcnodes=GraphManip.getDiffNodes(delta, src);
442 HashSet<AllocNode> newfdnodes=GraphManip.getNodes(graph, delta, newsrcnodes, fd);
443 /* Compute the union, and then the set of edges */
444 HashSet<AllocNode> newTargets=new HashSet<AllocNode>();
445 newTargets.addAll(newfdnodes);
446 newTargets.addAll(difffdnodes);
447 HashSet<Edge> edgesToAdd=GraphManip.genEdges(src, newTargets);
449 /* Compute set of edges to remove */
450 HashSet<Edge> edgesToRemove=GraphManip.getDiffEdges(delta, dst);
453 updateVarDelta(graph, delta, dst, edgesToAdd, edgesToRemove);
454 applyDiffs(graph, delta);
459 static void updateVarDelta(Graph graph, Delta delta, TempDescriptor tmp, HashSet<Edge> edgestoAdd, HashSet<Edge> edgestoRemove) {
460 HashSet<Edge> edgeAdd=delta.varedgeadd.get(tmp);
461 HashSet<Edge> edgeRemove=delta.varedgeremove.get(tmp);
462 HashSet<Edge> existingEdges=graph.getEdges(tmp);
463 for(Edge e: edgestoRemove) {
464 //remove edge from delta
466 //if the edge is already in the graph, add an explicit remove to the delta
467 if (existingEdges.contains(e))
470 for(Edge e: edgestoAdd) {
471 //Remove the edge from the remove set
472 edgeRemove.remove(e);
473 //Explicitly add it to the add set unless it is already in the graph
474 if (!existingEdges.contains(e))
479 static void updateHeapDelta(Graph graph, Delta delta, HashSet<Edge> edgestoAdd, HashSet<Edge> edgestoRemove) {
480 for(Edge e: edgestoRemove) {
482 HashSet<Edge> edgeAdd=delta.heapedgeadd.get(src);
483 HashSet<Edge> existingEdges=graph.getEdges(src);
484 //remove edge from delta
486 //if the edge is already in the graph, add an explicit remove to the delta
487 if (existingEdges.contains(e)) {
488 HashSet<Edge> edgeRemove=delta.heapedgeremove.get(src);
492 for(Edge e: edgestoAdd) {
494 HashSet<Edge> edgeRemove=delta.heapedgeremove.get(src);
495 HashSet<Edge> existingEdges=graph.getEdges(src);
496 //Remove the edge from the remove set
497 edgeRemove.remove(e);
498 //Explicitly add it to the add set unless it is already in the graph
499 if (!existingEdges.contains(e)) {
500 HashSet<Edge> edgeAdd=delta.heapedgeadd.get(src);
506 Delta processFlatNop(FlatNode node, Delta delta, Graph graph) {
507 applyDiffs(graph, delta);
511 Delta processNewNode(FlatNew node, Delta delta, Graph graph) {
512 AllocNode summary=allocFactory.getAllocNode(node, true);
513 AllocNode single=allocFactory.getAllocNode(node, false);
514 TempDescriptor tmp=node.getDst();
516 if (delta.getInit()) {
518 Edge e=new Edge(tmp, single);
520 HashSet<Edge> newedges=new HashSet<Edge>();
522 //Add it into the diffs
523 delta.varedgeadd.put(tmp, newedges);
524 //Remove the old edges
525 delta.varedgeremove.put(tmp, graph.getEdges(tmp));
526 //Apply incoming diffs to graph
527 applyDiffs(graph, delta);
529 /* 1. Fix up the variable edge additions */
531 for(Iterator<Map.Entry<TempDescriptor, HashSet<Edge>>> entryIt=delta.varedgeadd.entrySet().iterator();entryIt.hasNext();) {
532 Map.Entry<TempDescriptor, HashSet<Edge>> entry=entryIt.next();
534 if (entry.getKey()==tmp) {
535 /* Check if this is the tmp we overwrite */
538 /* Otherwise, check if the target of the edge is changed... */
539 rewriteSet(entry.getValue(), graph.varMap.get(entry.getKey()), single, summary);
543 /* 2. Fix up the base variable edges */
545 for(Iterator<Map.Entry<TempDescriptor, HashSet<Edge>>> entryIt=delta.basevaredge.entrySet().iterator();entryIt.hasNext();) {
546 Map.Entry<TempDescriptor, HashSet<Edge>> entry=entryIt.next();
547 TempDescriptor entrytmp=entry.getKey();
549 /* Check is this is the tmp we overwrite, if so add to remove set */
550 Util.relationUpdate(delta.varedgeremove, tmp, null, entry.getValue());
552 /* Check if the target of the edge is changed */
553 HashSet<Edge> newset=(HashSet<Edge>)entry.getValue().clone();
554 HashSet<Edge> removeset=shrinkSet(newset, graph.varMap.get(entrytmp), single, summary);
555 Util.relationUpdate(delta.varedgeremove, entrytmp, newset, removeset);
556 Util.relationUpdate(delta.varedgeadd, entrytmp, null, newset);
561 /* 3. Fix up heap edge additions */
563 HashMap<AllocNode, HashSet<Edge>> addheapedge=new HashMap<AllocNode, HashSet<Edge>>();
564 for(Iterator<Map.Entry<AllocNode, HashSet<Edge>>> entryIt=delta.heapedgeadd.entrySet().iterator();entryIt.hasNext();) {
565 Map.Entry<AllocNode, HashSet<Edge>> entry=entryIt.next();
566 HashSet<Edge> edgeset=entry.getValue();
567 AllocNode allocnode=entry.getKey();
568 if (allocnode==single) {
570 rewriteSet(edgeset, graph.nodeMap.get(summary), single, summary);
571 addheapedge.put(summary, edgeset);
573 rewriteSet(edgeset, graph.nodeMap.get(allocnode), single, summary);
579 for(Map.Entry<AllocNode, HashSet<Edge>> entry:addheapedge.entrySet()) {
580 AllocNode allocnode=entry.getKey();
581 Util.relationUpdate(delta.heapedgeadd, allocnode, null, entry.getValue());
584 /* 4. Fix up the base heap edges */
586 for(Iterator<Map.Entry<AllocNode, HashSet<Edge>>> entryIt=delta.baseheapedge.entrySet().iterator();entryIt.hasNext();) {
587 Map.Entry<AllocNode, HashSet<Edge>> entry=entryIt.next();
588 HashSet<Edge> edgeset=entry.getValue();
589 AllocNode allocnode=entry.getKey();
590 if (allocnode==single) {
593 AllocNode addnode=(allocnode==single)?summary:allocnode;
595 HashSet<Edge> newset=(HashSet<Edge>) edgeset.clone();
596 HashSet<Edge> removeset=shrinkSet(newset, graph.nodeMap.get(addnode), single, summary);
597 Util.relationUpdate(delta.heapedgeadd, addnode, null, newset);
598 Util.relationUpdate(delta.heapedgeremove, allocnode, null, removeset);
601 //Apply incoming diffs to graph
602 applyDiffs(graph, delta);
607 void rewriteSet(HashSet<Edge> edgeset, HashSet<Edge> oldedgeset, AllocNode oldnode, AllocNode newnode) {
608 HashSet<Edge> newSet=null;
609 for(Iterator<Edge> edgeit=edgeset.iterator();edgeit.hasNext();) {
610 Edge e=edgeit.next();
611 if (e.dst==oldnode||e.src==oldnode) {
613 newSet=new HashSet<Edge>();
620 if (oldedgeset==null||!oldedgeset.contains(e))
625 edgeset.addAll(newSet);
628 /* Shrinks the incoming set to just include rewritten values.
629 * Returns a set of the original rewritten values */
631 HashSet<Edge> shrinkSet(HashSet<Edge> edgeset, HashSet<Edge> oldedgeset, AllocNode oldnode, AllocNode newnode) {
632 HashSet<Edge> newSet=null;
633 HashSet<Edge> removeSet=null;
634 for(Iterator<Edge> edgeit=edgeset.iterator();edgeit.hasNext();) {
635 Edge e=edgeit.next();
637 if (e.dst==oldnode||e.src==oldnode) {
639 newSet=new HashSet<Edge>();
640 removeSet=new HashSet<Edge>();
643 removeSet.add(e.copy());
648 if (oldedgeset==null||!oldedgeset.contains(e))
653 edgeset.addAll(newSet);
657 Delta applyInitDelta(Delta delta, BBlock block) {
658 //Apply delta to graph
659 boolean newGraph=false;
660 if (!bbgraphMap.containsKey(block)) {
661 bbgraphMap.put(block, new Graph(null));
665 Graph graph=bbgraphMap.get(block);
668 newdelta=new Delta(null, true);
669 //Add in heap edges and throw away original diff
670 graph.nodeMap.putAll(delta.heapedgeadd);
671 //Add in var edges and throw away original diff
672 graph.varMap.putAll(delta.varedgeadd);
673 //Record that this is initial set...
675 newdelta=new Delta(null, false);
676 //merge in heap edges and variables
677 mergeHeapEdges(graph, delta, newdelta);
678 mergeVarEdges(graph, delta, newdelta);
679 //Record that this is a diff
680 newdelta.setInit(false);
685 /* This function merges in the heap edges. It updates delta to be
688 void mergeHeapEdges(Graph graph, Delta delta, Delta newdelta) {
690 for(Map.Entry<AllocNode, HashSet<Edge>> heapedge:delta.heapedgeadd.entrySet()) {
691 AllocNode nsrc=heapedge.getKey();
692 HashSet<Edge> edges=heapedge.getValue();
693 if (!graph.nodeMap.containsKey(nsrc)) {
694 graph.nodeMap.put(nsrc, new HashSet<Edge>());
696 HashSet<Edge> dstedges=graph.nodeMap.get(nsrc);
697 HashSet<Edge> diffedges=new HashSet<Edge>();
699 if (!dstedges.contains(e)) {
705 //Done with edge set...
706 if (diffedges.size()>0) {
708 newdelta.baseheapedge.put(nsrc, diffedges);
713 /* This function merges in the var edges. It updates delta to be
716 void mergeVarEdges(Graph graph, Delta delta, Delta newdelta) {
718 for(Map.Entry<TempDescriptor, HashSet<Edge>> varedge:delta.varedgeadd.entrySet()) {
719 TempDescriptor tmpsrc=varedge.getKey();
720 HashSet<Edge> edges=varedge.getValue();
721 if (!graph.varMap.containsKey(tmpsrc)) {
722 graph.varMap.put(tmpsrc, new HashSet<Edge>());
724 HashSet<Edge> dstedges=graph.varMap.get(tmpsrc);
725 HashSet<Edge> diffedges=new HashSet<Edge>();
727 if (!dstedges.contains(e)) {
733 //Done with edge set...
734 if (diffedges.size()>=0) {
736 newdelta.basevaredge.put(tmpsrc,diffedges);