2 #include "structdefs.h"
3 #include "bambooalign.h"
4 #include "multicoregc.h"
5 #include "runtime_arch.h"
6 #include "pmc_forward.h"
7 #include "pmc_refupdate.h"
8 #include "multicoremgc.h"
13 #define pmcupdateObj(objptr) ((void *)((struct ___Object___ *)objptr)->marked)
15 #define PMCUPDATEOBJ(obj) {void *updatetmpptr=obj; if (updatetmpptr!=NULL) {obj=pmcupdateObj(updatetmpptr);}}
16 //if (obj==NULL) {tprintf("BAD REF UPDATE %x->%x in %u\n",updatetmpptr,obj,__LINE__);}}}
18 #define PMCUPDATEOBJNONNULL(obj) {void *updatetmpptr=obj; obj=pmcupdateObj(updatetmpptr);}
19 //if (obj==NULL) {tprintf("BAD REF UPDATE in %x->%x %u\n",updatetmpptr,obj,__LINE__);}}
21 void pmc_updatePtrs(void *ptr, int type) {
22 unsigned int * pointer=pointerarray[type];
23 //tprintf("Updating pointers in %x\n", ptr);
25 /* Array of primitives */
26 } else if (((unsigned int)pointer)==1) {
27 /* Array of pointers */
28 struct ArrayObject *ao=(struct ArrayObject *) ptr;
29 int length=ao->___length___;
30 for(int j=0; j<length; j++) {
31 PMCUPDATEOBJ(((void **)(((char *)&ao->___length___)+sizeof(int)))[j]);
34 unsigned int size=pointer[0];
36 for(int i=1; i<=size; i++) {
37 unsigned int offset=pointer[i];
38 PMCUPDATEOBJ(*((void **)(((char *)ptr)+offset)));
44 void pmc_updategarbagelist(struct garbagelist *listptr) {
45 for(;listptr!=NULL; listptr=listptr->next) {
46 for(int i=0; i<listptr->size; i++) {
47 PMCUPDATEOBJ(listptr->array[i]);
52 void pmc_updateRuntimePtrs(struct garbagelist * stackptr) {
53 // update current stack
54 pmc_updategarbagelist(stackptr);
56 // update static pointers global_defs_p
57 if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
58 pmc_updategarbagelist((struct garbagelist *)global_defs_p);
63 if(BAMBOO_NUM_OF_CORE < NUMCORESACTIVE) {
64 for(int i=0; i<NUMCLASSES; i++) {
65 struct parameterwrapper ** queues = objectqueues[BAMBOO_NUM_OF_CORE][i];
66 int length = numqueues[BAMBOO_NUM_OF_CORE][i];
67 for(int j = 0; j < length; ++j) {
68 struct parameterwrapper * parameter = queues[j];
69 struct ObjectHash * set=parameter->objectset;
70 for(struct ObjectNode * ptr=set->listhead;ptr!=NULL;ptr=ptr->lnext) {
71 PMCUPDATEOBJNONNULL(ptr->key);
73 ObjectHashrehash(set);
78 // update current task descriptor
80 for(int i=0; i<currtpd->numParameters; i++) {
81 // the parameter can not be NULL
82 PMCUPDATEOBJNONNULL(currtpd->parameterArray[i]);
86 // update active tasks
87 if(activetasks != NULL) {
88 for(struct genpointerlist * ptr=activetasks->list;ptr!=NULL;ptr=ptr->inext){
89 struct taskparamdescriptor *tpd=ptr->src;
90 for(int i=0; i<tpd->numParameters; i++) {
91 // the parameter can not be NULL
92 PMCUPDATEOBJNONNULL(tpd->parameterArray[i]);
95 genrehash(activetasks);
98 // update cached transferred obj
99 for(struct QueueItem * tmpobjptr = getHead(&objqueue);tmpobjptr != NULL;tmpobjptr = getNextQueueItem(tmpobjptr)) {
100 struct transObjInfo * objInfo=(struct transObjInfo *)(tmpobjptr->objectptr);
101 // the obj can not be NULL
102 PMCUPDATEOBJNONNULL(objInfo->objptr);
105 // update cached objs to be transferred
106 for(struct QueueItem * item = getHead(totransobjqueue);item != NULL;item = getNextQueueItem(item)) {
107 struct transObjInfo * totransobj = (struct transObjInfo *)(item->objectptr);
108 // the obj can not be NULL
109 PMCUPDATEOBJNONNULL(totransobj->objptr);
112 // enqueue lock related info
113 for(int i = 0; i < runtime_locklen; ++i) {
114 PMCUPDATEOBJ(runtime_locks[i].redirectlock);
115 PMCUPDATEOBJ(runtime_locks[i].value);
120 // update the bamboo_threadlocks
121 for(int i = 0; i < bamboo_threadlocks.index; i++) {
122 // the locked obj can not be NULL
123 PMCUPDATEOBJNONNULL(bamboo_threadlocks.locks[i].object);
126 // update the bamboo_current_thread
127 PMCUPDATEOBJ(bamboo_current_thread);
129 // update global thread queue
130 if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
131 unsigned int thread_counter = *((unsigned int*)(bamboo_thread_queue+1));
132 if(thread_counter > 0) {
133 unsigned int start = *((unsigned int*)(bamboo_thread_queue+2));
134 for(int i = thread_counter; i > 0; i--) {
135 // the thread obj can not be NULL
136 PMCUPDATEOBJNONNULL(*((void **)&bamboo_thread_queue[4+start]));
137 start = (start+1)&bamboo_max_thread_num_mask;
146 void pmc_doreferenceupdate(struct garbagelist *stackptr) {
147 struct pmc_region * region=&pmc_heapptr->regions[BAMBOO_NUM_OF_CORE];
148 pmc_updateRuntimePtrs(stackptr);
149 pmc_referenceupdate(region->startptr, region->endptr);
152 void pmc_referenceupdate(void *bottomptr, void *topptr) {
153 void *tmpptr=bottomptr;
154 //tprintf("%x -- %x\n", bottomptr, topptr);
155 while(tmpptr<topptr) {
158 gettype_size(tmpptr, &type, &size);
159 size=((size-1)&(~(ALIGNMENTSIZE-1)))+ALIGNMENTSIZE;
161 tmpptr+=ALIGNMENTSIZE;
164 //if marked we update the pointers
165 if (((struct ___Object___ *) tmpptr)->marked) {
166 pmc_updatePtrs(tmpptr, type);
172 void pmc_docompact() {
173 struct pmc_region * region=&pmc_heapptr->regions[BAMBOO_NUM_OF_CORE];
174 pmc_compact(region, !(BAMBOO_NUM_OF_CORE&1), region->startptr, region->endptr);
178 void pmc_compact(struct pmc_region * region, int forward, void *bottomptr, void *topptr) {
180 void *tmpptr=bottomptr;
181 while(tmpptr<topptr) {
184 gettype_size(tmpptr, &type, &size);
185 size=((size-1)&(~(ALIGNMENTSIZE-1)))+ALIGNMENTSIZE;
187 tmpptr+=ALIGNMENTSIZE;
190 //if marked we update the pointers
191 void *forwardptr=(void *)((struct ___Object___ *) tmpptr)->marked;
192 ((struct ___Object___ *) tmpptr)->marked=NULL;
194 //tprintf("Compacting %x\n",tmpptr);
195 memmove(forwardptr, tmpptr, size);
200 struct ___Object___ *backward=region->lastobj;
201 struct ___Object___ *lastobj=NULL;
204 backward=backward->backward;
207 gettype_size(lastobj, &type, &size);
208 size=((size-1)&(~(ALIGNMENTSIZE-1)))+ALIGNMENTSIZE;
209 void *forwardptr=(void *)((struct ___Object___ *) lastobj)->marked;
210 ((struct ___Object___ *) lastobj)->marked=NULL;
211 //tprintf("Compacting %x\n",lastobj);
212 memmove(forwardptr, lastobj, size);