Add gcprofile to PMC garbage collector and compute the size of allocated obj instead...
[IRC.git] / Robust / src / Runtime / bamboo / pmc_garbage.c
index 0a769c3b5d84c9d50b80d3565c85285576764ff4..334005f9ff333d30afb7d90e054357bac86e1e95 100644 (file)
@@ -1,5 +1,6 @@
 #include "multicoregc.h"
 #include "multicoreruntime.h"
+#include "multicoregcprofile.h"
 #include "pmc_garbage.h"
 #include "runtime_arch.h"
 #include "pmc_mark.h"
@@ -46,9 +47,11 @@ void pmc_onceInit() {
        pmc_heapptr->regions[i].lastptr=pmc_heapptr->units[i*4-1].endptr;
       pmc_heapptr->regions[i].lowunit=4*i;
       pmc_heapptr->regions[i].highunit=4*(i+1);
-      pmc_heapptr->regions[i+1].lastptr=pmc_heapptr->units[(i+1)*4+3].endptr;
-      pmc_heapptr->regions[i+1].lowunit=4*(i+1);
-      pmc_heapptr->regions[i+1].highunit=4*(i+2);
+      if ((i+1)<NUMCORES4GC) {
+       pmc_heapptr->regions[i+1].lastptr=pmc_heapptr->units[(i+1)*4+3].endptr;
+       pmc_heapptr->regions[i+1].lowunit=4*(i+1);
+       pmc_heapptr->regions[i+1].highunit=4*(i+2);
+      }
     }
     //for(int i=0;i<NUMCORES4GC;i++) {
       //tprintf("%u lastptr=%x\n", i, pmc_heapptr->regions[i].lastptr);
@@ -61,10 +64,10 @@ void pmc_init() {
     pmc_heapptr->numthreads=NUMCORES4GC;
     for(int i=0;i<NUMCORES4GC;i+=2) {
       void *startptr=pmc_heapptr->regions[i].lastptr;
-      void *finishptr=pmc_heapptr->regions[i+1].lastptr;
+      void *finishptr=(i+1)<NUMCORES4GC?pmc_heapptr->regions[i+1].lastptr:pmc_heapptr->regions[i].endptr;
       struct pmc_region *region=&pmc_heapptr->regions[i];
       unsigned int startindex=region->lowunit;
-      unsigned int endindex=pmc_heapptr->regions[i+1].highunit;
+      unsigned int endindex=(i+1)<NUMCORES4GC?pmc_heapptr->regions[i+1].highunit:pmc_heapptr->regions[i].highunit;
       //tprintf("Free space in partition %u from %x to %x\n", i, startptr, finishptr);
       for(unsigned int index=startindex;index<endindex;index++) {
        void *ptr=pmc_heapptr->units[index].endptr;
@@ -90,31 +93,49 @@ void gc(struct garbagelist *gl) {
 #ifdef PERFCOUNT
   profile_start(GC_REGION);
 #endif
-  if (BAMBOO_NUM_OF_CORE==STARTUPCORE)
+  if (BAMBOO_NUM_OF_CORE==STARTUPCORE) {
     tprintf("start GC\n");
+    GCPROFILE_START_MASTER();
+  }
   pmc_init();
+  if (BAMBOO_NUM_OF_CORE==STARTUPCORE) {
+    GCPROFILE_ITEM_MASTER();
+  }
   //mark live objects
   //tprintf("mark\n");
   pmc_mark(gl);
   //count live objects per unit
   tmc_spin_barrier_wait(&pmc_heapptr->barrier);
+  if (BAMBOO_NUM_OF_CORE==STARTUPCORE) {
+    GCPROFILE_ITEM_MASTER();
+  }
   //tprintf("count\n");
   pmc_count();
   tmc_spin_barrier_wait(&pmc_heapptr->barrier);
+  if (BAMBOO_NUM_OF_CORE==STARTUPCORE) {
+    GCPROFILE_ITEM_MASTER();
+  }
   //divide up work
   //tprintf("divide\n");
   if (BAMBOO_NUM_OF_CORE==STARTUPCORE) {
     pmc_processunits();
+    GCPROFILE_ITEM_MASTER();
   }
   tmc_spin_barrier_wait(&pmc_heapptr->barrier);
   //set up forwarding pointers
   //tprintf("forward\n");
   pmc_doforward();
   tmc_spin_barrier_wait(&pmc_heapptr->barrier);
+  if (BAMBOO_NUM_OF_CORE==STARTUPCORE) {
+    GCPROFILE_ITEM_MASTER();
+  }
   //update pointers
   //tprintf("updaterefs\n");
   pmc_doreferenceupdate(gl);
   tmc_spin_barrier_wait(&pmc_heapptr->barrier);
+  if (BAMBOO_NUM_OF_CORE==STARTUPCORE) {
+    GCPROFILE_ITEM_MASTER();
+  }
   //compact data
   //tprintf("compact\n");
   pmc_docompact();
@@ -134,6 +155,10 @@ void gc(struct garbagelist *gl) {
 
   gcflag=false;
   tmc_spin_barrier_wait(&pmc_heapptr->barrier);
+  if (BAMBOO_NUM_OF_CORE==STARTUPCORE) {
+    GCPROFILE_RECORD_SPACE_MASTER();
+    GCPROFILE_END_MASTER();
+  }
 
 #ifdef PERFCOUNT
   profile_start(APP_REGION);