From aedf948382ae56b974b47b57b89a61c8a279f21d Mon Sep 17 00:00:00 2001 From: bdemsky <bdemsky> Date: Fri, 17 Nov 2006 23:51:05 +0000 Subject: [PATCH] split option processing into its own file --- Robust/src/IR/Flat/BuildCode.java | 6 +- Robust/src/Runtime/option.c | 78 ++++++++++++++++++++ Robust/src/Runtime/option.h | 4 + Robust/src/Runtime/runtime.c | 119 +++++------------------------- Robust/src/buildscript | 2 +- Robust/src/buildscriptrepair | 1 + Robust/src/buildscripttask | 2 +- Robust/src/buildscripttaskerror | 3 +- 8 files changed, 107 insertions(+), 108 deletions(-) create mode 100644 Robust/src/Runtime/option.c create mode 100644 Robust/src/Runtime/option.h diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 340feef6..bbddb987 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -110,8 +110,9 @@ public class BuildCode { //Print out definition for array type outclassdefs.println("struct "+arraytype+" {"); outclassdefs.println(" int type;"); + outclassdefs.println(" int flag;"); + if (state.TASK) { - outclassdefs.println(" int flag;"); outclassdefs.println(" void * flagptr;"); } printClassStruct(typeutil.getClass(TypeUtil.ObjectClass), outclassdefs); @@ -663,8 +664,9 @@ public class BuildCode { /* Output class structure */ classdefout.println("struct "+cn.getSafeSymbol()+" {"); classdefout.println(" int type;"); + classdefout.println(" int flag;"); + if (state.TASK) { - classdefout.println(" int flag;"); classdefout.println(" void * flagptr;"); } printClassStruct(cn, classdefout); diff --git a/Robust/src/Runtime/option.c b/Robust/src/Runtime/option.c new file mode 100644 index 00000000..d1500d63 --- /dev/null +++ b/Robust/src/Runtime/option.c @@ -0,0 +1,78 @@ +#include "option.h" +#include <stdio.h> +#include <string.h> +#include "runtime.h" + +extern char *options; +extern int injectfailures; +extern float failurechance; +extern int debugtask; +extern int injectinstructionfailures; +extern int failurecount; +extern float instfailurechance; +extern int numfailures; +extern int instaccum; +extern char ** environ; + +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,"-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++; + if (options==NULL) + break; + + sscanf(options, "%d", &numfailures); + options=strchr(options,' '); + if (options!=NULL) options++; + + instaccum=failurecount; + instructioncount=failurecount; + injectinstructionfailures=1; + printf("Number of failures=%d\n",numfailures); + 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 if (strncmp(options, "-initializerandom", sizeof("-initializerandom")-1)==0) { + options=strchr(options,' '); + if (options!=NULL) options++; + printf("Initializing random number generator.\n"); + srandomdev(); + } else + break; + } +} diff --git a/Robust/src/Runtime/option.h b/Robust/src/Runtime/option.h new file mode 100644 index 00000000..f9cd7ac7 --- /dev/null +++ b/Robust/src/Runtime/option.h @@ -0,0 +1,4 @@ +#ifdef OPTION_H +#define OPTION_H +void processOptions(); +#endif diff --git a/Robust/src/Runtime/runtime.c b/Robust/src/Runtime/runtime.c index 635df057..4da7565e 100644 --- a/Robust/src/Runtime/runtime.c +++ b/Robust/src/Runtime/runtime.c @@ -9,6 +9,7 @@ #include<errno.h> #include<signal.h> #include<stdio.h> +#include "option.h" extern int classsize[]; jmp_buf error_handler; @@ -28,8 +29,6 @@ int instructioncount; struct Queue * activetasks; struct parameterwrapper * objectqueues[NUMCLASSES]; struct genhashtable * failedtasks; -/*struct genhashtable * failedobjects;*/ -extern char ** environ; char *options; int injectfailures=0; float failurechance=0; @@ -40,71 +39,10 @@ float instfailurechance=0; int numfailures; int instaccum=0; -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,"-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++; - if (options==NULL) - break; - - sscanf(options, "%d", &numfailures); - options=strchr(options,' '); - if (options!=NULL) options++; - - instaccum=failurecount; - instructioncount=failurecount; - injectinstructionfailures=1; - printf("Number of failures=%d\n",numfailures); - 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 if (strncmp(options, "-initializerandom", sizeof("-initializerandom")-1)==0) { - options=strchr(options,' '); - if (options!=NULL) options++; - printf("Initializing random number generator.\n"); - srandomdev(); - } else - break; - } -} - int main(int argc, char **argv) { +#ifdef BOEHM_GC GC_init(); // Initialize the garbage collector +#endif #ifdef CONSCHECK initializemmap(); #endif @@ -117,8 +55,6 @@ 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(); /* Set flags */ @@ -157,13 +93,17 @@ int comparetpd(struct taskparamdescriptor *ftd1, struct taskparamdescriptor *ftd return 1; } +/* This function updates the flag for object ptr. It or's the flag + with the or mask and and's it with the andmask. */ + void flagorand(void * ptr, int ormask, int andmask) { int flag=((int *)ptr)[1]; struct RuntimeHash *flagptr=(struct RuntimeHash *)(((int*)ptr)[2]); flag|=ormask; flag&=andmask; ((int*)ptr)[1]=flag; - /*Remove from all queues */ + + /*Remove object from all queues */ while(flagptr!=NULL) { struct RuntimeHash *next; RuntimeHashget(flagptr, (int) ptr, (int *) &next); @@ -251,6 +191,7 @@ void flagorand(void * ptr, int ormask, int andmask) { /* Handler for signals. The signals catch null pointer errors and arithmatic errors. */ + void myhandler(int sig, siginfo_t *info, void *uap) { #ifdef DEBUG printf("sig=%d\n",sig); @@ -278,40 +219,6 @@ 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;i<task->numParameters;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); - } - } - } -} -*/ - #ifdef PRECISE_GC #define OFFSET 2 #else @@ -508,12 +415,16 @@ void CALL01(___System______printString____L___String___,struct ___String___ * __ } } +/* Object allocation function */ + void * allocate_new(int type) { void * v=FREEMALLOC(classsize[type]); *((int *)v)=type; return v; } +/* Array allocation function */ + struct ArrayObject * allocate_newarray(int type, int length) { struct ArrayObject * v=FREEMALLOC(sizeof(struct ArrayObject)+length*classsize[type]); v->type=type; @@ -521,6 +432,8 @@ struct ArrayObject * allocate_newarray(int type, int length) { return v; } +/* Converts C character arrays into Java strings */ + struct ___String___ * NewString(const char *str,int length) { struct ArrayObject * chararray=allocate_newarray(CHARARRAYTYPE, length); struct ___String___ * strobj=allocate_new(STRINGTYPE); @@ -535,6 +448,7 @@ struct ___String___ * NewString(const char *str,int length) { } /* Generated code calls this if we fail a bounds check */ + void failedboundschk() { #ifndef TASK printf("Array out of bounds\n"); @@ -544,6 +458,7 @@ void failedboundschk() { #endif } +/* Abort task call */ void abort_task() { #ifdef TASK longjmp(error_handler,4); diff --git a/Robust/src/buildscript b/Robust/src/buildscript index d11b87c0..973219b9 100755 --- a/Robust/src/buildscript +++ b/Robust/src/buildscript @@ -4,4 +4,4 @@ MAINFILE=$1 shift mkdir tmpbuilddirectory java -cp $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary $ROBUSTROOT/ClassLibrary/ -dir tmpbuilddirectory -precise -mainclass $MAINFILE $@ -gcc -I$ROBUSTROOT/Runtime -Itmpbuilddirectory -DPRECISE_GC -O0 -g tmpbuilddirectory/methods.c $ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/file.c -o $MAINFILE.bin \ No newline at end of file +gcc -I$ROBUSTROOT/Runtime -Itmpbuilddirectory -DPRECISE_GC -O0 -g tmpbuilddirectory/methods.c $ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/file.c $ROBUSTROOT/Runtime/option.c -o $MAINFILE.bin \ No newline at end of file diff --git a/Robust/src/buildscriptrepair b/Robust/src/buildscriptrepair index b8db54f7..bcdf48ce 100755 --- a/Robust/src/buildscriptrepair +++ b/Robust/src/buildscriptrepair @@ -66,5 +66,6 @@ $ROBUSTROOT/Runtime/file.c \ $ROBUSTROOT/Runtime/socket.c \ $ROBUSTROOT/Runtime/Queue.c $ROBUSTROOT/Runtime/SimpleHash.c \ $ROBUSTROOT/Runtime/checkpoint.c \ +$ROBUSTROOT/Runtime/option.c \ $ROBUSTROOT/Runtime/GenericHashtable.c $BUILDDIR/specdir/*.o -o \ $MAINFILE.bin diff --git a/Robust/src/buildscripttask b/Robust/src/buildscripttask index 6762801b..93edffbc 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 -precise -struct $MAINFILE -task $@ -gcc -DPRECISE_GC -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 +gcc -DPRECISE_GC -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 $ROBUSTROOT/Runtime/option.c -o $MAINFILE.bin \ No newline at end of file diff --git a/Robust/src/buildscripttaskerror b/Robust/src/buildscripttaskerror index 05475803..8b4be7cd 100755 --- a/Robust/src/buildscripttaskerror +++ b/Robust/src/buildscripttaskerror @@ -4,5 +4,4 @@ MAINFILE=$1 shift mkdir tmpbuilddirectory java -cp $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary $ROBUSTROOT/ClassLibrary/ -dir tmpbuilddirectory -struct $MAINFILE -task -instructionfailures $@ -#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/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 +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 $ROBUSTROOT/Runtime/option.c -o $MAINFILE.bin \ No newline at end of file -- 2.34.1