bug fixes
authorbdemsky <bdemsky>
Sun, 3 Jul 2011 23:29:54 +0000 (23:29 +0000)
committerbdemsky <bdemsky>
Sun, 3 Jul 2011 23:29:54 +0000 (23:29 +0000)
21 files changed:
Robust/src/Runtime/bamboo/MGCHash.c
Robust/src/Runtime/bamboo/gcqueue.c
Robust/src/Runtime/bamboo/gcqueue.h
Robust/src/Runtime/bamboo/markbit.c
Robust/src/Runtime/bamboo/multicoregarbage.c
Robust/src/Runtime/bamboo/multicoregarbage.h
Robust/src/Runtime/bamboo/multicoregccompact.c
Robust/src/Runtime/bamboo/multicoregccompact.h
Robust/src/Runtime/bamboo/multicoregcflush.c
Robust/src/Runtime/bamboo/multicoregcflush.h
Robust/src/Runtime/bamboo/multicoregcmark.c
Robust/src/Runtime/bamboo/multicoregcmark.h
Robust/src/Runtime/bamboo/multicoregcprofile.c
Robust/src/Runtime/bamboo/multicorehelper.h
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/multicoremsg.h
Robust/src/Runtime/bamboo/multicoreruntime.c
Robust/src/Runtime/bamboo/multicoreruntime.h

index 146c01036e515d8388232853009b6fb9ecc7c23b..fd6d4a97adab293c1c4a31ae77f255eb4d17852d 100644 (file)
@@ -1,5 +1,6 @@
 #include "MGCHash.h"
 #ifdef MULTICORE
+#include "structdefs.h"
 #include "runtime_arch.h"
 #else
 #include <stdio.h>
