1 #ifndef MULTICORE_GARBAGE_H
2 #define MULTICORE_GARBAGE_H
3 #include "multicoregc.h"
4 #include "multicorehelper.h" // for mappings between core # and block #
5 #include "structdefs.h"
7 #include "GCSharedHash.h"
9 #include "multicorecache.h"
10 #endif // GC_CACHE_ADAPT
16 // data structures for GC
17 #define BAMBOO_SMEM_SIZE_L (BAMBOO_SMEM_SIZE * 2)
18 #define BAMBOO_LARGE_SMEM_BOUND (BAMBOO_SMEM_SIZE_L*NUMCORES4GC)
19 // let each gc core to have one big block, this is very important
20 // for the computation of NUMBLOCKS(s, n), DO NOT change this!
23 #define GC_NUM_FLUSH_DTLB 1
24 int gc_num_flush_dtlb;
31 #define GCINFOLENGTH 100
34 #define GC_PROFILE_NUM_FIELD 16
36 #define GC_PROFILE_NUM_FIELD 15
37 #endif // GC_CACHE_ADAPT
39 typedef struct gc_info {
40 unsigned long long time[GC_PROFILE_NUM_FIELD];
44 GCInfo * gc_infoArray[GCINFOLENGTH];
47 unsigned long long gc_num_livespace;
48 unsigned long long gc_num_freespace;
49 unsigned long long gc_num_lobjspace;
50 unsigned int gc_num_lobj;
52 unsigned int gc_num_liveobj;
53 unsigned int gc_num_obj;
54 unsigned int gc_num_forwardobj;
70 INITPHASE = 0x0, // 0x0
73 SUBTLECOMPACTPHASE, // 0x3
77 PREFINISHPHASE, // 0x6
78 #endif // GC_CACHE_ADAPT
79 FINISHPHASE // 0x6/0x7
83 volatile bool gcprocessing;
84 volatile GCPHASETYPE gcphase; // indicating GC phase
86 volatile bool gcpreinform; // counter for stopped cores
87 volatile bool gcprecheck; // indicates if there are updated pregc information
90 struct MGCHash * gcforwardobjtbl; // cache forwarded objs in mark phase
91 // for mark phase termination
92 volatile int gccorestatus[NUMCORESACTIVE]; // records status of each core
95 volatile int gcnumsendobjs[2][NUMCORESACTIVE]; // the # of objects sent out
96 volatile int gcnumreceiveobjs[2][NUMCORESACTIVE]; // the # of objects received
97 volatile int gcnumsrobjs_index; // indicates which entry to record the info
98 // received before phase 1 of the mark finish
100 // the info received in phase 2 must be
101 // recorded in the other entry
102 volatile bool gcbusystatus;
103 int gcself_numsendobjs;
104 int gcself_numreceiveobjs;
106 // for load balancing
108 int gcloads[NUMCORES4GC];
109 int gctopcore; // the core host the top of the heap
110 int gctopblock; // the number of current top block
114 // compact instruction
115 INTPTR gcmarkedptrbound;
117 int gcstopblock[NUMCORES4GC]; // indicate when to stop compact phase
118 int gcfilledblocks[NUMCORES4GC]; //indicate how many blocks have been fulfilled
120 INTPTR gcmovestartaddr;
122 volatile bool gctomove;
123 int gcrequiredmems[NUMCORES4GC]; //record pending mem requests
124 volatile int gcmovepending;
126 // shared memory pointer for shared pointer mapping tbls
127 // In GC version, this block of memory is located at the bottom of the
128 // shared memory, right on the top of the smem tbl.
129 // The bottom of the shared memory = sbstart tbl + smemtbl
130 // + NUMCORES4GC bamboo_rmsp
131 // These three types of table are always reside at the bottom of the shared
132 // memory and will never be moved or garbage collected
133 #ifdef GC_SMALLPAGESIZE
134 #define BAMBOO_RMSP_SIZE (1024 * 1024)
136 #define BAMBOO_RMSP_SIZE (BAMBOO_SMEM_SIZE) // (45 * 16 * 1024)
139 // shared pointer mapping tbl
140 mgcsharedhashtbl_t * gcsharedptbl;
141 // remote shared pointer tbls
142 mgcsharedhashtbl_t * gcrpointertbls[NUMCORES4GC];
144 #ifdef LOCALHASHTBL_TEST
145 struct RuntimeHash * gcpointertbl;
147 mgchashtable_t * gcpointertbl;
151 volatile bool gcismapped;
153 // table recording the starting address of each small block
154 // (size is BAMBOO_SMEM_SIZE)
155 // Note: 1. this table always resides on the very bottom of the shared memory
156 // 2. it is not counted in the shared heap, would never be garbage
158 INTPTR * gcsbstarttbl;
159 int gcreservedsb; // number of reserved sblock for sbstarttbl
160 int gcnumblock; // number of total blocks in the shared mem
161 int gcbaseva; // base va for shared memory without reserved sblocks
162 #ifdef GC_CACHE_ADAPT
163 int gctopva; // top va for shared memory without reserved sblocks
164 volatile bool gccachestage;
165 // table recording the sampling data collected for cache adaption
166 unsigned int * gccachesamplingtbl;
167 unsigned int * gccachesamplingtbl_local;
168 unsigned int size_cachesamplingtbl_local;
169 unsigned int * gccachesamplingtbl_r;
170 unsigned int * gccachesamplingtbl_local_r;
171 unsigned int size_cachesamplingtbl_local_r;
172 int * gccachepolicytbl;
173 unsigned int size_cachepolicytbl;
174 #endif // GC_CACHE_ADAPT
176 #define ISSHAREDOBJ(p) \
177 ((((int)p)>gcbaseva)&&(((int)p)<(gcbaseva+(BAMBOO_SHARED_MEM_SIZE))))
179 #define ALIGNSIZE(s, as) \
180 (*((int*)as)) = (((s) & (~(BAMBOO_CACHE_LINE_MASK))) + (BAMBOO_CACHE_LINE_SIZE))
182 // mapping of pointer to block # (start from 0), here the block # is
184 #define BLOCKINDEX(p, b) \
186 int t = (p) - gcbaseva; \
187 if(t < (BAMBOO_LARGE_SMEM_BOUND)) { \
188 (*((int*)b)) = t / (BAMBOO_SMEM_SIZE_L); \
190 (*((int*)b)) = NUMCORES4GC+((t-(BAMBOO_LARGE_SMEM_BOUND))/(BAMBOO_SMEM_SIZE)); \
194 // mapping of pointer to core #
195 #define RESIDECORE(p, c) \
197 if(1 == (NUMCORES4GC)) { \
201 BLOCKINDEX((p), &b); \
202 (*((int*)c)) = gc_block2core[(b%(NUMCORES4GC*2))]; \
206 // NOTE: n starts from 0
207 // mapping of heaptop (how many bytes there are in the local heap) to
208 // the number of the block
209 // the number of the block indicates that the block is the xth block on
211 #define NUMBLOCKS(s, n) \
212 if(s < (BAMBOO_SMEM_SIZE_L)) { \
213 (*((int*)(n))) = 0; \
215 (*((int*)(n))) = 1 + ((s) - (BAMBOO_SMEM_SIZE_L)) / (BAMBOO_SMEM_SIZE); \
218 #define OFFSET(s, o) \
219 if(s < BAMBOO_SMEM_SIZE_L) { \
220 (*((int*)(o))) = (s); \
222 (*((int*)(o))) = ((s) - (BAMBOO_SMEM_SIZE_L)) % (BAMBOO_SMEM_SIZE); \
225 // mapping of (core #, index of the block) to the global block index
226 #define BLOCKINDEX2(c, n) (gc_core2block[(2*(c))+((n)%2)]+((NUMCORES4GC*2)*((n)/2)))
228 // mapping of (core #, number of the block) to the base pointer of the block
229 #define BASEPTR(c, n, p) \
231 int b = BLOCKINDEX2((c), (n)); \
232 if(b < (NUMCORES4GC)) { \
233 (*((int*)p)) = gcbaseva + b * (BAMBOO_SMEM_SIZE_L); \
235 (*((int*)p)) = gcbaseva+(BAMBOO_LARGE_SMEM_BOUND)+ \
236 (b-(NUMCORES4GC))*(BAMBOO_SMEM_SIZE); \
240 // the next core in the top of the heap
241 #define NEXTTOPCORE(b) (gc_block2core[((b)+1)%(NUMCORES4GC*2)])
243 inline bool gc(struct garbagelist * stackptr); // core coordinator routine
244 inline void gc_collect(struct garbagelist* stackptr); //core collector routine
245 inline void gc_nocollect(struct garbagelist* stackptr); //non-gc core collector routine
246 inline void transferMarkResults_I();
247 inline void gc_enqueue_I(void *ptr);
248 inline void gc_lobjenqueue_I(void *ptr, int length, int host);
249 inline bool gcfindSpareMem_I(int * startaddr,
255 inline void * gc_lobjdequeue4(int * length, int * host);
256 inline int gc_lobjmoreItems4();
257 inline void gc_lobjqueueinit4();
260 INLINE void gc_profileStart(void);
261 INLINE void gc_profileItem(void);
262 INLINE void gc_profileEnd(void);
263 void gc_outputProfileData();