fix bugs in multicoregc
authorjzhou <jzhou>
Sat, 5 Dec 2009 01:28:47 +0000 (01:28 +0000)
committerjzhou <jzhou>
Sat, 5 Dec 2009 01:28:47 +0000 (01:28 +0000)
Robust/src/Benchmarks/Scheduling/Tracking/TrackDemo.java
Robust/src/IR/Flat/BuildCodeMultiCore.java
Robust/src/Runtime/multicoregarbage.c
Robust/src/Runtime/multicoreruntime.c
Robust/src/Runtime/multicoreruntime.h
Robust/src/Runtime/multicoretask.c

index 778a802797ebfa167a311524c4715168be1e6afa..4a60902a6d00f986506c5beba9476cb3bf83a1ef 100644 (file)
@@ -60,6 +60,7 @@ public class TrackDemo {
       this.m_count = 0;
       
       this.m_num_bp = 0;
+                       this.m_num_bpl = 0;
       
       this.WINSZ = 8;
       this.N_FEA = 16; //00;
@@ -91,6 +92,17 @@ public class TrackDemo {
       this.m_cols_3f = this.N_FEA;
       this.m_counter_3f = 3;
       this.m_num_p = nump;
+
+                       this.m_rows = 0;
+                       this.m_cols = 0;
+                       this.m_image = null;
+                       this.m_image_resized = null;
+                       this.m_rows_r = 0;
+                       this.m_cols_r = 0;
+
+                       this.m_features = null;
+                       this.m_rows_f = 0;
+                       this.m_cols_f = 0;
     }
     
     public int getNumP() {
@@ -383,13 +395,13 @@ public class TrackDemo {
               }
             }
             if(k == nfea) {
-              System.printI(77777777);
+              //System.printI(77777777);
               return false;
             } else if(k == rindex) {
               k = k1;
             }
             if(f_ind[k] && (m3f[2][k] != image[localindex])) {
-              System.printI(88888888);
+              //System.printI(88888888);
               return false;
             }
             // move all things after k behind
@@ -1144,4 +1156,4 @@ public class TrackDemo {
           }
       }
     }
