From 99d1b8e06b0ccb691c6f898d362737b77bae7f21 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Thu, 16 Aug 2007 22:30:37 +0000 Subject: [PATCH] my changes --- .../Analysis/Locality/LocalityAnalysis.java | 9 ++-- Robust/src/IR/Flat/BuildCode.java | 51 ++++++++++++------- Robust/src/Runtime/DSTM/interface/dstm.h | 1 + Robust/src/Runtime/DSTM/interface/trans.c | 11 ++++ Robust/src/Runtime/runtime.c | 35 +++++++++++++ Robust/src/Runtime/runtime.h | 8 +++ Robust/src/buildscript | 2 +- 7 files changed, 95 insertions(+), 22 deletions(-) diff --git a/Robust/src/Analysis/Locality/LocalityAnalysis.java b/Robust/src/Analysis/Locality/LocalityAnalysis.java index 56179dcc..60695a26 100644 --- a/Robust/src/Analysis/Locality/LocalityAnalysis.java +++ b/Robust/src/Analysis/Locality/LocalityAnalysis.java @@ -128,10 +128,11 @@ public class LocalityAnalysis { public Set getTempSet(LocalityBinding lb) { HashSet set=new HashSet(); Hashtable> table=getTemps(lb); - for(Iterator faenit=table.keySet().iterator();faenit.hasNext();) { - FlatAtomicEnterNode faen=faenit.next(); - set.addAll(table.get(faen)); - } + if (table!=null) + for(Iterator faenit=table.keySet().iterator();faenit.hasNext();) { + FlatAtomicEnterNode faen=faenit.next(); + set.addAll(table.get(faen)); + } return set; } diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index de30c31e..387a327e 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -105,6 +105,8 @@ 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\""); /* Output Structures */ outputStructs(outstructs); @@ -290,8 +292,7 @@ public class BuildCode { outmethod.println("#include \"methodheaders.h\""); outmethod.println("#include \"virtualtable.h\""); outmethod.println("#include "); - if (state.DSM) -{ outmethod.println("#include \"dstm.h\""); + if (state.DSM) { outmethod.println("#include \"localobjects.h\""); } if (state.THREAD) @@ -1412,7 +1413,7 @@ public class BuildCode { return; /* Have to generate flat globalconv */ if (fgcn.getMakePtr()) { - output.println(generateTemp(fm, fgcn.getSrc(),lb)+"=transRead(trans,"+generateTemp(fm, fgcn.getSrc(),lb)+");"); + output.println(generateTemp(fm, fgcn.getSrc(),lb)+"=(void *)transRead(trans, (unsigned int) "+generateTemp(fm, fgcn.getSrc(),lb)+");"); } else { /* Need to convert to OID */ output.println(generateTemp(fm, fgcn.getSrc(),lb)+"=OID("+generateTemp(fm, fgcn.getSrc(),lb)+");"); @@ -1590,15 +1591,27 @@ public class BuildCode { if (GENERATEPRECISEGC) { output.print("&__parameterlist__"); needcomma=true; - } else { + } + + if (state.DSM&&locality.getBinding(lb,fc).isAtomic()) { + if (needcomma) + output.print(","); + output.print("trans"); + needcomma=true; + } + + if (!GENERATEPRECISEGC) { if (fc.getThis()!=null) { TypeDescriptor ptd=md.getThis().getType(); + if (needcomma) + output.print(","); if (ptd.isClass()&&!ptd.isArray()) output.print("(struct "+ptd.getSafeSymbol()+" *) "); output.print(generateTemp(fm,fc.getThis(),lb)); needcomma=true; } } + for(int i=0;i"+field+"="+temp+";"); //output.println("}"); //output.println(dst+"=temp;"); @@ -1658,7 +1671,7 @@ public class BuildCode { //} else { output.println(dst+"="+ src +"->"+field+ ";"); //output.println("if ("+dst+"&0x1) {"); - output.println(dst+"=transRead(trans,"+dst+");"); + output.println(dst+"=(void *) transRead(trans, (unsigned int) "+dst+");"); //output.println(src+"->"+field+"="+src+"->"+field+";"); //output.println("}"); //} @@ -1683,9 +1696,9 @@ public class BuildCode { if (fsfn.getField().getSymbol().equals("length")&&fsfn.getDst().getType().isArray()) throw new Error("Can't set array length"); if (state.DSM && locality.getAtomic(lb).get(fsfn).intValue()>0) { - Integer statussrc=locality.getNodeTempInfo(lb).get(fsfn).get(fsfn.getDst()); + Integer statussrc=locality.getNodeTempInfo(lb).get(fsfn).get(fsfn.getSrc()); Integer statusdst=locality.getNodeTempInfo(lb).get(fsfn).get(fsfn.getDst()); - boolean srcglobal=statusdst==LocalityAnalysis.GLOBAL; + boolean srcglobal=statussrc==LocalityAnalysis.GLOBAL; String src=generateTemp(fm,fsfn.getSrc(),lb); String dst=generateTemp(fm,fsfn.getDst(),lb); @@ -1694,12 +1707,13 @@ public class BuildCode { output.println("int srcoid="+src+"->"+oidstr+";"); } if (statusdst.equals(LocalityAnalysis.GLOBAL)) { - String glbdst="(struct "+fsfn.getDst().getType().getSafeSymbol()+" *)((unsigned int)"+dst+" +sizeof(objheader_t)))"; + String glbdst="((struct "+fsfn.getDst().getType().getSafeSymbol()+" *)((unsigned int)"+dst+" +sizeof(objheader_t)))"; //mark it dirty - output.println("((objheader_t *)"+dst+")->status|=DIRTY;"); - if (srcglobal) - output.println(glbdst+"->"+ fsfn.getField().getSafeSymbol()+"=srcoid;"); - else + output.println("*((unsigned int *)&("+dst+"->___localcopy___))|=DIRTY;"); + if (srcglobal) { + output.println("*((unsigned int *)&("+glbdst+"->"+ fsfn.getField().getSafeSymbol()+"))=srcoid;"); + output.println("}"); + } else output.println(glbdst+"->"+ fsfn.getField().getSafeSymbol()+"="+ src+";"); } else if (statusdst.equals(LocalityAnalysis.LOCAL)) { /** Check if we need to copy */ @@ -1771,18 +1785,21 @@ public class BuildCode { } private void generateFlatNew(FlatMethod fm, LocalityBinding lb, FlatNew fn, PrintWriter output) { + String isglobal=""; + if (fn.isGlobal()) + isglobal="global"; if (fn.getType().isArray()) { int arrayid=state.getArrayNumber(fn.getType())+state.numClasses(); if (GENERATEPRECISEGC) { - output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarray(&"+localsprefix+", "+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+");"); + output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarray"+isglobal+"(&"+localsprefix+", "+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+");"); } else { - output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarray("+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+");"); + output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarray"+isglobal+"("+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+");"); } } else { if (GENERATEPRECISEGC) { - output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_new(&"+localsprefix+", "+fn.getType().getClassDesc().getId()+");"); + output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_new"+isglobal+"(&"+localsprefix+", "+fn.getType().getClassDesc().getId()+");"); } else { - output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_new("+fn.getType().getClassDesc().getId()+");"); + output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_new"+isglobal+"("+fn.getType().getClassDesc().getId()+");"); } } } diff --git a/Robust/src/Runtime/DSTM/interface/dstm.h b/Robust/src/Runtime/DSTM/interface/dstm.h index cf2a3b2a..8fbc6edd 100644 --- a/Robust/src/Runtime/DSTM/interface/dstm.h +++ b/Robust/src/Runtime/DSTM/interface/dstm.h @@ -216,6 +216,7 @@ int transCommitProcess(trans_commit_data_t *, int); int dstmStartup(const char *); void transInit(); +void * dstmalloc(int size); void randomdelay(void); transrecord_t *transStart(); diff --git a/Robust/src/Runtime/DSTM/interface/trans.c b/Robust/src/Runtime/DSTM/interface/trans.c index 45b30ff0..338c718e 100644 --- a/Robust/src/Runtime/DSTM/interface/trans.c +++ b/Robust/src/Runtime/DSTM/interface/trans.c @@ -80,6 +80,17 @@ void prefetch(int ntuples, unsigned int *oids, short *endoffsets, short *arrayfi pthread_mutex_unlock(&pqueue.qlock); } +static int objid=1; +/* This function allocates an object */ +void * dstmalloc(int size) { + objheader_t * newobj=(objheader_t *)objstrAlloc(mainobjstore, size+sizeof(objheader_t)); + OID(newobj)=objid; + newobj->version=1; + newobj->rcount=0; + STATUS(newobj)=NEW; + objid+=2; + return newobj; +} /* This function starts up the transaction runtime. */ int dstmStartup(const char * option) { diff --git a/Robust/src/Runtime/runtime.c b/Robust/src/Runtime/runtime.c index de7b1a49..803f19db 100644 --- a/Robust/src/Runtime/runtime.c +++ b/Robust/src/Runtime/runtime.c @@ -7,6 +7,9 @@ #include #include #include "option.h" +#ifdef DSTM +#include "dstm.h" +#endif extern int classsize[]; jmp_buf error_handler; @@ -86,6 +89,38 @@ void CALL01(___System______printString____L___String___,struct ___String___ * __ /* Object allocation function */ +#ifdef DSTM +void * allocate_newglobal(void * ptr, int type) { + struct ___Object___ * v=(struct ___Object___ *) dstmalloc(classsize[type]); + v->type=type; +#ifdef THREADS + v->tid=0; + v->lockentry=0; + v->lockcount=0; +#endif + return v; +} + +/* Array allocation function */ + +struct ArrayObject * allocate_newarrayglobal(void * ptr, int type, int length) { + struct ArrayObject * v=(struct ArrayObject *)dstmalloc(classsize[type]); + v->type=type; + if (length<0) { + printf("ERROR: negative array\n"); + return NULL; + } + v->___length___=length; +#ifdef THREADS + v->tid=0; + v->lockentry=0; + v->lockcount=0; +#endif + return v; +} +#endif + + #ifdef PRECISE_GC void * allocate_new(void * ptr, int type) { struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]); diff --git a/Robust/src/Runtime/runtime.h b/Robust/src/Runtime/runtime.h index bfa83201..aa928154 100644 --- a/Robust/src/Runtime/runtime.h +++ b/Robust/src/Runtime/runtime.h @@ -16,11 +16,19 @@ extern int failurecount; #ifdef PRECISE_GC #include "garbage.h" +#ifdef DSTM +void * allocate_newglobal(void *, int type); +struct ArrayObject * allocate_newarrayglobal(void *, int type, int length); +#endif void * allocate_new(void *, int type); struct ArrayObject * allocate_newarray(void *, int type, int length); struct ___String___ * NewString(void *, const char *str,int length); struct ___TagDescriptor___ * allocate_tag(void *ptr, int index); #else +#ifdef DSTM +void * allocate_newglobal(int type); +struct ArrayObject * allocate_newarrayglobal(int type, int length); +#endif void * allocate_new(int type); struct ArrayObject * allocate_newarray(int type, int length); struct ___String___ * NewString(const char *str,int length); diff --git a/Robust/src/buildscript b/Robust/src/buildscript index 1ee6e48c..55e661a0 100755 --- a/Robust/src/buildscript +++ b/Robust/src/buildscript @@ -192,7 +192,7 @@ $ROBUSTROOT/Runtime/GenericHashtable.c $ROBUSTROOT/Runtime/object.c" if $DSMFLAG then -EXTRAOPTIONS="$EXTRAOPTIONS -lpthread -DCOMPILER -I$DSMRUNTIME" +EXTRAOPTIONS="$EXTRAOPTIONS -lpthread -DCOMPILER -DDSTM -I$DSMRUNTIME" FILES="$FILES $DSMRUNTIME/trans.c $DSMRUNTIME/mcpileq.c $DSMRUNTIME/objstr.c $DSMRUNTIME/dstm.c $DSMRUNTIME/mlookup.c $DSMRUNTIME/clookup.c $DSMRUNTIME/llookup.c $DSMRUNTIME/dstmserver.c $DSMRUNTIME/plookup.c $DSMRUNTIME/ip.c $DSMRUNTIME/queue.c $DSMRUNTIME/prelookup.c $DSMRUNTIME/machinepile.c $DSMRUNTIME/localobjects.c" fi -- 2.34.1