towards fixing bugs...
authorbdemsky <bdemsky>
Wed, 13 Jul 2011 08:40:11 +0000 (08:40 +0000)
committerbdemsky <bdemsky>
Wed, 13 Jul 2011 08:40:11 +0000 (08:40 +0000)
Robust/src/Runtime/bamboo/multicorecache.c
Robust/src/Runtime/bamboo/multicorecache.h
Robust/src/Runtime/bamboo/multicoregarbage.c
Robust/src/Runtime/bamboo/multicoregarbage.h
Robust/src/Runtime/bamboo/multicoregccompact.c
Robust/src/Runtime/bamboo/multicoremem.h

index 2de873f0192a9e1b4163313250bd72e2166b1faf..377bc698a11271e5b41eecf1dd11a9972d1d9aeb 100644 (file)
 #include "multicoremsg.h"
 #include "multicoregcprofile.h"
 
-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_BITS;
-  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_BITS;
-  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;
-}
+void cacheadapt_finish_src_page(void *srcptr, void *tostart, void *tofinish) {
+  unsigned int srcpage=(srcptr-gcbaseva)>>BAMBOO_PAGE_SIZE_BITS;
+  unsigned int dstpage=(tostart-gcbase)>>BAMBOO_PAGE_SIZE_BITS;
+  unsigned int numbytes=tofinish-tostart;
+  
+  unsigned int * oldtable=&gccachesamplingtbl[srcpage*NUMCORESACTIVE];
+  unsigned int * newtable=&gccachesamplingtbl_r[dstpage*NUMCORESACTIVE];
+  
+  unsigned int page64th=numbytes>>(BAMBOO_PAGE_SIZE_BITS-6);
 
-/* 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)>>BAMBOO_PAGE_SIZE_BITS;
-      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)>>BAMBOO_PAGE_SIZE_BITS;
-      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++;
+  for(int core = 0; core < NUMCORESACTIVE; core++) {
+    (*newtable)+=page64th*(*oldtable);
+    newtable++;
+    oldtable++;
+  }  
 }
 
-/* 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)>>BAMBOO_PAGE_SIZE_BITS;
-      newtable++;
-      oldtable++;
-      oldtable_next++;
-    }
+void cacheadapt_finish_dst_page(void *origptr, void *tostart, void *toptr, unsigned int bytesneeded) {
+  unsigned int numbytes=toptr-tostart;
 
-    // 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++;
-  }
-}
+  void *tobound=(tostart&~(BAMBOO_PAGE_SIZE-1))+BAMBOO_PAGE_SIZE;
+  void *origbound=(origstart&~(BAMBOO_PAGE_SIZE-1))+BAMBOO_PAGE_SIZE;
+  
+  unsigned int topage=(tostart-gcbase)>>BAMBOO_PAGE_SIZE_BITS; 
+  unsigned int origpage=(origptr-gcbaseva)>>BAMBOO_PAGE_SIZE_BITS;
 
-/* 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];
+  unsigned int * totable=&gccachesamplingtbl_r[topage*NUMCORESACTIVE];
+  unsigned int * origtable=&gccachesamplingtbl[origpage*NUMCORESACTIVE];
 
-  for(int tt = 0; tt < NUMCORESACTIVE; tt++) {
-    (*newtable)=(*newtable)+((*oldtable)*to_factor)>>BAMBOO_PAGE_SIZE_BITS;
-    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;
+  unsigned int remaintobytes=tobound-toptr;
+  unsigned int remainorigbytes=origbound-origptr;
 
-  // 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;
-  }
+  do {
+    //round source bytes down....don't want to close out page if not necessary
+    remainorigbytes=(remainorigbytes>bytesneeded)?bytesneeded:remainorigbytes;
 
-  // compute the revised profiling info for the following closed destination
-  // pages
-  restClosedPageConvert(current_ptr, main_factor, delta_factor);
+    if (remaintobytes<=remainorigbytes) {
+      //Need to close out to page
 
-  // compute the revised profiling info for the last destination page if needed
-  lastPageConvert(current_ptr);
-}
+      numbytes+=remaintobytes;
+      unsigned int page64th=numbytes>>(BAMBOO_PAGE_SIZE_BITS-6);
 
-/* 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)>>BAMBOO_PAGE_SIZE_BITS;
-        newtable++;
-        oldtable++;
+      for(int core = 0; core < NUMCORESACTIVE; core++) {
+       (*totable)=(*totable+page64th*(*origtable))>>6;
+       totable++;
+       origtable++;
       }
+      toptr+=remaintobytes;
+      origptr+=remaintobytes;
+      bytesneeded-=remaintobytes;
+      topage++;//to page is definitely done
+      tobound+=BAMBOO_PAGE_SIZE;
+      origpage=(origptr-gcbaseva)>>BAMBOO_PAGE_SIZE_BITS;//handle exact match case
+      origbound=(origptr&~(BAMBOO_PAGE_SIZE-1))+BAMBOO_PAGE_SIZE;
+    } else {
+      //Finishing off orig page
+
+      numbytes+=remainorigbytes;
+      unsigned int page64th=numbytes>>(BAMBOO_PAGE_SIZE_BITS-6);
+      
+      for(int core = 0; core < NUMCORESACTIVE; core++) {
+       (*totable)+=page64th*(*origtable);
+       totable++;
+       origtable++;
+      }
+      toptr+=remainorigbytes;
+      origptr+=remainorigbytes;
+      bytesneeded-=remainorigbytes;
+      origpage++;//just orig page is done
+      origbound+=BAMBOO_PAGE_SIZE;
     }
-  }
-} 
-
-/* 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_BITS;
-    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_BITS;
-      gc_cache_revise_information.to_page_end_va=gcbaseva+BAMBOO_PAGE_SIZE*(to_index+1);
-      gc_cache_revise_information.to_page_index=to_index;
-    }
-  }
+    totable=&gccachesamplingtbl_r[topage*NUMCORESACTIVE];
+    origtable=&gccachesamplingtbl[origpage*NUMCORESACTIVE];
+    
+    remaintobytes=tobound-toptr;
+    remainorigbytes=origbound-origptr;
+    
+    numbytes=0;
+  } while(bytesneeded!=0);
 }
 
 // prepare for cache adaption:
@@ -234,7 +108,7 @@ void cacheAdapt_gc(bool isgccachestage) {
 // 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*NUMCORESACTIVE]; \
+    unsigned int *local_tbl=&gccachesamplingtbl_r[page_index*NUMCORESACTIVE];  \
     for(int i = 0; i < NUMCORESACTIVE; i++) { \
       int freq = *local_tbl; \
       local_tbl++; \
@@ -248,7 +122,7 @@ void cacheAdapt_gc(bool isgccachestage) {
 // 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*NUMCORESACTIVE]; \
+    unsigned int *local_tbl=&gccachesamplingtbl_r[page_index*NUMCORESACTIVE];  \
     for(int i = 0; i < NUMCORESACTIVE; i++) { \
       int freq = *local_tbl; \
       local_tbl++; \
@@ -280,7 +154,7 @@ void cacheAdapt_policy_h4h(int coren){
   unsigned int page_index=page_gap*coren;
   unsigned int page_index_end=(coren==NUMCORESACTIVE-1)?page_num:(page_index+page_gap);
   VA page_sva = gcbaseva+(BAMBOO_PAGE_SIZE)*page_index;
-  int * tmp_p = gccachepolicytbl;
+  unsigned int * tmp_p = gccachepolicytbl;
   for(; page_index < page_index_end; page_index++) {
     bamboo_cache_policy_t policy = {0};
     policy.cache_mode = BAMBOO_CACHE_MODE_HASH;
@@ -296,7 +170,7 @@ void cacheAdapt_policy_local(int coren){
   unsigned int page_index=page_gap*coren;
   unsigned int page_index_end=(coren==NUMCORESACTIVE-1)?page_num:(page_index+page_gap);
   VA page_sva = gcbaseva+(BAMBOO_PAGE_SIZE)*page_index;
-  int * tmp_p = gccachepolicytbl;
+  unsigned int * tmp_p = gccachepolicytbl;
   for(; page_index < page_index_end; page_index++) {
     bamboo_cache_policy_t policy = {0};
     unsigned int block = 0;
@@ -314,7 +188,7 @@ void cacheAdapt_policy_hottest(int coren){
   unsigned int page_index=page_gap*coren;
   unsigned int page_index_end=(coren==NUMCORESACTIVE-1)?page_num:(page_index+page_gap);
   VA page_sva = gcbaseva+(BAMBOO_PAGE_SIZE)*page_index;
-  int * tmp_p = gccachepolicytbl;
+  unsigned int * tmp_p = gccachepolicytbl;
   for(; page_index < page_index_end; page_index++) {
     bamboo_cache_policy_t policy = {0};
     unsigned int hottestcore = 0;
@@ -345,7 +219,7 @@ void cacheAdapt_policy_dominate(int coren){
   unsigned int page_index=page_gap*coren;
   unsigned int page_index_end=(coren==NUMCORESACTIVE-1)?page_num:(page_index+page_gap);
   VA page_sva = gcbaseva+(BAMBOO_PAGE_SIZE)*page_index;
-  int * tmp_p = gccachepolicytbl;
+  unsigned int * tmp_p = gccachepolicytbl;
   for(; page_index < page_index_end; page_index++) {
     bamboo_cache_policy_t policy = {0};
     unsigned int hottestcore = 0;
@@ -394,7 +268,7 @@ unsigned int cacheAdapt_decision(int coren) {
 void cacheAdapt_mutator() {
   BAMBOO_CACHE_MF();
   // check the changes and adapt them
-  int * tmp_p = gccachepolicytbl;
+  unsigned int * tmp_p = gccachepolicytbl;
   unsigned int page_sva = gcbaseva;
   for(; page_sva<gctopva; page_sva+=BAMBOO_PAGE_SIZE) {
     // read out the policy
@@ -481,16 +355,28 @@ void gc_output_cache_sampling() {
     unsigned int block = 0;
     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];
+    //printf("%x,  %d,  %d,  ",(int)page_sva,page_index,coren);
+    unsigned int * local_tbl = &gccachesamplingtbl[page_index*NUMCORESACTIVE];
+    int accesscore = 0;
     for(int i = 0; i < NUMCORESACTIVE; i++) {
       int freq = *local_tbl;
       local_tbl++;
-      //if(freq != 0) {
+      if(freq != 0) {
+        accesscore++;
+        //printf("%d,  ", freq);
+      }
+    }
+    if(accesscore!=0) {
+      printf("%x,  %d,  %d,  ",(int)page_sva,page_index,coren);
+      unsigned int * local_tbl = &gccachesamplingtbl[page_index*NUMCORESACTIVE];
+      for(int i = 0; i < NUMCORESACTIVE; i++) {
+        int freq = *local_tbl;
+        local_tbl++;
         printf("%d,  ", freq);
-      //}
+      }
+      printf("\n");
     }
-    printf("\n");
+    //printf("\n");
   }
   printf("=================\n");
 } 
@@ -515,27 +401,29 @@ void gc_output_cache_sampling_r() {
     unsigned int block = 0;
     BLOCKINDEX(block, (void *)page_sva);
     unsigned int coren = gc_block2core[block%(NUMCORES4GC*2)];
-    printf(" %x,  %d,  %d,  ",(int)page_sva,page_index,coren);
+    //printf("%x,  %d,  %d,  ",(int)page_sva,page_index,coren);
     int accesscore = 0; // TODO
-    int * local_tbl = &gccachesamplingtbl_r[page_index*NUMCORESACTIVE];
+    unsigned int * local_tbl = &gccachesamplingtbl_r[page_index*NUMCORESACTIVE];
     for(int i = 0; i < NUMCORESACTIVE; i++) {
       int freq = *local_tbl; 
-      printf("%d,  ", freq);
+      //printf("%d,  ", freq);
       if(freq != 0) {
         accesscore++;// TODO
       }
       local_tbl++;
     }
     if(accesscore!=0) {
-      int * local_tbl = &gccachesamplingtbl_r[page_index*NUMCORESACTIVE];
+      printf("%x,  %d,  %d,  ",(int)page_sva,page_index,coren);
+      unsigned int * local_tbl = &gccachesamplingtbl_r[page_index*NUMCORESACTIVE];
       for(int i = 0; i < NUMCORESACTIVE; i++) {
         int freq = *local_tbl;
+        printf("%d,  ", freq);
         sumdata[accesscore-1][i]+=freq;
         local_tbl++;
       }
-    }
-  
-    printf("\n");
+      printf("\n");
+    }  
+    //printf("\n");
   }
   printf("+++++\n");
   // TODO printout the summary data
index c3e42b7feafb754bc28fd85c2c9b0cf48dc06c6e..cf4db76d8f816b3885dc70f0f0da0cb879b2133b 100644 (file)
@@ -40,30 +40,8 @@ typedef union
 #define BAMBOO_CACHE_MODE_NONE 3   // no caching
 #define BAMBOO_CACHE_MODE_COORDS 4 // cached on a specific core
 
-// data structure to hold page information while calculating revised sampling 
-// info during compaction
-typedef struct gc_cache_revise_info {
-  // the start address in current original page to be compacted to current 
-  // destination page
-  void * orig_page_start_va; 
-  // the end of current original page to be compacted
-  void * orig_page_end_va;
-  // the index of current original page
-  unsigned int orig_page_index;
-  // the start address in current destination page to where the current original
-  // page is compacted
-  void * to_page_start_va;
-  // the end of current destination page
-  void * to_page_end_va;
-  // the index of current destination page
-  unsigned int to_page_index;
-} gc_cache_revise_info_t;
-
-// global variable holding page information to compute revised sampling info
-extern gc_cache_revise_info_t gc_cache_revise_information;
-
-void samplingDataReviseInit(struct moveHelper * orig,struct moveHelper * to);
-void completePageConvert(void * origptr, void * toptr, void * current_ptr); 
+void cacheadapt_finish_src_page(void *srcptr, void *tostart, void *tofinish);
+void cacheadapt_finish_dst_page(void *origptr, void *tostart, void *toptr, unsigned int bytesneeded);
 void cacheAdapt_gc(bool isgccachestage);
 void cacheAdapt_master();
 void cacheAdapt_mutator();
@@ -93,11 +71,8 @@ void gc_output_cache_sampling_r();
 #define CACHEADAPT_SAMPLING_RESET() 
 #endif
 
-#define CACHEADAPT_SAMPLING_DATA_REVISE_INIT(o,t) \
-  samplingDataReviseInit((o),(t))
-//#define CACHEADAPT_SAMPLING_DATA_CONVERT(p) samplingDataConvert((p))
-#define CACHEADAPT_COMPLETE_PAGE_CONVERT(o, t, p) \
-  completePageConvert((o), (t), (p));
+#define CACHEADAPT_FINISH_SRC_PAGE(a,b,c) cacheadapt_finish_src_page(a,b,c);
+#define CACHEADAPT_FINISH_DST_PAGE(a,b,c,d) cacheadapt_finish_dst_page(a,b,c,d);
 
 #define CACHEADAPT_GC(b) cacheAdapt_gc(b)
 #define CACHEADAPT_MASTER() cacheAdapt_master()
@@ -131,9 +106,8 @@ void gc_output_cache_sampling_r();
 #define CACHEADAPT_ENABLE_TIMER() 
 #define CACHEADAPT_DISABLE_TIMER() 
 #define CACHEADAPT_SAMPING_RESET()
-#define CACHEADAPT_SAMPLING_DATA_REVISE_INIT(o,t) 
-#define CACHEADAPT_SAMPLING_DATA_CONVERT(p) 
-#define CACHEADAPT_COMPLETE_PAGE_CONVERT(o, t, p, b) 
+#define CACHEADAPT_FINISH_SRC_PAGE(a,b,c)
+#define CACHEADAPT_FINISH_DST_PAGE(a,b,c,d)
 #define CACHEADAPT_GC(b)
 #define CACHEADAPT_MASTER()
 #define CACHEADAPT_PHASE_CLIENT() 
index 1840d85527bd8d85fac223ffdb878baaf5555f24..3a42576892a38f6d8cbd0a2f52f5cc265fa8bd56 100644 (file)
@@ -117,9 +117,6 @@ void initmulticoregcdata() {
 #ifdef MGC_SPEC
   gc_profile_flag = false;
 #endif
-#ifdef GC_CACHE_ADAPT
-  gccachestage = false;
-#endif 
 
   if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
     allocationinfo.blocktable=RUNMALLOC(sizeof(struct blockrecord)*GCNUMBLOCK);
@@ -484,7 +481,7 @@ void gc_master(struct garbagelist * stackptr) {
 
   master_finish();
 
-  //tprintf("finish GC ! %d \n",gcflag);
+  tprintf("finish GC ! %d \n",gcflag);
 } 
 
 void pregccheck() {
index 717169b09cf3a84dfbe431b4757b107efc2118e0..34428b8cadb0b4c27812f924d0647757eb67deb4 100644 (file)
@@ -146,13 +146,13 @@ struct allocrecord allocationinfo;
 #ifdef GC_CACHE_ADAPT
 volatile bool gccachestage;
 // table recording the sampling data collected for cache adaption 
-int * gccachesamplingtbl;
-int * gccachesamplingtbl_local;// for zeroing memory only
+unsigned int * gccachesamplingtbl;
+unsigned int * gccachesamplingtbl_local;// for zeroing memory only
 unsigned int size_cachesamplingtbl_local; // for zeroing memory only
-int * gccachesamplingtbl_r;
-int * gccachesamplingtbl_local_r; // 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
-int * gccachepolicytbl;
+unsigned int * gccachepolicytbl;
 unsigned int size_cachepolicytbl;
 #endif
 
index 8117b6cf66e06a726dfded1cbbf3ec338b89367e..ea3264cf192b7d4434cf1b0a54e5b8521dafdfcf 100644 (file)
@@ -367,24 +367,38 @@ unsigned int compactblockshelper(struct moveHelper * orig, struct moveHelper * t
   unsigned int minimumbytes=0;
   void *origptr=orig->ptr;
   void *origbound=orig->bound;
-  while(origptr<origbound) {
+  void * tmporig=orig->ptr;
+  void * tmpto=to->ptr;
+
+  while(true) {
     //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);
+      //bump the orig page bound...
+      //use old orig pointer to make sure we get correct block
+      CACHEADAPT_FINISH_SRC_PAGE(tmporig, tmpto, to->ptr);
+      if (orig->ptr<origbound) {
+       tmporig=orig->ptr;
+       tmpto=to->ptr;
+       orig->pagebound=orig->pagebound+BAMBOO_PAGE_SIZE;
+      } else {
+       return 0;
+      }
     } else {
       // require more memory
-      return minimumbytes;
-    } 
+      void *endtoptr=to->ptr+minimumbytes;
+      if (endtoptr>to->bound) {
+       CACHEADAPT_FINISH_DST_PAGE(orig->ptr, tmpto, to->ptr, 0);
+       return minimumbytes;
+      } else {
+       CACHEADAPT_FINISH_DST_PAGE(orig->ptr, tmpto, to->ptr, minimumbytes);
+       to->pagebound=((endtoptr-1)&~(BAMBOO_PAGE_SIZE-1))+BAMBOO_PAGE_SIZE;
+       //update pointers to avoid double counting the stuff we already added in
+       tmporig=orig->ptr+minimumbytes;
+       tmpto=to->ptr+minimumbytes;
+      }
+    }
   }
-  // when you move to a different block return to the compacthelper
-  return minimumbytes;
 }
 #endif
 
@@ -393,21 +407,18 @@ unsigned int compactblockshelper(struct moveHelper * orig, struct moveHelper * t
 unsigned int compactblocks(struct moveHelper * orig, struct moveHelper * to) {
   void *toptrinit=to->ptr;
   void *toptr=toptrinit;
-  void *tobound=to->bound;
   void *origptr=orig->ptr;
 #ifdef GC_CACHE_ADAPT
   void *origbound=orig->pagebound;
-  void *topagebound=to->pagebound;
+  void *tobound=to->pagebound;
 #else
   void *origbound=orig->bound;
+  void *tobound=to->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);
@@ -416,16 +427,15 @@ unsigned int compactblocks(struct moveHelper * orig, struct moveHelper * to) {
        arrayoffset++;
        if (arrayoffset>=origendoffset) {
          //finished with block(a page in CACHE_ADAPT version)...
-         origptr=origbound;
          to->ptr=toptr;
-         orig->ptr=origptr;
+         orig->ptr=origbound;
          gccurr_heaptop-=(unsigned INTPTR)(toptr-toptrinit);
          return 0;
        }
       } while(!gcmarktbl[arrayoffset]);
       origptr=CONVERTTABLEINDEXTOPTR(arrayoffset);
     }
-
+    
     //Scan more carefully next
     objlength=getMarkedLength(origptr);
 
@@ -452,19 +462,15 @@ unsigned int compactblocks(struct moveHelper * orig, struct moveHelper * to) {
 
       void *endtoptr=toptr+length;
       if (endtoptr>tobound) {
-  gccurr_heaptop-=(unsigned INTPTR)(toptr-toptrinit);
-       to->ptr=tobound;
+       gccurr_heaptop-=(unsigned INTPTR)(toptr-toptrinit);
+       to->ptr=toptr;
        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
-
+      
       gcmappingtbl[OBJMAPPINGINDEX(origptr)]=toptr;
-
+      
       origptr+=length;
       toptr=endtoptr;
     } else
index 1d8f5aa3e77d6c1e89b6bb57c8fb9ed7ba6f5e6e..21fb53dfd2eb49afc38fad434b0f92f73afcbcc6 100644 (file)
@@ -31,7 +31,7 @@
 #endif
 #endif
 
-#define BAMBOO_SHARED_RUNTIME_PAGE_SIZE (1<<24)  //16M
+#define BAMBOO_SHARED_RUNTIME_PAGE_SIZE ((unsigned int)(1<<24))  //16M
 
 #define BAMBOO_PAGE_SIZE ((unsigned int)(64 * 1024)) // 64K
 #define BAMBOO_PAGE_SIZE_BITS (16)