From: bdemsky Date: Thu, 2 Nov 2006 07:51:47 +0000 (+0000) Subject: move socket code out of runtime.c X-Git-Tag: preEdgeChange~780 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=a8a8d788b8f23132d3d88317b36049e9ade7a163;p=IRC.git move socket code out of runtime.c add more error injection options --- diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index c3b05d5c..7a123a21 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -867,6 +867,9 @@ public class BuildCode { visited.add(current_node); if (nodetolabel.containsKey(current_node)) output.println("L"+nodetolabel.get(current_node)+":"); + if (state.INSTRUCTIONFAILURE) { + output.println("if ((--instructioncount)==0) injectinstructionfailure();"); + } if (current_node.numNext()==0) { output.print(" "); generateFlatNode(fm, current_node, output); diff --git a/Robust/src/IR/State.java b/Robust/src/IR/State.java index a40ed70d..b4326130 100644 --- a/Robust/src/IR/State.java +++ b/Robust/src/IR/State.java @@ -22,6 +22,7 @@ public class State { /** Boolean flag which indicates whether compiler is compiling a task-based * program. */ public boolean TASK; + public boolean INSTRUCTIONFAILURE=false; public String structfile; public String main; public boolean CONSCHECK=false; diff --git a/Robust/src/Main/Main.java b/Robust/src/Main/Main.java index 75487a3f..8e7f8850 100644 --- a/Robust/src/Main/Main.java +++ b/Robust/src/Main/Main.java @@ -33,6 +33,8 @@ public class Main { state.CONSCHECK=true; else if (option.equals("-task")) state.TASK=true; + else if (option.equals("-instructionfailures")) + state.INSTRUCTIONFAILURE=true; else if (option.equals("-help")) { System.out.println("-classlibrary classlibrarydirectory -- directory where classlibrary is located"); System.out.println("-dir outputdirectory -- output code in outputdirectory"); @@ -41,6 +43,8 @@ public class Main { System.out.println("-precise -- use precise garbage collection"); System.out.println("-conscheck -- turn on consistency checking"); + System.out.println("-task -- compiler for tasks"); + System.out.println("-instructionfailures -- insert code for instruction level failures"); System.out.println("-help -- print out help"); System.exit(0); } else { diff --git a/Robust/src/Runtime/runtime.c b/Robust/src/Runtime/runtime.c index 86d4e071..1ad9651b 100644 --- a/Robust/src/Runtime/runtime.c +++ b/Robust/src/Runtime/runtime.c @@ -12,6 +12,7 @@ extern int classsize[]; jmp_buf error_handler; +int instructioncount; #ifdef TASK #include "checkpoint.h" @@ -19,9 +20,6 @@ jmp_buf error_handler; #include "SimpleHash.h" #include "GenericHashtable.h" #include -#include -#include -#include #ifdef CONSCHECK #include "instrument.h" @@ -30,48 +28,71 @@ jmp_buf error_handler; struct Queue * activetasks; struct parameterwrapper * objectqueues[NUMCLASSES]; struct genhashtable * failedtasks; +/*struct genhashtable * failedobjects;*/ extern char ** environ; char *options; int injectfailures=0; float failurechance=0; int debugtask=0; +int injectinstructionfailures; +int failurecount; +float instfailurechance=0; -int main(int argc, char **argv) { - GC_init(); -#ifdef CONSCHECK - initializemmap(); -#endif - { - int i; - options=NULL; - for(i=0;environ[i]!=0;i++) { - if (strncmp(environ[i],"BRISTLECONE=",12)==0) { - options=environ[i]+12; - break; - } +void processOptions() { + int i; + options=NULL; + for(i=0;environ[i]!=0;i++) { + if (strncmp(environ[i],"BRISTLECONE=",12)==0) { + options=environ[i]+12; + break; } - - while(options!=NULL) { - if (strncmp(options,"-injectfailures",sizeof("-injectfailures")-1)==0) { - options=strchr(options,' '); - if (options!=NULL) options++; - if (options==NULL) - break; - sscanf(options, "%f", &failurechance); - injectfailures=1; - printf("Injecting errors with chance=%f\n",failurechance); - options=strchr(options,' '); - if (options!=NULL) options++; - } else if (strncmp(options, "-debugtask",sizeof("-debugtask")-1)==0) { - options=strchr(options,' '); - if (options!=NULL) options++; - debugtask=1; - printf("Debug task option on\n"); - } else + } + + while(options!=NULL) { + if (strncmp(options,"-injectfailures",sizeof("-injectfailures")-1)==0) { + options=strchr(options,' '); + if (options!=NULL) options++; + if (options==NULL) break; - } + sscanf(options, "%f", &failurechance); + injectfailures=1; + printf("Injecting errors with chance=%f\n",failurechance); + options=strchr(options,' '); + if (options!=NULL) options++; + } else if (strncmp(options,"-injectinstructionfailures",sizeof("-injectinstructionfailures")-1)==0) { + options=strchr(options,' '); + if (options!=NULL) options++; + if (options==NULL) + break; + sscanf(options, "%d", &failurecount); + options=strchr(options,' '); + if (options!=NULL) options++; + if (options==NULL) + break; + sscanf(options, "%f", &instfailurechance); + options=strchr(options,' '); + if (options!=NULL) options++; + instructioncount=failurecount; + injectinstructionfailures=1; + printf("Injecting errors with count=%d\n",failurecount); + printf("Injecting errors with chance=%f\n",instfailurechance); + + } else if (strncmp(options, "-debugtask",sizeof("-debugtask")-1)==0) { + options=strchr(options,' '); + if (options!=NULL) options++; + debugtask=1; + printf("Debug task option on.\n"); + } else + break; } +} +int main(int argc, char **argv) { + GC_init(); // Initialize the garbage collector +#ifdef CONSCHECK + initializemmap(); +#endif + processOptions(); { int i; @@ -80,6 +101,7 @@ int main(int argc, char **argv) { struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc-1); failedtasks=genallocatehashtable((unsigned int (*)(void *)) &hashCodetpd, (int (*)(void *,void *)) &comparetpd); + /* failedobjects=genallocatehashtable(NULL,NULL);*/ activetasks=createQueue(); @@ -240,6 +262,40 @@ void removereadfd(int fd) { } } +/* +void restoreObject(void * obj) { + if (gencontains(failedobjects, obj)) { + struct tpdlist *tpd=gengettable(failedobjects, obj); + genfreekey(failedobjects, obj); + while(tpd!=NULL) { + int i; + struct taskparamdescriptor *task=tpd->task; + genfreekey(failedtasks, task); + for(i=0;inumParameters;i++) { + void *objother=task->parameterArray[i]; + struct tpdlist *tpdother=gengettable(failedobjects, objother); + struct tpdlist *tmpptr; + genfreekey(failedobjects, objother); + struct tpdlist **tpdptr=&tpdother; + while((*tpdptr)->task!=task) + tpdptr=&((*tpdptr)->next); + tmpptr=*tpdptr; + (*tpdptr)=(*tpdptr)->next; + RUNFREE(tmpptr); + if (tpdother!=NULL) + genputtable(failedobjects, objother, tpdother); + } + RUNFREE(task); + { + struct tpdlist *old=tpd; + tpd=tpd->next; + RUNFREE(old); + } + } + } +} +*/ + void executetasks() { void * taskpointerarray[MAXTASKPARAMS]; @@ -313,6 +369,22 @@ void executetasks() { printf("Fatal Error=%d, Recovering!\n",x); #endif genputtable(failedtasks,tpd,tpd); + /* for(i=0;itask->numParameters;i++) { + void *parameter=tpd->parameterArray[i]; + { + // Create mapping from object -> failed tasks + struct tpdlist * tpnew=RUNMALLOC(sizeof(struct tpdlist)); + tpnew->task=tpd; + if (gencontains(failedobjects, parameter)) { + struct tpdlist * tpdptr=gengettable(failedobjects, parameter); + tpnew->next=tpdptr->next; + tpdptr->next=tpnew; + } else { + tpnew->next=NULL; + genputtable(failedobjects, parameter, tpnew); + } + } + } */ restorecheckpoint(tpd->task->numParameters, taskpointerarray, checkpoint, forward, reverse); } else { if (injectfailures) { @@ -358,123 +430,22 @@ void processtasks() { } } - - -int ___ServerSocket______createSocket____I(struct ___ServerSocket___ * sock, int port) { - int fd; - - int n=1; - struct sockaddr_in sin; - - bzero (&sin, sizeof (sin)); - sin.sin_family = AF_INET; - sin.sin_port = htons (port); - sin.sin_addr.s_addr = htonl (INADDR_ANY); - fd=socket(AF_INET, SOCK_STREAM, 0); - if (fd<0) { -#ifdef DEBUG - perror(NULL); - printf("createSocket error #1\n"); #endif - longjmp(error_handler,5); - } - if (setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (char *)&n, sizeof (n)) < 0) { - close(fd); -#ifdef DEBUG - perror(NULL); - printf("createSocket error #2\n"); -#endif - longjmp(error_handler, 6); - } - fcntl(fd, F_SETFD, 1); - fcntl(fd, F_SETFL, fcntl(fd, F_GETFL)|O_NONBLOCK); - /* bind to port */ - if (bind(fd, (struct sockaddr *) &sin, sizeof(sin))<0) { - close (fd); -#ifdef DEBUG - perror(NULL); - printf("createSocket error #3\n"); -#endif - longjmp(error_handler, 7); - } - - /* listen */ - if (listen(fd, 5)<0) { - close (fd); -#ifdef DEBUG - perror(NULL); - printf("createSocket error #4\n"); -#endif - longjmp(error_handler, 8); +void injectinstructionfailure() { +#ifdef TASK + if (injectinstructionfailures) { + instructioncount=failurecount; + if ((((double)random())/RAND_MAX)___fd___; - int newfd; - newfd=accept(fd, (struct sockaddr *)&sin, &sinlen); - - - if (newfd<0) { -#ifdef DEBUG - perror(NULL); - printf("acceptSocket error #1\n"); +#else #endif - longjmp(error_handler, 9); - } - fcntl(newfd, F_SETFL, fcntl(fd, F_GETFL)|O_NONBLOCK); - - RuntimeHashadd(fdtoobject, newfd, (int) sock); - addreadfd(newfd); - flagorand(serversock,0,0xFFFFFFFE); - return newfd; } - -void ___Socket______nativeWrite_____AR_B(struct ___Socket___ * sock, struct ArrayObject * ao) { - int fd=sock->___fd___; - int length=ao->___length___; - char * charstr=((char *)& ao->___length___)+sizeof(int); - int bytewritten=write(fd, charstr, length); - if (bytewritten!=length) { - printf("ERROR IN NATIVEWRITE\n"); - } - flagorand(sock,0,0xFFFFFFFE); -} - -int ___Socket______nativeRead_____AR_B(struct ___Socket___ * sock, struct ArrayObject * ao) { - int fd=sock->___fd___; - int length=ao->___length___; - char * charstr=((char *)& ao->___length___)+sizeof(int); - int byteread=read(fd, charstr, length); - - if (byteread<0) { - printf("ERROR IN NATIVEREAD\n"); - } - flagorand(sock,0,0xFFFFFFFE); - return byteread; -} - -void ___Socket______nativeClose____(struct ___Socket___ * sock) { - int fd=sock->___fd___; - int data; - RuntimeHashget(fdtoobject, fd, &data); - RuntimeHashremove(fdtoobject, fd, data); - removereadfd(fd); - close(fd); - flagorand(sock,0,0xFFFFFFFE); -} -#endif - int ___Object______hashcode____(struct ___Object___ * ___this___) { return (int) ___this___; } diff --git a/Robust/src/Runtime/runtime.h b/Robust/src/Runtime/runtime.h index c20578a8..7f90aa69 100644 --- a/Robust/src/Runtime/runtime.h +++ b/Robust/src/Runtime/runtime.h @@ -2,6 +2,7 @@ #define RUNTIME #include extern jmp_buf error_handler; +extern int instructioncount; void * allocate_new(int type); struct ArrayObject * allocate_newarray(int type, int length); @@ -10,6 +11,7 @@ struct ___String___ * NewString(const char *str,int length); void failedboundschk(); void failednullptr(); void abort_task(); +void injectinstructionfailure(); #ifdef TASK #include "SimpleHash.h" @@ -32,6 +34,11 @@ struct taskparamdescriptor { void ** parameterArray; }; +struct tpdlist { + struct taskparamdescriptor * task; + struct tpdlist * next; +}; + int hashCodetpd(struct taskparamdescriptor *); int comparetpd(struct taskparamdescriptor *, struct taskparamdescriptor *); #endif diff --git a/Robust/src/Runtime/socket.c b/Robust/src/Runtime/socket.c new file mode 100644 index 00000000..190aae55 --- /dev/null +++ b/Robust/src/Runtime/socket.c @@ -0,0 +1,123 @@ +#include "runtime.h" +#include "structdefs.h" +#include +#include +#include +#include +#include "SimpleHash.h" +#include "GenericHashtable.h" +extern struct RuntimeHash *fdtoobject; + +int ___ServerSocket______createSocket____I(struct ___ServerSocket___ * sock, int port) { + int fd; + + int n=1; + struct sockaddr_in sin; + + bzero (&sin, sizeof (sin)); + sin.sin_family = AF_INET; + sin.sin_port = htons (port); + sin.sin_addr.s_addr = htonl (INADDR_ANY); + fd=socket(AF_INET, SOCK_STREAM, 0); + if (fd<0) { +#ifdef DEBUG + perror(NULL); + printf("createSocket error #1\n"); +#endif + longjmp(error_handler,5); + } + + if (setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, (char *)&n, sizeof (n)) < 0) { + close(fd); +#ifdef DEBUG + perror(NULL); + printf("createSocket error #2\n"); +#endif + longjmp(error_handler, 6); + } + fcntl(fd, F_SETFD, 1); + fcntl(fd, F_SETFL, fcntl(fd, F_GETFL)|O_NONBLOCK); + + /* bind to port */ + if (bind(fd, (struct sockaddr *) &sin, sizeof(sin))<0) { + close (fd); +#ifdef DEBUG + perror(NULL); + printf("createSocket error #3\n"); +#endif + longjmp(error_handler, 7); + } + + /* listen */ + if (listen(fd, 5)<0) { + close (fd); +#ifdef DEBUG + perror(NULL); + printf("createSocket error #4\n"); +#endif + longjmp(error_handler, 8); + } + + /* Store the fd/socket object mapping */ + RuntimeHashadd(fdtoobject, fd, (int) sock); + addreadfd(fd); + return fd; +} + +int ___ServerSocket______nativeaccept____L___Socket___(struct ___ServerSocket___ * serversock, struct ___Socket___ * sock) { + struct sockaddr_in sin; + unsigned int sinlen=sizeof(sin); + int fd=serversock->___fd___; + int newfd; + newfd=accept(fd, (struct sockaddr *)&sin, &sinlen); + + + if (newfd<0) { +#ifdef DEBUG + perror(NULL); + printf("acceptSocket error #1\n"); +#endif + longjmp(error_handler, 9); + } + fcntl(newfd, F_SETFL, fcntl(fd, F_GETFL)|O_NONBLOCK); + + RuntimeHashadd(fdtoobject, newfd, (int) sock); + addreadfd(newfd); + flagorand(serversock,0,0xFFFFFFFE); + return newfd; +} + + +void ___Socket______nativeWrite_____AR_B(struct ___Socket___ * sock, struct ArrayObject * ao) { + int fd=sock->___fd___; + int length=ao->___length___; + char * charstr=((char *)& ao->___length___)+sizeof(int); + int bytewritten=write(fd, charstr, length); + if (bytewritten!=length) { + printf("ERROR IN NATIVEWRITE\n"); + } + flagorand(sock,0,0xFFFFFFFE); +} + +int ___Socket______nativeRead_____AR_B(struct ___Socket___ * sock, struct ArrayObject * ao) { + int fd=sock->___fd___; + int length=ao->___length___; + char * charstr=((char *)& ao->___length___)+sizeof(int); + int byteread=read(fd, charstr, length); + + if (byteread<0) { + printf("ERROR IN NATIVEREAD\n"); + } + flagorand(sock,0,0xFFFFFFFE); + return byteread; +} + +void ___Socket______nativeClose____(struct ___Socket___ * sock) { + int fd=sock->___fd___; + int data; + RuntimeHashget(fdtoobject, fd, &data); + RuntimeHashremove(fdtoobject, fd, data); + removereadfd(fd); + close(fd); + flagorand(sock,0,0xFFFFFFFE); +} diff --git a/Robust/src/buildscriptrepair b/Robust/src/buildscriptrepair index 75019383..b8db54f7 100755 --- a/Robust/src/buildscriptrepair +++ b/Robust/src/buildscriptrepair @@ -63,6 +63,7 @@ gcc -I$ROBUSTROOT/Runtime -I. -I$BUILDDIR/specdir \ -LRuntime/lib/ -lgc -DTASK -g tmpbuilddirectory/methods.c \ tmpbuilddirectory/taskdefs.c $ROBUSTROOT/Runtime/runtime.c \ $ROBUSTROOT/Runtime/file.c \ +$ROBUSTROOT/Runtime/socket.c \ $ROBUSTROOT/Runtime/Queue.c $ROBUSTROOT/Runtime/SimpleHash.c \ $ROBUSTROOT/Runtime/checkpoint.c \ $ROBUSTROOT/Runtime/GenericHashtable.c $BUILDDIR/specdir/*.o -o \ diff --git a/Robust/src/buildscripttask b/Robust/src/buildscripttask index 5b67f8f0..08784e1e 100755 --- a/Robust/src/buildscripttask +++ b/Robust/src/buildscripttask @@ -5,4 +5,4 @@ shift mkdir tmpbuilddirectory java -cp $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary $ROBUSTROOT/ClassLibrary/ -dir tmpbuilddirectory -struct $MAINFILE -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 $ROBUSTROOT/Runtime/GenericHashtable.c -o $MAINFILE.bin -gcc -I$ROBUSTROOT/Runtime -I. -IRuntime/include -Itmpbuilddirectory -O0 -DBOEHM_GC -LRuntime/lib/ -lgc -DTASK -DDEBUG -g tmpbuilddirectory/methods.c tmpbuilddirectory/taskdefs.c $ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/file.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 +gcc -I$ROBUSTROOT/Runtime -I. -IRuntime/include -Itmpbuilddirectory -O0 -DBOEHM_GC -LRuntime/lib/ -lgc -DTASK -DDEBUG -g tmpbuilddirectory/methods.c tmpbuilddirectory/taskdefs.c $ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/file.c $ROBUSTROOT/Runtime/socket.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