1 #ifndef MULTICORE_GARBAGE_H
2 #define MULTICORE_GARBAGE_H
3 #include "multicoregc.h"
4 #include "multicorehelper.h" // for mappins between core # and block #
5 #include "structdefs.h"
7 #include "GCSharedHash.h"
13 // data structures for GC
15 #define BAMBOO_SMEM_SIZE_L (BAMBOO_SMEM_SIZE) // * 2)
17 #define BAMBOO_SMEM_SIZE_L (BAMBOO_SMEM_SIZE) // * 2)
19 #define BAMBOO_LARGE_SMEM_BOUND (BAMBOO_SMEM_SIZE_L*NUMCORES4GC)
20 // let each gc core to have one big block, this is very important
21 // for the computation of NUMBLOCKS(s, n), DO NOT change this!
27 #define GCINFOLENGTH 100
29 typedef struct gc_info {
30 unsigned long long time[8];
34 GCInfo * gc_infoArray[GCINFOLENGTH];
39 unsigned long long flushstalltime;
40 unsigned long long flushstalltime_i;
41 int num_mapinforequest_i;
55 INITPHASE = 0x0, // 0x0
58 SUBTLECOMPACTPHASE, // 0x3
65 volatile bool gcprocessing;
66 volatile GCPHASETYPE gcphase; // indicating GC phase
69 struct MGCHash * gcforwardobjtbl; // cache forwarded objs in mark phase
70 // for mark phase termination
71 volatile int gccorestatus[NUMCORESACTIVE]; // records status of each core
74 volatile int gcnumsendobjs[NUMCORESACTIVE]; //records how many objects sent out
75 volatile int gcnumreceiveobjs[NUMCORESACTIVE]; //records how many objects
77 volatile bool gcbusystatus;
78 int gcself_numsendobjs;
79 int gcself_numreceiveobjs;
83 int gcloads[NUMCORES4GC];
84 int gctopcore; // the core host the top of the heap
85 int gctopblock; // the number of current top block
89 // compact instruction
90 INTPTR gcmarkedptrbound;
92 int gcstopblock[NUMCORES4GC]; // indicate when to stop compact phase
93 int gcfilledblocks[NUMCORES4GC]; //indicate how many blocks have been fulfilled
95 INTPTR gcmovestartaddr;
97 volatile bool gctomove;
98 int gcrequiredmems[NUMCORES4GC]; //record pending mem requests
99 volatile int gcmovepending;
101 // data structures to record remote cores that transferred the marked
102 // objs in the mark phase
107 struct RuntimeHash * gcrcoretbl;
108 #define NUM_MAPPING 40
109 void * gcmappingtbl[NUMCORESACTIVE][NUM_MAPPING];*/
111 // shared memory pointer for shared pointer mapping tbls
112 // In GC version, this block of memory is located at the bottom of the
113 // shared memory, right on the top of the smem tbl.
114 // The bottom of the shared memory = sbstart tbl + smemtbl
115 // + NUMCORES4GC bamboo_rmsp
116 // These three types of table are always reside at the bottom of the shared
117 // memory and will never be moved or garbage collected
118 #define BAMBOO_RMSP_SIZE (BAMBOO_SMEM_SIZE) // (45 * 16 * 1024)
120 // shared pointer mapping tbl
121 //volatile struct GCSharedHash * gcsharedptbl;
122 mgcsharedhashtbl_t * gcsharedptbl;
123 // remote shared pointer tbls
124 //struct GCSharedHash * gcrpointertbls[NUMCORES4GC];
125 mgcsharedhashtbl_t * gcrpointertbls[NUMCORES4GC];
127 volatile struct RuntimeHash * gcpointertbl;
128 //struct MGCHash * gcpointertbl;
131 volatile bool gcismapped;
133 // table recording the starting address of each small block
134 // (size is BAMBOO_SMEM_SIZE)
135 // Note: 1. this table always resides on the very bottom of the shared memory
136 // 2. the first two blocks are reserved for this table, would never be
137 // moved or garbage collected.
138 INTPTR * gcsbstarttbl;
139 int gcreservedsb; // number of reserved sblock for sbstarttbl
140 int gcnumblock; // number of total blocks in the shared mem
141 int gcbaseva; // base va for shared memory without reserved sblocks
143 #define ISSHAREDOBJ(p) \
144 ((((int)p)>gcbaseva)&&(((int)p)<(gcbaseva+(BAMBOO_SHARED_MEM_SIZE))))
146 #define ALIGNSIZE(s, as) \
147 (*((int*)as)) = (((s) & (~(BAMBOO_CACHE_LINE_MASK))) + (BAMBOO_CACHE_LINE_SIZE))
149 // mapping of pointer to block # (start from 0), here the block # is
151 #define BLOCKINDEX(p, b) \
153 int t = (p) - gcbaseva; \
154 if(t < (BAMBOO_LARGE_SMEM_BOUND)) { \
155 (*((int*)b)) = t / (BAMBOO_SMEM_SIZE_L); \
157 (*((int*)b)) = NUMCORES4GC+((t-(BAMBOO_LARGE_SMEM_BOUND))/(BAMBOO_SMEM_SIZE)); \
161 // mapping of pointer to core #
162 #define RESIDECORE(p, c) \
164 if(1 == (NUMCORES4GC)) { \
168 BLOCKINDEX((p), &b); \
169 (*((int*)c)) = gc_block2core[(b%(NUMCORES4GC*2))]; \
173 // NOTE: n starts from 0
174 // mapping of heaptop (how many bytes there are in the local heap) to
175 // the number of the block
176 // the number of the block indicates that the block is the xth block on
178 #define NUMBLOCKS(s, n) \
179 if(s < (BAMBOO_SMEM_SIZE_L)) { \
180 (*((int*)(n))) = 0; \
182 (*((int*)(n))) = 1 + ((s) - (BAMBOO_SMEM_SIZE_L)) / (BAMBOO_SMEM_SIZE); \
185 #define OFFSET(s, o) \
186 if(s < BAMBOO_SMEM_SIZE_L) { \
187 (*((int*)(o))) = (s); \
189 (*((int*)(o))) = ((s) - (BAMBOO_SMEM_SIZE_L)) % (BAMBOO_SMEM_SIZE); \
192 // mapping of (core #, index of the block) to the global block index
193 #define BLOCKINDEX2(c, n) (gc_core2block[(2*(c))+((n)%2)]+((NUMCORES4GC*2)*((n)/2)))
195 // mapping of (core #, number of the block) to the base pointer of the block
196 #define BASEPTR(c, n, p) \
198 int b = BLOCKINDEX2((c), (n)); \
199 if(b < (NUMCORES4GC)) { \
200 (*((int*)p)) = gcbaseva + b * (BAMBOO_SMEM_SIZE_L); \
202 (*((int*)p)) = gcbaseva+(BAMBOO_LARGE_SMEM_BOUND)+ \
203 (b-(NUMCORES4GC))*(BAMBOO_SMEM_SIZE); \
207 // the next core in the top of the heap
208 #define NEXTTOPCORE(b) (gc_block2core[((b)+1)%(NUMCORES4GC*2)])
210 inline void gc(struct garbagelist * stackptr); // core coordinator routine
211 inline void gc_collect(struct garbagelist* stackptr); //core collector routine
212 inline void gc_nocollect(struct garbagelist* stackptr); //non-gc core collector routine
213 inline void transferMarkResults_I();
214 inline void gc_enqueue_I(void *ptr);
215 inline void gc_lobjenqueue_I(void *ptr, int length, int host);
216 inline bool gcfindSpareMem_I(int * startaddr,
222 inline void * gc_lobjdequeue4(int * length, int * host);
223 inline int gc_lobjmoreItems4();
224 inline void gc_lobjqueueinit4();
227 INLINE void gc_profileStart(void);
228 INLINE void gc_profileItem(void);
229 INLINE void gc_profileEnd(void);
230 void gc_outputProfileData();