thread stuff
authorbdemsky <bdemsky>
Fri, 14 Sep 2007 08:58:02 +0000 (08:58 +0000)
committerbdemsky <bdemsky>
Fri, 14 Sep 2007 08:58:02 +0000 (08:58 +0000)
Robust/src/Analysis/Locality/LocalityAnalysis.java
Robust/src/IR/Flat/BuildCode.java
Robust/src/IR/TypeUtil.java
Robust/src/Runtime/DSTM/interface/dstmserver.c
Robust/src/Runtime/thread.c
Robust/src/Runtime/thread.h

index c2a9efd7d6c168be83beb4b90ae408bdb49598df..ea5d4332da8cbf7f5dedb10cd2bb76eb41cdd477 100644 (file)
@@ -78,7 +78,6 @@ public class LocalityAnalysis {
 
 
     /** This method returns a set of LocalityBindings for the parameter class. */
-       
     public Set<LocalityBinding> 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<LocalityBinding>());
        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<LocalityBinding>());
+       classtolb.get(lbrun.getMethod().getClassDesc()).add(lbrun);
+
+       if (!methodtolb.containsKey(lbrun.getMethod()))
+           methodtolb.put(lbrun.getMethod(), new HashSet<LocalityBinding>());
+       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));
index a7c202d2270592f7e51020fce915a534ad0dd2aa..1474de25f90607e4ecd34f8326ed8b6b8012445e 100644 (file)
@@ -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(
index 686a8c04cc4eb69e5ec5bbf787f3e48b874955d6..e5ce84bc70fda79a0df2e37c9ccbcfad1aaf2949 100644 (file)
@@ -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");
index e8f0718e6762a81c533c89dd3f0aa2c460abf1b1..72997705db93fb8d73b85e8fe6edf0cb11f314a6 100644 (file)
 #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;
 
index 817db2e7ccb0d422c8c42020a3b33434c2508ec0..70cd784d6be150dd208b8719d100245185c0f028 100644 (file)
@@ -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
index 5bb5d19c83e4c66ea31c7c442a34bb9d5d15cc09..e5388ab5985e313b1f1ff9259d137c9144df298f 100644 (file)
@@ -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;