bug fixes...runs at least one benchmark now....
authorbdemsky <bdemsky>
Fri, 8 Jul 2011 05:39:12 +0000 (05:39 +0000)
committerbdemsky <bdemsky>
Fri, 8 Jul 2011 05:39:12 +0000 (05:39 +0000)
looks like a GC_DEBUG snuck into a header file...perhaps this was causing a problem?

Robust/src/Runtime/bamboo/multicoremem.h
Robust/src/Runtime/bamboo/pmc_forward.c
Robust/src/Runtime/bamboo/pmc_garbage.c
Robust/src/Runtime/bamboo/pmc_mark.c
Robust/src/Runtime/bamboo/pmc_mem.c
Robust/src/Runtime/bamboo/pmc_refupdate.c

index 561898f8c8b5c810660e3eb864b587ff5e322a52..4dc93afd74c118b5061643cb6fc672c904c6e0e0 100644 (file)
@@ -4,7 +4,6 @@
 #include "Queue.h"
 #include "SimpleHash.h"
 
-#define GC_DEBUG 1
 // data structures for shared memory allocation
 #ifdef TILERA_BME
 #ifdef MGC
index 15477bac49039433419414d35d1eddc4676cd4c4..b4ec94e320a9613fe8a43cbc2e66fb011298714c 100644 (file)
@@ -10,6 +10,7 @@ void pmc_count() {
       //got lock
       void *unitbase=(i==0)?gcbaseva:pmc_heapptr->units[i-1].endptr;
       void *unittop=pmc_heapptr->units[i].endptr;
+      //tprintf("Cnt: %x - %x\n", unitbase, unittop);
       pmc_countbytes(&pmc_heapptr->units[i], unitbase, unittop);
     }
   }
@@ -76,8 +77,12 @@ void pmc_doforward() {
       totalbytes+=pmc_heapptr->units[i].numbytes;
     }
   }
-  if (startregion==-1) 
+  if (startregion==-1) {
+    //out of regions....
+    region->lowunit=region->highunit=NUMPMCUNITS;
+    region->lastptr=region->startptr=region->endptr=pmc_heapptr->units[region->highunit-1].endptr;
     return;
+  }
   if (endregion==-1)
     endregion=NUMPMCUNITS;
   region->lowunit=startregion;
@@ -91,29 +96,30 @@ void pmc_doforward() {
     //downward in memory
     region->lastptr=region->startptr+totalbytes;
   }
-
   pmc_forward(region, totalbytes, region->startptr, region->endptr, !(BAMBOO_NUM_OF_CORE&1));
 }
 
 
 //fwddirection=1 means move things to lower addresses
