get compiler side of STM working
authorbdemsky <bdemsky>
Mon, 6 Apr 2009 06:58:59 +0000 (06:58 +0000)
committerbdemsky <bdemsky>
Mon, 6 Apr 2009 06:58:59 +0000 (06:58 +0000)
20 files changed:
Robust/src/Analysis/Locality/GenerateConversions.java
Robust/src/Analysis/Locality/LocalityAnalysis.java
Robust/src/Analysis/Locality/LocalityBinding.java
Robust/src/Analysis/Loops/CSE.java
Robust/src/Analysis/Loops/GlobalFieldType.java
Robust/src/Analysis/Loops/LoopInvariant.java
Robust/src/Analysis/Loops/LoopOptimize.java
Robust/src/Analysis/Loops/WriteBarrier.java
Robust/src/ClassLibrary/Vector.java
Robust/src/IR/Flat/BuildCode.java
Robust/src/IR/Virtual.java
Robust/src/Main/Main.java
Robust/src/Makefile
Robust/src/Runtime/DSTM/interface/STMIDEAS [new file with mode: 0644]
Robust/src/Runtime/thread.c
Robust/src/Tests/STM.java [new file with mode: 0644]
Robust/src/Tests/STM2.java [new file with mode: 0644]
Robust/src/Tests/dotest
Robust/src/Tests/output/StringTest.output.goal
Robust/src/buildscript

