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
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;
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;
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() {
#define PMC_GARBAGE_H
#include <tmc/spin.h>
+#define PMC_MINALLOC 131072
#define NUMPMCUNITS (4*NUMCORES4GC)
#define UNITSIZE (BAMBOO_SHARED_MEM_SIZE/NUMPMCUNITS)
void * lastptr;
void * startptr;
void * endptr;
+ unsigned int lowunit;
+ unsigned int highunit;
tmc_spin_mutex_t lock;
struct ___Object___ * lastobj;
struct pmc_queue markqueue;
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();
+#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(®ion->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(®ion->lock);
+ return startptr;
+ } while(0);
+ tmc_spin_mutex_unlock(®ion->lock);
+ }
+ }
+ return NULL;
+}
#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