1 #include "multicoregc.h"
2 #include "multicoreruntime.h"
3 #include "pmc_garbage.h"
4 #include "runtime_arch.h"
6 struct pmc_heap * pmc_heapptr;
7 struct pmc_queue * pmc_localqueue;
10 void incrementthreads() {
11 tmc_spin_mutex_lock(&pmc_heapptr->lock);
12 pmc_heapptr->numthreads++;
13 tmc_spin_mutex_unlock(&pmc_heapptr->lock);
16 void decrementthreads() {
17 tmc_spin_mutex_lock(&pmc_heapptr->lock);
18 pmc_heapptr->numthreads--;
19 tmc_spin_mutex_unlock(&pmc_heapptr->lock);
22 void * pmc_unitend(unsigned int index) {
23 return gcbaseva+(index+1)*UNITSIZE;
27 pmc_localqueue=&pmc_heapptr->regions[BAMBOO_NUM_OF_CORE].markqueue;
28 pmc_queueinit(pmc_localqueue);
29 if (BAMBOO_NUM_OF_CORE==STARTUPCORE) {
30 tmc_spin_barrier_init(&pmc_heapptr->barrier, NUMCORES4GC);
31 for(int i=0;i<NUMPMCUNITS;i++) {
32 pmc_heapptr->units[i].endptr=pmc_unitend(i);
33 //tprintf("%u endptr=%x\n", i, pmc_heapptr->units[i].endptr);
36 for(int i=0;i<NUMCORES4GC;i+=2) {
38 pmc_heapptr->regions[i].lastptr=gcbaseva;
40 pmc_heapptr->regions[i].lastptr=pmc_heapptr->units[i*4-1].endptr;
41 pmc_heapptr->regions[i].lowunit=4*i;
42 pmc_heapptr->regions[i].highunit=4*(i+1);
43 pmc_heapptr->regions[i+1].lastptr=pmc_heapptr->units[(i+1)*4+3].endptr;
44 pmc_heapptr->regions[i+1].lowunit=4*(i+1);
45 pmc_heapptr->regions[i+1].highunit=4*(i+2);
47 // for(int i=0;i<NUMCORES4GC;i++) {
48 // tprintf("%u lastptr=%x\n", i, pmc_heapptr->regions[i].lastptr);
54 if (BAMBOO_NUM_OF_CORE==STARTUPCORE) {
55 pmc_heapptr->numthreads=NUMCORES4GC;
56 for(int i=0;i<NUMCORES4GC;i+=2) {
57 void *startptr=pmc_heapptr->regions[i].lastptr;
58 void *finishptr=pmc_heapptr->regions[i+1].lastptr;
59 struct pmc_region *region=&pmc_heapptr->regions[i];
60 unsigned int startindex=region->lowunit;
61 unsigned int endindex=pmc_heapptr->regions[i+1].highunit;
62 // tprintf("Free space in partition %u from %x to %x\n", i, startptr, finishptr);
63 for(unsigned int index=startindex;index<endindex;index++) {
64 void *ptr=pmc_heapptr->units[index].endptr;
65 if ((ptr>startptr)&&(ptr<=finishptr)) {
66 padspace(startptr, (unsigned int)(ptr-startptr));
70 void *prevunitptr=pmc_heapptr->units[index-1].endptr;
71 padspace(startptr, finishptr-startptr);
77 if (bamboo_smem_size) {
78 // tprintf("Left over alloc space from %x to %x\n", bamboo_cur_msp, bamboo_cur_msp+bamboo_smem_size);
79 padspace(bamboo_cur_msp, bamboo_smem_size);
81 tmc_spin_barrier_wait(&pmc_heapptr->barrier);
84 void gc(struct garbagelist *gl) {
85 if (BAMBOO_NUM_OF_CORE==STARTUPCORE)
86 tprintf("start GC\n");
91 //count live objects per unit
92 tmc_spin_barrier_wait(&pmc_heapptr->barrier);
93 // tprintf("count\n");
95 tmc_spin_barrier_wait(&pmc_heapptr->barrier);
97 // tprintf("divide\n");
98 if (BAMBOO_NUM_OF_CORE==STARTUPCORE) {
101 tmc_spin_barrier_wait(&pmc_heapptr->barrier);
102 //set up forwarding pointers
103 // tprintf("forward\n");
105 tmc_spin_barrier_wait(&pmc_heapptr->barrier);
107 // tprintf("updaterefs\n");
108 pmc_doreferenceupdate(gl);
109 tmc_spin_barrier_wait(&pmc_heapptr->barrier);
111 // tprintf("compact\n");
113 //reset memory allocation
116 // tprintf("done\n");
118 if (BAMBOO_NUM_OF_CORE==STARTUPCORE) {
119 tmc_spin_barrier_wait(&pmc_heapptr->barrier);
120 //people will resend...no need to get gcflag so quickly
122 // for(int i=0;i<NUMCORES4GC;i+=2) {
123 // tprintf("%u %x %x\n",i, pmc_heapptr->regions[i].lastptr, pmc_heapptr->regions[i+1].lastptr);
124 // 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);
125 // tprintf("%u %u %u %u\n", pmc_heapptr->regions[i].lowunit, pmc_heapptr->regions[i].highunit, pmc_heapptr->regions[i+1].lowunit, pmc_heapptr->regions[i+1].highunit);
127 // for(int i=0;i<NUMPMCUNITS;i++) {
128 // tprintf("%u %x %u\n",i, pmc_heapptr->units[i].endptr, pmc_heapptr->units[i].regionnum);
131 //start to listen for gcflags before we exit
133 tmc_spin_barrier_wait(&pmc_heapptr->barrier);
137 void padspace(void *ptr, unsigned int length) {
139 // tprintf("Padspace from %x to %x\n", ptr, ptr+length);
140 if (length<sizeof(struct ArrayObject)) {
141 BAMBOO_MEMSET_WH(ptr,0,length);
143 //generate fake arrays for big blocks
144 struct ArrayObject *ao=(struct ArrayObject *)ptr;
145 ao->type=BYTEARRAYTYPE;
146 unsigned arraylength=length-sizeof(struct ArrayObject);
147 ao->___length___=arraylength;
152 void gettype_size(void * ptr, int * ttype, unsigned int * tsize) {
153 int type = ((int *)ptr)[0];
154 if(type < NUMCLASSES) {
156 *tsize = classsize[type];
160 struct ArrayObject *ao=(struct ArrayObject *)ptr;
161 unsigned int elementsize=classsize[type];
162 unsigned int length=ao->___length___;
163 *tsize = sizeof(struct ArrayObject)+length*elementsize;