0fdf0fd127c5455c3ccff40252cb3725c2c663bc
[IRC.git] / Robust / src / Runtime / DSTM / interface / localobjects.c
1 #include "localobjects.h"
2 #include <string.h>
3
4 void REVERT_OBJ(struct ___Object___ * obj) {
5   int type=((int *)obj)[0];
6   struct ___Object___ * copyobj=obj->___localcopy___;
7   if (type<NUMCLASSES) {
8     /* We have a normal object */
9     int size=classsize[type];
10     memcpy(obj, copyobj, size);
11   } else {
12     /* We have an array */
13     struct ArrayObject *ao=(struct ArrayObject *)obj;
14     int elementsize=classsize[type];
15     int length=ao->___length___;
16     int size=sizeof(struct ArrayObject)+length*elementsize;
17     memcpy(obj, copyobj, size);
18   }
19 }
20
21 #ifdef PRECISE_GC
22 void COPY_OBJ(struct garbagelist * gl, struct ___Object___ *obj) {
23 #else
24 void COPY_OBJ(struct ___Object___ *obj) {
25 #endif
26   int type=((int *)obj)[0];
27   if (type<NUMCLASSES) {
28     /* We have a normal object */
29     int size=classsize[type];
30 #ifdef PRECISE_GC
31     int ptrarray[]={1, (int) gl, (int) obj};
32     struct ___Object___ * newobj=mygcmalloc((struct garbagelist *)ptrarray, size);
33 #else
34     struct ___Object___ * newobj=FREEMALLOC(size);
35 #endif
36     memcpy(newobj, (struct ___Object___ *) ptrarray[2], size);
37     ((struct ___Object___*)ptrarray[2])->___localcopy___=newobj;
38   } else {
39     /* We have an array */
40     struct ArrayObject *ao=(struct ArrayObject *)obj;
41     int elementsize=classsize[type];
42     int length=ao->___length___;
43     int size=sizeof(struct ArrayObject)+length*elementsize;
44 #ifdef PRECISE_GC
45     int ptrarray[]={1, (int) gl, (int) obj};
46     struct ___Object___ * newobj=mygcmalloc((struct garbagelist *)ptrarray, size);
47 #else
48     struct ___Object___ * newobj=FREEMALLOC(size);
49 #endif
50     memcpy(newobj, (struct ___Object___ *) ptrarray[2], size);
51     ((struct ___Object___*)ptrarray[2])->___localcopy___=newobj;
52   }
53 }