index d241970db2e10fbb8a869c3129629bb08b26b8d6..408ce3298e122345edb75146b5b4728e40a9fec8 100644 (file)
@@ -49,7 +49,7 @@ public class GenerateConversions {
       toprocess.remove(fn);
       boolean isatomic=atomictab.get(fn).intValue()>0;
 
-      Hashtable<TempDescriptor, Integer> nodetemptab=temptab.get(fn);
+      Hashtable<TempDescriptor, Integer> nodetemptab=state.DSM?temptab.get(fn):null;
 
       List<TempDescriptor> reads=Arrays.asList(fn.readsTemps());
       List<TempDescriptor> writes=Arrays.asList(fn.writesTemps());
@@ -111,7 +111,12 @@ public class GenerateConversions {
           * locality. */
          for(Iterator<TempDescriptor> 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<TempDescriptor, Integer>)temptab.get(fn).clone());
+         if (state.DSM)
+           temptab.put(fgcn, (Hashtable<TempDescriptor, Integer>)temptab.get(fn).clone());
 
          for(int i=0; i<fn.numPrev(); i++) {
            FlatNode fnprev=fn.getPrev(i);
@@ -184,12 +190,22 @@ public class GenerateConversions {
        //subtract out the ones we write to
        transtemps.removeAll(Arrays.asList(fn.writesTemps()));
        //add in the globals we read from
-       Hashtable<TempDescriptor, Integer> pretemptab=locality.getNodePreTempInfo(lb, fn);
-       TempDescriptor [] readtemps=fn.readsTemps();
-       for(int i=0; i<readtemps.length; i++) {
-         TempDescriptor tmp=readtemps[i];
-         if (pretemptab.get(tmp).intValue()==LocalityAnalysis.GLOBAL||state.SINGLETM) {
-           transtemps.add(tmp);
+       if (state.SINGLETM) {
+         TempDescriptor [] readtemps=fn.readsTemps();
+         for(int i=0; i<readtemps.length; i++) {
+           TempDescriptor tmp=readtemps[i];
+           if (tmp.getType().isPtr()) {
+             transtemps.add(tmp);
+           }
+         }
+       } else {
+         Hashtable<TempDescriptor, Integer> pretemptab=locality.getNodePreTempInfo(lb, fn);
+         TempDescriptor [] readtemps=fn.readsTemps();
+         for(int i=0; i<readtemps.length; i++) {
+           TempDescriptor tmp=readtemps[i];
+           if (pretemptab.get(tmp).intValue()==LocalityAnalysis.GLOBAL) {
+             transtemps.add(tmp);
+           }
          }
        }
        if (!nodetotranstemps.containsKey(fn)||!nodetotranstemps.get(fn).equals(transtemps)) {
@@ -212,7 +228,9 @@ public class GenerateConversions {
        for(Iterator<TempDescriptor> tempit=tempset.iterator(); tempit.hasNext();) {
          FlatGlobalConvNode fgcn=new FlatGlobalConvNode(tempit.next(), lb, true);
          atomictab.put(fgcn, atomictab.get(fn));
-         temptab.put(fgcn, (Hashtable<TempDescriptor, Integer>)temptab.get(fn).clone());
+         if (state.DSM) {
+           temptab.put(fgcn, (Hashtable<TempDescriptor, Integer>)temptab.get(fn).clone());
+         }
          fgcn.addNext(fn.getNext(0));
          fn.setNext(0, fgcn);
        }
index 6664af18ad70fd3759169a755a82bcc9959a3222..6376922cf4af10017f761cd2033685d0d8bfb405 100644 (file)
@@ -55,18 +55,20 @@ public class LocalityAnalysis {
 
   public LocalityBinding getBinding(LocalityBinding currlb, FlatCall fc) {
     boolean isatomic=getAtomic(currlb).get(fc).intValue()>0;
-    Hashtable<TempDescriptor, Integer> currtable=getNodePreTempInfo(currlb,fc);
+    Hashtable<TempDescriptor, Integer> 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<fc.numArgs(); i++) {
-      TempDescriptor arg=fc.getArg(i);
-      lb.setGlobal(i,currtable.get(arg));
+    if (state.DSM) {
+      for(int i=0; i<fc.numArgs(); i++) {
+       TempDescriptor arg=fc.getArg(i);
+       lb.setGlobal(i,currtable.get(arg));
+      }
     }
-    if (fc.getThis()!=null) {
+    if (state.DSM&&fc.getThis()!=null) {
       Integer thistype=currtable.get(fc.getThis());
       if (thistype==null)
        thistype=EITHER;
@@ -246,25 +248,11 @@ public class LocalityAnalysis {
     FlatMethod fm=state.getMethodFlat(md);
     HashSet<FlatNode> tovisit=new HashSet<FlatNode>();
     tovisit.add(fm.getNext(0));
-    {
-      // Build table for initial node
-      Hashtable<TempDescriptor,Integer> table=new Hashtable<TempDescriptor,Integer>();
-      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<fm.numParameters(); i++) {
-       TempDescriptor temp=fm.getParameter(i);
-       Integer b=lb.isGlobal(i-offset);
-       table.put(temp,b);
-      }
-    }
+    atomictable.put(fm, lb.isAtomic() ? 1 : 0);
 
     while(!tovisit.isEmpty()) {
       FlatNode fn=tovisit.iterator().next();
       tovisit.remove(fn);
-      Hashtable<TempDescriptor, Integer> currtable=new Hashtable<TempDescriptor, Integer>();
       int atomicstate=0;
       for(int i=0; i<fn.numPrev(); i++) {
        FlatNode prevnode=fn.getPrev(i);
@@ -272,7 +260,14 @@ public class LocalityAnalysis {
          atomicstate=atomictable.get(prevnode).intValue();
        }
       }
-      atomictable.put(fn, atomicstate);
+      Integer oldatomic=atomictable.get(fn);
+      if (oldatomic==null||!oldatomic.equals(atomicstate)) {
+       //add in the next node
+       for(int i=0;i<fn.numNext();i++) {
+         tovisit.add(fn.getNext(i));
+       }
+       atomictable.put(fn, atomicstate);
+      }
       // Process this node
       switch(fn.kind()) {
       case FKind.FlatAtomicEnterNode:
@@ -305,6 +300,7 @@ public class LocalityAnalysis {
       case FKind.FlatBackEdge:
       case FKind.FlatNop:
       case FKind.FlatPrefetchNode:
+      case FKind.FlatExit:
        //No action needed for these
        break;
 
@@ -332,7 +328,7 @@ public class LocalityAnalysis {
       // Build start -> 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);
+           } 
          }
        }
       }
index d10d9b28de9c8f9e0b18e73f801627ae573690a1..7e1647a09b9e50ac9f6f624ccd4ea7764f2eba37 100644 (file)
@@ -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<isglobal.length; i++)
-       if (!isglobal[i].equals(lb.isglobal[i]))
+       if (!equiv(isglobal[i], lb.isglobal[i]))
          return false;
 
-      if (isglobalthis==null) {
-       if (lb.isglobalthis!=null)
-         return false;
-      } else
-      if (!isglobalthis.equals(lb.isglobalthis))
+      if (!equiv(isglobalthis, lb.isglobalthis))
        return false;
       return (isatomic==lb.isatomic);
     }
@@ -165,7 +172,8 @@ public class LocalityBinding {
   public int hashCode() {
     int hashcode=md.hashCode();
     for(int i=0; i<isglobal.length; i++) {
-      hashcode=hashcode*31+(isglobal[i].intValue());
+      if (isglobal[i]!=null)
+       hashcode=hashcode*31+(isglobal[i].intValue());
     }
     hashcode=hashcode*31+(isatomic ? 1 : 0);
     return hashcode;
index b98b4f090ffa020706a45d7051625be193f8db96..254a40b1df28d04db8a1d4f7fe74796b24796c66 100644 (file)
@@ -49,6 +49,7 @@ public class CSE {
       case FKind.FlatAtomicEnterNode:
        {
          killexpressions(tab, null, null, true);
+         break;
        }
       case FKind.FlatCall:
        {
index 4802b1d95e620c7b5f566d35d29aa09178e1ae2a..a1493f6a7b8418c88a054e855c1e76fcba173fcf 100644 (file)
@@ -2,6 +2,7 @@ package Analysis.Loops;
 
 import IR.Flat.*;
 import IR.State;
+import IR.TypeUtil;
 import IR.MethodDescriptor;
 import IR.FieldDescriptor;
 import IR.TypeDescriptor;
@@ -45,6 +46,29 @@ public class GlobalFieldType {
          toprocess.add(md2);
        }
       }
+      if (md.getClassDesc().getSymbol().equals(TypeUtil.ThreadClass)&&
+          md.getSymbol().equals("start")&&!md.getModifiers().isStatic()&&
+          md.numParameters()==0) {
+       //start -> 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) {
index 2afbc5b2fe5cbe73ee5973663eee1824b0a9a034..e130c3a6f9fd5bda3e801e7c98d69d8441b00b7e 100644 (file)
@@ -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<FlatNode, Vector<FlatNode>> 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<FieldDescriptor> f=gft.getFields(md);
+         Set<TypeDescriptor> 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());
index e875918950177744cfdade17b7cee65dff397deb..84eeffc1509e99f961be3407e4855ea9a6f19414 100644 (file)
@@ -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);
index fd69784ca901d83671b721f4c217c412d2a61d9d..7a933bfff482d05e1adaa59beb1613d5454b3026 100644 (file)
@@ -44,8 +44,8 @@ public class WriteBarrier {
     HashSet toprocess=new HashSet();
     HashSet discovered=new HashSet();
     needbarrier=new Hashtable<FlatNode,HashSet<TempDescriptor>>();
-    toprocess.add(fm);
-    discovered.add(fm);
+    toprocess.add(fm.getNext(0));
+    discovered.add(fm.getNext(0));
     Hashtable<FlatNode, Integer> atomic=la.getAtomic(lb);
     
     while(!toprocess.isEmpty()) {
index 5cd06ca69e4763bdb266b1c637a8c9e58da670f1..2b11ee23db9d7f7f411515b105ed5de697bbd977 100644 (file)
@@ -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");
index 576b3872827c1c9bd75f4e447c36004d3dfaf89a..141a899d13accd8d8b53f987c0ad5e650bc3b16e 100644 (file)
@@ -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<TempDescriptor, TempDescriptor> backuptable;
   Hashtable<LocalityBinding, TempDescriptor> reverttable;
+  Hashtable<LocalityBinding, Hashtable<TempDescriptor, TempDescriptor>> 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<TempDescriptor, TempDescriptor>();
       this.reverttable=new Hashtable<LocalityBinding, TempDescriptor>();
+      this.backuptable=new Hashtable<LocalityBinding, Hashtable<TempDescriptor, TempDescriptor>>();
+      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 <setjmp.h>");
@@ -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 <thread.h>");
     if (state.main!=null) {
       outmethod.println("#include <string.h>");
@@ -365,11 +371,12 @@ public class BuildCode {
     generateLayoutStructs(outmethod);
 
     /* Generate code for methods */
-    if (state.DSM) {
+    if (state.DSM||state.SINGLETM) {
       for(Iterator<LocalityBinding> 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 <pthread.h>");
     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<maxcount; j++) {
        if (needcomma)
          outvirtual.print(", ");
-       if (state.DSM&&lbvirtualtable[i][j]!=null) {
+       if ((state.DSM||state.SINGLETM)&&lbvirtualtable[i][j]!=null) {
          LocalityBinding lb=lbvirtualtable[i][j];
          MethodDescriptor md=lb.getMethod();
          outvirtual.print("& "+md.getClassDesc().getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor());
-       } else if (!state.DSM&&virtualtable[i][j]!=null) {
+       } else if (!(state.DSM||state.SINGLETM)&&virtualtable[i][j]!=null) {
          MethodDescriptor md=virtualtable[i][j];
          outvirtual.print("& "+md.getClassDesc().getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor());
        } else {
@@ -890,9 +898,10 @@ public class BuildCode {
     TaskDescriptor task=fm.getTask();
     Set<TempDescriptor> 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<TempDescriptor, TempDescriptor>());
+    }
     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<TempDescriptor> tmpit=backuptable.values().iterator(); tmpit.hasNext();) {
+      for(Iterator<TempDescriptor> 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<MethodDescriptor> nativemethods=new HashSet<MethodDescriptor>();
       Set<LocalityBinding> 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<TempDescriptor> 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<TempDescriptor> 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);
index 5e91cde6698a846da8493546d9afa826d4a6b1d5..aea9ac7f14053f896a61b9420740e7e0f96688c1 100644 (file)
@@ -27,7 +27,7 @@ public class Virtual {
     this.state=state;
     this.locality=locality;
     classmethodcount=new Hashtable<ClassDescriptor, Integer>();
-    if (state.DSM)
+    if (state.DSM||state.SINGLETM)
       localitynumber=new Hashtable<LocalityBinding, Integer>();
     else
       methodnumber=new Hashtable<MethodDescriptor, Integer>();
@@ -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);
index ad156462fb35a29c388c9e019593cf4c9c733e4d..0e193ef82d720d7ffc716a2395fa793c02889c76 100644 (file)
@@ -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);
index f00ccfd72a3076c76141133423a8ca4280ceb5d6..7179fd3a6244045dcbd8c7e7aefa69cf708ebdc6 100644 (file)
@@ -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 (file)
index 0000000..28330b6
--- /dev/null
@@ -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
index 7086ed7155e141cd8b39963ebe8fa90af5a75d04..20c3342300f5981e4697010453a4e24d36084b82 100644 (file)
@@ -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 (file)
index 0000000..a775407
--- /dev/null
@@ -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 (file)
index 0000000..8e590db
--- /dev/null
@@ -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;
+  }
+}
index 63fed7f505eb0ad3e70d6a90e325fedaa641d963..f555f9fab969b21e2a8c193ca8aebeb441d93a75 100755 (executable)
@@ -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
index 39ff83e3577971b9ea53d7853ae1c249a34b16e9..33e412a1842b4321ac89dff712f21462a2421cf8 100644 (file)
@@ -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
index 3b4efbc7beeed9bc433341b0c1a1b56da3724e7f..a1104d5fbc6822e9f0e61cdc4ffc25bd59f057fa 100755 (executable)
@@ -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