bug fixes in multicore gc
authorjzhou <jzhou>
Fri, 4 Sep 2009 00:54:38 +0000 (00:54 +0000)
committerjzhou <jzhou>
Fri, 4 Sep 2009 00:54:38 +0000 (00:54 +0000)
Robust/src/IR/ClassDescriptor.java
Robust/src/IR/Flat/BuildCode.java
Robust/src/IR/Flat/BuildCodeMultiCore.java
Robust/src/IR/State.java
Robust/src/Runtime/multicoregarbage.c
Robust/src/Runtime/multicoreruntime.h
Robust/src/Runtime/multicoretask.c

index d86e115cddcaf9e8b786548c0720488797de665b..ffae50948e25b34c3e9c113cbe69a5a16eafdad8 100644 (file)
@@ -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;
index 9c24aa680a3ee83ca2c5645a87da79b704fdfac0..0cb950ffe2f1a7bd88d03f129afada7b00d7251d 100644 (file)
@@ -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; i<state.numClasses(); i++) {
       ClassDescriptor cd=cdarray[i];
-      outclassdefs.println(cd +"  "+i);
+      if(cd == null) {
+        outclassdefs.println("NULL " + i);
+      } else {
+        outclassdefs.println(cd +"  "+i);
+      }
     }
 
     for(int i=0; i<state.numArrays(); i++) {
@@ -950,7 +955,11 @@ public class BuildCode {
     for(int i=0; i<state.numClasses(); i++) {
       if (needcomma)
        outclassdefs.print(", ");
-      outclassdefs.print("sizeof(struct "+cdarray[i].getSafeSymbol()+")");
+      if(i>0) {
+        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; i<state.numClasses(); i++) {
       ClassDescriptor cd=cdarray[i];
-      ClassDescriptor supercd=cd.getSuperDesc();
+      ClassDescriptor supercd=i>0?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; i<state.numArrays(); i++) {
@@ -1196,7 +1209,7 @@ public class BuildCode {
       if (needcomma)
        output.println(", ");
       needcomma=true;
-      if (cn.hasFlags())
+      if ((cn != null) && (cn.hasFlags()))
        output.print("1");
       else
        output.print("0");
@@ -1213,7 +1226,7 @@ public class BuildCode {
       if (needcomma)
        output.println(",");
       needcomma=true;
-      if (cn.getSuperDesc()!=null) {
+      if ((cn != null) && (cn.getSuperDesc()!=null)) {
        ClassDescriptor cdsuper=cn.getSuperDesc();
        output.print(cdsuper.getId());
       } else
@@ -4438,7 +4451,7 @@ public class BuildCode {
       ClassDescriptor cn=cdarray[i];
       if (i>0)
        output.print(", ");
-      if (processedcd.contains(cn))
+      if ((cn != null) && (processedcd.contains(cn)))
        output.print("&classanalysiswrapper_"+cn.getSafeSymbol());
       else
        output.print("NULL");
index 6ea7dc37055db294892751558646384f2b8f95f6..844b2592fbb06f0f1145d71cfc2302071ca40402 100644 (file)
@@ -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);
     }
index b835f1021c94e8bffcb74fadda9b134074cf4520..e4cba35185f05ad8bfbf07b6fdafaeac00782863 100644 (file)
@@ -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;
index f834eb554b607c660adb0feaf79add4e2561a941..fb8d743a673f25fee8880c69fdd14edc76f3b122 100644 (file)
@@ -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,
index 4d04f388a307cc6f9f2d49f1e583159fb721d19e..5a7f861ecf236fe92c96c23a8f3ab2d8d8f428cc 100644 (file)
@@ -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
index 355f03d4772524e3830e10a0e721b3dca7d4586f..9513f49f37c5c239022b1b4205b40a4a16ee6f1c 100644 (file)
@@ -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;