@@ -13,8 +14,6 @@
 /* mgchash ********************************************************/
 mgchashtable_t * mgchashCreate(unsigned int size, double loadfactor) {
   mgchashtable_t *ctable;
-  mgchashlistnode_t *nodes;
-  int i;
 
   if (size <= 0) {
 #ifdef MULTICORE
@@ -48,10 +47,9 @@ mgchashtable_t * mgchashCreate(unsigned int size, double loadfactor) {
 }
 
 void mgchashreset(mgchashtable_t * tbl) {
-  mgchashlistnode_t *ptr = tbl->table;
-  int i;
+  /* mgchashlistnode_t *ptr = tbl->table;
 
-  /*if (tbl->numelements<(tbl->size>>6)) {
+   if (tbl->numelements<(tbl->size>>6)) {
        mgchashlistnode_t *top=&ptr[tbl->size];
        mgchashlistnode_t * list = tbl->list;
        while(list != NULL) {
@@ -64,7 +62,7 @@ void mgchashreset(mgchashtable_t * tbl) {
       list = next;
        }
   } else {*/
-       BAMBOO_MEMSET_WH(tbl->table, '\0', sizeof(mgchashlistnode_t)*tbl->size);
+  BAMBOO_MEMSET_WH(tbl->table, 0, sizeof(mgchashlistnode_t)*tbl->size);
   //}
   // TODO now never release any allocated memory, may need to be changed
   while(tbl->structs->next!=NULL) {
@@ -116,8 +114,6 @@ void mgchashInsert(mgchashtable_t * tbl, void * key, void *val) {
 #ifdef MULTICORE_GC
 mgchashtable_t * mgchashCreate_I(unsigned int size, double loadfactor) {
   mgchashtable_t *ctable;
-  mgchashlistnode_t *nodes;
-  int i;
 
   if (size <= 0) {
 #ifdef MULTICORE
@@ -336,7 +332,6 @@ unsigned int mgchashResize_I(mgchashtable_t * tbl, unsigned int newsize) {
 
 //Delete the entire hash table
 void mgchashDelete(mgchashtable_t * tbl) {
-  int i;
   mgcliststruct_t *ptr=tbl->structs;
   while(ptr!=NULL) {
     mgcliststruct_t *next=ptr->next;
@@ -357,7 +352,7 @@ struct MGCHash * allocateMGCHash(int size) {
   thisvar=(struct MGCHash *)RUNMALLOC(sizeof(struct MGCHash));
   thisvar->size = size;
   thisvar->mask = ((size>>1)-1)<<1;
-  thisvar->bucket=(int *) RUNCALLOC(sizeof(unsigned int)*size);
+  thisvar->bucket=(unsigned INTPTR *) RUNCALLOC(sizeof(unsigned INTPTR)*size);
   //Set data counts
   return thisvar;
 }
@@ -376,8 +371,8 @@ int MGCHashadd(struct MGCHash * thisvar, unsigned INTPTR data) {
   // Rehash code
 
   unsigned int hashkey = (data>>GC_SHIFT_BITS)&thisvar->mask;
-  int * ptr = &thisvar->bucket[hashkey];
-  int ptrval= *ptr;
+  unsigned INTPTR * ptr = &thisvar->bucket[hashkey];
+  unsigned INTPTR ptrval= *ptr;
   if (ptrval == 0) {
     *ptr=data;
     return 1;
@@ -402,7 +397,7 @@ struct MGCHash * allocateMGCHash_I(int size) {
   thisvar=(struct MGCHash *)RUNMALLOC_I(sizeof(struct MGCHash));
   thisvar->mask = ((size>>1)-1)<<1;
   thisvar->size = size;
-  thisvar->bucket=(int *) RUNCALLOC_I(sizeof(int)*size);
+  thisvar->bucket=(unsigned INTPTR *) RUNCALLOC_I(sizeof(unsigned INTPTR)*size);
   return thisvar;
 }
 
@@ -415,7 +410,7 @@ int MGCHashcontains(struct MGCHash *thisvar, unsigned INTPTR data) {
   // Rehash code
 
   unsigned int hashkey = (data>>GC_SHIFT_BITS)&thisvar->mask;
-  int * ptr = &thisvar->bucket[hashkey];
+  unsigned INTPTR * ptr = &thisvar->bucket[hashkey];
 
   if (*ptr==data) {
     return 1;
index 3eb3610812bb6448f0ca95f78d48d99fca1689bf..ac10d684dde9d20f6574c347bfc6c588ac935a50 100644 (file)
@@ -1,3 +1,4 @@
+#include "mem.h"
 #include "gcqueue.h"
 
 struct pointerblock *gchead=NULL;
index 0f38d445d80b59eadbf023da7e7c864b2bc62574..2ddad8aeabeeb8eeb4f7e15ed622828f09728552 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef GCQUEUE_H
 #define GCQUEUE_H
 #include "stdio.h"
+#include "multicore.h"
 
 #ifdef MGC
 #include "interrupt.h"
@@ -35,7 +36,7 @@ extern struct lobjpointerblock *gclobjtail;
 extern int gclobjtailindex;
 extern struct lobjpointerblock *gclobjspare;
 
-static void gc_queueinit() {
+INLINE static void gc_queueinit() {
   // initialize queue
   if (gchead==NULL) {
     gcheadindex=gctailindex=0;
@@ -60,7 +61,7 @@ static void gc_queueinit() {
 ////////////////////////////////////////////////////////////////////
 // functions that should be invoked with interrupts off
 ////////////////////////////////////////////////////////////////////
-static void gc_enqueue_I(void * ptr) {
+INLINE static void gc_enqueue_I(void * ptr) {
   if (gcheadindex==NUMPTRS) {
     struct pointerblock * tmp;
     if (gcspare!=NULL) {
@@ -78,7 +79,7 @@ static void gc_enqueue_I(void * ptr) {
 }
 
 // dequeue and destroy the queue
-static void * gc_dequeue_I() {
+INLINE static void * gc_dequeue_I() {
   if (gctailindex==NUMPTRS) {
     struct pointerblock *tmp=gctail;
     gctail=gctail->next;
@@ -93,13 +94,13 @@ static void * gc_dequeue_I() {
   return gctail->ptrs[gctailindex++];
 } 
 
-static int gc_moreItems_I() {
+INLINE static int gc_moreItems_I() {
   return !((gchead==gctail)&&(gctailindex==gcheadindex));
 } 
 
 // should be invoked with interruption closed 
 // enqueue a large obj: start addr & length
-static void gc_lobjenqueue_I(void * ptr,
+INLINE static void gc_lobjenqueue_I(void * ptr,
                              unsigned int length,
                              unsigned int host) {
   if (gclobjheadindex==NUMLOBJPTRS) {
@@ -123,7 +124,7 @@ static void gc_lobjenqueue_I(void * ptr,
 } 
 
 // dequeue and destroy the queue
-static void * gc_lobjdequeue_I(unsigned int * length,
+INLINE static void * gc_lobjdequeue_I(unsigned int * length,
                                      unsigned int * host) {
   if (gclobjtailindex==NUMLOBJPTRS) {
     struct lobjpointerblock *tmp=gclobjtail;
@@ -147,14 +148,14 @@ static void * gc_lobjdequeue_I(unsigned int * length,
   return gclobjtail->lobjs[gclobjtailindex++];
 } 
 
-static int gc_lobjmoreItems_I() {
+INLINE static int gc_lobjmoreItems_I() {
   return !((gclobjhead==gclobjtail)&&(gclobjtailindex==gclobjheadindex));
 } 
 
 ////////////////////////////////////////////////////////////////////
 // functions that can be invoked in normal places
 ////////////////////////////////////////////////////////////////////
-static void gc_enqueue(void * ptr) {
+INLINE static void gc_enqueue(void * ptr) {
   BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
   if (gcheadindex==NUMPTRS) {
     struct pointerblock * tmp;
@@ -173,7 +174,7 @@ static void gc_enqueue(void * ptr) {
   BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
 }
 
-static void * gc_dequeue() {
+INLINE static void * gc_dequeue() {
   BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
   if (gctailindex==NUMPTRS) {
     struct pointerblock *tmp=gctail;
@@ -191,14 +192,14 @@ static void * gc_dequeue() {
   return r;
 } 
 
-static int gc_moreItems() {
+INLINE static int gc_moreItems() {
   BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
   int r = !((gchead==gctail)&&(gctailindex==gcheadindex));
   BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
   return r;
 }
 
-static void gc_lobjenqueue(void * ptr,
+INLINE static void gc_lobjenqueue(void * ptr,
                            unsigned int length,
                            unsigned int host) {
   BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
index 4c013a61dae267852058af03c5fc662d99e9020e..8386c6d6dc09f69bceefcaaa0f9a178efbebb542 100644 (file)
@@ -1,4 +1,4 @@
-#include "runtime.h"
+#include "multicoreruntime.h"
 #include "multicoremem.h"
 #include "multicoregarbage.h"
 #include "markbit.h"
index 8416a52731eee2af39fbfb1576c41fd98c01ac87..05bb2d8cba1054074ee31d0d0341622a284a071e 100644 (file)
@@ -87,6 +87,22 @@ void dumpSMem() {
 }
 #endif
 
+bool gc_checkCoreStatus() {
+  for(int i = 0; i < NUMCORES4GC; i++) {
+    if(gccorestatus[i]) {
+      return false;
+    }
+  }
+  return true;
+}
+
+void gc_resetCoreStatus() {
+  for(int i = 0; i < NUMCORES4GC; i++) {
+    gccorestatus[i] = 1;
+  }
+}
+
+
 void initmulticoregcdata() {
   bamboo_smem_zero_top = NULL;
   gcflag = false;
@@ -349,8 +365,8 @@ void gc_nocollect(struct garbagelist * stackptr) {
 void master_mark(struct garbagelist *stackptr) {
 
   GC_PRINTF("Start mark phase \n");
-  GC_SEND_MSG_1_TO_CLIENT(GCSTART);
   gc_status_info.gcphase = MARKPHASE;
+  GC_SEND_MSG_1_TO_CLIENT(GCSTART);
   // mark phase
 
   mark(stackptr);
@@ -418,7 +434,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;
 
@@ -456,6 +472,7 @@ void gc_master(struct garbagelist * stackptr) {
     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 aac5bebd0aa3af6a13c9c81a3ec74e8f221465a8..dc2ded21c1a5603a651b08a019c6e438eb4894ec 100644 (file)
@@ -6,6 +6,7 @@
 #include "multicorehelper.h"  // for mappings between core # and block #
 #include "structdefs.h"
 #include "multicoregcprofile.h"
+#include "gctypes.h"
 
 #ifdef GC_DEBUG
 #define GC_PRINTF tprintf
@@ -25,8 +26,6 @@
 // let each gc core to have one big block, this is very important
 // for the computation of NUMBLOCKS(s, n), DO NOT change this!
 
-typedef int block_t;
-
 typedef enum {
   INITPHASE = 0x0,         // 0x0
   MARKPHASE,               // 0x1
@@ -115,20 +114,10 @@ volatile unsigned int * gcmarktbl;
 
 void * gcbaseva; // base va for shared memory without reserved sblocks
 
-static bool gc_checkCoreStatus() {
-  for(int i = 0; i < NUMCORES4GC; i++) {
-    if(gccorestatus[i]) {
-      return false;
-    }
-  }  
-  return true;
-}
+bool gc_checkCoreStatus();
+
+void gc_resetCoreStatus();
 
-static void gc_resetCoreStatus() {
-  for(int i = 0; i < NUMCORES4GC; i++) {
-    gccorestatus[i] = 1;
-  }
-}
 
 
 /* Structure to keep track of free space in block */
index 394ea3aa990980e6a293b7a1196734eb9afd46a8..e52ace57a4037872300571123cb2439ca0569bc1 100644 (file)
@@ -1,4 +1,5 @@
 #ifdef MULTICORE_GC
+#include "structdefs.h"
 #include "multicoregccompact.h"
 #include "runtime_arch.h"
 #include "multicoreruntime.h"
@@ -90,7 +91,7 @@ void handleReturnMem_I(unsigned int cnum, void *heaptop) {
   }
 }
 
-void useReturnedMem(unsigned int corenum, block_t localblockindex) {
+void useReturnedMem(unsigned int retcorenum, block_t localblockindex) {
   for(int i=0;i<NUMCORES4GC;i++) {
     unsigned INTPTR requiredmem=gcrequiredmems[i];
     if (requiredmem) {
@@ -100,7 +101,7 @@ void useReturnedMem(unsigned int corenum, block_t localblockindex) {
 
 
       for(block_t nextlocalblocknum=localblockindex;nextlocalblocknum<numblockspercore;nextlocalblocknum++) {
-       unsigned INTPTR blocknum=BLOCKINDEX2(corenum, nextlocalblocknum);
+       unsigned INTPTR blocknum=BLOCKINDEX2(retcorenum, nextlocalblocknum);
        struct blockrecord * nextblockrecord=&allocationinfo.blocktable[blocknum];
        if (nextblockrecord->status==BS_FREE) {
          unsigned INTPTR freespace=nextblockrecord->freespace&~BAMBOO_CACHE_LINE_MASK;
@@ -174,7 +175,7 @@ void getSpaceRemotely(struct moveHelper *to, unsigned int minimumbytes) {
 
 void getSpace(struct moveHelper *to, unsigned int minimumbytes) {
   //need more space to compact into
-  if (to->localblocknum < gcblock2fill) {
+  if ((to->localblocknum+1) < gcblock2fill) {
     getSpaceLocally(to);
   } else {
     getSpaceRemotely(to, minimumbytes);
@@ -221,14 +222,14 @@ void compacthelper(struct moveHelper * orig,struct moveHelper * to) {
   }
 }
 
-void * checkNeighbors_I(int corenum, unsigned INTPTR requiredmem, unsigned INTPTR desiredmem) {
+void * checkNeighbors_I(int ncorenum, unsigned INTPTR requiredmem, unsigned INTPTR desiredmem) {
   int minblockindex=allocationinfo.lowestfreeblock/NUMCORES4GC;
   unsigned INTPTR threshold=(desiredmem<MINMEMORYCHUNKSIZE)? desiredmem: MINMEMORYCHUNKSIZE;
   unsigned INTPTR memcheck=requiredmem>threshold?requiredmem:threshold;
 
   for(block_t lblock=minblockindex;lblock<numblockspercore;lblock++) {
     for(int i=0;i<NUM_CORES2TEST;i++) {
-      int neighborcore=core2test[corenum][i];
+      int neighborcore=core2test[ncorenum][i];
       if (neighborcore!=-1) {
        block_t globalblockindex=BLOCKINDEX2(neighborcore, lblock);
        struct blockrecord * block=&allocationinfo.blocktable[globalblockindex];
@@ -511,7 +512,6 @@ unsigned int compactblocks(struct moveHelper * orig, struct moveHelper * to) {
        return length;
       }
       //good to move objects and update pointers
-      //tprintf("Decided to compact obj %x to %x\n", origptr, toptr);
 
       gcmappingtbl[OBJMAPPINGINDEX(origptr)]=toptr;
 
@@ -532,8 +532,8 @@ void compact() {
   BAMBOO_ASSERT(COMPACTPHASE == gc_status_info.gcphase);
   
   // initialize structs for compacting
-  struct moveHelper orig={0,NULL,NULL,0,NULL,0,0,0,0};
-  struct moveHelper to={0,NULL,NULL,0,NULL,0,0,0,0};
+  struct moveHelper orig;
+  struct moveHelper to;
   initOrig_Dst(&orig, &to);
 
   CACHEADAPT_SAMPLING_DATA_REVISE_INIT(&orig, &to);
@@ -586,6 +586,41 @@ void master_compact() {
   while(!gc_checkCoreStatus())
     ;
 
+#ifdef GC_DEBUG
+  void *nextvalid=gcbaseva;
+  for(void *tmp=gcbaseva; tmp<gcbaseva+BAMBOO_SHARED_MEM_SIZE;tmp+=ALIGNMENTSIZE) {
+    unsigned int objlength=getMarkedLength(tmp);
+    void *forwarding=gcmappingtbl[OBJMAPPINGINDEX(tmp)];
+    if (tmp>=nextvalid&&((objlength!=0)!=(forwarding!=NULL))) {
+      tprintf("Maps disagree tmp=%x olength=%u forwarding=%x\n",tmp, objlength, forwarding);
+    }
+    if (tmp<nextvalid&&forwarding!=NULL) {
+      tprintf("Weird forwarding pointer\n");
+    }
+    if (tmp>=nextvalid&&(objlength!=0||forwarding!=NULL)) {
+      unsigned int length=ALIGNSIZETOBYTES(objlength);
+      unsigned int size;
+      unsigned int type;
+      nextvalid=tmp+length;
+      gettype_size(tmp, &type, &size);
+      size=((size-1)&(~(ALIGNMENTSIZE-1)))+ALIGNMENTSIZE;
+      if (size!=length) {
+       tprintf("Bad size in bitmap: tmp=%x length=%u size=%u type=%u\n", tmp, length, size, type);
+      }
+      block_t blockindex;
+      BLOCKINDEX(blockindex, forwarding);
+      struct blockrecord * block=&allocationinfo.blocktable[blockindex];
+      void *blockptr=OFFSET2BASEVA(blockindex)+gcbaseva;
+
+      if (block->status==BS_FREE) {
+       if (forwarding>(blockptr+block->usedspace)) {
+         tprintf("Pointer references free space forwarding=%x tmp=%x length=%u type=%u blockindex=%u, baseptr=%x, usedspace=%u, status=%u\n", forwarding, tmp, length, type,blockindex, blockptr, block->usedspace, block->status);
+       }
+      }
+    }
+  }
+#endif
+
   GCPROFILE_ITEM();
 
   //just in case we didn't get blocks back...
index 8daf58f5a9744ce92d2903165514686155438764..851363323f68203381dcb97952b5d83347bdd6c9 100644 (file)
@@ -3,6 +3,7 @@
 
 #ifdef MULTICORE_GC
 #include "multicore.h"
+#include "gctypes.h"
 
 struct moveHelper {
   unsigned int localblocknum;   // local block num for heap
@@ -14,7 +15,20 @@ struct moveHelper {
 #endif
 };
 
+int gc_countRunningCores();
 void initOrig_Dst(struct moveHelper * orig,struct moveHelper * to);
+void getSpaceLocally(struct moveHelper *to);
+void handleReturnMem_I(unsigned int cnum, void *heaptop);
+void useReturnedMem(unsigned int corenum, block_t localblockindex);
+void handleReturnMem(unsigned int cnum, void *heaptop);
+void getSpaceRemotely(struct moveHelper *to, unsigned int minimumbytes);
+void getSpace(struct moveHelper *to, unsigned int minimumbytes);
+void * checkNeighbors_I(int corenum, unsigned INTPTR requiredmem, unsigned INTPTR desiredmem);
+void * globalSearch_I(unsigned int topblock, unsigned INTPTR requiredmem, unsigned INTPTR desiredmem);
+void handleOneMemoryRequest(int core, unsigned int lowestblock);
+void handleMemoryRequests_I();
+void * gcfindSpareMem_I(unsigned INTPTR requiredmem, unsigned INTPTR desiredmem,unsigned int requiredcore);
+void master_compact();
 void compacthelper(struct moveHelper * orig,struct moveHelper * to);
 void compact();
 void compact_master(struct moveHelper * orig, struct moveHelper * to);
index cd336e739b93a41b6833a170127347cc7e4d9f74..66b863c383dc3155ab461439f447bd9f7170ef54 100644 (file)
@@ -1,4 +1,5 @@
 #ifdef MULTICORE_GC
+#include "multicoregccompact.h"
 #include "multicoregcflush.h"
 #include "multicoreruntime.h"
 #include "ObjectHash.h"
@@ -27,11 +28,13 @@ 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);if (!ISVALIDPTR(obj)) tprintf("Mapping problem for object %x -> %x, mark=%u, line=%u\n", updatetmpptr, obj, getMarkedLength(updatetmpptr),__LINE__);}}
+#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__);}}
 
-#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__);}
+#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) {
+void updategarbagelist(struct garbagelist *listptr) {
   for(;listptr!=NULL; listptr=listptr->next) {
     for(int i=0; i<listptr->size; i++) {
       UPDATEOBJ(listptr->array[i]);
@@ -39,7 +42,7 @@ INLINE void updategarbagelist(struct garbagelist *listptr) {
   }
 }
 
-INLINE void updateRuntimePtrs(struct garbagelist * stackptr) {
+void updateRuntimePtrs(struct garbagelist * stackptr) {
   // update current stack
   updategarbagelist(stackptr);
 
@@ -123,7 +126,7 @@ INLINE void updateRuntimePtrs(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
-        UPDATEOBJNONNULL(bamboo_thread_queue[4+start]);
+        UPDATEOBJNONNULL(*((void **)&bamboo_thread_queue[4+start]));
         start = (start+1)&bamboo_max_thread_num_mask;
       }
     }
@@ -132,7 +135,7 @@ INLINE void updateRuntimePtrs(struct garbagelist * stackptr) {
 #endif
 }
 
-INLINE void updatePtrsInObj(void * ptr) {
+void updatePtrsInObj(void * ptr) {
   int type = ((int *)(ptr))[0];
   // scan all pointers in ptr
   unsigned int * pointer=pointerarray[type];
@@ -184,6 +187,7 @@ void * updateblocks(struct moveHelper * orig, struct moveHelper * to) {
   unsigned INTPTR origendoffset=ALIGNTOTABLEINDEX((unsigned INTPTR)(origbound-gcbaseva));
   unsigned int objlength;
 
+
   while(origptr<origbound) {
     //Try to skip over stuff fast first
     unsigned INTPTR offset=(unsigned INTPTR) (origptr-gcbaseva);
@@ -215,16 +219,37 @@ void * updateblocks(struct moveHelper * orig, struct moveHelper * to) {
        return dstptr;
       }
 
+#ifdef GC_DEBUG
+      {
+       unsigned int size;
+       unsigned int type;
+       gettype_size(origptr, &type, &size);
+       size=((size-1)&(~(ALIGNMENTSIZE-1)))+ALIGNMENTSIZE;
+       if (size!=length) {
+         tprintf("BAD SIZE %u!=%u t=%u %x->%x\n",size,length,type, origptr, dstptr);
+         tprintf("origbase=%x origbound=%x\n",orig->base, origbound);
+         tprintf("tobase=%x tobound=%x\n",tobase, tobound);
+       }
+      }
+
+      if (dstptr>origptr) {
+       tprintf("move up %x -> %x\n", origptr, dstptr);
+      }
+      if (tmplast>origptr) {
+       tprintf("Overlap with last object\n");
+      }
+
+      tmplast=dstptr+length;
+#endif
+
       /* Move the object */
-      if(origptr >= endtoptr||dstptr >= origptr+length) {
+      if(origptr < endtoptr&&dstptr < origptr+length) {
         memmove(dstptr, origptr, length);
       } else if (origptr!=dstptr) {
        //no need to copy if the source & dest are equal....
         memcpy(dstptr, origptr, length);
       }
 
-      //tprintf("Moving object %x to %x with length %u\n", origptr, dstptr, length);
-      
       /* Update the pointers in the object */
       updatePtrsInObj(dstptr);
 
@@ -265,15 +290,15 @@ void updatehelper(struct moveHelper * orig,struct moveHelper * to) {
       //need more memory to compact into
       block_t blockindex;
       BLOCKINDEX(blockindex, dstptr);
-      unsigned int corenum;
-      BLOCK2CORE(corenum, blockindex);
+      unsigned int blockcore;
+      BLOCK2CORE(blockcore, blockindex);
       to->base=OFFSET2BASEVA(blockindex)+gcbaseva;
       to->bound=BOUNDPTR(blockindex)+gcbaseva;
-      if (corenum!=BAMBOO_NUM_OF_CORE) {
+      if (blockcore!=BAMBOO_NUM_OF_CORE) {
        //we have someone elses memory...need to ask to use it
        //first set flag to false
        blockgranted=false;
-       send_msg_3(corenum,GCREQBLOCK, BAMBOO_NUM_OF_CORE, to->bound);
+       send_msg_3(blockcore,GCREQBLOCK, BAMBOO_NUM_OF_CORE, to->bound);
        //wait for permission
        while(!blockgranted)
          ;
@@ -298,8 +323,8 @@ void updatehelper(struct moveHelper * orig,struct moveHelper * to) {
 
 void updateheap() {
   // initialize structs for compacting
-  struct moveHelper orig={0,NULL,NULL,0,NULL,0,0,0,0};
-  struct moveHelper to={0,NULL,NULL,0,NULL,0,0,0,0};
+  struct moveHelper orig;
+  struct moveHelper to;
   initOrig_Dst(&orig, &to);
   updatehelper(&orig, &to);
 }
index f4b56bfb3feee9038a1f47c7e9a884eb5f1979d7..9ae87258b8b9e39ee77683acefe783f9d0d5f558 100644 (file)
@@ -5,6 +5,6 @@
 #include "multicore.h"
 #include "runtime.h"
 
-void flush(struct garbagelist * stackptr);
+void update(struct garbagelist * stackptr);
 #endif // MULTICORE_GC
 #endif // BAMBOO_MULTICORE_GC_FLUSH_H
index 526941742b0402aaf75288489ea91b299185b892..ea542af9ae32fb03b9fc991f26e664502572b2ea 100644 (file)
@@ -23,7 +23,7 @@ extern struct global_defs_t * global_defs_p;
 extern struct lockvector bamboo_threadlocks;
 #endif
 
-INLINE void gettype_size(void * ptr, int * ttype, unsigned int * tsize) {
+void gettype_size(void * ptr, int * ttype, unsigned int * tsize) {
   int type = ((int *)ptr)[0];
   if(type < NUMCLASSES) {
     // a normal object
@@ -39,7 +39,7 @@ INLINE void gettype_size(void * ptr, int * ttype, unsigned int * tsize) {
   } 
 }
 
-INLINE bool isLarge(void * ptr, int * ttype, unsigned int * tsize) {
+bool isLarge(void * ptr, int * ttype, unsigned int * tsize) {
   // check if a pointer refers to a large object
   gettype_size(ptr, ttype, tsize);
   unsigned INTPTR blocksize = (((unsigned INTPTR)(ptr-gcbaseva)) < BAMBOO_LARGE_SMEM_BOUND)? BAMBOO_SMEM_SIZE_L:BAMBOO_SMEM_SIZE;
@@ -183,7 +183,7 @@ void tomark(struct garbagelist * stackptr) {
 #endif
 }
 
-INLINE void scanPtrsInObj(void * ptr, int type) {
+void scanPtrsInObj(void * ptr, int type) {
   // scan all pointers in ptr
   unsigned int * pointer = pointerarray[type];
   if (pointer==0) {
@@ -233,7 +233,6 @@ void mark(struct garbagelist * stackptr) {
 
   unsigned int isize = 0;
   gc_status_info.gcbusystatus = true;
-
   // mark phase
   while(MARKPHASE == gc_status_info.gcphase) {
     int counter = 0;
index 3bed08a57e5eaa8e5b24b25253320b14e0ef7da3..59a3c63a958f231ac5a4eee8f18181c7db843ce2 100644 (file)
@@ -3,11 +3,11 @@
 #ifdef MULTICORE_GC
 #include "multicore.h"
 
-INLINE void gettype_size(void * ptr, int * ttype, unsigned int * tsize);
-INLINE bool isLarge(void * ptr, int * ttype, unsigned int * tsize);
-INLINE void markgarbagelist(struct garbagelist * listptr);
-INLINE void tomark(struct garbagelist * stackptr);
-INLINE void scanPtrsInObj(void * ptr, int type);
+void gettype_size(void * ptr, int * ttype, unsigned int * tsize);
+bool isLarge(void * ptr, int * ttype, unsigned int * tsize);
+void markgarbagelist(struct garbagelist * listptr);
+void tomark(struct garbagelist * stackptr);
+void scanPtrsInObj(void * ptr, int type);
 void markObj(void * objptr);
 void mark(struct garbagelist * stackptr);
 
index 0daec7d22bb6c727afbfe9885e4ae0238c7d3a23..97b2b83caba498012e8e70db082bb361c33136b8 100644 (file)
@@ -1,6 +1,7 @@
 #ifdef MULTICORE_GC
 #ifdef GC_PROFILE
 #include "multicoregcprofile.h"
+#include "structdefs.h"
 #include "runtime_arch.h"
 #include "mem.h"
 
index 0a66c83e0e549a0b6a93cbdcd5109d55a4cdec70..31e096fe0e8a1718a2a0bfd588cd28fb8a9c4142 100644 (file)
 // NOTE: this file should be changed to be generated automatically
-
 #ifndef BAMBOO_MULTICORE_HELPER_H
 #define BAMBOO_MULTICORE_HELPER_H
+#include "structdefs.h"
 
-#ifdef GC_1
-// NUMCORES4GC = 1
-static unsigned int gc_core2block[2] = {0,1};
-
-static unsigned int gc_block2core[2] = { 0,  0};
-#elif defined GC_2
-// NUMCORES4GC = 2
-static unsigned int gc_core2block[4] = {
-  0,3,  
-  1,2
-};
-
-static unsigned int gc_block2core[4] = {
-  0, 1, 
-  1, 0
-};
-#elif defined GC_4
-// NUMCORES4GC = 4
-static unsigned int gc_core2block[8] = {
-  0,7,  3,4,  
-  1,6,  2,5
-};
-
-static unsigned int gc_block2core[8] = {
-  0, 2, 3, 1,
-  1, 3, 2, 0
-};
-#elif defined GC_8
-// NUMCORES4GC = 8
-static unsigned int gc_core2block[16] = {
-  0,15,   3,12,   4,11,   7,8, 
-  1,14,   2,13,   5,10,   6,9
-};
-
-static unsigned int gc_block2core[16] = {
-  0,  4,  5,  1,  2,  6,  7,  3,
-  3,  7,  6,  2,  1,  5,  4,  0
-};
-#elif defined GC_16
-// NUMCORES4GC = 16
-static unsigned int gc_core2block[32] = {
-  0,31,   7,24,   8,23,  15,16,
-  1,30,   6,25,   9,22,  14,17,
-  2,29,   5,26,  10,21,  13,18,
-  3,28,   4,27,  11,20,  12,19
-};
-
-static unsigned int gc_block2core[32] = {
-  0,  4,  8, 12, 13,  9,  5,  1,
-  2,  6, 10, 14, 15, 11,  7,  3,
-  3,  7, 11, 15, 14, 10,  6,  2,
-  1,  5,  9, 13, 12,  8,  4,  0
-};
-#elif defined GC_32
-// NUMCORES4GC = 32
-static unsigned int gc_core2block[64] = {
-  0,63,  15,48,  16,47,  31,32,   
-  1,62,  14,49,  17,46,  30,33,
-  2,61,  13,50,  18,45,  29,34, 
-  3,60,  12,51,  19,44,  28,35,
-  4,59,  11,52,  20,43,  27,36,  
-  5,58,  10,53,  21,42,  26,37,
-  6,57,   9,54,  22,41,  25,38,  
-  7,56,   8,55,  23,40,  24,39
-};
-
-static unsigned int gc_block2core[64] = {
-  0,  4,  8, 12, 16, 20, 24, 28, 29, 25, 21, 17, 13,  9,  5,  1,
-  2,  6, 10, 14, 18, 22, 26, 30, 31, 27, 23, 19, 15, 11,  7,  3,
-  3,  7, 11, 15, 19, 23, 27, 31, 30, 26, 22, 18, 14, 10,  6,  2,
-  1,  5,  9, 13, 17, 21, 25, 29, 28, 24, 20, 16, 12,  8,  4,  0
-};
-#elif defined GC_48
-// NUMCORES4GC = 50
-static unsigned int gc_core2block[96] = {
-  0,95,  15,80,  16,79,  31,64,  32,63,  47,48,
-  1,94,  14,81,  17,78,  30,65,  33,62,  46,49,
-  2,93,  13,82,  18,77,  29,66,  34,61,  45,50,
-  3,92,  12,83,  19,76,  28,67,  35,60,  44,51,
-  4,91,  11,84,  20,75,  27,68,  36,59,  43,52,
-  5,90,  10,85,  21,74,  26,69,  37,58,  42,53,
-  6,89,   9,86,  22,73,  25,70,  38,57,  41,54,
-  7,88,   8,87,  23,72,  24,71,  39,56,  40,55
-};
-
-static unsigned int gc_block2core[96] = {
-  0,  6, 12, 18, 24, 30, 36, 42, 43, 37, 31, 25, 19, 13,  7,  1,
-  2,  8, 14, 20, 26, 32, 38, 44, 45, 39, 33, 27, 21, 15,  9,  3,
-  4, 10, 16, 22, 28, 34, 40, 46, 47, 41, 35, 29, 23, 17, 11,  5,
-  5, 11, 17, 23, 29, 35, 41, 47, 46, 40, 34, 28, 22, 16, 10,  4,
-  3,  9, 15, 21, 27, 33, 39, 45, 44, 38, 32, 26, 20, 14,  8,  2,
-  1,  7, 13, 19, 25, 31, 37, 43, 42, 36, 30, 24, 18, 12,  6,  0
-};
-#elif defined GC_50
-// NUMCORES4GC = 50
-static unsigned int gc_core2block[100] = {
-  0,99,  15,84,  16,83,  31,68,  32,67,  47,52,
-  1,98,  14,85,  17,82,  30,69,  33,66,  46,53,
-  2,97,  13,86,  18,81,  29,70,  34,65,  45,54,
-  3,96,  12,87,  19,80,  28,71,  35,64,  44,55,
-  4,95,  11,88,  20,79,  27,72,  36,63,  43,56,
-  5,94,  10,89,  21,78,  26,73,  37,62,  42,57,
-  6,93,   9,90,  22,77,  25,74,  38,61,  41,58,  48,51,
-  7,92,   8,91,  23,76,  24,75,  39,60,  40,59,  49,50
-};
-
-static unsigned int gc_block2core[100] = {
-  0,  6, 12, 18, 24, 30, 36, 43, 44, 37, 31, 25, 19, 13,  7,  1,
-  2,  8, 14, 20, 26, 32, 38, 45, 46, 39, 33, 27, 21, 15,  9,  3,
-  4, 10, 16, 22, 28, 34, 40, 47, 48, 41, 35, 29, 23, 17, 11,  5,
-                         42, 49, 49, 42,
-  5, 11, 17, 23, 29, 35, 41, 48, 47, 40, 34, 28, 22, 16, 10,  4,
-  3,  9, 15, 21, 27, 33, 39, 46, 45, 38, 32, 26, 20, 14,  8,  2,
-  1,  7, 13, 19, 25, 31, 37, 44, 43, 36, 30, 24, 18, 12,  6,  0
-};
-#elif defined GC_56
-// NUMCORES4GC = 56
-static unsigned int gc_core2block[112] = {
-  0,111,  15, 96,  16,95,  31,80,  32,79,  47,64,  48,63,
-  1,110,  14, 97,  17,94,  30,81,  33,78,  46,65,  49,62,
-  2,109,  13, 98,  18,93,  29,82,  34,77,  45,66,  50,61,
-  3,108,  12, 99,  19,92,  28,83,  35,76,  44,67,  51,60,
-  4,107,  11,100,  20,91,  27,84,  36,75,  43,68,  52,59,
-  5,106,  10,101,  21,90,  26,85,  37,74,  42,69,  53,58,
-  6,105,   9,102,  22,89,  25,86,  38,73,  41,70,  54,57,
-  7,104,   8,103,  23,88,  24,87,  39,72,  40,71,  55,56
-};
-
-static unsigned int gc_block2core[112] = {
-  0,  7, 14, 21, 28, 35, 42, 49, 50, 43, 36, 29, 22, 15,  8,  1,
-  2,  9, 16, 23, 30, 37, 44, 51, 52, 45, 38, 31, 24, 17, 10,  3,
-  4, 11, 18, 25, 32, 39, 46, 53, 54, 47, 40, 33, 26, 19, 12,  5,
-  6, 13, 20, 27, 34, 41, 48, 55, 55, 48, 41, 34, 27, 20, 13,  6,
-  5, 12, 19, 26, 33, 40, 47, 54, 53, 46, 39, 32, 25, 18, 11,  4,
-  3, 10, 17, 24, 31, 38, 45, 52, 51, 44, 37, 30, 23, 16,  9,  2,
-  1,  8, 15, 22, 29, 36, 43, 50, 49, 42, 35, 28, 21, 14,  7,  0
-};
-#elif defined GC_62
-// NUMCORES4GC = 62
-static unsigned int gc_core2block[124] = {
-  0,123,  15,108,  16,107,  31,92,  32,91,  47,76,
-  1,122,  14,109,  17,106,  30,93,  33,90,  46,77,  48,75,  61,62,
-  2,121,  13,110,  18,105,  29,94,  34,89,  45,78,  49,74,  60,63,
-  3,120,  12,111,  19,104,  28,95,  35,88,  44,79,  50,73,  59,64,
-  4,119,  11,112,  20,103,  27,96,  36,87,  43,80,  51,72,  58,65,
-  5,118,  10,113,  21,102,  26,97,  37,86,  42,81,  52,71,  57,66,
-  6,117,   9,114,  22,101,  25,98,  38,85,  41,82,  53,70,  56,67,
-  7,116,   8,115,  23,100,  24,99,  39,84,  40,83,  54,69,  55,68
-};
+extern unsigned int gc_core2block[2*NUMCORES4GC];
+extern unsigned int gc_block2core[2*NUMCORES4GC];
 
-static unsigned int gc_block2core[124] = {
-  0,  6, 14, 22, 30, 38, 46, 54, 55, 47, 39, 31, 23, 15,  7,  1,
-  2,  8, 16, 24, 32, 40, 48, 56, 57, 49, 41, 33, 25, 17,  9,  3,
-  4, 10, 18, 26, 34, 42, 50, 58, 59, 51, 43, 35, 27, 19, 11,  5,
-  12, 20, 28, 36, 44, 52, 60, 61, 53, 45, 37, 29, 21, 13,
-  13, 21, 29, 37, 45, 53, 61, 60, 52, 44, 36, 28, 20, 12,
-  5, 11, 19, 27, 35, 43, 51, 59, 58, 50, 42, 34, 26, 18, 10,  4,
-  3,  9, 17, 25, 33, 41, 49, 57, 56, 48, 40, 32, 24, 16,  8,  2,
-  1,  7, 15, 23, 31, 39, 47, 55, 54, 46, 38, 30, 22, 14,  6,  0
-};
-#endif
 
 #endif // BAMBOO_MULTICORE_HELPER_H
index af942f81acb52a8fcbc1cbdb41107da4c036cf4c..0b04b03771541d71481caa663e99134d04018692 100644 (file)
@@ -1,17 +1,13 @@
-#ifdef MULTICORE
+#if defined(MULTICORE)&&defined(MULTICORE_GC)
 #include "runtime_arch.h"
 #include "multicoreruntime.h"
-
-#ifdef MULTICORE_GC
 #include "multicoregarbage.h"
 #include "multicorehelper.h"
 #include "multicoremem_helper.h"
 
 // Only allocate local mem chunks to each core.
 // If a core has used up its local shared memory, start gc.
-void * localmalloc_I(int coren,
-                     unsigned int memcheck,
-                     int * allocsize) {
+void * localmalloc_I(int coren, unsigned INTPTR memcheck, unsigned INTPTR * allocsize) {
   for(block_t localblocknum=0;localblocknum<GCNUMLOCALBLOCK;localblocknum++) {
     block_t searchblock=BLOCKINDEX2(coren, localblocknum);
     if (searchblock>=GCNUMBLOCK)
@@ -38,9 +34,7 @@ void * localmalloc_I(int coren,
 // Allocate the local shared memory to each core with the highest priority,
 // if a core has used up its local shared memory, try to allocate the 
 // shared memory that belong to its neighbours, if also failed, start gc.
-void * fixedmalloc_I(int coren,
-                     unsigned int memcheck,
-                     int * allocsize) {
+void * fixedmalloc_I(int coren, unsigned INTPTR memcheck, unsigned INTPTR * allocsize) {
   //try locally first
   void * mem=localmalloc_I(coren,memcheck,allocsize);
   if (mem!=NULL)
@@ -52,7 +46,7 @@ void * fixedmalloc_I(int coren,
       int neighborcore=core2test[coren][i];
       if (neighborcore!=-1) {
        block_t globalblockindex=BLOCKINDEX2(neighborcore, lblock);
-       if (globalblockindex>=GCNUMBLOCK)
+       if (globalblockindex>=GCNUMBLOCK||globalblockindex<0)
          return NULL;
        struct blockrecord * block=&allocationinfo.blocktable[globalblockindex];
        if (block->status==BS_FREE) {
@@ -81,9 +75,7 @@ void * fixedmalloc_I(int coren,
 // current memory allocation rate, if it has already reached the threshold,
 // start gc, otherwise, allocate the shared memory globally.  If all the 
 // shared memory has been used up, start gc.
-void * mixedmalloc_I(int coren,
-                     int isize,
-                     int * allocsize) {
+void * mixedmalloc_I(int coren, unsigned INTPTR isize, unsigned INTPTR * allocsize) {
   void * mem=fixedmalloc_I(coren,isize,allocsize);
   if (mem!=NULL)
     return mem;
@@ -95,7 +87,7 @@ void * mixedmalloc_I(int coren,
 
 // Allocate all the memory chunks globally, do not consider the host cores
 // When all the shared memory are used up, start gc.
-void * globalmalloc_I(int coren, unsigned INTPTR memcheck, int * allocsize) {
+void * globalmalloc_I(int coren, unsigned INTPTR memcheck, unsigned INTPTR * allocsize) {
   block_t firstfree=NOFREEBLOCK;
   block_t lowestblock=allocationinfo.lowestfreeblock;
   for(block_t searchblock=lowestblock;searchblock<GCNUMBLOCK;searchblock++) {
@@ -120,7 +112,7 @@ void * globalmalloc_I(int coren, unsigned INTPTR memcheck, int * allocsize) {
   return NULL;
 } 
 
-void * smemalloc(int coren, int isize, int * allocsize) {
+void * smemalloc(int coren, unsigned INTPTR isize, unsigned INTPTR * allocsize) {
   BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
   void *retval=smemalloc_I(coren, isize, allocsize);
   BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
@@ -128,7 +120,7 @@ void * smemalloc(int coren, int isize, int * allocsize) {
 }
 
 // malloc from the shared memory
-void * smemalloc_I(int coren, int isize, int * allocsize) {
+void * smemalloc_I(int coren, unsigned INTPTR isize, unsigned INTPTR * allocsize) {
 #ifdef SMEML
   void *mem = localmalloc_I(coren, isize, allocsize);
 #elif defined(SMEMF)
@@ -155,15 +147,12 @@ void * smemalloc_I(int coren, int isize, int * allocsize) {
         GC_SEND_MSG_1_TO_CLIENT(GCSTARTPRE);
       }
     }
-    return NULL;
   }
   return mem;
 }
 #else
 // malloc from the shared memory
-void * smemalloc_I(int coren,
-                   int size,
-                   int * allocsize) {
+void * smemalloc_I(int coren, unsigned INTPTR size, unsigned INTPTR * allocsize) {
   void * mem = NULL;
   int toallocate = (size>(BAMBOO_SMEM_SIZE)) ? (size) : (BAMBOO_SMEM_SIZE);
   if(toallocate > bamboo_free_smem_size) {
@@ -182,6 +171,4 @@ void * smemalloc_I(int coren,
   }
   return mem;
 } 
-#endif // MULTICORE_GC
-
-#endif // MULTICORE
+#endif
index 010c9e897cf639b2d5ff894e5836f6ae49e62e35..44611f2df52e098d69c646ed56bbe02d56316187 100644 (file)
@@ -42,7 +42,7 @@
 #ifdef GC_LARGESHAREDHEAP
 #define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(2+24)))
 #elif defined MGC
-#define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(72))) // 72M per core
+#define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*72)) // 72M per core
 #else
 #define BAMBOO_NUM_BLOCKS ((unsigned int)((GC_BAMBOO_NUMCORES)*(2+14)))
 #endif
@@ -121,6 +121,14 @@ volatile bool smemflag;
 //Pointer to new block of memory after request
 volatile void * bamboo_cur_msp;
 //Number of bytes in new block of memory
-volatile int bamboo_smem_size;
+volatile unsigned INTPTR bamboo_smem_size;
+
+void * localmalloc_I(int coren, unsigned INTPTR memcheck, unsigned INTPTR * allocsize);
+void * fixedmalloc_I(int coren, unsigned INTPTR memcheck, unsigned INTPTR * allocsize);
+void * mixedmalloc_I(int coren, unsigned INTPTR isize, unsigned INTPTR * allocsize);
+void * globalmalloc_I(int coren, unsigned INTPTR memcheck, unsigned INTPTR * allocsize);
+void * smemalloc(int coren, unsigned INTPTR isize, unsigned INTPTR * allocsize);
+void * smemalloc_I(int coren, unsigned INTPTR isize, unsigned INTPTR * allocsize);
+
 
 #endif // BAMBOO_MULTICORE_MEM_H
index 16bc13b2762a7e3dc4d39f91cfd0dae417728626..def4fbd28ca18e777b6642a9deb746302f90cec7 100644 (file)
@@ -19,11 +19,11 @@ void buildCore2Test() {
          //bad coordinate
          core2test[i][index]=-1;
        } else {
-         int corenum=BAMBOO_CORE(x,y);
-         if (corenum<0||corenum>=NUMCORES4GC) {
+         int blockcorenum=BAMBOO_CORE(x,y);
+         if (blockcorenum<0||blockcorenum>=NUMCORES4GC) {
            core2test[i][index]=-1;
          } else {
-           core2test[i][index]=corenum;
+           core2test[i][index]=blockcorenum;
          }
        }
        index++;
index 20b2bc9b7a1a8720952ffb25c31d0745e752c89f..0a54e09d675f4cd0579adbe919b23f6701c309d6 100644 (file)
@@ -64,7 +64,7 @@ int msgsizearray[] = {
   -1 //MSGEND
 };
 
-INLINE unsigned int checkMsgLength_I(unsigned int realtype) {
+unsigned int checkMsgLength_I(unsigned int realtype) {
 #if (defined(TASK)||defined(MULTICORE_GC))
   unsigned int type = realtype & 0xff;
 #else
@@ -363,14 +363,14 @@ void processmsg_memrequest_I() {
     // either not doing GC or the master core has decided to stop GC but 
     // // still sending msgs to other cores to inform them to stop the GC
 #endif
-    int allocsize = 0;
+    unsigned INTPTR allocsize = 0;
     void * mem = smemalloc_I(data2, data1, &allocsize);
     if(mem != NULL) {
       // send the start_va to request core, cache the msg first
       if(BAMBOO_CHECK_SEND_MODE()) {
-        cache_msg_3_I(data2,MEMRESPONSE,mem,allocsize);
+        cache_msg_3_I(data2,MEMRESPONSE,(unsigned INTPTR) mem,allocsize);
       } else {
-        send_msg_3_I(data2,MEMRESPONSE,mem,allocsize);
+        send_msg_3_I(data2,MEMRESPONSE,(unsigned INTPTR) mem,allocsize);
       }
     } //else if mem == NULL, the gcflag of the startup core has been set
     // and all the other cores have been informed to start gc
@@ -380,7 +380,7 @@ void processmsg_memrequest_I() {
 }
 
 void processmsg_memresponse_I() {
-  void * memptr = msgdata[msgdataindex];
+  void * memptr =(void *) msgdata[msgdataindex];
   MSG_INDEXINC_I();
   unsigned int numbytes = msgdata[msgdataindex];
   MSG_INDEXINC_I();
@@ -490,7 +490,7 @@ void processmsg_gcfinishinit_I() {
 void processmsg_reqblock_I() {
   int cnum=msgdata[msgdataindex];
   MSG_INDEXINC_I();
-  void * topptr=msgdata[msgdataindex];
+  void * topptr= (void *)msgdata[msgdataindex];
   MSG_INDEXINC_I();
   if (topptr<=update_origblockptr) {
     //send message
@@ -512,19 +512,19 @@ void processmsg_grantblock_I() {
 
 
 void processmsg_gcfinishmark_I() {
-  int data1 = msgdata[msgdataindex];
+  int cnum = msgdata[msgdataindex];
   MSG_INDEXINC_I();
-  int data2 = msgdata[msgdataindex];
+  int nsend = msgdata[msgdataindex];
   MSG_INDEXINC_I();
-  int data3 = msgdata[msgdataindex];
+  int nrecv = msgdata[msgdataindex];
   MSG_INDEXINC_I();
   // received a mark phase finish msg
   BAMBOO_ASSERT(BAMBOO_NUM_OF_CORE == STARTUPCORE);
-  BAMBOO_ASSERT(gc_status_info.gcphase = MARKPHASE);
+  BAMBOO_ASSERT(gc_status_info.gcphase == MARKPHASE);
 
   // all cores should do mark
-  if(data1 < NUMCORESACTIVE) {
-    gccorestatus[data1] = 0;
+  if(cnum < NUMCORESACTIVE) {
+    gccorestatus[cnum] = 0;
     int entry_index = 0;
     if(waitconfirm)  {
       // phase 2
@@ -533,8 +533,8 @@ void processmsg_gcfinishmark_I() {
       // phase 1
       entry_index = gcnumsrobjs_index;
     }
-    gcnumsendobjs[entry_index][data1] = data2;
-    gcnumreceiveobjs[entry_index][data1] = data3;
+    gcnumsendobjs[entry_index][cnum] = nsend;
+    gcnumreceiveobjs[entry_index][cnum] = nrecv;
   }
 }
  
@@ -569,9 +569,9 @@ void processmsg_gcfinishcompact_I() {
   void * startaddr=handlegcfinishcompact_I(cnum, bytesneeded, maxbytesneeded);
   if (startaddr) {
     if(BAMBOO_CHECK_SEND_MODE()) {
-      cache_msg_2_I(cnum,GCMOVESTART,startaddr);
+      cache_msg_2_I(cnum,GCMOVESTART,(unsigned INTPTR)startaddr);
     } else {
-      send_msg_2_I(cnum,GCMOVESTART,startaddr);
+      send_msg_2_I(cnum,GCMOVESTART,(unsigned INTPTR)startaddr);
     }
   }
 }
@@ -661,7 +661,7 @@ void processmsg_gclobjinfo_I(unsigned int msglength) {
 
   // large obj info here
   for(int k = 3; k < msglength; k+=2) {
-    int lobj = msgdata[msgdataindex];
+    void * lobj = (void *) msgdata[msgdataindex];
     MSG_INDEXINC_I();  
     int length = msgdata[msgdataindex];
     MSG_INDEXINC_I();   
index 0005e18043602dcfb4ccae2b2674d4edb20d2be9..5c5c092052214309571c276cb8e09cf15a30f4b4 100644 (file)
@@ -231,9 +231,66 @@ int receiveMsg_I();
 void transferObject(struct transObjInfo * transObj);
 #endif
 
+
 #ifdef MULTICORE_GC
 void transferMarkResults();
+void processmsg_gcstartinit_I();
+void processmsg_gcstart_I();
+void processmsg_gcstartcompact_I();
+void processmsg_gcstartupdate_I();
+void processmsg_gcfinishpre_I();
+void processmsg_gcfinishinit_I();
+void processmsg_memrequest_I();
+void processmsg_memresponse_I();
+void processmsg_reqblock_I();
+void processmsg_grantblock_I();
+void processmsg_gcfinishmark_I();
+void processmsg_returnmem_I();
+void * handlegcfinishcompact_I(int cnum, unsigned int bytesneeded, unsigned int maxbytesneeded);
+void processmsg_gcfinishcompact_I();
+void processmsg_gcfinishupdate_I();
+void processmsg_gcfinish_I();
+void processmsg_gcmarkconfirm_I();
+void processmsg_gcmarkreport_I();
+void processmsg_gcmarkedobj_I();
+void processmsg_gcmovestart_I();
+void processmsg_gclobjinfo_I(unsigned int msglength);
+#else
+void processmsg_lockrequest_I();
+void processmsg_lockrequest_I();
+void processmsg_lockgrount_I();
+void processmsg_lockdeny_I();
+void processmsg_lockrelease_I();
+void processmsg_redirectlock_I();
+void processmsg_redirectgrount_I();
+void processmsg_redirectdeny_I();
+void processmsg_redirectrelease_I();
 #endif 
 
+unsigned int checkMsgLength_I(unsigned int realtype);
+void processmsg_transtall_I();
+void processmsg_statusconfirm_I();
+void processmsg_statusreport_I();
+void processmsg_terminate_I();
+void processmsg_req_notify_start();
+void processmsg_notify_start();
+int receiveObject_I();
+
+
+#ifdef GC_PROFILE
+void processmsg_gcprofiles_I();
+#endif
+
+#ifdef GC_CACHE_ADAPT
+void processmsg_gcstartcachepolicy_I();
+void processmsg_gcfinishcachepolicy_I();
+void processmsg_gcstartpref_I();
+void processmsg_gcfinishpref_I();
+#endif
+
+#ifdef PROFILE
+void processmsg_profileoutput_I();
+void processmsg_profilefinish_I();
+#endif
 #endif // MULTICORE
 #endif // BAMBOO_MULTICORE_MSG_H
index a7548dcb951ad78f8347764598ff535c6ace6772..52ebbad4d15c570c2f9037ae9ce67cf1fc3d7a55 100644 (file)
@@ -1,9 +1,10 @@
 #ifdef MULTICORE
-
 #include "runtime.h"
 #include "multicoreruntime.h"
 #include "methodheaders.h"
 #include "multicoregarbage.h"
+#include "multicore_arch.h"
+#include <stdio.h>
 
 extern int classsize[];
 extern int typearray[];
@@ -165,13 +166,6 @@ int CALL12(___String______convertdoubletochar____D__AR_C,
   }
   return num;
 }
-#else
-int CALL12(___String______convertdoubletochar____D__AR_C, 
-           double ___val___, 
-           double ___val___, 
-           struct ArrayObject ___chararray___) {
-  return 0;
-}
 #endif
 
 #ifdef D___System______deepArrayCopy____L___Object____L___Object___
@@ -328,6 +322,7 @@ long long CALL00(___System______currentTimeMillis____) {
 }
 #endif
 
+#ifdef D___System______setgcprofileflag____
 void CALL00(___System______setgcprofileflag____) {
 #ifdef GC_PROFILE
 #ifdef MGC_SPEC
@@ -336,7 +331,9 @@ void CALL00(___System______setgcprofileflag____) {
 #endif
 #endif
 }
+#endif
 
+#ifdef D___System______resetgcprofileflag____
 void CALL00(___System______resetgcprofileflag____) {
 #ifdef GC_PROFILE
 #ifdef MGC_SPEC
@@ -345,6 +342,31 @@ void CALL00(___System______resetgcprofileflag____) {
 #endif
 #endif
 }
+#endif
+
+void CALL00(___System______gc____) {
+#ifdef MULTICORE_GC
+  if(BAMBOO_NUM_OF_CORE == STARTUPCORE) {
+    if(!gc_status_info.gcprocessing && !gcflag) {
+      gcflag = true;
+      gcprecheck = true;
+      for(int i = 0; i < NUMCORESACTIVE; i++) {
+        // reuse the gcnumsendobjs & gcnumreceiveobjs
+        gcnumsendobjs[0][i] = 0;
+        gcnumreceiveobjs[0][i] = 0;
+      }
+      for(int i = 0; i < NUMCORES4GC; i++) {
+        if(i != STARTUPCORE) {
+          send_msg_1_I(i,GCSTARTPRE);
+        }
+      }
+    }
+  } else {
+    // send msg to the startup core to start gc
+    send_msg_1(STARTUPCORE, GCINVOKE);
+  }
+#endif
+}
 
 void CALL00(___System______gc____) {
 #ifdef MULTICORE_GC
@@ -371,10 +393,8 @@ void CALL00(___System______gc____) {
 }
 
 #ifdef D___System______printString____L___String___
-void CALL01(___System______printString____L___String___,
-            struct ___String___ * ___s___) {
-#ifdef MGC
-#ifdef TILERA_BME
+void CALL01(___System______printString____L___String___, struct ___String___ * ___s___) {
+#if defined(MGC)&&defined(TILERA_BME)
   struct ArrayObject * chararray=VAR(___s___)->___value___;
   int i;
   int offset=VAR(___s___)->___offset___;
@@ -384,7 +404,6 @@ void CALL01(___System______printString____L___String___,
       ((short *)(((char *)&chararray->___length___)+sizeof(int)))[i+offset];
     printf("%c", sc);
   }
-#endif // TILERA_BME
 #endif // MGC
 }
 #endif
@@ -427,7 +446,7 @@ struct ArrayObject * allocate_newarray(void * ptr,
     return NULL;
   }
   v->___length___=length;
-  initlock(v);
+  initlock((struct ___Object___ *)v);
 #ifdef GC_PROFILE
   extern unsigned int gc_num_obj;
   gc_num_obj++;
@@ -459,7 +478,7 @@ struct ArrayObject * allocate_newarray(int type,
   v->lock = NULL;
 #endif
   v->___length___=length;
-  initlock(v);
+  initlock((struct ___Object___ *) v);
   return v;
 }
 #endif
@@ -603,7 +622,7 @@ void abort_task() {
 #endif
 }
 
-INLINE void initruntimedata() {
+void initruntimedata() {
   // initialize the arrays
   if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
     // startup core to initialize corestatus[]
@@ -655,25 +674,26 @@ INLINE void initruntimedata() {
   INITTASKDATA();
 }
 
-INLINE void disruntimedata() {
+void disruntimedata() {
   DISMULTICOREGCDATA();
   DISTASKDATA();
   BAMBOO_LOCAL_MEM_CLOSE();
   BAMBOO_SHARE_MEM_CLOSE();
 }
 
-INLINE void recordtotalexetime() {
+void recordtotalexetime() {
 #ifdef USEIO
   totalexetime = BAMBOO_GET_EXE_TIME()-bamboo_start_time;
 #else // USEIO
-  BAMBOO_PRINT(BAMBOO_GET_EXE_TIME()-bamboo_start_time);
+  unsigned long long timediff=BAMBOO_GET_EXE_TIME()-bamboo_start_time;
+  BAMBOO_PRINT(timediff);
 #ifndef BAMBOO_MEMPROF
   BAMBOO_PRINT(0xbbbbbbbb);
 #endif
 #endif // USEIO
 }
 
-INLINE void getprofiledata_I() {
+void getprofiledata_I() {
   //profile mode, send msgs to other cores to request pouring out progiling data
 #ifdef PROFILE
   // use numconfirm to check if all cores have finished output task profiling 
@@ -705,7 +725,7 @@ INLINE void getprofiledata_I() {
 #endif
 }
 
-INLINE void checkCoreStatus() {
+void checkCoreStatus() {
   int i = 0;
   int sumsendobj = 0;
   if((!waitconfirm) ||
@@ -773,7 +793,7 @@ INLINE void checkCoreStatus() {
 }
 
 // main function for each core
-inline void run(int argc, char** argv) {
+void run(int argc, char** argv) {
   bool sendStall = false;
   bool isfirst = true;
   bool tocontinue = false;
index c7d13b0c3e24cf3290f72f75f6267eff01e58f36..d543c32f931650d791b8243c74466accd6b530ad 100644 (file)
@@ -65,12 +65,12 @@ int self_numreceiveobjs;
 // these are functions should be implemented in           //
 // multicore runtime for any multicore processors         //
 ////////////////////////////////////////////////////////////
-INLINE void initCommunication(void);
-INLINE void fakeExecution(void);
-INLINE void terminate(void);
-INLINE void initlock(struct ___Object___ * v);
+void initCommunication(void);
+void fakeExecution(void);
+void terminate(void);
+void initlock(struct ___Object___ * v);
 #ifdef BAMBOO_MEMPROF
-INLINE void terminatememprof(void);
+void terminatememprof(void);
 #endif // BAMBOO_MEMPROF
 
 ///////////////////////////////////////////////////////////
@@ -141,5 +141,13 @@ INLINE void terminatememprof(void);
 //                                      stores to incoherent memory        //
 /////////////////////////////////////////////////////////////////////////////
 
+void handleReturnMem_I(unsigned int cnum, void *heaptop);
+void handleReturnMem(unsigned int cnum, void *heaptop);
+void run(int argc, char** argv);
+void checkCoreStatus();
+void getprofiledata_I();
+void recordtotalexetime();
+void disruntimedata();
+void initruntimedata();
 #endif  // #ifdef MULTICORE
 #endif  // BAMBOO_MULTICORE_RUNTIME_H