From 06cab2ad09187fae40348d1a1e73b71ffaaf4bbf Mon Sep 17 00:00:00 2001 From: bdemsky Date: Mon, 6 Apr 2009 06:58:59 +0000 Subject: [PATCH] get compiler side of STM working --- .../Locality/GenerateConversions.java | 38 ++- .../Analysis/Locality/LocalityAnalysis.java | 52 ++-- .../Analysis/Locality/LocalityBinding.java | 24 +- Robust/src/Analysis/Loops/CSE.java | 1 + .../src/Analysis/Loops/GlobalFieldType.java | 24 ++ Robust/src/Analysis/Loops/LoopInvariant.java | 19 +- Robust/src/Analysis/Loops/LoopOptimize.java | 5 +- Robust/src/Analysis/Loops/WriteBarrier.java | 4 +- Robust/src/ClassLibrary/Vector.java | 10 + Robust/src/IR/Flat/BuildCode.java | 255 ++++++++++++------ Robust/src/IR/Virtual.java | 4 +- Robust/src/Main/Main.java | 12 +- Robust/src/Makefile | 3 +- Robust/src/Runtime/DSTM/interface/STMIDEAS | 8 + Robust/src/Runtime/thread.c | 10 +- Robust/src/Tests/STM.java | 31 +++ Robust/src/Tests/STM2.java | 89 ++++++ Robust/src/Tests/dotest | 2 +- .../src/Tests/output/StringTest.output.goal | 3 + Robust/src/buildscript | 8 +- 20 files changed, 449 insertions(+), 153 deletions(-) create mode 100644 Robust/src/Runtime/DSTM/interface/STMIDEAS create mode 100644 Robust/src/Tests/STM.java create mode 100644 Robust/src/Tests/STM2.java diff --git a/Robust/src/Analysis/Locality/GenerateConversions.java b/Robust/src/Analysis/Locality/GenerateConversions.java index d241970d..408ce329 100644 --- a/Robust/src/Analysis/Locality/GenerateConversions.java +++ b/Robust/src/Analysis/Locality/GenerateConversions.java @@ -49,7 +49,7 @@ public class GenerateConversions { toprocess.remove(fn); boolean isatomic=atomictab.get(fn).intValue()>0; - Hashtable nodetemptab=temptab.get(fn); + Hashtable nodetemptab=state.DSM?temptab.get(fn):null; List reads=Arrays.asList(fn.readsTemps()); List writes=Arrays.asList(fn.writesTemps()); @@ -111,7 +111,12 @@ public class GenerateConversions { * locality. */ for(Iterator writeit=writes.iterator(); writeit.hasNext();) { TempDescriptor wrtmp=writeit.next(); - if (nodetemptab.get(wrtmp)==LocalityAnalysis.GLOBAL||state.SINGLETM) { + if (state.SINGLETM) { + if (wrtmp.getType().isPtr()) { + TempNodePair tnp=new TempNodePair(wrtmp); + tempset.add(tnp); + } + } else if (nodetemptab.get(wrtmp)==LocalityAnalysis.GLOBAL) { TempNodePair tnp=new TempNodePair(wrtmp); tempset.add(tnp); } @@ -140,7 +145,8 @@ public class GenerateConversions { TempDescriptor tmpd=tempit.next(); FlatGlobalConvNode fgcn=new FlatGlobalConvNode(tmpd, lb, false, nodetoconvs.get(fn).contains(tmpd)); atomictab.put(fgcn, atomictab.get(fn)); - temptab.put(fgcn, (Hashtable)temptab.get(fn).clone()); + if (state.DSM) + temptab.put(fgcn, (Hashtable)temptab.get(fn).clone()); for(int i=0; i pretemptab=locality.getNodePreTempInfo(lb, fn); - TempDescriptor [] readtemps=fn.readsTemps(); - for(int i=0; i pretemptab=locality.getNodePreTempInfo(lb, fn); + TempDescriptor [] readtemps=fn.readsTemps(); + for(int i=0; i tempit=tempset.iterator(); tempit.hasNext();) { FlatGlobalConvNode fgcn=new FlatGlobalConvNode(tempit.next(), lb, true); atomictab.put(fgcn, atomictab.get(fn)); - temptab.put(fgcn, (Hashtable)temptab.get(fn).clone()); + if (state.DSM) { + temptab.put(fgcn, (Hashtable)temptab.get(fn).clone()); + } fgcn.addNext(fn.getNext(0)); fn.setNext(0, fgcn); } diff --git a/Robust/src/Analysis/Locality/LocalityAnalysis.java b/Robust/src/Analysis/Locality/LocalityAnalysis.java index 6664af18..6376922c 100644 --- a/Robust/src/Analysis/Locality/LocalityAnalysis.java +++ b/Robust/src/Analysis/Locality/LocalityAnalysis.java @@ -55,18 +55,20 @@ public class LocalityAnalysis { public LocalityBinding getBinding(LocalityBinding currlb, FlatCall fc) { boolean isatomic=getAtomic(currlb).get(fc).intValue()>0; - Hashtable currtable=getNodePreTempInfo(currlb,fc); + Hashtable currtable=state.DSM?getNodePreTempInfo(currlb,fc):null; MethodDescriptor md=fc.getMethod(); boolean isnative=md.getModifiers().isNative(); LocalityBinding lb=new LocalityBinding(md, isatomic); - for(int i=0; i tovisit=new HashSet(); tovisit.add(fm.getNext(0)); - { - // Build table for initial node - Hashtable table=new Hashtable(); - atomictable.put(fm, lb.isAtomic() ? 1 : 0); - int offset=md.isStatic() ? 0 : 1; - if (!md.isStatic()) { - table.put(fm.getParameter(0), lb.getGlobalThis()); - } - for(int i=offset; i currtable=new Hashtable(); int atomicstate=0; for(int i=0; i run link if (nodemd.getClassDesc().getSymbol().equals(TypeUtil.ThreadClass)&& nodemd.getSymbol().equals("start")&&!nodemd.getModifiers().isStatic()&& - nodemd.numParameters()==1&&nodemd.getParamType(0).isInt()) { + nodemd.numParameters()==0) { assert(nodemd.getModifiers().isNative()); MethodDescriptor runmd=null; @@ -350,7 +346,6 @@ public class LocalityAnalysis { } } - Integer currreturnval=EITHER; //Start off with the either value for(Iterator methodit=methodset.iterator(); methodit.hasNext();) { MethodDescriptor md=(MethodDescriptor) methodit.next(); @@ -542,6 +537,7 @@ public class LocalityAnalysis { case FKind.FlatCondBranch: case FKind.FlatBackEdge: case FKind.FlatNop: + case FKind.FlatExit: case FKind.FlatPrefetchNode: //No action needed for these break; @@ -929,8 +925,14 @@ public class LocalityAnalysis { TempDescriptor tmp=tempit.next(); if (writes.contains(tmp)) { nodetosavetemps.get(atomicnode).add(tmp); - } else if (reads.contains(tmp)&&temptab.get(fn).get(tmp)==GLOBAL) { - nodetosavetemps.get(atomicnode).add(tmp); + } else if (state.DSM) { + if (reads.contains(tmp)&&temptab.get(fn).get(tmp)==GLOBAL) { + nodetosavetemps.get(atomicnode).add(tmp); + } + } else { + if (reads.contains(tmp)&&tmp.getType().isPtr()) { + nodetosavetemps.get(atomicnode).add(tmp); + } } } } diff --git a/Robust/src/Analysis/Locality/LocalityBinding.java b/Robust/src/Analysis/Locality/LocalityBinding.java index d10d9b28..7e1647a0 100644 --- a/Robust/src/Analysis/Locality/LocalityBinding.java +++ b/Robust/src/Analysis/Locality/LocalityBinding.java @@ -25,7 +25,9 @@ public class LocalityBinding { } private static String globalToString(Integer g) { - if (g==LocalityAnalysis.GLOBAL) + if (g==null) + return ""; + else if (g==LocalityAnalysis.GLOBAL) return "G"; else if (g==LocalityAnalysis.LOCAL) return "L"; @@ -141,6 +143,15 @@ public class LocalityBinding { return (isatomic==lb.isatomic); } + public static boolean equiv(Integer a, Integer b) { + if (a==null) { + return b==null; + } else if (b==null) { + //a is not null + return false; + } else return a.equals(b); + } + public boolean equals(Object o) { if (o instanceof LocalityBinding) { LocalityBinding lb=(LocalityBinding)o; @@ -148,14 +159,10 @@ public class LocalityBinding { return false; for(int i=0; i run link + MethodDescriptor runmd=null; + for(Iterator methodit=md.getClassDesc().getMethodTable().getSet("run").iterator(); methodit.hasNext();) { + MethodDescriptor mdrun=(MethodDescriptor) methodit.next(); + if (mdrun.numParameters()!=0||mdrun.getModifiers().isStatic()) + continue; + runmd=mdrun; + break; + } + if (runmd!=null) { + Set runmethodset=cg.getMethods(runmd); + for(Iterator it=runmethodset.iterator();it.hasNext();) { + MethodDescriptor md2=(MethodDescriptor)it.next(); + if (!discovered.contains(md2)) { + discovered.add(md2); + toprocess.add(md2); + } + } + } else throw new Error("Can't find run method"); + } } boolean changed=true; while(changed) { diff --git a/Robust/src/Analysis/Loops/LoopInvariant.java b/Robust/src/Analysis/Loops/LoopInvariant.java index 2afbc5b2..e130c3a6 100644 --- a/Robust/src/Analysis/Loops/LoopInvariant.java +++ b/Robust/src/Analysis/Loops/LoopInvariant.java @@ -1,6 +1,7 @@ package Analysis.Loops; import IR.Flat.*; +import IR.MethodDescriptor; import IR.FieldDescriptor; import IR.TypeDescriptor; import IR.TypeUtil; @@ -12,9 +13,11 @@ import java.util.Vector; import java.util.Hashtable; public class LoopInvariant { - public LoopInvariant(TypeUtil typeutil) { + public LoopInvariant(TypeUtil typeutil, GlobalFieldType gft) { this.typeutil=typeutil; + this.gft=gft; } + GlobalFieldType gft; LoopFinder loops; DomTree posttree; Hashtable> table; @@ -63,10 +66,20 @@ public class LoopInvariant { for(Iterator elit=elements.iterator();elit.hasNext();) { FlatNode fn=(FlatNode)elit.next(); if (fn.kind()==FKind.FlatAtomicEnterNode|| - fn.kind()==FKind.FlatAtomicExitNode|| - fn.kind()==FKind.FlatCall) { + fn.kind()==FKind.FlatAtomicExitNode) { unsafe=true; break; + } else if (fn.kind()==FKind.FlatCall) { + FlatCall fcall=(FlatCall)fn; + MethodDescriptor md=fcall.getMethod(); + Set f=gft.getFields(md); + Set t=gft.getArrays(md); + if (f!=null) + fields.addAll(f); + if (t!=null) + types.addAll(t); + if (gft.containsAtomic(md)) + unsafe=true; } else if (fn.kind()==FKind.FlatSetFieldNode) { FlatSetFieldNode fsfn=(FlatSetFieldNode)fn; fields.add(fsfn.getField()); diff --git a/Robust/src/Analysis/Loops/LoopOptimize.java b/Robust/src/Analysis/Loops/LoopOptimize.java index e8759189..84eeffc1 100644 --- a/Robust/src/Analysis/Loops/LoopOptimize.java +++ b/Robust/src/Analysis/Loops/LoopOptimize.java @@ -2,6 +2,7 @@ package Analysis.Loops; import IR.Flat.*; import IR.TypeUtil; +import IR.MethodDescriptor; import IR.Operation; import java.util.Set; import java.util.Vector; @@ -10,8 +11,8 @@ import java.util.Hashtable; public class LoopOptimize { LoopInvariant loopinv; - public LoopOptimize(TypeUtil typeutil) { - loopinv=new LoopInvariant(typeutil); + public LoopOptimize(GlobalFieldType gft, TypeUtil typeutil) { + loopinv=new LoopInvariant(typeutil,gft); } public void optimize(FlatMethod fm) { loopinv.analyze(fm); diff --git a/Robust/src/Analysis/Loops/WriteBarrier.java b/Robust/src/Analysis/Loops/WriteBarrier.java index fd69784c..7a933bff 100644 --- a/Robust/src/Analysis/Loops/WriteBarrier.java +++ b/Robust/src/Analysis/Loops/WriteBarrier.java @@ -44,8 +44,8 @@ public class WriteBarrier { HashSet toprocess=new HashSet(); HashSet discovered=new HashSet(); needbarrier=new Hashtable>(); - toprocess.add(fm); - discovered.add(fm); + toprocess.add(fm.getNext(0)); + discovered.add(fm.getNext(0)); Hashtable atomic=la.getAtomic(lb); while(!toprocess.isEmpty()) { diff --git a/Robust/src/ClassLibrary/Vector.java b/Robust/src/ClassLibrary/Vector.java index 5cd06ca6..2b11ee23 100644 --- a/Robust/src/ClassLibrary/Vector.java +++ b/Robust/src/ClassLibrary/Vector.java @@ -32,6 +32,16 @@ public class Vector { return -1; } + public boolean contains(Object e) { + return indexOf(e)!=-1; + } + + public void remove(Object o) { + int in=indexOf(o); + if (in!=-1) + removeElementAt(in); + } + public Object elementAt(int index) { if (index<0 || index >=size) { System.printString("Illegal Vector.elementAt\n"); diff --git a/Robust/src/IR/Flat/BuildCode.java b/Robust/src/IR/Flat/BuildCode.java index 576b3872..141a899d 100644 --- a/Robust/src/IR/Flat/BuildCode.java +++ b/Robust/src/IR/Flat/BuildCode.java @@ -18,7 +18,7 @@ import Analysis.TaskStateAnalysis.TaskIndex; import Analysis.Locality.LocalityAnalysis; import Analysis.Locality.LocalityBinding; import Analysis.Prefetch.*; - +import Analysis.Loops.WriteBarrier; public class BuildCode { State state; @@ -46,10 +46,11 @@ public class BuildCode { ClassDescriptor[] cdarray; TypeDescriptor[] arraytable; LocalityAnalysis locality; - Hashtable backuptable; Hashtable reverttable; + Hashtable> backuptable; SafetyAnalysis sa; PrefetchAnalysis pa; + WriteBarrier wb; public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, SafetyAnalysis sa, PrefetchAnalysis pa) { this(st, temptovar, typeutil, null, sa, pa); @@ -72,8 +73,9 @@ public class BuildCode { virtualcalls=new Virtual(state,locality); if (locality!=null) { this.locality=locality; - this.backuptable=new Hashtable(); this.reverttable=new Hashtable(); + this.backuptable=new Hashtable>(); + this.wb=new WriteBarrier(locality, st); } this.MLP=st.MLP; @@ -127,6 +129,8 @@ public class BuildCode { outmethodheader.println("#include \"structdefs.h\""); if (state.DSM) outmethodheader.println("#include \"dstm.h\""); + if (state.SINGLETM) + outmethodheader.println("#include \"tm.h\""); if (state.ABORTREADERS) { outmethodheader.println("#include \"abortreaders.h\""); outmethodheader.println("#include "); @@ -208,7 +212,7 @@ public class BuildCode { outmethod.println("#ifdef TRANSSTATS \n"); outmethod.println("handle();\n"); outmethod.println("#endif\n"); - if (state.THREAD||state.DSM) { + if (state.THREAD||state.DSM||state.SINGLETM) { outmethod.println("initializethreads();"); } if (state.DSM) { @@ -247,17 +251,17 @@ public class BuildCode { outmethod.println(" {"); if (GENERATEPRECISEGC) { - if (state.DSM) { + if (state.DSM||state.SINGLETM) { outmethod.print(" struct "+cd.getSafeSymbol()+locality.getMain().getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={"); } else outmethod.print(" struct "+cd.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={"); outmethod.println("1, NULL,"+"stringarray};"); - if (state.DSM) + if (state.DSM||state.SINGLETM) outmethod.println(" "+cd.getSafeSymbol()+locality.getMain().getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(& __parameterlist__);"); else outmethod.println(" "+cd.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(& __parameterlist__);"); } else { - if (state.DSM) + if (state.DSM||state.SINGLETM) outmethod.println(" "+cd.getSafeSymbol()+locality.getMain().getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(stringarray);"); else outmethod.println(" "+cd.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(stringarray);"); @@ -268,27 +272,29 @@ public class BuildCode { outmethod.println("}"); } - if (state.THREAD||state.DSM) { + if (state.THREAD||state.DSM||state.SINGLETM) { outmethod.println("pthread_mutex_lock(&gclistlock);"); outmethod.println("threadcount--;"); outmethod.println("pthread_cond_signal(&gccond);"); outmethod.println("pthread_mutex_unlock(&gclistlock);"); - if (state.THREAD) + if (state.THREAD||state.SINGLETM) outmethod.println("pthread_exit(NULL);"); } - outmethod.println("#ifdef TRANSSTATS \n"); - outmethod.println("printf(\"****** Transaction Stats ******\\n\");"); - outmethod.println("printf(\"numTransAbort= %d\\n\", numTransAbort);"); - outmethod.println("printf(\"numTransCommit= %d\\n\", numTransCommit);"); - outmethod.println("printf(\"nchashSearch= %d\\n\", nchashSearch);"); - outmethod.println("printf(\"nmhashSearch= %d\\n\", nmhashSearch);"); - outmethod.println("printf(\"nprehashSearch= %d\\n\", nprehashSearch);"); - outmethod.println("printf(\"nRemoteReadSend= %d\\n\", nRemoteSend);"); - outmethod.println("printf(\"nSoftAbort= %d\\n\", nSoftAbort);"); - outmethod.println("printf(\"bytesSent= %d\\n\", bytesSent);"); - outmethod.println("printf(\"bytesRecv= %d\\n\", bytesRecv);"); - outmethod.println("#endif\n"); + if (state.DSM||state.SINGLETM) { + outmethod.println("#ifdef TRANSSTATS \n"); + outmethod.println("printf(\"****** Transaction Stats ******\\n\");"); + outmethod.println("printf(\"numTransAbort= %d\\n\", numTransAbort);"); + outmethod.println("printf(\"numTransCommit= %d\\n\", numTransCommit);"); + outmethod.println("printf(\"nchashSearch= %d\\n\", nchashSearch);"); + outmethod.println("printf(\"nmhashSearch= %d\\n\", nmhashSearch);"); + outmethod.println("printf(\"nprehashSearch= %d\\n\", nprehashSearch);"); + outmethod.println("printf(\"nRemoteReadSend= %d\\n\", nRemoteSend);"); + outmethod.println("printf(\"nSoftAbort= %d\\n\", nSoftAbort);"); + outmethod.println("printf(\"bytesSent= %d\\n\", bytesSent);"); + outmethod.println("printf(\"bytesRecv= %d\\n\", bytesRecv);"); + outmethod.println("#endif\n"); + } outmethod.println("}"); } @@ -343,7 +349,7 @@ public class BuildCode { if(state.MULTICORE) { outmethod.println("#include \"task.h\""); } - if (state.THREAD||state.DSM) + if (state.THREAD||state.DSM||state.SINGLETM) outmethod.println("#include "); if (state.main!=null) { outmethod.println("#include "); @@ -365,11 +371,12 @@ public class BuildCode { generateLayoutStructs(outmethod); /* Generate code for methods */ - if (state.DSM) { + if (state.DSM||state.SINGLETM) { for(Iterator lbit=locality.getLocalityBindings().iterator(); lbit.hasNext();) { LocalityBinding lb=lbit.next(); MethodDescriptor md=lb.getMethod(); FlatMethod fm=state.getMethodFlat(md); + wb.analyze(lb); if (!md.getModifiers().isNative()) { generateFlatMethod(fm, lb, outmethod); } @@ -399,9 +406,10 @@ public class BuildCode { /* Output #defines that the runtime uses to determine type * numbers for various objects it needs */ outstructs.println("#define MAXCOUNT "+maxcount); - if (state.DSM) { + if (state.DSM||state.SINGLETM) { LocalityBinding lb=new LocalityBinding(typeutil.getRun(), false); - lb.setGlobalThis(LocalityAnalysis.GLOBAL); + if (state.DSM) + lb.setGlobalThis(LocalityAnalysis.GLOBAL); outstructs.println("#define RUNMETHOD "+virtualcalls.getLocalityNumber(lb)); } @@ -434,7 +442,7 @@ public class BuildCode { } protected void outputClassDeclarations(PrintWriter outclassdefs) { - if (state.THREAD||state.DSM) + if (state.THREAD||state.DSM||state.SINGLETM) outclassdefs.println("#include "); if(state.OPTIONAL) outclassdefs.println("#include \"optionalstruct.h\""); @@ -663,7 +671,7 @@ public class BuildCode { } MethodDescriptor[][] virtualtable=null; LocalityBinding[][] lbvirtualtable=null; - if (state.DSM) + if (state.DSM||state.SINGLETM) lbvirtualtable=new LocalityBinding[state.numClasses()+state.numArrays()][maxcount]; else virtualtable=new MethodDescriptor[state.numClasses()+state.numArrays()][maxcount]; @@ -672,7 +680,7 @@ public class BuildCode { classit=state.getClassSymbolTable().getDescriptorsIterator(); while(classit.hasNext()) { ClassDescriptor cd=(ClassDescriptor)classit.next(); - if (state.DSM) + if (state.DSM||state.SINGLETM) fillinRow(cd, lbvirtualtable, cd.getId()); else fillinRow(cd, virtualtable, cd.getId()); @@ -683,7 +691,7 @@ public class BuildCode { while(arrayit.hasNext()) { TypeDescriptor td=(TypeDescriptor)arrayit.next(); int id=state.getArrayNumber(td); - if (state.DSM) + if (state.DSM||state.SINGLETM) fillinRow(objectcd, lbvirtualtable, id+state.numClasses()); else fillinRow(objectcd, virtualtable, id+state.numClasses()); @@ -695,11 +703,11 @@ public class BuildCode { for(int j=0; j saveset=lb!=null ? locality.getTempSet(lb) : null; ParamsObject objectparams=md!=null ? new ParamsObject(md,tag++) : new ParamsObject(task, tag++); - - if (lb!=null) + if (lb!=null) { paramstable.put(lb, objectparams); + backuptable.put(lb, new Hashtable()); + } else if (md!=null) paramstable.put(md, objectparams); else @@ -906,7 +915,7 @@ public class BuildCode { else objectparams.addPrim(temp); if(lb!=null&&saveset.contains(temp)) { - backuptable.put(temp, temp.createNew()); + backuptable.get(lb).put(temp, temp.createNew()); } } @@ -937,14 +946,14 @@ public class BuildCode { else objecttemps.addPrim(temp); if(lb!=null&&saveset.contains(temp)&& - !backuptable.containsKey(temp)) - backuptable.put(temp, temp.createNew()); + !backuptable.get(lb).containsKey(temp)) + backuptable.get(lb).put(temp, temp.createNew()); } } /* Create backup temps */ if (lb!=null) { - for(Iterator tmpit=backuptable.values().iterator(); tmpit.hasNext();) { + for(Iterator tmpit=backuptable.get(lb).values().iterator(); tmpit.hasNext();) { TempDescriptor tmp=tmpit.next(); TypeDescriptor type=tmp.getType(); if (type.isPtr()&&GENERATEPRECISEGC) @@ -953,7 +962,7 @@ public class BuildCode { objecttemps.addPrim(tmp); } /* Create temp to hold revert table */ - if (lb.getHasAtomic()||lb.isAtomic()) { + if (state.DSM&&(lb.getHasAtomic()||lb.isAtomic())) { TempDescriptor reverttmp=new TempDescriptor("revertlist", typeutil.getClass(TypeUtil.ObjectClass)); if (GENERATEPRECISEGC) objecttemps.addPtr(reverttmp); @@ -1155,7 +1164,7 @@ public class BuildCode { printClassStruct(cn, classdefout); classdefout.println("};\n"); - if (state.DSM) { + if (state.DSM||state.SINGLETM) { /* Cycle through LocalityBindings */ HashSet nativemethods=new HashSet(); Set lbset=locality.getClassBindings(cn); @@ -1196,7 +1205,7 @@ public class BuildCode { /* Output parameter structure */ if (GENERATEPRECISEGC) { ParamsObject objectparams=(ParamsObject) paramstable.get(lb!=null ? lb : md); - if (state.DSM&&lb!=null) + if ((state.DSM||state.SINGLETM)&&lb!=null) output.println("struct "+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params {"); else output.println("struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params {"); @@ -1222,7 +1231,7 @@ public class BuildCode { /* Output temp structure */ if (GENERATEPRECISEGC) { - if (state.DSM) + if (state.DSM||state.SINGLETM) output.println("struct "+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals {"); else output.println("struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals {"); @@ -1251,14 +1260,14 @@ public class BuildCode { headersout.print("void "); /* Next the method name */ - if (state.DSM) { + if (state.DSM||state.SINGLETM) { headersout.print(cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"("); } else headersout.print(cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"("); boolean printcomma=false; if (GENERATEPRECISEGC) { - if (state.DSM) { + if (state.DSM||state.SINGLETM) { headersout.print("struct "+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params * "+paramsprefix); } else headersout.print("struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params * "+paramsprefix); @@ -1360,9 +1369,9 @@ public class BuildCode { TempObject objecttemp=(TempObject) tempstable.get(lb!=null ? lb : md!=null ? md : task); if (GENERATEPRECISEGC) { - if (md!=null&&state.DSM) + if (md!=null&&(state.DSM||state.SINGLETM)) output.print(" struct "+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals "+localsprefix+"={"); - else if (md!=null&&!state.DSM) + else if (md!=null&&!(state.DSM||state.SINGLETM)) output.print(" struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals "+localsprefix+"={"); else output.print(" struct "+task.getSafeSymbol()+"_locals "+localsprefix+"={"); @@ -1392,7 +1401,7 @@ public class BuildCode { /* Check to see if we need to do a GC if this is a * multi-threaded program...*/ - if ((state.THREAD||state.DSM)&&GENERATEPRECISEGC) { + if ((state.THREAD||state.DSM||state.SINGLETM)&&GENERATEPRECISEGC) { if (state.DSM&&lb.isAtomic()) output.println("if (needtocollect) checkcollect2(&"+localsprefix+");"); else @@ -1415,7 +1424,7 @@ public class BuildCode { if (nodetolabel.containsKey(current_node)) output.println("L"+nodetolabel.get(current_node)+":"); if (state.INSTRUCTIONFAILURE) { - if (state.THREAD||state.DSM) { + if (state.THREAD||state.DSM||state.SINGLETM) { output.println("if ((++instructioncount)>failurecount) {instructioncount=0;injectinstructionfailure();}"); } else output.println("if ((--instructioncount)==0) injectinstructionfailure();"); @@ -1491,7 +1500,6 @@ public class BuildCode { MethodDescriptor md=fm.getMethod(); TaskDescriptor task=fm.getTask(); TempObject objecttemps=(TempObject) tempstable.get(lb!=null ? lb : md!=null ? md : task); - if (objecttemps.isLocalPrim(td)||objecttemps.isParamPrim(td)) { //System.out.println("generateTemp returns " + td.getSafeSymbol()); return td.getSafeSymbol(); @@ -1586,7 +1594,7 @@ public class BuildCode { return; case FKind.FlatBackEdge: - if ((state.THREAD||state.DSM)&&GENERATEPRECISEGC) { + if ((state.THREAD||state.DSM||state.SINGLETM)&&GENERATEPRECISEGC) { if(state.DSM&&locality.getAtomic(lb).get(fn).intValue()>0) { output.println("if (needtocollect) checkcollect2(&"+localsprefix+");"); } else @@ -1825,7 +1833,7 @@ public class BuildCode { /* Backup the temps. */ for(Iterator tmpit=locality.getTemps(lb).get(faen).iterator(); tmpit.hasNext();) { TempDescriptor tmp=tmpit.next(); - output.println(generateTemp(fm, backuptable.get(tmp),lb)+"="+generateTemp(fm,tmp,lb)+";"); + output.println(generateTemp(fm, backuptable.get(lb).get(tmp),lb)+"="+generateTemp(fm,tmp,lb)+";"); } output.println("goto transstart"+faen.getIdentifier()+";"); @@ -1836,19 +1844,20 @@ public class BuildCode { /* Restore temps */ for(Iterator tmpit=locality.getTemps(lb).get(faen).iterator(); tmpit.hasNext();) { TempDescriptor tmp=tmpit.next(); - output.println(generateTemp(fm, tmp,lb)+"="+generateTemp(fm,backuptable.get(tmp),lb)+";"); + output.println(generateTemp(fm, tmp,lb)+"="+generateTemp(fm,backuptable.get(lb).get(tmp),lb)+";"); } - /********* Need to revert local object store ********/ - String revertptr=generateTemp(fm, reverttable.get(lb),lb); - - output.println("while ("+revertptr+") {"); - output.println("struct ___Object___ * tmpptr;"); - output.println("tmpptr="+revertptr+"->"+nextobjstr+";"); - output.println("REVERT_OBJ("+revertptr+");"); - output.println(revertptr+"=tmpptr;"); - output.println("}"); - + if (state.DSM) { + /********* Need to revert local object store ********/ + String revertptr=generateTemp(fm, reverttable.get(lb),lb); + + output.println("while ("+revertptr+") {"); + output.println("struct ___Object___ * tmpptr;"); + output.println("tmpptr="+revertptr+"->"+nextobjstr+";"); + output.println("REVERT_OBJ("+revertptr+");"); + output.println(revertptr+"=tmpptr;"); + output.println("}"); + } /******* Tell the runtime to start the transaction *******/ output.println("transstart"+faen.getIdentifier()+":"); @@ -1865,19 +1874,24 @@ public class BuildCode { if (locality.getAtomic(lb).get(faen).intValue()>0) return; //store the revert list before we lose the transaction object - String revertptr=generateTemp(fm, reverttable.get(lb),lb); - output.println(revertptr+"=revertlist;"); + String revertptr=null; + if (state.DSM) { + revertptr=generateTemp(fm, reverttable.get(lb),lb); + output.println(revertptr+"=revertlist;"); + } output.println("if (transCommit()) {"); /* Transaction aborts if it returns true */ output.println("goto transretry"+faen.getAtomicEnter().getIdentifier()+";"); - output.println("} else {"); + if (state.DSM) { + output.println("} else {"); /* Need to commit local object store */ - output.println("while ("+revertptr+") {"); - output.println("struct ___Object___ * tmpptr;"); - output.println("tmpptr="+revertptr+"->"+nextobjstr+";"); - output.println("COMMIT_OBJ("+revertptr+");"); - output.println(revertptr+"=tmpptr;"); - output.println("}"); + output.println("while ("+revertptr+") {"); + output.println("struct ___Object___ * tmpptr;"); + output.println("tmpptr="+revertptr+"->"+nextobjstr+";"); + output.println("COMMIT_OBJ("+revertptr+");"); + output.println(revertptr+"=tmpptr;"); + output.println("}"); + } output.println("}"); } @@ -1915,11 +1929,11 @@ public class BuildCode { private void generateFlatCall(FlatMethod fm, LocalityBinding lb, FlatCall fc, PrintWriter output) { MethodDescriptor md=fc.getMethod(); - ParamsObject objectparams=(ParamsObject)paramstable.get(state.DSM ? locality.getBinding(lb, fc) : md); + ParamsObject objectparams=(ParamsObject)paramstable.get(state.DSM||state.SINGLETM ? locality.getBinding(lb, fc) : md); ClassDescriptor cn=md.getClassDesc(); output.println("{"); if (GENERATEPRECISEGC) { - if (state.DSM) { + if (state.DSM||state.SINGLETM) { LocalityBinding fclb=locality.getBinding(lb, fc); output.print(" struct "+cn.getSafeSymbol()+fclb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={"); } else @@ -1961,7 +1975,7 @@ public class BuildCode { /* Do we need to do virtual dispatch? */ if (md.isStatic()||md.getReturnType()==null||singleCall(fc.getThis().getType().getClassDesc(),md)) { //no - if (state.DSM) { + if (state.DSM||state.SINGLETM) { LocalityBinding fclb=locality.getBinding(lb, fc); output.print(cn.getSafeSymbol()+fclb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()); } else { @@ -1978,7 +1992,7 @@ public class BuildCode { boolean printcomma=false; if (GENERATEPRECISEGC) { - if (state.DSM) { + if (state.DSM||state.SINGLETM) { LocalityBinding fclb=locality.getBinding(lb, fc); output.print("struct "+cn.getSafeSymbol()+fclb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params * "); } else @@ -1998,7 +2012,7 @@ public class BuildCode { } - if (state.DSM) { + if (state.DSM||state.SINGLETM) { LocalityBinding fclb=locality.getBinding(lb, fc); output.print("))virtualtable["+generateTemp(fm,fc.getThis(),lb)+"->type*"+maxcount+"+"+virtualcalls.getLocalityNumber(fclb)+"])"); } else @@ -2060,7 +2074,17 @@ public class BuildCode { } private void generateFlatFieldNode(FlatMethod fm, LocalityBinding lb, FlatFieldNode ffn, PrintWriter output) { - if (state.DSM) { + if (state.SINGLETM) { + //single machine transactional memory case + String field=ffn.getField().getSafeSymbol(); + String src=generateTemp(fm, ffn.getSrc(),lb); + String dst=generateTemp(fm, ffn.getDst(),lb); + + output.println(dst+"="+ src +"->"+field+ ";"); + if (ffn.getField().getType().isPtr()) { + output.println("TRANSREAD("+dst+", (unsigned int) "+dst+");"); + } + } else if (state.DSM) { Integer status=locality.getNodePreTempInfo(lb,ffn).get(ffn.getSrc()); if (status==LocalityAnalysis.GLOBAL) { String field=ffn.getField().getSafeSymbol(); @@ -2118,7 +2142,24 @@ public class BuildCode { private void generateFlatSetFieldNode(FlatMethod fm, LocalityBinding lb, FlatSetFieldNode fsfn, PrintWriter output) { if (fsfn.getField().getSymbol().equals("length")&&fsfn.getDst().getType().isArray()) throw new Error("Can't set array length"); - if (state.DSM && locality.getAtomic(lb).get(fsfn).intValue()>0) { + if (state.SINGLETM && locality.getAtomic(lb).get(fsfn).intValue()>0) { + //Single Machine Transaction Case + boolean srcptr=fsfn.getSrc().getType().isPtr(); + String src=generateTemp(fm,fsfn.getSrc(),lb); + String dst=generateTemp(fm,fsfn.getDst(),lb); + if (srcptr) { + output.println("{"); + output.println("int srcoid=("+src+"!=NULL?((int)"+src+"->"+oidstr+"):0);"); + } + if (wb.needBarrier(fsfn)) + output.println("*((unsigned int *)&("+dst+"->___localcopy___))|=DIRTY;"); + if (srcptr) { + output.println("*((unsigned int *)&("+dst+"->"+ fsfn.getField().getSafeSymbol()+"))=srcoid;"); + output.println("}"); + } else { + output.println(dst+"->"+ fsfn.getField().getSafeSymbol()+"="+ src+";"); + } + } else if (state.DSM && locality.getAtomic(lb).get(fsfn).intValue()>0) { Integer statussrc=locality.getNodePreTempInfo(lb,fsfn).get(fsfn.getSrc()); Integer statusdst=locality.getNodeTempInfo(lb).get(fsfn).get(fsfn.getDst()); boolean srcglobal=statussrc==LocalityAnalysis.GLOBAL; @@ -2132,7 +2173,8 @@ public class BuildCode { if (statusdst.equals(LocalityAnalysis.GLOBAL)) { String glbdst=dst; //mark it dirty - output.println("*((unsigned int *)&("+dst+"->___localcopy___))|=DIRTY;"); + if (wb.needBarrier(fsfn)) + output.println("*((unsigned int *)&("+dst+"->___localcopy___))|=DIRTY;"); if (srcglobal) { output.println("*((unsigned int *)&("+glbdst+"->"+ fsfn.getField().getSafeSymbol()+"))=srcoid;"); } else @@ -2157,9 +2199,7 @@ public class BuildCode { } else if (statusdst.equals(LocalityAnalysis.EITHER)) { //writing to a null...bad output.println("if ("+dst+") {"); - output.println("#ifndef RAW"); output.println("printf(\"BIG ERROR 2\\n\");exit(-1);}"); - output.println("#endif"); if (srcglobal) output.println(dst+"->"+ fsfn.getField().getSafeSymbol()+"=srcoid;"); else @@ -2198,7 +2238,17 @@ public class BuildCode { output.println("if ("+generateTemp(fm, fen.getIndex(),lb)+"< 0 || "+generateTemp(fm, fen.getIndex(),lb)+" >= "+generateTemp(fm,fen.getSrc(),lb) + "->___length___)"); output.println("failedboundschk();"); } - if (state.DSM) { + if (state.SINGLETM) { + //Single machine transaction case + String dst=generateTemp(fm, fen.getDst(),lb); + + if (elementtype.isPtr()) { + output.println(dst +"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex(),lb)+"];"); + output.println("TRANSREAD("+dst+", "+dst+");"); + } else { + output.println(dst +"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex(),lb)+"];"); + } + } else if (state.DSM) { Integer status=locality.getNodePreTempInfo(lb,fen).get(fen.getSrc()); if (status==LocalityAnalysis.GLOBAL) { String dst=generateTemp(fm, fen.getDst(),lb); @@ -2243,7 +2293,20 @@ public class BuildCode { output.println("failedboundschk();"); } - if (state.DSM && locality.getAtomic(lb).get(fsen).intValue()>0) { + if (state.SINGLETM && locality.getAtomic(lb).get(fsen).intValue()>0) { + //Transaction set element case + if (wb.needBarrier(fsen)) + output.println("*((unsigned int *)&("+generateTemp(fm,fsen.getDst(),lb)+"->___localcopy___))|=DIRTY;"); + if (fsen.getSrc().getType().isPtr()) { + output.println("{"); + String src=generateTemp(fm, fsen.getSrc(), lb); + output.println("int srcoid=("+src+"!=NULL?((int)"+src+"->"+oidstr+"):0);"); + output.println("((int*)(((char *) &("+ generateTemp(fm,fsen.getDst(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fsen.getIndex(),lb)+"]=srcoid;"); + output.println("}"); + } else { + output.println("(("+type +"*)(((char *) &("+ generateTemp(fm,fsen.getDst(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fsen.getIndex(),lb)+"]="+generateTemp(fm,fsen.getSrc(),lb)+";"); + } + } else if (state.DSM && locality.getAtomic(lb).get(fsen).intValue()>0) { Integer statussrc=locality.getNodePreTempInfo(lb,fsen).get(fsen.getSrc()); Integer statusdst=locality.getNodePreTempInfo(lb,fsen).get(fsen.getDst()); boolean srcglobal=statussrc==LocalityAnalysis.GLOBAL; @@ -2251,7 +2314,8 @@ public class BuildCode { boolean dstlocal=statusdst==LocalityAnalysis.LOCAL; if (dstglobal) { - output.println("*((unsigned int *)&("+generateTemp(fm,fsen.getDst(),lb)+"->___localcopy___))|=DIRTY;"); + if (wb.needBarrier(fsen)) + output.println("*((unsigned int *)&("+generateTemp(fm,fsen.getDst(),lb)+"->___localcopy___))|=DIRTY;"); } else if (dstlocal) { /** Check if we need to copy */ String dst=generateTemp(fm, fsen.getDst(),lb); @@ -2299,7 +2363,26 @@ public class BuildCode { String revertptr=generateTemp(fm, reverttable.get(lb),lb); output.println(revertptr+"=revertlist;"); } - if (fn.getType().isArray()) { + if (state.SINGLETM) { + if (fn.getType().isArray()) { + int arrayid=state.getArrayNumber(fn.getType())+state.numClasses(); + if (locality.getAtomic(lb).get(fn).intValue()>0) { + //inside transaction + output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarraytrans(&"+localsprefix+", "+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+");"); + } else { + //outside transaction + output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarray(&"+localsprefix+", "+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+");"); + } + } else { + if (locality.getAtomic(lb).get(fn).intValue()>0) { + //inside transaction + output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newtrans(&"+localsprefix+", "+fn.getType().getClassDesc().getId()+");"); + } else { + //outside transaction + output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_new(&"+localsprefix+", "+fn.getType().getClassDesc().getId()+");"); + } + } + } else if (fn.getType().isArray()) { int arrayid=state.getArrayNumber(fn.getType())+state.numClasses(); if (fn.isGlobal()) { output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarrayglobal("+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+");"); @@ -2448,7 +2531,7 @@ public class BuildCode { //catch the constructor case output.print("void "); if (md!=null) { - if (state.DSM) { + if (state.DSM||state.SINGLETM) { output.print(cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"("); } else output.print(cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"("); @@ -2458,7 +2541,7 @@ public class BuildCode { boolean printcomma=false; if (GENERATEPRECISEGC) { if (md!=null) { - if (state.DSM) { + if (state.DSM||state.SINGLETM) { output.print("struct "+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params * "+paramsprefix); } else output.print("struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params * "+paramsprefix); diff --git a/Robust/src/IR/Virtual.java b/Robust/src/IR/Virtual.java index 5e91cde6..aea9ac7f 100644 --- a/Robust/src/IR/Virtual.java +++ b/Robust/src/IR/Virtual.java @@ -27,7 +27,7 @@ public class Virtual { this.state=state; this.locality=locality; classmethodcount=new Hashtable(); - if (state.DSM) + if (state.DSM||state.SINGLETM) localitynumber=new Hashtable(); else methodnumber=new Hashtable(); @@ -38,7 +38,7 @@ public class Virtual { Iterator classit=state.getClassSymbolTable().getDescriptorsIterator(); while(classit.hasNext()) { ClassDescriptor cd=(ClassDescriptor)classit.next(); - if (state.DSM) + if (state.DSM||state.SINGLETM) numberLocality(cd); else numberMethods(cd); diff --git a/Robust/src/Main/Main.java b/Robust/src/Main/Main.java index ad156462..0e193ef8 100644 --- a/Robust/src/Main/Main.java +++ b/Robust/src/Main/Main.java @@ -228,7 +228,7 @@ public class Main { if (state.TASK) { sc.getClass("TagDescriptor"); } - if (state.THREAD||state.DSM) { + if (state.THREAD||state.DSM||state.SINGLETM) { sc.getClass("Thread"); } @@ -248,7 +248,7 @@ public class Main { GlobalFieldType gft=new GlobalFieldType(callgraph, state, tu.getMain()); CSE cse=new CSE(gft, tu); localCSE lcse=new localCSE(gft, tu); - LoopOptimize lo=new LoopOptimize(tu); + LoopOptimize lo=new LoopOptimize(gft, tu); Iterator classit=state.getClassSymbolTable().getDescriptorsIterator(); while(classit.hasNext()) { ClassDescriptor cn=(ClassDescriptor)classit.next(); @@ -260,10 +260,10 @@ public class Main { cp.optimize(fm); dc.optimize(fm); lo.optimize(fm); - cp.optimize(fm); - dc.optimize(fm); lcse.doAnalysis(fm); cse.doAnalysis(fm); + cp.optimize(fm); + dc.optimize(fm); } } } @@ -340,16 +340,14 @@ public class Main { } } } - if(!state.MULTICORE) { - if (state.DSM) { + if (state.DSM||state.SINGLETM) { CallGraph callgraph=new CallGraph(state); if (state.PREFETCH) { //speed up prefetch generation using locality analysis results LocalityAnalysis la=new LocalityAnalysis(state, callgraph, tu); pa=new PrefetchAnalysis(state, callgraph, tu, la); } - LocalityAnalysis la=new LocalityAnalysis(state, callgraph, tu); GenerateConversions gc=new GenerateConversions(la, state); BuildCode bc=new BuildCode(state, bf.getMap(), tu, la, pa); diff --git a/Robust/src/Makefile b/Robust/src/Makefile index f00ccfd7..7179fd3a 100644 --- a/Robust/src/Makefile +++ b/Robust/src/Makefile @@ -115,6 +115,7 @@ JAVAFILES=IR/*.java \ Main/*.java \ Analysis/CallGraph/*.java \ Analysis/FlatIRGraph/*.java \ + Analysis/Loops/*.java \ Analysis/Locality/*.java \ Analysis/OwnershipAnalysis/*.java \ Analysis/Prefetch/*.java \ @@ -142,7 +143,7 @@ wc: wc Interface/*.java Analysis/*/*.java IR/*.java IR/*/*.java Lex/*.java Util/*.java ClassLibrary/*.java wcrun: - wc Runtime/*.[c,h] + wc Runtime/*.[c,h] Runtime/DSTM/interface/*.[c,h] Parse/Parser.java Parse/Sym.java: Parse/java14.cup cd Parse && \ diff --git a/Robust/src/Runtime/DSTM/interface/STMIDEAS b/Robust/src/Runtime/DSTM/interface/STMIDEAS new file mode 100644 index 00000000..28330b66 --- /dev/null +++ b/Robust/src/Runtime/DSTM/interface/STMIDEAS @@ -0,0 +1,8 @@ +TODO List/Ideas for Software Transactional Memory Project: + +1) Do reads/writes to new objects in place + +2) Compute types of objects that are only read by a transaction. Do +reads of these objects in place. + +3) Don't lock object on TransRead \ No newline at end of file diff --git a/Robust/src/Runtime/thread.c b/Robust/src/Runtime/thread.c index 7086ed71..20c33423 100644 --- a/Robust/src/Runtime/thread.c +++ b/Robust/src/Runtime/thread.c @@ -107,7 +107,7 @@ void initializethreads() { signal(SIGPIPE, SIG_IGN); } -#ifdef THREADS +#if defined(THREADS)||defined(SINGLETM) void initthread(struct ___Thread___ * ___this___) { #ifdef PRECISE_GC int p[]={1, (int) NULL, (int) ___this___}; @@ -129,20 +129,20 @@ void initthread(struct ___Thread___ * ___this___) { #endif void CALL11(___Thread______sleep____J, long long ___millis___, long long ___millis___) { -#ifdef THREADS +#if defined(THREADS)||defined(SINGLETM) #ifdef PRECISE_GC struct listitem *tmp=stopforgc((struct garbagelist *)___params___); #endif #endif usleep(___millis___); -#ifdef THREADS +#if defined(THREADS)||defined(SINGLETM) #ifdef PRECISE_GC restartaftergc(tmp); #endif #endif } -#if defined(DSTM)|| defined(THREADS) +#if defined(DSTM)|| defined(THREADS)||defined(SINGLETM) void CALL00(___Thread______yield____) { pthread_yield(); } @@ -201,7 +201,7 @@ transstart: } #endif -#ifdef THREADS +#if defined(THREADS)||defined(SINGLETM) void CALL01(___Thread______nativeJoin____, struct ___Thread___ * ___this___) { #ifdef PRECISE_GC struct listitem *tmp=stopforgc((struct garbagelist *)___params___); diff --git a/Robust/src/Tests/STM.java b/Robust/src/Tests/STM.java new file mode 100644 index 00000000..a7754071 --- /dev/null +++ b/Robust/src/Tests/STM.java @@ -0,0 +1,31 @@ +/* This test case tests the thread joining for a threadDSM library */ +public class STM extends Thread { + Data x; + public STM(Data x) { + this.x=x; + } + public static void main(String[] st) { + Data d=new Data(); + STM s1=new STM(d); + STM s2=new STM(d); + + s1.start(); + s2.start(); + s1.join(); + s2.join(); + } + + public void run() { + int i; + atomic { + i=x.a++; + } + System.out.println("Initial value:"+i); + } +} + +public class Data { + int a; + public Data() { + } +} diff --git a/Robust/src/Tests/STM2.java b/Robust/src/Tests/STM2.java new file mode 100644 index 00000000..8e590db6 --- /dev/null +++ b/Robust/src/Tests/STM2.java @@ -0,0 +1,89 @@ +/* This test case tests the thread joining for a threadDSM library */ +public class STM2 extends Thread { + public People[] team; + public STM2() { + } + public static void main(String[] st) { + int b = 0,c = 0; + int i; + + Integer age; + STM2 tmp; + STM2[] at5; + + at5 = new STM2[4]; + atomic { + for(i = 0; i < 4; i++) { + at5[i] = new STM2(); + at5[i].team = new People[2]; + at5[i].team[0] = new People(); + at5[i].team[1] = new People(); + age = new Integer(35); + at5[i].team[0].age = age; + at5[i].team[1].age = age; + } + b = at5[1].team[0].getAge(); + } + System.printInt(b); + System.printString("\n"); + atomic { + age = new Integer(70); + at5[1].team[1].age = age; + c = at5[1].team[1].getAge(); + } + System.printInt(c); + System.printString("\n"); + System.printString("Starting\n"); + for(i = 0 ; i< 4; i++) { + tmp = at5[i]; + tmp.start(); + } + for(i = 0; i< 4; i++) { + tmp = at5[i]; + tmp.join(); + } + System.printString("Finished\n"); + } + + public void run() { + int ag; + boolean old = false; + atomic { + ag = team[1].getAge(); + if(ag > 65) + old = true; + } + if(old){ + System.printString("Gets Pension"); + System.printString("\n"); + } else { + System.printString("Gets No Pension"); + System.printString("\n"); + } + } +} + +public class People { + Integer age; + + public People() { + } + + public People(Integer age) { + this.age = age; + } + + public void setAge(Integer a) { + age = a; + } + + public int getAge() { + return age.intValue(); + } + + public boolean isSenior() { + if(this.getAge() > 65) + return true; + return false; + } +} diff --git a/Robust/src/Tests/dotest b/Robust/src/Tests/dotest index 63fed7f5..f555f9fa 100755 --- a/Robust/src/Tests/dotest +++ b/Robust/src/Tests/dotest @@ -7,7 +7,7 @@ shift dir=`pwd` echo Doing Test $ARG1 -../buildscript -joptimize -robustroot ${dir}/../ -mainclass $ARG1 $ARG2 -o $ARG1 +../buildscript -debug -joptimize -robustroot ${dir}/../ -mainclass $ARG1 $ARG2 -o $ARG1 $ARG1.bin $@ &> output/$ARG1.output diff output/$ARG1.output output/$ARG1.output.goal rm $ARG1.bin diff --git a/Robust/src/Tests/output/StringTest.output.goal b/Robust/src/Tests/output/StringTest.output.goal index 39ff83e3..33e412a1 100644 --- a/Robust/src/Tests/output/StringTest.output.goal +++ b/Robust/src/Tests/output/StringTest.output.goal @@ -3,3 +3,6 @@ hello world 6 lo world lo +normal: Danger iN cAVErn_coVE +upper: DANGER IN CAVERN_COVE +lower: danger in cavern_cove diff --git a/Robust/src/buildscript b/Robust/src/buildscript index 3b4efbc7..a1104d5f 100755 --- a/Robust/src/buildscript +++ b/Robust/src/buildscript @@ -223,6 +223,9 @@ JAVAOPTS="$JAVAOPTS -webinterface" elif [[ $1 = '-instructionfailures' ]] then JAVAOPTS="$JAVAOPTS -instructionfailures" +elif [[ $1 = '-joptimize' ]] +then +JAVAOPTS="$JAVAOPTS -optimize" elif [[ $1 = '-mlp' ]] then JAVAOPTS="$JAVAOPTS -mlp" @@ -313,6 +316,9 @@ if $DSMFLAG then #dsm stuff JAVAOPTS="$JAVAOPTS -classlibrary $ROBUSTROOT/ClassLibrary/JavaDSM" +elif $SINGLETM +then +JAVAOPTS="$JAVAOPTS -classlibrary $ROBUSTROOT/ClassLibrary/JavaSTM" elif $THREADFLAG then #threading java stuff @@ -478,7 +484,7 @@ fi if $SINGLETM then -EXTRAOPTIONS="$EXTRAOPTIONS -lpthread -DCOMPILER" +EXTRAOPTIONS="$EXTRAOPTIONS -lpthread -DCOMPILER -I$DSMRUNTIME" FILES="$FILES $DSMRUNTIME/dsmlock.c $DSMRUNTIME/singleTMCommit.c $DSMRUNTIME/clookup.c" fi -- 2.34.1