From c72cb280c8e2ba1874c8de46690dd542f6ed529e Mon Sep 17 00:00:00 2001 From: bdemsky Date: Mon, 26 Feb 2007 22:36:00 +0000 Subject: [PATCH] lots of bugs...garbage collection/checkpointing/etc --- .../src/Benchmarks/WebServer/Inventory.java | 49 +++++++++-------- .../WebServer/WebServerExample.java | 3 +- .../WebServer/Workload/batch/run2.sh | 2 +- Robust/src/Runtime/checkpoint.c | 24 +++++++-- Robust/src/Runtime/garbage.c | 18 +++++-- Robust/src/Runtime/runtime.c | 54 ++++++++++++------- 6 files changed, 99 insertions(+), 51 deletions(-) diff --git a/Robust/src/Benchmarks/WebServer/Inventory.java b/Robust/src/Benchmarks/WebServer/Inventory.java index 6964a18e..74756956 100644 --- a/Robust/src/Benchmarks/WebServer/Inventory.java +++ b/Robust/src/Benchmarks/WebServer/Inventory.java @@ -61,28 +61,31 @@ public class Inventory { } //Display the inventory list - public String inventory(){ - HashMapIterator i = new HashMapIterator(map, 0);// Gets key from the hashmap= name of item - HashMapIterator j = new HashMapIterator(map, 1);//Gets the value from hashmap - StringBuffer sb = new StringBuffer(""); + //Display the inventory list + public synchronized void inventory(Socket s){ + HashMapIterator i = new HashMapIterator(map, 0);// Gets key from the hashmap= name of item + HashMapIterator j = new HashMapIterator(map, 1);//Gets the value from hashmap int totalvalue=balance; - while (i.hasNext() == true) { - Object o = i.next(); - String name = o.toString(); - ItemInfo oo = (ItemInfo) j.next(); - sb.append(name); - sb.append(" "); - Integer q = new Integer(oo.quantity); - sb.append(q.toString()); - sb.append(" "); - Integer p = new Integer(oo.price); - sb.append(p.toString()); - sb.append("\n"); - totalvalue+=oo.quantity*oo.price; - } - sb.append("Total value: "); - sb.append((new Integer(totalvalue)).toString()); - sb.append("\n"); - return sb.toString(); - } + while (i.hasNext() == true) { + StringBuffer sb = new StringBuffer(""); + Object o = i.next(); + String name = o.toString(); + ItemInfo oo = (ItemInfo) j.next(); + sb.append(name); + sb.append(" "); + Integer q = new Integer(oo.quantity); + sb.append(q.toString()); + sb.append(" "); + Integer p = new Integer(oo.price); + sb.append(p.toString()); + sb.append("\n"); + totalvalue+=oo.quantity*oo.price; + s.write(sb.toString().getBytes()); + } + StringBuffer sb=new StringBuffer(""); + sb.append("Total value: "); + sb.append((new Integer(totalvalue)).toString()); + sb.append("\n"); + s.write(sb.toString().getBytes()); + } } diff --git a/Robust/src/Benchmarks/WebServer/WebServerExample.java b/Robust/src/Benchmarks/WebServer/WebServerExample.java index e4ace258..664465a5 100644 --- a/Robust/src/Benchmarks/WebServer/WebServerExample.java +++ b/Robust/src/Benchmarks/WebServer/WebServerExample.java @@ -101,8 +101,7 @@ task Transaction(WebServerSocket web{TransPending}, Inventory inventorylist{Tran } else if (op == 2) { /* Inventory */ // System.printString("DEBUG > Calling inventory transaction\n"); web.httpresponse(); - String towrite = inventorylist.inventory(); - web.write(towrite.getBytes()); + inventorylist.inventory(web); } else { /* Error */ // System.printString("T > Error - Unknown transaction\n"); } diff --git a/Robust/src/Benchmarks/WebServer/Workload/batch/run2.sh b/Robust/src/Benchmarks/WebServer/Workload/batch/run2.sh index c96b19a1..672780b0 100755 --- a/Robust/src/Benchmarks/WebServer/Workload/batch/run2.sh +++ b/Robust/src/Benchmarks/WebServer/Workload/batch/run2.sh @@ -7,7 +7,7 @@ rm output #Errors and total number of run count are redirected to this file #Sets the BRISTLECONE parameter with a certain instruction count, probability and #number of failures that can be injected #export BRISTLECONE="-initializerandom -injectinstructionfailures 10 0.00001667 1 -debugtask" -export BRISTLECONE="-initializerandom -injectinstructionfailures 35 0.00001667 50 -debugtask" +export BRISTLECONE="-initializerandom -injectinstructionfailures 35 0.00001667 50" rm -rf results mkdir results cd results diff --git a/Robust/src/Runtime/checkpoint.c b/Robust/src/Runtime/checkpoint.c index df66337d..d7556a72 100644 --- a/Robust/src/Runtime/checkpoint.c +++ b/Robust/src/Runtime/checkpoint.c @@ -154,16 +154,21 @@ void * createcopy(void * orig) { void restorecheckpoint(int numparams, void ** original, void ** checkpoint, struct RuntimeHash *forward, struct RuntimeHash * reverse) { struct RuntimeHash *todo=allocateRuntimeHash(100); + struct RuntimeHash *visited=allocateRuntimeHash(100); int i; for(i=0;i___length___)+sizeof(int)))[i]; if (objptr==NULL) ((void **)(((char *)& ao_cpy->___length___)+sizeof(int)))[i]=NULL; - else + else { + if (!RuntimeHashcontainskey(visited, (int) objptr)) { + RuntimeHashadd(visited, (int) objptr, (int) objptr); + RuntimeHashadd(todo, (int) objptr, (int) objptr); + } RuntimeHashget(reverse, (int) objptr, (int *) &((void **)(((char *)& ao_cpy->___length___)+sizeof(int)))[i]); + } } } else { int numptr=pointer[0]; @@ -208,8 +218,13 @@ void restorecheckpoint(int numparams, void ** original, void ** checkpoint, stru void * objptr=*((void **)(((int)ptr)+offset)); if (objptr==NULL) *((void **) (((int)cpy)+offset))=NULL; - else + else { + if (!RuntimeHashcontainskey(visited, (int) objptr)) { + RuntimeHashadd(visited, (int) objptr, (int) objptr); + RuntimeHashadd(todo, (int) objptr, (int) objptr); + } RuntimeHashget(reverse, (int) objptr, (int *) &(((char *)cpy)[offset])); + } } if (hasflags[type]) { (((void **)cpy)[2])=flagptr; @@ -219,4 +234,5 @@ void restorecheckpoint(int numparams, void ** original, void ** checkpoint, stru } } freeRuntimeHash(todo); + freeRuntimeHash(visited); } diff --git a/Robust/src/Runtime/garbage.c b/Robust/src/Runtime/garbage.c index 405cb872..69f32a6a 100644 --- a/Robust/src/Runtime/garbage.c +++ b/Robust/src/Runtime/garbage.c @@ -24,6 +24,7 @@ extern struct Queue * activetasks; extern struct parameterwrapper * objectqueues[NUMCLASSES]; extern struct genhashtable * failedtasks; +extern struct taskparamdescriptor *currtpd; extern struct RuntimeHash *forward; extern struct RuntimeHash *reverse; extern struct RuntimeHash *fdtoobject; @@ -194,6 +195,18 @@ void collect(struct garbagelist * stackptr) { } } + { + /* Update current task descriptor */ + int i; + for(i=0;inumParameters;i++) { + void *orig=currtpd->parameterArray[i]; + void *copy; + if (gc_createcopy(orig, ©)) + enqueue(orig); + currtpd->parameterArray[i]=copy; + } + + } { /* Update active tasks */ @@ -216,11 +229,10 @@ void collect(struct garbagelist * stackptr) { struct genpointerlist * ptr=failedtasks->list; while(ptr!=NULL) { struct taskparamdescriptor *tpd=ptr->src; - void *orig; - void *copy; int i; for(i=0;inumParameters;i++) { - orig=tpd->parameterArray[i]; + void * orig=tpd->parameterArray[i]; + void * copy; if (gc_createcopy(orig, ©)) enqueue(orig); tpd->parameterArray[i]=copy; diff --git a/Robust/src/Runtime/runtime.c b/Robust/src/Runtime/runtime.c index 1d5d35e1..3f717db1 100644 --- a/Robust/src/Runtime/runtime.c +++ b/Robust/src/Runtime/runtime.c @@ -41,6 +41,7 @@ int instaccum=0; struct Queue * activetasks; struct parameterwrapper * objectqueues[NUMCLASSES]; struct genhashtable * failedtasks; +struct taskparamdescriptor * currtpd; struct RuntimeHash * forward; struct RuntimeHash * reverse; @@ -120,10 +121,12 @@ int comparetpd(struct taskparamdescriptor *ftd1, struct taskparamdescriptor *ftd with the or mask and and's it with the andmask. */ void flagorand(void * ptr, int ormask, int andmask) { - int flag=((int *)ptr)[1]; + int oldflag=((int *)ptr)[1]; struct RuntimeHash *flagptr=(struct RuntimeHash *)(((int*)ptr)[2]); - flag|=ormask; + int flag=ormask|oldflag; flag&=andmask; + if (flag==oldflag) /* Don't do anything */ + return; ((int*)ptr)[1]=flag; /*Remove object from all queues */ @@ -182,7 +185,11 @@ void flagorand(void * ptr, int ormask, int andmask) { /* Queue task */ if (!gencontains(failedtasks, tpd)) addNewItem(activetasks, tpd); - + else { + RUNFREE(tpd->parameterArray); + RUNFREE(tpd); + } + /* This loop iterates to the next parameter combination */ for(j=0;jobjectptr; + currtpd=(struct taskparamdescriptor *) qi->objectptr; removeItem(activetasks, qi); /* Check if this task has failed */ - if (gencontains(failedtasks, tpd)) + if (gencontains(failedtasks, currtpd)) { + // Free up task parameter descriptor + RUNFREE(currtpd->parameterArray); + RUNFREE(currtpd); goto newtask; + } /* Make sure that the parameters are still in the queues */ - for(i=0;itask->numParameters;i++) { - void * parameter=tpd->parameterArray[i]; - struct parameterdescriptor * pd=tpd->task->descriptorarray[i]; + for(i=0;itask->numParameters;i++) { + void * parameter=currtpd->parameterArray[i]; + struct parameterdescriptor * pd=currtpd->task->descriptorarray[i]; struct parameterwrapper *pw=(struct parameterwrapper *) pd->queue; - if (!RuntimeHashcontainskey(pw->objectset, (int) parameter)) + if (!RuntimeHashcontainskey(pw->objectset, (int) parameter)) { + RUNFREE(currtpd->parameterArray); + RUNFREE(currtpd); goto newtask; + } taskpointerarray[i+OFFSET]=parameter; } { /* Checkpoint the state */ forward=allocateRuntimeHash(100); reverse=allocateRuntimeHash(100); - void ** checkpoint=makecheckpoint(tpd->task->numParameters, &taskpointerarray[OFFSET], forward, reverse); + void ** checkpoint=makecheckpoint(currtpd->task->numParameters, currtpd->parameterArray, forward, reverse); int x; if (x=setjmp(error_handler)) { /* Recover */ @@ -328,8 +343,8 @@ void executetasks() { #ifdef DEBUG printf("Fatal Error=%d, Recovering!\n",x); #endif - genputtable(failedtasks,tpd,tpd); - restorecheckpoint(tpd->task->numParameters, &taskpointerarray[OFFSET], checkpoint, forward, reverse); + genputtable(failedtasks,currtpd,currtpd); + restorecheckpoint(currtpd->task->numParameters, currtpd->parameterArray, checkpoint, forward, reverse); freeRuntimeHash(forward); freeRuntimeHash(reverse); freemalloc(); @@ -338,25 +353,28 @@ void executetasks() { } else { if (injectfailures) { if ((((double)random())/RAND_MAX)task->name); + printf("\nINJECTING TASK FAILURE to %s\n", currtpd->task->name); longjmp(error_handler,10); } } /* Actually call task */ #ifdef PRECISE_GC - ((int *)taskpointerarray)[0]=tpd->task->numParameters; + ((int *)taskpointerarray)[0]=currtpd->task->numParameters; taskpointerarray[1]=NULL; #endif if (debugtask) { - printf("ENTER %s count=%d\n",tpd->task->name, (instaccum-instructioncount)); - ((void (*) (void **)) tpd->task->taskptr)(taskpointerarray); - printf("EXIT %s count=%d\n",tpd->task->name, (instaccum-instructioncount)); + printf("ENTER %s count=%d\n",currtpd->task->name, (instaccum-instructioncount)); + ((void (*) (void **)) currtpd->task->taskptr)(taskpointerarray); + printf("EXIT %s count=%d\n",currtpd->task->name, (instaccum-instructioncount)); } else - ((void (*) (void **)) tpd->task->taskptr)(taskpointerarray); + ((void (*) (void **)) currtpd->task->taskptr)(taskpointerarray); freeRuntimeHash(forward); freeRuntimeHash(reverse); freemalloc(); + // Free up task parameter descriptor + RUNFREE(currtpd->parameterArray); + RUNFREE(currtpd); forward=NULL; reverse=NULL; } -- 2.34.1