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);if (obj==NULL) {tprintf("BAD REF UPDATE %x->%x in %u\n",updatetmpptr,obj,__LINE__);}}}
17 #define PMCUPDATEOBJNONNULL(obj) {void *updatetmpptr=obj; obj=pmcupdateObj(updatetmpptr);if (obj==NULL) {tprintf("BAD REF UPDATE in %x->%x %u\n",updatetmpptr,obj,__LINE__);}}
19 void pmc_updatePtrs(void *ptr, int type) {
20 unsigned int * pointer=pointerarray[type];
21 tprintf("Updating pointers in %x\n", ptr);
23 /* Array of primitives */
24 } else if (((unsigned int)pointer)==1) {
25 /* Array of pointers */
26 struct ArrayObject *ao=(struct ArrayObject *) ptr;
27 int length=ao->___length___;
28 for(int j=0; j<length; j++) {
29 PMCUPDATEOBJ(((void **)(((char *)&ao->___length___)+sizeof(int)))[j]);
32 unsigned int size=pointer[0];
34 for(int i=1; i<=size; i++) {
35 unsigned int offset=pointer[i];
36 PMCUPDATEOBJ(*((void **)(((char *)ptr)+offset)));
42 void pmc_updategarbagelist(struct garbagelist *listptr) {
43 for(;listptr!=NULL; listptr=listptr->next) {
44 for(int i=0; i<listptr->size; i++) {
45 PMCUPDATEOBJ(listptr->array[i]);
50 void pmc_updateRuntimePtrs(struct garbagelist * stackptr) {
51 // update current stack
52 pmc_updategarbagelist(stackptr);
54 // update static pointers global_defs_p
55 if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
56 pmc_updategarbagelist((struct garbagelist *)global_defs_p);
61 if(BAMBOO_NUM_OF_CORE < NUMCORESACTIVE) {
62 for(int i=0; i<NUMCLASSES; i++) {
63 struct parameterwrapper ** queues = objectqueues[BAMBOO_NUM_OF_CORE][i];
64 int length = numqueues[BAMBOO_NUM_OF_CORE][i];
65 for(int j = 0; j < length; ++j) {
66 struct parameterwrapper * parameter = queues[j];
67 struct ObjectHash * set=parameter->objectset;
68 for(struct ObjectNode * ptr=set->listhead;ptr!=NULL;ptr=ptr->lnext) {
69 PMCUPDATEOBJNONNULL(ptr->key);
71 ObjectHashrehash(set);
76 // update current task descriptor
78 for(int i=0; i<currtpd->numParameters; i++) {
79 // the parameter can not be NULL
80 PMCUPDATEOBJNONNULL(currtpd->parameterArray[i]);
84 // update active tasks
85 if(activetasks != NULL) {
86 for(struct genpointerlist * ptr=activetasks->list;ptr!=NULL;ptr=ptr->inext){
87 struct taskparamdescriptor *tpd=ptr->src;
88 for(int i=0; i<tpd->numParameters; i++) {
89 // the parameter can not be NULL
90 PMCUPDATEOBJNONNULL(tpd->parameterArray[i]);
93 genrehash(activetasks);
96 // update cached transferred obj
97 for(struct QueueItem * tmpobjptr = getHead(&objqueue);tmpobjptr != NULL;tmpobjptr = getNextQueueItem(tmpobjptr)) {
98 struct transObjInfo * objInfo=(struct transObjInfo *)(tmpobjptr->objectptr);
99 // the obj can not be NULL
100 PMCUPDATEOBJNONNULL(objInfo->objptr);
103 // update cached objs to be transferred
104 for(struct QueueItem * item = getHead(totransobjqueue);item != NULL;item = getNextQueueItem(item)) {
105 struct transObjInfo * totransobj = (struct transObjInfo *)(item->objectptr);
106 // the obj can not be NULL
107 PMCUPDATEOBJNONNULL(totransobj->objptr);
110 // enqueue lock related info
111 for(int i = 0; i < runtime_locklen; ++i) {
112 PMCUPDATEOBJ(runtime_locks[i].redirectlock);
113 PMCUPDATEOBJ(runtime_locks[i].value);
118 // update the bamboo_threadlocks
119 for(int i = 0; i < bamboo_threadlocks.index; i++) {
120 // the locked obj can not be NULL
121 PMCUPDATEOBJNONNULL(bamboo_threadlocks.locks[i].object);
124 // update the bamboo_current_thread
125 PMCUPDATEOBJ(bamboo_current_thread);
127 // update global thread queue
128 if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
129 unsigned int thread_counter = *((unsigned int*)(bamboo_thread_queue+1));
130 if(thread_counter > 0) {
131 unsigned int start = *((unsigned int*)(bamboo_thread_queue+2));
132 for(int i = thread_counter; i > 0; i--) {
133 // the thread obj can not be NULL
134 PMCUPDATEOBJNONNULL(*((void **)&bamboo_thread_queue[4+start]));
135 start = (start+1)&bamboo_max_thread_num_mask;
144 void pmc_doreferenceupdate(struct garbagelist *stackptr) {
145 struct pmc_region * region=&pmc_heapptr->regions[BAMBOO_NUM_OF_CORE];
146 pmc_updateRuntimePtrs(stackptr);
147 pmc_referenceupdate(region->startptr, region->endptr);
150 void pmc_referenceupdate(void *bottomptr, void *topptr) {
151 void *tmpptr=bottomptr;
152 tprintf("%x -- %x\n", bottomptr, topptr);
153 while(tmpptr<topptr) {
156 gettype_size(tmpptr, &type, &size);
157 size=((size-1)&(~(ALIGNMENTSIZE-1)))+ALIGNMENTSIZE;
159 tmpptr+=ALIGNMENTSIZE;
162 //if marked we update the pointers
163 if (((struct ___Object___ *) tmpptr)->marked) {
164 pmc_updatePtrs(tmpptr, type);
170 void pmc_docompact() {
171 struct pmc_region * region=&pmc_heapptr->regions[BAMBOO_NUM_OF_CORE];
172 pmc_compact(region, !(BAMBOO_NUM_OF_CORE&1), region->startptr, region->endptr);
176 void pmc_compact(struct pmc_region * region, int forward, void *bottomptr, void *topptr) {
178 void *tmpptr=bottomptr;
179 while(tmpptr<topptr) {
182 gettype_size(tmpptr, &type, &size);
183 size=((size-1)&(~(ALIGNMENTSIZE-1)))+ALIGNMENTSIZE;
185 tmpptr+=ALIGNMENTSIZE;
188 //if marked we update the pointers
189 void *forwardptr=(void *)((struct ___Object___ *) tmpptr)->marked;
190 ((struct ___Object___ *) tmpptr)->marked=NULL;
192 //tprintf("Compacting %x\n",tmpptr);
193 memmove(forwardptr, tmpptr, size);
198 struct ___Object___ *backward=region->lastobj;
199 struct ___Object___ *lastobj=NULL;
202 backward=backward->backward;
205 gettype_size(lastobj, &type, &size);
206 size=((size-1)&(~(ALIGNMENTSIZE-1)))+ALIGNMENTSIZE;
207 void *forwardptr=(void *)((struct ___Object___ *) lastobj)->marked;
208 ((struct ___Object___ *) lastobj)->marked=NULL;
209 //tprintf("Compacting %x\n",lastobj);
210 memmove(forwardptr, lastobj, size);