2 import IR.Tree.Modifiers;
3 import IR.Tree.FlagExpressionNode;
4 import IR.Tree.DNFFlag;
5 import IR.Tree.DNFFlagAtom;
6 import IR.Tree.TagExpressionList;
7 import IR.Tree.OffsetNode;
13 import Analysis.TaskStateAnalysis.FlagState;
14 import Analysis.TaskStateAnalysis.FlagComparator;
15 import Analysis.TaskStateAnalysis.OptionalTaskDescriptor;
16 import Analysis.TaskStateAnalysis.Predicate;
17 import Analysis.TaskStateAnalysis.SafetyAnalysis;
18 import Analysis.TaskStateAnalysis.TaskIndex;
19 import Analysis.Locality.LocalityAnalysis;
20 import Analysis.Locality.LocalityBinding;
21 import Analysis.Locality.DiscoverConflicts;
22 import Analysis.Locality.DelayComputation;
23 import Analysis.CallGraph.CallGraph;
24 import Analysis.Prefetch.*;
25 import Analysis.Loops.WriteBarrier;
26 import Analysis.Loops.GlobalFieldType;
27 import Analysis.Locality.TypeAnalysis;
28 import Analysis.MLP.MLPAnalysis;
29 import Analysis.MLP.VariableSourceToken;
30 import Analysis.MLP.CodePlan;
31 import Analysis.MLP.SESEandAgePair;
33 public class BuildCode {
36 Hashtable paramstable;
41 String localsprefix="___locals___";
42 String localsprefixaddr="&"+localsprefix;
43 String localsprefixderef=localsprefix+".";
44 String fcrevert="___fcrevert___";
45 String paramsprefix="___params___";
46 String oidstr="___nextobject___";
47 String nextobjstr="___nextobject___";
48 String localcopystr="___localcopy___";
49 public static boolean GENERATEPRECISEGC=false;
50 public static String PREFIX="";
51 public static String arraytype="ArrayObject";
52 public static int flagcount = 0;
55 protected int maxtaskparams=0;
56 private int maxcount=0;
57 ClassDescriptor[] cdarray;
58 TypeDescriptor[] arraytable;
59 LocalityAnalysis locality;
60 Hashtable<LocalityBinding, TempDescriptor> reverttable;
61 Hashtable<LocalityBinding, Hashtable<TempDescriptor, TempDescriptor>> backuptable;
65 String mlperrstr = "if(status != 0) { "+
66 "sprintf(errmsg, \"MLP error at %s:%d\", __FILE__, __LINE__); "+
67 "perror(errmsg); exit(-1); }";
68 boolean nonSESEpass=true;
71 DiscoverConflicts recorddc;
72 DelayComputation delaycomp;
75 public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, SafetyAnalysis sa, PrefetchAnalysis pa) {
76 this(st, temptovar, typeutil, null, sa, pa, null);
79 public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, SafetyAnalysis sa, PrefetchAnalysis pa, MLPAnalysis mlpa) {
80 this(st, temptovar, typeutil, null, sa, pa, mlpa);
83 public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality, PrefetchAnalysis pa, MLPAnalysis mlpa) {
84 this(st, temptovar, typeutil, locality, null, pa, mlpa);
87 public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality, SafetyAnalysis sa, PrefetchAnalysis pa, MLPAnalysis mlpa) {
92 callgraph=new CallGraph(state);
94 oidstr="___objlocation___";
95 this.temptovar=temptovar;
96 paramstable=new Hashtable();
97 tempstable=new Hashtable();
98 fieldorder=new Hashtable();
99 flagorder=new Hashtable();
100 this.typeutil=typeutil;
101 virtualcalls=new Virtual(state,locality);
102 if (locality!=null) {
103 this.locality=locality;
104 this.reverttable=new Hashtable<LocalityBinding, TempDescriptor>();
105 this.backuptable=new Hashtable<LocalityBinding, Hashtable<TempDescriptor, TempDescriptor>>();
106 this.wb=new WriteBarrier(locality, st);
108 if (state.SINGLETM&&state.DCOPTS) {
109 TypeAnalysis typeanalysis=new TypeAnalysis(locality, st, typeutil,callgraph);
110 this.dc=new DiscoverConflicts(locality, st, typeanalysis, null);
113 if (state.DELAYCOMP) {
114 //TypeAnalysis typeanalysis=new TypeAnalysis(locality, st, typeutil,callgraph);
115 TypeAnalysis typeanalysis=new TypeAnalysis(locality, st, typeutil,callgraph);
116 GlobalFieldType gft=new GlobalFieldType(callgraph, st, typeutil.getMain());
117 delaycomp=new DelayComputation(locality, st, typeanalysis, gft);
118 delaycomp.doAnalysis();
119 dc=delaycomp.getConflicts();
120 recorddc=new DiscoverConflicts(locality, st, typeanalysis, delaycomp.getCannotDelayMap(), true, true, null);
121 recorddc.doAnalysis();
125 /** The buildCode method outputs C code for all the methods. The Flat
126 * versions of the methods must already be generated and stored in
127 * the State object. */
128 PrintWriter outsandbox=null;
130 public void buildCode() {
131 /* Create output streams to write to */
132 PrintWriter outclassdefs=null;
133 PrintWriter outstructs=null;
134 PrintWriter outrepairstructs=null;
135 PrintWriter outmethodheader=null;
136 PrintWriter outmethod=null;
137 PrintWriter outvirtual=null;
138 PrintWriter outtask=null;
139 PrintWriter outtaskdefs=null;
140 PrintWriter outoptionalarrays=null;
141 PrintWriter optionalheaders=null;
145 outsandbox=new PrintWriter(new FileOutputStream(PREFIX+"sandboxdefs.c"), true);
147 outstructs=new PrintWriter(new FileOutputStream(PREFIX+"structdefs.h"), true);
148 outmethodheader=new PrintWriter(new FileOutputStream(PREFIX+"methodheaders.h"), true);
149 outclassdefs=new PrintWriter(new FileOutputStream(PREFIX+"classdefs.h"), true);
150 outmethod=new PrintWriter(new FileOutputStream(PREFIX+"methods.c"), true);
151 outvirtual=new PrintWriter(new FileOutputStream(PREFIX+"virtualtable.h"), true);
153 outtask=new PrintWriter(new FileOutputStream(PREFIX+"task.h"), true);
154 outtaskdefs=new PrintWriter(new FileOutputStream(PREFIX+"taskdefs.c"), true);
155 if (state.OPTIONAL) {
156 outoptionalarrays=new PrintWriter(new FileOutputStream(PREFIX+"optionalarrays.c"), true);
157 optionalheaders=new PrintWriter(new FileOutputStream(PREFIX+"optionalstruct.h"), true);
160 if (state.structfile!=null) {
161 outrepairstructs=new PrintWriter(new FileOutputStream(PREFIX+state.structfile+".struct"), true);
163 } catch (Exception e) {
168 /* Build the virtual dispatch tables */
169 buildVirtualTables(outvirtual);
171 /* Output includes */
172 outmethodheader.println("#ifndef METHODHEADERS_H");
173 outmethodheader.println("#define METHODHEADERS_H");
174 outmethodheader.println("#include \"structdefs.h\"");
176 outmethodheader.println("#include \"dstm.h\"");
178 outmethodheader.println("#include \"sandbox.h\"");
180 if (state.SINGLETM) {
181 outmethodheader.println("#include \"tm.h\"");
182 outmethodheader.println("#include \"delaycomp.h\"");
184 if (state.ABORTREADERS) {
185 outmethodheader.println("#include \"abortreaders.h\"");
186 outmethodheader.println("#include <setjmp.h>");
189 outmethodheader.println("#include <stdlib.h>");
190 outmethodheader.println("#include <stdio.h>");
191 outmethodheader.println("#include <string.h>");
192 outmethodheader.println("#include \"mlp_runtime.h\"");
193 outmethodheader.println("#include \"psemaphore.h\"");
196 /* Output Structures */
197 outputStructs(outstructs);
199 // Output the C class declarations
200 // These could mutually reference each other
201 outputClassDeclarations(outclassdefs);
203 // Output function prototypes and structures for parameters
204 Iterator it=state.getClassSymbolTable().getDescriptorsIterator();
205 while(it.hasNext()) {
206 ClassDescriptor cn=(ClassDescriptor)it.next();
207 generateCallStructs(cn, outclassdefs, outstructs, outmethodheader);
209 outclassdefs.close();
212 /* Map flags to integers */
213 /* The runtime keeps track of flags using these integers */
214 it=state.getClassSymbolTable().getDescriptorsIterator();
215 while(it.hasNext()) {
216 ClassDescriptor cn=(ClassDescriptor)it.next();
220 generateTaskStructs(outstructs, outmethodheader);
222 /* Outputs generic task structures if this is a task
224 outputTaskTypes(outtask);
228 // have to initialize some SESE compiler data before
229 // analyzing normal methods, which must happen before
230 // generating SESE internal code
231 for(Iterator<FlatSESEEnterNode> seseit=mlpa.getAllSESEs().iterator();seseit.hasNext();) {
232 FlatSESEEnterNode fsen = seseit.next();
233 initializeSESE( fsen );
237 /* Build the actual methods */
238 outputMethods(outmethod);
240 // Output function prototypes and structures for SESE's and code
243 // used to differentiate, during code generation, whether we are
244 // passing over SESE body code, or non-SESE code
247 // first generate code for each sese's internals
248 for(Iterator<FlatSESEEnterNode> seseit=mlpa.getAllSESEs().iterator();seseit.hasNext();) {
249 FlatSESEEnterNode fsen = seseit.next();
250 generateMethodSESE(fsen, null, outstructs, outmethodheader, outmethod);
253 // then write the invokeSESE switch to decouple scheduler
254 // from having to do unique details of sese invocation
255 generateSESEinvocationMethod(outmethodheader, outmethod);
259 /* Output code for tasks */
260 outputTaskCode(outtaskdefs, outmethod);
262 /* Record maximum number of task parameters */
263 outstructs.println("#define MAXTASKPARAMS "+maxtaskparams);
264 } else if (state.main!=null) {
265 /* Generate main method */
266 outputMainMethod(outmethod);
269 /* Generate information for task with optional parameters */
270 if (state.TASK&&state.OPTIONAL) {
271 generateOptionalArrays(outoptionalarrays, optionalheaders, state.getAnalysisResult(), state.getOptionalTaskDescriptors());
272 outoptionalarrays.close();
275 /* Output structure definitions for repair tool */
276 if (state.structfile!=null) {
277 buildRepairStructs(outrepairstructs);
278 outrepairstructs.close();
282 outmethodheader.println("#endif");
283 outmethodheader.close();
285 outstructs.println("#endif");
290 /* This code just generates the main C method for java programs.
291 * The main C method packs up the arguments into a string array
292 * and passes it to the java main method. */
294 private void outputMainMethod(PrintWriter outmethod) {
295 outmethod.println("int main(int argc, const char *argv[]) {");
296 outmethod.println(" int i;");
299 //outmethod.println(" pthread_once( &mlpOnceObj, mlpInitOncePerThread );");
300 outmethod.println(" workScheduleInit( "+state.MLP_NUMCORES+", invokeSESEmethod );");
304 outmethod.println("#ifdef TRANSSTATS \n");
305 outmethod.println("handle();\n");
306 outmethod.println("#endif\n");
308 if (state.THREAD||state.DSM||state.SINGLETM) {
309 outmethod.println("initializethreads();");
312 outmethod.println("if (dstmStartup(argv[1])) {");
313 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
314 outmethod.println(" struct ArrayObject * stringarray=allocate_newarray(NULL, STRINGARRAYTYPE, argc-2);");
316 outmethod.println(" struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc-2);");
319 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
320 outmethod.println(" struct ArrayObject * stringarray=allocate_newarray(NULL, STRINGARRAYTYPE, argc-1);");
322 outmethod.println(" struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc-1);");
326 outmethod.println(" for(i=2;i<argc;i++) {");
328 outmethod.println(" for(i=1;i<argc;i++) {");
329 outmethod.println(" int length=strlen(argv[i]);");
330 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
331 outmethod.println(" struct ___String___ *newstring=NewString(NULL, argv[i], length);");
333 outmethod.println(" struct ___String___ *newstring=NewString(argv[i], length);");
336 outmethod.println(" ((void **)(((char *)& stringarray->___length___)+sizeof(int)))[i-2]=newstring;");
338 outmethod.println(" ((void **)(((char *)& stringarray->___length___)+sizeof(int)))[i-1]=newstring;");
339 outmethod.println(" }");
341 MethodDescriptor md=typeutil.getMain();
342 ClassDescriptor cd=typeutil.getMainClass();
344 outmethod.println(" {");
345 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
346 if (state.DSM||state.SINGLETM) {
347 outmethod.print(" struct "+cd.getSafeSymbol()+locality.getMain().getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={");
349 outmethod.print(" struct "+cd.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={");
350 outmethod.println("1, NULL,"+"stringarray};");
351 if (state.DSM||state.SINGLETM)
352 outmethod.println(" "+cd.getSafeSymbol()+locality.getMain().getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(& __parameterlist__);");
354 outmethod.println(" "+cd.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(& __parameterlist__);");
356 if (state.DSM||state.SINGLETM)
357 outmethod.println(" "+cd.getSafeSymbol()+locality.getMain().getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(stringarray);");
359 outmethod.println(" "+cd.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(stringarray);");
361 outmethod.println(" }");
364 outmethod.println("}");
367 if (state.THREAD||state.DSM||state.SINGLETM) {
368 outmethod.println("pthread_mutex_lock(&gclistlock);");
369 outmethod.println("threadcount--;");
370 outmethod.println("pthread_cond_signal(&gccond);");
371 outmethod.println("pthread_mutex_unlock(&gclistlock);");
374 if (state.DSM||state.SINGLETM) {
375 outmethod.println("#ifdef TRANSSTATS \n");
376 outmethod.println("printf(\"****** Transaction Stats ******\\n\");");
377 outmethod.println("printf(\"numTransCommit= %d\\n\", numTransCommit);");
378 outmethod.println("printf(\"numTransAbort= %d\\n\", numTransAbort);");
379 outmethod.println("printf(\"nSoftAbort= %d\\n\", nSoftAbort);");
381 outmethod.println("printf(\"nchashSearch= %d\\n\", nchashSearch);");
382 outmethod.println("printf(\"nmhashSearch= %d\\n\", nmhashSearch);");
383 outmethod.println("printf(\"nprehashSearch= %d\\n\", nprehashSearch);");
384 outmethod.println("printf(\"nRemoteReadSend= %d\\n\", nRemoteSend);");
385 outmethod.println("printf(\"getResponse= %d\\n\", getResponse);");
386 outmethod.println("printf(\"bytesSent= %d\\n\", bytesSent);");
387 outmethod.println("printf(\"bytesRecv= %d\\n\", bytesRecv);");
388 } else if (state.SINGLETM) {
389 outmethod.println("printf(\"nSoftAbortAbort= %d\\n\", nSoftAbortAbort);");
390 outmethod.println("printf(\"nSoftAbortCommit= %d\\n\", nSoftAbortCommit);");
391 outmethod.println("#ifdef STMSTATS\n");
392 outmethod.println("for(i=0; i<TOTALNUMCLASSANDARRAY; i++) {\n");
393 outmethod.println(" printf(\"typesCausingAbort[%2d] numaccess= %5d numabort= %3d\\n\", i, typesCausingAbort[i].numaccess, typesCausingAbort[i].numabort);\n");
394 outmethod.println("}\n");
395 outmethod.println("#endif\n");
396 outmethod.println("fflush(stdout);");
398 outmethod.println("#endif\n");
401 if (state.THREAD||state.SINGLETM)
402 outmethod.println("pthread_exit(NULL);");
405 outmethod.println(" workScheduleBegin();");
408 outmethod.println("}");
411 /* This method outputs code for each task. */
413 private void outputTaskCode(PrintWriter outtaskdefs, PrintWriter outmethod) {
414 /* Compile task based program */
415 outtaskdefs.println("#include \"task.h\"");
416 outtaskdefs.println("#include \"methodheaders.h\"");
417 Iterator taskit=state.getTaskSymbolTable().getDescriptorsIterator();
418 while(taskit.hasNext()) {
419 TaskDescriptor td=(TaskDescriptor)taskit.next();
420 FlatMethod fm=state.getMethodFlat(td);
421 generateFlatMethod(fm, null, outmethod);
422 generateTaskDescriptor(outtaskdefs, fm, td);
425 //Output task descriptors
426 taskit=state.getTaskSymbolTable().getDescriptorsIterator();
427 outtaskdefs.println("struct taskdescriptor * taskarray[]= {");
429 while(taskit.hasNext()) {
430 TaskDescriptor td=(TaskDescriptor)taskit.next();
434 outtaskdefs.println(",");
435 outtaskdefs.print("&task_"+td.getSafeSymbol());
437 outtaskdefs.println("};");
439 outtaskdefs.println("int numtasks="+state.getTaskSymbolTable().getValueSet().size()+";");
442 /* This method outputs most of the methods.c file. This includes
443 * some standard includes and then an array with the sizes of
444 * objets and array that stores supertype and then the code for
445 * the Java methods.. */
447 protected void outputMethods(PrintWriter outmethod) {
448 outmethod.println("#include \"methodheaders.h\"");
449 outmethod.println("#include \"virtualtable.h\"");
450 outmethod.println("#include \"runtime.h\"");
452 outmethod.println("#include \"sandboxdefs.c\"");
455 outmethod.println("#include \"addPrefetchEnhance.h\"");
456 outmethod.println("#include \"localobjects.h\"");
458 if (state.FASTCHECK) {
459 outmethod.println("#include \"localobjects.h\"");
461 if(state.MULTICORE) {
462 outmethod.println("#include \"task.h\"");
463 outmethod.println("#include \"multicoreruntime.h\"");
464 outmethod.println("#include \"runtime_arch.h\"");
466 if (state.THREAD||state.DSM||state.SINGLETM)
467 outmethod.println("#include <thread.h>");
468 if (state.main!=null) {
469 outmethod.println("#include <string.h>");
471 if (state.CONSCHECK) {
472 outmethod.println("#include \"checkers.h\"");
475 outmethod.println("#include <stdlib.h>");
476 outmethod.println("#include <stdio.h>");
477 outmethod.println("#include \"mlp_runtime.h\"");
478 outmethod.println("#include \"psemaphore.h\"");
482 //Store the sizes of classes & array elements
483 generateSizeArray(outmethod);
485 //Store table of supertypes
486 generateSuperTypeTable(outmethod);
488 //Store the layout of classes
489 generateLayoutStructs(outmethod);
491 /* Generate code for methods */
492 if (state.DSM||state.SINGLETM) {
493 for(Iterator<LocalityBinding> lbit=locality.getLocalityBindings().iterator(); lbit.hasNext();) {
494 LocalityBinding lb=lbit.next();
495 MethodDescriptor md=lb.getMethod();
496 FlatMethod fm=state.getMethodFlat(md);
498 if (!md.getModifiers().isNative()) {
499 generateFlatMethod(fm, lb, outmethod);
503 Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
504 while(classit.hasNext()) {
505 ClassDescriptor cn=(ClassDescriptor)classit.next();
506 Iterator methodit=cn.getMethods();
507 while(methodit.hasNext()) {
508 /* Classify parameters */
509 MethodDescriptor md=(MethodDescriptor)methodit.next();
510 FlatMethod fm=state.getMethodFlat(md);
511 if (!md.getModifiers().isNative()) {
512 generateFlatMethod(fm, null, outmethod);
519 protected void outputStructs(PrintWriter outstructs) {
520 outstructs.println("#ifndef STRUCTDEFS_H");
521 outstructs.println("#define STRUCTDEFS_H");
522 outstructs.println("#include \"classdefs.h\"");
523 outstructs.println("#ifndef INTPTR");
524 outstructs.println("#ifdef BIT64");
525 outstructs.println("#define INTPTR long");
526 outstructs.println("#else");
527 outstructs.println("#define INTPTR int");
528 outstructs.println("#endif");
529 outstructs.println("#endif");
531 outstructs.println("#include \"mlp_runtime.h\"");
532 outstructs.println("#include \"psemaphore.h\"");
535 /* Output #defines that the runtime uses to determine type
536 * numbers for various objects it needs */
537 outstructs.println("#define MAXCOUNT "+maxcount);
538 if (state.DSM||state.SINGLETM) {
539 LocalityBinding lbrun=new LocalityBinding(typeutil.getRun(), false);
541 lbrun.setGlobalThis(LocalityAnalysis.GLOBAL);
543 else if (state.SINGLETM) {
544 lbrun.setGlobalThis(LocalityAnalysis.NORMAL);
546 outstructs.println("#define RUNMETHOD "+virtualcalls.getLocalityNumber(lbrun));
550 LocalityBinding lbexecute = new LocalityBinding(typeutil.getExecute(), false);
552 lbexecute.setGlobalThis(LocalityAnalysis.GLOBAL);
553 else if( state.SINGLETM)
554 lbexecute.setGlobalThis(LocalityAnalysis.NORMAL);
555 outstructs.println("#define EXECUTEMETHOD " + virtualcalls.getLocalityNumber(lbexecute));
558 outstructs.println("#define STRINGARRAYTYPE "+
559 (state.getArrayNumber(
560 (new TypeDescriptor(typeutil.getClass(TypeUtil.StringClass))).makeArray(state))+state.numClasses()));
562 outstructs.println("#define OBJECTARRAYTYPE "+
563 (state.getArrayNumber(
564 (new TypeDescriptor(typeutil.getClass(TypeUtil.ObjectClass))).makeArray(state))+state.numClasses()));
567 outstructs.println("#define STRINGTYPE "+typeutil.getClass(TypeUtil.StringClass).getId());
568 outstructs.println("#define CHARARRAYTYPE "+
569 (state.getArrayNumber((new TypeDescriptor(TypeDescriptor.CHAR)).makeArray(state))+state.numClasses()));
571 outstructs.println("#define BYTEARRAYTYPE "+
572 (state.getArrayNumber((new TypeDescriptor(TypeDescriptor.BYTE)).makeArray(state))+state.numClasses()));
574 outstructs.println("#define BYTEARRAYARRAYTYPE "+
575 (state.getArrayNumber((new TypeDescriptor(TypeDescriptor.BYTE)).makeArray(state).makeArray(state))+state.numClasses()));
577 outstructs.println("#define NUMCLASSES "+state.numClasses());
578 int totalClassSize = state.numClasses() + state.numArrays();
579 outstructs.println("#define TOTALNUMCLASSANDARRAY "+ totalClassSize);
581 outstructs.println("#define STARTUPTYPE "+typeutil.getClass(TypeUtil.StartupClass).getId());
582 outstructs.println("#define TAGTYPE "+typeutil.getClass(TypeUtil.TagClass).getId());
583 outstructs.println("#define TAGARRAYTYPE "+
584 (state.getArrayNumber(new TypeDescriptor(typeutil.getClass(TypeUtil.TagClass)).makeArray(state))+state.numClasses()));
588 protected void outputClassDeclarations(PrintWriter outclassdefs) {
589 if (state.THREAD||state.DSM||state.SINGLETM)
590 outclassdefs.println("#include <pthread.h>");
591 outclassdefs.println("#ifndef INTPTR");
592 outclassdefs.println("#ifdef BIT64");
593 outclassdefs.println("#define INTPTR long");
594 outclassdefs.println("#else");
595 outclassdefs.println("#define INTPTR int");
596 outclassdefs.println("#endif");
597 outclassdefs.println("#endif");
599 outclassdefs.println("#include \"optionalstruct.h\"");
600 outclassdefs.println("struct "+arraytype+";");
601 /* Start by declaring all structs */
602 Iterator it=state.getClassSymbolTable().getDescriptorsIterator();
603 while(it.hasNext()) {
604 ClassDescriptor cn=(ClassDescriptor)it.next();
605 outclassdefs.println("struct "+cn.getSafeSymbol()+";");
607 outclassdefs.println("");
608 //Print out definition for array type
609 outclassdefs.println("struct "+arraytype+" {");
610 outclassdefs.println(" int type;");
612 outclassdefs.println(" pthread_t tid;");
613 outclassdefs.println(" void * lockentry;");
614 outclassdefs.println(" int lockcount;");
617 outclassdefs.println(" int flag;");
618 if(!state.MULTICORE) {
619 outclassdefs.println(" void * flagptr;");
621 outclassdefs.println(" int version;");
622 outclassdefs.println(" int * lock;"); // lock entry for this obj
623 outclassdefs.println(" int mutex;");
624 outclassdefs.println(" int lockcount;");
625 if(state.MULTICOREGC) {
626 outclassdefs.println(" int marked;");
630 outclassdefs.println(" int numfses;");
631 outclassdefs.println(" int * fses;");
634 printClassStruct(typeutil.getClass(TypeUtil.ObjectClass), outclassdefs);
636 if (state.STMARRAY) {
637 outclassdefs.println(" int lowindex;");
638 outclassdefs.println(" int highindex;");
642 outclassdefs.println(" int paddingforarray;");
644 outclassdefs.println(" int ___length___;");
645 outclassdefs.println("};\n");
646 outclassdefs.println("extern int classsize[];");
647 outclassdefs.println("extern int hasflags[];");
648 outclassdefs.println("extern unsigned INTPTR * pointerarray[];");
649 outclassdefs.println("extern int supertypes[];");
652 /** Prints out definitions for generic task structures */
654 private void outputTaskTypes(PrintWriter outtask) {
655 outtask.println("#ifndef _TASK_H");
656 outtask.println("#define _TASK_H");
657 outtask.println("struct parameterdescriptor {");
658 outtask.println("int type;");
659 outtask.println("int numberterms;");
660 outtask.println("int *intarray;");
661 outtask.println("void * queue;");
662 outtask.println("int numbertags;");
663 outtask.println("int *tagarray;");
664 outtask.println("};");
666 outtask.println("struct taskdescriptor {");
667 outtask.println("void * taskptr;");
668 outtask.println("int numParameters;");
669 outtask.println(" int numTotal;");
670 outtask.println("struct parameterdescriptor **descriptorarray;");
671 outtask.println("char * name;");
672 outtask.println("};");
673 outtask.println("extern struct taskdescriptor * taskarray[];");
674 outtask.println("extern numtasks;");
675 outtask.println("#endif");
679 private void buildRepairStructs(PrintWriter outrepairstructs) {
680 Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
681 while(classit.hasNext()) {
682 ClassDescriptor cn=(ClassDescriptor)classit.next();
683 outrepairstructs.println("structure "+cn.getSymbol()+" {");
684 outrepairstructs.println(" int __type__;");
686 outrepairstructs.println(" int __flag__;");
687 if(!state.MULTICORE) {
688 outrepairstructs.println(" int __flagptr__;");
691 printRepairStruct(cn, outrepairstructs);
692 outrepairstructs.println("}\n");
695 for(int i=0; i<state.numArrays(); i++) {
696 TypeDescriptor tdarray=arraytable[i];
697 TypeDescriptor tdelement=tdarray.dereference();
698 outrepairstructs.println("structure "+arraytype+"_"+state.getArrayNumber(tdarray)+" {");
699 outrepairstructs.println(" int __type__;");
700 printRepairStruct(typeutil.getClass(TypeUtil.ObjectClass), outrepairstructs);
701 outrepairstructs.println(" int length;");
703 // Need to add support to repair tool for this
704 if (tdelement.isClass()||tdelement.isArray())
705 outrepairstructs.println(" "+tdelement.getRepairSymbol()+" * elem[this.length];");
707 outrepairstructs.println(" "+tdelement.getRepairSymbol()+" elem[this.length];");
709 outrepairstructs.println("}\n");
713 private void printRepairStruct(ClassDescriptor cn, PrintWriter output) {
714 ClassDescriptor sp=cn.getSuperDesc();
716 printRepairStruct(sp, output);
718 Vector fields=(Vector)fieldorder.get(cn);
720 for(int i=0; i<fields.size(); i++) {
721 FieldDescriptor fd=(FieldDescriptor)fields.get(i);
722 if (fd.getType().isArray()) {
723 output.println(" "+arraytype+"_"+ state.getArrayNumber(fd.getType()) +" * "+fd.getSymbol()+";");
724 } else if (fd.getType().isClass())
725 output.println(" "+fd.getType().getRepairSymbol()+" * "+fd.getSymbol()+";");
726 else if (fd.getType().isFloat())
727 output.println(" int "+fd.getSymbol()+"; /* really float */");
729 output.println(" "+fd.getType().getRepairSymbol()+" "+fd.getSymbol()+";");
733 /** This method outputs TaskDescriptor information */
734 private void generateTaskDescriptor(PrintWriter output, FlatMethod fm, TaskDescriptor task) {
735 for (int i=0; i<task.numParameters(); i++) {
736 VarDescriptor param_var=task.getParameter(i);
737 TypeDescriptor param_type=task.getParamType(i);
738 FlagExpressionNode param_flag=task.getFlag(param_var);
739 TagExpressionList param_tag=task.getTag(param_var);
742 if (param_flag==null) {
743 output.println("int parameterdnf_"+i+"_"+task.getSafeSymbol()+"[]={");
744 output.println("0x0, 0x0 };");
747 DNFFlag dflag=param_flag.getDNF();
748 dnfterms=dflag.size();
750 Hashtable flags=(Hashtable)flagorder.get(param_type.getClassDesc());
751 output.println("int parameterdnf_"+i+"_"+task.getSafeSymbol()+"[]={");
752 for(int j=0; j<dflag.size(); j++) {
755 Vector term=dflag.get(j);
758 for(int k=0; k<term.size(); k++) {
759 DNFFlagAtom dfa=(DNFFlagAtom)term.get(k);
760 FlagDescriptor fd=dfa.getFlag();
761 boolean negated=dfa.getNegated();
762 int flagid=1<<((Integer)flags.get(fd)).intValue();
767 output.print("0x"+Integer.toHexString(andmask)+", 0x"+Integer.toHexString(checkmask));
769 output.println("};");
772 output.println("int parametertag_"+i+"_"+task.getSafeSymbol()+"[]={");
773 //BUG...added next line to fix, test with any task program
775 for(int j=0; j<param_tag.numTags(); j++) {
778 /* for each tag we need */
779 /* which slot it is */
780 /* what type it is */
781 TagVarDescriptor tvd=(TagVarDescriptor)task.getParameterTable().get(param_tag.getName(j));
782 TempDescriptor tmp=param_tag.getTemp(j);
783 int slot=fm.getTagInt(tmp);
784 output.println(slot+", "+state.getTagId(tvd.getTag()));
786 output.println("};");
788 output.println("struct parameterdescriptor parameter_"+i+"_"+task.getSafeSymbol()+"={");
789 output.println("/* type */"+param_type.getClassDesc().getId()+",");
790 output.println("/* number of DNF terms */"+dnfterms+",");
791 output.println("parameterdnf_"+i+"_"+task.getSafeSymbol()+",");
792 output.println("0,");
793 //BUG, added next line to fix and else statement...test
794 //with any task program
796 output.println("/* number of tags */"+param_tag.numTags()+",");
798 output.println("/* number of tags */ 0,");
799 output.println("parametertag_"+i+"_"+task.getSafeSymbol());
800 output.println("};");
804 output.println("struct parameterdescriptor * parameterdescriptors_"+task.getSafeSymbol()+"[] = {");
805 for (int i=0; i<task.numParameters(); i++) {
808 output.print("¶meter_"+i+"_"+task.getSafeSymbol());
810 output.println("};");
812 output.println("struct taskdescriptor task_"+task.getSafeSymbol()+"={");
813 output.println("&"+task.getSafeSymbol()+",");
814 output.println("/* number of parameters */" +task.numParameters() + ",");
815 int numtotal=task.numParameters()+fm.numTags();
816 output.println("/* number total parameters */" +numtotal + ",");
817 output.println("parameterdescriptors_"+task.getSafeSymbol()+",");
818 output.println("\""+task.getSymbol()+"\"");
819 output.println("};");
823 /** The buildVirtualTables method outputs the virtual dispatch
824 * tables for methods. */
826 protected void buildVirtualTables(PrintWriter outvirtual) {
827 Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
828 while(classit.hasNext()) {
829 ClassDescriptor cd=(ClassDescriptor)classit.next();
830 if (virtualcalls.getMethodCount(cd)>maxcount)
831 maxcount=virtualcalls.getMethodCount(cd);
833 MethodDescriptor[][] virtualtable=null;
834 LocalityBinding[][] lbvirtualtable=null;
835 if (state.DSM||state.SINGLETM)
836 lbvirtualtable=new LocalityBinding[state.numClasses()+state.numArrays()][maxcount];
838 virtualtable=new MethodDescriptor[state.numClasses()+state.numArrays()][maxcount];
840 /* Fill in virtual table */
841 classit=state.getClassSymbolTable().getDescriptorsIterator();
842 while(classit.hasNext()) {
843 ClassDescriptor cd=(ClassDescriptor)classit.next();
844 if (state.DSM||state.SINGLETM)
845 fillinRow(cd, lbvirtualtable, cd.getId());
847 fillinRow(cd, virtualtable, cd.getId());
850 ClassDescriptor objectcd=typeutil.getClass(TypeUtil.ObjectClass);
851 Iterator arrayit=state.getArrayIterator();
852 while(arrayit.hasNext()) {
853 TypeDescriptor td=(TypeDescriptor)arrayit.next();
854 int id=state.getArrayNumber(td);
855 if (state.DSM||state.SINGLETM)
856 fillinRow(objectcd, lbvirtualtable, id+state.numClasses());
858 fillinRow(objectcd, virtualtable, id+state.numClasses());
861 outvirtual.print("void * virtualtable[]={");
862 boolean needcomma=false;
863 for(int i=0; i<state.numClasses()+state.numArrays(); i++) {
864 for(int j=0; j<maxcount; j++) {
866 outvirtual.print(", ");
867 if ((state.DSM||state.SINGLETM)&&lbvirtualtable[i][j]!=null) {
868 LocalityBinding lb=lbvirtualtable[i][j];
869 MethodDescriptor md=lb.getMethod();
870 outvirtual.print("& "+md.getClassDesc().getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor());
871 } else if (!(state.DSM||state.SINGLETM)&&virtualtable[i][j]!=null) {
872 MethodDescriptor md=virtualtable[i][j];
873 outvirtual.print("& "+md.getClassDesc().getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor());
875 outvirtual.print("0");
879 outvirtual.println("");
881 outvirtual.println("};");
885 private void fillinRow(ClassDescriptor cd, MethodDescriptor[][] virtualtable, int rownum) {
886 /* Get inherited methods */
887 if (cd.getSuperDesc()!=null)
888 fillinRow(cd.getSuperDesc(), virtualtable, rownum);
889 /* Override them with our methods */
890 for(Iterator it=cd.getMethods(); it.hasNext();) {
891 MethodDescriptor md=(MethodDescriptor)it.next();
892 if (md.isStatic()||md.getReturnType()==null)
894 int methodnum=virtualcalls.getMethodNumber(md);
895 virtualtable[rownum][methodnum]=md;
899 private void fillinRow(ClassDescriptor cd, LocalityBinding[][] virtualtable, int rownum) {
900 /* Get inherited methods */
901 if (cd.getSuperDesc()!=null)
902 fillinRow(cd.getSuperDesc(), virtualtable, rownum);
903 /* Override them with our methods */
904 if (locality.getClassBindings(cd)!=null)
905 for(Iterator<LocalityBinding> lbit=locality.getClassBindings(cd).iterator(); lbit.hasNext();) {
906 LocalityBinding lb=lbit.next();
907 MethodDescriptor md=lb.getMethod();
908 //Is the method static or a constructor
909 if (md.isStatic()||md.getReturnType()==null)
911 int methodnum=virtualcalls.getLocalityNumber(lb);
912 virtualtable[rownum][methodnum]=lb;
916 /** Generate array that contains the sizes of class objects. The
917 * object allocation functions in the runtime use this
920 private void generateSizeArray(PrintWriter outclassdefs) {
921 outclassdefs.print("extern struct prefetchCountStats * evalPrefetch;\n");
922 outclassdefs.print("#ifdef TRANSSTATS \n");
923 outclassdefs.print("extern int numTransAbort;\n");
924 outclassdefs.print("extern int numTransCommit;\n");
925 outclassdefs.print("extern int nSoftAbort;\n");
927 outclassdefs.print("extern int nchashSearch;\n");
928 outclassdefs.print("extern int nmhashSearch;\n");
929 outclassdefs.print("extern int nprehashSearch;\n");
930 outclassdefs.print("extern int nRemoteSend;\n");
931 outclassdefs.print("extern int getResponse;\n");
932 outclassdefs.print("extern int bytesSent;\n");
933 outclassdefs.print("extern int bytesRecv;\n");
934 outclassdefs.print("extern void handle();\n");
935 } else if (state.SINGLETM) {
936 outclassdefs.println("extern int nSoftAbortAbort;");
937 outclassdefs.println("extern int nSoftAbortCommit;");
938 outclassdefs.println("#ifdef STMSTATS\n");
939 outclassdefs.println("extern objtypestat_t typesCausingAbort[];");
940 outclassdefs.println("#endif\n");
942 outclassdefs.print("#endif\n");
943 outclassdefs.print("int numprefetchsites = " + pa.prefetchsiteid + ";\n");
945 Iterator it=state.getClassSymbolTable().getDescriptorsIterator();
946 cdarray=new ClassDescriptor[state.numClasses()];
948 while(it.hasNext()) {
949 ClassDescriptor cd=(ClassDescriptor)it.next();
950 cdarray[cd.getId()]=cd;
953 arraytable=new TypeDescriptor[state.numArrays()];
955 Iterator arrayit=state.getArrayIterator();
956 while(arrayit.hasNext()) {
957 TypeDescriptor td=(TypeDescriptor)arrayit.next();
958 int id=state.getArrayNumber(td);
964 /* Print out types */
965 outclassdefs.println("/* ");
966 for(int i=0; i<state.numClasses(); i++) {
967 ClassDescriptor cd=cdarray[i];
969 outclassdefs.println("NULL " + i);
971 outclassdefs.println(cd +" "+i);
975 for(int i=0; i<state.numArrays(); i++) {
976 TypeDescriptor arraytd=arraytable[i];
977 outclassdefs.println(arraytd.toPrettyString() +" "+(i+state.numClasses()));
980 outclassdefs.println("*/");
983 outclassdefs.print("int classsize[]={");
985 boolean needcomma=false;
986 for(int i=0; i<state.numClasses(); i++) {
988 outclassdefs.print(", ");
990 outclassdefs.print("sizeof(struct "+cdarray[i].getSafeSymbol()+")");
992 outclassdefs.print("0");
998 for(int i=0; i<state.numArrays(); i++) {
1000 outclassdefs.print(", ");
1001 TypeDescriptor tdelement=arraytable[i].dereference();
1002 if (tdelement.isArray()||tdelement.isClass())
1003 outclassdefs.print("sizeof(void *)");
1005 outclassdefs.print("sizeof("+tdelement.getSafeSymbol()+")");
1009 outclassdefs.println("};");
1011 ClassDescriptor objectclass=typeutil.getClass(TypeUtil.ObjectClass);
1013 outclassdefs.print("int typearray[]={");
1014 for(int i=0; i<state.numClasses(); i++) {
1015 ClassDescriptor cd=cdarray[i];
1016 ClassDescriptor supercd=i>0?cd.getSuperDesc():null;
1018 outclassdefs.print(", ");
1020 outclassdefs.print("-1");
1022 outclassdefs.print(supercd.getId());
1026 for(int i=0; i<state.numArrays(); i++) {
1027 TypeDescriptor arraytd=arraytable[i];
1028 ClassDescriptor arraycd=arraytd.getClassDesc();
1029 if (arraycd==null) {
1031 outclassdefs.print(", ");
1032 outclassdefs.print(objectclass.getId());
1036 ClassDescriptor cd=arraycd.getSuperDesc();
1039 TypeDescriptor supertd=new TypeDescriptor(cd);
1040 supertd.setArrayCount(arraytd.getArrayCount());
1041 type=state.getArrayNumber(supertd);
1043 type+=state.numClasses();
1046 cd=cd.getSuperDesc();
1049 outclassdefs.print(", ");
1050 outclassdefs.print(type);
1054 outclassdefs.println("};");
1059 outclassdefs.print("int typearray2[]={");
1060 for(int i=0; i<state.numArrays(); i++) {
1061 TypeDescriptor arraytd=arraytable[i];
1062 ClassDescriptor arraycd=arraytd.getClassDesc();
1063 if (arraycd==null) {
1065 outclassdefs.print(", ");
1066 outclassdefs.print("-1");
1070 ClassDescriptor cd=arraycd.getSuperDesc();
1071 int level=arraytd.getArrayCount()-1;
1073 for(; level>0; level--) {
1074 TypeDescriptor supertd=new TypeDescriptor(objectclass);
1075 supertd.setArrayCount(level);
1076 type=state.getArrayNumber(supertd);
1078 type+=state.numClasses();
1083 outclassdefs.print(", ");
1084 outclassdefs.print(type);
1088 outclassdefs.println("};");
1091 /** Constructs params and temp objects for each method or task.
1092 * These objects tell the compiler which temps need to be
1095 protected void generateTempStructs(FlatMethod fm, LocalityBinding lb) {
1096 MethodDescriptor md=fm.getMethod();
1097 TaskDescriptor task=fm.getTask();
1098 Set<TempDescriptor> saveset=lb!=null ? locality.getTempSet(lb) : null;
1099 ParamsObject objectparams=md!=null ? new ParamsObject(md,tag++) : new ParamsObject(task, tag++);
1101 paramstable.put(lb, objectparams);
1102 backuptable.put(lb, new Hashtable<TempDescriptor, TempDescriptor>());
1103 } else if (md!=null)
1104 paramstable.put(md, objectparams);
1106 paramstable.put(task, objectparams);
1108 for(int i=0; i<fm.numParameters(); i++) {
1109 TempDescriptor temp=fm.getParameter(i);
1110 TypeDescriptor type=temp.getType();
1111 if (type.isPtr()&&((GENERATEPRECISEGC) || (this.state.MULTICOREGC)))
1112 objectparams.addPtr(temp);
1114 objectparams.addPrim(temp);
1115 if(lb!=null&&saveset.contains(temp)) {
1116 backuptable.get(lb).put(temp, temp.createNew());
1120 for(int i=0; i<fm.numTags(); i++) {
1121 TempDescriptor temp=fm.getTag(i);
1122 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC))
1123 objectparams.addPtr(temp);
1125 objectparams.addPrim(temp);
1128 TempObject objecttemps=md!=null ? new TempObject(objectparams,md,tag++) : new TempObject(objectparams, task, tag++);
1130 tempstable.put(lb, objecttemps);
1132 tempstable.put(md, objecttemps);
1134 tempstable.put(task, objecttemps);
1136 for(Iterator nodeit=fm.getNodeSet().iterator(); nodeit.hasNext();) {
1137 FlatNode fn=(FlatNode)nodeit.next();
1138 TempDescriptor[] writes=fn.writesTemps();
1139 for(int i=0; i<writes.length; i++) {
1140 TempDescriptor temp=writes[i];
1141 TypeDescriptor type=temp.getType();
1142 if (type.isPtr()&&((GENERATEPRECISEGC) || (this.state.MULTICOREGC)))
1143 objecttemps.addPtr(temp);
1145 objecttemps.addPrim(temp);
1146 if(lb!=null&&saveset.contains(temp)&&
1147 !backuptable.get(lb).containsKey(temp))
1148 backuptable.get(lb).put(temp, temp.createNew());
1152 /* Create backup temps */
1154 for(Iterator<TempDescriptor> tmpit=backuptable.get(lb).values().iterator(); tmpit.hasNext();) {
1155 TempDescriptor tmp=tmpit.next();
1156 TypeDescriptor type=tmp.getType();
1157 if (type.isPtr()&&((GENERATEPRECISEGC) || (this.state.MULTICOREGC)))
1158 objecttemps.addPtr(tmp);
1160 objecttemps.addPrim(tmp);
1162 /* Create temp to hold revert table */
1163 if (state.DSM&&(lb.getHasAtomic()||lb.isAtomic())) {
1164 TempDescriptor reverttmp=new TempDescriptor("revertlist", typeutil.getClass(TypeUtil.ObjectClass));
1165 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC))
1166 objecttemps.addPtr(reverttmp);
1168 objecttemps.addPrim(reverttmp);
1169 reverttable.put(lb, reverttmp);
1174 /** This method outputs the following information about classes
1176 * (1) For classes, what are the locations of pointers.
1177 * (2) For arrays, does the array contain pointers or primitives.
1178 * (3) For classes, does the class contain flags.
1181 private void generateLayoutStructs(PrintWriter output) {
1182 Iterator it=state.getClassSymbolTable().getDescriptorsIterator();
1183 while(it.hasNext()) {
1184 ClassDescriptor cn=(ClassDescriptor)it.next();
1185 output.println("unsigned INTPTR "+cn.getSafeSymbol()+"_pointers[]={");
1186 Iterator allit=cn.getFieldTable().getAllDescriptorsIterator();
1188 while(allit.hasNext()) {
1189 FieldDescriptor fd=(FieldDescriptor)allit.next();
1190 TypeDescriptor type=fd.getType();
1191 if (state.DSM&&fd.isGlobal()) //Don't GC the global objects for now
1196 output.print(count);
1197 allit=cn.getFieldTable().getAllDescriptorsIterator();
1198 while(allit.hasNext()) {
1199 FieldDescriptor fd=(FieldDescriptor)allit.next();
1200 TypeDescriptor type=fd.getType();
1201 if (state.DSM&&fd.isGlobal()) //Don't GC the global objects for now
1204 output.println(",");
1205 output.print("((unsigned INTPTR)&(((struct "+cn.getSafeSymbol() +" *)0)->"+fd.getSafeSymbol()+"))");
1208 output.println("};");
1210 output.println("unsigned INTPTR * pointerarray[]={");
1211 boolean needcomma=false;
1212 for(int i=0; i<state.numClasses(); i++) {
1213 ClassDescriptor cn=cdarray[i];
1215 output.println(",");
1218 output.print(cn.getSafeSymbol()+"_pointers");
1220 output.print("NULL");
1224 for(int i=0; i<state.numArrays(); i++) {
1226 output.println(", ");
1227 TypeDescriptor tdelement=arraytable[i].dereference();
1228 if (tdelement.isArray()||tdelement.isClass())
1229 output.print("((unsigned INTPTR *)1)");
1235 output.println("};");
1237 output.println("int hasflags[]={");
1238 for(int i=0; i<state.numClasses(); i++) {
1239 ClassDescriptor cn=cdarray[i];
1241 output.println(", ");
1243 if ((cn != null) && (cn.hasFlags()))
1248 output.println("};");
1251 /** Print out table to give us supertypes */
1252 private void generateSuperTypeTable(PrintWriter output) {
1253 output.println("int supertypes[]={");
1254 boolean needcomma=false;
1255 for(int i=0; i<state.numClasses(); i++) {
1256 ClassDescriptor cn=cdarray[i];
1258 output.println(",");
1260 if ((cn != null) && (cn.getSuperDesc()!=null)) {
1261 ClassDescriptor cdsuper=cn.getSuperDesc();
1262 output.print(cdsuper.getId());
1266 output.println("};");
1269 /** Force consistent field ordering between inherited classes. */
1271 private void printClassStruct(ClassDescriptor cn, PrintWriter classdefout) {
1273 ClassDescriptor sp=cn.getSuperDesc();
1275 printClassStruct(sp, classdefout);
1277 if (!fieldorder.containsKey(cn)) {
1278 Vector fields=new Vector();
1279 fieldorder.put(cn,fields);
1280 Vector fieldvec=cn.getFieldVec();
1281 for(int i=0;i<fieldvec.size();i++) {
1282 FieldDescriptor fd=(FieldDescriptor)fieldvec.get(i);
1283 if ((sp==null||!sp.getFieldTable().contains(fd.getSymbol())))
1287 Vector fields=(Vector)fieldorder.get(cn);
1289 for(int i=0; i<fields.size(); i++) {
1290 FieldDescriptor fd=(FieldDescriptor)fields.get(i);
1291 if (fd.getType().isClass()||fd.getType().isArray())
1292 classdefout.println(" struct "+fd.getType().getSafeSymbol()+" * "+fd.getSafeSymbol()+";");
1294 classdefout.println(" "+fd.getType().getSafeSymbol()+" "+fd.getSafeSymbol()+";");
1299 /* Map flags to integers consistently between inherited
1302 protected void mapFlags(ClassDescriptor cn) {
1303 ClassDescriptor sp=cn.getSuperDesc();
1307 if (!flagorder.containsKey(cn)) {
1308 Hashtable flags=new Hashtable();
1309 flagorder.put(cn,flags);
1311 Hashtable superflags=(Hashtable)flagorder.get(sp);
1312 Iterator superflagit=superflags.keySet().iterator();
1313 while(superflagit.hasNext()) {
1314 FlagDescriptor fd=(FlagDescriptor)superflagit.next();
1315 Integer number=(Integer)superflags.get(fd);
1316 flags.put(fd, number);
1317 if ((number.intValue()+1)>max)
1318 max=number.intValue()+1;
1322 Iterator flagit=cn.getFlags();
1323 while(flagit.hasNext()) {
1324 FlagDescriptor fd=(FlagDescriptor)flagit.next();
1325 if (sp==null||!sp.getFlagTable().contains(fd.getSymbol()))
1326 flags.put(fd, new Integer(max++));
1332 /** This function outputs (1) structures that parameters are
1333 * passed in (when PRECISE GC is enabled) and (2) function
1334 * prototypes for the methods */
1336 protected void generateCallStructs(ClassDescriptor cn, PrintWriter classdefout, PrintWriter output, PrintWriter headersout) {
1337 /* Output class structure */
1338 classdefout.println("struct "+cn.getSafeSymbol()+" {");
1339 classdefout.println(" int type;");
1341 classdefout.println(" pthread_t tid;");
1342 classdefout.println(" void * lockentry;");
1343 classdefout.println(" int lockcount;");
1347 classdefout.println(" int flag;");
1348 if((!state.MULTICORE) || (cn.getSymbol().equals("TagDescriptor"))) {
1349 classdefout.println(" void * flagptr;");
1350 } else if (state.MULTICORE) {
1351 classdefout.println(" int version;");
1352 classdefout.println(" int * lock;"); // lock entry for this obj
1353 classdefout.println(" int mutex;");
1354 classdefout.println(" int lockcount;");
1355 if(state.MULTICOREGC) {
1356 classdefout.println(" int marked;");
1359 if (state.OPTIONAL) {
1360 classdefout.println(" int numfses;");
1361 classdefout.println(" int * fses;");
1364 printClassStruct(cn, classdefout);
1365 classdefout.println("};\n");
1367 if (state.DSM||state.SINGLETM) {
1368 /* Cycle through LocalityBindings */
1369 HashSet<MethodDescriptor> nativemethods=new HashSet<MethodDescriptor>();
1370 Set<LocalityBinding> lbset=locality.getClassBindings(cn);
1372 for(Iterator<LocalityBinding> lbit=lbset.iterator(); lbit.hasNext();) {
1373 LocalityBinding lb=lbit.next();
1374 MethodDescriptor md=lb.getMethod();
1375 if (md.getModifiers().isNative()) {
1376 //make sure we only print a native method once
1377 if (nativemethods.contains(md)) {
1378 FlatMethod fm=state.getMethodFlat(md);
1379 generateTempStructs(fm, lb);
1382 nativemethods.add(md);
1384 generateMethod(cn, md, lb, headersout, output);
1387 for(Iterator methodit=cn.getMethods(); methodit.hasNext();) {
1388 MethodDescriptor md=(MethodDescriptor)methodit.next();
1389 if (md.getModifiers().isNative()&&!nativemethods.contains(md)) {
1390 //Need to build param structure for library code
1391 FlatMethod fm=state.getMethodFlat(md);
1392 generateTempStructs(fm, null);
1393 generateMethodParam(cn, md, null, output);
1398 for(Iterator methodit=cn.getMethods(); methodit.hasNext();) {
1399 MethodDescriptor md=(MethodDescriptor)methodit.next();
1400 generateMethod(cn, md, null, headersout, output);
1404 private void generateMethodParam(ClassDescriptor cn, MethodDescriptor md, LocalityBinding lb, PrintWriter output) {
1405 /* Output parameter structure */
1406 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
1407 ParamsObject objectparams=(ParamsObject) paramstable.get(lb!=null ? lb : md);
1408 if ((state.DSM||state.SINGLETM)&&lb!=null)
1409 output.println("struct "+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params {");
1411 output.println("struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params {");
1412 output.println(" INTPTR size;");
1413 output.println(" void * next;");
1414 for(int i=0; i<objectparams.numPointers(); i++) {
1415 TempDescriptor temp=objectparams.getPointer(i);
1416 output.println(" struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol()+";");
1418 output.println("};\n");
1422 private void generateMethod(ClassDescriptor cn, MethodDescriptor md, LocalityBinding lb, PrintWriter headersout, PrintWriter output) {
1423 FlatMethod fm=state.getMethodFlat(md);
1424 generateTempStructs(fm, lb);
1426 ParamsObject objectparams=(ParamsObject) paramstable.get(lb!=null ? lb : md);
1427 TempObject objecttemps=(TempObject) tempstable.get(lb!=null ? lb : md);
1429 generateMethodParam(cn, md, lb, output);
1431 /* Output temp structure */
1432 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
1433 if (state.DSM||state.SINGLETM)
1434 output.println("struct "+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals {");
1436 output.println("struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals {");
1437 output.println(" INTPTR size;");
1438 output.println(" void * next;");
1439 for(int i=0; i<objecttemps.numPointers(); i++) {
1440 TempDescriptor temp=objecttemps.getPointer(i);
1441 if (temp.getType().isNull())
1442 output.println(" void * "+temp.getSafeSymbol()+";");
1444 output.println(" struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol()+";");
1446 output.println("};\n");
1449 /********* Output method declaration ***********/
1450 if (state.DSM||state.SINGLETM) {
1451 headersout.println("#define D"+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+" 1");
1453 headersout.println("#define D"+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+" 1");
1455 /* First the return type */
1456 if (md.getReturnType()!=null) {
1457 if (md.getReturnType().isClass()||md.getReturnType().isArray())
1458 headersout.print("struct " + md.getReturnType().getSafeSymbol()+" * ");
1460 headersout.print(md.getReturnType().getSafeSymbol()+" ");
1462 //catch the constructor case
1463 headersout.print("void ");
1465 /* Next the method name */
1466 if (state.DSM||state.SINGLETM) {
1467 headersout.print(cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(");
1469 headersout.print(cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(");
1471 boolean printcomma=false;
1472 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
1473 if (state.DSM||state.SINGLETM) {
1474 headersout.print("struct "+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params * "+paramsprefix);
1476 headersout.print("struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params * "+paramsprefix);
1480 /* Output parameter list*/
1481 for(int i=0; i<objectparams.numPrimitives(); i++) {
1482 TempDescriptor temp=objectparams.getPrimitive(i);
1484 headersout.print(", ");
1486 if (temp.getType().isClass()||temp.getType().isArray())
1487 headersout.print("struct " + temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol());
1489 headersout.print(temp.getType().getSafeSymbol()+" "+temp.getSafeSymbol());
1491 headersout.println(");\n");
1495 /** This function outputs (1) structures that parameters are
1496 * passed in (when PRECISE GC is enabled) and (2) function
1497 * prototypes for the tasks */
1499 private void generateTaskStructs(PrintWriter output, PrintWriter headersout) {
1500 /* Cycle through tasks */
1501 Iterator taskit=state.getTaskSymbolTable().getDescriptorsIterator();
1503 while(taskit.hasNext()) {
1504 /* Classify parameters */
1505 TaskDescriptor task=(TaskDescriptor)taskit.next();
1506 FlatMethod fm=state.getMethodFlat(task);
1507 generateTempStructs(fm, null);
1509 ParamsObject objectparams=(ParamsObject) paramstable.get(task);
1510 TempObject objecttemps=(TempObject) tempstable.get(task);
1512 /* Output parameter structure */
1513 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
1514 output.println("struct "+task.getSafeSymbol()+"_params {");
1516 output.println(" INTPTR size;");
1517 output.println(" void * next;");
1518 for(int i=0; i<objectparams.numPointers(); i++) {
1519 TempDescriptor temp=objectparams.getPointer(i);
1520 output.println(" struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol()+";");
1523 output.println("};\n");
1524 if ((objectparams.numPointers()+fm.numTags())>maxtaskparams) {
1525 maxtaskparams=objectparams.numPointers()+fm.numTags();
1529 /* Output temp structure */
1530 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
1531 output.println("struct "+task.getSafeSymbol()+"_locals {");
1532 output.println(" INTPTR size;");
1533 output.println(" void * next;");
1534 for(int i=0; i<objecttemps.numPointers(); i++) {
1535 TempDescriptor temp=objecttemps.getPointer(i);
1536 if (temp.getType().isNull())
1537 output.println(" void * "+temp.getSafeSymbol()+";");
1538 else if(temp.getType().isTag())
1539 output.println(" struct "+
1540 (new TypeDescriptor(typeutil.getClass(TypeUtil.TagClass))).getSafeSymbol()+" * "+temp.getSafeSymbol()+";");
1542 output.println(" struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol()+";");
1544 output.println("};\n");
1547 /* Output task declaration */
1548 headersout.print("void " + task.getSafeSymbol()+"(");
1550 boolean printcomma=false;
1551 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
1552 headersout.print("struct "+task.getSafeSymbol()+"_params * "+paramsprefix);
1554 headersout.print("void * parameterarray[]");
1555 headersout.println(");\n");
1559 /***** Generate code for FlatMethod fm. *****/
1561 Hashtable<FlatAtomicEnterNode, AtomicRecord> atomicmethodmap;
1562 static int atomicmethodcount=0;
1564 private void generateFlatMethod(FlatMethod fm, LocalityBinding lb, PrintWriter output) {
1565 if (State.PRINTFLAT)
1566 System.out.println(fm.printMethod());
1567 MethodDescriptor md=fm.getMethod();
1568 TaskDescriptor task=fm.getTask();
1569 ClassDescriptor cn=md!=null ? md.getClassDesc() : null;
1570 ParamsObject objectparams=(ParamsObject)paramstable.get(lb!=null ? lb : md!=null ? md : task);
1572 HashSet<AtomicRecord> arset=null;
1574 if (state.DELAYCOMP&&!lb.isAtomic()&&lb.getHasAtomic()) {
1576 if (atomicmethodmap==null)
1577 atomicmethodmap=new Hashtable<FlatAtomicEnterNode, AtomicRecord>();
1579 //fix these so we get right strings for local variables
1580 localsprefixaddr=localsprefix;
1581 localsprefixderef=localsprefix+"->";
1582 arset=new HashSet<AtomicRecord>();
1584 //Generate commit methods here
1585 for(Iterator<FlatNode> fnit=fm.getNodeSet().iterator();fnit.hasNext();) {
1586 FlatNode fn=fnit.next();
1587 if (fn.kind()==FKind.FlatAtomicEnterNode&&
1588 locality.getAtomic(lb).get(fn.getPrev(0)).intValue()==0) {
1589 //We have an atomic enter
1590 FlatAtomicEnterNode faen=(FlatAtomicEnterNode) fn;
1591 Set<FlatNode> exitset=faen.getExits();
1593 String methodname=md.getSymbol()+(atomicmethodcount++);
1594 AtomicRecord ar=new AtomicRecord();
1598 atomicmethodmap.put(faen, ar);
1600 //build data structure declaration
1601 output.println("struct atomicprimitives_"+methodname+" {");
1603 Set<FlatNode> recordset=delaycomp.livecode(lb);
1604 Set<TempDescriptor> liveinto=delaycomp.liveinto(lb, faen, recordset);
1605 Set<TempDescriptor> liveout=delaycomp.liveout(lb, faen);
1606 Set<TempDescriptor> liveoutvirtualread=delaycomp.liveoutvirtualread(lb, faen);
1608 ar.reallivein=new HashSet(liveinto);
1610 ar.liveoutvirtualread=liveoutvirtualread;
1612 for(Iterator<TempDescriptor> it=liveinto.iterator(); it.hasNext();) {
1613 TempDescriptor tmp=it.next();
1614 //remove the pointers
1615 if (tmp.getType().isPtr()) {
1618 //let's print it here
1619 output.println(tmp.getType().getSafeSymbol()+" "+tmp.getSafeSymbol()+";");
1622 for(Iterator<TempDescriptor> it=liveout.iterator(); it.hasNext();) {
1623 TempDescriptor tmp=it.next();
1624 //remove the pointers
1625 if (tmp.getType().isPtr()) {
1627 } else if (!liveinto.contains(tmp)) {
1628 //let's print it here
1629 output.println(tmp.getType().getSafeSymbol()+" "+tmp.getSafeSymbol()+";");
1632 output.println("};");
1634 //print out method name
1635 output.println("void "+methodname+"(struct "+ cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params * "+paramsprefix+", struct "+ cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals *"+localsprefix+", struct atomicprimitives_"+methodname+" * primitives) {");
1636 //build code for commit method
1638 //first define local primitives
1639 Set<TempDescriptor> alltemps=delaycomp.alltemps(lb, faen, recordset);
1640 for(Iterator<TempDescriptor> tmpit=alltemps.iterator();tmpit.hasNext();) {
1641 TempDescriptor tmp=tmpit.next();
1642 if (!tmp.getType().isPtr()) {
1643 if (liveinto.contains(tmp)||liveoutvirtualread.contains(tmp)) {
1644 //read from live into set
1645 output.println(tmp.getType().getSafeSymbol()+" "+tmp.getSafeSymbol()+"=primitives->"+tmp.getSafeSymbol()+";");
1648 output.println(tmp.getType().getSafeSymbol()+" "+tmp.getSafeSymbol()+";");
1652 //turn off write barrier generation
1654 state.SINGLETM=false;
1655 generateCode(faen, fm, lb, exitset, output, false);
1656 state.SINGLETM=true;
1657 //turn on write barrier generation
1659 output.println("}\n\n");
1663 //redefine these back to normal
1665 localsprefixaddr="&"+localsprefix;
1666 localsprefixderef=localsprefix+".";
1668 generateHeader(fm, lb, md!=null ? md : task,output);
1669 TempObject objecttemp=(TempObject) tempstable.get(lb!=null ? lb : md!=null ? md : task);
1671 if (state.DELAYCOMP&&!lb.isAtomic()&&lb.getHasAtomic()) {
1672 for(Iterator<AtomicRecord> arit=arset.iterator();arit.hasNext();) {
1673 AtomicRecord ar=arit.next();
1674 output.println("struct atomicprimitives_"+ar.name+" primitives_"+ar.name+";");
1678 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
1679 if (md!=null&&(state.DSM||state.SINGLETM))
1680 output.print(" struct "+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals "+localsprefix+"={");
1681 else if (md!=null&&!(state.DSM||state.SINGLETM))
1682 output.print(" struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals "+localsprefix+"={");
1684 output.print(" struct "+task.getSafeSymbol()+"_locals "+localsprefix+"={");
1686 output.print(objecttemp.numPointers()+",");
1687 output.print(paramsprefix);
1688 for(int j=0; j<objecttemp.numPointers(); j++)
1689 output.print(", NULL");
1690 output.println("};");
1693 for(int i=0; i<objecttemp.numPrimitives(); i++) {
1694 TempDescriptor td=objecttemp.getPrimitive(i);
1695 TypeDescriptor type=td.getType();
1697 output.println(" void * "+td.getSafeSymbol()+";");
1698 else if (type.isClass()||type.isArray())
1699 output.println(" struct "+type.getSafeSymbol()+" * "+td.getSafeSymbol()+";");
1701 output.println(" "+type.getSafeSymbol()+" "+td.getSafeSymbol()+";");
1706 if( fm.getNext(0) instanceof FlatSESEEnterNode ) {
1707 FlatSESEEnterNode callerSESEplaceholder = (FlatSESEEnterNode) fm.getNext( 0 );
1708 if( callerSESEplaceholder != mlpa.getMainSESE() ) {
1709 // declare variables for naming static SESE's
1710 output.println(" /* static SESE names */");
1711 Iterator<SESEandAgePair> pItr = callerSESEplaceholder.getNeededStaticNames().iterator();
1712 while( pItr.hasNext() ) {
1713 SESEandAgePair p = pItr.next();
1714 output.println(" void* "+p+";");
1717 // declare variables for tracking dynamic sources
1718 output.println(" /* dynamic variable sources */");
1719 Iterator<TempDescriptor> dynSrcItr = callerSESEplaceholder.getDynamicVarSet().iterator();
1720 while( dynSrcItr.hasNext() ) {
1721 TempDescriptor dynSrcVar = dynSrcItr.next();
1722 output.println(" void* "+dynSrcVar+"_srcSESE;");
1723 output.println(" int "+dynSrcVar+"_srcOffset;");
1730 /* Check to see if we need to do a GC if this is a
1731 * multi-threaded program...*/
1733 if (((state.THREAD||state.DSM||state.SINGLETM)&&GENERATEPRECISEGC)
1734 || this.state.MULTICOREGC) {
1735 //Don't bother if we aren't in recursive methods...The loops case will catch it
1736 if (callgraph.getAllMethods(md).contains(md)) {
1737 if (state.DSM&&lb.isAtomic())
1738 output.println("if (needtocollect) checkcollect2("+localsprefixaddr+");");
1739 else if (this.state.MULTICOREGC) {
1740 output.println("if(gcflag) gc("+localsprefixaddr+");");
1742 output.println("if (needtocollect) checkcollect("+localsprefixaddr+");");
1746 generateCode(fm.getNext(0), fm, lb, null, output, true);
1748 output.println("}\n\n");
1752 protected void initializeSESE( FlatSESEEnterNode fsen ) {
1754 FlatMethod fm = fsen.getfmEnclosing();
1755 MethodDescriptor md = fm.getMethod();
1756 ClassDescriptor cn = md.getClassDesc();
1759 // Creates bogus method descriptor to index into tables
1760 Modifiers modBogus = new Modifiers();
1761 MethodDescriptor mdBogus =
1762 new MethodDescriptor( modBogus,
1763 new TypeDescriptor( TypeDescriptor.VOID ),
1764 "sese_"+fsen.getPrettyIdentifier()+fsen.getIdentifier()
1767 mdBogus.setClassDesc( fsen.getcdEnclosing() );
1768 FlatMethod fmBogus = new FlatMethod( mdBogus, null );
1769 fsen.setfmBogus( fmBogus );
1770 fsen.setmdBogus( mdBogus );
1772 Set<TempDescriptor> inSetAndOutSet = new HashSet<TempDescriptor>();
1773 inSetAndOutSet.addAll( fsen.getInVarSet() );
1774 inSetAndOutSet.addAll( fsen.getOutVarSet() );
1776 // Build paramsobj for bogus method descriptor
1777 ParamsObject objectparams = new ParamsObject( mdBogus, tag++ );
1778 paramstable.put( mdBogus, objectparams );
1780 Iterator<TempDescriptor> itr = inSetAndOutSet.iterator();
1781 while( itr.hasNext() ) {
1782 TempDescriptor temp = itr.next();
1783 TypeDescriptor type = temp.getType();
1784 if( type.isPtr() ) {
1785 objectparams.addPtr( temp );
1787 objectparams.addPrim( temp );
1791 // Build normal temp object for bogus method descriptor
1792 TempObject objecttemps = new TempObject( objectparams, mdBogus, tag++ );
1793 tempstable.put( mdBogus, objecttemps );
1795 for( Iterator nodeit = fsen.getNodeSet().iterator(); nodeit.hasNext(); ) {
1796 FlatNode fn = (FlatNode)nodeit.next();
1797 TempDescriptor[] writes = fn.writesTemps();
1799 for( int i = 0; i < writes.length; i++ ) {
1800 TempDescriptor temp = writes[i];
1801 TypeDescriptor type = temp.getType();
1803 if( type.isPtr() ) {
1804 objecttemps.addPtr( temp );
1806 objecttemps.addPrim( temp );
1812 protected void generateMethodSESE(FlatSESEEnterNode fsen,
1814 PrintWriter outputStructs,
1815 PrintWriter outputMethHead,
1816 PrintWriter outputMethods
1819 ParamsObject objectparams = (ParamsObject) paramstable.get( fsen.getmdBogus() );
1820 TempObject objecttemps = (TempObject) tempstable .get( fsen.getmdBogus() );
1822 // generate locals structure
1823 outputStructs.println("struct "+
1824 fsen.getcdEnclosing().getSafeSymbol()+
1825 fsen.getmdBogus().getSafeSymbol()+"_"+
1826 fsen.getmdBogus().getSafeMethodDescriptor()+
1828 outputStructs.println(" INTPTR size;");
1829 outputStructs.println(" void * next;");
1830 for(int i=0; i<objecttemps.numPointers(); i++) {
1831 TempDescriptor temp=objecttemps.getPointer(i);
1833 if( fsen.getPrettyIdentifier().equals( "calc" ) ) {
1834 System.out.println( " got a pointer "+temp );
1837 if (temp.getType().isNull())
1838 outputStructs.println(" void * "+temp.getSafeSymbol()+";");
1840 outputStructs.println(" struct "+
1841 temp.getType().getSafeSymbol()+" * "+
1842 temp.getSafeSymbol()+";");
1844 outputStructs.println("};\n");
1847 // generate the SESE record structure
1848 outputStructs.println(fsen.getSESErecordName()+" {");
1850 // data common to any SESE, and it must be placed first so
1851 // a module that doesn't know what kind of SESE record this
1852 // is can cast the pointer to a common struct
1853 outputStructs.println(" SESEcommon common;");
1855 // then garbage list stuff
1856 outputStructs.println(" INTPTR size;");
1857 outputStructs.println(" void * next;");
1859 // in-set source tracking
1860 // in-vars that are READY come from parent, don't need anything
1861 // stuff STATIC needs a custom SESE pointer for each age pair
1862 Iterator<SESEandAgePair> itrStaticInVarSrcs = fsen.getStaticInVarSrcs().iterator();
1863 while( itrStaticInVarSrcs.hasNext() ) {
1864 SESEandAgePair srcPair = itrStaticInVarSrcs.next();
1865 outputStructs.println(" "+srcPair.getSESE().getSESErecordName()+"* "+srcPair+";");
1868 // DYNAMIC stuff needs a source SESE ptr and offset
1869 Iterator<TempDescriptor> itrDynInVars = fsen.getDynamicInVarSet().iterator();
1870 while( itrDynInVars.hasNext() ) {
1871 TempDescriptor dynInVar = itrDynInVars.next();
1872 outputStructs.println(" void* "+dynInVar+"_srcSESE;");
1873 outputStructs.println(" int "+dynInVar+"_srcOffset;");
1876 // space for all in and out set primitives
1877 Set<TempDescriptor> inSetAndOutSet = new HashSet<TempDescriptor>();
1878 inSetAndOutSet.addAll( fsen.getInVarSet() );
1879 inSetAndOutSet.addAll( fsen.getOutVarSet() );
1881 Set<TempDescriptor> inSetAndOutSetPrims = new HashSet<TempDescriptor>();
1883 Iterator<TempDescriptor> itr = inSetAndOutSet.iterator();
1884 while( itr.hasNext() ) {
1885 TempDescriptor temp = itr.next();
1886 TypeDescriptor type = temp.getType();
1887 if( !type.isPtr() ) {
1888 inSetAndOutSetPrims.add( temp );
1892 Iterator<TempDescriptor> itrPrims = inSetAndOutSetPrims.iterator();
1893 while( itrPrims.hasNext() ) {
1894 TempDescriptor temp = itrPrims.next();
1895 TypeDescriptor type = temp.getType();
1896 outputStructs.println(" "+temp.getType().getSafeSymbol()+" "+temp.getSafeSymbol()+";");
1899 for(int i=0; i<objectparams.numPointers(); i++) {
1900 TempDescriptor temp=objectparams.getPointer(i);
1901 if (temp.getType().isNull())
1902 outputStructs.println(" void * "+temp.getSafeSymbol()+";");
1904 outputStructs.println(" struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol()+";");
1907 outputStructs.println("};\n");
1910 // write method declaration to header file
1911 outputMethHead.print("void ");
1912 outputMethHead.print(fsen.getSESEmethodName()+"(");
1913 outputMethHead.print(fsen.getSESErecordName()+"* "+paramsprefix);
1914 outputMethHead.println(");\n");
1917 generateFlatMethodSESE( fsen.getfmBogus(),
1918 fsen.getcdEnclosing(),
1924 private void generateFlatMethodSESE(FlatMethod fm,
1926 FlatSESEEnterNode fsen,
1927 FlatSESEExitNode seseExit,
1931 MethodDescriptor md=fm.getMethod();
1933 output.print("void ");
1934 output.print(fsen.getSESEmethodName()+"(");
1935 output.print(fsen.getSESErecordName()+"* "+paramsprefix);
1936 output.println("){\n");
1938 TempObject objecttemp=(TempObject) tempstable.get(md);
1940 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
1941 output.print(" struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals "+localsprefix+"={");
1942 output.print(objecttemp.numPointers()+",");
1943 output.print("(void*) &("+paramsprefix+"->size)");
1944 for(int j=0; j<objecttemp.numPointers(); j++)
1945 output.print(", NULL");
1946 output.println("};");
1949 output.println(" /* regular local primitives */");
1950 for(int i=0; i<objecttemp.numPrimitives(); i++) {
1951 TempDescriptor td=objecttemp.getPrimitive(i);
1952 TypeDescriptor type=td.getType();
1954 output.println(" void * "+td.getSafeSymbol()+";");
1955 else if (type.isClass()||type.isArray())
1956 output.println(" struct "+type.getSafeSymbol()+" * "+td.getSafeSymbol()+";");
1958 output.println(" "+type.getSafeSymbol()+" "+td.getSafeSymbol()+";");
1962 // declare variables for naming static SESE's
1963 output.println(" /* static SESE names */");
1964 Iterator<SESEandAgePair> pItr = fsen.getNeededStaticNames().iterator();
1965 while( pItr.hasNext() ) {
1966 SESEandAgePair p = pItr.next();
1967 output.println(" void* "+p+";");
1970 // declare variables for tracking dynamic sources
1971 output.println(" /* dynamic variable sources */");
1972 Iterator<TempDescriptor> dynSrcItr = fsen.getDynamicVarSet().iterator();
1973 while( dynSrcItr.hasNext() ) {
1974 TempDescriptor dynSrcVar = dynSrcItr.next();
1975 output.println(" void* "+dynSrcVar+"_srcSESE;");
1976 output.println(" int "+dynSrcVar+"_srcOffset;");
1979 // declare local temps for in-set primitives, and if it is
1980 // a ready-source variable, get the value from the record
1981 output.println(" /* local temps for in-set primitives */");
1982 Iterator<TempDescriptor> itrInSet = fsen.getInVarSet().iterator();
1983 while( itrInSet.hasNext() ) {
1984 TempDescriptor temp = itrInSet.next();
1985 TypeDescriptor type = temp.getType();
1986 if( !type.isPtr() ) {
1987 if( fsen.getReadyInVarSet().contains( temp ) ) {
1988 output.println(" "+type+" "+temp+" = "+paramsprefix+"->"+temp+";");
1990 output.println(" "+type+" "+temp+";");
1995 // declare local temps for out-set primitives if its not already
1996 // in the in-set, and it's value will get written so no problem
1997 output.println(" /* local temp for out-set prim, not already in the in-set */");
1998 Iterator<TempDescriptor> itrOutSet = fsen.getOutVarSet().iterator();
1999 while( itrOutSet.hasNext() ) {
2000 TempDescriptor temp = itrOutSet.next();
2001 TypeDescriptor type = temp.getType();
2002 if( !type.isPtr() && !fsen.getInVarSet().contains( temp ) ) {
2003 output.println(" "+type+" "+temp+";");
2007 // copy in-set into place, ready vars were already
2008 // copied when the SESE was issued
2009 Iterator<TempDescriptor> tempItr;
2011 // static vars are from a known SESE
2012 tempItr = fsen.getStaticInVarSet().iterator();
2013 while( tempItr.hasNext() ) {
2014 TempDescriptor temp = tempItr.next();
2015 VariableSourceToken vst = fsen.getStaticInVarSrc( temp );
2016 SESEandAgePair srcPair = new SESEandAgePair( vst.getSESE(), vst.getAge() );
2018 // can't grab something from this source until it is done
2019 output.println(" {");
2020 output.println(" SESEcommon* com = (SESEcommon*)"+paramsprefix+"->"+srcPair+";" );
2021 output.println(" pthread_mutex_lock( &(com->lock) );");
2022 output.println(" while( com->doneExecuting == FALSE ) {");
2023 output.println(" pthread_cond_wait( &(com->doneCond), &(com->lock) );");
2024 output.println(" }");
2025 output.println(" pthread_mutex_unlock( &(com->lock) );");
2027 output.println(" "+generateTemp( fsen.getfmBogus(), temp, null )+
2028 " = "+paramsprefix+"->"+srcPair+"->"+vst.getAddrVar()+";");
2030 output.println(" }");
2033 // dynamic vars come from an SESE and src
2034 tempItr = fsen.getDynamicInVarSet().iterator();
2035 while( tempItr.hasNext() ) {
2036 TempDescriptor temp = tempItr.next();
2037 TypeDescriptor type = temp.getType();
2039 // go grab it from the SESE source
2040 output.println(" if( "+paramsprefix+"->"+temp+"_srcSESE != NULL ) {");
2042 // gotta wait until the source is done
2043 output.println(" SESEcommon* com = (SESEcommon*)"+paramsprefix+"->"+temp+"_srcSESE;" );
2044 output.println(" pthread_mutex_lock( &(com->lock) );");
2045 output.println(" while( com->doneExecuting == FALSE ) {");
2046 output.println(" pthread_cond_wait( &(com->doneCond), &(com->lock) );");
2047 output.println(" }");
2048 output.println(" pthread_mutex_unlock( &(com->lock) );");
2051 if( type.isNull() ) {
2053 } else if( type.isClass() || type.isArray() ) {
2054 typeStr = "struct "+type.getSafeSymbol()+"*";
2056 typeStr = type.getSafeSymbol();
2059 output.println(" "+generateTemp( fsen.getfmBogus(), temp, null )+
2060 " = *(("+typeStr+"*) ("+
2061 paramsprefix+"->"+temp+"_srcSESE + "+
2062 paramsprefix+"->"+temp+"_srcOffset));");
2064 // or if the source was our parent, its in the record to grab
2065 output.println(" } else {");
2066 output.println(" "+generateTemp( fsen.getfmBogus(), temp, null )+
2067 " = "+paramsprefix+"->"+temp+";");
2068 output.println(" }");
2071 // Check to see if we need to do a GC if this is a
2072 // multi-threaded program...
2073 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
2074 //Don't bother if we aren't in recursive methods...The loops case will catch it
2075 if (callgraph.getAllMethods(md).contains(md)) {
2076 if(this.state.MULTICOREGC) {
2077 output.println("if(gcflag) gc("+localsprefixaddr+");");
2079 output.println("if (needtocollect) checkcollect("+localsprefixaddr+");");
2084 // initialize thread-local var to a non-zero, invalid address
2085 output.println(" seseCaller = (SESEcommon*) 0x2;");
2087 HashSet<FlatNode> exitset=new HashSet<FlatNode>();
2088 exitset.add(seseExit);
2090 generateCode(fsen.getNext(0), fm, null, exitset, output, true);
2092 output.println("}\n\n");
2096 // when a new mlp thread is created for an issued SESE, it is started
2097 // by running this method which blocks on a cond variable until
2098 // it is allowed to transition to execute. Then a case statement
2099 // allows it to invoke the method with the proper SESE body, and after
2100 // exiting the SESE method, executes proper SESE exit code before the
2101 // thread can be destroyed
2102 private void generateSESEinvocationMethod(PrintWriter outmethodheader,
2103 PrintWriter outmethod
2106 outmethodheader.println("void* invokeSESEmethod( void* seseRecord );");
2107 outmethod.println( "void* invokeSESEmethod( void* seseRecord ) {");
2108 outmethod.println( " int status;");
2109 outmethod.println( " char errmsg[128];");
2111 // generate a case for each SESE class that can be invoked
2112 outmethod.println( " switch( *((int*)seseRecord) ) {");
2113 outmethod.println( " ");
2114 for(Iterator<FlatSESEEnterNode> seseit=mlpa.getAllSESEs().iterator();seseit.hasNext();) {
2115 FlatSESEEnterNode fsen = seseit.next();
2117 outmethod.println( " /* "+fsen.getPrettyIdentifier()+" */");
2118 outmethod.println( " case "+fsen.getIdentifier()+":");
2119 outmethod.println( " "+fsen.getSESEmethodName()+"( seseRecord );");
2121 if( fsen.equals( mlpa.getMainSESE() ) ) {
2122 outmethod.println( " /* work scheduler works forever, explicitly exit */");
2123 outmethod.println( " exit( 0 );");
2126 outmethod.println( " break;");
2127 outmethod.println( "");
2130 // default case should never be taken, error out
2131 outmethod.println( " default:");
2132 outmethod.println( " printf(\"Error: unknown SESE class ID in invoke method.\\n\");");
2133 outmethod.println( " exit(-30);");
2134 outmethod.println( " break;");
2135 outmethod.println( " }");
2136 outmethod.println( " return NULL;");
2137 outmethod.println( "}\n\n");
2141 protected void generateCode(FlatNode first,
2144 Set<FlatNode> stopset,
2145 PrintWriter output, boolean firstpass) {
2147 /* Assign labels to FlatNode's if necessary.*/
2148 Hashtable<FlatNode, Integer> nodetolabel=assignLabels(first, stopset);
2150 Set<FlatNode> storeset=null;
2151 HashSet<FlatNode> genset=null;
2152 Set<FlatNode> unionset=null;
2154 if (state.DELAYCOMP&&!lb.isAtomic()&&lb.getHasAtomic()) {
2155 storeset=delaycomp.livecode(lb);
2156 genset=new HashSet<FlatNode>();
2158 genset.addAll(delaycomp.getCannotDelay(lb));
2159 genset.addAll(delaycomp.getOther(lb));
2161 genset.addAll(delaycomp.getNotReady(lb));
2163 unionset=new HashSet<FlatNode>();
2164 unionset.addAll(storeset);
2165 unionset.addAll(genset);
2168 /* Do the actual code generation */
2169 FlatNode current_node=null;
2170 HashSet tovisit=new HashSet();
2171 HashSet visited=new HashSet();
2173 tovisit.add(first.getNext(0));
2176 while(current_node!=null||!tovisit.isEmpty()) {
2177 if (current_node==null) {
2178 current_node=(FlatNode)tovisit.iterator().next();
2179 tovisit.remove(current_node);
2180 } else if (tovisit.contains(current_node)) {
2181 tovisit.remove(current_node);
2183 visited.add(current_node);
2184 if (nodetolabel.containsKey(current_node)) {
2185 output.println("L"+nodetolabel.get(current_node)+":");
2187 if (state.INSTRUCTIONFAILURE) {
2188 if (state.THREAD||state.DSM||state.SINGLETM) {
2189 output.println("if ((++instructioncount)>failurecount) {instructioncount=0;injectinstructionfailure();}");
2191 output.println("if ((--instructioncount)==0) injectinstructionfailure();");
2193 if (current_node.numNext()==0||stopset!=null&&stopset.contains(current_node)) {
2195 if (!state.DELAYCOMP||firstpass) {
2196 generateFlatNode(fm, lb, current_node, output);
2198 //store primitive variables in out set
2199 AtomicRecord ar=atomicmethodmap.get((FlatAtomicEnterNode)first);
2200 Set<TempDescriptor> liveout=ar.liveout;
2201 for(Iterator<TempDescriptor> tmpit=liveout.iterator();tmpit.hasNext();) {
2202 TempDescriptor tmp=tmpit.next();
2203 output.println("primitives->"+tmp.getSafeSymbol()+"="+tmp.getSafeSymbol()+";");
2206 if (state.MLP && stopset!=null) {
2207 assert first.getPrev( 0 ) instanceof FlatSESEEnterNode;
2208 assert current_node instanceof FlatSESEExitNode;
2209 FlatSESEEnterNode fsen = (FlatSESEEnterNode) first.getPrev( 0 );
2210 FlatSESEExitNode fsxn = (FlatSESEExitNode) current_node;
2211 assert fsen.getFlatExit().equals( fsxn );
2212 assert fsxn.getFlatEnter().equals( fsen );
2214 if (current_node.kind()!=FKind.FlatReturnNode) {
2215 output.println(" return;");
2218 } else if(current_node.numNext()==1) {
2221 current_node.kind()==FKind.FlatSESEEnterNode &&
2222 !((FlatSESEEnterNode)current_node).getIsCallerSESEplaceholder()
2224 FlatSESEEnterNode fsen = (FlatSESEEnterNode)current_node;
2225 generateFlatNode(fm, lb, current_node, output);
2226 nextnode=fsen.getFlatExit().getNext(0);
2227 } else if (state.DELAYCOMP) {
2228 boolean specialprimitive=false;
2229 //skip literals...no need to add extra overhead
2230 if (storeset!=null&&storeset.contains(current_node)&¤t_node.kind()==FKind.FlatLiteralNode) {
2231 TypeDescriptor typedesc=((FlatLiteralNode)current_node).getType();
2232 if (!typedesc.isClass()&&!typedesc.isArray()) {
2233 specialprimitive=true;
2237 if (genset==null||genset.contains(current_node)||specialprimitive)
2238 generateFlatNode(fm, lb, current_node, output);
2239 if (storeset!=null&&storeset.contains(current_node)&&!specialprimitive) {
2240 TempDescriptor wrtmp=current_node.writesTemps()[0];
2242 //need to store value written by previous node
2243 if (wrtmp.getType().isPtr()) {
2244 //only lock the objects that may actually need locking
2245 if (recorddc.getNeedTrans(lb, current_node)) {
2246 output.println("STOREPTR("+generateTemp(fm, wrtmp,lb)+");/* "+current_node.nodeid+" */");
2248 output.println("STOREPTRNOLOCK("+generateTemp(fm, wrtmp,lb)+");/* "+current_node.nodeid+" */");
2251 output.println("STORE"+wrtmp.getType().getSafeDescriptor()+"("+generateTemp(fm, wrtmp, lb)+");/* "+current_node.nodeid+" */");
2254 //need to read value read by previous node
2255 if (wrtmp.getType().isPtr()) {
2256 output.println("RESTOREPTR("+generateTemp(fm, wrtmp,lb)+");/* "+current_node.nodeid+" */");
2258 output.println("RESTORE"+wrtmp.getType().getSafeDescriptor()+"("+generateTemp(fm, wrtmp, lb)+"); /* "+current_node.nodeid+" */");
2262 nextnode=current_node.getNext(0);
2265 generateFlatNode(fm, lb, current_node, output);
2266 nextnode=current_node.getNext(0);
2268 if (visited.contains(nextnode)) {
2269 output.println("goto L"+nodetolabel.get(nextnode)+";");
2272 current_node=nextnode;
2273 } else if (current_node.numNext()==2) {
2275 if (state.DELAYCOMP) {
2276 boolean computeside=false;
2278 //need to record which way it should go
2279 if (genset==null||genset.contains(current_node)) {
2280 if (storeset!=null&&storeset.contains(current_node)) {
2281 //need to store which way branch goes
2282 generateStoreFlatCondBranch(fm, lb, (FlatCondBranch)current_node, "L"+nodetolabel.get(current_node.getNext(1)), output);
2284 generateFlatCondBranch(fm, lb, (FlatCondBranch)current_node, "L"+nodetolabel.get(current_node.getNext(1)), output);
2286 //which side to execute
2290 if (genset.contains(current_node)) {
2291 generateFlatCondBranch(fm, lb, (FlatCondBranch)current_node, "L"+nodetolabel.get(current_node.getNext(1)), output);
2292 } else if (storeset.contains(current_node)) {
2294 output.println("RESTOREANDBRANCH(L"+nodetolabel.get(current_node.getNext(1))+"); /* "+current_node.nodeid+" */");
2296 //which side to execute
2301 Set<FlatNode> leftset=DelayComputation.getNext(current_node, 0, unionset, lb,locality, true);
2303 if (leftset.size()==0)
2305 if (visited.contains(current_node.getNext(branch))) {
2306 //already visited -- build jump
2307 output.println("goto L"+nodetolabel.get(current_node.getNext(branch))+";");
2310 current_node=current_node.getNext(branch);
2313 if (!visited.contains(current_node.getNext(1)))
2314 tovisit.add(current_node.getNext(1));
2315 if (visited.contains(current_node.getNext(0))) {
2316 output.println("goto L"+nodetolabel.get(current_node.getNext(0))+";");
2319 current_node=current_node.getNext(0);
2323 generateFlatCondBranch(fm, lb, (FlatCondBranch)current_node, "L"+nodetolabel.get(current_node.getNext(1)), output);
2324 if (!visited.contains(current_node.getNext(1)))
2325 tovisit.add(current_node.getNext(1));
2326 if (visited.contains(current_node.getNext(0))) {
2327 output.println("goto L"+nodetolabel.get(current_node.getNext(0))+";");
2330 current_node=current_node.getNext(0);
2332 } else throw new Error();
2336 /** This method assigns labels to FlatNodes */
2337 protected Hashtable<FlatNode, Integer> assignLabels(FlatNode first) {
2338 return assignLabels(first, null);
2341 protected Hashtable<FlatNode, Integer> assignLabels(FlatNode first, Set<FlatNode> lastset) {
2342 HashSet tovisit=new HashSet();
2343 HashSet visited=new HashSet();
2345 Hashtable<FlatNode, Integer> nodetolabel=new Hashtable<FlatNode, Integer>();
2348 /*Assign labels first. A node needs a label if the previous
2349 * node has two exits or this node is a join point. */
2351 while(!tovisit.isEmpty()) {
2352 FlatNode fn=(FlatNode)tovisit.iterator().next();
2357 if(lastset!=null&&lastset.contains(fn)) {
2358 // if last is not null and matches, don't go
2359 // any further for assigning labels
2363 for(int i=0; i<fn.numNext(); i++) {
2364 FlatNode nn=fn.getNext(i);
2367 //1) Edge >1 of node
2368 nodetolabel.put(nn,new Integer(labelindex++));
2370 if (!visited.contains(nn)&&!tovisit.contains(nn)) {
2374 nodetolabel.put(nn,new Integer(labelindex++));
2382 /** Generate text string that corresponds to the TempDescriptor td. */
2383 protected String generateTemp(FlatMethod fm, TempDescriptor td, LocalityBinding lb) {
2384 MethodDescriptor md=fm.getMethod();
2385 TaskDescriptor task=fm.getTask();
2386 TempObject objecttemps=(TempObject) tempstable.get(lb!=null ? lb : md!=null ? md : task);
2388 if (objecttemps.isLocalPrim(td)||objecttemps.isParamPrim(td)) {
2389 //System.out.println("generateTemp returns " + td.getSafeSymbol());
2390 return td.getSafeSymbol();
2393 if (objecttemps.isLocalPtr(td)) {
2394 return localsprefixderef+td.getSafeSymbol();
2397 if (objecttemps.isParamPtr(td)) {
2398 return paramsprefix+"->"+td.getSafeSymbol();
2404 protected void generateFlatNode(FlatMethod fm, LocalityBinding lb, FlatNode fn, PrintWriter output) {
2406 // insert pre-node actions from the code plan
2409 CodePlan cp = mlpa.getCodePlan( fn );
2412 FlatSESEEnterNode currentSESE = cp.getCurrentSESE();
2414 // for each sese and age pair that this parent statement
2415 // must stall on, take that child's stall semaphore, the
2416 // copying of values comes after the statement
2417 Iterator<VariableSourceToken> vstItr = cp.getStallTokens().iterator();
2418 while( vstItr.hasNext() ) {
2419 VariableSourceToken vst = vstItr.next();
2421 SESEandAgePair p = new SESEandAgePair( vst.getSESE(), vst.getAge() );
2423 output.println(" {");
2424 output.println(" SESEcommon* common = (SESEcommon*) "+p+";");
2426 output.println(" pthread_mutex_lock( &(common->lock) );");
2427 output.println(" while( common->doneExecuting == FALSE ) {");
2428 output.println(" pthread_cond_wait( &(common->doneCond), &(common->lock) );");
2429 output.println(" }");
2430 output.println(" pthread_mutex_unlock( &(common->lock) );");
2432 //output.println(" psem_take( &(common->stallSem) );");
2434 // copy things we might have stalled for
2435 output.println(" "+p.getSESE().getSESErecordName()+"* child = ("+
2436 p.getSESE().getSESErecordName()+"*) "+p+";");
2438 Iterator<TempDescriptor> tdItr = cp.getCopySet( vst ).iterator();
2439 while( tdItr.hasNext() ) {
2440 TempDescriptor td = tdItr.next();
2441 FlatMethod fmContext;
2442 if( currentSESE.getIsCallerSESEplaceholder() ) {
2443 fmContext = currentSESE.getfmEnclosing();
2445 fmContext = currentSESE.getfmBogus();
2447 output.println(" "+generateTemp( fmContext, td, null )+
2448 " = child->"+vst.getAddrVar().getSafeSymbol()+";");
2451 output.println(" }");
2454 // for each variable with a dynamic source, stall just for that variable
2455 Iterator<TempDescriptor> dynItr = cp.getDynamicStallSet().iterator();
2456 while( dynItr.hasNext() ) {
2457 TempDescriptor dynVar = dynItr.next();
2459 // only stall if the dynamic source is not yourself, denoted by src==NULL
2460 // otherwise the dynamic write nodes will have the local var up-to-date
2461 output.println(" {");
2462 output.println(" if( "+dynVar+"_srcSESE != NULL ) {");
2463 output.println(" SESEcommon* common = (SESEcommon*) "+dynVar+"_srcSESE;");
2464 output.println(" psem_take( &(common->stallSem) );");
2466 FlatMethod fmContext;
2467 if( currentSESE.getIsCallerSESEplaceholder() ) {
2468 fmContext = currentSESE.getfmEnclosing();
2470 fmContext = currentSESE.getfmBogus();
2472 output.println(" "+generateTemp( fmContext, dynVar, null )+
2473 " = *(("+dynVar.getType()+"*) ("+
2474 dynVar+"_srcSESE + "+dynVar+"_srcOffset));");
2476 output.println(" }");
2477 output.println(" }");
2480 // for each assignment of a variable to rhs that has a dynamic source,
2481 // copy the dynamic sources
2482 Iterator dynAssignItr = cp.getDynAssigns().entrySet().iterator();
2483 while( dynAssignItr.hasNext() ) {
2484 Map.Entry me = (Map.Entry) dynAssignItr.next();
2485 TempDescriptor lhs = (TempDescriptor) me.getKey();
2486 TempDescriptor rhs = (TempDescriptor) me.getValue();
2487 output.println(" "+lhs+"_srcSESE = "+rhs+"_srcSESE;");
2488 output.println(" "+lhs+"_srcOffset = "+rhs+"_srcOffset;");
2491 // for each lhs that is dynamic from a non-dynamic source, set the
2492 // dynamic source vars to the current SESE
2493 dynItr = cp.getDynAssignCurr().iterator();
2494 while( dynItr.hasNext() ) {
2495 TempDescriptor dynVar = dynItr.next();
2496 output.println(" "+dynVar+"_srcSESE = NULL;");
2502 case FKind.FlatAtomicEnterNode:
2503 generateFlatAtomicEnterNode(fm, lb, (FlatAtomicEnterNode) fn, output);
2506 case FKind.FlatAtomicExitNode:
2507 generateFlatAtomicExitNode(fm, lb, (FlatAtomicExitNode) fn, output);
2510 case FKind.FlatInstanceOfNode:
2511 generateFlatInstanceOfNode(fm, lb, (FlatInstanceOfNode)fn, output);
2514 case FKind.FlatSESEEnterNode:
2515 generateFlatSESEEnterNode(fm, lb, (FlatSESEEnterNode)fn, output);
2518 case FKind.FlatSESEExitNode:
2519 generateFlatSESEExitNode(fm, lb, (FlatSESEExitNode)fn, output);
2522 case FKind.FlatWriteDynamicVarNode:
2523 generateFlatWriteDynamicVarNode(fm, lb, (FlatWriteDynamicVarNode)fn, output);
2526 case FKind.FlatGlobalConvNode:
2527 generateFlatGlobalConvNode(fm, lb, (FlatGlobalConvNode) fn, output);
2530 case FKind.FlatTagDeclaration:
2531 generateFlatTagDeclaration(fm, lb, (FlatTagDeclaration) fn,output);
2534 case FKind.FlatCall:
2535 generateFlatCall(fm, lb, (FlatCall) fn,output);
2538 case FKind.FlatFieldNode:
2539 generateFlatFieldNode(fm, lb, (FlatFieldNode) fn,output);
2542 case FKind.FlatElementNode:
2543 generateFlatElementNode(fm, lb, (FlatElementNode) fn,output);
2546 case FKind.FlatSetElementNode:
2547 generateFlatSetElementNode(fm, lb, (FlatSetElementNode) fn,output);
2550 case FKind.FlatSetFieldNode:
2551 generateFlatSetFieldNode(fm, lb, (FlatSetFieldNode) fn,output);
2555 generateFlatNew(fm, lb, (FlatNew) fn,output);
2558 case FKind.FlatOpNode:
2559 generateFlatOpNode(fm, lb, (FlatOpNode) fn,output);
2562 case FKind.FlatCastNode:
2563 generateFlatCastNode(fm, lb, (FlatCastNode) fn,output);
2566 case FKind.FlatLiteralNode:
2567 generateFlatLiteralNode(fm, lb, (FlatLiteralNode) fn,output);
2570 case FKind.FlatReturnNode:
2571 generateFlatReturnNode(fm, lb, (FlatReturnNode) fn,output);
2575 output.println("/* nop */");
2578 case FKind.FlatExit:
2579 output.println("/* exit */");
2582 case FKind.FlatBackEdge:
2583 if (state.SINGLETM&&state.SANDBOX&&(locality.getAtomic(lb).get(fn).intValue()>0)) {
2584 output.println("if ((--transaction_check_counter)<=0) checkObjects();");
2586 if (((state.THREAD||state.DSM||state.SINGLETM)&&GENERATEPRECISEGC)
2587 || (this.state.MULTICOREGC)) {
2588 if(state.DSM&&locality.getAtomic(lb).get(fn).intValue()>0) {
2589 output.println("if (needtocollect) checkcollect2("+localsprefixaddr+");");
2590 } else if(this.state.MULTICOREGC) {
2591 output.println("if (gcflag) gc("+localsprefixaddr+");");
2593 output.println("if (needtocollect) checkcollect("+localsprefixaddr+");");
2595 output.println("/* nop */");
2598 case FKind.FlatCheckNode:
2599 generateFlatCheckNode(fm, lb, (FlatCheckNode) fn, output);
2602 case FKind.FlatFlagActionNode:
2603 generateFlatFlagActionNode(fm, lb, (FlatFlagActionNode) fn, output);
2606 case FKind.FlatPrefetchNode:
2607 generateFlatPrefetchNode(fm,lb, (FlatPrefetchNode) fn, output);
2610 case FKind.FlatOffsetNode:
2611 generateFlatOffsetNode(fm, lb, (FlatOffsetNode)fn, output);
2618 // insert post-node actions from the code-plan
2620 CodePlan cp = mlpa.getCodePlan( fn );
2627 public void generateFlatOffsetNode(FlatMethod fm, LocalityBinding lb, FlatOffsetNode fofn, PrintWriter output) {
2628 output.println("/* FlatOffsetNode */");
2629 FieldDescriptor fd=fofn.getField();
2630 output.println(generateTemp(fm, fofn.getDst(),lb)+ " = (short)(int) (&((struct "+fofn.getClassType().getSafeSymbol() +" *)0)->"+ fd.getSafeSymbol()+");");
2631 output.println("/* offset */");
2634 public void generateFlatPrefetchNode(FlatMethod fm, LocalityBinding lb, FlatPrefetchNode fpn, PrintWriter output) {
2635 if (state.PREFETCH) {
2636 Vector oids = new Vector();
2637 Vector fieldoffset = new Vector();
2638 Vector endoffset = new Vector();
2639 int tuplecount = 0; //Keeps track of number of prefetch tuples that need to be generated
2640 for(Iterator it = fpn.hspp.iterator(); it.hasNext();) {
2641 PrefetchPair pp = (PrefetchPair) it.next();
2642 Integer statusbase = locality.getNodePreTempInfo(lb,fpn).get(pp.base);
2643 /* Find prefetches that can generate oid */
2644 if(statusbase == LocalityAnalysis.GLOBAL) {
2645 generateTransCode(fm, lb, pp, oids, fieldoffset, endoffset, tuplecount, locality.getAtomic(lb).get(fpn).intValue()>0, false);
2647 } else if (statusbase == LocalityAnalysis.LOCAL) {
2648 generateTransCode(fm,lb,pp,oids,fieldoffset,endoffset,tuplecount,false,true);
2655 System.out.println("Adding prefetch "+fpn+ " to method:" +fm);
2656 output.println("{");
2657 output.println("/* prefetch */");
2658 output.println("/* prefetchid_" + fpn.siteid + " */");
2659 output.println("void * prefptr;");
2660 output.println("int tmpindex;");
2662 output.println("if((evalPrefetch["+fpn.siteid+"].operMode) || (evalPrefetch["+fpn.siteid+"].retrycount <= 0)) {");
2663 /*Create C code for oid array */
2664 output.print(" unsigned int oidarray_[] = {");
2665 boolean needcomma=false;
2666 for (Iterator it = oids.iterator(); it.hasNext();) {
2669 output.print(it.next());
2672 output.println("};");
2674 /*Create C code for endoffset values */
2675 output.print(" unsigned short endoffsetarry_[] = {");
2677 for (Iterator it = endoffset.iterator(); it.hasNext();) {
2680 output.print(it.next());
2683 output.println("};");
2685 /*Create C code for Field Offset Values */
2686 output.print(" short fieldarry_[] = {");
2688 for (Iterator it = fieldoffset.iterator(); it.hasNext();) {
2691 output.print(it.next());
2694 output.println("};");
2695 /* make the prefetch call to Runtime */
2696 output.println(" if(!evalPrefetch["+fpn.siteid+"].operMode) {");
2697 output.println(" evalPrefetch["+fpn.siteid+"].retrycount = RETRYINTERVAL;");
2698 output.println(" }");
2699 output.println(" prefetch("+fpn.siteid+" ,"+tuplecount+", oidarray_, endoffsetarry_, fieldarry_);");
2700 output.println(" } else {");
2701 output.println(" evalPrefetch["+fpn.siteid+"].retrycount--;");
2702 output.println(" }");
2703 output.println("}");
2707 public void generateTransCode(FlatMethod fm, LocalityBinding lb,PrefetchPair pp, Vector oids, Vector fieldoffset, Vector endoffset, int tuplecount, boolean inside, boolean localbase) {
2708 short offsetcount = 0;
2712 } else if (localbase) {
2713 for(; breakindex<pp.desc.size(); breakindex++) {
2714 Descriptor desc=pp.getDescAt(breakindex);
2715 if (desc instanceof FieldDescriptor) {
2716 FieldDescriptor fd=(FieldDescriptor)desc;
2717 if (fd.isGlobal()) {
2725 if (breakindex>pp.desc.size()) //all local
2728 TypeDescriptor lasttype=pp.base.getType();
2729 String basestr=generateTemp(fm, pp.base, lb);
2731 boolean maybenull=fm.getMethod().isStatic()||
2732 !pp.base.equals(fm.getParameter(0));
2734 for(int i=0; i<breakindex; i++) {
2735 String indexcheck="";
2737 Descriptor desc=pp.getDescAt(i);
2738 if (desc instanceof FieldDescriptor) {
2739 FieldDescriptor fd=(FieldDescriptor)desc;
2741 if (!teststr.equals(""))
2743 teststr+="((prefptr="+basestr+")!=NULL)";
2744 basestr="((struct "+lasttype.getSafeSymbol()+" *)prefptr)->"+fd.getSafeSymbol();
2746 basestr=basestr+"->"+fd.getSafeSymbol();
2749 lasttype=fd.getType();
2751 IndexDescriptor id=(IndexDescriptor)desc;
2752 indexcheck="((tmpindex=";
2753 for(int j=0; j<id.tddesc.size(); j++) {
2754 indexcheck+=generateTemp(fm, id.getTempDescAt(j), lb)+"+";
2756 indexcheck+=id.offset+")>=0)&(tmpindex<((struct ArrayObject *)prefptr)->___length___)";
2758 if (!teststr.equals(""))
2760 teststr+="((prefptr="+basestr+")!= NULL) &&"+indexcheck;
2761 basestr="((void **)(((char *) &(((struct ArrayObject *)prefptr)->___length___))+sizeof(int)))[tmpindex]";
2763 lasttype=lasttype.dereference();
2768 if (teststr.equals("")) {
2769 oid="((unsigned int)"+basestr+")";
2771 oid="((unsigned int)(("+teststr+")?"+basestr+":NULL))";
2775 for(int i = breakindex; i < pp.desc.size(); i++) {
2776 String newfieldoffset;
2777 Object desc = pp.getDescAt(i);
2778 if(desc instanceof FieldDescriptor) {
2779 FieldDescriptor fd=(FieldDescriptor)desc;
2780 newfieldoffset = new String("(unsigned int)(&(((struct "+ lasttype.getSafeSymbol()+" *)0)->"+ fd.getSafeSymbol()+ "))");
2781 lasttype=fd.getType();
2783 newfieldoffset = "";
2784 IndexDescriptor id=(IndexDescriptor)desc;
2785 for(int j = 0; j < id.tddesc.size(); j++) {
2786 newfieldoffset += generateTemp(fm, id.getTempDescAt(j), lb) + "+";
2788 newfieldoffset += id.offset.toString();
2789 lasttype=lasttype.dereference();
2791 fieldoffset.add(newfieldoffset);
2794 int base=(tuplecount>0) ? ((Short)endoffset.get(tuplecount-1)).intValue() : 0;
2795 base+=pp.desc.size()-breakindex;
2796 endoffset.add(new Short((short)base));
2801 public void generateFlatGlobalConvNode(FlatMethod fm, LocalityBinding lb, FlatGlobalConvNode fgcn, PrintWriter output) {
2802 if (lb!=fgcn.getLocality())
2804 /* Have to generate flat globalconv */
2805 if (fgcn.getMakePtr()) {
2807 output.println("TRANSREAD("+generateTemp(fm, fgcn.getSrc(),lb)+", (unsigned int) "+generateTemp(fm, fgcn.getSrc(),lb)+");");
2809 if ((dc==null)||!state.READSET&&dc.getNeedTrans(lb, fgcn)||state.READSET&&dc.getNeedWriteTrans(lb, fgcn)) {
2810 //need to do translation
2811 output.println("TRANSREAD("+generateTemp(fm, fgcn.getSrc(),lb)+", "+generateTemp(fm, fgcn.getSrc(),lb)+", (void *)("+localsprefixaddr+"));");
2812 } else if (state.READSET&&dc.getNeedTrans(lb, fgcn)) {
2813 output.println("TRANSREADRD("+generateTemp(fm, fgcn.getSrc(),lb)+", "+generateTemp(fm, fgcn.getSrc(),lb)+");");
2817 /* Need to convert to OID */
2818 if ((dc==null)||dc.getNeedSrcTrans(lb,fgcn)) {
2819 if (fgcn.doConvert()||(delaycomp!=null&&atomicmethodmap.get(fgcn.getAtomicEnter()).reallivein.contains(fgcn.getSrc()))) {
2820 output.println(generateTemp(fm, fgcn.getSrc(),lb)+"=(void *)COMPOID("+generateTemp(fm, fgcn.getSrc(),lb)+");");
2822 output.println(generateTemp(fm, fgcn.getSrc(),lb)+"=NULL;");
2828 public void generateFlatInstanceOfNode(FlatMethod fm, LocalityBinding lb, FlatInstanceOfNode fion, PrintWriter output) {
2830 if (fion.getType().isArray()) {
2831 type=state.getArrayNumber(fion.getType())+state.numClasses();
2833 type=fion.getType().getClassDesc().getId();
2836 if (fion.getType().getSymbol().equals(TypeUtil.ObjectClass))
2837 output.println(generateTemp(fm, fion.getDst(), lb)+"=1;");
2839 output.println(generateTemp(fm, fion.getDst(), lb)+"=instanceof("+generateTemp(fm,fion.getSrc(),lb)+","+type+");");
2842 int sandboxcounter=0;
2843 public void generateFlatAtomicEnterNode(FlatMethod fm, LocalityBinding lb, FlatAtomicEnterNode faen, PrintWriter output) {
2844 /* Check to see if we need to generate code for this atomic */
2845 if (locality==null) {
2846 output.println("pthread_mutex_lock(&atomiclock);");
2850 if (locality.getAtomic(lb).get(faen.getPrev(0)).intValue()>0)
2854 if (state.SANDBOX) {
2855 outsandbox.println("int atomiccounter"+sandboxcounter+"=LOW_CHECK_FREQUENCY;");
2856 output.println("counter_reset_pointer=&atomiccounter"+sandboxcounter+";");
2859 if (state.DELAYCOMP) {
2860 AtomicRecord ar=atomicmethodmap.get(faen);
2862 for(Iterator<TempDescriptor> tmpit=ar.livein.iterator();tmpit.hasNext();) {
2863 TempDescriptor tmp=tmpit.next();
2864 output.println("primitives_"+ar.name+"."+tmp.getSafeSymbol()+"="+tmp.getSafeSymbol()+";");
2867 //copy outs that depend on path
2868 for(Iterator<TempDescriptor> tmpit=ar.liveoutvirtualread.iterator();tmpit.hasNext();) {
2869 TempDescriptor tmp=tmpit.next();
2870 if (!ar.livein.contains(tmp))
2871 output.println("primitives_"+ar.name+"."+tmp.getSafeSymbol()+"="+tmp.getSafeSymbol()+";");
2875 /* Backup the temps. */
2876 for(Iterator<TempDescriptor> tmpit=locality.getTemps(lb).get(faen).iterator(); tmpit.hasNext();) {
2877 TempDescriptor tmp=tmpit.next();
2878 output.println(generateTemp(fm, backuptable.get(lb).get(tmp),lb)+"="+generateTemp(fm,tmp,lb)+";");
2881 output.println("goto transstart"+faen.getIdentifier()+";");
2883 /******* Print code to retry aborted transaction *******/
2884 output.println("transretry"+faen.getIdentifier()+":");
2887 for(Iterator<TempDescriptor> tmpit=locality.getTemps(lb).get(faen).iterator(); tmpit.hasNext();) {
2888 TempDescriptor tmp=tmpit.next();
2889 output.println(generateTemp(fm, tmp,lb)+"="+generateTemp(fm,backuptable.get(lb).get(tmp),lb)+";");
2893 /********* Need to revert local object store ********/
2894 String revertptr=generateTemp(fm, reverttable.get(lb),lb);
2896 output.println("while ("+revertptr+") {");
2897 output.println("struct ___Object___ * tmpptr;");
2898 output.println("tmpptr="+revertptr+"->"+nextobjstr+";");
2899 output.println("REVERT_OBJ("+revertptr+");");
2900 output.println(revertptr+"=tmpptr;");
2901 output.println("}");
2903 /******* Tell the runtime to start the transaction *******/
2905 output.println("transstart"+faen.getIdentifier()+":");
2906 if (state.SANDBOX) {
2907 output.println("transaction_check_counter=*counter_reset_pointer;");
2910 output.println("transStart();");
2912 if (state.ABORTREADERS||state.SANDBOX) {
2914 output.println("abortenabled=1;");
2915 output.println("if (_setjmp(aborttrans)) {");
2916 output.println(" goto transretry"+faen.getIdentifier()+"; }");
2920 public void generateFlatAtomicExitNode(FlatMethod fm, LocalityBinding lb, FlatAtomicExitNode faen, PrintWriter output) {
2921 /* Check to see if we need to generate code for this atomic */
2922 if (locality==null) {
2923 output.println("pthread_mutex_unlock(&atomiclock);");
2926 if (locality.getAtomic(lb).get(faen).intValue()>0)
2928 //store the revert list before we lose the transaction object
2929 String revertptr=null;
2931 revertptr=generateTemp(fm, reverttable.get(lb),lb);
2932 output.println(revertptr+"=revertlist;");
2934 if (state.DELAYCOMP) {
2935 AtomicRecord ar=atomicmethodmap.get(faen.getAtomicEnter());
2938 output.println("if (transCommit((void (*)(void *, void *, void *))&"+ar.name+", &primitives_"+ar.name+", &"+localsprefix+", "+paramsprefix+")) {");
2940 output.println("if (transCommit()) {");
2941 /* Transaction aborts if it returns true */
2942 output.println("goto transretry"+faen.getAtomicEnter().getIdentifier()+";");
2944 output.println("} else {");
2945 /* Need to commit local object store */
2946 output.println("while ("+revertptr+") {");
2947 output.println("struct ___Object___ * tmpptr;");
2948 output.println("tmpptr="+revertptr+"->"+nextobjstr+";");
2949 output.println("COMMIT_OBJ("+revertptr+");");
2950 output.println(revertptr+"=tmpptr;");
2951 output.println("}");
2953 output.println("}");
2954 if (state.DELAYCOMP) {
2956 AtomicRecord ar=atomicmethodmap.get(faen.getAtomicEnter());
2957 output.println("else {");
2958 for(Iterator<TempDescriptor> tmpit=ar.liveout.iterator();tmpit.hasNext();) {
2959 TempDescriptor tmp=tmpit.next();
2960 output.println(tmp.getSafeSymbol()+"=primitives_"+ar.name+"."+tmp.getSafeSymbol()+";");
2962 output.println("}");
2966 public void generateFlatSESEEnterNode( FlatMethod fm,
2968 FlatSESEEnterNode fsen,
2972 // if MLP flag is off, okay that SESE nodes are in IR graph,
2973 // just skip over them and code generates exactly the same
2978 // there may be an SESE in an unreachable method, skip over
2979 if( !mlpa.getAllSESEs().contains( fsen ) ) {
2983 // also, if we have encountered a placeholder, just skip it
2984 if( fsen.getIsCallerSESEplaceholder() ) {
2988 output.println(" {");
2990 // set up the parent
2991 if( fsen == mlpa.getMainSESE() ) {
2992 output.println(" SESEcommon* parentCommon = NULL;");
2994 if( fsen.getParent() == null ) {
2995 System.out.println( "in "+fm+", "+fsen+" has null parent" );
2997 assert fsen.getParent() != null;
2998 if( !fsen.getParent().getIsCallerSESEplaceholder() ) {
2999 output.println(" SESEcommon* parentCommon = &("+paramsprefix+"->common);");
3001 //output.println(" SESEcommon* parentCommon = (SESEcommon*) peekItem( seseCallStack );");
3002 output.println(" SESEcommon* parentCommon = seseCaller;");
3006 // before doing anything, lock your own record and increment the running children
3007 if( fsen != mlpa.getMainSESE() ) {
3008 output.println(" pthread_mutex_lock( &(parentCommon->lock) );");
3009 output.println(" ++(parentCommon->numRunningChildren);");
3010 output.println(" pthread_mutex_unlock( &(parentCommon->lock) );");
3013 // just allocate the space for this record
3014 output.println(" "+fsen.getSESErecordName()+"* seseToIssue = ("+
3015 fsen.getSESErecordName()+"*) mlpAllocSESErecord( sizeof( "+
3016 fsen.getSESErecordName()+" ) );");
3018 // and keep the thread-local sese stack up to date
3019 //output.println(" addNewItem( seseCallStack, (void*) seseToIssue);");
3021 // fill in common data
3022 output.println(" seseToIssue->common.classID = "+fsen.getIdentifier()+";");
3023 output.println(" psem_init( &(seseToIssue->common.stallSem) );");
3025 output.println(" seseToIssue->common.forwardList = createQueue();");
3026 output.println(" seseToIssue->common.unresolvedDependencies = 0;");
3027 output.println(" pthread_cond_init( &(seseToIssue->common.doneCond), NULL );");
3028 output.println(" seseToIssue->common.doneExecuting = FALSE;");
3029 output.println(" pthread_cond_init( &(seseToIssue->common.runningChildrenCond), NULL );");
3030 output.println(" seseToIssue->common.numRunningChildren = 0;");
3031 output.println(" seseToIssue->common.parent = parentCommon;");
3033 // all READY in-vars should be copied now and be done with it
3034 Iterator<TempDescriptor> tempItr = fsen.getReadyInVarSet().iterator();
3035 while( tempItr.hasNext() ) {
3036 TempDescriptor temp = tempItr.next();
3038 // when we are issuing the main SESE or an SESE with placeholder
3039 // caller SESE as parent, generate temp child child's eclosing method,
3040 // otherwise use the parent's enclosing method as the context
3041 boolean useParentContext = false;
3043 if( fsen != mlpa.getMainSESE() ) {
3044 assert fsen.getParent() != null;
3045 if( !fsen.getParent().getIsCallerSESEplaceholder() ) {
3046 useParentContext = true;
3050 if( useParentContext ) {
3051 output.println(" seseToIssue->"+temp+" = "+
3052 generateTemp( fsen.getParent().getfmBogus(), temp, null )+";");
3054 output.println(" seseToIssue->"+temp+" = "+
3055 generateTemp( fsen.getfmEnclosing(), temp, null )+";");
3059 // before potentially adding this SESE to other forwarding lists,
3060 // create it's lock and take it immediately
3061 output.println(" pthread_mutex_init( &(seseToIssue->common.lock), NULL );");
3062 output.println(" pthread_mutex_lock( &(seseToIssue->common.lock) );");
3064 if( fsen != mlpa.getMainSESE() ) {
3065 // count up outstanding dependencies, static first, then dynamic
3066 Iterator<SESEandAgePair> staticSrcsItr = fsen.getStaticInVarSrcs().iterator();
3067 while( staticSrcsItr.hasNext() ) {
3068 SESEandAgePair srcPair = staticSrcsItr.next();
3069 output.println(" {");
3070 output.println(" SESEcommon* src = (SESEcommon*)"+srcPair+";");
3071 output.println(" pthread_mutex_lock( &(src->lock) );");
3072 output.println(" if( !isEmpty( src->forwardList ) &&");
3073 output.println(" seseToIssue == peekItem( src->forwardList ) ) {");
3074 output.println(" printf( \"This shouldnt already be here\\n\");");
3075 output.println(" exit( -1 );");
3076 output.println(" }");
3077 output.println(" if( !src->doneExecuting ) {");
3078 output.println(" addNewItem( src->forwardList, seseToIssue );");
3079 output.println(" ++(seseToIssue->common.unresolvedDependencies);");
3080 output.println(" }");
3081 output.println(" pthread_mutex_unlock( &(src->lock) );");
3082 output.println(" }");
3084 // whether or not it is an outstanding dependency, make sure
3085 // to pass the static name to the child's record
3086 output.println(" seseToIssue->"+srcPair+" = "+srcPair+";");
3089 // dynamic sources might already be accounted for in the static list,
3090 // so only add them to forwarding lists if they're not already there
3091 Iterator<TempDescriptor> dynVarsItr = fsen.getDynamicInVarSet().iterator();
3092 while( dynVarsItr.hasNext() ) {
3093 TempDescriptor dynInVar = dynVarsItr.next();
3094 output.println(" {");
3095 output.println(" SESEcommon* src = (SESEcommon*)"+dynInVar+"_srcSESE;");
3097 // the dynamic source is NULL if it comes from your own space--you can't pass
3098 // the address off to the new child, because you're not done executing and
3099 // might change the variable, so copy it right now
3100 output.println(" if( src != NULL ) {");
3101 output.println(" pthread_mutex_lock( &(src->lock) );");
3102 output.println(" if( isEmpty( src->forwardList ) ||");
3103 output.println(" seseToIssue != peekItem( src->forwardList ) ) {");
3104 output.println(" if( !src->doneExecuting ) {");
3105 output.println(" addNewItem( src->forwardList, seseToIssue );");
3106 output.println(" ++(seseToIssue->common.unresolvedDependencies);");
3107 output.println(" }");
3108 output.println(" }");
3109 output.println(" pthread_mutex_unlock( &(src->lock) );");
3110 output.println(" seseToIssue->"+dynInVar+"_srcOffset = "+dynInVar+"_srcOffset;");
3111 output.println(" } else {");
3113 boolean useParentContext = false;
3114 if( fsen != mlpa.getMainSESE() ) {
3115 assert fsen.getParent() != null;
3116 if( !fsen.getParent().getIsCallerSESEplaceholder() ) {
3117 useParentContext = true;
3120 if( useParentContext ) {
3121 output.println(" seseToIssue->"+dynInVar+" = "+
3122 generateTemp( fsen.getParent().getfmBogus(), dynInVar, null )+";");
3124 output.println(" seseToIssue->"+dynInVar+" = "+
3125 generateTemp( fsen.getfmEnclosing(), dynInVar, null )+";");
3128 output.println(" }");
3129 output.println(" }");
3131 // even if the value is already copied, make sure your NULL source
3132 // gets passed so child knows it already has the dynamic value
3133 output.println(" seseToIssue->"+dynInVar+"_srcSESE = "+dynInVar+"_srcSESE;");
3136 // maintain pointers for for finding dynamic SESE
3137 // instances from static names
3138 SESEandAgePair p = new SESEandAgePair( fsen, 0 );
3139 if( fsen.getParent() != null &&
3140 //!fsen.getParent().getIsCallerSESEplaceholder() &&
3141 fsen.getParent().getNeededStaticNames().contains( p )
3144 for( int i = fsen.getOldestAgeToTrack(); i > 0; --i ) {
3145 SESEandAgePair p1 = new SESEandAgePair( fsen, i );
3146 SESEandAgePair p2 = new SESEandAgePair( fsen, i-1 );
3147 output.println(" "+p1+" = "+p2+";");
3149 output.println(" "+p+" = seseToIssue;");
3153 // if there were no outstanding dependencies, issue here
3154 output.println(" if( seseToIssue->common.unresolvedDependencies == 0 ) {");
3155 output.println(" workScheduleSubmit( (void*)seseToIssue );");
3156 output.println(" }");
3158 // release this SESE for siblings to update its dependencies or,
3159 // eventually, for it to mark itself finished
3160 output.println(" pthread_mutex_unlock( &(seseToIssue->common.lock) );");
3161 output.println(" }");
3165 public void generateFlatSESEExitNode( FlatMethod fm,
3167 FlatSESEExitNode fsexn,
3171 // if MLP flag is off, okay that SESE nodes are in IR graph,
3172 // just skip over them and code generates exactly the same
3177 // get the enter node for this exit that has meta data embedded
3178 FlatSESEEnterNode fsen = fsexn.getFlatEnter();
3180 // there may be an SESE in an unreachable method, skip over
3181 if( !mlpa.getAllSESEs().contains( fsen ) ) {
3185 // also, if we have encountered a placeholder, just jump it
3186 if( fsen.getIsCallerSESEplaceholder() ) {
3190 output.println(" /* SESE exiting */");
3192 String com = paramsprefix+"->common";
3194 // this SESE cannot be done until all of its children are done
3195 // so grab your own lock with the condition variable for watching
3196 // that the number of your running children is greater than zero
3197 output.println(" pthread_mutex_lock( &("+com+".lock) );");
3198 output.println(" while( "+com+".numRunningChildren > 0 ) {");
3199 output.println(" pthread_cond_wait( &("+com+".runningChildrenCond), &("+com+".lock) );");
3200 output.println(" }");
3202 // copy out-set from local temps into the sese record
3203 Iterator<TempDescriptor> itr = fsen.getOutVarSet().iterator();
3204 while( itr.hasNext() ) {
3205 TempDescriptor temp = itr.next();
3207 // only have to do this for primitives
3208 if( !temp.getType().isPrimitive() ) {
3212 // have to determine the context enclosing this sese
3213 boolean useParentContext = false;
3215 if( fsen != mlpa.getMainSESE() ) {
3216 assert fsen.getParent() != null;
3217 if( !fsen.getParent().getIsCallerSESEplaceholder() ) {
3218 useParentContext = true;
3223 if( useParentContext ) {
3224 from = generateTemp( fsen.getParent().getfmBogus(), temp, null );
3226 from = generateTemp( fsen.getfmEnclosing(), temp, null );
3229 output.println(" "+paramsprefix+
3230 "->"+temp.getSafeSymbol()+
3234 // mark yourself done, your SESE data is now read-only
3235 output.println(" "+com+".doneExecuting = TRUE;");
3236 output.println(" pthread_cond_signal( &("+com+".doneCond) );");
3237 output.println(" pthread_mutex_unlock( &("+com+".lock) );");
3239 // decrement dependency count for all SESE's on your forwarding list
3240 output.println(" while( !isEmpty( "+com+".forwardList ) ) {");
3241 output.println(" SESEcommon* consumer = (SESEcommon*) getItem( "+com+".forwardList );");
3242 output.println(" pthread_mutex_lock( &(consumer->lock) );");
3243 output.println(" --(consumer->unresolvedDependencies);");
3244 output.println(" if( consumer->unresolvedDependencies == 0 ) {");
3245 output.println(" workScheduleSubmit( (void*)consumer );");
3246 output.println(" }");
3247 output.println(" pthread_mutex_unlock( &(consumer->lock) );");
3248 output.println(" }");
3250 // if parent is stalling on you, let them know you're done
3251 if( fsexn.getFlatEnter() != mlpa.getMainSESE() ) {
3252 output.println(" psem_give( &("+paramsprefix+"->common.stallSem) );");
3255 // last of all, decrement your parent's number of running children
3256 output.println(" if( "+paramsprefix+"->common.parent != NULL ) {");
3257 output.println(" pthread_mutex_lock( &("+paramsprefix+"->common.parent->lock) );");
3258 output.println(" --("+paramsprefix+"->common.parent->numRunningChildren);");
3259 output.println(" pthread_cond_signal( &("+paramsprefix+"->common.parent->runningChildrenCond) );");
3260 output.println(" pthread_mutex_unlock( &("+paramsprefix+"->common.parent->lock) );");
3261 output.println(" }");
3263 // this is a thread-only variable that can be handled when critical sese-to-sese
3264 // data has been taken care of--set sese pointer to remember self over method
3265 // calls to a non-zero, invalid address
3266 output.println(" seseCaller = (SESEcommon*) 0x1;");
3269 public void generateFlatWriteDynamicVarNode( FlatMethod fm,
3271 FlatWriteDynamicVarNode fwdvn,
3275 // should node should not be in an IR graph if the
3276 // MLP flag is not set
3277 throw new Error("Unexpected presence of FlatWriteDynamicVarNode");
3280 Hashtable<TempDescriptor, VariableSourceToken> writeDynamic =
3283 assert writeDynamic != null;
3285 Iterator wdItr = writeDynamic.entrySet().iterator();
3286 while( wdItr.hasNext() ) {
3287 Map.Entry me = (Map.Entry) wdItr.next();
3288 TempDescriptor refVar = (TempDescriptor) me.getKey();
3289 VariableSourceToken vst = (VariableSourceToken) me.getValue();
3291 FlatSESEEnterNode current = fwdvn.getEnclosingSESE();
3293 // only do this if the variable in question should be tracked,
3294 // meaning that it was explicitly added to the dynamic var set
3295 if( !current.getDynamicVarSet().contains( vst.getAddrVar() ) ) {
3299 SESEandAgePair instance = new SESEandAgePair( vst.getSESE(), vst.getAge() );
3301 output.println(" {");
3303 if( current.equals( vst.getSESE() ) ) {
3304 // if the src comes from this SESE, it's a method local variable,
3305 // mark src pointer NULL to signify that the var is up-to-date
3306 output.println(" "+vst.getAddrVar()+"_srcSESE = NULL;");
3309 // otherwise we track where it will come from
3310 output.println(" "+vst.getAddrVar()+"_srcSESE = "+instance+";");
3311 output.println(" "+vst.getAddrVar()+"_srcOffset = (int) &((("+
3312 vst.getSESE().getSESErecordName()+"*)0)->"+vst.getAddrVar()+");");
3315 output.println(" }");
3320 private void generateFlatCheckNode(FlatMethod fm, LocalityBinding lb, FlatCheckNode fcn, PrintWriter output) {
3321 if (state.CONSCHECK) {
3322 String specname=fcn.getSpec();
3323 String varname="repairstate___";
3324 output.println("{");
3325 output.println("struct "+specname+"_state * "+varname+"=allocate"+specname+"_state();");
3327 TempDescriptor[] temps=fcn.getTemps();
3328 String[] vars=fcn.getVars();
3329 for(int i=0; i<temps.length; i++) {
3330 output.println(varname+"->"+vars[i]+"=(unsigned int)"+generateTemp(fm, temps[i],lb)+";");
3333 output.println("if (doanalysis"+specname+"("+varname+")) {");
3334 output.println("free"+specname+"_state("+varname+");");
3335 output.println("} else {");
3336 output.println("/* Bad invariant */");
3337 output.println("free"+specname+"_state("+varname+");");
3338 output.println("abort_task();");
3339 output.println("}");
3340 output.println("}");
3344 private void generateFlatCall(FlatMethod fm, LocalityBinding lb, FlatCall fc, PrintWriter output) {
3346 if( state.MLP && !nonSESEpass ) {
3347 output.println(" seseCaller = (SESEcommon*)"+paramsprefix+";");
3350 MethodDescriptor md=fc.getMethod();
3351 ParamsObject objectparams=(ParamsObject)paramstable.get(lb!=null ? locality.getBinding(lb, fc) : md);
3352 ClassDescriptor cn=md.getClassDesc();
3353 output.println("{");
3354 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
3356 LocalityBinding fclb=locality.getBinding(lb, fc);
3357 output.print(" struct "+cn.getSafeSymbol()+fclb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={");
3359 output.print(" struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={");
3361 output.print(objectparams.numPointers());
3362 output.print(", "+localsprefixaddr);
3363 if (md.getThis()!=null) {
3365 output.print("(struct "+md.getThis().getType().getSafeSymbol() +" *)"+ generateTemp(fm,fc.getThis(),lb));
3367 if (fc.getThis()!=null&&md.getThis()==null) {
3368 System.out.println("WARNING!!!!!!!!!!!!");
3369 System.out.println("Source code calls static method "+md+" on an object in "+fm.getMethod()+"!");
3373 for(int i=0; i<fc.numArgs(); i++) {
3374 Descriptor var=md.getParameter(i);
3375 TempDescriptor paramtemp=(TempDescriptor)temptovar.get(var);
3376 if (objectparams.isParamPtr(paramtemp)) {
3377 TempDescriptor targ=fc.getArg(i);
3379 TypeDescriptor td=md.getParamType(i);
3381 output.print("(struct "+(new TypeDescriptor(typeutil.getClass(TypeUtil.TagClass))).getSafeSymbol() +" *)"+generateTemp(fm, targ,lb));
3383 output.print("(struct "+md.getParamType(i).getSafeSymbol() +" *)"+generateTemp(fm, targ,lb));
3386 output.println("};");
3391 if (fc.getReturnTemp()!=null)
3392 output.print(generateTemp(fm,fc.getReturnTemp(),lb)+"=");
3394 /* Do we need to do virtual dispatch? */
3395 if (md.isStatic()||md.getReturnType()==null||singleCall(fc.getThis().getType().getClassDesc(),md)) {
3398 LocalityBinding fclb=locality.getBinding(lb, fc);
3399 output.print(cn.getSafeSymbol()+fclb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor());
3401 output.print(cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor());
3406 if (md.getReturnType().isClass()||md.getReturnType().isArray())
3407 output.print("struct " + md.getReturnType().getSafeSymbol()+" * ");
3409 output.print(md.getReturnType().getSafeSymbol()+" ");
3410 output.print("(*)(");
3412 boolean printcomma=false;
3413 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
3415 LocalityBinding fclb=locality.getBinding(lb, fc);
3416 output.print("struct "+cn.getSafeSymbol()+fclb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params * ");
3418 output.print("struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params * ");
3422 for(int i=0; i<objectparams.numPrimitives(); i++) {
3423 TempDescriptor temp=objectparams.getPrimitive(i);
3427 if (temp.getType().isClass()||temp.getType().isArray())
3428 output.print("struct " + temp.getType().getSafeSymbol()+" * ");
3430 output.print(temp.getType().getSafeSymbol());
3435 LocalityBinding fclb=locality.getBinding(lb, fc);
3436 output.print("))virtualtable["+generateTemp(fm,fc.getThis(),lb)+"->type*"+maxcount+"+"+virtualcalls.getLocalityNumber(fclb)+"])");
3438 output.print("))virtualtable["+generateTemp(fm,fc.getThis(),lb)+"->type*"+maxcount+"+"+virtualcalls.getMethodNumber(md)+"])");
3442 boolean needcomma=false;
3443 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
3444 output.print("&__parameterlist__");
3448 if (!GENERATEPRECISEGC && !this.state.MULTICOREGC) {
3449 if (fc.getThis()!=null) {
3450 TypeDescriptor ptd=md.getThis().getType();
3453 if (ptd.isClass()&&!ptd.isArray())
3454 output.print("(struct "+ptd.getSafeSymbol()+" *) ");
3455 output.print(generateTemp(fm,fc.getThis(),lb));
3460 for(int i=0; i<fc.numArgs(); i++) {
3461 Descriptor var=md.getParameter(i);
3462 TempDescriptor paramtemp=(TempDescriptor)temptovar.get(var);
3463 if (objectparams.isParamPrim(paramtemp)) {
3464 TempDescriptor targ=fc.getArg(i);
3468 TypeDescriptor ptd=md.getParamType(i);
3469 if (ptd.isClass()&&!ptd.isArray())
3470 output.print("(struct "+ptd.getSafeSymbol()+" *) ");
3471 output.print(generateTemp(fm, targ,lb));
3475 output.println(");");
3476 output.println(" }");
3479 private boolean singleCall(ClassDescriptor thiscd, MethodDescriptor md) {
3480 Set subclasses=typeutil.getSubClasses(thiscd);
3481 if (subclasses==null)
3483 for(Iterator classit=subclasses.iterator(); classit.hasNext();) {
3484 ClassDescriptor cd=(ClassDescriptor)classit.next();
3485 Set possiblematches=cd.getMethodTable().getSetFromSameScope(md.getSymbol());
3486 for(Iterator matchit=possiblematches.iterator(); matchit.hasNext();) {
3487 MethodDescriptor matchmd=(MethodDescriptor)matchit.next();
3488 if (md.matches(matchmd))
3495 private void generateFlatFieldNode(FlatMethod fm, LocalityBinding lb, FlatFieldNode ffn, PrintWriter output) {
3496 if (state.SINGLETM) {
3497 //single machine transactional memory case
3498 String field=ffn.getField().getSafeSymbol();
3499 String src=generateTemp(fm, ffn.getSrc(),lb);
3500 String dst=generateTemp(fm, ffn.getDst(),lb);
3502 output.println(dst+"="+ src +"->"+field+ ";");
3503 if (ffn.getField().getType().isPtr()&&locality.getAtomic(lb).get(ffn).intValue()>0&&
3504 locality.getNodePreTempInfo(lb, ffn).get(ffn.getSrc())!=LocalityAnalysis.SCRATCH) {
3505 if ((dc==null)||(!state.READSET&&dc.getNeedTrans(lb, ffn))||
3506 (state.READSET&&dc.getNeedWriteTrans(lb, ffn))) {
3507 output.println("TRANSREAD("+dst+", "+dst+", (void *) (" + localsprefixaddr + "));");
3508 } else if (state.READSET&&dc.getNeedTrans(lb, ffn)) {
3509 output.println("TRANSREADRD("+dst+", "+dst+");");
3512 } else if (state.DSM) {
3513 Integer status=locality.getNodePreTempInfo(lb,ffn).get(ffn.getSrc());
3514 if (status==LocalityAnalysis.GLOBAL) {
3515 String field=ffn.getField().getSafeSymbol();
3516 String src=generateTemp(fm, ffn.getSrc(),lb);
3517 String dst=generateTemp(fm, ffn.getDst(),lb);
3519 if (ffn.getField().getType().isPtr()) {
3521 //TODO: Uncomment this when we have runtime support
3522 //if (ffn.getSrc()==ffn.getDst()) {
3523 //output.println("{");
3524 //output.println("void * temp="+src+";");
3525 //output.println("if (temp&0x1) {");
3526 //output.println("temp=(void *) transRead(trans, (unsigned int) temp);");
3527 //output.println(src+"->"+field+"="+temp+";");
3528 //output.println("}");
3529 //output.println(dst+"=temp;");
3530 //output.println("}");
3532 output.println(dst+"="+ src +"->"+field+ ";");
3533 //output.println("if ("+dst+"&0x1) {");
3534 output.println("TRANSREAD("+dst+", (unsigned int) "+dst+");");
3535 //output.println(src+"->"+field+"="+src+"->"+field+";");
3536 //output.println("}");
3539 output.println(dst+"="+ src+"->"+field+";");
3541 } else if (status==LocalityAnalysis.LOCAL) {
3542 if (ffn.getField().getType().isPtr()&&
3543 ffn.getField().isGlobal()) {
3544 String field=ffn.getField().getSafeSymbol();
3545 String src=generateTemp(fm, ffn.getSrc(),lb);
3546 String dst=generateTemp(fm, ffn.getDst(),lb);
3547 output.println(dst+"="+ src +"->"+field+ ";");
3548 if (locality.getAtomic(lb).get(ffn).intValue()>0)
3549 output.println("TRANSREAD("+dst+", (unsigned int) "+dst+");");
3551 output.println(generateTemp(fm, ffn.getDst(),lb)+"="+ generateTemp(fm,ffn.getSrc(),lb)+"->"+ ffn.getField().getSafeSymbol()+";");
3552 } else if (status==LocalityAnalysis.EITHER) {
3553 //Code is reading from a null pointer
3554 output.println("if ("+generateTemp(fm, ffn.getSrc(),lb)+") {");
3555 output.println("#ifndef RAW");
3556 output.println("printf(\"BIG ERROR\\n\");exit(-1);}");
3557 output.println("#endif");
3558 //This should throw a suitable null pointer error
3559 output.println(generateTemp(fm, ffn.getDst(),lb)+"="+ generateTemp(fm,ffn.getSrc(),lb)+"->"+ ffn.getField().getSafeSymbol()+";");
3561 throw new Error("Read from non-global/non-local in:"+lb.getExplanation());
3563 output.println(generateTemp(fm, ffn.getDst(),lb)+"="+ generateTemp(fm,ffn.getSrc(),lb)+"->"+ ffn.getField().getSafeSymbol()+";");
3567 private void generateFlatSetFieldNode(FlatMethod fm, LocalityBinding lb, FlatSetFieldNode fsfn, PrintWriter output) {
3568 if (fsfn.getField().getSymbol().equals("length")&&fsfn.getDst().getType().isArray())
3569 throw new Error("Can't set array length");
3570 if (state.SINGLETM && locality.getAtomic(lb).get(fsfn).intValue()>0) {
3571 //Single Machine Transaction Case
3572 boolean srcptr=fsfn.getSrc().getType().isPtr();
3573 String src=generateTemp(fm,fsfn.getSrc(),lb);
3574 String dst=generateTemp(fm,fsfn.getDst(),lb);
3575 output.println("//"+srcptr+" "+fsfn.getSrc().getType().isNull());
3576 if (srcptr&&!fsfn.getSrc().getType().isNull()) {
3577 output.println("{");
3578 if ((dc==null)||dc.getNeedSrcTrans(lb, fsfn)&&
3579 locality.getNodePreTempInfo(lb, fsfn).get(fsfn.getSrc())!=LocalityAnalysis.SCRATCH) {
3580 output.println("INTPTR srcoid=("+src+"!=NULL?((INTPTR)"+src+"->"+oidstr+"):0);");
3582 output.println("INTPTR srcoid=(INTPTR)"+src+";");
3585 if (wb.needBarrier(fsfn)&&
3586 locality.getNodePreTempInfo(lb, fsfn).get(fsfn.getDst())!=LocalityAnalysis.SCRATCH) {
3587 output.println("*((unsigned int *)&("+dst+"->___objstatus___))|=DIRTY;");
3589 if (srcptr&!fsfn.getSrc().getType().isNull()) {
3590 output.println("*((unsigned INTPTR *)&("+dst+"->"+ fsfn.getField().getSafeSymbol()+"))=srcoid;");
3591 output.println("}");
3593 output.println(dst+"->"+ fsfn.getField().getSafeSymbol()+"="+ src+";");
3595 } else if (state.DSM && locality.getAtomic(lb).get(fsfn).intValue()>0) {
3596 Integer statussrc=locality.getNodePreTempInfo(lb,fsfn).get(fsfn.getSrc());
3597 Integer statusdst=locality.getNodeTempInfo(lb).get(fsfn).get(fsfn.getDst());
3598 boolean srcglobal=statussrc==LocalityAnalysis.GLOBAL;
3600 String src=generateTemp(fm,fsfn.getSrc(),lb);
3601 String dst=generateTemp(fm,fsfn.getDst(),lb);
3603 output.println("{");
3604 output.println("INTPTR srcoid=("+src+"!=NULL?((INTPTR)"+src+"->"+oidstr+"):0);");
3606 if (statusdst.equals(LocalityAnalysis.GLOBAL)) {
3609 if (wb.needBarrier(fsfn))
3610 output.println("*((unsigned int *)&("+dst+"->___localcopy___))|=DIRTY;");
3612 output.println("*((unsigned INTPTR *)&("+glbdst+"->"+ fsfn.getField().getSafeSymbol()+"))=srcoid;");
3614 output.println(glbdst+"->"+ fsfn.getField().getSafeSymbol()+"="+ src+";");
3615 } else if (statusdst.equals(LocalityAnalysis.LOCAL)) {
3616 /** Check if we need to copy */
3617 output.println("if(!"+dst+"->"+localcopystr+") {");
3618 /* Link object into list */
3619 String revertptr=generateTemp(fm, reverttable.get(lb),lb);
3620 output.println(revertptr+"=revertlist;");
3621 if (GENERATEPRECISEGC || this.state.MULTICOREGC)
3622 output.println("COPY_OBJ((struct garbagelist *)"+localsprefixaddr+",(struct ___Object___ *)"+dst+");");
3624 output.println("COPY_OBJ("+dst+");");
3625 output.println(dst+"->"+nextobjstr+"="+revertptr+";");
3626 output.println("revertlist=(struct ___Object___ *)"+dst+";");
3627 output.println("}");
3629 output.println(dst+"->"+ fsfn.getField().getSafeSymbol()+"=(void *) srcoid;");
3631 output.println(dst+"->"+ fsfn.getField().getSafeSymbol()+"="+ src+";");
3632 } else if (statusdst.equals(LocalityAnalysis.EITHER)) {
3633 //writing to a null...bad
3634 output.println("if ("+dst+") {");
3635 output.println("printf(\"BIG ERROR 2\\n\");exit(-1);}");
3637 output.println(dst+"->"+ fsfn.getField().getSafeSymbol()+"=(void *) srcoid;");
3639 output.println(dst+"->"+ fsfn.getField().getSafeSymbol()+"="+ src+";");
3642 output.println("}");
3645 if (state.FASTCHECK) {
3646 String dst=generateTemp(fm, fsfn.getDst(),lb);
3647 output.println("if(!"+dst+"->"+localcopystr+") {");
3648 /* Link object into list */
3649 if (GENERATEPRECISEGC || this.state.MULTICOREGC)
3650 output.println("COPY_OBJ((struct garbagelist *)"+localsprefixaddr+",(struct ___Object___ *)"+dst+");");
3652 output.println("COPY_OBJ("+dst+");");
3653 output.println(dst+"->"+nextobjstr+"="+fcrevert+";");
3654 output.println(fcrevert+"=(struct ___Object___ *)"+dst+";");
3655 output.println("}");
3657 output.println(generateTemp(fm, fsfn.getDst(),lb)+"->"+ fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc(),lb)+";");
3661 private void generateFlatElementNode(FlatMethod fm, LocalityBinding lb, FlatElementNode fen, PrintWriter output) {
3662 TypeDescriptor elementtype=fen.getSrc().getType().dereference();
3665 if (elementtype.isArray()||elementtype.isClass())
3668 type=elementtype.getSafeSymbol()+" ";
3670 if (this.state.ARRAYBOUNDARYCHECK && fen.needsBoundsCheck()) {
3671 output.println("if ("+generateTemp(fm, fen.getIndex(),lb)+"< 0 | "+generateTemp(fm, fen.getIndex(),lb)+" >= "+generateTemp(fm,fen.getSrc(),lb) + "->___length___)");
3672 output.println("failedboundschk();");
3674 if (state.SINGLETM) {
3675 //Single machine transaction case
3676 String dst=generateTemp(fm, fen.getDst(),lb);
3677 if (!state.STMARRAY||wb.needBarrier(fen)||locality.getNodePreTempInfo(lb, fen).get(fen.getSrc())==LocalityAnalysis.SCRATCH) {
3678 output.println(dst +"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex(),lb)+"];");
3680 output.println("STMGETARRAY("+dst+", "+ generateTemp(fm,fen.getSrc(),lb)+", "+generateTemp(fm, fen.getIndex(),lb)+", "+type+");");
3683 if (elementtype.isPtr()&&locality.getAtomic(lb).get(fen).intValue()>0&&
3684 locality.getNodePreTempInfo(lb, fen).get(fen.getSrc())!=LocalityAnalysis.SCRATCH) {
3685 if ((dc==null)||!state.READSET&&dc.getNeedTrans(lb, fen)||state.READSET&&dc.getNeedWriteTrans(lb, fen)) {
3686 output.println("TRANSREAD("+dst+", "+dst+", (void *)(" + localsprefixaddr+"));");
3687 } else if (state.READSET&&dc.getNeedTrans(lb, fen)) {
3688 output.println("TRANSREADRD("+dst+", "+dst+");");
3691 } else if (state.DSM) {
3692 Integer status=locality.getNodePreTempInfo(lb,fen).get(fen.getSrc());
3693 if (status==LocalityAnalysis.GLOBAL) {
3694 String dst=generateTemp(fm, fen.getDst(),lb);
3695 if (elementtype.isPtr()) {
3696 output.println(dst +"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex(),lb)+"];");
3697 output.println("TRANSREAD("+dst+", "+dst+");");
3699 output.println(dst +"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex(),lb)+"];");
3701 } else if (status==LocalityAnalysis.LOCAL) {
3702 output.println(generateTemp(fm, fen.getDst(),lb)+"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex(),lb)+"];");
3703 } else if (status==LocalityAnalysis.EITHER) {
3704 //Code is reading from a null pointer
3705 output.println("if ("+generateTemp(fm, fen.getSrc(),lb)+") {");
3706 output.println("#ifndef RAW");
3707 output.println("printf(\"BIG ERROR\\n\");exit(-1);}");
3708 output.println("#endif");
3709 //This should throw a suitable null pointer error
3710 output.println(generateTemp(fm, fen.getDst(),lb)+"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex(),lb)+"];");
3712 throw new Error("Read from non-global/non-local in:"+lb.getExplanation());
3714 output.println(generateTemp(fm, fen.getDst(),lb)+"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex(),lb)+"];");
3718 private void generateFlatSetElementNode(FlatMethod fm, LocalityBinding lb, FlatSetElementNode fsen, PrintWriter output) {
3719 //TODO: need dynamic check to make sure this assignment is actually legal
3720 //Because Object[] could actually be something more specific...ie. Integer[]
3722 TypeDescriptor elementtype=fsen.getDst().getType().dereference();
3725 if (elementtype.isArray()||elementtype.isClass())
3728 type=elementtype.getSafeSymbol()+" ";
3730 if (this.state.ARRAYBOUNDARYCHECK && fsen.needsBoundsCheck()) {
3731 output.println("if ("+generateTemp(fm, fsen.getIndex(),lb)+"< 0 | "+generateTemp(fm, fsen.getIndex(),lb)+" >= "+generateTemp(fm,fsen.getDst(),lb) + "->___length___)");
3732 output.println("failedboundschk();");
3735 if (state.SINGLETM && locality.getAtomic(lb).get(fsen).intValue()>0) {
3736 //Transaction set element case
3737 if (!state.STMARRAY&&wb.needBarrier(fsen)&&
3738 locality.getNodePreTempInfo(lb, fsen).get(fsen.getDst())!=LocalityAnalysis.SCRATCH) {
3739 output.println("*((unsigned int *)&("+generateTemp(fm,fsen.getDst(),lb)+"->___objstatus___))|=DIRTY;");
3741 if (fsen.getSrc().getType().isPtr()&&!fsen.getSrc().getType().isNull()) {
3742 output.println("{");
3743 String src=generateTemp(fm, fsen.getSrc(), lb);
3744 if ((dc==null)||dc.getNeedSrcTrans(lb, fsen)&&
3745 locality.getNodePreTempInfo(lb, fsen).get(fsen.getSrc())!=LocalityAnalysis.SCRATCH) {
3746 output.println("INTPTR srcoid=("+src+"!=NULL?((INTPTR)"+src+"->"+oidstr+"):0);");
3748 output.println("INTPTR srcoid=(INTPTR)"+src+";");
3750 if (state.STMARRAY&&locality.getNodePreTempInfo(lb, fsen).get(fsen.getDst())!=LocalityAnalysis.SCRATCH&&wb.needBarrier(fsen)) {
3751 output.println("STMSETARRAY("+generateTemp(fm, fsen.getDst(),lb)+", "+generateTemp(fm, fsen.getIndex(),lb)+", srcoid, INTPTR);");
3753 output.println("((INTPTR*)(((char *) &("+ generateTemp(fm,fsen.getDst(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fsen.getIndex(),lb)+"]=srcoid;");
3755 output.println("}");
3757 if (state.STMARRAY&&locality.getNodePreTempInfo(lb, fsen).get(fsen.getDst())!=LocalityAnalysis.SCRATCH&&wb.needBarrier(fsen)) {
3758 output.println("STMSETARRAY("+generateTemp(fm, fsen.getDst(),lb)+", "+generateTemp(fm, fsen.getIndex(),lb)+", "+ generateTemp(fm, fsen.getSrc(), lb) +", "+type+");");
3760 output.println("(("+type +"*)(((char *) &("+ generateTemp(fm,fsen.getDst(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fsen.getIndex(),lb)+"]="+generateTemp(fm,fsen.getSrc(),lb)+";");
3763 } else if (state.DSM && locality.getAtomic(lb).get(fsen).intValue()>0) {
3764 Integer statussrc=locality.getNodePreTempInfo(lb,fsen).get(fsen.getSrc());
3765 Integer statusdst=locality.getNodePreTempInfo(lb,fsen).get(fsen.getDst());
3766 boolean srcglobal=statussrc==LocalityAnalysis.GLOBAL;
3767 boolean dstglobal=statusdst==LocalityAnalysis.GLOBAL;
3768 boolean dstlocal=statusdst==LocalityAnalysis.LOCAL;
3771 if (wb.needBarrier(fsen))
3772 output.println("*((unsigned int *)&("+generateTemp(fm,fsen.getDst(),lb)+"->___localcopy___))|=DIRTY;");
3773 } else if (dstlocal) {
3774 /** Check if we need to copy */
3775 String dst=generateTemp(fm, fsen.getDst(),lb);
3776 output.println("if(!"+dst+"->"+localcopystr+") {");
3777 /* Link object into list */
3778 String revertptr=generateTemp(fm, reverttable.get(lb),lb);
3779 output.println(revertptr+"=revertlist;");
3780 if ((GENERATEPRECISEGC) || this.state.MULTICOREGC)
3781 output.println("COPY_OBJ((struct garbagelist *)"+localsprefixaddr+",(struct ___Object___ *)"+dst+");");
3783 output.println("COPY_OBJ("+dst+");");
3784 output.println(dst+"->"+nextobjstr+"="+revertptr+";");
3785 output.println("revertlist=(struct ___Object___ *)"+dst+";");
3786 output.println("}");
3787 } else throw new Error("Unknown array type");
3789 output.println("{");
3790 String src=generateTemp(fm, fsen.getSrc(), lb);
3791 output.println("INTPTR srcoid=("+src+"!=NULL?((INTPTR)"+src+"->"+oidstr+"):0);");
3792 output.println("((INTPTR*)(((char *) &("+ generateTemp(fm,fsen.getDst(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fsen.getIndex(),lb)+"]=srcoid;");
3793 output.println("}");
3795 output.println("(("+type +"*)(((char *) &("+ generateTemp(fm,fsen.getDst(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fsen.getIndex(),lb)+"]="+generateTemp(fm,fsen.getSrc(),lb)+";");
3798 if (state.FASTCHECK) {
3799 String dst=generateTemp(fm, fsen.getDst(),lb);
3800 output.println("if(!"+dst+"->"+localcopystr+") {");
3801 /* Link object into list */
3802 if (GENERATEPRECISEGC || this.state.MULTICOREGC)
3803 output.println("COPY_OBJ((struct garbagelist *)"+localsprefixaddr+",(struct ___Object___ *)"+dst+");");
3805 output.println("COPY_OBJ("+dst+");");
3806 output.println(dst+"->"+nextobjstr+"="+fcrevert+";");
3807 output.println(fcrevert+"=(struct ___Object___ *)"+dst+";");
3808 output.println("}");
3810 output.println("(("+type +"*)(((char *) &("+ generateTemp(fm,fsen.getDst(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fsen.getIndex(),lb)+"]="+generateTemp(fm,fsen.getSrc(),lb)+";");
3814 protected void generateFlatNew(FlatMethod fm, LocalityBinding lb, FlatNew fn, PrintWriter output) {
3815 if (state.DSM && locality.getAtomic(lb).get(fn).intValue()>0&&!fn.isGlobal()) {
3816 //Stash pointer in case of GC
3817 String revertptr=generateTemp(fm, reverttable.get(lb),lb);
3818 output.println(revertptr+"=revertlist;");
3820 if (state.SINGLETM) {
3821 if (fn.getType().isArray()) {
3822 int arrayid=state.getArrayNumber(fn.getType())+state.numClasses();
3823 if (locality.getAtomic(lb).get(fn).intValue()>0) {
3824 //inside transaction
3825 output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarraytrans("+localsprefixaddr+", "+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+");");
3827 //outside transaction
3828 output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarray("+localsprefixaddr+", "+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+");");
3831 if (locality.getAtomic(lb).get(fn).intValue()>0) {
3832 //inside transaction
3833 output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newtrans("+localsprefixaddr+", "+fn.getType().getClassDesc().getId()+");");
3835 //outside transaction
3836 output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_new("+localsprefixaddr+", "+fn.getType().getClassDesc().getId()+");");
3839 } else if (fn.getType().isArray()) {
3840 int arrayid=state.getArrayNumber(fn.getType())+state.numClasses();
3841 if (fn.isGlobal()&&(state.DSM||state.SINGLETM)) {
3842 output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarrayglobal("+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+");");
3843 } else if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
3844 output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarray("+localsprefixaddr+", "+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+");");
3846 output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarray("+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+");");
3849 if (fn.isGlobal()&&(state.DSM||state.SINGLETM)) {
3850 output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newglobal("+fn.getType().getClassDesc().getId()+");");
3851 } else if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
3852 output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_new("+localsprefixaddr+", "+fn.getType().getClassDesc().getId()+");");
3854 output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_new("+fn.getType().getClassDesc().getId()+");");
3857 if (state.DSM && locality.getAtomic(lb).get(fn).intValue()>0&&!fn.isGlobal()) {
3858 String revertptr=generateTemp(fm, reverttable.get(lb),lb);
3859 String dst=generateTemp(fm,fn.getDst(),lb);
3860 output.println(dst+"->___localcopy___=(struct ___Object___*)1;");
3861 output.println(dst+"->"+nextobjstr+"="+revertptr+";");
3862 output.println("revertlist=(struct ___Object___ *)"+dst+";");
3864 if (state.FASTCHECK) {
3865 String dst=generateTemp(fm,fn.getDst(),lb);
3866 output.println(dst+"->___localcopy___=(struct ___Object___*)1;");
3867 output.println(dst+"->"+nextobjstr+"="+fcrevert+";");
3868 output.println(fcrevert+"=(struct ___Object___ *)"+dst+";");
3872 private void generateFlatTagDeclaration(FlatMethod fm, LocalityBinding lb, FlatTagDeclaration fn, PrintWriter output) {
3873 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
3874 output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_tag("+localsprefixaddr+", "+state.getTagId(fn.getType())+");");
3876 output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_tag("+state.getTagId(fn.getType())+");");
3880 private void generateFlatOpNode(FlatMethod fm, LocalityBinding lb, FlatOpNode fon, PrintWriter output) {
3881 if (fon.getRight()!=null) {
3882 if (fon.getOp().getOp()==Operation.URIGHTSHIFT) {
3883 if (fon.getLeft().getType().isLong())
3884 output.println(generateTemp(fm, fon.getDest(),lb)+" = ((unsigned long long)"+generateTemp(fm, fon.getLeft(),lb)+")>>"+generateTemp(fm,fon.getRight(),lb)+";");
3886 output.println(generateTemp(fm, fon.getDest(),lb)+" = ((unsigned int)"+generateTemp(fm, fon.getLeft(),lb)+")>>"+generateTemp(fm,fon.getRight(),lb)+";");
3888 } else if (dc!=null) {
3889 output.print(generateTemp(fm, fon.getDest(),lb)+" = ");
3890 if (dc.getNeedLeftSrcTrans(lb, fon))
3891 output.print("("+generateTemp(fm, fon.getLeft(),lb)+"!=NULL?"+generateTemp(fm, fon.getLeft(),lb)+"->"+oidstr+":NULL)");
3893 output.print(generateTemp(fm, fon.getLeft(),lb));
3894 output.print(fon.getOp().toString());
3895 if (dc.getNeedRightSrcTrans(lb, fon))
3896 output.println("("+generateTemp(fm, fon.getRight(),lb)+"!=NULL?"+generateTemp(fm, fon.getRight(),lb)+"->"+oidstr+":NULL);");
3898 output.println(generateTemp(fm,fon.getRight(),lb)+";");
3900 output.println(generateTemp(fm, fon.getDest(),lb)+" = "+generateTemp(fm, fon.getLeft(),lb)+fon.getOp().toString()+generateTemp(fm,fon.getRight(),lb)+";");
3901 } else if (fon.getOp().getOp()==Operation.ASSIGN)
3902 output.println(generateTemp(fm, fon.getDest(),lb)+" = "+generateTemp(fm, fon.getLeft(),lb)+";");
3903 else if (fon.getOp().getOp()==Operation.UNARYPLUS)
3904 output.println(generateTemp(fm, fon.getDest(),lb)+" = "+generateTemp(fm, fon.getLeft(),lb)+";");
3905 else if (fon.getOp().getOp()==Operation.UNARYMINUS)
3906 output.println(generateTemp(fm, fon.getDest(),lb)+" = -"+generateTemp(fm, fon.getLeft(),lb)+";");
3907 else if (fon.getOp().getOp()==Operation.LOGIC_NOT)
3908 output.println(generateTemp(fm, fon.getDest(),lb)+" = !"+generateTemp(fm, fon.getLeft(),lb)+";");
3909 else if (fon.getOp().getOp()==Operation.COMP)
3910 output.println(generateTemp(fm, fon.getDest(),lb)+" = ~"+generateTemp(fm, fon.getLeft(),lb)+";");
3911 else if (fon.getOp().getOp()==Operation.ISAVAILABLE) {
3912 output.println(generateTemp(fm, fon.getDest(),lb)+" = "+generateTemp(fm, fon.getLeft(),lb)+"->fses==NULL;");
3914 output.println(generateTemp(fm, fon.getDest(),lb)+fon.getOp().toString()+generateTemp(fm, fon.getLeft(),lb)+";");
3917 private void generateFlatCastNode(FlatMethod fm, LocalityBinding lb, FlatCastNode fcn, PrintWriter output) {
3918 /* TODO: Do type check here */
3919 if (fcn.getType().isArray()) {
3920 output.println(generateTemp(fm,fcn.getDst(),lb)+"=(struct ArrayObject *)"+generateTemp(fm,fcn.getSrc(),lb)+";");
3921 } else if (fcn.getType().isClass())
3922 output.println(generateTemp(fm,fcn.getDst(),lb)+"=(struct "+fcn.getType().getSafeSymbol()+" *)"+generateTemp(fm,fcn.getSrc(),lb)+";");
3924 output.println(generateTemp(fm,fcn.getDst(),lb)+"=("+fcn.getType().getSafeSymbol()+")"+generateTemp(fm,fcn.getSrc(),lb)+";");
3927 private void generateFlatLiteralNode(FlatMethod fm, LocalityBinding lb, FlatLiteralNode fln, PrintWriter output) {
3928 if (fln.getValue()==null)
3929 output.println(generateTemp(fm, fln.getDst(),lb)+"=0;");
3930 else if (fln.getType().getSymbol().equals(TypeUtil.StringClass)) {
3931 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
3932 if (state.DSM && locality.getAtomic(lb).get(fln).intValue()>0) {
3933 //Stash pointer in case of GC
3934 String revertptr=generateTemp(fm, reverttable.get(lb),lb);
3935 output.println(revertptr+"=revertlist;");
3937 output.println(generateTemp(fm, fln.getDst(),lb)+"=NewString("+localsprefixaddr+", \""+FlatLiteralNode.escapeString((String)fln.getValue())+"\","+((String)fln.getValue()).length()+");");
3938 if (state.DSM && locality.getAtomic(lb).get(fln).intValue()>0) {
3939 //Stash pointer in case of GC
3940 String revertptr=generateTemp(fm, reverttable.get(lb),lb);
3941 output.println("revertlist="+revertptr+";");
3944 output.println(generateTemp(fm, fln.getDst(),lb)+"=NewString(\""+FlatLiteralNode.escapeString((String)fln.getValue())+"\","+((String)fln.getValue()).length()+");");
3946 } else if (fln.getType().isBoolean()) {
3947 if (((Boolean)fln.getValue()).booleanValue())
3948 output.println(generateTemp(fm, fln.getDst(),lb)+"=1;");
3950 output.println(generateTemp(fm, fln.getDst(),lb)+"=0;");
3951 } else if (fln.getType().isChar()) {
3952 String st=FlatLiteralNode.escapeString(fln.getValue().toString());
3953 output.println(generateTemp(fm, fln.getDst(),lb)+"='"+st+"';");
3954 } else if (fln.getType().isLong()) {
3955 output.println(generateTemp(fm, fln.getDst(),lb)+"="+fln.getValue()+"LL;");
3957 output.println(generateTemp(fm, fln.getDst(),lb)+"="+fln.getValue()+";");
3960 protected void generateFlatReturnNode(FlatMethod fm, LocalityBinding lb, FlatReturnNode frn, PrintWriter output) {
3961 if (frn.getReturnTemp()!=null) {
3962 if (frn.getReturnTemp().getType().isPtr())
3963 output.println("return (struct "+fm.getMethod().getReturnType().getSafeSymbol()+"*)"+generateTemp(fm, frn.getReturnTemp(), lb)+";");
3965 output.println("return "+generateTemp(fm, frn.getReturnTemp(), lb)+";");
3967 output.println("return;");
3971 protected void generateStoreFlatCondBranch(FlatMethod fm, LocalityBinding lb, FlatCondBranch fcb, String label, PrintWriter output) {
3972 output.println("STOREANDBRANCH(!"+generateTemp(fm, fcb.getTest(),lb)+", "+label+"); /* "+fcb.nodeid+" */");
3975 protected void generateFlatCondBranch(FlatMethod fm, LocalityBinding lb, FlatCondBranch fcb, String label, PrintWriter output) {
3976 output.println("if (!"+generateTemp(fm, fcb.getTest(),lb)+") goto "+label+";");
3979 /** This method generates header information for the method or
3980 * task referenced by the Descriptor des. */
3981 private void generateHeader(FlatMethod fm, LocalityBinding lb, Descriptor des, PrintWriter output) {
3982 generateHeader(fm, lb, des, output, false);
3985 private void generateHeader(FlatMethod fm, LocalityBinding lb, Descriptor des, PrintWriter output, boolean addSESErecord) {
3987 ParamsObject objectparams=(ParamsObject)paramstable.get(lb!=null ? lb : des);
3988 MethodDescriptor md=null;
3989 TaskDescriptor task=null;
3990 if (des instanceof MethodDescriptor)
3991 md=(MethodDescriptor) des;
3993 task=(TaskDescriptor) des;
3995 ClassDescriptor cn=md!=null ? md.getClassDesc() : null;
3997 if (md!=null&&md.getReturnType()!=null) {
3998 if (md.getReturnType().isClass()||md.getReturnType().isArray())
3999 output.print("struct " + md.getReturnType().getSafeSymbol()+" * ");
4001 output.print(md.getReturnType().getSafeSymbol()+" ");
4003 //catch the constructor case
4004 output.print("void ");
4006 if (state.DSM||state.SINGLETM) {
4007 output.print(cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(");
4009 output.print(cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(");
4011 output.print(task.getSafeSymbol()+"(");
4013 boolean printcomma=false;
4014 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
4016 if (state.DSM||state.SINGLETM) {
4017 output.print("struct "+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params * "+paramsprefix);
4019 output.print("struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params * "+paramsprefix);
4021 output.print("struct "+task.getSafeSymbol()+"_params * "+paramsprefix);
4027 for(int i=0; i<objectparams.numPrimitives(); i++) {
4028 TempDescriptor temp=objectparams.getPrimitive(i);
4032 if (temp.getType().isClass()||temp.getType().isArray())
4033 output.print("struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol());
4035 output.print(temp.getType().getSafeSymbol()+" "+temp.getSafeSymbol());
4037 output.println(") {");
4038 } else if (!GENERATEPRECISEGC && !this.state.MULTICOREGC) {
4039 /* Imprecise Task */
4040 output.println("void * parameterarray[]) {");
4041 /* Unpack variables */
4042 for(int i=0; i<objectparams.numPrimitives(); i++) {
4043 TempDescriptor temp=objectparams.getPrimitive(i);
4044 output.println("struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol()+"=parameterarray["+i+"];");
4046 for(int i=0; i<fm.numTags(); i++) {
4047 TempDescriptor temp=fm.getTag(i);
4048 int offset=i+objectparams.numPrimitives();
4049 output.println("struct ___TagDescriptor___ * "+temp.getSafeSymbol()+"=parameterarray["+offset+"];");
4052 if ((objectparams.numPrimitives()+fm.numTags())>maxtaskparams)
4053 maxtaskparams=objectparams.numPrimitives()+fm.numTags();
4054 } else output.println(") {");
4057 public void generateFlatFlagActionNode(FlatMethod fm, LocalityBinding lb, FlatFlagActionNode ffan, PrintWriter output) {
4058 output.println("/* FlatFlagActionNode */");
4061 /* Process tag changes */
4062 Relation tagsettable=new Relation();
4063 Relation tagcleartable=new Relation();
4065 Iterator tagsit=ffan.getTempTagPairs();
4066 while (tagsit.hasNext()) {
4067 TempTagPair ttp=(TempTagPair) tagsit.next();
4068 TempDescriptor objtmp=ttp.getTemp();
4069 TagDescriptor tag=ttp.getTag();
4070 TempDescriptor tagtmp=ttp.getTagTemp();
4071 boolean tagstatus=ffan.getTagChange(ttp);
4073 tagsettable.put(objtmp, tagtmp);
4075 tagcleartable.put(objtmp, tagtmp);
4080 Hashtable flagandtable=new Hashtable();
4081 Hashtable flagortable=new Hashtable();
4083 /* Process flag changes */
4084 Iterator flagsit=ffan.getTempFlagPairs();
4085 while(flagsit.hasNext()) {
4086 TempFlagPair tfp=(TempFlagPair)flagsit.next();
4087 TempDescriptor temp=tfp.getTemp();
4088 Hashtable flagtable=(Hashtable)flagorder.get(temp.getType().getClassDesc());
4089 FlagDescriptor flag=tfp.getFlag();
4091 //Newly allocate objects that don't set any flags case
4092 if (flagortable.containsKey(temp)) {
4096 flagortable.put(temp,new Integer(mask));
4098 int flagid=1<<((Integer)flagtable.get(flag)).intValue();
4099 boolean flagstatus=ffan.getFlagChange(tfp);
4102 if (flagortable.containsKey(temp)) {
4103 mask=((Integer)flagortable.get(temp)).intValue();
4106 flagortable.put(temp,new Integer(mask));
4108 int mask=0xFFFFFFFF;
4109 if (flagandtable.containsKey(temp)) {
4110 mask=((Integer)flagandtable.get(temp)).intValue();
4112 mask&=(0xFFFFFFFF^flagid);
4113 flagandtable.put(temp,new Integer(mask));
4119 HashSet flagtagset=new HashSet();
4120 flagtagset.addAll(flagortable.keySet());
4121 flagtagset.addAll(flagandtable.keySet());
4122 flagtagset.addAll(tagsettable.keySet());
4123 flagtagset.addAll(tagcleartable.keySet());
4125 Iterator ftit=flagtagset.iterator();
4126 while(ftit.hasNext()) {
4127 TempDescriptor temp=(TempDescriptor)ftit.next();
4130 Set tagtmps=tagcleartable.get(temp);
4131 if (tagtmps!=null) {
4132 Iterator tagit=tagtmps.iterator();
4133 while(tagit.hasNext()) {
4134 TempDescriptor tagtmp=(TempDescriptor)tagit.next();
4135 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC))
4136 output.println("tagclear("+localsprefixaddr+", (struct ___Object___ *)"+generateTemp(fm, temp,lb)+", "+generateTemp(fm,tagtmp,lb)+");");
4138 output.println("tagclear((struct ___Object___ *)"+generateTemp(fm, temp,lb)+", "+generateTemp(fm,tagtmp,lb)+");");
4142 tagtmps=tagsettable.get(temp);
4143 if (tagtmps!=null) {
4144 Iterator tagit=tagtmps.iterator();
4145 while(tagit.hasNext()) {
4146 TempDescriptor tagtmp=(TempDescriptor)tagit.next();
4147 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC))
4148 output.println("tagset("+localsprefixaddr+", (struct ___Object___ *)"+generateTemp(fm, temp,lb)+", "+generateTemp(fm,tagtmp,lb)+");");
4150 output.println("tagset((struct ___Object___ *)"+generateTemp(fm, temp, lb)+", "+generateTemp(fm,tagtmp, lb)+");");
4155 int andmask=0xFFFFFFF;
4157 if (flagortable.containsKey(temp))
4158 ormask=((Integer)flagortable.get(temp)).intValue();
4159 if (flagandtable.containsKey(temp))
4160 andmask=((Integer)flagandtable.get(temp)).intValue();
4161 generateFlagOrAnd(ffan, fm, lb, temp, output, ormask, andmask);
4162 generateObjectDistribute(ffan, fm, lb, temp, output);
4166 protected void generateFlagOrAnd(FlatFlagActionNode ffan, FlatMethod fm, LocalityBinding lb, TempDescriptor temp,
4167 PrintWriter output, int ormask, int andmask) {
4168 if (ffan.getTaskType()==FlatFlagActionNode.NEWOBJECT) {
4169 output.println("flagorandinit("+generateTemp(fm, temp, lb)+", 0x"+Integer.toHexString(ormask)+", 0x"+Integer.toHexString(andmask)+");");
4171 output.println("flagorand("+generateTemp(fm, temp, lb)+", 0x"+Integer.toHexString(ormask)+", 0x"+Integer.toHexString(andmask)+");");
4175 protected void generateObjectDistribute(FlatFlagActionNode ffan, FlatMethod fm, LocalityBinding lb, TempDescriptor temp, PrintWriter output) {
4176 output.println("enqueueObject("+generateTemp(fm, temp, lb)+");");
4179 void generateOptionalHeader(PrintWriter headers) {
4182 headers.println("#include \"task.h\"\n\n");
4183 headers.println("#ifndef _OPTIONAL_STRUCT_");
4184 headers.println("#define _OPTIONAL_STRUCT_");
4186 //STRUCT PREDICATEMEMBER
4187 headers.println("struct predicatemember{");
4188 headers.println("int type;");
4189 headers.println("int numdnfterms;");
4190 headers.println("int * flags;");
4191 headers.println("int numtags;");
4192 headers.println("int * tags;\n};\n\n");
4194 //STRUCT OPTIONALTASKDESCRIPTOR
4195 headers.println("struct optionaltaskdescriptor{");
4196 headers.println("struct taskdescriptor * task;");
4197 headers.println("int index;");
4198 headers.println("int numenterflags;");
4199 headers.println("int * enterflags;");
4200 headers.println("int numpredicatemembers;");
4201 headers.println("struct predicatemember ** predicatememberarray;");
4202 headers.println("};\n\n");
4204 //STRUCT TASKFAILURE
4205 headers.println("struct taskfailure {");
4206 headers.println("struct taskdescriptor * task;");
4207 headers.println("int index;");
4208 headers.println("int numoptionaltaskdescriptors;");
4209 headers.println("struct optionaltaskdescriptor ** optionaltaskdescriptorarray;\n};\n\n");
4211 //STRUCT FSANALYSISWRAPPER
4212 headers.println("struct fsanalysiswrapper{");
4213 headers.println("int flags;");
4214 headers.println("int numtags;");
4215 headers.println("int * tags;");
4216 headers.println("int numtaskfailures;");
4217 headers.println("struct taskfailure ** taskfailurearray;");
4218 headers.println("int numoptionaltaskdescriptors;");
4219 headers.println("struct optionaltaskdescriptor ** optionaltaskdescriptorarray;\n};\n\n");
4221 //STRUCT CLASSANALYSISWRAPPER
4222 headers.println("struct classanalysiswrapper{");
4223 headers.println("int type;");
4224 headers.println("int numotd;");
4225 headers.println("struct optionaltaskdescriptor ** otdarray;");
4226 headers.println("int numfsanalysiswrappers;");
4227 headers.println("struct fsanalysiswrapper ** fsanalysiswrapperarray;\n};");
4229 headers.println("extern struct classanalysiswrapper * classanalysiswrapperarray[];");
4231 Iterator taskit=state.getTaskSymbolTable().getDescriptorsIterator();
4232 while(taskit.hasNext()) {
4233 TaskDescriptor td=(TaskDescriptor)taskit.next();
4234 headers.println("extern struct taskdescriptor task_"+td.getSafeSymbol()+";");
4239 //CHECK OVER THIS -- THERE COULD BE SOME ERRORS HERE
4240 int generateOptionalPredicate(Predicate predicate, OptionalTaskDescriptor otd, ClassDescriptor cdtemp, PrintWriter output) {
4241 int predicateindex = 0;
4242 //iterate through the classes concerned by the predicate
4243 Set c_vard = predicate.vardescriptors;
4244 Hashtable<TempDescriptor, Integer> slotnumber=new Hashtable<TempDescriptor, Integer>();
4247 for(Iterator vard_it = c_vard.iterator(); vard_it.hasNext();) {
4248 VarDescriptor vard = (VarDescriptor)vard_it.next();
4249 TypeDescriptor typed = vard.getType();
4251 //generate for flags
4252 HashSet fen_hashset = predicate.flags.get(vard.getSymbol());
4253 output.println("int predicateflags_"+predicateindex+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+"[]={");
4255 if (fen_hashset!=null) {
4256 for (Iterator fen_it = fen_hashset.iterator(); fen_it.hasNext();) {
4257 FlagExpressionNode fen = (FlagExpressionNode)fen_it.next();
4259 DNFFlag dflag=fen.getDNF();
4260 numberterms+=dflag.size();
4262 Hashtable flags=(Hashtable)flagorder.get(typed.getClassDesc());
4264 for(int j=0; j<dflag.size(); j++) {
4266 output.println(",");
4267 Vector term=dflag.get(j);
4270 for(int k=0; k<term.size(); k++) {
4271 DNFFlagAtom dfa=(DNFFlagAtom)term.get(k);
4272 FlagDescriptor fd=dfa.getFlag();
4273 boolean negated=dfa.getNegated();
4274 int flagid=1<<((Integer)flags.get(fd)).intValue();
4279 output.print("/*andmask*/0x"+Integer.toHexString(andmask)+", /*checkmask*/0x"+Integer.toHexString(checkmask));
4284 output.println("};\n");
4287 TagExpressionList tagel = predicate.tags.get(vard.getSymbol());
4288 output.println("int predicatetags_"+predicateindex+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+"[]={");
4291 for(int j=0; j<tagel.numTags(); j++) {
4293 output.println(",");
4294 TempDescriptor tmp=tagel.getTemp(j);
4295 if (!slotnumber.containsKey(tmp)) {
4296 Integer slotint=new Integer(current_slot++);
4297 slotnumber.put(tmp,slotint);
4299 int slot=slotnumber.get(tmp).intValue();
4300 output.println("/* slot */"+ slot+", /*tagid*/"+state.getTagId(tmp.getTag()));
4302 numtags = tagel.numTags();
4304 output.println("};");
4306 //store the result into a predicatemember struct
4307 output.println("struct predicatemember predicatemember_"+predicateindex+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+"={");
4308 output.println("/*type*/"+typed.getClassDesc().getId()+",");
4309 output.println("/* number of dnf terms */"+numberterms+",");
4310 output.println("predicateflags_"+predicateindex+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+",");
4311 output.println("/* number of tag */"+numtags+",");
4312 output.println("predicatetags_"+predicateindex+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+",");
4313 output.println("};\n");
4318 //generate an array that stores the entire predicate
4319 output.println("struct predicatemember * predicatememberarray_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+"[]={");
4320 for( int j = 0; j<predicateindex; j++) {
4321 if( j != predicateindex-1) output.println("&predicatemember_"+j+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+",");
4322 else output.println("&predicatemember_"+j+"_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol());
4324 output.println("};\n");
4325 return predicateindex;
4329 void generateOptionalArrays(PrintWriter output, PrintWriter headers, Hashtable<ClassDescriptor, Hashtable<FlagState, Set<OptionalTaskDescriptor>>> safeexecution, Hashtable optionaltaskdescriptors) {
4330 generateOptionalHeader(headers);
4332 output.println("#include \"optionalstruct.h\"\n\n");
4333 output.println("#include \"stdlib.h\"\n");
4335 HashSet processedcd = new HashSet();
4337 Enumeration e = safeexecution.keys();
4338 while (e.hasMoreElements()) {
4341 ClassDescriptor cdtemp=(ClassDescriptor)e.nextElement();
4342 Hashtable flaginfo=(Hashtable)flagorder.get(cdtemp); //will be used several times
4344 //Generate the struct of optionals
4345 Collection c_otd = ((Hashtable)optionaltaskdescriptors.get(cdtemp)).values();
4346 numotd = c_otd.size();
4347 if(maxotd<numotd) maxotd = numotd;
4348 if( !c_otd.isEmpty() ) {
4349 for(Iterator otd_it = c_otd.iterator(); otd_it.hasNext();) {
4350 OptionalTaskDescriptor otd = (OptionalTaskDescriptor)otd_it.next();
4352 //generate the int arrays for the predicate
4353 Predicate predicate = otd.predicate;
4354 int predicateindex = generateOptionalPredicate(predicate, otd, cdtemp, output);
4355 TreeSet<Integer> fsset=new TreeSet<Integer>();
4356 //iterate through possible FSes corresponding to
4357 //the state when entering
4359 for(Iterator fses = otd.enterflagstates.iterator(); fses.hasNext();) {
4360 FlagState fs = (FlagState)fses.next();
4362 for(Iterator flags = fs.getFlags(); flags.hasNext();) {
4363 FlagDescriptor flagd = (FlagDescriptor)flags.next();
4364 int id=1<<((Integer)flaginfo.get(flagd)).intValue();
4367 fsset.add(new Integer(flagid));
4368 //tag information not needed because tag
4369 //changes are not tolerated.
4372 output.println("int enterflag_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+"[]={");
4373 boolean needcomma=false;
4374 for(Iterator<Integer> it=fsset.iterator(); it.hasNext();) {
4377 output.println(it.next());
4380 output.println("};\n");
4383 //generate optionaltaskdescriptor that actually
4384 //includes exit fses, predicate and the task
4386 output.println("struct optionaltaskdescriptor optionaltaskdescriptor_"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+"={");
4387 output.println("&task_"+otd.td.getSafeSymbol()+",");
4388 output.println("/*index*/"+otd.getIndex()+",");
4389 output.println("/*number of enter flags*/"+fsset.size()+",");
4390 output.println("enterflag_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+",");
4391 output.println("/*number of members */"+predicateindex+",");
4392 output.println("predicatememberarray_OTD"+otd.getuid()+"_"+cdtemp.getSafeSymbol()+",");
4393 output.println("};\n");
4397 // if there are no optionals, there is no need to build the rest of the struct
4399 output.println("struct optionaltaskdescriptor * otdarray"+cdtemp.getSafeSymbol()+"[]={");
4400 c_otd = ((Hashtable)optionaltaskdescriptors.get(cdtemp)).values();
4401 if( !c_otd.isEmpty() ) {
4402 boolean needcomma=false;
4403 for(Iterator otd_it = c_otd.iterator(); otd_it.hasNext();) {
4404 OptionalTaskDescriptor otd = (OptionalTaskDescriptor)otd_it.next();
4406 output.println(",");
4408 output.println("&optionaltaskdescriptor_"+otd.getuid()+"_"+cdtemp.getSafeSymbol());
4411 output.println("};\n");
4413 //get all the possible flagstates reachable by an object
4414 Hashtable hashtbtemp = safeexecution.get(cdtemp);
4416 TreeSet fsts=new TreeSet(new FlagComparator(flaginfo));
4417 fsts.addAll(hashtbtemp.keySet());
4418 for(Iterator fsit=fsts.iterator(); fsit.hasNext();) {
4419 FlagState fs = (FlagState)fsit.next();
4422 //get the set of OptionalTaskDescriptors corresponding
4423 HashSet<OptionalTaskDescriptor> availabletasks = (HashSet<OptionalTaskDescriptor>)hashtbtemp.get(fs);
4424 //iterate through the OptionalTaskDescriptors and
4425 //store the pointers to the optionals struct (see on
4426 //top) into an array
4428 output.println("struct optionaltaskdescriptor * optionaltaskdescriptorarray_FS"+fscounter+"_"+cdtemp.getSafeSymbol()+"[] = {");
4429 for(Iterator<OptionalTaskDescriptor> mos = ordertd(availabletasks).iterator(); mos.hasNext();) {
4430 OptionalTaskDescriptor mm = mos.next();
4432 output.println("&optionaltaskdescriptor_"+mm.getuid()+"_"+cdtemp.getSafeSymbol());
4434 output.println("&optionaltaskdescriptor_"+mm.getuid()+"_"+cdtemp.getSafeSymbol()+",");
4437 output.println("};\n");
4439 //process flag information (what the flag after failure is) so we know what optionaltaskdescriptors to choose.
4442 for(Iterator flags = fs.getFlags(); flags.hasNext();) {
4443 FlagDescriptor flagd = (FlagDescriptor)flags.next();
4444 int id=1<<((Integer)flaginfo.get(flagd)).intValue();
4448 //process tag information
4451 boolean first = true;
4452 Enumeration tag_enum = fs.getTags();
4453 output.println("int tags_FS"+fscounter+"_"+cdtemp.getSafeSymbol()+"[]={");
4454 while(tag_enum.hasMoreElements()) {
4456 TagDescriptor tagd = (TagDescriptor)tag_enum.nextElement();
4460 output.println(", ");
4461 output.println("/*tagid*/"+state.getTagId(tagd));
4463 output.println("};");
4465 Set<TaskIndex> tiset=sa.getTaskIndex(fs);
4466 for(Iterator<TaskIndex> itti=tiset.iterator(); itti.hasNext();) {
4467 TaskIndex ti=itti.next();
4471 Set<OptionalTaskDescriptor> otdset=sa.getOptions(fs, ti);
4473 output.print("struct optionaltaskdescriptor * optionaltaskfailure_FS"+fscounter+"_"+ti.getTask().getSafeSymbol()+"_"+ti.getIndex()+"_array[] = {");
4474 boolean needcomma=false;
4475 for(Iterator<OptionalTaskDescriptor> otdit=ordertd(otdset).iterator(); otdit.hasNext();) {
4476 OptionalTaskDescriptor otd=otdit.next();
4480 output.println("&optionaltaskdescriptor_"+otd.getuid()+"_"+cdtemp.getSafeSymbol());
4482 output.println("};");
4484 output.print("struct taskfailure taskfailure_FS"+fscounter+"_"+ti.getTask().getSafeSymbol()+"_"+ti.getIndex()+" = {");
4485 output.print("&task_"+ti.getTask().getSafeSymbol()+", ");
4486 output.print(ti.getIndex()+", ");
4487 output.print(otdset.size()+", ");
4488 output.print("optionaltaskfailure_FS"+fscounter+"_"+ti.getTask().getSafeSymbol()+"_"+ti.getIndex()+"_array");
4489 output.println("};");
4492 tiset=sa.getTaskIndex(fs);
4493 boolean needcomma=false;
4495 output.println("struct taskfailure * taskfailurearray"+fscounter+"_"+cdtemp.getSafeSymbol()+"[]={");
4496 for(Iterator<TaskIndex> itti=tiset.iterator(); itti.hasNext();) {
4497 TaskIndex ti=itti.next();
4498 if (ti.isRuntime()) {
4505 output.print("&taskfailure_FS"+fscounter+"_"+ti.getTask().getSafeSymbol()+"_"+ti.getIndex());
4507 output.println("};\n");
4509 //Store the result in fsanalysiswrapper
4511 output.println("struct fsanalysiswrapper fsanalysiswrapper_FS"+fscounter+"_"+cdtemp.getSafeSymbol()+"={");
4512 output.println("/*flag*/"+flagid+",");
4513 output.println("/* number of tags*/"+tagcounter+",");
4514 output.println("tags_FS"+fscounter+"_"+cdtemp.getSafeSymbol()+",");
4515 output.println("/* numtask failures */"+(tiset.size()-runtimeti)+",");
4516 output.println("taskfailurearray"+fscounter+"_"+cdtemp.getSafeSymbol()+",");
4517 output.println("/* number of optionaltaskdescriptors */"+availabletasks.size()+",");
4518 output.println("optionaltaskdescriptorarray_FS"+fscounter+"_"+cdtemp.getSafeSymbol());
4519 output.println("};\n");
4523 //Build the array of fsanalysiswrappers
4524 output.println("struct fsanalysiswrapper * fsanalysiswrapperarray_"+cdtemp.getSafeSymbol()+"[] = {");
4525 boolean needcomma=false;
4526 for(int i = 0; i<fscounter; i++) {
4527 if (needcomma) output.print(",");
4528 output.println("&fsanalysiswrapper_FS"+(i+1)+"_"+cdtemp.getSafeSymbol());
4531 output.println("};");
4533 //Build the classanalysiswrapper referring to the previous array
4534 output.println("struct classanalysiswrapper classanalysiswrapper_"+cdtemp.getSafeSymbol()+"={");
4535 output.println("/*type*/"+cdtemp.getId()+",");
4536 output.println("/*numotd*/"+numotd+",");
4537 output.println("otdarray"+cdtemp.getSafeSymbol()+",");
4538 output.println("/* number of fsanalysiswrappers */"+fscounter+",");
4539 output.println("fsanalysiswrapperarray_"+cdtemp.getSafeSymbol()+"};\n");
4540 processedcd.add(cdtemp);
4543 //build an array containing every classes for which code has been build
4544 output.println("struct classanalysiswrapper * classanalysiswrapperarray[]={");
4545 for(int i=0; i<state.numClasses(); i++) {
4546 ClassDescriptor cn=cdarray[i];
4549 if ((cn != null) && (processedcd.contains(cn)))
4550 output.print("&classanalysiswrapper_"+cn.getSafeSymbol());
4552 output.print("NULL");
4554 output.println("};");
4556 output.println("#define MAXOTD "+maxotd);
4557 headers.println("#endif");
4560 public List<OptionalTaskDescriptor> ordertd(Set<OptionalTaskDescriptor> otdset) {
4561 Relation r=new Relation();
4562 for(Iterator<OptionalTaskDescriptor>otdit=otdset.iterator(); otdit.hasNext();) {
4563 OptionalTaskDescriptor otd=otdit.next();
4564 TaskIndex ti=new TaskIndex(otd.td, otd.getIndex());
4568 LinkedList<OptionalTaskDescriptor> l=new LinkedList<OptionalTaskDescriptor>();
4569 for(Iterator it=r.keySet().iterator(); it.hasNext();) {
4570 Set s=r.get(it.next());
4571 for(Iterator it2=s.iterator(); it2.hasNext();) {
4572 OptionalTaskDescriptor otd=(OptionalTaskDescriptor)it2.next();
4580 protected void outputTransCode(PrintWriter output) {