From: bdemsky Date: Mon, 11 Apr 2011 07:42:26 +0000 (+0000) Subject: changes X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=7005d0e652433270ad22b2632ca746d2ef3d7285;p=IRC.git changes --- diff --git a/Robust/src/ClassLibrary/JavaThread/Object.java b/Robust/src/ClassLibrary/JavaThread/Object.java index 53173230..b48cd258 100644 --- a/Robust/src/ClassLibrary/JavaThread/Object.java +++ b/Robust/src/ClassLibrary/JavaThread/Object.java @@ -2,20 +2,14 @@ public class Object { public int cachedCode; //first field has to be a primitive public boolean cachedHash; - private Object nextlockobject; - private Object prevlockobject; - - // temporary extra unused int filed to align objects for Java - int wkhqwemnbmwnb; - public native int hashCode(); /* DON'T USE THIS METHOD UNLESS NECESSARY */ /* WE WILL DEPRECATE IT AS SOON AS INSTANCEOF WORKS */ public native int getType(); - public native int MonitorEnter(); - public native int MonitorExit(); + public native void MonitorEnter(); + public native void MonitorExit(); public String toString() { return "Object"+hashCode(); diff --git a/Robust/src/ClassLibrary/MGC/Object.java b/Robust/src/ClassLibrary/MGC/Object.java index b7e6f03f..a1d7703b 100644 --- a/Robust/src/ClassLibrary/MGC/Object.java +++ b/Robust/src/ClassLibrary/MGC/Object.java @@ -2,9 +2,6 @@ public class Object { public int cachedCode; //first field has to be a primitive public boolean cachedHash; - private Object nextlockobject; - private Object prevlockobject; - // temporary extra unused int filed to align objects for Java //int wkhqwemnbmwnb; @@ -14,8 +11,8 @@ public class Object { /* WE WILL DEPRECATE IT AS SOON AS INSTANCEOF WORKS */ public native int getType(); - public native int MonitorEnter(); - public native int MonitorExit(); + public native void MonitorEnter(); + public native void MonitorExit(); public String toString() { return "Object"+hashCode(); diff --git a/Robust/src/Runtime/garbage.c b/Robust/src/Runtime/garbage.c index 615747f2..4bc11974 100644 --- a/Robust/src/Runtime/garbage.c +++ b/Robust/src/Runtime/garbage.c @@ -398,6 +398,16 @@ void collect(struct garbagelist * stackptr) { } #if defined(THREADS)||defined(DSTM)||defined(STM)||defined(MLP) /* Go to next thread */ +#ifdef THREADS + { + struct lockvector * lvector=listptr->lvector; + int i; + for(i=0;iindex;i++) { + struct ___Object___ *orig=lvector->locks[i].object + ENQUEUE(orig, lvector->locks[i].object); + } + } +#endif #ifndef MAC //skip over us if (listptr==&litem) { @@ -405,11 +415,6 @@ void collect(struct garbagelist * stackptr) { // update forward list & memory queue for the current SESE updateForwardList(&((SESEcommon*)listptr->seseCommon)->forwardList,FALSE); updateMemoryQueue((SESEcommon*)(listptr->seseCommon)); -#endif -#ifdef THREADS - void *orig=pthread_getspecific(threadlocks); - ENQUEUE(orig, orig); - pthread_setspecific(threadlocks, orig); #endif listptr=listptr->next; } @@ -417,11 +422,6 @@ void collect(struct garbagelist * stackptr) { { struct listitem *litem=pthread_getspecific(litemkey); if (listptr==litem) { -#ifdef THREADS - void *orig=pthread_getspecific(threadlocks); - ENQUEUE(orig, orig); - pthread_setspecific(threadlocks, orig); -#endif listptr=listptr->next; } } diff --git a/Robust/src/Runtime/garbage.h b/Robust/src/Runtime/garbage.h index 2290d972..a5f7cd83 100644 --- a/Robust/src/Runtime/garbage.h +++ b/Robust/src/Runtime/garbage.h @@ -3,6 +3,7 @@ #ifdef STM #include "stmlookup.h" #endif + struct garbagelist { int size; struct garbagelist *next; @@ -23,7 +24,7 @@ struct listitem { struct listitem * next; struct garbagelist * stackptr; #ifdef THREADS - struct ___Object___ * locklist; + struct lockvector * lvector; #endif #ifdef STM unsigned int tc_size; diff --git a/Robust/src/Runtime/object.c b/Robust/src/Runtime/object.c index 55de437a..59c6bb9b 100644 --- a/Robust/src/Runtime/object.c +++ b/Robust/src/Runtime/object.c @@ -13,6 +13,10 @@ #include "mlp_lock.h" #endif +#ifndef MAC +extern __thread struct lockvector lvector; +#endif + #ifdef D___Object______nativehashCode____ int CALL01(___Object______nativehashCode____, struct ___Object___ * ___this___) { return (int)((INTPTR) VAR(___this___)); @@ -37,23 +41,26 @@ int CALL01(___Object______getType____, struct ___Object___ * ___this___) { #ifdef THREADS #ifdef D___Object______MonitorEnter____ -int CALL01(___Object______MonitorEnter____, struct ___Object___ * ___this___) { -#ifndef NOLOCK +void CALL01(___Object______MonitorEnter____, struct ___Object___ * ___this___) { +#ifdef MAC + struct lockvector *lptr=(struct lockvector *)pthread_getspecific(threadlocks); +#else + struct lockvector *lptr=&lvector; +#endif + struct lockpair *lpair=lptr->locks[lptr->index]; pthread_t self=pthread_self(); + lpair->object=VAR(___this___); + lptr->index++; + + if (self==VAR(___this___)->tid) { - atomic_inc(&VAR(___this___)->lockcount); + lpair->islastlock=0; } else { + lpair->islastlock=1; while(1) { if (VAR(___this___)->lockcount==0) { if (CAS32(&VAR(___this___)->lockcount, 0, 1)==0) { - VAR(___this___)->___prevlockobject___=NULL; - VAR(___this___)->___nextlockobject___=(struct ___Object___ *)pthread_getspecific(threadlocks); - if (VAR(___this___)->___nextlockobject___!=NULL) - VAR(___this___)->___nextlockobject___->___prevlockobject___=VAR(___this___); - pthread_setspecific(threadlocks, VAR(___this___)); VAR(___this___)->tid=self; - pthread_mutex_unlock(&objlock); - BARRIER(); return; } } @@ -67,7 +74,6 @@ int CALL01(___Object______MonitorEnter____, struct ___Object___ * ___this___) { } } } -#endif } #endif @@ -85,19 +91,8 @@ void CALL01(___Object______notifyAll____, struct ___Object___ * ___this___) { #ifdef D___Object______wait____ void CALL01(___Object______wait____, struct ___Object___ * ___this___) { pthread_t self=pthread_self(); - int lockcount=VAR(___this___)->lockcount; - //release lock - if (VAR(___this___)->___prevlockobject___==NULL) { - pthread_setspecific(threadlocks, VAR(___this___)->___nextlockobject___); - } else - VAR(___this___)->___prevlockobject___->___nextlockobject___=VAR(___this___)->___nextlockobject___; - if (VAR(___this___)->___nextlockobject___!=NULL) - VAR(___this___)->___nextlockobject___->___prevlockobject___=VAR(___this___)->___prevlockobject___; - VAR(___this___)->___nextlockobject___=NULL; - VAR(___this___)->___prevlockobject___=NULL; - //VAR(___this___)->lockentry=NULL; + VAR(___this___)->tid=0; - //release lock BARRIER(); VAR(___this___)->lockcount=0; @@ -113,13 +108,7 @@ void CALL01(___Object______wait____, struct ___Object___ * ___this___) { while(1) { if (VAR(___this___)->lockcount==0) { if (CAS32(&VAR(___this___)->lockcount, 0, lockcount)==0) { - VAR(___this___)->___prevlockobject___=NULL; - VAR(___this___)->___nextlockobject___=(struct ___Object___ *)pthread_getspecific(threadlocks); - if (VAR(___this___)->___nextlockobject___!=NULL) - VAR(___this___)->___nextlockobject___->___prevlockobject___=VAR(___this___); - pthread_setspecific(threadlocks, VAR(___this___)); VAR(___this___)->tid=self; - pthread_mutex_unlock(&objlock); BARRIER(); return; } @@ -137,34 +126,20 @@ void CALL01(___Object______wait____, struct ___Object___ * ___this___) { #endif #ifdef D___Object______MonitorExit____ -int CALL01(___Object______MonitorExit____, struct ___Object___ * ___this___) { -#ifndef NOLOCK - pthread_t self=pthread_self(); - if (self==VAR(___this___)->tid) { - //release one lock... - BARRIER(); - if (VAR(___this___)->lockcount==1) { - if (VAR(___this___)->___prevlockobject___==NULL) { - pthread_setspecific(threadlocks, VAR(___this___)->___nextlockobject___); - } else - VAR(___this___)->___prevlockobject___->___nextlockobject___=VAR(___this___)->___nextlockobject___; - if (VAR(___this___)->___nextlockobject___!=NULL) - VAR(___this___)->___nextlockobject___->___prevlockobject___=VAR(___this___)->___prevlockobject___; - VAR(___this___)->___nextlockobject___=NULL; - VAR(___this___)->___prevlockobject___=NULL; - //VAR(___this___)->lockentry=NULL; - VAR(___this___)->tid=0; - } - atomic_dec(&VAR(___this___)->lockcount); - } else { -#ifdef MULTICORE - BAMBOO_EXIT(0xf201); +void CALL01(___Object______MonitorExit____, struct ___Object___ * ___this___) { +#ifdef MAC + struct lockvector *lptr=(struct lockvector *)pthread_getspecific(threadlocks); #else - printf("ERROR...UNLOCKING LOCK WE DON'T HAVE\n"); - exit(-1); + struct lockvector *lptr=&lvector; #endif + struct lockpair *lpair=lptr->locks[--lptr->index]; + pthread_t self=pthread_self(); + + if (lpair->islastlock) { + lpair->object->tid=0; + BARRIER(); + lpair->object->lockcount=0; } -#endif } #endif #endif diff --git a/Robust/src/Runtime/object.h b/Robust/src/Runtime/object.h index b9484e1b..c40f4b99 100644 --- a/Robust/src/Runtime/object.h +++ b/Robust/src/Runtime/object.h @@ -3,15 +3,35 @@ #include "runtime.h" #include "structdefs.h" #include "methodheaders.h" + +#define MAXLOCKS 256 + +struct lockpair { + struct ___Object___ *object; + int islastlock; +}; + +struct lockvector { + int index; + struct lockpair locks[MAXLOCKS]; +}; + +#ifndef MAC +extern __thread struct lockvector lvector; +#endif + #ifdef D___Object______nativehashCode____ int CALL01(___Object______nativehashCode____, struct ___Object___ * ___this___); #endif #ifdef D___Object______hashCode____ -int CALL01(___Object______hashCode____, struct ___Object___ * ___this___); +int CALL01(___Object______hashCode____, struct ___Object___ * ___this___); +#endif +#ifdef D___Object______MonitorEnter____ +void CALL01(___Object______MonitorEnter____, struct ___Object___ * ___this___); +#endif +#ifdef D___Object______MonitorExit____ +void CALL01(___Object______MonitorExit____, struct ___Object___ * ___this___); #endif -#ifdef THREADS -int CALL01(___Object______MonitorEnter____, struct ___Object___ * ___this___); -int CALL01(___Object______MonitorExit____, struct ___Object___ * ___this___); #ifdef D___Object______notify____ void CALL01(___Object______notify____, struct ___Object___ * ___this___); #endif @@ -22,4 +42,3 @@ void CALL01(___Object______notifyAll____, struct ___Object___ * ___this___); void CALL01(___Object______wait____, struct ___Object___ * ___this___); #endif #endif -#endif diff --git a/Robust/src/Runtime/thread.c b/Robust/src/Runtime/thread.c index 857f89c8..7624cb3b 100644 --- a/Robust/src/Runtime/thread.c +++ b/Robust/src/Runtime/thread.c @@ -64,23 +64,26 @@ void threadexit() { void *value; #ifdef THREADS - struct ___Object___ *ll=pthread_getspecific(threadlocks); - while(ll!=NULL) { - struct ___Object___ *llnext=ll->___nextlockobject___; - ll->___nextlockobject___=NULL; - ll->___prevlockobject___=NULL; - ll->lockcount=0; - ll->tid=0; //unlock it - ll=llnext; +#ifdef MAC + struct lockvector *lptr=(struct lockvector *) pthread_getspecific(threadlocks); +#else + struct lockvector *lptr=&lvector; +#endif + for(lptr->index--;lptr->index>=0;lptr->index--) { + if (lptr->locks[lptr->index].islastlock) { + struct ___Object___ *ll=lptr->locks[lptr->index].object; + ll->tid=0; + BARRIER(); + ll->lockcount=0; + } } + pthread_mutex_lock(&objlock); //wake everyone up pthread_cond_broadcast(&objcond); pthread_mutex_unlock(&objlock); #endif pthread_mutex_lock(&gclistlock); -#ifdef THREADS - pthread_setspecific(threadlocks, litem.locklist); -#endif + #ifndef MAC if (litem.prev==NULL) { list=litem.next; @@ -287,7 +290,10 @@ void initthread(struct ___Thread___ * ___this___) { #ifdef MAC struct listitem litem; pthread_setspecific(litemkey, &litem); + struct lockvector lvector; + pthread_setspecific(threadlocks, &lvector); #endif + litem.lvector=&lvector; litem.prev=NULL; pthread_mutex_lock(&gclistlock); litem.next=list; @@ -295,7 +301,6 @@ void initthread(struct ___Thread___ * ___this___) { list->prev=&litem; list=&litem; pthread_mutex_unlock(&gclistlock); - #ifdef THREADS ___Thread______staticStart____L___Thread___((struct ___Thread______staticStart____L___Thread____params *)p); #else @@ -353,9 +358,6 @@ void initthread(struct ___Thread___ * ___this___) { pthread_mutex_unlock(&joinlock); pthread_mutex_lock(&gclistlock); -#ifdef THREADS - pthread_setspecific(threadlocks, litem.locklist); -#endif if (litem.prev==NULL) { list=litem.next; } else { diff --git a/Robust/src/Runtime/thread.h b/Robust/src/Runtime/thread.h index 4f65bd68..45e8a9d6 100644 --- a/Robust/src/Runtime/thread.h +++ b/Robust/src/Runtime/thread.h @@ -33,10 +33,4 @@ void initDSMthread(int *ptr); void startDSMthread(int oid, int objType); extern void * virtualtable[]; #endif - -struct locklist { - struct locklist * next; - struct locklist * prev; - struct ___Object___ * object; -}; #endif