From 53aec7d23817e7690b2099e6b585b2aef35977b6 Mon Sep 17 00:00:00 2001 From: bdemsky Date: Fri, 17 Nov 2006 08:46:41 +0000 Subject: [PATCH] Compiler/runtime modifications towards supporting precise garbage collection --- Robust/src/IR/Flat/BuildCode.java | 53 +++++++++++++++++--------- Robust/src/IR/Flat/BuildFlat.java | 16 ++++++-- Robust/src/IR/Flat/TempDescriptor.java | 4 ++ Robust/src/Runtime/file.c | 44 ++++++++++----------- Robust/src/Runtime/runtime.c | 39 ++++++++++++------- Robust/src/Runtime/runtime.h | 18 +++++++++ Robust/src/Runtime/socket.c | 38 +++++++++--------- Robust/src/buildscript | 4 +- Robust/src/buildscripttask | 5 +-- 9 files changed, 139 insertions(+), 82 deletions(-) diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index e33fc83c..340feef6 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -227,13 +227,13 @@ public class BuildCode { } else if (state.main!=null) { /* Generate main method */ outmethod.println("int main(int argc, const char *argv[]) {"); - outmethod.println("int i;"); - outmethod.println("struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc-1);"); - outmethod.println("for(i=1;i___length___)+sizeof(int)))[i-1]=newstring;"); - outmethod.println("}"); + outmethod.println(" int i;"); + outmethod.println(" struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc-1);"); + outmethod.println(" for(i=1;i___length___)+sizeof(int)))[i-1]=newstring;"); + outmethod.println(" }"); ClassDescriptor cd=typeutil.getClass(state.main); @@ -249,7 +249,14 @@ public class BuildCode { if (!md.getModifiers().isStatic()) throw new Error("Error: Non static main"); - outmethod.println(" "+cd.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(stringarray);"); + outmethod.println(" {"); + if (GENERATEPRECISEGC) { + outmethod.print(" struct "+cd.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={"); + outmethod.println("1, NULL,"+"stringarray};"); + outmethod.println(" "+cd.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(& __parameterlist__);"); + } else + outmethod.println(" "+cd.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(stringarray);"); + outmethod.println(" }"); break; } outmethod.println("}"); @@ -677,7 +684,7 @@ public class BuildCode { /* Output parameter structure */ if (GENERATEPRECISEGC) { output.println("struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params {"); - output.println(" int type;"); + output.println(" int size;"); output.println(" void * next;"); for(int i=0;imaxtaskparams) maxtaskparams=objectparams.numPrimitives(); - } else output.println(" {"); + } else output.println(") {"); } public void generateFlatFlagActionNode(FlatMethod fm, FlatFlagActionNode ffan, PrintWriter output) { diff --git a/Robust/src/IR/Flat/BuildFlat.java b/Robust/src/IR/Flat/BuildFlat.java index dde06ea4..ee17a317 100644 --- a/Robust/src/IR/Flat/BuildFlat.java +++ b/Robust/src/IR/Flat/BuildFlat.java @@ -72,9 +72,9 @@ public class BuildFlat { FlatNode fn=flattenBlockNode(bn).getBegin(); FlatMethod fm=new FlatMethod(md, fn); if (!md.isStatic()) - fm.addParameterTemp(getTempforVar(md.getThis())); + fm.addParameterTemp(getTempforParam(md.getThis())); for(int i=0;i #include "structdefs.h" #include "mem.h" +#include "runtime.h" - -void ___FileOutputStream______nativeWrite____I__AR_B(int fd, struct ArrayObject * ao) { - int length=ao->___length___; - char * string= (((char *)& ao->___length___)+sizeof(int)); +void CALL12(___FileOutputStream______nativeWrite____I__AR_B, int fd, int fd, struct ArrayObject * ___array___) { + int length=VAR(___array___)->___length___; + char * string= (((char *)& VAR(___array___)->___length___)+sizeof(int)); int status=write(fd, string, length); } -void ___FileOutputStream______nativeClose____I(int fd) { +void CALL11(___FileOutputStream______nativeClose____I, int fd, int fd) { close(fd); } -void ___FileOutputStream______nativeFlush____I(int fd) { +void CALL11(___FileOutputStream______nativeFlush____I, int fd, int fd) { fsync(fd); } -int ___FileOutputStream______nativeOpen_____AR_B(struct ArrayObject * ao) { - int length=ao->___length___; - char* filename= (((char *)& ao->___length___)+sizeof(int)); +int CALL01(___FileOutputStream______nativeOpen_____AR_B, struct ArrayObject * ___filename___) { + int length=VAR(___filename___)->___length___; + char* filename= (((char *)& VAR(___filename___)->___length___)+sizeof(int)); int fd=open(filename, O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU); return fd; } -int ___FileOutputStream______nativeAppend_____AR_B(struct ArrayObject * ao) { - int length=ao->___length___; - char* filename= (((char *)& ao->___length___)+sizeof(int)); +int CALL01(___FileOutputStream______nativeAppend_____AR_B, struct ArrayObject * ___filename___) { + int length=VAR(___filename___)->___length___; + char* filename= (((char *)& VAR(___filename___)->___length___)+sizeof(int)); int fd=open(filename, O_WRONLY|O_CREAT|O_APPEND, S_IRWXU); return fd; } -int ___FileInputStream______nativeOpen_____AR_B(struct ArrayObject * ao) { - int length=ao->___length___; - char* filename= (((char *)& ao->___length___)+sizeof(int)); +int CALL01(___FileInputStream______nativeOpen_____AR_B, struct ArrayObject * ___filename___) { + int length=VAR(___filename___)->___length___; + char* filename= (((char *)& VAR(___filename___)->___length___)+sizeof(int)); int fd=open(filename, O_RDONLY, 0); return fd; } -void ___FileInputStream______nativeClose____I(int fd) { +void CALL11(___FileInputStream______nativeClose____I, int fd, int fd) { close(fd); } -int ___FileInputStream______nativeRead____I__AR_B_I(int fd, struct ArrayObject * ao, int numBytes) { - int toread=ao->___length___; - char* string= (((char *)& ao->___length___)+sizeof(int)); +int CALL23(___FileInputStream______nativeRead____I__AR_B_I, int fd, int numBytes, int fd, struct ArrayObject * ___array___, int numBytes) { + int toread=VAR(___array___)->___length___; + char* string= (((char *)& VAR(___array___)->___length___)+sizeof(int)); int status; if (numBytes___length___; - char* filename= (((char *)& ao->___length___)+sizeof(int)); +long long CALL01(___File______nativeLength_____AR_B, struct ArrayObject * ___pathname___) { + int length=VAR(___pathname___)->___length___; + char* filename= (((char *)& VAR(___pathname___)->___length___)+sizeof(int)); struct stat st; stat(filename, &st); return st.st_size; diff --git a/Robust/src/Runtime/runtime.c b/Robust/src/Runtime/runtime.c index cf45bfd5..635df057 100644 --- a/Robust/src/Runtime/runtime.c +++ b/Robust/src/Runtime/runtime.c @@ -312,8 +312,14 @@ void restoreObject(void * obj) { } */ +#ifdef PRECISE_GC +#define OFFSET 2 +#else +#define OFFSET 0 +#endif + void executetasks() { - void * taskpointerarray[MAXTASKPARAMS]; + void * taskpointerarray[MAXTASKPARAMS+OFFSET]; /* Set up signal handlers */ struct sigaction sig; @@ -378,13 +384,13 @@ void executetasks() { struct parameterwrapper *pw=(struct parameterwrapper *) pd->queue; if (!RuntimeHashcontainskey(pw->objectset, (int) parameter)) goto newtask; - taskpointerarray[i]=parameter; + taskpointerarray[i+OFFSET]=parameter; } { /* Checkpoint the state */ struct RuntimeHash * forward=allocateRuntimeHash(100); struct RuntimeHash * reverse=allocateRuntimeHash(100); - void ** checkpoint=makecheckpoint(tpd->task->numParameters, taskpointerarray, forward, reverse); + void ** checkpoint=makecheckpoint(tpd->task->numParameters, &taskpointerarray[OFFSET], forward, reverse); int x; if (x=setjmp(error_handler)) { /* Recover */ @@ -409,7 +415,7 @@ void executetasks() { } } } */ - restorecheckpoint(tpd->task->numParameters, taskpointerarray, checkpoint, forward, reverse); + restorecheckpoint(tpd->task->numParameters, &taskpointerarray[OFFSET], checkpoint, forward, reverse); } else { if (injectfailures) { if ((((double)random())/RAND_MAX)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); @@ -479,21 +490,21 @@ void injectinstructionfailure() { #endif } -int ___Object______hashCode____(struct ___Object___ * ___this___) { - return (int) ___this___; +int CALL01(___Object______hashCode____, struct ___Object___ * ___this___) { + return (int) VAR(___this___); } -int ___Object______getType____(struct ___Object___ * ptr) { - return ((int *)ptr)[0]; +int CALL01(___Object______getType____, struct ___Object___ * ___this___) { + return ((int *)VAR(___this___))[0]; } -void ___System______printString____L___String___(struct ___String___ * s) { - struct ArrayObject * chararray=s->___value___; +void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) { + struct ArrayObject * chararray=VAR(___s___)->___value___; int i; - int offset=s->___offset___; - for(i=0;i___count___;i++) { - short s= ((short *)(((char *)& chararray->___length___)+sizeof(int)))[i+offset]; - putchar(s); + int offset=VAR(___s___)->___offset___; + for(i=0;i___count___;i++) { + short sc=((short *)(((char *)& chararray->___length___)+sizeof(int)))[i+offset]; + putchar(sc); } } diff --git a/Robust/src/Runtime/runtime.h b/Robust/src/Runtime/runtime.h index 7f90aa69..de2c8715 100644 --- a/Robust/src/Runtime/runtime.h +++ b/Robust/src/Runtime/runtime.h @@ -13,6 +13,24 @@ void failednullptr(); void abort_task(); void injectinstructionfailure(); +#ifdef PRECISE_GC +#define VAR(name) ___params___->name +#define CALL01(name, alt) name(struct name ## _params * ___params___) +#define CALL02(name, alt1, alt2) name(struct name ## _params * ___params___) +#define CALL11(name,rest, alt) name(struct name ## _params * ___params___, rest) +#define CALL12(name,rest, alt1, alt2) name(struct name ## _params * ___params___, rest) +#define CALL21(name,rest, rest2, alt) name(struct name ## _params * ___params___, rest, rest2) +#define CALL23(name, rest, rest2, alt1, alt2, alt3) name(struct name ## _params * ___params___, rest, rest2) +#else +#define VAR(name) name +#define CALL01(name, alt) name(alt) +#define CALL02(name, alt1, alt2) name(alt1, alt2) +#define CALL11(name,rest, alt) name(alt) +#define CALL12(name,rest, alt1, alt2) name(alt1, alt2) +#define CALL21(name,rest, rest2, alt) name(alt) +#define CALL23(name, rest, rest2, alt1, alt2, alt3) name(alt1, alt2, alt3) +#endif + #ifdef TASK #include "SimpleHash.h" #include "task.h" diff --git a/Robust/src/Runtime/socket.c b/Robust/src/Runtime/socket.c index ec049d16..460204e9 100644 --- a/Robust/src/Runtime/socket.c +++ b/Robust/src/Runtime/socket.c @@ -10,7 +10,7 @@ extern struct RuntimeHash *fdtoobject; -int ___ServerSocket______createSocket____I(struct ___ServerSocket___ * sock, int port) { +int CALL12(___ServerSocket______createSocket____I, int port, struct ___ServerSocket___ * ___this___, int port) { int fd; int n=1; @@ -61,15 +61,15 @@ int ___ServerSocket______createSocket____I(struct ___ServerSocket___ * sock, int } /* Store the fd/socket object mapping */ - RuntimeHashadd(fdtoobject, fd, (int) sock); + RuntimeHashadd(fdtoobject, fd, (int) VAR(___this___)); addreadfd(fd); return fd; } -int ___ServerSocket______nativeaccept____L___Socket___(struct ___ServerSocket___ * serversock, struct ___Socket___ * sock) { +int CALL02(___ServerSocket______nativeaccept____L___Socket___,struct ___ServerSocket___ * ___this___, struct ___Socket___ * ___s___) { struct sockaddr_in sin; unsigned int sinlen=sizeof(sin); - int fd=serversock->___fd___; + int fd=VAR(___this___)->___fd___; int newfd; newfd=accept(fd, (struct sockaddr *)&sin, &sinlen); @@ -83,17 +83,17 @@ int ___ServerSocket______nativeaccept____L___Socket___(struct ___ServerSocket___ } fcntl(newfd, F_SETFL, fcntl(fd, F_GETFL)|O_NONBLOCK); - RuntimeHashadd(fdtoobject, newfd, (int) sock); + RuntimeHashadd(fdtoobject, newfd, (int) VAR(___s___)); addreadfd(newfd); - flagorand(serversock,0,0xFFFFFFFE); + flagorand(VAR(___this___),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); +void CALL02(___Socket______nativeWrite_____AR_B, struct ___Socket___ * ___this___, struct ArrayObject * ___b___) { + int fd=VAR(___this___)->___fd___; + int length=VAR(___b___)->___length___; + char * charstr=((char *)& VAR(___b___)->___length___)+sizeof(int); while(1) { int bytewritten=write(fd, charstr, length); if (bytewritten==-1&&errno==EAGAIN) @@ -104,28 +104,28 @@ void ___Socket______nativeWrite_____AR_B(struct ___Socket___ * sock, struct Arra } break; } - // flagorand(sock,0,0xFFFFFFFE); + // flagorand(VAR(___this___),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 CALL02(___Socket______nativeRead_____AR_B, struct ___Socket___ * ___this___, struct ArrayObject * ___b___) { + int fd=VAR(___this___)->___fd___; + int length=VAR(___b___)->___length___; + char * charstr=((char *)& VAR(___b___)->___length___)+sizeof(int); int byteread=read(fd, charstr, length); if (byteread<0) { printf("ERROR IN NATIVEREAD\n"); } - flagorand(sock,0,0xFFFFFFFE); + flagorand(VAR(___this___),0,0xFFFFFFFE); return byteread; } -void ___Socket______nativeClose____(struct ___Socket___ * sock) { - int fd=sock->___fd___; +void CALL01(___Socket______nativeClose____, struct ___Socket___ * ___this___) { + int fd=VAR(___this___)->___fd___; int data; RuntimeHashget(fdtoobject, fd, &data); RuntimeHashremove(fdtoobject, fd, data); removereadfd(fd); close(fd); - flagorand(sock,0,0xFFFFFFFE); + flagorand(VAR(___this___),0,0xFFFFFFFE); } diff --git a/Robust/src/buildscript b/Robust/src/buildscript index 0ba7f571..d11b87c0 100755 --- a/Robust/src/buildscript +++ b/Robust/src/buildscript @@ -3,5 +3,5 @@ ROBUSTROOT=~/research/Robust/src MAINFILE=$1 shift mkdir tmpbuilddirectory -java -cp $ROBUSTROOT/../cup/:$ROBUSTROOT Main.Main -classlibrary $ROBUSTROOT/ClassLibrary/ -dir tmpbuilddirectory -mainclass $MAINFILE $@ -gcc -I$ROBUSTROOT/Runtime -Itmpbuilddirectory -O0 -g tmpbuilddirectory/methods.c $ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/file.c -o $MAINFILE.bin \ No newline at end of file +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 diff --git a/Robust/src/buildscripttask b/Robust/src/buildscripttask index 08784e1e..6762801b 100755 --- a/Robust/src/buildscripttask +++ b/Robust/src/buildscripttask @@ -3,6 +3,5 @@ ROBUSTROOT=~/research/Robust/src MAINFILE=$1 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/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 +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 -- 2.34.1