From: bdemsky Date: Mon, 9 May 2011 04:32:35 +0000 (+0000) Subject: changes committed X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=8d54c567d22483cbbbb9e910bb38306cb1e5bbcb;p=IRC.git changes committed --- diff --git a/Robust/src/Runtime/bamboo/gcqueue.c b/Robust/src/Runtime/bamboo/gcqueue.c new file mode 100644 index 00000000..3e51f265 --- /dev/null +++ b/Robust/src/Runtime/bamboo/gcqueue.c @@ -0,0 +1,17 @@ +#include "gcqueue.h" + +struct pointerblock *gchead=NULL; +int gcheadindex=0; +struct pointerblock *gctail=NULL; +int gctailindex=0; +struct pointerblock *gctail2=NULL; +int gctailindex2=0; +struct pointerblock *gcspare=NULL; + +struct lobjpointerblock *gclobjhead=NULL; +int gclobjheadindex=0; +struct lobjpointerblock *gclobjtail=NULL; +int gclobjtailindex=0; +struct lobjpointerblock *gclobjtail2=NULL; +int gclobjtailindex2=0; +struct lobjpointerblock *gclobjspare=NULL; diff --git a/Robust/src/Runtime/bamboo/gcqueue.h b/Robust/src/Runtime/bamboo/gcqueue.h new file mode 100644 index 00000000..5b7a01f4 --- /dev/null +++ b/Robust/src/Runtime/bamboo/gcqueue.h @@ -0,0 +1,217 @@ +#ifndef GCQUEUE_H +#define GCQUEUE_H + +#define NUMPTRS 120 + +struct pointerblock { + unsigned int ptrs[NUMPTRS]; + struct pointerblock *next; +}; + +#define NUMLOBJPTRS 20 + +struct lobjpointerblock { + unsigned int lobjs[NUMLOBJPTRS]; + int lengths[NUMLOBJPTRS]; + int hosts[NUMLOBJPTRS]; + struct lobjpointerblock *next; + struct lobjpointerblock *prev; +}; + +extern struct pointerblock *gchead; +extern int gcheadindex; +extern struct pointerblock *gctail; +extern int gctailindex; +extern struct pointerblock *gctail2; +extern int gctailindex2; +extern struct pointerblock *gcspare; + +extern struct lobjpointerblock *gclobjhead; +extern int gclobjheadindex; +extern struct lobjpointerblock *gclobjtail; +extern int gclobjtailindex; +extern struct lobjpointerblock *gclobjtail2; +extern int gclobjtailindex2; +extern struct lobjpointerblock *gclobjspare; + +static void gc_queueinit() { + // initialize queue + if (gchead==NULL) { + gcheadindex=gctailindex=gctailindex2 = 0; + gchead=gctail=gctail2=RUNMALLOC(sizeof(struct pointerblock)); + } else { + gctailindex=gctailindex2=gcheadindex=0; + gctail=gctail2=gchead; + } + gchead->next=NULL; + // initialize the large obj queues + if (gclobjhead==NULL) { + gclobjheadindex=0; + gclobjtailindex=0; + gclobjtailindex2=0; + gclobjhead=gclobjtail=gclobjtail2=RUNMALLOC(sizeof(struct lobjpointerblock)); + } else { + gclobjtailindex=gclobjtailindex2=gclobjheadindex=0; + gclobjtail=gclobjtail2=gclobjhead; + } + gclobjhead->next=gclobjhead->prev=NULL; +} + +static void gc_enqueue_I(unsigned int ptr) { + if (gcheadindex==NUMPTRS) { + struct pointerblock * tmp; + if (gcspare!=NULL) { + tmp=gcspare; + gcspare=NULL; + tmp->next = NULL; + } else { + tmp=RUNMALLOC_I(sizeof(struct pointerblock)); + } + gchead->next=tmp; + gchead=tmp; + gcheadindex=0; + } + gchead->ptrs[gcheadindex++]=ptr; +} + + +// dequeue and destroy the queue +static unsigned int gc_dequeue_I() { + if (gctailindex==NUMPTRS) { + struct pointerblock *tmp=gctail; + gctail=gctail->next; + gctailindex=0; + if (gcspare!=NULL) { + RUNFREE_I(tmp); + } else { + gcspare=tmp; + gcspare->next = NULL; + } + } + return gctail->ptrs[gctailindex++]; +} + +// dequeue and do not destroy the queue +static unsigned int gc_dequeue2_I() { + if (gctailindex2==NUMPTRS) { + struct pointerblock *tmp=gctail2; + gctail2=gctail2->next; + gctailindex2=0; + } + return gctail2->ptrs[gctailindex2++]; +} + +static int gc_moreItems_I() { + return !((gchead==gctail)&&(gctailindex==gcheadindex)); +} + +static int gc_moreItems2_I() { + return !((gchead==gctail2)&&(gctailindex2==gcheadindex)); +} + +// should be invoked with interruption closed +// enqueue a large obj: start addr & length +static void gc_lobjenqueue_I(unsigned int ptr, + unsigned int length, + unsigned int host) { + if (gclobjheadindex==NUMLOBJPTRS) { + struct lobjpointerblock * tmp; + if (gclobjspare!=NULL) { + tmp=gclobjspare; + gclobjspare=NULL; + tmp->next = NULL; + tmp->prev = NULL; + } else { + tmp=RUNMALLOC_I(sizeof(struct lobjpointerblock)); + } + gclobjhead->next=tmp; + tmp->prev = gclobjhead; + gclobjhead=tmp; + gclobjheadindex=0; + } + gclobjhead->lobjs[gclobjheadindex]=ptr; + gclobjhead->lengths[gclobjheadindex]=length; + gclobjhead->hosts[gclobjheadindex++]=host; +} + +// dequeue and destroy the queue +static unsigned int gc_lobjdequeue_I(unsigned int * length, + unsigned int * host) { + if (gclobjtailindex==NUMLOBJPTRS) { + struct lobjpointerblock *tmp=gclobjtail; + gclobjtail=gclobjtail->next; + gclobjtailindex=0; + gclobjtail->prev = NULL; + if (gclobjspare!=NULL) { + RUNFREE_I(tmp); + } else { + gclobjspare=tmp; + tmp->next = NULL; + tmp->prev = NULL; + } + } + if(length != NULL) { + *length = gclobjtail->lengths[gclobjtailindex]; + } + if(host != NULL) { + *host = (unsigned int)(gclobjtail->hosts[gclobjtailindex]); + } + return gclobjtail->lobjs[gclobjtailindex++]; +} + +static int gc_lobjmoreItems_I() { + return !((gclobjhead==gclobjtail)&&(gclobjtailindex==gclobjheadindex)); +} + +// dequeue and don't destroy the queue +static void gc_lobjdequeue2_I() { + if (gclobjtailindex2==NUMLOBJPTRS) { + gclobjtail2=gclobjtail2->next; + gclobjtailindex2=1; + } else { + gclobjtailindex2++; + } +} + +static int gc_lobjmoreItems2_I() { + return !((gclobjhead==gclobjtail2)&&(gclobjtailindex2==gclobjheadindex)); +} + +// 'reversly' dequeue and don't destroy the queue +static void gc_lobjdequeue3_I() { + if (gclobjtailindex2==0) { + gclobjtail2=gclobjtail2->prev; + gclobjtailindex2=NUMLOBJPTRS-1; + } else { + gclobjtailindex2--; + } +} + +static int gc_lobjmoreItems3_I() { + return !((gclobjtail==gclobjtail2)&&(gclobjtailindex2==gclobjtailindex)); +} + +static void gc_lobjqueueinit4_I() { + gclobjtail2 = gclobjtail; + gclobjtailindex2 = gclobjtailindex; +} + +static unsigned int gc_lobjdequeue4_I(unsigned int * length, + unsigned int * host) { + if (gclobjtailindex2==NUMLOBJPTRS) { + gclobjtail2=gclobjtail2->next; + gclobjtailindex2=0; + } + if(length != NULL) { + *length = gclobjtail2->lengths[gclobjtailindex2]; + } + if(host != NULL) { + *host = (unsigned int)(gclobjtail2->hosts[gclobjtailindex2]); + } + return gclobjtail2->lobjs[gclobjtailindex2++]; +} + +static int gc_lobjmoreItems4_I() { + return !((gclobjhead==gclobjtail2)&&(gclobjtailindex2==gclobjheadindex)); +} +#endif diff --git a/Robust/src/Runtime/bamboo/multicoregarbage.c b/Robust/src/Runtime/bamboo/multicoregarbage.c index e4ab8953..93137703 100644 --- a/Robust/src/Runtime/bamboo/multicoregarbage.c +++ b/Robust/src/Runtime/bamboo/multicoregarbage.c @@ -4,33 +4,16 @@ #include "runtime.h" #include "multicoregarbage.h" #include "multicoregcmark.h" +#include "gcqueue.h" #include "multicoregccompact.h" #include "multicoregcflush.h" #include "multicoreruntime.h" #include "multicoregcprofile.h" -struct pointerblock *gchead=NULL; -int gcheadindex=0; -struct pointerblock *gctail=NULL; -int gctailindex=0; -struct pointerblock *gctail2=NULL; -int gctailindex2=0; -struct pointerblock *gcspare=NULL; - -struct lobjpointerblock *gclobjhead=NULL; -int gclobjheadindex=0; -struct lobjpointerblock *gclobjtail=NULL; -int gclobjtailindex=0; -struct lobjpointerblock *gclobjtail2=NULL; -int gclobjtailindex2=0; -struct lobjpointerblock *gclobjspare=NULL; - -#ifdef MULTICORE_GC #ifdef SMEMM extern unsigned int gcmem_mixed_threshold; extern unsigned int gcmem_mixed_usedmem; #endif // SMEMM -#endif // MULTICORE_GC #ifdef GC_DEBUG // dump whole mem in blocks @@ -108,13 +91,12 @@ void dumpSMem() { void initmulticoregcdata() { if(STARTUPCORE == BAMBOO_NUM_OF_CORE) { // startup core to initialize corestatus[] - int i; - for(i = 0; i < NUMCORESACTIVE; ++i) { + for(int i = 0; i < NUMCORESACTIVE; i++) { gccorestatus[i] = 1; gcnumsendobjs[0][i] = gcnumsendobjs[1][i] = 0; gcnumreceiveobjs[0][i] = gcnumreceiveobjs[1][i] = 0; } - for(i = 0; i < NUMCORES4GC; ++i) { + for(int i = 0; i < NUMCORES4GC; i++) { gcloads[i] = 0; gcrequiredmems[i] = 0; gcstopblock[i] = 0; @@ -165,8 +147,7 @@ void dismulticoregcdata() { void initGC() { if(STARTUPCORE == BAMBOO_NUM_OF_CORE) { - int i; - for(i = 0; i < NUMCORES4GC; ++i) { + for(int i = 0; i < NUMCORES4GC; i++) { gccorestatus[i] = 1; gcnumsendobjs[0][i] = gcnumsendobjs[1][i] = 0; gcnumreceiveobjs[0][i] = gcnumreceiveobjs[1][i] = 0; @@ -175,7 +156,7 @@ void initGC() { gcfilledblocks[i] = 0; gcstopblock[i] = 0; } - for(i = NUMCORES4GC; i < NUMCORESACTIVE; ++i) { + for(int i = NUMCORES4GC; i < NUMCORESACTIVE; i++) { gccorestatus[i] = 1; gcnumsendobjs[0][i] = gcnumsendobjs[1][i] = 0; gcnumreceiveobjs[0][i] = gcnumreceiveobjs[1][i] = 0; @@ -183,7 +164,7 @@ void initGC() { gcheaptop = 0; gctopcore = 0; gctopblock = 0; - gcnumsrobjs_index = 0; + gcnumsrobjs_index = 0; } gcself_numsendobjs = 0; gcself_numreceiveobjs = 0; @@ -196,28 +177,7 @@ void initGC() { gccurr_heaptop = 0; gcdstcore = 0; - // initialize queue - if (gchead==NULL) { - gcheadindex=gctailindex=gctailindex2 = 0; - gchead=gctail=gctail2=RUNMALLOC(sizeof(struct pointerblock)); - } else { - gctailindex=gctailindex2=gcheadindex=0; - gctail=gctail2=gchead; - } - gchead->next=NULL; - - // initialize the large obj queues - if (gclobjhead==NULL) { - gclobjheadindex=0; - gclobjtailindex=0; - gclobjtailindex2=0; - gclobjhead=gclobjtail=gclobjtail2= - RUNMALLOC(sizeof(struct lobjpointerblock)); - } else { - gclobjtailindex=gclobjtailindex2=gclobjheadindex=0; - gclobjtail=gclobjtail2=gclobjhead; - } - gclobjhead->next=gclobjhead->prev=NULL; + gcqueue_init(); freeMGCHash(gcforwardobjtbl); gcforwardobjtbl = allocateMGCHash(20, 3); @@ -226,8 +186,7 @@ void initGC() { } bool gc_checkAllCoreStatus_I() { - int i; - for(i = 0; i < NUMCORESACTIVE; ++i) { + for(int i = 0; i < NUMCORESACTIVE; i++) { if(gccorestatus[i] != 0) { return false; } @@ -236,7 +195,6 @@ bool gc_checkAllCoreStatus_I() { } INLINE void checkMarkStatus() { - int i; if((!waitconfirm) || (waitconfirm && (numconfirm == 0))) { unsigned int entry_index = 0; @@ -262,7 +220,7 @@ INLINE void checkMarkStatus() { waitconfirm = true; numconfirm = NUMCORESACTIVE - 1; BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME(); - for(i = 1; i < NUMCORESACTIVE; ++i) { + for(int i = 1; i < NUMCORESACTIVE; i++) { gccorestatus[i] = 1; // send mark phase finish confirm request msg to core i send_msg_1(i, GCMARKCONFIRM, false); @@ -272,17 +230,17 @@ INLINE void checkMarkStatus() { // check if the sum of send objs and receive obj are the same // yes->check if the info is the latest; no->go on executing unsigned int sumsendobj = 0; - for(i = 0; i < NUMCORESACTIVE; ++i) { + for(int i = 0; i < NUMCORESACTIVE; i++) { sumsendobj += gcnumsendobjs[gcnumsrobjs_index][i]; } - for(i = 0; i < NUMCORESACTIVE; ++i) { + for(int i = 0; i < NUMCORESACTIVE; i++) { sumsendobj -= gcnumreceiveobjs[gcnumsrobjs_index][i]; } if(0 == sumsendobj) { // Check if there are changes of the numsendobjs or numreceiveobjs on // each core bool ischanged = false; - for(i = 0; i < NUMCORESACTIVE; ++i) { + for(int i = 0; i < NUMCORESACTIVE; i++) { if((gcnumsendobjs[0][i] != gcnumsendobjs[1][i]) || (gcnumreceiveobjs[0][i] != gcnumreceiveobjs[1][i]) ) { ischanged = true; @@ -293,7 +251,7 @@ INLINE void checkMarkStatus() { // all the core status info are the latest,stop mark phase gcphase = COMPACTPHASE; // restore the gcstatus for all cores - for(i = 0; i < NUMCORESACTIVE; ++i) { + for(int i = 0; i < NUMCORESACTIVE; i++) { gccorestatus[i] = 1; } } else { @@ -321,11 +279,10 @@ INLINE void checkMarkStatus() { // compute load balance for all cores INLINE int loadbalance(unsigned int * heaptop) { // compute load balance - int i; // get the total loads unsigned int tloads = gcloads[STARTUPCORE]; - for(i = 1; i < NUMCORES4GC; i++) { + for(int i = 1; i < NUMCORES4GC; i++) { tloads += gcloads[i]; } *heaptop = gcbaseva + tloads; @@ -432,8 +389,7 @@ INLINE bool cacheLObjs() { } // update the bmmboo_smemtbl to record current shared mem usage -void updateSmemTbl(unsigned int coren, - unsigned int localtop) { +void updateSmemTbl(unsigned int coren, unsigned int localtop) { unsigned int ltopcore = 0; unsigned int bound = BAMBOO_SMEM_SIZE_L; BLOCKINDEX(localtop, <opcore); @@ -441,31 +397,26 @@ void updateSmemTbl(unsigned int coren, bound = BAMBOO_SMEM_SIZE; } unsigned int load = (unsigned int)(localtop-gcbaseva)%(unsigned int)bound; - unsigned int i = 0; - unsigned int j = 0; unsigned int toset = 0; - do { - toset = gc_core2block[2*coren+i]+(unsigned int)(NUMCORES4GC*2)*j; - if(toset < ltopcore) { - bamboo_smemtbl[toset]=(toset= 0; i--) { + for(int i = gcnumblock-1; i >= 0; i--) { if(bamboo_smemtbl[i] > 0) { - break; - } - } - if(i == -1) { - tmpheaptop = gcbaseva; - } else { - tmpheaptop = gcbaseva+bamboo_smemtbl[i]+((iptr; *filledblocks = to->numblocks; } - + // send msgs to core coordinator indicating that the compact is finishing // send compact finish message to core coordinator if(STARTUPCORE == BAMBOO_NUM_OF_CORE) { @@ -506,21 +502,15 @@ innercompact: to->ptr = gcmovestartaddr; to->numblocks = gcblock2fill - 1; - to->bound = ((to->numblocks==0)?BAMBOO_SMEM_SIZE_L:BAMBOO_SMEM_SIZE_L) - +BAMBOO_SMEM_SIZE*to->numblocks; + to->bound = ((to->numblocks==0)?BAMBOO_SMEM_SIZE_L:BAMBOO_SMEM_SIZE_L)+BAMBOO_SMEM_SIZE*to->numblocks; BASEPTR(gcdstcore, to->numblocks, &(to->base)); to->offset = to->ptr - to->base; - to->top = (to->numblocks==0)?(to->offset) - :(to->bound-BAMBOO_SMEM_SIZE+to->offset); + to->top = (to->numblocks==0)?(to->offset):(to->bound-BAMBOO_SMEM_SIZE+to->offset); to->base = to->ptr; to->offset = BAMBOO_CACHE_LINE_SIZE; to->ptr += to->offset; // for header to->top += to->offset; - if(gcdstcore == BAMBOO_NUM_OF_CORE) { - *localcompact = true; - } else { - *localcompact = false; - } + *localcompact = (gcdstcore == BAMBOO_NUM_OF_CORE); CACHEADAPT_SAMPLING_DATA_REVISE_INIT(); goto innercompact; } @@ -528,9 +518,7 @@ innercompact: } void compact() { - if(COMPACTPHASE != gcphase) { - BAMBOO_EXIT(0xb025); - } + BAMBOO_ASSERT(COMPACTPHASE == gcphase, 0xb025); // initialize pointers for comapcting struct moveHelper * orig = (struct moveHelper *)RUNMALLOC(sizeof(struct moveHelper)); @@ -542,20 +530,19 @@ void compact() { 0, to->base, 0, false); RUNFREE(orig); RUNFREE(to); - return; - } - CACHEADAPT_SAMPLING_DATA_REVISE_INIT(); + } else { + CACHEADAPT_SAMPLING_DATA_REVISE_INIT(); - unsigned int filledblocks = 0; - unsigned int heaptopptr = 0; - bool localcompact = true; - compacthelper(orig, to, &filledblocks, &heaptopptr, &localcompact); - RUNFREE(orig); - RUNFREE(to); + unsigned int filledblocks = 0; + unsigned int heaptopptr = 0; + bool localcompact = true; + compacthelper(orig, to, &filledblocks, &heaptopptr, &localcompact); + RUNFREE(orig); + RUNFREE(to); + } } void compact_master(struct moveHelper * orig, struct moveHelper * to) { - bool finalcompact = false; // initialize pointers for comapcting initOrig_Dst(orig, to); CACHEADAPT_SAMPLING_DATA_REVISE_INIT(); diff --git a/Robust/src/Runtime/bamboo/multicoregcflush.c b/Robust/src/Runtime/bamboo/multicoregcflush.c index e6c6d6df..ea4b45f8 100644 --- a/Robust/src/Runtime/bamboo/multicoregcflush.c +++ b/Robust/src/Runtime/bamboo/multicoregcflush.c @@ -4,7 +4,8 @@ #include "ObjectHash.h" #include "GenericHashtable.h" -extern int corenum; +/* Task specific includes */ + #ifdef TASK extern struct parameterwrapper ** objectqueues[][NUMCLASSES]; extern int numqueues[][NUMCLASSES]; @@ -17,74 +18,46 @@ extern int runtime_locklen; extern struct global_defs_t * global_defs_p; -#ifdef SMEMM -extern unsigned int gcmem_mixed_threshold; -extern unsigned int gcmem_mixed_usedmem; -#endif - #ifdef MGC extern struct lockvector bamboo_threadlocks; #endif -extern struct pointerblock *gchead; -extern int gcheadindex; -extern struct pointerblock *gctail; -extern int gctailindex; -extern struct pointerblock *gctail2; -extern int gctailindex2; -extern struct pointerblock *gcspare; +// NOTE: the objptr should not be NULL and should not be non shared ptr +#define FLUSHOBJ(obj, tt) {void *flushtmpptr=obj; if (flushtmpptr!=NULL) obj=flushObj(flushtmpptr);} +#define FLUSHOBJNONNULL(obj, tt) {void *flushtmpptr=obj; obj=flushObj(flushtmpptr);} -extern struct lobjpointerblock *gclobjhead; -extern int gclobjheadindex; -extern struct lobjpointerblock *gclobjtail; -extern int gclobjtailindex; -extern struct lobjpointerblock *gclobjtail2; -extern int gclobjtailindex2; -extern struct lobjpointerblock *gclobjspare; +INLINE void * flushObj(void * objptr) { + return gcmappingtbl[OBJMAPPINGINDEX((unsigned int)objptr)]; +} -// NOTE: the objptr should not be NULL and should not be non shared ptr -INLINE void * flushObj(void * objptr, int linenum, void * ptr, int tt) { - void * dstptr = gcmappingtbl[OBJMAPPINGINDEX((unsigned int)objptr)]; - return dstptr; +INLINE void updategarbagelist(struct garbagelist *listptr) { + for(;listptr!=NULL; listptr=listptr->next) { + for(int i=0; isize; i++) { + FLUSHOBJ(listptr->array[i], i); + } + } } INLINE void flushRuntimeObj(struct garbagelist * stackptr) { - int i,j; // flush current stack - while(stackptr!=NULL) { - for(i=0; isize; i++) { - if(stackptr->array[i] != NULL) { - stackptr->array[i] = - flushObj(stackptr->array[i], __LINE__, stackptr->array[i], i); - } - } - stackptr=stackptr->next; - } + updategarbagelist(stackptr); // flush static pointers global_defs_p if(STARTUPCORE == BAMBOO_NUM_OF_CORE) { - struct garbagelist * staticptr=(struct garbagelist *)global_defs_p; - for(i=0; isize; i++) { - if(staticptr->array[i] != NULL) { - staticptr->array[i] = - flushObj(staticptr->array[i], __LINE__, staticptr->array[i], i); - } - } + updategarbagelist((struct garbagelist *)global_defs_p); } #ifdef TASK // flush objectsets if(BAMBOO_NUM_OF_CORE < NUMCORESACTIVE) { - for(i=0; iobjectset; - struct ObjectNode * ptr=set->listhead; - while(ptr!=NULL) { - ptr->key = flushObj((void *)ptr->key, __LINE__, (void *)ptr->key, 0); - ptr=ptr->lnext; + for(struct ObjectNode * ptr=set->listhead;ptr!=NULL;ptr=ptr->lnext) { + FLUSHOBJNONNULL(ptr->key, 0); } ObjectHashrehash(set); } @@ -93,87 +66,63 @@ INLINE void flushRuntimeObj(struct garbagelist * stackptr) { // flush current task descriptor if(currtpd != NULL) { - for(i=0; inumParameters; i++) { + for(int i=0; inumParameters; i++) { // the parameter can not be NULL - currtpd->parameterArray[i] = flushObj(currtpd->parameterArray[i], - __LINE__, currtpd->parameterArray[i], i); + FLUSHOBJNONNULL(currtpd->parameterArray[i], i); } } // flush active tasks if(activetasks != NULL) { - struct genpointerlist * ptr=activetasks->list; - while(ptr!=NULL) { + for(struct genpointerlist * ptr=activetasks->list;ptr!=NULL;ptr=ptr->inext) { struct taskparamdescriptor *tpd=ptr->src; - int i; - for(i=0; inumParameters; i++) { + for(int i=0; inumParameters; i++) { // the parameter can not be NULL - tpd->parameterArray[i] = - flushObj(tpd->parameterArray[i], __LINE__, tpd->parameterArray[i], i); + FLUSHOBJNONNULL(tpd->parameterArray[i], i); } - ptr=ptr->inext; } genrehash(activetasks); } // flush cached transferred obj - struct QueueItem * tmpobjptr = getHead(&objqueue); - while(tmpobjptr != NULL) { + for(struct QueueItem * tmpobjptr = getHead(&objqueue);tmpobjptr != NULL;tmpobjptr = getNextQueueItem(tmpobjptr)) { struct transObjInfo * objInfo=(struct transObjInfo *)(tmpobjptr->objectptr); // the obj can not be NULL - objInfo->objptr = flushObj(objInfo->objptr, __LINE__, objInfo->objptr, 0); - tmpobjptr = getNextQueueItem(tmpobjptr); + FLUSHOBJNONNULL(objInfo->objptr, 0); } // flush cached objs to be transferred - struct QueueItem * item = getHead(totransobjqueue); - while(item != NULL) { + for(struct QueueItem * item = getHead(totransobjqueue);item != NULL;item = getNextQueueItem(item);) { struct transObjInfo * totransobj = (struct transObjInfo *)(item->objectptr); // the obj can not be NULL - totransobj->objptr = - flushObj(totransobj->objptr, __LINE__, totransobj->objptr, 0); - item = getNextQueueItem(item); + FLUSHOBJNONNULL(totransobj->objptr, 0); } // enqueue lock related info - for(i = 0; i < runtime_locklen; ++i) { - if(runtime_locks[i].redirectlock != NULL) { - runtime_locks[i].redirectlock = flushObj(runtime_locks[i].redirectlock, - __LINE__, runtime_locks[i].redirectlock, i); - } - if(runtime_locks[i].value != NULL) { - runtime_locks[i].value = flushObj(runtime_locks[i].value, - __LINE__, runtime_locks[i].value, i); - } + for(int i = 0; i < runtime_locklen; ++i) { + FLUSHOBJ(runtime_locks[i].redirectlock, i); + FLUSHOBJ(runtime_locks[i].value, i); } #endif #ifdef MGC // flush the bamboo_threadlocks - for(i = 0; i < bamboo_threadlocks.index; i++) { + for(int i = 0; i < bamboo_threadlocks.index; i++) { // the locked obj can not be NULL - bamboo_threadlocks.locks[i].object = - flushObj((void *)(bamboo_threadlocks.locks[i].object), - __LINE__, (void *)(bamboo_threadlocks.locks[i].object), i); + FLUSHOBJNONNULL(bamboo_threadlocks.locks[i].object, i); } // flush the bamboo_current_thread - if(bamboo_current_thread != 0) { - bamboo_current_thread = - (unsigned int)(flushObj((void *)bamboo_current_thread, - __LINE__, (void *)bamboo_current_thread, 0)); - } + FLUSHOBJ(bamboo_current_thread, 0); // flush global thread queue if(STARTUPCORE == BAMBOO_NUM_OF_CORE) { unsigned int thread_counter = *((unsigned int*)(bamboo_thread_queue+1)); if(thread_counter > 0) { unsigned int start = *((unsigned int*)(bamboo_thread_queue+2)); - for(i = thread_counter; i > 0; i--) { + for(int i = thread_counter; i > 0; i--) { // the thread obj can not be NULL - bamboo_thread_queue[4+start] = - (INTPTR)(flushObj((void *)bamboo_thread_queue[4+start], - __LINE__, (void *)bamboo_thread_queue, 0)); + FLUSHOBJNONNULL(bamboo_thread_queue[4+start], 0); start = (start+1)&bamboo_max_thread_num_mask; } } @@ -185,57 +134,42 @@ INLINE void flushRuntimeObj(struct garbagelist * stackptr) { INLINE void flushPtrsInObj(void * ptr) { int type = ((int *)(ptr))[0]; // scan all pointers in ptr - unsigned int * pointer; - pointer=pointerarray[type]; + unsigned int * pointer=pointerarray[type]; if (pointer==0) { /* Array of primitives */ - pointer=pointerarray[OBJECTTYPE]; +#ifdef OBJECTHASPOINTERS //handle object class + pointer=pointerarray[OBJECTTYPE]; unsigned int size=pointer[0]; - int i; - for(i=1; i<=size; i++) { + for(int i=1; i<=size; i++) { unsigned int offset=pointer[i]; - void * objptr=*((void **)(((char *)ptr)+offset)); - if(objptr != NULL) { - *((void **)(((char *)ptr)+offset)) = flushObj(objptr, __LINE__, ptr, i); - } + FLUSHOBJ(*((void **)(((char *)ptr)+offset)), i); } +#endif } else if (((unsigned int)pointer)==1) { /* Array of pointers */ struct ArrayObject *ao=(struct ArrayObject *) ptr; int length=ao->___length___; - int j; - for(j=0; j___length___)+sizeof(int)))[j]; - if(objptr != NULL) { - ((void **)(((char *)&ao->___length___)+sizeof(int)))[j] = - flushObj(objptr, __LINE__, ptr, j); - } + for(int j=0; j___length___)+sizeof(int)))[j], j); } - { - pointer=pointerarray[OBJECTTYPE]; - //handle object class - unsigned int size=pointer[0]; - int i; - for(i=1; i<=size; i++) { - unsigned int offset=pointer[i]; - void * objptr=*((void **)(((char *)ptr)+offset)); - if(objptr != NULL) { - *((void **)(((char *)ptr)+offset)) = - flushObj(objptr, __LINE__, ptr, i); - } - } +#ifdef OBJECTHASPOINTERS + pointer=pointerarray[OBJECTTYPE]; + //handle object class + unsigned int size=pointer[0]; + + for(int i=1; i<=size; i++) { + unsigned int offset=pointer[i]; + FLUSHOBJ(*((void **)(((char *)ptr)+offset)), i); } +#endif } else { unsigned int size=pointer[0]; - int i; - for(i=1; i<=size; i++) { + + for(int i=1; i<=size; i++) { unsigned int offset=pointer[i]; - void * objptr=*((void **)(((char *)ptr)+offset)); - if(objptr != NULL) { - *((void **)(((char *)ptr)+offset)) = flushObj(objptr, __LINE__, ptr, i); - } - } + FLUSHOBJ(*((void **)(((char *)ptr)+offset)), i); + } } } @@ -243,7 +177,6 @@ void flush(struct garbagelist * stackptr) { BAMBOO_CACHE_MF(); flushRuntimeObj(stackptr); - while(true) { BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT(); if(!gc_moreItems_I()) { @@ -254,10 +187,9 @@ void flush(struct garbagelist * stackptr) { unsigned int ptr = gc_dequeue_I(); BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME(); // should be a local shared obj and should have mapping info - ptr = flushObj(ptr, __LINE__, ptr, 0); - if(ptr == NULL) { - BAMBOO_EXIT(0xb02a); - } + FLUSHOBJNONNULL(ptr, 0); + BAMBOO_ASSERT(ptr != NULL, 0xb02a); + if(((struct ___Object___ *)ptr)->marked == COMPACTED) { flushPtrsInObj((void *)ptr); // restore the mark field, indicating that this obj has been flushed @@ -270,10 +202,9 @@ void flush(struct garbagelist * stackptr) { // flush lobjs while(gc_lobjmoreItems_I()) { unsigned int ptr = gc_lobjdequeue_I(NULL, NULL); - ptr = flushObj(ptr, __LINE__, ptr, 0); - if(ptr == NULL) { - BAMBOO_EXIT(0xb02d); - } + FLUSHOBJ(ptr, 0); + BAMBOO_ASSERT(ptr!=NULL, 0xb02d); + if(((struct ___Object___ *)ptr)->marked == COMPACTED) { flushPtrsInObj((void *)ptr); // restore the mark field, indicating that this obj has been flushed diff --git a/Robust/src/Runtime/bamboo/multicoregcmark.c b/Robust/src/Runtime/bamboo/multicoregcmark.c index 264186e7..619c0718 100644 --- a/Robust/src/Runtime/bamboo/multicoregcmark.c +++ b/Robust/src/Runtime/bamboo/multicoregcmark.c @@ -3,6 +3,7 @@ #include "runtime.h" #include "multicoreruntime.h" #include "GenericHashtable.h" +#include "gcqueue.h" extern int corenum; #ifdef TASK @@ -26,202 +27,24 @@ extern unsigned int gcmem_mixed_usedmem; extern struct lockvector bamboo_threadlocks; #endif -extern struct pointerblock *gchead; -extern int gcheadindex; -extern struct pointerblock *gctail; -extern int gctailindex; -extern struct pointerblock *gctail2; -extern int gctailindex2; -extern struct pointerblock *gcspare; - -extern struct lobjpointerblock *gclobjhead; -extern int gclobjheadindex; -extern struct lobjpointerblock *gclobjtail; -extern int gclobjtailindex; -extern struct lobjpointerblock *gclobjtail2; -extern int gclobjtailindex2; -extern struct lobjpointerblock *gclobjspare; - -// should be invoked with interruption closed -INLINE void gc_enqueue_I(unsigned int ptr) { - if (gcheadindex==NUMPTRS) { - struct pointerblock * tmp; - if (gcspare!=NULL) { - tmp=gcspare; - gcspare=NULL; - tmp->next = NULL; - } else { - tmp=RUNMALLOC_I(sizeof(struct pointerblock)); - } - gchead->next=tmp; - gchead=tmp; - gcheadindex=0; - } - gchead->ptrs[gcheadindex++]=ptr; -} - -// dequeue and destroy the queue -INLINE unsigned int gc_dequeue_I() { - if (gctailindex==NUMPTRS) { - struct pointerblock *tmp=gctail; - gctail=gctail->next; - gctailindex=0; - if (gcspare!=NULL) { - RUNFREE_I(tmp); - } else { - gcspare=tmp; - gcspare->next = NULL; - } - } - return gctail->ptrs[gctailindex++]; -} - -// dequeue and do not destroy the queue -INLINE unsigned int gc_dequeue2_I() { - if (gctailindex2==NUMPTRS) { - struct pointerblock *tmp=gctail2; - gctail2=gctail2->next; - gctailindex2=0; - } - return gctail2->ptrs[gctailindex2++]; -} - -INLINE int gc_moreItems_I() { - return !((gchead==gctail)&&(gctailindex==gcheadindex)); -} - -INLINE int gc_moreItems2_I() { - return !((gchead==gctail2)&&(gctailindex2==gcheadindex)); -} - -// should be invoked with interruption closed -// enqueue a large obj: start addr & length -INLINE void gc_lobjenqueue_I(unsigned int ptr, - unsigned int length, - unsigned int host) { - if (gclobjheadindex==NUMLOBJPTRS) { - struct lobjpointerblock * tmp; - if (gclobjspare!=NULL) { - tmp=gclobjspare; - gclobjspare=NULL; - tmp->next = NULL; - tmp->prev = NULL; - } else { - tmp=RUNMALLOC_I(sizeof(struct lobjpointerblock)); - } - gclobjhead->next=tmp; - tmp->prev = gclobjhead; - gclobjhead=tmp; - gclobjheadindex=0; - } - gclobjhead->lobjs[gclobjheadindex]=ptr; - gclobjhead->lengths[gclobjheadindex]=length; - gclobjhead->hosts[gclobjheadindex++]=host; -} - -// dequeue and destroy the queue -INLINE unsigned int gc_lobjdequeue_I(unsigned int * length, - unsigned int * host) { - if (gclobjtailindex==NUMLOBJPTRS) { - struct lobjpointerblock *tmp=gclobjtail; - gclobjtail=gclobjtail->next; - gclobjtailindex=0; - gclobjtail->prev = NULL; - if (gclobjspare!=NULL) { - RUNFREE_I(tmp); - } else { - gclobjspare=tmp; - tmp->next = NULL; - tmp->prev = NULL; - } - } - if(length != NULL) { - *length = gclobjtail->lengths[gclobjtailindex]; - } - if(host != NULL) { - *host = (unsigned int)(gclobjtail->hosts[gclobjtailindex]); - } - return gclobjtail->lobjs[gclobjtailindex++]; -} - -INLINE int gc_lobjmoreItems_I() { - return !((gclobjhead==gclobjtail)&&(gclobjtailindex==gclobjheadindex)); -} - -// dequeue and don't destroy the queue -INLINE void gc_lobjdequeue2_I() { - if (gclobjtailindex2==NUMLOBJPTRS) { - gclobjtail2=gclobjtail2->next; - gclobjtailindex2=1; - } else { - gclobjtailindex2++; - } -} - -INLINE int gc_lobjmoreItems2_I() { - return !((gclobjhead==gclobjtail2)&&(gclobjtailindex2==gclobjheadindex)); -} - -// 'reversly' dequeue and don't destroy the queue -INLINE void gc_lobjdequeue3_I() { - if (gclobjtailindex2==0) { - gclobjtail2=gclobjtail2->prev; - gclobjtailindex2=NUMLOBJPTRS-1; - } else { - gclobjtailindex2--; - } -} - -INLINE int gc_lobjmoreItems3_I() { - return !((gclobjtail==gclobjtail2)&&(gclobjtailindex2==gclobjtailindex)); -} - -INLINE void gc_lobjqueueinit4_I() { - gclobjtail2 = gclobjtail; - gclobjtailindex2 = gclobjtailindex; -} - -INLINE unsigned int gc_lobjdequeue4_I(unsigned int * length, - unsigned int * host) { - if (gclobjtailindex2==NUMLOBJPTRS) { - gclobjtail2=gclobjtail2->next; - gclobjtailindex2=0; - } - if(length != NULL) { - *length = gclobjtail2->lengths[gclobjtailindex2]; - } - if(host != NULL) { - *host = (unsigned int)(gclobjtail2->hosts[gclobjtailindex2]); - } - return gclobjtail2->lobjs[gclobjtailindex2++]; -} - -INLINE int gc_lobjmoreItems4_I() { - return !((gclobjhead==gclobjtail2)&&(gclobjtailindex2==gclobjheadindex)); -} - -INLINE void gettype_size(void * ptr, - int * ttype, - unsigned int * tsize) { +INLINE void gettype_size(void * ptr, int * ttype, unsigned int * tsize) { int type = ((int *)ptr)[0]; - unsigned int size = 0; + unsigned int size; if(type < NUMCLASSES) { // a normal object - size = classsize[type]; + *tsize = classsize[type]; + *ttype = type; } else { // an array struct ArrayObject *ao=(struct ArrayObject *)ptr; unsigned int elementsize=classsize[type]; unsigned int length=ao->___length___; - size=sizeof(struct ArrayObject)+length*elementsize; + *tsize = sizeof(struct ArrayObject)+length*elementsize; + *ttype = type; } - *ttype = type; - *tsize = size; } -INLINE bool isLarge(void * ptr, - int * ttype, - unsigned int * tsize) { +INLINE bool isLarge(void * ptr, int * ttype, unsigned int * tsize) { // check if a pointer is referring to a large object gettype_size(ptr, ttype, tsize); unsigned int bound = (BAMBOO_SMEM_SIZE); @@ -230,7 +53,7 @@ INLINE bool isLarge(void * ptr, } // ptr is a start of a block OR it acrosses the boundary of current block return (((((unsigned int)ptr-gcbaseva)%(bound))==0)|| - ((bound-(((unsigned int)ptr-gcbaseva)%bound)) < (*tsize))); + ((bound-(((unsigned int)ptr-gcbaseva)%bound)) < (*tsize))); } INLINE unsigned int hostcore(void * ptr) { @@ -240,12 +63,29 @@ INLINE unsigned int hostcore(void * ptr) { return host; } +//push the null check into the mark macro +//#define MARKOBJ(objptr, ii) {void * marktmpptr=objptr; if (marktmpptr!=NULL) markObj(marktmpptr, __LINE__, ii);} + +//#define MARKOBJNONNULL(objptr, ii) {markObj(objptr, __LINE__, ii);} + +#define MARKOBJ(objptr, ii) {void * marktmpptr=objptr; if (marktmpptr!=NULL) markObj(marktmpptr);} + +#define MARKOBJNONNULL(objptr, ii) {markObj(objptr);} + // NOTE: the objptr should not be NULL and should be a shared obj -INLINE void markObj(void * objptr, int linenum, void * ptr, int ii) { +INLINE void markObj(void * objptr) { unsigned int host = hostcore(objptr); if(BAMBOO_NUM_OF_CORE == host) { // on this core - BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT(); + + /*BD: I think it is probably okay to keep interrupts enabled + * here... Reasoning is the following... Even if we enqueue an + * object twice, the pointers in it will be marked only once + * (we'll catch it in the mark phase), so correctness should not + * be a concern... The chances of this actually happening are + * pretty small, so efficiency should not be a concern + */ + if(((struct ___Object___ *)objptr)->marked == INIT) { // this is the first time that this object is discovered, // set the flag as DISCOVERED @@ -253,7 +93,6 @@ INLINE void markObj(void * objptr, int linenum, void * ptr, int ii) { BAMBOO_CACHE_FLUSH_LINE(objptr); gc_enqueue_I(objptr); } - BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME(); } else { // check if this obj has been forwarded if(!MGCHashcontains(gcforwardobjtbl, (int)objptr)) { @@ -266,51 +105,42 @@ INLINE void markObj(void * objptr, int linenum, void * ptr, int ii) { } } +INLINE void markgarbagelist(struct garbagelist * listptr) { + for(;listptr!=NULL;listptr=listptr->next) { + int size=listptr->size; + for(int i=0; iarray[i], i); + } + } +} + // enqueue root objs INLINE void tomark(struct garbagelist * stackptr) { - if(MARKPHASE != gcphase) { - BAMBOO_EXIT(0xb010); - } + BAMBOO_ASSERT(MARKPHASE == gcphase, 0xb010); + gcbusystatus = true; gcnumlobjs = 0; - int i,j; // enqueue current stack - while(stackptr!=NULL) { - for(i=0; isize; i++) { - if(stackptr->array[i] != NULL) { - markObj(stackptr->array[i], __LINE__, stackptr->array[i], i); - } - } - stackptr=stackptr->next; - } + markgarbagelist(stackptr); // enqueue static pointers global_defs_p if(STARTUPCORE == BAMBOO_NUM_OF_CORE) { - struct garbagelist * staticptr=(struct garbagelist *)global_defs_p; - while(staticptr != NULL) { - for(i=0; isize; i++) { - if(staticptr->array[i] != NULL) { - markObj(staticptr->array[i], __LINE__, staticptr->array[i], i); - } - } - staticptr = staticptr->next; - } + markgarbagelist((struct garbagelist *)global_defs_p); } #ifdef TASK // enqueue objectsets if(BAMBOO_NUM_OF_CORE < NUMCORESACTIVE) { - for(i=0; iobjectset; struct ObjectNode * ptr=set->listhead; - while(ptr!=NULL) { - markObj((void *)ptr->key, __LINE__, ptr, 0); - ptr=ptr->lnext; + for(;ptr!=NULL;ptr=ptr->lnext) { + MARKOBJNONNULL((void *)ptr->key, 0); } } } @@ -318,54 +148,44 @@ INLINE void tomark(struct garbagelist * stackptr) { // euqueue current task descriptor if(currtpd != NULL) { - for(i=0; inumParameters; i++) { + for(int i=0; inumParameters; i++) { // currtpd->parameterArray[i] can not be NULL - markObj(currtpd->parameterArray[i],__LINE__,currtpd->parameterArray[i],i); + MARKOBJNONNULL(currtpd->parameterArray[i], i); } } // euqueue active tasks if(activetasks != NULL) { struct genpointerlist * ptr=activetasks->list; - while(ptr!=NULL) { + for(;ptr!=NULL;ptr=ptr->inext) { struct taskparamdescriptor *tpd=ptr->src; - int i; - for(i=0; inumParameters; i++) { + for(int i=0; inumParameters; i++) { // the tpd->parameterArray[i] can not be NULL - markObj(tpd->parameterArray[i], __LINE__, tpd->parameterArray[i], i); + MARKOBJNONNULL(tpd->parameterArray[i], i); } - ptr=ptr->inext; } } // enqueue cached transferred obj struct QueueItem * tmpobjptr = getHead(&objqueue); - while(tmpobjptr != NULL) { + for(;tmpobjptr != NULL;tmpobjptr=getNextQueueItem(tmpobjptr)) { struct transObjInfo * objInfo=(struct transObjInfo *)(tmpobjptr->objectptr); // the objptr can not be NULL - markObj(objInfo->objptr, __LINE__, objInfo->objptr, 0); - tmpobjptr = getNextQueueItem(tmpobjptr); + MARKOBJNONNULL(objInfo->objptr, 0); } // enqueue cached objs to be transferred struct QueueItem * item = getHead(totransobjqueue); - while(item != NULL) { + for(;item != NULL;item=getNextQueueItem(item)) { struct transObjInfo * totransobj=(struct transObjInfo *)(item->objectptr); // the objptr can not be NULL - markObj(totransobj->objptr, __LINE__, totransobj->objptr, 0); - item = getNextQueueItem(item); - } // while(item != NULL) + MARKOBJNONNULL(totransobj->objptr, 0); + } // enqueue lock related info - for(i = 0; i < runtime_locklen; ++i) { - if(runtime_locks[i].redirectlock != NULL) { - markObj((void *)(runtime_locks[i].redirectlock), __LINE__, - (void *)(runtime_locks[i].redirectlock), 0); - } - if(runtime_locks[i].value != NULL) { - markObj((void *)(runtime_locks[i].value), __LINE__, - (void *)(runtime_locks[i].value), i); - } + for(int i = 0; i < runtime_locklen; i++) { + MARKOBJ((void *)(runtime_locks[i].redirectlock), 0); + MARKOBJ((void *)(runtime_locks[i].value), i); } #endif @@ -376,87 +196,70 @@ INLINE void tomark(struct garbagelist * stackptr) { unsigned int thread_counter = *((unsigned int*)(bamboo_thread_queue+1)); if(thread_counter > 0) { unsigned int start = *((unsigned int*)(bamboo_thread_queue+2)); - for(i = thread_counter; i > 0; i--) { + for(int i = thread_counter; i > 0; i--) { // the thread obj can not be NULL - markObj((void *)bamboo_thread_queue[4+start], __LINE__, - (void *)bamboo_thread_queue[4+start], 0); + MARKOBJNONNULL((void *)bamboo_thread_queue[4+start], 0); start = (start+1)&bamboo_max_thread_num_mask; } } } // enqueue the bamboo_threadlocks - for(i = 0; i < bamboo_threadlocks.index; i++) { + for(int i = 0; i < bamboo_threadlocks.index; i++) { // the locks can not be NULL - markObj((void *)(bamboo_threadlocks.locks[i].object), __LINE__, - (void *)(bamboo_threadlocks.locks[i].object), i); + MARKOBJNONNULL((void *)(bamboo_threadlocks.locks[i].object), i); } // enqueue the bamboo_current_thread - if(bamboo_current_thread != 0) { - markObj((void *)bamboo_current_thread, __LINE__, - (void *)bamboo_current_thread, 0); - } + MARKOBJ((void *)bamboo_current_thread, 0); #endif } -INLINE void scanPtrsInObj(void * ptr, - int type) { +INLINE void scanPtrsInObj(void * ptr, int type) { // scan all pointers in ptr - unsigned int * pointer; - pointer=pointerarray[type]; + unsigned int * pointer = pointerarray[type]; if (pointer==0) { /* Array of primitives */ +#ifdef OBJECTHASPOINTERS pointer=pointerarray[OBJECTTYPE]; //handle object class int size=pointer[0]; - int i; - for(i=1; i<=size; i++) { + for(int i=1; i<=size; i++) { unsigned int offset=pointer[i]; void * objptr=*((void **)(((char *)ptr)+offset)); - if(objptr != NULL) { - markObj(objptr, __LINE__, ptr, i); - } + MARKOBJ(objptr, i); } +#endif } else if (((unsigned int)pointer)==1) { /* Array of pointers */ struct ArrayObject *ao=(struct ArrayObject *) ptr; int length=ao->___length___; - int j; - for(j=0; j___length___)+sizeof(int)))[j]; - if(objptr != NULL) { - markObj(objptr, __LINE__, ptr, j); - } + for(int i=0; i___length___)+sizeof(int)))[i]; + MARKOBJ(objptr, i); } - { - pointer=pointerarray[OBJECTTYPE]; - //handle object class - int size=pointer[0]; - int i; - for(i=1; i<=size; i++) { - unsigned int offset=pointer[i]; - void * objptr=*((void **)(((char *)ptr)+offset)); - if(objptr != NULL) { - markObj(objptr, __LINE__, ptr, i); - } - } +#ifdef OBJECTHASPOINTERS + pointer=pointerarray[OBJECTTYPE]; + //handle object class + int size=pointer[0]; + for(int i=1; i<=size; i++) { + unsigned int offset=pointer[i]; + void * objptr=*((void **)(((char *)ptr)+offset)); + MARKOBJ(objptr, i); } +#endif } else { + /* Normal Object */ int size=pointer[0]; - int i; - for(i=1; i<=size; i++) { + for(int i=1; i<=size; i++) { unsigned int offset=pointer[i]; void * objptr=*((void **)(((char *)ptr)+offset)); - if(objptr != NULL) { - markObj(objptr, __LINE__, ptr, i); - } + MARKOBJ(objptr, i); } } } -INLINE void mark(bool isfirst, - struct garbagelist * stackptr) { +INLINE void mark(bool isfirst, struct garbagelist * stackptr) { if(isfirst) { // enqueue root objs tomark(stackptr); @@ -493,35 +296,25 @@ INLINE void mark(bool isfirst, gc_lobjenqueue_I(ptr, size, BAMBOO_NUM_OF_CORE); gcnumlobjs++; BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME(); - // mark this obj - ((struct ___Object___ *)ptr)->marked = MARKED; - BAMBOO_CACHE_FLUSH_LINE(ptr); } else { // ptr is an unmarked active object on this core ALIGNSIZE(size, &isize); gccurr_heaptop += isize; - // mark this obj - ((struct ___Object___ *)ptr)->marked = MARKED; - BAMBOO_CACHE_FLUSH_LINE(ptr); - + if((unsigned int)(ptr + size) > (unsigned int)gcmarkedptrbound) { gcmarkedptrbound = (unsigned int)(ptr + size); } } - + // mark this obj + ((struct ___Object___ *)ptr)->marked = MARKED; + BAMBOO_CACHE_FLUSH_LINE(ptr); + // scan the pointers in object scanPtrsInObj(ptr, type); } gcbusystatus = false; // send mark finish msg to core coordinator if(STARTUPCORE == BAMBOO_NUM_OF_CORE) { - int entry_index = 0; - if(waitconfirm) { - // phase 2 - entry_index = (gcnumsrobjs_index == 0) ? 1 : 0; - } else { - // phase 1 - entry_index = gcnumsrobjs_index; - } + int entry_index = waitconfirm ? (gcnumsrobjs_index==0) : gcnumsrobjs_index; gccorestatus[BAMBOO_NUM_OF_CORE] = 0; gcnumsendobjs[entry_index][BAMBOO_NUM_OF_CORE]=gcself_numsendobjs; gcnumreceiveobjs[entry_index][BAMBOO_NUM_OF_CORE]=gcself_numreceiveobjs; @@ -529,15 +322,14 @@ INLINE void mark(bool isfirst, } else { if(!sendStall) { send_msg_4(STARTUPCORE, GCFINISHMARK, BAMBOO_NUM_OF_CORE, - gcself_numsendobjs, gcself_numreceiveobjs, false); + gcself_numsendobjs, gcself_numreceiveobjs, false); sendStall = true; } } - - if(BAMBOO_NUM_OF_CORE == STARTUPCORE) { + + if(BAMBOO_NUM_OF_CORE == STARTUPCORE) return; - } - } + } BAMBOO_CACHE_MF(); } diff --git a/Robust/src/Runtime/bamboo/multicoregcmark.h b/Robust/src/Runtime/bamboo/multicoregcmark.h index f8588196..dcac595d 100644 --- a/Robust/src/Runtime/bamboo/multicoregcmark.h +++ b/Robust/src/Runtime/bamboo/multicoregcmark.h @@ -3,37 +3,5 @@ #ifdef MULTICORE_GC #include "multicore.h" -#define NUMPTRS 120 - -struct pointerblock { - unsigned int ptrs[NUMPTRS]; - struct pointerblock *next; -}; - -#define NUMLOBJPTRS 20 - -struct lobjpointerblock { - unsigned int lobjs[NUMLOBJPTRS]; - int lengths[NUMLOBJPTRS]; - int hosts[NUMLOBJPTRS]; - struct lobjpointerblock *next; - struct lobjpointerblock *prev; -}; - -INLINE void gc_enqueue_I(unsigned int ptr); -INLINE unsigned int gc_dequeue_I(); -INLINE void gc_lobjenqueue_I(unsigned int ptr, - unsigned int length, - unsigned int host); -INLINE int gc_lobjmoreItems_I(); -INLINE void gc_lobjdequeue2_I(); -INLINE int gc_lobjmoreItems2_I(); -INLINE void gc_lobjdequeue3_I(); -INLINE int gc_lobjmoreItems3_I(); -INLINE void gc_lobjqueueinit4(); -INLINE unsigned int gc_lobjdequeue4(unsigned int * length, - unsigned int * host); -INLINE int gc_lobjmoreItems4(); - #endif // MULTICORE_GC #endif // BAMBOO_MULTICORE_GC_MARK_H diff --git a/Robust/src/Runtime/bamboo/multicoremsg.c b/Robust/src/Runtime/bamboo/multicoremsg.c index 9876acc7..4c9a20bf 100644 --- a/Robust/src/Runtime/bamboo/multicoremsg.c +++ b/Robust/src/Runtime/bamboo/multicoremsg.c @@ -21,10 +21,8 @@ INLINE int checkMsgLength_I(int size) { case GCSTARTPREF: #endif #endif - { msglength = 1; break; - } #ifdef TASK case PROFILEOUTPUT: @@ -39,18 +37,14 @@ INLINE int checkMsgLength_I(int size) { case GCFINISHPREF: #endif #endif - { msglength = 2; break; - } case MEMREQUEST: case MEMRESPONSE: - { msglength = 3; break; - } - + case TRANSTALL: #ifdef TASK case LOCKGROUNT: @@ -68,11 +62,9 @@ INLINE int checkMsgLength_I(int size) { case GCPROFILES: #endif #endif - { msglength = 4; break; - } - + #ifdef TASK case LOCKREQUEST: #endif @@ -81,17 +73,13 @@ INLINE int checkMsgLength_I(int size) { case GCFINISHCOMPACT: case GCMARKREPORT: #endif - { msglength = 5; break; - } - + #ifdef TASK case REDIRECTLOCK: - { msglength = 6; break; - } #endif #ifdef TASK @@ -110,57 +98,45 @@ INLINE int checkMsgLength_I(int size) { } default: - { BAMBOO_EXIT(0xe001); break; } - } return msglength; } INLINE void processmsg_transobj_I() { MSG_INDEXINC_I(); struct transObjInfo * transObj=RUNMALLOC_I(sizeof(struct transObjInfo)); - int k = 0; - if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) { - BAMBOO_EXIT(0xe201); - } + BAMBOO_ASSERT(BAMBOO_NUM_OF_CORE <= NUMCORESACTIVE - 1, 0xe201); + // store the object and its corresponding queue info, enqueue it later transObj->objptr = (void *)msgdata[msgdataindex]; MSG_INDEXINC_I(); transObj->length = (msglength - 3) / 2; transObj->queues = RUNMALLOC_I(sizeof(int)*(msglength - 3)); - for(k = 0; k < transObj->length; ++k) { + for(int k = 0; k < transObj->length; k++) { transObj->queues[2*k] = msgdata[msgdataindex]; MSG_INDEXINC_I(); transObj->queues[2*k+1] = msgdata[msgdataindex]; MSG_INDEXINC_I(); } // check if there is an existing duplicate item - { - struct QueueItem * qitem = getHead(&objqueue); - struct QueueItem * prev = NULL; - while(qitem != NULL) { - struct transObjInfo * tmpinfo = - (struct transObjInfo *)(qitem->objectptr); - if(tmpinfo->objptr == transObj->objptr) { - // the same object, remove outdate one - RUNFREE_I(tmpinfo->queues); - RUNFREE_I(tmpinfo); - removeItem(&objqueue, qitem); - //break; - } else { - prev = qitem; - } - if(prev == NULL) { - qitem = getHead(&objqueue); - } else { - qitem = getNextQueueItem(prev); - } + struct QueueItem * prev = NULL; + for(struct QueueItem * qitem = getHead(&objqueue);qitem != NULL;qitem=(prev==NULL)?getHead(&objqueue):getNextQueueItem(prev)) { + struct transObjInfo * tmpinfo = (struct transObjInfo *)(qitem->objectptr); + if(tmpinfo->objptr == transObj->objptr) { + // the same object, remove outdate one + RUNFREE_I(tmpinfo->queues); + RUNFREE_I(tmpinfo); + removeItem(&objqueue, qitem); + //break; + } else { + prev = qitem; } - addNewItem_I(&objqueue, (void *)transObj); } - ++(self_numreceiveobjs); + addNewItem_I(&objqueue, (void *)transObj); + + self_numreceiveobjs++; #ifdef MULTICORE_GC if(gcprocessing) { if(STARTUPCORE == BAMBOO_NUM_OF_CORE) { @@ -170,10 +146,10 @@ INLINE void processmsg_transobj_I() { // send a update pregc information msg to the master core if(BAMBOO_CHECK_SEND_MODE()) { cache_msg_4(STARTUPCORE, GCFINISHPRE, BAMBOO_NUM_OF_CORE, - self_numsendobjs, self_numreceiveobjs); + self_numsendobjs, self_numreceiveobjs); } else { send_msg_4(STARTUPCORE, GCFINISHPRE, BAMBOO_NUM_OF_CORE, - self_numsendobjs, self_numreceiveobjs, true); + self_numsendobjs, self_numreceiveobjs, true); } } } @@ -181,10 +157,8 @@ INLINE void processmsg_transobj_I() { } INLINE void processmsg_transtall_I() { - if(BAMBOO_NUM_OF_CORE != STARTUPCORE) { - // non startup core can not receive stall msg - BAMBOO_EXIT(0xe002); - } + BAMBOO_ASSERT(BAMBOO_NUM_OF_CORE == STARTUPCORE,0xe002); + int num_core = msgdata[msgdataindex]; MSG_INDEXINC_I(); int data2 = msgdata[msgdataindex]; @@ -212,40 +186,31 @@ INLINE void processmsg_lockrequest_I() { MSG_INDEXINC_I(); // -1: redirected, 0: approved, 1: denied int deny=processlockrequest(locktype, data3, data2, data4, data4, true); - if(deny == -1) { - // this lock request is redirected - return; - } else { + if(deny != -1) { // send response msg // for 32 bit machine, the size is always 4 words, cache the msg first int tmp = deny==1 ? LOCKDENY : LOCKGROUNT; if(BAMBOO_CHECK_SEND_MODE()) { - cache_msg_4(data4, tmp, locktype, data2, data3); + cache_msg_4(data4, tmp, locktype, data2, data3); } else { - send_msg_4(data4, tmp, locktype, data2, data3, true); + send_msg_4(data4, tmp, locktype, data2, data3, true); } } } INLINE void processmsg_lockgrount_I() { MSG_INDEXINC_I(); - if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) { - BAMBOO_EXIT(0xe202); - } + BAMBOO_ASSERT(BAMBOO_NUM_OF_CORE <= NUMCORESACTIVE - 1, 0xe202); int data2 = msgdata[msgdataindex]; MSG_INDEXINC_I(); int data3 = msgdata[msgdataindex]; MSG_INDEXINC_I(); - if((lockobj == data2) && (lock2require == data3)) { - lockresult = 1; - lockflag = true; + BAMBOO_ASSERT((lockobj == data2) && (lock2require == data3), 0xe203); + lockresult = 1; + lockflag = true; #ifndef INTERRUPT - reside = false; + reside = false; #endif - } else { - // conflicts on lockresults - BAMBOO_EXIT(0xe203); - } } INLINE void processmsg_lockdeny_I() { @@ -254,19 +219,13 @@ INLINE void processmsg_lockdeny_I() { MSG_INDEXINC_I(); int data3 = msgdata[msgdataindex]; MSG_INDEXINC_I(); - if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) { - BAMBOO_EXIT(0xe204); - } - if((lockobj == data2) && (lock2require == data3)) { - lockresult = 0; - lockflag = true; + BAMBOO_ASSERT(BAMBOO_NUM_OF_CORE <= NUMCORESACTIVE - 1, 0xe204); + BAMBOO_ASSERT((lockobj == data2) && (lock2require == data3), 0xe205); + lockresult = 0; + lockflag = true; #ifndef INTERRUPT - reside = false; + reside = false; #endif - } else { - // conflicts on lockresults - BAMBOO_EXIT(0xe205); - } } INLINE void processmsg_lockrelease_I() { @@ -293,10 +252,7 @@ INLINE void processmsg_redirectlock_I() { int data5 = msgdata[msgdataindex]; MSG_INDEXINC_I(); // request core int deny = processlockrequest(data1, data3, data2, data5, data4, true); - if(deny == -1) { - // this lock request is redirected - return; - } else { + if(deny != -1) { // send response msg // for 32 bit machine, the size is always 4 words, cache the msg first if(BAMBOO_CHECK_SEND_MODE()) { @@ -313,22 +269,16 @@ INLINE void processmsg_redirectgrount_I() { MSG_INDEXINC_I(); int data2 = msgdata[msgdataindex]; MSG_INDEXINC_I(); - if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) { - BAMBOO_EXIT(0xe206); - } - if(lockobj == data2) { - int data3 = msgdata[msgdataindex]; - MSG_INDEXINC_I(); - lockresult = 1; - lockflag = true; - RuntimeHashadd_I(objRedirectLockTbl, lockobj, data3); + BAMBOO_ASSERT(BAMBOO_NUM_OF_CORE <= NUMCORESACTIVE - 1, 0xe206); + BAMBOO_ASSERT(lockobj == data2, 0xe207); + int data3 = msgdata[msgdataindex]; + MSG_INDEXINC_I(); + lockresult = 1; + lockflag = true; + RuntimeHashadd_I(objRedirectLockTbl, lockobj, data3); #ifndef INTERRUPT - reside = false; + reside = false; #endif - } else { - // conflicts on lockresults - BAMBOO_EXIT(0xe207); - } } INLINE void processmsg_redirectdeny_I() { @@ -337,19 +287,13 @@ INLINE void processmsg_redirectdeny_I() { MSG_INDEXINC_I(); int data3 = msgdata[msgdataindex]; MSG_INDEXINC_I(); - if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) { - BAMBOO_EXIT(0xe208); - } - if(lockobj == data2) { - lockresult = 0; - lockflag = true; + BAMBOO_ASSERT(BAMBOO_NUM_OF_CORE <= NUMCORESACTIVE - 1, 0x2e08); + BAMBOO_ASSERT(lockobj == data2, 0xe209); + lockresult = 0; + lockflag = true; #ifndef INTERRUPT - reside = false; + reside = false; #endif - } else { - // conflicts on lockresults - BAMBOO_EXIT(0xe209); - } } INLINE void processmsg_redirectrelease_I() { @@ -365,10 +309,7 @@ INLINE void processmsg_redirectrelease_I() { #ifdef PROFILE INLINE void processmsg_profileoutput_I() { - if(BAMBOO_NUM_OF_CORE == STARTUPCORE) { - // startup core can not receive profile output finish msg - BAMBOO_EXIT(0xe20a); - } + BAMBOO_ASSERT(BAMBOO_NUM_OF_CORE != STARTUPCORE, 0xe20a); stall = true; totalexetime = msgdata[msgdataindex]; MSG_INDEXINC_I(); @@ -385,10 +326,7 @@ INLINE void processmsg_profileoutput_I() { } INLINE void processmsg_profilefinish_I() { - if(BAMBOO_NUM_OF_CORE != STARTUPCORE) { - // non startup core can not receive profile output finish msg - BAMBOO_EXIT(0xe20b); - } + BAMBOO_ASSERT(BAMBOO_NUM_OF_CORE == STARTUPCORE, 0xe20b); int data1 = msgdata[msgdataindex]; MSG_INDEXINC_I(); profilestatus[data1] = 0; @@ -396,20 +334,15 @@ INLINE void processmsg_profilefinish_I() { #endif // PROFILE INLINE void processmsg_statusconfirm_I() { - if((BAMBOO_NUM_OF_CORE == STARTUPCORE) - || (BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1)) { - // wrong core to receive such msg - BAMBOO_EXIT(0xe003); + BAMBOO_ASSERT(((BAMBOO_NUM_OF_CORE != STARTUPCORE) && (BAMBOO_NUM_OF_CORE <= NUMCORESACTIVE - 1)), 0xe003); + // send response msg + // cache the msg first + if(BAMBOO_CHECK_SEND_MODE()) { + cache_msg_5(STARTUPCORE,STATUSREPORT,busystatus?1:0,BAMBOO_NUM_OF_CORE, + self_numsendobjs, self_numreceiveobjs); } else { - // send response msg - // cache the msg first - if(BAMBOO_CHECK_SEND_MODE()) { - cache_msg_5(STARTUPCORE,STATUSREPORT,busystatus?1:0,BAMBOO_NUM_OF_CORE, - self_numsendobjs, self_numreceiveobjs); - } else { - send_msg_5(STARTUPCORE,STATUSREPORT,busystatus?1:0,BAMBOO_NUM_OF_CORE, - self_numsendobjs,self_numreceiveobjs, true); - } + send_msg_5(STARTUPCORE,STATUSREPORT,busystatus?1:0,BAMBOO_NUM_OF_CORE, + self_numsendobjs,self_numreceiveobjs, true); } } @@ -423,17 +356,13 @@ INLINE void processmsg_statusreport_I() { int data4 = msgdata[msgdataindex]; MSG_INDEXINC_I(); // receive a status confirm info - if(BAMBOO_NUM_OF_CORE != STARTUPCORE) { - // wrong core to receive such msg - BAMBOO_EXIT(0xe004); - } else { - if(waitconfirm) { - numconfirm--; - } - corestatus[data2] = data1; - numsendobjs[data2] = data3; - numreceiveobjs[data2] = data4; + BAMBOO_ASSERT(BAMBOO_NUM_OF_CORE == STARTUPCORE, 0xe004); + if(waitconfirm) { + numconfirm--; } + corestatus[data2] = data1; + numsendobjs[data2] = data3; + numreceiveobjs[data2] = data4; } INLINE void processmsg_terminate_I() { @@ -452,33 +381,27 @@ INLINE void processmsg_memrequest_I() { int data2 = msgdata[msgdataindex]; MSG_INDEXINC_I(); // receive a shared memory request msg - if(BAMBOO_NUM_OF_CORE != STARTUPCORE) { - // wrong core to receive such msg - BAMBOO_EXIT(0xe005); - } else { - int allocsize = 0; - void * mem = NULL; + BAMBOO_ASSERT(BAMBOO_NUM_OF_CORE == STARTUPCORE, 0xe005); + int allocsize = 0; + void * mem = NULL; #ifdef MULTICORE_GC - if(gcprocessing && gcflag) { - // is currently doing GC and the master core did not decide to stop GC - } else { - // either not doing GC or the master core has decided to stop GC but - // // still sending msgs to other cores to inform them to stop the GC + if(!gcprocessing || !gcflag) { + // either not doing GC or the master core has decided to stop GC but + // // still sending msgs to other cores to inform them to stop the GC #endif - mem = smemalloc_I(data2, data1, &allocsize); - if(mem != NULL) { - // send the start_va to request core, cache the msg first - if(BAMBOO_CHECK_SEND_MODE()) { - cache_msg_3(data2, MEMRESPONSE, mem, allocsize); - } else { - send_msg_3(data2, MEMRESPONSE, mem, allocsize, true); - } - } //else if mem == NULL, the gcflag of the startup core has been set - // and all the other cores have been informed to start gc + mem = smemalloc_I(data2, data1, &allocsize); + if(mem != NULL) { + // send the start_va to request core, cache the msg first + if(BAMBOO_CHECK_SEND_MODE()) { + cache_msg_3(data2, MEMRESPONSE, mem, allocsize); + } else { + send_msg_3(data2, MEMRESPONSE, mem, allocsize, true); + } + } //else if mem == NULL, the gcflag of the startup core has been set + // and all the other cores have been informed to start gc #ifdef MULTICORE_GC - } -#endif } +#endif } INLINE void processmsg_memresponse_I() { @@ -522,18 +445,18 @@ INLINE void processmsg_memresponse_I() { #ifdef MULTICORE_GC INLINE void processmsg_gcstartpre_I() { // the first time to be informed to start gc - gcflag = true; - if(!smemflag) { + gcflag = true; + if(!smemflag) { // Zero out the remaining memory here because for the GC_CACHE_ADAPT // version, we need to make sure during the gcinit phase the shared heap // is not touched. Otherwise, there would be problem when adapt the cache // strategy. BAMBOO_CLOSE_CUR_MSP(); - bamboo_smem_size = 0; - bamboo_cur_msp = NULL; - smemflag = true; - bamboo_smem_zero_top = NULL; - } + bamboo_smem_size = 0; + bamboo_cur_msp = NULL; + smemflag = true; + bamboo_smem_zero_top = NULL; + } } INLINE void processmsg_gcstartinit_I() { @@ -563,14 +486,10 @@ INLINE void processmsg_gcfinishpre_I() { int data3 = msgdata[msgdataindex]; MSG_INDEXINC_I(); // received a init phase finish msg - if(BAMBOO_NUM_OF_CORE != STARTUPCORE) { - // non startup core can not receive this msg - BAMBOO_EXIT(0xe006); - } + BAMBOO_ASSERT(BAMBOO_NUM_OF_CORE == STARTUPCORE, 0xe006); + // All cores should do init GC - if(!gcprecheck) { - gcprecheck = true; - } + gcprecheck = true; gccorestatus[data1] = 0; gcnumsendobjs[0][data1] = data2; gcnumreceiveobjs[0][data1] = data3; @@ -580,10 +499,8 @@ INLINE void processmsg_gcfinishinit_I() { int data1 = msgdata[msgdataindex]; MSG_INDEXINC_I(); // received a init phase finish msg - if(BAMBOO_NUM_OF_CORE != STARTUPCORE) { - // non startup core can not receive this msg - BAMBOO_EXIT(0xe007); - } + BAMBOO_ASSERT(BAMBOO_NUM_OF_CORE == STARTUPCORE, 0xe007); + // All cores should do init GC if(data1 < NUMCORESACTIVE) { gccorestatus[data1] = 0; @@ -598,10 +515,8 @@ INLINE void processmsg_gcfinishmark_I() { int data3 = msgdata[msgdataindex]; MSG_INDEXINC_I(); // received a mark phase finish msg - if(BAMBOO_NUM_OF_CORE != STARTUPCORE) { - // non startup core can not receive this msg - BAMBOO_EXIT(0xe008); - } + BAMBOO_ASSERT(BAMBOO_NUM_OF_CORE == STARTUPCORE, 0xe008); + // all cores should do mark if(data1 < NUMCORESACTIVE) { gccorestatus[data1] = 0; @@ -619,11 +534,8 @@ INLINE void processmsg_gcfinishmark_I() { } INLINE void processmsg_gcfinishcompact_I() { - if(BAMBOO_NUM_OF_CORE != STARTUPCORE) { - // non startup core can not receive this msg - // return -1 - BAMBOO_EXIT(0xe009); - } + BAMBOO_ASSERT(BAMBOO_NUM_OF_CORE == STARTUPCORE, 0xe009); + int cnum = msgdata[msgdataindex]; MSG_INDEXINC_I(); int filledblocks = msgdata[msgdataindex]; @@ -661,10 +573,8 @@ INLINE void processmsg_gcfinishflush_I() { int data1 = msgdata[msgdataindex]; MSG_INDEXINC_I(); // received a flush phase finish msg - if(BAMBOO_NUM_OF_CORE != STARTUPCORE) { - // non startup core can not receive this msg - BAMBOO_EXIT(0xe00a); - } + BAMBOO_ASSERT(BAMBOO_NUM_OF_CORE == STARTUPCORE, 0xe00a); + // all cores should do flush if(data1 < NUMCORESACTIVE) { gccorestatus[data1] = 0; @@ -678,19 +588,15 @@ INLINE void processmsg_gcfinish_I() { } INLINE void processmsg_gcmarkconfirm_I() { - if((BAMBOO_NUM_OF_CORE==STARTUPCORE)||(BAMBOO_NUM_OF_CORE>NUMCORESACTIVE-1)){ - // wrong core to receive such msg - BAMBOO_EXIT(0xe00b); + BAMBOO_ASSERT(((BAMBOO_NUM_OF_CORE!=STARTUPCORE)&&(BAMBOO_NUM_OF_CORE<=NUMCORESACTIVE-1)), 0xe00b); + gcbusystatus = gc_moreItems2_I(); + // send response msg, cahce the msg first + if(BAMBOO_CHECK_SEND_MODE()) { + cache_msg_5(STARTUPCORE,GCMARKREPORT,BAMBOO_NUM_OF_CORE,gcbusystatus, + gcself_numsendobjs,gcself_numreceiveobjs); } else { - gcbusystatus = gc_moreItems2_I(); - // send response msg, cahce the msg first - if(BAMBOO_CHECK_SEND_MODE()) { - cache_msg_5(STARTUPCORE,GCMARKREPORT,BAMBOO_NUM_OF_CORE,gcbusystatus, - gcself_numsendobjs,gcself_numreceiveobjs); - } else { - send_msg_5(STARTUPCORE,GCMARKREPORT,BAMBOO_NUM_OF_CORE,gcbusystatus, - gcself_numsendobjs,gcself_numreceiveobjs, true); - } + send_msg_5(STARTUPCORE,GCMARKREPORT,BAMBOO_NUM_OF_CORE,gcbusystatus, + gcself_numsendobjs,gcself_numreceiveobjs, true); } } @@ -704,31 +610,24 @@ INLINE void processmsg_gcmarkreport_I() { int data4 = msgdata[msgdataindex]; MSG_INDEXINC_I(); // received a marked phase finish confirm response msg - if(BAMBOO_NUM_OF_CORE != STARTUPCORE) { - // wrong core to receive such msg - BAMBOO_EXIT(0xe00c); - } else { - int entry_index = 0; - if(waitconfirm) { - // phse 2 - numconfirm--; - entry_index = (gcnumsrobjs_index == 0) ? 1 : 0; - } else { - // can never reach here - BAMBOO_EXIT(0xe00d); - } - gccorestatus[data1] = data2; - gcnumsendobjs[entry_index][data1] = data3; - gcnumreceiveobjs[entry_index][data1] = data4; - } + BAMBOO_ASSERT(BAMBOO_NUM_OF_CORE == STARTUPCORE, 0xe00c); + int entry_index = 0; + BAMBOO_ASSERT(waitconfirm, 0xe00d); + + // phase 2 + numconfirm--; + entry_index = (gcnumsrobjs_index == 0) ? 1 : 0; + gccorestatus[data1] = data2; + gcnumsendobjs[entry_index][data1] = data3; + gcnumreceiveobjs[entry_index][data1] = data4; + } INLINE void processmsg_gcmarkedobj_I() { int data1 = msgdata[msgdataindex]; MSG_INDEXINC_I(); - if(!ISSHAREDOBJ(data1)) { - BAMBOO_EXIT(0xa0000000+(int)data1); - } + BAMBOO_ASSERT(ISSHAREDOBJ(data1), 0xa0000000+(int)data1); + // received a markedObj msg if(((struct ___Object___ *)data1)->marked == INIT) { // this is the first time that this object is discovered, @@ -752,14 +651,12 @@ INLINE void processmsg_gcmovestart_I() { INLINE void processmsg_gclobjinfo_I() { numconfirm--; - int data1 = msgdata[msgdataindex]; MSG_INDEXINC_I(); int data2 = msgdata[msgdataindex]; MSG_INDEXINC_I(); - if(BAMBOO_NUM_OF_CORE > NUMCORES4GC - 1) { - BAMBOO_EXIT(0xe00e); - } + BAMBOO_ASSERT(BAMBOO_NUM_OF_CORE <= NUMCORES4GC - 1, 0xe00e); + // store the mark result info int cnum = data2; gcloads[cnum] = msgdata[msgdataindex]; @@ -791,9 +688,9 @@ INLINE void processmsg_gcprofiles_I() { #ifdef MGC_SPEC if(gc_profile_flag) { #endif - gc_num_obj += data1; - gc_num_liveobj += data2; - gc_num_forwardobj += data3; + gc_num_obj += data1; + gc_num_liveobj += data2; + gc_num_forwardobj += data3; #ifdef MGC_SPEC } #endif @@ -810,10 +707,8 @@ INLINE void processmsg_gcfinishpref_I() { int data1 = msgdata[msgdataindex]; MSG_INDEXINC_I(); // received a flush phase finish msg - if(BAMBOO_NUM_OF_CORE != STARTUPCORE) { - // non startup core can not receive this msg - BAMBOO_EXIT(0xe00f); - } + BAMBOO_ASSERT(BAMBOO_NUM_OF_CORE == STARTUPCORE, 0xe00f); + // all cores should do flush if(data1 < NUMCORESACTIVE) { gccorestatus[data1] = 0; @@ -875,7 +770,6 @@ processmsg: break; } #endif - case TRANSTALL: { // receive a stall msg processmsg_transtall_I(); @@ -890,19 +784,16 @@ processmsg: processmsg_lockrequest_I(); break; } - case LOCKGROUNT: { // receive lock grount msg processmsg_lockgrount_I(); break; } - case LOCKDENY: { // receive lock deny msg processmsg_lockdeny_I(); break; } - case LOCKRELEASE: { processmsg_lockrelease_I(); break; @@ -915,7 +806,6 @@ processmsg: processmsg_profileoutput_I(); break; } - case PROFILEFINISH: { // receive a profile output finish msg processmsg_profilefinish_I(); diff --git a/Robust/src/Runtime/bamboo/multicoreruntime.h b/Robust/src/Runtime/bamboo/multicoreruntime.h index a4cfc158..c54bd2ce 100644 --- a/Robust/src/Runtime/bamboo/multicoreruntime.h +++ b/Robust/src/Runtime/bamboo/multicoreruntime.h @@ -8,6 +8,10 @@ #include "multicoretask.h" #include "multicoremgc.h" +//Define the following line if the base object type has pointers +//#define OBJECTHASPOINTERS + + #ifdef MULTICORE_GC #define GCCHECK(p) \ if(gcflag) gc(p) @@ -69,6 +73,16 @@ INLINE void initlock(struct ___Object___ * v); INLINE void terminatememprof(void); #endif // BAMBOO_MEMPROF +// Would probably be better to just have these print out line numbers... +// But not going to do that without consultation + +//Macros for performance runs....to eliminate assertions if we don't need them +//#define BAMBOO_ASSERT(x, y) ; +//#define BAMBOO_ASSERTMSG(x, y, z) ; + +#define BAMBOO_ASSERT(x, y) if (!x) BAMBOO_EXIT(y); +#define BAMBOO_ASSERTMSG(x, y, z) if (!x) {GC_PRINTF(y); BAMBOO_EXIT(z);} + /////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// diff --git a/Robust/src/Runtime/bamboo/multicoretask.c b/Robust/src/Runtime/bamboo/multicoretask.c index 837ef6ce..a54a063e 100644 --- a/Robust/src/Runtime/bamboo/multicoretask.c +++ b/Robust/src/Runtime/bamboo/multicoretask.c @@ -132,15 +132,15 @@ INLINE bool checkObjQueue() { BAMBOO_CACHE_FLUSH_RANGE((int)obj, classsize[((struct ___Object___ *)obj)->type]); // enqueue the object - for(k = 0; k < objInfo->length; ++k) { - int taskindex = objInfo->queues[2 * k]; - int paramindex = objInfo->queues[2 * k + 1]; - struct parameterwrapper ** queues = - &(paramqueues[BAMBOO_NUM_OF_CORE][taskindex][paramindex]); - BAMBOO_DEBUGPRINT_REG(taskindex); - BAMBOO_DEBUGPRINT_REG(paramindex); - enqueueObject_I(obj, queues, 1); - BAMBOO_DEBUGPRINT_REG(hashsize(activetasks)); + for(k = 0; k < objInfo->length; k++) { + int taskindex = objInfo->queues[2 * k]; + int paramindex = objInfo->queues[2 * k + 1]; + struct parameterwrapper ** queues = + &(paramqueues[BAMBOO_NUM_OF_CORE][taskindex][paramindex]); + BAMBOO_DEBUGPRINT_REG(taskindex); + BAMBOO_DEBUGPRINT_REG(paramindex); + enqueueObject_I(obj, queues, 1); + BAMBOO_DEBUGPRINT_REG(hashsize(activetasks)); } releasewritelock_I(tmpobj); RUNFREE_I(objInfo->queues); @@ -347,46 +347,43 @@ void tagset(struct ___Object___ * obj, } else { struct ArrayObject *ao=(struct ArrayObject *) tagset; if (ao->___cachedCode______length___) { - ARRAYSET(ao, struct ___Object___*, ao->___cachedCode___++, obj); + ARRAYSET(ao, struct ___Object___*, ao->___cachedCode___++, obj); } else { - int i; + int i; #ifdef MULTICORE_GC - int ptrarray[]={2, (int) ptr, (int) obj, (int)tagd}; - struct ArrayObject * aonew= - allocate_newarray(&ptrarray,OBJECTARRAYTYPE, - OBJECTARRAYINTERVAL+ao->___length___); - obj=(struct ___Object___ *)ptrarray[2]; - tagd=(struct ___TagDescriptor___ *)ptrarray[3]; - ao=(struct ArrayObject *)tagd->flagptr; + int ptrarray[]={2, (int) ptr, (int) obj, (int)tagd}; + struct ArrayObject * aonew= + allocate_newarray(&ptrarray,OBJECTARRAYTYPE, + OBJECTARRAYINTERVAL+ao->___length___); + obj=(struct ___Object___ *)ptrarray[2]; + tagd=(struct ___TagDescriptor___ *)ptrarray[3]; + ao=(struct ArrayObject *)tagd->flagptr; #else - struct ArrayObject * aonew=allocate_newarray(OBJECTARRAYTYPE, - OBJECTARRAYINTERVAL+ao->___length___); + struct ArrayObject * aonew=allocate_newarray(OBJECTARRAYTYPE, + OBJECTARRAYINTERVAL+ao->___length___); #endif - aonew->___cachedCode___=ao->___cachedCode___+1; - for(i=0; i___length___; i++) { - ARRAYSET(aonew, struct ___Object___*, i, - ARRAYGET(ao, struct ___Object___*, i)); - } - ARRAYSET(aonew, struct ___Object___ *, ao->___cachedCode___, obj); - tagd->flagptr=(struct ___Object___ *) aonew; + aonew->___cachedCode___=ao->___cachedCode___+1; + for(i=0; i___length___; i++) { + ARRAYSET(aonew, struct ___Object___*, i, + ARRAYGET(ao, struct ___Object___*, i)); + } + ARRAYSET(aonew, struct ___Object___ *, ao->___cachedCode___, obj); + tagd->flagptr=(struct ___Object___ *) aonew; } } } } - + /* This function clears a tag. */ #ifdef MULTICORE_GC -void tagclear(void *ptr, - struct ___Object___ * obj, - struct ___TagDescriptor___ * tagd) { +void tagclear(void *ptr, struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) { #else -void tagclear(struct ___Object___ * obj, - struct ___TagDescriptor___ * tagd) { +void tagclear(struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) { #endif /* We'll assume that tag is alway there. Need to statically check for this of course. */ struct ___Object___ * tagptr=obj->___tags___; - + if (tagptr->type==TAGTYPE) { if ((struct ___TagDescriptor___ *)tagptr==tagd) obj->___tags___=NULL; @@ -397,49 +394,48 @@ void tagclear(struct ___Object___ * obj, struct ___TagDescriptor___ * td= ARRAYGET(ao, struct ___TagDescriptor___ *, i); if (td==tagd) { - ao->___cachedCode___--; - if (i___cachedCode___) - ARRAYSET(ao, struct ___TagDescriptor___ *, i, - ARRAYGET(ao,struct ___TagDescriptor___*,ao->___cachedCode___)); - ARRAYSET(ao,struct ___TagDescriptor___ *,ao->___cachedCode___, NULL); - if (ao->___cachedCode___==0) - obj->___tags___=NULL; - goto PROCESSCLEAR; + ao->___cachedCode___--; + if (i___cachedCode___) + ARRAYSET(ao, struct ___TagDescriptor___ *, i, + ARRAYGET(ao,struct ___TagDescriptor___*,ao->___cachedCode___)); + ARRAYSET(ao,struct ___TagDescriptor___ *,ao->___cachedCode___, NULL); + if (ao->___cachedCode___==0) + obj->___tags___=NULL; + goto PROCESSCLEAR; } } } -PROCESSCLEAR: + PROCESSCLEAR: { struct ___Object___ *tagset=tagd->flagptr; if (tagset->type!=OBJECTARRAYTYPE) { if (tagset==obj) - tagd->flagptr=NULL; + tagd->flagptr=NULL; } else { struct ArrayObject *ao=(struct ArrayObject *) tagset; int i; for(i=0; i___cachedCode___; i++) { - struct ___Object___ * tobj=ARRAYGET(ao, struct ___Object___ *, i); - if (tobj==obj) { - ao->___cachedCode___--; - if (i___cachedCode___) - ARRAYSET(ao, struct ___Object___ *, i, - ARRAYGET(ao, struct ___Object___ *, ao->___cachedCode___)); - ARRAYSET(ao, struct ___Object___ *, ao->___cachedCode___, NULL); - if (ao->___cachedCode___==0) - tagd->flagptr=NULL; - goto ENDCLEAR; - } + struct ___Object___ * tobj=ARRAYGET(ao, struct ___Object___ *, i); + if (tobj==obj) { + ao->___cachedCode___--; + if (i___cachedCode___) + ARRAYSET(ao, struct ___Object___ *, i, + ARRAYGET(ao, struct ___Object___ *, ao->___cachedCode___)); + ARRAYSET(ao, struct ___Object___ *, ao->___cachedCode___, NULL); + if (ao->___cachedCode___==0) + tagd->flagptr=NULL; + goto ENDCLEAR; + } } } } -ENDCLEAR: + ENDCLEAR: return; } /* This function allocates a new tag. */ #ifdef MULTICORE_GC -struct ___TagDescriptor___ * allocate_tag(void *ptr, - int index) { +struct ___TagDescriptor___ * allocate_tag(void *ptr, int index) { struct ___TagDescriptor___ * v= (struct ___TagDescriptor___ *) FREEMALLOC((struct garbagelist *) ptr, classsize[TAGTYPE]); @@ -455,30 +451,20 @@ struct ___TagDescriptor___ * allocate_tag(int index) { /* This function updates the flag for object ptr. It or's the flag with the or mask and and's it with the andmask. */ -void flagbody(struct ___Object___ *ptr, - int flag, - struct parameterwrapper ** queues, - int length, - bool isnew); +void flagbody(struct ___Object___ *ptr, int flag, struct parameterwrapper ** queues, int length, bool isnew); int flagcomp(const int *val1, const int *val2) { return (*val1)-(*val2); } - -void flagorand(void * ptr, - int ormask, - int andmask, - struct parameterwrapper ** queues, - int length) { + +void flagorand(void * ptr, int ormask, int andmask, struct parameterwrapper ** queues, int length) { int oldflag=((int *)ptr)[2]; // the flag field is now the third one int flag=ormask|oldflag; flag&=andmask; flagbody(ptr, flag, queues, length, false); } -bool intflagorand(void * ptr, - int ormask, - int andmask) { +bool intflagorand(void * ptr, int ormask, int andmask) { int oldflag=((int *)ptr)[2]; // the flag field is the third one int flag=ormask|oldflag; flag&=andmask; @@ -489,16 +475,14 @@ bool intflagorand(void * ptr, return true; } } - -void flagorandinit(void * ptr, - int ormask, - int andmask) { + +void flagorandinit(void * ptr, int ormask, int andmask) { int oldflag=((int *)ptr)[2]; // the flag field is the third one int flag=ormask|oldflag; flag&=andmask; flagbody(ptr,flag,NULL,0,true); } - + void flagbody(struct ___Object___ *ptr, int flag, struct parameterwrapper ** vqueues, @@ -522,7 +506,7 @@ void flagbody(struct ___Object___ *ptr, ptr->flag=flag; /*Remove object from all queues */ - for(i = 0; i < length; ++i) { + for(i = 0; i < length; i++) { flagptr = queues[i]; ObjectHashget(flagptr->objectset, (int) ptr, (int *) &next, (int *) &enterflags, &UNUSED, &UNUSED2); @@ -536,7 +520,7 @@ void enqueueObject(void * vptr, struct parameterwrapper ** vqueues, int vlength) { struct ___Object___ *ptr = (struct ___Object___ *)vptr; - + { struct parameterwrapper * parameter=NULL; int j; @@ -556,48 +540,48 @@ void enqueueObject(void * vptr, /* Outer loop iterates through all parameter queues an object of this type could be in. */ - for(j = 0; j < length; ++j) { + for(j = 0; j < length; j++) { parameter = queues[j]; /* Check tags */ if (parameter->numbertags>0) { - if (tagptr==NULL) - goto nextloop; //that means the object has no tag - //but that param needs tag - else if(tagptr->type==TAGTYPE) { //one tag - for(i=0; inumbertags; i++) { - //slotid is parameter->tagarray[2*i]; - int tagid=parameter->tagarray[2*i+1]; - if (tagid!=tagptr->flag) - goto nextloop; /*We don't have this tag */ - } - } else { //multiple tags - struct ArrayObject * ao=(struct ArrayObject *) tagptr; - for(i=0; inumbertags; i++) { - //slotid is parameter->tagarray[2*i]; - int tagid=parameter->tagarray[2*i+1]; - int j; - for(j=0; j___cachedCode___; j++) { - if (tagid==ARRAYGET(ao, struct ___TagDescriptor___*, j)->flag) - goto foundtag; - } - goto nextloop; -foundtag: - ; - } - } + if (tagptr==NULL) + goto nextloop; //that means the object has no tag + //but that param needs tag + else if(tagptr->type==TAGTYPE) { //one tag + for(i=0; inumbertags; i++) { + //slotid is parameter->tagarray[2*i]; + int tagid=parameter->tagarray[2*i+1]; + if (tagid!=tagptr->flag) + goto nextloop; /*We don't have this tag */ + } + } else { //multiple tags + struct ArrayObject * ao=(struct ArrayObject *) tagptr; + for(i=0; inumbertags; i++) { + //slotid is parameter->tagarray[2*i]; + int tagid=parameter->tagarray[2*i+1]; + int j; + for(j=0; j___cachedCode___; j++) { + if (tagid==ARRAYGET(ao, struct ___TagDescriptor___*, j)->flag) + goto foundtag; + } + goto nextloop; + foundtag: + ; + } + } } - + /* Check flags */ for(i=0; inumberofterms; i++) { - int andmask=parameter->intarray[i*2]; - int checkmask=parameter->intarray[i*2+1]; - if ((ptr->flag&andmask)==checkmask) { - enqueuetasks(parameter, prevptr, ptr, NULL, 0); - prevptr=parameter; - break; - } + int andmask=parameter->intarray[i*2]; + int checkmask=parameter->intarray[i*2+1]; + if ((ptr->flag&andmask)==checkmask) { + enqueuetasks(parameter, prevptr, ptr, NULL, 0); + prevptr=parameter; + break; + } } -nextloop: + nextloop: ; } } @@ -627,88 +611,86 @@ void enqueueObject_I(void * vptr, /* Outer loop iterates through all parameter queues an object of this type could be in. */ - for(j = 0; j < length; ++j) { + for(j = 0; j < length; j++) { parameter = queues[j]; /* Check tags */ if (parameter->numbertags>0) { - if (tagptr==NULL) - goto nextloop; //that means the object has no tag - //but that param needs tag - else if(tagptr->type==TAGTYPE) { //one tag - for(i=0; inumbertags; i++) { - //slotid is parameter->tagarray[2*i]; - int tagid=parameter->tagarray[2*i+1]; - if (tagid!=tagptr->flag) - goto nextloop; /*We don't have this tag */ - } - } else { //multiple tags - struct ArrayObject * ao=(struct ArrayObject *) tagptr; - for(i=0; inumbertags; i++) { - //slotid is parameter->tagarray[2*i]; - int tagid=parameter->tagarray[2*i+1]; - int j; - for(j=0; j___cachedCode___; j++) { - if (tagid==ARRAYGET(ao, struct ___TagDescriptor___*, j)->flag) - goto foundtag; - } - goto nextloop; -foundtag: - ; - } - } + if (tagptr==NULL) + goto nextloop; //that means the object has no tag + //but that param needs tag + else if(tagptr->type==TAGTYPE) { //one tag + for(i=0; inumbertags; i++) { + //slotid is parameter->tagarray[2*i]; + int tagid=parameter->tagarray[2*i+1]; + if (tagid!=tagptr->flag) + goto nextloop; /*We don't have this tag */ + } + } else { //multiple tags + struct ArrayObject * ao=(struct ArrayObject *) tagptr; + for(i=0; inumbertags; i++) { + //slotid is parameter->tagarray[2*i]; + int tagid=parameter->tagarray[2*i+1]; + int j; + for(j=0; j___cachedCode___; j++) { + if (tagid==ARRAYGET(ao, struct ___TagDescriptor___*, j)->flag) + goto foundtag; + } + goto nextloop; + foundtag: + ; + } + } } - + /* Check flags */ for(i=0; inumberofterms; i++) { - int andmask=parameter->intarray[i*2]; - int checkmask=parameter->intarray[i*2+1]; - if ((ptr->flag&andmask)==checkmask) { - enqueuetasks_I(parameter, prevptr, ptr, NULL, 0); - prevptr=parameter; - break; - } + int andmask=parameter->intarray[i*2]; + int checkmask=parameter->intarray[i*2+1]; + if ((ptr->flag&andmask)==checkmask) { + enqueuetasks_I(parameter, prevptr, ptr, NULL, 0); + prevptr=parameter; + break; + } } -nextloop: + nextloop: ; } } } -int * getAliasLock(void ** ptrs, - int length, - struct RuntimeHash * tbl) { +int * getAliasLock(void ** ptrs, int length, struct RuntimeHash * tbl) { #ifdef TILERA_BME int i = 0; int locks[length]; int locklen = 0; // sort all the locks required by the objs in the aliased set for(; i < length; i++) { - struct ___Object___ * ptr = (struct ___Object___ *)(ptrs[i]); - int lock = 0; - int j = 0; - if(ptr->lock == NULL) { - lock = (int)(ptr); - } else { - lock = (int)(ptr->lock); - } - bool insert = true; - for(j = 0; j < locklen; j++) { - if(locks[j] == lock) { - insert = false; - break; - } else if(locks[j] > lock) { - break; - } - } - if(insert) { - int h = locklen; - for(; h > j; h--) { - locks[h] = locks[h-1]; - } - locks[j] = lock; - locklen++; - } + struct ___Object___ * ptr = (struct ___Object___ *)(ptrs[i]); + int lock = 0; + int j = 0; + if(ptr->lock == NULL) { + lock = (int)(ptr); + } else { + lock = (int)(ptr->lock); + } + bool insert = true; + for(j = 0; j < locklen; j++) { + if(locks[j] == lock) { + insert = false; + break; + } else if(locks[j] > lock) { + break; + } + } + if(insert) { + int h = locklen; + for(; h > j; h--) { + locks[h] = locks[h-1]; + } + locks[j] = lock; + locklen++; + } } // use the smallest lock as the shared lock for the whole set return (int *)(locks[0]); @@ -727,62 +709,61 @@ int * getAliasLock(void ** ptrs, int lock = 0; int j = 0; if(ptr->lock == NULL) { - lock = (int)(ptr); + lock = (int)(ptr); } else { - lock = (int)(ptr->lock); + lock = (int)(ptr->lock); } if(redirect) { - if(lock != redirectlock) { - RuntimeHashadd(tbl, lock, redirectlock); - } + if(lock != redirectlock) { + RuntimeHashadd(tbl, lock, redirectlock); + } } else { - if(RuntimeHashcontainskey(tbl, lock)) { - // already redirected - redirect = true; - RuntimeHashget(tbl, lock, &redirectlock); - for(; j < locklen; j++) { - if(locks[j] != redirectlock) { - RuntimeHashadd(tbl, locks[j], redirectlock); - } - } - } else { - bool insert = true; - for(j = 0; j < locklen; j++) { - if(locks[j] == lock) { - insert = false; - break; - } else if(locks[j] > lock) { - break; - } - } - if(insert) { - int h = locklen; - for(; h > j; h--) { - locks[h] = locks[h-1]; - } - locks[j] = lock; - locklen++; - } - } + if(RuntimeHashcontainskey(tbl, lock)) { + // already redirected + redirect = true; + RuntimeHashget(tbl, lock, &redirectlock); + for(; j < locklen; j++) { + if(locks[j] != redirectlock) { + RuntimeHashadd(tbl, locks[j], redirectlock); + } + } + } else { + bool insert = true; + for(j = 0; j < locklen; j++) { + if(locks[j] == lock) { + insert = false; + break; + } else if(locks[j] > lock) { + break; + } + } + if(insert) { + int h = locklen; + for(; h > j; h--) { + locks[h] = locks[h-1]; + } + locks[j] = lock; + locklen++; + } + } } } if(redirect) { return (int *)redirectlock; } else { - // use the first lock as the shared lock - for(j = 1; j < locklen; j++) { - if(locks[j] != locks[0]) { - RuntimeHashadd(tbl, locks[j], locks[0]); - } - } + // use the first lock as the shared lock + for(j = 1; j < locklen; j++) { + if(locks[j] != locks[0]) { + RuntimeHashadd(tbl, locks[j], locks[0]); + } + } return (int *)(locks[0]); } } #endif // TILERA_BME } -void addAliasLock(void * ptr, - int lock) { +void addAliasLock(void * ptr, int lock) { struct ___Object___ * obj = (struct ___Object___ *)ptr; if(((int)ptr != lock) && (obj->lock != (int*)lock)) { // originally no alias lock associated or have a different alias lock @@ -1125,7 +1106,7 @@ newtask: // check if has the lock already // can not get the lock, try later // release all grabbed locks for previous parameters - for(j = 0; j < i; ++j) { + for(j = 0; j < i; j++) { lock = (int*)(runtime_locks[j].value/*redirectlock*/); releasewritelock(lock); } @@ -1161,7 +1142,7 @@ newtask: BAMBOO_DEBUGPRINT(0xe994); BAMBOO_DEBUGPRINT_REG(parameter); // release grabbed locks - for(j = 0; j < runtime_locklen; ++j) { + for(j = 0; j < runtime_locklen; j++) { int * lock = (int *)(runtime_locks[j].value); releasewritelock(lock); } @@ -1175,7 +1156,7 @@ newtask: { int tmpi = 0; bool ismet = false; - for(tmpi = 0; tmpi < pw->numberofterms; ++tmpi) { + for(tmpi = 0; tmpi < pw->numberofterms; tmpi++) { andmask=pw->intarray[tmpi*2]; checkmask=pw->intarray[tmpi*2+1]; if((((struct ___Object___ *)parameter)->flag&andmask)==checkmask) { @@ -1197,7 +1178,7 @@ newtask: if (enterflags!=NULL) RUNFREE(enterflags); // release grabbed locks - for(j = 0; j < runtime_locklen; ++j) { + for(j = 0; j < runtime_locklen; j++) { int * lock = (int *)(runtime_locks[j].value/*redirectlock*/); releasewritelock(lock); } @@ -1219,14 +1200,12 @@ parameterpresent: struct ___TagDescriptor___ *tagd=currtpd->parameterArray[slotid]; if (!containstag(parameter, tagd)) { BAMBOO_DEBUGPRINT(0xe996); - { - // release grabbed locks - int tmpj = 0; - for(tmpj = 0; tmpj < runtime_locklen; ++tmpj) { - int * lock = (int *)(runtime_locks[tmpj].value/*redirectlock*/); - releasewritelock(lock); - } - } + // release grabbed locks + int tmpj = 0; + for(tmpj = 0; tmpj < runtime_locklen; tmpj++) { + int * lock = (int *)(runtime_locks[tmpj].value/*redirectlock*/); + releasewritelock(lock); + } RUNFREE(currtpd->parameterArray); RUNFREE(currtpd); currtpd = NULL; @@ -1382,44 +1361,44 @@ loopstart: /* Check for objects with existing tags */ for(i=0; idescriptorarray[i]; - int j; - for(j=0; jnumbertags; j++) { - int slotid=pd->tagarray[2*j]; - if(statusarray[slotid+numparams]!=0) { - processobject(parameter,i,pd,&iteratorcount, - statusarray,numparams); - processtags(pd,i,parameter,&iteratorcount,statusarray,numparams); - goto loopstart; - } - } + struct parameterdescriptor *pd=task->descriptorarray[i]; + int j; + for(j=0; jnumbertags; j++) { + int slotid=pd->tagarray[2*j]; + if(statusarray[slotid+numparams]!=0) { + processobject(parameter,i,pd,&iteratorcount, + statusarray,numparams); + processtags(pd,i,parameter,&iteratorcount,statusarray,numparams); + goto loopstart; + } + } } } - + /* Next do objects w/ unbound tags*/ - + for(i=0; idescriptorarray[i]; - if (pd->numbertags>0) { - processobject(parameter,i,pd,&iteratorcount,statusarray,numparams); - processtags(pd,i,parameter,&iteratorcount,statusarray,numparams); - goto loopstart; - } + struct parameterdescriptor *pd=task->descriptorarray[i]; + if (pd->numbertags>0) { + processobject(parameter,i,pd,&iteratorcount,statusarray,numparams); + processtags(pd,i,parameter,&iteratorcount,statusarray,numparams); + goto loopstart; + } } } - + /* Nothing with a tag enqueued */ - + for(i=0; idescriptorarray[i]; - processobject(parameter,i,pd,&iteratorcount,statusarray,numparams); - processtags(pd,i,parameter,&iteratorcount,statusarray,numparams); - goto loopstart; + struct parameterdescriptor *pd=task->descriptorarray[i]; + processobject(parameter,i,pd,&iteratorcount,statusarray,numparams); + processtags(pd,i,parameter,&iteratorcount,statusarray,numparams); + goto loopstart; } } - + /* Nothing left */ return; } @@ -1446,35 +1425,32 @@ void printdebug() { #endif ObjectHashiterator(set, &objit); while(ObjhasNext(&objit)) { - struct ___Object___ * obj=(struct ___Object___ *)Objkey(&objit); - struct ___Object___ * tagptr=obj->___tags___; - int nonfailed=Objdata4(&objit); - int numflags=Objdata3(&objit); - int flags=Objdata2(&objit); - Objnext(&objit); + struct ___Object___ * obj=(struct ___Object___ *)Objkey(&objit); + struct ___Object___ * tagptr=obj->___tags___; + int nonfailed=Objdata4(&objit); + int numflags=Objdata3(&objit); + int flags=Objdata2(&objit); + Objnext(&objit); #ifndef RAW - printf(" Contains %lx\n", obj); - printf(" flag=%d\n", obj->flag); + printf(" Contains %lx\n", obj); + printf(" flag=%d\n", obj->flag); #endif - if (tagptr==NULL) { - } else if (tagptr->type==TAGTYPE) { + if (tagptr==NULL) { + } else if (tagptr->type==TAGTYPE) { #ifndef RAW - printf(" tag=%lx\n",tagptr); -#else - ; + printf(" tag=%lx\n",tagptr); #endif - } else { - int tagindex=0; - struct ArrayObject *ao=(struct ArrayObject *)tagptr; - for(; tagindex___cachedCode___; tagindex++) { + } else { + int tagindex=0; + struct ArrayObject *ao=(struct ArrayObject *)tagptr; + for(; tagindex___cachedCode___; tagindex++) { #ifndef RAW - printf(" tag=%lx\n",ARRAYGET(ao,struct ___TagDescriptor___*, - tagindex)); + printf(" tag=%lx\n",ARRAYGET(ao,struct ___TagDescriptor___*, tagindex)); #else - ; + ; #endif - } - } + } + } } } } @@ -1551,13 +1527,13 @@ int toiHasNext(struct tagobjectiterator *it, int i; if (objptr->type!=OBJECTARRAYTYPE) { if (it->tagobjindex>0) - return 0; + return 0; if (!ObjectHashcontainskey(it->objectset, (int) objptr)) - return 0; + return 0; for(i=1; inumtags; i++) { - struct ___TagDescriptor___ *tag2=objectarray[it->tagbindings[i]]; - if (!containstag(objptr,tag2)) - return 0; + struct ___TagDescriptor___ *tag2=objectarray[it->tagbindings[i]]; + if (!containstag(objptr,tag2)) + return 0; } return 1; } else { @@ -1565,20 +1541,20 @@ int toiHasNext(struct tagobjectiterator *it, int tagindex; int i; for(tagindex=it->tagobjindex;tagindex___cachedCode___;tagindex++){ - struct ___Object___ *objptr= - ARRAYGET(ao,struct ___Object___*,tagindex); - if (!ObjectHashcontainskey(it->objectset, (int) objptr)) - continue; - for(i=1; inumtags; i++) { - struct ___TagDescriptor___ *tag2=objectarray[it->tagbindings[i]]; - if (!containstag(objptr,tag2)) - goto nexttag; - } - it->tagobjindex=tagindex; - return 1; -nexttag: - ; - } + struct ___Object___ *objptr= + ARRAYGET(ao,struct ___Object___*,tagindex); + if (!ObjectHashcontainskey(it->objectset, (int) objptr)) + continue; + for(i=1; inumtags; i++) { + struct ___TagDescriptor___ *tag2=objectarray[it->tagbindings[i]]; + if (!containstag(objptr,tag2)) + goto nexttag; + } + it->tagobjindex=tagindex; + return 1; + nexttag: + ; + } it->tagobjindex=tagindex; return 0; } @@ -1595,7 +1571,7 @@ int containstag(struct ___Object___ *ptr, struct ArrayObject *ao=(struct ArrayObject *)objptr; for(j=0; j___cachedCode___; j++) { if (ptr==ARRAYGET(ao, struct ___Object___*, j)) { - return 1; + return 1; } } return 0;