changes
authorbdemsky <bdemsky>
Wed, 12 Sep 2007 22:34:26 +0000 (22:34 +0000)
committerbdemsky <bdemsky>
Wed, 12 Sep 2007 22:34:26 +0000 (22:34 +0000)
Robust/src/Analysis/Locality/LocalityAnalysis.java
Robust/src/IR/Flat/BuildCode.java
Robust/src/IR/TypeUtil.java
Robust/src/Runtime/garbage.c
Robust/src/Runtime/garbage.h
Robust/src/Runtime/thread.c
Robust/src/buildscript

index de795283dc805eae0e9c70f1ec2baed6ccb0a546..641843e9dac93aa983289a2f76f8f8275b6d9530 100644 (file)
@@ -317,11 +317,31 @@ public class LocalityAnalysis {
     void processCallNode(LocalityBinding currlb, FlatCall fc, Hashtable<TempDescriptor, Integer> currtable, boolean isatomic) {
        MethodDescriptor nodemd=fc.getMethod();
        Set methodset=null;
+       Set runmethodset=null;
        if (nodemd.isStatic()||nodemd.getReturnType()==null) {
            methodset=new HashSet();
            methodset.add(nodemd);
        } else {
            methodset=callgraph.getMethods(nodemd, fc.getThis().getType());
+           // Build start -> run link
+           if (nodemd.getClassDesc().getSymbol().equals(TypeUtil.ThreadClass)&&
+               nodemd.getSymbol().equals("start")&&!nodemd.getModifiers().isStatic()&&
+               nodemd.numParameters()==1&&nodemd.getParamType(0).isInt()) {
+               assert(nodemd.getModifiers().isNative());
+               
+               MethodDescriptor runmd=null;
+               for(Iterator methodit=nodemd.getClassDesc().getMethodTable().getSet("run").iterator();methodit.hasNext();) {
+                   MethodDescriptor md=(MethodDescriptor) methodit.next();
+                   if (md.numParameters()!=0||md.getModifiers().isStatic())
+                       continue;
+                   runmd=md;
+                   break;
+               }
+               if (runmd!=null) {
+                   runmethodset=callgraph.getMethods(runmd,fc.getThis().getType());
+                   methodset.addAll(runmethodset);
+               } else throw new Error("Can't find run method");
+           }
        }
        Integer currreturnval=EITHER; //Start off with the either value
        for(Iterator methodit=methodset.iterator();methodit.hasNext();) {
@@ -332,17 +352,25 @@ public class LocalityAnalysis {
            if (isnative&&isatomic) {
                System.out.println("Don't call native methods in atomic blocks!");
            }
-           for(int i=0;i<fc.numArgs();i++) {
-               TempDescriptor arg=fc.getArg(i);
-               if(isnative&&(currtable.get(arg).equals(GLOBAL)||
-                             currtable.get(arg).equals(CONFLICT)))
-                  throw new Error("Potential call to native method "+md+" with global parameter:\n"+currlb.getExplanation());
-               lb.setGlobal(i,currtable.get(arg));
+           if (runmethodset==null||!runmethodset.contains(md)) {
+               //Skip this part if it is a run method
+               for(int i=0;i<fc.numArgs();i++) {
+                   TempDescriptor arg=fc.getArg(i);
+                   if(isnative&&(currtable.get(arg).equals(GLOBAL)||
+                                 currtable.get(arg).equals(CONFLICT)))
+                       throw new Error("Potential call to native method "+md+" with global parameter:\n"+currlb.getExplanation());
+                   lb.setGlobal(i,currtable.get(arg));
+               }
            }
+
+
            if (fc.getThis()!=null) {
                Integer thistype=currtable.get(fc.getThis());
                if (thistype==null)
                    thistype=EITHER;
+
+               if(runmethodset!=null&&runmethodset.contains(md)&&thistype.equals(LOCAL))
+                   throw new Error("Starting thread on local object not allowed in context:\n"+currlb.getExplanation());
                if(thistype.equals(CONFLICT))
                    throw new Error("Using type that can be either local or global in context:\n"+currlb.getExplanation());
                if(thistype.equals(GLOBAL)&&!isatomic)
@@ -350,9 +378,7 @@ public class LocalityAnalysis {
                if (isnative&&thistype.equals(GLOBAL))
                    throw new Error("Potential call to native method "+md+" on global objects:\n"+currlb.getExplanation());
                lb.setGlobalThis(thistype);
-           } //else
-           //lb.setGlobalThis(EITHER);//default value
-               
+           } 
            //lb is built
            if (!discovered.containsKey(lb)) {
                if (isnative)
index 0c92252cd79e8bbd14e98c880643880dd46775b2..a7c202d2270592f7e51020fce915a534ad0dd2aa 100644 (file)
@@ -1392,7 +1392,7 @@ public class BuildCode {
            output.println("/* nop */");
            return;
        case FKind.FlatBackEdge:
-           if (state.THREAD&&GENERATEPRECISEGC) {
+           if ((state.THREAD||state.DSM)&&GENERATEPRECISEGC) {
                output.println("checkcollect(&"+localsprefix+");");
            } else
                output.println("/* nop */");
index 981a098da102bc556f61196ae1d1b82b77c1f41e..686a8c04cc4eb69e5ec5bbf787f3e48b874955d6 100644 (file)
@@ -6,6 +6,7 @@ public class TypeUtil {
     public static final String ObjectClass="Object";
     public static final String StartupClass="StartupObject";
     public static final String TagClass="TagDescriptor";
+    public static final String ThreadClass="Thread";
     State state;
     Hashtable supertable;
     Hashtable subclasstable;
index 474444a6e096ec40d0063020813e59cbdc99bed9..e2b688b320f4fd93d233c0cca373a623e61c3c08 100644 (file)
@@ -5,9 +5,10 @@
 #include "SimpleHash.h"
 #include "GenericHashtable.h"
 #include <string.h>
-#ifdef THREADS
+#if defined(THREADS) || defined(DSTM)
 #include "thread.h"
 #endif
+
 #ifdef DMALLOC
 #include "dmalloc.h"
 #endif
@@ -30,7 +31,7 @@ extern struct RuntimeHash *reverse;
 extern struct RuntimeHash *fdtoobject;
 #endif
 
-#ifdef THREADS
+#if defined(THREADS) || defined(DSTM)
 int needtocollect=0;
 struct listitem * list=NULL;
 int listcount=0;
@@ -128,7 +129,7 @@ void enqueuetag(struct ___TagDescriptor___ *ptr) {
 
 
 void collect(struct garbagelist * stackptr) {
-#ifdef THREADS
+#if defined(THREADS)||defined(DSTM)
   needtocollect=1;
   pthread_mutex_lock(&gclistlock);
   while(1) {
@@ -154,7 +155,7 @@ void collect(struct garbagelist * stackptr) {
 #endif
 
   /* Check current stack */
-#ifdef THREADS
+#if defined(THREADS)||defined(DSTM)
  {
    struct listitem *listptr=list;
    while(1) {
@@ -168,7 +169,7 @@ void collect(struct garbagelist * stackptr) {
     }
     stackptr=stackptr->next;
   }
-#ifdef THREADS
+#if defined(THREADS)||defined(DSTM)
   /* Go to next thread */
   if (listptr!=NULL) {
     void * orig=listptr->locklist;
@@ -311,7 +312,7 @@ void collect(struct garbagelist * stackptr) {
   fixtags();
 #endif
 
-#ifdef THREADS
+#if defined(THREADS)||defined(DSTM)
   needtocollect=0;
   pthread_mutex_unlock(&gclistlock);
 #endif
@@ -378,7 +379,7 @@ void * tomalloc(int size) {
   return ptr;
 }
 
-#ifdef THREADS
+#if defined(THREADS)||defined(DSTM)
 
 void checkcollect(void * ptr) {
   if (needtocollect) {
@@ -425,7 +426,7 @@ void restartaftergc(struct listitem * litem) {
 
 void * mygcmalloc(struct garbagelist * stackptr, int size) {
   void *ptr;
-#ifdef THREADS
+#if defined(THREADS)||defined(DSTM)
   if (pthread_mutex_trylock(&gclock)!=0) {
     struct listitem *tmp=stopforgc(stackptr);
     pthread_mutex_lock(&gclock);
@@ -449,7 +450,7 @@ void * mygcmalloc(struct garbagelist * stackptr, int size) {
       to_heaptop=to_heapbase+INITIALHEAPSIZE;
       to_heapptr=to_heapbase;
       ptr=curr_heapbase;
-#ifdef THREADS
+#if defined(THREADS)||defined(DSTM)
       pthread_mutex_unlock(&gclock);
 #endif
       return ptr;
@@ -498,20 +499,20 @@ void * mygcmalloc(struct garbagelist * stackptr, int size) {
       
       /* Not enough room :(, redo gc */
       if (curr_heapptr>curr_heapgcpoint) {
-#ifdef THREADS
+#if defined(THREADS)||defined(DSTM)
        pthread_mutex_unlock(&gclock);
 #endif
        return mygcmalloc(stackptr, size);
       }
       
       bzero(tmp, curr_heaptop-tmp);
-#ifdef THREADS
+#if defined(THREADS)||defined(DSTM)
       pthread_mutex_unlock(&gclock);
 #endif
       return tmp;
     }
   } else {
-#ifdef THREADS
+#if defined(THREADS)||defined(DSTM)
     pthread_mutex_unlock(&gclock);
 #endif
     return ptr;
index c021ac6415bd0db3b9575c8e03a5c3020784bcf6..5a65de65db2d1adc0f239cbd690d381bdc80e3c8 100644 (file)
@@ -17,7 +17,7 @@ struct listitem {
 void fixtags();
 #endif
 
-#ifdef THREADS
+#if defined(THREADS)||defined(DSTM)
 void checkcollect(void * ptr);
 struct listitem * stopforgc(struct garbagelist * ptr);
 void restartaftergc(struct listitem * litem);
index a8b19c02c4cb579073435fd7855de19cb7d2da28..b070cbb01bc46cc0273a5d90feefffdd29aea333 100644 (file)
@@ -17,6 +17,7 @@ pthread_cond_t objcond;
 pthread_key_t threadlocks;
 
 void threadexit() {
+#ifdef THREADS
   struct ___Object___ *ll=pthread_getspecific(threadlocks);
   while(ll!=NULL) {
     struct ___Object___ *llnext=ll->___nextlockobject___;    
@@ -29,6 +30,7 @@ void threadexit() {
   pthread_mutex_lock(&objlock);//wake everyone up
   pthread_cond_broadcast(&objcond);
   pthread_mutex_unlock(&objlock);
+#endif
   pthread_mutex_lock(&gclistlock);
   threadcount--;
   pthread_cond_signal(&gccond);
@@ -66,6 +68,7 @@ void initializethreads() {
   sigaction(SIGFPE,&sig,0);
 }
 
+#ifdef THREADS
 void initthread(struct ___Thread___ * ___this___) {
 #ifdef PRECISE_GC
   struct ___Thread______staticStart____L___Thread____params p={1, NULL, ___this___};
@@ -78,6 +81,7 @@ void initthread(struct ___Thread___ * ___this___) {
   pthread_cond_signal(&gccond);
   pthread_mutex_unlock(&gclistlock);
 }
+#endif
 
 void CALL11(___Thread______sleep____J, long long ___millis___, long long ___millis___) {
 #ifdef THREADS
@@ -93,6 +97,7 @@ void CALL11(___Thread______sleep____J, long long ___millis___, long long ___mill
 #endif
 }
 
+#ifdef THREADS
 void CALL01(___Thread______nativeCreate____, struct ___Thread___ * ___this___) {
   pthread_t thread;
   int retval;
@@ -112,3 +117,4 @@ void CALL01(___Thread______nativeCreate____, struct ___Thread___ * ___this___) {
 
   pthread_attr_destroy(&nattr);
 }
+#endif
index 6b9e0f049479b9e200fb7ab84688bbe3b94a3052..110484075b51c582cd134233ad34bb91a0249af7 100755 (executable)
@@ -198,7 +198,7 @@ $ROBUSTROOT/Runtime/GenericHashtable.c $ROBUSTROOT/Runtime/object.c"
 if $DSMFLAG
 then
 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"
+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 $ROBUSTROOT/Runtime/thread.c"
 fi
 
 if $RECOVERFLAG