From: bdemsky Date: Sat, 18 Jun 2011 01:17:53 +0000 (+0000) Subject: change objects X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=57bb8b8bd9be540b058ca437d412cf5a0caeeb88;p=IRC.git change objects --- diff --git a/Robust/src/Runtime/bamboo/gcqueue.h b/Robust/src/Runtime/bamboo/gcqueue.h index 5aa15f47..0f38d445 100644 --- a/Robust/src/Runtime/bamboo/gcqueue.h +++ b/Robust/src/Runtime/bamboo/gcqueue.h @@ -38,7 +38,7 @@ extern struct lobjpointerblock *gclobjspare; static void gc_queueinit() { // initialize queue if (gchead==NULL) { - gcheadindex=gctailindex=gctailindex2 = 0; + gcheadindex=gctailindex=0; gchead=gctail=RUNMALLOC(sizeof(struct pointerblock)); } else { gctailindex=gcheadindex=0; diff --git a/Robust/src/Runtime/bamboo/markbit.h b/Robust/src/Runtime/bamboo/markbit.h index a597cc8d..871ac8ba 100644 --- a/Robust/src/Runtime/bamboo/markbit.h +++ b/Robust/src/Runtime/bamboo/markbit.h @@ -5,11 +5,21 @@ extern unsigned int markmappingarray[]; extern unsigned int bitmarkmappingarray[]; extern unsigned int revmarkmappingarray[]; +#define ALIGNMENTSIZE 32 +//Bytes to shift to get minimum alignment units +#define ALIGNMENTSHIFT 5 + #define NOTMARKED 0 -#define ALIGNOBJSIZE(x) (x)>>5 -#define ALIGNSIZETOBYTES(x) (x)<<5 -#define ALIGNTOTABLEINDEX(x) (x)>>(5+4) -#define CONVERTTABLEINDEXTOPTR(x) (((unsigned INTPTR)((x)<<(5+4)))+gcbase) +#define BITSPERALIGNMENT 2 +#define ALIGNOBJSIZE(x) (x)>>ALIGNMENTSHIFT +#define ALIGNSIZETOBYTES(x) (x)<>(ALIGNMENTSHIFT+4) +#define CONVERTTABLEINDEXTOPTR(x) (((unsigned INTPTR)((x)<<(ALIGNMENTSHIFT+4)))+gcbaseva) +//Minimum alignment unit + + + + #define OBJMASK 0x40000000 //set towhatever smallest object mark is @@ -32,7 +42,7 @@ extern unsigned int revmarkmappingarray[]; /* Return length in units of ALIGNSIZE */ static inline unsigned int getMarkedLength(void *ptr) { - unsigned INTPTR alignsize=ALIGNOBJSIZE((unsigned INTPTR)(ptr-gcbase)); + unsigned INTPTR alignsize=ALIGNOBJSIZE((unsigned INTPTR)(ptr-gcbaseva)); unsigned INTPTR hibits=alignsize>>4; unsigned INTPTR lobits=(alignsize&15)<<1; unsigned INTPTR val; @@ -53,7 +63,7 @@ static inline unsigned int getMarkedLength(void *ptr) { /* Return non-zero value if the object is marked */ static inline unsigned int checkMark(void *ptr) { - unsigned INTPTR alignsize=ALIGNOBJSIZE((unsigned INTPTR)(ptr-gcbase)); + unsigned INTPTR alignsize=ALIGNOBJSIZE((unsigned INTPTR)(ptr-gcbaseva)); unsigned INTPTR hibits=alignsize>>4; unsigned INTPTR lobits=(alignsize&15)<<1; @@ -63,7 +73,7 @@ static inline unsigned int checkMark(void *ptr) { /* Set length in units of ALIGNSIZE */ static inline void setLength(void *ptr, unsigned int length) { - unsigned INTPTR alignsize=ALIGNOBJSIZE((unsigned INTPTR)(ptr-gcbase)); + unsigned INTPTR alignsize=ALIGNOBJSIZE((unsigned INTPTR)(ptr-gcbaseva)); unsigned INTPTR hibits=alignsize>>4; unsigned INTPTR lobits=(alignsize&15)<<1; unsigned int ormask=(length>=16)?0xc4000000+(length-16):revmarkmappingarray[length]; @@ -78,7 +88,7 @@ static inline void setLength(void *ptr, unsigned int length) { /* Set length for premarked object */ static inline void setLengthMarked(void *ptr, unsigned int length) { - unsigned INTPTR alignsize=ALIGNOBJSIZE((unsigned INTPTR)(ptr-gcbase)); + unsigned INTPTR alignsize=ALIGNOBJSIZE((unsigned INTPTR)(ptr-gcbaseva)); unsigned INTPTR hibits=alignsize>>4; unsigned INTPTR lobits=(alignsize&15)<<1; unsigned int ormask=(length>=16)?0xc4000000+(length-16):revmarkmappingarray[length]; @@ -92,14 +102,14 @@ static inline void setLengthMarked(void *ptr, unsigned int length) { /* Set length in units of ALIGNSIZE */ static inline void setMark(void *ptr) { - unsigned INTPTR alignsize=ALIGNOBJSIZE((unsigned INTPTR)(ptr-gcbase)); + unsigned INTPTR alignsize=ALIGNOBJSIZE((unsigned INTPTR)(ptr-gcbaseva)); unsigned INTPTR hibits=alignsize>>4; unsigned INTPTR lobits=(alignsize&15)<<1; gcmarktbl[hibits]|=OBJMASK>>lobits; } static inline void clearMark(void *ptr) { - unsigned INTPTR alignsize=ALIGNOBJSIZE((unsigned INTPTR)(ptr-gcbase)); + unsigned INTPTR alignsize=ALIGNOBJSIZE((unsigned INTPTR)(ptr-gcbaseva)); unsigned INTPTR hibits=alignsize>>4; unsigned INTPTR lobits=(alignsize&15)<<1; diff --git a/Robust/src/Runtime/bamboo/multicorecache.h b/Robust/src/Runtime/bamboo/multicorecache.h index ad86f5e9..65d1ef7b 100644 --- a/Robust/src/Runtime/bamboo/multicorecache.h +++ b/Robust/src/Runtime/bamboo/multicorecache.h @@ -55,7 +55,7 @@ INLINE static void samplingDataReviseInit(struct moveHelper * orig,struct moveHe gc_cache_revise_information.to_page_index=toindex; gc_cache_revise_information.orig_page_start_va=orig->ptr; gc_cache_revise_information.orig_page_end_va=gcbaseva+BAMBOO_PAGE_SIZE*(((unsigned INTPTR)(orig->ptr-gcbaseva))/BAMBOO_PAGE_SIZE+1); - gc_cache_revise_information.orig_page_index=((unsigned INTPTR)(orig->blockbase-gcbaseva))/BAMBOO_PAGE_SIZE; + gc_cache_revise_information.orig_page_index=((unsigned INTPTR)(orig->base-gcbaseva))/BAMBOO_PAGE_SIZE; } INLINE static void samplingDataConvert(void * current_ptr) { diff --git a/Robust/src/Runtime/bamboo/multicoregarbage.c b/Robust/src/Runtime/bamboo/multicoregarbage.c index 2468a98b..95caaa30 100644 --- a/Robust/src/Runtime/bamboo/multicoregarbage.c +++ b/Robust/src/Runtime/bamboo/multicoregarbage.c @@ -306,94 +306,6 @@ int loadbalance(void ** heaptop, unsigned int * topblock, unsigned int * topcore return numbpc; } -// compute total mem size required and sort the lobjs in ascending order -unsigned int sortLObjs() { - unsigned int tmp_lobj = 0; - unsigned int tmp_len = 0; - unsigned int tmp_host = 0; - unsigned int sumsize = 0; - - gclobjtail2 = gclobjtail; - gclobjtailindex2 = gclobjtailindex; - // TODO USE QUICK SORT INSTEAD? - while(gc_lobjmoreItems2_I()) { - gc_lobjdequeue2_I(); - tmp_lobj = gclobjtail2->lobjs[gclobjtailindex2-1]; - tmp_host = gclobjtail2->hosts[gclobjtailindex2-1]; - tmp_len = gclobjtail2->lengths[gclobjtailindex2 - 1]; - sumsize += tmp_len; - GCPROFILE_RECORD_LOBJ(); - unsigned int i = gclobjtailindex2-1; - struct lobjpointerblock * tmp_block = gclobjtail2; - // find the place to insert - while(true) { - if(i == 0) { - if(tmp_block->prev == NULL) { - break; - } - if(tmp_block->prev->lobjs[NUMLOBJPTRS-1] > tmp_lobj) { - tmp_block->lobjs[i] = tmp_block->prev->lobjs[NUMLOBJPTRS-1]; - tmp_block->lengths[i] = tmp_block->prev->lengths[NUMLOBJPTRS-1]; - tmp_block->hosts[i] = tmp_block->prev->hosts[NUMLOBJPTRS-1]; - tmp_block = tmp_block->prev; - i = NUMLOBJPTRS-1; - } else { - break; - } // if(tmp_block->prev->lobjs[NUMLOBJPTRS-1] < tmp_lobj) - } else { - if(tmp_block->lobjs[i-1] > tmp_lobj) { - tmp_block->lobjs[i] = tmp_block->lobjs[i-1]; - tmp_block->lengths[i] = tmp_block->lengths[i-1]; - tmp_block->hosts[i] = tmp_block->hosts[i-1]; - i--; - } else { - break; - } - } - } - // insert it - if(i != gclobjtailindex2 - 1) { - tmp_block->lobjs[i] = tmp_lobj; - tmp_block->lengths[i] = tmp_len; - tmp_block->hosts[i] = tmp_host; - } - } - return sumsize; -} - -bool cacheLObjs() { - // check the total mem size need for large objs - unsigned long long sumsize = 0; - unsigned int size = 0; - - sumsize = sortLObjs(); - - GCPROFILE_RECORD_LOBJSPACE(); - - // check if there are enough space to cache these large objs - unsigned int dst = gcbaseva + (BAMBOO_SHARED_MEM_SIZE) -sumsize; - if((unsigned long long)gcheaptop > (unsigned long long)dst) { - // do not have enough room to cache large objs - return false; - } - - gcheaptop = dst; // Note: record the start of cached lobjs with gcheaptop - // cache the largeObjs to the top of the shared heap - dst = gcbaseva + (BAMBOO_SHARED_MEM_SIZE); - while(gc_lobjmoreItems3_I()) { - gc_lobjdequeue3_I(); - size = gclobjtail2->lengths[gclobjtailindex2]; - // set the mark field to , indicating that this obj has been moved - // and need to be flushed - dst -= size; - if((unsigned int)dst<(unsigned int)(gclobjtail2->lobjs[gclobjtailindex2]+size)) { - memmove(dst, gclobjtail2->lobjs[gclobjtailindex2], size); - } else { - memcpy(dst, gclobjtail2->lobjs[gclobjtailindex2], size); - } - } - return true; -} // update the bmmboo_smemtbl to record current shared mem usage void updateSmemTbl(unsigned int coren, void * localtop) { @@ -451,7 +363,7 @@ void gc_collect(struct garbagelist * stackptr) { compact(); GC_PRINTF("Finish compact phase\n"); - WAITFORGCPHASE(FLUSHPHASE); + WAITFORGCPHASE(UPDATEPHASE); GC_PRINTF("Start flush phase\n"); GCPROFILE_INFO_2_MASTER(); @@ -492,7 +404,7 @@ void gc_nocollect(struct garbagelist * stackptr) { GC_PRINTF("Finish mark phase, wait for flush\n"); // non-gc core collector routine - WAITFORGCPHASE(FLUSHPHASE); + WAITFORGCPHASE(UPDATEPHASE); GC_PRINTF("Start flush phase\n"); GCPROFILE_INFO_2_MASTER(); @@ -546,19 +458,17 @@ void master_getlargeobjs() { GCPROFILE_ITEM(); GC_PRINTF("prepare to cache large objs \n"); - // cache all large objs - BAMBOO_ASSERTMSG(cacheLObjs(), "Not enough space to cache large objects\n"); } void master_updaterefs(struct garbagelist * stackptr) { - gc_status_info.gcphase = FLUSHPHASE; - GC_SEND_MSG_1_TO_CLIENT(GCSTARTFLUSH); + gc_status_info.gcphase = UPDATEPHASE; + GC_SEND_MSG_1_TO_CLIENT(GCSTARTUPDATE); GCPROFILE_ITEM(); GC_PRINTF("Start flush phase \n"); // flush phase flush(stackptr); - GC_CHECK_ALL_CORE_STATUS(FLUSHPHASE==gc_status_info.gcphase); + GC_CHECK_ALL_CORE_STATUS(UPDATEPHASE==gc_status_info.gcphase); GC_PRINTF("Finish flush phase \n"); } diff --git a/Robust/src/Runtime/bamboo/multicoregarbage.h b/Robust/src/Runtime/bamboo/multicoregarbage.h index 7b83212d..8ba9bebb 100644 --- a/Robust/src/Runtime/bamboo/multicoregarbage.h +++ b/Robust/src/Runtime/bamboo/multicoregarbage.h @@ -127,11 +127,6 @@ unsigned int size_cachepolicytbl; ((((unsigned int)p)>=gcbaseva)&&(((unsigned int)p)<(gcbaseva+(BAMBOO_SHARED_MEM_SIZE)))) -//Minimum alignment unit -#define ALIGNMENTBYTES 32 - -//Bytes to shift to get minimum alignment units -#define ALIGNMENTSHIFT 5 #define MAXBLOCK 0x4fffffff //local block number that can never be reached... @@ -265,7 +260,7 @@ void gc_master(struct garbagelist * stackptr); void transferMarkResults_I(); -bool gcfindSpareMem_I(unsigned int * startaddr,unsigned int * tomove,unsigned int * dstcore,unsigned int requiredmem,unsigned int requiredcore); +void * gcfindSpareMem_I(unsigned int requiredmem,unsigned int requiredcore); #define INITMULTICOREGCDATA() initmulticoregcdata() #define DISMULTICOREGCDATA() dismulticoregcdata() diff --git a/Robust/src/Runtime/bamboo/multicoregccompact.c b/Robust/src/Runtime/bamboo/multicoregccompact.c index 3a6b9b04..7589129a 100644 --- a/Robust/src/Runtime/bamboo/multicoregccompact.c +++ b/Robust/src/Runtime/bamboo/multicoregccompact.c @@ -3,6 +3,7 @@ #include "runtime_arch.h" #include "multicoreruntime.h" #include "multicoregarbage.h" +#include "markbit.h" bool gc_checkCoreStatus() { for(int i = 0; i < NUMCORES4GC; ++i) { @@ -21,15 +22,15 @@ void gc_resetCoreStatus() { void initOrig_Dst(struct moveHelper * orig,struct moveHelper * to) { // init the dst ptr - to->blocknum = 0; - BASEPTR(to->base, BAMBOO_NUM_OF_CORE, to->blocknum); + to->localblocknum = 0; + BASEPTR(to->base, BAMBOO_NUM_OF_CORE, to->localblocknum); to->ptr = to->base; - to->bound=to->base+BLOCKSIZE(to->blocknum); + to->bound=to->base+BLOCKSIZE(to->localblocknum); // init the orig ptr - orig->blocknum = 0; + orig->localblocknum = 0; orig->ptr=orig->base = to->base; - orig->bound = orig->base + BLOCKSIZE(orig->blocknum); + orig->bound = orig->base + BLOCKSIZE(orig->localblocknum); } void getSpaceLocally(struct moveHelper *to) { @@ -107,7 +108,7 @@ unsigned int assignSpareMem_I(unsigned int sourcecore, unsigned int requiredmem, // next available block gcfilledblocks[sourcecore]++; void * newbase = NULL; - BASEPTR(sourcecore, gcfilledblocks[sourcecore], &newbase); + BASEPTR(newbase, sourcecore, gcfilledblocks[sourcecore]); topptrs[sourcecore] = newbase; return requiredmem-remain; } @@ -137,9 +138,9 @@ void * gcfindSpareMem_I(unsigned int requiredmem,unsigned int requiredcore) { return NULL; } -bool gcfindSpareMem(unsigned int * startaddr,unsigned int * tomove,unsigned int * dstcore,unsigned int requiredmem,unsigned int requiredcore) { +bool gcfindSpareMem(unsigned int requiredmem,unsigned int requiredcore) { BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT(); - bool retval=gcfindSpareMem_I(startaddr, tomove, dstcore, requiredmem, requiredcore); + bool retval=gcfindSpareMem_I(requiredmem, requiredcore); BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME(); return retval; } @@ -151,12 +152,12 @@ unsigned int compactblocks(struct moveHelper * orig, struct moveHelper * to) { void *tobound=to->bound; void *origptr=orig->ptr; void *origbound=orig->bound; - unsigned INTPTR origendoffset=ALIGNTOTABLEINDEX((unsigned INTPTR)(origbound-gcbase)); + unsigned INTPTR origendoffset=ALIGNTOTABLEINDEX((unsigned INTPTR)(origbound-gcbaseva)); unsigned int objlength; while(origptrbase; void *tobound=to->bound; void *origptr=orig->ptr; void *origbound=orig->bound; - unsigned INTPTR origendoffset=ALIGNTOTABLEINDEX((unsigned INTPTR)(origbound-gcbase)); + unsigned INTPTR origendoffset=ALIGNTOTABLEINDEX((unsigned INTPTR)(origbound-gcbaseva)); unsigned int objlength; while(origptrptr=toptr; orig->ptr=origptr; return 0; } @@ -210,17 +210,17 @@ unsigned int updateblocks(struct moveHelper * orig, struct moveHelper * to) { void *endtoptr=dstptr+length; if (endtoptr>tobound||endtoptrptr=toptr; + //get use the next block of memory + to->ptr=tobound; orig->ptr=origptr; - return length; + return dstptr; } /* Move the object */ - if(origptr <= dstptr+size) { - memmove(dstptr, origptr, size); + if(origptr <= endtoptr) { + memmove(dstptr, origptr, length); } else { - memcpy(dstptr, origptr, size); + memcpy(dstptr, origptr, length); } /* Update the pointers in the object */ @@ -232,7 +232,7 @@ unsigned int updateblocks(struct moveHelper * orig, struct moveHelper * to) { //good to move objects and update pointers origptr+=length; } else - origptr+=ALIGNSIZE; + origptr+=ALIGNMENTSIZE; } } diff --git a/Robust/src/Runtime/bamboo/multicoregcmark.c b/Robust/src/Runtime/bamboo/multicoregcmark.c index ae8a4943..847789c0 100644 --- a/Robust/src/Runtime/bamboo/multicoregcmark.c +++ b/Robust/src/Runtime/bamboo/multicoregcmark.c @@ -1,9 +1,10 @@ #ifdef MULTICORE_GC -#include "multicoregcmark.h" #include "runtime.h" #include "multicoreruntime.h" #include "GenericHashtable.h" #include "gcqueue.h" +#include "multicoregcmark.h" +#include "markbit.h" #ifdef TASK extern struct parameterwrapper ** objectqueues[][NUMCLASSES]; @@ -94,7 +95,7 @@ void markObj(void * objptr) { } } -INLINE void markgarbagelist(struct garbagelist * listptr) { +void markgarbagelist(struct garbagelist * listptr) { for(;listptr!=NULL;listptr=listptr->next) { int size=listptr->size; for(int i=0; i