lots of bug fixes...none of them the right one
authorbdemsky <bdemsky>
Sat, 2 Jul 2011 00:29:12 +0000 (00:29 +0000)
committerbdemsky <bdemsky>
Sat, 2 Jul 2011 00:29:12 +0000 (00:29 +0000)
Robust/src/Runtime/bamboo/multicoregarbage.c
Robust/src/Runtime/bamboo/multicoregarbage.h
Robust/src/Runtime/bamboo/multicoregccompact.c
Robust/src/Runtime/bamboo/multicoregcflush.c
Robust/src/Runtime/bamboo/multicoregcmark.c
Robust/src/Runtime/bamboo/multicoremem.c
Robust/src/Runtime/bamboo/multicoremem.h
Robust/src/Runtime/bamboo/multicoremem_helper.c
Robust/src/Runtime/bamboo/multicoremsg.c
Robust/src/Runtime/bamboo/multicoreruntime.c

index c161539d3a23de89628bbcd5c558aa77fbafff96..ef73a360c24b4015aaef099abf22956c4609d503 100644 (file)
@@ -417,7 +417,7 @@ void master_finish() {
 }
 
 void gc_master(struct garbagelist * stackptr) {
-  tprintf("start GC!\n");
+  //tprintf("start GC!\n");
   gc_status_info.gcprocessing = true;
   gc_status_info.gcphase = INITPHASE;
 
@@ -449,6 +449,12 @@ void gc_master(struct garbagelist * stackptr) {
   CACHEADAPT_PHASE_MASTER();
   //tprintf("finish cachdapt phase\n");
   // do finish up stuff
+#ifdef GC_DEBUG
+  for(int i=0;i<GCNUMBLOCK;i++) {
+    struct blockrecord *record=&allocationinfo.blocktable[i];
+    tprintf("%u. used=%u free=%u corenum=%u status=%u, base=%x, ptr=%x\n", i, record->usedspace, record->freespace, record->corenum, record->status, gcbaseva+OFFSET2BASEVA(i), (gcbaseva+OFFSET2BASEVA(i)+record->usedspace));
+  }
+#endif
   master_finish();
 
   //tprintf("finish GC ! %d \n",gcflag);
index 6218cb0c8bb06ceedab542a3115578b994273673..aac5bebd0aa3af6a13c9c81a3ec74e8f221465a8 100644 (file)
@@ -182,6 +182,8 @@ unsigned int size_cachepolicytbl;
 
 #define MINMEMORYCHUNKSIZE 32768
 
+#define ISVALIDPTR(x) ((((unsigned INTPTR)x)>=((unsigned INTPTR)gcbaseva))&&(((unsigned INTPTR)x)<((unsigned INTPTR)(gcbaseva+BAMBOO_SHARED_MEM_SIZE))))
+
 /* This macro waits for the given gc phase */
 #define WAITFORGCPHASE(phase) while(gc_status_info.gcphase != phase) ;
 
index 8cda2b36a46d56cd10617f358246138d21f15e35..18e3bf8f954b0b5386cea62d68223dd965c7a5a7 100644 (file)
@@ -5,6 +5,7 @@
 #include "multicoregarbage.h"
 #include "markbit.h"
 #include "multicoremem_helper.h"
+#include "gcqueue.h"
 
 int gc_countRunningCores() {
   int count=0;
@@ -58,6 +59,7 @@ void handleReturnMem_I(unsigned int cnum, void *heaptop) {
   }
 
   /* This is our own block...means we should mark other blocks above us as free*/
+  
   if (cnum==blockrecord->corenum) {
     unsigned INTPTR nextlocalblocknum=localblocknum+1;
     for(;nextlocalblocknum<numblockspercore;nextlocalblocknum++) {
@@ -183,6 +185,7 @@ void compacthelper(struct moveHelper * orig,struct moveHelper * to) {
       senttopmessage=true;
     }
     unsigned int minimumbytes=compactblocks(orig, to);
+
     if (orig->ptr==orig->bound) {
       //need more data to compact
       //increment the core
@@ -272,6 +275,10 @@ void handleOneMemoryRequest(int core, unsigned int lowestblock) {
     if (block->status==BS_FREE) {
       if(firstfree==NOFREEBLOCK)
        firstfree=searchblock;
+      //don't take a block from another core that hasn't returned its memory yet
+      if (block->corenum!=core&&returnedmem[block->corenum])
+       continue;
+      
       unsigned INTPTR freespace=block->freespace&~BAMBOO_CACHE_LINE_MASK;
       if (freespace>=memcheck) {
        //TODO: should check memory block at same level on our own core...if that works, use it to preserve locality
@@ -427,7 +434,6 @@ void compact() {
   initOrig_Dst(&orig, &to);
 
   CACHEADAPT_SAMPLING_DATA_REVISE_INIT(&orig, &to);
-
   compacthelper(&orig, &to);
 } 
 
index df4a978e508c9b28549b67d4e7d290710b70bc40..cd336e739b93a41b6833a170127347cc7e4d9f74 100644 (file)
@@ -27,12 +27,9 @@ extern struct lockvector bamboo_threadlocks;
 // NOTE: the objptr should not be NULL and should not be non shared ptr
 #define updateObj(objptr) gcmappingtbl[OBJMAPPINGINDEX(objptr)]
 //#define UPDATEOBJ(obj) {void *updatetmpptr=obj; if (updatetmpptr!=NULL) obj=updateObj(updatetmpptr);if (obj<gcbaseva) tprintf("BAD PTR %x to %x in %u\n", updatetmpptr, obj, __LINE__);}
-#define UPDATEOBJ(obj) {void *updatetmpptr=obj; if (updatetmpptr!=NULL) {obj=updateObj(updatetmpptr);}}
+#define UPDATEOBJ(obj) {void *updatetmpptr=obj; if (updatetmpptr!=NULL) {obj=updateObj(updatetmpptr);if (!ISVALIDPTR(obj)) tprintf("Mapping problem for object %x -> %x, mark=%u, line=%u\n", updatetmpptr, obj, getMarkedLength(updatetmpptr),__LINE__);}}
 
-//if (obj==NULL) tprintf("Mapping problem for object %x, mark=%u, line=%u\n", updatetmpptr, getMarkedLength(updatetmpptr),__LINE__);}}
-
-#define UPDATEOBJNONNULL(obj) {void *updatetmpptr=obj; obj=updateObj(updatetmpptr);}
-//if (updatetmpptr!=NULL&&obj==NULL) tprintf("Mapping parameter for object %x, mark=%u, line=%u\n", updatetmpptr, getMarkedLength(updatetmpptr),__LINE__);}
+#define UPDATEOBJNONNULL(obj) {void *updatetmpptr=obj; obj=updateObj(updatetmpptr); if (!ISVALIDPTR(obj)) tprintf("Mapping parameter for object %x -> %x, mark=%u, line=%u\n", updatetmpptr, obj, getMarkedLength(updatetmpptr),__LINE__);}
 
 INLINE void updategarbagelist(struct garbagelist *listptr) {
   for(;listptr!=NULL; listptr=listptr->next) {
@@ -206,20 +203,20 @@ void * updateblocks(struct moveHelper * orig, struct moveHelper * to) {
 
     //Scan more carefully next
     objlength=getMarkedLength(origptr);
-    void *dstptr=gcmappingtbl[OBJMAPPINGINDEX(origptr)];
     
     if (objlength!=NOTMARKED) {
+      void *dstptr=gcmappingtbl[OBJMAPPINGINDEX(origptr)];
       unsigned int length=ALIGNSIZETOBYTES(objlength);
       void *endtoptr=dstptr+length;
 
-      if (endtoptr>tobound||endtoptr<tobase) {
+      if (endtoptr>tobound||dstptr<tobase) {
        //get use the next block of memory
        orig->ptr=origptr;
        return dstptr;
       }
 
       /* Move the object */
-      if(origptr <= endtoptr) {
+      if(origptr >= endtoptr||dstptr >= origptr+length) {
         memmove(dstptr, origptr, length);
       } else if (origptr!=dstptr) {
        //no need to copy if the source & dest are equal....
@@ -227,19 +224,20 @@ void * updateblocks(struct moveHelper * orig, struct moveHelper * to) {
       }
 
       //tprintf("Moving object %x to %x with length %u\n", origptr, dstptr, length);
-
+      
       /* Update the pointers in the object */
       updatePtrsInObj(dstptr);
 
-
       /* Clear the mark */
       clearMark(origptr);
-
+      
       //good to move objects and update pointers
       origptr+=length;
     } else
       origptr+=ALIGNMENTSIZE;
   }
+  orig->ptr=origptr;
+  return NULL;
 }
 
 void updateOrigPtr(void *currtop) {
@@ -289,11 +287,9 @@ void updatehelper(struct moveHelper * orig,struct moveHelper * to) {
       //increment the core
       orig->localblocknum++;
       BASEPTR(orig->base,BAMBOO_NUM_OF_CORE, orig->localblocknum);
-      update_origblockptr=orig->base;
       orig->ptr=orig->base;
       orig->bound = orig->base + BLOCKSIZE(orig->localblocknum);
       if (orig->base >= gcbaseva+BAMBOO_SHARED_MEM_SIZE) {
-       //free our entire memory for others to use
        break;
       }
     }
index b3407676fab50fa3d8c3a12c8ed95db38f5b2b68..526941742b0402aaf75288489ea91b299185b892 100644 (file)
@@ -268,7 +268,7 @@ void mark(struct garbagelist * stackptr) {
 #endif
       if(islarge) {
         // ptr is a large object and not marked or enqueued
-       printf("NEED TO SUPPORT LARGE OBJECTS!\n");
+       printf("NEED TO SUPPORT LARGE OBJECTS: ptr=%x type=%u size=%u!\n", ptr, type, size);
       } else {
         // ptr is an unmarked active object on this core
        unsigned int isize=iunits<<ALIGNMENTSHIFT;
index c06cf03b3889e0cc5e649ccef7fdd1916c3f27ec..af942f81acb52a8fcbc1cbdb41107da4c036cf4c 100644 (file)
@@ -14,6 +14,8 @@ void * localmalloc_I(int coren,
                      int * allocsize) {
   for(block_t localblocknum=0;localblocknum<GCNUMLOCALBLOCK;localblocknum++) {
     block_t searchblock=BLOCKINDEX2(coren, localblocknum);
+    if (searchblock>=GCNUMBLOCK)
+      return NULL;
     struct blockrecord * block=&allocationinfo.blocktable[searchblock];
     if (block->status==BS_FREE) {
       unsigned INTPTR freespace=block->freespace&~BAMBOO_CACHE_LINE_MASK;
@@ -45,16 +47,17 @@ void * fixedmalloc_I(int coren,
     return mem;
 
   //failed try neighbors...in a round robin fashion
-  
   for(block_t lblock=0;lblock<MAXNEIGHBORALLOC;lblock++) {  
     for(int i=0;i<NUM_CORES2TEST;i++) {
-      int neighborcore=core2test[corenum][i];
+      int neighborcore=core2test[coren][i];
       if (neighborcore!=-1) {
        block_t globalblockindex=BLOCKINDEX2(neighborcore, lblock);
+       if (globalblockindex>=GCNUMBLOCK)
+         return NULL;
        struct blockrecord * block=&allocationinfo.blocktable[globalblockindex];
        if (block->status==BS_FREE) {
          unsigned INTPTR freespace=block->freespace&~BAMBOO_CACHE_LINE_MASK;
-         if (memcheck<=freespace) {
+         if (freespace>=memcheck) {
            //we have a block
            //mark block as used
            block->status=BS_USED;
@@ -67,7 +70,6 @@ void * fixedmalloc_I(int coren,
       }
     }
   }
-
   //no memory
   return NULL;
 } 
@@ -96,7 +98,6 @@ void * mixedmalloc_I(int coren,
 void * globalmalloc_I(int coren, unsigned INTPTR memcheck, int * allocsize) {
   block_t firstfree=NOFREEBLOCK;
   block_t lowestblock=allocationinfo.lowestfreeblock;
-
   for(block_t searchblock=lowestblock;searchblock<GCNUMBLOCK;searchblock++) {
     struct blockrecord * block=&allocationinfo.blocktable[searchblock];
     if (block->status==BS_FREE) {
index a307c24d46f260d952354a9c99c8415a33458f2a..010c9e897cf639b2d5ff894e5836f6ae49e62e35 100644 (file)
@@ -33,7 +33,7 @@
 
 #ifdef GC_DEBUG
 #include "structdefs.h"
-#define BAMBOO_NUM_BLOCKS (NUMCORES4GC*(2+1)+3)
+#define BAMBOO_NUM_BLOCKS (NUMCORES4GC*(2+3))
 #define BAMBOO_PAGE_SIZE (64 * 64)
 #define BAMBOO_SMEM_SIZE ((unsigned int)(BAMBOO_PAGE_SIZE))
 #define BAMBOO_SHARED_MEM_SIZE ((unsigned int)((BAMBOO_SMEM_SIZE) *(BAMBOO_NUM_BLOCKS)))
index 3f2907579b0d9d6e1589678052a39425c656076d..16bc13b2762a7e3dc4d39f91cfd0dae417728626 100644 (file)
@@ -12,6 +12,9 @@ void buildCore2Test() {
     int index=0;
     for(int x=xcoord-1;x<=(xcoord+1);x++) {
       for(int y=ycoord-1;y<=(ycoord+1);y++) {
+       if (x==xcoord&&y==ycoord)
+         continue;
+
        if ((x<0||x>7)||(y<0||y>7)) {
          //bad coordinate
          core2test[i][index]=-1;
index 6fa4c22409f277ead1de57eda738ffb96abea50b..8deb797b0113ad118ffb2ee6834d0bffe1f02819 100644 (file)
@@ -413,13 +413,6 @@ void processmsg_memresponse_I() {
 void processmsg_gcstartpre_I() {
   // the first time to be informed to start gc
   gcflag = true;
-  // Zero out the remaining memory here because for the GC_CACHE_ADAPT 
-  // version, we need to make sure during the gcinit phase the shared heap 
-  // is not touched. Otherwise, there would be problem when adapt the cache 
-  // strategy.
-  bamboo_smem_size = 0;
-  bamboo_cur_msp = NULL;
-  smemflag = true;
 }
 
 void processmsg_gcstartinit_I() {
index 1ed250e8b218c7371f9b9978fdc5b956afac5f7d..8f4a025c4e38e2f95059e8236c9be3d3096330c8 100644 (file)
@@ -758,7 +758,6 @@ inline void run(int argc, char** argv) {
   // initialize runtime data structures
   initruntimedata();
   initCommunication();
-
   if (BAMBOO_NUM_OF_CORE==STARTUPCORE) {
     numconfirm=NUMCORES-1;
     for(int i=0;i<NUMCORES;i++) {