1 package Analysis.OoOJava;
3 import java.io.BufferedWriter;
4 import java.io.FileWriter;
5 import java.io.IOException;
6 import java.util.Enumeration;
7 import java.util.HashSet;
8 import java.util.Hashtable;
9 import java.util.Iterator;
12 import java.util.Stack;
13 import java.util.Map.Entry;
15 import Analysis.ArrayReferencees;
16 import Analysis.Liveness;
17 import Analysis.CallGraph.CallGraph;
18 import Analysis.Disjoint.DisjointAnalysis;
19 import Analysis.Disjoint.Effect;
20 import Analysis.Disjoint.EffectsAnalysis;
21 import Analysis.Disjoint.Taint;
22 import Analysis.MLP.CodePlan;
23 import Analysis.MLP.SESEandAgePair;
24 import Analysis.MLP.VSTWrapper;
25 import Analysis.MLP.VarSrcTokTable;
26 import Analysis.MLP.VariableSourceToken;
28 import IR.MethodDescriptor;
33 import IR.Flat.FlatCall;
34 import IR.Flat.FlatEdge;
35 import IR.Flat.FlatElementNode;
36 import IR.Flat.FlatFieldNode;
37 import IR.Flat.FlatMethod;
38 import IR.Flat.FlatNew;
39 import IR.Flat.FlatNode;
40 import IR.Flat.FlatOpNode;
41 import IR.Flat.FlatSESEEnterNode;
42 import IR.Flat.FlatSESEExitNode;
43 import IR.Flat.FlatSetElementNode;
44 import IR.Flat.FlatSetFieldNode;
45 import IR.Flat.FlatWriteDynamicVarNode;
46 import IR.Flat.TempDescriptor;
48 public class OoOJavaAnalysis {
50 // data from the compiler
52 private TypeUtil typeUtil;
53 private CallGraph callGraph;
54 private RBlockRelationAnalysis rblockRel;
55 private RBlockStatusAnalysis rblockStatus;
56 private DisjointAnalysis disjointAnalysisTaints;
57 private DisjointAnalysis disjointAnalysisReach;
59 private Hashtable<FlatNode, Set<TempDescriptor>> livenessRootView;
60 private Hashtable<FlatNode, Set<TempDescriptor>> livenessVirtualReads;
61 private Hashtable<FlatNode, VarSrcTokTable> variableResults;
62 private Hashtable<FlatNode, Set<TempDescriptor>> notAvailableResults;
63 private Hashtable<FlatNode, CodePlan> codePlans;
65 private Hashtable<FlatSESEEnterNode, Set<TempDescriptor>> notAvailableIntoSESE;
67 private Hashtable<FlatEdge, FlatWriteDynamicVarNode> wdvNodesToSpliceIn;
69 // temporal data structures to track analysis progress.
70 static private int uniqueLockSetId = 0;
71 // mapping of a conflict graph to its compiled lock
72 private Hashtable<ConflictGraph, HashSet<SESELock>> conflictGraph2SESELock;
73 // mapping of a sese block to its conflict graph
74 private Hashtable<FlatNode, ConflictGraph> sese2conflictGraph;
76 public static int maxSESEage = -1;
78 public int getMaxSESEage() {
83 public CodePlan getCodePlan(FlatNode fn) {
84 CodePlan cp = codePlans.get(fn);
88 public Set<FlatNode> getNodesWithPlans() {
89 return codePlans.keySet();
92 public OoOJavaAnalysis(State state, TypeUtil typeUtil, CallGraph callGraph, Liveness liveness,
93 ArrayReferencees arrayReferencees) {
95 double timeStartAnalysis = (double) System.nanoTime();
98 this.typeUtil = typeUtil;
99 this.callGraph = callGraph;
100 this.maxSESEage = state.MLP_MAXSESEAGE;
102 livenessRootView = new Hashtable<FlatNode, Set<TempDescriptor>>();
103 livenessVirtualReads = new Hashtable<FlatNode, Set<TempDescriptor>>();
104 variableResults = new Hashtable<FlatNode, VarSrcTokTable>();
105 notAvailableResults = new Hashtable<FlatNode, Set<TempDescriptor>>();
106 codePlans = new Hashtable<FlatNode, CodePlan>();
107 wdvNodesToSpliceIn = new Hashtable<FlatEdge, FlatWriteDynamicVarNode>();
109 notAvailableIntoSESE = new Hashtable<FlatSESEEnterNode, Set<TempDescriptor>>();
111 sese2conflictGraph = new Hashtable<FlatNode, ConflictGraph>();
112 conflictGraph2SESELock = new Hashtable<ConflictGraph, HashSet<SESELock>>();
114 // add all methods transitively reachable from the
115 // source's main to set for analysis
116 MethodDescriptor mdSourceEntry = typeUtil.getMain();
117 FlatMethod fmMain = state.getMethodFlat(mdSourceEntry);
119 Set<MethodDescriptor> descriptorsToAnalyze = callGraph.getAllMethods(mdSourceEntry);
121 descriptorsToAnalyze.add(mdSourceEntry);
123 // 1st pass, find basic rblock relations & status
124 rblockRel = new RBlockRelationAnalysis(state, typeUtil, callGraph);
125 rblockStatus = new RBlockStatusAnalysis(state, typeUtil, callGraph, rblockRel);
127 // 2nd pass, liveness, in-set out-set (no virtual reads yet!)
128 Iterator<FlatSESEEnterNode> rootItr = rblockRel.getRootSESEs().iterator();
129 while (rootItr.hasNext()) {
130 FlatSESEEnterNode root = rootItr.next();
131 livenessAnalysisBackward(root, true, null);
134 // 3rd pass, variable analysis
135 Iterator<MethodDescriptor> methItr = descriptorsToAnalyze.iterator();
136 while (methItr.hasNext()) {
137 Descriptor d = methItr.next();
138 FlatMethod fm = state.getMethodFlat(d);
140 // starting from roots do a forward, fixed-point
141 // variable analysis for refinement and stalls
142 variableAnalysisForward(fm);
145 // 4th pass, compute liveness contribution from
146 // virtual reads discovered in variable pass
147 rootItr = rblockRel.getRootSESEs().iterator();
148 while (rootItr.hasNext()) {
149 FlatSESEEnterNode root = rootItr.next();
150 livenessAnalysisBackward(root, true, null);
153 // 5th pass, use disjointness with NO FLAGGED REGIONS
154 // to compute taints and effects
155 disjointAnalysisTaints =
156 new DisjointAnalysis(state, typeUtil, callGraph, liveness, arrayReferencees, null,
157 rblockRel, rblockStatus,
158 true ); // suppress output--this is an intermediate pass
160 // 6th pass, not available analysis FOR VARIABLES!
161 methItr = descriptorsToAnalyze.iterator();
162 while (methItr.hasNext()) {
163 Descriptor d = methItr.next();
164 FlatMethod fm = state.getMethodFlat(d);
166 // compute what is not available at every program
167 // point, in a forward fixed-point pass
168 notAvailableForward(fm);
171 // 7th pass, make conflict graph
172 // conflict graph is maintained by each parent sese,
174 Set<FlatSESEEnterNode> allSESEs=rblockRel.getAllSESEs();
175 for (Iterator iterator = allSESEs.iterator(); iterator.hasNext();) {
177 FlatSESEEnterNode parent = (FlatSESEEnterNode) iterator.next();
178 if (!parent.getIsLeafSESE()) {
180 EffectsAnalysis effectsAnalysis = disjointAnalysisTaints.getEffectsAnalysis();
181 ConflictGraph conflictGraph = sese2conflictGraph.get(parent);
182 if (conflictGraph == null) {
183 conflictGraph = new ConflictGraph(state);
186 Set<FlatSESEEnterNode> children = parent.getSESEChildren();
187 for (Iterator iterator2 = children.iterator(); iterator2.hasNext();) {
188 FlatSESEEnterNode child = (FlatSESEEnterNode) iterator2.next();
189 Hashtable<Taint, Set<Effect>> taint2Effects = effectsAnalysis.get(child);
190 conflictGraph.addLiveIn(taint2Effects);
191 if(taint2Effects!=null)
192 System.out.println("#add ="+taint2Effects+"currentSESE="+child+" into conflictGraph="+conflictGraph);
194 sese2conflictGraph.put(parent, conflictGraph);
199 Iterator descItr = disjointAnalysisTaints.getDescriptorsToAnalyze().iterator();
200 while (descItr.hasNext()) {
201 Descriptor d = (Descriptor) descItr.next();
202 FlatMethod fm = state.getMethodFlat(d);
204 makeConflictGraph(fm);
211 * Iterator iter = sese2conflictGraph.entrySet().iterator(); while
212 * (iter.hasNext()) { Entry e = (Entry) iter.next(); FlatNode fn =
213 * (FlatNode) e.getKey(); ConflictGraph conflictGraph = (ConflictGraph)
215 * System.out.println("---------------------------------------");
216 * System.out.println("CONFLICT GRAPH for " + fn); Set<String> keySet =
217 * conflictGraph.id2cn.keySet(); for (Iterator iterator = keySet.iterator();
218 * iterator.hasNext();) { String key = (String) iterator.next();
219 * ConflictNode node = conflictGraph.id2cn.get(key);
220 * System.out.println("key=" + key + " \n" + node.toStringAllEffects()); } }
223 // 8th pass, calculate all possible conflicts without using reachability
225 // and identify set of FlatNew that next disjoint reach. analysis should
227 Set<FlatNew> sitesToFlag = new HashSet<FlatNew>();
228 calculateConflicts(sitesToFlag, false);
232 // 9th pass, ask disjoint analysis to compute reachability
233 // for objects that may cause heap conflicts so the most
234 // efficient method to deal with conflict can be computed
237 disjointAnalysisReach =
238 new DisjointAnalysis(state, typeUtil, callGraph, liveness, arrayReferencees, sitesToFlag,
239 null, // don't do effects analysis again!
240 null // don't do effects analysis again!
242 // 10th pass, calculate conflicts with reachability info
243 calculateConflicts(null, true);
245 // 11th pass, compiling locks
248 // 12th pass, compute a plan for code injections
249 methItr = descriptorsToAnalyze.iterator();
250 while (methItr.hasNext()) {
251 Descriptor d = methItr.next();
252 FlatMethod fm = state.getMethodFlat(d);
253 codePlansForward(fm);
257 // splice new IR nodes into graph after all
258 // analysis passes are complete
259 Iterator spliceItr = wdvNodesToSpliceIn.entrySet().iterator();
260 while (spliceItr.hasNext()) {
261 Map.Entry me = (Map.Entry) spliceItr.next();
262 FlatWriteDynamicVarNode fwdvn = (FlatWriteDynamicVarNode) me.getValue();
263 fwdvn.spliceIntoIR();
266 if (state.OOODEBUG) {
269 disjointAnalysisTaints.getEffectsAnalysis().writeEffects("effects.txt");
270 writeConflictGraph();
271 } catch (IOException e) {
278 private void writeFile(Set<FlatNew> sitesToFlag) {
281 BufferedWriter bw = new BufferedWriter(new FileWriter("sitesToFlag.txt"));
283 for (Iterator iterator = sitesToFlag.iterator(); iterator.hasNext();) {
284 FlatNew fn = (FlatNew) iterator.next();
288 } catch (IOException e) {
294 private void livenessAnalysisBackward(FlatSESEEnterNode fsen, boolean toplevel,
295 Hashtable<FlatSESEExitNode, Set<TempDescriptor>> liveout) {
297 // start from an SESE exit, visit nodes in reverse up to
298 // SESE enter in a fixed-point scheme, where children SESEs
299 // should already be analyzed and therefore can be skipped
300 // because child SESE enter node has all necessary info
301 Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
304 flatNodesToVisit.add(fsen.getfmEnclosing().getFlatExit());
306 flatNodesToVisit.add(fsen.getFlatExit());
309 Hashtable<FlatNode, Set<TempDescriptor>> livenessResults =
310 new Hashtable<FlatNode, Set<TempDescriptor>>();
313 liveout = new Hashtable<FlatSESEExitNode, Set<TempDescriptor>>();
316 while (!flatNodesToVisit.isEmpty()) {
317 FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next();
318 flatNodesToVisit.remove(fn);
320 Set<TempDescriptor> prev = livenessResults.get(fn);
322 // merge sets from control flow joins
323 Set<TempDescriptor> u = new HashSet<TempDescriptor>();
324 for (int i = 0; i < fn.numNext(); i++) {
325 FlatNode nn = fn.getNext(i);
326 Set<TempDescriptor> s = livenessResults.get(nn);
332 Set<TempDescriptor> curr = liveness_nodeActions(fn, u, fsen, toplevel, liveout);
334 // if a new result, schedule backward nodes for analysis
335 if (!curr.equals(prev)) {
336 livenessResults.put(fn, curr);
338 // don't flow backwards past current SESE enter
339 if (!fn.equals(fsen)) {
340 for (int i = 0; i < fn.numPrev(); i++) {
341 FlatNode nn = fn.getPrev(i);
342 flatNodesToVisit.add(nn);
348 Set<TempDescriptor> s = livenessResults.get(fsen);
353 // remember liveness per node from the root view as the
354 // global liveness of variables for later passes to use
356 livenessRootView.putAll(livenessResults);
359 // post-order traversal, so do children first
360 Iterator<FlatSESEEnterNode> childItr = fsen.getChildren().iterator();
361 while (childItr.hasNext()) {
362 FlatSESEEnterNode fsenChild = childItr.next();
363 livenessAnalysisBackward(fsenChild, false, liveout);
367 private Set<TempDescriptor> liveness_nodeActions(FlatNode fn, Set<TempDescriptor> liveIn,
368 FlatSESEEnterNode currentSESE, boolean toplevel,
369 Hashtable<FlatSESEExitNode, Set<TempDescriptor>> liveout) {
372 case FKind.FlatSESEExitNode:
374 FlatSESEExitNode fsexn = (FlatSESEExitNode) fn;
375 if (!liveout.containsKey(fsexn)) {
376 liveout.put(fsexn, new HashSet<TempDescriptor>());
378 liveout.get(fsexn).addAll(liveIn);
380 // no break, sese exits should also execute default actions
383 // handle effects of statement in reverse, writes then reads
384 TempDescriptor[] writeTemps = fn.writesTemps();
385 for (int i = 0; i < writeTemps.length; ++i) {
386 liveIn.remove(writeTemps[i]);
389 FlatSESEExitNode fsexn = currentSESE.getFlatExit();
390 Set<TempDescriptor> livetemps = liveout.get(fsexn);
391 if (livetemps != null && livetemps.contains(writeTemps[i])) {
392 // write to a live out temp...
393 // need to put in SESE liveout set
394 currentSESE.addOutVar(writeTemps[i]);
399 TempDescriptor[] readTemps = fn.readsTemps();
400 for (int i = 0; i < readTemps.length; ++i) {
401 liveIn.add(readTemps[i]);
404 Set<TempDescriptor> virtualReadTemps = livenessVirtualReads.get(fn);
405 if (virtualReadTemps != null) {
406 liveIn.addAll(virtualReadTemps);
417 private void variableAnalysisForward(FlatMethod fm) {
419 Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
420 flatNodesToVisit.add(fm);
422 while (!flatNodesToVisit.isEmpty()) {
423 FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next();
424 flatNodesToVisit.remove(fn);
426 Stack<FlatSESEEnterNode> seseStack = rblockRel.getRBlockStacks(fm, fn);
427 assert seseStack != null;
429 VarSrcTokTable prev = variableResults.get(fn);
431 // merge sets from control flow joins
432 VarSrcTokTable curr = new VarSrcTokTable();
433 for (int i = 0; i < fn.numPrev(); i++) {
434 FlatNode nn = fn.getPrev(i);
435 VarSrcTokTable incoming = variableResults.get(nn);
436 curr.merge(incoming);
439 if (!seseStack.empty()) {
440 variable_nodeActions(fn, curr, seseStack.peek());
443 // if a new result, schedule forward nodes for analysis
444 if (!curr.equals(prev)) {
445 variableResults.put(fn, curr);
447 for (int i = 0; i < fn.numNext(); i++) {
448 FlatNode nn = fn.getNext(i);
449 flatNodesToVisit.add(nn);
455 private void variable_nodeActions(FlatNode fn, VarSrcTokTable vstTable,
456 FlatSESEEnterNode currentSESE) {
459 case FKind.FlatSESEEnterNode: {
460 FlatSESEEnterNode fsen = (FlatSESEEnterNode) fn;
461 assert fsen.equals(currentSESE);
463 vstTable.age(currentSESE);
464 vstTable.assertConsistency();
468 case FKind.FlatSESEExitNode: {
469 FlatSESEExitNode fsexn = (FlatSESEExitNode) fn;
470 FlatSESEEnterNode fsen = fsexn.getFlatEnter();
471 assert currentSESE.getChildren().contains(fsen);
473 // remap all of this child's children tokens to be
474 // from this child as the child exits
475 vstTable.remapChildTokens(fsen);
477 // liveness virtual reads are things that might be
478 // written by an SESE and should be added to the in-set
479 // anything virtually read by this SESE should be pruned
480 // of parent or sibling sources
481 Set<TempDescriptor> liveVars = livenessRootView.get(fn);
482 Set<TempDescriptor> fsenVirtReads =
483 vstTable.calcVirtReadsAndPruneParentAndSiblingTokens(fsen, liveVars);
484 Set<TempDescriptor> fsenVirtReadsOld = livenessVirtualReads.get(fn);
485 if (fsenVirtReadsOld != null) {
486 fsenVirtReads.addAll(fsenVirtReadsOld);
488 livenessVirtualReads.put(fn, fsenVirtReads);
490 // then all child out-set tokens are guaranteed
491 // to be filled in, so clobber those entries with
492 // the latest, clean sources
493 Iterator<TempDescriptor> outVarItr = fsen.getOutVarSet().iterator();
494 while (outVarItr.hasNext()) {
495 TempDescriptor outVar = outVarItr.next();
496 HashSet<TempDescriptor> ts = new HashSet<TempDescriptor>();
498 VariableSourceToken vst = new VariableSourceToken(ts, fsen, new Integer(0), outVar);
499 vstTable.remove(outVar);
502 vstTable.assertConsistency();
507 case FKind.FlatOpNode: {
508 FlatOpNode fon = (FlatOpNode) fn;
510 if (fon.getOp().getOp() == Operation.ASSIGN) {
511 TempDescriptor lhs = fon.getDest();
512 TempDescriptor rhs = fon.getLeft();
514 vstTable.remove(lhs);
516 Set<VariableSourceToken> forAddition = new HashSet<VariableSourceToken>();
518 Iterator<VariableSourceToken> itr = vstTable.get(rhs).iterator();
519 while (itr.hasNext()) {
520 VariableSourceToken vst = itr.next();
522 HashSet<TempDescriptor> ts = new HashSet<TempDescriptor>();
525 if (currentSESE.getChildren().contains(vst.getSESE())) {
526 // if the source comes from a child, copy it over
527 forAddition.add(new VariableSourceToken(ts, vst.getSESE(), vst.getAge(), vst
530 // otherwise, stamp it as us as the source
531 forAddition.add(new VariableSourceToken(ts, currentSESE, new Integer(0), lhs));
535 vstTable.addAll(forAddition);
537 // only break if this is an ASSIGN op node,
538 // otherwise fall through to default case
539 vstTable.assertConsistency();
544 // note that FlatOpNode's that aren't ASSIGN
545 // fall through to this default case
547 TempDescriptor[] writeTemps = fn.writesTemps();
548 if (writeTemps.length > 0) {
550 // for now, when writeTemps > 1, make sure
551 // its a call node, programmer enforce only
552 // doing stuff like calling a print routine
553 // assert writeTemps.length == 1;
554 if (writeTemps.length > 1) {
555 assert fn.kind() == FKind.FlatCall || fn.kind() == FKind.FlatMethod;
559 vstTable.remove(writeTemps[0]);
561 HashSet<TempDescriptor> ts = new HashSet<TempDescriptor>();
562 ts.add(writeTemps[0]);
564 vstTable.add(new VariableSourceToken(ts, currentSESE, new Integer(0), writeTemps[0]));
567 vstTable.assertConsistency();
574 private void notAvailableForward(FlatMethod fm) {
576 Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
577 flatNodesToVisit.add(fm);
579 while (!flatNodesToVisit.isEmpty()) {
580 FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next();
581 flatNodesToVisit.remove(fn);
583 Stack<FlatSESEEnterNode> seseStack = rblockRel.getRBlockStacks(fm, fn);
584 assert seseStack != null;
586 Set<TempDescriptor> prev = notAvailableResults.get(fn);
588 Set<TempDescriptor> curr = new HashSet<TempDescriptor>();
589 for (int i = 0; i < fn.numPrev(); i++) {
590 FlatNode nn = fn.getPrev(i);
591 Set<TempDescriptor> notAvailIn = notAvailableResults.get(nn);
592 if (notAvailIn != null) {
593 curr.addAll(notAvailIn);
597 if (!seseStack.empty()) {
598 notAvailable_nodeActions(fn, curr, seseStack.peek());
601 // if a new result, schedule forward nodes for analysis
602 if (!curr.equals(prev)) {
603 notAvailableResults.put(fn, curr);
605 for (int i = 0; i < fn.numNext(); i++) {
606 FlatNode nn = fn.getNext(i);
607 flatNodesToVisit.add(nn);
613 private void notAvailable_nodeActions(FlatNode fn, Set<TempDescriptor> notAvailSet,
614 FlatSESEEnterNode currentSESE) {
616 // any temps that are removed from the not available set
617 // at this node should be marked in this node's code plan
618 // as temps to be grabbed at runtime!
622 case FKind.FlatSESEEnterNode: {
623 FlatSESEEnterNode fsen = (FlatSESEEnterNode) fn;
624 assert fsen.equals(currentSESE);
626 // keep a copy of what's not available into the SESE
627 // and restore it at the matching exit node
628 Set<TempDescriptor> notAvailCopy = new HashSet<TempDescriptor>();
629 Iterator<TempDescriptor> tdItr = notAvailSet.iterator();
630 while (tdItr.hasNext()) {
631 notAvailCopy.add(tdItr.next());
633 notAvailableIntoSESE.put(fsen, notAvailCopy);
639 case FKind.FlatSESEExitNode: {
640 FlatSESEExitNode fsexn = (FlatSESEExitNode) fn;
641 FlatSESEEnterNode fsen = fsexn.getFlatEnter();
642 assert currentSESE.getChildren().contains(fsen);
644 notAvailSet.addAll(fsen.getOutVarSet());
646 Set<TempDescriptor> notAvailIn = notAvailableIntoSESE.get(fsen);
647 assert notAvailIn != null;
648 notAvailSet.addAll(notAvailIn);
653 case FKind.FlatMethod: {
657 case FKind.FlatOpNode: {
658 FlatOpNode fon = (FlatOpNode) fn;
660 if (fon.getOp().getOp() == Operation.ASSIGN) {
661 TempDescriptor lhs = fon.getDest();
662 TempDescriptor rhs = fon.getLeft();
664 // copy makes lhs same availability as rhs
665 if (notAvailSet.contains(rhs)) {
666 notAvailSet.add(lhs);
668 notAvailSet.remove(lhs);
671 // only break if this is an ASSIGN op node,
672 // otherwise fall through to default case
677 // note that FlatOpNode's that aren't ASSIGN
678 // fall through to this default case
680 TempDescriptor[] writeTemps = fn.writesTemps();
681 for (int i = 0; i < writeTemps.length; i++) {
682 TempDescriptor wTemp = writeTemps[i];
683 notAvailSet.remove(wTemp);
685 TempDescriptor[] readTemps = fn.readsTemps();
686 for (int i = 0; i < readTemps.length; i++) {
687 TempDescriptor rTemp = readTemps[i];
688 notAvailSet.remove(rTemp);
690 // if this variable has exactly one source, potentially
691 // get other things from this source as well
692 VarSrcTokTable vstTable = variableResults.get(fn);
694 VSTWrapper vstIfStatic = new VSTWrapper();
695 Integer srcType = vstTable.getRefVarSrcType(rTemp, currentSESE, vstIfStatic);
697 if (srcType.equals(VarSrcTokTable.SrcType_STATIC)) {
699 VariableSourceToken vst = vstIfStatic.vst;
701 Iterator<VariableSourceToken> availItr =
702 vstTable.get(vst.getSESE(), vst.getAge()).iterator();
704 // look through things that are also available from same source
705 while (availItr.hasNext()) {
706 VariableSourceToken vstAlsoAvail = availItr.next();
708 Iterator<TempDescriptor> refVarItr = vstAlsoAvail.getRefVars().iterator();
709 while (refVarItr.hasNext()) {
710 TempDescriptor refVarAlso = refVarItr.next();
712 // if a variable is available from the same source, AND it ALSO
713 // only comes from one statically known source, mark it available
714 VSTWrapper vstIfStaticNotUsed = new VSTWrapper();
715 Integer srcTypeAlso =
716 vstTable.getRefVarSrcType(refVarAlso, currentSESE, vstIfStaticNotUsed);
717 if (srcTypeAlso.equals(VarSrcTokTable.SrcType_STATIC)) {
718 notAvailSet.remove(refVarAlso);
730 private void codePlansForward(FlatMethod fm) {
732 // start from flat method top, visit every node in
733 // method exactly once
734 Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
735 flatNodesToVisit.add(fm);
737 Set<FlatNode> visited = new HashSet<FlatNode>();
739 while (!flatNodesToVisit.isEmpty()) {
740 Iterator<FlatNode> fnItr = flatNodesToVisit.iterator();
741 FlatNode fn = fnItr.next();
743 flatNodesToVisit.remove(fn);
746 Stack<FlatSESEEnterNode> seseStack = rblockRel.getRBlockStacks(fm, fn);
747 assert seseStack != null;
749 // use incoming results as "dot statement" or just
750 // before the current statement
751 VarSrcTokTable dotSTtable = new VarSrcTokTable();
752 for (int i = 0; i < fn.numPrev(); i++) {
753 FlatNode nn = fn.getPrev(i);
754 dotSTtable.merge(variableResults.get(nn));
757 // find dt-st notAvailableSet also
758 Set<TempDescriptor> dotSTnotAvailSet = new HashSet<TempDescriptor>();
759 for (int i = 0; i < fn.numPrev(); i++) {
760 FlatNode nn = fn.getPrev(i);
761 Set<TempDescriptor> notAvailIn = notAvailableResults.get(nn);
762 if (notAvailIn != null) {
763 dotSTnotAvailSet.addAll(notAvailIn);
767 Set<TempDescriptor> dotSTlive = livenessRootView.get(fn);
769 if (!seseStack.empty()) {
770 codePlans_nodeActions(fn, dotSTlive, dotSTtable, dotSTnotAvailSet, seseStack.peek());
773 for (int i = 0; i < fn.numNext(); i++) {
774 FlatNode nn = fn.getNext(i);
776 if (!visited.contains(nn)) {
777 flatNodesToVisit.add(nn);
783 private void codePlans_nodeActions(FlatNode fn, Set<TempDescriptor> liveSetIn,
784 VarSrcTokTable vstTableIn, Set<TempDescriptor> notAvailSetIn, FlatSESEEnterNode currentSESE) {
786 CodePlan plan = new CodePlan(currentSESE);
790 case FKind.FlatSESEEnterNode: {
791 FlatSESEEnterNode fsen = (FlatSESEEnterNode) fn;
792 assert fsen.equals(currentSESE);
794 // track the source types of the in-var set so generated
795 // code at this SESE issue can compute the number of
796 // dependencies properly
797 Iterator<TempDescriptor> inVarItr = fsen.getInVarSet().iterator();
798 while (inVarItr.hasNext()) {
799 TempDescriptor inVar = inVarItr.next();
801 // when we get to an SESE enter node we change the
802 // currentSESE variable of this analysis to the
803 // child that is declared by the enter node, so
804 // in order to classify in-vars correctly, pass
805 // the parent SESE in--at other FlatNode types just
806 // use the currentSESE
807 VSTWrapper vstIfStatic = new VSTWrapper();
808 Integer srcType = vstTableIn.getRefVarSrcType(inVar, fsen.getParent(), vstIfStatic);
810 // the current SESE needs a local space to track the dynamic
811 // variable and the child needs space in its SESE record
812 if (srcType.equals(VarSrcTokTable.SrcType_DYNAMIC)) {
813 fsen.addDynamicInVar(inVar);
814 fsen.getParent().addDynamicVar(inVar);
816 } else if (srcType.equals(VarSrcTokTable.SrcType_STATIC)) {
817 fsen.addStaticInVar(inVar);
818 VariableSourceToken vst = vstIfStatic.vst;
819 fsen.putStaticInVar2src(inVar, vst);
820 fsen.addStaticInVarSrc(new SESEandAgePair(vst.getSESE(), vst.getAge()));
822 assert srcType.equals(VarSrcTokTable.SrcType_READY);
823 fsen.addReadyInVar(inVar);
830 case FKind.FlatSESEExitNode: {
831 FlatSESEExitNode fsexn = (FlatSESEExitNode) fn;
835 case FKind.FlatOpNode: {
836 FlatOpNode fon = (FlatOpNode) fn;
838 if (fon.getOp().getOp() == Operation.ASSIGN) {
839 TempDescriptor lhs = fon.getDest();
840 TempDescriptor rhs = fon.getLeft();
842 // if this is an op node, don't stall, copy
843 // source and delay until we need to use value
845 // ask whether lhs and rhs sources are dynamic, static, etc.
846 VSTWrapper vstIfStatic = new VSTWrapper();
847 Integer lhsSrcType = vstTableIn.getRefVarSrcType(lhs, currentSESE, vstIfStatic);
848 Integer rhsSrcType = vstTableIn.getRefVarSrcType(rhs, currentSESE, vstIfStatic);
850 if (rhsSrcType.equals(VarSrcTokTable.SrcType_DYNAMIC)) {
851 // if rhs is dynamic going in, lhs will definitely be dynamic
852 // going out of this node, so track that here
853 plan.addDynAssign(lhs, rhs);
854 currentSESE.addDynamicVar(lhs);
855 currentSESE.addDynamicVar(rhs);
857 } else if (lhsSrcType.equals(VarSrcTokTable.SrcType_DYNAMIC)) {
858 // otherwise, if the lhs is dynamic, but the rhs is not, we
859 // need to update the variable's dynamic source as "current SESE"
860 plan.addDynAssign(lhs);
863 // only break if this is an ASSIGN op node,
864 // otherwise fall through to default case
869 // note that FlatOpNode's that aren't ASSIGN
870 // fall through to this default case
873 // a node with no live set has nothing to stall for
874 if (liveSetIn == null) {
878 TempDescriptor[] readarray = fn.readsTemps();
879 for (int i = 0; i < readarray.length; i++) {
880 TempDescriptor readtmp = readarray[i];
882 // ignore temps that are definitely available
883 // when considering to stall on it
884 if (!notAvailSetIn.contains(readtmp)) {
888 // check the source type of this variable
889 VSTWrapper vstIfStatic = new VSTWrapper();
890 Integer srcType = vstTableIn.getRefVarSrcType(readtmp, currentSESE, vstIfStatic);
892 if (srcType.equals(VarSrcTokTable.SrcType_DYNAMIC)) {
893 // 1) It is not clear statically where this variable will
894 // come from, so dynamically we must keep track
895 // along various control paths, and therefore when we stall,
896 // just stall for the exact thing we need and move on
897 plan.addDynamicStall(readtmp);
898 currentSESE.addDynamicVar(readtmp);
900 } else if (srcType.equals(VarSrcTokTable.SrcType_STATIC)) {
901 // 2) Single token/age pair: Stall for token/age pair, and copy
902 // all live variables with same token/age pair at the same
903 // time. This is the same stuff that the notavaialable analysis
904 // marks as now available.
905 VariableSourceToken vst = vstIfStatic.vst;
907 Iterator<VariableSourceToken> availItr =
908 vstTableIn.get(vst.getSESE(), vst.getAge()).iterator();
910 while (availItr.hasNext()) {
911 VariableSourceToken vstAlsoAvail = availItr.next();
913 // only grab additional stuff that is live
914 Set<TempDescriptor> copySet = new HashSet<TempDescriptor>();
916 Iterator<TempDescriptor> refVarItr = vstAlsoAvail.getRefVars().iterator();
917 while (refVarItr.hasNext()) {
918 TempDescriptor refVar = refVarItr.next();
919 if (liveSetIn.contains(refVar)) {
924 if (!copySet.isEmpty()) {
925 plan.addStall2CopySet(vstAlsoAvail, copySet);
930 // the other case for srcs is READY, so do nothing
933 // assert that everything being stalled for is in the
934 // "not available" set coming into this flat node and
935 // that every VST identified is in the possible "stall set"
936 // that represents VST's from children SESE's
944 // identify sese-age pairs that are statically useful
945 // and should have an associated SESE variable in code
946 // JUST GET ALL SESE/AGE NAMES FOR NOW, PRUNE LATER,
947 // AND ALWAYS GIVE NAMES TO PARENTS
948 Set<VariableSourceToken> staticSet = vstTableIn.get();
949 Iterator<VariableSourceToken> vstItr = staticSet.iterator();
950 while (vstItr.hasNext()) {
951 VariableSourceToken vst = vstItr.next();
953 // placeholder source tokens are useful results, but
954 // the placeholder static name is never needed
955 if (vst.getSESE().getIsCallerSESEplaceholder()) {
959 FlatSESEEnterNode sese = currentSESE;
960 while (sese != null) {
961 sese.addNeededStaticName(new SESEandAgePair(vst.getSESE(), vst.getAge()));
962 sese.mustTrackAtLeastAge(vst.getAge());
964 sese = sese.getParent();
968 codePlans.put(fn, plan);
970 // if any variables at this-node-*dot* have a static source (exactly one
972 // but go to a dynamic source at next-node-*dot*, create a new IR graph
973 // node on that edge to track the sources dynamically
974 VarSrcTokTable thisVstTable = variableResults.get(fn);
975 for (int i = 0; i < fn.numNext(); i++) {
976 FlatNode nn = fn.getNext(i);
977 VarSrcTokTable nextVstTable = variableResults.get(nn);
978 Set<TempDescriptor> nextLiveIn = livenessRootView.get(nn);
980 // the table can be null if it is one of the few IR nodes
981 // completely outside of the root SESE scope
982 if (nextVstTable != null && nextLiveIn != null) {
984 Hashtable<TempDescriptor, VSTWrapper> readyOrStatic2dynamicSet =
985 thisVstTable.getReadyOrStatic2DynamicSet(nextVstTable, nextLiveIn, currentSESE);
987 if (!readyOrStatic2dynamicSet.isEmpty()) {
989 // either add these results to partial fixed-point result
990 // or make a new one if we haven't made any here yet
991 FlatEdge fe = new FlatEdge(fn, nn);
992 FlatWriteDynamicVarNode fwdvn = wdvNodesToSpliceIn.get(fe);
995 fwdvn = new FlatWriteDynamicVarNode(fn, nn, readyOrStatic2dynamicSet, currentSESE);
996 wdvNodesToSpliceIn.put(fe, fwdvn);
998 fwdvn.addMoreVar2Src(readyOrStatic2dynamicSet);
1005 private void makeConflictGraph(FlatMethod fm) {
1007 Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
1008 flatNodesToVisit.add(fm);
1010 Set<FlatNode> visited = new HashSet<FlatNode>();
1012 while (!flatNodesToVisit.isEmpty()) {
1013 FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next();
1014 flatNodesToVisit.remove(fn);
1017 Stack<FlatSESEEnterNode> seseStack = rblockRel.getRBlockStacks(fm, fn);
1018 assert seseStack != null;
1020 if (!seseStack.isEmpty()) {
1021 conflictGraph_nodeAction(fn, seseStack.peek());
1024 // schedule forward nodes for analysis
1025 for (int i = 0; i < fn.numNext(); i++) {
1026 FlatNode nn = fn.getNext(i);
1027 if (!visited.contains(nn)) {
1028 flatNodesToVisit.add(nn);
1036 private void conflictGraph_nodeAction(FlatNode fn, FlatSESEEnterNode currentSESE) {
1038 ConflictGraph conflictGraph;
1042 EffectsAnalysis effectsAnalysis = disjointAnalysisTaints.getEffectsAnalysis();
1044 switch (fn.kind()) {
1046 case FKind.FlatFieldNode:
1047 case FKind.FlatElementNode: {
1049 if (fn instanceof FlatFieldNode) {
1050 FlatFieldNode ffn = (FlatFieldNode) fn;
1053 FlatElementNode fen = (FlatElementNode) fn;
1057 Set<FlatSESEEnterNode> parentSet = currentSESE.getSESEParent();
1058 for (Iterator iterator = parentSet.iterator(); iterator.hasNext();) {
1059 FlatSESEEnterNode parent = (FlatSESEEnterNode) iterator.next();
1060 // System.out.println("##current="+currentSESE.getmdEnclosing()+" PARENT=" + parent);
1061 conflictGraph = sese2conflictGraph.get(parent);
1062 if (conflictGraph == null) {
1063 conflictGraph = new ConflictGraph(state);
1067 Hashtable<Taint, Set<Effect>> taint2Effects = effectsAnalysis.get(fn);
1068 conflictGraph.addStallSite(taint2Effects, rhs);
1069 if (taint2Effects != null)
1070 // System.out.println("add =" + taint2Effects + "currentSESE=" + parent
1071 // + " into conflictGraph=" + conflictGraph);
1073 if (conflictGraph.id2cn.size() > 0) {
1074 sese2conflictGraph.put(parent, conflictGraph);
1081 case FKind.FlatSetFieldNode:
1082 case FKind.FlatSetElementNode: {
1084 if (fn instanceof FlatSetFieldNode) {
1085 FlatSetFieldNode fsfn = (FlatSetFieldNode) fn;
1086 lhs = fsfn.getDst();
1087 rhs = fsfn.getSrc();
1089 FlatSetElementNode fsen = (FlatSetElementNode) fn;
1090 lhs = fsen.getDst();
1091 rhs = fsen.getSrc();
1094 // collects effects of stall site and generates stall site node
1095 Set<FlatSESEEnterNode> parentSet = currentSESE.getSESEParent();
1096 for (Iterator iterator = parentSet.iterator(); iterator.hasNext();) {
1097 FlatSESEEnterNode parent = (FlatSESEEnterNode) iterator.next();
1098 conflictGraph = sese2conflictGraph.get(parent);
1099 if (conflictGraph == null) {
1100 conflictGraph = new ConflictGraph(state);
1103 Hashtable<Taint, Set<Effect>> taint2Effects = effectsAnalysis.get(fn);
1104 conflictGraph.addStallSite(taint2Effects, rhs);
1105 conflictGraph.addStallSite(taint2Effects, lhs);
1107 if (conflictGraph.id2cn.size() > 0) {
1108 sese2conflictGraph.put(parent, conflictGraph);
1115 case FKind.FlatCall: {
1116 conflictGraph = sese2conflictGraph.get(currentSESE);
1117 if (conflictGraph == null) {
1118 conflictGraph = new ConflictGraph(state);
1121 FlatCall fc = (FlatCall) fn;
1124 // collects effects of stall site and generates stall site node
1125 Hashtable<Taint, Set<Effect>> taint2Effects = effectsAnalysis.get(fn);
1127 Set<FlatSESEEnterNode> parentSet = currentSESE.getSESEParent();
1128 for (Iterator iterator = parentSet.iterator(); iterator.hasNext();) {
1129 FlatSESEEnterNode parent = (FlatSESEEnterNode) iterator.next();
1130 conflictGraph = sese2conflictGraph.get(parent);
1131 if (conflictGraph == null) {
1132 conflictGraph = new ConflictGraph(state);
1135 conflictGraph.addStallSite(taint2Effects, lhs);
1136 if (conflictGraph.id2cn.size() > 0) {
1137 sese2conflictGraph.put(parent, conflictGraph);
1150 private void calculateConflicts(Set<FlatNew> sitesToFlag, boolean useReachInfo) {
1151 // decide fine-grain edge or coarse-grain edge among all vertexes by
1152 // pair-wise comparison
1153 Iterator<FlatNode> seseIter = sese2conflictGraph.keySet().iterator();
1154 while (seseIter.hasNext()) {
1155 FlatSESEEnterNode sese = (FlatSESEEnterNode) seseIter.next();
1156 ConflictGraph conflictGraph = sese2conflictGraph.get(sese);
1157 // System.out.println("# CALCULATING SESE CONFLICT="+sese);
1159 // clear current conflict before recalculating with reachability info
1160 conflictGraph.clearAllConflictEdge();
1161 conflictGraph.setDisJointAnalysis(disjointAnalysisReach);
1162 conflictGraph.setFMEnclosing(sese.getfmEnclosing());
1164 conflictGraph.analyzeConflicts(sitesToFlag, useReachInfo);
1165 sese2conflictGraph.put(sese, conflictGraph);
1169 private void writeConflictGraph() {
1170 Enumeration<FlatNode> keyEnum = sese2conflictGraph.keys();
1171 while (keyEnum.hasMoreElements()) {
1172 FlatNode key = (FlatNode) keyEnum.nextElement();
1173 ConflictGraph cg = sese2conflictGraph.get(key);
1175 if (cg.hasConflictEdge()) {
1176 cg.writeGraph("ConflictGraphFor" + key, false);
1178 } catch (IOException e) {
1179 System.out.println("Error writing");
1185 private void synthesizeLocks() {
1186 Set<Entry<FlatNode, ConflictGraph>> graphEntrySet = sese2conflictGraph.entrySet();
1187 for (Iterator iterator = graphEntrySet.iterator(); iterator.hasNext();) {
1188 Entry<FlatNode, ConflictGraph> graphEntry = (Entry<FlatNode, ConflictGraph>) iterator.next();
1189 FlatNode sese = graphEntry.getKey();
1190 ConflictGraph conflictGraph = graphEntry.getValue();
1191 calculateCovering(conflictGraph);
1195 private void calculateCovering(ConflictGraph conflictGraph) {
1196 uniqueLockSetId = 0; // reset lock counter for every new conflict graph
1197 HashSet<ConflictEdge> fineToCover = new HashSet<ConflictEdge>();
1198 HashSet<ConflictEdge> coarseToCover = new HashSet<ConflictEdge>();
1199 HashSet<SESELock> lockSet = new HashSet<SESELock>();
1201 Set<ConflictEdge> tempCover = conflictGraph.getEdgeSet();
1202 for (Iterator iterator = tempCover.iterator(); iterator.hasNext();) {
1203 ConflictEdge conflictEdge = (ConflictEdge) iterator.next();
1204 if (conflictEdge.isCoarseEdge()) {
1205 coarseToCover.add(conflictEdge);
1207 fineToCover.add(conflictEdge);
1211 HashSet<ConflictEdge> toCover = new HashSet<ConflictEdge>();
1212 toCover.addAll(fineToCover);
1213 toCover.addAll(coarseToCover);
1215 while (!toCover.isEmpty()) {
1217 SESELock seseLock = new SESELock();
1218 seseLock.setID(uniqueLockSetId++);
1222 do { // fine-grained edge
1226 for (Iterator iterator = fineToCover.iterator(); iterator.hasNext();) {
1229 ConflictEdge edge = (ConflictEdge) iterator.next();
1230 if (seseLock.getConflictNodeSet().size() == 0) {
1232 if (seseLock.isWriteNode(edge.getVertexU())) {
1233 // mark as fine_write
1234 if (edge.getVertexU().isStallSiteNode()) {
1235 type = ConflictNode.PARENT_WRITE;
1237 type = ConflictNode.FINE_WRITE;
1239 seseLock.addConflictNode(edge.getVertexU(), type);
1241 // mark as fine_read
1242 if (edge.getVertexU().isStallSiteNode()) {
1243 type = ConflictNode.PARENT_READ;
1245 type = ConflictNode.FINE_READ;
1247 seseLock.addConflictNode(edge.getVertexU(), type);
1249 if (edge.getVertexV() != edge.getVertexU()) {
1250 if (seseLock.isWriteNode(edge.getVertexV())) {
1251 // mark as fine_write
1252 if (edge.getVertexV().isStallSiteNode()) {
1253 type = ConflictNode.PARENT_WRITE;
1255 type = ConflictNode.FINE_WRITE;
1257 seseLock.addConflictNode(edge.getVertexV(), type);
1259 // mark as fine_read
1260 if (edge.getVertexV().isStallSiteNode()) {
1261 type = ConflictNode.PARENT_READ;
1263 type = ConflictNode.FINE_READ;
1265 seseLock.addConflictNode(edge.getVertexV(), type);
1269 seseLock.addConflictEdge(edge);
1270 fineToCover.remove(edge);
1271 break;// exit iterator loop
1272 }// end of initial setup
1274 ConflictNode newNode;
1275 if ((newNode = seseLock.getNewNodeConnectedWithGroup(edge)) != null) {
1276 // new node has a fine-grained edge to all current node
1277 // If there is a coarse grained edge where need a fine edge, it's
1278 // okay to add the node
1279 // but the edge must remain uncovered.
1283 if (seseLock.containsConflictNode(newNode)) {
1284 seseLock.addEdge(edge);
1285 fineToCover.remove(edge);
1289 if (seseLock.isWriteNode(newNode)) {
1290 if (newNode.isStallSiteNode()) {
1291 type = ConflictNode.PARENT_WRITE;
1293 type = ConflictNode.FINE_WRITE;
1295 seseLock.setNodeType(newNode, type);
1297 if (newNode.isStallSiteNode()) {
1298 type = ConflictNode.PARENT_READ;
1300 type = ConflictNode.FINE_READ;
1302 seseLock.setNodeType(newNode, type);
1305 seseLock.addEdge(edge);
1306 Set<ConflictEdge> edgeSet = newNode.getEdgeSet();
1307 for (Iterator iterator2 = edgeSet.iterator(); iterator2.hasNext();) {
1308 ConflictEdge conflictEdge = (ConflictEdge) iterator2.next();
1310 // mark all fine edges between new node and nodes in the group as
1312 if (!conflictEdge.getVertexU().equals(newNode)) {
1313 if (seseLock.containsConflictNode(conflictEdge.getVertexU())) {
1315 seseLock.addConflictEdge(conflictEdge);
1316 fineToCover.remove(conflictEdge);
1318 } else if (!conflictEdge.getVertexV().equals(newNode)) {
1319 if (seseLock.containsConflictNode(conflictEdge.getVertexV())) {
1321 seseLock.addConflictEdge(conflictEdge);
1322 fineToCover.remove(conflictEdge);
1328 break;// exit iterator loop
1333 HashSet<ConflictEdge> notCovered=new HashSet<ConflictEdge>();
1337 for (Iterator iterator = coarseToCover.iterator(); iterator.hasNext();) {
1339 ConflictEdge edge = (ConflictEdge) iterator.next();
1340 if (seseLock.getConflictNodeSet().size() == 0) {
1342 if (seseLock.hasSelfCoarseEdge(edge.getVertexU())) {
1343 // node has a coarse-grained edge with itself
1344 if (!(edge.getVertexU().isStallSiteNode())) {
1345 // and it is not parent
1346 type = ConflictNode.SCC;
1349 type = ConflictNode.PARENT_COARSE;
1351 type = ConflictNode.PARENT_WRITE;
1354 seseLock.addConflictNode(edge.getVertexU(), type);
1356 if (edge.getVertexU().isStallSiteNode()) {
1358 type = ConflictNode.PARENT_COARSE;
1360 if (edge.getVertexU().getWriteEffectSet().isEmpty()) {
1361 type = ConflictNode.PARENT_READ;
1363 type = ConflictNode.PARENT_WRITE;
1367 type = ConflictNode.COARSE;
1369 seseLock.addConflictNode(edge.getVertexU(), type);
1371 if (seseLock.hasSelfCoarseEdge(edge.getVertexV())) {
1372 // node has a coarse-grained edge with itself
1373 if (!(edge.getVertexV().isStallSiteNode())) {
1374 // and it is not parent
1375 type = ConflictNode.SCC;
1378 type = ConflictNode.PARENT_COARSE;
1380 type = ConflictNode.PARENT_WRITE;
1383 seseLock.addConflictNode(edge.getVertexV(), type);
1385 if (edge.getVertexV().isStallSiteNode()) {
1387 type = ConflictNode.PARENT_COARSE;
1389 if (edge.getVertexV().getWriteEffectSet().isEmpty()) {
1390 type = ConflictNode.PARENT_READ;
1392 type = ConflictNode.PARENT_WRITE;
1396 type = ConflictNode.COARSE;
1398 seseLock.addConflictNode(edge.getVertexV(), type);
1401 coarseToCover.remove(edge);
1402 seseLock.addConflictEdge(edge);
1403 break;// exit iterator loop
1404 }// end of initial setup
1406 ConflictNode newNode;
1407 if ((newNode = seseLock.getNewNodeConnectedWithGroup(edge)) != null) {
1408 // new node has a coarse-grained edge to all fine-read, fine-write,
1412 if (newNode.isInVarNode() && (!seseLock.hasSelfCoarseEdge(newNode))
1413 && seseLock.hasCoarseEdgeWithParentCoarse(newNode)) {
1414 // this case can't be covered by this queue
1415 coarseToCover.remove(edge);
1416 notCovered.add(edge);
1420 if (seseLock.containsConflictNode(newNode)) {
1421 seseLock.addEdge(edge);
1422 coarseToCover.remove(edge);
1426 if (seseLock.hasSelfCoarseEdge(newNode)) {
1428 if (newNode.isStallSiteNode()) {
1429 type = ConflictNode.PARENT_COARSE;
1431 type = ConflictNode.SCC;
1433 seseLock.setNodeType(newNode, type);
1435 if (newNode.isStallSiteNode()) {
1436 type = ConflictNode.PARENT_COARSE;
1438 type = ConflictNode.COARSE;
1440 seseLock.setNodeType(newNode, type);
1443 seseLock.addEdge(edge);
1444 Set<ConflictEdge> edgeSet = newNode.getEdgeSet();
1445 for (Iterator iterator2 = edgeSet.iterator(); iterator2.hasNext();) {
1446 ConflictEdge conflictEdge = (ConflictEdge) iterator2.next();
1447 // mark all coarse edges between new node and nodes in the group
1449 if (!conflictEdge.getVertexU().equals(newNode)) {
1450 if (seseLock.containsConflictNode(conflictEdge.getVertexU())) {
1452 seseLock.addConflictEdge(conflictEdge);
1453 coarseToCover.remove(conflictEdge);
1455 } else if (!conflictEdge.getVertexV().equals(newNode)) {
1456 if (seseLock.containsConflictNode(conflictEdge.getVertexV())) {
1458 seseLock.addConflictEdge(conflictEdge);
1459 coarseToCover.remove(conflictEdge);
1464 break;// exit iterator loop
1470 lockSet.add(seseLock);
1473 coarseToCover.addAll(notCovered);
1474 toCover.addAll(fineToCover);
1475 toCover.addAll(coarseToCover);
1479 conflictGraph2SESELock.put(conflictGraph, lockSet);
1482 public ConflictGraph getConflictGraph(FlatNode sese) {
1483 return sese2conflictGraph.get(sese);
1486 public Set<SESELock> getLockMappings(ConflictGraph graph) {
1487 return conflictGraph2SESELock.get(graph);
1490 public Set<FlatSESEEnterNode> getAllSESEs() {
1491 return rblockRel.getAllSESEs();
1494 public FlatSESEEnterNode getMainSESE() {
1495 return rblockRel.getMainSESE();
1498 public void writeReports(String timeReport) throws java.io.IOException {
1500 BufferedWriter bw = new BufferedWriter(new FileWriter("mlpReport_summary.txt"));
1501 bw.write("MLP Analysis Results\n\n");
1502 bw.write(timeReport + "\n\n");
1503 printSESEHierarchy(bw);
1508 Iterator<Descriptor> methItr = disjointAnalysisTaints.getDescriptorsToAnalyze().iterator();
1509 while (methItr.hasNext()) {
1510 MethodDescriptor md = (MethodDescriptor) methItr.next();
1511 FlatMethod fm = state.getMethodFlat(md);
1514 new BufferedWriter(new FileWriter("mlpReport_" + md.getClassMethodName()
1515 + md.getSafeMethodDescriptor() + ".txt"));
1516 bw.write("MLP Results for " + md + "\n-------------------\n");
1518 FlatSESEEnterNode implicitSESE = (FlatSESEEnterNode) fm.getNext(0);
1519 if (!implicitSESE.getIsCallerSESEplaceholder() && implicitSESE != rblockRel.getMainSESE()) {
1520 System.out.println(implicitSESE + " is not implicit?!");
1523 bw.write("Dynamic vars to manage:\n " + implicitSESE.getDynamicVarSet());
1525 bw.write("\n\nLive-In, Root View\n------------------\n" + fm.printMethod(livenessRootView));
1526 bw.write("\n\nVariable Results-Out\n----------------\n" + fm.printMethod(variableResults));
1527 bw.write("\n\nNot Available Results-Out\n---------------------\n"
1528 + fm.printMethod(notAvailableResults));
1529 bw.write("\n\nCode Plans\n----------\n" + fm.printMethod(codePlans));
1535 private void printSESEHierarchy(BufferedWriter bw) throws java.io.IOException {
1536 bw.write("SESE Hierarchy\n--------------\n");
1537 Iterator<FlatSESEEnterNode> rootItr = rblockRel.getRootSESEs().iterator();
1538 while (rootItr.hasNext()) {
1539 FlatSESEEnterNode root = rootItr.next();
1540 if (root.getIsCallerSESEplaceholder()) {
1541 if (!root.getChildren().isEmpty()) {
1542 printSESEHierarchyTree(bw, root, 0);
1545 printSESEHierarchyTree(bw, root, 0);
1550 private void printSESEHierarchyTree(BufferedWriter bw, FlatSESEEnterNode fsen, int depth)
1551 throws java.io.IOException {
1552 for (int i = 0; i < depth; ++i) {
1555 bw.write("- " + fsen.getPrettyIdentifier() + "\n");
1557 Iterator<FlatSESEEnterNode> childItr = fsen.getChildren().iterator();
1558 while (childItr.hasNext()) {
1559 FlatSESEEnterNode fsenChild = childItr.next();
1560 printSESEHierarchyTree(bw, fsenChild, depth + 1);
1564 private void printSESEInfo(BufferedWriter bw) throws java.io.IOException {
1565 bw.write("\nSESE info\n-------------\n");
1566 Iterator<FlatSESEEnterNode> rootItr = rblockRel.getRootSESEs().iterator();
1567 while (rootItr.hasNext()) {
1568 FlatSESEEnterNode root = rootItr.next();
1569 if (root.getIsCallerSESEplaceholder()) {
1570 if (!root.getChildren().isEmpty()) {
1571 printSESEInfoTree(bw, root);
1574 printSESEInfoTree(bw, root);
1579 public DisjointAnalysis getDisjointAnalysis() {
1580 return disjointAnalysisTaints;
1583 private void printSESEInfoTree(BufferedWriter bw, FlatSESEEnterNode fsen)
1584 throws java.io.IOException {
1586 if (!fsen.getIsCallerSESEplaceholder()) {
1587 bw.write("SESE " + fsen.getPrettyIdentifier());
1588 if( fsen.getIsLeafSESE() ) {
1589 bw.write(" (leaf)");
1593 bw.write(" in-set: " + fsen.getInVarSet() + "\n");
1594 Iterator<TempDescriptor> tItr = fsen.getInVarSet().iterator();
1595 while (tItr.hasNext()) {
1596 TempDescriptor inVar = tItr.next();
1597 if (fsen.getReadyInVarSet().contains(inVar)) {
1598 bw.write(" (ready) " + inVar + "\n");
1600 if (fsen.getStaticInVarSet().contains(inVar)) {
1601 bw.write(" (static) " + inVar + " from " + fsen.getStaticInVarSrc(inVar) + "\n");
1603 if (fsen.getDynamicInVarSet().contains(inVar)) {
1604 bw.write(" (dynamic)" + inVar + "\n");
1608 bw.write(" Dynamic vars to manage: " + fsen.getDynamicVarSet() + "\n");
1610 bw.write(" out-set: " + fsen.getOutVarSet() + "\n");
1614 Iterator<FlatSESEEnterNode> childItr = fsen.getChildren().iterator();
1615 while (childItr.hasNext()) {
1616 FlatSESEEnterNode fsenChild = childItr.next();
1617 printSESEInfoTree(bw, fsenChild);