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;
63 for(unsigned int index=startindex;index<endindex;index++) {
64 void *ptr=pmc_unitend(index);
65 if ((ptr>startptr)&&(ptr<=finishptr)) {
66 pmc_heapptr->units[index].endptr=ptr;
67 padspace(startptr, (unsigned int)(ptr-startptr));
71 void *prevunitptr=pmc_heapptr->units[index-1].endptr;
72 padspace(startptr, finishptr-startptr);
78 if (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 tprintf("%x\n", pmc_heapptr);
91 //count live objects per unit
92 tmc_spin_barrier_wait(&pmc_heapptr->barrier);
95 tmc_spin_barrier_wait(&pmc_heapptr->barrier);
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
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
123 //start to listen for gcflags before we exit
125 tmc_spin_barrier_wait(&pmc_heapptr->barrier);
129 void padspace(void *ptr, unsigned int length) {
131 tprintf("Padspace from %x to %x\n", ptr, ptr+length);
132 if (length<sizeof(struct ArrayObject)) {
133 BAMBOO_MEMSET_WH(ptr,0,length);
135 //generate fake arrays for big blocks
136 struct ArrayObject *ao=(struct ArrayObject *)ptr;
137 ao->type=BYTEARRAYTYPE;
138 unsigned arraylength=length-sizeof(struct ArrayObject);
139 ao->___length___=arraylength;
144 void gettype_size(void * ptr, int * ttype, unsigned int * tsize) {
145 int type = ((int *)ptr)[0];
146 if(type < NUMCLASSES) {
148 *tsize = classsize[type];
152 struct ArrayObject *ao=(struct ArrayObject *)ptr;
153 unsigned int elementsize=classsize[type];
154 unsigned int length=ao->___length___;
155 *tsize = sizeof(struct ArrayObject)+length*elementsize;