From 8082d9728781e75918db402c86cdb854f5cb2ff6 Mon Sep 17 00:00:00 2001 From: jzhou Date: Thu, 31 Mar 2011 03:46:19 +0000 Subject: [PATCH] Bug fix: should use unsigned int instead of int for pointers in shared heap. Also as we now use a big share array to hold mapping information, do not need to allocate extra memory for master core's local heap. --- Robust/src/ClassLibrary/MGC/gnu/Stack.java | 1 + Robust/src/IR/Flat/BuildCode.java | 35 +- Robust/src/Runtime/bamboo/multicoregarbage.c | 366 ++++++++++--------- Robust/src/Runtime/bamboo/multicoregarbage.h | 120 +++--- Robust/src/Runtime/bamboo/multicorehelper.h | 12 +- Robust/src/Runtime/bamboo/multicoremem.h | 77 ++-- Robust/src/Runtime/bamboo/multicoreruntime.c | 53 ++- Robust/src/Runtime/mem.c | 36 +- Robust/src/Runtime/runtime.c | 2 +- Robust/src/Runtime/runtime.h | 4 +- 10 files changed, 363 insertions(+), 343 deletions(-) diff --git a/Robust/src/ClassLibrary/MGC/gnu/Stack.java b/Robust/src/ClassLibrary/MGC/gnu/Stack.java index b9fb3949..678be208 100644 --- a/Robust/src/ClassLibrary/MGC/gnu/Stack.java +++ b/Robust/src/ClassLibrary/MGC/gnu/Stack.java @@ -75,6 +75,7 @@ public class Stack/**/ extends Vector/**/ */ public Stack() { + super(); } /** diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index f6803b08..3c2015d4 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -52,6 +52,8 @@ public class BuildCode { Hashtable printedfieldstbl; int globaldefscount=0; boolean mgcstaticinit = false; + + int boundschknum = 0; public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil) { this(st, temptovar, typeutil, null); @@ -2661,19 +2663,24 @@ public class BuildCode { } } // redirect to the global_defs_p structure - if((ffn.getField().isStatic()) || (ffn.getSrc().getType().isClassNameRef())) { - // reference to the static field with Class name if (ffn.getField().getType().isPtr()) output.println(generateTemp(fm, ffn.getDst())+"=global_defs_p->"+ffn.getField().getSafeSymbol()+";"); else output.println(generateTemp(fm, ffn.getDst())+"=global_defsprim_p->"+ffn.getField().getSafeSymbol()+";"); - } else { - output.println(generateTemp(fm, ffn.getDst())+"=*"+ generateTemp(fm,ffn.getSrc())+"->"+ ffn.getField().getSafeSymbol()+";"); - } } else if (ffn.getField().isEnum()) { // an Enum value, directly replace the field access as int output.println(generateTemp(fm, ffn.getDst()) + "=" + ffn.getField().enumValue() + ";"); } else { + output.println("#ifdef MULTICORE_DEBUG"); + output.println("if (" + generateTemp(fm,ffn.getSrc()) + " == NULL) {"); + output.println("printf(\" NULL ptr error: %s, %s, %d \\n\", __FILE__, __func__, __LINE__);"); + if(state.MULTICOREGC) { + output.println("failednullptr(&___locals___);"); + } else { + output.println("failednullptr(NULL);"); + } + output.println("}"); + output.println("#endif //MULTICORE_DEBUG"); output.println(generateTemp(fm, ffn.getDst())+"="+ generateTemp(fm,ffn.getSrc())+"->"+ ffn.getField().getSafeSymbol()+";"); } } @@ -2726,19 +2733,23 @@ public class BuildCode { } } // redirect to the global_defs_p structure - if((fsfn.getDst().getType().isClassNameRef()) || (fsfn.getField().isStatic())) { - // reference to the static field with Class name if (fsfn.getField().getType().isPtr()) output.println("global_defs_p->" + fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc())+";"); else output.println("global_defsprim_p->" + fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc())+";"); + } else { + output.println("#ifdef MULTICORE_DEBUG"); + output.println("if (" + generateTemp(fm,fsfn.getDst()) + " == NULL) {"); + output.println("printf(\" NULL ptr error: %s, %s, %d \\n\", __FILE__, __func__, __LINE__);"); + if(state.MULTICOREGC) { + output.println("failednullptr(&___locals___);"); } else { - output.println("*"+generateTemp(fm, fsfn.getDst())+"->"+ - fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc())+";"); + output.println("failednullptr(NULL);"); } - } else { + output.println("}"); + output.println("#endif //MULTICORE_DEBUG"); output.println(generateTemp(fm, fsfn.getDst())+"->"+ fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc())+";"); } @@ -2758,7 +2769,7 @@ public class BuildCode { if (this.state.ARRAYBOUNDARYCHECK && fen.needsBoundsCheck()) { output.println("if (unlikely(((unsigned int)"+generateTemp(fm, fen.getIndex())+") >= "+generateTemp(fm,fen.getSrc()) + "->___length___))"); - output.println("failedboundschk();"); + output.println("failedboundschk(" + (boundschknum++) + ");"); } output.println(generateTemp(fm, fen.getDst())+"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc())+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex())+"];"); } @@ -2779,7 +2790,7 @@ public class BuildCode { if (this.state.ARRAYBOUNDARYCHECK && fsen.needsBoundsCheck()) { output.println("if (unlikely(((unsigned int)"+generateTemp(fm, fsen.getIndex())+") >= "+generateTemp(fm,fsen.getDst()) + "->___length___))"); - output.println("failedboundschk();"); + output.println("failedboundschk(" + (boundschknum++) + ");"); } if (state.FASTCHECK) { String dst=generateTemp(fm, fsen.getDst()); diff --git a/Robust/src/Runtime/bamboo/multicoregarbage.c b/Robust/src/Runtime/bamboo/multicoregarbage.c index f1fc156d..73d145c5 100644 --- a/Robust/src/Runtime/bamboo/multicoregarbage.c +++ b/Robust/src/Runtime/bamboo/multicoregarbage.c @@ -79,8 +79,8 @@ gc_cache_revise_info_t gc_cache_revise_infomation; inline void dumpSMem() { int block = 0; int sblock = 0; - int j = 0; - int i = 0; + unsigned int j = 0; + unsigned int i = 0; int coren = 0; int x = 0; int y = 0; @@ -207,8 +207,8 @@ inline int gc_moreItems2_I() { // should be invoked with interruption closed // enqueue a large obj: start addr & length inline void gc_lobjenqueue_I(void *ptr, - int length, - int host) { + unsigned int length, + unsigned int host) { GC_BAMBOO_DEBUGPRINT(0xe901); if (gclobjheadindex==NUMLOBJPTRS) { struct lobjpointerblock * tmp; @@ -232,8 +232,8 @@ inline void gc_lobjenqueue_I(void *ptr, } // void gc_lobjenqueue_I(void *ptr...) // dequeue and destroy the queue -inline void * gc_lobjdequeue_I(int * length, - int * host) { +inline void * gc_lobjdequeue_I(unsigned int * length, + unsigned int * host) { if (gclobjtailindex==NUMLOBJPTRS) { struct lobjpointerblock *tmp=gclobjtail; gclobjtail=gclobjtail->next; @@ -299,8 +299,8 @@ inline void gc_lobjqueueinit4_I() { gclobjtailindex2 = gclobjtailindex; } // void gc_lobjqueueinit2() -inline void * gc_lobjdequeue4_I(int * length, - int * host) { +inline void * gc_lobjdequeue4_I(unsigned int * length, + unsigned int * host) { if (gclobjtailindex2==NUMLOBJPTRS) { gclobjtail2=gclobjtail2->next; gclobjtailindex2=0; @@ -309,7 +309,7 @@ inline void * gc_lobjdequeue4_I(int * length, *length = gclobjtail2->lengths[gclobjtailindex2]; } if(host != NULL) { - *host = (int)(gclobjtail2->hosts[gclobjtailindex2]); + *host = (unsigned int)(gclobjtail2->hosts[gclobjtailindex2]); } return gclobjtail2->lobjs[gclobjtailindex2++]; } // void * gc_lobjdequeue() @@ -320,21 +320,21 @@ inline int gc_lobjmoreItems4_I() { return 1; } // int gc_lobjmoreItems( -INTPTR gccurr_heapbound = 0; +unsigned int gccurr_heapbound = 0; inline void gettype_size(void * ptr, int * ttype, - int * tsize) { + unsigned int * tsize) { int type = ((int *)ptr)[0]; - int size = 0; + unsigned int size = 0; if(type < NUMCLASSES) { // a normal object size = classsize[type]; } else { // an array struct ArrayObject *ao=(struct ArrayObject *)ptr; - int elementsize=classsize[type]; - int length=ao->___length___; + unsigned int elementsize=classsize[type]; + unsigned int length=ao->___length___; size=sizeof(struct ArrayObject)+length*elementsize; } // if(type < NUMCLASSES) *ttype = type; @@ -343,23 +343,23 @@ inline void gettype_size(void * ptr, inline bool isLarge(void * ptr, int * ttype, - int * tsize) { + unsigned int * tsize) { GC_BAMBOO_DEBUGPRINT(0xe701); GC_BAMBOO_DEBUGPRINT_REG(ptr); // check if a pointer is referring to a large object gettype_size(ptr, ttype, tsize); GC_BAMBOO_DEBUGPRINT(*tsize); - int bound = (BAMBOO_SMEM_SIZE); - if(((int)ptr-gcbaseva) < (BAMBOO_LARGE_SMEM_BOUND)) { + unsigned int bound = (BAMBOO_SMEM_SIZE); + if(((unsigned int)ptr-gcbaseva) < (BAMBOO_LARGE_SMEM_BOUND)) { bound = (BAMBOO_SMEM_SIZE_L); } - if((((int)ptr-gcbaseva)%(bound))==0) { + if((((unsigned int)ptr-gcbaseva)%(bound))==0) { // ptr is a start of a block GC_BAMBOO_DEBUGPRINT(0xe702); GC_BAMBOO_DEBUGPRINT(1); return true; } - if((bound-(((int)ptr-gcbaseva)%bound)) < (*tsize)) { + if((bound-(((unsigned int)ptr-gcbaseva)%bound)) < (*tsize)) { // it acrosses the boundary of current block GC_BAMBOO_DEBUGPRINT(0xe703); GC_BAMBOO_DEBUGPRINT(1); @@ -369,9 +369,9 @@ inline bool isLarge(void * ptr, return false; } // bool isLarge(void * ptr, int * ttype, int * tsize) -inline int hostcore(void * ptr) { +inline unsigned int hostcore(void * ptr) { // check the host core of ptr - int host = 0; + unsigned int host = 0; RESIDECORE(ptr, &host); GC_BAMBOO_DEBUGPRINT(0xedd0); GC_BAMBOO_DEBUGPRINT_REG(ptr); @@ -379,9 +379,9 @@ inline int hostcore(void * ptr) { return host; } // int hostcore(void * ptr) -inline void cpu2coords(int coren, - int * x, - int * y) { +inline void cpu2coords(unsigned int coren, + unsigned int * x, + unsigned int * y) { *x = bamboo_cpu2coords[2*coren]; *y = bamboo_cpu2coords[2*coren+1]; } // void cpu2coords(...) @@ -419,7 +419,7 @@ inline void checkMarkStatue() { if((!waitconfirm) || (waitconfirm && (numconfirm == 0))) { GC_BAMBOO_DEBUGPRINT(0xee02); - int entry_index = 0; + unsigned int entry_index = 0; if(waitconfirm) { // phase 2 entry_index = (gcnumsrobjs_index == 0) ? 1 : 0; @@ -455,7 +455,7 @@ inline void checkMarkStatue() { // Phase 2 // 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 - int sumsendobj = 0; + unsigned int sumsendobj = 0; for(i = 0; i < NUMCORESACTIVE; ++i) { sumsendobj += gcnumsendobjs[gcnumsrobjs_index][i]; } // for(i = 0; i < NUMCORESACTIVE; ++i) @@ -581,12 +581,12 @@ inline void initGC() { } // void initGC() // compute load balance for all cores -inline int loadbalance(int * heaptop) { +inline int loadbalance(unsigned int * heaptop) { // compute load balance int i; // get the total loads - int tloads = gcloads[STARTUPCORE]; + unsigned int tloads = gcloads[STARTUPCORE]; for(i = 1; i < NUMCORES4GC; i++) { tloads += gcloads[i]; } @@ -595,9 +595,9 @@ inline int loadbalance(int * heaptop) { GC_BAMBOO_DEBUGPRINT(0xdddd); GC_BAMBOO_DEBUGPRINT_REG(tloads); GC_BAMBOO_DEBUGPRINT_REG(*heaptop); - int b = 0; + unsigned int b = 0; BLOCKINDEX(*heaptop, &b); - int numbpc = b / NUMCORES4GC; // num of blocks per core + unsigned int numbpc = (unsigned int)b/(unsigned int)(NUMCORES4GC);// num of blocks per core GC_BAMBOO_DEBUGPRINT_REG(b); GC_BAMBOO_DEBUGPRINT_REG(numbpc); gctopblock = b; @@ -609,13 +609,13 @@ inline int loadbalance(int * heaptop) { inline bool cacheLObjs() { // check the total mem size need for large objs unsigned long long sumsize = 0; - int size = 0; + unsigned int size = 0; GC_BAMBOO_DEBUGPRINT(0xe801); gclobjtail2 = gclobjtail; gclobjtailindex2 = gclobjtailindex; - int tmp_lobj = 0; - int tmp_len = 0; - int tmp_host = 0; + unsigned int tmp_lobj = 0; + unsigned int tmp_len = 0; + unsigned int tmp_host = 0; // compute total mem size required and sort the lobjs in ascending order // TODO USE QUICK SORT INSTEAD? while(gc_lobjmoreItems2_I()) { @@ -630,7 +630,7 @@ inline bool cacheLObjs() { GC_BAMBOO_DEBUGPRINT_REG(gclobjtail2->lobjs[gclobjtailindex2-1]); GC_BAMBOO_DEBUGPRINT_REG(tmp_len); GC_BAMBOO_DEBUGPRINT_REG(sumsize); - int i = gclobjtailindex2-1; + unsigned int i = gclobjtailindex2-1; struct lobjpointerblock * tmp_block = gclobjtail2; // find the place to insert while(true) { @@ -670,7 +670,7 @@ inline bool cacheLObjs() { gc_num_lobjspace = sumsize; #endif // check if there are enough space to cache these large objs - INTPTR dst = gcbaseva + (BAMBOO_SHARED_MEM_SIZE) -sumsize; + 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 GC_BAMBOO_DEBUGPRINT(0xe802); @@ -693,7 +693,7 @@ inline bool cacheLObjs() { // and need to be flushed ((int *)(gclobjtail2->lobjs[gclobjtailindex2]))[BAMBOOMARKBIT] = COMPACTED; dst -= size; - if((int)dst < (int)(gclobjtail2->lobjs[gclobjtailindex2])+size) { + if((unsigned int)dst < (unsigned int)(gclobjtail2->lobjs[gclobjtailindex2]+size)) { memmove(dst, gclobjtail2->lobjs[gclobjtailindex2], size); } else { memcpy(dst, gclobjtail2->lobjs[gclobjtailindex2], size); @@ -709,20 +709,20 @@ inline bool cacheLObjs() { } // void cacheLObjs() // update the bmmboo_smemtbl to record current shared mem usage -void updateSmemTbl(int coren, - int localtop) { - int ltopcore = 0; - int bound = BAMBOO_SMEM_SIZE_L; +void updateSmemTbl(unsigned int coren, + unsigned int localtop) { + unsigned int ltopcore = 0; + unsigned int bound = BAMBOO_SMEM_SIZE_L; BLOCKINDEX(localtop, <opcore); - if(localtop >= (gcbaseva+(BAMBOO_LARGE_SMEM_BOUND))) { + if((unsigned int)localtop>=(unsigned int)(gcbaseva+BAMBOO_LARGE_SMEM_BOUND)){ bound = BAMBOO_SMEM_SIZE; } - int load = (localtop-gcbaseva)%bound; - int i = 0; - int j = 0; - int toset = 0; + 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]+(NUMCORES4GC*2)*j; + toset = gc_core2block[2*coren+i]+(unsigned int)(NUMCORES4GC*2)*j; if(toset < ltopcore) { bamboo_smemtbl[toset]= (toset (gcbaseva+(BAMBOO_SMEM_SIZE_L))) - && ((gcloads[0]%(BAMBOO_SMEM_SIZE)) == 0)) { + if(((unsigned int)gcloads[0] > (unsigned int)(gcbaseva+BAMBOO_SMEM_SIZE_L)) + && (((unsigned int)gcloads[0]%(BAMBOO_SMEM_SIZE)) == 0)) { // edge of a block, check if this is exactly the heaptop BASEPTR(0, gcfilledblocks[0]-1, &(gcloads[0])); gcloads[0]+=(gcfilledblocks[0]>1 ? @@ -769,12 +769,12 @@ inline void moveLObjs() { GC_BAMBOO_DEBUGPRINT_REG(gcloads[0]); GC_BAMBOO_DEBUGPRINT_REG(bamboo_smemtbl[0]); for(int i = 1; i < NUMCORES4GC; i++) { - int tmptop = 0; + unsigned int tmptop = 0; GC_BAMBOO_DEBUGPRINT(0xf000+i); GC_BAMBOO_DEBUGPRINT_REG(gcloads[i]); GC_BAMBOO_DEBUGPRINT_REG(gcfilledblocks[i]); if((gcfilledblocks[i] > 0) - && ((gcloads[i] % (BAMBOO_SMEM_SIZE)) == 0)) { + && (((unsigned int)gcloads[i] % (BAMBOO_SMEM_SIZE)) == 0)) { // edge of a block, check if this is exactly the heaptop BASEPTR(i, gcfilledblocks[i]-1, &gcloads[i]); gcloads[i] += @@ -789,9 +789,9 @@ inline void moveLObjs() { // TODO // a bug here: when using local allocation, directly move large objects // to the highest free chunk might not be memory efficient - int tmpheaptop = 0; - int size = 0; - int bound = 0; + unsigned int tmpheaptop = 0; + unsigned int size = 0; + unsigned int bound = 0; int i = 0; for(i = gcnumblock-1; i >= 0; i--) { if(bamboo_smemtbl[i] > 0) { @@ -808,7 +808,7 @@ inline void moveLObjs() { // move large objs from gcheaptop to tmpheaptop // write the header first - unsigned int tomove = gcbaseva + (BAMBOO_SHARED_MEM_SIZE) -gcheaptop; + unsigned int tomove = gcbaseva+(BAMBOO_SHARED_MEM_SIZE)-gcheaptop; #ifdef SMEMM gcmem_mixed_usedmem += tomove; #endif @@ -818,14 +818,15 @@ inline void moveLObjs() { GC_BAMBOO_DEBUGPRINT_REG(gcheaptop); // flush the sbstartbl BAMBOO_MEMSET_WH(&(gcsbstarttbl[gcreservedsb]), '\0', - (BAMBOO_SHARED_MEM_SIZE/BAMBOO_SMEM_SIZE-gcreservedsb)*sizeof(INTPTR)); + (BAMBOO_SHARED_MEM_SIZE/BAMBOO_SMEM_SIZE-(unsigned int)gcreservedsb) + *sizeof(unsigned int)); if(tomove == 0) { gcheaptop = tmpheaptop; } else { // check how many blocks it acrosses - int remain = tmpheaptop-gcbaseva; - int sb = remain/(BAMBOO_SMEM_SIZE) + gcreservedsb;//number of the sblock - int b = 0; // number of the block + unsigned int remain = tmpheaptop-gcbaseva; + unsigned int sb = remain/BAMBOO_SMEM_SIZE+(unsigned int)gcreservedsb;//number of the sblock + unsigned int b = 0; // number of the block BLOCKINDEX(tmpheaptop, &b); // check the remaining space in this block bound = (BAMBOO_SMEM_SIZE); @@ -836,11 +837,11 @@ inline void moveLObjs() { GC_BAMBOO_DEBUGPRINT(0xea04); size = 0; - int isize = 0; - int host = 0; - int ptr = 0; - int base = tmpheaptop; - int cpysize = 0; + unsigned int isize = 0; + unsigned int host = 0; + unsigned int ptr = 0; + unsigned int base = tmpheaptop; + unsigned int cpysize = 0; remain -= BAMBOO_CACHE_LINE_SIZE; tmpheaptop += BAMBOO_CACHE_LINE_SIZE; gc_lobjqueueinit4_I(); @@ -863,11 +864,12 @@ inline void moveLObjs() { remain -= BAMBOO_CACHE_LINE_SIZE; tmpheaptop += BAMBOO_CACHE_LINE_SIZE; BLOCKINDEX(tmpheaptop, &b); - sb = (tmpheaptop-gcbaseva)/(BAMBOO_SMEM_SIZE) + gcreservedsb; + sb = (unsigned int)(tmpheaptop-gcbaseva)/(BAMBOO_SMEM_SIZE) + +gcreservedsb; } // if(cpysize > 0) // move the large obj - if((int)gcheaptop < (int)(tmpheaptop)+size) { + if((unsigned int)gcheaptop < (unsigned int)(tmpheaptop+size)) { memmove(tmpheaptop, gcheaptop, size); } else { //BAMBOO_WRITE_HINT_CACHE(tmpheaptop, size); @@ -883,16 +885,17 @@ inline void moveLObjs() { GC_BAMBOO_DEBUGPRINT_REG(base); gcheaptop += size; // cache the mapping info - gcmappingtbl[OBJMAPPINGINDEX((int)ptr)] = (INTPTR)tmpheaptop; + gcmappingtbl[OBJMAPPINGINDEX((unsigned int)ptr)] = + (unsigned int)tmpheaptop; GC_BAMBOO_DEBUGPRINT(0xcdca); GC_BAMBOO_DEBUGPRINT_REG(ptr); GC_BAMBOO_DEBUGPRINT_REG(tmpheaptop); tmpheaptop += isize; // set the gcsbstarttbl and bamboo_smemtbl - int tmpsbs = 1+(isize-remain-1)/BAMBOO_SMEM_SIZE; + unsigned int tmpsbs=1+(unsigned int)(isize-remain-1)/BAMBOO_SMEM_SIZE; for(int k = 1; k < tmpsbs; k++) { - gcsbstarttbl[sb+k] = (INTPTR)(-1); + gcsbstarttbl[sb+k] = -1; } sb += tmpsbs; bound = (b___length___; @@ -1277,7 +1281,7 @@ inline void mark(bool isfirst, markObj(objptr); } } else { - INTPTR size=pointer[0]; + unsigned int size=pointer[0]; int i; for(i=1; i<=size; i++) { unsigned int offset=pointer[i]; @@ -1316,12 +1320,12 @@ inline void mark(bool isfirst, BAMBOO_CACHE_MF(); } // mark() -inline void compact2Heaptophelper_I(int coren, - int* p, - int* numblocks, - int* remain) { - int b; - int memneed = gcrequiredmems[coren] + BAMBOO_CACHE_LINE_SIZE; +inline void compact2Heaptophelper_I(unsigned int coren, + unsigned int* p, + unsigned int* numblocks, + unsigned int* remain) { + unsigned int b; + unsigned int memneed = gcrequiredmems[coren] + BAMBOO_CACHE_LINE_SIZE; if(STARTUPCORE == coren) { gctomove = true; gcmovestartaddr = *p; @@ -1345,7 +1349,7 @@ inline void compact2Heaptophelper_I(int coren, // next available block *p = *p + *remain; gcfilledblocks[gctopcore] += 1; - int newbase = 0; + unsigned int newbase = 0; BASEPTR(gctopcore, gcfilledblocks[gctopcore], &newbase); gcloads[gctopcore] = newbase; gcrequiredmems[coren] -= *remain - BAMBOO_CACHE_LINE_SIZE; @@ -1370,12 +1374,12 @@ inline void compact2Heaptophelper_I(int coren, inline void compact2Heaptop() { // no cores with spare mem and some cores are blocked with pending move // find the current heap top and make them move to the heap top - int p; - int numblocks = gcfilledblocks[gctopcore]; + unsigned int p; + unsigned int numblocks = gcfilledblocks[gctopcore]; p = gcloads[gctopcore]; - int b; + unsigned int b; BLOCKINDEX(p, &b); - int remain = (bblockbase = orig->blockbound; bool sbchanged = false; - INTPTR origptr = orig->ptr; - int blockbase = orig->blockbase; - int blockbound = orig->blockbound; - int bound = orig->bound; + unsigned int origptr = orig->ptr; + unsigned int blockbase = orig->blockbase; + unsigned int blockbound = orig->blockbound; + unsigned int bound = orig->bound; GC_BAMBOO_DEBUGPRINT(0xecc0); GC_BAMBOO_DEBUGPRINT_REG(blockbase); GC_BAMBOO_DEBUGPRINT_REG(blockbound); @@ -1546,9 +1550,10 @@ innernextSBlock: return false; } orig->blockbase = orig->base; - orig->sblockindex = (orig->blockbase-gcbaseva)/BAMBOO_SMEM_SIZE; + orig->sblockindex = + (unsigned int)(orig->blockbase-gcbaseva)/BAMBOO_SMEM_SIZE; sbchanged = true; - int blocknum = 0; + unsigned int blocknum = 0; BLOCKINDEX(orig->base, &blocknum); if(bamboo_smemtbl[blocknum] == 0) { // goto next block @@ -1577,7 +1582,7 @@ innernextSBlock: } // if(gcsbstarttbl[orig->sblockindex] == -1) else ... // setup information for this sblock - orig->blockbound = orig->blockbase + *((int*)(orig->blockbase)); + orig->blockbound = orig->blockbase+(unsigned int)*((int*)(orig->blockbase)); orig->offset = BAMBOO_CACHE_LINE_SIZE; orig->ptr = orig->blockbase + orig->offset; GC_BAMBOO_DEBUGPRINT(0xecc4); @@ -1606,12 +1611,12 @@ inline bool initOrig_Dst(struct moveHelper * orig, GC_BAMBOO_DEBUGPRINT(0xef01); GC_BAMBOO_DEBUGPRINT_REG(to->base); - INTPTR tobase = to->base; + unsigned int tobase = to->base; to->ptr = tobase + to->offset; #ifdef GC_CACHE_ADAPT // initialize the gc_cache_revise_information gc_cache_revise_infomation.to_page_start_va = to->ptr; - int toindex = (tobase-gcbaseva)/(BAMBOO_PAGE_SIZE); + unsigned int toindex = (unsigned int)(tobase-gcbaseva)/(BAMBOO_PAGE_SIZE); gc_cache_revise_infomation.to_page_end_va = (BAMBOO_PAGE_SIZE)* (toindex+1); gc_cache_revise_infomation.to_page_index = toindex; @@ -1621,13 +1626,13 @@ inline bool initOrig_Dst(struct moveHelper * orig, // init the orig ptr orig->numblocks = 0; orig->base = tobase; - int blocknum = 0; + unsigned int blocknum = 0; BLOCKINDEX(orig->base, &blocknum); - INTPTR origbase = orig->base; + unsigned int origbase = orig->base; // check the bamboo_smemtbl to decide the real bound - orig->bound = origbase + bamboo_smemtbl[blocknum]; + orig->bound = origbase + (unsigned int)bamboo_smemtbl[blocknum]; orig->blockbase = origbase; - orig->sblockindex = (origbase - gcbaseva) / BAMBOO_SMEM_SIZE; + orig->sblockindex = (unsigned int)(origbase - gcbaseva) / BAMBOO_SMEM_SIZE; GC_BAMBOO_DEBUGPRINT(0xef02); GC_BAMBOO_DEBUGPRINT_REG(origbase); GC_BAMBOO_DEBUGPRINT_REG(orig->sblockindex); @@ -1682,9 +1687,9 @@ inline void samplingDataConvert(int current_ptr) { inline void completePageConvert(struct moveHelper * orig, struct moveHelper * to, - int current_ptr, + unsigned int current_ptr, bool closeToPage) { - INTPTR ptr = 0; + unsigned int ptr = 0; int tocompare = 0; if(closeToPage) { ptr = to->ptr; @@ -1717,7 +1722,7 @@ inline void completePageConvert(struct moveHelper * orig, // endaddr does not contain spaces for headers inline bool moveobj(struct moveHelper * orig, struct moveHelper * to, - int stopblock) { + unsigned int stopblock) { if(stopblock == 0) { return true; } @@ -1727,19 +1732,19 @@ inline bool moveobj(struct moveHelper * orig, GC_BAMBOO_DEBUGPRINT_REG(to->ptr); int type = 0; - int size = 0; int mark = 0; - int isize = 0; + unsigned int size = 0; + unsigned int isize = 0; innermoveobj: while((*((char*)(orig->ptr))) == (char)(-2)) { - orig->ptr = (void*)(orig->ptr) + 1; + orig->ptr = (unsigned int)((void*)(orig->ptr) + 1); } #ifdef GC_CACHE_ADAPT completePageConvert(orig, to, to->ptr, false); #endif - INTPTR origptr = orig->ptr; - int origbound = orig->bound; - int origblockbound = orig->blockbound; + unsigned int origptr = (unsigned int)(orig->ptr); + unsigned int origbound = (unsigned int)orig->bound; + unsigned int origblockbound = (unsigned int)orig->blockbound; if((origptr >= origbound) || (origptr == origblockbound)) { if(!nextSBlock(orig)) { // finished, no more data @@ -1766,9 +1771,10 @@ innermoveobj: } else { // an array struct ArrayObject *ao=(struct ArrayObject *)(origptr); - int elementsize=classsize[type]; - int length=ao->___length___; - size=sizeof(struct ArrayObject)+length*elementsize; + unsigned int elementsize=classsize[type]; + unsigned int length=ao->___length___; + size=(unsigned int)sizeof(struct ArrayObject) + +(unsigned int)(length*elementsize); } mark = ((int *)(origptr))[BAMBOOMARKBIT]; bool isremote = ((((int *)(origptr))[BAMBOOMARKBIT] & REMOTEM) != 0); @@ -1778,15 +1784,15 @@ innermoveobj: ALIGNSIZE(size, &isize); // no matter is the obj marked or not // should be able to across it if((mark & MARKED) != 0) { - int totop = to->top; - int tobound = to->bound; + unsigned int totop = (unsigned int)to->top; + unsigned int tobound = (unsigned int)to->bound; GC_BAMBOO_DEBUGPRINT(0xe204); #ifdef GC_PROFILE gc_num_liveobj++; #endif // marked obj, copy it to current heap top // check to see if remaining space is enough - if(totop + isize > tobound) { + if((unsigned int)(totop + isize) > tobound) { // fill 0 indicating the end of this block BAMBOO_MEMSET_WH(to->ptr, '\0', tobound - totop); // fill the header of this block and then go to next block @@ -1794,7 +1800,7 @@ innermoveobj: BAMBOO_MEMSET_WH(to->base, '\0', BAMBOO_CACHE_LINE_SIZE); (*((int*)(to->base))) = to->offset; #ifdef GC_CACHE_ADAPT - int tmp_ptr = to->ptr; + unsigned int tmp_ptr = to->ptr; #endif // GC_CACHE_ADAPT nextBlock(to); #ifdef GC_CACHE_ADAPT @@ -1808,9 +1814,9 @@ innermoveobj: // set the mark field to 2, indicating that this obj has been moved // and need to be flushed ((int *)(origptr))[BAMBOOMARKBIT] = COMPACTED; - INTPTR toptr = to->ptr; + unsigned int toptr = (unsigned int)to->ptr; if(toptr != origptr) { - if((int)(origptr) < (int)(toptr)+size) { + if((unsigned int)(origptr) < (unsigned int)(toptr+size)) { memmove(toptr, origptr, size); } else { memcpy(toptr, origptr, size); @@ -1819,7 +1825,7 @@ innermoveobj: BAMBOO_MEMSET_WH(toptr+size, -2, isize-size); } // store mapping info - gcmappingtbl[OBJMAPPINGINDEX((int)origptr)] = (INTPTR)toptr; + gcmappingtbl[OBJMAPPINGINDEX((unsigned int)origptr)]=(unsigned int)toptr; GC_BAMBOO_DEBUGPRINT(0xcdce); GC_BAMBOO_DEBUGPRINT_REG(origptr); GC_BAMBOO_DEBUGPRINT_REG(toptr); @@ -1829,7 +1835,7 @@ innermoveobj: to->offset += isize; to->top += isize; #ifdef GC_CACHE_ADAPT - int tmp_ptr = to->ptr; + unsigned int tmp_ptr = to->ptr; #endif // GC_CACHE_ADAPT if(to->top == to->bound) { // fill the header of this block and then go to next block @@ -1850,7 +1856,8 @@ innermoveobj: GC_BAMBOO_DEBUGPRINT_REG(size); GC_BAMBOO_DEBUGPRINT_REG(orig->ptr); GC_BAMBOO_DEBUGPRINT_REG(orig->bound); - if((orig->ptr > orig->bound) || (orig->ptr == orig->blockbound)) { + if(((unsigned int)(orig->ptr) > (unsigned int)(orig->bound)) + || ((unsigned int)(orig->ptr) == (unsigned int)(orig->blockbound))) { GC_BAMBOO_DEBUGPRINT(0xe206); if(!nextSBlock(orig)) { // finished, no more data @@ -1863,16 +1870,16 @@ innermoveobj: } //bool moveobj(struct moveHelper* orig,struct moveHelper* to,int* endaddr) // should be invoked with interrupt closed -inline int assignSpareMem_I(int sourcecore, - int * requiredmem, - int * tomove, - int * startaddr) { - int b = 0; +inline int assignSpareMem_I(unsigned int sourcecore, + unsigned int * requiredmem, + unsigned int * tomove, + unsigned int * startaddr) { + unsigned int b = 0; BLOCKINDEX(gcloads[sourcecore], &b); - int boundptr = (bptr < gcmarkedptrbound) { + while((unsigned int)(orig->ptr) < (unsigned int)gcmarkedptrbound) { bool stop = moveobj(orig, to, gcblock2fill); if(stop) { break; @@ -1932,7 +1939,7 @@ innercompact: #endif // GC_CACHE_ADAPT // if no objs have been compact, do nothing, // otherwise, fill the header of this block - if(to->offset > BAMBOO_CACHE_LINE_SIZE) { + if(to->offset > (unsigned int)BAMBOO_CACHE_LINE_SIZE) { BAMBOO_MEMSET_WH(to->base, '\0', BAMBOO_CACHE_LINE_SIZE); (*((int*)(to->base))) = to->offset; } else { @@ -1956,7 +1963,7 @@ innercompact: if(STARTUPCORE == BAMBOO_NUM_OF_CORE) { gcfilledblocks[BAMBOO_NUM_OF_CORE] = *filledblocks; gcloads[BAMBOO_NUM_OF_CORE] = *heaptopptr; - if(orig->ptr < gcmarkedptrbound) { + if((unsigned int)(orig->ptr) < (unsigned int)gcmarkedptrbound) { GC_BAMBOO_DEBUGPRINT(0xe103); // ask for more mem gctomove = false; @@ -2071,8 +2078,8 @@ inline void compact() { (orig->blockbase-gcbaseva)/(BAMBOO_PAGE_SIZE); #endif // GC_CACHE_ADAPT - int filledblocks = 0; - INTPTR heaptopptr = 0; + unsigned int filledblocks = 0; + unsigned int heaptopptr = 0; bool localcompact = true; compacthelper(orig, to, &filledblocks, &heaptopptr, &localcompact); RUNFREE(orig); @@ -2280,14 +2287,14 @@ inline void flush(struct garbagelist * stackptr) { if((!ISSHAREDOBJ(ptr)) || (((int *)(ptr))[BAMBOOMARKBIT] == COMPACTED)) { int type = ((int *)(ptr))[0]; // scan all pointers in ptr - unsigned INTPTR * pointer; + unsigned int * pointer; pointer=pointerarray[type]; GC_BAMBOO_DEBUGPRINT(0xe303); GC_BAMBOO_DEBUGPRINT_REG(pointer); if (pointer==0) { /* Array of primitives */ /* Do nothing */ - } else if (((INTPTR)pointer)==1) { + } else if (((unsigned int)pointer)==1) { GC_BAMBOO_DEBUGPRINT(0xe304); /* Array of pointers */ struct ArrayObject *ao=(struct ArrayObject *) ptr; @@ -2307,7 +2314,7 @@ inline void flush(struct garbagelist * stackptr) { } } else { GC_BAMBOO_DEBUGPRINT(0xe306); - INTPTR size=pointer[0]; + unsigned int size=pointer[0]; int i; for(i=1; i<=size; i++) { GC_BAMBOO_DEBUGPRINT(0xe307); @@ -2347,14 +2354,14 @@ inline void flush(struct garbagelist * stackptr) { if(((int *)(ptr))[BAMBOOMARKBIT] == COMPACTED) { int type = ((int *)(ptr))[0]; // scan all pointers in ptr - unsigned INTPTR * pointer; + unsigned int * pointer; pointer=pointerarray[type]; GC_BAMBOO_DEBUGPRINT(0xe30b); GC_BAMBOO_DEBUGPRINT_REG(pointer); if (pointer==0) { /* Array of primitives */ /* Do nothing */ - } else if (((INTPTR)pointer)==1) { + } else if (((unsigned int)pointer)==1) { GC_BAMBOO_DEBUGPRINT(0xe30c); /* Array of pointers */ struct ArrayObject *ao=(struct ArrayObject *) ptr; @@ -2374,7 +2381,7 @@ inline void flush(struct garbagelist * stackptr) { } } else { GC_BAMBOO_DEBUGPRINT(0xe30e); - INTPTR size=pointer[0]; + unsigned int size=pointer[0]; int i; for(i=1; i<=size; i++) { GC_BAMBOO_DEBUGPRINT(0xe30f); @@ -2455,9 +2462,9 @@ int cacheAdapt_policy_local(){ for(page_index = 0; page_index < page_num; page_index++) { page_sva = gcbaseva + (BAMBOO_PAGE_SIZE) * page_index; bamboo_cache_policy_t policy = {0}; - int block = 0; + unsigned int block = 0; BLOCKINDEX(page_sva, &block); - int coren = gc_block2core[block%(NUMCORES4GC*2)]; + unsigned int coren = gc_block2core[block%(NUMCORES4GC*2)]; // locally cache the page in the hotest core // NOTE: (x,y) should be changed to (x+1, y+1)!!! policy.cache_mode = BAMBOO_CACHE_MODE_COORDS; @@ -2482,7 +2489,7 @@ int cacheAdapt_policy_hotest(){ for(page_index = 0; page_index < page_num; page_index++) { page_sva = gcbaseva + (BAMBOO_PAGE_SIZE) * page_index; bamboo_cache_policy_t policy = {0}; - int hotestcore = 0; + unsigned int hotestcore = 0; unsigned int hotfreq = 0; unsigned int *local_tbl=&gccachesamplingtbl_r[page_index]; @@ -2536,7 +2543,7 @@ int cacheAdapt_policy_dominate(){ for(page_index = 0; page_index < page_num; page_index++) { page_sva = gcbaseva + (BAMBOO_PAGE_SIZE) * page_index; bamboo_cache_policy_t policy = {0}; - int hotestcore = 0; + unsigned int hotestcore = 0; unsigned long long totalfreq = 0; unsigned int hotfreq = 0; @@ -2643,7 +2650,7 @@ int cacheAdapt_policy_overload(){ for(page_index = 0; page_index < page_num; page_index++) { page_sva = gcbaseva + (BAMBOO_PAGE_SIZE) * page_index; bamboo_cache_policy_t policy = {0}; - int hotestcore = 0; + unsigned int hotestcore = 0; unsigned long long totalfreq = 0; unsigned int hotfreq = 0; @@ -2743,7 +2750,7 @@ int cacheAdapt_policy_crowd(){ for(page_index = 0; page_index < page_num; page_index++) { page_sva = gcbaseva + (BAMBOO_PAGE_SIZE) * page_index; bamboo_cache_policy_t policy = {0}; - int hotestcore = 0; + unsigned int hotestcore = 0; unsigned long long totalfreq = 0; unsigned int hotfreq = 0; @@ -2889,7 +2896,7 @@ void gc_output_cache_sampling() { unsigned int page_num = (BAMBOO_SHARED_MEM_SIZE) / (BAMBOO_PAGE_SIZE); for(page_index = 0; page_index < page_num; page_index++) { page_sva = gcbaseva + (BAMBOO_PAGE_SIZE) * page_index; - int block = 0; + unsigned int block = 0; BLOCKINDEX(page_sva, &block); int coren = gc_block2core[block%(NUMCORES4GC*2)]; tprintf("va: %x page_index: %d host: %d\n", @@ -2911,7 +2918,7 @@ void gc_output_cache_sampling_r() { unsigned int page_num = (BAMBOO_SHARED_MEM_SIZE) / (BAMBOO_PAGE_SIZE); for(page_index = 0; page_index < page_num; page_index++) { page_sva = gcbaseva + (BAMBOO_PAGE_SIZE) * page_index; - int block = 0; + unsigned int block = 0; BLOCKINDEX(page_sva, &block); int coren = gc_block2core[block%(NUMCORES4GC*2)]; tprintf("va: %x page_index: %d host: %d\n", @@ -3152,6 +3159,7 @@ inline void gc_nocollect(struct garbagelist * stackptr) { } // void gc_collect(struct garbagelist * stackptr) inline void gc_master(struct garbagelist * stackptr) { + tprintf("start GC !!!!!!!!!!!!! \n"); gcphase = INITPHASE; int i = 0; @@ -3245,7 +3253,7 @@ inline void gc_master(struct garbagelist * stackptr) { BAMBOO_EXIT(0xb006); } // predict number of blocks to fill for each core - int tmpheaptop = 0; + unsigned int tmpheaptop = 0; int numpbc = loadbalance(&tmpheaptop); // TODO numpbc = (BAMBOO_SHARED_MEM_SIZE)/(BAMBOO_SMEM_SIZE); @@ -3261,7 +3269,7 @@ inline void gc_master(struct garbagelist * stackptr) { GC_BAMBOO_DEBUGPRINT(0xabab); GC_BAMBOO_DEBUGPRINT_REG(tmptopptr); for(i = 0; i < NUMCORES4GC; ++i) { - int tmpcoreptr = 0; + unsigned int tmpcoreptr = 0; BASEPTR(i, numpbc, &tmpcoreptr); //send start compact messages to all cores //TODO bug here, do not know if the direction is positive or negtive? @@ -3304,7 +3312,7 @@ inline void gc_master(struct garbagelist * stackptr) { (struct moveHelper *)RUNMALLOC(sizeof(struct moveHelper)); initOrig_Dst(orig, to); int filledblocks = 0; - INTPTR heaptopptr = 0; + unsigned int heaptopptr = 0; bool finishcompact = false; bool iscontinue = true; bool localcompact = true; diff --git a/Robust/src/Runtime/bamboo/multicoregarbage.h b/Robust/src/Runtime/bamboo/multicoregarbage.h index d278939f..96a629ba 100644 --- a/Robust/src/Runtime/bamboo/multicoregarbage.h +++ b/Robust/src/Runtime/bamboo/multicoregarbage.h @@ -27,7 +27,7 @@ #ifdef GC_FLUSH_DTLB #define GC_NUM_FLUSH_DTLB 1 -int gc_num_flush_dtlb; +unsigned int gc_num_flush_dtlb; #endif #define NUMPTRS 100 @@ -44,11 +44,11 @@ int gc_num_flush_dtlb; typedef struct gc_info { unsigned long long time[GC_PROFILE_NUM_FIELD]; - int index; + unsigned int index; } GCInfo; GCInfo * gc_infoArray[GCINFOLENGTH]; -int gc_infoIndex; +unsigned int gc_infoIndex; bool gc_infoOverflow; unsigned long long gc_num_livespace; unsigned long long gc_num_freespace; @@ -58,7 +58,7 @@ unsigned int gc_num_lobj; unsigned int gc_num_liveobj; unsigned int gc_num_obj; unsigned int gc_num_forwardobj; -int gc_num_profiles; +unsigned int gc_num_profiles; #endif // GC_PROFILE @@ -92,42 +92,42 @@ volatile GCPHASETYPE gcphase; // indicating GC phase volatile bool gcpreinform; // counter for stopped cores volatile bool gcprecheck; // indicates if there are updated pregc information -int gccurr_heaptop; +unsigned int gccurr_heaptop; struct MGCHash * gcforwardobjtbl; // cache forwarded objs in mark phase // for mark phase termination -volatile int gccorestatus[NUMCORESACTIVE]; // records status of each core +volatile unsigned int gccorestatus[NUMCORESACTIVE];//records status of each core // 1: running gc // 0: stall -volatile int gcnumsendobjs[2][NUMCORESACTIVE]; // the # of objects sent out -volatile int gcnumreceiveobjs[2][NUMCORESACTIVE]; // the # of objects received -volatile int gcnumsrobjs_index; // indicates which entry to record the info - // received before phase 1 of the mark finish - // checking process - // the info received in phase 2 must be - // recorded in the other entry +volatile unsigned int gcnumsendobjs[2][NUMCORESACTIVE];//# of objects sent out +volatile unsigned int gcnumreceiveobjs[2][NUMCORESACTIVE];//# of objects received +volatile unsigned int gcnumsrobjs_index;//indicates which entry to record the info + // received before phase 1 of the mark finish + // checking process + // the info received in phase 2 must be + // recorded in the other entry volatile bool gcbusystatus; -int gcself_numsendobjs; -int gcself_numreceiveobjs; +unsigned int gcself_numsendobjs; +unsigned int gcself_numreceiveobjs; // for load balancing -INTPTR gcheaptop; -int gcloads[NUMCORES4GC]; -int gctopcore; // the core host the top of the heap -int gctopblock; // the number of current top block +unsigned int gcheaptop; +unsigned int gcloads[NUMCORES4GC]; +unsigned int gctopcore; // the core host the top of the heap +unsigned int gctopblock; // the number of current top block -int gcnumlobjs; +unsigned int gcnumlobjs; // compact instruction -INTPTR gcmarkedptrbound; -int gcblock2fill; -int gcstopblock[NUMCORES4GC]; // indicate when to stop compact phase -int gcfilledblocks[NUMCORES4GC]; //indicate how many blocks have been fulfilled +unsigned int gcmarkedptrbound; +unsigned int gcblock2fill; +unsigned int gcstopblock[NUMCORES4GC]; // indicate when to stop compact phase +unsigned int gcfilledblocks[NUMCORES4GC]; //indicate how many blocks have been fulfilled // move instruction; -INTPTR gcmovestartaddr; -int gcdstcore; +unsigned int gcmovestartaddr; +unsigned int gcdstcore; volatile bool gctomove; -int gcrequiredmems[NUMCORES4GC]; //record pending mem requests -volatile int gcmovepending; +unsigned int gcrequiredmems[NUMCORES4GC]; //record pending mem requests +volatile unsigned int gcmovepending; // shared memory pointer for pointer mapping tbls // In GC version, this block of memory is located at the bottom of the @@ -135,8 +135,8 @@ volatile int gcmovepending; // The bottom of the shared memory = sbstart tbl + smemtbl + bamboo_rmsp // These three types of table are always reside at the bottom of the shared // memory and will never be moved or garbage collected -INTPTR * gcmappingtbl; -int bamboo_rmsp_size; +unsigned int * gcmappingtbl; +unsigned int bamboo_rmsp_size; unsigned int bamboo_baseobjsize; // table recording the starting address of each small block @@ -144,12 +144,12 @@ unsigned int bamboo_baseobjsize; // Note: 1. this table always resides on the very bottom of the shared memory // 2. it is not counted in the shared heap, would never be garbage // collected -INTPTR * gcsbstarttbl; -int gcreservedsb; // number of reserved sblock for sbstarttbl -int gcnumblock; // number of total blocks in the shared mem -int gcbaseva; // base va for shared memory without reserved sblocks +int * gcsbstarttbl; +unsigned int gcreservedsb; // number of reserved sblock for sbstarttbl +unsigned int gcnumblock; // number of total blocks in the shared mem +unsigned int gcbaseva; // base va for shared memory without reserved sblocks #ifdef GC_CACHE_ADAPT -int gctopva; // top va for shared memory without reserved sblocks +unsigned int gctopva; // top va for shared memory without reserved sblocks volatile bool gccachestage; // table recording the sampling data collected for cache adaption unsigned int * gccachesamplingtbl; @@ -158,27 +158,27 @@ unsigned int size_cachesamplingtbl_local; unsigned int * gccachesamplingtbl_r; unsigned int * gccachesamplingtbl_local_r; unsigned int size_cachesamplingtbl_local_r; -int * gccachepolicytbl; +unsigned int * gccachepolicytbl; unsigned int size_cachepolicytbl; #endif // GC_CACHE_ADAPT -#define OBJMAPPINGINDEX(p) (((int)p-gcbaseva)/bamboo_baseobjsize) +#define OBJMAPPINGINDEX(p) (((unsigned int)p-gcbaseva)/bamboo_baseobjsize) #define ISSHAREDOBJ(p) \ - ((((int)p)>gcbaseva)&&(((int)p)<(gcbaseva+(BAMBOO_SHARED_MEM_SIZE)))) + ((((unsigned int)p)>gcbaseva)&&(((unsigned int)p)<(gcbaseva+(BAMBOO_SHARED_MEM_SIZE)))) #define ALIGNSIZE(s, as) \ - (*((int*)as)) = (((s) & (~(BAMBOO_CACHE_LINE_MASK))) + (BAMBOO_CACHE_LINE_SIZE)) + (*((unsigned int*)as)) = (((s) & (~(BAMBOO_CACHE_LINE_MASK))) + (BAMBOO_CACHE_LINE_SIZE)) // mapping of pointer to block # (start from 0), here the block # is // the global index #define BLOCKINDEX(p, b) \ { \ - int t = (p) - gcbaseva; \ + unsigned int t = (p) - gcbaseva; \ if(t < (BAMBOO_LARGE_SMEM_BOUND)) { \ - (*((int*)b)) = t / (BAMBOO_SMEM_SIZE_L); \ + (*((unsigned int*)b)) = t / (BAMBOO_SMEM_SIZE_L); \ } else { \ - (*((int*)b)) = NUMCORES4GC+((t-(BAMBOO_LARGE_SMEM_BOUND))/(BAMBOO_SMEM_SIZE)); \ + (*((unsigned int*)b)) = NUMCORES4GC+((t-(BAMBOO_LARGE_SMEM_BOUND))/(BAMBOO_SMEM_SIZE)); \ } \ } @@ -186,11 +186,11 @@ unsigned int size_cachepolicytbl; #define RESIDECORE(p, c) \ { \ if(1 == (NUMCORES4GC)) { \ - (*((int*)c)) = 0; \ + (*((unsigned int*)c)) = 0; \ } else { \ - int b; \ + unsigned int b; \ BLOCKINDEX((p), &b); \ - (*((int*)c)) = gc_block2core[(b%(NUMCORES4GC*2))]; \ + (*((unsigned int*)c)) = gc_block2core[(b%(NUMCORES4GC*2))]; \ } \ } @@ -201,16 +201,16 @@ unsigned int size_cachepolicytbl; // the local heap #define NUMBLOCKS(s, n) \ if(s < (BAMBOO_SMEM_SIZE_L)) { \ - (*((int*)(n))) = 0; \ + (*((unsigned int*)(n))) = 0; \ } else { \ - (*((int*)(n))) = 1 + ((s) - (BAMBOO_SMEM_SIZE_L)) / (BAMBOO_SMEM_SIZE); \ + (*((unsigned int*)(n))) = 1 + ((s) - (BAMBOO_SMEM_SIZE_L)) / (BAMBOO_SMEM_SIZE); \ } #define OFFSET(s, o) \ if(s < BAMBOO_SMEM_SIZE_L) { \ - (*((int*)(o))) = (s); \ + (*((unsigned int*)(o))) = (s); \ } else { \ - (*((int*)(o))) = ((s) - (BAMBOO_SMEM_SIZE_L)) % (BAMBOO_SMEM_SIZE); \ + (*((unsigned int*)(o))) = ((s) - (BAMBOO_SMEM_SIZE_L)) % (BAMBOO_SMEM_SIZE); \ } // mapping of (core #, index of the block) to the global block index @@ -219,11 +219,11 @@ unsigned int size_cachepolicytbl; // mapping of (core #, number of the block) to the base pointer of the block #define BASEPTR(c, n, p) \ { \ - int b = BLOCKINDEX2((c), (n)); \ + unsigned int b = BLOCKINDEX2((c), (n)); \ if(b < (NUMCORES4GC)) { \ - (*((int*)p)) = gcbaseva + b * (BAMBOO_SMEM_SIZE_L); \ + (*((unsigned int*)p)) = gcbaseva + b * (BAMBOO_SMEM_SIZE_L); \ } else { \ - (*((int*)p)) = gcbaseva+(BAMBOO_LARGE_SMEM_BOUND)+ \ + (*((unsigned int*)p)) = gcbaseva+(BAMBOO_LARGE_SMEM_BOUND)+ \ (b-(NUMCORES4GC))*(BAMBOO_SMEM_SIZE); \ } \ } @@ -236,14 +236,14 @@ inline void gc_collect(struct garbagelist* stackptr); //core collector routine inline void gc_nocollect(struct garbagelist* stackptr); //non-gc core collector routine inline void transferMarkResults_I(); inline void gc_enqueue_I(void *ptr); -inline void gc_lobjenqueue_I(void *ptr, int length, int host); -inline bool gcfindSpareMem_I(int * startaddr, - int * tomove, - int * dstcore, - int requiredmem, - int requiredcore); - -inline void * gc_lobjdequeue4(int * length, int * host); +inline void gc_lobjenqueue_I(void *ptr, unsigned int length, unsigned int host); +inline bool gcfindSpareMem_I(unsigned int * startaddr, + unsigned int * tomove, + unsigned int * dstcore, + unsigned int requiredmem, + unsigned int requiredcore); + +inline void * gc_lobjdequeue4(unsigned int * length, unsigned int * host); inline int gc_lobjmoreItems4(); inline void gc_lobjqueueinit4(); diff --git a/Robust/src/Runtime/bamboo/multicorehelper.h b/Robust/src/Runtime/bamboo/multicorehelper.h index 3519f5a7..2410552d 100644 --- a/Robust/src/Runtime/bamboo/multicorehelper.h +++ b/Robust/src/Runtime/bamboo/multicorehelper.h @@ -3,12 +3,12 @@ #ifdef GC_1 // NUMCORES4GC = 1 -static int gc_core2block[2] = {0,1}; +static unsigned int gc_core2block[2] = {0,1}; -static int gc_block2core[2] = { 0, 0}; +static unsigned int gc_block2core[2] = { 0, 0}; #elif defined GC_56 // NUMCORES4GC = 56 -static int gc_core2block[112] = { +static unsigned int gc_core2block[112] = { 0,111, 15, 96, 16,95, 31,80, 32,79, 47,64, 48,63, 1,110, 14, 97, 17,94, 30,81, 33,78, 46,65, 49,62, 2,109, 13, 98, 18,93, 29,82, 34,77, 45,66, 50,61, @@ -19,7 +19,7 @@ static int gc_core2block[112] = { 7,104, 8,103, 23,88, 24,87, 39,72, 40,71, 55,56 }; -static int gc_block2core[112] = { +static unsigned int gc_block2core[112] = { 0, 7, 14, 21, 28, 35, 42, 49, 50, 43, 36, 29, 22, 15, 8, 1, 2, 9, 16, 23, 30, 37, 44, 51, 52, 45, 38, 31, 24, 17, 10, 3, 4, 11, 18, 25, 32, 39, 46, 53, 54, 47, 40, 33, 26, 19, 12, 5, @@ -30,7 +30,7 @@ static int gc_block2core[112] = { }; #elif defined GC_62 // NUMCORES4GC = 62 -static int gc_core2block[124] = { +static unsigned int gc_core2block[124] = { 0,123, 15,108, 16,107, 31,92, 32,91, 47,76, 1,122, 14,109, 17,106, 30,93, 33,90, 46,77, 48,75, 61,62, 2,121, 13,110, 18,105, 29,94, 34,89, 45,78, 49,74, 60,63, @@ -41,7 +41,7 @@ static int gc_core2block[124] = { 7,116, 8,115, 23,100, 24,99, 39,84, 40,83, 54,69, 55,68 }; -static int gc_block2core[124] = { +static unsigned int gc_block2core[124] = { 0, 6, 14, 22, 30, 38, 46, 54, 55, 47, 39, 31, 23, 15, 7, 1, 2, 8, 16, 24, 32, 40, 48, 56, 57, 49, 41, 33, 25, 17, 9, 3, 4, 10, 18, 26, 34, 42, 50, 58, 59, 51, 43, 35, 27, 19, 11, 5, diff --git a/Robust/src/Runtime/bamboo/multicoremem.h b/Robust/src/Runtime/bamboo/multicoremem.h index b681d8e1..92ecd6a0 100644 --- a/Robust/src/Runtime/bamboo/multicoremem.h +++ b/Robust/src/Runtime/bamboo/multicoremem.h @@ -3,16 +3,6 @@ #include "Queue.h" #include "SimpleHash.h" -#ifndef INTPTR -#ifdef BIT64 -#define INTPTR long -#define INTPTRSHIFT 3 -#else -#define INTPTR int -#define INTPTRSHIFT 2 -#endif -#endif - #ifndef bool #define bool int #define true 1 @@ -38,58 +28,57 @@ #include "structdefs.h" #define BAMBOO_NUM_BLOCKS (NUMCORES4GC*(2+1)+3) #define BAMBOO_PAGE_SIZE (64 * 64) -#define BAMBOO_SMEM_SIZE (BAMBOO_PAGE_SIZE) -#define BAMBOO_SHARED_MEM_SIZE ((BAMBOO_SMEM_SIZE) *(BAMBOO_NUM_BLOCKS)) +#define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE)) +#define BAMBOO_SHARED_MEM_SIZE ((unsigned int)((BAMBOO_SMEM_SIZE) *(BAMBOO_NUM_BLOCKS))) #elif defined GC_CACHE_ADAPT #ifdef GC_LARGESHAREDHEAP -#define BAMBOO_NUM_BLOCKS ((GC_BAMBOO_NUMCORES)*(2+24)) +#define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(2+24))) #else -#define BAMBOO_NUM_BLOCKS ((GC_BAMBOO_NUMCORES)*(2+14)) +#define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(2+14))) #endif -#define BAMBOO_PAGE_SIZE (64 * 1024) // 64K +#define BAMBOO_PAGE_SIZE ((unsigned int)(64 * 1024)) // 64K #ifdef GC_LARGEPAGESIZE -#define BAMBOO_PAGE_SIZE (4 * 64 * 1024) -#define BAMBOO_SMEM_SIZE (4 * (BAMBOO_PAGE_SIZE)) +#define BAMBOO_PAGE_SIZE ((unsigned int)(4 * 64 * 1024)) +#define BAMBOO_SMEM_SIZE ((unsigned int)(4 * (BAMBOO_PAGE_SIZE))) #elif defined GC_SMALLPAGESIZE -#define BAMBOO_SMEM_SIZE (BAMBOO_PAGE_SIZE) +#define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE)) #elif defined GC_SMALLPAGESIZE2 -#define BAMBOO_PAGE_SIZE (16 * 1024) // (4096) -#define BAMBOO_SMEM_SIZE (BAMBOO_PAGE_SIZE) +#define BAMBOO_PAGE_SIZE ((unsigned int)(16 * 1024)) // (4096) +#define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE)) #elif defined GC_LARGEPAGESIZE2 -#define BAMBOO_PAGE_SIZE (4 * 64 * 1024) // 64K -#define BAMBOO_SMEM_SIZE ((BAMBOO_PAGE_SIZE)) +#define BAMBOO_PAGE_SIZE ((unsigned int)(4 * 64 * 1024)) // 64K +#define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE)) #else -#define BAMBOO_SMEM_SIZE (4 * (BAMBOO_PAGE_SIZE)) +#define BAMBOO_SMEM_SIZE ((unsigned int)(4 * (BAMBOO_PAGE_SIZE))) #endif // GC_LARGEPAGESIZE -#define BAMBOO_SHARED_MEM_SIZE ((BAMBOO_SMEM_SIZE) * (BAMBOO_NUM_BLOCKS)) +#define BAMBOO_SHARED_MEM_SIZE ((unsigned int)((BAMBOO_SMEM_SIZE) * (BAMBOO_NUM_BLOCKS))) #else // GC_DEBUG #ifdef GC_LARGESHAREDHEAP -#define BAMBOO_NUM_BLOCKS ((GC_BAMBOO_NUMCORES)*(2+2)) +#define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(2+2))) #elif defined GC_LARGESHAREDHEAP2 -#define BAMBOO_NUM_BLOCKS ((GC_BAMBOO_NUMCORES)*(2+2)) +#define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(2+2))) #else -#define BAMBOO_NUM_BLOCKS ((GC_BAMBOO_NUMCORES)*(2+30/*3*/)) //(15 * 1024) //(64 * 4 * 0.75) //(1024 * 1024 * 3.5) 3G +#define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(2+54/*3*/))) //(15 * 1024) //(64 * 4 * 0.75) //(1024 * 1024 * 3.5) 3G #endif #ifdef GC_LARGEPAGESIZE -#define BAMBOO_PAGE_SIZE (4 * 1024 * 1024) // (4096) -#define BAMBOO_SMEM_SIZE (BAMBOO_PAGE_SIZE) +#define BAMBOO_PAGE_SIZE ((unsigned int)(4 * 1024 * 1024)) // (4096) +#define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE)) #elif defined GC_SMALLPAGESIZE -#define BAMBOO_PAGE_SIZE (256 * 1024) // (4096) -#define BAMBOO_SMEM_SIZE (BAMBOO_PAGE_SIZE) +#define BAMBOO_PAGE_SIZE ((unsigned int)(256 * 1024)) // (4096) +#define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE)) #elif defined GC_SMALLPAGESIZE2 -#define BAMBOO_PAGE_SIZE (64 * 1024) // (4096) -#define BAMBOO_SMEM_SIZE (BAMBOO_PAGE_SIZE) +#define BAMBOO_PAGE_SIZE ((unsigned int)(64 * 1024)) // (4096) +#define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE)) #else -#define BAMBOO_PAGE_SIZE (1024 * 1024) // (4096) -#define BAMBOO_SMEM_SIZE (BAMBOO_PAGE_SIZE) +#define BAMBOO_PAGE_SIZE ((unsigned int)(1024 * 1024)) // (4096) +#define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE)) #endif // GC_LARGEPAGESIZE -#define BAMBOO_SHARED_MEM_SIZE ((BAMBOO_SMEM_SIZE) * (BAMBOO_NUM_BLOCKS)) //(1024 * 1024 * 240) //((unsigned long long int)(3.0 * 1024 * 1024 * 1024)) // 3G +#define BAMBOO_SHARED_MEM_SIZE ((unsigned int)((BAMBOO_SMEM_SIZE) * (BAMBOO_NUM_BLOCKS))) //(1024 * 1024 * 240) //((unsigned long long int)(3.0 * 1024 * 1024 * 1024)) // 3G #endif // GC_DEBUG #ifdef MULTICORE_GC -volatile bool gc_localheap_s; #include "multicoregarbage.h" typedef enum { @@ -105,7 +94,7 @@ SMEMSTRATEGY bamboo_smem_mode; //-DSMEML: LOCAL; -DSMEMF: FIXED; //-DSMEMM: MIXED; -DSMEMG: GLOBAL; struct freeMemItem { - INTPTR ptr; + unsigned int ptr; int size; int startblock; int endblock; @@ -121,20 +110,20 @@ struct freeMemList { // table recording the number of allocated bytes on each block // Note: this table resides on the bottom of the shared heap for all cores // to access -volatile int * bamboo_smemtbl; -volatile int bamboo_free_block; +volatile unsigned int * bamboo_smemtbl; +volatile unsigned int bamboo_free_block; unsigned int bamboo_reserved_smem; // reserved blocks on the top of the shared // heap e.g. 20% of the heap and should not // be allocated otherwise gc is invoked -volatile INTPTR bamboo_smem_zero_top; -#define BAMBOO_SMEM_ZERO_UNIT_SIZE (4 * 1024) // 4KB +volatile unsigned int bamboo_smem_zero_top; +#define BAMBOO_SMEM_ZERO_UNIT_SIZE ((unsigned int)(4 * 1024)) // 4KB #else //volatile mspace bamboo_free_msp; -INTPTR bamboo_free_smemp; +unsigned int bamboo_free_smemp; int bamboo_free_smem_size; #endif // MULTICORE_GC volatile bool smemflag; -volatile INTPTR bamboo_cur_msp; +volatile unsigned int bamboo_cur_msp; volatile int bamboo_smem_size; #endif diff --git a/Robust/src/Runtime/bamboo/multicoreruntime.c b/Robust/src/Runtime/bamboo/multicoreruntime.c index 4467e88d..862b2962 100644 --- a/Robust/src/Runtime/bamboo/multicoreruntime.c +++ b/Robust/src/Runtime/bamboo/multicoreruntime.c @@ -401,13 +401,13 @@ struct ___String___ * NewString(const char *str,int length) { /* Generated code calls this if we fail a bounds check */ -void failedboundschk() { +void failedboundschk(int num) { #ifndef TASK printf("Array out of bounds\n"); #ifdef THREADS threadexit(); #elif defined MGC - BAMBOO_EXIT(0xa002); + BAMBOO_EXIT(0xa0000000 + num); #else exit(-1); #endif @@ -416,7 +416,52 @@ void failedboundschk() { printf("Array out of bounds\n"); longjmp(error_handler,2); #else - BAMBOO_EXIT(0xa002); + BAMBOO_EXIT(0xa0000000 + num); +#endif +#endif +} + +/* Generated code calls this if we fail null ptr chk */ +void failednullptr(void * ptr) { +#ifdef MULTICORE_GC +#ifndef RAW + //print out current stack + int i,j; + j = 0; + struct garbagelist * stackptr = (struct garbagelist *)ptr; + while(stackptr!=NULL) { + GC_BAMBOO_DEBUGPRINT(0xa501); + GC_BAMBOO_DEBUGPRINT_REG(stackptr->size); + GC_BAMBOO_DEBUGPRINT_REG(stackptr->next); + GC_BAMBOO_DEBUGPRINT_REG(stackptr->array[0]); + tprintf("Stack %d: \n\t", j); + for(i=0; isize; i++) { + if(stackptr->array[i] != NULL) { + tprintf("%x, ", stackptr->array[i]); + } else { + tprintf("NULL, "); + } + } + tprintf("\n"); + stackptr=stackptr->next; + } +#endif +#endif +#ifndef TASK + printf("NULL ptr\n"); +#ifdef THREADS + threadexit(); +#elif defined MGC + BAMBOO_EXIT(0xa001); +#else + exit(-1); +#endif +#else +#ifndef MULTICORE + printf("NULL ptr\n"); + longjmp(error_handler,2); +#else + BAMBOO_EXIT(0xa001); #endif #endif } @@ -530,7 +575,7 @@ INLINE void initruntimedata() { #ifdef GC_FLUSH_DTLB gc_num_flush_dtlb = 0; #endif - gc_localheap_s = false; + //gc_localheap_s = false; #ifdef GC_CACHE_ADAPT gccachestage = false; #endif // GC_CACHE_ADAPT diff --git a/Robust/src/Runtime/mem.c b/Robust/src/Runtime/mem.c index 8844c358..d5d194c7 100644 --- a/Robust/src/Runtime/mem.c +++ b/Robust/src/Runtime/mem.c @@ -61,21 +61,8 @@ void * mycalloc(int m, void * p = NULL; int isize = size; BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT(); -#ifdef MULTICORE_GC - extern bool gc_localheap_s; -inermycalloc_i: - p = gc_localheap_s ? BAMBOO_LOCAL_MEM_CALLOC_S(m, isize) : - BAMBOO_LOCAL_MEM_CALLOC(m, isize); -#else p = BAMBOO_LOCAL_MEM_CALLOC(m, isize); // calloc(m, isize); -#endif if(p == NULL) { -#ifdef MULTICORE_GC - if(!gc_localheap_s) { - gc_localheap_s = true; - goto inermycalloc_i; - } -#endif BAMBOO_EXIT(0xc001); } BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME(); @@ -87,36 +74,15 @@ void * mycalloc_i(int m, int size) { void * p = NULL; int isize = size; -#ifdef MULTICORE_GC - extern bool gc_localheap_s; -inermycalloc_i: - p = gc_localheap_s ? BAMBOO_LOCAL_MEM_CALLOC_S(m, isize) : - BAMBOO_LOCAL_MEM_CALLOC(m, isize); -#else p = BAMBOO_LOCAL_MEM_CALLOC(m, isize); // calloc(m, isize); -#endif if(p == NULL) { -#ifdef MULTICORE_GC - if(!gc_localheap_s) { - gc_localheap_s = true; - goto inermycalloc_i; - } -#endif BAMBOO_EXIT(0xc004); } return p; } void myfree(void * ptr) { -#ifdef MULTICORE_GC - if(ptr >= BAMBOO_LOCAL_HEAP_START_VA ) { -#endif - BAMBOO_LOCAL_MEM_FREE(ptr); -#ifdef MULTICORE_GC - } else if(ptr >= BAMBOO_LOCAL_HEAP_START_VA_S) { - BAMBOO_LOCAL_MEM_FREE_S(ptr); - } -#endif + BAMBOO_LOCAL_MEM_FREE(ptr); return; } diff --git a/Robust/src/Runtime/runtime.c b/Robust/src/Runtime/runtime.c index c8b1ac5a..8dabb783 100644 --- a/Robust/src/Runtime/runtime.c +++ b/Robust/src/Runtime/runtime.c @@ -852,7 +852,7 @@ __attribute__((malloc)) struct ___String___ * NewString(const char *str,int leng /* Generated code calls this if we fail a bounds check */ -void failedboundschk() { +void failedboundschk(int num) { #ifndef TASK printf("Array out of bounds\n"); #ifdef THREADS diff --git a/Robust/src/Runtime/runtime.h b/Robust/src/Runtime/runtime.h index 291244b3..18bf17de 100644 --- a/Robust/src/Runtime/runtime.h +++ b/Robust/src/Runtime/runtime.h @@ -96,8 +96,8 @@ __attribute__((malloc)) struct ___TagDescriptor___ * allocate_tag(int index); void initializeexithandler(); -void failedboundschk(); -void failednullptr(); +void failedboundschk(int num); +void failednullptr(void * stackptr); void abort_task(); void injectinstructionfailure(); #ifdef MULTICORE -- 2.34.1