From b81e786aaf30cea5d0b5437b77edb2320cb74702 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Thu, 15 Oct 2009 02:31:12 +0000 Subject: [PATCH] bug fixes --- Robust/src/Runtime/STM/array.h | 36 ++++++++++++++++++++------------- Robust/src/Runtime/STM/commit.c | 6 +++--- Robust/src/Runtime/STM/stm.c | 4 ++++ Robust/src/Runtime/runtime.c | 17 +++++++++++++--- 4 files changed, 43 insertions(+), 20 deletions(-) diff --git a/Robust/src/Runtime/STM/array.h b/Robust/src/Runtime/STM/array.h index 5024ed83..a4648e08 100644 --- a/Robust/src/Runtime/STM/array.h +++ b/Robust/src/Runtime/STM/array.h @@ -15,30 +15,36 @@ #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]; \ } @@ -46,11 +52,13 @@ #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 diff --git a/Robust/src/Runtime/STM/commit.c b/Robust/src/Runtime/STM/commit.c index e9dfe5ea..5cccde91 100644 --- a/Robust/src/Runtime/STM/commit.c +++ b/Robust/src/Runtime/STM/commit.c @@ -295,7 +295,7 @@ int transCommit() { } \ } else -#define READARRAYS \ +#define READARRAYS \ for(i=0; ikey; 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<___length___)); char *dstptr=((char *)dst)+baseoffset; char *srcptr=((char *)src)+baseoffset; for(j=lowoffset; j<=highoffset;j++, srcptr+=INDEXLENGTH,dstptr+=INDEXLENGTH) { diff --git a/Robust/src/Runtime/STM/stm.c b/Robust/src/Runtime/STM/stm.c index 38f73e7a..65394512 100644 --- a/Robust/src/Runtime/STM/stm.c +++ b/Robust/src/Runtime/STM/stm.c @@ -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; diff --git a/Robust/src/Runtime/runtime.c b/Robust/src/Runtime/runtime.c index 0f01de57..f914431e 100644 --- a/Robust/src/Runtime/runtime.c +++ b/Robust/src/Runtime/runtime.c @@ -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; -- 2.34.1