TypeDescriptor[] arraytable;
LocalityAnalysis locality;
Hashtable<TempDescriptor, TempDescriptor> backuptable;
+ Hashtable<LocalityBinding, TempDescriptor> reverttable;
public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil) {
+ this(st, temptovar, typeutil, null);
+ }
+
+ public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality) {
state=st;
this.temptovar=temptovar;
- paramstable=new Hashtable();
+ paramstable=new Hashtable();
tempstable=new Hashtable();
fieldorder=new Hashtable();
flagorder=new Hashtable();
this.typeutil=typeutil;
- virtualcalls=new Virtual(state);
- }
-
- public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality) {
- this(st, temptovar, typeutil);
- this.locality=locality;
- this.backuptable=new Hashtable<TempDescriptor, TempDescriptor>();
+ virtualcalls=new Virtual(state,locality);
+ if (locality!=null) {
+ this.locality=locality;
+ this.backuptable=new Hashtable<TempDescriptor, TempDescriptor>();
+ this.reverttable=new Hashtable<LocalityBinding, TempDescriptor>();
+ }
}
/** The buildCode method outputs C code for all the methods. The Flat
private void outputMainMethod(PrintWriter outmethod) {
outmethod.println("int main(int argc, const char *argv[]) {");
outmethod.println(" int i;");
- if (GENERATEPRECISEGC) {
- outmethod.println(" struct ArrayObject * stringarray=allocate_newarray(NULL, STRINGARRAYTYPE, argc-1);");
+ if (state.DSM) {
+ outmethod.println("if (dstmStart(argv[0])) {");
+ 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 {
- outmethod.println(" struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc-1);");
+ 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.THREAD) {
outmethod.println("initializethreads();");
}
- outmethod.println(" for(i=1;i<argc;i++) {");
+ if (state.DSM) {
+ outmethod.println(" for(i=2;i<argc;i++) {");
+ } else
+ outmethod.println(" for(i=1;i<argc;i++) {");
outmethod.println(" int length=strlen(argv[i]);");
if (GENERATEPRECISEGC) {
outmethod.println(" struct ___String___ *newstring=NewString(NULL, argv[i], length);");
} else {
outmethod.println(" struct ___String___ *newstring=NewString(argv[i], length);");
}
- outmethod.println(" ((void **)(((char *)& stringarray->___length___)+sizeof(int)))[i-1]=newstring;");
+ if (state.DSM)
+ outmethod.println(" ((void **)(((char *)& stringarray->___length___)+sizeof(int)))[i-2]=newstring;");
+ else
+ outmethod.println(" ((void **)(((char *)& stringarray->___length___)+sizeof(int)))[i-1]=newstring;");
outmethod.println(" }");
} else
outmethod.println(" "+cd.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(stringarray);");
outmethod.println(" }");
-
+
+ if (state.DSM) {
+ outmethod.println("}");
+ }
+
if (state.THREAD) {
outmethod.println("pthread_mutex_lock(&gclistlock);");
outmethod.println("threadcount--;");
outmethod.println("pthread_mutex_unlock(&gclistlock);");
outmethod.println("pthread_exit(NULL);");
}
+
+
outmethod.println("}");
}
outmethod.println("#include \"methodheaders.h\"");
outmethod.println("#include \"virtualtable.h\"");
outmethod.println("#include <runtime.h>");
+ if (state.DSM)
+ outmethod.println("#include \"localobjects.h\"");
if (state.THREAD)
outmethod.println("#include <thread.h>");
if (state.main!=null) {
if (virtualcalls.getMethodCount(cd)>maxcount)
maxcount=virtualcalls.getMethodCount(cd);
}
- MethodDescriptor[][] virtualtable=new MethodDescriptor[state.numClasses()+state.numArrays()][maxcount];
+ MethodDescriptor[][] virtualtable=null;
+ LocalityBinding[][] lbvirtualtable=null;
+ if (state.DSM)
+ lbvirtualtable=new LocalityBinding[state.numClasses()+state.numArrays()][maxcount];
+ else
+ virtualtable=new MethodDescriptor[state.numClasses()+state.numArrays()][maxcount];
/* Fill in virtual table */
classit=state.getClassSymbolTable().getDescriptorsIterator();
while(classit.hasNext()) {
ClassDescriptor cd=(ClassDescriptor)classit.next();
- fillinRow(cd, virtualtable, cd.getId());
+ if (state.DSM)
+ fillinRow(cd, lbvirtualtable, cd.getId());
+ else
+ fillinRow(cd, virtualtable, cd.getId());
}
ClassDescriptor objectcd=typeutil.getClass(TypeUtil.ObjectClass);
while(arrayit.hasNext()) {
TypeDescriptor td=(TypeDescriptor)arrayit.next();
int id=state.getArrayNumber(td);
- fillinRow(objectcd, virtualtable, id+state.numClasses());
+ if (state.DSM)
+ fillinRow(objectcd, lbvirtualtable, id+state.numClasses());
+ else
+ fillinRow(objectcd, virtualtable, id+state.numClasses());
}
outvirtual.print("void * virtualtable[]={");
for(int j=0;j<maxcount;j++) {
if (needcomma)
outvirtual.print(", ");
- if (virtualtable[i][j]!=null) {
+ if (state.DSM&&lbvirtualtable[i][j]!=null) {
+ LocalityBinding lb=lbvirtualtable[i][j];
+ MethodDescriptor md=lb.getMethod();
+ outvirtual.print("& "+md.getClassDesc().getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor());
+ } else if (!state.DSM&&virtualtable[i][j]!=null) {
MethodDescriptor md=virtualtable[i][j];
outvirtual.print("& "+md.getClassDesc().getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor());
} else {
}
}
+ private void fillinRow(ClassDescriptor cd, LocalityBinding[][] virtualtable, int rownum) {
+ /* Get inherited methods */
+ if (cd.getSuperDesc()!=null)
+ fillinRow(cd.getSuperDesc(), virtualtable, rownum);
+ /* Override them with our methods */
+ if (locality.getClassBindings(cd)!=null)
+ for(Iterator<LocalityBinding> 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. */
}
/* Create backup temps */
- if (state.DSM)
+ if (state.DSM) {
for(Iterator<TempDescriptor> tmpit=backuptable.values().iterator();tmpit.hasNext();) {
TempDescriptor tmp=tmpit.next();
TypeDescriptor type=tmp.getType();
else
objecttemps.addPrim(tmp);
}
+ /* Create temp to hold revert table */
+ if (lb.getHasAtomic()) {
+ TempDescriptor reverttmp=new TempDescriptor("revertlist", typeutil.getClass(TypeUtil.ObjectClass));
+ reverttable.put(lb, reverttmp);
+ }
+ }
}
/** This method outputs the following information about classes
output.println(", ");
TypeDescriptor tdelement=arraytable[i].dereference();
if (tdelement.isArray()||tdelement.isClass())
- output.print("((int *)1)");
+ output.print("((unsigned int *)1)");
else
output.print("0");
needcomma=true;
if (state.DSM) {
/* Cycle through LocalityBindings */
- for(Iterator<LocalityBinding> lbit=locality.getClassBindings(cn).iterator();lbit.hasNext();) {
- LocalityBinding lb=lbit.next();
- MethodDescriptor md=lb.getMethod();
- generateMethod(cn, md, lb, headersout, output);
- }
+ Set<LocalityBinding> lbset=locality.getClassBindings(cn);
+ if (lbset!=null)
+ for(Iterator<LocalityBinding> lbit=lbset.iterator();lbit.hasNext();) {
+ LocalityBinding lb=lbit.next();
+ MethodDescriptor md=lb.getMethod();
+ generateMethod(cn, md, lb, headersout, output);
+ }
} else {
/* Cycle through methods */
for(Iterator methodit=cn.getMethods();methodit.hasNext();) {
private void generateMethod(ClassDescriptor cn, MethodDescriptor md, LocalityBinding lb, PrintWriter headersout, PrintWriter output) {
FlatMethod fm=state.getMethodFlat(md);
- generateTempStructs(fm, null);
+ generateTempStructs(fm, lb);
ParamsObject objectparams=(ParamsObject) paramstable.get(md);
TempObject objecttemps=(TempObject) tempstable.get(md);
}
}
- /** Generate code for FlatMethod fm. */
+ /***** Generate code for FlatMethod fm. *****/
private void generateFlatMethod(FlatMethod fm, LocalityBinding lb, PrintWriter output) {
MethodDescriptor md=fm.getMethod();
case FKind.FlatAtomicExitNode:
generateFlatAtomicExitNode(fm, lb, (FlatAtomicExitNode) fn, output);
return;
+ case FKind.FlatGlobalConvNode:
+ generateFlatGlobalConvNode(fm, lb, (FlatGlobalConvNode) fn, output);
+ return;
case FKind.FlatTagDeclaration:
generateFlatTagDeclaration(fm, (FlatTagDeclaration) fn,output);
return;
case FKind.FlatCall:
- generateFlatCall(fm, (FlatCall) fn,output);
+ generateFlatCall(fm, lb, (FlatCall) fn,output);
return;
case FKind.FlatFieldNode:
generateFlatFieldNode(fm, lb, (FlatFieldNode) fn,output);
}
+ public void generateFlatGlobalConvNode(FlatMethod fm, LocalityBinding lb, FlatGlobalConvNode fgcn, PrintWriter output) {
+ if (lb!=fgcn.getLocality())
+ return;
+ /* Have to generate flat globalconv */
+ if (fgcn.getMakePtr()) {
+ output.println(generateTemp(fm, fgcn.getSrc())+"=transRead(trans,"+generateTemp(fm, fgcn.getSrc())+");");
+ } else {
+ /* Need to convert to OID */
+ output.println(generateTemp(fm, fgcn.getSrc())+"=OID("+generateTemp(fm, fgcn.getSrc())+");");
+ }
+ }
+
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.getAtomic(lb).get(faen.getPrev(0)).intValue()>0)
output.println(generateTemp(fm, tmp)+"="+generateTemp(fm,backuptable.get(tmp))+";");
}
- /* Need to revert local object store */
+ /********* Need to revert local object store ********/
+ String revertptr=generateTemp(fm, reverttable.get(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 *******/
/* Check to see if we need to generate code for this atomic */
if (locality.getAtomic(lb).get(faen).intValue()>0)
return;
- output.println("if (transCommit(trans))");
+ //store the revert list before we lose the transaction object
+ String revertptr=generateTemp(fm, reverttable.get(lb));
+ output.println(revertptr+"=trans->revertlist;");
+ output.println("if (transCommit(trans)) {");
/* Transaction aborts if it returns true */
output.println("goto transretry"+faen.getAtomicEnter().getIdentifier()+";");
+ output.println("} else {");
/* Need to commit local object store */
- //TODO
+ 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("}");
}
private void generateFlatCheckNode(FlatMethod fm, FlatCheckNode fcn, PrintWriter output) {
}
}
- private void generateFlatCall(FlatMethod fm, FlatCall fc, PrintWriter output) {
+ private void generateFlatCall(FlatMethod fm, LocalityBinding lb, FlatCall fc, PrintWriter output) {
MethodDescriptor md=fc.getMethod();
ParamsObject objectparams=(ParamsObject) paramstable.get(md);
ClassDescriptor cn=md.getClassDesc();
private void generateFlatSetFieldNode(FlatMethod fm, LocalityBinding lb, FlatSetFieldNode fsfn, PrintWriter output) {
if (fsfn.getField().getSymbol().equals("length")&&fsfn.getDst().getType().isArray())
throw new Error("Can't set array length");
- if (state.DSM) {
+ if (state.DSM && locality.getAtomic(lb).get(fsfn).intValue()>0) {
Integer statussrc=locality.getNodeTempInfo(lb).get(fsfn).get(fsfn.getDst());
Integer statusdst=locality.getNodeTempInfo(lb).get(fsfn).get(fsfn.getDst());
boolean srcglobal=statusdst==LocalityAnalysis.GLOBAL;
/* Link object into list */
output.println(dst+"->"+nextobjstr+"=trans->localtrans;");
output.println("trans->localtrans="+dst+";");
- output.println("OBJECT_COPY("+dst+");");
+ if (GENERATEPRECISEGC)
+ output.println("COPY_OBJ((struct garbagelist *)&"+localsprefix+",(struct ___Object___ *)"+dst+");");
+ else
+ output.println("COPY_OBJ("+dst+");");
output.println("}");
if (srcglobal)
output.println(dst+"->"+ fsfn.getField().getSafeSymbol()+"=srcoid;");
package IR;
import java.util.*;
+import Analysis.Locality.LocalityBinding;
+import Analysis.Locality.LocalityAnalysis;
public class Virtual {
State state;
- Hashtable methodnumber;
- Hashtable classmethodcount;
-
+ LocalityAnalysis locality;
+ Hashtable<MethodDescriptor, Integer> methodnumber;
+ Hashtable<ClassDescriptor, Integer> classmethodcount;
+ Hashtable<LocalityBinding, Integer> localitynumber;
+
public int getMethodNumber(MethodDescriptor md) {
- return ((Integer)methodnumber.get(md)).intValue();
+ return methodnumber.get(md).intValue();
}
-
+
public int getMethodCount(ClassDescriptor md) {
- return ((Integer)classmethodcount.get(md)).intValue();
+ return classmethodcount.get(md).intValue();
+ }
+
+ public int getLocalityNumber(LocalityBinding lb) {
+ return localitynumber.get(lb).intValue();
}
- public Virtual(State state) {
+ public Virtual(State state, LocalityAnalysis locality) {
this.state=state;
- methodnumber=new Hashtable();
- classmethodcount=new Hashtable();
+ this.locality=locality;
+ classmethodcount=new Hashtable<ClassDescriptor, Integer>();
+ if (state.DSM)
+ localitynumber=new Hashtable<LocalityBinding, Integer>();
+ else
+ methodnumber=new Hashtable<MethodDescriptor, Integer>();
doAnalysis();
}
Iterator classit=state.getClassSymbolTable().getDescriptorsIterator();
while(classit.hasNext()) {
ClassDescriptor cd=(ClassDescriptor)classit.next();
- numberMethods(cd);
+ if (state.DSM)
+ numberLocality(cd);
+ else
+ numberMethods(cd);
}
}
+ private int numberLocality(ClassDescriptor cd) {
+ if (classmethodcount.containsKey(cd))
+ return classmethodcount.get(cd).intValue();
+ ClassDescriptor superdesc=cd.getSuperDesc();
+ int start=0;
+ if (superdesc!=null)
+ start=numberLocality(superdesc);
+
+ if (locality.getClassBindings(cd)!=null)
+ for(Iterator<LocalityBinding> lbit=locality.getClassBindings(cd).iterator();lbit.hasNext();) {
+ LocalityBinding lb=lbit.next();
+ MethodDescriptor md=lb.getMethod();
+ //Is it a static method or constructor
+ if (md.isStatic()||md.getReturnType()==null)
+ continue;
+
+ if (superdesc!=null) {
+ Set possiblematches=superdesc.getMethodTable().getSet(md.getSymbol());
+ boolean foundmatch=false;
+ for(Iterator matchit=possiblematches.iterator();matchit.hasNext();) {
+ MethodDescriptor matchmd=(MethodDescriptor)matchit.next();
+ if (md.matches(matchmd)) {
+ Set<LocalityBinding> lbset=locality.getMethodBindings(matchmd);
+ if (lbset!=null)
+ for(Iterator<LocalityBinding> suplbit=lbset.iterator();suplbit.hasNext();) {
+ LocalityBinding suplb=suplbit.next();
+ if (lb.contextMatches(suplb)) {
+ foundmatch=true;
+ localitynumber.put(lb, localitynumber.get(suplb));
+ break;
+ }
+ }
+ break;
+ }
+ }
+ if (!foundmatch)
+ localitynumber.put(lb, new Integer(start++));
+ } else {
+ localitynumber.put(lb, new Integer(start++));
+ }
+ }
+ classmethodcount.put(cd, new Integer(start));
+ return start;
+ }
+
private int numberMethods(ClassDescriptor cd) {
if (classmethodcount.containsKey(cd))
- return ((Integer)classmethodcount.get(cd)).intValue();
+ return classmethodcount.get(cd).intValue();
ClassDescriptor superdesc=cd.getSuperDesc();
int start=0;
if (superdesc!=null)