b0a39fdb76536fa0528ac08ba114f477de429719
[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   pmc_init();
44   //mark live objects
45   pmc_mark(gl);
46   //count live objects per unit
47   pmc_count();
48   tmc_spin_barrier_wait(&pmc_heapptr->barrier);
49   //divide up work
50   if (BAMBOO_NUM_OF_CORE==STARTUPCORE) {
51     pmc_processunits();
52   }
53   tmc_spin_barrier_wait(&pmc_heapptr->barrier);
54   //set up forwarding pointers
55   pmc_doforward();
56   tmc_spin_barrier_wait(&pmc_heapptr->barrier);
57   //update pointers
58   pmc_doreferenceupdate();
59   tmc_spin_barrier_wait(&pmc_heapptr->barrier);
60   //compact data
61   pmc_docompact();
62   tmc_spin_barrier_wait(&pmc_heapptr->barrier);
63 }
64
65 void gettype_size(void * ptr, int * ttype, unsigned int * tsize) {
66   int type = ((int *)ptr)[0];
67   if(type < NUMCLASSES) {
68     // a normal object
69     *tsize = classsize[type];
70     *ttype = type;
71   } else {
72     // an array
73     struct ArrayObject *ao=(struct ArrayObject *)ptr;
74     unsigned int elementsize=classsize[type];
75     unsigned int length=ao->___length___;
76     *tsize = sizeof(struct ArrayObject)+length*elementsize;
77     *ttype = type;
78   } 
79 }