/** This method returns a set of LocalityBindings for the parameter class. */
-
public Set<LocalityBinding> getClassBindings(ClassDescriptor cd) {
return classtolb.get(cd);
}
private void computeLocalityBindings() {
lbmain=new LocalityBinding(typeutil.getMain(), false);
+ lbmain.setGlobalReturn(EITHER);
lbmain.setGlobal(0, LOCAL);
lbtovisit.add(lbmain);
discovered.put(lbmain, lbmain);
methodtolb.put(lbmain.getMethod(), new HashSet<LocalityBinding>());
methodtolb.get(lbmain.getMethod()).add(lbmain);
+ //Do this to force a virtual table number for the run method
+ LocalityBinding lbrun=new LocalityBinding(typeutil.getRun(), false);
+ lbrun.setGlobalReturn(EITHER);
+ lbrun.setGlobalThis(GLOBAL);
+ lbtovisit.add(lbrun);
+ discovered.put(lbrun, lbrun);
+ if (!classtolb.containsKey(lbrun.getMethod().getClassDesc()))
+ classtolb.put(lbrun.getMethod().getClassDesc(), new HashSet<LocalityBinding>());
+ classtolb.get(lbrun.getMethod().getClassDesc()).add(lbrun);
+
+ if (!methodtolb.containsKey(lbrun.getMethod()))
+ methodtolb.put(lbrun.getMethod(), new HashSet<LocalityBinding>());
+ methodtolb.get(lbrun.getMethod()).add(lbrun);
+
while(!lbtovisit.empty()) {
LocalityBinding lb=(LocalityBinding) lbtovisit.pop();
Integer returnglobal=lb.getGlobalReturn();
atomictab.put(lb, atomictable);
temptab.put(lb, temptable);
- if (!md.isStatic()&&!returnglobal.equals(lb.getGlobalReturn())) {
+ if (md.getReturnType()!=null&&!returnglobal.equals(lb.getGlobalReturn())) {
//return type is more precise now
//rerun everything that call us
lbtovisit.addAll(dependence.get(lb));
/* Output #defines that the runtime uses to determine type
* numbers for various objects it needs */
+ outstructs.println("#define MAXCOUNT "+maxcount);
+ if (state.DSM) {
+ LocalityBinding lb=new LocalityBinding(typeutil.getRun(), false);
+ lb.setGlobalThis(LocalityAnalysis.GLOBAL);
+ outstructs.println("#define RUNMETHOD "+virtualcalls.getLocalityNumber(lb));
+ }
outstructs.println("#define STRINGARRAYTYPE "+
(state.getArrayNumber(
return getClass(state.main);
}
+ public MethodDescriptor getRun() {
+ ClassDescriptor cd=getClass(TypeUtil.ThreadClass);
+ for(Iterator methodit=cd.getMethodTable().getSet("run").iterator();methodit.hasNext();) {
+ MethodDescriptor md=(MethodDescriptor) methodit.next();
+ if (md.numParameters()!=0||md.getModifiers().isStatic())
+ continue;
+ return md;
+ }
+ throw new Error("Can't find Thread.run");
+ }
+
public MethodDescriptor getMain() {
ClassDescriptor cd=getMainClass();
Set mainset=cd.getMethodTable().getSet("main");
#include "dstm.h"
#include "mlookup.h"
#include "llookup.h"
+#ifdef COMPILER
+#include "thread.h"
+#endif
+
#define LISTEN_PORT 2156
#define BACKLOG 10 //max pending connections
printf("dstmAccept(): received START_REMOTE_THREAD msg, oid=0x%x\n", oid);
objType = getObjType(oid);
printf("dstmAccept(): type of object 0x%x is %d\n", oid, objType);
+ startDSMthread(oid, objType);
+
+
}
break;
startRemoteThread((unsigned int)VAR(___this___), ___mid___);
}
#endif
+
+#ifdef DSTM
+void initDSMthread(int *ptr) {
+ int oid=ptr[0];
+ int type=ptr[1];
+ free(ptr);
+#ifdef PRECISE_GC
+ int p[]={1, 0 /* NULL */, oid};
+ ((void (*)(void *))virtualtable[type*MAXCOUNT+RUNMETHOD])(p);
+#else
+ ((void (*)(void *))virtualtable[type*MAXCOUNT+RUNMETHOD])(oid);
+#endif
+ pthread_mutex_lock(&gclistlock);
+ threadcount--;
+ pthread_cond_signal(&gccond);
+ pthread_mutex_unlock(&gclistlock);
+}
+
+void startDSMthread(int oid, int objType) {
+ pthread_t thread;
+ int retval;
+ pthread_attr_t nattr;
+
+ pthread_mutex_lock(&gclistlock);
+ threadcount++;
+ pthread_mutex_unlock(&gclistlock);
+ pthread_attr_init(&nattr);
+ pthread_attr_setdetachstate(&nattr, PTHREAD_CREATE_DETACHED);
+ int * ptr=malloc(sizeof(int)*2);
+ ptr[0]=oid;
+ ptr[1]=objType;
+ do {
+ retval=pthread_create(&thread, &nattr, (void * (*)(void *)) &initDSMthread, ptr);
+ if (retval!=0)
+ usleep(1);
+ } while(retval!=0);
+
+ pthread_attr_destroy(&nattr);
+}
+
+#endif
extern pthread_mutex_t objlock;
extern pthread_cond_t objcond;
extern pthread_key_t threadlocks;
+#ifdef THREADS
void initthread(struct ___Thread___ * ___this___);
+#endif
+#ifdef DSTM
+void initDSMthread(int *ptr);
+void startDSMthread(int oid, int objType);
+extern void * virtualtable[];
+#endif
struct locklist {
struct locklist * next;