From 7d0faf8b8e82d9d35de9c9e1bc540dd3f614b292 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Mon, 6 Apr 2009 23:19:48 +0000 Subject: [PATCH] number of changes --- Robust/src/Runtime/STM/stm.c | 32 ++++++++-------------- Robust/src/Runtime/STM/tm.h | 2 +- Robust/src/Runtime/runtime.c | 53 +++++++++++++++++++++++++++++++++++- Robust/src/Runtime/runtime.h | 5 ++++ 4 files changed, 70 insertions(+), 22 deletions(-) diff --git a/Robust/src/Runtime/STM/stm.c b/Robust/src/Runtime/STM/stm.c index ae19d711..3bb57420 100644 --- a/Robust/src/Runtime/STM/stm.c +++ b/Robust/src/Runtime/STM/stm.c @@ -11,6 +11,7 @@ */ #include "tm.h" +#include "garbage.h" /* Thread transaction variables */ __thread objstr_t *t_cache; @@ -68,18 +69,13 @@ void transStart() { * This function creates objects in the transaction record * ======================================================= */ -objheader_t *transCreateObj(unsigned int size) { - objheader_t *tmp = (objheader_t *) objstrAlloc(&t_cache, (sizeof(objheader_t) + size)); - OID(tmp) = getNewOID(); +objheader_t *transCreateObj(void * ptr, unsigned int size) { + objheader_t *tmp = mygcmalloc(ptr, (sizeof(objheader_t) + size)); + objheader_t *retval=&tmp[1]; tmp->version = 1; - STATUS(tmp) = NEW; - t_chashInsert(OID(tmp), tmp); + t_chashInsert((unsigned int) retval, retval); -#ifdef COMPILER - return &tmp[1]; //want space after object header -#else - return tmp; -#endif + return retval; //want space after object header } /* This functions inserts randowm wait delays in the order of msec @@ -143,7 +139,7 @@ __attribute__((pure)) objheader_t *transRead(unsigned int oid) { int size; /* Read from the main heap */ - objheader_t *header = (objheader_t *)(((char *)(&oid)) - sizeof(objheader_t)); + objheader_t *header = (objheader_t *)(((char *)oid) - sizeof(objheader_t)); if(read_trylock(STATUSPTR(header))) { //Can further acquire read locks GETSIZE(size, header); size += sizeof(objheader_t); @@ -152,11 +148,7 @@ __attribute__((pure)) objheader_t *transRead(unsigned int oid) { /* Insert into cache's lookup table */ STATUS(objcopy)=0; t_chashInsert(OID(header), objcopy); -#ifdef COMPILER return &objcopy[1]; -#else - return objcopy; -#endif } read_unlock(STATUSPTR(header)); } @@ -169,7 +161,7 @@ __attribute__((pure)) objheader_t *transRead(unsigned int oid) { * ================================================================ */ int transCommit() { - char finalResponse; + int finalResponse; char treplyretry; /* keeps track of the common response that needs to be sent */ do { @@ -186,7 +178,7 @@ int transCommit() { if(treplyretry && (finalResponse == TRANS_SOFT_ABORT)) { randomdelay(); } - if(finalResponse != TRANS_ABORT || finalResponse != TRANS_COMMIT || finalResponse != TRANS_SOFT_ABORT) { + if(finalResponse != TRANS_ABORT && finalResponse != TRANS_COMMIT && finalResponse != TRANS_SOFT_ABORT) { printf("Error: in %s() Unknown outcome", __func__); exit(-1); } @@ -217,7 +209,7 @@ int transCommit() { * - decides if a transaction should commit or abort * ================================================== */ -char traverseCache(char *treplyretry) { +int traverseCache(char *treplyretry) { /* Create info for newly creately objects */ int numcreated=0; unsigned int oidcreated[c_numelements]; @@ -232,7 +224,7 @@ char traverseCache(char *treplyretry) { int vnomatch; int numoidread; int numoidmod; - char response; + int response; int i; chashlistnode_t *ptr = c_table; @@ -276,7 +268,7 @@ char traverseCache(char *treplyretry) { * - updates the oids locked and oids newly created * =========================================================================== */ -char decideResponse(objheader_t *headeraddr, unsigned int *oidcreated, int *numcreated, unsigned int* oidrdlocked, int *numoidrdlocked, +int decideResponse(objheader_t *headeraddr, unsigned int *oidcreated, int *numcreated, unsigned int* oidrdlocked, int *numoidrdlocked, unsigned int*oidwrlocked, int *numoidwrlocked, int *vmatch_lock, int *vmatch_nolock, int *vnomatch, int *numoidmod, int *numoidread) { unsigned short version = headeraddr->version; unsigned int oid = OID(headeraddr); diff --git a/Robust/src/Runtime/STM/tm.h b/Robust/src/Runtime/STM/tm.h index 65a2afeb..ae866701 100644 --- a/Robust/src/Runtime/STM/tm.h +++ b/Robust/src/Runtime/STM/tm.h @@ -122,7 +122,7 @@ int stmStartup(); void objstrDelete(objstr_t *store); objstr_t *objstrCreate(unsigned int size); void transStart(); -objheader_t *transCreateObj(unsigned int size); +objheader_t *transCreateObj(void * ptr, unsigned int size); unsigned int getNewOID(void); void *objstrAlloc(objstr_t **osptr, unsigned int size); __attribute__((pure)) objheader_t *transRead(unsigned int oid); diff --git a/Robust/src/Runtime/runtime.c b/Robust/src/Runtime/runtime.c index 665eaf2d..1258c781 100644 --- a/Robust/src/Runtime/runtime.c +++ b/Robust/src/Runtime/runtime.c @@ -11,6 +11,9 @@ #include "prelookup.h" #include "prefetch.h" #endif +#ifdef STM +#include "tm.h" +#endif extern int classsize[]; extern int typearray[]; @@ -192,7 +195,54 @@ __attribute__((malloc)) struct ArrayObject * allocate_newarrayglobal(int type, i #endif -#ifdef PRECISE_GC +#ifdef STM +// STM Versions of allocation functions + +/* Object allocation function */ +__attribute__((malloc)) void * allocate_newtrans(void * ptr, int type) { + struct ___Object___ * v=(struct ___Object___ *) transCreateObj(ptr, classsize[type]); + v->type=type; + return v; +} + +/* Array allocation function */ + +__attribute__((malloc)) struct ArrayObject * allocate_newarraytrans(void * ptr, int type, int length) { + struct ArrayObject * v=(struct ArrayObject *)transCreateObj(ptr, sizeof(struct ArrayObject)+length*classsize[type]); + if (length<0) { + printf("ERROR: negative array\n"); + return NULL; + } + v->type=type; + v->___length___=length; + return v; +} +__attribute__((malloc)) void * allocate_new(void * ptr, int type) { + objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, classsize[type]+sizeof(objheader_t)); + struct ___Object___ * v=(struct ___Object___ *) &tmp[1]; + tmp->version = 1; + v->type = type; + return v; +} + +/* Array allocation function */ + +__attribute__((malloc)) struct ArrayObject * allocate_newarray(void * ptr, int type, int length) { + objheader_t *tmp=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]+sizeof(objheader_t)); + struct ArrayObject * v=(struct ArrayObject *) &tmp[1]; + tmp->version=1; + v->type=type; + if (length<0) { + printf("ERROR: negative array\n"); + return NULL; + } + v->___length___=length; + return v; +} +#endif + +#ifndef STM +#if defined(PRECISE_GC) __attribute__((malloc)) void * allocate_new(void * ptr, int type) { struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]); v->type=type; @@ -250,6 +300,7 @@ __attribute__((malloc)) struct ArrayObject * allocate_newarray(int type, int len return v; } #endif +#endif /* Converts C character arrays into Java strings */ diff --git a/Robust/src/Runtime/runtime.h b/Robust/src/Runtime/runtime.h index fa1afc2d..2ca7d2a7 100644 --- a/Robust/src/Runtime/runtime.h +++ b/Robust/src/Runtime/runtime.h @@ -31,6 +31,11 @@ __attribute__((malloc)) void * allocate_newglobal(int type); __attribute__((malloc)) struct ArrayObject * allocate_newarrayglobal(int type, int length); #endif +#ifdef STM +__attribute__((malloc)) void * allocate_newtrans(void * ptr, int type); +__attribute__((malloc)) struct ArrayObject * allocate_newarraytrans(void * ptr, int type, int length); +#endif + #ifdef PRECISE_GC #include "garbage.h" __attribute__((malloc)) void * allocate_new(void *, int type); -- 2.34.1