code to compute unit boundaries and allocation function
authorbdemsky <bdemsky>
Wed, 6 Jul 2011 10:16:18 +0000 (10:16 +0000)
committerbdemsky <bdemsky>
Wed, 6 Jul 2011 10:16:18 +0000 (10:16 +0000)
Robust/src/Runtime/bamboo/pmc_forward.c
Robust/src/Runtime/bamboo/pmc_garbage.c
Robust/src/Runtime/bamboo/pmc_garbage.h
Robust/src/Runtime/bamboo/pmc_mem.c
Robust/src/Runtime/bamboo/pmc_mem.h

index a7d14fccf42d1137f54f6e837c4771e1d7d671c4..bb5bd7e2d31b521f38d100b014eba98444c439aa 100644 (file)
@@ -76,8 +76,10 @@ void pmc_doforward() {
     return;
   if (endregion==-1)
     endregion=NUMPMCUNITS;
-  region->startptr=(i==0)?gcbaseva:pmc_heapptr->units[i-1].endptr;
-  region->endptr=pmc_heapptr->units[i].endptr;
+  region->lowunit=startregion;
+  region->highunit=endregion;
+  region->startptr=(startregion==0)?gcbaseva:pmc_heapptr->units[startregion-1].endptr;
+  region->endptr=pmc_heapptr->units[endregion].endptr;
 
   if (BAMBOO_NUM_OF_CORE&1) {
     //backward direction
@@ -95,6 +97,26 @@ void pmc_forward(struct pmc_region *region, unsigned int totalbytes, void *botto
   void *tmpptr=bottomptr;
   void *forwardptr=fwddirection?bottomptr:(topptr-totalbytes);
   struct ___Object___ *lastobj=NULL;
+  unsigned int currunit=region->lowunit;
+  void *endunit=pmc_unitend(currunit);
+
+  if (!fwddirection) {
+    //reset boundaries of beginning units
+    while(endunit<forwardptr) {
+      pmc_heapptr->units[currunit].endptr=endunit;
+      currunit++;
+      endunit=pmc_unitend(currunit);
+    }
+  } else {
+    //reset boundaries of end units
+    unsigned int lastunit=region->highunit-1;
+    void * lastunitend=pmc_unitend(lastunit);
+    while(lastunitend>forwardptr) {
+      pmc_heapptr->units[currunit].endptr=lastunitend;
+      lastunit--;
+      lastunitend=pmc_unitend(lastunit);
+    }
+  }
 
   while(tmpptr>topptr) {
     unsigned int type;
@@ -108,7 +130,14 @@ void pmc_forward(struct pmc_region *region, unsigned int totalbytes, void *botto
 
     if (((struct ___Object___ *)tmpptr)->mark) {
       ((struct ___Object___ *)tmpptr)->mark=forwardptr;
-      forwardptr+=size;
+      void *newforwardptr=forwardptr+size;
+      while(newforwardptr>endunit) {
+       pmc_heapptr->region[currunit].endptr=newforwardptr;
+       currunit++;
+       endunit=pmc_unitend(currunit);
+      }
+
+      forwardptr=newforwardptr;
       if (lastobj&&!fwddirection) {
        tmpptr->backward=lastobj;
        lastobj=(struct ___Object___ *)tmpptr;
index 4d0d747217643d0f377971b4be2a39b8fd899e9f..0b8301a9f051b4c9a1cbb0cf46a1b9fb40853e99 100644 (file)
@@ -14,10 +14,17 @@ void decrementthreads() {
   tmc_spin_mutex_unlock(&pmc_heapptr->lock);
 }
 
+void * pmc_unitend(unsigned int index) {
+  return gcbaseva+(index+1)*NUMPMCUNITS;
+}
+
 void pmc_onceInit() {
   pmc_localqueue=&pmc_heapptr->regions[BAMBOO_NUM_OF_THREADS].markqueue;
   pmc_queueinit(pmc_localqueue);
   tmc_spin_barrier_init(&pmc_heapptr->barrier, NUMCORES4GC);
+  for(int i=0;i<NUMPMCUNITS;i++) {
+    pmc_heapptr->units[i].endptr=pmc_unitend(i);
+  }
 }
 
 void pmc_init() {
index 2be0312eccccc276f86cb47355991d96e3aaa18f..9f565252acf86f3df1e9787e3120f07e46055f42 100644 (file)
@@ -2,6 +2,7 @@
 #define PMC_GARBAGE_H
 #include <tmc/spin.h>
 
+#define PMC_MINALLOC 131072
 #define NUMPMCUNITS (4*NUMCORES4GC)
 #define UNITSIZE (BAMBOO_SHARED_MEM_SIZE/NUMPMCUNITS)
 
@@ -17,6 +18,8 @@ struct pmc_region {
   void * lastptr;
   void * startptr;
   void * endptr;
+  unsigned int lowunit;
+  unsigned int highunit;
   tmc_spin_mutex_t lock;
   struct ___Object___ * lastobj;
   struct pmc_queue markqueue;
@@ -32,6 +35,7 @@ struct pmc_heap {
 extern struct pmc_heap * pmc_heapptr;
 extern struct pmc_queue * pmc_localqueue;
 
+void * pmc_unitend(unsigned int index);
 void incrementthreads();
 void decrementthreads();
 void pmc_onceInit();
index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..a939bf30c4bc15ecb74af63859fbed0cb067cb58 100644 (file)
@@ -0,0 +1,41 @@
+#include "pmc_mem.h"
+
+void * pmc_alloc(unsigned int * numbytesallocated, unsigned int minimumbytes) {
+  unsigned int memcheck=minimumbytes>PMC_MINALLOC?minimumbytes:PMC_MINALLOC;
+
+  for(int i=0;i<NUMCORES4GC;i+=2) {
+    void *startptr=pmc_heapptr->regions[i].lastptr;
+    void *finishptr=pmc_heapptr->regions[i+1].lastptr;
+
+    if ((finishptr-startptr)>memcheck) {
+      struct pmc_region *region=&pmc_heapptr->regions[i];
+      tmc_spin_mutex_lock(&region->lock);
+      startptr=region->lastptr;
+      do {
+       //double check that we have the space
+       if ((finishptr-startptr)<memcheck)
+         break;
+       unsigned int startindex=region->lowunit;
+       unsigned int endindex=pmc_heapptr->regions[i+1]->highunit;
+       void * newstartptr=startptr+memcheck;
+       
+       //update unit end points
+       for(unsigned int index=startindex;index<endindex;index++) {
+         void *ptr=pmc_unitend(index);
+         if ((ptr>startptr)&&(ptr<newstartptr)) {
+           pmc_heapptr->units[index].endptr=newstartptr;
+         }
+         if (ptr>newstartptr)
+           break;
+       }
+       region->lastptr=newstartptr;
+
+       *numbytesallocated=(unsigned int)(newstartptr-startptr);
+       tmc_spin_mutex_unlock(&region->lock);
+       return startptr;
+      } while(0);
+      tmc_spin_mutex_unlock(&region->lock);
+    }
+  }
+  return NULL;
+}
index caad0d0b605c6f13928ef166c0d4eb43583ec9e6..3f1fbb3e9c0ab1422e4294b8d743c4fff68b3962 100644 (file)
@@ -1,14 +1,6 @@
 #ifndef PMC_MEM_H
 #define PMC_MEM_H
 
-void * pmc_alloc(unsigned int * numbytesallocated, unsigned int minimumbytes) {
-  for(int i=0;i<NUMCORES4GC;i+=2) {
-    void *startptr=pmc_heapptr->regions[i].lastptr;
-    void *finishptr=pmc_heapptr->regions[i+1].lastptr;
-    if ((finishptr-startptr)>minimumbytes) {
-      
-    }
-  }
-}
+void * pmc_alloc(unsigned int * numbytesallocated, unsigned int minimumbytes);
 
 #endif