changes, large objs processing not finished yet
authorjzhou <jzhou>
Sat, 8 Aug 2009 00:15:03 +0000 (00:15 +0000)
committerjzhou <jzhou>
Sat, 8 Aug 2009 00:15:03 +0000 (00:15 +0000)
Robust/src/Runtime/mem.c
Robust/src/Runtime/mem.h
Robust/src/Runtime/multicoregarbage.c
Robust/src/Runtime/multicoregarbage.h
Robust/src/Runtime/multicoreruntime.h
Robust/src/Runtime/multicoretask.c
Robust/src/Runtime/runtime.h

index e4854e5743cc07e18a5891447e69a130e4ded311..2f91e49396e839bb62b07693a8b227a6d0a30021 100644 (file)
@@ -4,7 +4,8 @@
 #include "runtime.h"
 #include "runtime_arch.h"
 
-void * mycalloc(int m, int size) {
+void * mycalloc(int m, 
+                           int size) {
   void * p = NULL;
   int isize = size; 
   BAMBOO_START_CRITICAL_SECTION_MEM();
@@ -17,7 +18,9 @@ void * mycalloc(int m, int size) {
 }
 
 #ifdef MULTICORE_GC
-void * mycalloc_share(struct garbagelist * stackptr, int m, int size) {
+void * mycalloc_share(struct garbagelist * stackptr, 
+                                 int m, 
+                                                                                       int size) {
        void * p = NULL;
   int isize = 2*BAMBOO_CACHE_LINE_SIZE-4+(size-1)&(~BAMBOO_CACHE_LINE_MASK);
 memalloc:
@@ -33,13 +36,15 @@ memalloc:
                goto memalloc;
   }
   BAMBOO_CLOSE_CRITICAL_SECTION_MEM();
-       void * alignedp = (void *)(BAMBOO_CACHE_LINE_SIZE+((int)p-1)&(~BAMBOO_CACHE_LINE_MASK));
+       void * alignedp = 
+               (void *)(BAMBOO_CACHE_LINE_SIZE+((int)p-1)&(~BAMBOO_CACHE_LINE_MASK));
        memset(p, -2, (alignedp - p));
   memset(alignedp + size, -2, p + isize - alignedp - size);
        return alignedp;
 }
 #else
-void * mycalloc_share(int m, int size) {
+void * mycalloc_share(int m, 
+                                 int size) {
   void * p = NULL;
   int isize = 2*BAMBOO_CACHE_LINE_SIZE-4+(size-1)&(~BAMBOO_CACHE_LINE_MASK);
   BAMBOO_START_CRITICAL_SECTION_MEM();
@@ -49,11 +54,13 @@ void * mycalloc_share(int m, int size) {
                BAMBOO_EXIT(0xa025);
   }
   BAMBOO_CLOSE_CRITICAL_SECTION_MEM();
-  return (void *)(BAMBOO_CACHE_LINE_SIZE+((int)p-1)&(~BAMBOO_CACHE_LINE_MASK));
+  return 
+               (void *)(BAMBOO_CACHE_LINE_SIZE+((int)p-1)&(~BAMBOO_CACHE_LINE_MASK));
 }
 #endif
 
-void * mycalloc_i(int m, int size) {
+void * mycalloc_i(int m, 
+                             int size) {
   void * p = NULL;
   int isize = size; 
   p = BAMBOO_LOCAL_MEM_CALLOC(m, isize); // calloc(m, isize);
index 9fa64726529c9930332187cfe8d509f9e299ab98..759d983f25740f699330a5ba0d116dbb31824490 100644 (file)
@@ -27,7 +27,7 @@ void * mycalloc(int m, int size);
 void * mycalloc_i(int m, int size);
 void myfree(void * ptr);
 #define RUNMALLOC(x) mycalloc(1,x) // handle interruption inside
-#define RUNMALLOC_I(x) mycalloc_i(1,x) // with interruption blocked beforehand
+#define RUNMALLOC_I(x) mycalloc_i(1,x) //with interruption blocked beforehand
 #define RUNFREE(x) myfree(x)
 #ifdef MULTICORE_GC
 void * mycalloc_share(struct garbagelist * stackptr, int m, int size);
index e83199c4f1e29d639bd67ed55238745b2bb23a57..f18814811ef83bcf30c7f9d6f8e7da1431e83c4c 100644 (file)
@@ -72,7 +72,9 @@ int gc_moreItems2() {
 INTPTR curr_heaptop = 0;
 INTPTR curr_heapbound = 0;
 
-bool isLarge(void * ptr, int * ttype, int * tsize) {
+bool isLarge(void * ptr, 
+                        int * ttype, 
+                                                int * tsize) {
        // check if a pointer is referring to a large object
        int type = ((int *)ptr)[0];
        int size = 0;
@@ -97,7 +99,7 @@ int hostcore(void * ptr) {
        int x = 0;
        int y = 0;
        RESIDECORE(ptr, &x, &y);
-       host = (x == 0)?(x * bamboo_height + y) : (x * bamboo_height + y - 2);
+       host = (x==0)?(x*bamboo_height+y):(x*bamboo_height+y-2);
        return host;
 }
 
@@ -109,6 +111,46 @@ bool isLocal(void * ptr) {
 void transferMarkResults() {
        // TODO, need distiguish between send and cache
        // invoked inside interruptiong handler
+       int msgsize = 4;
+  int i = 0;
+
+       // TODO check large objs here
+
+  isMsgSending = true;
+  DynamicHeader msgHdr = tmc_udn_header_from_cpu(STARTUPCORE);
+
+       // send header
+  __tmc_udn_send_header_with_size_and_tag(msgHdr, msgsize, 
+                                                           UDN0_DEMUX_TAG);  
+#ifdef DEBUG
+  BAMBOO_DEBUGPRINT(0xbbbb);
+  BAMBOO_DEBUGPRINT(0xb000 + STARTUPCORE);       // targetcore
+#endif
+  udn_send(GCLOBJINFO);
+#ifdef DEBUG
+  BAMBOO_DEBUGPRINT(GCLOBJINFO);
+#endif
+  udn_send(msgsize);
+#ifdef DEBUG
+  BAMBOO_DEBUGPRINT_REG(msgsize);
+#endif
+       udn_send(BAMBOO_NUM_OF_CORE);
+#ifdef DEBUG
+  BAMBOO_DEBUGPRINT_REG(BAMBOO_NUM_OF_CORE);
+#endif
+       udn_send(curr_heaptop);
+#ifdef DEBUG
+  BAMBOO_DEBUGPRINT_REG(curr_heaptop);
+#endif
+       // TODO large objs here
+       
+#ifdef DEBUG
+  BAMBOO_DEBUGPRINT(0xffff);
+#endif
+
+  // end of sending this msg, set sand msg flag false
+  isMsgSending = false;
+  send_hanging_msg();
 }
 
 void transferCompactStart(int core) {
@@ -140,7 +182,9 @@ void transferCompactStart(int core) {
   isMsgSending = true;
   DynamicHeader msgHdr = tmc_udn_header_from_cpu(core);
 
-  __tmc_udn_send_header_with_size_and_tag(msgHdr, msgsize, UDN0_DEMUX_TAG);  // send header
+       // send header
+  __tmc_udn_send_header_with_size_and_tag(msgHdr, msgsize, 
+                                                           UDN0_DEMUX_TAG);  
 #ifdef DEBUG
   BAMBOO_DEBUGPRINT(0xbbbb);
   BAMBOO_DEBUGPRINT(0xb000 + core);       // targetcore
@@ -485,7 +529,8 @@ void gc(struct garbagelist * stackptr) {
                        send_msg_1(i, GCFINISH);
                }
 
-               // need to create free memory list and invalidate all shared mem pointers TODO
+               // need to create free memory list and invalidate all 
+               // shared mem pointers TODO
 
                gcflag = false;
                gcprocessing = false;
@@ -525,7 +570,8 @@ void tomark(struct garbagelist * stackptr) {
        }
        // enqueue objectsets
        for(i=0; i<NUMCLASSES; i++) {
-               struct parameterwrapper ** queues=objectqueues[BAMBOO_NUM_OF_CORE][i];
+               struct parameterwrapper ** queues = 
+                       objectqueues[BAMBOO_NUM_OF_CORE][i];
                int length = numqueues[BAMBOO_NUM_OF_CORE][i];
                for(j = 0; j < length; ++j) {
                        struct parameterwrapper * parameter = queues[j];
@@ -554,13 +600,15 @@ void tomark(struct garbagelist * stackptr) {
        // enqueue cached transferred obj
        struct QueueItem * tmpobjptr =  getHead(&objqueue);
        while(tmpobjptr != NULL) {
-               struct transObjInfo * objInfo = (struct transObjInfo *)(tmpobjptr->objectptr); 
+               struct transObjInfo * objInfo = 
+                       (struct transObjInfo *)(tmpobjptr->objectptr); 
                gc_enqueue(objInfo->objptr);
                getNextQueueItem(tmpobjptr);
        }
 }
 
-void mark(bool isfirst, struct garbagelist * stackptr) {
+void mark(bool isfirst, 
+                     struct garbagelist * stackptr) {
        if(isfirst) {
                // enqueue root objs
                tomark(stackptr);
@@ -579,7 +627,7 @@ void mark(bool isfirst, struct garbagelist * stackptr) {
                        if(isLarge(ptr, &type, &size)) {
                                // ptr is a large object
                                struct largeObjItem * loi = 
-                                       (struct largeObjItem *)RUNMALLOC(sizeof(struct largeObjItem));  
+                                       (struct largeObjItem*)RUNMALLOC(sizeof(struct largeObjItem)); 
                                loi->orig = (INTPTR)ptr;
                                loi->dst = (INTPTR)0;
                                loi->length = size;
@@ -598,7 +646,7 @@ void mark(bool isfirst, struct garbagelist * stackptr) {
                                curr_heaptop += isize;
                                if(curr_heaptop > curr_heapbound) {
                                        // change to another block
-                                       curr_heaptop = curr_heapbound + BAMBOO_CACHE_LINE_SIZE + isize;
+                                       curr_heaptop = curr_heapbound+BAMBOO_CACHE_LINE_SIZE+isize;
                                        curr_heapbound += BAMBOO_SMEM_SIZE;
                                }
                                // mark this obj
@@ -619,7 +667,8 @@ void mark(bool isfirst, struct garbagelist * stackptr) {
                                int length=ao->___length___;
                                int j;
                                for(j=0; j<length; j++) {
-                                       void *objptr=((void **)(((char *)&ao->___length___)+sizeof(int)))[j];
+                                       void *objptr = 
+                                               ((void **)(((char *)&ao->___length___)+sizeof(int)))[j];
                                        int host = hostcore(objptr);
                                        if(BAMBOO_NUM_OF_CORE == host) {
                                                // on this core
@@ -661,13 +710,13 @@ void mark(bool isfirst, struct garbagelist * stackptr) {
 
 struct moveHelper {
        int numblocks; // block num for heap
-       INTPTR base; // real base virtual address of current heap block
-       INTPTR ptr; // real virtual address of current heap top
+       INTPTR base; // base virtual address of current heap block
+       INTPTR ptr; // virtual address of current heap top
        int offset; // offset in current heap block
-       int blockbase; // real virtual address of current small block to check with
-       int blockbound; // real bound virtual address of current small blcok to check
+       int blockbase; // virtual address of current small block to check
+       int blockbound; // bound virtual address of current small blcok 
        int top; // real size of current heap block to check
-       int bound; // real bound virtual address of current heap block to check
+       int bound; // bound size of current heap block to check
 };
 
 void nextSBlock(struct moveHelper * orig) {
@@ -694,7 +743,9 @@ void nextBlock(struct moveHelper * to) {
 }
 
 // endaddr does not contain spaces for headers
-bool moveobj(struct moveHelper * orig, struct moveHelper * to, INTPTR * endaddr) {
+bool moveobj(struct moveHelper * orig, 
+                        struct moveHelper * to, 
+                                                INTPTR * endaddr) {
        int type = 0;
        int size = 0;
        int mark = 0;
@@ -746,7 +797,8 @@ innermoveobj:
                        nextBlock(to);
                }
                memcpy(to->ptr, orig->ptr, size);
-               RuntimeHashadd(pointertbl, orig->ptr, to->ptr);  // store the mapping info
+               // store mapping info
+               RuntimeHashadd(pointertbl, orig->ptr, to->ptr); 
                to->ptr += isize;
                to->offset += isize;
                to->top += isize;
@@ -765,7 +817,8 @@ void migrateobjs(struct moveHelper * orig) {
                while(!gctomove) {}
                // start moving objects to other cores
                gctomove = false;
-               struct moveHelper * into = (struct moveHelper *)RUNMALLOC(sizeof(struct moveHelper));
+               struct moveHelper * into = 
+                       (struct moveHelper *)RUNMALLOC(sizeof(struct moveHelper));
                for(int j = 0; j < cinstruction->movenum; j++) {
                        if(cinstruction->moveflag[j] == 1) {
                                // can start moving to corresponding core
@@ -773,11 +826,13 @@ void migrateobjs(struct moveHelper * orig) {
                                num_dsts--;
                                into->ptr = cinstruction->startaddrs[j];
                                BLOCKINDEX(into->ptr, &(into->numblocks));
-                               into->bound = 
-                                       (into->numblocks==0)?BAMBOO_SMEM_SIZE_L:BAMBOO_SMEM_SIZE_L+BAMBOO_SMEM_SIZE*into->numblocks;
+                               into->bound = (into->numblocks==0)?
+                                       BAMBOO_SMEM_SIZE_L:
+                                       BAMBOO_SMEM_SIZE_L+BAMBOO_SMEM_SIZE*into->numblocks;
                                BASEPTR(BAMBOO_NUM_OF_CORE, into->numblocks, &(into->base));
                                into->offset = into->ptr - into->base;
-                               into->top = (into->numblocks==0)?(into->offset):(into->bound-BAMBOO_SMEM_SIZE+into->offset);
+                               into->top = (into->numblocks==0)?
+                                       (into->offset):(into->bound-BAMBOO_SMEM_SIZE+into->offset);
                                into->base = into->ptr;
                                into->offset = BAMBOO_CACHE_LINE_SIZE;
                                into->ptr += into->offset; // for header
@@ -791,7 +846,8 @@ void migrateobjs(struct moveHelper * orig) {
                                                break;
                                        }                                                       
                                } while(orig->ptr < markedptrbound + 1);
-                               cinstruction->moveflag[j] = 2; // set the flag indicating move finished
+                               // set the flag indicating move finished
+                               cinstruction->moveflag[j] = 2; 
                                // fill the header of this blockk
                                (*((int*)(into->base))) = into->offset;
                        } // if(cinstruction->moveflag[j] == 1)
@@ -808,8 +864,10 @@ void compact() {
        INTPTR heaptopptr = 0;
 
        // initialize pointers for comapcting
-       struct moveHelper * orig = (struct moveHelper *)RUNMALLOC(sizeof(struct moveHelper));
-       struct moveHelper * to = (struct moveHelper *)RUNMALLOC(sizeof(struct moveHelper));
+       struct moveHelper * orig = 
+               (struct moveHelper *)RUNMALLOC(sizeof(struct moveHelper));
+       struct moveHelper * to = 
+               (struct moveHelper *)RUNMALLOC(sizeof(struct moveHelper));
        to->numblocks = 0;
        to->top = to->offset = BAMBOO_CACHE_LINE_SIZE;
        to->bound = BAMBOO_SMEM_SIZE_L;
@@ -824,7 +882,7 @@ void compact() {
 
        // scan over all objs in this block, compact those scheduled to 
        // reside on this core
-       // loop stop when finishing either scanning all active objs or moving 
+       // loop stop when finishing either scanning all active objs or moving
        // all objs to reside on this core
        int endaddr = cinstruction->loads;
        do {
@@ -872,7 +930,8 @@ void compact() {
                        }
                        heaptopptr = to->ptr;
                } else {
-                       // have incoming objs, send messages to corresponding cores to start moving
+                       // have incoming objs, send messages to corresponding cores 
+                       // to start moving
                        INTPTR startaddr = 0;
                        INTPTR endaddr = 0;
                        int heapptr = curr_heapptr;
@@ -880,21 +939,24 @@ void compact() {
                        int bound = curr_heapbound;
                        for(int j = 0; j < cinstruction->movenum; j++) {
                                startaddr = heapptr;
-                               top = top + cinstruction->size2move[j] + BAMBOO_CACHE_LINE_SIZE;
+                               top = top+cinstruction->size2move[j]+BAMBOO_CACHE_LINE_SIZE;
                                if(top > bound) {
                                        // will cross block boundary
                                        int numb = (top - bound) / BAMBOO_SMEM_SIZE + 1;
                                        top += numb * BAMBOO_CACHE_LINE_SIZE;
                                        BASEPTR(BAMBOO_NUM_OF_CORE, numblocks + numb, &endaddr);
-                                       endaddr += (top - bound) % BAMBOO_SMEM_SIZE + BAMBOO_CACHE_LINE_SIZE;
+                                       endaddr += 
+                                               (top-bound)%BAMBOO_SMEM_SIZE+BAMBOO_CACHE_LINE_SIZE;
                                        heapptr = endaddr;
                                        bound += BAMBOO_SMEM_SIZE * numb;
                                } else {
-                                       endaddr = heapptr + cinstruction->size2move[j] + BAMBOO_CACHE_LINE_SIZE;
+                                       endaddr = 
+                                               heapptr+cinstruction->size2move[j]+BAMBOO_CACHE_LINE_SIZE;
                                        heapptr = endaddr;
                                }
                                send_msg_4(cinstruction->dsts[j], GCMOVESTART, 
-                                                      BAMBOO_NUM_OF_CORE, startaddr, cinstruction->size2move[j]);
+                                                      BAMBOO_NUM_OF_CORE, startaddr, 
+                                                                        cinstruction->size2move[j]);
                        }
                        heaptopptr = heapptr;
                } // if(cinstruction->ismove) 
@@ -915,7 +977,8 @@ void compact() {
                }while(cinstruction->largeobjs != NULL);
        }*/
        // send compact finish message to core coordinator
-       send_msg_3(STARTUPCORE, GCFINISHCOMPACT, BAMBOO_NUM_OF_CORE, to->ptr);
+       send_msg_3(STARTUPCORE, GCFINISHCOMPACT, 
+                              BAMBOO_NUM_OF_CORE, to->ptr);
 
        RUNFREE(orig);
        RUNFREE(to);
@@ -937,7 +1000,8 @@ void flush() {
                        int length=ao->___length___;
                        int j;
                        for(j=0; j<length; j++) {
-                               void *objptr=((void **)(((char *)&ao->___length___)+sizeof(int)))[j];
+                               void *objptr=
+                                       ((void **)(((char *)&ao->___length___)+sizeof(int)))[j];
                                // change to new address
                                void *dstptr = NULL;
                                RuntimeHashget(pointertbl, objptr, &dstptr);
@@ -951,7 +1015,7 @@ void flush() {
                                        while(!ismapped) {}
                                        RuntimeHashget(pointertbl, objptr, &dstptr);
                                }
-                               ((void **)(((char *)&ao->___length___)+sizeof(int)))[j] = dstptr;
+                               ((void **)(((char *)&ao->___length___)+sizeof(int)))[j]=dstptr;
                        }
                } else {
                        INTPTR size=pointer[0];
index d43e5f44dba382a8647eb6c893f18284dac78917..b01fbf642efbc1c51a5957bf9229cc00fe711a5c 100644 (file)
@@ -9,7 +9,7 @@
 #define BAMBOO_BASE_VA 0xd000000
 #define BAMBOO_SMEM_SIZE 16 * BAMBOO_PAGE_SIZE
 #define BAMBOO_SMEM_SIZE_L 512 * BAMBOO_PAGE_SIZE
-#define BAMBOO_LARGE_SMEM_BOUND BAMBOO_SMEM_SIZE_L*NUMCORES // NUMCORES = 62
+#define BAMBOO_LARGE_SMEM_BOUND BAMBOO_SMEM_SIZE_L*NUMCORES // NUMCORES=62
 
 struct garbagelist {
   int size;
@@ -70,8 +70,8 @@ GCPHASETYPE gcphase; // indicating GC phase
 int gccorestatus[NUMCORES]; // records status of each core
                             // 1: running gc
                             // 0: stall
-int gcnumsendobjs[NUMCORES]; // records how many objects a core has sent out
-int gcnumreceiveobjs[NUMCORES]; // records how many objects a core has received
+int gcnumsendobjs[NUMCORES]; // records how many objects sent out
+int gcnumreceiveobjs[NUMCORES]; // records how many objects received
 int gcself_numsendobjs;
 int gcself_numreceiveobjs;
 
@@ -100,7 +100,7 @@ bool ismapped;
        if(t < BAMBOO_LARGE_SMEM_BOUND) { \
                (*((int*)b)) = t / BAMBOO_SMEM_SIZE_L; \
        } else { \
-               (*((int*)b)) = NUMCORES + (t - BAMBOO_LARGE_SMEM_BOUND) / BAMBOO_SMEM_SIZE; \
+               (*((int*)b)) = NUMCORES+(t-BAMBOO_LARGE_SMEM_BOUND)/BAMBOO_SMEM_SIZE;\
        }
 
 #define RESIDECORE(p, x, y) \
index c30dfb576f7b16d577ea8af6bf8abe19d3a26fd3..4d13ba275763b369256df8b52e40499a31d181b9 100644 (file)
@@ -57,35 +57,59 @@ volatile bool isMsgSending;
  *      1f -- large objs info response
  *
  * ObjMsg: 0 + size of msg + obj's address + (task index + param index)+
- * StallMsg: 1 + corenum + sendobjs + receiveobjs (size is always 4 * sizeof(int))
- * LockMsg: 2 + lock type + obj pointer + lock + request core (size is always 5 * sizeof(int))
- *          3/4/5 + lock type + obj pointer + lock (size is always 4 * sizeof(int))
- *          8 + lock type + obj pointer +  redirect lock + root request core + request core (size is always 6 * sizeof(int))
- *          9/a + lock type + obj pointer + redirect lock (size is always 4 * sizeof(int))
- *          b + lock type + lock + redirect lock (size is always 4 * sizeof(int))
+ * StallMsg: 1 + corenum + sendobjs + receiveobjs 
+ *             (size is always 4 * sizeof(int))
+ * LockMsg: 2 + lock type + obj pointer + lock + request core 
+ *            (size is always 5 * sizeof(int))
+ *          3/4/5 + lock type + obj pointer + lock 
+ *            (size is always 4 * sizeof(int))
+ *          8 + lock type + obj pointer +  redirect lock + root request core 
+ *            + request core 
+ *            (size is always 6 * sizeof(int))
+ *          9/a + lock type + obj pointer + redirect lock 
+ *              (size is always 4 * sizeof(int))
+ *          b + lock type + lock + redirect lock 
+ *            (size is always 4 * sizeof(int))
  *          lock type: 0 -- read; 1 -- write
- * ProfileMsg: 6 + totalexetime (size is always 2 * sizeof(int))
- *             7 + corenum (size is always 2 * sizeof(int))
+ * ProfileMsg: 6 + totalexetime 
+ *               (size is always 2 * sizeof(int))
+ *             7 + corenum 
+ *               (size is always 2 * sizeof(int))
  * StatusMsg: c (size is always 1 * sizeof(int))
- *            d + status + corenum + sendobjs + receiveobjs (size is always 5 * sizeof(int))
+ *            d + status + corenum + sendobjs + receiveobjs 
+ *              (size is always 5 * sizeof(int))
  *            status: 0 -- stall; 1 -- busy
  * TerminateMsg: e (size is always 1 * sizeof(int)
- * MemoryMsg: f + size + corenum (size is always 3 * sizeof(int))
- *           10 + base_va + size (size is always 3 * sizeof(int))
+ * MemoryMsg: f + size + corenum 
+ *              (size is always 3 * sizeof(int))
+ *           10 + base_va + size 
+ *              (size is always 3 * sizeof(int))
  * GCMsg: 11 (size is always 1 * sizeof(int))
- *        12 + size of msg + (num of objs to move + (start address + end address + dst core + start dst)+)? + (num of incoming objs + (start dst + orig core)+)? + (num of large obj lists + (start address + lenght + start dst)+)?
+ *        12 + size of msg + (num of objs to move + (start address 
+ *           + end address + dst core + start dst)+)? 
+ *           + (num of incoming objs + (start dst + orig core)+)? 
+ *           + (num of large obj lists + (start address + lenght 
+ *           + start dst)+)?
  *        13 (size is always 1 * sizeof(int))
- *        14 + corenum + gcsendobjs + gcreceiveobjs (size if always 4 * sizeof(int))
- *        15/16 + corenum (size is always 2 * sizeof(int))
+ *        14 + corenum + gcsendobjs + gcreceiveobjs    
+ *           (size if always 4 * sizeof(int))
+ *        15/16 + corenum 
+ *              (size is always 2 * sizeof(int))
  *        17 (size is always 1 * sizeof(int))
  *        18 (size if always 1 * sizeof(int))
- *        19 + size of msg + corenum + gcsendobjs + gcreceiveobjs (size is always 5 * sizeof(int))
- *        1a + obj's address (size is always 2 * sizeof(int))
- *        1b + corenum ( size is always 2 * sizeof(int))
- *        1c + obj's address + corenum (size is always 3 * sizeof(int))
- *        1d + obj's address + dst address (size if always 3 * sizeof(int))
+ *        19 + size of msg + corenum + gcsendobjs + gcreceiveobjs 
+ *           (size is always 5 * sizeof(int))
+ *        1a + obj's address 
+ *           (size is always 2 * sizeof(int))
+ *        1b + corenum 
+ *           ( size is always 2 * sizeof(int))
+ *        1c + obj's address + corenum 
+ *           (size is always 3 * sizeof(int))
+ *        1d + obj's address + dst address 
+ *           (size if always 3 * sizeof(int))
  *        1e (size is always 1 * sizeof(int))
- *        1f + size of msg + corenum + current heap size + (num of large obj lists + (start address + length)+)?
+ *        1f + size of msg + corenum + current heap size 
+ *           + (num of large obj lists + (start address + length)+)?
  */
 enum MSGTYPE {
        TRANSOBJ = 0x0,  // 0x0
@@ -146,6 +170,7 @@ struct LockValue {
        int redirectlock;
        int value;
 };
+struct RuntimeHash * lockRedirectTbl;
 struct RuntimeHash * objRedirectLockTbl;
 int lockobj;
 int lock2require;
@@ -159,6 +184,22 @@ struct Queue objqueue;
 // data structures for shared memory allocation
 #ifdef MULTICORE_GC
 #include "multicoregarbage.h"
+
+struct freeMemItem {
+       INTPTR ptr;
+       int size;
+       struct freeMemItem * next;
+};
+
+struct freeMemList {
+       struct freeMemItem * head;
+       struct freeMemItem * tail;
+};
+
+bool smemflag;
+struct freeMemList * bamboo_free_mem_list;
+INTPTR bamboo_cur_msp;
+int bamboo_smem_size;
 #else
 #define BAMBOO_NUM_PAGES 1024 * 512
 #define BAMBOO_PAGE_SIZE 4096
@@ -237,22 +278,71 @@ void releasewritelock_I(void * ptr);
 // if return -1: the lock request is redirected
 //            0: the lock request is approved
 //            1: the lock request is denied
-inline int processlockrequest(int locktype, int lock, int obj, int requestcore, int rootrequestcore, bool cache) __attribute_((always_inline));
-inline void processlockrelease(int locktype, int lock, int redirectlock, bool isredirect) __attribute_((always_inline));
+inline int processlockrequest(int locktype, 
+                                         int lock, 
+                                                                                                                       int obj, 
+                                                                                                                       int requestcore, 
+                                                                                                                       int rootrequestcore, 
+                                                                                                                       bool cache) __attribute_((always_inline));
+inline void processlockrelease(int locktype, 
+                                          int lock, 
+                                                                                                                        int redirectlock, 
+                                                                                                                        bool isredirect) __attribute_((always_inline));
 
 // msg related functions
 inline void send_hanging_msg() __attribute__((always_inline));
-inline void send_msg_1(int targetcore, unsigned long n0) __attribute__((always_inline));
-inline void send_msg_2(int targetcore, unsigned long n0, unsigned long n1) __attribute__((always_inline));
-inline void send_msg_3(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2) __attribute__((always_inline));
-inline void send_msg_4(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2, unsigned long n3) __attribute__((always_inline));
-inline void send_msg_5(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2, unsigned long n3, unsigned long n4) __attribute__((always_inline));
-inline void send_msg_6(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2, unsigned long n3, unsigned long n4, unsigned long n5) __attribute__((always_inline));
-inline void cache_msg_2(int targetcore, unsigned long n0, unsigned long n1) __attribute__((always_inline));
-inline void cache_msg_3(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2) __attribute__((always_inline));
-inline void cache_msg_4(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2, unsigned long n3) __attribute__((always_inline));
-inline void cache_msg_5(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2, unsigned long n3, unsigned long n4) __attribute__((always_inline));
-inline void cache_msg_6(int targetcore, unsigned long n0, unsigned long n1, unsigned long n2, unsigned long n3, unsigned long n4, unsigned long n5) __attribute__((always_inline));
+inline void send_msg_1(int targetcore, 
+                                  unsigned long n0) __attribute__((always_inline));
+inline void send_msg_2(int targetcore, 
+                                  unsigned long n0, 
+                                                                                        unsigned long n1) __attribute__((always_inline));
+inline void send_msg_3(int targetcore, 
+                                  unsigned long n0, 
+                                                                                        unsigned long n1, 
+                                                                                        unsigned long n2) __attribute__((always_inline));
+inline void send_msg_4(int targetcore, 
+                                  unsigned long n0, 
+                                                                                        unsigned long n1, 
+                                                                                        unsigned long n2, 
+                                                                                        unsigned long n3) __attribute__((always_inline));
+inline void send_msg_5(int targetcore, 
+                                  unsigned long n0, 
+                                                                                        unsigned long n1, 
+                                                                                        unsigned long n2, 
+                                                                                        unsigned long n3, 
+                                                                                        unsigned long n4) __attribute__((always_inline));
+inline void send_msg_6(int targetcore, 
+                                  unsigned long n0, 
+                                                                                        unsigned long n1, 
+                                                                                        unsigned long n2, 
+                                                                                        unsigned long n3, 
+                                                                                        unsigned long n4, 
+                                                                                        unsigned long n5) __attribute__((always_inline));
+inline void cache_msg_2(int targetcore, 
+                                   unsigned long n0, 
+                                                                                               unsigned long n1) __attribute__((always_inline));
+inline void cache_msg_3(int targetcore, 
+                                   unsigned long n0, 
+                                                                                               unsigned long n1, 
+                                                                                               unsigned long n2) __attribute__((always_inline));
+inline void cache_msg_4(int targetcore, 
+                                   unsigned long n0, 
+                                                                                               unsigned long n1, 
+                                                                                               unsigned long n2, 
+                                                                                               unsigned long n3) __attribute__((always_inline));
+inline void cache_msg_5(int targetcore, 
+                                   unsigned long n0, 
+                                                                                               unsigned long n1, 
+                                                                                               unsigned long n2, 
+                                                                                               unsigned long n3, 
+                                                                                               unsigned long n4) __attribute__((always_inline));
+inline void cache_msg_6(int targetcore, 
+                                   unsigned long n0, 
+                                                                                               unsigned long n1, 
+                                                                                               unsigned long n2, 
+                                                                                               unsigned long n3, 
+                                                                                               unsigned long n4, 
+                                                                                               unsigned long n5) __attribute__((always_inline));
 inline void transferObject(struct transObjInfo * transObj);
 inline int receiveMsg(void) __attribute__((always_inline));
 
@@ -263,46 +353,48 @@ void outputProfileData();
 #endif  // #ifdef PROFILE
 ///////////////////////////////////////////////////////////
 
-//////////////////////////////////////////////////////////////////////////////////////
-//  For each version of BAMBOO runtime, there should be a header file named        //
-//  runtim_arch.h defining following MARCOS:                                       //
-//  BAMBOO_TOTALCORE: the total # of cores available in the processor              //
-//  BAMBOO_NUM_OF_CORE: the # of current residing core                             //
-//  BAMBOO_GET_NUM_OF_CORE(): compute the # of current residing core               //
-//  BAMBOO_DEBUGPRINT(x): print out integer x                                      //
-//  BAMBOO_DEBUGPRINT_REG(x): print out value of variable x                        //
-//  BAMBOO_LOCAL_MEM_CALLOC(x, y): allocate an array of x elements each of whose   //
-//                                 size in bytes is y on local memory              //
-//  BAMBOO_LOCAL_MEM_FREE(x): free space with ptr x on local memory                //
-//  BAMBOO_SHARE_MEM_CALLOC(x, y): allocate an array of x elements each of whose   //
-//                                 size in bytes is y on shared memory             //
-//  BAMBOO_START_CRITICAL_SECTION_OBJ_QUEUE()                                      //
-//  BAMBOO_CLOSE_CRITICAL_SECTION_OBJ_QUEUE(): locks for global data structures    //
-//                                             related to obj queue                //
-//  BAMBOO_START_CRITICAL_SECTION_STATUS()                                         //
-//  BAMBOO_CLOSE_CRITICAL_SECTION_STATUS(): locks for global data structures       //
-//                                          related to status data                 //
-//  BAMBOO_START_CRITICAL_SECTION_MSG()                                            //
-//  BAMBOO_CLOSE_CRITICAL_SECTION_MSG(): locks for global data structures related  //
-//                                       to msg data                               //
-//  BAMBOO_START_CRITICAL_SECTION_LOCK()                                           //
-//  BAMBOO_CLOSE_CRITICAL_SECTION_LOCK(): locks for global data structures related //
-//                                        to lock table                            //
-//  BAMBOO_START_CRITICAL_SECTION_MEM()                                            //
-//  BAMBOO_CLOSE_CRITICAL_SECTION_MEM(): locks for allocating memory               //
-//  BAMBOO_START_CRITICAL_SECTION()                                                //
-//  BAMBOO_CLOSE_CRITICAL_SECTION(): locks for all global data structures          //
-//  BAMBOO_WAITING_FOR_LOCK(): routine executed while waiting for lock request     //
-//                             response                                            //
-//  BAMBOO_CACHE_LINE_SIZE: the cache line size                                    //
-//  BAMBOO_CACHE_LINE_MASK: mask for a cache line                                  //
-//  BAMBOO_CACHE_FLUSH_RANGE(x, y): flush cache lines started at x with length y   //
-//  BAMBOO_CACHE_FLUSH_ALL(): flush the whole cache of a core if necessary         //
-//  BAMBOO_EXIT(x): exit routine                                                   //
-//  BAMBOO_MSG_AVAIL(): checking if there are msgs coming in                       //
-//  BAMBOO_GCMSG_AVAIL(): checking if there are gcmsgs coming in                   //
-//  BAMBOO_GET_EXE_TIME(): rountine to get current clock cycle number              //
-/////////////////////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////////////
+// For each version of BAMBOO runtime, there should be a header file named //
+// runtim_arch.h defining following MARCOS:                                //
+// BAMBOO_TOTALCORE: the total # of cores available in the processor       //
+// BAMBOO_NUM_OF_CORE: the # of current residing core                      //
+// BAMBOO_GET_NUM_OF_CORE(): compute the # of current residing core        //
+// BAMBOO_DEBUGPRINT(x): print out integer x                               //
+// BAMBOO_DEBUGPRINT_REG(x): print out value of variable x                 //
+// BAMBOO_LOCAL_MEM_CALLOC(x, y): allocate an array of x elements each of  //
+//                                whose size in bytes is y on local memory //
+// BAMBOO_LOCAL_MEM_FREE(x): free space with ptr x on local memory         //
+// BAMBOO_SHARE_MEM_CALLOC(x, y): allocate an array of x elements each of  //
+//                                whose size in bytes is y on shared memory//
+// BAMBOO_START_CRITICAL_SECTION_OBJ_QUEUE()                               //
+// BAMBOO_CLOSE_CRITICAL_SECTION_OBJ_QUEUE(): locks for global data        //
+//                                            structures related to obj    //
+//                                            queue                        //
+// BAMBOO_START_CRITICAL_SECTION_STATUS()                                  //
+// BAMBOO_CLOSE_CRITICAL_SECTION_STATUS(): locks for global data structures//
+//                                         related to status data          //
+// BAMBOO_START_CRITICAL_SECTION_MSG()                                     //
+// BAMBOO_CLOSE_CRITICAL_SECTION_MSG(): locks for global data structures   //
+//                                      related to msg data                //
+// BAMBOO_START_CRITICAL_SECTION_LOCK()                                    //
+// BAMBOO_CLOSE_CRITICAL_SECTION_LOCK(): locks for global data structures  //
+//                                       related to lock table             //
+// BAMBOO_START_CRITICAL_SECTION_MEM()                                     //
+// BAMBOO_CLOSE_CRITICAL_SECTION_MEM(): locks for allocating memory        //
+// BAMBOO_START_CRITICAL_SECTION()                                         //
+// BAMBOO_CLOSE_CRITICAL_SECTION(): locks for all global data structures   //
+// BAMBOO_WAITING_FOR_LOCK(): routine executed while waiting for lock      //
+//                            request response                             //
+// BAMBOO_CACHE_LINE_SIZE: the cache line size                             //
+// BAMBOO_CACHE_LINE_MASK: mask for a cache line                           //
+// BAMBOO_CACHE_FLUSH_RANGE(x, y): flush cache lines started at x with     //
+//                                 length y                                //
+// BAMBOO_CACHE_FLUSH_ALL(): flush the whole cache of a core if necessary  //
+// BAMBOO_EXIT(x): exit routine                                            //
+// BAMBOO_MSG_AVAIL(): checking if there are msgs coming in                //
+// BAMBOO_GCMSG_AVAIL(): checking if there are gcmsgs coming in            //
+// BAMBOO_GET_EXE_TIME(): rountine to get current clock cycle number       //
+/////////////////////////////////////////////////////////////////////////////
 
 #endif  // #ifdef MULTICORE
 #endif  // #ifdef TASK
index 28fb9094bf8b3a18ff747994f257e7746b02b3b8..86b5de723560cd12fe58638808a755c44186b401 100644 (file)
@@ -9,8 +9,14 @@ struct genhashtable * activetasks;
 struct taskparamdescriptor * currtpd;
 
 // specific functions used inside critical sections
-void enqueueObject_I(void * ptr, struct parameterwrapper ** queues, int length);
-int enqueuetasks_I(struct parameterwrapper *parameter, struct parameterwrapper *prevptr, struct ___Object___ *ptr, int * enterflags, int numenterflags);
+void enqueueObject_I(void * ptr, 
+                                struct parameterwrapper ** queues, 
+                                                                                int length);
+int enqueuetasks_I(struct parameterwrapper *parameter, 
+                              struct parameterwrapper *prevptr, 
+                                                                        struct ___Object___ *ptr, 
+                                                                        int * enterflags, 
+                                                                        int numenterflags);
 
 inline void initruntimedata() {
        // initialize the arrays
@@ -18,7 +24,7 @@ inline void initruntimedata() {
     // startup core to initialize corestatus[]
     for(i = 0; i < NUMCORES; ++i) {
       corestatus[i] = 1;
-      numsendobjs[i] = 0;                   // assume all variables are local variables! MAY BE WRONG!!!
+      numsendobjs[i] = 0; 
       numreceiveobjs[i] = 0;
 #ifdef PROFILE
                        // initialize the profile data arrays
@@ -80,7 +86,8 @@ inline void initruntimedata() {
 #else
        // create the lock table, lockresult table and obj queue
   locktable.size = 20;
-  locktable.bucket = (struct RuntimeNode **) RUNMALLOC_I(sizeof(struct RuntimeNode *)*20);
+  locktable.bucket = 
+               (struct RuntimeNode **) RUNMALLOC_I(sizeof(struct RuntimeNode *)*20);
   /* Set allocation blocks*/
   locktable.listhead=NULL;
   locktable.listtail=NULL;
@@ -179,18 +186,22 @@ bool checkObjQueue(void * sendStall) {
                                // flush the object
 #ifdef CACHEFLUSH
                                BAMBOO_CACHE_FLUSH_RANGE((int)obj,sizeof(int));
-                               BAMBOO_CACHE_FLUSH_RANGE((int)obj, classsize[((struct ___Object___ *)obj)->type]);
+                               BAMBOO_CACHE_FLUSH_RANGE((int)obj, 
+                                               classsize[((struct ___Object___ *)obj)->type]);
 #endif
                                // enqueue the object
                                for(k = 0; k < objInfo->length; ++k) {
                                        int taskindex = objInfo->queues[2 * k];
                                        int paramindex = objInfo->queues[2 * k + 1];
-                                       struct parameterwrapper ** queues = &(paramqueues[BAMBOO_NUM_OF_CORE][taskindex][paramindex]);
+                                       struct parameterwrapper ** queues = 
+                                               &(paramqueues[BAMBOO_NUM_OF_CORE][taskindex][paramindex]);
 #ifdef DEBUG
                                        BAMBOO_DEBUGPRINT_REG(taskindex);
                                        BAMBOO_DEBUGPRINT_REG(paramindex);
                                        struct ___Object___ * tmpptr = (struct ___Object___ *)obj;
-                                       tprintf("Process %x(%d): receive obj %x(%lld), ptrflag %x\n", BAMBOO_NUM_OF_CORE, BAMBOO_NUM_OF_CORE, (int)obj, (long)obj, tmpptr->flag);
+                                       tprintf("Process %x(%d): receive obj %x(%lld), ptrflag %x\n", 
+                                                           BAMBOO_NUM_OF_CORE, BAMBOO_NUM_OF_CORE, (int)obj, 
+                                                                       (long)obj, tmpptr->flag);
 #endif
                                        enqueueObject_I(obj, queues, 1);
 #ifdef DEBUG                            
@@ -206,7 +217,8 @@ bool checkObjQueue(void * sendStall) {
                                struct QueueItem * qitem = getHead(&objqueue);
                                struct QueueItem * prev = NULL;
                                while(qitem != NULL) {
-                                       struct transObjInfo * tmpinfo = (struct transObjInfo *)(qitem->objectptr);
+                                       struct transObjInfo * tmpinfo = 
+                                               (struct transObjInfo *)(qitem->objectptr);
                                        if(tmpinfo->objptr == obj) {
                                                // the same object in the queue, which should be enqueued
                                                // recently. Current one is outdate, do not re-enqueue it
@@ -442,8 +454,9 @@ inline void run(void * arg) {
        fakeExecution();
   } else {
          /* Create queue of active tasks */
-         activetasks=genallocatehashtable((unsigned int(*) (void *)) &hashCodetpd,
-                                       (int(*) (void *,void *)) &comparetpd);
+         activetasks=
+                       genallocatehashtable((unsigned int(*) (void *)) &hashCodetpd,
+                           (int(*) (void *,void *)) &comparetpd);
          
          /* Process task information */
          processtasks();
@@ -475,7 +488,8 @@ inline void run(void * arg) {
                  BAMBOO_DEBUGPRINT(0xee01);
 #endif  
                  
-                 // check if there are some pending objects, if yes, enqueue them and executetasks again
+                 // check if there are some pending objects, 
+                       // if yes, enqueue them and executetasks again
                  tocontinue = checkObjQueue();
 
                  if(!tocontinue) {
@@ -511,7 +525,8 @@ inline void run(void * arg) {
                                                          BAMBOO_DEBUGPRINT(0xee0b);
 #endif
                                                          // send stall msg
-                                                         send_msg_4(STARTUPCORE, 1, BAMBOO_NUM_OF_CORE, self_numsendobjs, self_numreceiveobjs);
+                                                         send_msg_4(STARTUPCORE, 1, BAMBOO_NUM_OF_CORE, 
+                                                                                      self_numsendobjs, self_numreceiveobjs);
                                                          sendStall = true;
                                                          isfirst = true;
                                                          busystatus = false;
@@ -533,16 +548,21 @@ inline void run(void * arg) {
 
 } // run()
 
-void createstartupobject(int argc, char ** argv) {
+void createstartupobject(int argc, 
+                                    char ** argv) {
   int i;
 
   /* Allocate startup object     */
 #ifdef MULTICORE_GC
-  struct ___StartupObject___ *startupobject=(struct ___StartupObject___*) allocate_new(NULL, STARTUPTYPE);
-  struct ArrayObject * stringarray=allocate_newarray(NULL, STRINGARRAYTYPE, argc-1);
+  struct ___StartupObject___ *startupobject=
+               (struct ___StartupObject___*) allocate_new(NULL, STARTUPTYPE);
+  struct ArrayObject * stringarray=
+               allocate_newarray(NULL, STRINGARRAYTYPE, argc-1);
 #else
-  struct ___StartupObject___ *startupobject=(struct ___StartupObject___*) allocate_new(STARTUPTYPE);
-  struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc-1);
+  struct ___StartupObject___ *startupobject=
+               (struct ___StartupObject___*) allocate_new(STARTUPTYPE);
+  struct ArrayObject * stringarray=
+               allocate_newarray(STRINGARRAYTYPE, argc-1);
 #endif
   /* Build array of strings */
   startupobject->___parameters___=stringarray;
@@ -553,7 +573,8 @@ void createstartupobject(int argc, char ** argv) {
 #else
     struct ___String___ *newstring=NewString(argv[i],length);
 #endif
-    ((void **)(((char *)&stringarray->___length___)+sizeof(int)))[i-1]=newstring;
+    ((void **)(((char *)&stringarray->___length___)+sizeof(int)))[i-1]=
+                       newstring;
   }
 
   startupobject->version = 0;
@@ -576,7 +597,8 @@ int hashCodetpd(struct taskparamdescriptor *ftd) {
   return hash;
 }
 
-int comparetpd(struct taskparamdescriptor *ftd1, struct taskparamdescriptor *ftd2) {
+int comparetpd(struct taskparamdescriptor *ftd1, 
+                          struct taskparamdescriptor *ftd2) {
   int i;
   if (ftd1->task!=ftd2->task)
     return 0;
@@ -588,9 +610,12 @@ int comparetpd(struct taskparamdescriptor *ftd1, struct taskparamdescriptor *ftd
 
 /* This function sets a tag. */
 #ifdef MULTICORE_GC
-void tagset(void *ptr, struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) {
+void tagset(void *ptr, 
+                       struct ___Object___ * obj, 
+                                               struct ___TagDescriptor___ * tagd) {
 #else
-void tagset(struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) {
+void tagset(struct ___Object___ * obj, 
+                       struct ___TagDescriptor___ * tagd) {
 #endif
   struct ArrayObject * ao=NULL;
   struct ___Object___ * tagptr=obj->___tags___;
@@ -605,7 +630,8 @@ void tagset(struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) {
       }
 #ifdef MULTICORE_GC
       int ptrarray[]={2, (int) ptr, (int) obj, (int)tagd};
-      struct ArrayObject * ao=allocate_newarray(&ptrarray,TAGARRAYTYPE,TAGARRAYINTERVAL);
+      struct ArrayObject * ao=
+                               allocate_newarray(&ptrarray,TAGARRAYTYPE,TAGARRAYINTERVAL);
       obj=(struct ___Object___ *)ptrarray[2];
       tagd=(struct ___TagDescriptor___ *)ptrarray[3];
       td=(struct ___TagDescriptor___ *) obj->___tags___;
@@ -622,7 +648,8 @@ void tagset(struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) {
       int i;
       struct ArrayObject *ao=(struct ArrayObject *) tagptr;
       for(i=0; i<ao->___cachedCode___; i++) {
-       struct ___TagDescriptor___ * td=ARRAYGET(ao, struct ___TagDescriptor___*, i);
+       struct ___TagDescriptor___ * td=
+               ARRAYGET(ao, struct ___TagDescriptor___*, i);
        if (td==tagd) {
          return;
        }
@@ -633,17 +660,21 @@ void tagset(struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) {
       } else {
 #ifdef MULTICORE_GC
        int ptrarray[]={2,(int) ptr, (int) obj, (int) tagd};
-       struct ArrayObject * aonew=allocate_newarray(&ptrarray,TAGARRAYTYPE,TAGARRAYINTERVAL+ao->___length___);
+       struct ArrayObject * aonew=
+               allocate_newarray(&ptrarray,TAGARRAYTYPE,
+                                             TAGARRAYINTERVAL+ao->___length___);
        obj=(struct ___Object___ *)ptrarray[2];
        tagd=(struct ___TagDescriptor___ *) ptrarray[3];
        ao=(struct ArrayObject *)obj->___tags___;
 #else
-       struct ArrayObject * aonew=allocate_newarray(TAGARRAYTYPE,TAGARRAYINTERVAL+ao->___length___);
+       struct ArrayObject * aonew=
+               allocate_newarray(TAGARRAYTYPE,TAGARRAYINTERVAL+ao->___length___);
 #endif
 
        aonew->___cachedCode___=ao->___length___+1;
        for(i=0; i<ao->___length___; i++) {
-         ARRAYSET(aonew, struct ___TagDescriptor___*, i, ARRAYGET(ao, struct ___TagDescriptor___*, i));
+         ARRAYSET(aonew, struct ___TagDescriptor___*, i, 
+                                    ARRAYGET(ao, struct ___TagDescriptor___*, i));
        }
        ARRAYSET(aonew, struct ___TagDescriptor___ *, ao->___length___, tagd);
       }
@@ -657,11 +688,13 @@ void tagset(struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) {
     } else if (tagset->type!=OBJECTARRAYTYPE) {
 #ifdef MULTICORE_GC
       int ptrarray[]={2, (int) ptr, (int) obj, (int)tagd};
-      struct ArrayObject * ao=allocate_newarray(&ptrarray,OBJECTARRAYTYPE,OBJECTARRAYINTERVAL);
+      struct ArrayObject * ao=
+                               allocate_newarray(&ptrarray,OBJECTARRAYTYPE,OBJECTARRAYINTERVAL);
       obj=(struct ___Object___ *)ptrarray[2];
       tagd=(struct ___TagDescriptor___ *)ptrarray[3];
 #else
-      struct ArrayObject * ao=allocate_newarray(OBJECTARRAYTYPE,OBJECTARRAYINTERVAL);
+      struct ArrayObject * ao=
+                               allocate_newarray(OBJECTARRAYTYPE,OBJECTARRAYINTERVAL);
 #endif
       ARRAYSET(ao, struct ___Object___ *, 0, tagd->flagptr);
       ARRAYSET(ao, struct ___Object___ *, 1, obj);
@@ -675,16 +708,20 @@ void tagset(struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) {
        int i;
 #ifdef MULTICORE_GC
        int ptrarray[]={2, (int) ptr, (int) obj, (int)tagd};
-       struct ArrayObject * aonew=allocate_newarray(&ptrarray,OBJECTARRAYTYPE,OBJECTARRAYINTERVAL+ao->___length___);
+       struct ArrayObject * aonew=
+               allocate_newarray(&ptrarray,OBJECTARRAYTYPE,
+                                             OBJECTARRAYINTERVAL+ao->___length___);
        obj=(struct ___Object___ *)ptrarray[2];
        tagd=(struct ___TagDescriptor___ *)ptrarray[3];
        ao=(struct ArrayObject *)tagd->flagptr;
 #else
-       struct ArrayObject * aonew=allocate_newarray(OBJECTARRAYTYPE,OBJECTARRAYINTERVAL);
+       struct ArrayObject * aonew=
+               allocate_newarray(OBJECTARRAYTYPE,OBJECTARRAYINTERVAL);
 #endif
        aonew->___cachedCode___=ao->___cachedCode___+1;
        for(i=0; i<ao->___length___; i++) {
-         ARRAYSET(aonew, struct ___Object___*, i, ARRAYGET(ao, struct ___Object___*, i));
+         ARRAYSET(aonew, struct ___Object___*, i, 
+                                    ARRAYGET(ao, struct ___Object___*, i));
        }
        ARRAYSET(aonew, struct ___Object___ *, ao->___cachedCode___, obj);
        tagd->flagptr=(struct ___Object___ *) aonew;
@@ -695,9 +732,12 @@ void tagset(struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) {
 
 /* This function clears a tag. */
 #ifdef MULTICORE_GC
-void tagclear(void *ptr, struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) {
+void tagclear(void *ptr, 
+                         struct ___Object___ * obj, 
+                                                       struct ___TagDescriptor___ * tagd) {
 #else
-void tagclear(struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) {
+void tagclear(struct ___Object___ * obj, 
+                         struct ___TagDescriptor___ * tagd) {
 #endif
   /* We'll assume that tag is alway there.
      Need to statically check for this of course. */
@@ -706,30 +746,23 @@ void tagclear(struct ___Object___ * obj, struct ___TagDescriptor___ * tagd) {
   if (tagptr->type==TAGTYPE) {
     if ((struct ___TagDescriptor___ *)tagptr==tagd)
       obj->___tags___=NULL;
-    else
-#ifndef MULTICORE
-      printf("ERROR 1 in tagclear\n");
-#else
-         ;
-#endif
   } else {
     struct ArrayObject *ao=(struct ArrayObject *) tagptr;
     int i;
     for(i=0; i<ao->___cachedCode___; i++) {
-      struct ___TagDescriptor___ * td=ARRAYGET(ao, struct ___TagDescriptor___ *, i);
+      struct ___TagDescriptor___ * td=
+                               ARRAYGET(ao, struct ___TagDescriptor___ *, i);
       if (td==tagd) {
        ao->___cachedCode___--;
        if (i<ao->___cachedCode___)
-         ARRAYSET(ao, struct ___TagDescriptor___ *, i, ARRAYGET(ao, struct ___TagDescriptor___ *, ao->___cachedCode___));
+         ARRAYSET(ao, struct ___TagDescriptor___ *, i, 
+                               ARRAYGET(ao, struct ___TagDescriptor___ *, ao->___cachedCode___));
        ARRAYSET(ao, struct ___TagDescriptor___ *, ao->___cachedCode___, NULL);
        if (ao->___cachedCode___==0)
          obj->___tags___=NULL;
        goto PROCESSCLEAR;
       }
     }
-#ifndef MULTICORE
-    printf("ERROR 2 in tagclear\n");
-#endif
   }
 PROCESSCLEAR:
   {
@@ -737,12 +770,6 @@ PROCESSCLEAR:
     if (tagset->type!=OBJECTARRAYTYPE) {
       if (tagset==obj)
        tagd->flagptr=NULL;
-      else
-#ifndef MULTICORE
-       printf("ERROR 3 in tagclear\n");
-#else
-         ;
-#endif
     } else {
       struct ArrayObject *ao=(struct ArrayObject *) tagset;
       int i;
@@ -751,16 +778,14 @@ PROCESSCLEAR:
        if (tobj==obj) {
          ao->___cachedCode___--;
          if (i<ao->___cachedCode___)
-           ARRAYSET(ao, struct ___Object___ *, i, ARRAYGET(ao, struct ___Object___ *, ao->___cachedCode___));
+           ARRAYSET(ao, struct ___Object___ *, i, 
+                                       ARRAYGET(ao, struct ___Object___ *, ao->___cachedCode___));
          ARRAYSET(ao, struct ___Object___ *, ao->___cachedCode___, NULL);
          if (ao->___cachedCode___==0)
            tagd->flagptr=NULL;
          goto ENDCLEAR;
        }
       }
-#ifndef MULTICORE
-      printf("ERROR 4 in tagclear\n");
-#endif
     }
   }
 ENDCLEAR:
@@ -769,8 +794,11 @@ ENDCLEAR:
 
 /* This function allocates a new tag. */
 #ifdef MULTICORE_GC
-struct ___TagDescriptor___ * allocate_tag(void *ptr, int index) {
-  struct ___TagDescriptor___ * v=(struct ___TagDescriptor___ *) FREEMALLOC((struct garbagelist *) ptr, classsize[TAGTYPE]);
+struct ___TagDescriptor___ * allocate_tag(void *ptr, 
+                                                     int index) {
+  struct ___TagDescriptor___ * v=
+               (struct ___TagDescriptor___ *) FREEMALLOC((struct garbagelist *) ptr, 
+                                                                     classsize[TAGTYPE]);
 #else
 struct ___TagDescriptor___ * allocate_tag(int index) {
   struct ___TagDescriptor___ * v=FREEMALLOC(classsize[TAGTYPE]);
@@ -786,13 +814,21 @@ struct ___TagDescriptor___ * allocate_tag(int index) {
 /* This function updates the flag for object ptr.  It or's the flag
    with the or mask and and's it with the andmask. */
 
-void flagbody(struct ___Object___ *ptr, int flag, struct parameterwrapper ** queues, int length, bool isnew);
+void flagbody(struct ___Object___ *ptr, 
+                         int flag, 
+                                                       struct parameterwrapper ** queues, 
+                                                       int length, 
+                                                       bool isnew);
 
 int flagcomp(const int *val1, const int *val2) {
   return (*val1)-(*val2);
 }
 
-void flagorand(void * ptr, int ormask, int andmask, struct parameterwrapper ** queues, int length) {
+void flagorand(void * ptr, 
+                          int ormask, 
+                                                        int andmask, 
+                                                        struct parameterwrapper ** queues, 
+                                                        int length) {
   {
     int oldflag=((int *)ptr)[1];
     int flag=ormask|oldflag;
@@ -801,7 +837,9 @@ void flagorand(void * ptr, int ormask, int andmask, struct parameterwrapper ** q
   }
 }
 
-bool intflagorand(void * ptr, int ormask, int andmask) {
+bool intflagorand(void * ptr, 
+                             int ormask, 
+                                                                       int andmask) {
   {
     int oldflag=((int *)ptr)[1];
     int flag=ormask|oldflag;
@@ -815,14 +853,20 @@ bool intflagorand(void * ptr, int ormask, int andmask) {
   }
 }
 
-void flagorandinit(void * ptr, int ormask, int andmask) {
+void flagorandinit(void * ptr, 
+                              int ormask, 
+                                                                        int andmask) {
   int oldflag=((int *)ptr)[1];
   int flag=ormask|oldflag;
   flag&=andmask;
   flagbody(ptr,flag,NULL,0,true);
 }
 
-void flagbody(struct ___Object___ *ptr, int flag, struct parameterwrapper ** vqueues, int vlength, bool isnew) {
+void flagbody(struct ___Object___ *ptr, 
+                         int flag, 
+                                                       struct parameterwrapper ** vqueues, 
+                                                       int vlength, 
+                                                       bool isnew) {
   struct parameterwrapper * flagptr = NULL;
   int i = 0;
   struct parameterwrapper ** queues = vqueues;
@@ -843,14 +887,17 @@ void flagbody(struct ___Object___ *ptr, int flag, struct parameterwrapper ** vqu
   /*Remove object from all queues */
   for(i = 0; i < length; ++i) {
     flagptr = queues[i];
-    ObjectHashget(flagptr->objectset, (int) ptr, (int *) &next, (int *) &enterflags, &UNUSED, &UNUSED2);
+    ObjectHashget(flagptr->objectset, (int) ptr, (int *) &next, 
+                                         (int *) &enterflags, &UNUSED, &UNUSED2);
     ObjectHashremove(flagptr->objectset, (int)ptr);
     if (enterflags!=NULL)
       RUNFREE(enterflags);
   }
 }
 
-void enqueueObject(void * vptr, struct parameterwrapper ** vqueues, int vlength) {
+void enqueueObject(void * vptr, 
+                              struct parameterwrapper ** vqueues, 
+                                                                        int vlength) {
        struct ___Object___ *ptr = (struct ___Object___ *)vptr;
        
        {
@@ -878,9 +925,11 @@ void enqueueObject(void * vptr, struct parameterwrapper ** vqueues, int vlength)
                        /* Check tags */
                        if (parameter->numbertags>0) {
                                if (tagptr==NULL)
-                                       goto nextloop; //that means the object has no tag but that param needs tag
+                                       goto nextloop; //that means the object has no tag 
+                                                //but that param needs tag
                                else if(tagptr->type==TAGTYPE) { //one tag
-                                       //struct ___TagDescriptor___ * tag=(struct ___TagDescriptor___*) tagptr;         
+                                       //struct ___TagDescriptor___ * tag=
+                                       //(struct ___TagDescriptor___*) tagptr;  
                                        for(i=0; i<parameter->numbertags; i++) {
                                                //slotid is parameter->tagarray[2*i];
                                                int tagid=parameter->tagarray[2*i+1];
@@ -920,7 +969,9 @@ nextloop:
        }
 }
 
-void enqueueObject_I(void * vptr, struct parameterwrapper ** vqueues, int vlength) {
+void enqueueObject_I(void * vptr, 
+                                struct parameterwrapper ** vqueues, 
+                                                                                int vlength) {
        struct ___Object___ *ptr = (struct ___Object___ *)vptr;
        
        {
@@ -948,7 +999,8 @@ void enqueueObject_I(void * vptr, struct parameterwrapper ** vqueues, int vlengt
                        /* Check tags */
                        if (parameter->numbertags>0) {
                                if (tagptr==NULL)
-                                       goto nextloop; //that means the object has no tag but that param needs tag
+                                       goto nextloop; //that means the object has no tag 
+                                                //but that param needs tag
                                else if(tagptr->type==TAGTYPE) { //one tag
                                        //struct ___TagDescriptor___ * tag=(struct ___TagDescriptor___*) tagptr;         
                                        for(i=0; i<parameter->numbertags; i++) {
@@ -991,7 +1043,9 @@ nextloop:
 }
 
 
-int * getAliasLock(void ** ptrs, int length, struct RuntimeHash * tbl) {
+int * getAliasLock(void ** ptrs, 
+                              int length, 
+                                                                        struct RuntimeHash * tbl) {
        if(length == 0) {
                return (int*)(RUNMALLOC(sizeof(int)));
        } else {
@@ -1052,7 +1106,8 @@ int * getAliasLock(void ** ptrs, int length, struct RuntimeHash * tbl) {
        }
 }
 
-void addAliasLock(void * ptr, int lock) {
+void addAliasLock(void * ptr, 
+                             int lock) {
   struct ___Object___ * obj = (struct ___Object___ *)ptr;
   if(((int)ptr != lock) && (obj->lock != (int*)lock)) {
     // originally no alias lock associated or have a different alias lock
@@ -1074,6 +1129,69 @@ inline void addNewObjInfo(void * nobj) {
 }
 #endif
 
+void * smemalloc(int size, 
+                            int * allocsize) {
+       // TODO can not handle large obj which is bigger than a block
+#ifdef MULTICORE_GC
+       // go through free mem list for suitable blocks
+       struct freeMemItem * freemem = bamboo_free_mem_list->head;
+       struct freeMemItem * prev = NULL;
+       do {
+smemsearch:
+               if(freemem->size > size) {
+                       // found one
+                       break;
+               }
+               prev = freemem;
+               freemem = freemem->next;
+       } while(freemem != NULL);
+       if(freemem != NULL) {
+               void * mem = (void *)(freemem->ptr);
+               int b = 0;
+               BLOCKINDEX(mem, &b);
+               // check the remaining space in this block
+               int remain = BAMBOO_SMEM_SIZE_L+b*BAMBOO_SMEM_SIZE-(mem-BAMBOO_BASE_VA);
+               // TODO how about large objs?
+               if(remain < size) {
+                       // not enough space in this block
+                       struct freeMemItem * tmp = 
+                               (struct freeMemItem*)RUNMALLOC(sizeof(struct freeMemItem));
+                       tmp->ptr = mem;
+                       tmp->size = remain;
+                       tmp->next = freemem;
+                       if(bamboo_free_mem_list->head == freemem) {
+                               bamboo_free_mem_list->head = tmp;
+                       } else {
+                               prev->next = tmp;
+                       }
+                       freemem->ptr += size;
+                       freemem->size -= size;
+                       // continue checking
+                       goto smemsearch;
+               } else {
+                       *allocsize = size;
+                       freemem->ptr += size;
+                       freemem->size -= size;
+               }
+       } else {
+#else
+       void * mem = mspace_calloc(bamboo_free_msp, 1, size);
+       *allocsize = size;
+       if(mem == NULL) {
+#endif
+               // no enough shared global memory
+               *allocsize = 0;
+#ifdef MULTICORE_GC
+               gcflag = true;
+               return NULL;
+#else
+               BAMBOO_DEBUGPRINT(0xa016);
+               BAMBOO_EXIT(0xa016);
+#endif
+       }
+       return mem;
+}
+
 // receive object transferred from other cores
 // or the terminate message from other cores
 // Should be invoked in critical sections!!
@@ -1105,7 +1223,8 @@ msg:
     switch(type) {
     case TRANSOBJ: {
       // receive a object transfer msg
-      struct transObjInfo * transObj = RUNMALLOC_I(sizeof(struct transObjInfo));
+      struct transObjInfo * transObj = 
+                               RUNMALLOC_I(sizeof(struct transObjInfo));
       int k = 0;
 #ifdef DEBUG
 #ifndef TILERA
@@ -1119,7 +1238,7 @@ msg:
                                BAMBOO_EXIT(0xa005);
                        } 
       // store the object and its corresponding queue info, enqueue it later
-      transObj->objptr = (void *)msgdata[2];   // data1 is now size of the msg
+      transObj->objptr = (void *)msgdata[2]; // data1 is now size of the msg
       transObj->length = (msglength - 3) / 2;
       transObj->queues = RUNMALLOC_I(sizeof(int)*(msglength - 3));
       for(k = 0; k < transObj->length; ++k) {
@@ -1193,7 +1312,8 @@ msg:
                        int data2 = msgdata[2]; // obj pointer
       int data3 = msgdata[3]; // lock
                        int data4 = msgdata[4]; // request core
-      deny = processlockrequest(data1, data3, data2, data4, data4, true);  // -1: redirected, 0: approved, 1: denied
+                       // -1: redirected, 0: approved, 1: denied
+      deny = processlockrequest(data1, data3, data2, data4, data4, true);  
                        if(deny == -1) {
                                // this lock request is redirected
                                break;
@@ -1493,22 +1613,16 @@ msg:
                                break;
                        }
 #endif
-                 void * mem = mspace_calloc(bamboo_free_msp, 1, msgdata[1]);
-                 if(mem == NULL) {
-                               // no enough shared global memory
-#ifdef MULTICORE_GC
-                               gcflag = true;
+                       int allocsize = 0;
+                 void * mem = smemalloc(msgdata[1], &allocsize);
+                       if(mem == NULL) {
                                break;
-#else
-                         BAMBOO_DEBUGPRINT(0xa016);
-                         BAMBOO_EXIT(0xa016);
-#endif
-                 }
-                 // send the start_va to request core
+                       }
+                       // send the start_va to request core
                        if(isMsgSending) {
-                               cache_msg_3(msgdata[2], MEMRESPONSE, mem, msgdata[1]);
+                               cache_msg_3(msgdata[2], MEMRESPONSE, mem, allocsize);
                        } else {
-                               send_msg_3( msgdata[2], MEMRESPONSE, mem, msgdata[1]);
+                               send_msg_3( msgdata[2], MEMRESPONSE, mem, allocsize);
                        } 
                }
          break;
@@ -1529,14 +1643,18 @@ msg:
 #endif
          if(msgdata[2] == 0) {
                  bamboo_smem_size = 0;
-                 bamboo_cur_msp = NULL;
+                 bamboo_cur_msp = 0;
          } else {
                        // fill header to store the size of this mem block
                        (*((int*)msgdata[1])) = msgdata[2];
                  bamboo_smem_size = msgdata[2] - BAMBOO_CACHE_LINE_SIZE;
-                 bamboo_cur_msp = create_mspace_with_base((void*)(msgdata[1]+BAMBOO_CACHE_LINE_SIZE),
-                                                                                  msgdata[2] - BAMBOO_CACHE_LINE_SIZE, 
-                                                                                                                                                                                        0);
+#ifdef MULTICORE_GC
+                       bamboo_cur_msp = msgdata[1] + BAMBOO_CACHE_LINE_SIZE;
+#else
+                 bamboo_cur_msp = 
+                               create_mspace_with_base((void*)(msgdata[1]+BAMBOO_CACHE_LINE_SIZE),
+                                                        msgdata[2]-BAMBOO_CACHE_LINE_SIZE, 
+                                                                                                                                0);
          }
          smemflag = true;
          break;
@@ -1679,7 +1797,8 @@ msg:
                  // send response msg
                  if(isMsgSending) {
                          cache_msg_5(STARTUPCORE, GCMARKREPORT, BAMBOO_NUM_OF_CORE, 
-                                                       gcbusystatus, gcself_numsendobjs, gcself_numreceiveobjs);
+                                                       gcbusystatus, gcself_numsendobjs, 
+                                                                               gcself_numreceiveobjs);
                  } else {
                          send_msg_5(STARTUPCORE, GCMARKREPORT, BAMBOO_NUM_OF_CORE, 
                                                       gcbusystatus, gcself_numsendobjs, gcself_numreceiveobjs);
@@ -1772,8 +1891,18 @@ msg:
 
        case GCLOBJINFO: {
                // received a large objs info response msg
-               // TODO
                gcwaitconfirm--;
+
+               if(BAMBOO_NUM_OF_CORE > NUMCORES - 1) {
+#ifndef TILERA
+                       BAMBOO_DEBUGPRINT_REG(msgdata[2]);
+#endif
+                       BAMBOO_EXIT(0xa005);
+               } 
+               // store the mark result info 
+               int cnum = msgdata[2];
+               gcloads[cnum] = msgdata[3];
+               // TODO large obj info here
                break;
        }
 #endif
@@ -1818,7 +1947,11 @@ msg:
 }
 
 
-ent enqueuetasks(struct parameterwrapper *parameter, struct parameterwrapper *prevptr, struct ___Object___ *ptr, int * enterflags, int numenterflags) {
+int enqueuetasks(struct parameterwrapper *parameter, 
+                            struct parameterwrapper *prevptr, 
+                                                                struct ___Object___ *ptr, 
+                                                                int * enterflags, 
+                                                                int numenterflags) {
   void * taskpointerarray[MAXTASKPARAMS];
   int j;
   //int numparams=parameter->task->numParameters;
@@ -1828,7 +1961,8 @@ ent enqueuetasks(struct parameterwrapper *parameter, struct parameterwrapper *pr
   struct taskdescriptor * task=parameter->task;
 
    //this add the object to parameterwrapper
-   ObjectHashadd(parameter->objectset, (int) ptr, 0, (int) enterflags, numenterflags, enterflags==NULL);
+   ObjectHashadd(parameter->objectset, (int) ptr, 0, (int) enterflags, 
+                                  numenterflags, enterflags==NULL);
 
   /* Add enqueued object to parameter vector */
   taskpointerarray[parameter->slot]=ptr;
@@ -1841,7 +1975,7 @@ ent enqueuetasks(struct parameterwrapper *parameter, struct parameterwrapper *pr
   /* Find initial state */
   for(j=0; j<numiterators; j++) {
 backtrackinit:
-    if(toiHasNext(&parameter->iterators[j], taskpointerarray OPTARG(failed)))
+    if(toiHasNext(&parameter->iterators[j],taskpointerarray OPTARG(failed)))
       toiNext(&parameter->iterators[j], taskpointerarray OPTARG(failed));
     else if (j>0) {
       /* Need to backtrack */
@@ -1857,16 +1991,19 @@ backtrackinit:
   while(1) {
     /* Enqueue current state */
     //int launch = 0;
-    struct taskparamdescriptor *tpd=RUNMALLOC(sizeof(struct taskparamdescriptor));
+    struct taskparamdescriptor *tpd=
+                       RUNMALLOC(sizeof(struct taskparamdescriptor));
     tpd->task=task;
     tpd->numParameters=numiterators+1;
     tpd->parameterArray=RUNMALLOC(sizeof(void *)*(numiterators+1));
 
     for(j=0; j<=numiterators; j++) {
-      tpd->parameterArray[j]=taskpointerarray[j]; //store the actual parameters
+                       //store the actual parameters
+      tpd->parameterArray[j]=taskpointerarray[j]; 
     }
     /* Enqueue task */
-    if ((/*!gencontains(failedtasks, tpd)&&*/ !gencontains(activetasks,tpd))) {
+    if ((/*!gencontains(failedtasks, tpd)&&*/ 
+                                       !gencontains(activetasks,tpd))) {
                genputtable(activetasks, tpd, tpd);
     } else {
       RUNFREE(tpd->parameterArray);
@@ -1879,7 +2016,7 @@ backtrackinit:
 
     for(j=numiterators-1; j<numiterators; j++) {
 backtrackinc:
-      if(toiHasNext(&parameter->iterators[j], taskpointerarray OPTARG(failed)))
+      if(toiHasNext(&parameter->iterators[j],taskpointerarray OPTARG(failed)))
        toiNext(&parameter->iterators[j], taskpointerarray OPTARG(failed));
       else if (j>0) {
        /* Need to backtrack */
@@ -1895,7 +2032,11 @@ backtrackinc:
   return retval;
 }
 
-int enqueuetasks_I(struct parameterwrapper *parameter, struct parameterwrapper *prevptr, struct ___Object___ *ptr, int * enterflags, int numenterflags) {
+int enqueuetasks_I(struct parameterwrapper *parameter, 
+                              struct parameterwrapper *prevptr, 
+                                                                        struct ___Object___ *ptr, 
+                                                                        int * enterflags, 
+                                                                        int numenterflags) {
   void * taskpointerarray[MAXTASKPARAMS];
   int j;
   //int numparams=parameter->task->numParameters;
@@ -1907,7 +2048,8 @@ int enqueuetasks_I(struct parameterwrapper *parameter, struct parameterwrapper *
   struct taskdescriptor * task=parameter->task;
 
    //this add the object to parameterwrapper
-   ObjectHashadd_I(parameter->objectset, (int) ptr, 0, (int) enterflags, numenterflags, enterflags==NULL);  
+   ObjectHashadd_I(parameter->objectset, (int) ptr, 0, (int) enterflags, 
+                                    numenterflags, enterflags==NULL);  
 
   /* Add enqueued object to parameter vector */
   taskpointerarray[parameter->slot]=ptr;
@@ -1920,7 +2062,7 @@ int enqueuetasks_I(struct parameterwrapper *parameter, struct parameterwrapper *
   /* Find initial state */
   for(j=0; j<numiterators; j++) {
 backtrackinit:
-    if(toiHasNext(&parameter->iterators[j], taskpointerarray OPTARG(failed)))
+    if(toiHasNext(&parameter->iterators[j],taskpointerarray OPTARG(failed)))
       toiNext(&parameter->iterators[j], taskpointerarray OPTARG(failed));
     else if (j>0) {
       /* Need to backtrack */
@@ -1936,16 +2078,19 @@ backtrackinit:
   while(1) {
     /* Enqueue current state */
     //int launch = 0;
-    struct taskparamdescriptor *tpd=RUNMALLOC_I(sizeof(struct taskparamdescriptor));
+    struct taskparamdescriptor *tpd=
+                       RUNMALLOC_I(sizeof(struct taskparamdescriptor));
     tpd->task=task;
     tpd->numParameters=numiterators+1;
     tpd->parameterArray=RUNMALLOC_I(sizeof(void *)*(numiterators+1));
 
     for(j=0; j<=numiterators; j++) {
-      tpd->parameterArray[j]=taskpointerarray[j]; //store the actual parameters
+                       //store the actual parameters
+      tpd->parameterArray[j]=taskpointerarray[j]; 
     }
     /* Enqueue task */
-    if ((/*!gencontains(failedtasks, tpd)&&*/ !gencontains(activetasks,tpd))) {
+    if ((/*!gencontains(failedtasks, tpd)&&*/ 
+                                       !gencontains(activetasks,tpd))) {
                genputtable_I(activetasks, tpd, tpd);
     } else {
       RUNFREE(tpd->parameterArray);
@@ -1974,50 +2119,14 @@ backtrackinc:
   return retval;
 }
 
-/* Handler for signals. The signals catch null pointer errors and
-   arithmatic errors. */
-#ifndef MULTICORE
-void myhandler(int sig, siginfo_t *info, void *uap) {
-  sigset_t toclear;
-#ifdef DEBUG
-  printf("sig=%d\n",sig);
-  printf("signal\n");
-#endif
-  sigemptyset(&toclear);
-  sigaddset(&toclear, sig);
-  sigprocmask(SIG_UNBLOCK, &toclear,NULL);
-  longjmp(error_handler,1);
-}
-#endif
-
-#ifndef MULTICORE
-fd_set readfds;
-int maxreadfd;
-struct RuntimeHash *fdtoobject;
-
-void addreadfd(int fd) {
-  if (fd>=maxreadfd)
-    maxreadfd=fd+1;
-  FD_SET(fd, &readfds);
-}
-
-void removereadfd(int fd) {
-  FD_CLR(fd, &readfds);
-  if (maxreadfd==(fd+1)) {
-    maxreadfd--;
-    while(maxreadfd>0&&!FD_ISSET(maxreadfd-1, &readfds))
-      maxreadfd--;
-  }
-}
-#endif
-
 #ifdef MULTICORE_GC
 #define OFFSET 2
 #else
 #define OFFSET 0
 #endif
 
-int containstag(struct ___Object___ *ptr, struct ___TagDescriptor___ *tag);
+int containstag(struct ___Object___ *ptr, 
+                           struct ___TagDescriptor___ *tag);
 
 void executetasks() {
   void * taskpointerarray[MAXTASKPARAMS+OFFSET];
@@ -2061,7 +2170,8 @@ newtask:
       numparams=currtpd->task->numParameters;
       numtotal=currtpd->task->numTotal;
 
-         // clear the lockRedirectTbl (TODO, this table should be empty after all locks are released)
+         // clear the lockRedirectTbl 
+               // (TODO, this table should be empty after all locks are released)
          // reset all locks
          for(j = 0; j < MAXTASKPARAMS; j++) {
                  locks[j].redirectlock = 0;
@@ -2188,7 +2298,8 @@ newtask:
 
        // flush the object
 #ifdef CACHEFLUSH
-       BAMBOO_CACHE_FLUSH_RANGE((int)parameter, classsize[((struct ___Object___ *)parameter)->type]);
+       BAMBOO_CACHE_FLUSH_RANGE((int)parameter, 
+                       classsize[((struct ___Object___ *)parameter)->type]);
 #endif
        tmpparam = (struct ___Object___ *)parameter;
        pd=currtpd->task->descriptorarray[i];
@@ -2230,7 +2341,8 @@ newtask:
 #ifdef DEBUG
            BAMBOO_DEBUGPRINT(0xe995);
 #endif
-           ObjectHashget(pw->objectset, (int) parameter, (int *) &next, (int *) &enterflags, &UNUSED, &UNUSED2);
+           ObjectHashget(pw->objectset, (int) parameter, (int *) &next, 
+                                                 (int *) &enterflags, &UNUSED, &UNUSED2);
            ObjectHashremove(pw->objectset, (int)parameter);
            if (enterflags!=NULL)
              RUNFREE(enterflags);
@@ -2296,20 +2408,10 @@ execute:
          profileTaskStart(currtpd->task->name);
 #endif
 
-         if(debugtask) {
-#ifndef MULTICORE
-        printf("ENTER %s count=%d\n",currtpd->task->name, (instaccum-instructioncount));
-#endif
-           ((void(*) (void **))currtpd->task->taskptr)(taskpointerarray);
-#ifndef MULTICORE
-           printf("EXIT %s count=%d\n",currtpd->task->name, (instaccum-instructioncount));
-#endif
-         } else {
 #ifdef DEBUG
-                 BAMBOO_DEBUGPRINT(0xe997);
+               BAMBOO_DEBUGPRINT(0xe997);
 #endif
-           ((void(*) (void **))currtpd->task->taskptr)(taskpointerarray);
-         } // line 2990: if(debugtask)
+               ((void(*) (void **))currtpd->task->taskptr)(taskpointerarray);
 #ifdef PROFILE
 #ifdef ACCURATEPROFILE
          // task finish, set the end of the checkTaskInfo
@@ -2365,7 +2467,12 @@ execute:
 }
 
 /* This function processes an objects tags */
-void processtags(struct parameterdescriptor *pd, int index, struct parameterwrapper *parameter, int * iteratorcount, int *statusarray, int numparams) {
+void processtags(struct parameterdescriptor *pd, 
+                            int index, 
+                                                                struct parameterwrapper *parameter, 
+                                                                int * iteratorcount, 
+                                                                int *statusarray, 
+                                                                int numparams) {
   int i;
 
   for(i=0; i<pd->numbertags; i++) {
@@ -2384,10 +2491,16 @@ void processtags(struct parameterdescriptor *pd, int index, struct parameterwrap
 }
 
 
-void processobject(struct parameterwrapper *parameter, int index, struct parameterdescriptor *pd, int *iteratorcount, int * statusarray, int numparams) {
+void processobject(struct parameterwrapper *parameter, 
+                              int index, 
+                                                                        struct parameterdescriptor *pd, 
+                                                                        int *iteratorcount, 
+                                                                        int * statusarray, 
+                                                                        int numparams) {
   int i;
   int tagcount=0;
-  struct ObjectHash * objectset=((struct parameterwrapper *)pd->queue)->objectset;
+  struct ObjectHash * objectset=
+               ((struct parameterwrapper *)pd->queue)->objectset;
 
   parameter->iterators[*iteratorcount].istag=0;
   parameter->iterators[*iteratorcount].slot=index;
@@ -2399,7 +2512,8 @@ void processobject(struct parameterwrapper *parameter, int index, struct paramet
     //int tagid=pd->tagarray[2*i+1];
     if (statusarray[slotid+numparams]!=0) {
       /* This tag has already been enqueued, use it to narrow search */
-      parameter->iterators[*iteratorcount].tagbindings[tagcount]=slotid+numparams;
+      parameter->iterators[*iteratorcount].tagbindings[tagcount]=
+                               slotid+numparams;
       tagcount++;
     }
   }
@@ -2410,7 +2524,9 @@ void processobject(struct parameterwrapper *parameter, int index, struct paramet
 
 /* This function builds the iterators for a task & parameter */
 
-void builditerators(struct taskdescriptor * task, int index, struct parameterwrapper * parameter) {
+void builditerators(struct taskdescriptor * task, 
+                               int index, 
+                                                                               struct parameterwrapper * parameter) {
   int statusarray[MAXTASKPARAMS];
   int i;
   int numparams=task->numParameters;
@@ -2420,7 +2536,8 @@ void builditerators(struct taskdescriptor * task, int index, struct parameterwra
   statusarray[index]=1; /* Initial parameter */
   /* Process tags for initial iterator */
 
-  processtags(task->descriptorarray[index], index, parameter, &iteratorcount, statusarray, numparams);
+  processtags(task->descriptorarray[index], index, parameter, 
+                               &iteratorcount, statusarray, numparams);
 
   while(1) {
 loopstart:
@@ -2432,7 +2549,8 @@ loopstart:
        for(j=0; j<pd->numbertags; j++) {
          int slotid=pd->tagarray[2*j];
          if(statusarray[slotid+numparams]!=0) {
-           processobject(parameter, i, pd, &iteratorcount, statusarray, numparams);
+           processobject(parameter, i, pd, &iteratorcount, statusarray, 
+                                                 numparams);
            processtags(pd, i, parameter, &iteratorcount, statusarray, numparams);
            goto loopstart;
          }
@@ -2477,7 +2595,7 @@ void printdebug() {
   }
   for(i=0; i<numtasks[BAMBOO_NUM_OF_CORE]; i++) {
     struct taskdescriptor * task=taskarray[BAMBOO_NUM_OF_CORE][i];
-#ifndef MULTICORE
+#ifndef RAW 
        printf("%s\n", task->name);
 #endif
     for(j=0; j<task->numParameters; j++) {
@@ -2485,7 +2603,7 @@ void printdebug() {
       struct parameterwrapper *parameter=param->queue;
       struct ObjectHash * set=parameter->objectset;
       struct ObjectIterator objit;
-#ifndef MULTICORE
+#ifndef RAW
          printf("  Parameter %d\n", j);
 #endif
       ObjectHashiterator(set, &objit);
@@ -2496,13 +2614,13 @@ void printdebug() {
        int numflags=Objdata3(&objit);
        int flags=Objdata2(&objit);
        Objnext(&objit);
-#ifndef MULTICORE
+#ifndef RAW
        printf("    Contains %lx\n", obj);
        printf("      flag=%d\n", obj->flag);
 #endif
        if (tagptr==NULL) {
        } else if (tagptr->type==TAGTYPE) {
-#ifndef MULTICORE
+#ifndef RAW
          printf("      tag=%lx\n",tagptr);
 #else
          ;
@@ -2511,8 +2629,9 @@ void printdebug() {
          int tagindex=0;
          struct ArrayObject *ao=(struct ArrayObject *)tagptr;
          for(; tagindex<ao->___cachedCode___; tagindex++) {
-#ifndef MULTICORE
-                 printf("      tag=%lx\n",ARRAYGET(ao, struct ___TagDescriptor___*, tagindex));
+#ifndef RAW
+                 printf("      tag=%lx\n",ARRAYGET(ao, struct ___TagDescriptor___*, 
+                                                tagindex));
 #else
                  ;
 #endif
@@ -2563,7 +2682,8 @@ void toiReset(struct tagobjectiterator * it) {
   }
 }
 
-int toiHasNext(struct tagobjectiterator *it, void ** objectarray OPTARG(int * failed)) {
+int toiHasNext(struct tagobjectiterator *it, 
+                          void ** objectarray OPTARG(int * failed)) {
   if (it->istag) {
     /* Iterate tag */
     /* Get object with tags */
@@ -2579,7 +2699,8 @@ int toiHasNext(struct tagobjectiterator *it, void ** objectarray OPTARG(int * fa
       struct ArrayObject *ao=(struct ArrayObject *) tagptr;
       int tagindex=it->tagobjindex;
       for(; tagindex<ao->___cachedCode___; tagindex++) {
-       struct ___TagDescriptor___ *td=ARRAYGET(ao, struct ___TagDescriptor___ *, tagindex);
+       struct ___TagDescriptor___ *td=
+               ARRAYGET(ao, struct ___TagDescriptor___ *, tagindex);
        if (td->flag==it->tagid) {
          it->tagobjindex=tagindex; /* Found right type of tag */
          return 1;
@@ -2607,7 +2728,7 @@ int toiHasNext(struct tagobjectiterator *it, void ** objectarray OPTARG(int * fa
       struct ArrayObject *ao=(struct ArrayObject *) objptr;
       int tagindex;
       int i;
-      for(tagindex=it->tagobjindex; tagindex<ao->___cachedCode___; tagindex++) {
+      for(tagindex=it->tagobjindex;tagindex<ao->___cachedCode___;tagindex++) {
        struct ___Object___ *objptr=ARRAYGET(ao, struct ___Object___*, tagindex);
        if (!ObjectHashcontainskey(it->objectset, (int) objptr))
          continue;
@@ -2629,7 +2750,8 @@ nexttag:
   }
 }
 
-int containstag(struct ___Object___ *ptr, struct ___TagDescriptor___ *tag) {
+int containstag(struct ___Object___ *ptr, 
+                           struct ___TagDescriptor___ *tag) {
   int j;
   struct ___Object___ * objptr=tag->flagptr;
   if (objptr->type==OBJECTARRAYTYPE) {
@@ -2643,7 +2765,8 @@ int containstag(struct ___Object___ *ptr, struct ___TagDescriptor___ *tag) {
     return objptr==ptr;
 }
 
-void toiNext(struct tagobjectiterator *it, void ** objectarray OPTARG(int * failed)) {
+void toiNext(struct tagobjectiterator *it, 
+                        void ** objectarray OPTARG(int * failed)) {
   /* hasNext has all of the intelligence */
   if(it->istag) {
     /* Iterate tag */
@@ -2655,7 +2778,8 @@ void toiNext(struct tagobjectiterator *it, void ** objectarray OPTARG(int * fail
       objectarray[it->slot]=tagptr;
     } else {
       struct ArrayObject *ao=(struct ArrayObject *) tagptr;
-      objectarray[it->slot]=ARRAYGET(ao, struct ___TagDescriptor___ *, it->tagobjindex++);
+      objectarray[it->slot]=
+                               ARRAYGET(ao, struct ___TagDescriptor___ *, it->tagobjindex++);
     }
   } else if (it->numtags>0) {
     /* Use tags to locate appropriate objects */
@@ -2666,7 +2790,8 @@ void toiNext(struct tagobjectiterator *it, void ** objectarray OPTARG(int * fail
       objectarray[it->slot]=objptr;
     } else {
       struct ArrayObject *ao=(struct ArrayObject *) objptr;
-      objectarray[it->slot]=ARRAYGET(ao, struct ___Object___ *, it->tagobjindex++);
+      objectarray[it->slot]=
+                               ARRAYGET(ao, struct ___Object___ *, it->tagobjindex++);
     }
   } else {
     /* Iterate object */
index 76c169264901344f136660ddb64abf9080856d51..b102305a61ebb8a4ccd5a9e1e9793fa6fb7685f6 100644 (file)
@@ -121,7 +121,6 @@ struct transObjInfo {
   int * queues;
   int length;
 };
-struct RuntimeHash * lockRedirectTbl;
 #endif
 
 #ifdef FASTCHECK
@@ -140,6 +139,7 @@ inline void addNewObjInfo(void * nobj);
 #endif
 int * getAliasLock(void ** ptrs, int length, struct RuntimeHash * tbl);
 void addAliasLock(void * ptr, int lock);
+void * smemalloc(int size, int * allocsize);
 #else
 void flagorand(void * ptr, int ormask, int andmask);
 void flagorandinit(void * ptr, int ormask, int andmask);