-}
\ No newline at end of file
+}
index 844b2592fbb06f0f1145d71cfc2302071ca40402..3b6146543d822ec8add15783a4f25309100987b4 100644 (file)
@@ -37,6 +37,7 @@ import IR.Tree.TagExpressionList;
 public class BuildCodeMultiCore extends BuildCode {
   private Vector<Schedule> scheduling;
   int coreNum;
+  int tcoreNum;
   Schedule currentSchedule;
   Hashtable[] fsate2qnames;
   String objqarrayprefix= "objqueuearray4class";
@@ -64,6 +65,7 @@ public class BuildCodeMultiCore extends BuildCode {
     super(st, temptovar, typeutil, sa, pa);
     this.scheduling = scheduling;
     this.coreNum = coreNum;
+    this.tcoreNum = coreNum;
     this.currentSchedule = null;
     this.fsate2qnames = null;
     this.startupcorenum = 0;
@@ -290,8 +292,10 @@ public class BuildCodeMultiCore extends BuildCode {
       outstructs.println("#define MAXTASKPARAMS "+maxtaskparams);
       /* Record maximum number of all types, i.e. length of classsize[] */
       outstructs.println("#define NUMTYPES "+(state.numClasses() + state.numArrays()));
-      /* Record number of cores */
-      outstructs.println("#define NUMCORES "+this.coreNum);
+      /* Record number of total cores */
+      outstructs.println("#define NUMCORES "+this.tcoreNum);
+      /* Record number of active cores */
+      outstructs.println("#define NUMCORESACTIVE "+this.coreNum);
       /* Record number of core containing startup task */
       outstructs.println("#define STARTUPCORE "+this.startupcorenum);
     }     //else if (state.main!=null) {
index 7b486c5b21ca86ad57f34666aaa11ef49c6ef451..daa0177b645d9bc77c4aefc53e8748e3a81a3a7d 100644 (file)
@@ -40,6 +40,7 @@ struct lobjpointerblock {
        //void * origs[NUMLOBJPTRS];
        int hosts[NUMLOBJPTRS];
   struct lobjpointerblock *next;
+       struct lobjpointerblock *prev;
 };
 
 struct lobjpointerblock *gclobjhead=NULL;
@@ -201,6 +202,7 @@ inline void gc_lobjenqueue_I(void *ptr,
       tmp=RUNMALLOC_I(sizeof(struct lobjpointerblock));
                } // if (gclobjspare!=NULL)
     gclobjhead->next=tmp;
+               tmp->prev = gclobjhead;
     gclobjhead=tmp;
     gclobjheadindex=0;
   } // if (gclobjheadindex==NUMLOBJPTRS)
@@ -221,10 +223,13 @@ inline void * gc_lobjdequeue(int * length,
     struct lobjpointerblock *tmp=gclobjtail;
     gclobjtail=gclobjtail->next;
     gclobjtailindex=0;
+               gclobjtail->prev = NULL;
     if (gclobjspare!=NULL) {
       RUNFREE(tmp);
                } else {
       gclobjspare=tmp;
+                       tmp->next = NULL;
+                       tmp->prev = NULL;
                } // if (gclobjspare!=NULL)
   } // if (gclobjtailindex==NUMLOBJPTRS)
        if(length != NULL) {
@@ -258,6 +263,22 @@ inline int gc_lobjmoreItems2() {
   return 1;
 } // int gc_lobjmoreItems2()
 
+// 'reversly' dequeue and don't destroy the queue
+inline void gc_lobjdequeue3() {
+  if (gclobjtailindex2==0) {
+    gclobjtail2=gclobjtail2->prev;
+    gclobjtailindex2=NUMLOBJPTRS-1;
+  } else {
+               gclobjtailindex2--;
+       }// if (gclobjtailindex2==NUMLOBJPTRS)
+} // void * gc_lobjdequeue3()
+
+inline int gc_lobjmoreItems3() {
+  if ((gclobjtail==gclobjtail2)&&(gclobjtailindex2==gclobjtailindex))
+    return 0;
+  return 1;
+} // int gc_lobjmoreItems3()
+
 INTPTR gccurr_heapbound = 0;
 
 inline void gettype_size(void * ptr, 
@@ -437,12 +458,12 @@ inline bool preGC() {
                // send out status confirm msgs to all cores to check if there are
                // transfer obj msgs on-the-fly
                waitconfirm = true;
-               numconfirm = NUMCORES - 1;
-               for(i = 1; i < NUMCORES; ++i) { 
+               numconfirm = NUMCORESACTIVE - 1;
+               for(i = 1; i < NUMCORESACTIVE; ++i) {   
                        corestatus[i] = 1;
                        // send status confirm msg to core i
                        send_msg_1(i, STATUSCONFIRM);
-               } // for(i = 1; i < NUMCORES; ++i)
+               } // for(i = 1; i < NUMCORESACTIVE; ++i)
 
 #ifdef DEBUG
                BAMBOO_DEBUGPRINT(0xec02);
@@ -463,22 +484,22 @@ inline bool preGC() {
 #ifdef DEBUG
                BAMBOO_DEBUGPRINT(0xec04);
 #endif
-               for(i = 0; i < NUMCORES; ++i) {
+               for(i = 0; i < NUMCORESACTIVE; ++i) {
                        sumsendobj += numsendobjs[i];
 #ifdef DEBUG
                        BAMBOO_DEBUGPRINT(0xf000 + numsendobjs[i]);
 #endif
-               } // for(i = 1; i < NUMCORES; ++i)
+               } // for(i = 1; i < NUMCORESACTIVE; ++i)
 #ifdef DEBUG
        BAMBOO_DEBUGPRINT(0xec05);
        BAMBOO_DEBUGPRINT_REG(sumsendobj);
 #endif
-               for(i = 0; i < NUMCORES; ++i) {
+               for(i = 0; i < NUMCORESACTIVE; ++i) {
                        sumsendobj -= numreceiveobjs[i];
 #ifdef DEBUG
                        BAMBOO_DEBUGPRINT(0xf000 + numreceiveobjs[i]);
 #endif
-               } // for(i = 1; i < NUMCORES; ++i)
+               } // for(i = 1; i < NUMCORESACTIVE; ++i)
 #ifdef DEBUG
                BAMBOO_DEBUGPRINT(0xec06);
                BAMBOO_DEBUGPRINT_REG(sumsendobj);
@@ -514,7 +535,7 @@ inline void initGC() {
                gcheaptop = 0;
                gctopcore = 0;
                gctopblock = 0;
-       }
+       } // if(STARTUPCORE == BAMBOO_NUM_OF_CORE) 
        gcself_numsendobjs = 0;
        gcself_numreceiveobjs = 0;
        gcmarkedptrbound = 0;
@@ -546,9 +567,10 @@ inline void initGC() {
                gclobjhead=gclobjtail=gclobjtail2=
                        RUNMALLOC(sizeof(struct lobjpointerblock));
        } else {
-               gclobjtailindex = gclobjtailindex2 = gclobjheadindex;
+               gclobjtailindex = gclobjtailindex2 = gclobjheadindex = 0;
                gclobjtail = gclobjtail2 = gclobjhead;
        }
+       gclobjhead->next = gclobjhead->prev = NULL;
 
        freeRuntimeHash(gcpointertbl);
        gcpointertbl = allocateRuntimeHash(20);
@@ -596,15 +618,55 @@ inline bool cacheLObjs() {
 #endif
        gclobjtail2 = gclobjtail;
        gclobjtailindex2 = gclobjtailindex;
+       int tmp_lobj = 0;
+       int tmp_len = 0;
+       int tmp_host = 0;
+       // compute total mem size required and sort the lobjs in ascending order
        while(gc_lobjmoreItems2()){
                gc_lobjdequeue2();
-               size = gclobjtail2->lengths[gclobjtailindex2 - 1];
-               sumsize += size;
+               tmp_lobj = gclobjtail2->lobjs[gclobjtailindex2-1];
+               tmp_host = gclobjtail2->hosts[gclobjtailindex2-1];
+               tmp_len = gclobjtail2->lengths[gclobjtailindex2 - 1];
+               sumsize += tmp_len;
 #ifdef DEBUG
                BAMBOO_DEBUGPRINT_REG(gclobjtail2->lobjs[gclobjtailindex2-1]);
-               BAMBOO_DEBUGPRINT_REG(size);
+               BAMBOO_DEBUGPRINT_REG(tmp_len);
                BAMBOO_DEBUGPRINT_REG(sumsize);
 #endif
+               int i = gclobjtailindex2-1;
+               struct lobjpointerblock * tmp_block = gclobjtail2;
+               // find the place to insert
+               while(true) {
+                       if(i == 0) {
+                               if(tmp_block->prev == NULL) {
+                                       break;
+                               }
+                               if(tmp_block->prev->lobjs[NUMLOBJPTRS-1] > tmp_lobj) {
+                                       tmp_block->lobjs[i] = tmp_block->prev->lobjs[NUMLOBJPTRS-1];
+                                       tmp_block->lengths[i] = tmp_block->prev->lengths[NUMLOBJPTRS-1];
+                                       tmp_block->hosts[i] = tmp_block->prev->hosts[NUMLOBJPTRS-1];
+                                       tmp_block = tmp_block->prev;
+                                       i = NUMLOBJPTRS-1;
+                               } else {
+                                       break;
+                               } // if(tmp_block->prev->lobjs[NUMLOBJPTRS-1] < tmp_lobj)
+                       } else {
+                               if(tmp_block->lobjs[i-1] > tmp_lobj) {
+                                       tmp_block->lobjs[i] = tmp_block->lobjs[i-1];
+                                       tmp_block->lengths[i] = tmp_block->lengths[i-1];
+                                       tmp_block->hosts[i] = tmp_block->hosts[i-1];
+                                       i--;
+                               } else {
+                                       break;
+                               } // if(tmp_block->lobjs[i-1] < tmp_lobj)
+                       } // if(i ==0 ) else {}
+               } // while(true)
+               // insert it
+               if(i != gclobjtailindex2 - 1) {
+                       tmp_block->lobjs[i] = tmp_lobj;
+                       tmp_block->lengths[i] = tmp_len;
+                       tmp_block->hosts[i] = tmp_host;
+               }
        } // while(gc_lobjmoreItems2())
 
        // check if there are enough space to cache these large objs
@@ -626,20 +688,24 @@ inline bool cacheLObjs() {
 
        gcheaptop = dst; // Note: record the start of cached lobjs with gcheaptop
        // cache the largeObjs to the top of the shared heap
-       gclobjtail2 = gclobjtail;
-       gclobjtailindex2 = gclobjtailindex;
-       while(gc_lobjmoreItems2()) {
-               gc_lobjdequeue2();
-               size = gclobjtail2->lengths[gclobjtailindex2 - 1];
+       //gclobjtail2 = gclobjtail;
+       //gclobjtailindex2 = gclobjtailindex;
+       dst = (BAMBOO_BASE_VA) + (BAMBOO_SHARED_MEM_SIZE);
+       while(gc_lobjmoreItems3()) {
+               gc_lobjdequeue3();
+               size = gclobjtail2->lengths[gclobjtailindex2];
                // set the mark field to 2, indicating that this obj has been moved and 
                // need to be flushed
-               ((int *)(gclobjtail2->lobjs[gclobjtailindex2-1]))[6] = 2;
-               memcpy(dst, gclobjtail2->lobjs[gclobjtailindex2 - 1], size);
-               dst += size;
-#ifdef DEBUG 
-               BAMBOO_DEBUGPRINT_REG(gclobjtail2->lobjs[gclobjtailindex2-1]);
-               BAMBOO_DEBUGPRINT(dst-size);
+               ((int *)(gclobjtail2->lobjs[gclobjtailindex2]))[6] = 2;
+               dst -= size;
+               memcpy(dst, gclobjtail2->lobjs[gclobjtailindex2], size);
+#ifdef DEBUG
+               BAMBOO_DEBUGPRINT(0x804);
+               BAMBOO_DEBUGPRINT_REG(gclobjtail2->lobjs[gclobjtailindex2]);
+               BAMBOO_DEBUGPRINT(dst);
                BAMBOO_DEBUGPRINT_REG(size);
+               BAMBOO_DEBUGPRINT_REG(*((int*)gclobjtail2->lobjs[gclobjtailindex2]));
+               BAMBOO_DEBUGPRINT_REG(*((int*)(dst)));
 #endif
        }
        return true;
@@ -664,7 +730,7 @@ void updateSmemTbl(int coren,
        do{
                toset = gc_core2block[2*coren+i]+(NUMCORES*2)*j;
                if(toset < ltopcore) {
-                       gcsmemtbl[toset] = (toset<NUMCORES)?BAMBOO_SMEM_SIZE_L:BAMBOO_SMEM_SIZE;
+                       gcsmemtbl[toset]=(toset<NUMCORES)?BAMBOO_SMEM_SIZE_L:BAMBOO_SMEM_SIZE;
                } else if(toset == ltopcore) {
                        gcsmemtbl[toset] = load;
                        break;
@@ -705,7 +771,16 @@ inline struct freeMemItem * addFreeMemItem(int ptr,
        // zero out all these spare memory
        // note that, leave the mem starting from heaptop, as it caches large objs
        // zero out these cache later when moving large obj
-       memset(tochange->ptr, '\0', tochange->size);
+       {
+               INTPTR tmp = tochange->ptr;
+               unsigned long long int size = tochange->size;
+               while(size > 0) {
+                       int tsize = size>1024*1024*1024?1024*1024*1024:size;
+                       memset(tmp, '\0', tsize);
+                       size -= tsize;
+                       tmp += tsize;
+               }
+       }
        return tochange;
 } // struct freeMemItem * addFreeMemItem(int,int,struct freeMemItem*,bool*, int)
 
@@ -786,7 +861,7 @@ inline void moveLObjs() {
        } else {
                // check how many blocks it acrosses
                int remain = tmpheaptop-gcbaseva;
-               int sb = remain/(BAMBOO_SMEM_SIZE) + gcreservedsb; // number of the sblock
+               int sb = remain/(BAMBOO_SMEM_SIZE) + gcreservedsb; //number of the sblock
                int b = 0; // number of the block
                BLOCKINDEX(tmpheaptop, &b);
                // check the remaining space in this block
@@ -922,6 +997,7 @@ inline void moveLObjs() {
                                        BAMBOO_DEBUGPRINT(0xcdcc);
                                        BAMBOO_DEBUGPRINT_REG(ptr);
                                        BAMBOO_DEBUGPRINT_REG(tmpheaptop);
+                                       BAMBOO_DEBUGPRINT_REG(*((int*)tmpheaptop));
 #endif
                                } else {
                                        // send the original host core with the mapping info
@@ -1068,19 +1144,21 @@ inline void tomark(struct garbagelist * stackptr) {
        BAMBOO_DEBUGPRINT(0xe503);
 #endif
        // enqueue objectsets
-       for(i=0; i<NUMCLASSES; 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];
-                       struct ObjectHash * set=parameter->objectset;
-                       struct ObjectNode * ptr=set->listhead;
-                       while(ptr!=NULL) {
-                               BAMBOO_START_CRITICAL_SECTION();
-                               gc_enqueue_I((void *)ptr->key);
-                               BAMBOO_CLOSE_CRITICAL_SECTION();
-                               ptr=ptr->lnext;
+       if(BAMBOO_NUM_OF_CORE < NUMCORESACTIVE) {
+               for(i=0; i<NUMCLASSES; 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];
+                               struct ObjectHash * set=parameter->objectset;
+                               struct ObjectNode * ptr=set->listhead;
+                               while(ptr!=NULL) {
+                                       BAMBOO_START_CRITICAL_SECTION();
+                                       gc_enqueue_I((void *)ptr->key);
+                                       BAMBOO_CLOSE_CRITICAL_SECTION();
+                                       ptr=ptr->lnext;
+                               }
                        }
                }
        }
@@ -1101,16 +1179,18 @@ inline void tomark(struct garbagelist * stackptr) {
        BAMBOO_DEBUGPRINT(0xe505);
 #endif
        // euqueue active tasks
-       struct genpointerlist * ptr=activetasks->list;
-       while(ptr!=NULL) {
-               struct taskparamdescriptor *tpd=ptr->src;
-               int i;
-               for(i=0; i<tpd->numParameters; i++) {
-                       BAMBOO_START_CRITICAL_SECTION();
-                       gc_enqueue_I(tpd->parameterArray[i]);
-                       BAMBOO_CLOSE_CRITICAL_SECTION();
+       if(activetasks != NULL) {
+               struct genpointerlist * ptr=activetasks->list;
+               while(ptr!=NULL) {
+                       struct taskparamdescriptor *tpd=ptr->src;
+                       int i;
+                       for(i=0; i<tpd->numParameters; i++) {
+                               BAMBOO_START_CRITICAL_SECTION();
+                               gc_enqueue_I(tpd->parameterArray[i]);
+                               BAMBOO_CLOSE_CRITICAL_SECTION();
+                       }
+                       ptr=ptr->inext;
                }
-               ptr=ptr->inext;
        }
 
 #ifdef DEBUG
@@ -1225,13 +1305,16 @@ inline void mark(bool isfirst,
                        // check if it is a shared obj
                        if(ISSHAREDOBJ(ptr)) {
                                // a shared obj, check if it is a local obj on this core
-                               if(isLarge(ptr, &type, &size)) {
-                                       // ptr is a large object
-                                       if(((int *)ptr)[6] == 0) {
-                                               // not marked and not enqueued
+                               int host = hostcore(ptr);
+                               bool islocal = (host == BAMBOO_NUM_OF_CORE);
+                               if(islocal) {
+                                       bool isnotmarked = (((int *)ptr)[6] == 0);
+                                       if(isLarge(ptr, &type, &size) && isnotmarked) {
+                                               // ptr is a large object and not marked or enqueued
 #ifdef DEBUG
                                                BAMBOO_DEBUGPRINT(0xecec);
                                                BAMBOO_DEBUGPRINT_REG(ptr);
+                                               BAMBOO_DEBUGPRINT_REG(*((int*)ptr));
 #endif
                                                BAMBOO_START_CRITICAL_SECTION();
                                                gc_lobjenqueue_I(ptr, size, BAMBOO_NUM_OF_CORE);
@@ -1239,10 +1322,7 @@ inline void mark(bool isfirst,
                                                BAMBOO_CLOSE_CRITICAL_SECTION();
                                                // mark this obj
                                                ((int *)ptr)[6] = 1;
-                                       } // if(((int *)ptr)[6] == 0)
-                               } else {
-                                       bool islocal = isLocal(ptr);
-                                       if (islocal && (((int *)ptr)[6] == 0)) {
+                                       } else if(isnotmarked) {
                                                // ptr is an unmarked active object on this core
                                                ALIGNSIZE(size, &isize);
                                                gccurr_heaptop += isize;
@@ -1257,19 +1337,18 @@ inline void mark(bool isfirst,
                                                if(ptr + size > gcmarkedptrbound) {
                                                        gcmarkedptrbound = ptr + size;
                                                } // if(ptr + size > gcmarkedptrbound)
-                                       } else if (!islocal /*&& (((int *)ptr)[6] == 0)*/) {
-                                               int host = hostcore(ptr);
+                                       } // if(isLarge(ptr, &type, &size)) else ...
+                               } else {
 #ifdef DEBUG
-                                               BAMBOO_DEBUGPRINT(0xbbbb);
-                                               BAMBOO_DEBUGPRINT_REG(host);
-                                               BAMBOO_DEBUGPRINT_REG(ptr);
+                                       BAMBOO_DEBUGPRINT(0xbbbb);
+                                       BAMBOO_DEBUGPRINT_REG(host);
+                                       BAMBOO_DEBUGPRINT_REG(ptr);
 #endif
-                                               // send a msg to host informing that ptr is active
-                                               send_msg_2(host, GCMARKEDOBJ, ptr);
-                                               gcself_numsendobjs++;
-                                               checkfield = false;
-                                       }// if(isLocal(ptr)) else ...
-                               } // if(isLarge(ptr, &type, &size)) else ...
+                                       // send a msg to host informing that ptr is active
+                                       send_msg_2(host, GCMARKEDOBJ, ptr);
+                                       gcself_numsendobjs++;
+                                       checkfield = false;
+                               }// if(isLocal(ptr)) else ...
                        } // if(ISSHAREDOBJ(ptr))
 #ifdef DEBUG 
                        BAMBOO_DEBUGPRINT(0xed06);
@@ -1837,6 +1916,7 @@ innermoveobj:
                }
        }
 #ifdef DEBUG
+       BAMBOO_DEBUGPRINT(0xe207);
        BAMBOO_DEBUGPRINT_REG(orig->ptr);
 #endif
        return false;
@@ -1899,14 +1979,15 @@ inline bool compacthelper(struct moveHelper * orig,
 #ifdef DEBUG
        BAMBOO_DEBUGPRINT(0xe101);
        BAMBOO_DEBUGPRINT_REG(gcblock2fill);
+       BAMBOO_DEBUGPRINT_REG(gcmarkedptrbound);
 #endif
 innercompact:
-       do {
+       while(orig->ptr < gcmarkedptrbound) {
                bool stop = moveobj(orig, to, gcblock2fill);
                if(stop) {
                        break;
                }
-       } while(orig->ptr < gcmarkedptrbound);
+       } 
        // if no objs have been compact, do nothing, 
        // otherwise, fill the header of this block
        if(to->offset > BAMBOO_CACHE_LINE_SIZE) {
@@ -2038,6 +2119,13 @@ inline void compact() {
 
        if(!initOrig_Dst(orig, to)) {
                // no available data to compact
+               // send compact finish msg to STARTUP core
+#ifdef DEBUG
+               BAMBOO_DEBUGPRINT(0xe001);
+               BAMBOO_DEBUGPRINT_REG(to->base);
+#endif
+               send_msg_5(STARTUPCORE, GCFINISHCOMPACT, BAMBOO_NUM_OF_CORE,
+                                      0, to->base, 0);
                RUNFREE(orig);
                RUNFREE(to);
                return;
@@ -2070,7 +2158,7 @@ inline void * flushObj(void * objptr) {
                BAMBOO_DEBUGPRINT_REG(dstptr);
 #endif
                if(NULL == dstptr) {
-#ifdef DEBUG 
+#ifdef DEBUG
                        BAMBOO_DEBUGPRINT(0xe403);
                        BAMBOO_DEBUGPRINT_REG(objptr);
                        BAMBOO_DEBUGPRINT_REG(hostcore(objptr));
@@ -2118,19 +2206,21 @@ inline void flushRuntimeObj(struct garbagelist * stackptr) {
        }
 
        // flush objectsets
-       for(i=0; i<NUMCLASSES; 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];
-                       struct ObjectHash * set=parameter->objectset;
-                       struct ObjectNode * ptr=set->listhead;
-                       while(ptr!=NULL) {
-                               ptr->key = flushObj((void *)ptr->key);
-                               ptr=ptr->lnext;
+       if(BAMBOO_NUM_OF_CORE < NUMCORESACTIVE) {
+               for(i=0; i<NUMCLASSES; 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];
+                               struct ObjectHash * set=parameter->objectset;
+                               struct ObjectNode * ptr=set->listhead;
+                               while(ptr!=NULL) {
+                                       ptr->key = flushObj((void *)ptr->key);
+                                       ptr=ptr->lnext;
+                               }
+                               ObjectHashrehash(set);
                        }
-                       ObjectHashrehash(set);
                }
        }
 
@@ -2142,16 +2232,18 @@ inline void flushRuntimeObj(struct garbagelist * stackptr) {
        }
 
        // flush active tasks
-       struct genpointerlist * ptr=activetasks->list;
-       while(ptr!=NULL) {
-               struct taskparamdescriptor *tpd=ptr->src;
-               int i;
-               for(i=0; i<tpd->numParameters; i++) {
-                       tpd->parameterArray[i] = flushObj(tpd->parameterArray[i]);
+       if(activetasks != NULL) {
+               struct genpointerlist * ptr=activetasks->list;
+               while(ptr!=NULL) {
+                       struct taskparamdescriptor *tpd=ptr->src;
+                       int i;
+                       for(i=0; i<tpd->numParameters; i++) {
+                               tpd->parameterArray[i] = flushObj(tpd->parameterArray[i]);
+                       }
+                       ptr=ptr->inext;
                }
-               ptr=ptr->inext;
+               genrehash(activetasks);
        }
-       genrehash(activetasks);
 
        // flush cached transferred obj
        struct QueueItem * tmpobjptr =  getHead(&objqueue);
@@ -2173,7 +2265,8 @@ inline void flushRuntimeObj(struct garbagelist * stackptr) {
 
        // enqueue lock related info
        for(i = 0; i < runtime_locklen; ++i) {
-         runtime_locks[i].redirectlock = (int)flushObj(runtime_locks[i].redirectlock);
+         runtime_locks[i].redirectlock = 
+                       (int)flushObj(runtime_locks[i].redirectlock);
                if(runtime_locks[i].value != NULL) {
                  runtime_locks[i].value = (int)flushObj(runtime_locks[i].value);
          }
@@ -2194,6 +2287,7 @@ inline void flush(struct garbagelist * stackptr) {
                BAMBOO_DEBUGPRINT(0xe302);
                BAMBOO_DEBUGPRINT_REG(ptr);
                BAMBOO_DEBUGPRINT_REG(tptr);
+               BAMBOO_DEBUGPRINT_REG(((int *)(tptr))[0]);
 #endif
                if(tptr != NULL) {
                        ptr = tptr;
index 5f65bc0461ba0e4e50ab75807b1a4092f1f7b1b9..2690c1577faed6c92ea1441eeb6d49e626809eb9 100644 (file)
@@ -197,6 +197,7 @@ void * allocate_new(void * ptr, int type) {
   v->type=type;
   v->version = 0;
   v->lock = NULL;
+       v->lockcount = 0;
        initlock(v);
   return v;
 }
index d7dc2a9a312a76f6bb819ca5ac4b5bef04192d97..0d1865df503236e32d7de7451ed17903bfd87b4d 100644 (file)
@@ -180,11 +180,12 @@ typedef enum {
 } MSGTYPE;
 
 // data structures of status for termination
-int corestatus[NUMCORES]; // records status of each core
-                          // 1: running tasks
-                          // 0: stall
-int numsendobjs[NUMCORES]; // records how many objects a core has sent out
-int numreceiveobjs[NUMCORES]; // records how many objects a core has received
+// only check working cores
+int corestatus[NUMCORESACTIVE]; // records status of each core
+                                // 1: running tasks
+                                // 0: stall
+int numsendobjs[NUMCORESACTIVE]; // records how many objects a core has sent out
+int numreceiveobjs[NUMCORESACTIVE]; // records how many objects a core has received
 volatile int numconfirm;
 volatile bool waitconfirm;
 bool busystatus;
@@ -296,7 +297,7 @@ bool taskInfoOverflow;
 /*InterruptInfo * interruptInfoArray[INTERRUPTINFOLENGTH];
    int interruptInfoIndex;
    bool interruptInfoOverflow;*/
-int profilestatus[NUMCORES]; // records status of each core
+int profilestatus[NUMCORESACTIVE]; // records status of each core
                              // 1: running tasks
                              // 0: stall
 #endif // #ifdef PROFILE
index 59f943ee6440bdceae93e7bf0390ad2248f35e9b..b84de5c2f30a9a7778c1c5e4fcdfba0f2eebac08 100644 (file)
@@ -44,7 +44,7 @@ void initruntimedata() {
        // initialize the arrays
   if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
     // startup core to initialize corestatus[]
-    for(i = 0; i < NUMCORES; ++i) {
+    for(i = 0; i < NUMCORESACTIVE; ++i) {
       corestatus[i] = 1;
       numsendobjs[i] = 0; 
       numreceiveobjs[i] = 0;
@@ -52,7 +52,9 @@ void initruntimedata() {
                        // initialize the profile data arrays
                        profilestatus[i] = 1;
 #endif
+    } // for(i = 0; i < NUMCORESACTIVE; ++i)
 #ifdef MULTICORE_GC
+               for(i = 0; i < NUMCORES; ++i) {
                        gccorestatus[i] = 1;
                        gcnumsendobjs[i] = 0; 
       gcnumreceiveobjs[i] = 0;
@@ -60,8 +62,8 @@ void initruntimedata() {
                        gcrequiredmems[i] = 0;
                        gcstopblock[i] = 0;
                        gcfilledblocks[i] = 0;
-#endif
     } // for(i = 0; i < NUMCORES; ++i)
+#endif
                numconfirm = 0;
                waitconfirm = false; 
                
@@ -328,9 +330,9 @@ void checkCoreStatus() {
                // check the status of all cores
                allStall = true;
 #ifdef DEBUG
-               BAMBOO_DEBUGPRINT_REG(NUMCORES);
+               BAMBOO_DEBUGPRINT_REG(NUMCORESACTIVE);
 #endif
-               for(i = 0; i < NUMCORES; ++i) {
+               for(i = 0; i < NUMCORESACTIVE; ++i) {
 #ifdef DEBUG
                        BAMBOO_DEBUGPRINT(0xe000 + corestatus[i]);
 #endif
@@ -338,23 +340,23 @@ void checkCoreStatus() {
                                allStall = false;
                                break;
                        }
-               } // for(i = 0; i < NUMCORES; ++i)
+               } // for(i = 0; i < NUMCORESACTIVE; ++i)
                if(allStall) {
                        // check if the sum of send objs and receive obj are the same
                        // yes->check if the info is the latest; no->go on executing
                        sumsendobj = 0;
-                       for(i = 0; i < NUMCORES; ++i) {
+                       for(i = 0; i < NUMCORESACTIVE; ++i) {
                                sumsendobj += numsendobjs[i];
 #ifdef DEBUG
                                BAMBOO_DEBUGPRINT(0xf000 + numsendobjs[i]);
 #endif
-                       } // for(i = 0; i < NUMCORES; ++i)      
-                       for(i = 0; i < NUMCORES; ++i) {
+                       } // for(i = 0; i < NUMCORESACTIVE; ++i)        
+                       for(i = 0; i < NUMCORESACTIVE; ++i) {
                                sumsendobj -= numreceiveobjs[i];
 #ifdef DEBUG
                                BAMBOO_DEBUGPRINT(0xf000 + numreceiveobjs[i]);
 #endif
-                       } // for(i = 0; i < NUMCORES; ++i)
+                       } // for(i = 0; i < NUMCORESACTIVE; ++i)
                        if(0 == sumsendobj) {
                                if(!waitconfirm) {
                                        // the first time found all cores stall
@@ -364,13 +366,13 @@ void checkCoreStatus() {
                                        BAMBOO_DEBUGPRINT(0xee05);
 #endif
                                        corestatus[BAMBOO_NUM_OF_CORE] = 1;
-                                       for(i = 1; i < NUMCORES; ++i) { 
+                                       for(i = 1; i < NUMCORESACTIVE; ++i) {   
                                                corestatus[i] = 1;
                                                // send status confirm msg to core i
                                                send_msg_1(i, STATUSCONFIRM);
-                                       } // for(i = 1; i < NUMCORES; ++i)
+                                       } // for(i = 1; i < NUMCORESACTIVE; ++i)
                                        waitconfirm = true;
-                                       numconfirm = NUMCORES - 1;
+                                       numconfirm = NUMCORESACTIVE - 1;
                                } else {
                                        // all the core status info are the latest
                                        // terminate; for profiling mode, send request to all
@@ -393,10 +395,10 @@ void checkCoreStatus() {
 #ifdef DEBUG
                                        BAMBOO_DEBUGPRINT(0xf000);
 #endif
-                                       for(i = 1; i < NUMCORES; ++i) {
+                                       for(i = 1; i < NUMCORESACTIVE; ++i) {
                                                // send profile request msg to core i
                                                send_msg_2(i, PROFILEOUTPUT, totalexetime);
-                                       } // for(i = 1; i < NUMCORES; ++i)
+                                       } // for(i = 1; i < NUMCORESACTIVE; ++i)
                                        // pour profiling data on startup core
                                        outputProfileData();
                                        while(true) {
@@ -408,9 +410,9 @@ void checkCoreStatus() {
                                                // check the status of all cores
                                                allStall = true;
 #ifdef DEBUG
-                                               BAMBOO_DEBUGPRINT_REG(NUMCORES);
+                                               BAMBOO_DEBUGPRINT_REG(NUMCORESACTIVE);
 #endif 
-                                               for(i = 0; i < NUMCORES; ++i) {
+                                               for(i = 0; i < NUMCORESACTIVE; ++i) {
 #ifdef DEBUG
                                                        BAMBOO_DEBUGPRINT(0xe000 + profilestatus[i]);
 #endif
@@ -418,7 +420,7 @@ void checkCoreStatus() {
                                                                allStall = false;
                                                                break;
                                                        }
-                                               }  // for(i = 0; i < NUMCORES; ++i)
+                                               }  // for(i = 0; i < NUMCORESACTIVE; ++i)
                                                if(!allStall) {
                                                        int halt = 100;
                                                        BAMBOO_CLOSE_CRITICAL_SECTION_STATUS();
@@ -485,7 +487,7 @@ inline void run(void * arg) {
   initializeexithandler();
 
   // main process of the execution module
-  if(BAMBOO_NUM_OF_CORE > NUMCORES - 1) {
+  if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) {
        // non-executing cores, only processing communications
     activetasks = NULL;
 /*#ifdef PROFILE
@@ -594,7 +596,7 @@ inline void run(void * arg) {
                          } // if(STARTUPCORE == BAMBOO_NUM_OF_CORE) 
                  } // if(!tocontinue)
          } // while(true) 
-  } // if(BAMBOO_NUM_OF_CORE > NUMCORES - 1)
+  } // if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1)
 
 } // run()
 
@@ -934,7 +936,7 @@ void flagbody(struct ___Object___ *ptr,
   int UNUSED, UNUSED2;
   int * enterflags = NULL;
   if((!isnew) && (queues == NULL)) {
-    if(BAMBOO_NUM_OF_CORE < NUMCORES) {
+    if(BAMBOO_NUM_OF_CORE < NUMCORESACTIVE) {
                queues = objectqueues[BAMBOO_NUM_OF_CORE][ptr->type];
                length = numqueues[BAMBOO_NUM_OF_CORE][ptr->type];
        } else {
@@ -968,7 +970,7 @@ void enqueueObject(void * vptr,
                struct ___Object___ *tagptr=NULL;
                struct parameterwrapper ** queues = vqueues;
                int length = vlength;
-               if(BAMBOO_NUM_OF_CORE > NUMCORES - 1) {
+               if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) {
                        return;
                }
                if(queues == NULL) {
@@ -1042,7 +1044,7 @@ void enqueueObject_I(void * vptr,
                struct ___Object___ *tagptr=NULL;
                struct parameterwrapper ** queues = vqueues;
                int length = vlength;
-               if(BAMBOO_NUM_OF_CORE > NUMCORES - 1) {
+               if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) {
                        return;
                }
                if(queues == NULL) {
@@ -1463,7 +1465,7 @@ msg:
                        BAMBOO_DEBUGPRINT(0xe880);
 #endif
 #endif
-      if(BAMBOO_NUM_OF_CORE > NUMCORES - 1) {
+      if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) {
 #ifndef CLOSE_PRINT
                                BAMBOO_DEBUGPRINT_REG(msgdata[2]);
 #endif
@@ -1522,7 +1524,7 @@ msg:
 #endif
                                BAMBOO_EXIT(0xa003);
       } 
-      if(msgdata[1] < NUMCORES) {
+      if(msgdata[1] < NUMCORESACTIVE) {
 #ifdef DEBUG
 #ifndef CLOSE_PRINT
                                BAMBOO_DEBUGPRINT(0xe881);
@@ -1565,7 +1567,7 @@ msg:
 
     case LOCKGROUNT: {
       // receive lock grount msg
-      if(BAMBOO_NUM_OF_CORE > NUMCORES - 1) {
+      if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) {
 #ifndef CLOSE_PRINT
                                BAMBOO_DEBUGPRINT_REG(msgdata[2]);
 #endif
@@ -1594,7 +1596,7 @@ msg:
 
     case LOCKDENY: {
       // receive lock deny msg
-      if(BAMBOO_NUM_OF_CORE > NUMCORES - 1) {
+      if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) {
 #ifndef CLOSE_PRINT
                                BAMBOO_DEBUGPRINT_REG(msgdata[2]);
 #endif
@@ -1700,7 +1702,7 @@ msg:
 
        case REDIRECTGROUNT: {
                // receive a lock grant msg with redirect info
-               if(BAMBOO_NUM_OF_CORE > NUMCORES - 1) {
+               if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) {
 #ifndef CLOSE_PRINT
                        BAMBOO_DEBUGPRINT_REG(msgdata[2]);
 #endif
@@ -1730,7 +1732,7 @@ msg:
        
        case REDIRECTDENY: {
          // receive a lock deny msg with redirect info
-         if(BAMBOO_NUM_OF_CORE > NUMCORES - 1) {
+         if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) {
 #ifndef CLOSE_PRINT
                  BAMBOO_DEBUGPRINT_REG(msgdata[2]);
 #endif
@@ -1767,7 +1769,7 @@ msg:
        case STATUSCONFIRM: {
       // receive a status confirm info
          if((BAMBOO_NUM_OF_CORE == STARTUPCORE) 
-                               || (BAMBOO_NUM_OF_CORE > NUMCORES - 1)) {
+                               || (BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1)) {
                  // wrong core to receive such msg
                  BAMBOO_EXIT(0xa00e);
                } else {
@@ -1958,7 +1960,7 @@ msg:
                  BAMBOO_DEBUGPRINT_REG(msgdata[1]);
 #endif
                  BAMBOO_EXIT(0xb002);
-               } 
+               }
                if(msgdata[1] < NUMCORES) {
                        gccorestatus[msgdata[1]] = 0;
                        gcnumsendobjs[msgdata[1]] = msgdata[2];
@@ -2769,13 +2771,14 @@ execute:
          if(islock) {
 #ifdef DEBUG
                  BAMBOO_DEBUGPRINT(0xe999);
-#endif
+#endif 
            for(i = 0; i < runtime_locklen; ++i) {
                                void * ptr = (void *)(runtime_locks[i].redirectlock);
              int * lock = (int *)(runtime_locks[i].value);
 #ifdef DEBUG
                  BAMBOO_DEBUGPRINT_REG((int)ptr);
                  BAMBOO_DEBUGPRINT_REG((int)lock);
+                       BAMBOO_DEBUGPRINT_REG(*((int*)lock+5));
 #endif
 #ifndef MULTICORE_GC
                  if(RuntimeHashcontainskey(lockRedirectTbl, (int)lock)) {
@@ -2936,7 +2939,7 @@ loopstart:
 void printdebug() {
   int i;
   int j;
-  if(BAMBOO_NUM_OF_CORE > NUMCORES - 1) {
+  if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) {
     return;
   }
   for(i=0; i<numtasks[BAMBOO_NUM_OF_CORE]; i++) {
@@ -2994,7 +2997,7 @@ void printdebug() {
 
 void processtasks() {
   int i;
-  if(BAMBOO_NUM_OF_CORE > NUMCORES - 1) {
+  if(BAMBOO_NUM_OF_CORE > NUMCORESACTIVE - 1) {
     return;
   }
   for(i=0; i<numtasks[BAMBOO_NUM_OF_CORE]; i++) {