// Output the C class declarations
// These could mutually reference each other
+ if (state.THREAD)
+ outclassdefs.println("#include <pthread.h>");
+
outclassdefs.println("struct "+arraytype+";");
Iterator it=state.getClassSymbolTable().getDescriptorsIterator();
//Print out definition for array type
outclassdefs.println("struct "+arraytype+" {");
outclassdefs.println(" int type;");
- outclassdefs.println(" int flag;");
+ if (state.THREAD) {
+ outclassdefs.println(" pthread_t tid;");
+ outclassdefs.println(" int lockcount;");
+ }
if (state.TASK) {
+ outclassdefs.println(" int flag;");
outclassdefs.println(" void * flagptr;");
}
printClassStruct(typeutil.getClass(TypeUtil.ObjectClass), outclassdefs);
break;
}
if (state.THREAD) {
- outmethod.println("pthread_mutex_lock(&threadtable);");
- outmethod.println("threadcount--;");
- outmethod.println("pthread_mutex_unlock(&threadtable);");
outmethod.println("pthread_mutex_lock(&gclistlock);");
+ outmethod.println("threadcount--;");
outmethod.println("pthread_cond_signal(&gccond);");
outmethod.println("pthread_mutex_unlock(&gclistlock);");
outmethod.println("pthread_exit(NULL);");
/* Output class structure */
classdefout.println("struct "+cn.getSafeSymbol()+" {");
classdefout.println(" int type;");
- classdefout.println(" int flag;");
+ if (state.THREAD) {
+ classdefout.println(" pthread_t tid;");
+ classdefout.println(" int lockcount;");
+ }
if (state.TASK) {
+ classdefout.println(" int flag;");
classdefout.println(" void * flagptr;");
}
printClassStruct(cn, classdefout);
public class BuildFlat {
State state;
Hashtable temptovar;
+ MethodDescriptor currmd;
+ TypeUtil typeutil;
- public BuildFlat(State st) {
+ public BuildFlat(State st, TypeUtil typeutil) {
state=st;
temptovar=new Hashtable();
+ this.typeutil=typeutil;
}
public Hashtable getMap() {
private void flattenClass(ClassDescriptor cn) {
Iterator methodit=cn.getMethods();
while(methodit.hasNext()) {
- MethodDescriptor md=(MethodDescriptor)methodit.next();
- BlockNode bn=state.getMethodBody(md);
- FlatNode fn=flattenBlockNode(bn).getBegin();
- FlatMethod fm=new FlatMethod(md, fn);
- if (!md.isStatic())
- fm.addParameterTemp(getTempforParam(md.getThis()));
- for(int i=0;i<md.numParameters();i++) {
- fm.addParameterTemp(getTempforParam(md.getParameter(i)));
+ currmd=(MethodDescriptor)methodit.next();
+ BlockNode bn=state.getMethodBody(currmd);
+ NodePair np=flattenBlockNode(bn);
+ FlatNode fn=np.getBegin();
+ if (state.THREAD&&currmd.getModifiers().isSynchronized()) {
+ MethodDescriptor memd=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorEnter");
+ TempDescriptor thistd=getTempforVar(currmd.getThis());
+ FlatCall fc=new FlatCall(memd, null, thistd, new TempDescriptor[0]);
+ fc.addNext(fn);
+ fn=fc;
+ if (np.getEnd().kind()!=FKind.FlatReturnNode) {
+ MethodDescriptor memdex=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorExit");
+ FlatCall fcunlock=new FlatCall(memdex, null, thistd, new TempDescriptor[0]);
+ np.getEnd().addNext(fcunlock);
+ }
+ }
+
+ FlatMethod fm=new FlatMethod(currmd, fn);
+ if (!currmd.isStatic())
+ fm.addParameterTemp(getTempforParam(currmd.getThis()));
+ for(int i=0;i<currmd.numParameters();i++) {
+ fm.addParameterTemp(getTempforParam(currmd.getParameter(i)));
}
- state.addFlatCode(md,fm);
+ state.addFlatCode(currmd,fm);
}
}
}
FlatReturnNode rnflat=new FlatReturnNode(retval);
+ FlatNode ln=rnflat;
+ if (state.THREAD&&currmd.getModifiers().isSynchronized()) {
+ MethodDescriptor memd=(MethodDescriptor)typeutil.getClass("Object").getMethodTable().get("MonitorExit");
+ TempDescriptor thistd=getTempforVar(currmd.getThis());
+ FlatCall fc=new FlatCall(memd, null, thistd, new TempDescriptor[0]);
+ fc.addNext(rnflat);
+ ln=fc;
+ }
if (cond!=null) {
- cond.getEnd().addNext(rnflat);
+ cond.getEnd().addNext(ln);
return new NodePair(cond.getBegin(),rnflat);
} else
- return new NodePair(rnflat,rnflat);
+ return new NodePair(ln,rnflat);
}
private NodePair flattenTaskExitNode(TaskExitNode ten) {
ParseNode modn=pnv.elementAt(i);
if (isNode(modn,"public"))
m.addModifier(Modifiers.PUBLIC);
- if (isNode(modn,"protected"))
+ else if (isNode(modn,"protected"))
m.addModifier(Modifiers.PROTECTED);
- if (isNode(modn,"private"))
+ else if (isNode(modn,"private"))
m.addModifier(Modifiers.PRIVATE);
- if (isNode(modn,"static"))
+ else if (isNode(modn,"static"))
m.addModifier(Modifiers.STATIC);
- if (isNode(modn,"final"))
+ else if (isNode(modn,"final"))
m.addModifier(Modifiers.FINAL);
- if (isNode(modn,"native"))
+ else if (isNode(modn,"native"))
m.addModifier(Modifiers.NATIVE);
+ else if (isNode(modn,"synchronized"))
+ m.addModifier(Modifiers.SYNCHRONIZED);
+ else throw new Error("Unrecognized Modifier");
}
}
return m;
// ABSTRACT=16
public static final int FINAL=32;
public static final int NATIVE=64;
-// SYNCHRONIZED=128
+ public static final int SYNCHRONIZED=128;
// TRANSIENT=256
// VOLATILE=512
// STRICTFP=1024
public void addModifier(int mod) {
value|=mod;
+ if (isSynchronized()&&isNative())
+ throw new Error("Synchronized native methods are not supported");
+ }
+
+ public boolean isSynchronized() {
+ return ((value&SYNCHRONIZED)!=0);
}
public boolean isStatic() {
st+="final ";
if ((value&NATIVE)!=0)
st+="native ";
+ if ((value&SYNCHRONIZED)!=0)
+ st+="synchronized ";
return st;
}
}
switch(op.getOp()) {
case Operation.LOGIC_OR:
case Operation.LOGIC_AND:
- if (!(ltd.isBoolean()&&rtd.isBoolean()))
+ if (!(rtd.isBoolean()))
+ throw new Error();
+ on.setRightType(rtd);
+ case Operation.LOGIC_NOT:
+ if (!(ltd.isBoolean()))
throw new Error();
//no promotion
on.setLeftType(ltd);
- on.setRightType(rtd);
+
on.setType(new TypeDescriptor(TypeDescriptor.BOOLEAN));
break;
on.setType(lefttype);
break;
default:
- throw new Error();
+ throw new Error(op.toString());
}
if (td!=null)
}
}
- readSourceFile(state, ClassLibraryPrefix+"Object.java");
+
readSourceFile(state, ClassLibraryPrefix+"System.java");
readSourceFile(state, ClassLibraryPrefix+"String.java");
readSourceFile(state, ClassLibraryPrefix+"HashSet.java");
readSourceFile(state, ClassLibraryPrefix+"FileOutputStream.java");
readSourceFile(state, ClassLibraryPrefix+"File.java");
if (state.TASK) {
+ readSourceFile(state, ClassLibraryPrefix+"Object.java");
readSourceFile(state, ClassLibraryPrefix+"StartupObject.java");
readSourceFile(state, ClassLibraryPrefix+"Socket.java");
readSourceFile(state, ClassLibraryPrefix+"ServerSocket.java");
} else {
+ readSourceFile(state, ClassLibraryPrefix+"ObjectJava.java");
readSourceFile(state, ClassLibraryPrefix+"SocketJava.java");
readSourceFile(state, ClassLibraryPrefix+"ServerSocketJava.java");
}
sc.semanticCheck();
tu.createFullTable();
- BuildFlat bf=new BuildFlat(state);
+ BuildFlat bf=new BuildFlat(state,tu);
bf.buildFlat();
BuildCode bc=new BuildCode(state, bf.getMap(), tu);
STATIC {: RESULT=new ParseNode("static"); :} |
// ABSTRACT |
FINAL {: RESULT=new ParseNode("final"); :}|
- NATIVE {: RESULT=new ParseNode("native"); :}
-// SYNCHRONIZED |
+ NATIVE {: RESULT=new ParseNode("native"); :} |
+ SYNCHRONIZED {: RESULT=new ParseNode("synchronized"); :}
// TRANSIENT |
// VOLATILE |
// STRICTFP // note that semantic analysis must check that the
void collect(struct garbagelist * stackptr) {
#ifdef THREADS
needtocollect=1;
+ pthread_mutex_lock(&gclistlock);
while(1) {
- pthread_mutex_lock(&gclistlock);
- pthread_mutex_lock(&threadtable);
if ((listcount+1)==threadcount) {
- pthread_mutex_unlock(&threadtable);
- pthread_mutex_unlock(&gclistlock);
break; /* Have all other threads stopped */
}
- pthread_mutex_unlock(&threadtable);
pthread_cond_wait(&gccond, &gclistlock);
- pthread_mutex_unlock(&gclistlock);
}
#endif
}
#ifdef THREADS
needtocollect=0;
+ pthread_mutex_unlock(&gclistlock);
#endif
}
void checkcollect(void * ptr) {
if (needtocollect) {
struct listitem * tmp=stopforgc((struct garbagelist *)ptr);
- pthread_mutex_lock(&gclock);
+ pthread_mutex_lock(&gclock); // Wait for GC
restartaftergc(tmp);
pthread_mutex_unlock(&gclock);
+
}
}
#endif
}
-int CALL01(___Object______hashCode____, struct ___Object___ * ___this___) {
- return (int) VAR(___this___);
-}
-
-int CALL01(___Object______getType____, struct ___Object___ * ___this___) {
- return ((int *)VAR(___this___))[0];
-}
-
void CALL01(___System______printString____L___String___,struct ___String___ * ___s___) {
struct ArrayObject * chararray=VAR(___s___)->___value___;
int i;
#ifdef PRECISE_GC
void * allocate_new(void * ptr, int type) {
- void * v=mygcmalloc((struct garbagelist *) ptr, classsize[type]);
- *((int *)v)=type;
+ struct ___Object___ * v=(struct ___Object___ *) mygcmalloc((struct garbagelist *) ptr, classsize[type]);
+ v->type=type;
+#ifdef THREADS
+ v->tid=0;
+ v->lockcount=0;
+#endif
return v;
}
struct ArrayObject * v=mygcmalloc((struct garbagelist *) ptr, sizeof(struct ArrayObject)+length*classsize[type]);
v->type=type;
v->___length___=length;
+#ifdef THREADS
+ v->tid=0;
+ v->lockcount=0;
+#endif
return v;
}
#include <stdio.h>
-pthread_mutex_t threadtable;
int threadcount;
pthread_mutex_t gclock;
pthread_mutex_t gclistlock;
pthread_cond_t gccond;
+pthread_mutex_t objlock;
+pthread_cond_t objcond;
void initializethreads() {
- pthread_mutex_init(&threadtable,NULL);
threadcount=1;
pthread_mutex_init(&gclock, NULL);
pthread_mutex_init(&gclistlock, NULL);
pthread_cond_init(&gccond, NULL);
+ pthread_mutex_init(&objlock,NULL);
+ pthread_cond_init(&objcond,NULL);
}
void initthread(struct ___Thread___ * ___this___) {
#else
___Thread______staticStart____L___Thread___(___this___);
#endif
- pthread_mutex_lock(&threadtable);
- threadcount--;
- pthread_mutex_unlock(&threadtable);
pthread_mutex_lock(&gclistlock);
+ threadcount--;
pthread_cond_signal(&gccond);
pthread_mutex_unlock(&gclistlock);
}
void CALL01(___Thread______nativeCreate____, struct ___Thread___ * ___this___) {
pthread_t thread;
- pthread_mutex_lock(&threadtable);
+ pthread_mutex_lock(&gclistlock);
threadcount++;
- pthread_mutex_unlock(&threadtable);
+ pthread_mutex_unlock(&gclistlock);
pthread_create(&thread, NULL,(void * (*)(void *)) &initthread, VAR(___this___));
}
#include "methodheaders.h"
#include "pthread.h"
-extern pthread_mutex_t threadtable;
extern int threadcount;
extern pthread_mutex_t gclock;
extern pthread_mutex_t gclistlock;
extern pthread_cond_t gccond;
+extern pthread_mutex_t objlock;
+extern pthread_cond_t objcond;
void initthread(struct ___Thread___ * ___this___);
#endif
FILES="$ROBUSTROOT/Runtime/runtime.c $ROBUSTROOT/Runtime/file.c \
$ROBUSTROOT/Runtime/Queue.c $ROBUSTROOT/Runtime/SimpleHash.c \
$ROBUSTROOT/Runtime/option.c $ROBUSTROOT/Runtime/garbage.c \
-$ROBUSTROOT/Runtime/socket.c $ROBUSTROOT/Runtime/GenericHashtable.c"
+$ROBUSTROOT/Runtime/socket.c $ROBUSTROOT/Runtime/GenericHashtable.c \
+$ROBUSTROOT/Runtime/object.c"
if $RECOVERFLAG
then