gc_cache_revise_info_t gc_cache_revise_information;
+/* This function initialize the gc_cache_revise_information. It should be
+ * invoked before we start compaction.
+ */
+void samplingDataReviseInit(struct moveHelper * orig,struct moveHelper * to) {
+ // initialize the destination page info
+ gc_cache_revise_information.to_page_start_va=to->ptr;
+ unsigned int toindex=(unsigned INTPTR)(to->base-gcbaseva)/BAMBOO_PAGE_SIZE;
+ gc_cache_revise_information.to_page_end_va=gcbaseva+BAMBOO_PAGE_SIZE*(toindex+1);
+ gc_cache_revise_information.to_page_index=toindex;
+ // initilaize the original page info
+ unsigned int origindex=((unsigned INTPTR)(orig->base-gcbaseva))/BAMBOO_PAGE_SIZE;
+ gc_cache_revise_information.orig_page_start_va=orig->ptr;
+ gc_cache_revise_information.orig_page_end_va=gcbaseva+BAMBOO_PAGE_SIZE*(origindex+1);
+ gc_cache_revise_information.orig_page_index=origindex;
+}
+
+/* This function computes the revised profiling data of the first closed destination
+ * page of an object that acrosses multiple pages
+ */
+void firstPageConvert(bool origclosefirst, unsigned INTPTR main_factor, unsigned INTPTR delta_factor) {
+ unsigned INTPTR topage=gc_cache_revise_information.to_page_index*NUMCORESACTIVE;
+ unsigned INTPTR oldpage=gc_cache_revise_information.orig_page_index*NUMCORESACTIVE;
+ int * newtable=&gccachesamplingtbl_r[topage];
+ int * oldtable=&gccachesamplingtbl[oldpage];
+ // compute the revised profiling info for the start destination page
+ if(origclosefirst) {
+ // the start original page closes first, now compute the revised profiling
+ // info for the start destination page.
+ // The start destination page = the rest of the start original page +
+ // delta_fator from the next original page
+ int * oldtable_next=&gccachesamplingtbl[oldpage+NUMCORESACTIVE];
+ for(int tt = 0; tt < NUMCORESACTIVE; tt++) {
+ (*newtable)=((*newtable)+(*oldtable)*main_factor+(*oldtable_next)*delta_factor);
+ newtable++;
+ oldtable++;
+ oldtable_next++;
+ }
+ // close the start original page
+ gc_cache_revise_information.orig_page_start_va+=main_factor+delta_factor;
+ gc_cache_revise_information.orig_page_end_va+=BAMBOO_PAGE_SIZE;
+ gc_cache_revise_information.orig_page_index++;
+ } else {
+ // the start destination page closes first, now compute the revised
+ // profiling info for it.
+ for(int tt = 0; tt < NUMCORESACTIVE; tt++) {
+ (*newtable)=((*newtable)+(*oldtable)*main_factor);
+ newtable++;
+ oldtable++;
+ }
+ // record the new start of the original page
+ gc_cache_revise_information.orig_page_start_va+=main_factor;
+ }
+ // close the start original page and destination page
+ gc_cache_revise_information.to_page_start_va=gc_cache_revise_information.to_page_end_va;
+ gc_cache_revise_information.to_page_end_va+=BAMBOO_PAGE_SIZE;
+ gc_cache_revise_information.to_page_index++;
+}
+
+/* This function computes the revised profiling info for closed destination
+ * pages that are occupied by one object that acrosses multiple pages.
+ * the destination page = main_factor from the first unclosed original page
+ * + delta_factor from the next unclosed original page
+ */
+void restClosedPageConvert(void * current_ptr, unsigned INTPTR main_factor, unsigned INTPTR delta_factor) {
+ while(gc_cache_revise_information.to_page_end_va<=current_ptr) {
+ unsigned INTPTR topage=gc_cache_revise_information.to_page_index*NUMCORESACTIVE;
+ unsigned INTPTR oldpage=gc_cache_revise_information.orig_page_index*NUMCORESACTIVE;
+ int *newtable=&gccachesamplingtbl_r[topage];
+ int *oldtable=&gccachesamplingtbl[oldpage];
+ int *oldtable_next=&gccachesamplingtbl[oldpage+NUMCORESACTIVE];
+
+ for(int tt = 0; tt < NUMCORESACTIVE; tt++) {
+ (*newtable)=((*newtable)+(*oldtable)*main_factor+(*oldtable_next)*delta_factor);
+ newtable++;
+ oldtable++;
+ oldtable_next++;
+ }
+
+ // close the original page and the destination page
+ gc_cache_revise_information.orig_page_start_va+=BAMBOO_PAGE_SIZE;
+ gc_cache_revise_information.orig_page_end_va+=BAMBOO_PAGE_SIZE;
+ gc_cache_revise_information.orig_page_index++;
+ gc_cache_revise_information.to_page_start_va=gc_cache_revise_information.to_page_end_va;
+ gc_cache_revise_information.to_page_end_va+=BAMBOO_PAGE_SIZE;
+ gc_cache_revise_information.to_page_index++;
+ }
+}
+
+/* This function computes the revised profiling info for the last
+ * destination page of an object that acrosses multiple pages.
+ */
+void lastPageConvert(void * current_ptr) {
+ unsigned INTPTR to_factor=current_ptr-gc_cache_revise_information.to_page_start_va;
+ unsigned INTPTR topage=gc_cache_revise_information.to_page_index*NUMCORESACTIVE;
+ unsigned INTPTR oldpage=gc_cache_revise_information.orig_page_index*NUMCORESACTIVE;
+ int *newtable=&gccachesamplingtbl_r[topage];
+ int *oldtable=&gccachesamplingtbl[oldpage];
+
+ for(int tt = 0; tt < NUMCORESACTIVE; tt++) {
+ (*newtable)=((*newtable)+(*oldtable)*to_factor);
+ newtable++;
+ oldtable++;
+ }
+ // do not need to set gc_cache_revise_information here for the last
+ // original/destination page as it will be set in completePageConvert()
+}
+
+/* This function converts multiple original pages profiling data to multiple
+ * destination pages' profiling data
+ */
+void samplingDataConvertMultiple(void * current_ptr) {
+ // first decide which page close first: original or destination?
+ unsigned INTPTR to_factor=(unsigned INTPTR)(gc_cache_revise_information.to_page_end_va-gc_cache_revise_information.to_page_start_va);
+ unsigned INTPTR orig_factor=(unsigned INTPTR)(gc_cache_revise_information.orig_page_end_va-gc_cache_revise_information.orig_page_start_va);
+ bool origclosefirst=to_factor>orig_factor;
+ unsigned INTPTR delta_factor=(origclosefirst)?(to_factor-orig_factor):(orig_factor-to_factor);
+ unsigned INTPTR main_factor=(origclosefirst)?orig_factor:to_factor;
+
+ // compute the revised profiling info for the start destination page
+ firstPageConvert(origclosefirst, main_factor, delta_factor);
+ // update main_factor/delta_factor
+ if(origclosefirst) {
+ // for the following destination pages that are fully used:
+ // the destination page = (page_size-delta_factor) from the
+ // first unclosed original page + delta_factor
+ // from the next unclosed original page
+ // we always use main_factor to represent the factor from the first
+ // unclosed original page
+ main_factor=BAMBOO_PAGE_SIZE-delta_factor;
+ } else {
+ // for the following destination pages that are fully used:
+ // the destination page = delta_factor from the first unclosed original
+ // page + (page_size-delta_factor) from the next
+ // unclosed original page
+ // we always use main_factor to represent the factor from the first
+ // unclosed original page
+ main_factor=delta_factor;
+ delta_factor=BAMBOO_PAGE_SIZE-delta_factor;
+ }
+
+ // compute the revised profiling info for the following closed destination
+ // pages
+ restClosedPageConvert(current_ptr, main_factor, delta_factor);
+
+ // compute the revised profiling info for the last destination page if needed
+ lastPageConvert(current_ptr);
+}
+
+/* This function converts originial pages' profiling data to destination pages'
+ * profiling data.
+ * The parameter current_ptr indicates the current position in the destination
+ * pages.
+ * Note that there could be objects that across pages. In such cases, there are
+ * multiple orig/to pages are closed and all these to pages' profiling data
+ * should be properly updated.
+ */
+void samplingDataConvert(void * current_ptr) {
+ if(gc_cache_revise_information.to_page_end_va<current_ptr) {
+ // multiple pages are closed
+ samplingDataConvertMultiple(current_ptr);
+ } else {
+ unsigned INTPTR tmp_factor=(unsigned INTPTR)(current_ptr-gc_cache_revise_information.to_page_start_va);
+ if(tmp_factor) {
+ unsigned INTPTR topage=gc_cache_revise_information.to_page_index*NUMCORESACTIVE;
+ unsigned INTPTR oldpage=gc_cache_revise_information.orig_page_index*NUMCORESACTIVE;
+ int * newtable=&gccachesamplingtbl_r[topage];
+ int * oldtable=&gccachesamplingtbl[oldpage];
+
+ for(int tt = 0; tt < NUMCORESACTIVE; tt++) {
+ (*newtable)=((*newtable)+(*oldtable)*tmp_factor);
+ newtable++;
+ oldtable++;
+ }
+ }
+ }
+}
+
+/* This function computes the impact of an original page on a destination page
+ * in terms of profiling data. It can only be invoked when there is an original
+ * page that is closed or a destination page that is closed. When finished
+ * computing the revised profiling info of the current destination page, it
+ * sets up the gc_cache_revise_information to the latest position in the
+ * original page and the destination page.
+ */
+void completePageConvert(void * origptr, void * toptr, void * current_ptr) {
+ bool closeToPage=(unsigned int)(toptr)>=(unsigned int)(gc_cache_revise_information.to_page_end_va);
+ bool closeOrigPage=(unsigned int)(origptr)>=(unsigned int)(gc_cache_revise_information.orig_page_end_va);
+ if(closeToPage||closeOrigPage) {
+ // end of one or more orig/to page
+ // compute the impact of the original page(s) for the desitination page(s)
+ samplingDataConvert(current_ptr);
+ // prepare for an new orig page
+ unsigned INTPTR tmp_index=((unsigned INTPTR)(origptr-gcbaseva))/BAMBOO_PAGE_SIZE;
+ gc_cache_revise_information.orig_page_start_va=origptr;
+ gc_cache_revise_information.orig_page_end_va=gcbaseva+BAMBOO_PAGE_SIZE*(tmp_index+1);
+ gc_cache_revise_information.orig_page_index=tmp_index;
+ gc_cache_revise_information.to_page_start_va=toptr;
+ if(closeToPage) {
+ unsigned INTPTR to_index=((unsigned INTPTR)(toptr-gcbaseva))/BAMBOO_PAGE_SIZE;
+ gc_cache_revise_information.to_page_end_va=gcbaseva+BAMBOO_PAGE_SIZE*(to_index+1);
+ gc_cache_revise_information.to_page_index=to_index;
+ }
+ }
+}
+
// prepare for cache adaption:
// -- flush the shared heap
// -- clean dtlb entries
// find the core that accesses the page #page_index most
#define CACHEADAPT_FIND_HOTTEST_CORE(page_index,hottestcore,hotfreq) \
{ \
- int *local_tbl=&gccachesamplingtbl_r[page_index]; \
+ int *local_tbl=&gccachesamplingtbl_r[page_index*NUMCORESACTIVE]; \
for(int i = 0; i < NUMCORESACTIVE; i++) { \
int freq = *local_tbl; \
- local_tbl=(int *)(((void *)local_tbl)+size_cachesamplingtbl_local_r); \
+ local_tbl++; \
if(hotfreq < freq) { \
hotfreq = freq; \
hottestcore = i; \
// access time of the page at the same time
#define CACHEADAPT_FIND_HOTTEST_CORE_W_TOTALFREQ(page_index,hottestcore,hotfreq,totalfreq) \
{ \
- int *local_tbl=&gccachesamplingtbl_r[page_index]; \
+ int *local_tbl=&gccachesamplingtbl_r[page_index*NUMCORESACTIVE]; \
for(int i = 0; i < NUMCORESACTIVE; i++) { \
int freq = *local_tbl; \
- local_tbl=(int *)(((void *)local_tbl)+size_cachesamplingtbl_local_r); \
+ local_tbl++; \
totalfreq += freq; \
if(hotfreq < freq) { \
hotfreq = freq; \
BLOCKINDEX(block, (void *) page_sva);
unsigned int coren = gc_block2core[block%(NUMCORES4GC*2)];
printf("%x, %d, %d, ",(int)page_sva,page_index,coren);
+ int * local_tbl = &gccachesamplingtbl[page_index*NUMCORESACTIVE];
for(int i = 0; i < NUMCORESACTIVE; i++) {
- int * local_tbl = (int *)((void *)gccachesamplingtbl+size_cachesamplingtbl_local*i);
- int freq = local_tbl[page_index];
+ int freq = *local_tbl;
+ local_tbl++;
//if(freq != 0) {
printf("%d, ", freq);
//}
unsigned int coren = gc_block2core[block%(NUMCORES4GC*2)];
printf(" %x, %d, %d, ",(int)page_sva,page_index,coren);
int accesscore = 0; // TODO
+ int * local_tbl = &gccachesamplingtbl_r[page_index*NUMCORESACTIVE];
for(int i = 0; i < NUMCORESACTIVE; i++) {
- int * local_tbl = (int *)((void *)gccachesamplingtbl_r+size_cachesamplingtbl_local_r*i);
- int freq = local_tbl[page_index]/BAMBOO_PAGE_SIZE;
+ int freq = *local_tbl; ///BAMBOO_PAGE_SIZE;
printf("%d, ", freq);
if(freq != 0) {
accesscore++;// TODO
}
+ local_tbl++;
}
if(accesscore!=0) {
+ int * local_tbl = &gccachesamplingtbl_r[page_index];
for(int i = 0; i < NUMCORESACTIVE; i++) {
- int * local_tbl = (int *)((void *)gccachesamplingtbl_r+size_cachesamplingtbl_local_r*i);
- int freq = local_tbl[page_index]; ///BAMBOO_PAGE_SIZE;
+ int freq = *local_tbl; ///BAMBOO_PAGE_SIZE;
sumdata[accesscore-1][i]+=freq;
+ local_tbl++;
}
}
// global variable holding page information to compute revised sampling info
extern gc_cache_revise_info_t gc_cache_revise_information;
-/* This function initialize the gc_cache_revise_information. It should be
- * invoked before we start compaction.
- */
-INLINE static void samplingDataReviseInit(struct moveHelper * orig,struct moveHelper * to) {
- // initialize the destination page info
- gc_cache_revise_information.to_page_start_va=to->ptr;
- unsigned int toindex=(unsigned INTPTR)(to->base-gcbaseva)/BAMBOO_PAGE_SIZE;
- gc_cache_revise_information.to_page_end_va=gcbaseva+BAMBOO_PAGE_SIZE*(toindex+1);
- gc_cache_revise_information.to_page_index=toindex;
- // initilaize the original page info
- unsigned int origindex=((unsigned INTPTR)(orig->base-gcbaseva))/BAMBOO_PAGE_SIZE;
- gc_cache_revise_information.orig_page_start_va=orig->ptr;
- gc_cache_revise_information.orig_page_end_va=gcbaseva+BAMBOO_PAGE_SIZE*(origindex+1);
- gc_cache_revise_information.orig_page_index=origindex;
-}
-
-/* This function computes the revised profiling data of the first closed destination
- * page of an object that acrosses multiple pages
- */
-INLINE static void firstPageConvert(bool origclosefirst, unsigned INTPTR main_factor, unsigned INTPTR delta_factor) {
- unsigned INTPTR topage=gc_cache_revise_information.to_page_index;
- unsigned INTPTR oldpage=gc_cache_revise_information.orig_page_index;
- int * newtable=&gccachesamplingtbl_r[topage];
- int * oldtable=&gccachesamplingtbl[oldpage];
- // compute the revised profiling info for the start destination page
- if(origclosefirst) {
- // the start original page closes first, now compute the revised profiling
- // info for the start destination page.
- // The start destination page = the rest of the start original page +
- // delta_fator from the next original page
- int * oldtable_next=&gccachesamplingtbl[oldpage+1];
- for(int tt = 0; tt < NUMCORESACTIVE; tt++) {
- (*newtable)=((*newtable)+(*oldtable)*main_factor+(*oldtable_next)*delta_factor);
- newtable=(int*)(((char *)newtable)+size_cachesamplingtbl_local_r);
- oldtable=(int*) (((char *)oldtable)+size_cachesamplingtbl_local);
- oldtable_next=(int*) (((char *)oldtable_next)+size_cachesamplingtbl_local);
- }
- // close the start original page
- gc_cache_revise_information.orig_page_start_va+=main_factor+delta_factor;
- gc_cache_revise_information.orig_page_end_va+=BAMBOO_PAGE_SIZE;
- gc_cache_revise_information.orig_page_index++;
- } else {
- // the start destination page closes first, now compute the revised
- // profiling info for it.
- for(int tt = 0; tt < NUMCORESACTIVE; tt++) {
- (*newtable)=((*newtable)+(*oldtable)*main_factor);
- newtable=(int*)(((char *)newtable)+size_cachesamplingtbl_local_r);
- oldtable=(int*) (((char *)oldtable)+size_cachesamplingtbl_local);
- }
- // record the new start of the original page
- gc_cache_revise_information.orig_page_start_va+=main_factor;
- }
- // close the start original page and destination page
- gc_cache_revise_information.to_page_start_va=gc_cache_revise_information.to_page_end_va;
- gc_cache_revise_information.to_page_end_va+=BAMBOO_PAGE_SIZE;
- gc_cache_revise_information.to_page_index++;
-}
-
-/* This function computes the revised profiling info for closed destination
- * pages that are occupied by one object that acrosses multiple pages.
- * the destination page = main_factor from the first unclosed original page
- * + delta_factor from the next unclosed original page
- */
-INLINE static void restClosedPageConvert(void * current_ptr, unsigned INTPTR main_factor, unsigned INTPTR delta_factor) {
- while(gc_cache_revise_information.to_page_end_va<=current_ptr) {
- unsigned INTPTR topage=gc_cache_revise_information.to_page_index;
- unsigned INTPTR oldpage=gc_cache_revise_information.orig_page_index;
- int *newtable=&gccachesamplingtbl_r[topage];
- int *oldtable=&gccachesamplingtbl[oldpage];
- int *oldtable_next=&gccachesamplingtbl[oldpage+1];
-
- for(int tt = 0; tt < NUMCORESACTIVE; tt++) {
- (*newtable)=((*newtable)+(*oldtable)*main_factor+(*oldtable_next)*delta_factor);
- newtable=(int*)(((char *)newtable)+size_cachesamplingtbl_local_r);
- oldtable=(int*) (((char *)oldtable)+size_cachesamplingtbl_local);
- oldtable_next=(int*) (((char *)oldtable_next)+size_cachesamplingtbl_local);
- }
-
- // close the original page and the destination page
- gc_cache_revise_information.orig_page_start_va+=BAMBOO_PAGE_SIZE;
- gc_cache_revise_information.orig_page_end_va+=BAMBOO_PAGE_SIZE;
- gc_cache_revise_information.orig_page_index++;
- gc_cache_revise_information.to_page_start_va=gc_cache_revise_information.to_page_end_va;
- gc_cache_revise_information.to_page_end_va+=BAMBOO_PAGE_SIZE;
- gc_cache_revise_information.to_page_index++;
- }
-}
-
-/* This function computes the revised profiling info for the last
- * destination page of an object that acrosses multiple pages.
- */
-INLINE static void lastPageConvert(void * current_ptr) {
- unsigned INTPTR to_factor=current_ptr-gc_cache_revise_information.to_page_start_va;
- unsigned INTPTR topage=gc_cache_revise_information.to_page_index;
- unsigned INTPTR oldpage=gc_cache_revise_information.orig_page_index;
- int *newtable=&gccachesamplingtbl_r[topage];
- int *oldtable=&gccachesamplingtbl[oldpage];
-
- for(int tt = 0; tt < NUMCORESACTIVE; tt++) {
- (*newtable)=((*newtable)+(*oldtable)*to_factor);
- newtable=(int*)(((char *)newtable)+size_cachesamplingtbl_local_r);
- oldtable=(int*) (((char *)oldtable)+size_cachesamplingtbl_local);
- }
- // do not need to set gc_cache_revise_information here for the last
- // original/destination page as it will be set in completePageConvert()
-}
-
-/* This function converts multiple original pages profiling data to multiple
- * destination pages' profiling data
- */
-INLINE static void samplingDataConvertMultiple(void * current_ptr) {
- // first decide which page close first: original or destination?
- unsigned INTPTR to_factor=(unsigned INTPTR)(gc_cache_revise_information.to_page_end_va-gc_cache_revise_information.to_page_start_va);
- unsigned INTPTR orig_factor=(unsigned INTPTR)(gc_cache_revise_information.orig_page_end_va-gc_cache_revise_information.orig_page_start_va);
- bool origclosefirst=to_factor>orig_factor;
- unsigned INTPTR delta_factor=(origclosefirst)?(to_factor-orig_factor):(orig_factor-to_factor);
- unsigned INTPTR main_factor=(origclosefirst)?orig_factor:to_factor;
-
- // compute the revised profiling info for the start destination page
- firstPageConvert(origclosefirst, main_factor, delta_factor);
- // update main_factor/delta_factor
- if(origclosefirst) {
- // for the following destination pages that are fully used:
- // the destination page = (page_size-delta_factor) from the
- // first unclosed original page + delta_factor
- // from the next unclosed original page
- // we always use main_factor to represent the factor from the first
- // unclosed original page
- main_factor=BAMBOO_PAGE_SIZE-delta_factor;
- } else {
- // for the following destination pages that are fully used:
- // the destination page = delta_factor from the first unclosed original
- // page + (page_size-delta_factor) from the next
- // unclosed original page
- // we always use main_factor to represent the factor from the first
- // unclosed original page
- main_factor=delta_factor;
- delta_factor=BAMBOO_PAGE_SIZE-delta_factor;
- }
-
- // compute the revised profiling info for the following closed destination
- // pages
- restClosedPageConvert(current_ptr, main_factor, delta_factor);
-
- // compute the revised profiling info for the last destination page if needed
- lastPageConvert(current_ptr);
-}
-
-/* This function converts originial pages' profiling data to destination pages'
- * profiling data.
- * The parameter current_ptr indicates the current position in the destination
- * pages.
- * Note that there could be objects that across pages. In such cases, there are
- * multiple orig/to pages are closed and all these to pages' profiling data
- * should be properly updated.
- */
-INLINE static void samplingDataConvert(void * current_ptr) {
- if(gc_cache_revise_information.to_page_end_va<current_ptr) {
- // multiple pages are closed
- samplingDataConvertMultiple(current_ptr);
- } else {
- unsigned INTPTR tmp_factor=(unsigned INTPTR)(current_ptr-gc_cache_revise_information.to_page_start_va);
- if(tmp_factor) {
- unsigned INTPTR topage=gc_cache_revise_information.to_page_index;
- unsigned INTPTR oldpage=gc_cache_revise_information.orig_page_index;
- int * newtable=&gccachesamplingtbl_r[topage];
- int * oldtable=&gccachesamplingtbl[oldpage];
-
- for(int tt = 0; tt < NUMCORESACTIVE; tt++) {
- (*newtable)=((*newtable)+(*oldtable)*tmp_factor);
- newtable=(int*)(((char *)newtable)+size_cachesamplingtbl_local_r);
- oldtable=(int*) (((char *)oldtable)+size_cachesamplingtbl_local);
- }
- }
- }
-}
-
-/*
- */
-INLINE static void completePageConvert(void * origptr, void * toptr, void * current_ptr) {
- bool closeToPage=(unsigned int)(toptr)>=(unsigned int)(gc_cache_revise_information.to_page_end_va);
- bool closeOrigPage=(unsigned int)(origptr)>=(unsigned int)(gc_cache_revise_information.orig_page_end_va);
- if(closeToPage||closeOrigPage) {
- // end of one or more orig/to page
- // compute the impact of the original page(s) for the desitination page(s)
- samplingDataConvert(current_ptr);
- // prepare for an new orig page
- unsigned INTPTR tmp_index=((unsigned INTPTR)(origptr-gcbaseva))/BAMBOO_PAGE_SIZE;
- gc_cache_revise_information.orig_page_start_va=origptr;
- gc_cache_revise_information.orig_page_end_va=gcbaseva+BAMBOO_PAGE_SIZE*(tmp_index+1);
- gc_cache_revise_information.orig_page_index=tmp_index;
- gc_cache_revise_information.to_page_start_va=toptr;
- if(closeToPage) {
- unsigned INTPTR to_index=((unsigned INTPTR)(toptr-gcbaseva))/BAMBOO_PAGE_SIZE;
- gc_cache_revise_information.to_page_end_va=gcbaseva+BAMBOO_PAGE_SIZE*(to_index+1);
- gc_cache_revise_information.to_page_index=to_index;
- }
- }
-}
-
+void samplingDataReviseInit(struct moveHelper * orig,struct moveHelper * to);
+void completePageConvert(void * origptr, void * toptr, void * current_ptr);
void cacheAdapt_gc(bool isgccachestage);
void cacheAdapt_master();
void cacheAdapt_mutator();
#define CACHEADAPT_SAMPLING_DATA_REVISE_INIT(o,t) \
samplingDataReviseInit((o),(t))
-#define CACHEADAPT_SAMPLING_DATA_CONVERT(p) samplingDataConvert((p))
+//#define CACHEADAPT_SAMPLING_DATA_CONVERT(p) samplingDataConvert((p))
#define CACHEADAPT_COMPLETE_PAGE_CONVERT(o, t, p) \
completePageConvert((o), (t), (p));
volatile bool gccachestage;
// table recording the sampling data collected for cache adaption
int * gccachesamplingtbl;
-int * gccachesamplingtbl_local;
-unsigned int size_cachesamplingtbl_local;
+int * gccachesamplingtbl_local;// for zeroing memory only
+unsigned int size_cachesamplingtbl_local; // for zeroing memory only
int * gccachesamplingtbl_r;
-int * gccachesamplingtbl_local_r;
-unsigned int size_cachesamplingtbl_local_r;
+int * gccachesamplingtbl_local_r; // for zeroing memory only
+unsigned int size_cachesamplingtbl_local_r; // for zeroing memory only
int * gccachepolicytbl;
unsigned int size_cachepolicytbl;
#endif
// init the orig ptr
orig->localblocknum = 0;
orig->ptr=orig->base = to->base;
- orig->bound = orig->base + BLOCKSIZE(orig->localblocknum);
+ orig->bound=orig->base+BLOCKSIZE(orig->localblocknum);
#ifdef GC_CACHE_ADAPT
to->pagebound=to->base+BAMBOO_PAGE_SIZE;
orig->pagebound=orig->base+BAMBOO_PAGE_SIZE;
to->localblocknum++;
BASEPTR(to->base,BAMBOO_NUM_OF_CORE, to->localblocknum);
to->ptr=to->base;
- to->bound = to->base + BLOCKSIZE(to->localblocknum);
+ to->bound=to->base+BLOCKSIZE(to->localblocknum);
#ifdef GC_CACHE_ADAPT
to->pagebound=to->base+BAMBOO_PAGE_SIZE;
#endif
unsigned int globalblocknum;
BLOCKINDEX(globalblocknum, to->ptr);
to->base = gcbaseva + OFFSET2BASEVA(globalblocknum);
- to->bound = gcbaseva + BOUNDPTR(globalblocknum);
+ to->bound=gcbaseva+BOUNDPTR(globalblocknum);
#ifdef GC_CACHE_ADAPT
to->pagebound=(void *)((int)((int)(to->ptr)&(~(BAMBOO_PAGE_SIZE-1)))+BAMBOO_PAGE_SIZE);
#endif
void compacthelper(struct moveHelper * orig,struct moveHelper * to) {
bool senttopmessage=false;
while(true) {
- if ((gccurr_heaptop < ((unsigned INTPTR)(to->bound-to->ptr)))&&!senttopmessage) {
+ if ((gccurr_heaptop <= ((unsigned INTPTR)(to->bound-to->ptr)))&&!senttopmessage) {
//This block is the last for this core...let the startup know
if (BAMBOO_NUM_OF_CORE==STARTUPCORE) {
handleReturnMem(BAMBOO_NUM_OF_CORE, to->ptr+gccurr_heaptop);
orig->localblocknum++;
BASEPTR(orig->base,BAMBOO_NUM_OF_CORE, orig->localblocknum);
orig->ptr=orig->base;
- orig->bound = orig->base + BLOCKSIZE(orig->localblocknum);
+ orig->bound=orig->base+BLOCKSIZE(orig->localblocknum);
#ifdef GC_CACHE_ADAPT
orig->pagebound=orig->base+BAMBOO_PAGE_SIZE;
#endif
}
#ifdef GC_CACHE_ADAPT
-/* To compute access rate per pages, we need to compact to page boundary
- * instead of block boundary
- */
-unsigned int compactpages(struct moveHelper * orig, struct moveHelper * to) {
- void *toptrinit=to->ptr;
- void *toptr=toptrinit;
- void *tobound=to->bound;
- void *topagebound=to->pagebound;
+unsigned int compactblockshelper(struct moveHelper * orig, struct moveHelper * to) {
+ unsigned int minimumbytes=0;
void *origptr=orig->ptr;
- void *origpagebound=orig->pagebound;
- unsigned INTPTR origendoffset=ALIGNTOTABLEINDEX((unsigned INTPTR)(origpagebound-gcbaseva));
- unsigned int objlength;
- while((origptr<origpagebound)&&(toptr<topagebound)){
- //Try to skip over stuff fast first
- unsigned INTPTR offset=(unsigned INTPTR) (origptr-gcbaseva);
- unsigned INTPTR arrayoffset=ALIGNTOTABLEINDEX(offset);
- if (!gcmarktbl[arrayoffset]) {
- do {
- arrayoffset++;
- if (arrayoffset>=origendoffset) {
- //finished with a page...
- origptr=origpagebound;
- to->ptr=toptr;
- orig->ptr=origptr;
- orig->pagebound+=BAMBOO_PAGE_SIZE;
- gccurr_heaptop-=(unsigned INTPTR)(toptr-toptrinit);
- // close the last destination page
- CACHEADAPT_COMPLETE_PAGE_CONVERT(origptr, toptr, toptr);
- return 0;
- }
- } while(!gcmarktbl[arrayoffset]);
- origptr=CONVERTTABLEINDEXTOPTR(arrayoffset);
- }
-
- //Scan more carefully next
- objlength=getMarkedLength(origptr);
-
- if (objlength!=NOTMARKED) {
- unsigned int length=ALIGNSIZETOBYTES(objlength);
-
- //code between this and next comment should be removed
-#ifdef GC_DEBUG
- unsigned int size;
- unsigned int type;
- gettype_size(origptr, &type, &size);
- size=((size-1)&(~(ALIGNMENTSIZE-1)))+ALIGNMENTSIZE;
-
- if (size!=length) {
- tprintf("BAD SIZE IN BITMAP: type=%u object=%x size=%u length=%u\n", type, origptr, size, length);
- unsigned INTPTR alignsize=ALIGNOBJSIZE((unsigned INTPTR)(origptr-gcbaseva));
- unsigned INTPTR hibits=alignsize>>4;
- unsigned INTPTR lobits=(alignsize&15)<<1;
- tprintf("hibits=%x lobits=%x\n", hibits, lobits);
- tprintf("hi=%x lo=%x\n", gcmarktbl[hibits], gcmarktbl[hibits+1]);
- }
-#endif
- //end of code to remove
-
- void *endtoptr=toptr+length;
- if (endtoptr>tobound) {
- gccurr_heaptop-=(unsigned INTPTR)(toptr-toptrinit);
- to->ptr=tobound;
- orig->ptr=origptr;
- // close a destination page, update the revise profiling info
- CACHEADAPT_COMPLETE_PAGE_CONVERT(origptr, tobound, toptr);
- return length;
- }
- //good to move objects and update pointers
- //tprintf("Decided to compact obj %x to %x\n", origptr, toptr);
-
- gcmappingtbl[OBJMAPPINGINDEX(origptr)]=toptr;
-
- origptr+=length;
- toptr=endtoptr;
- } else
- origptr+=ALIGNMENTSIZE;
+ void *origbound=orig->bound;
+ while(origptr<origbound) {
+ //call compactblocks using the page boundaries at the current bounds
+ minimumbytes=compactblocks(orig, to);
+ if(minimumbytes == 0) {
+ //update cacheadpate information and the page bounds
+ origptr=orig->ptr;
+ void *toptr=to->ptr;
+ orig->pagebound=(void *)((int)(((int)origptr)&(~(BAMBOO_PAGE_SIZE-1)))+BAMBOO_PAGE_SIZE);
+ to->pagebound=(void *)((int)(((int)toptr)&(~(BAMBOO_PAGE_SIZE-1)))+BAMBOO_PAGE_SIZE);
+ // close the last destination page
+ CACHEADAPT_COMPLETE_PAGE_CONVERT(origptr, toptr, toptr);
+ } else {
+ // require more memory
+ return minimumbytes;
+ }
}
- to->ptr=toptr;
- orig->ptr=origptr;
- orig->pagebound=(void *)((int)(((int)origptr)&(~(BAMBOO_PAGE_SIZE-1)))+BAMBOO_PAGE_SIZE);
- to->pagebound=(void *)((int)(((int)toptr)&(~(BAMBOO_PAGE_SIZE-1)))+BAMBOO_PAGE_SIZE);
- gccurr_heaptop-=(unsigned INTPTR)(toptr-toptrinit);
- // close the last destination page
- CACHEADAPT_COMPLETE_PAGE_CONVERT(origptr, toptr, toptr);
- return 0;
+ // when you move to a different block return to the compacthelper
+ return minimumbytes;
}
+#endif
-#else
/* This function is performance critical... spend more time optimizing it */
unsigned int compactblocks(struct moveHelper * orig, struct moveHelper * to) {
void *toptr=toptrinit;
void *tobound=to->bound;
void *origptr=orig->ptr;
+#ifdef GC_CACHE_ADAPT
+ void *origbound=orig->pagebound;
+ void *topagebound=to->pagebound;
+#else
void *origbound=orig->bound;
+#endif
unsigned INTPTR origendoffset=ALIGNTOTABLEINDEX((unsigned INTPTR)(origbound-gcbaseva));
unsigned int objlength;
+#ifdef GC_CACHE_ADAPT
+ while((origptr<origbound)&&(toptr<topagebound)){
+#else
while(origptr<origbound) {
+#endif
//Try to skip over stuff fast first
unsigned INTPTR offset=(unsigned INTPTR) (origptr-gcbaseva);
unsigned INTPTR arrayoffset=ALIGNTOTABLEINDEX(offset);
do {
arrayoffset++;
if (arrayoffset>=origendoffset) {
- //finished with block...
+ //finished with block(a page in CACHE_ADAPT version)...
origptr=origbound;
to->ptr=toptr;
orig->ptr=origptr;
gccurr_heaptop-=(unsigned INTPTR)(toptr-toptrinit);
to->ptr=tobound;
orig->ptr=origptr;
+#ifdef GC_CACHE_ADAPT
+ // close a destination page, update the revise profiling info
+ CACHEADAPT_COMPLETE_PAGE_CONVERT(origptr, tobound, toptr);
+#endif
return length;
}
//good to move objects and update pointers
return 0;
}
-#endif
-
void compact() {
BAMBOO_ASSERT(COMPACTPHASE == gc_status_info.gcphase);
void * ptr; // current pointer into block
void * bound; // upper bound of current block
#ifdef GC_CACHE_ADAPT
- void * pagebound; // upper bound of current available page
+ void * pagebound; // upper bound of current page
#endif
};
void compacthelper(struct moveHelper * orig,struct moveHelper * to);
void compact();
void compact_master(struct moveHelper * orig, struct moveHelper * to);
+unsigned int compactblocks(struct moveHelper * orig,struct moveHelper * to);
#ifdef GC_CACHE_ADAPT
-unsigned int compactpages(struct moveHelper * orig,struct moveHelper * to);
-#define COMPACTUNITS(o,t) compactpages((o), (t))
+unsigned int compactblockshelper(struct moveHelper * orig,struct moveHelper * to);
+#define COMPACTUNITS(o,t) compactblockshelper((o), (t))
#else
-unsigned int compactblocks(struct moveHelper * orig,struct moveHelper * to);
#define COMPACTUNITS(o,t) compactblocks((o), (t))
#endif
#endif // MULTICORE_GC