start of new file
[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 #ifdef PRECISE_GC
37     memcpy(newobj, (struct ___Object___ *) ptrarray[2], size);
38     ((struct ___Object___*)ptrarray[2])->___localcopy___=newobj;
39 #else
40     memcpy(newobj, obj, size);
41     obj->___localcopy___=newobj;
42 #endif
43   } else {
44     /* We have an array */
45     struct ArrayObject *ao=(struct ArrayObject *)obj;
46     int elementsize=classsize[type];
47     int length=ao->___length___;
48     int size=sizeof(struct ArrayObject)+length*elementsize;
49 #ifdef PRECISE_GC
50     int ptrarray[]={1, (int) gl, (int) obj};
51     struct ___Object___ * newobj=mygcmalloc((struct garbagelist *)ptrarray, size);
52 #else
53     struct ___Object___ * newobj=FREEMALLOC(size);
54 #endif
55 #ifdef PRECISE_GC
56     memcpy(newobj, (struct ___Object___ *) ptrarray[2], size);
57     ((struct ___Object___*)ptrarray[2])->___localcopy___=newobj;
58 #else
59     memcpy(newobj, obj, size);
60     obj->___localcopy___=newobj;
61 #endif
62   }
63 }