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

index b32e89904fcc1c5ea2b8127a8fa70983987ad892..5024ed83056d11c3b72c6310033c12b3f48d4d34 100644 (file)
 #define MAXARRAYSIZE 2147483647
 
 #define GETLOCKPTR(lock, array, byteindex) {                           \
-    lock=(unsigned int *)((char *)array-sizeof(objheader_t)-sizeof(int)*2*(byteindex>>INDEXSHIFT)); \
+    lock=(unsigned int *)((char *)array-sizeof(objheader_t)-sizeof(int)*2*(byteindex>>INDEXSHIFT)-2*sizeof(int)); \
   }
 
 #define GETLOCKVAL(lock, array, byteindex) {                           \
-    lock=*(unsigned int *)((char *)array-sizeof(objheader_t)-sizeof(int)*2*(byteindex>>INDEXSHIFT)); \
+    lock=*(unsigned int *)((char *)array-sizeof(objheader_t)-sizeof(int)*2*(byteindex>>INDEXSHIFT)-2*sizeof(int)); \
   }
 
 #define GETVERSIONVAL(version, array, byteindex) {                     \
@@ -36,7 +36,7 @@
     int *status;                                                       \
     if (array!=array->___objlocation___) {                             \
       GETLOCKPTR(status, array, byteindex);                            \
-      if ((*status)==STMNONE) {                                                \
+      if ((*status)==STMNONE&&!(array->___objstatus___&NEW)) {         \
        arraycopy(array, byteindex);                                    \
        *status=STMCLEAN;};                                             \
     }                                                                  \
@@ -47,8 +47,8 @@
     int byteindex=index*sizeof(type);                                  \
     int * lengthoff=&array->___length___;                              \
     int *status;                                                       \
-    GETLOCKPTR(status, array);                                         \
-    if (*status==STMNONE)                                              \
+    GETLOCKPTR(status, array, byteindex);                              \
+    if (*status==STMNONE&&!(array->___objstatus___&NEW))               \
       arraycopy(array, byteindex, sizeof(type)*(*lengthoff));          \
     *status=STMDIRTY;                                                  \
     ((type *)(((char *) lengthoff)+sizeof(int)))[index]=src;           \
index bda2038f0aa0dfd8ce2e8ae58a2415ba59900830..e9dfe5ea429e69dc2fa317f9d40324d8ba7bd80e 100644 (file)
@@ -264,7 +264,7 @@ int transCommit() {
     int j;                                                             \
     int addwrobject=0, addrdobject=0;                                  \
     for(j=lowoffset; j<=highoffset;j++) {                              \
-      int status;                                                      \
+      unsigned int status;                                             \
       GETLOCKVAL(status, transao, j);                                  \
       if (status==STMDIRTY) {                                          \
        unsigned int * lockptr;                                         \
@@ -305,10 +305,10 @@ int transCommit() {
     int highoffset=(transao->highindex)>>INDEXSHIFT;                   \
     int j;                                                             \
     for(j=lowoffset; j<=highoffset;j++) {                              \
-      int locallock;GETLOCKVAL(locallock,transao,j);                   \
+      unsigned int locallock;GETLOCKVAL(locallock,transao,j);          \
       if (locallock==STMCLEAN) {                                       \
        /* do read check */                                             \
-       int mainlock; GETLOCKVAL(mainlock, mainao, j);                  \
+       unsigned int mainlock; GETLOCKVAL(mainlock, mainao, j);         \
        if (mainlock>0) {                                               \
          CFENCE;                                                       \
          unsigned int localversion;                                    \
@@ -833,10 +833,10 @@ void transAbortProcess(struct garbagelist *oidwrlocked, int numoidwrlocked) {
       int j;
       int addwrobject=0, addrdobject=0;
       for(j=lowoffset; j<=highoffset;j++) {
-       int status;
+       unsigned int status;
        GETLOCKVAL(status, src, j);
        if (status==STMDIRTY) {
-         int *lockptr;
+         unsigned int *lockptr;
          GETLOCKPTR(lockptr, ((struct ArrayObject *)dst), j);
          write_unlock(lockptr);
        }
@@ -903,12 +903,14 @@ void transCommitProcess(struct garbagelist * oidwrlocked, int numoidwrlocked) {
       int j;
       int addwrobject=0, addrdobject=0;
       int elementsize=classsize[type];
-      int baseoffset=(lowoffset*elementsize)&HIGHMASK;
-      for(j=lowoffset; j<=highoffset;j++, baseoffset+=elementsize) {
-       int status;
+      int baseoffset=((lowoffset*elementsize)&HIGHMASK)+sizeof(struct ArrayObject);
+      char *dstptr=((char *)dst)+baseoffset;
+      char *srcptr=((char *)src)+baseoffset;
+      for(j=lowoffset; j<=highoffset;j++, srcptr+=INDEXLENGTH,dstptr+=INDEXLENGTH) {
+       unsigned int status;
        GETLOCKVAL(status, ((struct ArrayObject *)src), j);
        if (status==STMDIRTY) {
-         A_memcpy(((char *)&oid[1])+baseoffset, ((char *)&orig[1])+baseoffset, INDEXLENGTH);
+         A_memcpy(dstptr, srcptr, INDEXLENGTH);
        }
       }
     } else
@@ -944,10 +946,10 @@ void transCommitProcess(struct garbagelist * oidwrlocked, int numoidwrlocked) {
       int j;
       int addwrobject=0, addrdobject=0;
       for(j=lowoffset; j<=highoffset;j++) {
-       int status;
+       unsigned int status;
        GETLOCKVAL(status, src, j);
        if (status==STMDIRTY) {
-         int *ptr;
+         unsigned int *intptr;
          GETVERSIONPTR(intptr, ((struct ArrayObject *)dst), j);
          (*intptr)++;
          GETLOCKPTR(intptr, ((struct ArrayObject *)dst), j);
index ff5779156d036eaa29b4b5614fcb713e14b991f9..38f73e7a6fde45c59927f21afecec5a0e95cfe6f 100644 (file)
@@ -91,8 +91,8 @@ void transStart() {
  */
 #ifdef STMARRAY
 objheader_t *transCreateObj(void * ptr, unsigned int size, int bytelength) {
-  int *tmpint = mygcmalloc(ptr, (sizeof(objheader_t) + size));
-  objheader_t *tmp = (objheader_t *) (tmpint+bytelength);
+  char *tmpchar = mygcmalloc(ptr, (sizeof(objheader_t) + size));
+  objheader_t *tmp = (objheader_t *) (tmpchar+bytelength);
 #else
 objheader_t *transCreateObj(void * ptr, unsigned int size) {
   objheader_t *tmp = mygcmalloc(ptr, (sizeof(objheader_t) + size));
@@ -170,9 +170,9 @@ void *transRead(void * oid, void *gl) {
     int basesize=((struct ArrayObject *)oid)->___length___*classsize[type];
     basesize=(basesize+LOWMASK)&HIGHMASK;
     int metasize=sizeof(int)*2*(basesize>>INDEXSHIFT);
-    size = basesize + sizeof(objheader_t)+metasize;
+    size = basesize + sizeof(objheader_t)+metasize+sizeof(struct ArrayObject);
     char *tmpptr = (char *) objstrAlloc(size);
-    bzero(objcopy, metasize);//clear out stm data
+    bzero(tmpptr, metasize);//clear out stm data
     objcopy=(objheader_t *) (tmpptr+metasize);
     A_memcpy(objcopy, header, sizeof(objheader_t)+sizeof(struct ArrayObject)); //copy the metadata and base array info
   } else {