From 54247994d668aca96780c573a067b607af0fc069 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Tue, 29 Aug 2006 09:09:08 +0000 Subject: [PATCH] checking in working system --- Robust/src/ClassLibrary/String.java | 9 +- Robust/src/Runtime/GenericHashtable.c | 8 +- Robust/src/Runtime/Queue.c | 4 +- Robust/src/Runtime/Queue.h | 1 - Robust/src/Runtime/checkpoint.c | 1 + Robust/src/Runtime/runtime.c | 133 +++++++++++++++++--------- Robust/src/Runtime/runtime.h | 11 ++- Robust/src/Tests/TaskExample.java | 2 +- Robust/src/buildscripttask | 2 +- 9 files changed, 112 insertions(+), 59 deletions(-) diff --git a/Robust/src/ClassLibrary/String.java b/Robust/src/ClassLibrary/String.java index 6752c7ec..af399d99 100644 --- a/Robust/src/ClassLibrary/String.java +++ b/Robust/src/ClassLibrary/String.java @@ -26,11 +26,16 @@ public class String { chararray=new char[length+1]; else chararray=new char[length]; + int offset; if (x<0) { chararray[0]='-'; - } + offset=1; + x=-x; + } else + offset=0; + do { - chararray[--length]=(char)(x%10+'0'); + chararray[--length+offset]=(char)(x%10+'0'); x=x/10; } while (length!=0); return new String(chararray); diff --git a/Robust/src/Runtime/GenericHashtable.c b/Robust/src/Runtime/GenericHashtable.c index 8c24e05d..86f40e58 100755 --- a/Robust/src/Runtime/GenericHashtable.c +++ b/Robust/src/Runtime/GenericHashtable.c @@ -3,11 +3,13 @@ #include #include #include -#include +#include + #include "GenericHashtable.h" #include "mem.h" //#include "dmalloc.h" + int genputtable(struct genhashtable *ht, void * key, void * object) { unsigned int bin=genhashfunction(ht,key); struct genpointerlist * newptrlist=(struct genpointerlist *) RUNMALLOC(sizeof(struct genpointerlist)); @@ -27,9 +29,9 @@ int genputtable(struct genhashtable *ht, void * key, void * object) { } ht->bins[bin]=newptrlist; ht->counter++; - if(ht->counter>ht->currentsize&&ht->currentsize!=MAXINT) { + if(ht->counter>ht->currentsize&&ht->currentsize!=INT_MAX) { /* Expand hashtable */ - long newcurrentsize=(ht->currentsize<(MAXINT/2))?ht->currentsize*2:MAXINT; + long newcurrentsize=(ht->currentsize<(INT_MAX/2))?ht->currentsize*2:INT_MAX; long oldcurrentsize=ht->currentsize; struct genpointerlist **newbins=(struct genpointerlist **) RUNMALLOC(sizeof (struct genpointerlist *)*newcurrentsize); struct genpointerlist **oldbins=ht->bins; diff --git a/Robust/src/Runtime/Queue.c b/Robust/src/Runtime/Queue.c index bc8643e2..51c9a1da 100644 --- a/Robust/src/Runtime/Queue.c +++ b/Robust/src/Runtime/Queue.c @@ -42,4 +42,6 @@ struct QueueItem * getTail(struct Queue * queue) { return queue->tail; } - +struct QueueItem * getNext(struct QueueItem * qi) { + return qi->next; +} diff --git a/Robust/src/Runtime/Queue.h b/Robust/src/Runtime/Queue.h index d19d2cb7..6e9f63dc 100644 --- a/Robust/src/Runtime/Queue.h +++ b/Robust/src/Runtime/Queue.h @@ -11,7 +11,6 @@ struct QueueItem { struct Queue * queue; struct QueueItem * next; struct QueueItem * prev; - struct QueueItem * nextqueue; }; struct Queue * createQueue(); diff --git a/Robust/src/Runtime/checkpoint.c b/Robust/src/Runtime/checkpoint.c index 86c885ce..353c5b66 100644 --- a/Robust/src/Runtime/checkpoint.c +++ b/Robust/src/Runtime/checkpoint.c @@ -66,6 +66,7 @@ void ** makecheckpoint(int numparams, void ** srcpointer, struct SimpleHash * fo } } } + return newarray; } void * createcopy(void * orig) { diff --git a/Robust/src/Runtime/runtime.c b/Robust/src/Runtime/runtime.c index 4d62b52a..a48abf6c 100644 --- a/Robust/src/Runtime/runtime.c +++ b/Robust/src/Runtime/runtime.c @@ -17,19 +17,21 @@ jmp_buf error_handler; #include "checkpoint.h" #include "Queue.h" #include "SimpleHash.h" -#include "task.h" #include "GenericHashtable.h" -struct SimpleHash * activetasks; +struct Queue * activetasks; struct parameterwrapper * objectqueues[NUMCLASSES]; +struct genhashtable * failedtasks; int main(int argc, char **argv) { int i; /* Allocate startup object */ struct ___StartupObject___ *startupobject=(struct ___StartupObject___*) allocate_new(STARTUPTYPE); struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc); - - activetasks=allocateSimpleHash(50); + failedtasks=genallocatehashtable((unsigned int (*)(void *)) &hashCodetpd, + (int (*)(void *,void *)) &comparetpd); + + activetasks=createQueue(); /* Set flags */ processtasks(); @@ -47,16 +49,16 @@ int main(int argc, char **argv) { executetasks(); } -int hashCodeftd(struct failedtaskdescriptor *ftd) { - int hash=ftd->task; +int hashCodetpd(struct taskparamdescriptor *ftd) { + int hash=(int)ftd->task; int i; for(i=0;inumParameters;i++) { - hash^=(int)parameterArray[i]; + hash^=(int)ftd->parameterArray[i]; } return hash; } -int compareftd(struct failedtaskdescriptor *ftd1, failedtaskdescriptor *ftd2) { +int comparetpd(struct taskparamdescriptor *ftd1, struct taskparamdescriptor *ftd2) { int i; if (ftd1->task!=ftd2->task) return 0; @@ -68,14 +70,15 @@ int compareftd(struct failedtaskdescriptor *ftd1, failedtaskdescriptor *ftd2) { void flagorand(void * ptr, int ormask, int andmask) { int flag=((int *)ptr)[1]; - struct QueueItem *flagptr=(struct QueueItem *)(((int*)ptr)[2]); + struct SimpleHash *flagptr=(struct SimpleHash *)(((int*)ptr)[2]); flag|=ormask; flag&=andmask; ((int*)ptr)[1]=flag; /*Remove from all queues */ while(flagptr!=NULL) { - struct QueueItem * next=flagptr->nextqueue; - removeItem(flagptr->queue, flagptr); + struct SimpleHash *next; + SimpleHashget(flagptr, (int) ptr, (int *) &next); + SimpleHashremove(flagptr, (int)ptr, (int) next); flagptr=next; } @@ -83,27 +86,73 @@ void flagorand(void * ptr, int ormask, int andmask) { struct QueueItem *tmpptr; struct parameterwrapper * parameter=objectqueues[((int *)ptr)[0]]; int i; - flagptr=NULL; + struct SimpleHash * prevptr=NULL; while(parameter!=NULL) { for(i=0;inumberofterms;i++) { int andmask=parameter->intarray[i*2]; int checkmask=parameter->intarray[i*2+1]; if ((flag&andmask)==checkmask) { - struct QueueItem * qitem=addNewItem(parameter->queue, ptr); - if (flagptr==NULL) { - flagptr=qitem; - tmpptr=flagptr; - } else { - tmpptr->nextqueue=qitem; - tmpptr=qitem; + SimpleHashadd(parameter->objectset, (int) ptr, (int) prevptr); + prevptr=parameter->objectset; + { + struct SimpleIterator iteratorarray[MAXTASKPARAMS]; + void * taskpointerarray[MAXTASKPARAMS]; + int j; + int numparams=parameter->task->numParameters; + int done=1; + struct taskdescriptor * task=parameter->task; + int newindex=-1; + for(j=0;jdescriptorarray[j]->queue; + if (parameter==pw) { + taskpointerarray[j]=ptr; + newindex=j; + } else { + SimpleHashiterator(pw->objectset, &iteratorarray[j]); + if (hasNext(&iteratorarray[j])) + taskpointerarray[j]=(void *) next(&iteratorarray[j]); + else + break; /* No tasks to dispatch */ + } + } + /* Queue task items... */ + + while(done) { + struct taskparamdescriptor *tpd=RUNMALLOC(sizeof(struct taskparamdescriptor)); + tpd->task=task; + tpd->numParameters=numparams; + tpd->parameterArray=RUNMALLOC(sizeof(void *)*numparams); + for(j=0;jparameterArray[j]=taskpointerarray[j]; + /* Queue task */ + if (!gencontains(failedtasks, tpd)) + addNewItem(activetasks, tpd); + + /* This loop iterates to the next paramter combination */ + for(j=0;jdescriptorarray[j]->queue, &iteratorarray[j]); + } else { + done=0; + break; + } + } + } } - SimpleHashadd(activetasks, (int)parameter->task, (int)parameter->task); break; } } parameter=parameter->next; } - ((struct QueueItem **)ptr)[2]=flagptr; + ((struct SimpleHash **)ptr)[2]=prevptr; } } @@ -115,8 +164,7 @@ void myhandler(int sig, struct __siginfo *info, void *uap) { } void executetasks() { - void * pointerarray[MAXTASKPARAMS]; - struct genhashtable * failedtasks=genallocatehashtable(&hashCodeftd, &compareftd); + void * taskpointerarray[MAXTASKPARAMS]; /* Set up signal handlers */ struct sigaction sig; @@ -133,38 +181,33 @@ void executetasks() { mmap(0, 0x1000, 0, MAP_SHARED|MAP_FIXED|MAP_ANON, -1, 0); newtask: - while(SimpleHashcountset(activetasks)!=0) { - struct taskdescriptor * task=(struct taskdescriptor *) SimpleHashfirstkey(activetasks); + while(!isEmpty(activetasks)) { + struct QueueItem * qi=(struct QueueItem *) getTail(activetasks); + struct taskparamdescriptor *tpd=(struct taskparamdescriptor *) qi->objectptr; int i; - for(i=0;inumParameters;i++) { - struct parameterwrapper * parameter=(struct parameterwrapper *) task->descriptorarray[i]->queue; - struct Queue * queue=parameter->queue; - if (isEmpty(queue)) { - SimpleHashremove(activetasks, (int)task, (int)task); + removeItem(activetasks, qi); + + for(i=0;itask->numParameters;i++) { + void * parameter=tpd->parameterArray[i]; + struct parameterdescriptor * pd=tpd->task->descriptorarray[i]; + struct parameterwrapper *pw=(struct parameterwrapper *) pd->queue; + if (!SimpleHashcontainskey(pw->objectset, (int) parameter)) goto newtask; - } - pointerarray[i]=getTail(queue)->objectptr; + taskpointerarray[i]=parameter; } { struct SimpleHash * forward=allocateSimpleHash(100); struct SimpleHash * reverse=allocateSimpleHash(100); - void ** checkpoint=makecheckpoint(task->numParameters, pointerarray, forward, reverse); + void ** checkpoint=makecheckpoint(tpd->task->numParameters, taskpointerarray, forward, reverse); if (setjmp(error_handler)) { /* Recover */ - struct failedtaskdescriptor *ftd=RUNMALLOC(sizeof(struct failedtaskdescriptor)); int h; - ftd->task=task; - ftd->numParameters=task->numParameters; - ftd->parameterArray=RUNMALLOC(task->numParameters*sizeof(void *)); - for(j=0;jnumParameters;j++) { - ftd->parameterArray[j]=pointerarray[j]; - } - genputtable(failedtasks,ftd,ftd); - restorecheckpoint(task->numParameters, pointerarray, checkpoint, forward, reverse); - /* TODO: REMOVE TASK FROM QUEUE */ + printf("Recovering\n"); + genputtable(failedtasks,tpd,tpd); + restorecheckpoint(tpd->task->numParameters, taskpointerarray, checkpoint, forward, reverse); } else { /* Actually call task */ - ((void (*) (void **)) task->taskptr)(pointerarray); + ((void (*) (void **)) tpd->task->taskptr)(taskpointerarray); } } } @@ -182,7 +225,7 @@ void processtasks() { struct parameterwrapper ** ptr=&objectqueues[param->type]; param->queue=parameter; - parameter->queue=createQueue(); + parameter->objectset=allocateSimpleHash(10); parameter->numberofterms=param->numberterms; parameter->intarray=param->intarray; parameter->task=task; diff --git a/Robust/src/Runtime/runtime.h b/Robust/src/Runtime/runtime.h index a82ca495..6236c46b 100644 --- a/Robust/src/Runtime/runtime.h +++ b/Robust/src/Runtime/runtime.h @@ -11,27 +11,28 @@ void failedboundschk(); void failednullptr(); #ifdef TASK -#include "Queue.h" +#include "SimpleHash.h" +#include "task.h" void flagorand(void * ptr, int ormask, int andmask); void executetasks(); void processtasks(); struct parameterwrapper { struct parameterwrapper *next; - struct Queue * queue; + struct SimpleHash * objectset; int numberofterms; int * intarray; struct taskdescriptor * task; }; -struct failedtaskdescriptor { +struct taskparamdescriptor { struct taskdescriptor * task; int numParameters; void ** parameterArray; }; -int hashCodeftd(struct failedtaskdescriptor *); -int compareftd(struct failedtaskdescriptor *, failedtaskdescriptor *); +int hashCodetpd(struct taskparamdescriptor *); +int comparetpd(struct taskparamdescriptor *, struct taskparamdescriptor *); #endif #endif diff --git a/Robust/src/Tests/TaskExample.java b/Robust/src/Tests/TaskExample.java index d271abe8..27ff89c4 100644 --- a/Robust/src/Tests/TaskExample.java +++ b/Robust/src/Tests/TaskExample.java @@ -16,7 +16,7 @@ class Example { task Startup(StartupObject s {initialstate}) { for(int i=0;i<10;i++) { Example e=new Example() {needoperation}; - e.x=i+2; + e.x=i; e.y=2; e.operation=i%2; } diff --git a/Robust/src/buildscripttask b/Robust/src/buildscripttask index fdf88dd3..d7f8f009 100755 --- a/Robust/src/buildscripttask +++ b/Robust/src/buildscripttask @@ -4,4 +4,4 @@ MAINFILE=$1 shift mkdir tmpbuilddirectory java -cp $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary $ROBUSTROOT/ClassLibrary/ -dir tmpbuilddirectory -task $@ -gcc -I$ROBUSTROOT/Runtime -Itmpbuilddirectory -O0 -DTASK -g tmpbuilddirectory/methods.c tmpbuilddirectory/taskdefs.c $ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/Queue.c $ROBUSTROOT/Runtime/SimpleHash.c $ROBUSTROOT/Runtime/checkpoint.c -o $MAINFILE.bin \ No newline at end of file +gcc -I$ROBUSTROOT/Runtime -Itmpbuilddirectory -O0 -DTASK -g tmpbuilddirectory/methods.c tmpbuilddirectory/taskdefs.c $ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/Queue.c $ROBUSTROOT/Runtime/SimpleHash.c $ROBUSTROOT/Runtime/checkpoint.c $ROBUSTROOT/Runtime/GenericHashtable.c -o $MAINFILE.bin \ No newline at end of file -- 2.34.1