change
[IRC.git] / Robust / src / Runtime / STM / stm.c
index fb5b6c6631d8848c1b9ba274d08a09ef42743bad..76e6ac7206b330fc22e60da9fd7e4bb6d9cbb3ff 100644 (file)
@@ -13,7 +13,6 @@
 #include "tm.h"
 #include "garbage.h"
 
-#define likely(x) x
 /* Per thread transaction variables */
 __thread objstr_t *t_cache;
 __thread objstr_t *t_reserve;
@@ -90,9 +89,15 @@ void transStart() {
  * This function creates objects in the transaction record
  * =======================================================
  */
+#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);
+#else
 objheader_t *transCreateObj(void * ptr, unsigned int size) {
   objheader_t *tmp = mygcmalloc(ptr, (sizeof(objheader_t) + size));
-  objheader_t *retval=&tmp[1];
+#endif
+  objheader_t *retval=tmp+1;
   tmp->lock=RW_LOCK_BIAS;
   tmp->version = 1;
   //initialize obj lock to the header
@@ -130,31 +135,63 @@ void randomdelay(int softaborted) {
  * -copies the object into the transaction cache
  * =============================================================
  */
+
+//void *TR(void *x, void * y, void *z) {
+//  void * inputvalue;                         
+//  if ((inputvalue=y)==NULL) x=NULL;          
+//  else {
+//    chashlistnode_t * cnodetmp=&c_table[(((unsigned INTPTR)inputvalue)&c_mask)>>4]; 
+//    do { 
+//      if (cnodetmp->key==inputvalue) {x=cnodetmp->val; break;} 
+//      cnodetmp=cnodetmp->next; 
+//      if (cnodetmp==NULL) {if (((struct ___Object___*)inputvalue)->___objstatus___&NEW) {x=inputvalue; break;} else
+//                          {x=transRead(inputvalue,z); asm volatile ("" : "=m" (c_table),"\=m" (c_mask)); break;}}
+//    } while(1);
+//  }
+//  return x;
+//}
+
 //__attribute__ ((pure)) 
 void *transRead(void * oid, void *gl) {
   objheader_t *tmp, *objheader;
   objheader_t *objcopy;
   int size;
 
-  /* Read from the main heap */
-  //No lock for now
   objheader_t *header = (objheader_t *)(((char *)oid) - sizeof(objheader_t));
-  GETSIZE(size, header);
-  size += sizeof(objheader_t);
-  objcopy = (objheader_t *) objstrAlloc(size);
 #ifdef STMSTATS
   header->accessCount++;
   if(header->riskyflag) {
     header=needLock(header,gl);
   }
 #endif
+#ifdef STMARRAY
+  int type=TYPE(header);
+  if (type>=NUMCLASSES) {
+    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;
+    char *tmpptr = (char *) objstrAlloc(size);
+    bzero(objcopy, 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 {
+    GETSIZE(size, header);
+    size += sizeof(objheader_t);
+    objcopy = (objheader_t *) objstrAlloc(size);
+    A_memcpy(objcopy, header, size);
+  }
+#else
+  GETSIZE(size, header);
+  size += sizeof(objheader_t);
+  objcopy = (objheader_t *) objstrAlloc(size);
   A_memcpy(objcopy, header, size);
+#endif
 #ifdef STMSTATS
   /* keep track of the object's access sequence in a transaction */
   objheader_t *tmpheader = objcopy;
   tmpheader->accessCount = ++t_objnumcount;
 #endif
-
   /* Insert into cache's lookup table */
   STATUS(objcopy)=0;
   if (((unsigned INTPTR)oid)<((unsigned INTPTR ) curr_heapbase)|| ((unsigned INTPTR)oid) >((unsigned INTPTR) curr_heapptr))
@@ -163,6 +200,19 @@ void *transRead(void * oid, void *gl) {
   return &objcopy[1];
 }
 
+#ifdef STMARRAY
+//caller needs to mark data as present
+ void arraycopy(struct ArrayObject *oid, int byteindex) {
+   struct ArrayObject * orig=oid->___objlocation___;
+   int baseoffset=byteindex&HIGHMASK;
+   A_memcpy(((char *)&oid[1])+baseoffset, ((char *)&orig[1])+baseoffset, INDEXLENGTH);
+   if (oid->lowoffset>baseoffset)
+     oid->lowoffset=baseoffset;
+   if (oid->highoffset<baseoffset)
+     oid->highoffset=baseoffset;
+ }
+#endif
+
 void freenewobjs() {
   struct objlist *ptr=newobjs;
   while(ptr->next!=NULL) {