task Startup( StartupObject s{ initialstate } )
{
//System.printString("Top of task Startup\n");
- SubProblem top = new SubProblem(){ findingNewFits, main };
+ SubProblem top = newflag SubProblem(){ findingNewFits, main };
// use this initialization to solve the above example
[top.tilesFitted[0].y] = 0;
top.highScore = 0;
- GlobalCounter counter = new GlobalCounter() {Init};
+ GlobalCounter counter = newflag GlobalCounter() {Init};
taskexit( s{ !initialstate } );
}
//System.printString( "North: \n" );
SubProblem newSP = null;
if(sp.tilesToFit.length == 1 ) {
- newSP = new SubProblem() { !scored, leaf };
+ newSP = newflag SubProblem() { !scored, leaf };
++counter.counter;
} else {
- newSP = new SubProblem() { findingNewFits };
+ newSP = newflag SubProblem() { findingNewFits };
}
sp.initializeSubProblem( newSP, 1 );
//System.printString( "match! new a SubProblem\n" );
//System.printString( "South: \n" );
SubProblem newSP = null;
if(sp.tilesToFit.length == 1) {
- newSP = new SubProblem() { !scored, leaf };
+ newSP = newflag SubProblem() { !scored, leaf };
++counter.counter;
} else {
- newSP = new SubProblem() { findingNewFits };
+ newSP = newflag SubProblem() { findingNewFits };
}
sp.initializeSubProblem( newSP, 2 );
//System.printString( "match! new a SubProblem\n" );
//System.printString( "East: \n" );
SubProblem newSP = null;
if(sp.tilesToFit.length == 1) {
- newSP = new SubProblem() { !scored, leaf };
+ newSP = newflag SubProblem() { !scored, leaf };
++counter.counter;
} else {
- newSP = new SubProblem() { findingNewFits };
+ newSP = newflag SubProblem() { findingNewFits };
}
sp.initializeSubProblem( newSP, 3 );
//System.printString( "match! new a SubProblem\n" );
//System.printString( "West:\n" );
SubProblem newSP = null;
if(sp.tilesToFit.length == 1) {
- newSP = new SubProblem() { !scored, leaf };
+ newSP = newflag SubProblem() { !scored, leaf };
++counter.counter;
} else {
- newSP = new SubProblem() { findingNewFits };
+ newSP = newflag SubProblem() { findingNewFits };
}
sp.initializeSubProblem( newSP, 4 );
//System.printString( "match! new a SubProblem\nSpawn finished! Go on find new fits.\n" );
outmethodheader.close();
outmethod.close();
outstructs.println("#endif");
+ outstructs.println();
outstructs.close();
postCodeGenCleanUp();
}
protected void outputStructs(PrintWriter outstructs) {
- outstructs.println("#ifndef STRUCTDEFS_H");
- outstructs.println("#define STRUCTDEFS_H");
+ outstructs.println("#ifndef __STRUCTDEFS_H__");
+ outstructs.println("#define __STRUCTDEFS_H__");
outstructs.println("#include \"classdefs.h\"");
outstructs.println("#ifndef INTPTR");
outstructs.println("#ifdef BIT64");
outclassdefs.println(" int * lock;"); // lock entry for this obj
outclassdefs.println(" int mutex;");
outclassdefs.println(" volatile int lockcount;");
- outclassdefs.println(" volatile int notifycount;");
if(state.MULTICOREGC) {
outclassdefs.println(" int marked;");
}
classdefout.println(" int version;");
classdefout.println(" int * lock;"); // lock entry for this obj
classdefout.println(" int mutex;");
- classdefout.println(" int lockcount;");
+ classdefout.println(" volatile int lockcount;");
if(state.MULTICOREGC) {
classdefout.println(" int marked;");
}
}
}
- //gcflag = false;
- //gcprocessing = false;
#ifdef RAWPATH // TODO GC_DEBUG
printf("(%x,%x) Finish gc! \n", udn_tile_coord_x(), udn_tile_coord_y());
#endif
break;
}
}
- //gcflag = false;
- //gcprocessing = false;
#ifdef RAWPATH // TODO GC_DEBUG
printf("(%x,%x) Finish gc! \n", udn_tile_coord_x(), udn_tile_coord_y());
#endif
} // void gc_collect(struct garbagelist * stackptr)
inline void gc_master(struct garbagelist * stackptr) {
- //tprintf("start GC !!!!!!!!!!!!! \n");
+ tprintf("start GC !!!!!!!!!!!!! \n");
gcphase = INITPHASE;
int i = 0;
printf("(%x,%x) gc finished \n", udn_tile_coord_x(),
udn_tile_coord_y());
#endif
- //tprintf("finish GC ! \n");
+ tprintf("finish GC ! \n");
} // void gc_master(struct garbagelist * stackptr)
inline bool gc(struct garbagelist * stackptr) {
#endif
#ifdef TASK
-#define BAMBOOMARKBIT 6
+#define BAMBOOMARKBIT 8
#elif defined MGC
#define BAMBOOMARKBIT 5
#endif // TASK
void * mem = NULL;
#ifdef MULTICORE_GC
if(gcprocessing) {
- // is currently doing gc, dump this msg
- if(INITPHASE == gcphase) {
- // if still in the initphase of gc, send a startinit msg again,
- // cache the msg first
+ // is currently doing gc, dump this msg if at the beginning of the gc
+ // if at the end of the gc, send a msg with a block with size of -1
+ // to ask the request core to send the mem request again
+ if(FINISHPHASE == gcphase) {
+ // if still in the finishphase of gc, send a memresponse msg with
+ // invalid block: addr 0, size -1
+ if(BAMBOO_CHECK_SEND_MODE()) {
+ cache_msg_3(data2, MEMRESPONSE, 0, -1);
+ } else {
+ send_msg_3(data2, MEMRESPONSE, 0, -1, true);
+ }
+ } else if(INITPHASE == gcphase) {
if(BAMBOO_CHECK_SEND_MODE()) {
cache_msg_1(data2, GCSTARTINIT);
} else {
send_msg_1(data2, GCSTARTINIT, true);
}
- }
+ }
} else {
#endif
mem = smemalloc_I(data2, data1, &allocsize);
#ifdef MULTICORE_GC
bamboo_smem_zero_top = 0;
#endif
+ } else if(data2 == -1) {
+ bamboo_smem_size = data2;
+ bamboo_cur_msp = (void *)data1;
} else {
#ifdef MULTICORE_GC
// fill header to store the size of this mem block
INLINE void processmsg_gcstartpre_I() {
if(gcprocessing) {
// already stall for gc
- // send a update pregc information msg to the master core
- /*if(BAMBOO_CHECK_SEND_MODE()) {
- cache_msg_4(STARTUPCORE, GCFINISHPRE, BAMBOO_NUM_OF_CORE,
- self_numsendobjs, self_numreceiveobjs);
- } else {
- send_msg_4(STARTUPCORE, GCFINISHPRE, BAMBOO_NUM_OF_CORE,
- self_numsendobjs, self_numreceiveobjs, true);
- }*/
} else {
// the first time to be informed to start gc
gcflag = true;
#include "runtime_arch.h"
#ifdef MULTICORE_GC
+extern volatile bool gcflag;
void * mycalloc_share(struct garbagelist * stackptr,
int m,
int size) {
- void * p = NULL;
+ void * p = NULL;
//int isize = 2*BAMBOO_CACHE_LINE_SIZE-4+(size-1)&(~BAMBOO_CACHE_LINE_MASK);
int isize = (size & (~(BAMBOO_CACHE_LINE_MASK))) + (BAMBOO_CACHE_LINE_SIZE);
- int hasgc = 0;
+ int hasgc = 0;
memalloc:
BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
+ if(gcflag) {
+ BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
+ gc(stackptr);
+ BAMBOO_ENTER_RUNTIME_MODE_FROM_CLIENT();
+ }
p = BAMBOO_SHARE_MEM_CALLOC_I(m, isize); // calloc(m, isize);
if(p == NULL) {
// no more global shared memory
BAMBOO_ENTER_CLIENT_MODE_FROM_RUNTIME();
if(hasgc < 5) {
// start gc
- if(gc(stackptr)) {
- hasgc++;
+ while(gcflag) {
+ gc(stackptr);
}
+ hasgc++;
} else {
// no more global shared memory
BAMBOO_EXIT(0xc001);