-m#ifndef BAMBOO_MULTICORE_GARBAGE_H
+#ifndef BAMBOO_MULTICORE_GARBAGE_H
#define BAMBOO_MULTICORE_GARBAGE_H
#ifdef MULTICORE_GC
#include "multicore.h"
#include "multicorehelper.h" // for mappings between core # and block #
#include "structdefs.h"
#include "multicoregcprofile.h"
+#include "gctypes.h"
#ifdef GC_DEBUG
#define GC_PRINTF tprintf
#define GC_PRINTF if(0) tprintf
#endif
+#ifdef GC_DEBUG
+#define TR() tprintf("%u\n",__LINE__)
+#else
+#define TR()
+#endif
+
// data structures for GC
#define BAMBOO_SMEM_SIZE_L (BAMBOO_SMEM_SIZE * 2)
#define BAMBOO_LARGE_SMEM_BOUND (BAMBOO_SMEM_SIZE_L*NUMCORES4GC)
volatile unsigned int gccorestatus[NUMCORESACTIVE];//records status of each core
// 1: running gc
// 0: stall
+
+volatile unsigned int returnedmem[NUMCORESACTIVE];//records status of each core
+ // 1: running gc
+ // 0: stall
volatile unsigned int gcnumsendobjs[2][NUMCORESACTIVE];//# of objects sent out
volatile unsigned int gcnumreceiveobjs[2][NUMCORESACTIVE];//# of objects received
volatile unsigned int gcnumsrobjs_index;//indicates which entry to record the
unsigned int gcself_numreceiveobjs;
// for load balancing
-unsigned int gcheaptop;
unsigned INTPTR gcloads[NUMCORES4GC];
-unsigned INTPTR numblockspercore;
+block_t numblockspercore;
//Top of each core's heap
void * topptrs[NUMCORES4GC];
volatile bool gctomove;
//keeps track of memory request master was not able to serve
-unsigned int gcrequiredmems[NUMCORES4GC]; //record pending mem requests
+volatile unsigned int maxusefulmems[NUMCORES4GC]; //record pending mem requests
+volatile unsigned int gcrequiredmems[NUMCORES4GC]; //record pending mem requests
volatile unsigned int gcmovepending;
+//keep track of current base block pointer for orig block
+volatile void * update_origblockptr;
+volatile void * origblockarray[NUMCORES4GC];
+volatile int origarraycount;
+volatile bool blockgranted;
+
+
// shared memory pointer for pointer mapping tbls
// In GC version, this block of memory is located at the bottom of the
// shared memory, right on the top of the smem tbl.
unsigned int bamboo_rmsp_size;
//mark table....keep track of mark bits
-unsigned int * gcmarktbl;
+volatile unsigned int * gcmarktbl;
+
+bool gc_checkCoreStatus();
+
+void gc_resetCoreStatus();
+
-void * gcbaseva; // base va for shared memory without reserved sblocks
/* Structure to keep track of free space in block */
enum blockstatus {
- /* BS_INIT indicates that we don't have information for this block yet */
- BS_INIT,
+ /* BS_USED indicates that we don't have information for this block yet */
+ BS_USED,
/* BS_LARGEOBJECT indicates that the beginning of this block has a large object*/
BS_LARGEOBJECT,
/* BS_FREE indicates that the block is at least partially free */
struct blockrecord {
enum blockstatus status;
unsigned INTPTR usedspace;
+ unsigned INTPTR freespace;
unsigned int corenum;
-
};
#define NOFREEBLOCK 0xffffffff
struct allocrecord allocationinfo;
#ifdef GC_CACHE_ADAPT
-void * gctopva; // top va for shared memory without reserved sblocks
-volatile bool gccachestage;
// table recording the sampling data collected for cache adaption
-int * gccachesamplingtbl;
-int * gccachesamplingtbl_local;
-unsigned int size_cachesamplingtbl_local;
-int * gccachesamplingtbl_r;
-int * gccachesamplingtbl_local_r;
-unsigned int size_cachesamplingtbl_local_r;
-int * gccachepolicytbl;
+unsigned int * gccachesamplingtbl;
+unsigned int * gccachesamplingtbl_local;// for zeroing memory only
+unsigned int size_cachesamplingtbl_local; // for zeroing memory only
+unsigned int * gccachesamplingtbl_r;
+unsigned int * gccachesamplingtbl_local_r; // for zeroing memory only
+unsigned int size_cachesamplingtbl_local_r; // for zeroing memory only
+unsigned int * gccachepolicytbl;
unsigned int size_cachepolicytbl;
#endif
#define GCNUMBLOCK (NUMCORES4GC+(BAMBOO_SHARED_MEM_SIZE-BAMBOO_LARGE_SMEM_BOUND)/BAMBOO_SMEM_SIZE)
#define GCNUMLOCALBLOCK (GCNUMBLOCK/NUMCORES4GC)
+/* Leave the neighboring cores with at least two blocks */
+#define MAXNEIGHBORALLOC (GCNUMLOCALBLOCK-2)
+
+/* This macro defines the smallest memoy chunk the master will hand out to another core during compacting */
+
+#define MINMEMORYCHUNKSIZE 32768
+
+#define ISVALIDPTR(x) ((((unsigned INTPTR)x)>=((unsigned INTPTR)gcbaseva))&&(((unsigned INTPTR)x)<((unsigned INTPTR)(gcbaseva+BAMBOO_SHARED_MEM_SIZE))))
+
/* This macro waits for the given gc phase */
#define WAITFORGCPHASE(phase) while(gc_status_info.gcphase != phase) ;
} \
}
+#define BLOCK2CORE(c, b) { \
+ if(1 == (NUMCORES4GC)) { \
+ c = 0; \
+ } else { \
+ c = gc_block2core[(b%(NUMCORES4GC*2))]; \
+ } \
+ }
+
INLINE static unsigned int hostcore(void * ptr) {
// check the host core of ptr
unsigned int host;
//This macro takes in a local block number and returns the size of the block
#define BLOCKSIZE(c) \
- ((c)?BAMBOO_SMEM_SIZE_L:BAMBOO_SMEM_SIZE)
+ ((c)?BAMBOO_SMEM_SIZE:BAMBOO_SMEM_SIZE_L)
+
+//This macro takes in a local block number and returns the size of the block
+#define GLOBALBLOCKSIZE(c) \
+ ((c<NUMCORES4GC)?BAMBOO_SMEM_SIZE_L:BAMBOO_SMEM_SIZE)
//Takes as input the core number c and the local block index n and
//returns the global block index
#define NEXTTOPCORE(b) (gc_block2core[((b)+1)%(NUMCORES4GC*2)])
// check if all cores are stall now
-#define GC_CHECK_ALL_CORE_STATUS(f) \
- { \
- gccorestatus[BAMBOO_NUM_OF_CORE] = 0; \
- while(f) { \
- if(gc_checkAllCoreStatus()) { \
- break; \
- } \
- } \
- }
+#define GC_CHECK_ALL_CORE_STATUS() gccorestatus[BAMBOO_NUM_OF_CORE] = 0; \
+ while(!gc_checkCoreStatus()) ;
// send a 1-word msg to all clients
#define GC_SEND_MSG_1_TO_CLIENT(m) \
void initmulticoregcdata();
void dismulticoregcdata();
-bool gc_checkAllCoreStatus();
bool gc(struct garbagelist * stackptr); // core coordinator routine
void gc_collect(struct garbagelist* stackptr); //core collector routine
void gc_nocollect(struct garbagelist* stackptr); //non-gc core collector routine
void transferMarkResults_I();
-void * gcfindSpareMem_I(unsigned int requiredmem,unsigned int requiredcore);
+void * gcfindSpareMem_I(unsigned INTPTR requiredmem, unsigned INTPTR maxbytesneeded, unsigned int requiredcore);
#define INITMULTICOREGCDATA() initmulticoregcdata()
#define DISMULTICOREGCDATA() dismulticoregcdata()