From: bdemsky Date: Sat, 26 Feb 2011 00:41:54 +0000 (+0000) Subject: big code reorg...get TM out of buildcode X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=e340225160b755bbf9963bc7a9db6e24a8542d07;p=IRC.git big code reorg...get TM out of buildcode --- diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index cfa6eb7c..501b4bda 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -17,17 +17,8 @@ import Analysis.TaskStateAnalysis.OptionalTaskDescriptor; import Analysis.TaskStateAnalysis.Predicate; import Analysis.TaskStateAnalysis.SafetyAnalysis; import Analysis.TaskStateAnalysis.TaskIndex; -import Analysis.Locality.LocalityAnalysis; -import Analysis.Locality.LocalityBinding; -import Analysis.Locality.DiscoverConflicts; -import Analysis.Locality.DCWrapper; -import Analysis.Locality.DelayComputation; -import Analysis.Locality.BranchAnalysis; import Analysis.CallGraph.CallGraph; -import Analysis.Prefetch.*; -import Analysis.Loops.WriteBarrier; import Analysis.Loops.GlobalFieldType; -import Analysis.Locality.TypeAnalysis; import Util.CodePrinter; public class BuildCode { @@ -43,7 +34,6 @@ public class BuildCode { String localsprefixderef=localsprefix+"."; String fcrevert="___fcrevert___"; String paramsprefix="___params___"; - String oidstr="___nextobject___"; String nextobjstr="___nextobject___"; String localcopystr="___localcopy___"; public static boolean GENERATEPRECISEGC=false; @@ -53,71 +43,36 @@ public class BuildCode { Virtual virtualcalls; TypeUtil typeutil; protected int maxtaskparams=0; - private int maxcount=0; + protected int maxcount=0; ClassDescriptor[] cdarray; TypeDescriptor[] arraytable; - LocalityAnalysis locality; - Hashtable reverttable; - Hashtable> backuptable; SafetyAnalysis sa; - PrefetchAnalysis pa; - WriteBarrier wb; - DiscoverConflicts dc; - DiscoverConflicts recorddc; - DCWrapper delaycomp; CallGraph callgraph; Hashtable printedfieldstbl; - public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, SafetyAnalysis sa, PrefetchAnalysis pa) { - this(st, temptovar, typeutil, null, sa, pa); + public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil) { + this(st, temptovar, typeutil, null); } - public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality, PrefetchAnalysis pa) { - this(st, temptovar, typeutil, locality, null, pa); - } - - public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality, SafetyAnalysis sa, PrefetchAnalysis pa) { + public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, SafetyAnalysis sa) { this.sa=sa; - this.pa=pa; state=st; callgraph=new CallGraph(state); - if (state.SINGLETM) - oidstr="___objlocation___"; this.temptovar=temptovar; paramstable=new Hashtable(); tempstable=new Hashtable(); fieldorder=new Hashtable(); flagorder=new Hashtable(); this.typeutil=typeutil; - virtualcalls=new Virtual(state,locality); - if (locality!=null) { - this.locality=locality; - this.reverttable=new Hashtable(); - this.backuptable=new Hashtable>(); - this.wb=new WriteBarrier(locality, st); - } - if (state.SINGLETM&&state.DCOPTS) { - TypeAnalysis typeanalysis=new TypeAnalysis(locality, st, typeutil,callgraph); - GlobalFieldType gft=new GlobalFieldType(callgraph, st, typeutil.getMain()); - this.dc=new DiscoverConflicts(locality, st, typeanalysis, gft); - dc.doAnalysis(); - } - if (state.DELAYCOMP) { - TypeAnalysis typeanalysis=new TypeAnalysis(locality, st, typeutil,callgraph); - GlobalFieldType gft=new GlobalFieldType(callgraph, st, typeutil.getMain()); - delaycomp=new DCWrapper(locality, st, typeanalysis, gft); - dc=delaycomp.getConflicts(); - recorddc=new DiscoverConflicts(locality, st, typeanalysis, delaycomp.getCannotDelayMap(), true, true, null); - recorddc.doAnalysis(); - } + virtualcalls=new Virtual(state, null); printedfieldstbl = new Hashtable(); } /** The buildCode method outputs C code for all the methods. The Flat * versions of the methods must already be generated and stored in * the State object. */ - PrintWriter outsandbox=null; + public void buildCode() { /* Create output streams to write to */ @@ -134,9 +89,7 @@ public class BuildCode { PrintWriter outglobaldefs=null; try { - if (state.SANDBOX) { - outsandbox=new CodePrinter(new FileOutputStream(PREFIX+"sandboxdefs.c"), true); - } + buildCodeSetup();//EXTENSION POINT outstructs=new CodePrinter(new FileOutputStream(PREFIX+"structdefs.h"), true); outmethodheader=new CodePrinter(new FileOutputStream(PREFIX+"methodheaders.h"), true); outclassdefs=new CodePrinter(new FileOutputStream(PREFIX+"classdefs.h"), true); @@ -175,28 +128,13 @@ public class BuildCode { outmethodheader.println("#ifndef METHODHEADERS_H"); outmethodheader.println("#define METHODHEADERS_H"); outmethodheader.println("#include \"structdefs.h\""); - if (state.DSM) - outmethodheader.println("#include \"dstm.h\""); - if (state.SANDBOX) { - outmethodheader.println("#include \"sandbox.h\""); - } + if (state.EVENTMONITOR) { outmethodheader.println("#include \"monitor.h\""); } - if (state.SINGLETM) { - outmethodheader.println("#include \"tm.h\""); - outmethodheader.println("#include \"delaycomp.h\""); - outmethodheader.println("#include \"inlinestm.h\""); - } - if (state.ABORTREADERS) { - outmethodheader.println("#include \"abortreaders.h\""); - outmethodheader.println("#include "); - } - additionalIncludesMethodsHeader(outmethodheader); - /* Output Structures */ outputStructs(outstructs); @@ -367,50 +305,24 @@ public class BuildCode { additionalCodeAtTopOfMain(outmethod); - - if (state.DSM) { - if (state.DSMRECOVERYSTATS) { - outmethod.println("#ifdef RECOVERYSTATS \n"); - outmethod.println("handle();\n"); - outmethod.println("#endif\n"); - } else { - outmethod.println("#if defined(TRANSSTATS) || defined(RECOVERYSTATS) \n"); - outmethod.println("handle();\n"); - outmethod.println("#endif\n"); - } - } - - if (state.THREAD||state.DSM||state.SINGLETM) { + if (state.THREAD) { outmethod.println("initializethreads();"); } - if (state.DSM) { - outmethod.println("if (dstmStartup(argv[1])) {"); - if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { - outmethod.println(" struct ArrayObject * stringarray=allocate_newarray(NULL, STRINGARRAYTYPE, argc-2);"); - } else { - outmethod.println(" struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc-2);"); - } + + if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { + outmethod.println(" struct ArrayObject * stringarray=allocate_newarray(NULL, STRINGARRAYTYPE, argc-1);"); } else { - if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { - outmethod.println(" struct ArrayObject * stringarray=allocate_newarray(NULL, STRINGARRAYTYPE, argc-1);"); - } else { - outmethod.println(" struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc-1);"); - } + outmethod.println(" struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc-1);"); } - if (state.DSM) { - outmethod.println(" for(i=2;i___length___)+sizeof(int)))[i-2]=newstring;"); - else - outmethod.println(" ((void **)(((char *)& stringarray->___length___)+sizeof(int)))[i-1]=newstring;"); + outmethod.println(" ((void **)(((char *)& stringarray->___length___)+sizeof(int)))[i-1]=newstring;"); outmethod.println(" }"); MethodDescriptor md=typeutil.getMain(); @@ -418,81 +330,37 @@ public class BuildCode { outmethod.println(" {"); if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { - if (state.DSM||state.SINGLETM) { - outmethod.print(" struct "+cd.getSafeSymbol()+locality.getMain().getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={"); - } else - outmethod.print(" struct "+cd.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={"); + outmethod.print(" struct "+cd.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={"); outmethod.println("1, NULL,"+"stringarray};"); - if (state.DSM||state.SINGLETM) - outmethod.println(" "+cd.getSafeSymbol()+locality.getMain().getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(& __parameterlist__);"); - else - outmethod.println(" "+cd.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(& __parameterlist__);"); + outmethod.println(" "+cd.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(& __parameterlist__);"); } else { - if (state.DSM||state.SINGLETM) - outmethod.println(" "+cd.getSafeSymbol()+locality.getMain().getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(stringarray);"); - else - outmethod.println(" "+cd.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(stringarray);"); + outmethod.println(" "+cd.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(stringarray);"); } outmethod.println(" }"); - if (state.DSM) { - outmethod.println("}"); - } - - if (state.THREAD||state.DSM||state.SINGLETM) { + if (state.THREAD) { outmethod.println("pthread_mutex_lock(&gclistlock);"); outmethod.println("threadcount--;"); outmethod.println("pthread_cond_signal(&gccond);"); outmethod.println("pthread_mutex_unlock(&gclistlock);"); } - if (state.DSM||state.SINGLETM) { - outmethod.println("#if defined(TRANSSTATS) \n"); - outmethod.println("printf(\"****** Transaction Stats ******\\n\");"); - outmethod.println("printf(\"numTransCommit= %d\\n\", numTransCommit);"); - outmethod.println("printf(\"numTransAbort= %d\\n\", numTransAbort);"); - outmethod.println("printf(\"nSoftAbort= %d\\n\", nSoftAbort);"); - if (state.DSM) { - outmethod.println("printf(\"nchashSearch= %d\\n\", nchashSearch);"); - outmethod.println("printf(\"nmhashSearch= %d\\n\", nmhashSearch);"); - outmethod.println("printf(\"nprehashSearch= %d\\n\", nprehashSearch);"); - outmethod.println("printf(\"ndirtyCacheObj= %d\\n\", ndirtyCacheObj);"); - outmethod.println("printf(\"nRemoteReadSend= %d\\n\", nRemoteSend);"); - outmethod.println("printf(\"bytesSent= %d\\n\", bytesSent);"); - outmethod.println("printf(\"bytesRecv= %d\\n\", bytesRecv);"); - outmethod.println("printf(\"totalObjSize= %d\\n\", totalObjSize);"); - outmethod.println("printf(\"sendRemoteReq= %d\\n\", sendRemoteReq);"); - outmethod.println("printf(\"getResponse= %d\\n\", getResponse);"); - } else if (state.SINGLETM) { - outmethod.println("printf(\"nSoftAbortAbort= %d\\n\", nSoftAbortAbort);"); - outmethod.println("printf(\"nSoftAbortCommit= %d\\n\", nSoftAbortCommit);"); - outmethod.println("#ifdef STMSTATS\n"); - outmethod.println("for(i=0; i lbit=locality.getLocalityBindings().iterator(); lbit.hasNext(); ) { - LocalityBinding lb=lbit.next(); - MethodDescriptor md=lb.getMethod(); + Iterator classit=state.getClassSymbolTable().getDescriptorsIterator(); + while(classit.hasNext()) { + ClassDescriptor cn=(ClassDescriptor)classit.next(); + Iterator methodit=cn.getMethods(); + while(methodit.hasNext()) { + /* Classify parameters */ + MethodDescriptor md=(MethodDescriptor)methodit.next(); FlatMethod fm=state.getMethodFlat(md); - wb.analyze(lb); if (!md.getModifiers().isNative()) { - generateFlatMethod(fm, lb, outmethod); - } - } - } else { - Iterator classit=state.getClassSymbolTable().getDescriptorsIterator(); - while(classit.hasNext()) { - ClassDescriptor cn=(ClassDescriptor)classit.next(); - Iterator methodit=cn.getMethods(); - while(methodit.hasNext()) { - /* Classify parameters */ - MethodDescriptor md=(MethodDescriptor)methodit.next(); - FlatMethod fm=state.getMethodFlat(md); - if (!md.getModifiers().isNative()) { - generateFlatMethod(fm, null, outmethod); - } + generateFlatMethod(fm, outmethod); } } } @@ -633,24 +485,6 @@ public class BuildCode { /* Output #defines that the runtime uses to determine type * numbers for various objects it needs */ outstructs.println("#define MAXCOUNT "+maxcount); - if (state.DSM||state.SINGLETM) { - LocalityBinding lbrun=new LocalityBinding(typeutil.getRun(), false); - if (state.DSM) { - lbrun.setGlobalThis(LocalityAnalysis.GLOBAL); - } else if (state.SINGLETM) { - lbrun.setGlobalThis(LocalityAnalysis.NORMAL); - } - outstructs.println("#define RUNMETHOD "+virtualcalls.getLocalityNumber(lbrun)); - } - - if (state.DSMTASK) { - LocalityBinding lbexecute = new LocalityBinding(typeutil.getExecute(), false); - if(state.DSM) - lbexecute.setGlobalThis(LocalityAnalysis.GLOBAL); - else if( state.SINGLETM) - lbexecute.setGlobalThis(LocalityAnalysis.NORMAL); - outstructs.println("#define EXECUTEMETHOD " + virtualcalls.getLocalityNumber(lbexecute)); - } outstructs.println("#define STRINGARRAYTYPE "+ (state.getArrayNumber( @@ -759,15 +593,9 @@ public class BuildCode { printClassStruct(typeutil.getClass(TypeUtil.ObjectClass), outclassdefs, outglobaldefs); printedfieldstbl.clear(); - - if (state.STMARRAY) { - outclassdefs.println(" int lowindex;"); - outclassdefs.println(" int highindex;"); - } - if (state.ARRAYPAD) + printExtraArrayFields(outclassdefs); + if (state.ARRAYPAD) { outclassdefs.println(" int paddingforarray;"); - if (state.DUALVIEW) { - outclassdefs.println(" int arrayversion;"); } outclassdefs.println(" int ___length___;"); @@ -832,7 +660,7 @@ public class BuildCode { /** Prints out definitions for generic task structures */ - private void outputTaskTypes(PrintWriter outtask) { + protected void outputTaskTypes(PrintWriter outtask) { outtask.println("#ifndef _TASK_H"); outtask.println("#define _TASK_H"); outtask.println("struct parameterdescriptor {"); @@ -857,7 +685,7 @@ public class BuildCode { } - private void buildRepairStructs(PrintWriter outrepairstructs) { + protected void buildRepairStructs(PrintWriter outrepairstructs) { Iterator classit=state.getClassSymbolTable().getDescriptorsIterator(); while(classit.hasNext()) { ClassDescriptor cn=(ClassDescriptor)classit.next(); @@ -884,7 +712,7 @@ public class BuildCode { } } - private void printRepairStruct(ClassDescriptor cn, PrintWriter output) { + protected void printRepairStruct(ClassDescriptor cn, PrintWriter output) { ClassDescriptor sp=cn.getSuperDesc(); if (sp!=null) printRepairStruct(sp, output); @@ -905,7 +733,7 @@ public class BuildCode { } /** This method outputs TaskDescriptor information */ - private void generateTaskDescriptor(PrintWriter output, FlatMethod fm, TaskDescriptor task) { + protected void generateTaskDescriptor(PrintWriter output, FlatMethod fm, TaskDescriptor task) { for (int i=0; i lbit=locality.getClassBindings(cd).iterator(); lbit.hasNext(); ) { - LocalityBinding lb=lbit.next(); - MethodDescriptor md=lb.getMethod(); - //Is the method static or a constructor - if (md.isStatic()||md.getReturnType()==null) - continue; - int methodnum=virtualcalls.getLocalityNumber(lb); - virtualtable[rownum][methodnum]=lb; - } - } - /** Generate array that contains the sizes of class objects. The * object allocation functions in the runtime use this * information. */ - private void generateSizeArray(PrintWriter outclassdefs) { + protected void generateSizeArray(PrintWriter outclassdefs) { outclassdefs.print("extern struct prefetchCountStats * evalPrefetch;\n"); - outclassdefs.print("#ifdef TRANSSTATS \n"); - outclassdefs.print("extern int numTransAbort;\n"); - outclassdefs.print("extern int numTransCommit;\n"); - outclassdefs.print("extern int nSoftAbort;\n"); - if (state.DSM) { - outclassdefs.print("extern int nchashSearch;\n"); - outclassdefs.print("extern int nmhashSearch;\n"); - outclassdefs.print("extern int nprehashSearch;\n"); - outclassdefs.print("extern int ndirtyCacheObj;\n"); - outclassdefs.print("extern int nRemoteSend;\n"); - outclassdefs.print("extern int sendRemoteReq;\n"); - outclassdefs.print("extern int getResponse;\n"); - outclassdefs.print("extern int bytesSent;\n"); - outclassdefs.print("extern int bytesRecv;\n"); - outclassdefs.print("extern int totalObjSize;\n"); - outclassdefs.print("extern void handle();\n"); - } else if (state.SINGLETM) { - outclassdefs.println("extern int nSoftAbortAbort;"); - outclassdefs.println("extern int nSoftAbortCommit;"); - outclassdefs.println("#ifdef STMSTATS\n"); - outclassdefs.println("extern objtypestat_t typesCausingAbort[];"); - outclassdefs.println("#endif\n"); - } - outclassdefs.print("#endif\n"); - - outclassdefs.print("int numprefetchsites = " + pa.prefetchsiteid + ";\n"); - + generateSizeArrayExtensions(outclassdefs); Iterator it=state.getClassSymbolTable().getDescriptorsIterator(); cdarray=new ClassDescriptor[state.numClasses()]; @@ -1148,8 +919,6 @@ public class BuildCode { arraytable[id]=td; } - - /* Print out types */ outclassdefs.println("/* "); for(int i=0; i saveset=lb!=null ? locality.getTempSet(lb) : null; ParamsObject objectparams=md!=null ? new ParamsObject(md,tag++) : new ParamsObject(task, tag++); - if (lb!=null) { - paramstable.put(lb, objectparams); - backuptable.put(lb, new Hashtable()); - } else if (md!=null) + if (md!=null) paramstable.put(md, objectparams); else paramstable.put(task, objectparams); @@ -1301,9 +1066,6 @@ public class BuildCode { objectparams.addPtr(temp); else objectparams.addPrim(temp); - if(lb!=null&&saveset.contains(temp)) { - backuptable.get(lb).put(temp, temp.createNew()); - } } for(int i=0; i tmpit=backuptable.get(lb).values().iterator(); tmpit.hasNext(); ) { - TempDescriptor tmp=tmpit.next(); - TypeDescriptor type=tmp.getType(); - if (type.isPtr()&&((GENERATEPRECISEGC) || (this.state.MULTICOREGC))) - objecttemps.addPtr(tmp); - else - objecttemps.addPrim(tmp); - } - /* Create temp to hold revert table */ - if (state.DSM&&(lb.getHasAtomic()||lb.isAtomic())) { - TempDescriptor reverttmp=new TempDescriptor("revertlist", typeutil.getClass(TypeUtil.ObjectClass)); - if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) - objecttemps.addPtr(reverttmp); - else - objecttemps.addPrim(reverttmp); - reverttable.put(lb, reverttmp); } } } @@ -1367,7 +1103,7 @@ public class BuildCode { * (3) For classes, does the class contain flags. */ - private void generateLayoutStructs(PrintWriter output) { + protected void generateLayoutStructs(PrintWriter output) { Iterator it=state.getClassSymbolTable().getDescriptorsIterator(); while(it.hasNext()) { ClassDescriptor cn=(ClassDescriptor)it.next(); @@ -1377,8 +1113,6 @@ public class BuildCode { while(allit.hasNext()) { FieldDescriptor fd=(FieldDescriptor)allit.next(); TypeDescriptor type=fd.getType(); - if (state.DSM&&fd.isGlobal()) //Don't GC the global objects for now - continue; if (type.isPtr()) count++; } @@ -1387,8 +1121,6 @@ public class BuildCode { while(allit.hasNext()) { FieldDescriptor fd=(FieldDescriptor)allit.next(); TypeDescriptor type=fd.getType(); - if (state.DSM&&fd.isGlobal()) //Don't GC the global objects for now - continue; if (type.isPtr()) { output.println(","); output.print("((unsigned INTPTR)&(((struct "+cn.getSafeSymbol() +" *)0)->"+ @@ -1438,44 +1170,28 @@ public class BuildCode { output.println("};"); } + /** Print out table to give us supertypes */ - private void generateSuperTypeTable(PrintWriter output) { + protected void generateSuperTypeTable(PrintWriter output) { output.println("int supertypes[]={"); boolean needcomma=false; for(int i=0; i(); classdefout.println("};\n"); + generateCallStructsMethods(cn, output, headersout); + } - if (state.DSM||state.SINGLETM) { - /* Cycle through LocalityBindings */ - HashSet nativemethods=new HashSet(); - Set lbset=locality.getClassBindings(cn); - if (lbset!=null) { - for(Iterator lbit=lbset.iterator(); lbit.hasNext(); ) { - LocalityBinding lb=lbit.next(); - MethodDescriptor md=lb.getMethod(); - if (md.getModifiers().isNative()) { - //make sure we only print a native method once - if (nativemethods.contains(md)) { - FlatMethod fm=state.getMethodFlat(md); - generateTempStructs(fm, lb); - continue; - } else - nativemethods.add(md); - } - generateMethod(cn, md, lb, headersout, output); - } - } - for(Iterator methodit=cn.getMethods(); methodit.hasNext(); ) { - MethodDescriptor md=(MethodDescriptor)methodit.next(); - if (md.getModifiers().isNative()&&!nativemethods.contains(md)) { - //Need to build param structure for library code - FlatMethod fm=state.getMethodFlat(md); - generateTempStructs(fm, null); - generateMethodParam(cn, md, null, output); - } - } - } else - for(Iterator methodit=cn.getMethods(); methodit.hasNext(); ) { - MethodDescriptor md=(MethodDescriptor)methodit.next(); - generateMethod(cn, md, null, headersout, output); - } + protected void generateCallStructsMethods(ClassDescriptor cn, PrintWriter output, PrintWriter headersout) { + for(Iterator methodit=cn.getMethods(); methodit.hasNext(); ) { + MethodDescriptor md=(MethodDescriptor)methodit.next(); + generateMethod(cn, md, headersout, output); + } } - private void generateMethodParam(ClassDescriptor cn, MethodDescriptor md, LocalityBinding lb, PrintWriter output) { + protected void generateMethodParam(ClassDescriptor cn, MethodDescriptor md, PrintWriter output) { /* Output parameter structure */ if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { - ParamsObject objectparams=(ParamsObject) paramstable.get(lb!=null ? lb : md); - if ((state.DSM||state.SINGLETM)&&lb!=null) - output.println("struct "+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params {"); - else - output.println("struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params {"); + ParamsObject objectparams=(ParamsObject) paramstable.get(md); + output.println("struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params {"); output.println(" int size;"); output.println(" void * next;"); for(int i=0; i atomicmethodmap; - static int atomicmethodcount=0; - - - BranchAnalysis branchanalysis; - private void generateFlatMethod(FlatMethod fm, LocalityBinding lb, PrintWriter output) { + protected void generateFlatMethod(FlatMethod fm, PrintWriter output) { if (State.PRINTFLAT) System.out.println(fm.printMethod()); MethodDescriptor md=fm.getMethod(); TaskDescriptor task=fm.getTask(); ClassDescriptor cn=md!=null ? md.getClassDesc() : null; - ParamsObject objectparams=(ParamsObject)paramstable.get(lb!=null ? lb : md!=null ? md : task); - - HashSet arset=null; - branchanalysis=null; - - if (state.DELAYCOMP&&!lb.isAtomic()&&lb.getHasAtomic()) { - //create map - if (atomicmethodmap==null) - atomicmethodmap=new Hashtable(); - - //fix these so we get right strings for local variables - localsprefixaddr=localsprefix; - localsprefixderef=localsprefix+"->"; - arset=new HashSet(); - - //build branchanalysis - branchanalysis=new BranchAnalysis(locality, lb, delaycomp.getNotReady(lb), delaycomp.livecode(lb), state); - - //Generate commit methods here - for(Iterator fnit=fm.getNodeSet().iterator(); fnit.hasNext(); ) { - FlatNode fn=fnit.next(); - if (fn.kind()==FKind.FlatAtomicEnterNode&& - locality.getAtomic(lb).get(fn.getPrev(0)).intValue()==0&& - delaycomp.needsFission(lb, (FlatAtomicEnterNode) fn)) { - //We have an atomic enter - FlatAtomicEnterNode faen=(FlatAtomicEnterNode) fn; - Set exitset=faen.getExits(); - //generate header - String methodname=md.getSymbol()+(atomicmethodcount++); - AtomicRecord ar=new AtomicRecord(); - ar.name=methodname; - arset.add(ar); - - atomicmethodmap.put(faen, ar); - - //build data structure declaration - output.println("struct atomicprimitives_"+methodname+" {"); - - Set recordset=delaycomp.livecode(lb); - Set liveinto=delaycomp.liveinto(lb, faen, recordset); - Set liveout=delaycomp.liveout(lb, faen); - Set liveoutvirtualread=delaycomp.liveoutvirtualread(lb, faen); - ar.livein=liveinto; - ar.reallivein=new HashSet(liveinto); - ar.liveout=liveout; - ar.liveoutvirtualread=liveoutvirtualread; - - - for(Iterator it=liveinto.iterator(); it.hasNext(); ) { - TempDescriptor tmp=it.next(); - //remove the pointers - if (tmp.getType().isPtr()) { - it.remove(); - } else { - //let's print it here - output.println(tmp.getType().getSafeSymbol()+" "+tmp.getSafeSymbol()+";"); - } - } - for(Iterator it=liveout.iterator(); it.hasNext(); ) { - TempDescriptor tmp=it.next(); - //remove the pointers - if (tmp.getType().isPtr()) { - it.remove(); - } else if (!liveinto.contains(tmp)) { - //let's print it here - output.println(tmp.getType().getSafeSymbol()+" "+tmp.getSafeSymbol()+";"); - } - } - output.println("};"); - - //print out method name - 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) {"); - //build code for commit method - - //first define local primitives - Set alltemps=delaycomp.alltemps(lb, faen, recordset); - for(Iterator tmpit=alltemps.iterator(); tmpit.hasNext(); ) { - TempDescriptor tmp=tmpit.next(); - if (!tmp.getType().isPtr()) { - if (liveinto.contains(tmp)||liveoutvirtualread.contains(tmp)) { - //read from live into set - output.println(tmp.getType().getSafeSymbol()+" "+tmp.getSafeSymbol()+"=primitives->"+tmp.getSafeSymbol()+";"); - } else { - //just define - output.println(tmp.getType().getSafeSymbol()+" "+tmp.getSafeSymbol()+";"); - } - } - } - //turn off write barrier generation - wb.turnoff(); - state.SINGLETM=false; - generateCode(faen, fm, lb, exitset, output, false); - state.SINGLETM=true; - //turn on write barrier generation - wb.turnon(); - output.println("}\n\n"); - } - } - } - //redefine these back to normal - - localsprefixaddr="&"+localsprefix; - localsprefixderef=localsprefix+"."; - - generateHeader(fm, lb, md!=null ? md : task,output); - TempObject objecttemp=(TempObject) tempstable.get(lb!=null ? lb : md!=null ? md : task); - - if (state.DELAYCOMP&&!lb.isAtomic()&&lb.getHasAtomic()) { - for(Iterator arit=arset.iterator(); arit.hasNext(); ) { - AtomicRecord ar=arit.next(); - output.println("struct atomicprimitives_"+ar.name+" primitives_"+ar.name+";"); - } - } + ParamsObject objectparams=(ParamsObject)paramstable.get(md!=null ? md : task); + generateHeader(fm, md!=null ? md : task,output); + TempObject objecttemp=(TempObject) tempstable.get(md!=null ? md : task); if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { - if (md!=null&&(state.DSM||state.SINGLETM)) - output.print(" struct "+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals "+localsprefix+"={"); - else if (md!=null&&!(state.DSM||state.SINGLETM)) + if (md!=null) output.print(" struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals "+localsprefix+"={"); else output.print(" struct "+task.getSafeSymbol()+"_locals "+localsprefix+"={"); @@ -2026,22 +1579,16 @@ public class BuildCode { output.println(" "+type.getSafeSymbol()+" "+td.getSafeSymbol()+";"); } - - additionalCodeAtTopFlatMethodBody(output, fm); - - /* Check to see if we need to do a GC if this is a * multi-threaded program...*/ - if (((state.OOOJAVA||state.THREAD||state.DSM||state.SINGLETM)&&GENERATEPRECISEGC) + if (((state.OOOJAVA||state.THREAD)&&GENERATEPRECISEGC) || this.state.MULTICOREGC) { //Don't bother if we aren't in recursive methods...The loops case will catch it if (callgraph.getAllMethods(md).contains(md)) { - if (state.DSM&&lb.isAtomic()) - output.println("if (needtocollect) checkcollect2("+localsprefixaddr+");"); - else if (this.state.MULTICOREGC) { + if (this.state.MULTICOREGC) { output.println("if(gcflag) gc("+localsprefixaddr+");"); } else { output.println("if (unlikely(needtocollect)) checkcollect("+localsprefixaddr+");"); @@ -2068,73 +1615,38 @@ public class BuildCode { FieldDescriptor fd=(FieldDescriptor)fields.get(i); if(fd.isStatic()) { // static field - output.println(generateTemp(fm,fm.getParameter(0),lb)+"->"+fd.getSafeSymbol()+"=&(global_defs_p->"+fd.getSafeSymbol()+");"); + output.println(generateTemp(fm,fm.getParameter(0))+"->"+fd.getSafeSymbol()+"=&(global_defs_p->"+fd.getSafeSymbol()+");"); } } } } - generateCode(fm.getNext(0), fm, lb, null, output, true); + generateCode(fm.getNext(0), fm, null, output); output.println("}\n\n"); } - - protected void generateCode(FlatNode first, FlatMethod fm, - LocalityBinding lb, Set stopset, - PrintWriter output, - boolean firstpass) { + PrintWriter output) { /* Assign labels to FlatNode's if necessary.*/ Hashtable nodetolabel; - if (state.DELAYCOMP&&!firstpass) - nodetolabel=dcassignLabels(first, stopset); - else - nodetolabel=assignLabels(first, stopset); + nodetolabel=assignLabels(first, stopset); Set storeset=null; HashSet genset=null; HashSet refset=null; Set unionset=null; - if (state.DELAYCOMP&&!lb.isAtomic()&&lb.getHasAtomic()) { - storeset=delaycomp.livecode(lb); - genset=new HashSet(); - if (state.STMARRAY&&!state.DUALVIEW) { - refset=new HashSet(); - refset.addAll(delaycomp.getDeref(lb)); - refset.removeAll(delaycomp.getCannotDelay(lb)); - refset.removeAll(delaycomp.getOther(lb)); - } - if (firstpass) { - genset.addAll(delaycomp.getCannotDelay(lb)); - genset.addAll(delaycomp.getOther(lb)); - } else { - genset.addAll(delaycomp.getNotReady(lb)); - if (state.STMARRAY&&!state.DUALVIEW) { - genset.removeAll(refset); - } - } - unionset=new HashSet(); - unionset.addAll(storeset); - unionset.addAll(genset); - if (state.STMARRAY&&!state.DUALVIEW) - unionset.addAll(refset); - } - /* Do the actual code generation */ FlatNode current_node=null; HashSet tovisit=new HashSet(); HashSet visited=new HashSet(); - if (!firstpass) - tovisit.add(first.getNext(0)); - else - tovisit.add(first); + tovisit.add(first); while(current_node!=null||!tovisit.isEmpty()) { if (current_node==null) { current_node=(FlatNode)tovisit.iterator().next(); @@ -2147,24 +1659,15 @@ public class BuildCode { output.println("L"+nodetolabel.get(current_node)+":"); } if (state.INSTRUCTIONFAILURE) { - if (state.THREAD||state.DSM||state.SINGLETM) { + if (state.THREAD) { output.println("if ((++instructioncount)>failurecount) {instructioncount=0;injectinstructionfailure();}"); } else output.println("if ((--instructioncount)==0) injectinstructionfailure();"); } if (current_node.numNext()==0||stopset!=null&&stopset.contains(current_node)) { output.print(" "); - if (!state.DELAYCOMP||firstpass) { - generateFlatNode(fm, lb, current_node, output); - } else { - //store primitive variables in out set - AtomicRecord ar=atomicmethodmap.get((FlatAtomicEnterNode)first); - Set liveout=ar.liveout; - for(Iterator tmpit=liveout.iterator(); tmpit.hasNext(); ) { - TempDescriptor tmp=tmpit.next(); - output.println("primitives->"+tmp.getSafeSymbol()+"="+tmp.getSafeSymbol()+";"); - } - } + generateFlatNode(fm, current_node, output); + if (state.OOOJAVA && stopset!=null) { assert first.getPrev(0) instanceof FlatSESEEnterNode; assert current_node instanceof FlatSESEExitNode; @@ -2188,56 +1691,13 @@ public class BuildCode { } else if(current_node.numNext()==1) { FlatNode nextnode; if (state.OOOJAVA && - current_node.kind()==FKind.FlatSESEEnterNode - ) { + current_node.kind()==FKind.FlatSESEEnterNode) { FlatSESEEnterNode fsen = (FlatSESEEnterNode)current_node; - generateFlatNode(fm, lb, current_node, output); + generateFlatNode(fm, current_node, output); nextnode=fsen.getFlatExit().getNext(0); - } else if (state.DELAYCOMP) { - boolean specialprimitive=false; - //skip literals...no need to add extra overhead - if (storeset!=null&&storeset.contains(current_node)&¤t_node.kind()==FKind.FlatLiteralNode) { - TypeDescriptor typedesc=((FlatLiteralNode)current_node).getType(); - if (!typedesc.isClass()&&!typedesc.isArray()) { - specialprimitive=true; - } - } - - if (genset==null||genset.contains(current_node)||specialprimitive) - generateFlatNode(fm, lb, current_node, output); - if (state.STMARRAY&&!state.DUALVIEW&&refset!=null&&refset.contains(current_node)) { - //need to acquire lock - handleArrayDeref(fm, lb, current_node, output, firstpass); - } - if (storeset!=null&&storeset.contains(current_node)&&!specialprimitive) { - TempDescriptor wrtmp=current_node.writesTemps()[0]; - if (firstpass) { - //need to store value written by previous node - if (wrtmp.getType().isPtr()) { - //only lock the objects that may actually need locking - if (recorddc.getNeedTrans(lb, current_node)&& - (!state.STMARRAY||state.DUALVIEW||!wrtmp.getType().isArray()|| - wrtmp.getType().getSymbol().equals(TypeUtil.ObjectClass))) { - output.println("STOREPTR("+generateTemp(fm, wrtmp,lb)+");/* "+current_node.nodeid+" */"); - } else { - output.println("STOREPTRNOLOCK("+generateTemp(fm, wrtmp,lb)+");/* "+current_node.nodeid+" */"); - } - } else { - output.println("STORE"+wrtmp.getType().getSafeDescriptor()+"("+generateTemp(fm, wrtmp, lb)+");/* "+current_node.nodeid+" */"); - } - } else { - //need to read value read by previous node - if (wrtmp.getType().isPtr()) { - output.println("RESTOREPTR("+generateTemp(fm, wrtmp,lb)+");/* "+current_node.nodeid+" */"); - } else { - output.println("RESTORE"+wrtmp.getType().getSafeDescriptor()+"("+generateTemp(fm, wrtmp, lb)+"); /* "+current_node.nodeid+" */"); - } - } - } - nextnode=current_node.getNext(0); } else { output.print(" "); - generateFlatNode(fm, lb, current_node, output); + generateFlatNode(fm, current_node, output); nextnode=current_node.getNext(0); } if (visited.contains(nextnode)) { @@ -2247,165 +1707,19 @@ public class BuildCode { current_node=nextnode; } else if (current_node.numNext()==2) { /* Branch */ - if (state.DELAYCOMP) { - boolean computeside=false; - if (firstpass) { - //need to record which way it should go - if (genset==null||genset.contains(current_node)) { - if (storeset!=null&&storeset.contains(current_node)) { - //need to store which way branch goes - generateStoreFlatCondBranch(fm, lb, (FlatCondBranch)current_node, "L"+nodetolabel.get(current_node.getNext(1)), output); - } else - generateFlatCondBranch(fm, lb, (FlatCondBranch)current_node, "L"+nodetolabel.get(current_node.getNext(1)), output); - } else { - //which side to execute - computeside=true; - } - } else { - if (genset.contains(current_node)) { - generateFlatCondBranch(fm, lb, (FlatCondBranch)current_node, "L"+nodetolabel.get(current_node.getNext(1)), output); - } else if (storeset.contains(current_node)) { - //need to do branch - branchanalysis.generateGroupCode(current_node, output, nodetolabel); - } else { - //which side to execute - computeside=true; - } - } - if (computeside) { - Set leftset=DelayComputation.getNext(current_node, 0, unionset, lb,locality, true); - int branch=0; - if (leftset.size()==0) - branch=1; - if (visited.contains(current_node.getNext(branch))) { - //already visited -- build jump - output.println("goto L"+nodetolabel.get(current_node.getNext(branch))+";"); - current_node=null; - } else { - current_node=current_node.getNext(branch); - } - } else { - if (!visited.contains(current_node.getNext(1))) - tovisit.add(current_node.getNext(1)); - if (visited.contains(current_node.getNext(0))) { - output.println("goto L"+nodetolabel.get(current_node.getNext(0))+";"); - current_node=null; - } else - current_node=current_node.getNext(0); - } - } else { - output.print(" "); - generateFlatCondBranch(fm, lb, (FlatCondBranch)current_node, "L"+nodetolabel.get(current_node.getNext(1)), output); - if (!visited.contains(current_node.getNext(1))) - tovisit.add(current_node.getNext(1)); - if (visited.contains(current_node.getNext(0))) { - output.println("goto L"+nodetolabel.get(current_node.getNext(0))+";"); - current_node=null; - } else - current_node=current_node.getNext(0); - } + output.print(" "); + generateFlatCondBranch(fm, (FlatCondBranch)current_node, "L"+nodetolabel.get(current_node.getNext(1)), output); + if (!visited.contains(current_node.getNext(1))) + tovisit.add(current_node.getNext(1)); + if (visited.contains(current_node.getNext(0))) { + output.println("goto L"+nodetolabel.get(current_node.getNext(0))+";"); + current_node=null; + } else + current_node=current_node.getNext(0); } else throw new Error(); } } - protected void handleArrayDeref(FlatMethod fm, LocalityBinding lb, FlatNode fn, PrintWriter output, boolean firstpass) { - if (fn.kind()==FKind.FlatSetElementNode) { - FlatSetElementNode fsen=(FlatSetElementNode) fn; - String dst=generateTemp(fm, fsen.getDst(), lb); - String src=generateTemp(fm, fsen.getSrc(), lb); - String index=generateTemp(fm, fsen.getIndex(), lb); - TypeDescriptor elementtype=fsen.getDst().getType().dereference(); - String type=""; - if (elementtype.isArray()||elementtype.isClass()) - type="void *"; - else - type=elementtype.getSafeSymbol()+" "; - if (firstpass) { - output.println("STOREARRAY("+dst+","+index+","+type+")"); - } else { - output.println("{"); - output.println(" struct ArrayObject *array;"); - output.println(" int index;"); - output.println(" RESTOREARRAY(array,index);"); - output.println(" (("+type+"*)(((char *)&array->___length___)+sizeof(int)))[index]="+src+";"); - output.println("}"); - } - } else if (fn.kind()==FKind.FlatElementNode) { - FlatElementNode fen=(FlatElementNode) fn; - String src=generateTemp(fm, fen.getSrc(), lb); - String index=generateTemp(fm, fen.getIndex(), lb); - TypeDescriptor elementtype=fen.getSrc().getType().dereference(); - String dst=generateTemp(fm, fen.getDst(), lb); - String type=""; - if (elementtype.isArray()||elementtype.isClass()) - type="void *"; - else - type=elementtype.getSafeSymbol()+" "; - if (firstpass) { - output.println("STOREARRAY("+src+","+index+","+type+")"); - } else { - output.println("{"); - output.println(" struct ArrayObject *array;"); - output.println(" int index;"); - output.println(" RESTOREARRAY(array,index);"); - output.println(" "+dst+"=(("+type+"*)(((char *)&array->___length___)+sizeof(int)))[index];"); - output.println("}"); - } - } - } - /** Special label assignment for delaycomputation */ - protected Hashtable dcassignLabels(FlatNode first, Set lastset) { - HashSet tovisit=new HashSet(); - HashSet visited=new HashSet(); - int labelindex=0; - Hashtable nodetolabel=new Hashtable(); - - //Label targets of branches - Set targets=branchanalysis.getTargets(); - for(Iterator it=targets.iterator(); it.hasNext(); ) { - nodetolabel.put(it.next(), new Integer(labelindex++)); - } - - - tovisit.add(first); - /*Assign labels first. A node needs a label if the previous - * node has two exits or this node is a join point. */ - - while(!tovisit.isEmpty()) { - FlatNode fn=(FlatNode)tovisit.iterator().next(); - tovisit.remove(fn); - visited.add(fn); - - - if(lastset!=null&&lastset.contains(fn)) { - // if last is not null and matches, don't go - // any further for assigning labels - continue; - } - - for(int i=0; i0) { - //1) Edge >1 of node - nodetolabel.put(nn,new Integer(labelindex++)); - } - if (!visited.contains(nn)&&!tovisit.contains(nn)) { - tovisit.add(nn); - } else { - //2) Join point - nodetolabel.put(nn,new Integer(labelindex++)); - } - } - } - return nodetolabel; - - } - - protected Hashtable assignLabels(FlatNode first) { - return assignLabels(first, null); - } - protected Hashtable assignLabels(FlatNode first, Set lastset) { HashSet tovisit=new HashSet(); HashSet visited=new HashSet(); @@ -2446,12 +1760,11 @@ public class BuildCode { return nodetolabel; } - /** Generate text string that corresponds to the TempDescriptor td. */ - protected String generateTemp(FlatMethod fm, TempDescriptor td, LocalityBinding lb) { + protected String generateTemp(FlatMethod fm, TempDescriptor td) { MethodDescriptor md=fm.getMethod(); TaskDescriptor task=fm.getTask(); - TempObject objecttemps=(TempObject) tempstable.get(lb!=null ? lb : md!=null ? md : task); + TempObject objecttemps=(TempObject) tempstable.get(md!=null ? md : task); if (objecttemps.isLocalPrim(td)||objecttemps.isParamPrim(td)) { return td.getSafeSymbol(); @@ -2470,83 +1783,81 @@ public class BuildCode { - protected void generateFlatNode(FlatMethod fm, LocalityBinding lb, FlatNode fn, PrintWriter output) { - - - additionalCodePreNode(fm, lb, fn, output); + protected void generateFlatNode(FlatMethod fm, FlatNode fn, PrintWriter output) { + additionalCodePreNode(fm, fn, output); switch(fn.kind()) { case FKind.FlatAtomicEnterNode: - generateFlatAtomicEnterNode(fm, lb, (FlatAtomicEnterNode) fn, output); + generateFlatAtomicEnterNode(fm, (FlatAtomicEnterNode) fn, output); break; case FKind.FlatAtomicExitNode: - generateFlatAtomicExitNode(fm, lb, (FlatAtomicExitNode) fn, output); + generateFlatAtomicExitNode(fm, (FlatAtomicExitNode) fn, output); break; case FKind.FlatInstanceOfNode: - generateFlatInstanceOfNode(fm, lb, (FlatInstanceOfNode)fn, output); + generateFlatInstanceOfNode(fm, (FlatInstanceOfNode)fn, output); break; case FKind.FlatSESEEnterNode: - generateFlatSESEEnterNode(fm, lb, (FlatSESEEnterNode)fn, output); + generateFlatSESEEnterNode(fm, (FlatSESEEnterNode)fn, output); break; case FKind.FlatSESEExitNode: - generateFlatSESEExitNode(fm, lb, (FlatSESEExitNode)fn, output); + generateFlatSESEExitNode(fm, (FlatSESEExitNode)fn, output); break; case FKind.FlatWriteDynamicVarNode: - generateFlatWriteDynamicVarNode(fm, lb, (FlatWriteDynamicVarNode)fn, output); + generateFlatWriteDynamicVarNode(fm, (FlatWriteDynamicVarNode)fn, output); break; case FKind.FlatGlobalConvNode: - generateFlatGlobalConvNode(fm, lb, (FlatGlobalConvNode) fn, output); + generateFlatGlobalConvNode(fm, (FlatGlobalConvNode) fn, output); break; case FKind.FlatTagDeclaration: - generateFlatTagDeclaration(fm, lb, (FlatTagDeclaration) fn,output); + generateFlatTagDeclaration(fm, (FlatTagDeclaration) fn,output); break; case FKind.FlatCall: - generateFlatCall(fm, lb, (FlatCall) fn,output); + generateFlatCall(fm, (FlatCall) fn,output); break; case FKind.FlatFieldNode: - generateFlatFieldNode(fm, lb, (FlatFieldNode) fn,output); + generateFlatFieldNode(fm, (FlatFieldNode) fn,output); break; case FKind.FlatElementNode: - generateFlatElementNode(fm, lb, (FlatElementNode) fn,output); + generateFlatElementNode(fm, (FlatElementNode) fn,output); break; case FKind.FlatSetElementNode: - generateFlatSetElementNode(fm, lb, (FlatSetElementNode) fn,output); + generateFlatSetElementNode(fm, (FlatSetElementNode) fn,output); break; case FKind.FlatSetFieldNode: - generateFlatSetFieldNode(fm, lb, (FlatSetFieldNode) fn,output); + generateFlatSetFieldNode(fm, (FlatSetFieldNode) fn,output); break; case FKind.FlatNew: - generateFlatNew(fm, lb, (FlatNew) fn,output); + generateFlatNew(fm, (FlatNew) fn,output); break; case FKind.FlatOpNode: - generateFlatOpNode(fm, lb, (FlatOpNode) fn,output); + generateFlatOpNode(fm, (FlatOpNode) fn,output); break; case FKind.FlatCastNode: - generateFlatCastNode(fm, lb, (FlatCastNode) fn,output); + generateFlatCastNode(fm, (FlatCastNode) fn,output); break; case FKind.FlatLiteralNode: - generateFlatLiteralNode(fm, lb, (FlatLiteralNode) fn,output); + generateFlatLiteralNode(fm, (FlatLiteralNode) fn,output); break; case FKind.FlatReturnNode: - generateFlatReturnNode(fm, lb, (FlatReturnNode) fn,output); + generateFlatReturnNode(fm, (FlatReturnNode) fn,output); break; case FKind.FlatNop: @@ -2563,257 +1874,59 @@ public class BuildCode { break; case FKind.FlatBackEdge: - if (state.SINGLETM&&state.SANDBOX&&(locality.getAtomic(lb).get(fn).intValue()>0)) { - output.println("if (unlikely((--transaction_check_counter)<=0)) checkObjects();"); - } - if(state.DSM&&state.SANDBOX&&(locality.getAtomic(lb).get(fn).intValue()>0)) { - output.println("if (unlikely((--transaction_check_counter)<=0)) checkObjects();"); - } - if (((state.OOOJAVA||state.THREAD||state.DSM||state.SINGLETM)&&GENERATEPRECISEGC) - || (this.state.MULTICOREGC)) { - if(state.DSM&&locality.getAtomic(lb).get(fn).intValue()>0) { - output.println("if (needtocollect) checkcollect2("+localsprefixaddr+");"); - } else if(this.state.MULTICOREGC) { - output.println("if (gcflag) gc("+localsprefixaddr+");"); - } else { - output.println("if (unlikely(needtocollect)) checkcollect("+localsprefixaddr+");"); - } - } else - output.println("/* nop */"); + generateFlatBackEdge(fm, (FlatBackEdge)fn, output); break; case FKind.FlatCheckNode: - generateFlatCheckNode(fm, lb, (FlatCheckNode) fn, output); + generateFlatCheckNode(fm, (FlatCheckNode) fn, output); break; case FKind.FlatFlagActionNode: - generateFlatFlagActionNode(fm, lb, (FlatFlagActionNode) fn, output); + generateFlatFlagActionNode(fm, (FlatFlagActionNode) fn, output); break; case FKind.FlatPrefetchNode: - generateFlatPrefetchNode(fm,lb, (FlatPrefetchNode) fn, output); + generateFlatPrefetchNode(fm, (FlatPrefetchNode) fn, output); break; case FKind.FlatOffsetNode: - generateFlatOffsetNode(fm, lb, (FlatOffsetNode)fn, output); + generateFlatOffsetNode(fm, (FlatOffsetNode)fn, output); break; default: throw new Error(); } + additionalCodePostNode(fm, fn, output); + } - additionalCodePostNode(fm, lb, fn, output); + public void generateFlatBackEdge(FlatMethod fm, FlatBackEdge fn, PrintWriter output) { + if (((state.OOOJAVA||state.THREAD)&&GENERATEPRECISEGC) + || (this.state.MULTICOREGC)) { + if(this.state.MULTICOREGC) { + output.println("if (gcflag) gc("+localsprefixaddr+");"); + } else { + output.println("if (unlikely(needtocollect)) checkcollect("+localsprefixaddr+");"); + } + } else + output.println("/* nop */"); } - public void generateFlatOffsetNode(FlatMethod fm, LocalityBinding lb, FlatOffsetNode fofn, PrintWriter output) { + public void generateFlatOffsetNode(FlatMethod fm, FlatOffsetNode fofn, PrintWriter output) { output.println("/* FlatOffsetNode */"); FieldDescriptor fd=fofn.getField(); - output.println(generateTemp(fm, fofn.getDst(),lb)+ " = (short)(int) (&((struct "+fofn.getClassType().getSafeSymbol() +" *)0)->"+ + output.println(generateTemp(fm, fofn.getDst())+ " = (short)(int) (&((struct "+fofn.getClassType().getSafeSymbol() +" *)0)->"+ fd.getSafeSymbol()+");"); output.println("/* offset */"); } - public void generateFlatPrefetchNode(FlatMethod fm, LocalityBinding lb, FlatPrefetchNode fpn, PrintWriter output) { - if (state.PREFETCH) { - Vector oids = new Vector(); - Vector fieldoffset = new Vector(); - Vector endoffset = new Vector(); - int tuplecount = 0; //Keeps track of number of prefetch tuples that need to be generated - for(Iterator it = fpn.hspp.iterator(); it.hasNext(); ) { - PrefetchPair pp = (PrefetchPair) it.next(); - Integer statusbase = locality.getNodePreTempInfo(lb,fpn).get(pp.base); - /* Find prefetches that can generate oid */ - if(statusbase == LocalityAnalysis.GLOBAL) { - generateTransCode(fm, lb, pp, oids, fieldoffset, endoffset, tuplecount, locality.getAtomic(lb).get(fpn).intValue()>0, false); - tuplecount++; - } else if (statusbase == LocalityAnalysis.LOCAL) { - generateTransCode(fm,lb,pp,oids,fieldoffset,endoffset,tuplecount,false,true); - } else { - continue; - } - } - if (tuplecount==0) - return; - System.out.println("Adding prefetch "+fpn+ " to method:" +fm); - output.println("{"); - output.println("/* prefetch */"); - output.println("/* prefetchid_" + fpn.siteid + " */"); - output.println("void * prefptr;"); - output.println("int tmpindex;"); - - output.println("if((evalPrefetch["+fpn.siteid+"].operMode) || (evalPrefetch["+fpn.siteid+"].retrycount <= 0)) {"); - /*Create C code for oid array */ - output.print(" unsigned int oidarray_[] = {"); - boolean needcomma=false; - for (Iterator it = oids.iterator(); it.hasNext(); ) { - if (needcomma) - output.print(", "); - output.print(it.next()); - needcomma=true; - } - output.println("};"); - - /*Create C code for endoffset values */ - output.print(" unsigned short endoffsetarry_[] = {"); - needcomma=false; - for (Iterator it = endoffset.iterator(); it.hasNext(); ) { - if (needcomma) - output.print(", "); - output.print(it.next()); - needcomma=true; - } - output.println("};"); - - /*Create C code for Field Offset Values */ - output.print(" short fieldarry_[] = {"); - needcomma=false; - for (Iterator it = fieldoffset.iterator(); it.hasNext(); ) { - if (needcomma) - output.print(", "); - output.print(it.next()); - needcomma=true; - } - output.println("};"); - /* make the prefetch call to Runtime */ - output.println(" if(!evalPrefetch["+fpn.siteid+"].operMode) {"); - output.println(" evalPrefetch["+fpn.siteid+"].retrycount = RETRYINTERVAL;"); - output.println(" }"); - output.println(" prefetch("+fpn.siteid+" ,"+tuplecount+", oidarray_, endoffsetarry_, fieldarry_);"); - output.println(" } else {"); - output.println(" evalPrefetch["+fpn.siteid+"].retrycount--;"); - output.println(" }"); - output.println("}"); - } + public void generateFlatPrefetchNode(FlatMethod fm, FlatPrefetchNode fpn, PrintWriter output) { } - public void generateTransCode(FlatMethod fm, LocalityBinding lb,PrefetchPair pp, Vector oids, Vector fieldoffset, Vector endoffset, int tuplecount, boolean inside, boolean localbase) { - short offsetcount = 0; - int breakindex=0; - if (inside) { - breakindex=1; - } else if (localbase) { - for(; breakindexpp.desc.size()) //all local - return; - - TypeDescriptor lasttype=pp.base.getType(); - String basestr=generateTemp(fm, pp.base, lb); - String teststr=""; - boolean maybenull=fm.getMethod().isStatic()|| - !pp.base.equals(fm.getParameter(0)); - - for(int i=0; i"+ - fd.getSafeSymbol(); - } else { - basestr=basestr+"->"+ - fd.getSafeSymbol(); - maybenull=true; - } - lasttype=fd.getType(); - } else { - IndexDescriptor id=(IndexDescriptor)desc; - indexcheck="((tmpindex="; - for(int j=0; j=0)&(tmpindex<((struct ArrayObject *)prefptr)->___length___)"; - - if (!teststr.equals("")) - teststr+="&&"; - teststr+="((prefptr="+basestr+")!= NULL) &&"+indexcheck; - basestr="((void **)(((char *) &(((struct ArrayObject *)prefptr)->___length___))+sizeof(int)))[tmpindex]"; - maybenull=true; - lasttype=lasttype.dereference(); - } - } - - String oid; - if (teststr.equals("")) { - oid="((unsigned int)"+basestr+")"; - } else { - oid="((unsigned int)(("+teststr+")?"+basestr+":NULL))"; - } - oids.add(oid); - - for(int i = breakindex; i < pp.desc.size(); i++) { - String newfieldoffset; - Object desc = pp.getDescAt(i); - if(desc instanceof FieldDescriptor) { - FieldDescriptor fd=(FieldDescriptor)desc; - newfieldoffset = new String("(unsigned int)(&(((struct "+ lasttype.getSafeSymbol()+" *)0)->"+ fd.getSafeSymbol()+ "))"); - lasttype=fd.getType(); - } else { - newfieldoffset = ""; - IndexDescriptor id=(IndexDescriptor)desc; - for(int j = 0; j < id.tddesc.size(); j++) { - newfieldoffset += generateTemp(fm, id.getTempDescAt(j), lb) + "+"; - } - newfieldoffset += id.offset.toString(); - lasttype=lasttype.dereference(); - } - fieldoffset.add(newfieldoffset); - } - - int base=(tuplecount>0) ? ((Short)endoffset.get(tuplecount-1)).intValue() : 0; - base+=pp.desc.size()-breakindex; - endoffset.add(new Short((short)base)); - } - - - - public void generateFlatGlobalConvNode(FlatMethod fm, LocalityBinding lb, FlatGlobalConvNode fgcn, PrintWriter output) { - if (lb!=fgcn.getLocality()) - return; - /* Have to generate flat globalconv */ - if (fgcn.getMakePtr()) { - if (state.DSM) { - output.println("TRANSREAD("+generateTemp(fm, fgcn.getSrc(),lb)+", (unsigned int) "+generateTemp(fm, fgcn.getSrc(),lb)+");"); - } else { - if ((dc==null)||!state.READSET&&dc.getNeedTrans(lb, fgcn)||state.READSET&&dc.getNeedWriteTrans(lb, fgcn)) { - //need to do translation - output.println("TRANSREAD("+generateTemp(fm, fgcn.getSrc(),lb)+", "+generateTemp(fm, fgcn.getSrc(),lb)+", (void *)("+localsprefixaddr+"));"); - } else if (state.READSET&&dc.getNeedTrans(lb, fgcn)) { - if (state.HYBRID&&delaycomp.getConv(lb).contains(fgcn)) { - output.println("TRANSREADRDFISSION("+generateTemp(fm, fgcn.getSrc(),lb)+", "+generateTemp(fm, fgcn.getSrc(),lb)+");"); - } else - output.println("TRANSREADRD("+generateTemp(fm, fgcn.getSrc(),lb)+", "+generateTemp(fm, fgcn.getSrc(),lb)+");"); - } - } - } else { - /* Need to convert to OID */ - if ((dc==null)||dc.getNeedSrcTrans(lb,fgcn)) { - if (fgcn.doConvert()||(delaycomp!=null&&delaycomp.needsFission(lb, fgcn.getAtomicEnter())&&atomicmethodmap.get(fgcn.getAtomicEnter()).reallivein.contains(fgcn.getSrc()))) { - output.println(generateTemp(fm, fgcn.getSrc(),lb)+"=(void *)COMPOID("+generateTemp(fm, fgcn.getSrc(),lb)+");"); - } else { - output.println(generateTemp(fm, fgcn.getSrc(),lb)+"=NULL;"); - } - } - } + public void generateFlatGlobalConvNode(FlatMethod fm, FlatGlobalConvNode fgcn, PrintWriter output) { } - public void generateFlatInstanceOfNode(FlatMethod fm, LocalityBinding lb, FlatInstanceOfNode fion, PrintWriter output) { + public void generateFlatInstanceOfNode(FlatMethod fm, FlatInstanceOfNode fion, PrintWriter output) { int type; if (fion.getType().isArray()) { type=state.getArrayNumber(fion.getType())+state.numClasses(); @@ -2822,166 +1935,18 @@ public class BuildCode { } if (fion.getType().getSymbol().equals(TypeUtil.ObjectClass)) - output.println(generateTemp(fm, fion.getDst(), lb)+"=1;"); + output.println(generateTemp(fm, fion.getDst())+"=1;"); else - output.println(generateTemp(fm, fion.getDst(), lb)+"=instanceof("+generateTemp(fm,fion.getSrc(),lb)+","+type+");"); + output.println(generateTemp(fm, fion.getDst())+"=instanceof("+generateTemp(fm,fion.getSrc())+","+type+");"); } - int sandboxcounter=0; - public void generateFlatAtomicEnterNode(FlatMethod fm, LocalityBinding lb, FlatAtomicEnterNode faen, PrintWriter output) { - /* Check to see if we need to generate code for this atomic */ - if (locality==null) { - if (GENERATEPRECISEGC) { - output.println("if (pthread_mutex_trylock(&atomiclock)!=0) {"); - output.println("stopforgc((struct garbagelist *) &___locals___);"); - output.println("pthread_mutex_lock(&atomiclock);"); - output.println("restartaftergc();"); - output.println("}"); - } else { - output.println("pthread_mutex_lock(&atomiclock);"); - } - return; - } - - if (locality.getAtomic(lb).get(faen.getPrev(0)).intValue()>0) - return; - - - if (state.SANDBOX) { - outsandbox.println("int atomiccounter"+sandboxcounter+"=LOW_CHECK_FREQUENCY;"); - output.println("counter_reset_pointer=&atomiccounter"+sandboxcounter+";"); - } - - if (state.DELAYCOMP&&delaycomp.needsFission(lb, faen)) { - AtomicRecord ar=atomicmethodmap.get(faen); - //copy in - for(Iterator tmpit=ar.livein.iterator(); tmpit.hasNext(); ) { - TempDescriptor tmp=tmpit.next(); - output.println("primitives_"+ar.name+"."+tmp.getSafeSymbol()+"="+tmp.getSafeSymbol()+";"); - } - - //copy outs that depend on path - for(Iterator tmpit=ar.liveoutvirtualread.iterator(); tmpit.hasNext(); ) { - TempDescriptor tmp=tmpit.next(); - if (!ar.livein.contains(tmp)) - output.println("primitives_"+ar.name+"."+tmp.getSafeSymbol()+"="+tmp.getSafeSymbol()+";"); - } - } - - /* Backup the temps. */ - for(Iterator tmpit=locality.getTemps(lb).get(faen).iterator(); tmpit.hasNext(); ) { - TempDescriptor tmp=tmpit.next(); - output.println(generateTemp(fm, backuptable.get(lb).get(tmp),lb)+"="+generateTemp(fm,tmp,lb)+";"); - } - - output.println("goto transstart"+faen.getIdentifier()+";"); - - /******* Print code to retry aborted transaction *******/ - output.println("transretry"+faen.getIdentifier()+":"); - - /* Restore temps */ - for(Iterator tmpit=locality.getTemps(lb).get(faen).iterator(); tmpit.hasNext(); ) { - TempDescriptor tmp=tmpit.next(); - output.println(generateTemp(fm, tmp,lb)+"="+generateTemp(fm,backuptable.get(lb).get(tmp),lb)+";"); - } - - if (state.DSM) { - /********* Need to revert local object store ********/ - String revertptr=generateTemp(fm, reverttable.get(lb),lb); - - output.println("while ("+revertptr+") {"); - output.println("struct ___Object___ * tmpptr;"); - output.println("tmpptr="+revertptr+"->"+nextobjstr+";"); - output.println("REVERT_OBJ("+revertptr+");"); - output.println(revertptr+"=tmpptr;"); - output.println("}"); - } - /******* Tell the runtime to start the transaction *******/ - - output.println("transstart"+faen.getIdentifier()+":"); - if (state.SANDBOX) { - output.println("transaction_check_counter=*counter_reset_pointer;"); - sandboxcounter++; - } - output.println("transStart();"); - - if (state.ABORTREADERS||state.SANDBOX) { - if (state.SANDBOX) - output.println("abortenabled=1;"); - output.println("if (_setjmp(aborttrans)) {"); - output.println(" goto transretry"+faen.getIdentifier()+"; }"); - } + public void generateFlatAtomicEnterNode(FlatMethod fm, FlatAtomicEnterNode faen, PrintWriter output) { } - public void generateFlatAtomicExitNode(FlatMethod fm, LocalityBinding lb, FlatAtomicExitNode faen, PrintWriter output) { - /* Check to see if we need to generate code for this atomic */ - if (locality==null) { - output.println("pthread_mutex_unlock(&atomiclock);"); - return; - } - if (locality.getAtomic(lb).get(faen).intValue()>0) - return; - //store the revert list before we lose the transaction object - - if (state.DSM) { - String revertptr=generateTemp(fm, reverttable.get(lb),lb); - output.println(revertptr+"=revertlist;"); - output.println("if (transCommit()) {"); - output.println("if (unlikely(needtocollect)) checkcollect("+localsprefixaddr+");"); - output.println("goto transretry"+faen.getAtomicEnter().getIdentifier()+";"); - output.println("} else {"); - /* Need to commit local object store */ - output.println("while ("+revertptr+") {"); - output.println("struct ___Object___ * tmpptr;"); - output.println("tmpptr="+revertptr+"->"+nextobjstr+";"); - output.println("COMMIT_OBJ("+revertptr+");"); - output.println(revertptr+"=tmpptr;"); - output.println("}"); - output.println("}"); - return; - } - - if (!state.DELAYCOMP) { - //Normal STM stuff - output.println("if (transCommit()) {"); - /* Transaction aborts if it returns true */ - output.println("if (unlikely(needtocollect)) checkcollect("+localsprefixaddr+");"); - output.println("goto transretry"+faen.getAtomicEnter().getIdentifier()+";"); - output.println("}"); - } else { - if (delaycomp.optimizeTrans(lb, faen.getAtomicEnter())&&(!state.STMARRAY||state.DUALVIEW)) { - AtomicRecord ar=atomicmethodmap.get(faen.getAtomicEnter()); - output.println("LIGHTWEIGHTCOMMIT("+ar.name+", &primitives_"+ar.name+", &"+localsprefix+", "+paramsprefix+", transretry"+faen.getAtomicEnter().getIdentifier()+");"); - //copy out - for(Iterator tmpit=ar.liveout.iterator(); tmpit.hasNext(); ) { - TempDescriptor tmp=tmpit.next(); - output.println(tmp.getSafeSymbol()+"=primitives_"+ar.name+"."+tmp.getSafeSymbol()+";"); - } - } else if (delaycomp.needsFission(lb, faen.getAtomicEnter())) { - AtomicRecord ar=atomicmethodmap.get(faen.getAtomicEnter()); - //do call - output.println("if (transCommit((void (*)(void *, void *, void *))&"+ar.name+", &primitives_"+ar.name+", &"+localsprefix+", "+paramsprefix+")) {"); - output.println("if (unlikely(needtocollect)) checkcollect("+localsprefixaddr+");"); - output.println("goto transretry"+faen.getAtomicEnter().getIdentifier()+";"); - output.println("}"); - //copy out - output.println("else {"); - for(Iterator tmpit=ar.liveout.iterator(); tmpit.hasNext(); ) { - TempDescriptor tmp=tmpit.next(); - output.println(tmp.getSafeSymbol()+"=primitives_"+ar.name+"."+tmp.getSafeSymbol()+";"); - } - output.println("}"); - } else { - output.println("if (transCommit(NULL, NULL, NULL, NULL)) {"); - output.println("if (unlikely(needtocollect)) checkcollect("+localsprefixaddr+");"); - output.println("goto transretry"+faen.getAtomicEnter().getIdentifier()+";"); - output.println("}"); - } - } + public void generateFlatAtomicExitNode(FlatMethod fm, FlatAtomicExitNode faen, PrintWriter output) { } public void generateFlatSESEEnterNode(FlatMethod fm, - LocalityBinding lb, FlatSESEEnterNode fsen, PrintWriter output) { // if OOOJAVA flag is off, okay that SESE nodes are in IR graph, @@ -2989,7 +1954,6 @@ public class BuildCode { } public void generateFlatSESEExitNode(FlatMethod fm, - LocalityBinding lb, FlatSESEExitNode fsexn, PrintWriter output) { // if OOOJAVA flag is off, okay that SESE nodes are in IR graph, @@ -2997,19 +1961,12 @@ public class BuildCode { } public void generateFlatWriteDynamicVarNode(FlatMethod fm, - LocalityBinding lb, FlatWriteDynamicVarNode fwdvn, - PrintWriter output - ) { - if( !state.OOOJAVA ) { - // should node should not be in an IR graph if the - // OOOJAVA flag is not set - throw new Error("Unexpected presence of FlatWriteDynamicVarNode"); - } + PrintWriter output) { } - private void generateFlatCheckNode(FlatMethod fm, LocalityBinding lb, FlatCheckNode fcn, PrintWriter output) { + protected void generateFlatCheckNode(FlatMethod fm, FlatCheckNode fcn, PrintWriter output) { if (state.CONSCHECK) { String specname=fcn.getSpec(); String varname="repairstate___"; @@ -3019,7 +1976,7 @@ public class BuildCode { TempDescriptor[] temps=fcn.getTemps(); String[] vars=fcn.getVars(); for(int i=0; i"+vars[i]+"=(unsigned int)"+generateTemp(fm, temps[i],lb)+";"); + output.println(varname+"->"+vars[i]+"=(unsigned int)"+generateTemp(fm, temps[i])+";"); } output.println("if (doanalysis"+specname+"("+varname+")) {"); @@ -3033,10 +1990,9 @@ public class BuildCode { } } - private void generateFlatCall(FlatMethod fm, LocalityBinding lb, FlatCall fc, PrintWriter output) { - + protected void generateFlatCall(FlatMethod fm, FlatCall fc, PrintWriter output) { MethodDescriptor md=fc.getMethod(); - ParamsObject objectparams=(ParamsObject)paramstable.get(lb!=null ? locality.getBinding(lb, fc) : md); + ParamsObject objectparams=(ParamsObject)paramstable.get(md); ClassDescriptor cn=md.getClassDesc(); // if the called method is a static block or a static method or a constructor @@ -3081,16 +2037,12 @@ public class BuildCode { output.println("{"); if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { - if (lb!=null) { - LocalityBinding fclb=locality.getBinding(lb, fc); - output.print(" struct "+cn.getSafeSymbol()+fclb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={"); - } else - output.print(" struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={"); + output.print(" struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={"); output.print(objectparams.numPointers()); output.print(", "+localsprefixaddr); if (md.getThis()!=null) { output.print(", "); - output.print("(struct "+md.getThis().getType().getSafeSymbol() +" *)"+ generateTemp(fm,fc.getThis(),lb)); + output.print("(struct "+md.getThis().getType().getSafeSymbol() +" *)"+ generateTemp(fm,fc.getThis())); } if (fc.getThis()!=null&&md.getThis()==null) { System.out.println("WARNING!!!!!!!!!!!!"); @@ -3106,9 +2058,9 @@ public class BuildCode { output.print(", "); TypeDescriptor td=md.getParamType(i); if (td.isTag()) - output.print("(struct "+(new TypeDescriptor(typeutil.getClass(TypeUtil.TagClass))).getSafeSymbol() +" *)"+generateTemp(fm, targ,lb)); + output.print("(struct "+(new TypeDescriptor(typeutil.getClass(TypeUtil.TagClass))).getSafeSymbol() +" *)"+generateTemp(fm, targ)); else - output.print("(struct "+md.getParamType(i).getSafeSymbol() +" *)"+generateTemp(fm, targ,lb)); + output.print("(struct "+md.getParamType(i).getSafeSymbol() +" *)"+generateTemp(fm, targ)); } } output.println("};"); @@ -3117,17 +2069,12 @@ public class BuildCode { if (fc.getReturnTemp()!=null) - output.print(generateTemp(fm,fc.getReturnTemp(),lb)+"="); + output.print(generateTemp(fm,fc.getReturnTemp())+"="); /* Do we need to do virtual dispatch? */ if (md.isStatic()||md.getReturnType()==null||singleCall(fc.getThis().getType().getClassDesc(),md)) { //no - if (lb!=null) { - LocalityBinding fclb=locality.getBinding(lb, fc); - output.print(cn.getSafeSymbol()+fclb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()); - } else { - output.print(cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()); - } + output.print(cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()); } else { //yes output.print("(("); @@ -3141,11 +2088,7 @@ public class BuildCode { boolean printcomma=false; if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { - if (lb!=null) { - LocalityBinding fclb=locality.getBinding(lb, fc); - output.print("struct "+cn.getSafeSymbol()+fclb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params * "); - } else - output.print("struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params * "); + output.print("struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params * "); printcomma=true; } @@ -3163,11 +2106,7 @@ public class BuildCode { } - if (lb!=null) { - LocalityBinding fclb=locality.getBinding(lb, fc); - output.print("))virtualtable["+generateTemp(fm,fc.getThis(),lb)+"->type*"+maxcount+"+"+virtualcalls.getLocalityNumber(fclb)+"])"); - } else - output.print("))virtualtable["+generateTemp(fm,fc.getThis(),lb)+"->type*"+maxcount+"+"+virtualcalls.getMethodNumber(md)+"])"); + output.print("))virtualtable["+generateTemp(fm,fc.getThis())+"->type*"+maxcount+"+"+virtualcalls.getMethodNumber(md)+"])"); } output.print("("); @@ -3191,7 +2130,7 @@ public class BuildCode { // do nothing } else if (ptd.isClass()&&!ptd.isArray()) output.print("(struct "+ptd.getSafeSymbol()+" *) "); - output.print(generateTemp(fm,fc.getThis(),lb)); + output.print(generateTemp(fm,fc.getThis())); needcomma=true; } } @@ -3209,7 +2148,7 @@ public class BuildCode { // do nothing } else if (ptd.isClass()&&!ptd.isArray()) output.print("(struct "+ptd.getSafeSymbol()+" *) "); - output.print(generateTemp(fm, targ,lb)); + output.print(generateTemp(fm, targ)); needcomma=true; } } @@ -3217,7 +2156,7 @@ public class BuildCode { output.println(" }"); } - private boolean singleCall(ClassDescriptor thiscd, MethodDescriptor md) { + protected boolean singleCall(ClassDescriptor thiscd, MethodDescriptor md) { Set subclasses=typeutil.getSubClasses(thiscd); if (subclasses==null) return true; @@ -3233,262 +2172,120 @@ public class BuildCode { return true; } - private void generateFlatFieldNode(FlatMethod fm, LocalityBinding lb, FlatFieldNode ffn, PrintWriter output) { - if (state.SINGLETM) { - //single machine transactional memory case - String field=ffn.getField().getSafeSymbol(); - String src=generateTemp(fm, ffn.getSrc(),lb); - String dst=generateTemp(fm, ffn.getDst(),lb); - - output.println(dst+"="+ src +"->"+field+ ";"); - if (ffn.getField().getType().isPtr()&&locality.getAtomic(lb).get(ffn).intValue()>0&& - locality.getNodePreTempInfo(lb, ffn).get(ffn.getSrc())!=LocalityAnalysis.SCRATCH) { - if ((dc==null)||(!state.READSET&&dc.getNeedTrans(lb, ffn))|| - (state.READSET&&dc.getNeedWriteTrans(lb, ffn))) { - output.println("TRANSREAD("+dst+", "+dst+", (void *) (" + localsprefixaddr + "));"); - } else if (state.READSET&&dc.getNeedTrans(lb, ffn)) { - if (state.HYBRID&&delaycomp.getConv(lb).contains(ffn)) { - output.println("TRANSREADRDFISSION("+dst+", "+dst+");"); - } else - output.println("TRANSREADRD("+dst+", "+dst+");"); - } - } - } else if (state.DSM) { - Integer status=locality.getNodePreTempInfo(lb,ffn).get(ffn.getSrc()); - if (status==LocalityAnalysis.GLOBAL) { - String field=ffn.getField().getSafeSymbol(); - String src=generateTemp(fm, ffn.getSrc(),lb); - String dst=generateTemp(fm, ffn.getDst(),lb); - - if (ffn.getField().getType().isPtr()) { - output.println(dst+"="+ src +"->"+field+ ";"); - output.println("TRANSREAD("+dst+", (unsigned int) "+dst+");"); - } else { - output.println(dst+"="+ src+"->"+field+";"); - } - } else if (status==LocalityAnalysis.LOCAL) { - if (ffn.getField().getType().isPtr()&& - ffn.getField().isGlobal()) { - String field=ffn.getField().getSafeSymbol(); - String src=generateTemp(fm, ffn.getSrc(),lb); - String dst=generateTemp(fm, ffn.getDst(),lb); - output.println(dst+"="+ src +"->"+field+ ";"); - if (locality.getAtomic(lb).get(ffn).intValue()>0) - output.println("TRANSREAD("+dst+", (unsigned int) "+dst+");"); - } else - output.println(generateTemp(fm, ffn.getDst(),lb)+"="+ generateTemp(fm,ffn.getSrc(),lb)+"->"+ ffn.getField().getSafeSymbol()+";"); - } else if (status==LocalityAnalysis.EITHER) { - //Code is reading from a null pointer - output.println("if ("+generateTemp(fm, ffn.getSrc(),lb)+") {"); - output.println("#ifndef RAW"); - output.println("printf(\"BIG ERROR\\n\");exit(-1);}"); - output.println("#endif"); - //This should throw a suitable null pointer error - output.println(generateTemp(fm, ffn.getDst(),lb)+"="+ generateTemp(fm,ffn.getSrc(),lb)+"->"+ ffn.getField().getSafeSymbol()+";"); - } else - throw new Error("Read from non-global/non-local in:"+lb.getExplanation()); - } else { - if(state.MGC) { - // TODO add version for normal Java later - if(ffn.getField().isStatic()) { - // static field - if((fm.getMethod().isStaticBlock()) || (fm.getMethod().isInvokedByStatic())) { - // is a static block or is invoked in some static block - ClassDescriptor cd = fm.getMethod().getClassDesc(); - ClassDescriptor cn = ffn.getSrc().getType().getClassDesc(); - if(cd == cn) { - // the same class, do nothing - // TODO may want to invoke static field initialization here - } else { - if((cn.getNumStaticFields() != 0) || (cn.getNumStaticBlocks() != 0)) { - // need to check if the class' static fields have been initialized and/or - // its static blocks have been executed - output.println("#ifdef MGC_STATIC_INIT_CHECK"); - output.println("if(global_defs_p->" + cn.getSafeSymbol()+"static_block_exe_flag == 0) {"); - if(cn.getNumStaticBlocks() != 0) { - MethodDescriptor t_md = (MethodDescriptor)cn.getMethodTable().get("staticblocks"); - output.println(" "+cn.getSafeSymbol()+t_md.getSafeSymbol()+"_"+t_md.getSafeMethodDescriptor()+"();"); - } else { - output.println(" global_defs_p->" + cn.getSafeSymbol()+"static_block_exe_flag = 1;"); - } - output.println("}"); - output.println("#endif // MGC_STATIC_INIT_CHECK"); + protected void generateFlatFieldNode(FlatMethod fm, FlatFieldNode ffn, PrintWriter output) { + if(state.MGC) { + // TODO add version for normal Java later + if(ffn.getField().isStatic()) { + // static field + if((fm.getMethod().isStaticBlock()) || (fm.getMethod().isInvokedByStatic())) { + // is a static block or is invoked in some static block + ClassDescriptor cd = fm.getMethod().getClassDesc(); + ClassDescriptor cn = ffn.getSrc().getType().getClassDesc(); + if(cd == cn) { + // the same class, do nothing + // TODO may want to invoke static field initialization here + } else { + if((cn.getNumStaticFields() != 0) || (cn.getNumStaticBlocks() != 0)) { + // need to check if the class' static fields have been initialized and/or + // its static blocks have been executed + output.println("#ifdef MGC_STATIC_INIT_CHECK"); + output.println("if(global_defs_p->" + cn.getSafeSymbol()+"static_block_exe_flag == 0) {"); + if(cn.getNumStaticBlocks() != 0) { + MethodDescriptor t_md = (MethodDescriptor)cn.getMethodTable().get("staticblocks"); + output.println(" "+cn.getSafeSymbol()+t_md.getSafeSymbol()+"_"+t_md.getSafeMethodDescriptor()+"();"); + } else { + output.println(" global_defs_p->" + cn.getSafeSymbol()+"static_block_exe_flag = 1;"); } + output.println("}"); + output.println("#endif // MGC_STATIC_INIT_CHECK"); } } - // redirect to the global_defs_p structure - if((ffn.getField().isStatic()) || (ffn.getSrc().getType().isClassNameRef())) { - // reference to the static field with Class name - output.println(generateTemp(fm, ffn.getDst(),lb)+"=global_defs_p->"+ffn.getField().getSafeSymbol()+";"); - } else { - output.println(generateTemp(fm, ffn.getDst(),lb)+"=*"+ generateTemp(fm,ffn.getSrc(),lb)+"->"+ ffn.getField().getSafeSymbol()+";"); - } - } else if (ffn.getField().isEnum()) { - // an Enum value, directly replace the field access as int - output.println(generateTemp(fm, ffn.getDst(), lb) + "=" + ffn.getField().enumValue() + ";"); + } + // redirect to the global_defs_p structure + if((ffn.getField().isStatic()) || (ffn.getSrc().getType().isClassNameRef())) { + // reference to the static field with Class name + output.println(generateTemp(fm, ffn.getDst())+"=global_defs_p->"+ffn.getField().getSafeSymbol()+";"); } else { - output.println(generateTemp(fm, ffn.getDst(),lb)+"="+ generateTemp(fm,ffn.getSrc(),lb)+"->"+ ffn.getField().getSafeSymbol()+";"); + output.println(generateTemp(fm, ffn.getDst())+"=*"+ generateTemp(fm,ffn.getSrc())+"->"+ ffn.getField().getSafeSymbol()+";"); } + } else if (ffn.getField().isEnum()) { + // an Enum value, directly replace the field access as int + output.println(generateTemp(fm, ffn.getDst()) + "=" + ffn.getField().enumValue() + ";"); } else { - output.println(generateTemp(fm, ffn.getDst(),lb)+"="+ generateTemp(fm,ffn.getSrc(),lb)+"->"+ ffn.getField().getSafeSymbol()+";"); + output.println(generateTemp(fm, ffn.getDst())+"="+ generateTemp(fm,ffn.getSrc())+"->"+ ffn.getField().getSafeSymbol()+";"); } + } else { + output.println(generateTemp(fm, ffn.getDst())+"="+ generateTemp(fm,ffn.getSrc())+"->"+ ffn.getField().getSafeSymbol()+";"); } } - private void generateFlatSetFieldNode(FlatMethod fm, LocalityBinding lb, FlatSetFieldNode fsfn, PrintWriter output) { + protected void generateFlatSetFieldNode(FlatMethod fm, FlatSetFieldNode fsfn, PrintWriter output) { if (fsfn.getField().getSymbol().equals("length")&&fsfn.getDst().getType().isArray()) throw new Error("Can't set array length"); - if (state.SINGLETM && locality.getAtomic(lb).get(fsfn).intValue()>0) { - //Single Machine Transaction Case - boolean srcptr=fsfn.getSrc().getType().isPtr(); - String src=generateTemp(fm,fsfn.getSrc(),lb); - String dst=generateTemp(fm,fsfn.getDst(),lb); - output.println("//"+srcptr+" "+fsfn.getSrc().getType().isNull()); - if (srcptr&&!fsfn.getSrc().getType().isNull()) { - output.println("{"); - if ((dc==null)||dc.getNeedSrcTrans(lb, fsfn)&& - locality.getNodePreTempInfo(lb, fsfn).get(fsfn.getSrc())!=LocalityAnalysis.SCRATCH) { - output.println("INTPTR srcoid=("+src+"!=NULL?((INTPTR)"+src+"->"+oidstr+"):0);"); - } else { - output.println("INTPTR srcoid=(INTPTR)"+src+";"); - } - } - if (wb.needBarrier(fsfn)&& - locality.getNodePreTempInfo(lb, fsfn).get(fsfn.getDst())!=LocalityAnalysis.SCRATCH) { - if (state.EVENTMONITOR) { - output.println("if ("+dst+"->___objstatus___&DIRTY) EVLOGEVENTOBJ(EV_WRITE,"+dst+"->objuid)"); - } - output.println("*((unsigned int *)&("+dst+"->___objstatus___))|=DIRTY;"); - } - if (srcptr&!fsfn.getSrc().getType().isNull()) { - output.println("*((unsigned INTPTR *)&("+dst+"->"+ - fsfn.getField().getSafeSymbol()+"))=srcoid;"); - output.println("}"); - } else { - output.println(dst+"->"+ - fsfn.getField().getSafeSymbol()+"="+ src+";"); - } - } else if (state.DSM && locality.getAtomic(lb).get(fsfn).intValue()>0) { - Integer statussrc=locality.getNodePreTempInfo(lb,fsfn).get(fsfn.getSrc()); - Integer statusdst=locality.getNodeTempInfo(lb).get(fsfn).get(fsfn.getDst()); - boolean srcglobal=statussrc==LocalityAnalysis.GLOBAL; - - String src=generateTemp(fm,fsfn.getSrc(),lb); - String dst=generateTemp(fm,fsfn.getDst(),lb); - if (srcglobal) { - output.println("{"); - output.println("INTPTR srcoid=("+src+"!=NULL?((INTPTR)"+src+"->"+oidstr+"):0);"); - } - if (statusdst.equals(LocalityAnalysis.GLOBAL)) { - String glbdst=dst; - //mark it dirty - if (wb.needBarrier(fsfn)) - output.println("*((unsigned int *)&("+dst+"->___localcopy___))|=DIRTY;"); - if (srcglobal) { - output.println("*((unsigned INTPTR *)&("+glbdst+"->"+ - fsfn.getField().getSafeSymbol()+"))=srcoid;"); - } else - output.println(glbdst+"->"+ - fsfn.getField().getSafeSymbol()+"="+ src+";"); - } else if (statusdst.equals(LocalityAnalysis.LOCAL)) { - /** Check if we need to copy */ - output.println("if(!"+dst+"->"+localcopystr+") {"); - /* Link object into list */ - String revertptr=generateTemp(fm, reverttable.get(lb),lb); - output.println(revertptr+"=revertlist;"); - if (GENERATEPRECISEGC || this.state.MULTICOREGC) - output.println("COPY_OBJ((struct garbagelist *)"+localsprefixaddr+",(struct ___Object___ *)"+dst+");"); - else - output.println("COPY_OBJ("+dst+");"); - output.println(dst+"->"+nextobjstr+"="+revertptr+";"); - output.println("revertlist=(struct ___Object___ *)"+dst+";"); - output.println("}"); - if (srcglobal) - output.println(dst+"->"+ - fsfn.getField().getSafeSymbol()+"=(void *) srcoid;"); - else - output.println(dst+"->"+ - fsfn.getField().getSafeSymbol()+"="+ src+";"); - } else if (statusdst.equals(LocalityAnalysis.EITHER)) { - //writing to a null...bad - output.println("if ("+dst+") {"); - output.println("printf(\"BIG ERROR 2\\n\");exit(-1);}"); - if (srcglobal) - output.println(dst+"->"+ - fsfn.getField().getSafeSymbol()+"=(void *) srcoid;"); - else - output.println(dst+"->"+ - fsfn.getField().getSafeSymbol()+"="+ src+";"); - } - if (srcglobal) { - output.println("}"); - } - } else { - if (state.FASTCHECK) { - String dst=generateTemp(fm, fsfn.getDst(),lb); - output.println("if(!"+dst+"->"+localcopystr+") {"); - /* Link object into list */ - if (GENERATEPRECISEGC || this.state.MULTICOREGC) - output.println("COPY_OBJ((struct garbagelist *)"+localsprefixaddr+",(struct ___Object___ *)"+dst+");"); - else - output.println("COPY_OBJ("+dst+");"); - output.println(dst+"->"+nextobjstr+"="+fcrevert+";"); - output.println(fcrevert+"=(struct ___Object___ *)"+dst+";"); - output.println("}"); - } - if(state.MGC) { - // TODO add version for normal Java later - if(fsfn.getField().isStatic()) { - // static field - if((fm.getMethod().isStaticBlock()) || (fm.getMethod().isInvokedByStatic())) { + if (state.FASTCHECK) { + String dst=generateTemp(fm, fsfn.getDst()); + output.println("if(!"+dst+"->"+localcopystr+") {"); + /* Link object into list */ + if (GENERATEPRECISEGC || this.state.MULTICOREGC) + output.println("COPY_OBJ((struct garbagelist *)"+localsprefixaddr+",(struct ___Object___ *)"+dst+");"); + else + output.println("COPY_OBJ("+dst+");"); + output.println(dst+"->"+nextobjstr+"="+fcrevert+";"); + output.println(fcrevert+"=(struct ___Object___ *)"+dst+";"); + output.println("}"); + } + if(state.MGC) { + // TODO add version for normal Java later + if(fsfn.getField().isStatic()) { + // static field + if((fm.getMethod().isStaticBlock()) || (fm.getMethod().isInvokedByStatic())) { // is a static block or is invoked in some static block - ClassDescriptor cd = fm.getMethod().getClassDesc(); - ClassDescriptor cn = fsfn.getDst().getType().getClassDesc(); - if(cd == cn) { - // the same class, do nothing - // TODO may want to invoke static field initialization here - } else { - if((cn.getNumStaticFields() != 0) || (cn.getNumStaticBlocks() != 0)) { - // need to check if the class' static fields have been initialized and/or - // its static blocks have been executed - output.println("#ifdef MGC_STATIC_INIT_CHECK"); - output.println("if(global_defs_p->" + cn.getSafeSymbol()+"static_block_exe_flag == 0) {"); - if(cn.getNumStaticFields() != 0) { - // TODO add static field initialization here - } - if(cn.getNumStaticBlocks() != 0) { - MethodDescriptor t_md = (MethodDescriptor)cn.getMethodTable().get("staticblocks"); - output.println(" "+cn.getSafeSymbol()+t_md.getSafeSymbol()+"_"+t_md.getSafeMethodDescriptor()+"();"); - } else { - output.println(" global_defs_p->" + cn.getSafeSymbol()+"static_block_exe_flag = 1;"); - } - output.println("}"); - output.println("#endif // MGC_STATIC_INIT_CHECK"); + ClassDescriptor cd = fm.getMethod().getClassDesc(); + ClassDescriptor cn = fsfn.getDst().getType().getClassDesc(); + if(cd == cn) { + // the same class, do nothing + // TODO may want to invoke static field initialization here + } else { + if((cn.getNumStaticFields() != 0) || (cn.getNumStaticBlocks() != 0)) { + // need to check if the class' static fields have been initialized and/or + // its static blocks have been executed + output.println("#ifdef MGC_STATIC_INIT_CHECK"); + output.println("if(global_defs_p->" + cn.getSafeSymbol()+"static_block_exe_flag == 0) {"); + if(cn.getNumStaticFields() != 0) { + // TODO add static field initialization here + } + if(cn.getNumStaticBlocks() != 0) { + MethodDescriptor t_md = (MethodDescriptor)cn.getMethodTable().get("staticblocks"); + output.println(" "+cn.getSafeSymbol()+t_md.getSafeSymbol()+"_"+t_md.getSafeMethodDescriptor()+"();"); + } else { + output.println(" global_defs_p->" + cn.getSafeSymbol()+"static_block_exe_flag = 1;"); } + output.println("}"); + output.println("#endif // MGC_STATIC_INIT_CHECK"); } } - // redirect to the global_defs_p structure - if(fsfn.getDst().getType().isClassNameRef()) { - // reference to the static field with Class name - output.println("global_defs_p->" + - fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc(),lb)+";"); - } else { - output.println("*"+generateTemp(fm, fsfn.getDst(),lb)+"->"+ - fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc(),lb)+";"); - } + } + // redirect to the global_defs_p structure + if(fsfn.getDst().getType().isClassNameRef()) { + // reference to the static field with Class name + output.println("global_defs_p->" + + fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc())+";"); } else { - output.println(generateTemp(fm, fsfn.getDst(),lb)+"->"+ - fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc(),lb)+";"); + output.println("*"+generateTemp(fm, fsfn.getDst())+"->"+ + fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc())+";"); } } else { - output.println(generateTemp(fm, fsfn.getDst(),lb)+"->"+ - fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc(),lb)+";"); + output.println(generateTemp(fm, fsfn.getDst())+"->"+ + fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc())+";"); } + } else { + output.println(generateTemp(fm, fsfn.getDst())+"->"+ + fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc())+";"); } } - - private void generateFlatElementNode(FlatMethod fm, LocalityBinding lb, FlatElementNode fen, PrintWriter output) { + + protected void generateFlatElementNode(FlatMethod fm, FlatElementNode fen, PrintWriter output) { TypeDescriptor elementtype=fen.getSrc().getType().dereference(); String type=""; @@ -3500,57 +2297,13 @@ public class BuildCode { type=elementtype.getSafeSymbol()+" "; if (this.state.ARRAYBOUNDARYCHECK && fen.needsBoundsCheck()) { - output.println("if (unlikely(((unsigned int)"+generateTemp(fm, fen.getIndex(),lb)+") >= "+generateTemp(fm,fen.getSrc(),lb) + "->___length___))"); + output.println("if (unlikely(((unsigned int)"+generateTemp(fm, fen.getIndex())+") >= "+generateTemp(fm,fen.getSrc()) + "->___length___))"); output.println("failedboundschk();"); } - if (state.SINGLETM) { - //Single machine transaction case - String dst=generateTemp(fm, fen.getDst(),lb); - if ((!state.STMARRAY)||(!wb.needBarrier(fen))||locality.getNodePreTempInfo(lb, fen).get(fen.getSrc())==LocalityAnalysis.SCRATCH||locality.getAtomic(lb).get(fen).intValue()==0||(state.READSET&&!dc.getNeedGet(lb, fen))) { - output.println(dst +"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex(),lb)+"];"); - } else { - output.println("STMGETARRAY("+dst+", "+ generateTemp(fm,fen.getSrc(),lb)+", "+generateTemp(fm, fen.getIndex(),lb)+", "+type+");"); - } - - if (elementtype.isPtr()&&locality.getAtomic(lb).get(fen).intValue()>0&& - locality.getNodePreTempInfo(lb, fen).get(fen.getSrc())!=LocalityAnalysis.SCRATCH) { - if ((dc==null)||!state.READSET&&dc.getNeedTrans(lb, fen)||state.READSET&&dc.getNeedWriteTrans(lb, fen)) { - output.println("TRANSREAD("+dst+", "+dst+", (void *)(" + localsprefixaddr+"));"); - } else if (state.READSET&&dc.getNeedTrans(lb, fen)) { - if (state.HYBRID&&delaycomp.getConv(lb).contains(fen)) { - output.println("TRANSREADRDFISSION("+dst+", "+dst+");"); - } else - output.println("TRANSREADRD("+dst+", "+dst+");"); - } - } - } else if (state.DSM) { - Integer status=locality.getNodePreTempInfo(lb,fen).get(fen.getSrc()); - if (status==LocalityAnalysis.GLOBAL) { - String dst=generateTemp(fm, fen.getDst(),lb); - if (elementtype.isPtr()) { - output.println(dst +"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex(),lb)+"];"); - output.println("TRANSREAD("+dst+", "+dst+");"); - } else { - output.println(dst +"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex(),lb)+"];"); - } - } else if (status==LocalityAnalysis.LOCAL) { - output.println(generateTemp(fm, fen.getDst(),lb)+"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex(),lb)+"];"); - } else if (status==LocalityAnalysis.EITHER) { - //Code is reading from a null pointer - output.println("if ("+generateTemp(fm, fen.getSrc(),lb)+") {"); - output.println("#ifndef RAW"); - output.println("printf(\"BIG ERROR\\n\");exit(-1);}"); - output.println("#endif"); - //This should throw a suitable null pointer error - output.println(generateTemp(fm, fen.getDst(),lb)+"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex(),lb)+"];"); - } else - throw new Error("Read from non-global/non-local in:"+lb.getExplanation()); - } else { - output.println(generateTemp(fm, fen.getDst(),lb)+"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex(),lb)+"];"); - } + output.println(generateTemp(fm, fen.getDst())+"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc())+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex())+"];"); } - private void generateFlatSetElementNode(FlatMethod fm, LocalityBinding lb, FlatSetElementNode fsen, PrintWriter output) { + protected void generateFlatSetElementNode(FlatMethod fm, FlatSetElementNode fsen, PrintWriter output) { //TODO: need dynamic check to make sure this assignment is actually legal //Because Object[] could actually be something more specific...ie. Integer[] @@ -3565,249 +2318,118 @@ public class BuildCode { type=elementtype.getSafeSymbol()+" "; if (this.state.ARRAYBOUNDARYCHECK && fsen.needsBoundsCheck()) { - output.println("if (unlikely(((unsigned int)"+generateTemp(fm, fsen.getIndex(),lb)+") >= "+generateTemp(fm,fsen.getDst(),lb) + "->___length___))"); + output.println("if (unlikely(((unsigned int)"+generateTemp(fm, fsen.getIndex())+") >= "+generateTemp(fm,fsen.getDst()) + "->___length___))"); output.println("failedboundschk();"); } - - if (state.SINGLETM && locality.getAtomic(lb).get(fsen).intValue()>0) { - //Transaction set element case - if (wb.needBarrier(fsen)&& - locality.getNodePreTempInfo(lb, fsen).get(fsen.getDst())!=LocalityAnalysis.SCRATCH) { - output.println("*((unsigned int *)&("+generateTemp(fm,fsen.getDst(),lb)+"->___objstatus___))|=DIRTY;"); - } - if (fsen.getSrc().getType().isPtr()&&!fsen.getSrc().getType().isNull()) { - output.println("{"); - String src=generateTemp(fm, fsen.getSrc(), lb); - if ((dc==null)||dc.getNeedSrcTrans(lb, fsen)&& - locality.getNodePreTempInfo(lb, fsen).get(fsen.getSrc())!=LocalityAnalysis.SCRATCH) { - output.println("INTPTR srcoid=("+src+"!=NULL?((INTPTR)"+src+"->"+oidstr+"):0);"); - } else { - output.println("INTPTR srcoid=(INTPTR)"+src+";"); - } - if (state.STMARRAY&&locality.getNodePreTempInfo(lb, fsen).get(fsen.getDst())!=LocalityAnalysis.SCRATCH&&wb.needBarrier(fsen)&&locality.getAtomic(lb).get(fsen).intValue()>0) { - output.println("STMSETARRAY("+generateTemp(fm, fsen.getDst(),lb)+", "+generateTemp(fm, fsen.getIndex(),lb)+", srcoid, INTPTR);"); - } else { - output.println("((INTPTR*)(((char *) &("+ generateTemp(fm,fsen.getDst(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fsen.getIndex(),lb)+"]=srcoid;"); - } - output.println("}"); - } else { - if (state.STMARRAY&&locality.getNodePreTempInfo(lb, fsen).get(fsen.getDst())!=LocalityAnalysis.SCRATCH&&wb.needBarrier(fsen)&&locality.getAtomic(lb).get(fsen).intValue()>0) { - output.println("STMSETARRAY("+generateTemp(fm, fsen.getDst(),lb)+", "+generateTemp(fm, fsen.getIndex(),lb)+", "+ generateTemp(fm, fsen.getSrc(), lb) +", "+type+");"); - } else { - output.println("(("+type +"*)(((char *) &("+ generateTemp(fm,fsen.getDst(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fsen.getIndex(),lb)+"]="+generateTemp(fm,fsen.getSrc(),lb)+";"); - } - } - } else if (state.DSM && locality.getAtomic(lb).get(fsen).intValue()>0) { - Integer statussrc=locality.getNodePreTempInfo(lb,fsen).get(fsen.getSrc()); - Integer statusdst=locality.getNodePreTempInfo(lb,fsen).get(fsen.getDst()); - boolean srcglobal=statussrc==LocalityAnalysis.GLOBAL; - boolean dstglobal=statusdst==LocalityAnalysis.GLOBAL; - boolean dstlocal=(statusdst==LocalityAnalysis.LOCAL)||(statusdst==LocalityAnalysis.EITHER); - - if (dstglobal) { - if (wb.needBarrier(fsen)) - output.println("*((unsigned int *)&("+generateTemp(fm,fsen.getDst(),lb)+"->___localcopy___))|=DIRTY;"); - } else if (dstlocal) { - /** Check if we need to copy */ - String dst=generateTemp(fm, fsen.getDst(),lb); - output.println("if(!"+dst+"->"+localcopystr+") {"); - /* Link object into list */ - String revertptr=generateTemp(fm, reverttable.get(lb),lb); - output.println(revertptr+"=revertlist;"); - if ((GENERATEPRECISEGC) || this.state.MULTICOREGC) - output.println("COPY_OBJ((struct garbagelist *)"+localsprefixaddr+",(struct ___Object___ *)"+dst+");"); - else - output.println("COPY_OBJ("+dst+");"); - output.println(dst+"->"+nextobjstr+"="+revertptr+";"); - output.println("revertlist=(struct ___Object___ *)"+dst+";"); - output.println("}"); - } else { - System.out.println("Node: "+fsen); - System.out.println(lb); - System.out.println("statusdst="+statusdst); - System.out.println(fm.printMethod()); - throw new Error("Unknown array type"); - } - if (srcglobal) { - output.println("{"); - String src=generateTemp(fm, fsen.getSrc(), lb); - output.println("INTPTR srcoid=("+src+"!=NULL?((INTPTR)"+src+"->"+oidstr+"):0);"); - output.println("((INTPTR*)(((char *) &("+ generateTemp(fm,fsen.getDst(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fsen.getIndex(),lb)+"]=srcoid;"); - output.println("}"); - } else { - output.println("(("+type +"*)(((char *) &("+ generateTemp(fm,fsen.getDst(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fsen.getIndex(),lb)+"]="+generateTemp(fm,fsen.getSrc(),lb)+";"); - } - } else { - if (state.FASTCHECK) { - String dst=generateTemp(fm, fsen.getDst(),lb); - output.println("if(!"+dst+"->"+localcopystr+") {"); - /* Link object into list */ - if (GENERATEPRECISEGC || this.state.MULTICOREGC) - output.println("COPY_OBJ((struct garbagelist *)"+localsprefixaddr+",(struct ___Object___ *)"+dst+");"); - else - output.println("COPY_OBJ("+dst+");"); - output.println(dst+"->"+nextobjstr+"="+fcrevert+";"); - output.println(fcrevert+"=(struct ___Object___ *)"+dst+";"); - output.println("}"); - } - output.println("(("+type +"*)(((char *) &("+ generateTemp(fm,fsen.getDst(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fsen.getIndex(),lb)+"]="+generateTemp(fm,fsen.getSrc(),lb)+";"); + if (state.FASTCHECK) { + String dst=generateTemp(fm, fsen.getDst()); + output.println("if(!"+dst+"->"+localcopystr+") {"); + /* Link object into list */ + if (GENERATEPRECISEGC || this.state.MULTICOREGC) + output.println("COPY_OBJ((struct garbagelist *)"+localsprefixaddr+",(struct ___Object___ *)"+dst+");"); + else + output.println("COPY_OBJ("+dst+");"); + output.println(dst+"->"+nextobjstr+"="+fcrevert+";"); + output.println(fcrevert+"=(struct ___Object___ *)"+dst+";"); + output.println("}"); } + output.println("(("+type +"*)(((char *) &("+ generateTemp(fm,fsen.getDst())+"->___length___))+sizeof(int)))["+generateTemp(fm, fsen.getIndex())+"]="+generateTemp(fm,fsen.getSrc())+";"); } - protected void generateFlatNew(FlatMethod fm, LocalityBinding lb, FlatNew fn, PrintWriter output) { - if (state.DSM && locality.getAtomic(lb).get(fn).intValue()>0&&!fn.isGlobal()) { - //Stash pointer in case of GC - String revertptr=generateTemp(fm, reverttable.get(lb),lb); - output.println(revertptr+"=revertlist;"); - } - if (state.SINGLETM) { - if (fn.getType().isArray()) { - int arrayid=state.getArrayNumber(fn.getType())+state.numClasses(); - if (locality.getAtomic(lb).get(fn).intValue()>0) { - //inside transaction - output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarraytrans("+localsprefixaddr+", "+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+");"); - } else { - //outside transaction - output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarray("+localsprefixaddr+", "+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+");"); - } - } else { - if (locality.getAtomic(lb).get(fn).intValue()>0) { - //inside transaction - output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newtrans("+localsprefixaddr+", "+fn.getType().getClassDesc().getId()+");"); - } else { - //outside transaction - output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_new("+localsprefixaddr+", "+fn.getType().getClassDesc().getId()+");"); - } - } - } else if (fn.getType().isArray()) { + protected void generateFlatNew(FlatMethod fm, FlatNew fn, PrintWriter output) { + if (fn.getType().isArray()) { int arrayid=state.getArrayNumber(fn.getType())+state.numClasses(); - if (fn.isGlobal()&&(state.DSM||state.SINGLETM)) { - output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarrayglobal("+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+");"); - } else if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { - output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarray("+localsprefixaddr+", "+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+");"); + if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { + output.println(generateTemp(fm,fn.getDst())+"=allocate_newarray("+localsprefixaddr+", "+arrayid+", "+generateTemp(fm, fn.getSize())+");"); } else { - output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarray("+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+");"); + output.println(generateTemp(fm,fn.getDst())+"=allocate_newarray("+arrayid+", "+generateTemp(fm, fn.getSize())+");"); } } else { - if (fn.isGlobal()&&(state.DSM||state.SINGLETM)) { - output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newglobal("+fn.getType().getClassDesc().getId()+");"); - } else if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { - output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_new("+localsprefixaddr+", "+fn.getType().getClassDesc().getId()+");"); + if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { + output.println(generateTemp(fm,fn.getDst())+"=allocate_new("+localsprefixaddr+", "+fn.getType().getClassDesc().getId()+");"); } else { - output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_new("+fn.getType().getClassDesc().getId()+");"); + output.println(generateTemp(fm,fn.getDst())+"=allocate_new("+fn.getType().getClassDesc().getId()+");"); } } - if (state.DSM && locality.getAtomic(lb).get(fn).intValue()>0&&!fn.isGlobal()) { - String revertptr=generateTemp(fm, reverttable.get(lb),lb); - String dst=generateTemp(fm,fn.getDst(),lb); - output.println(dst+"->___localcopy___=(struct ___Object___*)1;"); - output.println(dst+"->"+nextobjstr+"="+revertptr+";"); - output.println("revertlist=(struct ___Object___ *)"+dst+";"); - } if (state.FASTCHECK) { - String dst=generateTemp(fm,fn.getDst(),lb); + String dst=generateTemp(fm,fn.getDst()); output.println(dst+"->___localcopy___=(struct ___Object___*)1;"); output.println(dst+"->"+nextobjstr+"="+fcrevert+";"); output.println(fcrevert+"=(struct ___Object___ *)"+dst+";"); } } - private void generateFlatTagDeclaration(FlatMethod fm, LocalityBinding lb, FlatTagDeclaration fn, PrintWriter output) { + protected void generateFlatTagDeclaration(FlatMethod fm, FlatTagDeclaration fn, PrintWriter output) { if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { - output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_tag("+localsprefixaddr+", "+state.getTagId(fn.getType())+");"); + output.println(generateTemp(fm,fn.getDst())+"=allocate_tag("+localsprefixaddr+", "+state.getTagId(fn.getType())+");"); } else { - output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_tag("+state.getTagId(fn.getType())+");"); + output.println(generateTemp(fm,fn.getDst())+"=allocate_tag("+state.getTagId(fn.getType())+");"); } } - private void generateFlatOpNode(FlatMethod fm, LocalityBinding lb, FlatOpNode fon, PrintWriter output) { + protected void generateFlatOpNode(FlatMethod fm, FlatOpNode fon, PrintWriter output) { if (fon.getRight()!=null) { if (fon.getOp().getOp()==Operation.URIGHTSHIFT) { if (fon.getLeft().getType().isLong()) - output.println(generateTemp(fm, fon.getDest(),lb)+" = ((unsigned long long)"+generateTemp(fm, fon.getLeft(),lb)+")>>"+generateTemp(fm,fon.getRight(),lb)+";"); - else - output.println(generateTemp(fm, fon.getDest(),lb)+" = ((unsigned int)"+generateTemp(fm, fon.getLeft(),lb)+")>>"+generateTemp(fm,fon.getRight(),lb)+";"); - - } else if (dc!=null) { - output.print(generateTemp(fm, fon.getDest(),lb)+" = ("); - if (fon.getLeft().getType().isPtr()&&(fon.getOp().getOp()==Operation.EQUAL||fon.getOp().getOp()==Operation.NOTEQUAL)) - output.print("(void *)"); - if (dc.getNeedLeftSrcTrans(lb, fon)) - output.print("("+generateTemp(fm, fon.getLeft(),lb)+"!=NULL?"+generateTemp(fm, fon.getLeft(),lb)+"->"+oidstr+":NULL)"); + output.println(generateTemp(fm, fon.getDest())+" = ((unsigned long long)"+generateTemp(fm, fon.getLeft())+")>>"+generateTemp(fm,fon.getRight())+";"); else - output.print(generateTemp(fm, fon.getLeft(),lb)); - output.print(")"+fon.getOp().toString()+"("); - if (fon.getRight().getType().isPtr()&&(fon.getOp().getOp()==Operation.EQUAL||fon.getOp().getOp()==Operation.NOTEQUAL)) - output.print("(void *)"); - if (dc.getNeedRightSrcTrans(lb, fon)) - output.println("("+generateTemp(fm, fon.getRight(),lb)+"!=NULL?"+generateTemp(fm, fon.getRight(),lb)+"->"+oidstr+":NULL));"); - else - output.println(generateTemp(fm,fon.getRight(),lb)+");"); + output.println(generateTemp(fm, fon.getDest())+" = ((unsigned int)"+generateTemp(fm, fon.getLeft())+")>>"+generateTemp(fm,fon.getRight())+";"); + } else - output.println(generateTemp(fm, fon.getDest(),lb)+" = "+generateTemp(fm, fon.getLeft(),lb)+fon.getOp().toString()+generateTemp(fm,fon.getRight(),lb)+";"); + output.println(generateTemp(fm, fon.getDest())+" = "+generateTemp(fm, fon.getLeft())+fon.getOp().toString()+generateTemp(fm,fon.getRight())+";"); } else if (fon.getOp().getOp()==Operation.ASSIGN) - output.println(generateTemp(fm, fon.getDest(),lb)+" = "+generateTemp(fm, fon.getLeft(),lb)+";"); + output.println(generateTemp(fm, fon.getDest())+" = "+generateTemp(fm, fon.getLeft())+";"); else if (fon.getOp().getOp()==Operation.UNARYPLUS) - output.println(generateTemp(fm, fon.getDest(),lb)+" = "+generateTemp(fm, fon.getLeft(),lb)+";"); + output.println(generateTemp(fm, fon.getDest())+" = "+generateTemp(fm, fon.getLeft())+";"); else if (fon.getOp().getOp()==Operation.UNARYMINUS) - output.println(generateTemp(fm, fon.getDest(),lb)+" = -"+generateTemp(fm, fon.getLeft(),lb)+";"); + output.println(generateTemp(fm, fon.getDest())+" = -"+generateTemp(fm, fon.getLeft())+";"); else if (fon.getOp().getOp()==Operation.LOGIC_NOT) - output.println(generateTemp(fm, fon.getDest(),lb)+" = !"+generateTemp(fm, fon.getLeft(),lb)+";"); + output.println(generateTemp(fm, fon.getDest())+" = !"+generateTemp(fm, fon.getLeft())+";"); else if (fon.getOp().getOp()==Operation.COMP) - output.println(generateTemp(fm, fon.getDest(),lb)+" = ~"+generateTemp(fm, fon.getLeft(),lb)+";"); + output.println(generateTemp(fm, fon.getDest())+" = ~"+generateTemp(fm, fon.getLeft())+";"); else if (fon.getOp().getOp()==Operation.ISAVAILABLE) { - output.println(generateTemp(fm, fon.getDest(),lb)+" = "+generateTemp(fm, fon.getLeft(),lb)+"->fses==NULL;"); + output.println(generateTemp(fm, fon.getDest())+" = "+generateTemp(fm, fon.getLeft())+"->fses==NULL;"); } else - output.println(generateTemp(fm, fon.getDest(),lb)+fon.getOp().toString()+generateTemp(fm, fon.getLeft(),lb)+";"); + output.println(generateTemp(fm, fon.getDest())+fon.getOp().toString()+generateTemp(fm, fon.getLeft())+";"); } - private void generateFlatCastNode(FlatMethod fm, LocalityBinding lb, FlatCastNode fcn, PrintWriter output) { + protected void generateFlatCastNode(FlatMethod fm, FlatCastNode fcn, PrintWriter output) { /* TODO: Do type check here */ if (fcn.getType().isArray()) { - output.println(generateTemp(fm,fcn.getDst(),lb)+"=(struct ArrayObject *)"+generateTemp(fm,fcn.getSrc(),lb)+";"); + output.println(generateTemp(fm,fcn.getDst())+"=(struct ArrayObject *)"+generateTemp(fm,fcn.getSrc())+";"); } else if (state.MGC && fcn.getType().isClass() && fcn.getType().getClassDesc().isEnum()) { - output.println(generateTemp(fm,fcn.getDst(),lb)+"=(int)"+generateTemp(fm,fcn.getSrc(),lb)+";"); + output.println(generateTemp(fm,fcn.getDst())+"=(int)"+generateTemp(fm,fcn.getSrc())+";"); } else if (fcn.getType().isClass()) - output.println(generateTemp(fm,fcn.getDst(),lb)+"=(struct "+fcn.getType().getSafeSymbol()+" *)"+generateTemp(fm,fcn.getSrc(),lb)+";"); + output.println(generateTemp(fm,fcn.getDst())+"=(struct "+fcn.getType().getSafeSymbol()+" *)"+generateTemp(fm,fcn.getSrc())+";"); else - output.println(generateTemp(fm,fcn.getDst(),lb)+"=("+fcn.getType().getSafeSymbol()+")"+generateTemp(fm,fcn.getSrc(),lb)+";"); + output.println(generateTemp(fm,fcn.getDst())+"=("+fcn.getType().getSafeSymbol()+")"+generateTemp(fm,fcn.getSrc())+";"); } - private void generateFlatLiteralNode(FlatMethod fm, LocalityBinding lb, FlatLiteralNode fln, PrintWriter output) { + protected void generateFlatLiteralNode(FlatMethod fm, FlatLiteralNode fln, PrintWriter output) { if (fln.getValue()==null) - output.println(generateTemp(fm, fln.getDst(),lb)+"=0;"); + output.println(generateTemp(fm, fln.getDst())+"=0;"); else if (fln.getType().getSymbol().equals(TypeUtil.StringClass)) { if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { - if (state.DSM && locality.getAtomic(lb).get(fln).intValue()>0) { - //Stash pointer in case of GC - String revertptr=generateTemp(fm, reverttable.get(lb),lb); - output.println(revertptr+"=revertlist;"); - } - output.println(generateTemp(fm, fln.getDst(),lb)+"=NewString("+localsprefixaddr+", \""+FlatLiteralNode.escapeString((String)fln.getValue())+"\","+((String)fln.getValue()).length()+");"); - if (state.DSM && locality.getAtomic(lb).get(fln).intValue()>0) { - //Stash pointer in case of GC - String revertptr=generateTemp(fm, reverttable.get(lb),lb); - output.println("revertlist="+revertptr+";"); - } + output.println(generateTemp(fm, fln.getDst())+"=NewString("+localsprefixaddr+", \""+FlatLiteralNode.escapeString((String)fln.getValue())+"\","+((String)fln.getValue()).length()+");"); } else { - output.println(generateTemp(fm, fln.getDst(),lb)+"=NewString(\""+FlatLiteralNode.escapeString((String)fln.getValue())+"\","+((String)fln.getValue()).length()+");"); + output.println(generateTemp(fm, fln.getDst())+"=NewString(\""+FlatLiteralNode.escapeString((String)fln.getValue())+"\","+((String)fln.getValue()).length()+");"); } } else if (fln.getType().isBoolean()) { if (((Boolean)fln.getValue()).booleanValue()) - output.println(generateTemp(fm, fln.getDst(),lb)+"=1;"); + output.println(generateTemp(fm, fln.getDst())+"=1;"); else - output.println(generateTemp(fm, fln.getDst(),lb)+"=0;"); + output.println(generateTemp(fm, fln.getDst())+"=0;"); } else if (fln.getType().isChar()) { String st=FlatLiteralNode.escapeString(fln.getValue().toString()); - output.println(generateTemp(fm, fln.getDst(),lb)+"='"+st+"';"); + output.println(generateTemp(fm, fln.getDst())+"='"+st+"';"); } else if (fln.getType().isLong()) { - output.println(generateTemp(fm, fln.getDst(),lb)+"="+fln.getValue()+"LL;"); + output.println(generateTemp(fm, fln.getDst())+"="+fln.getValue()+"LL;"); } else - output.println(generateTemp(fm, fln.getDst(),lb)+"="+fln.getValue()+";"); + output.println(generateTemp(fm, fln.getDst())+"="+fln.getValue()+";"); } - protected void generateFlatReturnNode(FlatMethod fm, LocalityBinding lb, FlatReturnNode frn, PrintWriter output) { + protected void generateFlatReturnNode(FlatMethod fm, FlatReturnNode frn, PrintWriter output) { if(state.MGC) { // TODO add version for normal Java later if((fm.getMethod() != null) && (fm.getMethod().isStaticBlock())) { @@ -3818,44 +2440,27 @@ public class BuildCode { } if (frn.getReturnTemp()!=null) { if (frn.getReturnTemp().getType().isPtr()) - output.println("return (struct "+fm.getMethod().getReturnType().getSafeSymbol()+"*)"+generateTemp(fm, frn.getReturnTemp(), lb)+";"); + output.println("return (struct "+fm.getMethod().getReturnType().getSafeSymbol()+"*)"+generateTemp(fm, frn.getReturnTemp())+";"); else - output.println("return "+generateTemp(fm, frn.getReturnTemp(), lb)+";"); + output.println("return "+generateTemp(fm, frn.getReturnTemp())+";"); } else { output.println("return;"); } } - protected void generateStoreFlatCondBranch(FlatMethod fm, LocalityBinding lb, FlatCondBranch fcb, String label, PrintWriter output) { - int left=-1; - int right=-1; - //only record if this group has more than one exit - if (branchanalysis.numJumps(fcb)>1) { - left=branchanalysis.jumpValue(fcb, 0); - right=branchanalysis.jumpValue(fcb, 1); - } - output.println("if (!"+generateTemp(fm, fcb.getTest(),lb)+") {"); - if (right!=-1) - output.println("STOREBRANCH("+right+");"); - output.println("goto "+label+";"); - output.println("}"); - if (left!=-1) - output.println("STOREBRANCH("+left+");"); - } - - protected void generateFlatCondBranch(FlatMethod fm, LocalityBinding lb, FlatCondBranch fcb, String label, PrintWriter output) { - output.println("if (!"+generateTemp(fm, fcb.getTest(),lb)+") goto "+label+";"); + protected void generateFlatCondBranch(FlatMethod fm, FlatCondBranch fcb, String label, PrintWriter output) { + output.println("if (!"+generateTemp(fm, fcb.getTest())+") goto "+label+";"); } /** This method generates header information for the method or * task referenced by the Descriptor des. */ - private void generateHeader(FlatMethod fm, LocalityBinding lb, Descriptor des, PrintWriter output) { - generateHeader(fm, lb, des, output, false); + protected void generateHeader(FlatMethod fm, Descriptor des, PrintWriter output) { + generateHeader(fm, des, output, false); } - private void generateHeader(FlatMethod fm, LocalityBinding lb, Descriptor des, PrintWriter output, boolean addSESErecord) { + protected void generateHeader(FlatMethod fm, Descriptor des, PrintWriter output, boolean addSESErecord) { /* Print header */ - ParamsObject objectparams=(ParamsObject)paramstable.get(lb!=null ? lb : des); + ParamsObject objectparams=(ParamsObject)paramstable.get(des); MethodDescriptor md=null; TaskDescriptor task=null; if (des instanceof MethodDescriptor) @@ -3876,20 +2481,14 @@ public class BuildCode { //catch the constructor case output.print("void "); if (md!=null) { - if (state.DSM||state.SINGLETM) { - output.print(cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"("); - } else - output.print(cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"("); + output.print(cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"("); } else output.print(task.getSafeSymbol()+"("); boolean printcomma=false; if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { if (md!=null) { - if (state.DSM||state.SINGLETM) { - output.print("struct "+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params * "+paramsprefix); - } else - output.print("struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params * "+paramsprefix); + output.print("struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params * "+paramsprefix); } else output.print("struct "+task.getSafeSymbol()+"_params * "+paramsprefix); printcomma=true; @@ -3933,7 +2532,7 @@ public class BuildCode { } else output.println(") {"); } - public void generateFlatFlagActionNode(FlatMethod fm, LocalityBinding lb, FlatFlagActionNode ffan, PrintWriter output) { + public void generateFlatFlagActionNode(FlatMethod fm, FlatFlagActionNode ffan, PrintWriter output) { output.println("/* FlatFlagActionNode */"); @@ -4012,9 +2611,9 @@ public class BuildCode { while(tagit.hasNext()) { TempDescriptor tagtmp=(TempDescriptor)tagit.next(); if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) - output.println("tagclear("+localsprefixaddr+", (struct ___Object___ *)"+generateTemp(fm, temp,lb)+", "+generateTemp(fm,tagtmp,lb)+");"); + output.println("tagclear("+localsprefixaddr+", (struct ___Object___ *)"+generateTemp(fm, temp)+", "+generateTemp(fm,tagtmp)+");"); else - output.println("tagclear((struct ___Object___ *)"+generateTemp(fm, temp,lb)+", "+generateTemp(fm,tagtmp,lb)+");"); + output.println("tagclear((struct ___Object___ *)"+generateTemp(fm, temp)+", "+generateTemp(fm,tagtmp)+");"); } } @@ -4024,9 +2623,9 @@ public class BuildCode { while(tagit.hasNext()) { TempDescriptor tagtmp=(TempDescriptor)tagit.next(); if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) - output.println("tagset("+localsprefixaddr+", (struct ___Object___ *)"+generateTemp(fm, temp,lb)+", "+generateTemp(fm,tagtmp,lb)+");"); + output.println("tagset("+localsprefixaddr+", (struct ___Object___ *)"+generateTemp(fm, temp)+", "+generateTemp(fm,tagtmp)+");"); else - output.println("tagset((struct ___Object___ *)"+generateTemp(fm, temp, lb)+", "+generateTemp(fm,tagtmp, lb)+");"); + output.println("tagset((struct ___Object___ *)"+generateTemp(fm, temp)+", "+generateTemp(fm,tagtmp)+");"); } } @@ -4037,22 +2636,22 @@ public class BuildCode { ormask=((Integer)flagortable.get(temp)).intValue(); if (flagandtable.containsKey(temp)) andmask=((Integer)flagandtable.get(temp)).intValue(); - generateFlagOrAnd(ffan, fm, lb, temp, output, ormask, andmask); - generateObjectDistribute(ffan, fm, lb, temp, output); + generateFlagOrAnd(ffan, fm, temp, output, ormask, andmask); + generateObjectDistribute(ffan, fm, temp, output); } } - protected void generateFlagOrAnd(FlatFlagActionNode ffan, FlatMethod fm, LocalityBinding lb, TempDescriptor temp, + protected void generateFlagOrAnd(FlatFlagActionNode ffan, FlatMethod fm, TempDescriptor temp, PrintWriter output, int ormask, int andmask) { if (ffan.getTaskType()==FlatFlagActionNode.NEWOBJECT) { - output.println("flagorandinit("+generateTemp(fm, temp, lb)+", 0x"+Integer.toHexString(ormask)+", 0x"+Integer.toHexString(andmask)+");"); + output.println("flagorandinit("+generateTemp(fm, temp)+", 0x"+Integer.toHexString(ormask)+", 0x"+Integer.toHexString(andmask)+");"); } else { - output.println("flagorand("+generateTemp(fm, temp, lb)+", 0x"+Integer.toHexString(ormask)+", 0x"+Integer.toHexString(andmask)+");"); + output.println("flagorand("+generateTemp(fm, temp)+", 0x"+Integer.toHexString(ormask)+", 0x"+Integer.toHexString(andmask)+");"); } } - protected void generateObjectDistribute(FlatFlagActionNode ffan, FlatMethod fm, LocalityBinding lb, TempDescriptor temp, PrintWriter output) { - output.println("enqueueObject("+generateTemp(fm, temp, lb)+");"); + protected void generateObjectDistribute(FlatFlagActionNode ffan, FlatMethod fm, TempDescriptor temp, PrintWriter output) { + output.println("enqueueObject("+generateTemp(fm, temp)+");"); } void generateOptionalHeader(PrintWriter headers) { @@ -4456,13 +3055,16 @@ public class BuildCode { return l; } - protected void outputTransCode(PrintWriter output) { - } - - - // override these methods in a subclass of BuildCode // to generate code for additional systems + protected void printExtraArrayFields(PrintWriter outclassdefs) { + } + protected void outputTransCode(PrintWriter output) { + } + protected void buildCodeSetup() { + } + protected void generateSizeArrayExtensions(PrintWriter outclassdefs) { + } protected void additionalIncludesMethodsHeader(PrintWriter outmethodheader) { } protected void preCodeGenInitialization() { @@ -4487,9 +3089,9 @@ public class BuildCode { } protected void additionalCodeAtTopFlatMethodBody(PrintWriter output, FlatMethod fm) { } - protected void additionalCodePreNode(FlatMethod fm, LocalityBinding lb, FlatNode fn, PrintWriter output) { + protected void additionalCodePreNode(FlatMethod fm, FlatNode fn, PrintWriter output) { } - protected void additionalCodePostNode(FlatMethod fm, LocalityBinding lb, FlatNode fn, PrintWriter output) { + protected void additionalCodePostNode(FlatMethod fm, FlatNode fn, PrintWriter output) { } } diff --git a/Robust/src/IR/Flat/BuildCodeMGC.java b/Robust/src/IR/Flat/BuildCodeMGC.java index c0accd80..e2d998eb 100644 --- a/Robust/src/IR/Flat/BuildCodeMGC.java +++ b/Robust/src/IR/Flat/BuildCodeMGC.java @@ -5,7 +5,6 @@ import java.io.PrintWriter; import java.util.Hashtable; import java.util.Iterator; -import Analysis.Prefetch.*; import Analysis.TaskStateAnalysis.SafetyAnalysis; import IR.ClassDescriptor; import IR.MethodDescriptor; @@ -26,9 +25,8 @@ public class BuildCodeMGC extends BuildCode { SafetyAnalysis sa, int coreNum, int tcoreNum, - int gcoreNum, - PrefetchAnalysis pa) { - super(st, temptovar, typeutil, sa, pa); + int gcoreNum) { + super(st, temptovar, typeutil, sa); this.coreNum = coreNum; // # of the active cores this.tcoreNum = tcoreNum; // # of the total number of cores this.gcoreNum = gcoreNum; // # of the cores for gc if any diff --git a/Robust/src/IR/Flat/BuildCodeMultiCore.java b/Robust/src/IR/Flat/BuildCodeMultiCore.java index 8da73cd4..de2a6238 100644 --- a/Robust/src/IR/Flat/BuildCodeMultiCore.java +++ b/Robust/src/IR/Flat/BuildCodeMultiCore.java @@ -10,7 +10,6 @@ import java.util.Queue; import java.util.Set; import java.util.Vector; -import Analysis.Locality.LocalityBinding; import Analysis.Scheduling.Schedule; import Analysis.TaskStateAnalysis.FEdge; import Analysis.TaskStateAnalysis.FlagState; @@ -50,8 +49,8 @@ public class BuildCodeMultiCore extends BuildCode { String otqueueprefix = "___otqueue"; int startupcorenum; // record the core containing startup task, suppose only one core can hava startup object - private OwnershipAnalysis m_oa; - private Vector> m_aliasSets; + protected OwnershipAnalysis m_oa; + protected Vector> m_aliasSets; Hashtable> m_aliasFNTbl4Para; Hashtable> m_aliasFNTbl; Hashtable> m_aliaslocksTbl4FN; @@ -62,9 +61,8 @@ public class BuildCodeMultiCore extends BuildCode { SafetyAnalysis sa, Vector scheduling, int coreNum, - int gcoreNum, - PrefetchAnalysis pa) { - super(st, temptovar, typeutil, sa, pa); + int gcoreNum) { + super(st, temptovar, typeutil, sa); this.scheduling = scheduling; this.coreNum = coreNum; // # of the active cores this.tcoreNum = coreNum; // # of the cores setup by users @@ -135,10 +133,11 @@ public class BuildCodeMultiCore extends BuildCode { FieldShadow.handleFieldShadow(state); /* Build the virtual dispatch tables */ - super.buildVirtualTables(outvirtual); + + buildVirtualTables(outvirtual); /* Tag the methods that are invoked by static blocks */ - super.tagMethodInvokedByStaticBlock(); + tagMethodInvokedByStaticBlock(); /* Output includes */ outmethodheader.println("#ifndef METHODHEADERS_H"); @@ -148,20 +147,20 @@ public class BuildCodeMultiCore extends BuildCode { outmethodheader.println("#include \"dstm.h\"");*/ /* Output Structures */ - super.outputStructs(outstructs); + outputStructs(outstructs); // Output the C class declarations // These could mutually reference each other outclassdefs.println("#ifndef __CLASSDEF_H_"); outclassdefs.println("#define __CLASSDEF_H_"); - super.outputClassDeclarations(outclassdefs, outglobaldefs); + outputClassDeclarations(outclassdefs, outglobaldefs); // Output function prototypes and structures for parameters Iterator it=state.getClassSymbolTable().getDescriptorsIterator(); int numclasses = this.state.numClasses(); while(it.hasNext()) { ClassDescriptor cn=(ClassDescriptor)it.next(); - super.generateCallStructs(cn, outclassdefs, outstructs, outmethodheader, outglobaldefs); + generateCallStructs(cn, outclassdefs, outstructs, outmethodheader, outglobaldefs); } outclassdefs.println("#endif"); outclassdefs.close(); @@ -172,7 +171,7 @@ public class BuildCodeMultiCore extends BuildCode { it=state.getClassSymbolTable().getDescriptorsIterator(); while(it.hasNext()) { ClassDescriptor cn=(ClassDescriptor)it.next(); - super.mapFlags(cn); + mapFlags(cn); } /* Generate Tasks */ generateTaskStructs(outstructs, outmethodheader); @@ -183,7 +182,7 @@ public class BuildCodeMultiCore extends BuildCode { } /* Build the actual methods */ - super.outputMethods(outmethod); + outputMethods(outmethod); if (state.TASK) { Iterator[] taskits = new Iterator[this.coreNum]; @@ -346,7 +345,7 @@ public class BuildCodeMultiCore extends BuildCode { * passed in (when PRECISE GC is enabled) and (2) function * prototypes for the tasks */ - private void generateTaskStructs(PrintWriter output, + protected void generateTaskStructs(PrintWriter output, PrintWriter headersout) { /* Cycle through tasks */ for(int i = 0; i < this.scheduling.size(); ++i) { @@ -358,7 +357,7 @@ public class BuildCodeMultiCore extends BuildCode { /* Classify parameters */ TaskDescriptor task=taskit.next(); FlatMethod fm=state.getMethodFlat(task); - super.generateTempStructs(fm, null); + generateTempStructs(fm); ParamsObject objectparams=(ParamsObject) paramstable.get(task); TempObject objecttemps=(TempObject) tempstable.get(task); @@ -412,7 +411,7 @@ public class BuildCodeMultiCore extends BuildCode { /* This method outputs code for each task. */ - private void outputTaskCode(PrintWriter outtaskdefs, + protected void outputTaskCode(PrintWriter outtaskdefs, PrintWriter outmethod, PrintWriter outtask, Iterator[] taskits, @@ -435,7 +434,7 @@ public class BuildCodeMultiCore extends BuildCode { while(taskit.hasNext()) { TaskDescriptor td=taskit.next(); FlatMethod fm=state.getMethodFlat(td); - generateTaskMethod(fm, null, outmethod); + generateTaskMethod(fm, outmethod); generateTaskDescriptor(outtaskdefs, outtask, fm, td, qnames); } @@ -486,7 +485,7 @@ public class BuildCodeMultiCore extends BuildCode { } /** Prints out definitions for generic task structures */ - private void outputTaskTypes(PrintWriter outtask) { + protected void outputTaskTypes(PrintWriter outtask) { outtask.println("#ifndef _TASK_H"); outtask.println("#define _TASK_H"); outtask.println("#include \"ObjectHash.h\""); @@ -554,7 +553,7 @@ public class BuildCodeMultiCore extends BuildCode { outtask.println(); } - private void generateObjectTransQueues(PrintWriter output) { + protected void generateObjectTransQueues(PrintWriter output) { if(this.fsate2qnames == null) { this.fsate2qnames = new Hashtable[this.coreNum]; for(int i = 0; i < this.fsate2qnames.length; ++i) { @@ -598,22 +597,18 @@ public class BuildCodeMultiCore extends BuildCode { output.println(); } - private void generateTaskMethod(FlatMethod fm, - LocalityBinding lb, - PrintWriter output) { + protected void generateTaskMethod(FlatMethod fm, + PrintWriter output) { /*if (State.PRINTFLAT) System.out.println(fm.printMethod());*/ TaskDescriptor task=fm.getTask(); assert(task != null); int num = this.currentSchedule.getCoreNum(); - //ParamsObject objectparams=(ParamsObject)paramstable.get(lb!=null?lb:task); - generateTaskHeader(fm, lb, task,output); + //ParamsObject objectparams=(ParamsObject)paramstable.get(task); + generateTaskHeader(fm, task,output); - TempObject objecttemp=(TempObject) tempstable.get(lb!=null ? lb : task); - /*if (state.DSM&&lb.getHasAtomic()) { - output.println("transrecord_t * trans;"); - }*/ + TempObject objecttemp=(TempObject) tempstable.get(task); if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { output.print(" struct "+task.getCoreSafeSymbol(num)+"_locals "+localsprefix+"={"); @@ -640,13 +635,13 @@ public class BuildCodeMultiCore extends BuildCode { for(int i = 0; i < fm.numParameters(); ++i) { TempDescriptor temp = fm.getParameter(i); - output.println(" int "+generateTempFlagName(fm, temp, lb)+" = "+super.generateTemp(fm, temp, lb)+ + output.println(" int "+generateTempFlagName(fm, temp)+" = "+generateTemp(fm, temp)+ "->flag;"); } /* Assign labels to FlatNode's if necessary.*/ - Hashtable nodetolabel=super.assignLabels(fm); + Hashtable nodetolabel=assignLabels(fm, null); /* Check to see if we need to do a GC if this is a * multi-threaded program...*/ @@ -654,13 +649,6 @@ public class BuildCodeMultiCore extends BuildCode { output.println("if(gcflag) gc("+localsprefixaddr+");"); } - /*if ((state.THREAD||state.DSM)&&GENERATEPRECISEGC) { - if (state.DSM&&lb.isAtomic()) - output.println("checkcollect2(&"+localsprefix+",trans);"); - else - output.println("checkcollect(&"+localsprefix+");"); - }*/ - /* Create queues to store objects need to be transferred to other cores and their destination*/ //output.println(" struct Queue * totransobjqueue = createQueue();"); output.println(" clearQueue(totransobjqueue);"); @@ -670,7 +658,7 @@ public class BuildCodeMultiCore extends BuildCode { this.m_aliasFNTbl4Para = null; this.m_aliasFNTbl = null; this.m_aliaslocksTbl4FN = null; - outputAliasLockCode(fm, lb, output); + outputAliasLockCode(fm, output); /* generate print information for RAW version */ output.println("#ifdef MULTICORE"); @@ -712,7 +700,7 @@ public class BuildCodeMultiCore extends BuildCode { for(int i = 0; i < fm.numParameters(); ++i) { TempDescriptor temp = fm.getParameter(i); - output.println(" ++" + super.generateTemp(fm, temp, lb)+"->version;"); + output.println(" ++" + generateTemp(fm, temp)+"->version;"); } /* Do the actual code generation */ @@ -737,7 +725,7 @@ public class BuildCodeMultiCore extends BuildCode { }*/ if (current_node.numNext()==0) { output.print(" "); - super.generateFlatNode(fm, lb, current_node, output); + generateFlatNode(fm, current_node, output); if (current_node.kind()!=FKind.FlatReturnNode) { //output.println(" flushAll();"); output.println("#ifdef CACHEFLUSH"); @@ -757,7 +745,7 @@ public class BuildCodeMultiCore extends BuildCode { current_node=null; } else if(current_node.numNext()==1) { output.print(" "); - super.generateFlatNode(fm, lb, current_node, output); + generateFlatNode(fm, current_node, output); FlatNode nextnode=current_node.getNext(0); if (visited.contains(nextnode)) { output.println("goto L"+nodetolabel.get(nextnode)+";"); @@ -767,7 +755,7 @@ public class BuildCodeMultiCore extends BuildCode { } else if (current_node.numNext()==2) { /* Branch */ output.print(" "); - super.generateFlatCondBranch(fm, lb, (FlatCondBranch)current_node, "L"+nodetolabel.get(current_node.getNext(1)), output); + generateFlatCondBranch(fm, (FlatCondBranch)current_node, "L"+nodetolabel.get(current_node.getNext(1)), output); if (!visited.contains(current_node.getNext(1))) tovisit.add(current_node.getNext(1)); if (visited.contains(current_node.getNext(0))) { @@ -782,7 +770,7 @@ public class BuildCodeMultiCore extends BuildCode { } /** This method outputs TaskDescriptor information */ - private void generateTaskDescriptor(PrintWriter output, + protected void generateTaskDescriptor(PrintWriter output, PrintWriter outtask, FlatMethod fm, TaskDescriptor task, @@ -916,12 +904,11 @@ public class BuildCodeMultiCore extends BuildCode { /** This method generates header information for the task * referenced by the Descriptor des. */ - private void generateTaskHeader(FlatMethod fm, - LocalityBinding lb, + protected void generateTaskHeader(FlatMethod fm, Descriptor des, PrintWriter output) { /* Print header */ - ParamsObject objectparams=(ParamsObject)paramstable.get(lb!=null ? lb : des); + ParamsObject objectparams=(ParamsObject)paramstable.get(des); TaskDescriptor task=(TaskDescriptor) des; int num = this.currentSchedule.getCoreNum(); @@ -935,13 +922,6 @@ public class BuildCodeMultiCore extends BuildCode { printcomma=true; } - /*if (state.DSM&&lb.isAtomic()) { - if (printcomma) - output.print(", "); - output.print("transrecord_t * trans"); - printcomma=true; - }*/ - if (!GENERATEPRECISEGC && !this.state.MULTICOREGC) { /* Imprecise Task */ output.println("void * parameterarray[]) {"); @@ -963,13 +943,12 @@ public class BuildCodeMultiCore extends BuildCode { protected void generateFlagOrAnd(FlatFlagActionNode ffan, FlatMethod fm, - LocalityBinding lb, TempDescriptor temp, PrintWriter output, int ormask, int andmask) { if (ffan.getTaskType()==FlatFlagActionNode.NEWOBJECT) { - output.println("flagorandinit("+super.generateTemp(fm, temp, lb)+", 0x"+Integer.toHexString(ormask)+", 0x"+Integer.toHexString(andmask)+");"); + output.println("flagorandinit("+generateTemp(fm, temp)+", 0x"+Integer.toHexString(ormask)+", 0x"+Integer.toHexString(andmask)+");"); } else { int num = this.currentSchedule.getCoreNum(); ClassDescriptor cd = temp.getType().getClassDesc(); @@ -978,7 +957,7 @@ public class BuildCodeMultiCore extends BuildCode { FlagState tmpFState = initfstates.elementAt(i); output.println("{"); QueueInfo qinfo = outputqueues(tmpFState, num, output, false); - output.println("flagorand("+super.generateTemp(fm, temp, lb)+", 0x"+Integer.toHexString(ormask)+ + output.println("flagorand("+generateTemp(fm, temp)+", 0x"+Integer.toHexString(ormask)+ ", 0x"+Integer.toHexString(andmask)+", " + qinfo.qname + ", " + qinfo.length + ");"); output.println("}"); @@ -994,7 +973,6 @@ public class BuildCodeMultiCore extends BuildCode { protected void generateObjectDistribute(FlatFlagActionNode ffan, FlatMethod fm, - LocalityBinding lb, TempDescriptor temp, PrintWriter output) { ClassDescriptor cd = temp.getType().getClassDesc(); @@ -1034,7 +1012,7 @@ public class BuildCodeMultiCore extends BuildCode { for(int j = 0; j < targetFStates.length; ++j) { if(initfstates != null) { FlagState fs = initfstates.elementAt(j); - output.println("if(" + generateTempFlagName(fm, temp, lb) + "&(0x" + Integer.toHexString(fs.getAndmask()) + output.println("if(" + generateTempFlagName(fm, temp) + "&(0x" + Integer.toHexString(fs.getAndmask()) + ")==(0x" + Integer.toHexString(fs.getCheckmask()) + ")) {"); } Vector tmpfstates = (Vector)targetFStates[j]; @@ -1043,7 +1021,7 @@ public class BuildCodeMultiCore extends BuildCode { // TODO // may have bugs here output.println("/* reside on this core*"); - output.println("enqueueObject("+super.generateTemp(fm, temp, lb)+", NULL, 0);"); + output.println("enqueueObject("+generateTemp(fm, temp)+", NULL, 0);"); } if(initfstates != null) { output.println("}"); @@ -1058,7 +1036,7 @@ public class BuildCodeMultiCore extends BuildCode { FlagState fs = null; if(initfstates != null) { fs = initfstates.elementAt(j); - output.println("if((" + generateTempFlagName(fm, temp, lb) + "&(0x" + Integer.toHexString(fs.getAndmask()) + output.println("if((" + generateTempFlagName(fm, temp) + "&(0x" + Integer.toHexString(fs.getAndmask()) + "))==(0x" + Integer.toHexString(fs.getCheckmask()) + ")) {"); } Vector tmpfstates = (Vector)targetFStates[j]; @@ -1100,21 +1078,21 @@ public class BuildCodeMultiCore extends BuildCode { if(isolate) { output.println("{"); QueueInfo qinfo = outputqueues(tmpFState, num, output, true); - output.println("enqueueObject("+super.generateTemp(fm, temp, lb)+", " + qinfo.qname + + output.println("enqueueObject("+generateTemp(fm, temp)+", " + qinfo.qname + ", " + qinfo.length + ");"); output.println("}"); } /*else { // TODO // really needed? output.println("/* possibly needed by multi-parameter tasks on this core*//*"); - output.println("enqueueObject("+super.generateTemp(fm, temp, lb)+", NULL, 0);"); + output.println("enqueueObject("+generateTemp(fm, temp)+", NULL, 0);"); }*/ // deleted 09/07/06, multi-param tasks are pinned to one core now } else { /*if(!isolate) { // TODO // Is it possible to decide the actual queues? output.println("/* possibly needed by multi-parameter tasks on this core*//*"); - output.println("enqueueObject("+super.generateTemp(fm, temp, lb)+", NULL, 0);"); + output.println("enqueueObject("+generateTemp(fm, temp)+", NULL, 0);"); }*/ // deleted 09/07/06, multi-param tasks are pinned to one core now output.println("/* transfer to core " + targetcore.toString() + "*/"); output.println("{"); @@ -1122,7 +1100,7 @@ public class BuildCodeMultiCore extends BuildCode { // all the possible queues QueueInfo qinfo = null; TranObjInfo tmpinfo = new TranObjInfo(); - tmpinfo.name = super.generateTemp(fm, temp, lb); + tmpinfo.name = generateTemp(fm, temp); tmpinfo.targetcore = targetcore; FlagState targetFS = this.currentSchedule.getTargetFState(tmpFState); if(targetFS != null) { @@ -1147,7 +1125,7 @@ public class BuildCodeMultiCore extends BuildCode { // TODO // Is it possible to decide the actual queues? output.println("/* possibly needed by multi-parameter tasks on this core*//*"); - output.println("enqueueObject("+super.generateTemp(fm, temp, lb)+", NULL, 0);"); + output.println("enqueueObject("+generateTemp(fm, temp)+", NULL, 0);"); }*/ // deleted 09/07/06, multi-param tasks are pinned to one core now output.println("/* transfer to core " + targetcore.toString() + "*/"); output.println("{"); @@ -1155,7 +1133,7 @@ public class BuildCodeMultiCore extends BuildCode { // all the possible queues QueueInfo qinfo = null; TranObjInfo tmpinfo = new TranObjInfo(); - tmpinfo.name = super.generateTemp(fm, temp, lb); + tmpinfo.name = generateTemp(fm, temp); tmpinfo.targetcore = targetcore; FlagState targetFS = this.currentSchedule.getTargetFState(tmpFState); if(targetFS != null) { @@ -1180,13 +1158,13 @@ public class BuildCodeMultiCore extends BuildCode { if(isolate) { output.println("{"); QueueInfo qinfo = outputqueues(tmpFState, num, output, true); - output.println("enqueueObject("+super.generateTemp(fm, temp, lb)+", " + qinfo.qname + + output.println("enqueueObject("+generateTemp(fm, temp)+", " + qinfo.qname + ", " + qinfo.length + ");"); output.println("}"); } /*else { // TODO // really needed? - output.println("enqueueObject("+super.generateTemp(fm, temp, lb)+", NULL, 0);"); + output.println("enqueueObject("+generateTemp(fm, temp)+", NULL, 0);"); }*/ // deleted 09/07/06, multi-param tasks are pinned to one core now } @@ -1209,7 +1187,7 @@ public class BuildCodeMultiCore extends BuildCode { // all the possible queues QueueInfo qinfo = null; TranObjInfo tmpinfo = new TranObjInfo(); - tmpinfo.name = super.generateTemp(fm, temp, lb); + tmpinfo.name = generateTemp(fm, temp); tmpinfo.targetcore = targetcore; FlagState targetFS = this.currentSchedule.getTargetFState(tmpFState); if(targetFS != null) { @@ -1237,7 +1215,7 @@ public class BuildCodeMultiCore extends BuildCode { } } - private QueueInfo outputqueues(FlagState tmpFState, + protected QueueInfo outputqueues(FlagState tmpFState, int num, PrintWriter output, boolean isEnqueue) { @@ -1274,7 +1252,7 @@ public class BuildCodeMultiCore extends BuildCode { return qinfo; } - private QueueInfo outputtransqueues(FlagState tmpFState, + protected QueueInfo outputtransqueues(FlagState tmpFState, int targetcore, PrintWriter output) { // queue array @@ -1313,17 +1291,16 @@ public class BuildCodeMultiCore extends BuildCode { return qinfo; } - private class QueueInfo { + protected class QueueInfo { public int length; public String qname; } - private String generateTempFlagName(FlatMethod fm, - TempDescriptor td, - LocalityBinding lb) { + protected String generateTempFlagName(FlatMethod fm, + TempDescriptor td) { MethodDescriptor md=fm.getMethod(); TaskDescriptor task=fm.getTask(); - TempObject objecttemps=(TempObject) tempstable.get(lb!=null ? lb : md!=null ? md : task); + TempObject objecttemps=(TempObject) tempstable.get(md!=null ? md : task); if (objecttemps.isLocalPrim(td)||objecttemps.isParamPrim(td)) { return td.getSafeSymbol() + "_oldflag"; @@ -1350,7 +1327,6 @@ public class BuildCodeMultiCore extends BuildCode { } protected void outputAliasLockCode(FlatMethod fm, - LocalityBinding lb, PrintWriter output) { if(this.m_oa == null) { return; @@ -1538,7 +1514,7 @@ public class BuildCodeMultiCore extends BuildCode { output.println("void * tmpptrs_" + lockindex + "[] = {"); for(int j = 0; j < toadd.size(); j++) { int para = toadd.elementAt(j).intValue(); - output.print(super.generateTemp(fm, fm.getParameter(para), lb)); + output.print(generateTemp(fm, fm.getParameter(para))); if(j < toadd.size() - 1) { output.print(", "); } else { @@ -1549,7 +1525,7 @@ public class BuildCodeMultiCore extends BuildCode { for(int j = 0; j < toadd.size(); j++) { int para = toadd.elementAt(j).intValue(); - output.println("addAliasLock(" + super.generateTemp(fm, fm.getParameter(para), lb) + ", aliaslocks[" + i + "]);"); + output.println("addAliasLock(" + generateTemp(fm, fm.getParameter(para)) + ", aliaslocks[" + i + "]);"); } // check if this lock is also associated with any FlatNew nodes if(this.m_aliasFNTbl4Para.containsKey(toadd.elementAt(0))) { @@ -1573,10 +1549,10 @@ public class BuildCodeMultiCore extends BuildCode { for(int i = 0; i < key.length; i++) { int para = ((Integer)key[i]).intValue(); - output.println("void * tmpptrs_" + lockindex + "[] = {" + super.generateTemp(fm, fm.getParameter(para), lb) + "};"); + output.println("void * tmpptrs_" + lockindex + "[] = {" + generateTemp(fm, fm.getParameter(para)) + "};"); output.println("aliaslocks[tmpi++] = getAliasLock(tmpptrs_" + lockindex + ", 1, lockRedirectTbl);"); - output.println("addAliasLock(" + super.generateTemp(fm, fm.getParameter(para), lb) + ", aliaslocks[" + lockindex + "]);"); + output.println("addAliasLock(" + generateTemp(fm, fm.getParameter(para)) + ", aliaslocks[" + lockindex + "]);"); Vector tmpv = this.m_aliasFNTbl4Para.get(para); for(int j = 0; j < tmpv.size(); j++) { FlatNew fn = tmpv.elementAt(j); @@ -1619,14 +1595,13 @@ public class BuildCodeMultiCore extends BuildCode { } protected void generateFlatReturnNode(FlatMethod fm, - LocalityBinding lb, FlatReturnNode frn, PrintWriter output) { if (frn.getReturnTemp()!=null) { if (frn.getReturnTemp().getType().isPtr()) - output.println("return (struct "+fm.getMethod().getReturnType().getSafeSymbol()+"*)"+generateTemp(fm, frn.getReturnTemp(), lb)+";"); + output.println("return (struct "+fm.getMethod().getReturnType().getSafeSymbol()+"*)"+generateTemp(fm, frn.getReturnTemp())+";"); else - output.println("return "+generateTemp(fm, frn.getReturnTemp(), lb)+";"); + output.println("return "+generateTemp(fm, frn.getReturnTemp())+";"); } else { if(fm.getTask() != null) { output.println("#ifdef CACHEFLUSH"); @@ -1647,57 +1622,45 @@ public class BuildCodeMultiCore extends BuildCode { } protected void generateFlatNew(FlatMethod fm, - LocalityBinding lb, FlatNew fn, PrintWriter output) { - if (state.DSM && locality.getAtomic(lb).get(fn).intValue() > 0 - && !fn.isGlobal()) { - // Stash pointer in case of GC - String revertptr = super.generateTemp(fm, reverttable.get(lb), lb); - output.println(revertptr + "=trans->revertlist;"); - } if (fn.getType().isArray()) { int arrayid = state.getArrayNumber(fn.getType()) + state.numClasses(); if (fn.isGlobal()) { - output.println(super.generateTemp(fm, fn.getDst(), lb) + output.println(generateTemp(fm, fn.getDst()) + "=allocate_newarrayglobal(trans, " + arrayid + ", " - + super.generateTemp(fm, fn.getSize(), lb) + ");"); + + generateTemp(fm, fn.getSize()) + ");"); } else if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { - output.println(super.generateTemp(fm, fn.getDst(), lb) + output.println(generateTemp(fm, fn.getDst()) + "=allocate_newarray(&" + localsprefix + ", " - + arrayid + ", " + super.generateTemp(fm, fn.getSize(), lb) + + arrayid + ", " + generateTemp(fm, fn.getSize()) + ");"); } else { - output.println(super.generateTemp(fm, fn.getDst(), lb) + output.println(generateTemp(fm, fn.getDst()) + "=allocate_newarray(" + arrayid + ", " - + super.generateTemp(fm, fn.getSize(), lb) + ");"); + + generateTemp(fm, fn.getSize()) + ");"); } } else { if (fn.isGlobal()) { - output.println(super.generateTemp(fm, fn.getDst(), lb) + output.println(generateTemp(fm, fn.getDst()) + "=allocate_newglobal(trans, " + fn.getType().getClassDesc().getId() + ");"); } else if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { - output.println(super.generateTemp(fm, fn.getDst(), lb) + output.println(generateTemp(fm, fn.getDst()) + "=allocate_new(&" + localsprefix + ", " + fn.getType().getClassDesc().getId() + ");"); } else { - output.println(super.generateTemp(fm, fn.getDst(), lb) + output.println(generateTemp(fm, fn.getDst()) + "=allocate_new(" + fn.getType().getClassDesc().getId() + ");"); } } - if (state.DSM && locality.getAtomic(lb).get(fn).intValue() > 0 - && !fn.isGlobal()) { - String revertptr = super.generateTemp(fm, reverttable.get(lb), lb); - output.println("trans->revertlist=" + revertptr + ";"); - } // create alias lock if necessary if((this.m_aliaslocksTbl4FN != null) && (this.m_aliaslocksTbl4FN.containsKey(fn))) { Vector tmpv = this.m_aliaslocksTbl4FN.get(fn); for(int i = 0; i < tmpv.size(); i++) { - output.println("addAliasLock(" + super.generateTemp(fm, fn.getDst(), lb) + ", aliaslocks[" + tmpv.elementAt(i).intValue() + "]);"); + output.println("addAliasLock(" + generateTemp(fm, fn.getDst()) + ", aliaslocks[" + tmpv.elementAt(i).intValue() + "]);"); } } // generate codes for profiling, recording how many new objects are created @@ -1716,7 +1679,7 @@ public class BuildCodeMultiCore extends BuildCode { public FlagState fs; } - private boolean contains(Vector sendto, + protected boolean contains(Vector sendto, TranObjInfo t) { if(sendto.size() == 0) { return false; diff --git a/Robust/src/IR/Flat/BuildCodeTran.java b/Robust/src/IR/Flat/BuildCodeTran.java new file mode 100644 index 00000000..59d76bb0 --- /dev/null +++ b/Robust/src/IR/Flat/BuildCodeTran.java @@ -0,0 +1,2268 @@ +package IR.Flat; +import IR.Tree.Modifiers; +import IR.Tree.FlagExpressionNode; +import IR.Tree.DNFFlag; +import IR.Tree.DNFFlagAtom; +import IR.Tree.TagExpressionList; +import IR.Tree.OffsetNode; +import IR.*; + +import java.util.*; +import java.io.*; + +import Util.Relation; +import Analysis.TaskStateAnalysis.FlagState; +import Analysis.TaskStateAnalysis.FlagComparator; +import Analysis.TaskStateAnalysis.OptionalTaskDescriptor; +import Analysis.TaskStateAnalysis.Predicate; +import Analysis.TaskStateAnalysis.SafetyAnalysis; +import Analysis.TaskStateAnalysis.TaskIndex; +import Analysis.Locality.LocalityAnalysis; +import Analysis.Locality.LocalityBinding; +import Analysis.Locality.DiscoverConflicts; +import Analysis.Locality.DCWrapper; +import Analysis.Locality.DelayComputation; +import Analysis.Locality.BranchAnalysis; +import Analysis.CallGraph.CallGraph; +import Analysis.Prefetch.*; +import Analysis.Loops.WriteBarrier; +import Analysis.Loops.GlobalFieldType; +import Analysis.Locality.TypeAnalysis; +import Util.CodePrinter; + +public class BuildCodeTran extends BuildCode { + String oidstr="___nextobject___"; + LocalityAnalysis locality; + Hashtable reverttable; + Hashtable> backuptable; + PrefetchAnalysis pa; + WriteBarrier wb; + DiscoverConflicts dc; + DiscoverConflicts recorddc; + DCWrapper delaycomp; + LocalityBinding currlb; + + + public BuildCodeTran(State st, Hashtable temptovar, TypeUtil typeutil, SafetyAnalysis sa, PrefetchAnalysis pa) { + this(st, temptovar, typeutil, null, sa, pa); + } + + public BuildCodeTran(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality, PrefetchAnalysis pa) { + this(st, temptovar, typeutil, locality, null, pa); + } + + public BuildCodeTran(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality, SafetyAnalysis sa, PrefetchAnalysis pa) { + super(st, temptovar, typeutil, sa); + this.sa=sa; + if (state.SINGLETM) + oidstr="___objlocation___"; + if (locality!=null) { + this.locality=locality; + this.reverttable=new Hashtable(); + this.backuptable=new Hashtable>(); + this.wb=new WriteBarrier(locality, st); + } + if (state.SINGLETM&&state.DCOPTS) { + TypeAnalysis typeanalysis=new TypeAnalysis(locality, st, typeutil,callgraph); + GlobalFieldType gft=new GlobalFieldType(callgraph, st, typeutil.getMain()); + this.dc=new DiscoverConflicts(locality, st, typeanalysis, gft); + dc.doAnalysis(); + } + if (state.DELAYCOMP) { + TypeAnalysis typeanalysis=new TypeAnalysis(locality, st, typeutil,callgraph); + GlobalFieldType gft=new GlobalFieldType(callgraph, st, typeutil.getMain()); + delaycomp=new DCWrapper(locality, st, typeanalysis, gft); + dc=delaycomp.getConflicts(); + recorddc=new DiscoverConflicts(locality, st, typeanalysis, delaycomp.getCannotDelayMap(), true, true, null); + recorddc.doAnalysis(); + } + } + + /** The buildCode method outputs C code for all the methods. The Flat + * versions of the methods must already be generated and stored in + * the State object. */ + + PrintWriter outsandbox=null; + + protected void buildCodeSetup() { + try { + if (state.SANDBOX) { + outsandbox=new CodePrinter(new FileOutputStream(PREFIX+"sandboxdefs.c"), true); + } + } catch (Exception e) { + e.printStackTrace(); + System.exit(-1); + } + } + + protected void additionalIncludesMethodsHeader(PrintWriter outmethodheader) { + if (state.DSM) + outmethodheader.println("#include \"dstm.h\""); + if (state.SANDBOX) { + outmethodheader.println("#include \"sandbox.h\""); + } + if (state.SINGLETM) { + outmethodheader.println("#include \"tm.h\""); + outmethodheader.println("#include \"delaycomp.h\""); + outmethodheader.println("#include \"inlinestm.h\""); + } + if (state.ABORTREADERS) { + outmethodheader.println("#include \"abortreaders.h\""); + outmethodheader.println("#include "); + } + + } + + + protected void outputMainMethod(PrintWriter outmethod) { + outmethod.println("int main(int argc, const char *argv[]) {"); + outmethod.println(" int i;"); + outputStaticBlocks(outmethod); + outputClassObjects(outmethod); + additionalCodeAtTopOfMain(outmethod); + + if (state.DSM) { + if (state.DSMRECOVERYSTATS) { + outmethod.println("#ifdef RECOVERYSTATS \n"); + outmethod.println("handle();\n"); + outmethod.println("#endif\n"); + } else { + outmethod.println("#if defined(TRANSSTATS) || defined(RECOVERYSTATS) \n"); + outmethod.println("handle();\n"); + outmethod.println("#endif\n"); + } + } + outmethod.println("initializethreads();"); + + if (state.DSM) { + outmethod.println("if (dstmStartup(argv[1])) {"); + if (GENERATEPRECISEGC) { + outmethod.println(" struct ArrayObject * stringarray=allocate_newarray(NULL, STRINGARRAYTYPE, argc-2);"); + } else { + outmethod.println(" struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc-2);"); + } + } else { + if (GENERATEPRECISEGC) { + outmethod.println(" struct ArrayObject * stringarray=allocate_newarray(NULL, STRINGARRAYTYPE, argc-1);"); + } else { + outmethod.println(" struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc-1);"); + } + } + if (state.DSM) { + outmethod.println(" for(i=2;i___length___)+sizeof(int)))[i-2]=newstring;"); + else + outmethod.println(" ((void **)(((char *)& stringarray->___length___)+sizeof(int)))[i-1]=newstring;"); + outmethod.println(" }"); + + MethodDescriptor md=typeutil.getMain(); + ClassDescriptor cd=typeutil.getMainClass(); + + outmethod.println(" {"); + if (GENERATEPRECISEGC) { + outmethod.print(" struct "+cd.getSafeSymbol()+locality.getMain().getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={"); + outmethod.println("1, NULL,"+"stringarray};"); + outmethod.println(" "+cd.getSafeSymbol()+locality.getMain().getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(& __parameterlist__);"); + } else { + outmethod.println(" "+cd.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(stringarray);"); + } + outmethod.println(" }"); + + if (state.DSM) { + outmethod.println("}"); + } + + outmethod.println("pthread_mutex_lock(&gclistlock);"); + outmethod.println("threadcount--;"); + outmethod.println("pthread_cond_signal(&gccond);"); + outmethod.println("pthread_mutex_unlock(&gclistlock);"); + + outmethod.println("#if defined(TRANSSTATS) \n"); + outmethod.println("printf(\"****** Transaction Stats ******\\n\");"); + outmethod.println("printf(\"numTransCommit= %d\\n\", numTransCommit);"); + outmethod.println("printf(\"numTransAbort= %d\\n\", numTransAbort);"); + outmethod.println("printf(\"nSoftAbort= %d\\n\", nSoftAbort);"); + if (state.DSM) { + outmethod.println("printf(\"nchashSearch= %d\\n\", nchashSearch);"); + outmethod.println("printf(\"nmhashSearch= %d\\n\", nmhashSearch);"); + outmethod.println("printf(\"nprehashSearch= %d\\n\", nprehashSearch);"); + outmethod.println("printf(\"ndirtyCacheObj= %d\\n\", ndirtyCacheObj);"); + outmethod.println("printf(\"nRemoteReadSend= %d\\n\", nRemoteSend);"); + outmethod.println("printf(\"bytesSent= %d\\n\", bytesSent);"); + outmethod.println("printf(\"bytesRecv= %d\\n\", bytesRecv);"); + outmethod.println("printf(\"totalObjSize= %d\\n\", totalObjSize);"); + outmethod.println("printf(\"sendRemoteReq= %d\\n\", sendRemoteReq);"); + outmethod.println("printf(\"getResponse= %d\\n\", getResponse);"); + } else if (state.SINGLETM) { + outmethod.println("printf(\"nSoftAbortAbort= %d\\n\", nSoftAbortAbort);"); + outmethod.println("printf(\"nSoftAbortCommit= %d\\n\", nSoftAbortCommit);"); + outmethod.println("#ifdef STMSTATS\n"); + outmethod.println("for(i=0; i lbit=locality.getLocalityBindings().iterator(); lbit.hasNext(); ) { + LocalityBinding lb=lbit.next(); + MethodDescriptor md=lb.getMethod(); + FlatMethod fm=state.getMethodFlat(md); + wb.analyze(lb); + if (!md.getModifiers().isNative()) { + generateFlatMethod(fm, lb, outmethod); + } + } + } + + protected void additionalIncludesStructsHeader(PrintWriter outstructs) { + LocalityBinding lbrun=new LocalityBinding(typeutil.getRun(), false); + if (state.DSM) { + lbrun.setGlobalThis(LocalityAnalysis.GLOBAL); + } else if (state.SINGLETM) { + lbrun.setGlobalThis(LocalityAnalysis.NORMAL); + } + outstructs.println("#define RUNMETHOD "+virtualcalls.getLocalityNumber(lbrun)); + + if (state.DSMTASK) { + LocalityBinding lbexecute = new LocalityBinding(typeutil.getExecute(), false); + if(state.DSM) + lbexecute.setGlobalThis(LocalityAnalysis.GLOBAL); + else if( state.SINGLETM) + lbexecute.setGlobalThis(LocalityAnalysis.NORMAL); + outstructs.println("#define EXECUTEMETHOD " + virtualcalls.getLocalityNumber(lbexecute)); + } + } + + protected void printExtraArrayFields(PrintWriter outclassdefs) { + if (state.STMARRAY) { + outclassdefs.println(" int lowindex;"); + outclassdefs.println(" int highindex;"); + } + if (state.DUALVIEW) { + outclassdefs.println(" int arrayversion;"); + } + } + + /** The buildVirtualTables method outputs the virtual dispatch + * tables for methods. */ + + protected void buildVirtualTables(PrintWriter outvirtual) { + Iterator classit=state.getClassSymbolTable().getDescriptorsIterator(); + while(classit.hasNext()) { + ClassDescriptor cd=(ClassDescriptor)classit.next(); + if (virtualcalls.getMethodCount(cd)>maxcount) + maxcount=virtualcalls.getMethodCount(cd); + } + + LocalityBinding[][] lbvirtualtable=null; + lbvirtualtable=new LocalityBinding[state.numClasses()+state.numArrays()][maxcount]; + + /* Fill in virtual table */ + classit=state.getClassSymbolTable().getDescriptorsIterator(); + while(classit.hasNext()) { + ClassDescriptor cd=(ClassDescriptor)classit.next(); + if(cd.isInterface()) { + continue; + } + fillinRow(cd, lbvirtualtable, cd.getId()); + } + + ClassDescriptor objectcd=typeutil.getClass(TypeUtil.ObjectClass); + Iterator arrayit=state.getArrayIterator(); + while(arrayit.hasNext()) { + TypeDescriptor td=(TypeDescriptor)arrayit.next(); + int id=state.getArrayNumber(td); + fillinRow(objectcd, lbvirtualtable, id+state.numClasses()); + } + + outvirtual.print("void * virtualtable[]={"); + boolean needcomma=false; + for(int i=0; i lbit=locality.getClassBindings(cd).iterator(); lbit.hasNext(); ) { + LocalityBinding lb=lbit.next(); + MethodDescriptor md=lb.getMethod(); + //Is the method static or a constructor + if (md.isStatic()||md.getReturnType()==null) + continue; + int methodnum=virtualcalls.getLocalityNumber(lb); + virtualtable[rownum][methodnum]=lb; + } + } + + /** Generate array that contains the sizes of class objects. The + * object allocation functions in the runtime use this + * information. */ + + protected void generateSizeArrayExtensions(PrintWriter outclassdefs) { + outclassdefs.print("#ifdef TRANSSTATS \n"); + outclassdefs.print("extern int numTransAbort;\n"); + outclassdefs.print("extern int numTransCommit;\n"); + outclassdefs.print("extern int nSoftAbort;\n"); + if (state.DSM) { + outclassdefs.print("extern int nchashSearch;\n"); + outclassdefs.print("extern int nmhashSearch;\n"); + outclassdefs.print("extern int nprehashSearch;\n"); + outclassdefs.print("extern int ndirtyCacheObj;\n"); + outclassdefs.print("extern int nRemoteSend;\n"); + outclassdefs.print("extern int sendRemoteReq;\n"); + outclassdefs.print("extern int getResponse;\n"); + outclassdefs.print("extern int bytesSent;\n"); + outclassdefs.print("extern int bytesRecv;\n"); + outclassdefs.print("extern int totalObjSize;\n"); + outclassdefs.print("extern void handle();\n"); + } else if (state.SINGLETM) { + outclassdefs.println("extern int nSoftAbortAbort;"); + outclassdefs.println("extern int nSoftAbortCommit;"); + outclassdefs.println("#ifdef STMSTATS\n"); + outclassdefs.println("extern objtypestat_t typesCausingAbort[];"); + outclassdefs.println("#endif\n"); + } + outclassdefs.print("#endif\n"); + + outclassdefs.print("int numprefetchsites = " + pa.prefetchsiteid + ";\n"); + } + + /** Constructs params and temp objects for each method or task. + * These objects tell the compiler which temps need to be + * allocated. */ + + protected void generateTempStructs(FlatMethod fm, LocalityBinding lb) { + MethodDescriptor md=fm.getMethod(); + TaskDescriptor task=fm.getTask(); + Set saveset=lb!=null ? locality.getTempSet(lb) : null; + ParamsObject objectparams=md!=null ? new ParamsObject(md,tag++) : new ParamsObject(task, tag++); + if (lb!=null) { + paramstable.put(lb, objectparams); + backuptable.put(lb, new Hashtable()); + } else if (md!=null) + paramstable.put(md, objectparams); + else + paramstable.put(task, objectparams); + + for(int i=0; i tmpit=backuptable.get(lb).values().iterator(); tmpit.hasNext(); ) { + TempDescriptor tmp=tmpit.next(); + TypeDescriptor type=tmp.getType(); + if (type.isPtr()&&((GENERATEPRECISEGC) || (this.state.MULTICOREGC))) + objecttemps.addPtr(tmp); + else + objecttemps.addPrim(tmp); + } + /* Create temp to hold revert table */ + if (state.DSM&&(lb.getHasAtomic()||lb.isAtomic())) { + TempDescriptor reverttmp=new TempDescriptor("revertlist", typeutil.getClass(TypeUtil.ObjectClass)); + if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) + objecttemps.addPtr(reverttmp); + else + objecttemps.addPrim(reverttmp); + reverttable.put(lb, reverttmp); + } + } + } + + /** This method outputs the following information about classes + * and arrays: + * (1) For classes, what are the locations of pointers. + * (2) For arrays, does the array contain pointers or primitives. + * (3) For classes, does the class contain flags. + */ + + protected void generateLayoutStructs(PrintWriter output) { + Iterator it=state.getClassSymbolTable().getDescriptorsIterator(); + while(it.hasNext()) { + ClassDescriptor cn=(ClassDescriptor)it.next(); + output.println("unsigned INTPTR "+cn.getSafeSymbol()+"_pointers[]={"); + Iterator allit=cn.getFieldTable().getAllDescriptorsIterator(); + int count=0; + while(allit.hasNext()) { + FieldDescriptor fd=(FieldDescriptor)allit.next(); + TypeDescriptor type=fd.getType(); + if (state.DSM&&fd.isGlobal()) //Don't GC the global objects for now + continue; + if (type.isPtr()) + count++; + } + output.print(count); + allit=cn.getFieldTable().getAllDescriptorsIterator(); + while(allit.hasNext()) { + FieldDescriptor fd=(FieldDescriptor)allit.next(); + TypeDescriptor type=fd.getType(); + if (state.DSM&&fd.isGlobal()) //Don't GC the global objects for now + continue; + if (type.isPtr()) { + output.println(","); + output.print("((unsigned INTPTR)&(((struct "+cn.getSafeSymbol() +" *)0)->"+ + fd.getSafeSymbol()+"))"); + } + } + output.println("};"); + } + output.println("unsigned INTPTR * pointerarray[]={"); + boolean needcomma=false; + for(int i=0; i nativemethods=new HashSet(); + Set lbset=locality.getClassBindings(cn); + if (lbset!=null) { + for(Iterator lbit=lbset.iterator(); lbit.hasNext(); ) { + LocalityBinding lb=lbit.next(); + MethodDescriptor md=lb.getMethod(); + if (md.getModifiers().isNative()) { + //make sure we only print a native method once + if (nativemethods.contains(md)) { + FlatMethod fm=state.getMethodFlat(md); + generateTempStructs(fm, lb); + continue; + } else + nativemethods.add(md); + } + generateMethod(cn, md, lb, headersout, output); + } + } + for(Iterator methodit=cn.getMethods(); methodit.hasNext(); ) { + MethodDescriptor md=(MethodDescriptor)methodit.next(); + if (md.getModifiers().isNative()&&!nativemethods.contains(md)) { + //Need to build param structure for library code + FlatMethod fm=state.getMethodFlat(md); + generateTempStructs(fm, null); + generateMethodParam(cn, md, null, output); + } + } + } + + + protected void generateMethodParam(ClassDescriptor cn, MethodDescriptor md, LocalityBinding lb, PrintWriter output) { + /* Output parameter structure */ + if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { + ParamsObject objectparams=(ParamsObject) paramstable.get(lb!=null ? lb : md); + if ((state.DSM||state.SINGLETM)&&lb!=null) + output.println("struct "+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params {"); + else + output.println("struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params {"); + output.println(" int size;"); + output.println(" void * next;"); + for(int i=0; i atomicmethodmap; + static int atomicmethodcount=0; + + + BranchAnalysis branchanalysis; + protected void generateFlatMethod(FlatMethod fm, LocalityBinding lb, PrintWriter output) { + if (State.PRINTFLAT) + System.out.println(fm.printMethod()); + MethodDescriptor md=fm.getMethod(); + TaskDescriptor task=fm.getTask(); + ClassDescriptor cn=md!=null ? md.getClassDesc() : null; + ParamsObject objectparams=(ParamsObject)paramstable.get(lb!=null ? lb : md!=null ? md : task); + + HashSet arset=null; + branchanalysis=null; + + if (state.DELAYCOMP&&!lb.isAtomic()&&lb.getHasAtomic()) { + //create map + if (atomicmethodmap==null) + atomicmethodmap=new Hashtable(); + + //fix these so we get right strings for local variables + localsprefixaddr=localsprefix; + localsprefixderef=localsprefix+"->"; + arset=new HashSet(); + + //build branchanalysis + branchanalysis=new BranchAnalysis(locality, lb, delaycomp.getNotReady(lb), delaycomp.livecode(lb), state); + + //Generate commit methods here + for(Iterator fnit=fm.getNodeSet().iterator(); fnit.hasNext(); ) { + FlatNode fn=fnit.next(); + if (fn.kind()==FKind.FlatAtomicEnterNode&& + locality.getAtomic(lb).get(fn.getPrev(0)).intValue()==0&& + delaycomp.needsFission(lb, (FlatAtomicEnterNode) fn)) { + //We have an atomic enter + FlatAtomicEnterNode faen=(FlatAtomicEnterNode) fn; + Set exitset=faen.getExits(); + //generate header + String methodname=md.getSymbol()+(atomicmethodcount++); + AtomicRecord ar=new AtomicRecord(); + ar.name=methodname; + arset.add(ar); + + atomicmethodmap.put(faen, ar); + + //build data structure declaration + output.println("struct atomicprimitives_"+methodname+" {"); + + Set recordset=delaycomp.livecode(lb); + Set liveinto=delaycomp.liveinto(lb, faen, recordset); + Set liveout=delaycomp.liveout(lb, faen); + Set liveoutvirtualread=delaycomp.liveoutvirtualread(lb, faen); + ar.livein=liveinto; + ar.reallivein=new HashSet(liveinto); + ar.liveout=liveout; + ar.liveoutvirtualread=liveoutvirtualread; + + + for(Iterator it=liveinto.iterator(); it.hasNext(); ) { + TempDescriptor tmp=it.next(); + //remove the pointers + if (tmp.getType().isPtr()) { + it.remove(); + } else { + //let's print it here + output.println(tmp.getType().getSafeSymbol()+" "+tmp.getSafeSymbol()+";"); + } + } + for(Iterator it=liveout.iterator(); it.hasNext(); ) { + TempDescriptor tmp=it.next(); + //remove the pointers + if (tmp.getType().isPtr()) { + it.remove(); + } else if (!liveinto.contains(tmp)) { + //let's print it here + output.println(tmp.getType().getSafeSymbol()+" "+tmp.getSafeSymbol()+";"); + } + } + output.println("};"); + + //print out method name + 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) {"); + //build code for commit method + + //first define local primitives + Set alltemps=delaycomp.alltemps(lb, faen, recordset); + for(Iterator tmpit=alltemps.iterator(); tmpit.hasNext(); ) { + TempDescriptor tmp=tmpit.next(); + if (!tmp.getType().isPtr()) { + if (liveinto.contains(tmp)||liveoutvirtualread.contains(tmp)) { + //read from live into set + output.println(tmp.getType().getSafeSymbol()+" "+tmp.getSafeSymbol()+"=primitives->"+tmp.getSafeSymbol()+";"); + } else { + //just define + output.println(tmp.getType().getSafeSymbol()+" "+tmp.getSafeSymbol()+";"); + } + } + } + //turn off write barrier generation + wb.turnoff(); + state.SINGLETM=false; + generateCode(faen, fm, lb, exitset, output, false); + state.SINGLETM=true; + //turn on write barrier generation + wb.turnon(); + output.println("}\n\n"); + } + } + } + //redefine these back to normal + + localsprefixaddr="&"+localsprefix; + localsprefixderef=localsprefix+"."; + + generateHeader(fm, lb, md!=null ? md : task,output); + TempObject objecttemp=(TempObject) tempstable.get(lb!=null ? lb : md!=null ? md : task); + + if (state.DELAYCOMP&&!lb.isAtomic()&&lb.getHasAtomic()) { + for(Iterator arit=arset.iterator(); arit.hasNext(); ) { + AtomicRecord ar=arit.next(); + output.println("struct atomicprimitives_"+ar.name+" primitives_"+ar.name+";"); + } + } + + if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { + if (md!=null&&(state.DSM||state.SINGLETM)) + output.print(" struct "+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals "+localsprefix+"={"); + else if (md!=null&&!(state.DSM||state.SINGLETM)) + output.print(" struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals "+localsprefix+"={"); + else + output.print(" struct "+task.getSafeSymbol()+"_locals "+localsprefix+"={"); + output.print(objecttemp.numPointers()+","); + output.print(paramsprefix); + for(int j=0; j stopset, + PrintWriter output, + boolean firstpass) { + + /* Assign labels to FlatNode's if necessary.*/ + + Hashtable nodetolabel; + currlb=lb; + if (state.DELAYCOMP&&!firstpass) + nodetolabel=dcassignLabels(first, stopset); + else + nodetolabel=assignLabels(first, stopset); + + Set storeset=null; + HashSet genset=null; + HashSet refset=null; + Set unionset=null; + + if (state.DELAYCOMP&&!lb.isAtomic()&&lb.getHasAtomic()) { + storeset=delaycomp.livecode(lb); + genset=new HashSet(); + if (state.STMARRAY&&!state.DUALVIEW) { + refset=new HashSet(); + refset.addAll(delaycomp.getDeref(lb)); + refset.removeAll(delaycomp.getCannotDelay(lb)); + refset.removeAll(delaycomp.getOther(lb)); + } + if (firstpass) { + genset.addAll(delaycomp.getCannotDelay(lb)); + genset.addAll(delaycomp.getOther(lb)); + } else { + genset.addAll(delaycomp.getNotReady(lb)); + if (state.STMARRAY&&!state.DUALVIEW) { + genset.removeAll(refset); + } + } + unionset=new HashSet(); + unionset.addAll(storeset); + unionset.addAll(genset); + if (state.STMARRAY&&!state.DUALVIEW) + unionset.addAll(refset); + } + + /* Do the actual code generation */ + FlatNode current_node=null; + HashSet tovisit=new HashSet(); + HashSet visited=new HashSet(); + if (!firstpass) + tovisit.add(first.getNext(0)); + else + tovisit.add(first); + while(current_node!=null||!tovisit.isEmpty()) { + if (current_node==null) { + current_node=(FlatNode)tovisit.iterator().next(); + tovisit.remove(current_node); + } else if (tovisit.contains(current_node)) { + tovisit.remove(current_node); + } + visited.add(current_node); + if (nodetolabel.containsKey(current_node)) { + output.println("L"+nodetolabel.get(current_node)+":"); + } + if (state.INSTRUCTIONFAILURE) { + if (state.THREAD||state.DSM||state.SINGLETM) { + output.println("if ((++instructioncount)>failurecount) {instructioncount=0;injectinstructionfailure();}"); + } else + output.println("if ((--instructioncount)==0) injectinstructionfailure();"); + } + if (current_node.numNext()==0||stopset!=null&&stopset.contains(current_node)) { + output.print(" "); + if (!state.DELAYCOMP||firstpass) { + generateFlatNode(fm, current_node, output); + } else { + //store primitive variables in out set + AtomicRecord ar=atomicmethodmap.get((FlatAtomicEnterNode)first); + Set liveout=ar.liveout; + for(Iterator tmpit=liveout.iterator(); tmpit.hasNext(); ) { + TempDescriptor tmp=tmpit.next(); + output.println("primitives->"+tmp.getSafeSymbol()+"="+tmp.getSafeSymbol()+";"); + } + } + + if (current_node.kind()!=FKind.FlatReturnNode) { + if(state.MGC) { + // TODO add version for normal Java later + if((fm.getMethod() != null) && (fm.getMethod().isStaticBlock())) { + // a static block, check if it has been executed + output.println(" global_defs_p->" + fm.getMethod().getClassDesc().getSafeSymbol()+"static_block_exe_flag = 1;"); + output.println(""); + } + } + output.println(" return;"); + } + current_node=null; + } else if(current_node.numNext()==1) { + FlatNode nextnode; + if (state.DELAYCOMP) { + boolean specialprimitive=false; + //skip literals...no need to add extra overhead + if (storeset!=null&&storeset.contains(current_node)&¤t_node.kind()==FKind.FlatLiteralNode) { + TypeDescriptor typedesc=((FlatLiteralNode)current_node).getType(); + if (!typedesc.isClass()&&!typedesc.isArray()) { + specialprimitive=true; + } + } + + if (genset==null||genset.contains(current_node)||specialprimitive) { + generateFlatNode(fm, current_node, output); + } + if (state.STMARRAY&&!state.DUALVIEW&&refset!=null&&refset.contains(current_node)) { + //need to acquire lock + handleArrayDeref(fm, lb, current_node, output, firstpass); + } + if (storeset!=null&&storeset.contains(current_node)&&!specialprimitive) { + TempDescriptor wrtmp=current_node.writesTemps()[0]; + if (firstpass) { + //need to store value written by previous node + if (wrtmp.getType().isPtr()) { + //only lock the objects that may actually need locking + if (recorddc.getNeedTrans(lb, current_node)&& + (!state.STMARRAY||state.DUALVIEW||!wrtmp.getType().isArray()|| + wrtmp.getType().getSymbol().equals(TypeUtil.ObjectClass))) { + output.println("STOREPTR("+generateTemp(fm, wrtmp)+");/* "+current_node.nodeid+" */"); + } else { + output.println("STOREPTRNOLOCK("+generateTemp(fm, wrtmp)+");/* "+current_node.nodeid+" */"); + } + } else { + output.println("STORE"+wrtmp.getType().getSafeDescriptor()+"("+generateTemp(fm, wrtmp)+");/* "+current_node.nodeid+" */"); + } + } else { + //need to read value read by previous node + if (wrtmp.getType().isPtr()) { + output.println("RESTOREPTR("+generateTemp(fm, wrtmp)+");/* "+current_node.nodeid+" */"); + } else { + output.println("RESTORE"+wrtmp.getType().getSafeDescriptor()+"("+generateTemp(fm, wrtmp)+"); /* "+current_node.nodeid+" */"); + } + } + } + nextnode=current_node.getNext(0); + } else { + output.print(" "); + generateFlatNode(fm, current_node, output); + nextnode=current_node.getNext(0); + } + if (visited.contains(nextnode)) { + output.println("goto L"+nodetolabel.get(nextnode)+";"); + current_node=null; + } else + current_node=nextnode; + } else if (current_node.numNext()==2) { + /* Branch */ + if (state.DELAYCOMP) { + boolean computeside=false; + if (firstpass) { + //need to record which way it should go + if (genset==null||genset.contains(current_node)) { + if (storeset!=null&&storeset.contains(current_node)) { + //need to store which way branch goes + generateStoreFlatCondBranch(fm, lb, (FlatCondBranch)current_node, "L"+nodetolabel.get(current_node.getNext(1)), output); + } else + generateFlatCondBranch(fm, (FlatCondBranch)current_node, "L"+nodetolabel.get(current_node.getNext(1)), output); + } else { + //which side to execute + computeside=true; + } + } else { + if (genset.contains(current_node)) { + generateFlatCondBranch(fm, (FlatCondBranch)current_node, "L"+nodetolabel.get(current_node.getNext(1)), output); + } else if (storeset.contains(current_node)) { + //need to do branch + branchanalysis.generateGroupCode(current_node, output, nodetolabel); + } else { + //which side to execute + computeside=true; + } + } + if (computeside) { + Set leftset=DelayComputation.getNext(current_node, 0, unionset, lb,locality, true); + int branch=0; + if (leftset.size()==0) + branch=1; + if (visited.contains(current_node.getNext(branch))) { + //already visited -- build jump + output.println("goto L"+nodetolabel.get(current_node.getNext(branch))+";"); + current_node=null; + } else { + current_node=current_node.getNext(branch); + } + } else { + if (!visited.contains(current_node.getNext(1))) + tovisit.add(current_node.getNext(1)); + if (visited.contains(current_node.getNext(0))) { + output.println("goto L"+nodetolabel.get(current_node.getNext(0))+";"); + current_node=null; + } else + current_node=current_node.getNext(0); + } + } else { + output.print(" "); + generateFlatCondBranch(fm, (FlatCondBranch)current_node, "L"+nodetolabel.get(current_node.getNext(1)), output); + if (!visited.contains(current_node.getNext(1))) + tovisit.add(current_node.getNext(1)); + if (visited.contains(current_node.getNext(0))) { + output.println("goto L"+nodetolabel.get(current_node.getNext(0))+";"); + current_node=null; + } else + current_node=current_node.getNext(0); + } + } else throw new Error(); + } + } + + protected void handleArrayDeref(FlatMethod fm, LocalityBinding lb, FlatNode fn, PrintWriter output, boolean firstpass) { + if (fn.kind()==FKind.FlatSetElementNode) { + FlatSetElementNode fsen=(FlatSetElementNode) fn; + String dst=generateTemp(fm, fsen.getDst()); + String src=generateTemp(fm, fsen.getSrc()); + String index=generateTemp(fm, fsen.getIndex()); + TypeDescriptor elementtype=fsen.getDst().getType().dereference(); + String type=""; + if (elementtype.isArray()||elementtype.isClass()) + type="void *"; + else + type=elementtype.getSafeSymbol()+" "; + if (firstpass) { + output.println("STOREARRAY("+dst+","+index+","+type+")"); + } else { + output.println("{"); + output.println(" struct ArrayObject *array;"); + output.println(" int index;"); + output.println(" RESTOREARRAY(array,index);"); + output.println(" (("+type+"*)(((char *)&array->___length___)+sizeof(int)))[index]="+src+";"); + output.println("}"); + } + } else if (fn.kind()==FKind.FlatElementNode) { + FlatElementNode fen=(FlatElementNode) fn; + String src=generateTemp(fm, fen.getSrc()); + String index=generateTemp(fm, fen.getIndex()); + TypeDescriptor elementtype=fen.getSrc().getType().dereference(); + String dst=generateTemp(fm, fen.getDst()); + String type=""; + if (elementtype.isArray()||elementtype.isClass()) + type="void *"; + else + type=elementtype.getSafeSymbol()+" "; + if (firstpass) { + output.println("STOREARRAY("+src+","+index+","+type+")"); + } else { + output.println("{"); + output.println(" struct ArrayObject *array;"); + output.println(" int index;"); + output.println(" RESTOREARRAY(array,index);"); + output.println(" "+dst+"=(("+type+"*)(((char *)&array->___length___)+sizeof(int)))[index];"); + output.println("}"); + } + } + } + /** Special label assignment for delaycomputation */ + protected Hashtable dcassignLabels(FlatNode first, Set lastset) { + HashSet tovisit=new HashSet(); + HashSet visited=new HashSet(); + int labelindex=0; + Hashtable nodetolabel=new Hashtable(); + + //Label targets of branches + Set targets=branchanalysis.getTargets(); + for(Iterator it=targets.iterator(); it.hasNext(); ) { + nodetolabel.put(it.next(), new Integer(labelindex++)); + } + + + tovisit.add(first); + /*Assign labels first. A node needs a label if the previous + * node has two exits or this node is a join point. */ + + while(!tovisit.isEmpty()) { + FlatNode fn=(FlatNode)tovisit.iterator().next(); + tovisit.remove(fn); + visited.add(fn); + + + if(lastset!=null&&lastset.contains(fn)) { + // if last is not null and matches, don't go + // any further for assigning labels + continue; + } + + for(int i=0; i0) { + //1) Edge >1 of node + nodetolabel.put(nn,new Integer(labelindex++)); + } + if (!visited.contains(nn)&&!tovisit.contains(nn)) { + tovisit.add(nn); + } else { + //2) Join point + nodetolabel.put(nn,new Integer(labelindex++)); + } + } + } + return nodetolabel; + + } + + /** Generate text string that corresponds to the TempDescriptor td. */ + protected String generateTemp(FlatMethod fm, TempDescriptor td) { + MethodDescriptor md=fm.getMethod(); + TaskDescriptor task=fm.getTask(); + TempObject objecttemps=(TempObject) tempstable.get(currlb!=null ? currlb : md!=null ? md : task); + + if (objecttemps.isLocalPrim(td)||objecttemps.isParamPrim(td)) { + return td.getSafeSymbol(); + } + + if (objecttemps.isLocalPtr(td)) { + return localsprefixderef+td.getSafeSymbol(); + } + + if (objecttemps.isParamPtr(td)) { + return paramsprefix+"->"+td.getSafeSymbol(); + } + + throw new Error(); + } + + public void generateFlatBackEdge(FlatMethod fm, FlatBackEdge fn, PrintWriter output) { + if (state.SINGLETM&&state.SANDBOX&&(locality.getAtomic(currlb).get(fn).intValue()>0)) { + output.println("if (unlikely((--transaction_check_counter)<=0)) checkObjects();"); + } + if(state.DSM&&state.SANDBOX&&(locality.getAtomic(currlb).get(fn).intValue()>0)) { + output.println("if (unlikely((--transaction_check_counter)<=0)) checkObjects();"); + } + if (((state.THREAD||state.DSM||state.SINGLETM)&&GENERATEPRECISEGC)) { + if(state.DSM&&locality.getAtomic(currlb).get(fn).intValue()>0) { + output.println("if (needtocollect) checkcollect2("+localsprefixaddr+");"); + } else { + output.println("if (unlikely(needtocollect)) checkcollect("+localsprefixaddr+");"); + } + } else + output.println("/* nop */"); + } + + + public void generateFlatPrefetchNode(FlatMethod fm, FlatPrefetchNode fpn, PrintWriter output) { + if (state.PREFETCH) { + Vector oids = new Vector(); + Vector fieldoffset = new Vector(); + Vector endoffset = new Vector(); + int tuplecount = 0; //Keeps track of number of prefetch tuples that need to be generated + for(Iterator it = fpn.hspp.iterator(); it.hasNext(); ) { + PrefetchPair pp = (PrefetchPair) it.next(); + Integer statusbase = locality.getNodePreTempInfo(currlb,fpn).get(pp.base); + /* Find prefetches that can generate oid */ + if(statusbase == LocalityAnalysis.GLOBAL) { + generateTransCode(fm, currlb, pp, oids, fieldoffset, endoffset, tuplecount, locality.getAtomic(currlb).get(fpn).intValue()>0, false); + tuplecount++; + } else if (statusbase == LocalityAnalysis.LOCAL) { + generateTransCode(fm,currlb,pp,oids,fieldoffset,endoffset,tuplecount,false,true); + } else { + continue; + } + } + if (tuplecount==0) + return; + System.out.println("Adding prefetch "+fpn+ " to method:" +fm); + output.println("{"); + output.println("/* prefetch */"); + output.println("/* prefetchid_" + fpn.siteid + " */"); + output.println("void * prefptr;"); + output.println("int tmpindex;"); + + output.println("if((evalPrefetch["+fpn.siteid+"].operMode) || (evalPrefetch["+fpn.siteid+"].retrycount <= 0)) {"); + /*Create C code for oid array */ + output.print(" unsigned int oidarray_[] = {"); + boolean needcomma=false; + for (Iterator it = oids.iterator(); it.hasNext(); ) { + if (needcomma) + output.print(", "); + output.print(it.next()); + needcomma=true; + } + output.println("};"); + + /*Create C code for endoffset values */ + output.print(" unsigned short endoffsetarry_[] = {"); + needcomma=false; + for (Iterator it = endoffset.iterator(); it.hasNext(); ) { + if (needcomma) + output.print(", "); + output.print(it.next()); + needcomma=true; + } + output.println("};"); + + /*Create C code for Field Offset Values */ + output.print(" short fieldarry_[] = {"); + needcomma=false; + for (Iterator it = fieldoffset.iterator(); it.hasNext(); ) { + if (needcomma) + output.print(", "); + output.print(it.next()); + needcomma=true; + } + output.println("};"); + /* make the prefetch call to Runtime */ + output.println(" if(!evalPrefetch["+fpn.siteid+"].operMode) {"); + output.println(" evalPrefetch["+fpn.siteid+"].retrycount = RETRYINTERVAL;"); + output.println(" }"); + output.println(" prefetch("+fpn.siteid+" ,"+tuplecount+", oidarray_, endoffsetarry_, fieldarry_);"); + output.println(" } else {"); + output.println(" evalPrefetch["+fpn.siteid+"].retrycount--;"); + output.println(" }"); + output.println("}"); + } + } + + public void generateTransCode(FlatMethod fm, LocalityBinding lb,PrefetchPair pp, Vector oids, Vector fieldoffset, Vector endoffset, int tuplecount, boolean inside, boolean localbase) { + short offsetcount = 0; + int breakindex=0; + if (inside) { + breakindex=1; + } else if (localbase) { + for(; breakindexpp.desc.size()) //all local + return; + + TypeDescriptor lasttype=pp.base.getType(); + String basestr=generateTemp(fm, pp.base); + String teststr=""; + boolean maybenull=fm.getMethod().isStatic()|| + !pp.base.equals(fm.getParameter(0)); + + for(int i=0; i"+ + fd.getSafeSymbol(); + } else { + basestr=basestr+"->"+ + fd.getSafeSymbol(); + maybenull=true; + } + lasttype=fd.getType(); + } else { + IndexDescriptor id=(IndexDescriptor)desc; + indexcheck="((tmpindex="; + for(int j=0; j=0)&(tmpindex<((struct ArrayObject *)prefptr)->___length___)"; + + if (!teststr.equals("")) + teststr+="&&"; + teststr+="((prefptr="+basestr+")!= NULL) &&"+indexcheck; + basestr="((void **)(((char *) &(((struct ArrayObject *)prefptr)->___length___))+sizeof(int)))[tmpindex]"; + maybenull=true; + lasttype=lasttype.dereference(); + } + } + + String oid; + if (teststr.equals("")) { + oid="((unsigned int)"+basestr+")"; + } else { + oid="((unsigned int)(("+teststr+")?"+basestr+":NULL))"; + } + oids.add(oid); + + for(int i = breakindex; i < pp.desc.size(); i++) { + String newfieldoffset; + Object desc = pp.getDescAt(i); + if(desc instanceof FieldDescriptor) { + FieldDescriptor fd=(FieldDescriptor)desc; + newfieldoffset = new String("(unsigned int)(&(((struct "+ lasttype.getSafeSymbol()+" *)0)->"+ fd.getSafeSymbol()+ "))"); + lasttype=fd.getType(); + } else { + newfieldoffset = ""; + IndexDescriptor id=(IndexDescriptor)desc; + for(int j = 0; j < id.tddesc.size(); j++) { + newfieldoffset += generateTemp(fm, id.getTempDescAt(j)) + "+"; + } + newfieldoffset += id.offset.toString(); + lasttype=lasttype.dereference(); + } + fieldoffset.add(newfieldoffset); + } + + int base=(tuplecount>0) ? ((Short)endoffset.get(tuplecount-1)).intValue() : 0; + base+=pp.desc.size()-breakindex; + endoffset.add(new Short((short)base)); + } + + + + public void generateFlatGlobalConvNode(FlatMethod fm, FlatGlobalConvNode fgcn, PrintWriter output) { + if (currlb!=fgcn.getLocality()) + return; + /* Have to generate flat globalconv */ + if (fgcn.getMakePtr()) { + if (state.DSM) { + output.println("TRANSREAD("+generateTemp(fm, fgcn.getSrc())+", (unsigned int) "+generateTemp(fm, fgcn.getSrc())+");"); + } else { + if ((dc==null)||!state.READSET&&dc.getNeedTrans(currlb, fgcn)||state.READSET&&dc.getNeedWriteTrans(currlb, fgcn)) { + //need to do translation + output.println("TRANSREAD("+generateTemp(fm, fgcn.getSrc())+", "+generateTemp(fm, fgcn.getSrc())+", (void *)("+localsprefixaddr+"));"); + } else if (state.READSET&&dc.getNeedTrans(currlb, fgcn)) { + if (state.HYBRID&&delaycomp.getConv(currlb).contains(fgcn)) { + output.println("TRANSREADRDFISSION("+generateTemp(fm, fgcn.getSrc())+", "+generateTemp(fm, fgcn.getSrc())+");"); + } else + output.println("TRANSREADRD("+generateTemp(fm, fgcn.getSrc())+", "+generateTemp(fm, fgcn.getSrc())+");"); + } + } + } else { + /* Need to convert to OID */ + if ((dc==null)||dc.getNeedSrcTrans(currlb,fgcn)) { + if (fgcn.doConvert()||(delaycomp!=null&&delaycomp.needsFission(currlb, fgcn.getAtomicEnter())&&atomicmethodmap.get(fgcn.getAtomicEnter()).reallivein.contains(fgcn.getSrc()))) { + output.println(generateTemp(fm, fgcn.getSrc())+"=(void *)COMPOID("+generateTemp(fm, fgcn.getSrc())+");"); + } else { + output.println(generateTemp(fm, fgcn.getSrc())+"=NULL;"); + } + } + } + } + + int sandboxcounter=0; + public void generateFlatAtomicEnterNode(FlatMethod fm, FlatAtomicEnterNode faen, PrintWriter output) { + /* Check to see if we need to generate code for this atomic */ + if (locality==null) { + if (GENERATEPRECISEGC) { + output.println("if (pthread_mutex_trylock(&atomiclock)!=0) {"); + output.println("stopforgc((struct garbagelist *) &___locals___);"); + output.println("pthread_mutex_lock(&atomiclock);"); + output.println("restartaftergc();"); + output.println("}"); + } else { + output.println("pthread_mutex_lock(&atomiclock);"); + } + return; + } + + if (locality.getAtomic(currlb).get(faen.getPrev(0)).intValue()>0) + return; + + + if (state.SANDBOX) { + outsandbox.println("int atomiccounter"+sandboxcounter+"=LOW_CHECK_FREQUENCY;"); + output.println("counter_reset_pointer=&atomiccounter"+sandboxcounter+";"); + } + + if (state.DELAYCOMP&&delaycomp.needsFission(currlb, faen)) { + AtomicRecord ar=atomicmethodmap.get(faen); + //copy in + for(Iterator tmpit=ar.livein.iterator(); tmpit.hasNext(); ) { + TempDescriptor tmp=tmpit.next(); + output.println("primitives_"+ar.name+"."+tmp.getSafeSymbol()+"="+tmp.getSafeSymbol()+";"); + } + + //copy outs that depend on path + for(Iterator tmpit=ar.liveoutvirtualread.iterator(); tmpit.hasNext(); ) { + TempDescriptor tmp=tmpit.next(); + if (!ar.livein.contains(tmp)) + output.println("primitives_"+ar.name+"."+tmp.getSafeSymbol()+"="+tmp.getSafeSymbol()+";"); + } + } + + /* Backup the temps. */ + for(Iterator tmpit=locality.getTemps(currlb).get(faen).iterator(); tmpit.hasNext(); ) { + TempDescriptor tmp=tmpit.next(); + output.println(generateTemp(fm, backuptable.get(currlb).get(tmp))+"="+generateTemp(fm,tmp)+";"); + } + + output.println("goto transstart"+faen.getIdentifier()+";"); + + /******* Print code to retry aborted transaction *******/ + output.println("transretry"+faen.getIdentifier()+":"); + + /* Restore temps */ + for(Iterator tmpit=locality.getTemps(currlb).get(faen).iterator(); tmpit.hasNext(); ) { + TempDescriptor tmp=tmpit.next(); + output.println(generateTemp(fm, tmp)+"="+generateTemp(fm,backuptable.get(currlb).get(tmp))+";"); + } + + if (state.DSM) { + /********* Need to revert local object store ********/ + String revertptr=generateTemp(fm, reverttable.get(currlb)); + + output.println("while ("+revertptr+") {"); + output.println("struct ___Object___ * tmpptr;"); + output.println("tmpptr="+revertptr+"->"+nextobjstr+";"); + output.println("REVERT_OBJ("+revertptr+");"); + output.println(revertptr+"=tmpptr;"); + output.println("}"); + } + /******* Tell the runtime to start the transaction *******/ + + output.println("transstart"+faen.getIdentifier()+":"); + if (state.SANDBOX) { + output.println("transaction_check_counter=*counter_reset_pointer;"); + sandboxcounter++; + } + output.println("transStart();"); + + if (state.ABORTREADERS||state.SANDBOX) { + if (state.SANDBOX) + output.println("abortenabled=1;"); + output.println("if (_setjmp(aborttrans)) {"); + output.println(" goto transretry"+faen.getIdentifier()+"; }"); + } + } + + public void generateFlatAtomicExitNode(FlatMethod fm, FlatAtomicExitNode faen, PrintWriter output) { + /* Check to see if we need to generate code for this atomic */ + if (locality==null) { + output.println("pthread_mutex_unlock(&atomiclock);"); + return; + } + if (locality.getAtomic(currlb).get(faen).intValue()>0) + return; + //store the revert list before we lose the transaction object + + if (state.DSM) { + String revertptr=generateTemp(fm, reverttable.get(currlb)); + output.println(revertptr+"=revertlist;"); + output.println("if (transCommit()) {"); + output.println("if (unlikely(needtocollect)) checkcollect("+localsprefixaddr+");"); + output.println("goto transretry"+faen.getAtomicEnter().getIdentifier()+";"); + output.println("} else {"); + /* Need to commit local object store */ + output.println("while ("+revertptr+") {"); + output.println("struct ___Object___ * tmpptr;"); + output.println("tmpptr="+revertptr+"->"+nextobjstr+";"); + output.println("COMMIT_OBJ("+revertptr+");"); + output.println(revertptr+"=tmpptr;"); + output.println("}"); + output.println("}"); + return; + } + + if (!state.DELAYCOMP) { + //Normal STM stuff + output.println("if (transCommit()) {"); + /* Transaction aborts if it returns true */ + output.println("if (unlikely(needtocollect)) checkcollect("+localsprefixaddr+");"); + output.println("goto transretry"+faen.getAtomicEnter().getIdentifier()+";"); + output.println("}"); + } else { + if (delaycomp.optimizeTrans(currlb, faen.getAtomicEnter())&&(!state.STMARRAY||state.DUALVIEW)) { + AtomicRecord ar=atomicmethodmap.get(faen.getAtomicEnter()); + output.println("LIGHTWEIGHTCOMMIT("+ar.name+", &primitives_"+ar.name+", &"+localsprefix+", "+paramsprefix+", transretry"+faen.getAtomicEnter().getIdentifier()+");"); + //copy out + for(Iterator tmpit=ar.liveout.iterator(); tmpit.hasNext(); ) { + TempDescriptor tmp=tmpit.next(); + output.println(tmp.getSafeSymbol()+"=primitives_"+ar.name+"."+tmp.getSafeSymbol()+";"); + } + } else if (delaycomp.needsFission(currlb, faen.getAtomicEnter())) { + AtomicRecord ar=atomicmethodmap.get(faen.getAtomicEnter()); + //do call + output.println("if (transCommit((void (*)(void *, void *, void *))&"+ar.name+", &primitives_"+ar.name+", &"+localsprefix+", "+paramsprefix+")) {"); + output.println("if (unlikely(needtocollect)) checkcollect("+localsprefixaddr+");"); + output.println("goto transretry"+faen.getAtomicEnter().getIdentifier()+";"); + output.println("}"); + //copy out + output.println("else {"); + for(Iterator tmpit=ar.liveout.iterator(); tmpit.hasNext(); ) { + TempDescriptor tmp=tmpit.next(); + output.println(tmp.getSafeSymbol()+"=primitives_"+ar.name+"."+tmp.getSafeSymbol()+";"); + } + output.println("}"); + } else { + output.println("if (transCommit(NULL, NULL, NULL, NULL)) {"); + output.println("if (unlikely(needtocollect)) checkcollect("+localsprefixaddr+");"); + output.println("goto transretry"+faen.getAtomicEnter().getIdentifier()+";"); + output.println("}"); + } + } + } + + protected void generateFlatCall(FlatMethod fm, FlatCall fc, PrintWriter output) { + MethodDescriptor md=fc.getMethod(); + ParamsObject objectparams=(ParamsObject)paramstable.get(currlb!=null ? locality.getBinding(currlb, fc) : md); + ClassDescriptor cn=md.getClassDesc(); + + // if the called method is a static block or a static method or a constructor + // need to check if it can be invoked inside some static block + if(state.MGC) { + // TODO add version for normal Java later + if((md.isStatic() || md.isStaticBlock() || md.isConstructor()) && + ((fm.getMethod().isStaticBlock()) || (fm.getMethod().isInvokedByStatic()))) { + if(!md.isInvokedByStatic()) { + System.err.println("Error: a method that is invoked inside a static block is not tagged!"); + } + // is a static block or is invoked in some static block + ClassDescriptor cd = fm.getMethod().getClassDesc(); + if(cd == cn) { + // the same class, do nothing + // TODO may want to invoke static field initialization here + } else { + if((cn.getNumStaticFields() != 0) || (cn.getNumStaticBlocks() != 0)) { + // need to check if the class' static fields have been initialized and/or + // its static blocks have been executed + output.println("#ifdef MGC_STATIC_INIT_CHECK"); + output.println("if(global_defs_p->" + cn.getSafeSymbol()+"static_block_exe_flag == 0) {"); + if(cn.getNumStaticBlocks() != 0) { + MethodDescriptor t_md = (MethodDescriptor)cn.getMethodTable().get("staticblocks"); + output.println(" "+cn.getSafeSymbol()+t_md.getSafeSymbol()+"_"+t_md.getSafeMethodDescriptor()+"();"); + } else { + output.println(" global_defs_p->" + cn.getSafeSymbol()+"static_block_exe_flag = 1;"); + } + output.println("}"); + output.println("#endif // MGC_STATIC_INIT_CHECK"); + } + } + } + if((md.getSymbol().equals("MonitorEnter") || md.getSymbol().equals("MonitorExit")) && fc.getThis().getSymbol().equals("classobj")) { + // call MonitorEnter/MonitorExit on a class obj + output.println(" " + cn.getSafeSymbol()+md.getSafeSymbol()+"_" + +md.getSafeMethodDescriptor() + "((struct ___Object___*)(&global_defs_p->" + + fc.getThis().getType().getClassDesc().getSafeSymbol() +"classobj));"); + return; + } + } + + output.println("{"); + if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { + if (currlb!=null) { + LocalityBinding fclb=locality.getBinding(currlb, fc); + output.print(" struct "+cn.getSafeSymbol()+fclb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={"); + } else + output.print(" struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={"); + output.print(objectparams.numPointers()); + output.print(", "+localsprefixaddr); + if (md.getThis()!=null) { + output.print(", "); + output.print("(struct "+md.getThis().getType().getSafeSymbol() +" *)"+ generateTemp(fm,fc.getThis())); + } + if (fc.getThis()!=null&&md.getThis()==null) { + System.out.println("WARNING!!!!!!!!!!!!"); + System.out.println("Source code calls static method "+md+" on an object in "+fm.getMethod()+"!"); + } + + + for(int i=0; itype*"+maxcount+"+"+virtualcalls.getLocalityNumber(fclb)+"])"); + } else + output.print("))virtualtable["+generateTemp(fm,fc.getThis())+"->type*"+maxcount+"+"+virtualcalls.getMethodNumber(md)+"])"); + } + + output.print("("); + boolean needcomma=false; + if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { + output.print("&__parameterlist__"); + needcomma=true; + } + + if (!GENERATEPRECISEGC && !this.state.MULTICOREGC) { + if (fc.getThis()!=null) { + TypeDescriptor ptd=null; + if(md.getThis() != null) { + ptd = md.getThis().getType(); + } else { + ptd = fc.getThis().getType(); + } + if (needcomma) + output.print(","); + if(state.MGC && ptd.isClass() && ptd.getClassDesc().isEnum()) { + // do nothing + } else if (ptd.isClass()&&!ptd.isArray()) + output.print("(struct "+ptd.getSafeSymbol()+" *) "); + output.print(generateTemp(fm,fc.getThis())); + needcomma=true; + } + } + + for(int i=0; i"+field+ ";"); + if (ffn.getField().getType().isPtr()&&locality.getAtomic(currlb).get(ffn).intValue()>0&& + locality.getNodePreTempInfo(currlb, ffn).get(ffn.getSrc())!=LocalityAnalysis.SCRATCH) { + if ((dc==null)||(!state.READSET&&dc.getNeedTrans(currlb, ffn))|| + (state.READSET&&dc.getNeedWriteTrans(currlb, ffn))) { + output.println("TRANSREAD("+dst+", "+dst+", (void *) (" + localsprefixaddr + "));"); + } else if (state.READSET&&dc.getNeedTrans(currlb, ffn)) { + if (state.HYBRID&&delaycomp.getConv(currlb).contains(ffn)) { + output.println("TRANSREADRDFISSION("+dst+", "+dst+");"); + } else + output.println("TRANSREADRD("+dst+", "+dst+");"); + } + } + } else if (state.DSM) { + Integer status=locality.getNodePreTempInfo(currlb,ffn).get(ffn.getSrc()); + if (status==LocalityAnalysis.GLOBAL) { + String field=ffn.getField().getSafeSymbol(); + String src=generateTemp(fm, ffn.getSrc()); + String dst=generateTemp(fm, ffn.getDst()); + + if (ffn.getField().getType().isPtr()) { + output.println(dst+"="+ src +"->"+field+ ";"); + output.println("TRANSREAD("+dst+", (unsigned int) "+dst+");"); + } else { + output.println(dst+"="+ src+"->"+field+";"); + } + } else if (status==LocalityAnalysis.LOCAL) { + if (ffn.getField().getType().isPtr()&& + ffn.getField().isGlobal()) { + String field=ffn.getField().getSafeSymbol(); + String src=generateTemp(fm, ffn.getSrc()); + String dst=generateTemp(fm, ffn.getDst()); + output.println(dst+"="+ src +"->"+field+ ";"); + if (locality.getAtomic(currlb).get(ffn).intValue()>0) + output.println("TRANSREAD("+dst+", (unsigned int) "+dst+");"); + } else + output.println(generateTemp(fm, ffn.getDst())+"="+ generateTemp(fm,ffn.getSrc())+"->"+ ffn.getField().getSafeSymbol()+";"); + } else if (status==LocalityAnalysis.EITHER) { + //Code is reading from a null pointer + output.println("if ("+generateTemp(fm, ffn.getSrc())+") {"); + output.println("#ifndef RAW"); + output.println("printf(\"BIG ERROR\\n\");exit(-1);}"); + output.println("#endif"); + //This should throw a suitable null pointer error + output.println(generateTemp(fm, ffn.getDst())+"="+ generateTemp(fm,ffn.getSrc())+"->"+ ffn.getField().getSafeSymbol()+";"); + } else + throw new Error("Read from non-global/non-local in:"+currlb.getExplanation()); + } + } + + protected void generateFlatSetFieldNode(FlatMethod fm, FlatSetFieldNode fsfn, PrintWriter output) { + if (fsfn.getField().getSymbol().equals("length")&&fsfn.getDst().getType().isArray()) + throw new Error("Can't set array length"); + if (state.SINGLETM && locality.getAtomic(currlb).get(fsfn).intValue()>0) { + //Single Machine Transaction Case + boolean srcptr=fsfn.getSrc().getType().isPtr(); + String src=generateTemp(fm,fsfn.getSrc()); + String dst=generateTemp(fm,fsfn.getDst()); + output.println("//"+srcptr+" "+fsfn.getSrc().getType().isNull()); + if (srcptr&&!fsfn.getSrc().getType().isNull()) { + output.println("{"); + if ((dc==null)||dc.getNeedSrcTrans(currlb, fsfn)&& + locality.getNodePreTempInfo(currlb, fsfn).get(fsfn.getSrc())!=LocalityAnalysis.SCRATCH) { + output.println("INTPTR srcoid=("+src+"!=NULL?((INTPTR)"+src+"->"+oidstr+"):0);"); + } else { + output.println("INTPTR srcoid=(INTPTR)"+src+";"); + } + } + if (wb.needBarrier(fsfn)&& + locality.getNodePreTempInfo(currlb, fsfn).get(fsfn.getDst())!=LocalityAnalysis.SCRATCH) { + if (state.EVENTMONITOR) { + output.println("if ("+dst+"->___objstatus___&DIRTY) EVLOGEVENTOBJ(EV_WRITE,"+dst+"->objuid)"); + } + output.println("*((unsigned int *)&("+dst+"->___objstatus___))|=DIRTY;"); + } + if (srcptr&!fsfn.getSrc().getType().isNull()) { + output.println("*((unsigned INTPTR *)&("+dst+"->"+ + fsfn.getField().getSafeSymbol()+"))=srcoid;"); + output.println("}"); + } else { + output.println(dst+"->"+ + fsfn.getField().getSafeSymbol()+"="+ src+";"); + } + } else if (state.DSM && locality.getAtomic(currlb).get(fsfn).intValue()>0) { + Integer statussrc=locality.getNodePreTempInfo(currlb,fsfn).get(fsfn.getSrc()); + Integer statusdst=locality.getNodeTempInfo(currlb).get(fsfn).get(fsfn.getDst()); + boolean srcglobal=statussrc==LocalityAnalysis.GLOBAL; + + String src=generateTemp(fm,fsfn.getSrc()); + String dst=generateTemp(fm,fsfn.getDst()); + if (srcglobal) { + output.println("{"); + output.println("INTPTR srcoid=("+src+"!=NULL?((INTPTR)"+src+"->"+oidstr+"):0);"); + } + if (statusdst.equals(LocalityAnalysis.GLOBAL)) { + String glbdst=dst; + //mark it dirty + if (wb.needBarrier(fsfn)) + output.println("*((unsigned int *)&("+dst+"->___localcopy___))|=DIRTY;"); + if (srcglobal) { + output.println("*((unsigned INTPTR *)&("+glbdst+"->"+ + fsfn.getField().getSafeSymbol()+"))=srcoid;"); + } else + output.println(glbdst+"->"+ + fsfn.getField().getSafeSymbol()+"="+ src+";"); + } else if (statusdst.equals(LocalityAnalysis.LOCAL)) { + /** Check if we need to copy */ + output.println("if(!"+dst+"->"+localcopystr+") {"); + /* Link object into list */ + String revertptr=generateTemp(fm, reverttable.get(currlb)); + output.println(revertptr+"=revertlist;"); + if (GENERATEPRECISEGC || this.state.MULTICOREGC) + output.println("COPY_OBJ((struct garbagelist *)"+localsprefixaddr+",(struct ___Object___ *)"+dst+");"); + else + output.println("COPY_OBJ("+dst+");"); + output.println(dst+"->"+nextobjstr+"="+revertptr+";"); + output.println("revertlist=(struct ___Object___ *)"+dst+";"); + output.println("}"); + if (srcglobal) + output.println(dst+"->"+ + fsfn.getField().getSafeSymbol()+"=(void *) srcoid;"); + else + output.println(dst+"->"+ + fsfn.getField().getSafeSymbol()+"="+ src+";"); + } else if (statusdst.equals(LocalityAnalysis.EITHER)) { + //writing to a null...bad + output.println("if ("+dst+") {"); + output.println("printf(\"BIG ERROR 2\\n\");exit(-1);}"); + if (srcglobal) + output.println(dst+"->"+ + fsfn.getField().getSafeSymbol()+"=(void *) srcoid;"); + else + output.println(dst+"->"+ + fsfn.getField().getSafeSymbol()+"="+ src+";"); + } + if (srcglobal) { + output.println("}"); + } + } + } + + protected void generateFlatElementNode(FlatMethod fm, FlatElementNode fen, PrintWriter output) { + TypeDescriptor elementtype=fen.getSrc().getType().dereference(); + String type=""; + + if (state.MGC && elementtype.isClass() && elementtype.getClassDesc().isEnum()) { + type="int "; + } else if (elementtype.isArray()||elementtype.isClass()) + type="void *"; + else + type=elementtype.getSafeSymbol()+" "; + + if (this.state.ARRAYBOUNDARYCHECK && fen.needsBoundsCheck()) { + output.println("if (unlikely(((unsigned int)"+generateTemp(fm, fen.getIndex())+") >= "+generateTemp(fm,fen.getSrc()) + "->___length___))"); + output.println("failedboundschk();"); + } + if (state.SINGLETM) { + //Single machine transaction case + String dst=generateTemp(fm, fen.getDst()); + 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))) { + output.println(dst +"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc())+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex())+"];"); + } else { + output.println("STMGETARRAY("+dst+", "+ generateTemp(fm,fen.getSrc())+", "+generateTemp(fm, fen.getIndex())+", "+type+");"); + } + + if (elementtype.isPtr()&&locality.getAtomic(currlb).get(fen).intValue()>0&& + locality.getNodePreTempInfo(currlb, fen).get(fen.getSrc())!=LocalityAnalysis.SCRATCH) { + if ((dc==null)||!state.READSET&&dc.getNeedTrans(currlb, fen)||state.READSET&&dc.getNeedWriteTrans(currlb, fen)) { + output.println("TRANSREAD("+dst+", "+dst+", (void *)(" + localsprefixaddr+"));"); + } else if (state.READSET&&dc.getNeedTrans(currlb, fen)) { + if (state.HYBRID&&delaycomp.getConv(currlb).contains(fen)) { + output.println("TRANSREADRDFISSION("+dst+", "+dst+");"); + } else + output.println("TRANSREADRD("+dst+", "+dst+");"); + } + } + } else if (state.DSM) { + Integer status=locality.getNodePreTempInfo(currlb,fen).get(fen.getSrc()); + if (status==LocalityAnalysis.GLOBAL) { + String dst=generateTemp(fm, fen.getDst()); + if (elementtype.isPtr()) { + output.println(dst +"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc())+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex())+"];"); + output.println("TRANSREAD("+dst+", "+dst+");"); + } else { + output.println(dst +"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc())+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex())+"];"); + } + } else if (status==LocalityAnalysis.LOCAL) { + output.println(generateTemp(fm, fen.getDst())+"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc())+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex())+"];"); + } else if (status==LocalityAnalysis.EITHER) { + //Code is reading from a null pointer + output.println("if ("+generateTemp(fm, fen.getSrc())+") {"); + output.println("#ifndef RAW"); + output.println("printf(\"BIG ERROR\\n\");exit(-1);}"); + output.println("#endif"); + //This should throw a suitable null pointer error + output.println(generateTemp(fm, fen.getDst())+"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc())+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex())+"];"); + } else + throw new Error("Read from non-global/non-local in:"+currlb.getExplanation()); + } + } + + protected void generateFlatSetElementNode(FlatMethod fm, FlatSetElementNode fsen, PrintWriter output) { + //TODO: need dynamic check to make sure this assignment is actually legal + //Because Object[] could actually be something more specific...ie. Integer[] + + TypeDescriptor elementtype=fsen.getDst().getType().dereference(); + String type=""; + + if (state.MGC && elementtype.isClass() && elementtype.getClassDesc().isEnum()) { + type="int "; + } else if (elementtype.isArray()||elementtype.isClass() || (state.MGC && elementtype.isNull())) + type="void *"; + else + type=elementtype.getSafeSymbol()+" "; + + if (this.state.ARRAYBOUNDARYCHECK && fsen.needsBoundsCheck()) { + output.println("if (unlikely(((unsigned int)"+generateTemp(fm, fsen.getIndex())+") >= "+generateTemp(fm,fsen.getDst()) + "->___length___))"); + output.println("failedboundschk();"); + } + + if (state.SINGLETM && locality.getAtomic(currlb).get(fsen).intValue()>0) { + //Transaction set element case + if (wb.needBarrier(fsen)&& + locality.getNodePreTempInfo(currlb, fsen).get(fsen.getDst())!=LocalityAnalysis.SCRATCH) { + output.println("*((unsigned int *)&("+generateTemp(fm,fsen.getDst())+"->___objstatus___))|=DIRTY;"); + } + if (fsen.getSrc().getType().isPtr()&&!fsen.getSrc().getType().isNull()) { + output.println("{"); + String src=generateTemp(fm, fsen.getSrc()); + if ((dc==null)||dc.getNeedSrcTrans(currlb, fsen)&& + locality.getNodePreTempInfo(currlb, fsen).get(fsen.getSrc())!=LocalityAnalysis.SCRATCH) { + output.println("INTPTR srcoid=("+src+"!=NULL?((INTPTR)"+src+"->"+oidstr+"):0);"); + } else { + output.println("INTPTR srcoid=(INTPTR)"+src+";"); + } + if (state.STMARRAY&&locality.getNodePreTempInfo(currlb, fsen).get(fsen.getDst())!=LocalityAnalysis.SCRATCH&&wb.needBarrier(fsen)&&locality.getAtomic(currlb).get(fsen).intValue()>0) { + output.println("STMSETARRAY("+generateTemp(fm, fsen.getDst())+", "+generateTemp(fm, fsen.getIndex())+", srcoid, INTPTR);"); + } else { + output.println("((INTPTR*)(((char *) &("+ generateTemp(fm,fsen.getDst())+"->___length___))+sizeof(int)))["+generateTemp(fm, fsen.getIndex())+"]=srcoid;"); + } + output.println("}"); + } else { + if (state.STMARRAY&&locality.getNodePreTempInfo(currlb, fsen).get(fsen.getDst())!=LocalityAnalysis.SCRATCH&&wb.needBarrier(fsen)&&locality.getAtomic(currlb).get(fsen).intValue()>0) { + output.println("STMSETARRAY("+generateTemp(fm, fsen.getDst())+", "+generateTemp(fm, fsen.getIndex())+", "+ generateTemp(fm, fsen.getSrc()) +", "+type+");"); + } else { + output.println("(("+type +"*)(((char *) &("+ generateTemp(fm,fsen.getDst())+"->___length___))+sizeof(int)))["+generateTemp(fm, fsen.getIndex())+"]="+generateTemp(fm,fsen.getSrc())+";"); + } + } + } else if (state.DSM && locality.getAtomic(currlb).get(fsen).intValue()>0) { + Integer statussrc=locality.getNodePreTempInfo(currlb,fsen).get(fsen.getSrc()); + Integer statusdst=locality.getNodePreTempInfo(currlb,fsen).get(fsen.getDst()); + boolean srcglobal=statussrc==LocalityAnalysis.GLOBAL; + boolean dstglobal=statusdst==LocalityAnalysis.GLOBAL; + boolean dstlocal=(statusdst==LocalityAnalysis.LOCAL)||(statusdst==LocalityAnalysis.EITHER); + + if (dstglobal) { + if (wb.needBarrier(fsen)) + output.println("*((unsigned int *)&("+generateTemp(fm,fsen.getDst())+"->___localcopy___))|=DIRTY;"); + } else if (dstlocal) { + /** Check if we need to copy */ + String dst=generateTemp(fm, fsen.getDst()); + output.println("if(!"+dst+"->"+localcopystr+") {"); + /* Link object into list */ + String revertptr=generateTemp(fm, reverttable.get(currlb)); + output.println(revertptr+"=revertlist;"); + if ((GENERATEPRECISEGC) || this.state.MULTICOREGC) + output.println("COPY_OBJ((struct garbagelist *)"+localsprefixaddr+",(struct ___Object___ *)"+dst+");"); + else + output.println("COPY_OBJ("+dst+");"); + output.println(dst+"->"+nextobjstr+"="+revertptr+";"); + output.println("revertlist=(struct ___Object___ *)"+dst+";"); + output.println("}"); + } else { + System.out.println("Node: "+fsen); + System.out.println(currlb); + System.out.println("statusdst="+statusdst); + System.out.println(fm.printMethod()); + throw new Error("Unknown array type"); + } + if (srcglobal) { + output.println("{"); + String src=generateTemp(fm, fsen.getSrc()); + output.println("INTPTR srcoid=("+src+"!=NULL?((INTPTR)"+src+"->"+oidstr+"):0);"); + output.println("((INTPTR*)(((char *) &("+ generateTemp(fm,fsen.getDst())+"->___length___))+sizeof(int)))["+generateTemp(fm, fsen.getIndex())+"]=srcoid;"); + output.println("}"); + } else { + output.println("(("+type +"*)(((char *) &("+ generateTemp(fm,fsen.getDst())+"->___length___))+sizeof(int)))["+generateTemp(fm, fsen.getIndex())+"]="+generateTemp(fm,fsen.getSrc())+";"); + } + } else { + if (state.FASTCHECK) { + String dst=generateTemp(fm, fsen.getDst()); + output.println("if(!"+dst+"->"+localcopystr+") {"); + /* Link object into list */ + if (GENERATEPRECISEGC || this.state.MULTICOREGC) + output.println("COPY_OBJ((struct garbagelist *)"+localsprefixaddr+",(struct ___Object___ *)"+dst+");"); + else + output.println("COPY_OBJ("+dst+");"); + output.println(dst+"->"+nextobjstr+"="+fcrevert+";"); + output.println(fcrevert+"=(struct ___Object___ *)"+dst+";"); + output.println("}"); + } + output.println("(("+type +"*)(((char *) &("+ generateTemp(fm,fsen.getDst())+"->___length___))+sizeof(int)))["+generateTemp(fm, fsen.getIndex())+"]="+generateTemp(fm,fsen.getSrc())+";"); + } + } + + + protected void generateFlatNew(FlatMethod fm, FlatNew fn, PrintWriter output) { + if (state.DSM && locality.getAtomic(currlb).get(fn).intValue()>0&&!fn.isGlobal()) { + //Stash pointer in case of GC + String revertptr=generateTemp(fm, reverttable.get(currlb)); + output.println(revertptr+"=revertlist;"); + } + if (state.SINGLETM) { + if (fn.getType().isArray()) { + int arrayid=state.getArrayNumber(fn.getType())+state.numClasses(); + if (locality.getAtomic(currlb).get(fn).intValue()>0) { + //inside transaction + output.println(generateTemp(fm,fn.getDst())+"=allocate_newarraytrans("+localsprefixaddr+", "+arrayid+", "+generateTemp(fm, fn.getSize())+");"); + } else { + //outside transaction + output.println(generateTemp(fm,fn.getDst())+"=allocate_newarray("+localsprefixaddr+", "+arrayid+", "+generateTemp(fm, fn.getSize())+");"); + } + } else { + if (locality.getAtomic(currlb).get(fn).intValue()>0) { + //inside transaction + output.println(generateTemp(fm,fn.getDst())+"=allocate_newtrans("+localsprefixaddr+", "+fn.getType().getClassDesc().getId()+");"); + } else { + //outside transaction + output.println(generateTemp(fm,fn.getDst())+"=allocate_new("+localsprefixaddr+", "+fn.getType().getClassDesc().getId()+");"); + } + } + } else if (fn.getType().isArray()) { + int arrayid=state.getArrayNumber(fn.getType())+state.numClasses(); + if (fn.isGlobal()) { + output.println(generateTemp(fm,fn.getDst())+"=allocate_newarrayglobal("+arrayid+", "+generateTemp(fm, fn.getSize())+");"); + } else if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { + output.println(generateTemp(fm,fn.getDst())+"=allocate_newarray("+localsprefixaddr+", "+arrayid+", "+generateTemp(fm, fn.getSize())+");"); + } else { + output.println(generateTemp(fm,fn.getDst())+"=allocate_newarray("+arrayid+", "+generateTemp(fm, fn.getSize())+");"); + } + } else { + if (fn.isGlobal()) { + output.println(generateTemp(fm,fn.getDst())+"=allocate_newglobal("+fn.getType().getClassDesc().getId()+");"); + } else if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { + output.println(generateTemp(fm,fn.getDst())+"=allocate_new("+localsprefixaddr+", "+fn.getType().getClassDesc().getId()+");"); + } else { + output.println(generateTemp(fm,fn.getDst())+"=allocate_new("+fn.getType().getClassDesc().getId()+");"); + } + } + if (state.DSM && locality.getAtomic(currlb).get(fn).intValue()>0&&!fn.isGlobal()) { + String revertptr=generateTemp(fm, reverttable.get(currlb)); + String dst=generateTemp(fm,fn.getDst()); + output.println(dst+"->___localcopy___=(struct ___Object___*)1;"); + output.println(dst+"->"+nextobjstr+"="+revertptr+";"); + output.println("revertlist=(struct ___Object___ *)"+dst+";"); + } + if (state.FASTCHECK) { + String dst=generateTemp(fm,fn.getDst()); + output.println(dst+"->___localcopy___=(struct ___Object___*)1;"); + output.println(dst+"->"+nextobjstr+"="+fcrevert+";"); + output.println(fcrevert+"=(struct ___Object___ *)"+dst+";"); + } + } + + protected void generateFlatOpNode(FlatMethod fm, FlatOpNode fon, PrintWriter output) { + if (fon.getRight()!=null) { + if (fon.getOp().getOp()==Operation.URIGHTSHIFT) { + if (fon.getLeft().getType().isLong()) + output.println(generateTemp(fm, fon.getDest())+" = ((unsigned long long)"+generateTemp(fm, fon.getLeft())+")>>"+generateTemp(fm,fon.getRight())+";"); + else + output.println(generateTemp(fm, fon.getDest())+" = ((unsigned int)"+generateTemp(fm, fon.getLeft())+")>>"+generateTemp(fm,fon.getRight())+";"); + + } else if (dc!=null) { + output.print(generateTemp(fm, fon.getDest())+" = ("); + if (fon.getLeft().getType().isPtr()&&(fon.getOp().getOp()==Operation.EQUAL||fon.getOp().getOp()==Operation.NOTEQUAL)) + output.print("(void *)"); + if (dc.getNeedLeftSrcTrans(currlb, fon)) + output.print("("+generateTemp(fm, fon.getLeft())+"!=NULL?"+generateTemp(fm, fon.getLeft())+"->"+oidstr+":NULL)"); + else + output.print(generateTemp(fm, fon.getLeft())); + output.print(")"+fon.getOp().toString()+"("); + if (fon.getRight().getType().isPtr()&&(fon.getOp().getOp()==Operation.EQUAL||fon.getOp().getOp()==Operation.NOTEQUAL)) + output.print("(void *)"); + if (dc.getNeedRightSrcTrans(currlb, fon)) + output.println("("+generateTemp(fm, fon.getRight())+"!=NULL?"+generateTemp(fm, fon.getRight())+"->"+oidstr+":NULL));"); + else + output.println(generateTemp(fm,fon.getRight())+");"); + } else + output.println(generateTemp(fm, fon.getDest())+" = "+generateTemp(fm, fon.getLeft())+fon.getOp().toString()+generateTemp(fm,fon.getRight())+";"); + } else if (fon.getOp().getOp()==Operation.ASSIGN) + output.println(generateTemp(fm, fon.getDest())+" = "+generateTemp(fm, fon.getLeft())+";"); + else if (fon.getOp().getOp()==Operation.UNARYPLUS) + output.println(generateTemp(fm, fon.getDest())+" = "+generateTemp(fm, fon.getLeft())+";"); + else if (fon.getOp().getOp()==Operation.UNARYMINUS) + output.println(generateTemp(fm, fon.getDest())+" = -"+generateTemp(fm, fon.getLeft())+";"); + else if (fon.getOp().getOp()==Operation.LOGIC_NOT) + output.println(generateTemp(fm, fon.getDest())+" = !"+generateTemp(fm, fon.getLeft())+";"); + else if (fon.getOp().getOp()==Operation.COMP) + output.println(generateTemp(fm, fon.getDest())+" = ~"+generateTemp(fm, fon.getLeft())+";"); + else if (fon.getOp().getOp()==Operation.ISAVAILABLE) { + output.println(generateTemp(fm, fon.getDest())+" = "+generateTemp(fm, fon.getLeft())+"->fses==NULL;"); + } else + output.println(generateTemp(fm, fon.getDest())+fon.getOp().toString()+generateTemp(fm, fon.getLeft())+";"); + } + + protected void generateFlatLiteralNode(FlatMethod fm, FlatLiteralNode fln, PrintWriter output) { + if (fln.getValue()==null) + output.println(generateTemp(fm, fln.getDst())+"=0;"); + else if (fln.getType().getSymbol().equals(TypeUtil.StringClass)) { + if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { + if (state.DSM && locality.getAtomic(currlb).get(fln).intValue()>0) { + //Stash pointer in case of GC + String revertptr=generateTemp(fm, reverttable.get(currlb)); + output.println(revertptr+"=revertlist;"); + } + output.println(generateTemp(fm, fln.getDst())+"=NewString("+localsprefixaddr+", \""+FlatLiteralNode.escapeString((String)fln.getValue())+"\","+((String)fln.getValue()).length()+");"); + if (state.DSM && locality.getAtomic(currlb).get(fln).intValue()>0) { + //Stash pointer in case of GC + String revertptr=generateTemp(fm, reverttable.get(currlb)); + output.println("revertlist="+revertptr+";"); + } + } else { + output.println(generateTemp(fm, fln.getDst())+"=NewString(\""+FlatLiteralNode.escapeString((String)fln.getValue())+"\","+((String)fln.getValue()).length()+");"); + } + } else if (fln.getType().isBoolean()) { + if (((Boolean)fln.getValue()).booleanValue()) + output.println(generateTemp(fm, fln.getDst())+"=1;"); + else + output.println(generateTemp(fm, fln.getDst())+"=0;"); + } else if (fln.getType().isChar()) { + String st=FlatLiteralNode.escapeString(fln.getValue().toString()); + output.println(generateTemp(fm, fln.getDst())+"='"+st+"';"); + } else if (fln.getType().isLong()) { + output.println(generateTemp(fm, fln.getDst())+"="+fln.getValue()+"LL;"); + } else + output.println(generateTemp(fm, fln.getDst())+"="+fln.getValue()+";"); + } + + protected void generateStoreFlatCondBranch(FlatMethod fm, LocalityBinding lb, FlatCondBranch fcb, String label, PrintWriter output) { + int left=-1; + int right=-1; + //only record if this group has more than one exit + if (branchanalysis.numJumps(fcb)>1) { + left=branchanalysis.jumpValue(fcb, 0); + right=branchanalysis.jumpValue(fcb, 1); + } + output.println("if (!"+generateTemp(fm, fcb.getTest())+") {"); + if (right!=-1) + output.println("STOREBRANCH("+right+");"); + output.println("goto "+label+";"); + output.println("}"); + if (left!=-1) + output.println("STOREBRANCH("+left+");"); + } + + /** This method generates header information for the method or + * task referenced by the Descriptor des. */ + protected void generateHeader(FlatMethod fm, LocalityBinding lb, Descriptor des, PrintWriter output) { + /* Print header */ + ParamsObject objectparams=(ParamsObject)paramstable.get(lb!=null ? lb : des); + MethodDescriptor md=null; + TaskDescriptor task=null; + if (des instanceof MethodDescriptor) + md=(MethodDescriptor) des; + else + task=(TaskDescriptor) des; + + ClassDescriptor cn=md!=null ? md.getClassDesc() : null; + + if (md!=null&&md.getReturnType()!=null) { + if (state.MGC && md.getReturnType().isClass() && md.getReturnType().getClassDesc().isEnum()) { + output.print("int "); + } else if (md.getReturnType().isClass()||md.getReturnType().isArray()) + output.print("struct " + md.getReturnType().getSafeSymbol()+" * "); + else + output.print(md.getReturnType().getSafeSymbol()+" "); + } else + //catch the constructor case + output.print("void "); + if (md!=null) { + output.print(cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"("); + } else + output.print(task.getSafeSymbol()+"("); + + boolean printcomma=false; + if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { + if (md!=null) { + output.print("struct "+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params * "+paramsprefix); + } else + output.print("struct "+task.getSafeSymbol()+"_params * "+paramsprefix); + printcomma=true; + } + + if (md!=null) { + /* Method */ + for(int i=0; imaxtaskparams) + maxtaskparams=objectparams.numPrimitives()+fm.numTags(); + } else output.println(") {"); + } +} + + + + + + diff --git a/Robust/src/IR/Flat/BuildOoOJavaCode.java b/Robust/src/IR/Flat/BuildOoOJavaCode.java index b0d045bc..4377493a 100644 --- a/Robust/src/IR/Flat/BuildOoOJavaCode.java +++ b/Robust/src/IR/Flat/BuildOoOJavaCode.java @@ -7,11 +7,9 @@ import java.io.*; import Util.*; import Analysis.TaskStateAnalysis.*; -import Analysis.Locality.*; import Analysis.CallGraph.*; import Analysis.Disjoint.*; import Analysis.OoOJava.*; -import Analysis.Prefetch.*; import Analysis.Loops.*; import Analysis.Locality.*; @@ -34,11 +32,10 @@ public class BuildOoOJavaCode extends BuildCode { Hashtable temptovar, TypeUtil typeutil, SafetyAnalysis sa, - PrefetchAnalysis pa, OoOJavaAnalysis oooa ) { - super( st, temptovar, typeutil, sa, pa ); + super( st, temptovar, typeutil, sa); this.oooa = oooa; } @@ -175,7 +172,7 @@ public class BuildOoOJavaCode extends BuildCode { while( seseit.hasNext() ) { FlatSESEEnterNode fsen = seseit.next(); - generateMethodSESE( fsen, null, outstructs, outmethodheader, outmethod ); + generateMethodSESE( fsen, outstructs, outmethodheader, outmethod ); } // then write the invokeSESE switch to decouple scheduler @@ -306,11 +303,9 @@ public class BuildOoOJavaCode extends BuildCode { protected void generateMethodSESE(FlatSESEEnterNode fsen, - LocalityBinding lb, PrintWriter outputStructs, PrintWriter outputMethHead, - PrintWriter outputMethods - ) { + PrintWriter outputMethods) { ParamsObject objectparams = (ParamsObject) paramstable.get( fsen.getmdBogus() ); TempObject objecttemps = (TempObject) tempstable .get( fsen.getmdBogus() ); @@ -626,7 +621,7 @@ public class BuildOoOJavaCode extends BuildCode { TempDescriptor temp = tempItr.next(); VariableSourceToken vst = fsen.getStaticInVarSrc( temp ); SESEandAgePair srcPair = new SESEandAgePair( vst.getSESE(), vst.getAge() ); - output.println(" "+generateTemp( fsen.getfmBogus(), temp, null )+ + output.println(" "+generateTemp( fsen.getfmBogus(), temp)+ " = "+paramsprefix+"->"+srcPair+"->"+vst.getAddrVar()+";"); } @@ -661,7 +656,7 @@ public class BuildOoOJavaCode extends BuildCode { typeStr = type.getSafeSymbol(); } - output.println(" "+generateTemp( fsen.getfmBogus(), temp, null )+ + output.println(" "+generateTemp( fsen.getfmBogus(), temp)+ " = *(("+typeStr+"*) ((void*)"+ paramsprefix+"->"+temp+"_srcSESE + "+ paramsprefix+"->"+temp+"_srcOffset));"); @@ -673,7 +668,7 @@ public class BuildOoOJavaCode extends BuildCode { // or if the source was our parent, its already in our record to grab output.println(" } else {"); - output.println(" "+generateTemp( fsen.getfmBogus(), temp, null )+ + output.println(" "+generateTemp( fsen.getfmBogus(), temp)+ " = "+paramsprefix+"->"+temp+";"); output.println(" }"); } @@ -700,7 +695,7 @@ public class BuildOoOJavaCode extends BuildCode { HashSet exitset=new HashSet(); exitset.add(seseExit); - generateCode(fsen.getNext(0), fm, null, exitset, output, true); + generateCode(fsen.getNext(0), fm, exitset, output); output.println("}\n\n"); } @@ -808,7 +803,7 @@ public class BuildOoOJavaCode extends BuildCode { output.println(" if(!atomic_sub_and_test(localCount, &(stallrecord->common.unresolvedDependencies))) {"); //have to do fine-grained work also output.println(" stallrecord->___obj___=(struct ___Object___ *)" - + generateTemp(fm, stalltd, null) + ";"); + + generateTemp(fm, stalltd) + ";"); output.println(" stallrecord->common.classID=-" + rcr.getTraverserID(stalltd, fn) + ";"); @@ -845,7 +840,6 @@ public class BuildOoOJavaCode extends BuildCode { protected void additionalCodePreNode( FlatMethod fm, - LocalityBinding lb, FlatNode fn, PrintWriter output ) { // insert pre-node actions from the code plan @@ -910,7 +904,7 @@ public class BuildOoOJavaCode extends BuildCode { Iterator tdItr = cp.getCopySet( vst ).iterator(); while( tdItr.hasNext() ) { TempDescriptor td = tdItr.next(); - output.println(" "+generateTemp( fmContext, td, null )+ + output.println(" "+generateTemp( fmContext, td)+ " = child->"+vst.getAddrVar().getSafeSymbol()+";"); } @@ -961,7 +955,7 @@ public class BuildOoOJavaCode extends BuildCode { typeStr = type.getSafeSymbol(); } - output.println(" "+generateTemp( fmContext, dynVar, null )+ + output.println(" "+generateTemp( fmContext, dynVar )+ " = *(("+typeStr+"*) ((void*)"+ dynVar+"_srcSESE + "+dynVar+"_srcOffset));"); @@ -1073,7 +1067,7 @@ public class BuildOoOJavaCode extends BuildCode { output.println(" rentry=mlpCreateFineREntry(runningSESE->memoryQueueArray[" + waitingElement.getQueueID() + "]," + waitingElement.getStatus() + ", runningSESE, (void*)&" - + generateTemp(fm, waitingElement.getTempDesc(), lb) + ");"); + + generateTemp(fm, waitingElement.getTempDesc()) + ");"); } output.println(" rentry->parentStallSem=&runningSESEstallSem;"); output.println(" psem_reset( &runningSESEstallSem);"); @@ -1110,7 +1104,6 @@ public class BuildOoOJavaCode extends BuildCode { protected void additionalCodePostNode( FlatMethod fm, - LocalityBinding lb, FlatNode fn, PrintWriter output ) { @@ -1119,7 +1112,6 @@ public class BuildOoOJavaCode extends BuildCode { public void generateFlatSESEEnterNode( FlatMethod fm, - LocalityBinding lb, FlatSESEEnterNode fsen, PrintWriter output ) { @@ -1251,10 +1243,10 @@ public class BuildOoOJavaCode extends BuildCode { FlatSESEEnterNode parent = fsen.getLocalParent(); if( parent != null && !parent.getIsCallerProxySESE() ) { output.println(" seseToIssue->"+temp+" = "+ - generateTemp( parent.getfmBogus(), temp, null )+";"); + generateTemp( parent.getfmBogus(), temp )+";"); } else { output.println(" seseToIssue->"+temp+" = "+ - generateTemp( fsen.getfmEnclosing(), temp, null )+";"); + generateTemp( fsen.getfmEnclosing(), temp )+";"); } } @@ -1327,10 +1319,10 @@ public class BuildOoOJavaCode extends BuildCode { FlatSESEEnterNode parent = fsen.getLocalParent(); if( parent != null && !parent.getIsCallerProxySESE() ) { output.println(" seseToIssue->"+dynInVar+" = "+ - generateTemp( parent.getfmBogus(), dynInVar, null )+";"); + generateTemp( parent.getfmBogus(), dynInVar )+";"); } else { output.println(" seseToIssue->"+dynInVar+" = "+ - generateTemp( fsen.getfmEnclosing(), dynInVar, null )+";"); + generateTemp( fsen.getfmEnclosing(), dynInVar )+";"); } output.println(" }"); @@ -1397,7 +1389,7 @@ public class BuildOoOJavaCode extends BuildCode { } if(state.RCR) { - dispatchMEMRC(fm, lb, fsen, output); + dispatchMEMRC(fm, fsen, output); } else { // there may be several task types that can get to this @@ -1554,7 +1546,6 @@ public class BuildOoOJavaCode extends BuildCode { void dispatchMEMRC( FlatMethod fm, - LocalityBinding lb, FlatSESEEnterNode fsen, PrintWriter output ) { // NEED TO FIX IT, TODO @@ -1669,7 +1660,6 @@ public class BuildOoOJavaCode extends BuildCode { public void generateFlatSESEExitNode( FlatMethod fm, - LocalityBinding lb, FlatSESEExitNode fsexn, PrintWriter output ) { @@ -1735,9 +1725,9 @@ public class BuildOoOJavaCode extends BuildCode { assert !fsen.getIsCallerProxySESE(); FlatSESEEnterNode parent = fsen.getLocalParent(); if( parent != null && !parent.getIsCallerProxySESE() ) { - from = generateTemp( parent.getfmBogus(), temp, null ); + from = generateTemp( parent.getfmBogus(), temp ); } else { - from = generateTemp( fsen.getfmEnclosing(), temp, null ); + from = generateTemp( fsen.getfmEnclosing(), temp ); } output.println(" "+paramsprefix+ @@ -1902,7 +1892,6 @@ public class BuildOoOJavaCode extends BuildCode { public void generateFlatWriteDynamicVarNode( FlatMethod fm, - LocalityBinding lb, FlatWriteDynamicVarNode fwdvn, PrintWriter output ) { @@ -1952,7 +1941,6 @@ public class BuildOoOJavaCode extends BuildCode { protected void generateFlatNew( FlatMethod fm, - LocalityBinding lb, FlatNew fn, PrintWriter output ) { @@ -1960,24 +1948,24 @@ public class BuildOoOJavaCode extends BuildCode { int arrayid = state.getArrayNumber( fn.getType() )+state.numClasses(); if( GENERATEPRECISEGC ) { - output.println(generateTemp( fm, fn.getDst(), lb )+ + output.println(generateTemp( fm, fn.getDst())+ "=allocate_newarray_mlp("+localsprefixaddr+ - ", "+arrayid+", "+generateTemp( fm, fn.getSize(), lb )+ + ", "+arrayid+", "+generateTemp( fm, fn.getSize())+ ", oid, "+ oooa.getDisjointAnalysis().getAllocationSiteFromFlatNew( fn ).getUniqueAllocSiteID()+ ");"); output.println(" oid += oidIncrement;"); } else { - output.println(generateTemp( fm, fn.getDst(), lb )+ + output.println(generateTemp( fm, fn.getDst())+ "=allocate_newarray("+arrayid+ - ", "+generateTemp( fm, fn.getSize(), lb )+ + ", "+generateTemp( fm, fn.getSize())+ ");"); } } else { // not an array if( GENERATEPRECISEGC ) { - output.println( generateTemp( fm, fn.getDst(), lb )+ + output.println( generateTemp( fm, fn.getDst())+ "=allocate_new_mlp("+localsprefixaddr+ ", "+fn.getType().getClassDesc().getId()+ ", oid, "+ @@ -1985,7 +1973,7 @@ public class BuildOoOJavaCode extends BuildCode { ");"); output.println(" oid += oidIncrement;"); } else { - output.println( generateTemp( fm, fn.getDst(), lb )+ + output.println( generateTemp( fm, fn.getDst())+ "=allocate_new("+fn.getType().getClassDesc().getId()+ ");"); } diff --git a/Robust/src/Main/Main.java b/Robust/src/Main/Main.java index f291d23d..e329aa8b 100644 --- a/Robust/src/Main/Main.java +++ b/Robust/src/Main/Main.java @@ -18,6 +18,7 @@ import IR.Flat.BuildCodeMultiCore; import IR.Flat.BuildCodeMGC; import IR.Flat.BuildFlat; import IR.Flat.BuildCode; +import IR.Flat.BuildCodeTran; import IR.Flat.BuildOoOJavaCode; import IR.Flat.Inliner; import IR.ClassDescriptor; @@ -593,8 +594,7 @@ public class Main { sa, scheduling, mcImplSynthesis.getCoreNum(), - state.CORENUM4GC, - pa); + state.CORENUM4GC); bcm.setOwnershipAnalysis(oa); bcm.buildCode(); } @@ -613,8 +613,7 @@ public class Main { sa, state.CORENUM, state.CORENUM, - state.CORENUM4GC, - pa); + state.CORENUM4GC); bcmgc.buildCode(); } } @@ -631,12 +630,12 @@ public class Main { } LocalityAnalysis la=new LocalityAnalysis(state, callgraph, tu); GenerateConversions gc=new GenerateConversions(la, state); - bc=new BuildCode(state, bf.getMap(), tu, la, pa); + bc=new BuildCodeTran(state, bf.getMap(), tu, la, pa); } else { if( state.OOOJAVA ) { - bc=new BuildOoOJavaCode(state, bf.getMap(), tu, sa, pa, oooa); + bc=new BuildOoOJavaCode(state, bf.getMap(), tu, sa, oooa); } else { - bc=new BuildCode(state, bf.getMap(), tu, sa, pa); + bc=new BuildCode(state, bf.getMap(), tu, sa); } }