From cbbba6bdf3dad63d274243049ad44d3cffafbc65 Mon Sep 17 00:00:00 2001 From: jjenista Date: Thu, 23 Sep 2010 19:17:12 +0000 Subject: [PATCH] while working on memory pool for task records, fixed bug where mem Q hashtable entries had to wait for pointer value but used the wrong object id (oid) --- Robust/src/IR/Flat/BuildCode.java | 149 ++++++++++--------- Robust/src/Runtime/garbage.c | 2 +- Robust/src/Runtime/memPool.h | 4 +- Robust/src/Runtime/mlp_lock.h | 4 + Robust/src/Runtime/mlp_runtime.c | 55 ++++--- Robust/src/Runtime/mlp_runtime.h | 34 +++-- Robust/src/Runtime/workschedule.c | 4 +- Robust/src/Tests/oooJava/poolalloc/test.java | 14 +- 8 files changed, 144 insertions(+), 122 deletions(-) diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 0e592230..7abc1326 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -1916,10 +1916,8 @@ public class BuildCode { System.out.println("size="+lockSet.size()); if (lockSet.size() > 0) { output.println(" numMemoryQueue=" + lockSet.size() + ";"); - output - .println(" seseCaller->numMemoryQueue=numMemoryQueue;"); - output - .println(" seseCaller->memoryQueueArray=mlpCreateMemoryQueueArray(numMemoryQueue);"); + output.println(" runningSESE->numMemoryQueue=numMemoryQueue;"); + output.println(" runningSESE->memoryQueueArray=mlpCreateMemoryQueueArray(numMemoryQueue);"); output.println(); } } @@ -1942,10 +1940,8 @@ public class BuildCode { System.out.println("size="+lockSet.size()); if (lockSet.size() > 0) { output.println(" numMemoryQueue=" + lockSet.size() + ";"); - output - .println(" seseCaller->numMemoryQueue=numMemoryQueue;"); - output - .println(" seseCaller->memoryQueueArray=mlpCreateMemoryQueueArray(numMemoryQueue);"); + output.println(" runningSESE->numMemoryQueue=numMemoryQueue;"); + output.println(" runningSESE->memoryQueueArray=mlpCreateMemoryQueueArray(numMemoryQueue);"); output.println(); } } @@ -2203,6 +2199,7 @@ public class BuildCode { output.print(fsen.getSESErecordName()+"* "+paramsprefix); output.println("){\n"); + TempObject objecttemp=(TempObject) tempstable.get(md); if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) { @@ -2271,6 +2268,14 @@ public class BuildCode { output.println(" "+type+" "+temp+";"); } } + + + // initialize thread-local var to a the task's record, which is fused + // with the param list + output.println(" "); + output.println(" /* code of this task's body should use this to access the running task record */"); + output.println(" runningSESE = &(___params___->common);"); + output.println(" "); // setup memory queue // eom @@ -2281,16 +2286,12 @@ public class BuildCode { Analysis.OoOJava.ConflictGraph graph = oooa.getConflictGraph(fsen); if (graph != null && graph.hasConflictEdge()) { output.println(" {"); - output - .println(" SESEcommon* parentCommon = &(___params___->common);"); Set lockSet = oooa.getLockMappings(graph); System.out.println("#lockSet="+lockSet); if (lockSet.size() > 0) { output.println(" numMemoryQueue=" + lockSet.size() + ";"); - output - .println(" parentCommon->numMemoryQueue=numMemoryQueue;"); - output - .println(" parentCommon->memoryQueueArray=mlpCreateMemoryQueueArray(numMemoryQueue);"); + output.println(" runningSESE->numMemoryQueue=numMemoryQueue;"); + output.println(" runningSESE->memoryQueueArray=mlpCreateMemoryQueueArray(numMemoryQueue);"); output.println(); } output.println(" }"); @@ -2303,18 +2304,14 @@ public class BuildCode { graph = mlpa.getConflictGraphResults().get(fsen); if (graph != null && graph.hasConflictEdge()) { output.println(" {"); - output - .println(" SESEcommon* parentCommon = &(___params___->common);"); HashSet lockSet = mlpa.getConflictGraphLockMap().get( graph); System.out.println("#lockSet="+lockSet); if (lockSet.size() > 0) { output.println(" numMemoryQueue=" + lockSet.size() + "; "); - output - .println(" parentCommon->numMemoryQueue=numMemoryQueue;"); - output - .println(" parentCommon->memoryQueueArray=mlpCreateMemoryQueueArray(numMemoryQueue);"); + output.println(" runningSESE->numMemoryQueue=numMemoryQueue;"); + output.println(" runningSESE->memoryQueueArray=mlpCreateMemoryQueueArray(numMemoryQueue);"); output.println(); } output.println(" }"); @@ -2323,6 +2320,16 @@ public class BuildCode { } + // set up a task's mem pool to recycle the allocation of children tasks + // TODO: optimize by skipping this initialization when the current task + // is known to have no children (non-trivial, no children in body and + // no possibilty of issuing child within method calls) + output.println(" {"); + output.println(" runningSESE->taskRecordMemPool = poolcreate( "+ + maxTaskRecSizeStr+" );"); + output.println(" }"); + + // copy in-set into place, ready vars were already // copied when the SESE was issued Iterator tempItr; @@ -2334,22 +2341,11 @@ public class BuildCode { VariableSourceToken vst = fsen.getStaticInVarSrc( temp ); SESEandAgePair srcPair = new SESEandAgePair( vst.getSESE(), vst.getAge() ); - // can't grab something from this source until it is done - output.println(" {"); - /* - If we are running, everything is done. This check is redundant. - - output.println(" SESEcommon* com = (SESEcommon*)"+paramsprefix+"->"+srcPair+";" ); - output.println(" pthread_mutex_lock( &(com->lock) );"); - output.println(" while( com->doneExecuting == FALSE ) {"); - output.println(" pthread_cond_wait( &(com->doneCond), &(com->lock) );"); - output.println(" }"); - output.println(" pthread_mutex_unlock( &(com->lock) );"); - */ output.println(" "+generateTemp( fsen.getfmBogus(), temp, null )+ " = "+paramsprefix+"->"+srcPair+"->"+vst.getAddrVar()+";"); - - output.println(" }"); + //output.println(" if( atomic_sub_and_test( 1, &src->refCount ) ) {"); + //output.println(" poolfree( src->parent->taskRecordMemPool, src );"); + //output.println(" }"); } // dynamic vars come from an SESE and src @@ -2361,17 +2357,6 @@ public class BuildCode { // go grab it from the SESE source output.println(" if( "+paramsprefix+"->"+temp+"_srcSESE != NULL ) {"); - // gotta wait until the source is done - output.println(" SESEcommon* com = (SESEcommon*)"+paramsprefix+"->"+temp+"_srcSESE;" ); - /* - If we are running, everything is done! - output.println(" pthread_mutex_lock( &(com->lock) );"); - output.println(" while( com->doneExecuting == FALSE ) {"); - output.println(" pthread_cond_wait( &(com->doneCond), &(com->lock) );"); - output.println(" }"); - output.println(" pthread_mutex_unlock( &(com->lock) );"); - */ - String typeStr; if( type.isNull() ) { typeStr = "void*"; @@ -2385,8 +2370,13 @@ public class BuildCode { " = *(("+typeStr+"*) ("+ paramsprefix+"->"+temp+"_srcSESE + "+ paramsprefix+"->"+temp+"_srcOffset));"); + + //output.println(" if( atomic_sub_and_test( 1, &src->refCount ) ) {"); + //output.println(" poolfree( src->parent->taskRecordMemPool, src );"); + //output.println(" }"); - // or if the source was our parent, its in the record to grab + + // or if the source was our parent, its in our record to grab output.println(" } else {"); output.println(" "+generateTemp( fsen.getfmBogus(), temp, null )+ " = "+paramsprefix+"->"+temp+";"); @@ -2407,9 +2397,6 @@ public class BuildCode { // } } - // initialize thread-local var to a non-zero, invalid address - output.println(" seseCaller = (SESEcommon*) 0x2;"); - if( state.COREPROF ) { output.println(" CP_LOGEVENT( CP_EVENTID_TASKEXECUTE, CP_EVENTTYPE_BEGIN );"); } @@ -3012,13 +2999,13 @@ public class BuildCode { } if( waitingElement.getStatus() >= ConflictNode.COARSE ){ - output.println(" rentry=mlpCreateREntry("+ waitingElement.getStatus()+ ", seseCaller);"); + output.println(" rentry=mlpCreateREntry("+ waitingElement.getStatus()+ ", runningSESE);"); }else{ - output.println(" rentry=mlpCreateFineREntry("+ waitingElement.getStatus()+ ", seseCaller, (void*)&" +generateTemp(fm,waitingElement.getTempDesc(),lb)+ ");"); + output.println(" rentry=mlpCreateFineREntry("+ waitingElement.getStatus()+ ", runningSESE, (void*)&" +generateTemp(fm,waitingElement.getTempDesc(),lb)+ ");"); } output.println(" psem_init( &(rentry->parentStallSem) );"); - output.println(" rentry->queue=seseCaller->memoryQueueArray["+ waitingElement.getQueueID()+ "];"); - output.println(" if(ADDRENTRY(seseCaller->memoryQueueArray["+ waitingElement.getQueueID() + output.println(" rentry->queue=runningSESE->memoryQueueArray["+ waitingElement.getQueueID()+ "];"); + output.println(" if(ADDRENTRY(runningSESE->memoryQueueArray["+ waitingElement.getQueueID() + "],rentry)==NOTREADY){"); if( state.COREPROF ) { //output.println(" CP_LOGEVENT( CP_EVENTID_TASKSTALLMEM, CP_EVENTTYPE_BEGIN );"); @@ -3062,15 +3049,14 @@ public class BuildCode { if( waitingElement.getStatus() >= ConflictNode.COARSE ){ // HERE! a parent might conflict with a child - output.println(" rentry=mlpCreateREntry("+ waitingElement.getStatus()+ ", seseCaller);"); + output.println(" rentry=mlpCreateREntry("+ waitingElement.getStatus()+ ", runningSESE);"); }else{ - output.println(" rentry=mlpCreateFineREntry("+ waitingElement.getStatus()+ ", seseCaller, (void*)&___locals___."+ waitingElement.getDynID() + ");"); - // output.println(" rentry=mlpCreateFineREntry("+ waitingElement.getStatus()+ ", seseCaller, ___locals___."+ waitingElement.getDynID() + "->oid);"); + output.println(" rentry=mlpCreateFineREntry("+ waitingElement.getStatus()+ ", runningSESE, (void*)&___locals___."+ waitingElement.getDynID() + ");"); } output.println(" psem_init( &(rentry->parentStallSem) );"); - output.println(" rentry->queue=seseCaller->memoryQueueArray["+ waitingElement.getQueueID()+ "];"); + output.println(" rentry->queue=runningSESE->memoryQueueArray["+ waitingElement.getQueueID()+ "];"); output - .println(" if(ADDRENTRY(seseCaller->memoryQueueArray["+ waitingElement.getQueueID() + .println(" if(ADDRENTRY(runningSESE->memoryQueueArray["+ waitingElement.getQueueID() + "],rentry)==NOTREADY){"); if( state.COREPROF ) { //output.println(" CP_LOGEVENT( CP_EVENTID_TASKSTALLMEM, CP_EVENTTYPE_BEGIN );"); @@ -3635,7 +3621,7 @@ public class BuildCode { output.println(" SESEcommon* parentCommon = &("+paramsprefix+"->common);"); } else { //output.println(" SESEcommon* parentCommon = (SESEcommon*) peekItem( seseCallStack );"); - output.println(" SESEcommon* parentCommon = seseCaller;"); + output.println(" SESEcommon* parentCommon = runningSESE;"); } } @@ -3652,6 +3638,21 @@ public class BuildCode { fsen.getSESErecordName()+"*) mlpAllocSESErecord( sizeof( "+ fsen.getSESErecordName()+" ) );"); + /* + if( (state.MLP && fsen != mlpa.getMainSESE()) || + (state.OOOJAVA && fsen != oooa.getMainSESE()) + ) { + output.println(" "+ + fsen.getSESErecordName()+"* seseToIssue = ("+ + fsen.getSESErecordName()+"*) poolalloc( runningSESE->taskRecordMemPool );"); + } else { + output.println(" "+ + fsen.getSESErecordName()+"* seseToIssue = ("+ + fsen.getSESErecordName()+"*) mlpAllocSESErecord( sizeof( "+ + fsen.getSESErecordName()+" ) );"); + } + */ + // set up the SESE in-set and out-set objects, which look // like a garbage list output.println(" struct garbagelist * gl= (struct garbagelist *)&(((SESEcommon*)(seseToIssue))[1]);"); @@ -3674,10 +3675,6 @@ public class BuildCode { ); } - - // and keep the thread-local sese stack up to date (jjenista--this still relevant??) - //output.println(" addNewItem( seseCallStack, (void*) seseToIssue);"); - // fill in common data output.println(" int localCount=0;"); output.println(" seseToIssue->common.classID = "+fsen.getIdentifier()+";"); @@ -3690,6 +3687,7 @@ public class BuildCode { output.println(" pthread_cond_init( &(seseToIssue->common.runningChildrenCond), NULL );"); output.println(" seseToIssue->common.numRunningChildren = 0;"); output.println(" seseToIssue->common.parent = parentCommon;"); + output.println(" seseToIssue->common.refCount = 1;"); // all READY in-vars should be copied now and be done with it Iterator tempItr = fsen.getReadyInVarSet().iterator(); @@ -3748,7 +3746,7 @@ public class BuildCode { output.println(" }"); output.println(" if( !src->doneExecuting ) {"); output.println(" addNewItem( src->forwardList, seseToIssue );"); -// output.println(" ++(seseToIssue->common.unresolvedDependencies);"); + output.println(" src->refCount++;"); output.println(" ++(localCount);"); output.println(" }"); output.println(" pthread_mutex_unlock( &(src->lock) );"); @@ -3783,7 +3781,7 @@ public class BuildCode { output.println(" seseToIssue != peekItem( src->forwardList ) ) {"); output.println(" if( !src->doneExecuting ) {"); output.println(" addNewItem( src->forwardList, seseToIssue );"); -// output.println(" ++(seseToIssue->common.unresolvedDependencies);"); + output.println(" src->refCount++;"); output.println(" ++(localCount);"); output.println(" }"); output.println(" }"); @@ -4298,10 +4296,19 @@ public class BuildCode { output.println(" }"); output.println(" }"); - // this is a thread-only variable that can be handled when critical sese-to-sese - // data has been taken care of--set sese pointer to remember self over method - // calls to a non-zero, invalid address - output.println(" seseCaller = (SESEcommon*) 0x1;"); + // only do this pool free if this is not the Main sese (which has no parent + // and therefore no pool to free into) + if( (state.MLP && fsen != mlpa.getMainSESE()) || + (state.OOOJAVA && fsen != oooa.getMainSESE()) + ) { + //output.println(" if( atomic_sub_and_test( 1, &runningSESE->refCount ) ) {"); + //output.println(" poolfree( runningSESE->parent->taskRecordMemPool, runningSESE );"); + //output.println(" }"); + } + + // as this thread is wrapping up the task, make sure the thread-local var + // for the currently running task record references an invalid task + output.println(" runningSESE = (SESEcommon*) 0x1;"); if( state.COREPROF ) { output.println(" CP_LOGEVENT( CP_EVENTID_TASKRETIRE, CP_EVENTTYPE_END );"); @@ -4380,11 +4387,13 @@ public class BuildCode { private void generateFlatCall(FlatMethod fm, LocalityBinding lb, FlatCall fc, PrintWriter output) { + /* if( (state.MLP && !nonSESEpass) || (state.OOOJAVA && !nonSESEpass) ) { - output.println(" seseCaller = (SESEcommon*)"+paramsprefix+";"); + output.println(" runningSESE = (SESEcommon*)"+paramsprefix+";"); } + */ MethodDescriptor md=fc.getMethod(); ParamsObject objectparams=(ParamsObject)paramstable.get(lb!=null ? locality.getBinding(lb, fc) : md); diff --git a/Robust/src/Runtime/garbage.c b/Robust/src/Runtime/garbage.c index c5da7ce8..ae1f65f0 100644 --- a/Robust/src/Runtime/garbage.c +++ b/Robust/src/Runtime/garbage.c @@ -1019,7 +1019,7 @@ updateForwardList(struct Queue *forwardList, int prevUpdate){ } -updateMemoryQueue(SESEcommon_p seseParent){ +updateMemoryQueue(SESEcommon* seseParent){ // update memory queue int i,binidx; for(i=0; inumMemoryQueue; i++){ diff --git a/Robust/src/Runtime/memPool.h b/Robust/src/Runtime/memPool.h index ffd665c1..14c0fac1 100644 --- a/Robust/src/Runtime/memPool.h +++ b/Robust/src/Runtime/memPool.h @@ -47,9 +47,9 @@ typedef struct MemPool_t { // the memory pool must always have at least one // item in it static MemPool* poolcreate( int itemSize ) { - MemPool* p = malloc( sizeof( MemPool ) ); + MemPool* p = calloc( 1, sizeof( MemPool ) ); p->itemSize = itemSize; - p->head = malloc( itemSize ); + p->head = calloc( 1, itemSize ); p->head->next = NULL; p->tail = p->head; } diff --git a/Robust/src/Runtime/mlp_lock.h b/Robust/src/Runtime/mlp_lock.h index 0550a9c3..3eb341ea 100644 --- a/Robust/src/Runtime/mlp_lock.h +++ b/Robust/src/Runtime/mlp_lock.h @@ -30,6 +30,10 @@ static inline void atomic_inc(volatile int *v) { : "+m" (*v)); } +// this returns TRUE if the atomic subtraction results in +// a zero value--this way two threads cannot dec a value +// atomically, but then go ahead and both read zero, +// thinking they both are the last decrementer static inline int atomic_sub_and_test(int i, volatile int *v) { unsigned char c; diff --git a/Robust/src/Runtime/mlp_runtime.c b/Robust/src/Runtime/mlp_runtime.c index b7a87b55..3e7fe723 100644 --- a/Robust/src/Runtime/mlp_runtime.c +++ b/Robust/src/Runtime/mlp_runtime.c @@ -10,15 +10,7 @@ #include "methodheaders.h" - -/* -__thread struct Queue* seseCallStack; -__thread pthread_once_t mlpOnceObj = PTHREAD_ONCE_INIT; -void mlpInitOncePerThread() { - seseCallStack = createQueue(); -} -*/ -__thread SESEcommon_p seseCaller; +__thread SESEcommon* runningSESE; void* mlpAllocSESErecord( int size ) { @@ -54,10 +46,6 @@ REntry* mlpCreateFineREntry(int type, void* seseToIssue, void* dynID){ newREntry->type=type; newREntry->seseRec=seseToIssue; newREntry->pointer=dynID; - if((*newREntry->pointer)!=0){// make sure it is not unresolved address. - struct ___Object___ * obj=(struct ___Object___*)((unsigned INTPTR)*newREntry->pointer); - newREntry->oid=obj->oid; - } return newREntry; } @@ -246,7 +234,12 @@ int ADDTABLE(MemoryQueue *q, REntry *r) { //at this point, have table Hashtable* table=(Hashtable*)q->tail; r->hashtable=table; // set rentry's hashtable - if((*(r->pointer)==0 || (*(r->pointer)!=0 && BARRIER() && table->unresolvedQueue!=NULL))){ + if( *(r->pointer)==0 || + ( *(r->pointer)!=0 && + BARRIER() && + table->unresolvedQueue!=NULL + ) + ){ struct Queue* val; // grab lock on the queue do { @@ -273,8 +266,16 @@ int ADDTABLE(MemoryQueue *q, REntry *r) { return NOTREADY; } BinItem * val; - //int key=generateKey((unsigned int)(unsigned INTPTR)*(r->pointer)); - int key=generateKey(r->oid); + + // leave this--its a helpful test when things are going bonkers + //if( OBJPTRPTR_2_OBJOID( r->pointer ) == 0 ) { + // // we started numbering object ID's at 1, if we try to + // // hash a zero oid, something BAD is about to happen! + // printf( "Tried to insert invalid object type=%d into mem Q hashtable!\n", + // OBJPTRPTR_2_OBJTYPE( r->pointer ) ); + // exit( -1 ); + //} + int key=generateKey( OBJPTRPTR_2_OBJOID( r->pointer ) ); do { val=(BinItem*)0x1; BinElement* bin=table->array[key]; @@ -295,8 +296,7 @@ int ADDTABLE(MemoryQueue *q, REntry *r) { int ADDTABLEITEM(Hashtable* table, REntry* r, int inc){ BinItem * val; - // int key=generateKey((unsigned int)(unsigned INTPTR)*(r->pointer)); - int key=generateKey(r->oid); + int key=generateKey( OBJPTRPTR_2_OBJOID( r->pointer ) ); do { val=(BinItem*)0x1; BinElement* bin=table->array[key]; @@ -436,7 +436,6 @@ int TAILREADCASE(Hashtable *T, REntry *r, BinItem *val, BinItem *bintail, int ke readbintail->array[readbintail->index++]=r; atomic_inc(&readbintail->item.total); r->binitem=(BinItem*)readbintail; - //printf("grouping with %d\n",readbintail->index); } if(inc){ atomic_inc(&T->item.total); @@ -587,8 +586,7 @@ RETIREHASHTABLE(MemoryQueue *q, REntry *r) { } RETIREBIN(Hashtable *T, REntry *r, BinItem *b) { - // int key=generateKey((unsigned int)(unsigned INTPTR)*(r->pointer)); - int key=generateKey(r->oid); + int key=generateKey( OBJPTRPTR_2_OBJOID( r->pointer ) ); if(isFineRead(r)) { atomic_dec(&b->total); } @@ -809,7 +807,7 @@ int RESOLVEBUFFORHASHTABLE(MemoryQueue * q, Hashtable* table, SESEcommon *seseCo for(i=0; ibufcount;i++){ REntry *r=q->buf[i]; if(r->type==WRITE){ - int key=generateKey(r->oid); + int key=generateKey( OBJPTRPTR_2_OBJOID( r->pointer ) ); if(q->binbuf[key]==NULL){ // for multiple writes, add only the first write that hashes to the same bin q->binbuf[key]=r; @@ -822,7 +820,7 @@ int RESOLVEBUFFORHASHTABLE(MemoryQueue * q, Hashtable* table, SESEcommon *seseCo for(i=0; ibufcount;i++){ REntry *r=q->buf[i]; if(r!=NULL && r->type==READ){ - int key=generateKey(r->oid); + int key=generateKey( OBJPTRPTR_2_OBJOID( r->pointer ) ); if(q->binbuf[key]==NULL){ // read item that hashes to the bin which doen't contain any write seseCommon->rentryArray[seseCommon->rentryIdx++]=r; @@ -874,7 +872,7 @@ int RESOLVEBUF(MemoryQueue * q, SESEcommon *seseCommon){ for(i=0; ibufcount;i++){ REntry *r=q->buf[i]; if(r->type==WRITE){ - int key=generateKey(r->oid); + int key=generateKey( OBJPTRPTR_2_OBJOID( r->pointer ) ); if(q->binbuf[key]==NULL){ // for multiple writes, add only the first write that hashes to the same bin q->binbuf[key]=r; @@ -887,7 +885,7 @@ int RESOLVEBUF(MemoryQueue * q, SESEcommon *seseCommon){ for(i=0; ibufcount;i++){ REntry *r=q->buf[i]; if(r!=NULL && r->type==READ){ - int key=generateKey(r->oid); + int key=generateKey( OBJPTRPTR_2_OBJOID( r->pointer ) ); if(q->binbuf[key]==NULL){ // read item that hashes to the bin which doen't contain any write seseCommon->rentryArray[seseCommon->rentryIdx++]=r; @@ -940,9 +938,8 @@ resolvePointer(REntry* rentry){ break; } removeItem(val,head); - //now, address is resolved. update OID field. - struct ___Object___ * obj=(struct ___Object___*)((unsigned INTPTR)*rentry->pointer); - rentry->oid=obj->oid; + + //now, address is resolved //check if rentry is buffer mode if(rentry->isBufMode==TRUE){ @@ -981,7 +978,7 @@ resolvePointer(REntry* rentry){ } } -void rehashMemoryQueue(SESEcommon_p seseParent){ +void rehashMemoryQueue(SESEcommon* seseParent){ #if 0 // update memory queue int i,binidx; diff --git a/Robust/src/Runtime/mlp_runtime.h b/Robust/src/Runtime/mlp_runtime.h index a14cf7dc..f7ec85b2 100644 --- a/Robust/src/Runtime/mlp_runtime.h +++ b/Robust/src/Runtime/mlp_runtime.h @@ -6,6 +6,7 @@ #include "Queue.h" #include "psemaphore.h" #include "mlp_lock.h" +#include "memPool.h" #ifndef FALSE #define FALSE 0 @@ -48,6 +49,11 @@ #define TRUE 1 #endif + +#define OBJPTRPTR_2_OBJTYPE( opp ) ((int*)(*(opp)))[0] +#define OBJPTRPTR_2_OBJOID( opp ) ((int*)(*(opp)))[1] + + typedef struct REntry_t{ int type; // fine read:0, fine write:1, parent read:2, parent write:3 coarse: 4, parent coarse:5, scc: 6 struct Hashtable_t* hashtable; @@ -58,7 +64,6 @@ typedef struct REntry_t{ psemaphore parentStallSem; void* seseRec; INTPTR* pointer; - int oid; int isBufMode; } REntry; @@ -121,8 +126,6 @@ int ADDRENTRY(MemoryQueue* q, REntry * r); void RETIRERENTRY(MemoryQueue* Q, REntry * r); -// forward declaration of pointer type -typedef struct SESEcommon_t* SESEcommon_p; // these fields are common to any SESE, and casting the // generated SESE record to this can be used, because @@ -132,6 +135,8 @@ typedef struct SESEcommon_t { // the identifier for the class of sese's that // are instances of one particular static code block + // IMPORTANT: the class ID must be the first field of + // the task record so task dispatch works correctly! int classID; // a parent waits on this semaphore when stalling on @@ -144,7 +149,7 @@ typedef struct SESEcommon_t { pthread_mutex_t lock; struct Queue* forwardList; - volatile int unresolvedDependencies; + volatile int unresolvedDependencies; pthread_cond_t doneCond; int doneExecuting; @@ -152,7 +157,7 @@ typedef struct SESEcommon_t { pthread_cond_t runningChildrenCond; int numRunningChildren; - SESEcommon_p parent; + struct SESEcommon_t* parent; psemaphore parentStallSem; pthread_cond_t stallDone; @@ -167,16 +172,17 @@ typedef struct SESEcommon_t { int numDependentSESErecords; int offsetToDepSESErecords; + // for determining when task records can be returned + // to the parent record's memory pool + MemPool* taskRecordMemPool; + volatile int refCount; + } SESEcommon; -// a thread-local stack of SESEs and function to -// ensure it is initialized once per thread -/* -extern __thread struct Queue* seseCallStack; -extern __thread pthread_once_t mlpOnceObj; -void mlpInitOncePerThread(); -*/ -extern __thread SESEcommon_p seseCaller; + +// a thread-local var refers to the currently +// running task +extern __thread SESEcommon* runningSESE; // simple mechanical allocation and @@ -189,6 +195,6 @@ MemoryQueue** mlpCreateMemoryQueueArray(int numMemoryQueue); REntry* mlpCreateFineREntry(int type, void* seseToIssue, void* dynID); REntry* mlpCreateREntry(int type, void* seseToIssue); MemoryQueue* createMemoryQueue(); -void rehashMemoryQueue(SESEcommon_p seseParent); +void rehashMemoryQueue(SESEcommon* seseParent); #endif /* __MLP_RUNTIME__ */ diff --git a/Robust/src/Runtime/workschedule.c b/Robust/src/Runtime/workschedule.c index 723ab190..0d9aea03 100644 --- a/Robust/src/Runtime/workschedule.c +++ b/Robust/src/Runtime/workschedule.c @@ -70,7 +70,9 @@ void* workerMain( void* arg ) { //pthread_cleanup_push( workerExit, NULL ); - oid = myData->id; + // ensure that object ID's start at 1 so that using + // oid with value 0 indicates an invalid object + oid = myData->id + 1; //pthread_setcanceltype ( PTHREAD_CANCEL_ASYNCHRONOUS, &oldState ); //pthread_setcancelstate( PTHREAD_CANCEL_ENABLE, &oldState ); diff --git a/Robust/src/Tests/oooJava/poolalloc/test.java b/Robust/src/Tests/oooJava/poolalloc/test.java index 390657ec..7e0430cb 100644 --- a/Robust/src/Tests/oooJava/poolalloc/test.java +++ b/Robust/src/Tests/oooJava/poolalloc/test.java @@ -7,9 +7,10 @@ public class Test { static public void main( String args[] ) { - int x = 12345; + int x = 1000000; for( int i = 0; i < 200000; ++i ) { + //for( int i = 0; i < 98; ++i ) { rblock a { Foo f = new Foo(); f.z = 0; @@ -18,11 +19,14 @@ public class Test { rblock b { --f.z; } - int y = -1; + int y = -1000; if( i % 2 == 0 ) { - rblock c { - y = 1; - } + //rblock c { + y = 1000; + //} + } + if( f.z > 0 ) { + System.out.println( "WHOA WHOA WHOA" ); } x += f.z + y; } -- 2.34.1