start of new file
[IRC.git] / Robust / src / Runtime / garbage.c
index 7ead1fb476bd599c01debd1da5339f8ee4b7d3d9..beb67c8613b1e8fbcf9a4dc3a6e03bb7139962ea 100644 (file)
@@ -12,7 +12,9 @@
 #ifdef DMALLOC
 #include "dmalloc.h"
 #endif
-
+#ifdef DSTM
+#include "dstm.h"
+#endif
 
 #define NUMPTRS 100
 
@@ -23,7 +25,9 @@
 
 #ifdef TASK
 extern struct genhashtable * activetasks;
+#ifndef MULTICORE
 extern struct parameterwrapper * objectqueues[NUMCLASSES];
+#endif
 extern struct genhashtable * failedtasks;
 extern struct taskparamdescriptor *currtpd;
 extern struct RuntimeHash *forward;
@@ -37,12 +41,11 @@ struct listitem * list=NULL;
 int listcount=0;
 #endif
 
+//Need to check if pointers are transaction pointers
 #ifdef DSTM
 #define ENQUEUE(orig, dst) \
 if ((!(((unsigned int)orig)&0x1))) {\
-if (orig>to_heapbase&&orig<to_heaptop) {\
-dst=NULL;\
-} else if (orig>curr_heapbase&&orig<curr_heaptop) {\
+if (orig>=curr_heapbase&&orig<curr_heaptop) {\
 void *copy;\
 if (gc_createcopy(orig,&copy))\
 enqueue(orig);\
@@ -187,6 +190,8 @@ void collect(struct garbagelist * stackptr) {
     /* Update objectsets */
     int i;
     for(i=0;i<NUMCLASSES;i++) {
+#ifdef MULTICORE
+#else
       struct parameterwrapper * p=objectqueues[i];
       while(p!=NULL) {
        struct ObjectHash * set=p->objectset;
@@ -199,6 +204,7 @@ void collect(struct garbagelist * stackptr) {
        ObjectHashrehash(set); /* Rehash the table */
        p=p->next;
       }
+#endif
     }
   }
   
@@ -288,10 +294,20 @@ void collect(struct garbagelist * stackptr) {
     if (pointer==0) {
       /* Array of primitives */
       /* Do nothing */
+#ifdef DSTM
+      struct ArrayObject *ao=(struct ArrayObject *) ptr;
+      struct ArrayObject *ao_cpy=(struct ArrayObject *) cpy;
+      ENQUEUE((void *)ao->___nextobject___, *((void **)&ao_cpy->___nextobject___));
+      ENQUEUE((void *)ao->___localcopy___, *((void **)&ao_cpy->___localcopy___));
+#endif
     } else if (((int)pointer)==1) {
       /* Array of pointers */
       struct ArrayObject *ao=(struct ArrayObject *) ptr;
       struct ArrayObject *ao_cpy=(struct ArrayObject *) cpy;
+#ifdef DSTM
+      ENQUEUE((void *)ao->___nextobject___, *((void **)&ao_cpy->___nextobject___));
+      ENQUEUE((void *)ao->___localcopy___, *((void **)&ao_cpy->___localcopy___));
+#endif
       int length=ao->___length___;
       int i;
       for(i=0;i<length;i++) {
@@ -352,6 +368,7 @@ void fixtags() {
        
        livecount=((livecount-1)/OBJECTARRAYINTERVAL+1)*OBJECTARRAYINTERVAL;
        aonew=(struct ArrayObject *) tomalloc(sizeof(struct ArrayObject)+sizeof(struct ___Object___*)*livecount);
+       memcpy(aonew, ao, sizeof(struct ArrayObject));
        aonew->type=OBJECTARRAYTYPE;
        aonew->___length___=livecount;
        copy->flagptr=aonew;
@@ -363,7 +380,9 @@ void fixtags() {
          }
        }
        aonew->___cachedCode___=k;
-       
+       for(;k<livecount;k++) {
+         ARRAYSET(aonew, struct ___Object___*, k, NULL);
+       }
       } else {
        /* No object live anymore */
        copy->flagptr=NULL;
@@ -385,7 +404,6 @@ void * tomalloc(int size) {
 }
 
 #if defined(THREADS)||defined(DSTM)
-
 void checkcollect(void * ptr) {
   if (needtocollect) {
     struct listitem * tmp=stopforgc((struct garbagelist *)ptr);
@@ -396,6 +414,20 @@ void checkcollect(void * ptr) {
   }
 }
 
+#ifdef DSTM
+void checkcollect2(void * ptr, transrecord_t *trans) {
+  if (needtocollect) {
+    int ptrarray[]={1, (int)ptr, (int) trans->revertlist};
+    struct listitem * tmp=stopforgc((struct garbagelist *)ptrarray);
+    pthread_mutex_lock(&gclock); // Wait for GC
+    restartaftergc(tmp);
+    pthread_mutex_unlock(&gclock);
+    trans->revertlist=(struct ___Object___*)ptrarray[2];
+  }
+}
+#endif
+
+
 struct listitem * stopforgc(struct garbagelist * ptr) {
   struct listitem * litem=malloc(sizeof(struct listitem));
   litem->stackptr=ptr;