#include "multicoregarbage.h"
#ifdef PMC_GC
#include "multicoregcprofile.h"
+#include "multicoregc.h"
+#include "pmc_garbage.h"
#endif
#include "multicore_arch.h"
#include <stdio.h>
#include "multicoretask.h"
#include "multicoremgc.h"
#include "multicorecache.h"
+#ifdef PMC_GC
+#include "multicoregc.h"
+#include "pmc_garbage.h"
+#endif
+
//Define the following line if the base object type has pointers
//#define OBJECTHASPOINTERS
//got lock
void *unitbase=(i==0)?gcbaseva:pmc_heapptr->units[i-1].endptr;
void *unittop=pmc_heapptr->units[i].endptr;
- tprintf("Cnt: %x - %x\n", unitbase, unittop);
+ //tprintf("Cnt: %x - %x\n", unitbase, unittop);
pmc_countbytes(&pmc_heapptr->units[i], unitbase, unittop);
}
}
int totalbytes=0;
int numregions=0;
+ pmc_heapptr->regions[0].startptr=gcbaseva;
+ pmc_heapptr->regions[0].lowunit=0;
+
for(int i=0;i<NUMPMCUNITS;i++) {
if (numregions>0&&(totalbytes+pmc_heapptr->units[i].numbytes)>livebytespercore) {
+ pmc_heapptr->regions[regionnum].highunit=i;
+ pmc_heapptr->regions[regionnum].endptr=pmc_heapptr->units[i-1].endptr;
+
+ pmc_heapptr->regions[regionnum+1].startptr=pmc_heapptr->units[i-1].endptr;
+ pmc_heapptr->regions[regionnum+1].lowunit=i;
regionnum++;
totalbytes-=livebytespercore;
numregions=0;
tmc_spin_mutex_init(&pmc_heapptr->units[i].lock);
totalbytes+=pmc_heapptr->units[i].numbytes;
}
+ pmc_heapptr->regions[regionnum].highunit=NUMPMCUNITS;
+ pmc_heapptr->regions[regionnum].endptr=pmc_heapptr->units[NUMPMCUNITS-1].endptr;
+ regionnum++;
+ for(;regionnum<NUMCORES4GC;regionnum++) {
+ pmc_heapptr->regions[regionnum].highunit=NUMPMCUNITS;
+ pmc_heapptr->regions[regionnum].endptr=pmc_heapptr->units[NUMPMCUNITS-1].endptr;
+ pmc_heapptr->regions[regionnum+1].startptr=pmc_heapptr->units[NUMPMCUNITS-1].endptr;
+ pmc_heapptr->regions[regionnum+1].lowunit=NUMPMCUNITS;
+ }
}
void pmc_doforward() {
int endregion=-1;
unsigned int totalbytes=0;
struct pmc_region * region=&pmc_heapptr->regions[BAMBOO_NUM_OF_CORE];
- for(int i=0;i<NUMPMCUNITS;i++) {
- if (startregion==-1&&BAMBOO_NUM_OF_CORE==pmc_heapptr->units[i].regionnum) {
- startregion=i;
- }
- if (BAMBOO_NUM_OF_CORE<pmc_heapptr->units[i].regionnum) {
- endregion=i;
- break;
- }
- if (startregion!=-1) {
- totalbytes+=pmc_heapptr->units[i].numbytes;
- }
- }
- if (startregion==-1) {
- //out of regions....
- region->lowunit=region->highunit=NUMPMCUNITS;
- region->lastptr=region->startptr=region->endptr=pmc_heapptr->units[region->highunit-1].endptr;
- return;
+ for(int index=region->lowunit; index<region->highunit;index++) {
+ totalbytes+=pmc_heapptr->units[index].numbytes;
}
- if (endregion==-1)
- endregion=NUMPMCUNITS;
- region->lowunit=startregion;
- region->highunit=endregion;
- region->startptr=(startregion==0)?gcbaseva:pmc_heapptr->units[startregion-1].endptr;
- region->endptr=pmc_heapptr->units[endregion-1].endptr;
+
if (BAMBOO_NUM_OF_CORE&1) {
//upward in memory
region->lastptr=region->endptr-totalbytes;
struct ___Object___ *lastobj=NULL;
unsigned int currunit=region->lowunit;
void *endunit=pmc_unitend(currunit);
+ bool internal=!(BAMBOO_NUM_OF_CORE&1);
+ int highbound=internal?region->highunit:region->highunit-1;
+
if (!lower) {
//We're resetting the boundaries of units at the low address end of the region...
//Be sure not to reset the boundary of our last unit...it is shared with another region
- while(endunit<=region->lastptr&&(currunit<(region->highunit-1))) {
+
+ while(endunit<=region->lastptr&&(currunit<highbound)) {
pmc_heapptr->units[currunit].endptr=endunit;
+ //tprintf("Ch2: %u -> %x\n", currunit, endunit);
currunit++;
endunit=pmc_unitend(currunit);
}
} else {
//We're resetting the boundaries of units at the high address end of the region...
//Very top most unit defines boundary of region...we can't move that right now
- unsigned int lastunit=region->highunit-2;
+ unsigned int lastunit=internal?region->highunit-1:region->highunit-2;
void * lastunitend=pmc_unitend(lastunit);
while(lastunitend>=region->lastptr) {
pmc_heapptr->units[lastunit].endptr=lastunitend;
+ //tprintf("Ch3: %u -> %x\n", lastunit, lastunitend);
lastunit--;
lastunitend=pmc_unitend(lastunit);
}
void *newforwardptr=forwardptr+size;
//Need to make sure that unit boundaries do not fall in the middle of an object...
//Unless the unit boundary is at the end of the region...then just ignore it.
- while(newforwardptr>=endunit&&currunit<(region->highunit-1)) {
+ while(newforwardptr>=endunit&&currunit<highbound) {
pmc_heapptr->units[currunit].endptr=newforwardptr;
+ //tprintf("Ch4: %u -> %x\n", currunit, newforwardptr);
currunit++;
endunit=pmc_unitend(currunit);
}
}
tmpptr+=size;
}
- tprintf("forwardptr=%x\n",forwardptr);
+ //tprintf("forwardptr=%x\n",forwardptr);
region->lastobj=lastobj;
}
tmc_spin_barrier_init(&pmc_heapptr->barrier, NUMCORES4GC);
for(int i=0;i<NUMPMCUNITS;i++) {
pmc_heapptr->units[i].endptr=pmc_unitend(i);
- tprintf("%u endptr=%x\n", i, pmc_heapptr->units[i].endptr);
+ //tprintf("Ch5: %u-> %x\n", i, pmc_heapptr->units[i].endptr);
}
for(int i=0;i<NUMCORES4GC;i+=2) {
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);
- }
+ //for(int i=0;i<NUMCORES4GC;i++) {
+ //tprintf("%u lastptr=%x\n", i, pmc_heapptr->regions[i].lastptr);
+ //}
}
}
struct pmc_region *region=&pmc_heapptr->regions[i];
unsigned int startindex=region->lowunit;
unsigned int endindex=pmc_heapptr->regions[i+1].highunit;
- tprintf("Free space in partition %u from %x to %x\n", i, startptr, finishptr);
+ //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;
if ((ptr>startptr)&&(ptr<=finishptr)) {
}
}
if (bamboo_smem_size) {
- tprintf("Left over alloc space from %x to %x\n", bamboo_cur_msp, bamboo_cur_msp+bamboo_smem_size);
+ //tprintf("Left over alloc space from %x to %x\n", bamboo_cur_msp, bamboo_cur_msp+bamboo_smem_size);
padspace(bamboo_cur_msp, bamboo_smem_size);
}
tmc_spin_barrier_wait(&pmc_heapptr->barrier);
}
void gc(struct garbagelist *gl) {
- tprintf("start GC\n");
+ if (BAMBOO_NUM_OF_CORE==STARTUPCORE)
+ tprintf("start GC\n");
pmc_init();
//mark live objects
- tprintf("mark\n");
+ //tprintf("mark\n");
pmc_mark(gl);
//count live objects per unit
tmc_spin_barrier_wait(&pmc_heapptr->barrier);
- tprintf("count\n");
+ //tprintf("count\n");
pmc_count();
tmc_spin_barrier_wait(&pmc_heapptr->barrier);
//divide up work
- tprintf("divide\n");
+ //tprintf("divide\n");
if (BAMBOO_NUM_OF_CORE==STARTUPCORE) {
pmc_processunits();
}
tmc_spin_barrier_wait(&pmc_heapptr->barrier);
//set up forwarding pointers
- tprintf("forward\n");
+ //tprintf("forward\n");
pmc_doforward();
tmc_spin_barrier_wait(&pmc_heapptr->barrier);
//update pointers
- tprintf("updaterefs\n");
+ //tprintf("updaterefs\n");
pmc_doreferenceupdate(gl);
tmc_spin_barrier_wait(&pmc_heapptr->barrier);
//compact data
- tprintf("compact\n");
+ //tprintf("compact\n");
pmc_docompact();
//reset memory allocation
bamboo_cur_msp=NULL;
bamboo_smem_size=0;
- tprintf("done\n");
+ //tprintf("done\n");
+
+ //if (BAMBOO_NUM_OF_CORE==STARTUPCORE) {
+ // for(int i=0;i<NUMCORES4GC;i+=2) {
+ // void *startptr=pmc_heapptr->regions[i].lastptr;
+ // void *finishptr=pmc_heapptr->regions[i+1].lastptr;
+ // tprintf("Partition %u from %x to %x\n", i, startptr, finishptr);
+ // tprintf("%x %x %x %x\n", pmc_heapptr->regions[i].startptr, pmc_heapptr->regions[i].endptr, pmc_heapptr->regions[i+1].startptr, pmc_heapptr->regions[i+1].endptr);
+ // }
+ // }
gcflag=false;
tmc_spin_barrier_wait(&pmc_heapptr->barrier);
- tprintf("exit GC\n");
+ //tprintf("exit GC\n");
}
void padspace(void *ptr, unsigned int length) {
//zero small blocks
- tprintf("Padspace from %x to %x\n", ptr, ptr+length);
if (length<sizeof(struct ArrayObject)) {
BAMBOO_MEMSET_WH(ptr,0,length);
} else {
void gettype_size(void * ptr, unsigned int * ttype, unsigned int * tsize) {
int type = ((int *)ptr)[0];
- if (type>TOTALNUMCLASSANDARRAY) {
- tprintf("ptr=%x type=%u\n", ptr, type);
- }
+ // if (type>TOTALNUMCLASSANDARRAY) {
+ // tprintf("ptr=%x type=%u\n", ptr, type);
+ // }
if(type < NUMCLASSES) {
// a normal object
#include "pmc_queue.h"
#include "structdefs.h"
-//#define PMC_MINALLOC 131072
-#define PMC_MINALLOC 2048
+#define PMC_MINALLOC 131072
+//#define PMC_MINALLOC 2048
#define NUMPMCUNITS (4*NUMCORES4GC)
#define UNITSIZE (BAMBOO_SHARED_MEM_SIZE/NUMPMCUNITS)
//update unit end points
for(unsigned int index=startindex;index<(endindex-1);index++) {
void *ptr=pmc_unitend(index);
- if ((ptr>startptr)&&(ptr<newstartptr)) {
+ if ((ptr>startptr)&&(ptr<=newstartptr)) {
+ //tprintf("Ch: %u -> %x\n", index, newstartptr);
pmc_heapptr->units[index].endptr=newstartptr;
}
+
if (ptr>newstartptr)
break;
}
*numbytesallocated=(unsigned int)(newstartptr-startptr);
tmc_spin_mutex_unlock(®ion->lock);
+
return startptr;
} while(0);
tmc_spin_mutex_unlock(®ion->lock);
#define pmcupdateObj(objptr) ((void *)((struct ___Object___ *)objptr)->marked)
-#define PMCUPDATEOBJ(obj) {void *updatetmpptr=obj; if (updatetmpptr!=NULL) {obj=pmcupdateObj(updatetmpptr);if (obj==NULL) {tprintf("BAD REF UPDATE %x->%x in %u\n",updatetmpptr,obj,__LINE__);}}}
+#define PMCUPDATEOBJ(obj) {void *updatetmpptr=obj; if (updatetmpptr!=NULL) {obj=pmcupdateObj(updatetmpptr);}}
+//if (obj==NULL) {tprintf("BAD REF UPDATE %x->%x in %u\n",updatetmpptr,obj,__LINE__);}}}
-#define PMCUPDATEOBJNONNULL(obj) {void *updatetmpptr=obj; obj=pmcupdateObj(updatetmpptr);if (obj==NULL) {tprintf("BAD REF UPDATE in %x->%x %u\n",updatetmpptr,obj,__LINE__);}}
+#define PMCUPDATEOBJNONNULL(obj) {void *updatetmpptr=obj; obj=pmcupdateObj(updatetmpptr);}
+//if (obj==NULL) {tprintf("BAD REF UPDATE in %x->%x %u\n",updatetmpptr,obj,__LINE__);}}
void pmc_updatePtrs(void *ptr, int type) {
unsigned int * pointer=pointerarray[type];
- tprintf("Updating pointers in %x\n", ptr);
+ //tprintf("Updating pointers in %x\n", ptr);
if (pointer==0) {
/* Array of primitives */
} else if (((unsigned int)pointer)==1) {
PMCUPDATEOBJ(*((void **)(((char *)ptr)+offset)));
}
}
- tprintf("done\n");
+ //tprintf("done\n");
}
void pmc_updategarbagelist(struct garbagelist *listptr) {
void pmc_referenceupdate(void *bottomptr, void *topptr) {
void *tmpptr=bottomptr;
- tprintf("%x -- %x\n", bottomptr, topptr);
+ //tprintf("%x -- %x\n", bottomptr, topptr);
while(tmpptr<topptr) {
unsigned int type;
unsigned int size;
#include "multicoremem.h"
#include "multicoregarbage.h"
#endif
+#ifdef PMC_GC
+#include "multicoregc.h"
+#include "pmc_garbage.h"
+#endif
#if defined(MULTICORE_GC)||defined(PMC_GC)
extern volatile bool gcflag;