From 8abeab4c72e409097c42e74b798535420c53e22c Mon Sep 17 00:00:00 2001 From: bdemsky Date: Wed, 1 Nov 2006 23:21:03 +0000 Subject: [PATCH] Added environment options. Use export BRISTLECONE="-debugtask" to print out debug information. --- Robust/src/IR/Flat/BuildCode.java | 36 ++++++++++---------- Robust/src/IR/State.java | 1 - Robust/src/Main/Main.java | 2 -- Robust/src/Runtime/runtime.c | 55 +++++++++++++++++++++++++++++-- Robust/src/buildscripttaskdebug | 8 ----- 5 files changed, 70 insertions(+), 32 deletions(-) delete mode 100755 Robust/src/buildscripttaskdebug diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 809fd147..c3b05d5c 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -131,6 +131,7 @@ public class BuildCode { outtask.println("void * taskptr;"); outtask.println("int numParameters;"); outtask.println("struct parameterdescriptor **descriptorarray;"); + outtask.println("char * name;"); outtask.println("};"); outtask.println("extern struct taskdescriptor * taskarray[];"); outtask.println("extern numtasks;"); @@ -205,18 +206,22 @@ public class BuildCode { generateTaskDescriptor(outtaskdefs, td); } - taskit=state.getTaskSymbolTable().getDescriptorsIterator(); - outtaskdefs.println("struct taskdescriptor * taskarray[]= {"); - boolean first=true; - while(taskit.hasNext()) { - TaskDescriptor td=(TaskDescriptor)taskit.next(); - if (first) - first=false; - else - outtaskdefs.println(","); - outtaskdefs.print("&task_"+td.getSafeSymbol()); + { + //Output task descriptors + taskit=state.getTaskSymbolTable().getDescriptorsIterator(); + outtaskdefs.println("struct taskdescriptor * taskarray[]= {"); + boolean first=true; + while(taskit.hasNext()) { + TaskDescriptor td=(TaskDescriptor)taskit.next(); + if (first) + first=false; + else + outtaskdefs.println(","); + outtaskdefs.print("&task_"+td.getSafeSymbol()); + } + outtaskdefs.println("};"); } - outtaskdefs.println("};"); + outtaskdefs.println("int numtasks="+state.getTaskSymbolTable().getValueSet().size()+";"); } else if (state.main!=null) { @@ -366,7 +371,8 @@ public class BuildCode { output.println("struct taskdescriptor task_"+task.getSafeSymbol()+"={"); output.println("&"+task.getSafeSymbol()+","); output.println("/* number of parameters */" +task.numParameters() + ","); - output.println("parameterdescriptors_"+task.getSafeSymbol()); + output.println("parameterdescriptors_"+task.getSafeSymbol()+","); + output.println("\""+task.getSymbol()+"\""); output.println("};"); } @@ -848,8 +854,6 @@ public class BuildCode { } } } - if (task!=null&&state.TASKDEBUG) - output.println("printf(\"ENTER "+task.getSymbol()+"\\n\");"); //Do the actual code generation tovisit=new HashSet(); @@ -867,8 +871,6 @@ public class BuildCode { output.print(" "); generateFlatNode(fm, current_node, output); if (current_node.kind()!=FKind.FlatReturnNode) { - if (task!=null&&state.TASKDEBUG) - output.println("printf(\"EXIT "+task.getSymbol()+"\\n\");"); output.println(" return;"); } current_node=null; @@ -1198,8 +1200,6 @@ public class BuildCode { private void generateFlatReturnNode(FlatMethod fm, FlatReturnNode frn, PrintWriter output) { - if (fm.getTask()!=null&&state.TASKDEBUG) - output.println("printf(\"EXIT "+fm.getTask().getSymbol()+"\\n\");"); if (frn.getReturnTemp()!=null) output.println("return "+generateTemp(fm, frn.getReturnTemp())+";"); else diff --git a/Robust/src/IR/State.java b/Robust/src/IR/State.java index 4797a6be..a40ed70d 100644 --- a/Robust/src/IR/State.java +++ b/Robust/src/IR/State.java @@ -22,7 +22,6 @@ public class State { /** Boolean flag which indicates whether compiler is compiling a task-based * program. */ public boolean TASK; - public boolean TASKDEBUG; 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 9ccb839e..75487a3f 100644 --- a/Robust/src/Main/Main.java +++ b/Robust/src/Main/Main.java @@ -33,8 +33,6 @@ public class Main { state.CONSCHECK=true; else if (option.equals("-task")) state.TASK=true; - else if (option.equals("-taskdebug")) - state.TASKDEBUG=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"); diff --git a/Robust/src/Runtime/runtime.c b/Robust/src/Runtime/runtime.c index 05e014c4..86d4e071 100644 --- a/Robust/src/Runtime/runtime.c +++ b/Robust/src/Runtime/runtime.c @@ -30,12 +30,49 @@ jmp_buf error_handler; struct Queue * activetasks; struct parameterwrapper * objectqueues[NUMCLASSES]; struct genhashtable * failedtasks; +extern char ** environ; +char *options; +int injectfailures=0; +float failurechance=0; +int debugtask=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; + } + } + + 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 + break; + } + } + + { int i; /* Allocate startup object */ @@ -268,17 +305,29 @@ void executetasks() { struct RuntimeHash * forward=allocateRuntimeHash(100); struct RuntimeHash * reverse=allocateRuntimeHash(100); void ** checkpoint=makecheckpoint(tpd->task->numParameters, taskpointerarray, forward, reverse); - if (setjmp(error_handler)) { + int x; + if (x=setjmp(error_handler)) { /* Recover */ int h; #ifdef DEBUG - printf("Fatal Error! Recovering!\n"); + printf("Fatal Error=%d, Recovering!\n",x); #endif genputtable(failedtasks,tpd,tpd); restorecheckpoint(tpd->task->numParameters, taskpointerarray, checkpoint, forward, reverse); } else { + if (injectfailures) { + if ((((double)random())/RAND_MAX)task->name); + longjmp(error_handler,10); + } + } /* Actually call task */ - ((void (*) (void **)) tpd->task->taskptr)(taskpointerarray); + if (debugtask) { + printf("ENTER %s\n",tpd->task->name); + ((void (*) (void **)) tpd->task->taskptr)(taskpointerarray); + printf("EXIT %s\n",tpd->task->name); + } else + ((void (*) (void **)) tpd->task->taskptr)(taskpointerarray); } } } diff --git a/Robust/src/buildscripttaskdebug b/Robust/src/buildscripttaskdebug deleted file mode 100755 index ab704ab5..00000000 --- a/Robust/src/buildscripttaskdebug +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/bash -ROBUSTROOT=~/research/Robust/src -MAINFILE=$1 -shift -mkdir tmpbuilddirectory -java -cp $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary $ROBUSTROOT/ClassLibrary/ -dir tmpbuilddirectory -struct $MAINFILE -task -taskdebug $@ -#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 -- 2.34.1