From c2dad107911f5de5cf15eeebe4752e481845afdf Mon Sep 17 00:00:00 2001 From: bdemsky Date: Fri, 14 Sep 2007 08:58:02 +0000 Subject: [PATCH] thread stuff --- .../Analysis/Locality/LocalityAnalysis.java | 18 +++++++- Robust/src/IR/Flat/BuildCode.java | 6 +++ Robust/src/IR/TypeUtil.java | 11 +++++ .../src/Runtime/DSTM/interface/dstmserver.c | 7 ++++ Robust/src/Runtime/thread.c | 41 +++++++++++++++++++ Robust/src/Runtime/thread.h | 7 ++++ 6 files changed, 88 insertions(+), 2 deletions(-) diff --git a/Robust/src/Analysis/Locality/LocalityAnalysis.java b/Robust/src/Analysis/Locality/LocalityAnalysis.java index c2a9efd7..ea5d4332 100644 --- a/Robust/src/Analysis/Locality/LocalityAnalysis.java +++ b/Robust/src/Analysis/Locality/LocalityAnalysis.java @@ -78,7 +78,6 @@ public class LocalityAnalysis { /** This method returns a set of LocalityBindings for the parameter class. */ - public Set getClassBindings(ClassDescriptor cd) { return classtolb.get(cd); } @@ -165,6 +164,7 @@ public class LocalityAnalysis { private void computeLocalityBindings() { lbmain=new LocalityBinding(typeutil.getMain(), false); + lbmain.setGlobalReturn(EITHER); lbmain.setGlobal(0, LOCAL); lbtovisit.add(lbmain); discovered.put(lbmain, lbmain); @@ -176,6 +176,20 @@ public class LocalityAnalysis { methodtolb.put(lbmain.getMethod(), new HashSet()); methodtolb.get(lbmain.getMethod()).add(lbmain); + //Do this to force a virtual table number for the run method + LocalityBinding lbrun=new LocalityBinding(typeutil.getRun(), false); + lbrun.setGlobalReturn(EITHER); + lbrun.setGlobalThis(GLOBAL); + lbtovisit.add(lbrun); + discovered.put(lbrun, lbrun); + if (!classtolb.containsKey(lbrun.getMethod().getClassDesc())) + classtolb.put(lbrun.getMethod().getClassDesc(), new HashSet()); + classtolb.get(lbrun.getMethod().getClassDesc()).add(lbrun); + + if (!methodtolb.containsKey(lbrun.getMethod())) + methodtolb.put(lbrun.getMethod(), new HashSet()); + methodtolb.get(lbrun.getMethod()).add(lbrun); + while(!lbtovisit.empty()) { LocalityBinding lb=(LocalityBinding) lbtovisit.pop(); Integer returnglobal=lb.getGlobalReturn(); @@ -186,7 +200,7 @@ public class LocalityAnalysis { atomictab.put(lb, atomictable); temptab.put(lb, temptable); - if (!md.isStatic()&&!returnglobal.equals(lb.getGlobalReturn())) { + if (md.getReturnType()!=null&&!returnglobal.equals(lb.getGlobalReturn())) { //return type is more precise now //rerun everything that call us lbtovisit.addAll(dependence.get(lb)); diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index a7c202d2..1474de25 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -345,6 +345,12 @@ 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) { + LocalityBinding lb=new LocalityBinding(typeutil.getRun(), false); + lb.setGlobalThis(LocalityAnalysis.GLOBAL); + outstructs.println("#define RUNMETHOD "+virtualcalls.getLocalityNumber(lb)); + } outstructs.println("#define STRINGARRAYTYPE "+ (state.getArrayNumber( diff --git a/Robust/src/IR/TypeUtil.java b/Robust/src/IR/TypeUtil.java index 686a8c04..e5ce84bc 100644 --- a/Robust/src/IR/TypeUtil.java +++ b/Robust/src/IR/TypeUtil.java @@ -39,6 +39,17 @@ public class TypeUtil { return getClass(state.main); } + public MethodDescriptor getRun() { + ClassDescriptor cd=getClass(TypeUtil.ThreadClass); + for(Iterator methodit=cd.getMethodTable().getSet("run").iterator();methodit.hasNext();) { + MethodDescriptor md=(MethodDescriptor) methodit.next(); + if (md.numParameters()!=0||md.getModifiers().isStatic()) + continue; + return md; + } + throw new Error("Can't find Thread.run"); + } + public MethodDescriptor getMain() { ClassDescriptor cd=getMainClass(); Set mainset=cd.getMethodTable().getSet("main"); diff --git a/Robust/src/Runtime/DSTM/interface/dstmserver.c b/Robust/src/Runtime/DSTM/interface/dstmserver.c index e8f0718e..72997705 100644 --- a/Robust/src/Runtime/DSTM/interface/dstmserver.c +++ b/Robust/src/Runtime/DSTM/interface/dstmserver.c @@ -10,6 +10,10 @@ #include "dstm.h" #include "mlookup.h" #include "llookup.h" +#ifdef COMPILER +#include "thread.h" +#endif + #define LISTEN_PORT 2156 #define BACKLOG 10 //max pending connections @@ -184,6 +188,9 @@ void *dstmAccept(void *acceptfd) printf("dstmAccept(): received START_REMOTE_THREAD msg, oid=0x%x\n", oid); objType = getObjType(oid); printf("dstmAccept(): type of object 0x%x is %d\n", oid, objType); + startDSMthread(oid, objType); + + } break; diff --git a/Robust/src/Runtime/thread.c b/Robust/src/Runtime/thread.c index 817db2e7..70cd784d 100644 --- a/Robust/src/Runtime/thread.c +++ b/Robust/src/Runtime/thread.c @@ -124,3 +124,44 @@ void CALL12(___Thread______start____I, int ___mid___, struct ___Thread___ * ___t startRemoteThread((unsigned int)VAR(___this___), ___mid___); } #endif + +#ifdef DSTM +void initDSMthread(int *ptr) { + int oid=ptr[0]; + int type=ptr[1]; + free(ptr); +#ifdef PRECISE_GC + int p[]={1, 0 /* NULL */, oid}; + ((void (*)(void *))virtualtable[type*MAXCOUNT+RUNMETHOD])(p); +#else + ((void (*)(void *))virtualtable[type*MAXCOUNT+RUNMETHOD])(oid); +#endif + pthread_mutex_lock(&gclistlock); + threadcount--; + pthread_cond_signal(&gccond); + pthread_mutex_unlock(&gclistlock); +} + +void startDSMthread(int oid, int objType) { + pthread_t thread; + int retval; + pthread_attr_t nattr; + + pthread_mutex_lock(&gclistlock); + threadcount++; + pthread_mutex_unlock(&gclistlock); + pthread_attr_init(&nattr); + pthread_attr_setdetachstate(&nattr, PTHREAD_CREATE_DETACHED); + int * ptr=malloc(sizeof(int)*2); + ptr[0]=oid; + ptr[1]=objType; + do { + retval=pthread_create(&thread, &nattr, (void * (*)(void *)) &initDSMthread, ptr); + if (retval!=0) + usleep(1); + } while(retval!=0); + + pthread_attr_destroy(&nattr); +} + +#endif diff --git a/Robust/src/Runtime/thread.h b/Robust/src/Runtime/thread.h index 5bb5d19c..e5388ab5 100644 --- a/Robust/src/Runtime/thread.h +++ b/Robust/src/Runtime/thread.h @@ -10,7 +10,14 @@ extern pthread_cond_t gccond; extern pthread_mutex_t objlock; extern pthread_cond_t objcond; extern pthread_key_t threadlocks; +#ifdef THREADS void initthread(struct ___Thread___ * ___this___); +#endif +#ifdef DSTM +void initDSMthread(int *ptr); +void startDSMthread(int oid, int objType); +extern void * virtualtable[]; +#endif struct locklist { struct locklist * next; -- 2.34.1