1 package Analysis.Locality;
4 import Analysis.CallGraph.CallGraph;
8 import IR.MethodDescriptor;
10 import IR.ClassDescriptor;
12 public class LocalityAnalysis {
15 Hashtable<LocalityBinding,LocalityBinding> discovered;
16 Hashtable<LocalityBinding, Set<LocalityBinding>> dependence;
17 Hashtable<LocalityBinding, Hashtable<FlatNode,Hashtable<TempDescriptor, Integer>>> temptab;
18 Hashtable<LocalityBinding, Hashtable<FlatNode, Integer>> atomictab;
19 Hashtable<LocalityBinding, Hashtable<FlatAtomicEnterNode, Set<TempDescriptor>>> tempstosave;
20 Hashtable<ClassDescriptor, Set<LocalityBinding>> classtolb;
21 Hashtable<MethodDescriptor, Set<LocalityBinding>> methodtolb;
22 private LocalityBinding lbmain;
26 public static final Integer LOCAL=new Integer(0);
27 public static final Integer GLOBAL=new Integer(1);
28 public static final Integer EITHER=new Integer(2);
29 public static final Integer CONFLICT=new Integer(3);
31 public LocalityAnalysis(State state, CallGraph callgraph, TypeUtil typeutil) {
32 this.typeutil=typeutil;
34 this.discovered=new Hashtable<LocalityBinding,LocalityBinding>();
35 this.dependence=new Hashtable<LocalityBinding, Set<LocalityBinding>>();
36 this.temptab=new Hashtable<LocalityBinding, Hashtable<FlatNode,Hashtable<TempDescriptor, Integer>>>();
37 this.atomictab=new Hashtable<LocalityBinding, Hashtable<FlatNode, Integer>>();
38 this.lbtovisit=new Stack();
39 this.callgraph=callgraph;
40 this.tempstosave=new Hashtable<LocalityBinding, Hashtable<FlatAtomicEnterNode, Set<TempDescriptor>>>();
41 this.classtolb=new Hashtable<ClassDescriptor, Set<LocalityBinding>>();
42 this.methodtolb=new Hashtable<MethodDescriptor, Set<LocalityBinding>>();
46 public LocalityBinding getMain() {
50 /** This method returns the set of LocalityBindings that a given
51 * flatcall could invoke */
53 public LocalityBinding getBinding(LocalityBinding currlb, FlatCall fc) {
54 boolean isatomic=getAtomic(currlb).get(fc).intValue()>0;
55 Hashtable<TempDescriptor, Integer> currtable=getNodePreTempInfo(currlb,fc);
56 MethodDescriptor md=fc.getMethod();
58 boolean isnative=md.getModifiers().isNative();
60 LocalityBinding lb=new LocalityBinding(md, isatomic);
62 for(int i=0;i<fc.numArgs();i++) {
63 TempDescriptor arg=fc.getArg(i);
64 lb.setGlobal(i,currtable.get(arg));
66 if (fc.getThis()!=null) {
67 Integer thistype=currtable.get(fc.getThis());
70 lb.setGlobalThis(thistype);
72 // lb.setGlobalThis(EITHER);//default value
73 if (discovered.containsKey(lb))
74 lb=discovered.get(lb);
75 else throw new Error();
80 /** This method returns a set of LocalityBindings for the parameter class. */
81 public Set<LocalityBinding> getClassBindings(ClassDescriptor cd) {
82 return classtolb.get(cd);
85 /** This method returns a set of LocalityBindings for the parameter method. */
87 public Set<LocalityBinding> getMethodBindings(MethodDescriptor md) {
88 return methodtolb.get(md);
91 /** This method returns a set of LocalityBindings. A
92 * LocalityBinding specifies a context a method can be invoked in.
93 * It specifies whether the method is in a transaction and whether
94 * its parameter objects are locals or globals. */
96 public Set<LocalityBinding> getLocalityBindings() {
97 return discovered.keySet();
100 /** This method returns a hashtable for a given LocalityBinding
101 * that tells the current local/global status of temps at the each
102 * node in the flat representation. */
104 public Hashtable<FlatNode, Hashtable<TempDescriptor, Integer>> getNodeTempInfo(LocalityBinding lb) {
105 return temptab.get(lb);
108 /** This method returns a hashtable for a given LocalityBinding
109 * that tells the current local/global status of temps at the
110 * beginning of each node in the flat representation. */
112 public Hashtable<TempDescriptor, Integer> getNodePreTempInfo(LocalityBinding lb, FlatNode fn) {
113 Hashtable<TempDescriptor, Integer> currtable=new Hashtable<TempDescriptor, Integer>();
114 Hashtable<FlatNode, Hashtable<TempDescriptor, Integer>> temptable=getNodeTempInfo(lb);
116 for(int i=0;i<fn.numPrev();i++) {
117 FlatNode prevnode=fn.getPrev(i);
118 Hashtable<TempDescriptor, Integer> prevtable=temptable.get(prevnode);
119 for(Iterator<TempDescriptor> tempit=prevtable.keySet().iterator();tempit.hasNext();) {
120 TempDescriptor temp=tempit.next();
121 Integer tmpint=prevtable.get(temp);
122 Integer oldint=currtable.containsKey(temp)?currtable.get(temp):EITHER;
123 Integer newint=merge(tmpint, oldint);
124 currtable.put(temp, newint);
130 /** This method returns an hashtable for a given LocalitBinding
131 * that tells whether a node in the flat represenation is in a
132 * transaction or not. Integer values greater than 0 indicate
133 * that the node is in a transaction and give the nesting depth.
134 * The outermost AtomicEnterNode will have a value of 1 and the
135 * outermost AtomicExitNode will have a value of 0. */
137 public Hashtable<FlatNode, Integer> getAtomic(LocalityBinding lb) {
138 return atomictab.get(lb);
141 /** This methods returns a hashtable for a given LocalityBinding
142 * that tells which temps needs to be saved for each
143 * AtomicEnterNode. */
145 public Hashtable<FlatAtomicEnterNode, Set<TempDescriptor>> getTemps(LocalityBinding lb) {
146 return tempstosave.get(lb);
149 public Set<TempDescriptor> getTempSet(LocalityBinding lb) {
150 HashSet<TempDescriptor> set=new HashSet<TempDescriptor>();
151 Hashtable<FlatAtomicEnterNode, Set<TempDescriptor>> table=getTemps(lb);
153 for(Iterator<FlatAtomicEnterNode> faenit=table.keySet().iterator();faenit.hasNext();) {
154 FlatAtomicEnterNode faen=faenit.next();
155 set.addAll(table.get(faen));
160 private void doAnalysis() {
161 computeLocalityBindings();
162 computeTempstoSave();
165 private void computeLocalityBindings() {
166 lbmain=new LocalityBinding(typeutil.getMain(), false);
167 lbmain.setGlobalReturn(EITHER);
168 lbmain.setGlobal(0, LOCAL);
169 lbtovisit.add(lbmain);
170 discovered.put(lbmain, lbmain);
171 if (!classtolb.containsKey(lbmain.getMethod().getClassDesc()))
172 classtolb.put(lbmain.getMethod().getClassDesc(), new HashSet<LocalityBinding>());
173 classtolb.get(lbmain.getMethod().getClassDesc()).add(lbmain);
175 if (!methodtolb.containsKey(lbmain.getMethod()))
176 methodtolb.put(lbmain.getMethod(), new HashSet<LocalityBinding>());
177 methodtolb.get(lbmain.getMethod()).add(lbmain);
179 //Do this to force a virtual table number for the run method
180 LocalityBinding lbrun=new LocalityBinding(typeutil.getRun(), false);
181 lbrun.setGlobalReturn(EITHER);
182 lbrun.setGlobalThis(GLOBAL);
183 lbtovisit.add(lbrun);
184 discovered.put(lbrun, lbrun);
185 if (!classtolb.containsKey(lbrun.getMethod().getClassDesc()))
186 classtolb.put(lbrun.getMethod().getClassDesc(), new HashSet<LocalityBinding>());
187 classtolb.get(lbrun.getMethod().getClassDesc()).add(lbrun);
189 if (!methodtolb.containsKey(lbrun.getMethod()))
190 methodtolb.put(lbrun.getMethod(), new HashSet<LocalityBinding>());
191 methodtolb.get(lbrun.getMethod()).add(lbrun);
193 while(!lbtovisit.empty()) {
194 LocalityBinding lb=(LocalityBinding) lbtovisit.pop();
195 Integer returnglobal=lb.getGlobalReturn();
196 MethodDescriptor md=lb.getMethod();
197 Hashtable<FlatNode,Hashtable<TempDescriptor, Integer>> temptable=new Hashtable<FlatNode,Hashtable<TempDescriptor, Integer>>();
198 Hashtable<FlatNode, Integer> atomictable=new Hashtable<FlatNode, Integer>();
199 computeCallsFlags(md, lb, temptable, atomictable);
200 atomictab.put(lb, atomictable);
201 temptab.put(lb, temptable);
203 if (md.getReturnType()!=null&&!returnglobal.equals(lb.getGlobalReturn())) {
204 //return type is more precise now
205 //rerun everything that call us
206 lbtovisit.addAll(dependence.get(lb));
211 public void computeCallsFlags(MethodDescriptor md, LocalityBinding lb, Hashtable<FlatNode, Hashtable<TempDescriptor, Integer>> temptable, Hashtable<FlatNode, Integer> atomictable) {
212 FlatMethod fm=state.getMethodFlat(md);
213 HashSet<FlatNode> tovisit=new HashSet<FlatNode>();
214 tovisit.add(fm.getNext(0));
216 // Build table for initial node
217 Hashtable<TempDescriptor,Integer> table=new Hashtable<TempDescriptor,Integer>();
218 temptable.put(fm, table);
219 atomictable.put(fm, lb.isAtomic()?1:0);
220 int offset=md.isStatic()?0:1;
221 if (!md.isStatic()) {
222 table.put(fm.getParameter(0), lb.getGlobalThis());
224 for(int i=offset;i<fm.numParameters();i++) {
225 TempDescriptor temp=fm.getParameter(i);
226 Integer b=lb.isGlobal(i-offset);
231 while(!tovisit.isEmpty()) {
232 FlatNode fn=tovisit.iterator().next();
234 Hashtable<TempDescriptor, Integer> currtable=new Hashtable<TempDescriptor, Integer>();
236 for(int i=0;i<fn.numPrev();i++) {
237 FlatNode prevnode=fn.getPrev(i);
238 if (atomictable.containsKey(prevnode)) {
239 atomicstate=atomictable.get(prevnode).intValue();
241 if (!temptable.containsKey(prevnode))
243 Hashtable<TempDescriptor, Integer> prevtable=temptable.get(prevnode);
244 for(Iterator<TempDescriptor> tempit=prevtable.keySet().iterator();tempit.hasNext();) {
245 TempDescriptor temp=tempit.next();
246 Integer tmpint=prevtable.get(temp);
247 Integer oldint=currtable.containsKey(temp)?currtable.get(temp):EITHER;
248 Integer newint=merge(tmpint, oldint);
249 currtable.put(temp, newint);
252 atomictable.put(fn, atomicstate);
255 case FKind.FlatAtomicEnterNode:
256 processAtomicEnterNode((FlatAtomicEnterNode)fn, atomictable);
260 case FKind.FlatAtomicExitNode:
261 processAtomicExitNode((FlatAtomicExitNode)fn, atomictable);
264 processCallNode(lb, (FlatCall)fn, currtable, isAtomic(atomictable, fn));
266 case FKind.FlatFieldNode:
267 processFieldNode(lb, (FlatFieldNode)fn, isAtomic(atomictable, fn), currtable);
269 case FKind.FlatSetFieldNode:
270 processSetFieldNode(lb, (FlatSetFieldNode)fn, isAtomic(atomictable,fn), currtable);
273 processNew(lb, (FlatNew)fn, isAtomic(atomictable, fn), currtable);
275 case FKind.FlatOpNode:
276 processOpNode((FlatOpNode)fn, currtable);
278 case FKind.FlatCastNode:
279 processCastNode((FlatCastNode)fn, currtable);
281 case FKind.FlatLiteralNode:
282 processLiteralNode((FlatLiteralNode)fn, currtable);
284 case FKind.FlatReturnNode:
285 processReturnNode(lb, (FlatReturnNode)fn, currtable);
287 case FKind.FlatSetElementNode:
288 processSetElementNode(lb, (FlatSetElementNode)fn, currtable, isAtomic(atomictable, fn));
290 case FKind.FlatElementNode:
291 processElementNode(lb, (FlatElementNode)fn, currtable, isAtomic(atomictable, fn));
293 case FKind.FlatCondBranch:
294 case FKind.FlatBackEdge:
296 case FKind.FlatPrefetchNode:
297 //No action needed for these
299 case FKind.FlatFlagActionNode:
300 case FKind.FlatCheckNode:
301 case FKind.FlatTagDeclaration:
302 throw new Error("Incompatible with tasks!");
303 case FKind.FlatMethod:
307 Hashtable<TempDescriptor,Integer> oldtable=temptable.get(fn);
308 if (oldtable==null||!oldtable.equals(currtable)) {
309 // Update table for this node
310 temptable.put(fn, currtable);
311 for(int i=0;i<fn.numNext();i++) {
312 tovisit.add(fn.getNext(i));
318 private static boolean isAtomic(Hashtable<FlatNode, Integer> atomictable, FlatNode fn) {
319 return atomictable.get(fn).intValue()>0;
322 private static Integer merge(Integer a, Integer b) {
323 if (a==null||a.equals(EITHER))
325 if (b==null||b.equals(EITHER))
332 void processCallNode(LocalityBinding currlb, FlatCall fc, Hashtable<TempDescriptor, Integer> currtable, boolean isatomic) {
333 MethodDescriptor nodemd=fc.getMethod();
335 Set runmethodset=null;
336 if (nodemd.isStatic()||nodemd.getReturnType()==null) {
337 methodset=new HashSet();
338 methodset.add(nodemd);
340 methodset=callgraph.getMethods(nodemd, fc.getThis().getType());
341 // Build start -> run link
342 if (nodemd.getClassDesc().getSymbol().equals(TypeUtil.ThreadClass)&&
343 nodemd.getSymbol().equals("start")&&!nodemd.getModifiers().isStatic()&&
344 nodemd.numParameters()==1&&nodemd.getParamType(0).isInt()) {
345 assert(nodemd.getModifiers().isNative());
347 MethodDescriptor runmd=null;
348 for(Iterator methodit=nodemd.getClassDesc().getMethodTable().getSet("run").iterator();methodit.hasNext();) {
349 MethodDescriptor md=(MethodDescriptor) methodit.next();
350 if (md.numParameters()!=0||md.getModifiers().isStatic())
356 runmethodset=callgraph.getMethods(runmd,fc.getThis().getType());
357 methodset.addAll(runmethodset);
358 } else throw new Error("Can't find run method");
361 Integer currreturnval=EITHER; //Start off with the either value
362 for(Iterator methodit=methodset.iterator();methodit.hasNext();) {
363 MethodDescriptor md=(MethodDescriptor) methodit.next();
364 boolean isnative=md.getModifiers().isNative();
366 LocalityBinding lb=new LocalityBinding(md, isatomic);
367 if (isnative&&isatomic) {
368 System.out.println("Don't call native methods in atomic blocks!");
370 if (runmethodset==null||!runmethodset.contains(md)) {
371 //Skip this part if it is a run method
372 for(int i=0;i<fc.numArgs();i++) {
373 TempDescriptor arg=fc.getArg(i);
374 if(isnative&&(currtable.get(arg).equals(GLOBAL)||
375 currtable.get(arg).equals(CONFLICT)))
376 throw new Error("Potential call to native method "+md+" with global parameter:\n"+currlb.getExplanation());
377 lb.setGlobal(i,currtable.get(arg));
382 if (fc.getThis()!=null) {
383 Integer thistype=currtable.get(fc.getThis());
387 if(runmethodset!=null&&runmethodset.contains(md)&&thistype.equals(LOCAL))
388 throw new Error("Starting thread on local object not allowed in context:\n"+currlb.getExplanation());
389 if(thistype.equals(CONFLICT))
390 throw new Error("Using type that can be either local or global in context:\n"+currlb.getExplanation());
391 if(runmethodset==null&&thistype.equals(GLOBAL)&&!isatomic)
392 throw new Error("Using global object outside of transaction in context:\n"+currlb.getExplanation());
393 if (runmethodset==null&&isnative&&thistype.equals(GLOBAL))
394 throw new Error("Potential call to native method "+md+" on global objects:\n"+currlb.getExplanation());
395 lb.setGlobalThis(thistype);
398 if (!discovered.containsKey(lb)) {
400 lb.setGlobalReturn(LOCAL);
402 lb.setGlobalReturn(EITHER);
403 lb.setParent(currlb);
405 discovered.put(lb, lb);
406 if (!classtolb.containsKey(lb.getMethod().getClassDesc()))
407 classtolb.put(lb.getMethod().getClassDesc(), new HashSet<LocalityBinding>());
408 classtolb.get(lb.getMethod().getClassDesc()).add(lb);
409 if (!methodtolb.containsKey(lb.getMethod()))
410 methodtolb.put(lb.getMethod(), new HashSet<LocalityBinding>());
411 methodtolb.get(lb.getMethod()).add(lb);
413 lb=discovered.get(lb);
414 Integer returnval=lb.getGlobalReturn();
415 currreturnval=merge(returnval, currreturnval);
416 if (!dependence.containsKey(lb))
417 dependence.put(lb, new HashSet<LocalityBinding>());
418 dependence.get(lb).add(currlb);
420 if (fc.getReturnTemp()!=null) {
421 currtable.put(fc.getReturnTemp(), currreturnval);
425 void processFieldNode(LocalityBinding lb, FlatFieldNode ffn, boolean transaction, Hashtable<TempDescriptor, Integer> currtable) {
426 Integer type=currtable.get(ffn.getSrc());
427 TempDescriptor dst=ffn.getDst();
428 if (type.equals(LOCAL)) {
429 if (ffn.getField().isGlobal())
430 currtable.put(dst,GLOBAL);
432 currtable.put(dst,LOCAL);
433 } else if (type.equals(GLOBAL)) {
435 throw new Error("Global access outside of a transaction in context:\n"+lb.getExplanation());
436 if (ffn.getField().getType().isPrimitive())
437 currtable.put(dst, LOCAL); // primitives are local
439 currtable.put(dst, GLOBAL);
440 } else if (type.equals(EITHER)) {
441 if (ffn.getField().getType().isPrimitive())
442 currtable.put(dst, LOCAL); // primitives are local
443 else if (ffn.getField().isGlobal())
444 currtable.put(dst, GLOBAL);
446 currtable.put(dst, EITHER);
447 } else if (type.equals(CONFLICT)) {
448 throw new Error("Access to object that could be either global or local in context:\n"+lb.getExplanation());
452 //need to handle primitives
453 void processSetFieldNode(LocalityBinding lb, FlatSetFieldNode fsfn, boolean transaction, Hashtable<TempDescriptor, Integer> currtable) {
454 Integer srctype=currtable.get(fsfn.getSrc());
455 Integer dsttype=currtable.get(fsfn.getDst());
457 if (dsttype.equals(LOCAL)) {
458 if (fsfn.getField().isGlobal()) {
459 if (!(srctype.equals(GLOBAL)||srctype.equals(EITHER)))
460 throw new Error("Writing possible local reference to global field in context: \n"+lb.getExplanation());
462 if (!(srctype.equals(LOCAL)||srctype.equals(EITHER)))
463 throw new Error("Writing possible global reference to local object in context: \n"+lb.getExplanation());
465 } else if (dsttype.equals(GLOBAL)) {
467 throw new Error("Global access outside of a transaction in context:\n"+lb.getExplanation());
468 //okay to store primitives in global object
469 if (srctype.equals(LOCAL) && fsfn.getField().getType().isPrimitive())
471 if (!(srctype.equals(GLOBAL)||srctype.equals(EITHER)))
472 throw new Error("Writing possible local reference to global object in context:\n"+lb.getExplanation()+" for FlatFieldNode "+fsfn);
473 } else if (dsttype.equals(EITHER)) {
474 if (srctype.equals(CONFLICT))
475 throw new Error("Using reference that could be local or global in context:\n"+lb.getExplanation());
476 } else if (dsttype.equals(CONFLICT)) {
477 throw new Error("Access to object that could be either global or local in context:\n"+lb.getExplanation());
481 void processNew(LocalityBinding lb, FlatNew fn, boolean transaction, Hashtable<TempDescriptor, Integer> currtable) {
482 if (fn.isGlobal()&&!transaction) {
483 throw new Error("Allocating global object outside of transaction in context:"+lb.getExplanation());
486 currtable.put(fn.getDst(), GLOBAL);
488 currtable.put(fn.getDst(), LOCAL);
491 void processOpNode(FlatOpNode fon, Hashtable<TempDescriptor, Integer> currtable) {
492 /* Just propagate value */
493 Integer srcvalue=currtable.get(fon.getLeft());
494 if (srcvalue==null) {
495 throw new Error(fon.getLeft()+" is undefined!");
497 currtable.put(fon.getDest(), currtable.get(fon.getLeft()));
500 void processCastNode(FlatCastNode fcn, Hashtable<TempDescriptor, Integer> currtable) {
501 currtable.put(fcn.getDst(), currtable.get(fcn.getSrc()));
504 void processLiteralNode(FlatLiteralNode fln, Hashtable<TempDescriptor, Integer> currtable) {
506 if (fln.getValue()==null)
507 currtable.put(fln.getDst(), EITHER);
509 currtable.put(fln.getDst(), LOCAL);
512 void processReturnNode(LocalityBinding lb, FlatReturnNode frn, Hashtable<TempDescriptor, Integer> currtable) {
513 if(frn.getReturnTemp()!=null) {
514 Integer returntype=currtable.get(frn.getReturnTemp());
515 lb.setGlobalReturn(merge(returntype, lb.getGlobalReturn()));
519 void processSetElementNode(LocalityBinding lb, FlatSetElementNode fsen, Hashtable<TempDescriptor, Integer> currtable, boolean isatomic) {
520 Integer srctype=currtable.get(fsen.getSrc());
521 Integer dsttype=currtable.get(fsen.getDst());
523 if (dsttype.equals(LOCAL)) {
524 if (!(srctype.equals(LOCAL)||srctype.equals(EITHER)))
525 throw new Error("Writing possible global reference to local object in context:\n"+lb.getExplanation());
526 } else if (dsttype.equals(GLOBAL)) {
527 if (!(srctype.equals(GLOBAL)||srctype.equals(EITHER)))
528 throw new Error("Writing possible local reference to global object in context:\n"+lb.getExplanation());
530 throw new Error("Global access outside of a transaction in context:\n"+lb.getExplanation());
531 } else if (dsttype.equals(EITHER)) {
532 if (srctype.equals(CONFLICT))
533 throw new Error("Using reference that could be local or global in context:\n"+lb.getExplanation());
534 } else if (dsttype.equals(CONFLICT)) {
535 throw new Error("Access to object that could be either global or local in context:\n"+lb.getExplanation());
539 void processElementNode(LocalityBinding lb, FlatElementNode fen, Hashtable<TempDescriptor, Integer> currtable, boolean isatomic) {
540 Integer type=currtable.get(fen.getSrc());
541 TempDescriptor dst=fen.getDst();
542 if (type.equals(LOCAL)) {
543 currtable.put(dst,LOCAL);
544 } else if (type.equals(GLOBAL)) {
546 throw new Error("Global access outside of a transaction in context:\n"+lb.getExplanation());
547 currtable.put(dst, GLOBAL);
548 } else if (type.equals(EITHER)) {
549 currtable.put(dst, EITHER);
550 } else if (type.equals(CONFLICT)) {
551 throw new Error("Access to object that could be either global or local in context:\n"+lb.getExplanation());
555 void processAtomicEnterNode(FlatAtomicEnterNode fen, Hashtable<FlatNode, Integer> atomictable) {
556 int atomic=atomictable.get(fen).intValue();
557 atomictable.put(fen, new Integer(atomic+1));
560 void processAtomicExitNode(FlatAtomicExitNode fen, Hashtable<FlatNode, Integer> atomictable) {
561 int atomic=atomictable.get(fen).intValue();
562 atomictable.put(fen, new Integer(atomic-1));
565 private Hashtable<FlatNode, Set<TempDescriptor>> computeLiveTemps(FlatMethod fm) {
566 Hashtable<FlatNode, Set<TempDescriptor>> nodetotemps=new Hashtable<FlatNode, Set<TempDescriptor>>();
568 Set<FlatNode> toprocess=fm.getNodeSet();
570 while(!toprocess.isEmpty()) {
571 FlatNode fn=toprocess.iterator().next();
572 toprocess.remove(fn);
574 List<TempDescriptor> reads=Arrays.asList(fn.readsTemps());
575 List<TempDescriptor> writes=Arrays.asList(fn.readsTemps());
577 HashSet<TempDescriptor> tempset=new HashSet<TempDescriptor>();
578 for(int i=0;i<fn.numNext();i++) {
579 FlatNode fnnext=fn.getNext(i);
580 if (nodetotemps.containsKey(fnnext))
581 tempset.addAll(nodetotemps.get(fnnext));
583 tempset.removeAll(writes);
584 tempset.addAll(reads);
585 if (!nodetotemps.containsKey(fn)||
586 nodetotemps.get(fn).equals(tempset)) {
587 nodetotemps.put(fn, tempset);
588 for(int i=0;i<fn.numPrev();i++)
589 toprocess.add(fn.getPrev(i));
595 private void computeTempstoSave() {
596 for(Iterator<LocalityBinding> lbit=getLocalityBindings().iterator();lbit.hasNext();) {
597 LocalityBinding lb=lbit.next();
598 computeTempstoSave(lb);
602 /* Need to checkpoint all temps that could be read from along any
603 * path that are either:
604 1) Written to by any assignment inside the transaction
605 2) Read from a global temp.
607 Generate tempstosave map from
608 localitybinding->flatatomicenternode->Set<TempDescriptors>
611 private void computeTempstoSave(LocalityBinding lb) {
614 Hashtable<FlatNode, Integer> atomictab=getAtomic(lb);
615 Hashtable<FlatNode, Hashtable<TempDescriptor, Integer>> temptab=getNodeTempInfo(lb);
616 MethodDescriptor md=lb.getMethod();
617 FlatMethod fm=state.getMethodFlat(md);
619 Hashtable<FlatNode, Set<TempDescriptor>> nodetotemps=computeLiveTemps(fm);
620 Hashtable<FlatAtomicEnterNode, Set<TempDescriptor>> nodetosavetemps=new Hashtable<FlatAtomicEnterNode, Set<TempDescriptor>>();
621 tempstosave.put(lb, nodetosavetemps);
623 Hashtable<FlatNode, FlatAtomicEnterNode> nodemap=new Hashtable<FlatNode, FlatAtomicEnterNode>();
625 HashSet<FlatNode> toprocess=new HashSet<FlatNode>();
626 HashSet<FlatNode> discovered=new HashSet<FlatNode>();
629 while(!toprocess.isEmpty()) {
630 FlatNode fn=toprocess.iterator().next();
631 toprocess.remove(fn);
632 boolean isatomic=atomictab.get(fn).intValue()>0;
634 atomictab.get(fn.getPrev(0)).intValue()==0) {
635 assert(fn.getPrev(0).kind()==FKind.FlatAtomicEnterNode);
636 nodemap.put(fn, (FlatAtomicEnterNode)fn);
637 nodetosavetemps.put((FlatAtomicEnterNode)fn, new HashSet<TempDescriptor>());
638 } else if (isatomic) {
639 FlatAtomicEnterNode atomicnode=nodemap.get(fn);
640 Set<TempDescriptor> livetemps=nodetotemps.get(fn);
641 List<TempDescriptor> reads=Arrays.asList(fn.readsTemps());
642 List<TempDescriptor> writes=Arrays.asList(fn.readsTemps());
644 for(Iterator<TempDescriptor> tempit=livetemps.iterator();tempit.hasNext();) {
645 TempDescriptor tmp=tempit.next();
646 if (writes.contains(tmp)) {
647 nodetosavetemps.get(atomicnode).add(tmp);
648 } else if (reads.contains(tmp)&&temptab.get(fn).get(tmp)==GLOBAL) {
649 nodetosavetemps.get(atomicnode).add(tmp);
653 for(int i=0;i<fn.numNext();i++) {
654 FlatNode fnnext=fn.getNext(i);
655 if (!discovered.contains(fnnext)) {
656 discovered.add(fnnext);
657 toprocess.add(fnnext);
659 nodemap.put(fnnext, nodemap.get(fn));