-void pmc_forward(struct pmc_region *region, unsigned int totalbytes, void *bottomptr, void *topptr, bool fwddirection) {
+void pmc_forward(struct pmc_region *region, unsigned int totalbytes, void *bottomptr, void *topptr, bool lower) {
   void *tmpptr=bottomptr;
-  void *forwardptr=fwddirection?bottomptr:(topptr-totalbytes);
+  void *forwardptr=lower?bottomptr:(topptr-totalbytes);
   struct ___Object___ *lastobj=NULL;
   unsigned int currunit=region->lowunit;
   void *endunit=pmc_unitend(currunit);
 
-  if (!fwddirection) {
-    //reset boundaries of beginning units
-    while(endunit<=region->lastptr) {
+  if (!lower) {
+    //We're resetting the boundaries of units at the low address end of the region...
+    //Be sure not to reset the boundary of our last unit...it is shared with another region
+    while(endunit<=region->lastptr&&(currunit<(region->highunit-1))) {
       pmc_heapptr->units[currunit].endptr=endunit;
       currunit++;
       endunit=pmc_unitend(currunit);
     }
   } else {
-    //reset boundaries of end units
-    unsigned int lastunit=region->highunit-1;
+    //We're resetting the boundaries of units at the high address end of the region...
+    //Very top most unit defines boundary of region...we can't move that right now
+    unsigned int lastunit=region->highunit-2;
     void * lastunitend=pmc_unitend(lastunit);
     while(lastunitend>=region->lastptr) {
       pmc_heapptr->units[lastunit].endptr=lastunitend;
@@ -134,22 +140,24 @@ void pmc_forward(struct pmc_region *region, unsigned int totalbytes, void *botto
 
     if (((struct ___Object___ *)tmpptr)->marked) {
       ((struct ___Object___ *)tmpptr)->marked=forwardptr;
-      tprintf("Forwarding %x->%x\n", tmpptr, forwardptr);
+      //tprintf("Forwarding %x->%x\n", tmpptr, forwardptr);
       void *newforwardptr=forwardptr+size;
-      while(newforwardptr>=endunit) {
-       pmc_heapptr->regions[currunit].endptr=newforwardptr;
+      //Need to make sure that unit boundaries do not fall in the middle of an object...
+      //Unless the unit boundary is at the end of the region...then just ignore it.
+      while(newforwardptr>=endunit&&currunit<(region->highunit-1)) {
+       pmc_heapptr->units[currunit].endptr=newforwardptr;
        currunit++;
        endunit=pmc_unitend(currunit);
       }
 
       forwardptr=newforwardptr;
-      if (lastobj&&!fwddirection) {
+      if (!lower) {
        ((struct ___Object___ *)tmpptr)->backward=lastobj;
        lastobj=(struct ___Object___ *)tmpptr;
       }
     }
     tmpptr+=size;
   }
-  tprintf("forwardptr=%x\n",forwardptr);
+  //tprintf("forwardptr=%x\n",forwardptr);
   region->lastobj=lastobj;
 }
index f56043d930668e473a4883d49b41cea04776a2dd..2e0a8fc1264c8a13383fe508b0df7217175c5e7e 100644 (file)
@@ -30,7 +30,7 @@ void pmc_onceInit() {
     tmc_spin_barrier_init(&pmc_heapptr->barrier, NUMCORES4GC);
     for(int i=0;i<NUMPMCUNITS;i++) {
       pmc_heapptr->units[i].endptr=pmc_unitend(i);
-      tprintf("%u endptr=%x\n", i, pmc_heapptr->units[i].endptr);
+      //tprintf("%u endptr=%x\n", i, pmc_heapptr->units[i].endptr);
     }
     
     for(int i=0;i<NUMCORES4GC;i+=2) {
@@ -44,9 +44,9 @@ void pmc_onceInit() {
       pmc_heapptr->regions[i+1].lowunit=4*(i+1);
       pmc_heapptr->regions[i+1].highunit=4*(i+2);
     }
-    for(int i=0;i<NUMCORES4GC;i++) {
-      tprintf("%u lastptr=%x\n", i, pmc_heapptr->regions[i].lastptr);
-    }
+    //    for(int i=0;i<NUMCORES4GC;i++) {
+    //      tprintf("%u lastptr=%x\n", i, pmc_heapptr->regions[i].lastptr);
+    //    }
   }
 }
 
@@ -59,11 +59,10 @@ void pmc_init() {
       struct pmc_region *region=&pmc_heapptr->regions[i];
       unsigned int startindex=region->lowunit;
       unsigned int endindex=pmc_heapptr->regions[i+1].highunit;
-
+      //      tprintf("Free space in partition %u from %x to %x\n", i, startptr, finishptr);
       for(unsigned int index=startindex;index<endindex;index++) {
-       void *ptr=pmc_unitend(index);
+       void *ptr=pmc_heapptr->units[index].endptr;
        if ((ptr>startptr)&&(ptr<=finishptr)) {
-         pmc_heapptr->units[index].endptr=ptr;
          padspace(startptr, (unsigned int)(ptr-startptr));
          startptr=ptr;
        }
@@ -76,49 +75,58 @@ void pmc_init() {
     }
   }
   if (bamboo_smem_size) {
+    //    tprintf("Left over alloc space from %x to %x\n", bamboo_cur_msp, bamboo_cur_msp+bamboo_smem_size);
     padspace(bamboo_cur_msp, bamboo_smem_size);  
   }
   tmc_spin_barrier_wait(&pmc_heapptr->barrier);
 }
 
 void gc(struct garbagelist *gl) {
-  tprintf("%x\n", pmc_heapptr);
-  tprintf("init\n");
+  if (BAMBOO_NUM_OF_CORE==STARTUPCORE)
+    tprintf("start GC\n");
   pmc_init();
   //mark live objects
-  tprintf("mark\n");
+  //  tprintf("mark\n");
   pmc_mark(gl);
   //count live objects per unit
   tmc_spin_barrier_wait(&pmc_heapptr->barrier);
-  tprintf("count\n");
+  //  tprintf("count\n");
   pmc_count();
   tmc_spin_barrier_wait(&pmc_heapptr->barrier);
   //divide up work
-  tprintf("divide\n");
+  //  tprintf("divide\n");
   if (BAMBOO_NUM_OF_CORE==STARTUPCORE) {
     pmc_processunits();
   }
   tmc_spin_barrier_wait(&pmc_heapptr->barrier);
   //set up forwarding pointers
-  tprintf("forward\n");
+  //  tprintf("forward\n");
   pmc_doforward();
   tmc_spin_barrier_wait(&pmc_heapptr->barrier);
   //update pointers
-  tprintf("updaterefs\n");
+  //  tprintf("updaterefs\n");
   pmc_doreferenceupdate(gl);
   tmc_spin_barrier_wait(&pmc_heapptr->barrier);
   //compact data
-  tprintf("compact\n");
+  //  tprintf("compact\n");
   pmc_docompact();
   //reset memory allocation
   bamboo_cur_msp=NULL;
   bamboo_smem_size=0;
-  tprintf("done\n");
+  //  tprintf("done\n");
 
   if (BAMBOO_NUM_OF_CORE==STARTUPCORE) {
     tmc_spin_barrier_wait(&pmc_heapptr->barrier);
     //people will resend...no need to get gcflag so quickly
     gcflag=false;
+    //    for(int i=0;i<NUMCORES4GC;i+=2) {
+    //      tprintf("%u %x %x\n",i, pmc_heapptr->regions[i].lastptr, pmc_heapptr->regions[i+1].lastptr);
+    //      tprintf("%x %x %x %x\n", pmc_heapptr->regions[i].startptr, pmc_heapptr->regions[i].endptr, pmc_heapptr->regions[i+1].startptr, pmc_heapptr->regions[i+1].endptr);
+    //      tprintf("%u %u %u %u\n", pmc_heapptr->regions[i].lowunit, pmc_heapptr->regions[i].highunit, pmc_heapptr->regions[i+1].lowunit, pmc_heapptr->regions[i+1].highunit);
+    //    }
+    //    for(int i=0;i<NUMPMCUNITS;i++) {
+    //      tprintf("%u %x %u\n",i, pmc_heapptr->units[i].endptr, pmc_heapptr->units[i].regionnum);
+    //    }
   } else {
     //start to listen for gcflags before we exit
     gcflag=false;
@@ -128,7 +136,7 @@ void gc(struct garbagelist *gl) {
 
 void padspace(void *ptr, unsigned int length) {
   //zero small blocks
-  tprintf("Padspace from %x to %x\n", ptr, ptr+length);
+  //  tprintf("Padspace from %x to %x\n", ptr, ptr+length);
   if (length<sizeof(struct ArrayObject)) {
     BAMBOO_MEMSET_WH(ptr,0,length);
   } else {
index 66413aa31e7470ebf68f69d5065494ba2f449db2..20b4972713f97e3ccbfbce92ad455d5344448ba5 100644 (file)
@@ -27,6 +27,7 @@ void pmc_scanPtrsInObj(void * ptr, int type) {
     int length=ao->___length___;
     for(int i=0; i<length; i++) {
       void *objptr=((void **)(((char *)&ao->___length___)+sizeof(int)))[i];
+      //tprintf("%x marks %x\n", ptr, objptr);
       PMC_MARKOBJ(objptr);
     }
   } else {
@@ -35,6 +36,7 @@ void pmc_scanPtrsInObj(void * ptr, int type) {
     for(int i=1; i<=size; i++) {
       unsigned int offset=pointer[i];
       void * objptr=*((void **)(((char *)ptr)+offset));
+      //tprintf("%x marks %x\n", ptr, objptr);
       PMC_MARKOBJ(objptr);
     }
   }
@@ -44,6 +46,7 @@ void pmc_markgarbagelist(struct garbagelist * listptr) {
   for(;listptr!=NULL;listptr=listptr->next) {
     int size=listptr->size;
     for(int i=0; i<size; i++) {
+      //tprintf("gl marks %x\n", listptr->array[i]);
       PMC_MARKOBJ(listptr->array[i]);
     }
   }
@@ -163,6 +166,7 @@ void pmc_tomark(struct garbagelist * stackptr) {
       unsigned int start = *((unsigned int*)(bamboo_thread_queue+2));
       for(int i = thread_counter; i > 0; i--) {
         // the thread obj can not be NULL
+       //tprintf("mgc marks %x\n", (void *)bamboo_thread_queue[4+start]);
         PMC_MARKOBJNONNULL((void *)bamboo_thread_queue[4+start]);
         start = (start+1)&bamboo_max_thread_num_mask;
       }
@@ -171,9 +175,11 @@ void pmc_tomark(struct garbagelist * stackptr) {
   // enqueue the bamboo_threadlocks
   for(int i = 0; i < bamboo_threadlocks.index; i++) {
     // the locks can not be NULL
+    //tprintf("mgc2 marks %x\n", (void *)bamboo_threadlocks.locks[i].object);
     PMC_MARKOBJNONNULL((void *)(bamboo_threadlocks.locks[i].object));
   }
   // enqueue the bamboo_current_thread
+  //tprintf("mgc3 marks %x\n", bamboo_current_thread);
   PMC_MARKOBJ(bamboo_current_thread);
 #endif
 }
index ed36e97c66e89b6ea19d0a140d2d5edf02bb6e4c..7da2af76d855fa28b808eb8bbb0724d33f65b462 100644 (file)
@@ -26,7 +26,7 @@ void * pmc_alloc(unsigned int * numbytesallocated, unsigned int minimumbytes) {
        void * newstartptr=startptr+memcheck;
        
        //update unit end points
-       for(unsigned int index=startindex;index<endindex;index++) {
+       for(unsigned int index=startindex;index<(endindex-1);index++) {
          void *ptr=pmc_unitend(index);
          if ((ptr>startptr)&&(ptr<newstartptr)) {
            pmc_heapptr->units[index].endptr=newstartptr;
index 7bc9baa260e8dee875514bd495699842d2cb96ab..7587b36c53c292482a2d6ad54ecaee3cebbd4bf5 100644 (file)
 
 #define pmcupdateObj(objptr) ((void *)((struct ___Object___ *)objptr)->marked)
 
-#define PMCUPDATEOBJ(obj) {void *updatetmpptr=obj; if (updatetmpptr!=NULL) {obj=pmcupdateObj(updatetmpptr);if (obj==NULL) {tprintf("BAD REF UPDATE %x->%x in %u\n",updatetmpptr,obj,__LINE__);}}}
+#define PMCUPDATEOBJ(obj) {void *updatetmpptr=obj; if (updatetmpptr!=NULL) {obj=pmcupdateObj(updatetmpptr);}}
 
-#define PMCUPDATEOBJNONNULL(obj) {void *updatetmpptr=obj; obj=pmcupdateObj(updatetmpptr);if (obj==NULL) {tprintf("BAD REF UPDATE in %x->%x %u\n",updatetmpptr,obj,__LINE__);}}
+//if (obj==NULL) {tprintf("BAD REF UPDATE %x->%x in %u\n",updatetmpptr,obj,__LINE__);}}}
+
+#define PMCUPDATEOBJNONNULL(obj) {void *updatetmpptr=obj; obj=pmcupdateObj(updatetmpptr);}
+//if (obj==NULL) {tprintf("BAD REF UPDATE in %x->%x %u\n",updatetmpptr,obj,__LINE__);}}
 
 void pmc_updatePtrs(void *ptr, int type) {
   unsigned int * pointer=pointerarray[type];
+  //tprintf("Updating pointers in %x\n", ptr);
   if (pointer==0) {
     /* Array of primitives */
   } else if (((unsigned int)pointer)==1) {
@@ -33,7 +37,8 @@ void pmc_updatePtrs(void *ptr, int type) {
       unsigned int offset=pointer[i];
       PMCUPDATEOBJ(*((void **)(((char *)ptr)+offset)));
     }
-  }  
+  }
+  //tprintf("done\n");
 }
 
 void pmc_updategarbagelist(struct garbagelist *listptr) {
@@ -146,7 +151,7 @@ void pmc_doreferenceupdate(struct garbagelist *stackptr) {
 
 void pmc_referenceupdate(void *bottomptr, void *topptr) {
   void *tmpptr=bottomptr;
-  tprintf("%x -- %x\n", bottomptr, topptr);
+  //tprintf("%x -- %x\n", bottomptr, topptr);
   while(tmpptr<topptr) {
     unsigned int type;
     unsigned int size;
@@ -186,12 +191,13 @@ void pmc_compact(struct pmc_region * region, int forward, void *bottomptr, void
       void *forwardptr=(void *)((struct ___Object___ *) tmpptr)->marked;
       ((struct ___Object___ *) tmpptr)->marked=NULL;
       if (forwardptr) {
+       //tprintf("Compacting %x\n",tmpptr);
        memmove(forwardptr, tmpptr, size);
       }
       tmpptr+=size;
     }
   } else {
-    struct ___Object___ *backward=((struct ___Object___ *) region)->backward;
+    struct ___Object___ *backward=region->lastobj;
     struct ___Object___ *lastobj=NULL;
     while(backward) {
       lastobj=backward;
@@ -202,9 +208,8 @@ void pmc_compact(struct pmc_region * region, int forward, void *bottomptr, void
       size=((size-1)&(~(ALIGNMENTSIZE-1)))+ALIGNMENTSIZE;
       void *forwardptr=(void *)((struct ___Object___ *) lastobj)->marked;
       ((struct ___Object___ *) lastobj)->marked=NULL;
-      if (forwardptr) {
-       memmove(forwardptr, lastobj, size);
-      }
+      //tprintf("Compacting %x\n",lastobj);
+      memmove(forwardptr, lastobj, size);
     }
   }
 }