bug fixes checked in
[IRC.git] / Robust / src / Runtime / checkpoint.c
index e1ceaa6b94a8fd964e3cbf99bca5e7380031dda0..64373652fac82c3c5820ad274d0ac8ecd8eb3cd4 100644 (file)
@@ -2,6 +2,9 @@
 #include "runtime.h"
 #include "structdefs.h"
 #include <string.h>
+#ifdef DMALLOC
+#include "dmalloc.h"
+#endif
 
 #define MALLOCSIZE 20*1024
 
@@ -68,7 +71,19 @@ void ** makecheckpoint(int numparams, void ** srcpointer, struct RuntimeHash * f
     {
       void *cpy;
       RuntimeHashget(forward, (int) ptr, (int *) &cpy);
-      int * pointer=pointerarray[type];
+      unsigned int * pointer=pointerarray[type];
+#ifdef TASK
+      if (type==TAGTYPE) {
+       void *objptr=((struct ___TagDescriptor___*)ptr)->flagptr;
+       if (objptr!=NULL) {
+         void * copy=createcopy(objptr);
+         RuntimeHashadd(forward, (int) objptr, (int) copy);
+         RuntimeHashadd(reverse, (int) copy, (int) objptr);
+         RuntimeHashadd(todo, (int) objptr, (int) objptr);
+         ((struct ___TagDescriptor___*)cpy)->flagptr=copy;
+       }
+      } else
+#endif
       if (pointer==0) {
        /* Array of primitives */
        /* Do nothing */
@@ -113,6 +128,7 @@ void ** makecheckpoint(int numparams, void ** srcpointer, struct RuntimeHash * f
       }
     }
   }
+  freeRuntimeHash(todo);
   return newarray;
 }
 
@@ -150,24 +166,41 @@ void * createcopy(void * orig) {
 
 void restorecheckpoint(int numparams, void ** original, void ** checkpoint, struct RuntimeHash *forward, struct RuntimeHash * reverse) {
   struct RuntimeHash *todo=allocateRuntimeHash(100);
+  struct RuntimeHash *visited=allocateRuntimeHash(100);
   int i;
 
   for(i=0;i<numparams;i++) {
-    RuntimeHashadd(todo, (int) checkpoint[i], (int) checkpoint[i]);
+    if (checkpoint[i]!=NULL) {
+      RuntimeHashadd(todo, (int) checkpoint[i], (int) checkpoint[i]);
+      RuntimeHashadd(visited, (int) checkpoint[i], (int) checkpoint[i]);
+    }
   }
-
+  
   while(RuntimeHashcountset(todo)!=0) {
     void * ptr=(void *) RuntimeHashfirstkey(todo);
     int type=((int *)ptr)[0];
     RuntimeHashremove(todo, (int) ptr, (int) ptr);
+
     {
       void *cpy;
-      int *pointer;
+      unsigned int *pointer;
       int size;
       RuntimeHashget(reverse, (int) ptr, (int *) &cpy);
       pointer=pointerarray[type];
       size=classsize[type];
-
+#ifdef TASK
+      if (type==TAGTYPE) {
+       void *objptr=((struct ___TagDescriptor___*)ptr)->flagptr;
+       memcpy(cpy, ptr, size);
+       if (objptr!=NULL) {
+         if (!RuntimeHashcontainskey(visited, (int) objptr)) {
+           RuntimeHashadd(visited, (int) objptr, (int) objptr);
+           RuntimeHashadd(todo, (int) objptr, (int) objptr);
+         }
+         RuntimeHashget(reverse, (int) objptr, (int *) & (((struct ___TagDescriptor___ *)cpy)->flagptr));
+       }
+      } else
+#endif
       if (pointer==0) {
        /* Array of primitives */
        struct ArrayObject *ao=(struct ArrayObject *) ptr;
@@ -188,8 +221,13 @@ void restorecheckpoint(int numparams, void ** original, void ** checkpoint, stru
          void *objptr=((void **)(((char *)& ao->___length___)+sizeof(int)))[i];
          if (objptr==NULL)
            ((void **)(((char *)& ao_cpy->___length___)+sizeof(int)))[i]=NULL;
-         else
+         else {
+           if (!RuntimeHashcontainskey(visited, (int) objptr)) {
+             RuntimeHashadd(visited, (int) objptr, (int) objptr);
+             RuntimeHashadd(todo, (int) objptr, (int) objptr);
+           }
            RuntimeHashget(reverse, (int) objptr, (int *) &((void **)(((char *)& ao_cpy->___length___)+sizeof(int)))[i]);
+         }
        }
       } else {
        int numptr=pointer[0];
@@ -204,14 +242,21 @@ void restorecheckpoint(int numparams, void ** original, void ** checkpoint, stru
          void * objptr=*((void **)(((int)ptr)+offset));
          if (objptr==NULL)
            *((void **) (((int)cpy)+offset))=NULL;
-         else
+         else {
+           if (!RuntimeHashcontainskey(visited, (int) objptr)) {
+             RuntimeHashadd(visited, (int) objptr, (int) objptr);
+             RuntimeHashadd(todo, (int) objptr, (int) objptr);
+           }
            RuntimeHashget(reverse, (int) objptr, (int *) &(((char *)cpy)[offset]));
+         }
        }
        if (hasflags[type]) {
          (((void **)cpy)[2])=flagptr;
-         flagorand(cpy, 1, 0xFFFFFFFF);
+         flagorandinit(cpy, 0, 0xFFFFFFFF);
        }
       }
     }
   }
+  freeRuntimeHash(todo);
+  freeRuntimeHash(visited);
 }