import IR.*;
import java.util.*;
import java.io.*;
+
import Util.Relation;
import Analysis.TaskStateAnalysis.FlagState;
import Analysis.TaskStateAnalysis.FlagComparator;
public static boolean GENERATEPRECISEGC=false;
public static String PREFIX="";
public static String arraytype="ArrayObject";
- public static int count = 0;
public static int flagcount = 0;
Virtual virtualcalls;
TypeUtil typeutil;
- private int maxtaskparams=0;
+ protected int maxtaskparams=0;
private int maxcount=0;
ClassDescriptor[] cdarray;
TypeDescriptor[] arraytable;
Hashtable<TempDescriptor, TempDescriptor> backuptable;
Hashtable<LocalityBinding, TempDescriptor> reverttable;
SafetyAnalysis sa;
+ PrefetchAnalysis pa;
- public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, SafetyAnalysis sa) {
- this(st, temptovar, typeutil, null, sa);
+ 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, LocalityAnalysis locality) {
- this(st, temptovar, typeutil, locality, 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) {
+ public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality, SafetyAnalysis sa, PrefetchAnalysis pa) {
this.sa=sa;
+ this.pa=pa;
state=st;
this.temptovar=temptovar;
paramstable=new Hashtable();
private void outputMainMethod(PrintWriter outmethod) {
outmethod.println("int main(int argc, const char *argv[]) {");
outmethod.println(" int i;");
+ outmethod.println("#ifdef TRANSSTATS \n");
+ outmethod.println("handle();\n");
+ outmethod.println("#endif\n");
if (state.THREAD||state.DSM) {
outmethod.println("initializethreads();");
}
outmethod.println("pthread_exit(NULL);");
}
-
+ outmethod.println("#ifdef TRANSSTATS \n");
+ outmethod.println("printf(\"****** Transaction Stats ******\\n\");");
+ outmethod.println("printf(\"numTransAbort= %d\\n\", numTransAbort);");
+ outmethod.println("printf(\"numTransCommit= %d\\n\", numTransCommit);");
+ outmethod.println("#endif\n");
outmethod.println("}");
+
}
/* This method outputs code for each task. */
* objets and array that stores supertype and then the code for
* the Java methods.. */
- private void outputMethods(PrintWriter outmethod) {
+ protected void outputMethods(PrintWriter outmethod) {
outmethod.println("#include \"methodheaders.h\"");
outmethod.println("#include \"virtualtable.h\"");
- outmethod.println("#include <runtime.h>");
+ outmethod.println("#include \"runtime.h\"");
if (state.DSM) {
+ outmethod.println("#include \"addPrefetchEnhance.h\"");
outmethod.println("#include \"localobjects.h\"");
}
+ if(state.MULTICORE) {
+ outmethod.println("#include \"task.h\"");
+ }
if (state.THREAD||state.DSM)
outmethod.println("#include <thread.h>");
if (state.main!=null) {
}
}
- private void outputStructs(PrintWriter outstructs) {
+ protected void outputStructs(PrintWriter outstructs) {
outstructs.println("#ifndef STRUCTDEFS_H");
outstructs.println("#define STRUCTDEFS_H");
outstructs.println("#include \"classdefs.h\"");
}
}
- private void outputClassDeclarations(PrintWriter outclassdefs) {
+ protected void outputClassDeclarations(PrintWriter outclassdefs) {
if (state.THREAD||state.DSM)
outclassdefs.println("#include <pthread.h>");
if(state.OPTIONAL)
}
if (state.TASK) {
outclassdefs.println(" int flag;");
- outclassdefs.println(" void * flagptr;");
+ if(!state.MULTICORE) {
+ outclassdefs.println(" void * flagptr;");
+ } else {
+ outclassdefs.println(" int isolate;"); // indicate if this object is shared or not
+ outclassdefs.println(" int version;");
+ outclassdefs.println(" struct ___Object___ * original;");
+ }
if(state.OPTIONAL){
outclassdefs.println(" int numfses;");
outclassdefs.println(" int * fses;");
outtask.println("struct taskdescriptor {");
outtask.println("void * taskptr;");
outtask.println("int numParameters;");
- outtask.println("int numTotal;");
+ outtask.println(" int numTotal;");
outtask.println("struct parameterdescriptor **descriptorarray;");
outtask.println("char * name;");
outtask.println("};");
outrepairstructs.println(" int __type__;");
if (state.TASK) {
outrepairstructs.println(" int __flag__;");
- outrepairstructs.println(" int __flagptr__;");
+ if(!state.MULTICORE) {
+ outrepairstructs.println(" int __flagptr__;");
+ }
}
printRepairStruct(cn, outrepairstructs);
outrepairstructs.println("}\n");
}
/** This method outputs TaskDescriptor information */
- void generateTaskDescriptor(PrintWriter output, FlatMethod fm, TaskDescriptor task) {
+ private void generateTaskDescriptor(PrintWriter output, FlatMethod fm, TaskDescriptor task) {
for (int i=0;i<task.numParameters();i++) {
VarDescriptor param_var=task.getParameter(i);
TypeDescriptor param_type=task.getParamType(i);
/** The buildVirtualTables method outputs the virtual dispatch
* tables for methods. */
-
- private void buildVirtualTables(PrintWriter outvirtual) {
+
+ protected void buildVirtualTables(PrintWriter outvirtual) {
Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
while(classit.hasNext()) {
ClassDescriptor cd=(ClassDescriptor)classit.next();
* information. */
private void generateSizeArray(PrintWriter outclassdefs) {
- outclassdefs.print("int classsize[]={");
+ 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 void handle();\n");
+ outclassdefs.print("#endif\n");
+ outclassdefs.print("int numprefetchsites = " + pa.prefetchsiteid + ";\n");
+
+ outclassdefs.print("int classsize[]={");
Iterator it=state.getClassSymbolTable().getDescriptorsIterator();
cdarray=new ClassDescriptor[state.numClasses()];
while(it.hasNext()) {
* These objects tell the compiler which temps need to be
* allocated. */
- private void generateTempStructs(FlatMethod fm, LocalityBinding lb) {
+ protected void generateTempStructs(FlatMethod fm, LocalityBinding lb) {
MethodDescriptor md=fm.getMethod();
TaskDescriptor task=fm.getTask();
Set<TempDescriptor> saveset=lb!=null?locality.getTempSet(lb):null;
if (!fieldorder.containsKey(cn)) {
Vector fields=new Vector();
fieldorder.put(cn,fields);
- if (sp==null) {
+ if (sp==null&&!state.TASK) {
fields.add(cn.getFieldTable().get("cachedCode"));
}
Iterator fieldit=cn.getFields();
while(fieldit.hasNext()) {
FieldDescriptor fd=(FieldDescriptor)fieldit.next();
if ((sp==null||!sp.getFieldTable().contains(fd.getSymbol()))&&
- (!fd.getSymbol().equals("cachedCode")))
+ (!fd.getSymbol().equals("cachedCode")||state.TASK))
fields.add(fd);
}
}
/* Map flags to integers consistently between inherited
* classes. */
- private void mapFlags(ClassDescriptor cn) {
+ protected void mapFlags(ClassDescriptor cn) {
ClassDescriptor sp=cn.getSuperDesc();
if (sp!=null)
mapFlags(sp);
* passed in (when PRECISE GC is enabled) and (2) function
* prototypes for the methods */
- private void generateCallStructs(ClassDescriptor cn, PrintWriter classdefout, PrintWriter output, PrintWriter headersout) {
+ protected void generateCallStructs(ClassDescriptor cn, PrintWriter classdefout, PrintWriter output, PrintWriter headersout) {
/* Output class structure */
classdefout.println("struct "+cn.getSafeSymbol()+" {");
classdefout.println(" int type;");
if (state.TASK) {
classdefout.println(" int flag;");
- classdefout.println(" void * flagptr;");
+ if((!state.MULTICORE) || (cn.getSymbol().equals("TagDescriptor"))) {
+ classdefout.println(" void * flagptr;");
+ } else if (state.MULTICORE){
+ classdefout.println(" int isolate;"); // indicate if this object is shared or not
+ classdefout.println(" int version;");
+ classdefout.println(" struct ___Object___ * original;");
+ }
if (state.OPTIONAL){
classdefout.println(" int numfses;");
classdefout.println(" int * fses;");
printcomma=true;
}
- if (state.DSM&&lb.isAtomic()) {
+ if (state.DSM&&lb.isAtomic()&&!md.getModifiers().isNative()) {
if (printcomma)
headersout.print(", ");
headersout.print("transrecord_t * trans");
/** This method assigns labels to FlatNodes */
- private Hashtable<FlatNode, Integer> assignLabels(FlatMethod fm) {
+ protected Hashtable<FlatNode, Integer> assignLabels(FlatMethod fm) {
HashSet tovisit=new HashSet();
HashSet visited=new HashSet();
int labelindex=0;
/** Generate text string that corresponds to the TempDescriptor td. */
- private String generateTemp(FlatMethod fm, TempDescriptor td, LocalityBinding lb) {
+ protected String generateTemp(FlatMethod fm, TempDescriptor td, LocalityBinding lb) {
MethodDescriptor md=fm.getMethod();
TaskDescriptor task=fm.getTask();
TempObject objecttemps=(TempObject) tempstable.get(lb!=null?lb:md!=null?md:task);
throw new Error();
}
- private void generateFlatNode(FlatMethod fm, LocalityBinding lb, FlatNode fn, PrintWriter output) {
+ protected void generateFlatNode(FlatMethod fm, LocalityBinding lb, FlatNode fn, PrintWriter output) {
switch(fn.kind()) {
case FKind.FlatAtomicEnterNode:
generateFlatAtomicEnterNode(fm, lb, (FlatAtomicEnterNode) fn, output);
generateFlatFlagActionNode(fm, lb, (FlatFlagActionNode) fn, output);
return;
case FKind.FlatPrefetchNode:
- if (!state.excprefetch.contains(fm.getMethod().getClassMethodName()))
- generateFlatPrefetchNode(fm,lb, (FlatPrefetchNode) fn, output);
+ generateFlatPrefetchNode(fm,lb, (FlatPrefetchNode) fn, output);
return;
}
throw new Error();
}
public void generateFlatPrefetchNode(FlatMethod fm, LocalityBinding lb, FlatPrefetchNode fpn, PrintWriter output) {
- short[] arrayfields = null;
- Vector fieldoffset = new Vector();
+ if (state.PREFETCH) {
+ Vector oids = new Vector();
+ Vector fieldoffset = new Vector();
Vector endoffset = new Vector();
- Vector oids = new Vector();
- short offsetcount = 0;
- int tuplecount = 0; //Keeps track of number of prefetch tuples that need to be generated
- int i,j;
-
- if (state.PREFETCH) {
- output.println("/* prefetch */");
- output.println("; /* empty statement to avoid compiler error */");
- Iterator it = fpn.hspp.iterator();
- String oidlist = new String();
- while(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) {
- if(locality.getAtomic(lb).get(fpn).intValue()>0) { /* Inside transaction */
- generateInsideTransCode(fm,lb,output, pp,oids,fieldoffset,endoffset,tuplecount);
- } else {/* Outside Transaction */
- generateOutsideTransCode(fm,lb,pp,oids,fieldoffset,endoffset,tuplecount);
- }
- tuplecount++;
- } else if(statusbase == LocalityAnalysis.LOCAL) {
- generateLocalTransCode(fm,lb,pp,oids,fieldoffset,endoffset,tuplecount);
- } else {
- continue;
- }
- }
-
- /*Create C code for numtuples */
- output.println(" int numtuples_" + count + " = " + tuplecount + ";");
-
- /*Create C code for oid array */
- output.print(" unsigned int oidarray_" + count + "[] = {");
- boolean needcomma=false;
- it = oids.iterator();
- while(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_" + count +"[] = {");
- needcomma=false;
- it = endoffset.iterator();
- while(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_" + count +"[] = {");
- needcomma=false;
- it = fieldoffset.iterator();
- while(it.hasNext()) {
- if (needcomma)
- output.print(", ");
- output.print(it.next());
- needcomma=true;
- }
- output.println("};");
- /* make the prefetch call to Runtime */
- if(tuplecount > 0) {
- output.println(" prefetch((int) numtuples_"+count+ ", oidarray_"+count+ ", endoffsetarry_"+
- count+", fieldarry_"+count+");");
+ 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;
+ 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(;breakindex<pp.desc.size();breakindex++) {
+ Descriptor desc=pp.getDescAt(breakindex);
+ if (desc instanceof FieldDescriptor) {
+ FieldDescriptor fd=(FieldDescriptor)desc;
+ if (fd.isGlobal()) {
+ break;
}
- count++;
- }
+ }
+ }
+ breakindex++;
+ }
- /* Free heap memory */
- fieldoffset = null;
- endoffset = null;
- oids = null;
- }
+ if (breakindex>pp.desc.size()) //all local
+ return;
- public void generateInsideTransCode(FlatMethod fm, LocalityBinding lb,PrintWriter output,PrefetchPair pp,Vector oids, Vector fieldoffset,Vector endoffset, int tuplecount){
- int i,j;
- short offsetcount = 0;
- String test = new String();
-
- Object newdesc = pp.desc.get(0);
- if(newdesc instanceof FieldDescriptor) {
- FieldDescriptor fd = (FieldDescriptor)newdesc;
- String oid = new String("(unsigned int) (" +
- generateTemp(fm, pp.base, lb) + " != NULL ? " +
- generateTemp(fm, pp.base, lb) + "->" + ((FieldDescriptor)fd).getSafeSymbol() +
- " : NULL)");
- oids.add(oid);
+ 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<breakindex;i++) {
+ String indexcheck="";
+
+ Descriptor desc=pp.getDescAt(i);
+ if (desc instanceof FieldDescriptor) {
+ FieldDescriptor fd=(FieldDescriptor)desc;
+ if (maybenull) {
+ if (!teststr.equals(""))
+ teststr+="&&";
+ teststr+="((prefptr="+basestr+")!=NULL)";
+ basestr="((struct "+lasttype.getSafeSymbol()+" *)prefptr)->"+fd.getSafeSymbol();
+ } else {
+ basestr=basestr+"->"+fd.getSafeSymbol();
+ maybenull=true;
+ }
+ lasttype=fd.getType();
} else {
- IndexDescriptor id = (IndexDescriptor)newdesc;
- String tstlbl = new String();
- for(i=0; i<id.tddesc.size(); i++) {
- tstlbl += generateTemp(fm, id.getTempDescAt(i), lb) + "+";
- }
- tstlbl += id.offset.toString();
-
- TypeDescriptor elementtype = pp.base.getType().dereference();
- String type="";
- if (elementtype.isArray()||elementtype.isClass())
- type="void *";
- else
- type=elementtype.getSafeSymbol()+" ";
-
- String oid = new String("(unsigned int) (" + generateTemp(fm, pp.base, lb) + " != NULL ? " +
- "((" + tstlbl+"< 0 || "+tstlbl+" >= "+ generateTemp(fm, pp.base, lb) + "->___length___) ? 0 :"+
- "((" + type + "*)(((char *) &("+ generateTemp(fm, pp.base, lb)+ "->___length___))+sizeof(int)))["+tstlbl+"]) : 0)");
- oids.add(oid);
- }
-
- for(i = 1; i < pp.desc.size(); i++) {
- TypeDescriptor newtd;
- ClassDescriptor cd;
- String newfieldoffset;
- Object desc = pp.getDescAt(i);
- offsetcount++;
- if(desc instanceof FieldDescriptor) {
- Object prevdesc = pp.getDescAt(i-1);
- if(prevdesc instanceof IndexDescriptor){
- if((i-1) == 0) {
- newtd = pp.base.getType();
- cd = newtd.getClassDesc();
- } else {
- //FIXME currently handles one dimensional arrays
- newtd = ((FieldDescriptor)pp.getDescAt(i-2)).getType();
- cd = newtd.getClassDesc();
- }
- newfieldoffset = new String("(unsigned int)(&(((struct "+ cd.getSafeSymbol() +" *)0)->"+
- ((FieldDescriptor)desc).getSafeSymbol()+ "))");
- } else {
- newtd = ((FieldDescriptor)pp.getDescAt(i-1)).getType();
- newfieldoffset = new String("(unsigned int)(&(((struct "+ newtd.getSafeSymbol()+" *)0)->"+
- ((FieldDescriptor)desc).getSafeSymbol()+ "))");
- }
- fieldoffset.add(newfieldoffset);
- } else {
- String tstlbl = new String();
- for(j = 0; j < ((IndexDescriptor)desc).tddesc.size(); j++) {
- tstlbl += generateTemp(fm, ((IndexDescriptor)desc).getTempDescAt(j), lb) + "+";
- }
- tstlbl += ((IndexDescriptor)desc).offset.toString();
- newfieldoffset = new String(tstlbl);
- fieldoffset.add(newfieldoffset);
- }
- }
- if(tuplecount > 0) {
- int tmp = (int) ((Short)(endoffset.get(tuplecount-1))).shortValue() + (int) offsetcount;
- short endoffsetval = (short) tmp;
- endoffset.add(endoffsetval);
- }else {
- endoffset.add(offsetcount);
- }
- flagcount++;
- }
+ IndexDescriptor id=(IndexDescriptor)desc;
+ indexcheck="((tmpindex=";
+ for(int j=0;j<id.tddesc.size();j++) {
+ indexcheck+=generateTemp(fm, id.getTempDescAt(j), lb)+"+";
+ }
+ indexcheck+=id.offset+")>=0)&&(tmpindex<((struct ArrayObject *)prefptr)->___length___)";
- public void generateOutsideTransCode(FlatMethod fm, LocalityBinding lb,PrefetchPair pp, Vector oids, Vector fieldoffset, Vector endoffset, int tuplecount) {
- int i,j;
- short offsetcount = 0;
-
- String oid = new String(" (unsigned int) (" + generateTemp(fm, pp.base, lb)+ ")");
- oids.add(oid);
- for(i = 0; i < pp.desc.size(); i++) {
- TypeDescriptor newtd;
- ClassDescriptor cd;
- String newfieldoffset;
- Object desc = pp.getDescAt(i);
- offsetcount++;
- if(desc instanceof FieldDescriptor) {
- if(i == 0){
- newtd = pp.base.getType();
- newfieldoffset = new String("(unsigned int)(&(((struct "+ newtd.getSafeSymbol()+" *)0)->"+
- ((FieldDescriptor)desc).getSafeSymbol()+ "))");
- } else {
- Object prevdesc = pp.getDescAt(i-1);
- if(prevdesc instanceof IndexDescriptor){
- if((i-1) == 0) {
- newtd = pp.base.getType();
- cd = newtd.getClassDesc();
- } else {
- //FIXME currently handles one dimensional arrays
- newtd = ((FieldDescriptor)pp.getDescAt(i-2)).getType();
- cd = newtd.getClassDesc();
- }
- newfieldoffset = new String("(unsigned int)(&(((struct "+ cd.getSafeSymbol() +" *)0)->"+
- ((FieldDescriptor)desc).getSafeSymbol()+ "))");
- } else {
- newtd = ((FieldDescriptor)pp.getDescAt(i-1)).getType();
- newfieldoffset = new String("(unsigned int)(&(((struct "+ newtd.getSafeSymbol()+" *)0)->"+
- ((FieldDescriptor)desc).getSafeSymbol()+ "))");
- }
- }
- } else {
- String tstlbl = new String();
- for(j = 0; j < ((IndexDescriptor)desc).tddesc.size(); j++) {
- tstlbl += generateTemp(fm, ((IndexDescriptor)desc).getTempDescAt(j), lb) + "+";
- }
- tstlbl += ((IndexDescriptor)desc).offset.toString();
- newfieldoffset = new String(tstlbl);
- }
- fieldoffset.add(newfieldoffset);
+ if (!teststr.equals(""))
+ teststr+="&&";
+ teststr+="((prefptr="+basestr+")!= NULL) &&"+indexcheck;
+ basestr="((void **)(((char *) &(((struct ArrayObject *)prefptr)->___length___))+sizeof(int)))[tmpindex]";
+ maybenull=true;
+ lasttype=lasttype.dereference();
}
- if(tuplecount > 0) {
- int tmp = (int) ((Short)(endoffset.get(tuplecount-1))).shortValue() + (int) offsetcount;
- short endoffsetval = (short) tmp;
- endoffset.add(endoffsetval);
- }else {
- endoffset.add(offsetcount);
+ }
+
+ 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);
+ }
- public void generateLocalTransCode(FlatMethod fm, LocalityBinding lb,PrefetchPair pp,Vector oids, Vector fieldoffset,Vector endoffset, int tuplecount) {
- int i, j, k;
- short offsetcount = 0;
-
- Vector prefix = new Vector();
- prefix.add(generateTemp(fm,pp.base,lb));
- String tstlbl = new String("(" + prefix.get(0) + " != NULL ");
- for (i = 0; i < pp.desc.size(); i++) {
- Object newdesc = pp.desc.get(i);
- if(newdesc instanceof FieldDescriptor) {
- FieldDescriptor fd = (FieldDescriptor) newdesc;
- if(fd.isGlobal()){
- /* Field descriptor is global */
- String oid = new String(" (unsigned int) (");
- tstlbl += ") ? ";
- for(j = 0; j < prefix.size(); j++) {
- tstlbl += prefix.get(j) + "->";
- }
- tstlbl += fd.getSafeSymbol() + ": NULL";
- oid += tstlbl+ " )";
- oids.add(oid);
- for(j = i+1; j < pp.desc.size(); j++) {
- TypeDescriptor newtd;
- String newfieldoffset;
- Object desc = pp.getDescAt(j);
- offsetcount++;
- if(desc instanceof FieldDescriptor) {
- Object prevdesc = pp.getDescAt(j-1);
- if(prevdesc instanceof IndexDescriptor){
- //FIXME currently handles one dimensional arrays
- newtd = ((FieldDescriptor)pp.getDescAt(j-2)).getType();
- } else {
- newtd = ((FieldDescriptor) pp.getDescAt(j-1)).getType();
- }
- newfieldoffset = new String("(unsigned int)(&(((struct "+ newtd.getSafeSymbol()+" *)0)->"+
- ((FieldDescriptor)desc).getSafeSymbol()+ "))");
- } else {
- String indexlbl = new String();
- for(k = 0; k < ((IndexDescriptor)desc).tddesc.size(); k++) {
- indexlbl += generateTemp(fm, ((IndexDescriptor)desc).getTempDescAt(k), lb) + "+";
- }
- indexlbl += ((IndexDescriptor)desc).offset.toString();
- newfieldoffset = new String(indexlbl);
- }
- fieldoffset.add(newfieldoffset);
- }
- if(tuplecount > 0) {
- int tmp = (int) ((Short)(endoffset.get(tuplecount-1))).shortValue() + (int) offsetcount;
- short endoffsetval = (short) tmp;
- endoffset.add(endoffsetval);
- }else {
- endoffset.add(offsetcount);
- }
- tuplecount++;
- break; //break from outer for loop
- } else {
- tstlbl += "&& ";
- for(j = 0; j < prefix.size(); j++) {
- tstlbl += prefix.get(j) + "->";
- }
- prefix.add(fd.getSafeSymbol());
- tstlbl += fd.getSafeSymbol() + " != NULL";
- }
- } else { /* if Index descriptor */
- String indexstring = new String();
- IndexDescriptor id = (IndexDescriptor) newdesc;
- if(i == 0) {
- indexstring = generateTemp(fm, pp.base, lb);
- } else {
- indexstring = ((FieldDescriptor)pp.getDescAt(i-1)).getSafeSymbol();
- }
- tstlbl += "&& ";
- for(j = 0; j < prefix.size(); j++) {
- tstlbl += prefix.get(j) + "[";
- }
- indexstring += "[";
- for(j = 0; j < id.tddesc.size(); j++) {
- tstlbl += generateTemp(fm, id.getTempDescAt(j), lb) + "+";
- indexstring += generateTemp(fm,id.getTempDescAt(j), lb) + "+";
- }
- tstlbl += id.offset.toString()+ "]";
- indexstring += id.offset.toString()+ "]";
- prefix. removeElementAt(prefix.size() -1);
- prefix.add(indexstring);
- tstlbl += " != NULL";
- }
- }
+ 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;
output.print(objectparams.numPointers());
output.print(", & "+localsprefix);
- if (fc.getThis()!=null) {
+ if (md.getThis()!=null) {
output.print(", ");
output.print("(struct "+md.getThis().getType().getSafeSymbol() +" *)"+ generateTemp(fm,fc.getThis(),lb));
}
+ 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;i<fc.numArgs();i++) {
Descriptor var=md.getParameter(i);
TempDescriptor paramtemp=(TempDescriptor)temptovar.get(var);
output.print(temp.getType().getSafeSymbol());
}
+ if (state.DSM&&locality.getBinding(lb,fc).isAtomic()&&!fc.getMethod().getModifiers().isNative()) {
+ LocalityBinding fclb=locality.getBinding(lb, fc);
+ if (printcomma)
+ output.print(", ");
+ output.print("transrecord_t *");
+ printcomma=true;
+ }
+
if (state.DSM) {
LocalityBinding fclb=locality.getBinding(lb, fc);
output.print("))virtualtable["+generateTemp(fm,fc.getThis(),lb)+"->type*"+maxcount+"+"+virtualcalls.getLocalityNumber(fclb)+"])");
needcomma=true;
}
- if (state.DSM&&locality.getBinding(lb,fc).isAtomic()) {
+ if (state.DSM&&locality.getBinding(lb,fc).isAtomic()&&!fc.getMethod().getModifiers().isNative()) {
if (needcomma)
output.print(",");
output.print("trans");
} 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
} else if (statusdst.equals(LocalityAnalysis.EITHER)) {
//writing to a null...bad
output.println("if ("+dst+") {");
+ output.println("#ifndef RAW");
output.println("printf(\"BIG ERROR 2\\n\");exit(-1);}");
+ output.println("#endif");
if (srcglobal)
output.println(dst+"->"+ fsfn.getField().getSafeSymbol()+"=srcoid;");
else
} 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
output.println(generateTemp(fm, fln.getDst(),lb)+"="+fln.getValue()+";");
}
- private void generateFlatReturnNode(FlatMethod fm, LocalityBinding lb, FlatReturnNode frn, PrintWriter output) {
+ 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)+";");
else
output.println("return "+generateTemp(fm, frn.getReturnTemp(), lb)+";");
- } else
+ } else {
output.println("return;");
+ }
}
- private void generateFlatCondBranch(FlatMethod fm, LocalityBinding lb, FlatCondBranch fcb, String label, PrintWriter output) {
+ protected void generateFlatCondBranch(FlatMethod fm, LocalityBinding lb, FlatCondBranch fcb, String label, PrintWriter output) {
output.println("if (!"+generateTemp(fm, fcb.getTest(),lb)+") goto "+label+";");
}
ormask=((Integer)flagortable.get(temp)).intValue();
if (flagandtable.containsKey(temp))
andmask=((Integer)flagandtable.get(temp)).intValue();
- if (ffan.getTaskType()==FlatFlagActionNode.NEWOBJECT) {
- output.println("flagorandinit("+generateTemp(fm, temp, lb)+", 0x"+Integer.toHexString(ormask)+", 0x"+Integer.toHexString(andmask)+");");
- } else {
- output.println("flagorand("+generateTemp(fm, temp, lb)+", 0x"+Integer.toHexString(ormask)+", 0x"+Integer.toHexString(andmask)+");");
- }
+ generateFlagOrAnd(ffan, fm, lb, temp, output, ormask, andmask);
+ generateObjectDistribute(ffan, fm, lb, temp, output);
+ }
+ }
+
+ 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("+generateTemp(fm, temp, lb)+", 0x"+Integer.toHexString(ormask)+", 0x"+Integer.toHexString(andmask)+");");
+ } else {
+ output.println("flagorand("+generateTemp(fm, temp, lb)+", 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)+");");
+ }
+
void generateOptionalHeader(PrintWriter headers) {
//GENERATE HEADERS
return l;
}
+
+ protected void outputTransCode(PrintWriter output) {
+ }
}