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;
14 import Analysis.TaskStateAnalysis.FlagState;
15 import Analysis.TaskStateAnalysis.FlagComparator;
16 import Analysis.TaskStateAnalysis.OptionalTaskDescriptor;
17 import Analysis.TaskStateAnalysis.Predicate;
18 import Analysis.TaskStateAnalysis.SafetyAnalysis;
19 import Analysis.TaskStateAnalysis.TaskIndex;
20 import Analysis.Locality.LocalityAnalysis;
21 import Analysis.Locality.LocalityBinding;
22 import Analysis.Locality.DiscoverConflicts;
23 import Analysis.Locality.DCWrapper;
24 import Analysis.Locality.DelayComputation;
25 import Analysis.Locality.BranchAnalysis;
26 import Analysis.CallGraph.CallGraph;
27 import Analysis.Prefetch.*;
28 import Analysis.Loops.WriteBarrier;
29 import Analysis.Loops.GlobalFieldType;
30 import Analysis.Locality.TypeAnalysis;
31 import Util.CodePrinter;
33 public class BuildCodeTran extends BuildCode {
34 String oidstr="___nextobject___";
35 LocalityAnalysis locality;
36 Hashtable<LocalityBinding, TempDescriptor> reverttable;
37 Hashtable<LocalityBinding, Hashtable<TempDescriptor, TempDescriptor>> backuptable;
41 DiscoverConflicts recorddc;
43 LocalityBinding currlb;
46 public BuildCodeTran(State st, Hashtable temptovar, TypeUtil typeutil, SafetyAnalysis sa, PrefetchAnalysis pa) {
47 this(st, temptovar, typeutil, null, sa, pa);
50 public BuildCodeTran(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality, PrefetchAnalysis pa) {
51 this(st, temptovar, typeutil, locality, null, pa);
54 public BuildCodeTran(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality, SafetyAnalysis sa, PrefetchAnalysis pa) {
55 super(st, temptovar, typeutil, sa);
58 oidstr="___objlocation___";
60 this.locality=locality;
61 this.reverttable=new Hashtable<LocalityBinding, TempDescriptor>();
62 this.backuptable=new Hashtable<LocalityBinding, Hashtable<TempDescriptor, TempDescriptor>>();
63 this.wb=new WriteBarrier(locality, st);
65 if (state.SINGLETM&&state.DCOPTS) {
66 TypeAnalysis typeanalysis=new TypeAnalysis(locality, st, typeutil,callgraph);
67 GlobalFieldType gft=new GlobalFieldType(callgraph, st, typeutil.getMain());
68 this.dc=new DiscoverConflicts(locality, st, typeanalysis, gft);
71 if (state.DELAYCOMP) {
72 TypeAnalysis typeanalysis=new TypeAnalysis(locality, st, typeutil,callgraph);
73 GlobalFieldType gft=new GlobalFieldType(callgraph, st, typeutil.getMain());
74 delaycomp=new DCWrapper(locality, st, typeanalysis, gft);
75 dc=delaycomp.getConflicts();
76 recorddc=new DiscoverConflicts(locality, st, typeanalysis, delaycomp.getCannotDelayMap(), true, true, null);
77 recorddc.doAnalysis();
81 /** The buildCode method outputs C code for all the methods. The Flat
82 * versions of the methods must already be generated and stored in
83 * the State object. */
85 PrintWriter outsandbox=null;
87 protected void buildCodeSetup() {
90 outsandbox=new CodePrinter(new FileOutputStream(PREFIX+"sandboxdefs.c"), true);
92 } catch (Exception e) {
98 protected void additionalIncludesMethodsHeader(PrintWriter outmethodheader) {
100 outmethodheader.println("#include \"dstm.h\"");
102 outmethodheader.println("#include \"sandbox.h\"");
104 if (state.SINGLETM) {
105 outmethodheader.println("#include \"tm.h\"");
106 outmethodheader.println("#include \"delaycomp.h\"");
107 outmethodheader.println("#include \"inlinestm.h\"");
109 if (state.ABORTREADERS) {
110 outmethodheader.println("#include \"abortreaders.h\"");
111 outmethodheader.println("#include <setjmp.h>");
117 protected void outputMainMethod(PrintWriter outmethod) {
118 outmethod.println("int main(int argc, const char *argv[]) {");
119 outmethod.println(" int i;");
120 outmethod.println(" global_defs_p=calloc(1, sizeof(struct global_defs_t));");
121 outmethod.println(" global_defsprim_p=calloc(1, sizeof(struct global_defsprim_t));");
122 if (GENERATEPRECISEGC) {
123 outmethod.println(" global_defs_p->size="+globaldefscount+";");
124 outmethod.println(" for(i=0;i<"+globaldefscount+";i++) {");
125 outmethod.println(" ((struct garbagelist *)global_defs_p)->array[i]=NULL;");
126 outmethod.println(" }");
129 outputStaticBlocks(outmethod);
130 outputClassObjects(outmethod);
131 additionalCodeAtTopOfMain(outmethod);
134 if (state.DSMRECOVERYSTATS) {
135 outmethod.println("#ifdef RECOVERYSTATS \n");
136 outmethod.println("handle();\n");
137 outmethod.println("#endif\n");
139 outmethod.println("#if defined(TRANSSTATS) || defined(RECOVERYSTATS) \n");
140 outmethod.println("handle();\n");
141 outmethod.println("#endif\n");
144 outmethod.println("initializethreads();");
147 outmethod.println("if (dstmStartup(argv[1])) {");
148 if (GENERATEPRECISEGC) {
149 outmethod.println(" struct ArrayObject * stringarray=allocate_newarray(NULL, STRINGARRAYTYPE, argc-2);");
151 outmethod.println(" struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc-2);");
154 if (GENERATEPRECISEGC) {
155 outmethod.println(" struct ArrayObject * stringarray=allocate_newarray(NULL, STRINGARRAYTYPE, argc-1);");
157 outmethod.println(" struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc-1);");
161 outmethod.println(" for(i=2;i<argc;i++) {");
163 outmethod.println(" for(i=1;i<argc;i++) {");
164 outmethod.println(" int length=strlen(argv[i]);");
165 if (GENERATEPRECISEGC) {
166 outmethod.println(" struct ___String___ *newstring=NewString(NULL, argv[i], length);");
168 outmethod.println(" struct ___String___ *newstring=NewString(argv[i], length);");
171 outmethod.println(" ((void **)(((char *)& stringarray->___length___)+sizeof(int)))[i-2]=newstring;");
173 outmethod.println(" ((void **)(((char *)& stringarray->___length___)+sizeof(int)))[i-1]=newstring;");
174 outmethod.println(" }");
176 MethodDescriptor md=typeutil.getMain();
177 ClassDescriptor cd=typeutil.getMainClass();
179 outmethod.println(" {");
180 if (GENERATEPRECISEGC) {
181 outmethod.print(" struct "+cd.getSafeSymbol()+locality.getMain().getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={");
182 outmethod.println("1, NULL,"+"stringarray};");
183 outmethod.println(" "+cd.getSafeSymbol()+locality.getMain().getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(& __parameterlist__);");
185 outmethod.println(" "+cd.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(stringarray);");
187 outmethod.println(" }");
190 outmethod.println("}");
193 outmethod.println("pthread_mutex_lock(&gclistlock);");
194 outmethod.println("threadcount--;");
195 outmethod.println("pthread_cond_signal(&gccond);");
196 outmethod.println("pthread_mutex_unlock(&gclistlock);");
198 outmethod.println("#if defined(TRANSSTATS) \n");
199 outmethod.println("printf(\"****** Transaction Stats ******\\n\");");
200 outmethod.println("printf(\"numTransCommit= %d\\n\", numTransCommit);");
201 outmethod.println("printf(\"numTransAbort= %d\\n\", numTransAbort);");
202 outmethod.println("printf(\"nSoftAbort= %d\\n\", nSoftAbort);");
204 outmethod.println("printf(\"nchashSearch= %d\\n\", nchashSearch);");
205 outmethod.println("printf(\"nmhashSearch= %d\\n\", nmhashSearch);");
206 outmethod.println("printf(\"nprehashSearch= %d\\n\", nprehashSearch);");
207 outmethod.println("printf(\"ndirtyCacheObj= %d\\n\", ndirtyCacheObj);");
208 outmethod.println("printf(\"nRemoteReadSend= %d\\n\", nRemoteSend);");
209 outmethod.println("printf(\"bytesSent= %d\\n\", bytesSent);");
210 outmethod.println("printf(\"bytesRecv= %d\\n\", bytesRecv);");
211 outmethod.println("printf(\"totalObjSize= %d\\n\", totalObjSize);");
212 outmethod.println("printf(\"sendRemoteReq= %d\\n\", sendRemoteReq);");
213 outmethod.println("printf(\"getResponse= %d\\n\", getResponse);");
214 } else if (state.SINGLETM) {
215 outmethod.println("printf(\"nSoftAbortAbort= %d\\n\", nSoftAbortAbort);");
216 outmethod.println("printf(\"nSoftAbortCommit= %d\\n\", nSoftAbortCommit);");
217 outmethod.println("#ifdef STMSTATS\n");
218 outmethod.println("for(i=0; i<TOTALNUMCLASSANDARRAY; i++) {\n");
219 outmethod.println(" printf(\"typesCausingAbort[%2d] numaccess= %5d numabort= %3d\\n\", i, typesCausingAbort[i].numaccess, typesCausingAbort[i].numabort);\n");
220 outmethod.println("}\n");
221 outmethod.println("#endif\n");
222 outmethod.println("fflush(stdout);");
224 outmethod.println("#endif\n");
227 if (state.EVENTMONITOR) {
228 outmethod.println("dumpdata();");
232 outmethod.println("pthread_exit(NULL);");
233 additionalCodeAtBottomOfMain(outmethod);
234 outmethod.println("}");
237 protected void additionalIncludesMethodsImplementation(PrintWriter outmethod) {
239 outmethod.println("#include \"sandboxdefs.c\"");
242 outmethod.println("#include \"addPrefetchEnhance.h\"");
243 outmethod.println("#include \"localobjects.h\"");
247 protected void generateMethods(PrintWriter outmethod) {
248 for(Iterator<LocalityBinding> lbit=locality.getLocalityBindings().iterator(); lbit.hasNext(); ) {
249 LocalityBinding lb=lbit.next();
250 MethodDescriptor md=lb.getMethod();
251 FlatMethod fm=state.getMethodFlat(md);
253 if (!md.getModifiers().isNative()) {
254 generateFlatMethod(fm, lb, outmethod);
259 protected void additionalIncludesStructsHeader(PrintWriter outstructs) {
260 LocalityBinding lbrun=new LocalityBinding(typeutil.getRun(), false);
262 lbrun.setGlobalThis(LocalityAnalysis.GLOBAL);
263 } else if (state.SINGLETM) {
264 lbrun.setGlobalThis(LocalityAnalysis.NORMAL);
266 outstructs.println("#define RUNMETHOD "+virtualcalls.getLocalityNumber(lbrun));
269 LocalityBinding lbexecute = new LocalityBinding(typeutil.getExecute(), false);
271 lbexecute.setGlobalThis(LocalityAnalysis.GLOBAL);
272 else if( state.SINGLETM)
273 lbexecute.setGlobalThis(LocalityAnalysis.NORMAL);
274 outstructs.println("#define EXECUTEMETHOD " + virtualcalls.getLocalityNumber(lbexecute));
278 protected void printExtraArrayFields(PrintWriter outclassdefs) {
279 if (state.STMARRAY) {
280 outclassdefs.println(" int lowindex;");
281 outclassdefs.println(" int highindex;");
283 if (state.DUALVIEW) {
284 outclassdefs.println(" int arrayversion;");
288 /** The buildVirtualTables method outputs the virtual dispatch
289 * tables for methods. */
291 protected void buildVirtualTables(PrintWriter outvirtual) {
292 Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
293 while(classit.hasNext()) {
294 ClassDescriptor cd=(ClassDescriptor)classit.next();
295 if (virtualcalls.getMethodCount(cd)>maxcount)
296 maxcount=virtualcalls.getMethodCount(cd);
299 LocalityBinding[][] lbvirtualtable=null;
300 lbvirtualtable=new LocalityBinding[state.numClasses()+state.numArrays()][maxcount];
302 /* Fill in virtual table */
303 classit=state.getClassSymbolTable().getDescriptorsIterator();
304 while(classit.hasNext()) {
305 ClassDescriptor cd=(ClassDescriptor)classit.next();
306 if(cd.isInterface()) {
309 fillinRow(cd, lbvirtualtable, cd.getId());
312 ClassDescriptor objectcd=typeutil.getClass(TypeUtil.ObjectClass);
313 Iterator arrayit=state.getArrayIterator();
314 while(arrayit.hasNext()) {
315 TypeDescriptor td=(TypeDescriptor)arrayit.next();
316 int id=state.getArrayNumber(td);
317 fillinRow(objectcd, lbvirtualtable, id+state.numClasses());
320 outvirtual.print("void * virtualtable[]={");
321 boolean needcomma=false;
322 for(int i=0; i<state.numClasses()+state.numArrays(); i++) {
323 for(int j=0; j<maxcount; j++) {
325 outvirtual.print(", ");
326 if (lbvirtualtable[i][j]!=null) {
327 LocalityBinding lb=lbvirtualtable[i][j];
328 MethodDescriptor md=lb.getMethod();
329 outvirtual.print("& "+md.getClassDesc().getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor());
331 outvirtual.print("0");
335 outvirtual.println("");
337 outvirtual.println("};");
341 protected void fillinRow(ClassDescriptor cd, LocalityBinding[][] virtualtable, int rownum) {
342 /* Get inherited methods */
343 if (cd.getSuperDesc()!=null)
344 fillinRow(cd.getSuperDesc(), virtualtable, rownum);
345 /* Override them with our methods */
346 if (locality.getClassBindings(cd)!=null)
347 for(Iterator<LocalityBinding> lbit=locality.getClassBindings(cd).iterator(); lbit.hasNext(); ) {
348 LocalityBinding lb=lbit.next();
349 MethodDescriptor md=lb.getMethod();
350 //Is the method static or a constructor
351 if (md.isStatic()||md.getReturnType()==null)
353 int methodnum=virtualcalls.getLocalityNumber(lb);
354 virtualtable[rownum][methodnum]=lb;
358 /** Generate array that contains the sizes of class objects. The
359 * object allocation functions in the runtime use this
362 protected void generateSizeArrayExtensions(PrintWriter outclassdefs) {
363 outclassdefs.print("#ifdef TRANSSTATS \n");
364 outclassdefs.print("extern int numTransAbort;\n");
365 outclassdefs.print("extern int numTransCommit;\n");
366 outclassdefs.print("extern int nSoftAbort;\n");
368 outclassdefs.print("extern int nchashSearch;\n");
369 outclassdefs.print("extern int nmhashSearch;\n");
370 outclassdefs.print("extern int nprehashSearch;\n");
371 outclassdefs.print("extern int ndirtyCacheObj;\n");
372 outclassdefs.print("extern int nRemoteSend;\n");
373 outclassdefs.print("extern int sendRemoteReq;\n");
374 outclassdefs.print("extern int getResponse;\n");
375 outclassdefs.print("extern int bytesSent;\n");
376 outclassdefs.print("extern int bytesRecv;\n");
377 outclassdefs.print("extern int totalObjSize;\n");
378 outclassdefs.print("extern void handle();\n");
379 } else if (state.SINGLETM) {
380 outclassdefs.println("extern int nSoftAbortAbort;");
381 outclassdefs.println("extern int nSoftAbortCommit;");
382 outclassdefs.println("#ifdef STMSTATS\n");
383 outclassdefs.println("extern objtypestat_t typesCausingAbort[];");
384 outclassdefs.println("#endif\n");
386 outclassdefs.print("#endif\n");
388 outclassdefs.print("int numprefetchsites = " + pa.prefetchsiteid + ";\n");
391 /** Constructs params and temp objects for each method or task.
392 * These objects tell the compiler which temps need to be
395 protected void generateTempStructs(FlatMethod fm, LocalityBinding lb) {
396 MethodDescriptor md=fm.getMethod();
397 TaskDescriptor task=fm.getTask();
398 Set<TempDescriptor> saveset=lb!=null ? locality.getTempSet(lb) : null;
399 ParamsObject objectparams=md!=null ? new ParamsObject(md,tag++) : new ParamsObject(task, tag++);
401 paramstable.put(lb, objectparams);
402 backuptable.put(lb, new Hashtable<TempDescriptor, TempDescriptor>());
404 paramstable.put(md, objectparams);
406 paramstable.put(task, objectparams);
408 for(int i=0; i<fm.numParameters(); i++) {
409 TempDescriptor temp=fm.getParameter(i);
410 TypeDescriptor type=temp.getType();
411 if (type.isPtr()&&((GENERATEPRECISEGC) || (this.state.MULTICOREGC)))
412 objectparams.addPtr(temp);
414 objectparams.addPrim(temp);
415 if(lb!=null&&saveset.contains(temp)) {
416 backuptable.get(lb).put(temp, temp.createNew());
420 for(int i=0; i<fm.numTags(); i++) {
421 TempDescriptor temp=fm.getTag(i);
422 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC))
423 objectparams.addPtr(temp);
425 objectparams.addPrim(temp);
428 TempObject objecttemps=md!=null ? new TempObject(objectparams,md,tag++) : new TempObject(objectparams, task, tag++);
430 tempstable.put(lb, objecttemps);
432 tempstable.put(md, objecttemps);
434 tempstable.put(task, objecttemps);
436 for(Iterator nodeit=fm.getNodeSet().iterator(); nodeit.hasNext(); ) {
437 FlatNode fn=(FlatNode)nodeit.next();
438 TempDescriptor[] writes=fn.writesTemps();
439 for(int i=0; i<writes.length; i++) {
440 TempDescriptor temp=writes[i];
441 TypeDescriptor type=temp.getType();
442 if (type.isPtr()&&((GENERATEPRECISEGC) || (this.state.MULTICOREGC)))
443 objecttemps.addPtr(temp);
445 objecttemps.addPrim(temp);
446 if(lb!=null&&saveset.contains(temp)&&
447 !backuptable.get(lb).containsKey(temp))
448 backuptable.get(lb).put(temp, temp.createNew());
452 /* Create backup temps */
454 for(Iterator<TempDescriptor> tmpit=backuptable.get(lb).values().iterator(); tmpit.hasNext(); ) {
455 TempDescriptor tmp=tmpit.next();
456 TypeDescriptor type=tmp.getType();
457 if (type.isPtr()&&((GENERATEPRECISEGC) || (this.state.MULTICOREGC)))
458 objecttemps.addPtr(tmp);
460 objecttemps.addPrim(tmp);
462 /* Create temp to hold revert table */
463 if (state.DSM&&(lb.getHasAtomic()||lb.isAtomic())) {
464 TempDescriptor reverttmp=new TempDescriptor("revertlist", typeutil.getClass(TypeUtil.ObjectClass));
465 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC))
466 objecttemps.addPtr(reverttmp);
468 objecttemps.addPrim(reverttmp);
469 reverttable.put(lb, reverttmp);
474 /** This method outputs the following information about classes
476 * (1) For classes, what are the locations of pointers.
477 * (2) For arrays, does the array contain pointers or primitives.
478 * (3) For classes, does the class contain flags.
481 protected void generateLayoutStructs(PrintWriter output) {
482 Iterator it=state.getClassSymbolTable().getDescriptorsIterator();
483 while(it.hasNext()) {
484 ClassDescriptor cn=(ClassDescriptor)it.next();
485 output.println("unsigned INTPTR "+cn.getSafeSymbol()+"_pointers[]={");
486 Iterator allit=cn.getFieldTable().getAllDescriptorsIterator();
488 while(allit.hasNext()) {
489 FieldDescriptor fd=(FieldDescriptor)allit.next();
490 TypeDescriptor type=fd.getType();
491 if (state.DSM&&fd.isGlobal()) //Don't GC the global objects for now
497 allit=cn.getFieldTable().getAllDescriptorsIterator();
498 while(allit.hasNext()) {
499 FieldDescriptor fd=(FieldDescriptor)allit.next();
500 TypeDescriptor type=fd.getType();
501 if (state.DSM&&fd.isGlobal()) //Don't GC the global objects for now
505 output.print("((unsigned INTPTR)&(((struct "+cn.getSafeSymbol() +" *)0)->"+
506 fd.getSafeSymbol()+"))");
509 output.println("};");
511 output.println("unsigned INTPTR * pointerarray[]={");
512 boolean needcomma=false;
513 for(int i=0; i<state.numClasses(); i++) {
514 ClassDescriptor cn=cdarray[i];
519 output.print(cn.getSafeSymbol()+"_pointers");
521 output.print("NULL");
525 for(int i=0; i<state.numArrays(); i++) {
527 output.println(", ");
528 TypeDescriptor tdelement=arraytable[i].dereference();
529 if (tdelement.isArray()||tdelement.isClass())
530 output.print("((unsigned INTPTR *)1)");
536 output.println("};");
538 output.println("int hasflags[]={");
539 for(int i=0; i<state.numClasses(); i++) {
540 ClassDescriptor cn=cdarray[i];
542 output.println(", ");
544 if ((cn != null) && (cn.hasFlags()))
549 output.println("};");
553 protected void generateCallStructsMethods(ClassDescriptor cn, PrintWriter output, PrintWriter headersout) {
554 /* Cycle through LocalityBindings */
555 HashSet<MethodDescriptor> nativemethods=new HashSet<MethodDescriptor>();
556 Set<LocalityBinding> lbset=locality.getClassBindings(cn);
558 for(Iterator<LocalityBinding> lbit=lbset.iterator(); lbit.hasNext(); ) {
559 LocalityBinding lb=lbit.next();
560 MethodDescriptor md=lb.getMethod();
561 if (md.getModifiers().isNative()) {
562 //make sure we only print a native method once
563 if (nativemethods.contains(md)) {
564 FlatMethod fm=state.getMethodFlat(md);
565 generateTempStructs(fm, lb);
568 nativemethods.add(md);
570 generateMethod(cn, md, lb, headersout, output);
573 for(Iterator methodit=cn.getMethods(); methodit.hasNext(); ) {
574 MethodDescriptor md=(MethodDescriptor)methodit.next();
575 if (md.getModifiers().isNative()&&!nativemethods.contains(md)) {
576 //Need to build param structure for library code
577 FlatMethod fm=state.getMethodFlat(md);
578 generateTempStructs(fm, null);
579 generateMethodParam(cn, md, null, output);
585 protected void generateMethodParam(ClassDescriptor cn, MethodDescriptor md, LocalityBinding lb, PrintWriter output) {
586 /* Output parameter structure */
587 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
588 ParamsObject objectparams=(ParamsObject) paramstable.get(lb!=null ? lb : md);
589 if ((state.DSM||state.SINGLETM)&&lb!=null)
590 output.println("struct "+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params {");
592 output.println("struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params {");
593 output.println(" int size;");
594 output.println(" void * next;");
595 for(int i=0; i<objectparams.numPointers(); i++) {
596 TempDescriptor temp=objectparams.getPointer(i);
597 if(state.MGC && temp.getType().isClass() && temp.getType().getClassDesc().isEnum()) {
598 output.println(" int " + temp.getSafeSymbol() + ";");
600 output.println(" struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol()+";");
603 output.println("};\n");
607 protected void generateMethod(ClassDescriptor cn, MethodDescriptor md, LocalityBinding lb, PrintWriter headersout, PrintWriter output) {
608 FlatMethod fm=state.getMethodFlat(md);
609 generateTempStructs(fm, lb);
611 ParamsObject objectparams=(ParamsObject) paramstable.get(lb);
612 TempObject objecttemps=(TempObject) tempstable.get(lb);
614 generateMethodParam(cn, md, lb, output);
616 /* Output temp structure */
617 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
618 output.println("struct "+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals {");
619 output.println(" int size;");
620 output.println(" void * next;");
621 for(int i=0; i<objecttemps.numPointers(); i++) {
622 TempDescriptor temp=objecttemps.getPointer(i);
623 if (temp.getType().isNull())
624 output.println(" void * "+temp.getSafeSymbol()+";");
626 output.println(" struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol()+";");
628 output.println("};\n");
631 /********* Output method declaration ***********/
632 headersout.println("#define D"+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+" 1");
634 /* First the return type */
635 if (md.getReturnType()!=null) {
636 if(state.MGC && md.getReturnType().isClass() && md.getReturnType().getClassDesc().isEnum()) {
637 headersout.println(" int ");
638 } else if (md.getReturnType().isClass()||md.getReturnType().isArray())
639 headersout.print("struct " + md.getReturnType().getSafeSymbol()+" * ");
641 headersout.print(md.getReturnType().getSafeSymbol()+" ");
643 //catch the constructor case
644 headersout.print("void ");
646 /* Next the method name */
647 headersout.print(cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(");
649 boolean printcomma=false;
650 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
651 headersout.print("struct "+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params * "+paramsprefix);
655 /* Output parameter list*/
656 for(int i=0; i<objectparams.numPrimitives(); i++) {
657 TempDescriptor temp=objectparams.getPrimitive(i);
659 headersout.print(", ");
661 if(state.MGC && temp.getType().isClass() && temp.getType().getClassDesc().isEnum()) {
662 headersout.print("int " + temp.getSafeSymbol());
663 } else if (temp.getType().isClass()||temp.getType().isArray())
664 headersout.print("struct " + temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol());
666 headersout.print(temp.getType().getSafeSymbol()+" "+temp.getSafeSymbol());
668 headersout.println(");\n");
671 /***** Generate code for FlatMethod fm. *****/
673 Hashtable<FlatAtomicEnterNode, AtomicRecord> atomicmethodmap;
674 static int atomicmethodcount=0;
677 BranchAnalysis branchanalysis;
678 protected void generateFlatMethod(FlatMethod fm, LocalityBinding lb, PrintWriter output) {
680 System.out.println(fm.printMethod());
681 MethodDescriptor md=fm.getMethod();
682 TaskDescriptor task=fm.getTask();
683 ClassDescriptor cn=md!=null ? md.getClassDesc() : null;
684 ParamsObject objectparams=(ParamsObject)paramstable.get(lb!=null ? lb : md!=null ? md : task);
686 HashSet<AtomicRecord> arset=null;
689 if (state.DELAYCOMP&&!lb.isAtomic()&&lb.getHasAtomic()) {
691 if (atomicmethodmap==null)
692 atomicmethodmap=new Hashtable<FlatAtomicEnterNode, AtomicRecord>();
694 //fix these so we get right strings for local variables
695 localsprefixaddr=localsprefix;
696 localsprefixderef=localsprefix+"->";
697 arset=new HashSet<AtomicRecord>();
699 //build branchanalysis
700 branchanalysis=new BranchAnalysis(locality, lb, delaycomp.getNotReady(lb), delaycomp.livecode(lb), state);
702 //Generate commit methods here
703 for(Iterator<FlatNode> fnit=fm.getNodeSet().iterator(); fnit.hasNext(); ) {
704 FlatNode fn=fnit.next();
705 if (fn.kind()==FKind.FlatAtomicEnterNode&&
706 locality.getAtomic(lb).get(fn.getPrev(0)).intValue()==0&&
707 delaycomp.needsFission(lb, (FlatAtomicEnterNode) fn)) {
708 //We have an atomic enter
709 FlatAtomicEnterNode faen=(FlatAtomicEnterNode) fn;
710 Set<FlatNode> exitset=faen.getExits();
712 String methodname=md.getSymbol()+(atomicmethodcount++);
713 AtomicRecord ar=new AtomicRecord();
717 atomicmethodmap.put(faen, ar);
719 //build data structure declaration
720 output.println("struct atomicprimitives_"+methodname+" {");
722 Set<FlatNode> recordset=delaycomp.livecode(lb);
723 Set<TempDescriptor> liveinto=delaycomp.liveinto(lb, faen, recordset);
724 Set<TempDescriptor> liveout=delaycomp.liveout(lb, faen);
725 Set<TempDescriptor> liveoutvirtualread=delaycomp.liveoutvirtualread(lb, faen);
727 ar.reallivein=new HashSet(liveinto);
729 ar.liveoutvirtualread=liveoutvirtualread;
732 for(Iterator<TempDescriptor> it=liveinto.iterator(); it.hasNext(); ) {
733 TempDescriptor tmp=it.next();
734 //remove the pointers
735 if (tmp.getType().isPtr()) {
738 //let's print it here
739 output.println(tmp.getType().getSafeSymbol()+" "+tmp.getSafeSymbol()+";");
742 for(Iterator<TempDescriptor> it=liveout.iterator(); it.hasNext(); ) {
743 TempDescriptor tmp=it.next();
744 //remove the pointers
745 if (tmp.getType().isPtr()) {
747 } else if (!liveinto.contains(tmp)) {
748 //let's print it here
749 output.println(tmp.getType().getSafeSymbol()+" "+tmp.getSafeSymbol()+";");
752 output.println("};");
754 //print out method name
755 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) {");
756 //build code for commit method
758 //first define local primitives
759 Set<TempDescriptor> alltemps=delaycomp.alltemps(lb, faen, recordset);
760 for(Iterator<TempDescriptor> tmpit=alltemps.iterator(); tmpit.hasNext(); ) {
761 TempDescriptor tmp=tmpit.next();
762 if (!tmp.getType().isPtr()) {
763 if (liveinto.contains(tmp)||liveoutvirtualread.contains(tmp)) {
764 //read from live into set
765 output.println(tmp.getType().getSafeSymbol()+" "+tmp.getSafeSymbol()+"=primitives->"+tmp.getSafeSymbol()+";");
768 output.println(tmp.getType().getSafeSymbol()+" "+tmp.getSafeSymbol()+";");
772 //turn off write barrier generation
774 state.SINGLETM=false;
775 generateCode(faen, fm, lb, exitset, output, false);
777 //turn on write barrier generation
779 output.println("}\n\n");
783 //redefine these back to normal
785 localsprefixaddr="&"+localsprefix;
786 localsprefixderef=localsprefix+".";
788 generateHeader(fm, lb, md!=null ? md : task,output);
789 TempObject objecttemp=(TempObject) tempstable.get(lb!=null ? lb : md!=null ? md : task);
791 if (state.DELAYCOMP&&!lb.isAtomic()&&lb.getHasAtomic()) {
792 for(Iterator<AtomicRecord> arit=arset.iterator(); arit.hasNext(); ) {
793 AtomicRecord ar=arit.next();
794 output.println("struct atomicprimitives_"+ar.name+" primitives_"+ar.name+";");
798 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
799 if (md!=null&&(state.DSM||state.SINGLETM))
800 output.print(" struct "+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals "+localsprefix+"={");
801 else if (md!=null&&!(state.DSM||state.SINGLETM))
802 output.print(" struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals "+localsprefix+"={");
804 output.print(" struct "+task.getSafeSymbol()+"_locals "+localsprefix+"={");
805 output.print(objecttemp.numPointers()+",");
806 output.print(paramsprefix);
807 for(int j=0; j<objecttemp.numPointers(); j++)
808 output.print(", NULL");
809 output.println("};");
812 for(int i=0; i<objecttemp.numPrimitives(); i++) {
813 TempDescriptor td=objecttemp.getPrimitive(i);
814 TypeDescriptor type=td.getType();
815 if (type.isNull() && !type.isArray())
816 output.println(" void * "+td.getSafeSymbol()+";");
817 else if (state.MGC && type.isClass() && type.getClassDesc().isEnum()) {
818 output.println(" int " + td.getSafeSymbol() + ";");
819 } else if (type.isClass()||type.isArray())
820 output.println(" struct "+type.getSafeSymbol()+" * "+td.getSafeSymbol()+";");
822 output.println(" "+type.getSafeSymbol()+" "+td.getSafeSymbol()+";");
827 additionalCodeAtTopFlatMethodBody(output, fm);
831 /* Check to see if we need to do a GC if this is a
832 * multi-threaded program...*/
834 if (((state.THREAD||state.DSM||state.SINGLETM)&&GENERATEPRECISEGC)) {
835 //Don't bother if we aren't in recursive methods...The loops case will catch it
836 if (callgraph.getAllMethods(md).contains(md)) {
837 if (state.DSM&&lb.isAtomic())
838 output.println("if (needtocollect) checkcollect2("+localsprefixaddr+");");
840 output.println("if (unlikely(needtocollect)) checkcollect("+localsprefixaddr+");");
844 generateCode(fm.getNext(0), fm, lb, null, output, true);
845 output.println("}\n\n");
850 protected void generateCode(FlatNode first,
853 Set<FlatNode> stopset,
857 /* Assign labels to FlatNode's if necessary.*/
859 Hashtable<FlatNode, Integer> nodetolabel;
861 if (state.DELAYCOMP&&!firstpass)
862 nodetolabel=dcassignLabels(first, stopset);
864 nodetolabel=assignLabels(first, stopset);
866 Set<FlatNode> storeset=null;
867 HashSet<FlatNode> genset=null;
868 HashSet<FlatNode> refset=null;
869 Set<FlatNode> unionset=null;
871 if (state.DELAYCOMP&&!lb.isAtomic()&&lb.getHasAtomic()) {
872 storeset=delaycomp.livecode(lb);
873 genset=new HashSet<FlatNode>();
874 if (state.STMARRAY&&!state.DUALVIEW) {
875 refset=new HashSet<FlatNode>();
876 refset.addAll(delaycomp.getDeref(lb));
877 refset.removeAll(delaycomp.getCannotDelay(lb));
878 refset.removeAll(delaycomp.getOther(lb));
881 genset.addAll(delaycomp.getCannotDelay(lb));
882 genset.addAll(delaycomp.getOther(lb));
884 genset.addAll(delaycomp.getNotReady(lb));
885 if (state.STMARRAY&&!state.DUALVIEW) {
886 genset.removeAll(refset);
889 unionset=new HashSet<FlatNode>();
890 unionset.addAll(storeset);
891 unionset.addAll(genset);
892 if (state.STMARRAY&&!state.DUALVIEW)
893 unionset.addAll(refset);
896 /* Do the actual code generation */
897 FlatNode current_node=null;
898 HashSet tovisit=new HashSet();
899 HashSet visited=new HashSet();
901 tovisit.add(first.getNext(0));
904 while(current_node!=null||!tovisit.isEmpty()) {
905 if (current_node==null) {
906 current_node=(FlatNode)tovisit.iterator().next();
907 tovisit.remove(current_node);
908 } else if (tovisit.contains(current_node)) {
909 tovisit.remove(current_node);
911 visited.add(current_node);
912 if (nodetolabel.containsKey(current_node)) {
913 output.println("L"+nodetolabel.get(current_node)+":");
915 if (state.INSTRUCTIONFAILURE) {
916 if (state.THREAD||state.DSM||state.SINGLETM) {
917 output.println("if ((++instructioncount)>failurecount) {instructioncount=0;injectinstructionfailure();}");
919 output.println("if ((--instructioncount)==0) injectinstructionfailure();");
921 if (current_node.numNext()==0||stopset!=null&&stopset.contains(current_node)) {
923 if (!state.DELAYCOMP||firstpass) {
924 generateFlatNode(fm, current_node, output);
926 //store primitive variables in out set
927 AtomicRecord ar=atomicmethodmap.get((FlatAtomicEnterNode)first);
928 Set<TempDescriptor> liveout=ar.liveout;
929 for(Iterator<TempDescriptor> tmpit=liveout.iterator(); tmpit.hasNext(); ) {
930 TempDescriptor tmp=tmpit.next();
931 output.println("primitives->"+tmp.getSafeSymbol()+"="+tmp.getSafeSymbol()+";");
935 if (current_node.kind()!=FKind.FlatReturnNode) {
937 // TODO add version for normal Java later
938 if((fm.getMethod() != null) && (fm.getMethod().isStaticBlock())) {
939 // a static block, check if it has been executed
940 output.println(" global_defsprim_p->" + fm.getMethod().getClassDesc().getSafeSymbol()+"static_block_exe_flag = 1;");
944 output.println(" return;");
947 } else if(current_node.numNext()==1) {
949 if (state.DELAYCOMP) {
950 boolean specialprimitive=false;
951 //skip literals...no need to add extra overhead
952 if (storeset!=null&&storeset.contains(current_node)&¤t_node.kind()==FKind.FlatLiteralNode) {
953 TypeDescriptor typedesc=((FlatLiteralNode)current_node).getType();
954 if (!typedesc.isClass()&&!typedesc.isArray()) {
955 specialprimitive=true;
959 if (genset==null||genset.contains(current_node)||specialprimitive) {
960 generateFlatNode(fm, current_node, output);
962 if (state.STMARRAY&&!state.DUALVIEW&&refset!=null&&refset.contains(current_node)) {
963 //need to acquire lock
964 handleArrayDeref(fm, lb, current_node, output, firstpass);
966 if (storeset!=null&&storeset.contains(current_node)&&!specialprimitive) {
967 TempDescriptor wrtmp=current_node.writesTemps()[0];
969 //need to store value written by previous node
970 if (wrtmp.getType().isPtr()) {
971 //only lock the objects that may actually need locking
972 if (recorddc.getNeedTrans(lb, current_node)&&
973 (!state.STMARRAY||state.DUALVIEW||!wrtmp.getType().isArray()||
974 wrtmp.getType().getSymbol().equals(TypeUtil.ObjectClass))) {
975 output.println("STOREPTR("+generateTemp(fm, wrtmp)+");/* "+current_node.nodeid+" */");
977 output.println("STOREPTRNOLOCK("+generateTemp(fm, wrtmp)+");/* "+current_node.nodeid+" */");
980 output.println("STORE"+wrtmp.getType().getSafeDescriptor()+"("+generateTemp(fm, wrtmp)+");/* "+current_node.nodeid+" */");
983 //need to read value read by previous node
984 if (wrtmp.getType().isPtr()) {
985 output.println("RESTOREPTR("+generateTemp(fm, wrtmp)+");/* "+current_node.nodeid+" */");
987 output.println("RESTORE"+wrtmp.getType().getSafeDescriptor()+"("+generateTemp(fm, wrtmp)+"); /* "+current_node.nodeid+" */");
991 nextnode=current_node.getNext(0);
994 generateFlatNode(fm, current_node, output);
995 nextnode=current_node.getNext(0);
997 if (visited.contains(nextnode)) {
998 output.println("goto L"+nodetolabel.get(nextnode)+";");
1001 current_node=nextnode;
1002 } else if (current_node.numNext()==2) {
1004 if (state.DELAYCOMP) {
1005 boolean computeside=false;
1007 //need to record which way it should go
1008 if (genset==null||genset.contains(current_node)) {
1009 if (storeset!=null&&storeset.contains(current_node)) {
1010 //need to store which way branch goes
1011 generateStoreFlatCondBranch(fm, lb, (FlatCondBranch)current_node, "L"+nodetolabel.get(current_node.getNext(1)), output);
1013 generateFlatCondBranch(fm, (FlatCondBranch)current_node, "L"+nodetolabel.get(current_node.getNext(1)), output);
1015 //which side to execute
1019 if (genset.contains(current_node)) {
1020 generateFlatCondBranch(fm, (FlatCondBranch)current_node, "L"+nodetolabel.get(current_node.getNext(1)), output);
1021 } else if (storeset.contains(current_node)) {
1023 branchanalysis.generateGroupCode(current_node, output, nodetolabel);
1025 //which side to execute
1030 Set<FlatNode> leftset=DelayComputation.getNext(current_node, 0, unionset, lb,locality, true);
1032 if (leftset.size()==0)
1034 if (visited.contains(current_node.getNext(branch))) {
1035 //already visited -- build jump
1036 output.println("goto L"+nodetolabel.get(current_node.getNext(branch))+";");
1039 current_node=current_node.getNext(branch);
1042 if (!visited.contains(current_node.getNext(1)))
1043 tovisit.add(current_node.getNext(1));
1044 if (visited.contains(current_node.getNext(0))) {
1045 output.println("goto L"+nodetolabel.get(current_node.getNext(0))+";");
1048 current_node=current_node.getNext(0);
1052 generateFlatCondBranch(fm, (FlatCondBranch)current_node, "L"+nodetolabel.get(current_node.getNext(1)), output);
1053 if (!visited.contains(current_node.getNext(1)))
1054 tovisit.add(current_node.getNext(1));
1055 if (visited.contains(current_node.getNext(0))) {
1056 output.println("goto L"+nodetolabel.get(current_node.getNext(0))+";");
1059 current_node=current_node.getNext(0);
1061 } else throw new Error();
1065 protected void handleArrayDeref(FlatMethod fm, LocalityBinding lb, FlatNode fn, PrintWriter output, boolean firstpass) {
1066 if (fn.kind()==FKind.FlatSetElementNode) {
1067 FlatSetElementNode fsen=(FlatSetElementNode) fn;
1068 String dst=generateTemp(fm, fsen.getDst());
1069 String src=generateTemp(fm, fsen.getSrc());
1070 String index=generateTemp(fm, fsen.getIndex());
1071 TypeDescriptor elementtype=fsen.getDst().getType().dereference();
1073 if (elementtype.isArray()||elementtype.isClass())
1076 type=elementtype.getSafeSymbol()+" ";
1078 output.println("STOREARRAY("+dst+","+index+","+type+")");
1080 output.println("{");
1081 output.println(" struct ArrayObject *array;");
1082 output.println(" int index;");
1083 output.println(" RESTOREARRAY(array,index);");
1084 output.println(" (("+type+"*)(((char *)&array->___length___)+sizeof(int)))[index]="+src+";");
1085 output.println("}");
1087 } else if (fn.kind()==FKind.FlatElementNode) {
1088 FlatElementNode fen=(FlatElementNode) fn;
1089 String src=generateTemp(fm, fen.getSrc());
1090 String index=generateTemp(fm, fen.getIndex());
1091 TypeDescriptor elementtype=fen.getSrc().getType().dereference();
1092 String dst=generateTemp(fm, fen.getDst());
1094 if (elementtype.isArray()||elementtype.isClass())
1097 type=elementtype.getSafeSymbol()+" ";
1099 output.println("STOREARRAY("+src+","+index+","+type+")");
1101 output.println("{");
1102 output.println(" struct ArrayObject *array;");
1103 output.println(" int index;");
1104 output.println(" RESTOREARRAY(array,index);");
1105 output.println(" "+dst+"=(("+type+"*)(((char *)&array->___length___)+sizeof(int)))[index];");
1106 output.println("}");
1110 /** Special label assignment for delaycomputation */
1111 protected Hashtable<FlatNode, Integer> dcassignLabels(FlatNode first, Set<FlatNode> lastset) {
1112 HashSet tovisit=new HashSet();
1113 HashSet visited=new HashSet();
1115 Hashtable<FlatNode, Integer> nodetolabel=new Hashtable<FlatNode, Integer>();
1117 //Label targets of branches
1118 Set<FlatNode> targets=branchanalysis.getTargets();
1119 for(Iterator<FlatNode> it=targets.iterator(); it.hasNext(); ) {
1120 nodetolabel.put(it.next(), new Integer(labelindex++));
1125 /*Assign labels first. A node needs a label if the previous
1126 * node has two exits or this node is a join point. */
1128 while(!tovisit.isEmpty()) {
1129 FlatNode fn=(FlatNode)tovisit.iterator().next();
1134 if(lastset!=null&&lastset.contains(fn)) {
1135 // if last is not null and matches, don't go
1136 // any further for assigning labels
1140 for(int i=0; i<fn.numNext(); i++) {
1141 FlatNode nn=fn.getNext(i);
1144 //1) Edge >1 of node
1145 nodetolabel.put(nn,new Integer(labelindex++));
1147 if (!visited.contains(nn)&&!tovisit.contains(nn)) {
1151 nodetolabel.put(nn,new Integer(labelindex++));
1159 /** Generate text string that corresponds to the TempDescriptor td. */
1160 protected String generateTemp(FlatMethod fm, TempDescriptor td) {
1161 MethodDescriptor md=fm.getMethod();
1162 TaskDescriptor task=fm.getTask();
1163 TempObject objecttemps=(TempObject) tempstable.get(currlb!=null ? currlb : md!=null ? md : task);
1165 if (objecttemps.isLocalPrim(td)||objecttemps.isParamPrim(td)) {
1166 return td.getSafeSymbol();
1169 if (objecttemps.isLocalPtr(td)) {
1170 return localsprefixderef+td.getSafeSymbol();
1173 if (objecttemps.isParamPtr(td)) {
1174 return paramsprefix+"->"+td.getSafeSymbol();
1180 public void generateFlatBackEdge(FlatMethod fm, FlatBackEdge fn, PrintWriter output) {
1181 if (state.SINGLETM&&state.SANDBOX&&(locality.getAtomic(currlb).get(fn).intValue()>0)) {
1182 output.println("if (unlikely((--transaction_check_counter)<=0)) checkObjects();");
1184 if(state.DSM&&state.SANDBOX&&(locality.getAtomic(currlb).get(fn).intValue()>0)) {
1185 output.println("if (unlikely((--transaction_check_counter)<=0)) checkObjects();");
1187 if (((state.THREAD||state.DSM||state.SINGLETM)&&GENERATEPRECISEGC)) {
1188 if(state.DSM&&locality.getAtomic(currlb).get(fn).intValue()>0) {
1189 output.println("if (needtocollect) checkcollect2("+localsprefixaddr+");");
1191 output.println("if (unlikely(needtocollect)) checkcollect("+localsprefixaddr+");");
1194 output.println("/* nop */");
1198 public void generateFlatPrefetchNode(FlatMethod fm, FlatPrefetchNode fpn, PrintWriter output) {
1199 if (state.PREFETCH) {
1200 Vector oids = new Vector();
1201 Vector fieldoffset = new Vector();
1202 Vector endoffset = new Vector();
1203 int tuplecount = 0; //Keeps track of number of prefetch tuples that need to be generated
1204 for(Iterator it = fpn.hspp.iterator(); it.hasNext(); ) {
1205 PrefetchPair pp = (PrefetchPair) it.next();
1206 Integer statusbase = locality.getNodePreTempInfo(currlb,fpn).get(pp.base);
1207 /* Find prefetches that can generate oid */
1208 if(statusbase == LocalityAnalysis.GLOBAL) {
1209 generateTransCode(fm, currlb, pp, oids, fieldoffset, endoffset, tuplecount, locality.getAtomic(currlb).get(fpn).intValue()>0, false);
1211 } else if (statusbase == LocalityAnalysis.LOCAL) {
1212 generateTransCode(fm,currlb,pp,oids,fieldoffset,endoffset,tuplecount,false,true);
1219 System.out.println("Adding prefetch "+fpn+ " to method:" +fm);
1220 output.println("{");
1221 output.println("/* prefetch */");
1222 output.println("/* prefetchid_" + fpn.siteid + " */");
1223 output.println("void * prefptr;");
1224 output.println("int tmpindex;");
1226 output.println("if((evalPrefetch["+fpn.siteid+"].operMode) || (evalPrefetch["+fpn.siteid+"].retrycount <= 0)) {");
1227 /*Create C code for oid array */
1228 output.print(" unsigned int oidarray_[] = {");
1229 boolean needcomma=false;
1230 for (Iterator it = oids.iterator(); it.hasNext(); ) {
1233 output.print(it.next());
1236 output.println("};");
1238 /*Create C code for endoffset values */
1239 output.print(" unsigned short endoffsetarry_[] = {");
1241 for (Iterator it = endoffset.iterator(); it.hasNext(); ) {
1244 output.print(it.next());
1247 output.println("};");
1249 /*Create C code for Field Offset Values */
1250 output.print(" short fieldarry_[] = {");
1252 for (Iterator it = fieldoffset.iterator(); it.hasNext(); ) {
1255 output.print(it.next());
1258 output.println("};");
1259 /* make the prefetch call to Runtime */
1260 output.println(" if(!evalPrefetch["+fpn.siteid+"].operMode) {");
1261 output.println(" evalPrefetch["+fpn.siteid+"].retrycount = RETRYINTERVAL;");
1262 output.println(" }");
1263 output.println(" prefetch("+fpn.siteid+" ,"+tuplecount+", oidarray_, endoffsetarry_, fieldarry_);");
1264 output.println(" } else {");
1265 output.println(" evalPrefetch["+fpn.siteid+"].retrycount--;");
1266 output.println(" }");
1267 output.println("}");
1271 public void generateTransCode(FlatMethod fm, LocalityBinding lb,PrefetchPair pp, Vector oids, Vector fieldoffset, Vector endoffset, int tuplecount, boolean inside, boolean localbase) {
1272 short offsetcount = 0;
1276 } else if (localbase) {
1277 for(; breakindex<pp.desc.size(); breakindex++) {
1278 Descriptor desc=pp.getDescAt(breakindex);
1279 if (desc instanceof FieldDescriptor) {
1280 FieldDescriptor fd=(FieldDescriptor)desc;
1281 if (fd.isGlobal()) {
1289 if (breakindex>pp.desc.size()) //all local
1292 TypeDescriptor lasttype=pp.base.getType();
1293 String basestr=generateTemp(fm, pp.base);
1295 boolean maybenull=fm.getMethod().isStatic()||
1296 !pp.base.equals(fm.getParameter(0));
1298 for(int i=0; i<breakindex; i++) {
1299 String indexcheck="";
1301 Descriptor desc=pp.getDescAt(i);
1302 if (desc instanceof FieldDescriptor) {
1303 FieldDescriptor fd=(FieldDescriptor)desc;
1305 if (!teststr.equals(""))
1307 teststr+="((prefptr="+basestr+")!=NULL)";
1308 basestr="((struct "+lasttype.getSafeSymbol()+" *)prefptr)->"+
1311 basestr=basestr+"->"+
1315 lasttype=fd.getType();
1317 IndexDescriptor id=(IndexDescriptor)desc;
1318 indexcheck="((tmpindex=";
1319 for(int j=0; j<id.tddesc.size(); j++) {
1320 indexcheck+=generateTemp(fm, id.getTempDescAt(j))+"+";
1322 indexcheck+=id.offset+")>=0)&(tmpindex<((struct ArrayObject *)prefptr)->___length___)";
1324 if (!teststr.equals(""))
1326 teststr+="((prefptr="+basestr+")!= NULL) &&"+indexcheck;
1327 basestr="((void **)(((char *) &(((struct ArrayObject *)prefptr)->___length___))+sizeof(int)))[tmpindex]";
1329 lasttype=lasttype.dereference();
1334 if (teststr.equals("")) {
1335 oid="((unsigned int)"+basestr+")";
1337 oid="((unsigned int)(("+teststr+")?"+basestr+":NULL))";
1341 for(int i = breakindex; i < pp.desc.size(); i++) {
1342 String newfieldoffset;
1343 Object desc = pp.getDescAt(i);
1344 if(desc instanceof FieldDescriptor) {
1345 FieldDescriptor fd=(FieldDescriptor)desc;
1346 newfieldoffset = new String("(unsigned int)(&(((struct "+ lasttype.getSafeSymbol()+" *)0)->"+ fd.getSafeSymbol()+ "))");
1347 lasttype=fd.getType();
1349 newfieldoffset = "";
1350 IndexDescriptor id=(IndexDescriptor)desc;
1351 for(int j = 0; j < id.tddesc.size(); j++) {
1352 newfieldoffset += generateTemp(fm, id.getTempDescAt(j)) + "+";
1354 newfieldoffset += id.offset.toString();
1355 lasttype=lasttype.dereference();
1357 fieldoffset.add(newfieldoffset);
1360 int base=(tuplecount>0) ? ((Short)endoffset.get(tuplecount-1)).intValue() : 0;
1361 base+=pp.desc.size()-breakindex;
1362 endoffset.add(new Short((short)base));
1367 public void generateFlatGlobalConvNode(FlatMethod fm, FlatGlobalConvNode fgcn, PrintWriter output) {
1368 if (currlb!=fgcn.getLocality())
1370 /* Have to generate flat globalconv */
1371 if (fgcn.getMakePtr()) {
1373 output.println("TRANSREAD("+generateTemp(fm, fgcn.getSrc())+", (unsigned int) "+generateTemp(fm, fgcn.getSrc())+");");
1375 if ((dc==null)||!state.READSET&&dc.getNeedTrans(currlb, fgcn)||state.READSET&&dc.getNeedWriteTrans(currlb, fgcn)) {
1376 //need to do translation
1377 output.println("TRANSREAD("+generateTemp(fm, fgcn.getSrc())+", "+generateTemp(fm, fgcn.getSrc())+", (void *)("+localsprefixaddr+"));");
1378 } else if (state.READSET&&dc.getNeedTrans(currlb, fgcn)) {
1379 if (state.HYBRID&&delaycomp.getConv(currlb).contains(fgcn)) {
1380 output.println("TRANSREADRDFISSION("+generateTemp(fm, fgcn.getSrc())+", "+generateTemp(fm, fgcn.getSrc())+");");
1382 output.println("TRANSREADRD("+generateTemp(fm, fgcn.getSrc())+", "+generateTemp(fm, fgcn.getSrc())+");");
1386 /* Need to convert to OID */
1387 if ((dc==null)||dc.getNeedSrcTrans(currlb,fgcn)) {
1388 if (fgcn.doConvert()||(delaycomp!=null&&delaycomp.needsFission(currlb, fgcn.getAtomicEnter())&&atomicmethodmap.get(fgcn.getAtomicEnter()).reallivein.contains(fgcn.getSrc()))) {
1389 output.println(generateTemp(fm, fgcn.getSrc())+"=(void *)COMPOID("+generateTemp(fm, fgcn.getSrc())+");");
1391 output.println(generateTemp(fm, fgcn.getSrc())+"=NULL;");
1397 int sandboxcounter=0;
1398 public void generateFlatAtomicEnterNode(FlatMethod fm, FlatAtomicEnterNode faen, PrintWriter output) {
1399 /* Check to see if we need to generate code for this atomic */
1400 if (locality==null) {
1401 if (GENERATEPRECISEGC) {
1402 output.println("if (pthread_mutex_trylock(&atomiclock)!=0) {");
1403 output.println("stopforgc((struct garbagelist *) &___locals___);");
1404 output.println("pthread_mutex_lock(&atomiclock);");
1405 output.println("restartaftergc();");
1406 output.println("}");
1408 output.println("pthread_mutex_lock(&atomiclock);");
1413 if (locality.getAtomic(currlb).get(faen.getPrev(0)).intValue()>0)
1417 if (state.SANDBOX) {
1418 outsandbox.println("int atomiccounter"+sandboxcounter+"=LOW_CHECK_FREQUENCY;");
1419 output.println("counter_reset_pointer=&atomiccounter"+sandboxcounter+";");
1422 if (state.DELAYCOMP&&delaycomp.needsFission(currlb, faen)) {
1423 AtomicRecord ar=atomicmethodmap.get(faen);
1425 for(Iterator<TempDescriptor> tmpit=ar.livein.iterator(); tmpit.hasNext(); ) {
1426 TempDescriptor tmp=tmpit.next();
1427 output.println("primitives_"+ar.name+"."+tmp.getSafeSymbol()+"="+tmp.getSafeSymbol()+";");
1430 //copy outs that depend on path
1431 for(Iterator<TempDescriptor> tmpit=ar.liveoutvirtualread.iterator(); tmpit.hasNext(); ) {
1432 TempDescriptor tmp=tmpit.next();
1433 if (!ar.livein.contains(tmp))
1434 output.println("primitives_"+ar.name+"."+tmp.getSafeSymbol()+"="+tmp.getSafeSymbol()+";");
1438 /* Backup the temps. */
1439 for(Iterator<TempDescriptor> tmpit=locality.getTemps(currlb).get(faen).iterator(); tmpit.hasNext(); ) {
1440 TempDescriptor tmp=tmpit.next();
1441 output.println(generateTemp(fm, backuptable.get(currlb).get(tmp))+"="+generateTemp(fm,tmp)+";");
1444 output.println("goto transstart"+faen.getIdentifier()+";");
1446 /******* Print code to retry aborted transaction *******/
1447 output.println("transretry"+faen.getIdentifier()+":");
1450 for(Iterator<TempDescriptor> tmpit=locality.getTemps(currlb).get(faen).iterator(); tmpit.hasNext(); ) {
1451 TempDescriptor tmp=tmpit.next();
1452 output.println(generateTemp(fm, tmp)+"="+generateTemp(fm,backuptable.get(currlb).get(tmp))+";");
1456 /********* Need to revert local object store ********/
1457 String revertptr=generateTemp(fm, reverttable.get(currlb));
1459 output.println("while ("+revertptr+") {");
1460 output.println("struct ___Object___ * tmpptr;");
1461 output.println("tmpptr="+revertptr+"->"+nextobjstr+";");
1462 output.println("REVERT_OBJ("+revertptr+");");
1463 output.println(revertptr+"=tmpptr;");
1464 output.println("}");
1466 /******* Tell the runtime to start the transaction *******/
1468 output.println("transstart"+faen.getIdentifier()+":");
1469 if (state.SANDBOX) {
1470 output.println("transaction_check_counter=*counter_reset_pointer;");
1473 output.println("transStart();");
1475 if (state.ABORTREADERS||state.SANDBOX) {
1477 output.println("abortenabled=1;");
1478 output.println("if (_setjmp(aborttrans)) {");
1479 output.println(" goto transretry"+faen.getIdentifier()+"; }");
1483 public void generateFlatAtomicExitNode(FlatMethod fm, FlatAtomicExitNode faen, PrintWriter output) {
1484 /* Check to see if we need to generate code for this atomic */
1485 if (locality==null) {
1486 output.println("pthread_mutex_unlock(&atomiclock);");
1489 if (locality.getAtomic(currlb).get(faen).intValue()>0)
1491 //store the revert list before we lose the transaction object
1494 String revertptr=generateTemp(fm, reverttable.get(currlb));
1495 output.println(revertptr+"=revertlist;");
1496 output.println("if (transCommit()) {");
1497 output.println("if (unlikely(needtocollect)) checkcollect("+localsprefixaddr+");");
1498 output.println("goto transretry"+faen.getAtomicEnter().getIdentifier()+";");
1499 output.println("} else {");
1500 /* Need to commit local object store */
1501 output.println("while ("+revertptr+") {");
1502 output.println("struct ___Object___ * tmpptr;");
1503 output.println("tmpptr="+revertptr+"->"+nextobjstr+";");
1504 output.println("COMMIT_OBJ("+revertptr+");");
1505 output.println(revertptr+"=tmpptr;");
1506 output.println("}");
1507 output.println("}");
1511 if (!state.DELAYCOMP) {
1513 output.println("if (transCommit()) {");
1514 /* Transaction aborts if it returns true */
1515 output.println("if (unlikely(needtocollect)) checkcollect("+localsprefixaddr+");");
1516 output.println("goto transretry"+faen.getAtomicEnter().getIdentifier()+";");
1517 output.println("}");
1519 if (delaycomp.optimizeTrans(currlb, faen.getAtomicEnter())&&(!state.STMARRAY||state.DUALVIEW)) {
1520 AtomicRecord ar=atomicmethodmap.get(faen.getAtomicEnter());
1521 output.println("LIGHTWEIGHTCOMMIT("+ar.name+", &primitives_"+ar.name+", &"+localsprefix+", "+paramsprefix+", transretry"+faen.getAtomicEnter().getIdentifier()+");");
1523 for(Iterator<TempDescriptor> tmpit=ar.liveout.iterator(); tmpit.hasNext(); ) {
1524 TempDescriptor tmp=tmpit.next();
1525 output.println(tmp.getSafeSymbol()+"=primitives_"+ar.name+"."+tmp.getSafeSymbol()+";");
1527 } else if (delaycomp.needsFission(currlb, faen.getAtomicEnter())) {
1528 AtomicRecord ar=atomicmethodmap.get(faen.getAtomicEnter());
1530 output.println("if (transCommit((void (*)(void *, void *, void *))&"+ar.name+", &primitives_"+ar.name+", &"+localsprefix+", "+paramsprefix+")) {");
1531 output.println("if (unlikely(needtocollect)) checkcollect("+localsprefixaddr+");");
1532 output.println("goto transretry"+faen.getAtomicEnter().getIdentifier()+";");
1533 output.println("}");
1535 output.println("else {");
1536 for(Iterator<TempDescriptor> tmpit=ar.liveout.iterator(); tmpit.hasNext(); ) {
1537 TempDescriptor tmp=tmpit.next();
1538 output.println(tmp.getSafeSymbol()+"=primitives_"+ar.name+"."+tmp.getSafeSymbol()+";");
1540 output.println("}");
1542 output.println("if (transCommit(NULL, NULL, NULL, NULL)) {");
1543 output.println("if (unlikely(needtocollect)) checkcollect("+localsprefixaddr+");");
1544 output.println("goto transretry"+faen.getAtomicEnter().getIdentifier()+";");
1545 output.println("}");
1550 protected void generateFlatCall(FlatMethod fm, FlatCall fc, PrintWriter output) {
1551 MethodDescriptor md=fc.getMethod();
1552 ParamsObject objectparams=(ParamsObject)paramstable.get(currlb!=null ? locality.getBinding(currlb, fc) : md);
1553 ClassDescriptor cn=md.getClassDesc();
1555 // if the called method is a static block or a static method or a constructor
1556 // need to check if it can be invoked inside some static block
1558 // TODO add version for normal Java later
1559 if((md.isStatic() || md.isStaticBlock() || md.isConstructor()) &&
1560 ((fm.getMethod().isStaticBlock()) || (fm.getMethod().isInvokedByStatic()))) {
1561 if(!md.isInvokedByStatic()) {
1562 System.err.println("Error: a method that is invoked inside a static block is not tagged!");
1564 // is a static block or is invoked in some static block
1565 ClassDescriptor cd = fm.getMethod().getClassDesc();
1567 // the same class, do nothing
1568 // TODO may want to invoke static field initialization here
1570 if((cn.getNumStaticFields() != 0) || (cn.getNumStaticBlocks() != 0)) {
1571 // need to check if the class' static fields have been initialized and/or
1572 // its static blocks have been executed
1573 output.println("#ifdef MGC_STATIC_INIT_CHECK");
1574 output.println("if(global_defsprim_p->" + cn.getSafeSymbol()+"static_block_exe_flag == 0) {");
1575 if(cn.getNumStaticBlocks() != 0) {
1576 MethodDescriptor t_md = (MethodDescriptor)cn.getMethodTable().get("staticblocks");
1577 output.println(" "+cn.getSafeSymbol()+t_md.getSafeSymbol()+"_"+t_md.getSafeMethodDescriptor()+"();");
1579 output.println(" global_defsprim_p->" + cn.getSafeSymbol()+"static_block_exe_flag = 1;");
1581 output.println("}");
1582 output.println("#endif // MGC_STATIC_INIT_CHECK");
1586 if((md.getSymbol().equals("MonitorEnter") || md.getSymbol().equals("MonitorExit")) && fc.getThis().getSymbol().equals("classobj")) {
1587 // call MonitorEnter/MonitorExit on a class obj
1588 output.println(" " + cn.getSafeSymbol()+md.getSafeSymbol()+"_"
1589 +md.getSafeMethodDescriptor() + "((struct ___Object___*)(&global_defs_p->"
1590 + fc.getThis().getType().getClassDesc().getSafeSymbol() +"classobj));");
1595 output.println("{");
1596 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
1598 LocalityBinding fclb=locality.getBinding(currlb, fc);
1599 output.print(" struct "+cn.getSafeSymbol()+fclb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={");
1601 output.print(" struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={");
1602 output.print(objectparams.numPointers());
1603 output.print(", "+localsprefixaddr);
1604 if (md.getThis()!=null) {
1606 output.print("(struct "+md.getThis().getType().getSafeSymbol() +" *)"+ generateTemp(fm,fc.getThis()));
1608 if (fc.getThis()!=null&&md.getThis()==null) {
1609 System.out.println("WARNING!!!!!!!!!!!!");
1610 System.out.println("Source code calls static method "+md+" on an object in "+fm.getMethod()+"!");
1614 for(int i=0; i<fc.numArgs(); i++) {
1615 Descriptor var=md.getParameter(i);
1616 TempDescriptor paramtemp=(TempDescriptor)temptovar.get(var);
1617 if (objectparams.isParamPtr(paramtemp)) {
1618 TempDescriptor targ=fc.getArg(i);
1620 TypeDescriptor td=md.getParamType(i);
1622 output.print("(struct "+(new TypeDescriptor(typeutil.getClass(TypeUtil.TagClass))).getSafeSymbol() +" *)"+generateTemp(fm, targ));
1624 output.print("(struct "+md.getParamType(i).getSafeSymbol() +" *)"+generateTemp(fm, targ));
1627 output.println("};");
1632 if (fc.getReturnTemp()!=null)
1633 output.print(generateTemp(fm,fc.getReturnTemp())+"=");
1635 /* Do we need to do virtual dispatch? */
1636 if (md.isStatic()||md.getReturnType()==null||singleCall(fc.getThis().getType().getClassDesc(),md)) {
1639 LocalityBinding fclb=locality.getBinding(currlb, fc);
1640 output.print(cn.getSafeSymbol()+fclb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor());
1642 output.print(cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor());
1647 if (state.MGC && md.getReturnType().isClass() && md.getReturnType().getClassDesc().isEnum()) {
1648 output.print("int ");
1649 } else if (md.getReturnType().isClass()||md.getReturnType().isArray())
1650 output.print("struct " + md.getReturnType().getSafeSymbol()+" * ");
1652 output.print(md.getReturnType().getSafeSymbol()+" ");
1653 output.print("(*)(");
1655 boolean printcomma=false;
1656 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
1658 LocalityBinding fclb=locality.getBinding(currlb, fc);
1659 output.print("struct "+cn.getSafeSymbol()+fclb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params * ");
1661 output.print("struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params * ");
1665 for(int i=0; i<objectparams.numPrimitives(); i++) {
1666 TempDescriptor temp=objectparams.getPrimitive(i);
1670 if (state.MGC && temp.getType().isClass() && temp.getType().getClassDesc().isEnum()) {
1671 output.print("int ");
1672 } else if (temp.getType().isClass()||temp.getType().isArray())
1673 output.print("struct " + temp.getType().getSafeSymbol()+" * ");
1675 output.print(temp.getType().getSafeSymbol());
1680 LocalityBinding fclb=locality.getBinding(currlb, fc);
1681 output.print("))virtualtable["+generateTemp(fm,fc.getThis())+"->type*"+maxcount+"+"+virtualcalls.getLocalityNumber(fclb)+"])");
1683 output.print("))virtualtable["+generateTemp(fm,fc.getThis())+"->type*"+maxcount+"+"+virtualcalls.getMethodNumber(md)+"])");
1687 boolean needcomma=false;
1688 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
1689 output.print("&__parameterlist__");
1693 if (!GENERATEPRECISEGC && !this.state.MULTICOREGC) {
1694 if (fc.getThis()!=null) {
1695 TypeDescriptor ptd=null;
1696 if(md.getThis() != null) {
1697 ptd = md.getThis().getType();
1699 ptd = fc.getThis().getType();
1703 if(state.MGC && ptd.isClass() && ptd.getClassDesc().isEnum()) {
1705 } else if (ptd.isClass()&&!ptd.isArray())
1706 output.print("(struct "+ptd.getSafeSymbol()+" *) ");
1707 output.print(generateTemp(fm,fc.getThis()));
1712 for(int i=0; i<fc.numArgs(); i++) {
1713 Descriptor var=md.getParameter(i);
1714 TempDescriptor paramtemp=(TempDescriptor)temptovar.get(var);
1715 if (objectparams.isParamPrim(paramtemp)) {
1716 TempDescriptor targ=fc.getArg(i);
1720 TypeDescriptor ptd=md.getParamType(i);
1721 if (state.MGC && ptd.isClass() && ptd.getClassDesc().isEnum()) {
1723 } else if (ptd.isClass()&&!ptd.isArray())
1724 output.print("(struct "+ptd.getSafeSymbol()+" *) ");
1725 output.print(generateTemp(fm, targ));
1729 output.println(");");
1730 output.println(" }");
1734 protected void generateFlatFieldNode(FlatMethod fm, FlatFieldNode ffn, PrintWriter output) {
1735 if (state.SINGLETM) {
1736 //single machine transactional memory case
1737 String field=ffn.getField().getSafeSymbol();
1738 String src=generateTemp(fm, ffn.getSrc());
1739 String dst=generateTemp(fm, ffn.getDst());
1741 output.println(dst+"="+ src +"->"+field+ ";");
1742 if (ffn.getField().getType().isPtr()&&locality.getAtomic(currlb).get(ffn).intValue()>0&&
1743 locality.getNodePreTempInfo(currlb, ffn).get(ffn.getSrc())!=LocalityAnalysis.SCRATCH) {
1744 if ((dc==null)||(!state.READSET&&dc.getNeedTrans(currlb, ffn))||
1745 (state.READSET&&dc.getNeedWriteTrans(currlb, ffn))) {
1746 output.println("TRANSREAD("+dst+", "+dst+", (void *) (" + localsprefixaddr + "));");
1747 } else if (state.READSET&&dc.getNeedTrans(currlb, ffn)) {
1748 if (state.HYBRID&&delaycomp.getConv(currlb).contains(ffn)) {
1749 output.println("TRANSREADRDFISSION("+dst+", "+dst+");");
1751 output.println("TRANSREADRD("+dst+", "+dst+");");
1754 } else if (state.DSM) {
1755 Integer status=locality.getNodePreTempInfo(currlb,ffn).get(ffn.getSrc());
1756 if (status==LocalityAnalysis.GLOBAL) {
1757 String field=ffn.getField().getSafeSymbol();
1758 String src=generateTemp(fm, ffn.getSrc());
1759 String dst=generateTemp(fm, ffn.getDst());
1761 if (ffn.getField().getType().isPtr()) {
1762 output.println(dst+"="+ src +"->"+field+ ";");
1763 output.println("TRANSREAD("+dst+", (unsigned int) "+dst+");");
1765 output.println(dst+"="+ src+"->"+field+";");
1767 } else if (status==LocalityAnalysis.LOCAL) {
1768 if (ffn.getField().getType().isPtr()&&
1769 ffn.getField().isGlobal()) {
1770 String field=ffn.getField().getSafeSymbol();
1771 String src=generateTemp(fm, ffn.getSrc());
1772 String dst=generateTemp(fm, ffn.getDst());
1773 output.println(dst+"="+ src +"->"+field+ ";");
1774 if (locality.getAtomic(currlb).get(ffn).intValue()>0)
1775 output.println("TRANSREAD("+dst+", (unsigned int) "+dst+");");
1777 output.println(generateTemp(fm, ffn.getDst())+"="+ generateTemp(fm,ffn.getSrc())+"->"+ ffn.getField().getSafeSymbol()+";");
1778 } else if (status==LocalityAnalysis.EITHER) {
1779 //Code is reading from a null pointer
1780 output.println("if ("+generateTemp(fm, ffn.getSrc())+") {");
1781 output.println("#ifndef RAW");
1782 output.println("printf(\"BIG ERROR\\n\");exit(-1);}");
1783 output.println("#endif");
1784 //This should throw a suitable null pointer error
1785 output.println(generateTemp(fm, ffn.getDst())+"="+ generateTemp(fm,ffn.getSrc())+"->"+ ffn.getField().getSafeSymbol()+";");
1787 throw new Error("Read from non-global/non-local in:"+currlb.getExplanation());
1791 protected void generateFlatSetFieldNode(FlatMethod fm, FlatSetFieldNode fsfn, PrintWriter output) {
1792 if (fsfn.getField().getSymbol().equals("length")&&fsfn.getDst().getType().isArray())
1793 throw new Error("Can't set array length");
1794 if (state.SINGLETM && locality.getAtomic(currlb).get(fsfn).intValue()>0) {
1795 //Single Machine Transaction Case
1796 boolean srcptr=fsfn.getSrc().getType().isPtr();
1797 String src=generateTemp(fm,fsfn.getSrc());
1798 String dst=generateTemp(fm,fsfn.getDst());
1799 output.println("//"+srcptr+" "+fsfn.getSrc().getType().isNull());
1800 if (srcptr&&!fsfn.getSrc().getType().isNull()) {
1801 output.println("{");
1802 if ((dc==null)||dc.getNeedSrcTrans(currlb, fsfn)&&
1803 locality.getNodePreTempInfo(currlb, fsfn).get(fsfn.getSrc())!=LocalityAnalysis.SCRATCH) {
1804 output.println("INTPTR srcoid=("+src+"!=NULL?((INTPTR)"+src+"->"+oidstr+"):0);");
1806 output.println("INTPTR srcoid=(INTPTR)"+src+";");
1809 if (wb.needBarrier(fsfn)&&
1810 locality.getNodePreTempInfo(currlb, fsfn).get(fsfn.getDst())!=LocalityAnalysis.SCRATCH) {
1811 if (state.EVENTMONITOR) {
1812 output.println("if ("+dst+"->___objstatus___&DIRTY) EVLOGEVENTOBJ(EV_WRITE,"+dst+"->objuid)");
1814 output.println("*((unsigned int *)&("+dst+"->___objstatus___))|=DIRTY;");
1816 if (srcptr&!fsfn.getSrc().getType().isNull()) {
1817 output.println("*((unsigned INTPTR *)&("+dst+"->"+
1818 fsfn.getField().getSafeSymbol()+"))=srcoid;");
1819 output.println("}");
1821 output.println(dst+"->"+
1822 fsfn.getField().getSafeSymbol()+"="+ src+";");
1824 } else if (state.DSM && locality.getAtomic(currlb).get(fsfn).intValue()>0) {
1825 Integer statussrc=locality.getNodePreTempInfo(currlb,fsfn).get(fsfn.getSrc());
1826 Integer statusdst=locality.getNodeTempInfo(currlb).get(fsfn).get(fsfn.getDst());
1827 boolean srcglobal=statussrc==LocalityAnalysis.GLOBAL;
1829 String src=generateTemp(fm,fsfn.getSrc());
1830 String dst=generateTemp(fm,fsfn.getDst());
1832 output.println("{");
1833 output.println("INTPTR srcoid=("+src+"!=NULL?((INTPTR)"+src+"->"+oidstr+"):0);");
1835 if (statusdst.equals(LocalityAnalysis.GLOBAL)) {
1838 if (wb.needBarrier(fsfn))
1839 output.println("*((unsigned int *)&("+dst+"->___localcopy___))|=DIRTY;");
1841 output.println("*((unsigned INTPTR *)&("+glbdst+"->"+
1842 fsfn.getField().getSafeSymbol()+"))=srcoid;");
1844 output.println(glbdst+"->"+
1845 fsfn.getField().getSafeSymbol()+"="+ src+";");
1846 } else if (statusdst.equals(LocalityAnalysis.LOCAL)) {
1847 /** Check if we need to copy */
1848 output.println("if(!"+dst+"->"+localcopystr+") {");
1849 /* Link object into list */
1850 String revertptr=generateTemp(fm, reverttable.get(currlb));
1851 output.println(revertptr+"=revertlist;");
1852 if (GENERATEPRECISEGC || this.state.MULTICOREGC)
1853 output.println("COPY_OBJ((struct garbagelist *)"+localsprefixaddr+",(struct ___Object___ *)"+dst+");");
1855 output.println("COPY_OBJ("+dst+");");
1856 output.println(dst+"->"+nextobjstr+"="+revertptr+";");
1857 output.println("revertlist=(struct ___Object___ *)"+dst+";");
1858 output.println("}");
1860 output.println(dst+"->"+
1861 fsfn.getField().getSafeSymbol()+"=(void *) srcoid;");
1863 output.println(dst+"->"+
1864 fsfn.getField().getSafeSymbol()+"="+ src+";");
1865 } else if (statusdst.equals(LocalityAnalysis.EITHER)) {
1866 //writing to a null...bad
1867 output.println("if ("+dst+") {");
1868 output.println("printf(\"BIG ERROR 2\\n\");exit(-1);}");
1870 output.println(dst+"->"+
1871 fsfn.getField().getSafeSymbol()+"=(void *) srcoid;");
1873 output.println(dst+"->"+
1874 fsfn.getField().getSafeSymbol()+"="+ src+";");
1877 output.println("}");
1882 protected void generateFlatElementNode(FlatMethod fm, FlatElementNode fen, PrintWriter output) {
1883 TypeDescriptor elementtype=fen.getSrc().getType().dereference();
1886 if (state.MGC && elementtype.isClass() && elementtype.getClassDesc().isEnum()) {
1888 } else if (elementtype.isArray()||elementtype.isClass())
1891 type=elementtype.getSafeSymbol()+" ";
1893 if (this.state.ARRAYBOUNDARYCHECK && fen.needsBoundsCheck()) {
1894 output.println("if (unlikely(((unsigned int)"+generateTemp(fm, fen.getIndex())+") >= "+generateTemp(fm,fen.getSrc()) + "->___length___))");
1895 output.println("failedboundschk();");
1897 if (state.SINGLETM) {
1898 //Single machine transaction case
1899 String dst=generateTemp(fm, fen.getDst());
1900 if ((!state.STMARRAY)||(!wb.needBarrier(fen))||locality.getNodePreTempInfo(currlb, fen).get(fen.getSrc())==LocalityAnalysis.SCRATCH||locality.getAtomic(currlb).get(fen).intValue()==0||(state.READSET&&!dc.getNeedGet(currlb, fen))) {
1901 output.println(dst +"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc())+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex())+"];");
1903 output.println("STMGETARRAY("+dst+", "+ generateTemp(fm,fen.getSrc())+", "+generateTemp(fm, fen.getIndex())+", "+type+");");
1906 if (elementtype.isPtr()&&locality.getAtomic(currlb).get(fen).intValue()>0&&
1907 locality.getNodePreTempInfo(currlb, fen).get(fen.getSrc())!=LocalityAnalysis.SCRATCH) {
1908 if ((dc==null)||!state.READSET&&dc.getNeedTrans(currlb, fen)||state.READSET&&dc.getNeedWriteTrans(currlb, fen)) {
1909 output.println("TRANSREAD("+dst+", "+dst+", (void *)(" + localsprefixaddr+"));");
1910 } else if (state.READSET&&dc.getNeedTrans(currlb, fen)) {
1911 if (state.HYBRID&&delaycomp.getConv(currlb).contains(fen)) {
1912 output.println("TRANSREADRDFISSION("+dst+", "+dst+");");
1914 output.println("TRANSREADRD("+dst+", "+dst+");");
1917 } else if (state.DSM) {
1918 Integer status=locality.getNodePreTempInfo(currlb,fen).get(fen.getSrc());
1919 if (status==LocalityAnalysis.GLOBAL) {
1920 String dst=generateTemp(fm, fen.getDst());
1921 if (elementtype.isPtr()) {
1922 output.println(dst +"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc())+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex())+"];");
1923 output.println("TRANSREAD("+dst+", "+dst+");");
1925 output.println(dst +"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc())+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex())+"];");
1927 } else if (status==LocalityAnalysis.LOCAL) {
1928 output.println(generateTemp(fm, fen.getDst())+"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc())+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex())+"];");
1929 } else if (status==LocalityAnalysis.EITHER) {
1930 //Code is reading from a null pointer
1931 output.println("if ("+generateTemp(fm, fen.getSrc())+") {");
1932 output.println("#ifndef RAW");
1933 output.println("printf(\"BIG ERROR\\n\");exit(-1);}");
1934 output.println("#endif");
1935 //This should throw a suitable null pointer error
1936 output.println(generateTemp(fm, fen.getDst())+"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc())+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex())+"];");
1938 throw new Error("Read from non-global/non-local in:"+currlb.getExplanation());
1942 protected void generateFlatSetElementNode(FlatMethod fm, FlatSetElementNode fsen, PrintWriter output) {
1943 //TODO: need dynamic check to make sure this assignment is actually legal
1944 //Because Object[] could actually be something more specific...ie. Integer[]
1946 TypeDescriptor elementtype=fsen.getDst().getType().dereference();
1949 if (state.MGC && elementtype.isClass() && elementtype.getClassDesc().isEnum()) {
1951 } else if (elementtype.isArray()||elementtype.isClass() || (state.MGC && elementtype.isNull()))
1954 type=elementtype.getSafeSymbol()+" ";
1956 if (this.state.ARRAYBOUNDARYCHECK && fsen.needsBoundsCheck()) {
1957 output.println("if (unlikely(((unsigned int)"+generateTemp(fm, fsen.getIndex())+") >= "+generateTemp(fm,fsen.getDst()) + "->___length___))");
1958 output.println("failedboundschk();");
1961 if (state.SINGLETM && locality.getAtomic(currlb).get(fsen).intValue()>0) {
1962 //Transaction set element case
1963 if (wb.needBarrier(fsen)&&
1964 locality.getNodePreTempInfo(currlb, fsen).get(fsen.getDst())!=LocalityAnalysis.SCRATCH) {
1965 output.println("*((unsigned int *)&("+generateTemp(fm,fsen.getDst())+"->___objstatus___))|=DIRTY;");
1967 if (fsen.getSrc().getType().isPtr()&&!fsen.getSrc().getType().isNull()) {
1968 output.println("{");
1969 String src=generateTemp(fm, fsen.getSrc());
1970 if ((dc==null)||dc.getNeedSrcTrans(currlb, fsen)&&
1971 locality.getNodePreTempInfo(currlb, fsen).get(fsen.getSrc())!=LocalityAnalysis.SCRATCH) {
1972 output.println("INTPTR srcoid=("+src+"!=NULL?((INTPTR)"+src+"->"+oidstr+"):0);");
1974 output.println("INTPTR srcoid=(INTPTR)"+src+";");
1976 if (state.STMARRAY&&locality.getNodePreTempInfo(currlb, fsen).get(fsen.getDst())!=LocalityAnalysis.SCRATCH&&wb.needBarrier(fsen)&&locality.getAtomic(currlb).get(fsen).intValue()>0) {
1977 output.println("STMSETARRAY("+generateTemp(fm, fsen.getDst())+", "+generateTemp(fm, fsen.getIndex())+", srcoid, INTPTR);");
1979 output.println("((INTPTR*)(((char *) &("+ generateTemp(fm,fsen.getDst())+"->___length___))+sizeof(int)))["+generateTemp(fm, fsen.getIndex())+"]=srcoid;");
1981 output.println("}");
1983 if (state.STMARRAY&&locality.getNodePreTempInfo(currlb, fsen).get(fsen.getDst())!=LocalityAnalysis.SCRATCH&&wb.needBarrier(fsen)&&locality.getAtomic(currlb).get(fsen).intValue()>0) {
1984 output.println("STMSETARRAY("+generateTemp(fm, fsen.getDst())+", "+generateTemp(fm, fsen.getIndex())+", "+ generateTemp(fm, fsen.getSrc()) +", "+type+");");
1986 output.println("(("+type +"*)(((char *) &("+ generateTemp(fm,fsen.getDst())+"->___length___))+sizeof(int)))["+generateTemp(fm, fsen.getIndex())+"]="+generateTemp(fm,fsen.getSrc())+";");
1989 } else if (state.DSM && locality.getAtomic(currlb).get(fsen).intValue()>0) {
1990 Integer statussrc=locality.getNodePreTempInfo(currlb,fsen).get(fsen.getSrc());
1991 Integer statusdst=locality.getNodePreTempInfo(currlb,fsen).get(fsen.getDst());
1992 boolean srcglobal=statussrc==LocalityAnalysis.GLOBAL;
1993 boolean dstglobal=statusdst==LocalityAnalysis.GLOBAL;
1994 boolean dstlocal=(statusdst==LocalityAnalysis.LOCAL)||(statusdst==LocalityAnalysis.EITHER);
1997 if (wb.needBarrier(fsen))
1998 output.println("*((unsigned int *)&("+generateTemp(fm,fsen.getDst())+"->___localcopy___))|=DIRTY;");
1999 } else if (dstlocal) {
2000 /** Check if we need to copy */
2001 String dst=generateTemp(fm, fsen.getDst());
2002 output.println("if(!"+dst+"->"+localcopystr+") {");
2003 /* Link object into list */
2004 String revertptr=generateTemp(fm, reverttable.get(currlb));
2005 output.println(revertptr+"=revertlist;");
2006 if ((GENERATEPRECISEGC) || this.state.MULTICOREGC)
2007 output.println("COPY_OBJ((struct garbagelist *)"+localsprefixaddr+",(struct ___Object___ *)"+dst+");");
2009 output.println("COPY_OBJ("+dst+");");
2010 output.println(dst+"->"+nextobjstr+"="+revertptr+";");
2011 output.println("revertlist=(struct ___Object___ *)"+dst+";");
2012 output.println("}");
2014 System.out.println("Node: "+fsen);
2015 System.out.println(currlb);
2016 System.out.println("statusdst="+statusdst);
2017 System.out.println(fm.printMethod());
2018 throw new Error("Unknown array type");
2021 output.println("{");
2022 String src=generateTemp(fm, fsen.getSrc());
2023 output.println("INTPTR srcoid=("+src+"!=NULL?((INTPTR)"+src+"->"+oidstr+"):0);");
2024 output.println("((INTPTR*)(((char *) &("+ generateTemp(fm,fsen.getDst())+"->___length___))+sizeof(int)))["+generateTemp(fm, fsen.getIndex())+"]=srcoid;");
2025 output.println("}");
2027 output.println("(("+type +"*)(((char *) &("+ generateTemp(fm,fsen.getDst())+"->___length___))+sizeof(int)))["+generateTemp(fm, fsen.getIndex())+"]="+generateTemp(fm,fsen.getSrc())+";");
2030 if (state.FASTCHECK) {
2031 String dst=generateTemp(fm, fsen.getDst());
2032 output.println("if(!"+dst+"->"+localcopystr+") {");
2033 /* Link object into list */
2034 if (GENERATEPRECISEGC || this.state.MULTICOREGC)
2035 output.println("COPY_OBJ((struct garbagelist *)"+localsprefixaddr+",(struct ___Object___ *)"+dst+");");
2037 output.println("COPY_OBJ("+dst+");");
2038 output.println(dst+"->"+nextobjstr+"="+fcrevert+";");
2039 output.println(fcrevert+"=(struct ___Object___ *)"+dst+";");
2040 output.println("}");
2042 output.println("(("+type +"*)(((char *) &("+ generateTemp(fm,fsen.getDst())+"->___length___))+sizeof(int)))["+generateTemp(fm, fsen.getIndex())+"]="+generateTemp(fm,fsen.getSrc())+";");
2047 protected void generateFlatNew(FlatMethod fm, FlatNew fn, PrintWriter output) {
2048 if (state.DSM && locality.getAtomic(currlb).get(fn).intValue()>0&&!fn.isGlobal()) {
2049 //Stash pointer in case of GC
2050 String revertptr=generateTemp(fm, reverttable.get(currlb));
2051 output.println(revertptr+"=revertlist;");
2053 if (state.SINGLETM) {
2054 if (fn.getType().isArray()) {
2055 int arrayid=state.getArrayNumber(fn.getType())+state.numClasses();
2056 if (locality.getAtomic(currlb).get(fn).intValue()>0) {
2057 //inside transaction
2058 output.println(generateTemp(fm,fn.getDst())+"=allocate_newarraytrans("+localsprefixaddr+", "+arrayid+", "+generateTemp(fm, fn.getSize())+");");
2060 //outside transaction
2061 output.println(generateTemp(fm,fn.getDst())+"=allocate_newarray("+localsprefixaddr+", "+arrayid+", "+generateTemp(fm, fn.getSize())+");");
2064 if (locality.getAtomic(currlb).get(fn).intValue()>0) {
2065 //inside transaction
2066 output.println(generateTemp(fm,fn.getDst())+"=allocate_newtrans("+localsprefixaddr+", "+fn.getType().getClassDesc().getId()+");");
2068 //outside transaction
2069 output.println(generateTemp(fm,fn.getDst())+"=allocate_new("+localsprefixaddr+", "+fn.getType().getClassDesc().getId()+");");
2072 } else if (fn.getType().isArray()) {
2073 int arrayid=state.getArrayNumber(fn.getType())+state.numClasses();
2074 if (fn.isGlobal()) {
2075 output.println(generateTemp(fm,fn.getDst())+"=allocate_newarrayglobal("+arrayid+", "+generateTemp(fm, fn.getSize())+");");
2076 } else if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
2077 output.println(generateTemp(fm,fn.getDst())+"=allocate_newarray("+localsprefixaddr+", "+arrayid+", "+generateTemp(fm, fn.getSize())+");");
2079 output.println(generateTemp(fm,fn.getDst())+"=allocate_newarray("+arrayid+", "+generateTemp(fm, fn.getSize())+");");
2082 if (fn.isGlobal()) {
2083 output.println(generateTemp(fm,fn.getDst())+"=allocate_newglobal("+fn.getType().getClassDesc().getId()+");");
2084 } else if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
2085 output.println(generateTemp(fm,fn.getDst())+"=allocate_new("+localsprefixaddr+", "+fn.getType().getClassDesc().getId()+");");
2087 output.println(generateTemp(fm,fn.getDst())+"=allocate_new("+fn.getType().getClassDesc().getId()+");");
2090 if (state.DSM && locality.getAtomic(currlb).get(fn).intValue()>0&&!fn.isGlobal()) {
2091 String revertptr=generateTemp(fm, reverttable.get(currlb));
2092 String dst=generateTemp(fm,fn.getDst());
2093 output.println(dst+"->___localcopy___=(struct ___Object___*)1;");
2094 output.println(dst+"->"+nextobjstr+"="+revertptr+";");
2095 output.println("revertlist=(struct ___Object___ *)"+dst+";");
2097 if (state.FASTCHECK) {
2098 String dst=generateTemp(fm,fn.getDst());
2099 output.println(dst+"->___localcopy___=(struct ___Object___*)1;");
2100 output.println(dst+"->"+nextobjstr+"="+fcrevert+";");
2101 output.println(fcrevert+"=(struct ___Object___ *)"+dst+";");
2105 protected void generateFlatOpNode(FlatMethod fm, FlatOpNode fon, PrintWriter output) {
2106 if (fon.getRight()!=null) {
2107 if (fon.getOp().getOp()==Operation.URIGHTSHIFT) {
2108 if (fon.getLeft().getType().isLong())
2109 output.println(generateTemp(fm, fon.getDest())+" = ((unsigned long long)"+generateTemp(fm, fon.getLeft())+")>>"+generateTemp(fm,fon.getRight())+";");
2111 output.println(generateTemp(fm, fon.getDest())+" = ((unsigned int)"+generateTemp(fm, fon.getLeft())+")>>"+generateTemp(fm,fon.getRight())+";");
2113 } else if (dc!=null) {
2114 output.print(generateTemp(fm, fon.getDest())+" = (");
2115 if (fon.getLeft().getType().isPtr()&&(fon.getOp().getOp()==Operation.EQUAL||fon.getOp().getOp()==Operation.NOTEQUAL))
2116 output.print("(void *)");
2117 if (dc.getNeedLeftSrcTrans(currlb, fon))
2118 output.print("("+generateTemp(fm, fon.getLeft())+"!=NULL?"+generateTemp(fm, fon.getLeft())+"->"+oidstr+":NULL)");
2120 output.print(generateTemp(fm, fon.getLeft()));
2121 output.print(")"+fon.getOp().toString()+"(");
2122 if (fon.getRight().getType().isPtr()&&(fon.getOp().getOp()==Operation.EQUAL||fon.getOp().getOp()==Operation.NOTEQUAL))
2123 output.print("(void *)");
2124 if (dc.getNeedRightSrcTrans(currlb, fon))
2125 output.println("("+generateTemp(fm, fon.getRight())+"!=NULL?"+generateTemp(fm, fon.getRight())+"->"+oidstr+":NULL));");
2127 output.println(generateTemp(fm,fon.getRight())+");");
2129 output.println(generateTemp(fm, fon.getDest())+" = "+generateTemp(fm, fon.getLeft())+fon.getOp().toString()+generateTemp(fm,fon.getRight())+";");
2130 } else if (fon.getOp().getOp()==Operation.ASSIGN)
2131 output.println(generateTemp(fm, fon.getDest())+" = "+generateTemp(fm, fon.getLeft())+";");
2132 else if (fon.getOp().getOp()==Operation.UNARYPLUS)
2133 output.println(generateTemp(fm, fon.getDest())+" = "+generateTemp(fm, fon.getLeft())+";");
2134 else if (fon.getOp().getOp()==Operation.UNARYMINUS)
2135 output.println(generateTemp(fm, fon.getDest())+" = -"+generateTemp(fm, fon.getLeft())+";");
2136 else if (fon.getOp().getOp()==Operation.LOGIC_NOT)
2137 output.println(generateTemp(fm, fon.getDest())+" = !"+generateTemp(fm, fon.getLeft())+";");
2138 else if (fon.getOp().getOp()==Operation.COMP)
2139 output.println(generateTemp(fm, fon.getDest())+" = ~"+generateTemp(fm, fon.getLeft())+";");
2140 else if (fon.getOp().getOp()==Operation.ISAVAILABLE) {
2141 output.println(generateTemp(fm, fon.getDest())+" = "+generateTemp(fm, fon.getLeft())+"->fses==NULL;");
2143 output.println(generateTemp(fm, fon.getDest())+fon.getOp().toString()+generateTemp(fm, fon.getLeft())+";");
2146 protected void generateFlatLiteralNode(FlatMethod fm, FlatLiteralNode fln, PrintWriter output) {
2147 if (fln.getValue()==null)
2148 output.println(generateTemp(fm, fln.getDst())+"=0;");
2149 else if (fln.getType().getSymbol().equals(TypeUtil.StringClass)) {
2150 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
2151 if (state.DSM && locality.getAtomic(currlb).get(fln).intValue()>0) {
2152 //Stash pointer in case of GC
2153 String revertptr=generateTemp(fm, reverttable.get(currlb));
2154 output.println(revertptr+"=revertlist;");
2156 output.println(generateTemp(fm, fln.getDst())+"=NewString("+localsprefixaddr+", \""+FlatLiteralNode.escapeString((String)fln.getValue())+"\","+((String)fln.getValue()).length()+");");
2157 if (state.DSM && locality.getAtomic(currlb).get(fln).intValue()>0) {
2158 //Stash pointer in case of GC
2159 String revertptr=generateTemp(fm, reverttable.get(currlb));
2160 output.println("revertlist="+revertptr+";");
2163 output.println(generateTemp(fm, fln.getDst())+"=NewString(\""+FlatLiteralNode.escapeString((String)fln.getValue())+"\","+((String)fln.getValue()).length()+");");
2165 } else if (fln.getType().isBoolean()) {
2166 if (((Boolean)fln.getValue()).booleanValue())
2167 output.println(generateTemp(fm, fln.getDst())+"=1;");
2169 output.println(generateTemp(fm, fln.getDst())+"=0;");
2170 } else if (fln.getType().isChar()) {
2171 String st=FlatLiteralNode.escapeString(fln.getValue().toString());
2172 output.println(generateTemp(fm, fln.getDst())+"='"+st+"';");
2173 } else if (fln.getType().isLong()) {
2174 output.println(generateTemp(fm, fln.getDst())+"="+fln.getValue()+"LL;");
2176 output.println(generateTemp(fm, fln.getDst())+"="+fln.getValue()+";");
2179 protected void generateStoreFlatCondBranch(FlatMethod fm, LocalityBinding lb, FlatCondBranch fcb, String label, PrintWriter output) {
2182 //only record if this group has more than one exit
2183 if (branchanalysis.numJumps(fcb)>1) {
2184 left=branchanalysis.jumpValue(fcb, 0);
2185 right=branchanalysis.jumpValue(fcb, 1);
2187 output.println("if (!"+generateTemp(fm, fcb.getTest())+") {");
2189 output.println("STOREBRANCH("+right+");");
2190 output.println("goto "+label+";");
2191 output.println("}");
2193 output.println("STOREBRANCH("+left+");");
2196 /** This method generates header information for the method or
2197 * task referenced by the Descriptor des. */
2198 protected void generateHeader(FlatMethod fm, LocalityBinding lb, Descriptor des, PrintWriter output) {
2200 ParamsObject objectparams=(ParamsObject)paramstable.get(lb!=null ? lb : des);
2201 MethodDescriptor md=null;
2202 TaskDescriptor task=null;
2203 if (des instanceof MethodDescriptor)
2204 md=(MethodDescriptor) des;
2206 task=(TaskDescriptor) des;
2208 ClassDescriptor cn=md!=null ? md.getClassDesc() : null;
2210 if (md!=null&&md.getReturnType()!=null) {
2211 if (state.MGC && md.getReturnType().isClass() && md.getReturnType().getClassDesc().isEnum()) {
2212 output.print("int ");
2213 } else if (md.getReturnType().isClass()||md.getReturnType().isArray())
2214 output.print("struct " + md.getReturnType().getSafeSymbol()+" * ");
2216 output.print(md.getReturnType().getSafeSymbol()+" ");
2218 //catch the constructor case
2219 output.print("void ");
2221 output.print(cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(");
2223 output.print(task.getSafeSymbol()+"(");
2225 boolean printcomma=false;
2226 if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
2228 output.print("struct "+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params * "+paramsprefix);
2230 output.print("struct "+task.getSafeSymbol()+"_params * "+paramsprefix);
2236 for(int i=0; i<objectparams.numPrimitives(); i++) {
2237 TempDescriptor temp=objectparams.getPrimitive(i);
2241 if(state.MGC && temp.getType().isClass() && temp.getType().getClassDesc().isEnum()) {
2242 output.print("int " + temp.getSafeSymbol());
2243 } else if (temp.getType().isClass()||temp.getType().isArray())
2244 output.print("struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol());
2246 output.print(temp.getType().getSafeSymbol()+" "+temp.getSafeSymbol());
2248 output.println(") {");
2249 } else if (!GENERATEPRECISEGC && !this.state.MULTICOREGC) {
2250 /* Imprecise Task */
2251 output.println("void * parameterarray[]) {");
2252 /* Unpack variables */
2253 for(int i=0; i<objectparams.numPrimitives(); i++) {
2254 TempDescriptor temp=objectparams.getPrimitive(i);
2255 if(state.MGC && temp.getType().isClass() && temp.getType().getClassDesc().isEnum()) {
2256 output.print("int " + temp.getSafeSymbol() + "=parameterarray["+i+"];");
2258 output.println("struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol()+"=parameterarray["+i+"];");
2261 for(int i=0; i<fm.numTags(); i++) {
2262 TempDescriptor temp=fm.getTag(i);
2263 int offset=i+objectparams.numPrimitives();
2264 output.println("struct ___TagDescriptor___ * "+temp.getSafeSymbol()+"=parameterarray["+offset+"];");
2267 if ((objectparams.numPrimitives()+fm.numTags())>maxtaskparams)
2268 maxtaskparams=objectparams.numPrimitives()+fm.numTags();
2269 } else output.println(") {");