} 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<argc;i++) {");
- outmethod.println("int length=strlen(argv[i]);");
- outmethod.println("struct ___String___ *newstring=NewString(argv[i],length);");
- outmethod.println("((void **)(((char *)& stringarray->___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<argc;i++) {");
+ outmethod.println(" int length=strlen(argv[i]);");
+ outmethod.println(" struct ___String___ *newstring=NewString(argv[i],length);");
+ outmethod.println(" ((void **)(((char *)& stringarray->___length___)+sizeof(int)))[i-1]=newstring;");
+ outmethod.println(" }");
ClassDescriptor cd=typeutil.getClass(state.main);
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("}");
/* 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;i<objectparams.numPointers();i++) {
TempDescriptor temp=objectparams.getPointer(i);
/* Output temp structure */
if (GENERATEPRECISEGC) {
output.println("struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals {");
- output.println(" int type;");
+ output.println(" int size;");
output.println(" void * next;");
for(int i=0;i<objecttemps.numPointers();i++) {
TempDescriptor temp=objecttemps.getPointer(i);
if (GENERATEPRECISEGC) {
output.println("struct "+task.getSafeSymbol()+"_params {");
- output.println(" int type;");
+ output.println(" int size;");
output.println(" void * next;");
for(int i=0;i<objectparams.numPointers();i++) {
TempDescriptor temp=objectparams.getPointer(i);
/* Output temp structure */
if (GENERATEPRECISEGC) {
output.println("struct "+task.getSafeSymbol()+"_locals {");
- output.println(" int type;");
+ output.println(" int size;");
output.println(" void * next;");
for(int i=0;i<objecttemps.numPointers();i++) {
TempDescriptor temp=objecttemps.getPointer(i);
generateHeader(md!=null?md:task,output);
/* Print code */
-
if (GENERATEPRECISEGC) {
if (md!=null)
output.println(" struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals "+localsprefix+";");
else
output.println(" "+type.getSafeSymbol()+" "+td.getSafeSymbol()+";");
}
-
+
+ /* Link the local pointers into chain. */
+ if (GENERATEPRECISEGC) {
+ if (md!=null) {
+ output.println(localsprefix+".size="+objecttemp.numPointers()+";");
+ output.println(localsprefix+".next="+paramsprefix+";");
+ }
+ }
/* Generate labels first */
HashSet tovisit=new HashSet();
MethodDescriptor md=fm.getMethod();
TaskDescriptor task=fm.getTask();
TempObject objecttemps=(TempObject) tempstable.get(md!=null?md:task);
+
if (objecttemps.isLocalPrim(td)||objecttemps.isParamPrim(td)) {
return td.getSafeSymbol();
}
if (GENERATEPRECISEGC) {
output.print(" struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={");
- output.print(objectparams.getUID());
+ output.print(objectparams.numPointers());
+ // output.print(objectparams.getUID());
output.print(", & "+localsprefix);
if (fc.getThis()!=null) {
output.print(", ");
- output.print(generateTemp(fm,fc.getThis()));
+ output.print("(struct "+md.getThis().getType().getSafeSymbol() +" *)"+ generateTemp(fm,fc.getThis()));
}
for(int i=0;i<fc.numArgs();i++) {
VarDescriptor var=md.getParameter(i);
if (objectparams.isParamPtr(paramtemp)) {
TempDescriptor targ=fc.getArg(i);
output.print(", ");
- output.print(generateTemp(fm, targ));
+ output.print("(struct "+md.getParamType(i).getSafeSymbol() +" *)"+generateTemp(fm, targ));
}
}
output.println("};");
output.print(temp.getType().getSafeSymbol()+" "+temp.getSafeSymbol());
}
output.println(") {");
- } else if (!GENERATEPRECISEGC) {
+ } else if (!GENERATEPRECISEGC){
output.println("void * parameterarray[]) {");
for(int i=0;i<objectparams.numPrimitives();i++) {
TempDescriptor temp=objectparams.getPrimitive(i);
}
if (objectparams.numPrimitives()>maxtaskparams)
maxtaskparams=objectparams.numPrimitives();
- } else output.println(" {");
+ } else output.println(") {");
}
public void generateFlatFlagActionNode(FlatMethod fm, FlatFlagActionNode ffan, PrintWriter output) {
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<md.numParameters();i++) {
- fm.addParameterTemp(getTempforVar(md.getParameter(i)));
+ fm.addParameterTemp(getTempforParam(md.getParameter(i)));
}
state.addFlatCode(md,fm);
}
return new NodePair(fn,fn);
}
}
-
+
+ private TempDescriptor getTempforParam(VarDescriptor vd) {
+ if (temptovar.containsKey(vd))
+ return (TempDescriptor)temptovar.get(vd);
+ else {
+ TempDescriptor td=TempDescriptor.paramtempFactory(vd.getName(),vd.getType());
+ temptovar.put(vd,td);
+ return td;
+ }
+ }
+
private TempDescriptor getTempforVar(VarDescriptor vd) {
if (temptovar.containsKey(vd))
return (TempDescriptor)temptovar.get(vd);
return new TempDescriptor(name+currentid,td);
}
+ public static TempDescriptor paramtempFactory(String name, TypeDescriptor td) {
+ return new TempDescriptor(name,td);
+ }
+
public String toString() {
return safename;
#include <unistd.h>
#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<toread)
return status;
}
-long long ___File______nativeLength_____AR_B(struct ArrayObject * ao) {
- int length=ao->___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;
}
*/
+#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;
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 */
}
}
} */
- 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)<failurechance) {
}
}
/* Actually call task */
+#ifdef PRECISE_GC
+ ((int *)taskpointerarray)[0]=tpd->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);
#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<s->___count___;i++) {
- short s= ((short *)(((char *)& chararray->___length___)+sizeof(int)))[i+offset];
- putchar(s);
+ int offset=VAR(___s___)->___offset___;
+ for(i=0;i<VAR(___s___)->___count___;i++) {
+ short sc=((short *)(((char *)& chararray->___length___)+sizeof(int)))[i+offset];
+ putchar(sc);
}
}
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"
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;
}
/* 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);
}
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)
}
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);
}
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
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