bug fixes
authorbdemsky <bdemsky>
Thu, 15 Oct 2009 02:31:12 +0000 (02:31 +0000)
committerbdemsky <bdemsky>
Thu, 15 Oct 2009 02:31:12 +0000 (02:31 +0000)
Robust/src/Runtime/STM/array.h
Robust/src/Runtime/STM/commit.c
Robust/src/Runtime/STM/stm.c
Robust/src/Runtime/runtime.c

index 5024ed83056d11c3b72c6310033c12b3f48d4d34..a4648e0801113918ce81aa5ca1fcb3536c85cc34 100644 (file)
 #define MAXARRAYSIZE 2147483647
 
 #define GETLOCKPTR(lock, array, byteindex) {                           \
-    lock=(unsigned int *)((char *)array-sizeof(objheader_t)-sizeof(int)*2*(byteindex>>INDEXSHIFT)-2*sizeof(int)); \
+    lock=(unsigned int *)((char *)array-sizeof(objheader_t)-sizeof(int)*2*(byteindex)-2*sizeof(int)); \
   }
 
 #define GETLOCKVAL(lock, array, byteindex) {                           \
-    lock=*(unsigned int *)((char *)array-sizeof(objheader_t)-sizeof(int)*2*(byteindex>>INDEXSHIFT)-2*sizeof(int)); \
+    lock=*(unsigned int *)((char *)array-sizeof(objheader_t)-sizeof(int)*2*(byteindex)-2*sizeof(int)); \
   }
 
 #define GETVERSIONVAL(version, array, byteindex) {                     \
-    version=*(unsigned int *)((char *)array-sizeof(objheader_t)-sizeof(int)*2*(byteindex>>INDEXSHIFT)-sizeof(int)); \
+    version=*(unsigned int *)((char *)array-sizeof(objheader_t)-sizeof(int)*2*(byteindex)-sizeof(int)); \
+  }
+
+#define SETVERSION(array, byteindex, version) {                                \
+    *(unsigned int *)((char *)array-sizeof(objheader_t)-sizeof(int)*2*(byteindex)-sizeof(int))=version; \
   }
 
 #define GETVERSIONPTR(version, array, byteindex) {                     \
-    version=(unsigned int *)((char *)array-sizeof(objheader_t)-sizeof(int)*2*(byteindex>>INDEXSHIFT)-sizeof(int)); \
+    version=(unsigned int *)((char *)array-sizeof(objheader_t)-sizeof(int)*2*(byteindex)-sizeof(int)); \
   }
 
 #define STMGETARRAY(dst, array, index, type) {                         \
     int byteindex=index*sizeof(type);                                  \
     int * lengthoff=&array->___length___;                              \
-    int *status;                                                       \
     if (array!=array->___objlocation___) {                             \
-      GETLOCKPTR(status, array, byteindex);                            \
-      if ((*status)==STMNONE&&!(array->___objstatus___&NEW)) {         \
-       arraycopy(array, byteindex);                                    \
-       *status=STMCLEAN;};                                             \
+      if(!(array->___objstatus___&NEW)) {                              \
+       int *status;                                                    \
+       GETLOCKPTR(status, array, byteindex>>INDEXSHIFT);               \
+       if ((*status)==STMNONE) {                                       \
+         arraycopy(array, byteindex);                                  \
+         *status=STMCLEAN;}                                            \
+      }                                                                        \
     }                                                                  \
     dst=((type *)(((char *) lengthoff)+sizeof(int)))[index];           \
   }
 #define STMSETARRAY(array, index, src, type) {                         \
     int byteindex=index*sizeof(type);                                  \
     int * lengthoff=&array->___length___;                              \
-    int *status;                                                       \
-    GETLOCKPTR(status, array, byteindex);                              \
-    if (*status==STMNONE&&!(array->___objstatus___&NEW))               \
-      arraycopy(array, byteindex, sizeof(type)*(*lengthoff));          \
-    *status=STMDIRTY;                                                  \
+    if (!(array->___objstatus___&NEW)) {                               \
+      int *status;                                                     \
+      GETLOCKPTR(status, array, byteindex>>INDEXSHIFT);                        \
+      if ((*status)==STMNONE)                                          \
+       arraycopy(array, byteindex);                                    \
+      *status=STMDIRTY;                                                        \
+    }                                                                  \
     ((type *)(((char *) lengthoff)+sizeof(int)))[index]=src;           \
   }
 #endif
