last known issues...now waiting to test
[IRC.git] / Robust / src / Runtime / bamboo / pmc_garbage.c
1 #include "multicoregc.h"
2 #include "multicoreruntime.h"
3 #include "pmc_garbage.h"
4 #include "runtime_arch.h"
5
6 struct pmc_heap * pmc_heapptr;
7 struct pmc_queue * pmc_localqueue;
8 volatile bool gcflag;
9
10 void incrementthreads() {
11   tmc_spin_mutex_lock(&pmc_heapptr->lock);
12   pmc_heapptr->numthreads++;
13   tmc_spin_mutex_unlock(&pmc_heapptr->lock);
14 }
15
16 void decrementthreads() {
17   tmc_spin_mutex_lock(&pmc_heapptr->lock);
18   pmc_heapptr->numthreads--;
19   tmc_spin_mutex_unlock(&pmc_heapptr->lock);
20 }
21
22 void * pmc_unitend(unsigned int index) {
23   return gcbaseva+(index+1)*NUMPMCUNITS;
24 }
25
26 void pmc_onceInit() {
27   pmc_localqueue=&pmc_heapptr->regions[BAMBOO_NUM_OF_CORE].markqueue;
28   pmc_queueinit(pmc_localqueue);
29   tmc_spin_barrier_init(&pmc_heapptr->barrier, NUMCORES4GC);
30   for(int i=0;i<NUMPMCUNITS;i++) {
31     pmc_heapptr->units[i].endptr=pmc_unitend(i);
32   }
33 }
34
35 void pmc_init() {
36   if (BAMBOO_NUM_OF_CORE==STARTUPCORE) {
37     pmc_heapptr->numthreads=NUMCORES4GC;
38   }
39   tmc_spin_barrier_wait(&pmc_heapptr->barrier);
40 }
41
42 void gc(struct garbagelist *gl) {
43   tprintf("init\n");
44   pmc_init();
45   //mark live objects
46   tprintf("mark\n");
47   pmc_mark(gl);
48   //count live objects per unit
49   tprintf("count\n");
50   pmc_count();
51   tmc_spin_barrier_wait(&pmc_heapptr->barrier);
52   //divide up work
53   tprintf("divide\n");
54   if (BAMBOO_NUM_OF_CORE==STARTUPCORE) {
55     pmc_processunits();
56   }
57   tmc_spin_barrier_wait(&pmc_heapptr->barrier);
58   //set up forwarding pointers
59   tprintf("forward\n");
60   pmc_doforward();
61   tmc_spin_barrier_wait(&pmc_heapptr->barrier);
62   //update pointers
63   tprintf("updaterefs\n");
64   pmc_doreferenceupdate();
65   tmc_spin_barrier_wait(&pmc_heapptr->barrier);
66   //compact data
67   tprintf("compact\n");
68   pmc_docompact();
69   tmc_spin_barrier_wait(&pmc_heapptr->barrier);
70 }
71
72 void gettype_size(void * ptr, int * ttype, unsigned int * tsize) {
73   int type = ((int *)ptr)[0];
74   if(type < NUMCLASSES) {
75     // a normal object
76     *tsize = classsize[type];
77     *ttype = type;
78   } else {
79     // an array
80     struct ArrayObject *ao=(struct ArrayObject *)ptr;
81     unsigned int elementsize=classsize[type];
82     unsigned int length=ao->___length___;
83     *tsize = sizeof(struct ArrayObject)+length*elementsize;
84     *ttype = type;
85   } 
86 }