number of changes
authorbdemsky <bdemsky>
Mon, 6 Apr 2009 23:19:48 +0000 (23:19 +0000)
committerbdemsky <bdemsky>
Mon, 6 Apr 2009 23:19:48 +0000 (23:19 +0000)
Robust/src/Runtime/STM/stm.c
Robust/src/Runtime/STM/tm.h
Robust/src/Runtime/runtime.c
Robust/src/Runtime/runtime.h

index ae19d71181fbe95172bc0b1a4d13fa20cca9a137..3bb57420472fadacab1668412eb4af1c52663516 100644 (file)
@@ -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);
index 65a2afeb3c3e195ac36ccc47013fdeadd1b3838b..ae866701f18bf92eaa6dc17f79b9749165b2e6f5 100644 (file)
@@ -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);
index 665eaf2dc58ed8397b495502553d2fc61c49e862..1258c78107ffbebe7d382c5d05f5fe36a79253dd 100644 (file)
@@ -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 */
index fa1afc2db4014f96be5d6cf2e7aa38544022c98c..2ca7d2a7c220ca048539f01a34efec1c8a3a9dd5 100644 (file)
@@ -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);