changes
authorbdemsky <bdemsky>
Mon, 11 Apr 2011 07:42:26 +0000 (07:42 +0000)
committerbdemsky <bdemsky>
Mon, 11 Apr 2011 07:42:26 +0000 (07:42 +0000)
Robust/src/ClassLibrary/JavaThread/Object.java
Robust/src/ClassLibrary/MGC/Object.java
Robust/src/Runtime/garbage.c
Robust/src/Runtime/garbage.h
Robust/src/Runtime/object.c
Robust/src/Runtime/object.h
Robust/src/Runtime/thread.c
Robust/src/Runtime/thread.h

index 53173230780d0e611925a5db823436b303a5acbb..b48cd258c6a4484b47f11593784b80385ac59bba 100644 (file)
@@ -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();
index b7e6f03f297f84adf515fbb202ff93c5d1028ef1..a1d7703bfb367c5f1ebb04d0a68e3113ac701a13 100644 (file)
@@ -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();
index 615747f283d02b46fb1880d672b0ddfd94554a1e..4bc119745f73f0d44afe12b5ff5a232caa964295 100644 (file)
@@ -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;i<lvector->index;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;
   }
  }
index 2290d9729ab808f5ef8d226126b428c1727d8e6d..a5f7cd83486cceec7f1ace21fea98a37b0b43269 100644 (file)
@@ -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;
index 55de437ade644fdfb8a4493d4b8dc37c9022246a..59c6bb9b22ee26a3811a16be136b1f412d0c2b6d 100644 (file)
 #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
index b9484e1b64278c7e2bf5f21acb2285865a5e38da..c40f4b99627f509b61f95cca03c07def2b659430 100644 (file)
@@ -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
index 857f89c81462e5562e8f52ae91d8337fd6ce8a44..7624cb3b9199c597a8e165390f4d9c10d581d27d 100644 (file)
@@ -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 {
index 4f65bd68b8a92eb0d4579f336e06910da257748c..45e8a9d6c438181bbc4443e64772bd187198881d 100644 (file)
@@ -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