return 1;
} // int gc_lobjmoreItems3()
+inline void gc_lobjqueueinit4() {
+ gclobjtail2 = gclobjtail;
+ gclobjtailindex2 = gclobjtailindex;
+} // void gc_lobjqueueinit2()
+
+inline void * gc_lobjdequeue4(int * length,
+ int * host) {
+ if (gclobjtailindex2==NUMLOBJPTRS) {
+ gclobjtail2=gclobjtail2->next;
+ gclobjtailindex2=0;
+ } // if (gclobjtailindex==NUMLOBJPTRS)
+ if(length != NULL) {
+ *length = gclobjtail2->lengths[gclobjtailindex];
+ }
+ if(host != NULL) {
+ *host = (int)(gclobjtail2->hosts[gclobjtailindex]);
+ }
+ return gclobjtail2->lobjs[gclobjtailindex++];
+} // void * gc_lobjdequeue()
+
+inline int gc_lobjmoreItems4() {
+ if ((gclobjhead==gclobjtail2)&&(gclobjtailindex2==gclobjheadindex))
+ return 0;
+ return 1;
+} // int gc_lobjmoreItems(
+
INTPTR gccurr_heapbound = 0;
inline void gettype_size(void * ptr,
freeRuntimeHash(gcpointertbl);
gcpointertbl = allocateRuntimeHash(20);
+ //freeMGCHash(gcpointertbl);
+ //gcpointertbl = allocateMGCHash(20);
+ //mgchashreset();
memset(gcsmemtbl, '\0', sizeof(int)*gcnumblock);
} // void initGC()
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]))[6] = 2;
+ // set the mark field to , indicating that this obj has been moved
+ // and need to be flushed
+ ((int *)(gclobjtail2->lobjs[gclobjtailindex2]))[6] = COMPACTED;
dst -= size;
- memcpy(dst, gclobjtail2->lobjs[gclobjtailindex2], size);
+ if((int)dst < (int)(gclobjtail2->lobjs[gclobjtailindex2])+size) {
+ memmove(dst, gclobjtail2->lobjs[gclobjtailindex2], size);
+ } else {
+ memcpy(dst, gclobjtail2->lobjs[gclobjtailindex2], size);
+ }
#ifdef DEBUG
BAMBOO_DEBUGPRINT(0x804);
BAMBOO_DEBUGPRINT_REG(gclobjtail2->lobjs[gclobjtailindex2]);
do{
toset = gc_core2block[2*coren+i]+(NUMCORES4GC*2)*j;
if(toset < ltopcore) {
- gcsmemtbl[toset]=(toset<NUMCORES4GC)?BAMBOO_SMEM_SIZE_L:BAMBOO_SMEM_SIZE;
+ gcsmemtbl[toset]=
+ (toset<NUMCORES4GC)?BAMBOO_SMEM_SIZE_L:BAMBOO_SMEM_SIZE;
} else if(toset == ltopcore) {
gcsmemtbl[toset] = load;
break;
(BAMBOO_SMEM_SIZE_L*i):
(BAMBOO_SMEM_SIZE*(i-NUMCORES4GC)+BAMBOO_LARGE_SMEM_BOUND));
}
+
// move large objs from gcheaptop to tmpheaptop
// write the header first
int tomove = (BAMBOO_BASE_VA) + (BAMBOO_SHARED_MEM_SIZE) - gcheaptop;
#endif
// flush the sbstartbl
memset(&(gcsbstarttbl[gcreservedsb]), '\0',
- BAMBOO_SHARED_MEM_SIZE/BAMBOO_SMEM_SIZE*sizeof(INTPTR));
+ (BAMBOO_SHARED_MEM_SIZE/BAMBOO_SMEM_SIZE-gcreservedsb)*sizeof(INTPTR));
if(tomove == 0) {
gcheaptop = tmpheaptop;
} else {
// close current block, fill its header
memset(base, '\0', BAMBOO_CACHE_LINE_SIZE);
*((int*)base) = cpysize + BAMBOO_CACHE_LINE_SIZE;
- gcsmemtbl[b] = cpysize + BAMBOO_CACHE_LINE_SIZE;
+ gcsmemtbl[b]+=BAMBOO_CACHE_LINE_SIZE; // add the size of the header
cpysize = 0;
base = tmpheaptop;
if(remain == 0) {
} // if(cpysize > 0)
// move the large obj
- memcpy(tmpheaptop, gcheaptop, size);
+ if((int)gcheaptop < (int)(tmpheaptop)+size) {
+ memmove(tmpheaptop, gcheaptop, size);
+ } else {
+ memcpy(tmpheaptop, gcheaptop, size);
+ }
// fill the remaining space with -2 padding
memset(tmpheaptop+size, -2, isize-size);
// zero out original mem caching the lobj
#endif
gcheaptop += size;
if(host == BAMBOO_NUM_OF_CORE) {
+ //if(ptr != tmpheaptop) {
BAMBOO_START_CRITICAL_SECTION();
+ //mgchashInsert_I(ptr, tmpheaptop);
RuntimeHashadd_I(gcpointertbl, ptr, tmpheaptop);
+ //MGCHashadd_I(gcpointertbl, ptr, tmpheaptop);
BAMBOO_CLOSE_CRITICAL_SECTION();
+ //}
#ifdef DEBUG
BAMBOO_DEBUGPRINT(0xcdca);
BAMBOO_DEBUGPRINT_REG(ptr);
*((int*)base) = isize + BAMBOO_CACHE_LINE_SIZE;
cpysize = 0;
base = tmpheaptop;
+ if(remain == BAMBOO_CACHE_LINE_SIZE) {
+ // fill with 0 in case
+ memset(tmpheaptop, '\0', remain);
+ }
remain -= BAMBOO_CACHE_LINE_SIZE;
tmpheaptop += BAMBOO_CACHE_LINE_SIZE;
} else {
remain -= isize;
// move the large obj
- memcpy(tmpheaptop, gcheaptop, size);
+ if((int)gcheaptop < (int)(tmpheaptop)+size) {
+ memmove(tmpheaptop, gcheaptop, size);
+ } else {
+ memcpy(tmpheaptop, gcheaptop, size);
+ }
// fill the remaining space with -2 padding
memset(tmpheaptop+size, -2, isize-size);
// zero out original mem caching the lobj
BAMBOO_DEBUGPRINT_REG(size);
BAMBOO_DEBUGPRINT_REG(isize);
#endif
+
gcheaptop += size;
cpysize += isize;
if(host == BAMBOO_NUM_OF_CORE) {
+ //if(ptr != tmpheaptop) {
BAMBOO_START_CRITICAL_SECTION();
+ //mgchashInsert_I(ptr, tmpheaptop);
RuntimeHashadd_I(gcpointertbl, ptr, tmpheaptop);
+ //MGCHashadd_I(gcpointertbl, ptr, tmpheaptop);
BAMBOO_CLOSE_CRITICAL_SECTION();
+ //}
#ifdef DEBUG
BAMBOO_DEBUGPRINT(0xcdcc);
BAMBOO_DEBUGPRINT_REG(ptr);
tmpheaptop += isize;
// update gcsmemtbl
- if(gcsmemtbl[b] == 0) {
- // add the header's size
- gcsmemtbl[b] = BAMBOO_CACHE_LINE_SIZE;
- }
gcsmemtbl[b] += isize;
} // if(remain < isize) else ...
} // while(gc_lobjmoreItems())
// close current block, fill the header
memset(base, '\0', BAMBOO_CACHE_LINE_SIZE);
*((int*)base) = cpysize + BAMBOO_CACHE_LINE_SIZE;
- gcsmemtbl[b] = cpysize + BAMBOO_CACHE_LINE_SIZE;
+ gcsmemtbl[b] += BAMBOO_CACHE_LINE_SIZE; // add the size of the header
} else {
tmpheaptop -= BAMBOO_CACHE_LINE_SIZE;
}
gcheaptop = tmpheaptop;
+
} // if(tomove == 0)
#ifdef DEBUG
int startptr = 0;
size = 0;
bound = BAMBOO_SMEM_SIZE_L;
- for(i = 0; i < gcnumblock; i++) {
+ for(i = 0; i < gcnumblock-bamboo_reserved_smem; i++) {
if(gcsmemtbl[i] < bound) {
if(gcsmemtbl[i] == 0) {
// blank one
startptr = 0;
size = 0;
}
- // remove the remaing list to the back up list
+ // remove the remaing list to the back up list, only remain one node,
+ // free the others
if(tochange->next != NULL) {
- struct freeMemItem * blist = bamboo_free_mem_list->backuplist;
- bamboo_free_mem_list->backuplist = tochange->next;
+ struct freeMemItem * blist = NULL;
+ if(bamboo_free_mem_list->backuplist != NULL) {
+ blist = tochange->next;
+ } else {
+ bamboo_free_mem_list->backuplist = tochange->next;
+ blist = bamboo_free_mem_list->backuplist->next;
+ bamboo_free_mem_list->backuplist->next = NULL;
+ }
tochange->next = NULL;
- if(blist != NULL) {
- struct freeMemItem * tmp = bamboo_free_mem_list->backuplist;
- while(tmp->next != NULL) {
- tmp = tmp->next;
- }
- tmp->next = blist;
+ while(blist != NULL) {
+ struct freeMemItem * tmp = blist;
+ blist = blist->next;
+ RUNFREE(tmp);
} // if(blist != NULL)
}
#endif
} // void moveLObjs()
+inline void markObj(void * objptr) {
+ if(objptr == NULL) {
+ return;
+ }
+ if(ISSHAREDOBJ(objptr)) {
+ int host = hostcore(objptr);
+ if(BAMBOO_NUM_OF_CORE == host) {
+ // on this core
+ if(((int *)objptr)[6] == INIT) {
+ // this is the first time that this object is discovered,
+ // set the flag as DISCOVERED
+ ((int *)objptr)[6] = DISCOVERED;
+ BAMBOO_START_CRITICAL_SECTION();
+ gc_enqueue_I(objptr);
+ BAMBOO_CLOSE_CRITICAL_SECTION();
+ }
+ } else {
+#ifdef DEBUG
+ BAMBOO_DEBUGPRINT(0xbbbb);
+ BAMBOO_DEBUGPRINT_REG(host);
+ BAMBOO_DEBUGPRINT_REG(objptr);
+#endif
+ // send a msg to host informing that objptr is active
+ send_msg_2(host, GCMARKEDOBJ, objptr);
+ gcself_numsendobjs++;
+ }
+ } else {
+ BAMBOO_START_CRITICAL_SECTION();
+ gc_enqueue_I(objptr);
+ BAMBOO_CLOSE_CRITICAL_SECTION();
+ } // if(ISSHAREDOBJ(objptr))
+} // void markObj(void * objptr)
+
// enqueue root objs
inline void tomark(struct garbagelist * stackptr) {
if(MARKPHASE != gcphase) {
#endif
for(i=0; i<stackptr->size; i++) {
if(stackptr->array[i] != NULL) {
- BAMBOO_START_CRITICAL_SECTION();
- gc_enqueue_I(stackptr->array[i]);
- BAMBOO_CLOSE_CRITICAL_SECTION();
+ //BAMBOO_START_CRITICAL_SECTION();
+ //gc_enqueue_I(stackptr->array[i]);
+ //BAMBOO_CLOSE_CRITICAL_SECTION();
+ markObj(stackptr->array[i]);
}
}
stackptr=stackptr->next;
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();
+ //BAMBOO_START_CRITICAL_SECTION();
+ //gc_enqueue_I((void *)ptr->key);
+ //BAMBOO_CLOSE_CRITICAL_SECTION();
+ markObj((void *)ptr->key);
ptr=ptr->lnext;
}
}
BAMBOO_DEBUGPRINT(0xe504);
#endif
for(i=0; i<currtpd->numParameters; i++) {
- BAMBOO_START_CRITICAL_SECTION();
- gc_enqueue_I(currtpd->parameterArray[i]);
- BAMBOO_CLOSE_CRITICAL_SECTION();
+ //BAMBOO_START_CRITICAL_SECTION();
+ //gc_enqueue_I(currtpd->parameterArray[i]);
+ //BAMBOO_CLOSE_CRITICAL_SECTION();
+ markObj(currtpd->parameterArray[i]);
}
}
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();
+ //BAMBOO_START_CRITICAL_SECTION();
+ //gc_enqueue_I(tpd->parameterArray[i]);
+ //BAMBOO_CLOSE_CRITICAL_SECTION();
+ markObj(tpd->parameterArray[i]);
}
ptr=ptr->inext;
}
while(tmpobjptr != NULL) {
struct transObjInfo * objInfo =
(struct transObjInfo *)(tmpobjptr->objectptr);
- BAMBOO_START_CRITICAL_SECTION();
- gc_enqueue_I(objInfo->objptr);
- BAMBOO_CLOSE_CRITICAL_SECTION();
+ //BAMBOO_START_CRITICAL_SECTION();
+ //gc_enqueue_I(objInfo->objptr);
+ //BAMBOO_CLOSE_CRITICAL_SECTION();
+ markObj(objInfo->objptr);
tmpobjptr = getNextQueueItem(tmpobjptr);
}
while(item != NULL) {
struct transObjInfo * totransobj =
(struct transObjInfo *)(item->objectptr);
- BAMBOO_START_CRITICAL_SECTION();
- gc_enqueue_I(totransobj->objptr);
- BAMBOO_CLOSE_CRITICAL_SECTION();
+ //BAMBOO_START_CRITICAL_SECTION();
+ //gc_enqueue_I(totransobj->objptr);
+ //BAMBOO_CLOSE_CRITICAL_SECTION();
+ markObj(totransobj->objptr);
item = getNextQueueItem(item);
} // while(item != NULL)
#endif
// enqueue lock related info
for(i = 0; i < runtime_locklen; ++i) {
- gc_enqueue_I((void *)(runtime_locks[i].redirectlock));
+ //gc_enqueue_I((void *)(runtime_locks[i].redirectlock));
+ markObj((void *)(runtime_locks[i].redirectlock));
if(runtime_locks[i].value != NULL) {
- gc_enqueue_I((void *)(runtime_locks[i].value));
+ //gc_enqueue_I((void *)(runtime_locks[i].value));
+ markObj((void *)(runtime_locks[i].value));
}
}
} // void tomark(struct garbagelist * stackptr)
-inline void markObj(void * objptr) {
- if(objptr == NULL) {
- return;
- }
- if(ISSHAREDOBJ(objptr)) {
- int host = hostcore(objptr);
- if(BAMBOO_NUM_OF_CORE == host) {
- // on this core
- BAMBOO_START_CRITICAL_SECTION();
- gc_enqueue_I(objptr);
- BAMBOO_CLOSE_CRITICAL_SECTION();
- } else {
-#ifdef DEBUG
- BAMBOO_DEBUGPRINT(0xbbbb);
- BAMBOO_DEBUGPRINT_REG(host);
- BAMBOO_DEBUGPRINT_REG(objptr);
-#endif
- // send a msg to host informing that objptr is active
- send_msg_2(host, GCMARKEDOBJ, objptr);
- gcself_numsendobjs++;
- }
- } else {
- BAMBOO_START_CRITICAL_SECTION();
- gc_enqueue_I(objptr);
- BAMBOO_CLOSE_CRITICAL_SECTION();
- } // if(ISSHAREDOBJ(objptr))
-} // void markObj(void * objptr)
-
inline void mark(bool isfirst,
struct garbagelist * stackptr) {
#ifdef DEBUG
gcbusystatus = true;
checkfield = true;
void * ptr = gc_dequeue2();
+
#ifdef DEBUG
BAMBOO_DEBUGPRINT_REG(ptr);
#endif
int host = hostcore(ptr);
bool islocal = (host == BAMBOO_NUM_OF_CORE);
if(islocal) {
- bool isnotmarked = (((int *)ptr)[6] == 0);
+ bool isnotmarked = (((int *)ptr)[6] == DISCOVERED);
if(isLarge(ptr, &type, &size) && isnotmarked) {
// ptr is a large object and not marked or enqueued
#ifdef DEBUG
gcnumlobjs++;
BAMBOO_CLOSE_CRITICAL_SECTION();
// mark this obj
- ((int *)ptr)[6] = 1;
+ ((int *)ptr)[6] = MARKED;
} else if(isnotmarked) {
// ptr is an unmarked active object on this core
ALIGNSIZE(size, &isize);
BAMBOO_DEBUGPRINT(((int *)(ptr))[0]);
#endif
// mark this obj
- ((int *)ptr)[6] = 1;
+ ((int *)ptr)[6] = MARKED;
+
if(ptr + size > gcmarkedptrbound) {
gcmarkedptrbound = ptr + size;
} // if(ptr + size > gcmarkedptrbound)
// if out of boundary of valid shared memory, return false, else return true
inline bool nextSBlock(struct moveHelper * orig) {
orig->blockbase = orig->blockbound;
+ bool sbchanged = false;
#ifdef DEBUG
BAMBOO_DEBUGPRINT(0xecc0);
BAMBOO_DEBUGPRINT_REG(orig->blockbase);
orig->bound = orig->base + BAMBOO_SMEM_SIZE;
orig->blockbase = orig->base;
orig->sblockindex = (orig->blockbase-BAMBOO_BASE_VA)/BAMBOO_SMEM_SIZE;
+ sbchanged = true;
} else if(0 == (orig->blockbase%BAMBOO_SMEM_SIZE)) {
orig->sblockindex += 1;
+ sbchanged = true;
} // if((orig->blockbase >= orig->bound) || (orig->ptr >= orig->bound)...
// check if this sblock should be omitted or have special start point
orig->sblockindex += 1;
orig->blockbase += BAMBOO_SMEM_SIZE;
goto outernextSBlock;
- } else if(gcsbstarttbl[orig->sblockindex] != 0) {
+ } else if((gcsbstarttbl[orig->sblockindex] != 0)
+ && (sbchanged)) {
+ // the first time to access this SBlock
#ifdef DEBUG
BAMBOO_DEBUGPRINT(0xecc3);
#endif
#endif
ALIGNSIZE(size, &isize); // no matter is the obj marked or not
// should be able to across it
- if(mark == 1) {
+ if(mark == MARKED) {
#ifdef DEBUG
BAMBOO_DEBUGPRINT(0xe204);
#endif
// marked obj, copy it to current heap top
// check to see if remaining space is enough
if(to->top + isize > to->bound) {
- // fill -1 indicating the end of this block
- /*if(to->top != to->bound) {
- *((int*)to->ptr) = -1;
- }*/
- //memset(to->ptr+1, -2, to->bound - to->top - 1);
+ // fill 0 indicating the end of this block
+ memset(to->ptr, '\0', to->bound - to->top);
// fill the header of this block and then go to next block
to->offset += to->bound - to->top;
memset(to->base, '\0', BAMBOO_CACHE_LINE_SIZE);
} // if(to->top + isize > to->bound)
// set the mark field to 2, indicating that this obj has been moved
// and need to be flushed
- ((int *)(orig->ptr))[6] = 2;
+ ((int *)(orig->ptr))[6] = COMPACTED;
if(to->ptr != orig->ptr) {
- memcpy(to->ptr, orig->ptr, size);
+ if((int)(orig->ptr) < (int)(to->ptr)+size) {
+ memmove(to->ptr, orig->ptr, size);
+ } else {
+ memcpy(to->ptr, orig->ptr, size);
+ }
// fill the remaining space with -2
memset(to->ptr+size, -2, isize-size);
}
// store mapping info
BAMBOO_START_CRITICAL_SECTION();
+ //mgchashInsert_I(orig->ptr, to->ptr);
RuntimeHashadd_I(gcpointertbl, orig->ptr, to->ptr);
+ //MGCHashadd_I(gcpointertbl, orig->ptr, to->ptr);
BAMBOO_CLOSE_CRITICAL_SECTION();
+ //}
+
#ifdef DEBUG
BAMBOO_DEBUGPRINT(0xcdce);
BAMBOO_DEBUGPRINT_REG(orig->ptr);
BAMBOO_DEBUGPRINT(0xe205);
#endif
// move to next obj
- orig->ptr += isize;
+ orig->ptr += size;
+
#ifdef DEBUG
BAMBOO_DEBUGPRINT_REG(isize);
+ BAMBOO_DEBUGPRINT_REG(size);
BAMBOO_DEBUGPRINT_REG(orig->ptr);
BAMBOO_DEBUGPRINT_REG(orig->bound);
#endif
#endif
// a shared obj ptr, change to new address
BAMBOO_START_CRITICAL_SECTION();
+ //dstptr = mgchashSearch(objptr);
RuntimeHashget(gcpointertbl, objptr, &dstptr);
+ //MGCHashget(gcpointertbl, objptr, &dstptr);
BAMBOO_CLOSE_CRITICAL_SECTION();
#ifdef DEBUG
BAMBOO_DEBUGPRINT_REG(dstptr);
// error! the obj is right on this core, but cannot find it
BAMBOO_DEBUGPRINT_REG(objptr);
BAMBOO_EXIT(0xb103);
- }
+ // assume that the obj has not been moved, use the original address
+ //dstptr = objptr;
+ } else {
// send msg to host core for the mapping info
gcobj2map = (int)objptr;
gcismapped = false;
}
}
BAMBOO_START_CRITICAL_SECTION();
+ //dstptr = mgchashSearch(objptr);
RuntimeHashget(gcpointertbl, objptr, &dstptr);
+ //MGCHashget(gcpointertbl, objptr, &dstptr);
BAMBOO_CLOSE_CRITICAL_SECTION();
+ }
#ifdef DEBUG
BAMBOO_DEBUGPRINT_REG(dstptr);
#endif
}
- } // if(ISSHAREDOBJ(objptr))
+ } else {
+ // not a shared obj, use the old address
+ dstptr = objptr;
+ }// if(ISSHAREDOBJ(objptr))
#ifdef DEBUG
BAMBOO_DEBUGPRINT(0xe404);
#endif
inline void flush(struct garbagelist * stackptr) {
flushRuntimeObj(stackptr);
-
+
while(gc_moreItems()) {
#ifdef DEBUG
BAMBOO_DEBUGPRINT(0xe301);
#endif
void * ptr = gc_dequeue();
+ if(ISSHAREDOBJ(ptr)) {
void * tptr = flushObj(ptr);
#ifdef DEBUG
BAMBOO_DEBUGPRINT(0xe302);
if(tptr != NULL) {
ptr = tptr;
}
- if(((int *)(ptr))[6] == 2) {
+ }
+ if((!ISSHAREDOBJ(ptr)) || (((int *)(ptr))[6] == COMPACTED)) {
int type = ((int *)(ptr))[0];
// scan all pointers in ptr
unsigned INTPTR * pointer;
#endif
unsigned int offset=pointer[i];
void * objptr=*((void **)(((char *)ptr)+offset));
+
#ifdef DEBUG
BAMBOO_DEBUGPRINT_REG(objptr);
#endif
} // for(i=1; i<=size; i++)
} // if (pointer==0) else if (((INTPTR)pointer)==1) else ()
// restore the mark field, indicating that this obj has been flushed
- ((int *)(ptr))[6] = 0;
- } // if(((int *)(ptr))[6] == 2)
+ if(ISSHAREDOBJ(ptr)) {
+ ((int *)(ptr))[6] = INIT;
+ }
+ } // if(((int *)(ptr))[6] == COMPACTED)
} // while(gc_moreItems())
#ifdef DEBUG
BAMBOO_DEBUGPRINT(0xe308);
#endif
+
+ // flush lobjs
+ while(gc_lobjmoreItems()) {
+#ifdef DEBUG
+ BAMBOO_DEBUGPRINT(0xe309);
+#endif
+ void * ptr = gc_lobjdequeue(NULL, NULL);
+ //if(ISSHAREDOBJ(ptr)) {
+ void * tptr = flushObj(ptr);
+#ifdef DEBUG
+ BAMBOO_DEBUGPRINT(0xe30a);
+ BAMBOO_DEBUGPRINT_REG(ptr);
+ BAMBOO_DEBUGPRINT_REG(tptr);
+ BAMBOO_DEBUGPRINT_REG(((int *)(tptr))[0]);
+#endif
+ if(tptr != NULL) {
+ ptr = tptr;
+ }
+ //}
+ if(/*(!ISSHAREDOBJ(ptr)) || */(((int *)(ptr))[6] == COMPACTED)) {
+ int type = ((int *)(ptr))[0];
+ // scan all pointers in ptr
+ unsigned INTPTR * pointer;
+ pointer=pointerarray[type];
+#ifdef DEBUG
+ BAMBOO_DEBUGPRINT(0xe30b);
+ BAMBOO_DEBUGPRINT_REG(pointer);
+#endif
+ if (pointer==0) {
+ /* Array of primitives */
+ /* Do nothing */
+ } else if (((INTPTR)pointer)==1) {
+#ifdef DEBUG
+ BAMBOO_DEBUGPRINT(0xe30c);
+#endif
+ /* Array of pointers */
+ struct ArrayObject *ao=(struct ArrayObject *) ptr;
+ int length=ao->___length___;
+ int j;
+ for(j=0; j<length; j++) {
+#ifdef DEBUG
+ BAMBOO_DEBUGPRINT(0xe30d);
+#endif
+ void *objptr=
+ ((void **)(((char *)&ao->___length___)+sizeof(int)))[j];
+#ifdef DEBUG
+ BAMBOO_DEBUGPRINT_REG(objptr);
+#endif
+ ((void **)(((char *)&ao->___length___)+sizeof(int)))[j] =
+ flushObj(objptr);
+ }
+ } else {
+#ifdef DEBUG
+ BAMBOO_DEBUGPRINT(0xe30e);
+#endif
+ INTPTR size=pointer[0];
+ int i;
+ for(i=1; i<=size; i++) {
+#ifdef DEBUG
+ BAMBOO_DEBUGPRINT(0xe30f);
+#endif
+ unsigned int offset=pointer[i];
+ void * objptr=*((void **)(((char *)ptr)+offset));
+
+#ifdef DEBUG
+ BAMBOO_DEBUGPRINT_REG(objptr);
+#endif
+ *((void **)(((char *)ptr)+offset)) = flushObj(objptr);
+ } // for(i=1; i<=size; i++)
+ } // if (pointer==0) else if (((INTPTR)pointer)==1) else ()
+ // restore the mark field, indicating that this obj has been flushed
+ //if(ISSHAREDOBJ(ptr)) {
+ ((int *)(ptr))[6] = INIT;
+ //}
+ } // if(((int *)(ptr))[6] == COMPACTED)
+ } // while(gc_lobjmoreItems())
+#ifdef DEBUG
+ BAMBOO_DEBUGPRINT(0xe310);
+#endif
+
// send flush finish message to core coordinator
if(STARTUPCORE == BAMBOO_NUM_OF_CORE) {
gccorestatus[BAMBOO_NUM_OF_CORE] = 0;
send_msg_2(STARTUPCORE, GCFINISHFLUSH, BAMBOO_NUM_OF_CORE);
}
#ifdef DEBUG
- BAMBOO_DEBUGPRINT(0xe309);
+ BAMBOO_DEBUGPRINT(0xe311);
#endif
} // flush()
tprintf("start gc! \n");
//dumpSMem();
#endif
-
gcprocessing = true;
int i = 0;
waitconfirm = false;
bool allStall = false;
initGC();
-#ifdef GC_DEBUG
+#ifdef RAWPATH // TODO GC_DEBUG
tprintf("Check core status \n");
#endif
}
BAMBOO_CLOSE_CRITICAL_SECTION();
}
-#ifdef GC_DEBUG
+#ifdef RAWPATH // TODO GC_DEBUG
tprintf("Start mark phase \n");
#endif
// all cores have finished compacting
if(gcheaptop < gcmarkedptrbound) {
gcheaptop = gcmarkedptrbound;
}
-#ifdef GC_DEBUG
+#ifdef RAWPATH // TODO GC_DEBUG
tprintf("prepare to cache large objs \n");
//dumpSMem();
#endif
int numpbc = loadbalance();
// TODO
numpbc = (BAMBOO_SHARED_MEM_SIZE)/(BAMBOO_SMEM_SIZE);
-#ifdef GC_DEBUG
+#ifdef RAWPATH // TODO GC_DEBUG
tprintf("mark phase finished \n");
//dumpSMem();
#endif
} // if(gctomove)
} // while(COMPACTPHASE == gcphase)
-#ifdef GC_DEBUG
+
+#ifdef RAWPATH // TODO GC_DEBUG
tprintf("prepare to move large objs \n");
//dumpSMem();
#endif
// move largeObjs
moveLObjs();
-#ifdef GC_DEBUG
+#ifdef RAWPATH // TODO GC_DEBUG
tprintf("compact phase finished \n");
//dumpSMem();
#endif
+ RUNFREE(orig);
+ RUNFREE(to);
+ orig = to = NULL;
gcphase = FLUSHPHASE;
gccorestatus[BAMBOO_NUM_OF_CORE] = 1;
send_msg_1(i, GCSTARTFLUSH);
}
-#ifdef GC_DEBUG
+#ifdef RAWPATH // TODO GC_DEBUG
tprintf("Start flush phase \n");
#endif
// flush phase
gcself_numsendobjs = 0;
gcself_numreceiveobjs = 0;
gcmarkedptrbound = 0;
+ //mgchashCreate(2000, 0.75);
gcpointertbl = allocateRuntimeHash(20);
+ //gcpointertbl = allocateMGCHash(20);
gcobj2map = 0;
gcmappedobj = 0;
gcismapped = false;
inline __attribute__((always_inline))
void disruntimedata() {
#ifdef MULTICORE_GC
+ //mgchashDelete();
freeRuntimeHash(gcpointertbl);
+ //freeMGCHash(gcpointertbl);
+ if(gcsmemtbl != NULL) {
+ RUNFREE(gcsmemtbl);
+ }
#else
freeRuntimeHash(lockRedirectTbl);
freeRuntimeHash(objRedirectLockTbl);
prev->next = freemem;
}
// put it to the tail of the list for reuse
- toremove->next = bamboo_free_mem_list->backuplist;
- bamboo_free_mem_list->backuplist = toremove;
+ if(bamboo_free_mem_list->backuplist == NULL) {
+ //toremove->next = bamboo_free_mem_list->backuplist;
+ bamboo_free_mem_list->backuplist = toremove;
+ bamboo_free_mem_list->backuplist->next = NULL;
+ } else {
+ // free it
+ RUNFREE(toremove);
+ }
} else {
prev = freemem;
freemem = freemem->next;
(struct transObjInfo *)(qitem->objectptr);
if(tmpinfo->objptr == transObj->objptr) {
// the same object, remove outdate one
+ RUNFREE(tmpinfo->queues);
+ RUNFREE(tmpinfo);
removeItem(&objqueue, qitem);
//break;
} else {
case GCMARKEDOBJ: {
// received a markedObj msg
- gc_enqueue_I(msgdata[1]);
+ if(((int *)msgdata[1])[6] == INIT) {
+ // this is the first time that this object is discovered,
+ // set the flag as DISCOVERED
+ ((int *)msgdata[1])[6] = DISCOVERED;
+ gc_enqueue_I(msgdata[1]);
+ }
gcself_numreceiveobjs++;
gcbusystatus = true;
break;
case GCMAPREQUEST: {
// received a mapping info request msg
void * dstptr = NULL;
+ //dstptr = mgchashSearch(msgdata[1]);
RuntimeHashget(gcpointertbl, msgdata[1], &dstptr);
+ //MGCHashget(gcpointertbl, msgdata[1], &dstptr);
if(NULL == dstptr) {
// no such pointer in this core, something is wrong
#ifdef DEBUG
BAMBOO_DEBUGPRINT_REG(msgdata[2]);
#endif
BAMBOO_EXIT(0xb007);
+ //assume that the object was not moved, use the original address
+ /*if(isMsgSending) {
+ cache_msg_3(msgdata[2], GCMAPINFO, msgdata[1], msgdata[1]);
+ } else {
+ send_msg_3(msgdata[2], GCMAPINFO, msgdata[1], msgdata[1]);
+ }*/
} else {
// send back the mapping info
if(isMsgSending) {
BAMBOO_EXIT(0xb008);
} else {
gcmappedobj = msgdata[2];
+ //mgchashInsert_I(gcobj2map, gcmappedobj);
RuntimeHashadd_I(gcpointertbl, gcobj2map, gcmappedobj);
+ //MGCHashadd_I(gcpointertbl, gcobj2map, gcmappedobj);
}
gcismapped = true;
break;
case GCLOBJMAPPING: {
// received a large obj mapping info msg
+ //mgchashInsert_I(msgdata[1], msgdata[2]);
RuntimeHashadd_I(gcpointertbl, msgdata[1], msgdata[2]);
+ //MGCHashadd_I(gcpointertbl, msgdata[1], msgdata[2]);
break;
}
#endif
/* See if there are any active tasks */
- if (hashsize(activetasks)>0) {
+ //if (hashsize(activetasks)>0) {
int i;
#ifdef PROFILE
#ifdef ACCURATEPROFILE
profileTaskStart("tpd checking");
#endif
#endif
+ //long clock1;
+ //clock1 = BAMBOO_GET_EXE_TIME();
+
busystatus = true;
currtpd=(struct taskparamdescriptor *) getfirstkey(activetasks);
genfreekey(activetasks, currtpd);
// clear the lockRedirectTbl
// (TODO, this table should be empty after all locks are released)
// reset all locks
- for(j = 0; j < MAXTASKPARAMS; j++) {
+ /*for(j = 0; j < MAXTASKPARAMS; j++) {
runtime_locks[j].redirectlock = 0;
runtime_locks[j].value = 0;
- }
+ }*/
// get all required locks
runtime_locklen = 0;
// check which locks are needed
#ifdef DEBUG
BAMBOO_DEBUGPRINT(0xe991);
#endif
+ //long clock2;
+ //clock2 = BAMBOO_GET_EXE_TIME();
+
for(i = 0; i < runtime_locklen; i++) {
+ /*for(i = 0; i < numparams; i++) {
+ void * param = currtpd->parameterArray[i];
+ int * lock = 0;
+ bool insert = true;
+ if(((struct ___Object___ *)param)->type == STARTUPTYPE) {
+ islock = false;
+ taskpointerarray[i+OFFSET]=param;
+ goto execute;
+ }
+ if(((struct ___Object___ *)param)->lock == NULL) {
+ lock = (int *)param;
+ } else {
+ lock = (int *)(((struct ___Object___ *)param)->lock);
+ }
+ */
+
int * lock = (int *)(runtime_locks[i].redirectlock);
islock = true;
// require locks for this parameter if it is not a startup object
#endif
if(grount == 0) {
- int j = 0;
#ifdef DEBUG
BAMBOO_DEBUGPRINT(0xe992);
BAMBOO_DEBUGPRINT_REG(lock);
#endif
+ // check if has the lock already
+ /*bool giveup = true;
+ for(j = 0; j < runtime_locklen; j++) {
+ if(runtime_locks[j].value == lock) {
+ giveup = false;
+ break;
+ }
+ }
+ if(giveup) {*/
// can not get the lock, try later
- // releas all grabbed locks for previous parameters
- for(j = 0; j < i; ++j) {
+ // release all grabbed locks for previous parameters
+ for(j = 0; j < i; ++j) {
+ //for(j = 0; j < runtime_locklen; ++j) {
lock = (int*)(runtime_locks[j].redirectlock);
releasewritelock(lock);
}
#endif
#endif
goto newtask;
- } // line 2794: if(grount == 0)
+ //}
+ }/* else { // line 2794: if(grount == 0)
+ // TODO
+ runtime_locks[runtime_locklen].value = (int)lock;
+ runtime_locks[runtime_locklen].redirectlock = (int)param;
+ runtime_locklen++;
+ }*/
} // line 2752: for(i = 0; i < runtime_locklen; i++)
+ /*long clock3;
+ clock3 = BAMBOO_GET_EXE_TIME();
+ //tprintf("sort: %d, grab: %d \n", clock2-clock1, clock3-clock2);*/
+
#ifdef DEBUG
BAMBOO_DEBUGPRINT(0xe993);
#endif
#endif
profileTaskStart(currtpd->task->name);
#endif
+ // TODO
+ //long clock4;
+ //clock4 = BAMBOO_GET_EXE_TIME();
+ //tprintf("sort: %d, grab: %d, check: %d \n", (int)(clock2-clock1), (int)(clock3-clock2), (int)(clock4-clock3));
#ifdef DEBUG
BAMBOO_DEBUGPRINT(0xe997);
#endif
((void(*) (void **))currtpd->task->taskptr)(taskpointerarray);
+ // TODO
+ //long clock5;
+ //clock5 = BAMBOO_GET_EXE_TIME();
+ // tprintf("sort: %d, grab: %d, check: %d \n", (int)(clock2-clock1), (int)(clock3-clock2), (int)(clock4-clock3));
+
#ifdef PROFILE
#ifdef ACCURATEPROFILE
// task finish, set the end of the checkTaskInfo
}
} // line 3015: if(islock)
+ //long clock6;
+ //clock6 = BAMBOO_GET_EXE_TIME();
+ //tprintf("sort: %d, grab: %d, check: %d \n", (int)(clock2-clock1), (int)(clock3-clock2), (int)(clock4-clock3));
+
#ifdef PROFILE
// post task execution finish, set the end of the postTaskInfo
profileTaskEnd();
#ifdef DEBUG
BAMBOO_DEBUGPRINT(0xe99a);
#endif
+ //long clock7;
+ //clock7 = BAMBOO_GET_EXE_TIME();
+ //tprintf("sort: %d, grab: %d, check: %d, release: %d, other %d \n", (int)(clock2-clock1), (int)(clock3-clock2), (int)(clock4-clock3), (int)(clock6-clock5), (int)(clock7-clock6));
+
} //
- } // if (hashsize(activetasks)>0)
+ //} // if (hashsize(activetasks)>0)
} // while(hashsize(activetasks)>0)
#ifdef DEBUG
BAMBOO_DEBUGPRINT(0xe99b);