From 80b72eb420403cc566740b76a7036f4fc55fb2d4 Mon Sep 17 00:00:00 2001 From: jzhou Date: Fri, 4 Sep 2009 00:54:38 +0000 Subject: [PATCH] bug fixes in multicore gc --- Robust/src/IR/ClassDescriptor.java | 2 +- Robust/src/IR/Flat/BuildCode.java | 27 +++++-- Robust/src/IR/Flat/BuildCodeMultiCore.java | 3 +- Robust/src/IR/State.java | 2 +- Robust/src/Runtime/multicoregarbage.c | 89 +++++++++++++++++----- Robust/src/Runtime/multicoreruntime.h | 18 ++--- Robust/src/Runtime/multicoretask.c | 21 ++--- 7 files changed, 112 insertions(+), 50 deletions(-) diff --git a/Robust/src/IR/ClassDescriptor.java b/Robust/src/IR/ClassDescriptor.java index d86e115c..ffae5094 100644 --- a/Robust/src/IR/ClassDescriptor.java +++ b/Robust/src/IR/ClassDescriptor.java @@ -3,7 +3,7 @@ import java.util.*; import IR.Tree.*; public class ClassDescriptor extends Descriptor { - private static int UIDCount=0; + private static int UIDCount=1; // start from 1 instead of 0 for multicore gc private final int classid; String superclass; ClassDescriptor superdesc; diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 9c24aa68..0cb950ff 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -913,6 +913,7 @@ public class BuildCode { Iterator it=state.getClassSymbolTable().getDescriptorsIterator(); cdarray=new ClassDescriptor[state.numClasses()]; + cdarray[0] = null; while(it.hasNext()) { ClassDescriptor cd=(ClassDescriptor)it.next(); cdarray[cd.getId()]=cd; @@ -933,7 +934,11 @@ public class BuildCode { outclassdefs.println("/* "); for(int i=0; i0) { + outclassdefs.print("sizeof(struct "+cdarray[i].getSafeSymbol()+")"); + } else { + outclassdefs.print("0"); + } needcomma=true; } @@ -973,7 +982,7 @@ public class BuildCode { outclassdefs.print("int typearray[]={"); for(int i=0; i0?cd.getSuperDesc():null; if (needcomma) outclassdefs.print(", "); if (supercd==null) @@ -1174,7 +1183,11 @@ public class BuildCode { if (needcomma) output.println(","); needcomma=true; - output.print(cn.getSafeSymbol()+"_pointers"); + if(cn != null) { + output.print(cn.getSafeSymbol()+"_pointers"); + } else { + output.print("NULL"); + } } for(int i=0; i0) output.print(", "); - if (processedcd.contains(cn)) + if ((cn != null) && (processedcd.contains(cn))) output.print("&classanalysiswrapper_"+cn.getSafeSymbol()); else output.print("NULL"); diff --git a/Robust/src/IR/Flat/BuildCodeMultiCore.java b/Robust/src/IR/Flat/BuildCodeMultiCore.java index 6ea7dc37..844b2592 100644 --- a/Robust/src/IR/Flat/BuildCodeMultiCore.java +++ b/Robust/src/IR/Flat/BuildCodeMultiCore.java @@ -143,9 +143,8 @@ public class BuildCodeMultiCore extends BuildCode { // Output function prototypes and structures for parameters Iterator it=state.getClassSymbolTable().getDescriptorsIterator(); - int numclasses = 0; + int numclasses = this.state.numClasses(); while(it.hasNext()) { - ++numclasses; ClassDescriptor cn=(ClassDescriptor)it.next(); super.generateCallStructs(cn, outclassdefs, outstructs, outmethodheader); } diff --git a/Robust/src/IR/State.java b/Robust/src/IR/State.java index b835f102..e4cba351 100644 --- a/Robust/src/IR/State.java +++ b/Robust/src/IR/State.java @@ -104,7 +104,7 @@ public class State { public Hashtable flatmethodmap; private HashSet arraytypes; public Hashtable arraytonumber; - private int numclasses=0; + private int numclasses=1; // start from 1 instead of 0 for multicore gc private int numtasks=0; private int arraycount=0; public boolean OPTIMIZE=false; diff --git a/Robust/src/Runtime/multicoregarbage.c b/Robust/src/Runtime/multicoregarbage.c index f834eb55..fb8d743a 100644 --- a/Robust/src/Runtime/multicoregarbage.c +++ b/Robust/src/Runtime/multicoregarbage.c @@ -616,7 +616,7 @@ inline bool cacheLObjs() { // check the total mem size need for large objs int sumsize = 0; int size = 0; -#ifdef DEBUG +#ifdef GC_DEBUG BAMBOO_DEBUGPRINT(0xe801); #endif gclobjtail2 = gclobjtail; @@ -625,7 +625,8 @@ inline bool cacheLObjs() { gc_lobjdequeue2(); size = gclobjtail2->lengths[gclobjtailindex2 - 1]; sumsize += size; -#ifdef DEBUG +#ifdef GC_DEBUG + BAMBOO_DEBUGPRINT_REG(gclobjtail2->lobjs[gclobjtailindex2-1]); BAMBOO_DEBUGPRINT_REG(size); BAMBOO_DEBUGPRINT_REG(sumsize); #endif @@ -637,7 +638,7 @@ inline bool cacheLObjs() { // do not have enough room to cache large objs return false; } -#ifdef DEBUG +#ifdef GC_DEBUG BAMBOO_DEBUGPRINT(0xe802); BAMBOO_DEBUGPRINT_REG(dst); #endif @@ -651,9 +652,11 @@ inline bool cacheLObjs() { size = gclobjtail2->lengths[gclobjtailindex2 - 1]; // set the mark field to 2, indicating that this obj has been moved and need to be flushed ((int *)(gclobjtail2->lobjs[gclobjtailindex2-1]))[6] = 2; + // TODO + BAMBOO_DEBUGPRINT(0xdcdc); memcpy(dst, gclobjtail2->lobjs[gclobjtailindex2 - 1], size); dst += size; -#ifdef DEBUG +#ifdef GC_DEBUG BAMBOO_DEBUGPRINT_REG(gclobjtail2->lobjs[gclobjtailindex2-1]); BAMBOO_DEBUGPRINT(dst-size); BAMBOO_DEBUGPRINT_REG(size); @@ -805,7 +808,7 @@ inline void moveLObjs() { #endif } tochange->ptr = tmpheaptop; - tochange->size = BAMBOO_SHARED_MEM_SIZE + BAMBOO_BASE_VA - tmpheaptop; + tochange->size = gcheaptop - tmpheaptop; // zero out all these spare memory memset(tochange->ptr, '\0', tochange->size); if(bamboo_free_mem_list->tail != tochange) { @@ -822,6 +825,8 @@ inline void moveLObjs() { #ifdef DEBUG BAMBOO_DEBUGPRINT(0xea02); BAMBOO_DEBUGPRINT_REG(tomove); + BAMBOO_DEBUGPRINT_REG(tmpheaptop); + BAMBOO_DEBUGPRINT_REG(gcheaptop); #endif // flush the sbstartbl memset(&(gcsbstarttbl[gcreservedsb]), '\0', @@ -874,6 +879,8 @@ inline void moveLObjs() { memcpy(tmpheaptop, gcheaptop, size); // fill the remaining space with -2 padding memset(tmpheaptop+size, -2, isize-size); + // zero out original mem caching the lobj + memset(gcheaptop, '\0', size); #ifdef DEBUG BAMBOO_DEBUGPRINT(0xea04); BAMBOO_DEBUGPRINT_REG(gcheaptop); @@ -971,8 +978,8 @@ inline void moveLObjs() { } gcheaptop = tmpheaptop; // update the free mem list - tochange->size -= tmpheaptop-tochange->ptr; - tochange->ptr = tmpheaptop; + tochange->size = (BAMBOO_BASE_VA)+(BAMBOO_SHARED_MEM_SIZE)-gcheaptop; + tochange->ptr = gcheaptop; #ifdef DEBUG BAMBOO_DEBUGPRINT(0xea06); BAMBOO_DEBUGPRINT_REG(gcheaptop); @@ -1182,6 +1189,10 @@ inline void mark(bool isfirst, // ptr is a large object if(((int *)ptr)[6] == 0) { // not marked and not enqueued +#ifdef GC_DEBUG + BAMBOO_DEBUGPRINT(0xecec); + BAMBOO_DEBUGPRINT_REG(ptr); +#endif BAMBOO_START_CRITICAL_SECTION(); gc_lobjenqueue_I(ptr, size, BAMBOO_NUM_OF_CORE); gcnumlobjs++; @@ -1558,27 +1569,55 @@ struct moveHelper { inline void nextSBlock(struct moveHelper * orig) { orig->blockbase = orig->blockbound; +#ifdef GC_DEBUG + BAMBOO_DEBUGPRINT(0xecc0); + BAMBOO_DEBUGPRINT_REG(orig->blockbase); + BAMBOO_DEBUGPRINT_REG(orig->blockbound); + BAMBOO_DEBUGPRINT_REG(orig->bound); + BAMBOO_DEBUGPRINT_REG(orig->ptr); +#endif + if((orig->blockbase >= orig->bound) || (orig->ptr >= orig->bound) + || ((*((int*)orig->ptr))==0) || ((*((int*)orig->blockbase))==0)) { innernextSBlock: - if(orig->blockbase >= orig->bound) { // end of current heap block, jump to next one orig->numblocks++; +#ifdef GC_DEBUG + BAMBOO_DEBUGPRINT(0xecc1); + BAMBOO_DEBUGPRINT_REG(orig->numblocks); +#endif BASEPTR(BAMBOO_NUM_OF_CORE, orig->numblocks, &(orig->base)); +#ifdef DEBUG + BAMBOO_DEBUGPRINT(orig->base); +#endif orig->bound = orig->base + BAMBOO_SMEM_SIZE; orig->blockbase = orig->base; - } - orig->sblockindex = (orig->blockbase-BAMBOO_BASE_VA)/BAMBOO_SMEM_SIZE; - if(gcsbstarttbl[orig->sblockindex] == -1) { - // goto next sblock - orig->sblockindex += 1; - orig->blockbase += BAMBOO_SMEM_SIZE; - goto innernextSBlock; - } else if(gcsbstarttbl[orig->sblockindex] != 0) { - // not start from the very beginning - orig->blockbase = gcsbstarttbl[orig->sblockindex]; + orig->sblockindex = (orig->blockbase-BAMBOO_BASE_VA)/BAMBOO_SMEM_SIZE; + if(gcsbstarttbl[orig->sblockindex] == -1) { + // goto next sblock +#ifdef DEBUG + BAMBOO_DEBUGPRINT(0xecc2); +#endif + orig->sblockindex += 1; + orig->blockbase += BAMBOO_SMEM_SIZE; + goto innernextSBlock; + } else if(gcsbstarttbl[orig->sblockindex] != 0) { + // not start from the very beginning + orig->blockbase = gcsbstarttbl[orig->sblockindex]; + } } orig->blockbound = orig->blockbase + *((int*)(orig->blockbase)); orig->offset = BAMBOO_CACHE_LINE_SIZE; orig->ptr = orig->blockbase + orig->offset; +#ifdef GC_DEBUG + BAMBOO_DEBUGPRINT(0xecc3); + BAMBOO_DEBUGPRINT_REG(orig->base); + BAMBOO_DEBUGPRINT_REG(orig->bound); + BAMBOO_DEBUGPRINT_REG(orig->ptr); +#endif + if(orig->ptr >= orig->bound) { + // met a lobj, move to next block + goto innernextSBlock; + } } // void nextSBlock(struct moveHelper * orig) inline void initOrig_Dst(struct moveHelper * orig, @@ -1685,7 +1724,7 @@ innermoveobj: // check the obj's type, size and mark flag type = ((int *)(orig->ptr))[0]; size = 0; - if(type == -1) { + if(type == 0) { // end of this block, go to next one nextSBlock(orig); goto innermoveobj; @@ -1712,9 +1751,9 @@ innermoveobj: ALIGNSIZE(size, &isize); if(to->top + isize > to->bound) { // fill -1 indicating the end of this block - if(to->top != to->bound) { + /*if(to->top != to->bound) { *((int*)to->ptr) = -1; - } + }*/ //memset(to->ptr+1, -2, to->bound - to->top - 1); // fill the header of this block and then go to next block to->offset += to->bound - to->top; @@ -1748,6 +1787,12 @@ innermoveobj: to->ptr += isize; to->offset += isize; to->top += isize; + if(to->top == to->bound) { + // fill the header of this block and then go to next block + memset(to->base, '\0', BAMBOO_CACHE_LINE_SIZE); + (*((int*)(to->base))) = to->offset; + nextBlock(to); + } } // if(mark == 1) #ifdef DEBUG BAMBOO_DEBUGPRINT(0xe205); @@ -1757,6 +1802,7 @@ innermoveobj: #ifdef DEBUG BAMBOO_DEBUGPRINT_REG(isize); BAMBOO_DEBUGPRINT_REG(orig->ptr); + BAMBOO_DEBUGPRINT_REG(orig->bound); #endif if((orig->ptr > orig->bound) || (orig->ptr == orig->blockbound)) { #ifdef DEBUG @@ -1904,6 +1950,7 @@ innercompact: } else { #ifdef DEBUG BAMBOO_DEBUGPRINT(0xe108); + BAMBOO_DEBUGPRINT_REG(*heaptopptr); #endif // finish compacting send_msg_5(STARTUPCORE, GCFINISHCOMPACT, BAMBOO_NUM_OF_CORE, diff --git a/Robust/src/Runtime/multicoreruntime.h b/Robust/src/Runtime/multicoreruntime.h index 4d04f388..5a7f861e 100644 --- a/Robust/src/Runtime/multicoreruntime.h +++ b/Robust/src/Runtime/multicoreruntime.h @@ -181,8 +181,8 @@ int corestatus[NUMCORES]; // records status of each core // 0: stall int numsendobjs[NUMCORES]; // records how many objects a core has sent out int numreceiveobjs[NUMCORES]; // records how many objects a core has received -int numconfirm; -bool waitconfirm; +volatile int numconfirm; +volatile bool waitconfirm; bool busystatus; int self_numsendobjs; int self_numreceiveobjs; @@ -237,15 +237,15 @@ struct freeMemList { struct freeMemItem * tail; }; -bool smemflag; +volatile bool smemflag; struct freeMemList * bamboo_free_mem_list; -INTPTR bamboo_cur_msp; -int bamboo_smem_size; +volatile INTPTR bamboo_cur_msp; +volatile int bamboo_smem_size; #else -bool smemflag; -mspace bamboo_free_msp; -INTPTR bamboo_cur_msp; -int bamboo_smem_size; +volatile bool smemflag; +volatile mspace bamboo_free_msp; +volatile INTPTR bamboo_cur_msp; +volatile int bamboo_smem_size; #endif // for test TODO diff --git a/Robust/src/Runtime/multicoretask.c b/Robust/src/Runtime/multicoretask.c index 355f03d4..9513f49f 100644 --- a/Robust/src/Runtime/multicoretask.c +++ b/Robust/src/Runtime/multicoretask.c @@ -1165,7 +1165,9 @@ inline void addNewObjInfo(void * nobj) { void * smemalloc(int size, int * allocsize) { void * mem = NULL; - int isize = size; + int isize = size+(BAMBOO_CACHE_LINE_SIZE); + int toallocate = ((size+(BAMBOO_CACHE_LINE_SIZE))>(BAMBOO_SMEM_SIZE)) ? + (size+(BAMBOO_CACHE_LINE_SIZE)):(BAMBOO_SMEM_SIZE); #ifdef MULTICORE_GC // go through free mem list for suitable blocks struct freeMemItem * freemem = bamboo_free_mem_list->head; @@ -1189,14 +1191,13 @@ void * smemalloc(int size, remain = bound - remain%bound; if(remain < isize) { // this object acrosses blocks - // try to align the block if required a block - if((isize == BAMBOO_SMEM_SIZE) && (freemem->size >= isize + remain)) { - isize += remain; - } + *allocsize = isize; + } else { + // round the asigned block to the end of the current block + *allocsize = remain; } - *allocsize = isize; - freemem->ptr = ((void*)freemem->ptr) + isize; - freemem->size -= isize; + freemem->ptr = ((void*)freemem->ptr) + (*allocsize); + freemem->size -= *allocsize; } else { #else mem = mspace_calloc(bamboo_free_msp, 1, isize); @@ -1971,7 +1972,9 @@ msg: } // large obj info here for(int k = 5; k < msgdata[1];) { - gc_lobjenqueue_I(msgdata[k++], msgdata[k++], cnum); + int lobj = msgdata[k++]; + int length = msgdata[k++]; + gc_lobjenqueue_I(lobj, length, cnum); gcnumlobjs++; } // for(int k = 5; k < msgdata[1];) break; -- 2.34.1