big update for forwarding lists and dependency counts, stable compile but seg faults
[IRC.git] / Robust / src / Runtime / multicoregarbage.h
1 #ifndef MULTICORE_GARBAGE_H
2 #define MULTICORE_GARBAGE_H
3 #include "Queue.h"
4
5 // data structures for GC
6 #define BAMBOO_NUM_PAGES 1024 * 512
7 #define BAMBOO_PAGE_SIZE 4096
8 #define BAMBOO_SHARED_MEM_SIZE BAMBOO_PAGE_SIZE * BAMBOO_PAGE_SIZE
9 #define BAMBOO_BASE_VA 0xd000000
10 #define BAMBOO_SMEM_SIZE 16 * BAMBOO_PAGE_SIZE
11 #define BAMBOO_SMEM_SIZE_L 512 * BAMBOO_PAGE_SIZE
12 #define BAMBOO_LARGE_SMEM_BOUND BAMBOO_SMEM_SIZE_L * NUMCORES // NUMCORES = 62
13
14 struct markedObjItem {
15         INTPTR orig;
16         INTPTR dst;
17         struct markedObjItem * next;
18 };
19
20 struct largeObjItem {
21         INTPTR orig;
22         INTPTR dst;
23         int length;
24         struct largeObjItem * next;
25 };
26
27 struct moveObj {
28         INTPTR * starts;
29         INTPTR * ends;
30         INTPTR * dststarts;
31         int * dsts;
32         int length;
33 };
34
35 struct compactInstr {
36         struct moveObj * tomoveobjs;
37         struct moveObj * incomingobjs;
38         struct largeObjItem * largeobjs;
39 };
40
41 enum GCPHASETYPE {
42         MARKPHASE = 0x0,   // 0x0
43         COMPACTPHASE,      // 0x1
44         FLUSHPHASE,        // 0x2
45         FINISHPHASE        // 0x3
46 };
47
48 volatile bool gcflag;
49 GCPHASETYPE gcphase; // indicating GC phase
50 bool gctomove; // flag indicating if can start moving objects to other cores
51 struct Queue * gcdsts;
52 struct Queue gctomark; // global queue of objects to mark
53 // for mark phase termination
54 int gccorestatus[NUMCORES]; // records status of each core
55                            // 1: running gc
56                            // 0: stall
57 int gcnumsendobjs[NUMCORES]; // records how many objects a core has sent out
58 int gcnumreceiveobjs[NUMCORES]; // records how many objects a core has received
59 int gcnumconfirm;
60 bool gcwaitconfirm;
61 bool gcbusystatus;
62 int gcself_numsendobjs;
63 int gcself_numreceiveobjs;
64 // compact instruction
65 struct compactInstr * cinstruction;
66 // mapping of old address to new address
67 struct genhashtable * pointertbl;
68 int obj2map;
69 int mappedobj;
70 bool ismapped;
71
72 #define BLOCKNUM(p, b) \
73         if((p) < BAMBOO_LARGE_SMEM_BOUND) { \
74                 (*((int*)b)) = (p) / BAMBOO_SMEM_SIZE_L; \
75         } else { \
76                 (*((int*)b)) = NUMCORES + ((p) - BAMBOO_LARGE_SMEM_BOUND) / BAMBOO_SMEM_SIZE; \
77         }
78
79 #define RESIDECORE(p, x, y) \
80         int b; \
81         BLOCKNUM((p), &b); \
82         bool reverse = (b / NUMCORES) % 2; \
83         int l = b % NUMCORES; \
84         if(reverse) { \
85                 if(l < 16) { \
86                         l += 1; \
87                 } else { \
88                         l += 2; \
89                 } \
90                 (*((int*)y)) = 7 - l / 8; \
91         } else { \
92                 if(l > 54) { \
93                         l += 2; \
94                 } else if(l > 47) {\
95                         l += 1; \
96                 } \
97                 (*((int*)y)) = l / 8; \
98         } \
99         if((l/8)%2) { \
100                 (*((int*)x)) = 1 - l % 8; \
101         } else { \
102                 (*((int*)x)) = l % 8; \
103         }
104
105 void gc(); // core coordinator routine
106 void gc_collect(); // core collector routine
107 void transferMarkResults(); 
108
109 #endif
110