From 9676a663460b3a8b25b0c36e7f9d89d187224eb3 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Thu, 15 Oct 2009 01:11:32 +0000 Subject: [PATCH] bug fixes --- Robust/src/Runtime/STM/array.h | 10 +++++----- Robust/src/Runtime/STM/commit.c | 24 +++++++++++++----------- Robust/src/Runtime/STM/stm.c | 8 ++++---- 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/Robust/src/Runtime/STM/array.h b/Robust/src/Runtime/STM/array.h index b32e8990..5024ed83 100644 --- a/Robust/src/Runtime/STM/array.h +++ b/Robust/src/Runtime/STM/array.h @@ -15,11 +15,11 @@ #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; \ diff --git a/Robust/src/Runtime/STM/commit.c b/Robust/src/Runtime/STM/commit.c index bda2038f..e9dfe5ea 100644 --- a/Robust/src/Runtime/STM/commit.c +++ b/Robust/src/Runtime/STM/commit.c @@ -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); diff --git a/Robust/src/Runtime/STM/stm.c b/Robust/src/Runtime/STM/stm.c index ff577915..38f73e7a 100644 --- a/Robust/src/Runtime/STM/stm.c +++ b/Robust/src/Runtime/STM/stm.c @@ -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 { -- 2.34.1