007466f52788438159b721ac1bb00f7dd43f0195
[IRC.git] / Robust / src / Runtime / bamboo / pmc_forward.c
1 #include "pmc_forward.h"
2
3
4 //Comment: should build dummy byte arrays to allow skipping data...
5 void pmc_countbytes(struct pmc_region * region, void *bottomptr, void *topptr) {
6   void *tmpptr=bottomptr;
7   unsigned int totalbytes=0;
8   while(tmpptr<topptr) {
9     unsigned int type;
10     unsigned int size;
11     gettype_size(tmpptr, &type, &size);
12     if (!type) {
13       tmpptr+=ALIGNMENTSIZE;
14       continue;
15     }
16     size=((size-1)&(~(ALIGNMENTSIZE-1)))+ALIGNMENTSIZE;
17     if (((struct ___Object___ *)tmpptr)->mark)
18       totalbytes+=size;
19     tmpptr+=size;
20   }
21   region->numbytes=totalbytes;
22 }
23
24
25 void pmc_forward(struct pmc_region *region, unsigned int totalbytes, void *bottomptr, void *topptr, bool fwddirection) {
26   void *tmpptr=bottomptr;
27   void *forwardptr=fwddirection?bottomptr:(topptr-totalbytes);
28   struct ___Object___ *lastobj=NULL;
29
30   while(tmpptr>topptr) {
31     unsigned int type;
32     unsigned int size;
33     gettype_size(tmpptr, &type, &size);
34     if (!type) {
35       tmpptr+=ALIGNMENTSIZE;
36       continue;
37     }
38     size=((size-1)&(~(ALIGNMENTSIZE-1)))+ALIGNMENTSIZE;
39
40     if (((struct ___Object___ *)tmpptr)->mark) {
41       ((struct ___Object___ *)tmpptr)->mark=forwardptr;
42       forwardptr+=size;
43       if (lastobj&&!fwddirection) {
44         tmpptr->backward=lastobj;
45         lastobj=(struct ___Object___ *)tmpptr;
46       }
47     }
48     tmpptr+=size;
49   }
50   region->lastobj=lastobj;
51 }