1 #ifndef MULTICORE_GARBAGE_H
2 #define MULTICORE_GARBAGE_H
3 #include "multicoregc.h"
4 #include "structdefs.h"
10 // data structures for GC
12 #define BAMBOO_SMEM_SIZE_L (BAMBOO_SMEM_SIZE)
14 #define BAMBOO_SMEM_SIZE_L (32 * BAMBOO_SMEM_SIZE)
16 #define BAMBOO_LARGE_SMEM_BOUND (BAMBOO_SMEM_SIZE_L*NUMCORES) // NUMCORES=62
21 INITPHASE = 0x0, // 0x0
24 SUBTLECOMPACTPHASE,// 0x3
30 volatile bool gcprocessing;
31 volatile GCPHASETYPE gcphase; // indicating GC phase
34 // for mark phase termination
35 int gccorestatus[NUMCORES]; // records status of each core
38 int gcnumsendobjs[NUMCORES]; // records how many objects sent out
39 int gcnumreceiveobjs[NUMCORES]; // records how many objects received
41 int gcself_numsendobjs;
42 int gcself_numreceiveobjs;
46 int gcloads[NUMCORES];
47 int gctopcore; // the core host the top of the heap
48 bool gcheapdirection; // 0: decrease; 1: increase
52 // compact instruction
53 INTPTR gcmarkedptrbound;
55 int gcstopblock[NUMCORES]; // indicate when to stop compact phase
56 int gcfilledblocks[NUMCORES]; //indicate how many blocks have been fulfilled
58 INTPTR gcmovestartaddr;
60 volatile bool gctomove;
61 int gcrequiredmems[NUMCORES]; //record pending mem requests
62 volatile int gcmovepending;
64 // mapping of old address to new address
65 struct RuntimeHash * gcpointertbl;
68 volatile bool gcismapped;
70 // table recording the starting address of each small block
71 // (size is BAMBOO_SMEM_SIZE)
72 // Note: 1. this table always resides on the very bottom of the shared memory
73 // 2. the first two blocks are reserved for this table, would never be
74 // moved or garbage collected.
75 INTPTR * gcsbstarttbl;
76 int gcreservedsb; // number of reserved sblock for sbstarttbl
77 int gcbaseva; // base va for shared memory without reserved sblocks
79 #define ISSHAREDOBJ(p) \
80 (((p)>gcbaseva)&&((p)<(gcbaseva+(BAMBOO_SHARED_MEM_SIZE))))
82 #define ALIGNSIZE(s, as) \
83 (*((int*)as)) = (((s) & (~(BAMBOO_CACHE_LINE_MASK))) + (BAMBOO_CACHE_LINE_SIZE))
85 #define BLOCKINDEX(p, b) \
87 int t = (p) - gcbaseva; \
88 if(t < (BAMBOO_LARGE_SMEM_BOUND)) { \
89 (*((int*)b)) = t / (BAMBOO_SMEM_SIZE_L); \
91 (*((int*)b)) = NUMCORES+((t-(BAMBOO_LARGE_SMEM_BOUND))/(BAMBOO_SMEM_SIZE));\
95 #define RESIDECORE(p, x, y) \
97 if(1 == (NUMCORES)) { \
102 BLOCKINDEX((p), &b); \
103 bool reverse = (b / (NUMCORES)) % 2; \
104 int l = b % (NUMCORES); \
106 if(62 == (NUMCORES)) { \
113 (*((int*)y)) = bamboo_height - 1 - (l / bamboo_width); \
115 if(62 == (NUMCORES)) {\
120 (*((int*)y)) = l / bamboo_width; \
122 if(((!reverse)&&(*((int*)y))%2) || ((reverse)&&((*((int*)y))%2==0))){ \
123 (*((int*)x)) = bamboo_width - 1 - (l % bamboo_width); \
125 (*((int*)x)) = (l % bamboo_width); \
130 // NOTE: n starts from 0
131 #define NUMBLOCKS(s, n) \
132 if(s < (BAMBOO_SMEM_SIZE_L)) { \
133 (*((int*)(n))) = 0; \
135 (*((int*)(n))) = 1 + ((s) - (BAMBOO_SMEM_SIZE_L)) / (BAMBOO_SMEM_SIZE); \
138 #define OFFSET(s, o) \
139 if(s < BAMBOO_SMEM_SIZE_L) { \
140 (*((int*)(o))) = (s); \
142 (*((int*)(o))) = ((s) - (BAMBOO_SMEM_SIZE_L)) % (BAMBOO_SMEM_SIZE); \
145 #define BLOCKINDEX2(c, n, b) \
151 if((62 == (NUMCORES)) && (cc > 5)) cc += 2; \
152 x = cc / bamboo_height; \
153 y = cc % bamboo_height; \
156 t = x + (bamboo_width - 1 - y) * bamboo_width; \
158 t = bamboo_width - 1 - x + (bamboo_width - 1 - y) * bamboo_width; \
160 if(62 == (NUMCORES)) {\
169 t = bamboo_width - 1 - x + y * bamboo_width; \
171 t = x + y * bamboo_width; \
173 if(62 == (NUMCORES)) { \
179 t += (NUMCORES) * (n); \
184 #define BASEPTR(c, n, p) \
187 BLOCKINDEX2(c, n, &b); \
188 if(b < (NUMCORES)) { \
189 (*((int*)p)) = gcbaseva + b * (BAMBOO_SMEM_SIZE_L); \
191 (*((int*)p)) = gcbaseva+(BAMBOO_LARGE_SMEM_BOUND)+(b-(NUMCORES))*(BAMBOO_SMEM_SIZE); \
195 inline void gc(struct garbagelist * stackptr); // core coordinator routine
196 inline void gc_collect(struct garbagelist* stackptr);//core collector routine
197 inline void transferMarkResults_I();
198 inline void gc_enqueue_I(void *ptr);
199 inline void gc_lobjenqueue_I(void *ptr, int length, int host);
200 inline bool gcfindSpareMem_I(int * startaddr,