Bug fix: during gc compact, one block's usage information could be modified by multip...
authorjzhou <jzhou>
Fri, 5 Aug 2011 22:04:07 +0000 (22:04 +0000)
committerjzhou <jzhou>
Fri, 5 Aug 2011 22:04:07 +0000 (22:04 +0000)
Robust/src/Runtime/bamboo/multicoregccompact.c
Robust/src/Runtime/bamboo/multicoregcmark.c

index d1457a475bfe2b3154975d4b91afe63d91176902..d0adbc6fe8f5bd460e55c5198addd16fcedcf0a1 100644 (file)
@@ -58,25 +58,28 @@ void handleReturnMem_I(unsigned int cnum, void *heaptop) {
 
   struct blockrecord * blockrecord=&allocationinfo.blocktable[blockindex];
 
-  blockrecord->status=BS_FREE;
-  blockrecord->usedspace=(unsigned INTPTR)(heaptop-OFFSET2BASEVA(blockindex)-gcbaseva);
-  blockrecord->freespace=BLOCKSIZE(localblocknum)-blockrecord->usedspace;
-  /* Update the lowest free block */
-  if (blockindex < allocationinfo.lowestfreeblock) {
-    allocationinfo.lowestfreeblock=blockindex;
-  }
+  unsigned INTPTR newusedspace=(unsigned INTPTR)(heaptop-OFFSET2BASEVA(blockindex)-gcbaseva);
+  if(blockrecord->usedspace < newusedspace) {
+    blockrecord->status=BS_FREE;
+    blockrecord->usedspace=newusedspace;
+    blockrecord->freespace=BLOCKSIZE(localblocknum)-blockrecord->usedspace;
+    /* Update the lowest free block */
+    if (blockindex < allocationinfo.lowestfreeblock) {
+      allocationinfo.lowestfreeblock=blockindex;
+    }
 
-  /* 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++) {
-      unsigned INTPTR blocknum=BLOCKINDEX2(cnum, nextlocalblocknum);
-      struct blockrecord * nextblockrecord=&allocationinfo.blocktable[blocknum];
-      nextblockrecord->status=BS_FREE;
-      nextblockrecord->usedspace=0;
-      //this is true because this cannot be the lowest block
-      nextblockrecord->freespace=BLOCKSIZE(1);
+    /* 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++) {
+        unsigned INTPTR blocknum=BLOCKINDEX2(cnum, nextlocalblocknum);
+        struct blockrecord * nextblockrecord=&allocationinfo.blocktable[blocknum];
+        nextblockrecord->status=BS_FREE;
+        nextblockrecord->usedspace=0;
+        //this is true because this cannot be the lowest block
+        nextblockrecord->freespace=BLOCKSIZE(1);
+      }
     }
   }
 
@@ -570,6 +573,7 @@ void master_compact() {
   while(!gc_checkCoreStatus())
     ;
 
+// GC_CACHE_COHERENT_ON should be true for gcmappingtbl, and the gcmappingtbl should be zeroed out before starting gc
 #ifdef GC_DEBUG
   void *nextvalid=gcbaseva;
   for(void *tmp=gcbaseva; tmp<gcbaseva+BAMBOO_SHARED_MEM_SIZE;tmp+=ALIGNMENTSIZE) {
index a0cfb364d1f2970fd548a6437063272cceb73e60..51844bef6b5d61227b9ce60a5cf45bd87e436a14 100644 (file)
@@ -50,7 +50,7 @@ bool isLarge(void * ptr, int * ttype, unsigned int * tsize) {
 
 //push the null check into the mark macro
 
-//#define MARKOBJ(objptr) {void * marktmpptr=objptr; if (marktmpptr!=NULL) {markObj(marktmpptr);if ((marktmpptr<gcbaseva)||(marktmpptr>(gcbaseva+BAMBOO_SHARED_MEM_SIZE))) tprintf("Bad pointer %x in line %u\n",marktmpptr, __LINE__);  }}
+//#define MARKOBJ(objptr) {void * marktmpptr=objptr; if (marktmpptr!=NULL) {markObj(marktmpptr);if ((marktmpptr<gcbaseva)||(marktmpptr>(gcbaseva+BAMBOO_SHARED_MEM_SIZE))) tprintf("Bad pointer %x in line %u\n",marktmpptr, __LINE__); }}
 
 #define MARKOBJ(objptr) {void * marktmpptr=objptr; if (marktmpptr!=NULL) {markObj(marktmpptr);}}
 
@@ -259,10 +259,10 @@ void mark(struct garbagelist * stackptr) {
       if (unit!=iunits) {
        tprintf("Bad mark on %x %u!=%u\n", ptr, unit, iunits);
        tprintf("hibits=%x lobits=%x\n", hibits, lobits);
-       tprintf("ohigh=%x olow=%x", ohigh, olow);
+       tprintf("ohigh=%x olow=%x\n", ohigh, olow);
        unsigned INTPTR nhigh=gcmarktbl[hibits];
        unsigned INTPTR nlow=gcmarktbl[hibits+1];
-       tprintf("nhigh=%x nlow=%x", nhigh, nlow);
+       tprintf("nhigh=%x nlow=%x\n", nhigh, nlow);
       }
 #endif
       if(islarge) {