1 #include "pmc_forward.h"
4 for(int i=0;i<NUMPMCUNITS;i++) {
5 if (!tmc_spin_mutex_trylock(&pmc_heapptr->units[i].lock)) {
7 void *unitbase=(i==0)?gcbaseva:pmc_heapptr->unit[i-1]->endptr;
8 void *unittop=pmc_heapptr->unit[i]->endptr;
9 pmc_countbytes(&pmc_heapptr->unit[i], unitbase, unittop);
14 //Comment: should build dummy byte arrays to allow skipping data...
15 void pmc_countbytes(struct pmc_unit * unit, void *bottomptr, void *topptr) {
16 void *tmpptr=bottomptr;
17 unsigned int totalbytes=0;
18 while(tmpptr<topptr) {
21 gettype_size(tmpptr, &type, &size);
23 tmpptr+=ALIGNMENTSIZE;
26 size=((size-1)&(~(ALIGNMENTSIZE-1)))+ALIGNMENTSIZE;
27 if (((struct ___Object___ *)tmpptr)->mark)
31 unit->numbytes=totalbytes;
34 void pmc_processunits() {
35 unsigned int livebytes=0;
36 for(int i=0;i<NUMPMCUNITS;i++) {
37 livebytes+=pmc_heapptr->units[i].numbytes;
39 //make sure to round up
40 unsigned int livebytespercore=((livebytes-1)/NUMCORES4GC)+1;
41 unsigned int regionnum=0;
45 for(int i=0;i<NUMPMCUNITS;i++) {
46 if (numregions>0&&(totalbytes+pmc_heapptr->units[i].numbytes)>livebytespercore) {
48 totalbytes-=livebytespercore;
52 pmc_heapptr->units[i].regionnum=regionnum;
53 tmc_spin_mutex_init(&pmc_heapptr->units[i].lock);
54 totalbytes+=pmc_heapptr->units[i].numbytes;
58 void pmc_doforward() {
61 unsigned int totalbytes=0;
62 struct pmc_region * region=&pmc_heapptr->regions[BAMBOO_NUM_OF_CORE];
63 for(int i=0;i<NUMPMCUNITS;i++) {
64 if (startregion==-1&&BAMBOO_NUM_OF_CORE==pmc_heapptr->units[i].regionnum) {
67 if (BAMBOO_NUM_OF_CORE<pmc_heapptr->units[i].regionnum) {
71 if (startregion!=-1) {
72 totalbytes+=pmc_heapptr->units[i].numbytes;
78 endregion=NUMPMCUNITS;
79 region->startptr=(i==0)?gcbaseva:pmc_heapptr->units[i-1].endptr;
80 region->endptr=pmc_heapptr->units[i].endptr;
82 if (BAMBOO_NUM_OF_CORE&1) {
84 region->lastptr=region->endptr-totalbytes;
87 region->lastptr=region->startptr+totalbytes;
90 pmc_forward(region, totalbytes, region->startptr, region->endptr, !(BAMBOO_NUM_OF_CORE&1));
94 void pmc_forward(struct pmc_region *region, unsigned int totalbytes, void *bottomptr, void *topptr, bool fwddirection) {
95 void *tmpptr=bottomptr;
96 void *forwardptr=fwddirection?bottomptr:(topptr-totalbytes);
97 struct ___Object___ *lastobj=NULL;
99 while(tmpptr>topptr) {
102 gettype_size(tmpptr, &type, &size);
104 tmpptr+=ALIGNMENTSIZE;
107 size=((size-1)&(~(ALIGNMENTSIZE-1)))+ALIGNMENTSIZE;
109 if (((struct ___Object___ *)tmpptr)->mark) {
110 ((struct ___Object___ *)tmpptr)->mark=forwardptr;
112 if (lastobj&&!fwddirection) {
113 tmpptr->backward=lastobj;
114 lastobj=(struct ___Object___ *)tmpptr;
119 region->lastobj=lastobj;