more bug fixes
authorbdemsky <bdemsky>
Fri, 8 Jul 2011 00:08:45 +0000 (00:08 +0000)
committerbdemsky <bdemsky>
Fri, 8 Jul 2011 00:08:45 +0000 (00:08 +0000)
Robust/src/Runtime/bamboo/pmc_forward.c
Robust/src/Runtime/bamboo/pmc_garbage.c
Robust/src/Runtime/bamboo/pmc_mem.c
Robust/src/Runtime/bamboo/pmc_refupdate.c
Robust/src/Runtime/bamboo/pmc_refupdate.h

index d50053a3236d7f22311877ef7ac532d053693602..15477bac49039433419414d35d1eddc4676cd4c4 100644 (file)
@@ -17,7 +17,6 @@ void pmc_count() {
 
 //Comment: should build dummy byte arrays to allow skipping data...
 void pmc_countbytes(struct pmc_unit * unit, void *bottomptr, void *topptr) {
-  tprintf("%x--%x\n",bottomptr, topptr);
   void *tmpptr=bottomptr;
   unsigned int totalbytes=0;
   while(tmpptr<topptr) {
@@ -85,16 +84,12 @@ void pmc_doforward() {
   region->highunit=endregion;
   region->startptr=(startregion==0)?gcbaseva:pmc_heapptr->units[startregion-1].endptr;
   region->endptr=pmc_heapptr->units[endregion-1].endptr;
-  tprintf("startregion=%u gcbaseva=%x\n", startregion, gcbaseva);
-  tprintf("totalbytes=%u\n", totalbytes);
   if (BAMBOO_NUM_OF_CORE&1) {
     //upward in memory
     region->lastptr=region->endptr-totalbytes;
-    tprintf("(up) Assigning lastptr for %u to %x ep=%x\n", BAMBOO_NUM_OF_CORE, region->lastptr, region->endptr);
   } else {
     //downward in memory
     region->lastptr=region->startptr+totalbytes;
-    tprintf("(down) Assigning lastptr for %u to %x sp=%x\n", BAMBOO_NUM_OF_CORE, region->lastptr, region->startptr);
   }
 
   pmc_forward(region, totalbytes, region->startptr, region->endptr, !(BAMBOO_NUM_OF_CORE&1));
@@ -111,7 +106,7 @@ void pmc_forward(struct pmc_region *region, unsigned int totalbytes, void *botto
 
   if (!fwddirection) {
     //reset boundaries of beginning units
-    while(endunit<forwardptr) {
+    while(endunit<=region->lastptr) {
       pmc_heapptr->units[currunit].endptr=endunit;
       currunit++;
       endunit=pmc_unitend(currunit);
@@ -120,7 +115,7 @@ void pmc_forward(struct pmc_region *region, unsigned int totalbytes, void *botto
     //reset boundaries of end units
     unsigned int lastunit=region->highunit-1;
     void * lastunitend=pmc_unitend(lastunit);
-    while(lastunitend>forwardptr) {
+    while(lastunitend>=region->lastptr) {
       pmc_heapptr->units[lastunit].endptr=lastunitend;
       lastunit--;
       lastunitend=pmc_unitend(lastunit);
@@ -139,8 +134,9 @@ 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);
       void *newforwardptr=forwardptr+size;
-      while(newforwardptr>endunit) {
+      while(newforwardptr>=endunit) {
        pmc_heapptr->regions[currunit].endptr=newforwardptr;
        currunit++;
        endunit=pmc_unitend(currunit);
@@ -154,5 +150,6 @@ void pmc_forward(struct pmc_region *region, unsigned int totalbytes, void *botto
     }
     tmpptr+=size;
   }
+  tprintf("forwardptr=%x\n",forwardptr);
   region->lastobj=lastobj;
 }
index 46b7619c48dff7426a07b8bbb225081836bd0ef8..f56043d930668e473a4883d49b41cea04776a2dd 100644 (file)
@@ -62,7 +62,6 @@ void pmc_init() {
 
       for(unsigned int index=startindex;index<endindex;index++) {
        void *ptr=pmc_unitend(index);
-       tprintf("index=%u ptr=%x\n", index, ptr);
        if ((ptr>startptr)&&(ptr<=finishptr)) {
          pmc_heapptr->units[index].endptr=ptr;
          padspace(startptr, (unsigned int)(ptr-startptr));
@@ -106,7 +105,7 @@ void gc(struct garbagelist *gl) {
   tmc_spin_barrier_wait(&pmc_heapptr->barrier);
   //update pointers
   tprintf("updaterefs\n");
-  pmc_doreferenceupdate();
+  pmc_doreferenceupdate(gl);
   tmc_spin_barrier_wait(&pmc_heapptr->barrier);
   //compact data
   tprintf("compact\n");
index a49808467ed353ca028f11bcfd90acc741b21d3d..ed36e97c66e89b6ea19d0a140d2d5edf02bb6e4c 100644 (file)
@@ -13,8 +13,6 @@ void * pmc_alloc(unsigned int * numbytesallocated, unsigned int minimumbytes) {
     void *startptr=pmc_heapptr->regions[i].lastptr;
     void *finishptr=pmc_heapptr->regions[i+1].lastptr;
 
-    tprintf("%u %x - %x\n",i, startptr, finishptr);
-
     if ((finishptr-startptr)>memcheck) {
       struct pmc_region *region=&pmc_heapptr->regions[i];
       tmc_spin_mutex_lock(&region->lock);
@@ -40,8 +38,6 @@ void * pmc_alloc(unsigned int * numbytesallocated, unsigned int minimumbytes) {
 
        *numbytesallocated=(unsigned int)(newstartptr-startptr);
        tmc_spin_mutex_unlock(&region->lock);
-       tprintf("fptr=%x\n", finishptr);
-       tprintf("Allocing %x to %x\n", startptr, newstartptr);
        return startptr;
       } while(0);
       tmc_spin_mutex_unlock(&region->lock);
index a99c2bb1a3d9ea0dc059b6f786d1800fbe9d6756..7bc9baa260e8dee875514bd495699842d2cb96ab 100644 (file)
@@ -4,13 +4,16 @@
 #include "runtime_arch.h"
 #include "pmc_forward.h"
 #include "pmc_refupdate.h"
+#include "multicoremgc.h"
+#include "runtime.h"
+#include "thread.h"
 
 
 #define pmcupdateObj(objptr) ((void *)((struct ___Object___ *)objptr)->marked)
 
-#define PMCUPDATEOBJ(obj) {void *updatetmpptr=obj; if (updatetmpptr!=NULL) {obj=pmcupdateObj(updatetmpptr);}}
+#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 PMCUPDATEOBJNONNULL(obj) {void *updatetmpptr=obj; 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__);}}
 
 void pmc_updatePtrs(void *ptr, int type) {
   unsigned int * pointer=pointerarray[type];
@@ -33,8 +36,111 @@ void pmc_updatePtrs(void *ptr, int type) {
   }  
 }
 
-void pmc_doreferenceupdate() {
+void pmc_updategarbagelist(struct garbagelist *listptr) {
+  for(;listptr!=NULL; listptr=listptr->next) {
+    for(int i=0; i<listptr->size; i++) {
+      PMCUPDATEOBJ(listptr->array[i]);
+    }
+  }
+}
+
+void pmc_updateRuntimePtrs(struct garbagelist * stackptr) {
+  // update current stack
+  pmc_updategarbagelist(stackptr);
+
+  // update static pointers global_defs_p
+  if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
+    pmc_updategarbagelist((struct garbagelist *)global_defs_p);
+  }
+
+#ifdef TASK
+  // update objectsets
+  if(BAMBOO_NUM_OF_CORE < NUMCORESACTIVE) {
+    for(int i=0; i<NUMCLASSES; i++) {
+      struct parameterwrapper ** queues = objectqueues[BAMBOO_NUM_OF_CORE][i];
+      int length = numqueues[BAMBOO_NUM_OF_CORE][i];
+      for(int j = 0; j < length; ++j) {
+        struct parameterwrapper * parameter = queues[j];
+        struct ObjectHash * set=parameter->objectset;
+        for(struct ObjectNode * ptr=set->listhead;ptr!=NULL;ptr=ptr->lnext) {
+          PMCUPDATEOBJNONNULL(ptr->key);
+        }
+        ObjectHashrehash(set);
+      }
+    }
+  }
+
+  // update current task descriptor
+  if(currtpd != NULL) {
+    for(int i=0; i<currtpd->numParameters; i++) {
+      // the parameter can not be NULL
+      PMCUPDATEOBJNONNULL(currtpd->parameterArray[i]);
+    }
+  }
+
+  // update active tasks
+  if(activetasks != NULL) {
+    for(struct genpointerlist * ptr=activetasks->list;ptr!=NULL;ptr=ptr->inext){
+      struct taskparamdescriptor *tpd=ptr->src;
+      for(int i=0; i<tpd->numParameters; i++) {
+        // the parameter can not be NULL
+       PMCUPDATEOBJNONNULL(tpd->parameterArray[i]);
+      }
+    }
+    genrehash(activetasks);
+  }
+
+  // update cached transferred obj
+  for(struct QueueItem * tmpobjptr =  getHead(&objqueue);tmpobjptr != NULL;tmpobjptr = getNextQueueItem(tmpobjptr)) {
+    struct transObjInfo * objInfo=(struct transObjInfo *)(tmpobjptr->objectptr);
+    // the obj can not be NULL
+    PMCUPDATEOBJNONNULL(objInfo->objptr);
+  }
+
+  // update cached objs to be transferred
+  for(struct QueueItem * item = getHead(totransobjqueue);item != NULL;item = getNextQueueItem(item)) {
+    struct transObjInfo * totransobj = (struct transObjInfo *)(item->objectptr);
+    // the obj can not be NULL
+    PMCUPDATEOBJNONNULL(totransobj->objptr);
+  }  
+
+  // enqueue lock related info
+  for(int i = 0; i < runtime_locklen; ++i) {
+    PMCUPDATEOBJ(runtime_locks[i].redirectlock);
+    PMCUPDATEOBJ(runtime_locks[i].value);
+  }
+#endif
+
+#ifdef MGC
+  // update the bamboo_threadlocks
+  for(int i = 0; i < bamboo_threadlocks.index; i++) {
+    // the locked obj can not be NULL
+    PMCUPDATEOBJNONNULL(bamboo_threadlocks.locks[i].object);
+  }
+
+  // update the bamboo_current_thread
+  PMCUPDATEOBJ(bamboo_current_thread);
+
+  // update global thread queue
+  if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
+    unsigned int thread_counter = *((unsigned int*)(bamboo_thread_queue+1));
+    if(thread_counter > 0) {
+      unsigned int start = *((unsigned int*)(bamboo_thread_queue+2));
+      for(int i = thread_counter; i > 0; i--) {
+        // the thread obj can not be NULL
+        PMCUPDATEOBJNONNULL(*((void **)&bamboo_thread_queue[4+start]));
+        start = (start+1)&bamboo_max_thread_num_mask;
+      }
+    }
+    unlockthreadqueue();
+  }
+#endif
+}
+
+
+void pmc_doreferenceupdate(struct garbagelist *stackptr) {
   struct pmc_region * region=&pmc_heapptr->regions[BAMBOO_NUM_OF_CORE];
+  pmc_updateRuntimePtrs(stackptr);
   pmc_referenceupdate(region->startptr, region->endptr);
 }
 
index 107b90ef577ecd9061f54e0b51b5f0f35649a936..9e9019f691a75aa567dfe5ed71f0e07f088529ea 100644 (file)
@@ -1,9 +1,16 @@
 #ifndef PMC_REFUPDATE_H
 #define PMC_REFUPDATE_H
 
+#include "multicore.h"
+#include "multicoregc.h"
+#include "structdefs.h"
+
 void pmc_updatePtrs(void *ptr, int type);
-void pmc_doreferenceupdate();
+void pmc_doreferenceupdate(struct garbagelist *);
 void pmc_referenceupdate(void *bottomptr, void *topptr);
 void pmc_docompact();
 void pmc_compact(struct pmc_region * region, int forward, void *bottomptr, void *topptr);
+void pmc_updategarbagelist(struct garbagelist *listptr);
+void pmc_updateRuntimePtrs(struct garbagelist * stackptr);
+
 #endif