index e9dfe5ea429e69dc2fa317f9d40324d8ba7bd80e..5cccde91e215d43ea624d33a20a3c4f6e388ebb2 100644 (file)
@@ -295,7 +295,7 @@ int transCommit() {
     }                                                                  \
   } else                                                               
 
-#define READARRAYS                                     \
+#define READARRAYS                                                     \
   for(i=0; i<numoidrdlockedarray; i++) {                               \
     objheader_t * transheader=oidrdlockedarray[i];                     \
     struct ArrayObject * transao=(struct ArrayObject *)&transheader[1];        \
@@ -616,7 +616,7 @@ int alttraverseCache() {
     void *objptr=curr->key;
     objheader_t *header=(objheader_t *)(((char *)objptr)-sizeof(objheader_t));
     unsigned int version = headeraddr->version;
-    
+
     PROCESSARRAY;
 
     if(STATUS(headeraddr) & DIRTY) {
@@ -903,7 +903,7 @@ void transCommitProcess(struct garbagelist * oidwrlocked, int numoidwrlocked) {
       int j;
       int addwrobject=0, addrdobject=0;
       int elementsize=classsize[type];
-      int baseoffset=((lowoffset*elementsize)&HIGHMASK)+sizeof(struct ArrayObject);
+      int baseoffset=(lowoffset<<INDEXSHIFT)+sizeof(int)+((int)&(((struct ArrayObject *)0)->___length___));
       char *dstptr=((char *)dst)+baseoffset;
       char *srcptr=((char *)src)+baseoffset;
       for(j=lowoffset; j<=highoffset;j++, srcptr+=INDEXLENGTH,dstptr+=INDEXLENGTH) {
index 38f73e7a6fde45c59927f21afecec5a0e95cfe6f..653945121a21f42fb701490f06b364d97307953c 100644 (file)
@@ -205,6 +205,10 @@ void *transRead(void * oid, void *gl) {
  void arraycopy(struct ArrayObject *oid, int byteindex) {
    struct ArrayObject * orig=(struct ArrayObject *) oid->___objlocation___;
    int baseoffset=byteindex&HIGHMASK;
+   unsigned int mainversion;
+   int baseindex=baseoffset>>INDEXSHIFT;
+   GETVERSIONVAL(mainversion, orig, baseindex);
+   SETVERSION(oid, baseindex, mainversion);
    A_memcpy(((char *)&oid[1])+baseoffset, ((char *)&orig[1])+baseoffset, INDEXLENGTH);
    if (oid->lowindex>baseoffset)
      oid->lowindex=baseoffset;
index 0f01de57a10a57c52cb656e6d6a745a5b38d6d13..f914431e6aae9e2b57973fa5a5c6a5686777a73a 100644 (file)
@@ -494,8 +494,14 @@ __attribute__((malloc)) struct ArrayObject * allocate_newarraytrans(void * ptr,
   int basesize=length*classsize[type];
   //round the base size up
   basesize=(basesize+LOWMASK)&HIGHMASK;
-  int bookkeepsize=(basesize>>INDEXSHIFT)*2*sizeof(int);
+  int numlocks=basesize>>INDEXSHIFT;
+  int bookkeepsize=numlocks*2*sizeof(int);
   struct ArrayObject * v=(struct ArrayObject *)transCreateObj(ptr, sizeof(struct ArrayObject)+basesize+bookkeepsize, bookkeepsize);
+  unsigned int *intptr=(unsigned int *)(((char *)v)-sizeof(objheader_t));
+  for(;numlocks>0;numlocks--) {
+    intptr-=2;
+    intptr[0]=1;
+  }
   v->highindex=-1;
   v->lowindex=MAXARRAYSIZE;
 #else
@@ -528,9 +534,14 @@ __attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int t
   int basesize=length*classsize[type];
   //round the base size up
   basesize=(basesize+LOWMASK)&HIGHMASK;
-  int bookkeepsize=(basesize>>INDEXSHIFT)*2*sizeof(int);
+  int numlocks=basesize>>INDEXSHIFT;
+  int bookkeepsize=(numlocks)*2*sizeof(int);
   int *tmpint=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+basesize+sizeof(objheader_t)+bookkeepsize);
-  objheader_t *tmp=(objheader_t *)(tmpint+bookkeepsize);
+  for(;numlocks>0;numlocks--) {
+    tmpint[0]=1;
+    tmpint+=2;
+  }
+  objheader_t *tmp=(objheader_t *)tmpint;
   struct ArrayObject * v=(struct ArrayObject *) &tmp[1];
   v->highindex=-1;
   v->lowindex=MAXARRAYSIZE;