Fixed variable dynamic source bookkeeping bug, regression test runs for single and...
[IRC.git] / Robust / src / IR / Flat / BuildCode.java
index 48f20209856d1c2440bc2b24fa78c9970613b307..9c24aa680a3ee83ca2c5645a87da79b704fdfac0 100644 (file)
@@ -65,10 +65,10 @@ public class BuildCode {
   String mlperrstr = "if(status != 0) { "+
     "sprintf(errmsg, \"MLP error at %s:%d\", __FILE__, __LINE__); "+
     "perror(errmsg); exit(-1); }";
-  Hashtable<FlatSESEEnterNode, FlatMethod> sese2bogusFlatMeth;
   boolean nonSESEpass=true;
   WriteBarrier wb;
   DiscoverConflicts dc;
+  DiscoverConflicts recorddc;
   DelayComputation delaycomp;
   CallGraph callgraph;
 
@@ -107,7 +107,7 @@ public class BuildCode {
     }
     if (state.SINGLETM&&state.DCOPTS) {
       TypeAnalysis typeanalysis=new TypeAnalysis(locality, st, typeutil,callgraph);
-      this.dc=new DiscoverConflicts(locality, st, typeanalysis);
+      this.dc=new DiscoverConflicts(locality, st, typeanalysis, null);
       dc.doAnalysis();
     }
     if (state.DELAYCOMP) {
@@ -117,10 +117,8 @@ public class BuildCode {
       delaycomp=new DelayComputation(locality, st, typeanalysis, gft);
       delaycomp.doAnalysis();
       dc=delaycomp.getConflicts();
-    }
-
-    if(state.MLP) {
-      sese2bogusFlatMeth = new Hashtable<FlatSESEEnterNode, FlatMethod>();
+      recorddc=new DiscoverConflicts(locality, st, typeanalysis, delaycomp.getCannotDelayMap(), true, true, null);
+      recorddc.doAnalysis();
     }
   }
 
@@ -183,7 +181,9 @@ public class BuildCode {
     if (state.MLP) {
       outmethodheader.println("#include <stdlib.h>");
       outmethodheader.println("#include <stdio.h>");
+      outmethodheader.println("#include <string.h>");
       outmethodheader.println("#include \"mlp_runtime.h\"");
+      outmethodheader.println("#include \"psemaphore.h\"");
     }
 
     /* Output Structures */
@@ -217,6 +217,16 @@ public class BuildCode {
       outputTaskTypes(outtask);
     }
 
+    if( state.MLP ) {
+      // have to initialize some SESE compiler data before
+      // analyzing normal methods, which must happen before
+      // generating SESE internal code
+      for(Iterator<FlatSESEEnterNode> seseit=mlpa.getAllSESEs().iterator();seseit.hasNext();) {
+       FlatSESEEnterNode fsen = seseit.next();
+       initializeSESE( fsen );
+      }
+    }
+
     /* Build the actual methods */
     outputMethods(outmethod);
 
@@ -274,9 +284,12 @@ public class BuildCode {
   private void outputMainMethod(PrintWriter outmethod) {
     outmethod.println("int main(int argc, const char *argv[]) {");
     outmethod.println("  int i;");
+
     if (state.MLP) {
-      outmethod.println("  mlpInit( "+mlpa.getAllSESEs().size()+", "+mlpa.getMaxSESEage()+" );");
+      //outmethod.println("  pthread_once( &mlpOnceObj, mlpInitOncePerThread );");
+      outmethod.println("  workScheduleInit( "+state.MLP_NUMCORES+", invokeSESEmethod );");
     }
+
     if (state.DSM) {
       outmethod.println("#ifdef TRANSSTATS \n");
       outmethod.println("handle();\n");
@@ -287,13 +300,13 @@ public class BuildCode {
     }
     if (state.DSM) {
       outmethod.println("if (dstmStartup(argv[1])) {");
-      if (GENERATEPRECISEGC) {
+      if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
        outmethod.println("  struct ArrayObject * stringarray=allocate_newarray(NULL, STRINGARRAYTYPE, argc-2);");
       } else {
        outmethod.println("  struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc-2);");
       }
     } else {
-      if (GENERATEPRECISEGC) {
+      if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
        outmethod.println("  struct ArrayObject * stringarray=allocate_newarray(NULL, STRINGARRAYTYPE, argc-1);");
       } else {
        outmethod.println("  struct ArrayObject * stringarray=allocate_newarray(STRINGARRAYTYPE, argc-1);");
@@ -304,7 +317,7 @@ public class BuildCode {
     } else
       outmethod.println("  for(i=1;i<argc;i++) {");
     outmethod.println("    int length=strlen(argv[i]);");
-    if (GENERATEPRECISEGC) {
+    if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
       outmethod.println("    struct ___String___ *newstring=NewString(NULL, argv[i], length);");
     } else {
       outmethod.println("    struct ___String___ *newstring=NewString(argv[i], length);");
@@ -319,7 +332,7 @@ public class BuildCode {
     ClassDescriptor cd=typeutil.getMainClass();
 
     outmethod.println("   {");
-    if (GENERATEPRECISEGC) {
+    if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
       if (state.DSM||state.SINGLETM) {
        outmethod.print("       struct "+cd.getSafeSymbol()+locality.getMain().getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={");
       } else
@@ -351,8 +364,8 @@ public class BuildCode {
     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(\"numTransAbort= %d\\n\", numTransAbort);");
       outmethod.println("printf(\"nSoftAbort= %d\\n\", nSoftAbort);");
       if (state.DSM) {
        outmethod.println("printf(\"nchashSearch= %d\\n\", nchashSearch);");
@@ -366,7 +379,7 @@ public class BuildCode {
        outmethod.println("printf(\"nSoftAbortCommit= %d\\n\", nSoftAbortCommit);");
        outmethod.println("#ifdef STMSTATS\n");
        outmethod.println("for(i=0; i<TOTALNUMCLASSANDARRAY; i++) {\n");
-       outmethod.println("  printf(\"typesCausingAbort[%d]= %d\\n\", i, typesCausingAbort[i]);\n");
+       outmethod.println("  printf(\"typesCausingAbort[%2d] numaccess= %5d numabort= %3d\\n\", i, typesCausingAbort[i].numaccess, typesCausingAbort[i].numabort);\n");
        outmethod.println("}\n");
        outmethod.println("#endif\n");
        outmethod.println("fflush(stdout);");
@@ -377,6 +390,10 @@ public class BuildCode {
     if (state.THREAD||state.SINGLETM)
       outmethod.println("pthread_exit(NULL);");
 
+    if (state.MLP) {
+      outmethod.println("  workScheduleBegin();");
+    }
+
     outmethod.println("}");
   }
 
@@ -444,6 +461,7 @@ public class BuildCode {
       outmethod.println("#include <stdlib.h>");
       outmethod.println("#include <stdio.h>");
       outmethod.println("#include \"mlp_runtime.h\"");
+      outmethod.println("#include \"psemaphore.h\"");
     }
 
 
@@ -495,6 +513,10 @@ public class BuildCode {
     outstructs.println("#define INTPTR int");
     outstructs.println("#endif");
     outstructs.println("#endif");
+    if( state.MLP ) {
+      outstructs.println("#include \"mlp_runtime.h\"");
+      outstructs.println("#include \"psemaphore.h\"");
+    }
 
     /* Output #defines that the runtime uses to determine type
      * numbers for various objects it needs */
@@ -571,11 +593,13 @@ public class BuildCode {
       if(!state.MULTICORE) {
        outclassdefs.println("  void * flagptr;");
       } else {
-       outclassdefs.println("  int isolate;");        // indicate if this object is shared or not
-       outclassdefs.println("  int version;");
-       outclassdefs.println("  struct ___Object___ * original;");
-       //outclassdefs.println("  int numlocks;");        // array for locks
-       outclassdefs.println("  int * lock;");
+        outclassdefs.println("  int version;");
+        outclassdefs.println("  int * lock;");  // lock entry for this obj
+        outclassdefs.println("  int mutex;");  
+        outclassdefs.println("  int lockcount;");
+        if(state.MULTICOREGC) {
+          outclassdefs.println("  int marked;");
+        }
       }
       if(state.OPTIONAL) {
        outclassdefs.println("  int numfses;");
@@ -584,6 +608,9 @@ public class BuildCode {
     }
     printClassStruct(typeutil.getClass(TypeUtil.ObjectClass), outclassdefs);
 
+    if (state.ARRAYPAD)
+      outclassdefs.println("  int paddingforarray;");
+
     outclassdefs.println("  int ___length___;");
     outclassdefs.println("};\n");
     outclassdefs.println("extern int classsize[];");
@@ -878,7 +905,7 @@ public class BuildCode {
       outclassdefs.println("extern int nSoftAbortAbort;");
       outclassdefs.println("extern int nSoftAbortCommit;");
       outclassdefs.println("#ifdef STMSTATS\n");
-      outclassdefs.println("extern int typesCausingAbort[];");
+      outclassdefs.println("extern objtypestat_t typesCausingAbort[];");
       outclassdefs.println("#endif\n");
     }
     outclassdefs.print("#endif\n");
@@ -1041,7 +1068,7 @@ public class BuildCode {
     for(int i=0; i<fm.numParameters(); i++) {
       TempDescriptor temp=fm.getParameter(i);
       TypeDescriptor type=temp.getType();
-      if (type.isPtr()&&GENERATEPRECISEGC)
+      if (type.isPtr()&&((GENERATEPRECISEGC) || (this.state.MULTICOREGC)))
        objectparams.addPtr(temp);
       else
        objectparams.addPrim(temp);
@@ -1052,7 +1079,7 @@ public class BuildCode {
 
     for(int i=0; i<fm.numTags(); i++) {
       TempDescriptor temp=fm.getTag(i);
-      if (GENERATEPRECISEGC)
+      if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC))
        objectparams.addPtr(temp);
       else
        objectparams.addPrim(temp);
@@ -1072,7 +1099,7 @@ public class BuildCode {
       for(int i=0; i<writes.length; i++) {
        TempDescriptor temp=writes[i];
        TypeDescriptor type=temp.getType();
-       if (type.isPtr()&&GENERATEPRECISEGC)
+       if (type.isPtr()&&((GENERATEPRECISEGC) || (this.state.MULTICOREGC)))
          objecttemps.addPtr(temp);
        else
          objecttemps.addPrim(temp);
@@ -1087,7 +1114,7 @@ public class BuildCode {
       for(Iterator<TempDescriptor> tmpit=backuptable.get(lb).values().iterator(); tmpit.hasNext();) {
        TempDescriptor tmp=tmpit.next();
        TypeDescriptor type=tmp.getType();
-       if (type.isPtr()&&GENERATEPRECISEGC)
+       if (type.isPtr()&&((GENERATEPRECISEGC) || (this.state.MULTICOREGC)))
          objecttemps.addPtr(tmp);
        else
          objecttemps.addPrim(tmp);
@@ -1095,7 +1122,7 @@ public class BuildCode {
       /* Create temp to hold revert table */
       if (state.DSM&&(lb.getHasAtomic()||lb.isAtomic())) {
        TempDescriptor reverttmp=new TempDescriptor("revertlist", typeutil.getClass(TypeUtil.ObjectClass));
-       if (GENERATEPRECISEGC)
+       if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC))
          objecttemps.addPtr(reverttmp);
        else
          objecttemps.addPrim(reverttmp);
@@ -1206,14 +1233,10 @@ public class BuildCode {
     if (!fieldorder.containsKey(cn)) {
       Vector fields=new Vector();
       fieldorder.put(cn,fields);
-      if (sp==null&&!state.TASK) {
-       fields.add(cn.getFieldTable().get("cachedCode"));
-      }
-      Iterator fieldit=cn.getFields();
-      while(fieldit.hasNext()) {
-       FieldDescriptor fd=(FieldDescriptor)fieldit.next();
-       if ((sp==null||!sp.getFieldTable().contains(fd.getSymbol()))&&
-           (!fd.getSymbol().equals("cachedCode")||state.TASK))
+      Vector fieldvec=cn.getFieldVec();
+      for(int i=0;i<fieldvec.size();i++) {
+       FieldDescriptor fd=(FieldDescriptor)fieldvec.get(i);
+       if ((sp==null||!sp.getFieldTable().contains(fd.getSymbol())))
          fields.add(fd);
       }
     }
@@ -1281,11 +1304,13 @@ public class BuildCode {
       if((!state.MULTICORE) || (cn.getSymbol().equals("TagDescriptor"))) {
        classdefout.println("  void * flagptr;");
       } else if (state.MULTICORE) {
-       classdefout.println("  int isolate;");        // indicate if this object is shared or not
        classdefout.println("  int version;");
-       classdefout.println("  struct ___Object___ * original;");
-       //classdefout.println("  int numlocks;");        // array for locks
-       classdefout.println("  int * lock;");
+    classdefout.println("  int * lock;");  // lock entry for this obj
+    classdefout.println("  int mutex;");  
+    classdefout.println("  int lockcount;");
+    if(state.MULTICOREGC) {
+      classdefout.println("  int marked;");
+    }
       }
       if (state.OPTIONAL) {
        classdefout.println("  int numfses;");
@@ -1334,7 +1359,7 @@ public class BuildCode {
 
   private void generateMethodParam(ClassDescriptor cn, MethodDescriptor md, LocalityBinding lb, PrintWriter output) {
     /* Output parameter structure */
-    if (GENERATEPRECISEGC) {
+    if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
       ParamsObject objectparams=(ParamsObject) paramstable.get(lb!=null ? lb : md);
       if ((state.DSM||state.SINGLETM)&&lb!=null)
        output.println("struct "+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params {");
@@ -1360,7 +1385,7 @@ public class BuildCode {
     generateMethodParam(cn, md, lb, output);
 
     /* Output temp structure */
-    if (GENERATEPRECISEGC) {
+    if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
       if (state.DSM||state.SINGLETM)
        output.println("struct "+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals {");
       else
@@ -1400,7 +1425,7 @@ public class BuildCode {
       headersout.print(cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(");
     }
     boolean printcomma=false;
-    if (GENERATEPRECISEGC) {
+    if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
       if (state.DSM||state.SINGLETM) {
        headersout.print("struct "+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params * "+paramsprefix);
       } else
@@ -1441,7 +1466,7 @@ public class BuildCode {
       TempObject objecttemps=(TempObject) tempstable.get(task);
 
       /* Output parameter structure */
-      if (GENERATEPRECISEGC) {
+      if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
        output.println("struct "+task.getSafeSymbol()+"_params {");
 
        output.println("  INTPTR size;");
@@ -1458,7 +1483,7 @@ public class BuildCode {
       }
 
       /* Output temp structure */
-      if (GENERATEPRECISEGC) {
+      if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
        output.println("struct "+task.getSafeSymbol()+"_locals {");
        output.println("  INTPTR size;");
        output.println("  void * next;");
@@ -1479,7 +1504,7 @@ public class BuildCode {
       headersout.print("void " + task.getSafeSymbol()+"(");
 
       boolean printcomma=false;
-      if (GENERATEPRECISEGC) {
+      if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
        headersout.print("struct "+task.getSafeSymbol()+"_params * "+paramsprefix);
       } else
        headersout.print("void * parameterarray[]");
@@ -1580,8 +1605,13 @@ public class BuildCode {
              }
            }
          }
-
+         //turn off write barrier generation
+         wb.turnoff();
+         state.SINGLETM=false;
          generateCode(faen, fm, lb, exitset, output, false);
+         state.SINGLETM=true;
+         //turn on write barrier generation
+         wb.turnon();
          output.println("}\n\n");
        }
       }
@@ -1601,7 +1631,7 @@ public class BuildCode {
       }
     }
 
-    if (GENERATEPRECISEGC) {
+    if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
       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||state.SINGLETM))
@@ -1627,15 +1657,44 @@ public class BuildCode {
        output.println("   "+type.getSafeSymbol()+" "+td.getSafeSymbol()+";");
     }
 
+
+    if( state.MLP ) {      
+      if( fm.getNext(0) instanceof FlatSESEEnterNode ) {
+       FlatSESEEnterNode callerSESEplaceholder = (FlatSESEEnterNode) fm.getNext( 0 );
+       if( callerSESEplaceholder != mlpa.getMainSESE() ) {
+         // declare variables for naming static SESE's
+         output.println("   /* static SESE names */");
+         Iterator<SESEandAgePair> pItr = callerSESEplaceholder.getNeededStaticNames().iterator();
+         while( pItr.hasNext() ) {
+           SESEandAgePair p = pItr.next();
+           output.println("   void* "+p+";");
+         }
+
+         // declare variables for tracking dynamic sources
+         output.println("   /* dynamic variable sources */");
+         Iterator<TempDescriptor> dynSrcItr = callerSESEplaceholder.getDynamicVarSet().iterator();
+         while( dynSrcItr.hasNext() ) {
+           TempDescriptor dynSrcVar = dynSrcItr.next();
+           output.println("   void* "+dynSrcVar+"_srcSESE;");
+           output.println("   int   "+dynSrcVar+"_srcOffset;");
+         }    
+       }
+      }
+    }
+
+
     /* Check to see if we need to do a GC if this is a
      * multi-threaded program...*/
 
-    if ((state.THREAD||state.DSM||state.SINGLETM)&&GENERATEPRECISEGC) {
+    if (((state.THREAD||state.DSM||state.SINGLETM)&&GENERATEPRECISEGC) 
+        || this.state.MULTICOREGC) {
       //Don't bother if we aren't in recursive methods...The loops case will catch it
       if (callgraph.getAllMethods(md).contains(md)) {
        if (state.DSM&&lb.isAtomic())
          output.println("if (needtocollect) checkcollect2("+localsprefixaddr+");");
-       else
+       else if (this.state.MULTICOREGC) {
+      output.println("if(gcflag) gc("+localsprefixaddr+");");
+    } else
          output.println("if (needtocollect) checkcollect("+localsprefixaddr+");");
       }
     }
@@ -1645,130 +1704,49 @@ public class BuildCode {
     output.println("}\n\n");
   }
 
-  // when a new mlp thread is created for an issued SESE, it is started
-  // by running this method which blocks on a cond variable until
-  // it is allowed to transition to execute.  Then a case statement
-  // allows it to invoke the method with the proper SESE body, and after
-  // exiting the SESE method, executes proper SESE exit code before the
-  // thread can be destroyed
-  private void generateSESEinvocationMethod(PrintWriter outmethodheader,
-                                            PrintWriter outmethod
-                                            ) {
-
-    outmethodheader.println("void invokeSESEmethod( void* vargs );");
-    outmethod.println(      "void invokeSESEmethod( void* vargs ) {");
-    outmethod.println(      "  int status;");
-    outmethod.println(      "  char errmsg[128];");
-    outmethod.println(      "  invokeSESEargs* args = (invokeSESEargs*) vargs;");
-
-    /*
-    // wait on a condition variable that dispatcher will signal
-    // then this SESE instance's dependencies are resolved
-    outmethod.println(      "  status = pthread_mutex_lock( args->invokee->startCondVarLock );");
-    outmethod.println(      "  "+mlperrstr);
-    outmethod.println(      "  while( !(args->invokee->startedExecuting) ){");
-    outmethod.println(      "    status = pthread_cond_wait( args->invokee->startCondVar, args->invokee->startCondVarLock );");
-    outmethod.println(      "    "+mlperrstr);
-    outmethod.println(      "  }");
-    */
-
-    // generate a case for each SESE class that can be invoked
-    outmethod.println(      "  switch( args->classID ) {");
-    outmethod.println(      "    ");
-    for(Iterator<FlatSESEEnterNode> seseit=mlpa.getAllSESEs().iterator();seseit.hasNext();) {
-      FlatSESEEnterNode fsen = seseit.next();
-      outmethod.println(    "    /* "+fsen.getPrettyIdentifier()+" */");
-      outmethod.println(    "    case "+fsen.getIdentifier()+":");
-      generateSESEinvocation(fsen, outmethod);
-      outmethod.println(    "      break;");
-      outmethod.println(    "");
-    }
-
-    // default case should never be taken, error out
-    outmethod.println(      "    default:");
-    outmethod.println(      "      printf(\"Error: unknown SESE class ID in invoke method.\\n\");");
-    outmethod.println(      "      exit(-30);");
-    outmethod.println(      "      break;");
-    outmethod.println(      "  }");
-    outmethod.println(      "}\n\n");
-  }
 
-  private void generateSESEinvocation(FlatSESEEnterNode fsen,
-                                      PrintWriter output
-                                      ) {
+  protected void initializeSESE( FlatSESEEnterNode fsen ) {
 
-    FlatMethod       fm = fsen.getEnclosingFlatMeth();
-    MethodDescriptor md = fm.getMethod();
-    ClassDescriptor  cn = md.getClassDesc();
-
-    FlatMethod       bogusfm  = sese2bogusFlatMeth.get(fsen);
-    MethodDescriptor bogusmd  = bogusfm.getMethod();
-    ParamsObject objectparams = (ParamsObject)paramstable.get(bogusmd);
-
-    // first copy SESE record into param structure
-
-
-    // then invoke the sese's method
-    output.print("      "+cn.getSafeSymbol()+bogusmd.getSafeSymbol()+"_"+bogusmd.getSafeMethodDescriptor());
-    output.print("( args->invokee, ");
-
-    // first argument is parameter structure
-    output.print("(struct "+cn.getSafeSymbol()+bogusmd.getSafeSymbol()+"__params*)");
-    output.print("&(args->invokee->paramStruct)");
-
-    // other arguments are primitive parameters
-    for(int i=0; i<objectparams.numPrimitives(); i++) {
-      TempDescriptor td=objectparams.getPrimitive(i);
-      TypeDescriptor type=td.getType();
-      assert type.isPrimitive();
-      output.print( ", (("+fsen.namespaceStructNameString()+
-                      "*)args->invokee->namespace)->"+td );
-    }
-    
-    output.println(");");
-  }
-
-  protected void generateMethodSESE(FlatSESEEnterNode fsen,
-                                    LocalityBinding lb,
-                                    PrintWriter outputStructs,
-                                    PrintWriter outputMethHead,
-                                    PrintWriter outputMethods
-                                    ) {
-
-
-    FlatMethod       fm = fsen.getEnclosingFlatMeth();
+    FlatMethod       fm = fsen.getfmEnclosing();
     MethodDescriptor md = fm.getMethod();
     ClassDescriptor  cn = md.getClassDesc();
     
         
-    //Creates bogus method descriptor to index into tables
-    Modifiers bogusmod=new Modifiers();
-    MethodDescriptor bogusmd=new MethodDescriptor(bogusmod, 
-                                                  new TypeDescriptor(TypeDescriptor.VOID), 
-                                                  "sese_"+fsen.getPrettyIdentifier()+fsen.getIdentifier());
-    bogusmd.setClassDesc(cn);
-    FlatMethod bogusfm=new FlatMethod(bogusmd, null);
-    sese2bogusFlatMeth.put(fsen, bogusfm);
-
-
-    //Build paramsobj for bogus method descriptor
-    ParamsObject objectparams=new ParamsObject(bogusmd, tag++);
-    paramstable.put(bogusmd, objectparams);
+    // Creates bogus method descriptor to index into tables
+    Modifiers modBogus = new Modifiers();
+    MethodDescriptor mdBogus = 
+      new MethodDescriptor( modBogus, 
+                           new TypeDescriptor( TypeDescriptor.VOID ), 
+                           "sese_"+fsen.getPrettyIdentifier()+fsen.getIdentifier()
+                           );
     
-    for(int i=0; i<fsen.numParameters(); i++) {
-      TempDescriptor temp=fsen.getParameter(i);
-      TypeDescriptor type=temp.getType();
-      if (type.isPtr()&&GENERATEPRECISEGC) {
-       objectparams.addPtr(temp);
+    mdBogus.setClassDesc( fsen.getcdEnclosing() );
+    FlatMethod fmBogus = new FlatMethod( mdBogus, null );
+    fsen.setfmBogus( fmBogus );
+    fsen.setmdBogus( mdBogus );
+
+    Set<TempDescriptor> inSetAndOutSet = new HashSet<TempDescriptor>();
+    inSetAndOutSet.addAll( fsen.getInVarSet() );
+    inSetAndOutSet.addAll( fsen.getOutVarSet() );
+
+    // Build paramsobj for bogus method descriptor
+    ParamsObject objectparams = new ParamsObject( mdBogus, tag++ );
+    paramstable.put( mdBogus, objectparams );
+    
+    Iterator<TempDescriptor> itr = inSetAndOutSet.iterator();
+    while( itr.hasNext() ) {
+      TempDescriptor temp = itr.next();
+      TypeDescriptor type = temp.getType();
+      if( type.isPtr() ) {
+       objectparams.addPtr( temp );
       } else {
-       objectparams.addPrim(temp);
+       objectparams.addPrim( temp );
       }
     }
-    
-    
-    //Build normal temp object for bogus method descriptor
-    TempObject objecttemps=new TempObject(objectparams,bogusmd,tag++);
-    tempstable.put(bogusmd, objecttemps);
+        
+    // Build normal temp object for bogus method descriptor
+    TempObject objecttemps = new TempObject( objectparams, mdBogus, tag++ );
+    tempstable.put( mdBogus, objecttemps );
     
     for(Iterator nodeit=fsen.getNodeSet().iterator(); nodeit.hasNext();) {
       FlatNode fn=(FlatNode)nodeit.next();
@@ -1776,21 +1754,28 @@ public class BuildCode {
       for(int i=0; i<writes.length; i++) {
        TempDescriptor temp=writes[i];
        TypeDescriptor type=temp.getType();
-       if (type.isPtr()&&GENERATEPRECISEGC)
+       if (type.isPtr()&&GENERATEPRECISEGC) {
          objecttemps.addPtr(temp);
-       else
+       } else {
          objecttemps.addPrim(temp);
+       }
       }
     }
-    
-    // declare namespace struct
-    outputStructs.println(fsen.namespaceStructDeclarationString());
-    
-    //Generate code for parameters structure
-    generateMethodParam(cn, bogusmd, null, outputStructs);
+  }
 
-    //Generate code for locals structure
-    outputStructs.println("struct "+cn.getSafeSymbol()+bogusmd.getSafeSymbol()+"_"+bogusmd.getSafeMethodDescriptor()+"_locals {");
+  protected void generateMethodSESE(FlatSESEEnterNode fsen,
+                                    LocalityBinding lb,
+                                    PrintWriter outputStructs,
+                                    PrintWriter outputMethHead,
+                                    PrintWriter outputMethods
+                                    ) {
+
+    ParamsObject objectparams = (ParamsObject) paramstable.get( fsen.getmdBogus() );
+                
+    TempObject objecttemps = (TempObject) tempstable.get( fsen.getmdBogus() );
+    
+    // generate locals structure
+    outputStructs.println("struct "+fsen.getcdEnclosing().getSafeSymbol()+fsen.getmdBogus().getSafeSymbol()+"_"+fsen.getmdBogus().getSafeMethodDescriptor()+"_locals {");
     outputStructs.println("  INTPTR size;");
     outputStructs.println("  void * next;");
     for(int i=0; i<objecttemps.numPointers(); i++) {
@@ -1801,58 +1786,111 @@ public class BuildCode {
         outputStructs.println("  struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol()+";");
     }
     outputStructs.println("};\n");
+
+    
+    // generate the SESE record structure
+    outputStructs.println(fsen.getSESErecordName()+" {");
     
+    // data common to any SESE, and it must be placed first so
+    // a module that doesn't know what kind of SESE record this
+    // is can cast the pointer to a common struct
+    outputStructs.println("  SESEcommon common;");
 
-    // write method declaration to header file
-    outputMethHead.print("void ");
-    outputMethHead.print(cn.getSafeSymbol()+bogusmd.getSafeSymbol()+"_"+bogusmd.getSafeMethodDescriptor()+"(");
-    outputMethHead.print("SESErecord* currentSESE, ");
-    boolean printcomma=false;
-    if (GENERATEPRECISEGC) {
-      outputMethHead.print("struct "+cn.getSafeSymbol()+
-                           bogusmd.getSafeSymbol()+"_"+
-                           bogusmd.getSafeMethodDescriptor()+"_params * "+paramsprefix);
-      printcomma=true;
+    // then garbage list stuff
+    outputStructs.println("  INTPTR size;");
+    outputStructs.println("  void * next;");
+
+    // in-set source tracking
+    // in-vars that are READY come from parent, don't need anything
+    // stuff STATIC needs a custom SESE pointer for each age pair
+    Iterator<SESEandAgePair> itrStaticInVarSrcs = fsen.getStaticInVarSrcs().iterator();
+    while( itrStaticInVarSrcs.hasNext() ) {
+      SESEandAgePair srcPair = itrStaticInVarSrcs.next();
+      outputStructs.println("  "+srcPair.getSESE().getSESErecordName()+"* "+srcPair+";");
+    }    
+
+    // DYNAMIC stuff needs a source SESE ptr and offset
+    Iterator<TempDescriptor> itrDynInVars = fsen.getDynamicInVarSet().iterator();
+    while( itrDynInVars.hasNext() ) {
+      TempDescriptor dynInVar = itrDynInVars.next();
+      outputStructs.println("  void* "+dynInVar+"_srcSESE;");
+      outputStructs.println("  int   "+dynInVar+"_srcOffset;");
+    }    
+
+    // space for all in and out set primitives
+    Set<TempDescriptor> inSetAndOutSet = new HashSet<TempDescriptor>();
+    inSetAndOutSet.addAll( fsen.getInVarSet() );
+    inSetAndOutSet.addAll( fsen.getOutVarSet() );
+
+    Set<TempDescriptor> inSetAndOutSetPrims = new HashSet<TempDescriptor>();
+
+    Iterator<TempDescriptor> itr = inSetAndOutSet.iterator();
+    while( itr.hasNext() ) {
+      TempDescriptor temp = itr.next();
+      TypeDescriptor type = temp.getType();
+      if( !type.isPtr() ) {
+       inSetAndOutSetPrims.add( temp );
+      }
     }
-    //  Output parameter list
-    for(int i=0; i<objectparams.numPrimitives(); i++) {
-      TempDescriptor temp=objectparams.getPrimitive(i);
-      if (printcomma)
-       outputMethHead.print(", ");
-      printcomma=true;
-      if (temp.getType().isClass()||temp.getType().isArray())
-       outputMethHead.print("struct " + temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol());
+
+    Iterator<TempDescriptor> itrPrims = inSetAndOutSetPrims.iterator();
+    while( itrPrims.hasNext() ) {
+      TempDescriptor temp = itrPrims.next();
+      TypeDescriptor type = temp.getType();
+      outputStructs.println("  "+temp.getType().getSafeSymbol()+" "+temp.getSafeSymbol()+";");
+    }
+
+    for(int i=0; i<objectparams.numPointers(); i++) {
+      TempDescriptor temp=objectparams.getPointer(i);
+      if (temp.getType().isNull())
+        outputStructs.println("  void * "+temp.getSafeSymbol()+";");
       else
-       outputMethHead.print(temp.getType().getSafeSymbol()+" "+temp.getSafeSymbol());
+        outputStructs.println("  struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol()+";");
     }
+    
+    outputStructs.println("};\n");
+
+    
+    // write method declaration to header file
+    outputMethHead.print("void ");
+    outputMethHead.print(fsen.getSESEmethodName()+"(");
+    outputMethHead.print(fsen.getSESErecordName()+"* "+paramsprefix);
     outputMethHead.println(");\n");
 
 
-    generateFlatMethodSESE(bogusfm, cn, fsen, fsen.getFlatExit(), outputMethods);
+    generateFlatMethodSESE( fsen.getfmBogus(), 
+                           fsen.getcdEnclosing(), 
+                           fsen, 
+                           fsen.getFlatExit(), 
+                           outputMethods );
   }
 
   private void generateFlatMethodSESE(FlatMethod fm, 
                                       ClassDescriptor cn, 
-                                      FlatSESEEnterNode seseEnter
+                                      FlatSESEEnterNode fsen
                                       FlatSESEExitNode  seseExit, 
                                       PrintWriter output
                                       ) {
 
     MethodDescriptor md=fm.getMethod();
-    ParamsObject objectparams=(ParamsObject)paramstable.get(md);
-    generateHeader(fm, null, md, output, true);
-    TempObject objecttemp=(TempObject) tempstable.get(md);
 
+    output.print("void ");
+    output.print(fsen.getSESEmethodName()+"(");
+    output.print(fsen.getSESErecordName()+"* "+paramsprefix);
+    output.println("){\n");
 
-    if (GENERATEPRECISEGC) {
+    TempObject objecttemp=(TempObject) tempstable.get(md);
+
+    if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
       output.print("   struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals "+localsprefix+"={");
       output.print(objecttemp.numPointers()+",");
-      output.print(paramsprefix);
+      output.print("(void*) &("+paramsprefix+"->size)");
       for(int j=0; j<objecttemp.numPointers(); j++)
        output.print(", NULL");
       output.println("};");
     }
 
+    output.println("   /* regular local primitives */");
     for(int i=0; i<objecttemp.numPrimitives(); i++) {
       TempDescriptor td=objecttemp.getPrimitive(i);
       TypeDescriptor type=td.getType();
@@ -1865,53 +1903,197 @@ public class BuildCode {
     }
 
 
-    // declare variables for naming SESE's
-    Iterator<SESEandAgePair> pItr = seseEnter.getNeededStaticNames().iterator();
+    // declare variables for naming static SESE's
+    output.println("   /* static SESE names */");
+    Iterator<SESEandAgePair> pItr = fsen.getNeededStaticNames().iterator();
     while( pItr.hasNext() ) {
       SESEandAgePair p = pItr.next();
-      output.println("   SESErecord* "+p+";");
+      output.println("   void* "+p+";");
+    }
+
+    // declare variables for tracking dynamic sources
+    output.println("   /* dynamic variable sources */");
+    Iterator<TempDescriptor> dynSrcItr = fsen.getDynamicVarSet().iterator();
+    while( dynSrcItr.hasNext() ) {
+      TempDescriptor dynSrcVar = dynSrcItr.next();
+      output.println("   void* "+dynSrcVar+"_srcSESE;");
+      output.println("   int   "+dynSrcVar+"_srcOffset;");
+    }    
+
+    // declare local temps for in-set primitives, and if it is
+    // a ready-source variable, get the value from the record
+    output.println("   /* local temps for in-set primitives */");
+    Iterator<TempDescriptor> itrInSet = fsen.getInVarSet().iterator();
+    while( itrInSet.hasNext() ) {
+      TempDescriptor temp = itrInSet.next();
+      TypeDescriptor type = temp.getType();
+      if( !type.isPtr() ) {
+       if( fsen.getReadyInVarSet().contains( temp ) ) {
+         output.println("   "+type+" "+temp+" = "+paramsprefix+"->"+temp+";");
+       } else {
+         output.println("   "+type+" "+temp+";");
+       }
+      }
+    }    
+
+    // declare local temps for out-set primitives if its not already
+    // in the in-set, and it's value will get written so no problem
+    output.println("   /* local temp for out-set prim, not already in the in-set */");
+    Iterator<TempDescriptor> itrOutSet = fsen.getOutVarSet().iterator();
+    while( itrOutSet.hasNext() ) {
+      TempDescriptor temp = itrOutSet.next();
+      TypeDescriptor type = temp.getType();
+      if( !type.isPtr() && !fsen.getInVarSet().contains( temp ) ) {
+       output.println("   "+type+" "+temp+";");       
+      }
+    }    
+
+    // copy in-set into place, ready vars were already 
+    // copied when the SESE was issued
+    Iterator<TempDescriptor> tempItr;
+
+    // static vars are from a known SESE
+    tempItr = fsen.getStaticInVarSet().iterator();
+    while( tempItr.hasNext() ) {
+      TempDescriptor temp = tempItr.next();
+      VariableSourceToken vst = fsen.getStaticInVarSrc( temp );
+      SESEandAgePair srcPair = new SESEandAgePair( vst.getSESE(), vst.getAge() );
+      
+      // can't grab something from this source until it is done
+      output.println("   {");
+      output.println("     SESEcommon* com = (SESEcommon*)"+paramsprefix+"->"+srcPair+";" );
+      output.println("     pthread_mutex_lock( &(com->lock) );");
+      output.println("     while( com->doneExecuting == FALSE ) {");
+      output.println("       pthread_cond_wait( &(com->doneCond), &(com->lock) );");
+      output.println("     }");
+      output.println("     pthread_mutex_unlock( &(com->lock) );");
+
+      output.println("     "+generateTemp( fsen.getfmBogus(), temp, null )+
+                    " = "+paramsprefix+"->"+srcPair+"->"+vst.getAddrVar()+";");
+
+      output.println("   }");
+    }
+
+    // dynamic vars come from an SESE and src
+    tempItr = fsen.getDynamicInVarSet().iterator();
+    while( tempItr.hasNext() ) {
+      TempDescriptor temp = tempItr.next();
+      TypeDescriptor type = temp.getType();
+      
+      // go grab it from the SESE source
+      output.println("   if( "+paramsprefix+"->"+temp+"_srcSESE != NULL ) {");
+
+      // gotta wait until the source is done
+      output.println("     SESEcommon* com = (SESEcommon*)"+paramsprefix+"->"+temp+"_srcSESE;" );
+      output.println("     pthread_mutex_lock( &(com->lock) );");
+      output.println("     while( com->doneExecuting == FALSE ) {");
+      output.println("       pthread_cond_wait( &(com->doneCond), &(com->lock) );");
+      output.println("     }");
+      output.println("     pthread_mutex_unlock( &(com->lock) );");
+
+      String typeStr;
+      if( type.isNull() ) {
+       typeStr = "void*";
+      } else if( type.isClass() || type.isArray() ) {
+       typeStr = "struct "+type.getSafeSymbol()+"*";
+      } else {
+       typeStr = type.getSafeSymbol();
+      }
+      
+      output.println("     "+generateTemp( fsen.getfmBogus(), temp, null )+
+                    " = *(("+typeStr+"*) ("+
+                    paramsprefix+"->"+temp+"_srcSESE + "+
+                    paramsprefix+"->"+temp+"_srcOffset));");
+
+      // or if the source was our parent, its in the record to grab
+      output.println("   } else {");
+      output.println("     "+generateTemp( fsen.getfmBogus(), temp, null )+
+                          " = "+paramsprefix+"->"+temp+";");
+      output.println("   }");
     }
-    
 
     // Check to see if we need to do a GC if this is a
     // multi-threaded program...    
-    if (GENERATEPRECISEGC) {
+    if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
       //Don't bother if we aren't in recursive methods...The loops case will catch it
       if (callgraph.getAllMethods(md).contains(md)) {
-        output.println("if (needtocollect) checkcollect("+localsprefixaddr+");");
+        if(this.state.MULTICOREGC) {
+          output.println("if(gcflag) gc("+localsprefixaddr+");");
+        } else {
+          output.println("if (needtocollect) checkcollect("+localsprefixaddr+");");
+        }
       }
     }    
 
+    // initialize thread-local var to a non-zero, invalid address
+    output.println("   seseCaller = (SESEcommon*) 0x2;");
+
     HashSet<FlatNode> exitset=new HashSet<FlatNode>();
-    exitset.add(seseExit);
-    generateCode(seseEnter.getNext(0), fm, null, exitset, output, true);
+    exitset.add(seseExit);    
 
+    generateCode(fsen.getNext(0), fm, null, exitset, output, true);
     
     output.println("}\n\n");
   }
 
+
+  // when a new mlp thread is created for an issued SESE, it is started
+  // by running this method which blocks on a cond variable until
+  // it is allowed to transition to execute.  Then a case statement
+  // allows it to invoke the method with the proper SESE body, and after
+  // exiting the SESE method, executes proper SESE exit code before the
+  // thread can be destroyed
+  private void generateSESEinvocationMethod(PrintWriter outmethodheader,
+                                            PrintWriter outmethod
+                                            ) {
+
+    outmethodheader.println("void* invokeSESEmethod( void* seseRecord );");
+    outmethod.println(      "void* invokeSESEmethod( void* seseRecord ) {");
+    outmethod.println(      "  int status;");
+    outmethod.println(      "  char errmsg[128];");
+
+    // generate a case for each SESE class that can be invoked
+    outmethod.println(      "  switch( *((int*)seseRecord) ) {");
+    outmethod.println(      "    ");
+    for(Iterator<FlatSESEEnterNode> seseit=mlpa.getAllSESEs().iterator();seseit.hasNext();) {
+      FlatSESEEnterNode fsen = seseit.next();
+
+      outmethod.println(    "    /* "+fsen.getPrettyIdentifier()+" */");
+      outmethod.println(    "    case "+fsen.getIdentifier()+":");
+      outmethod.println(    "      "+fsen.getSESEmethodName()+"( seseRecord );");  
+      
+      if( fsen.equals( mlpa.getMainSESE() ) ) {
+       outmethod.println(  "      /* work scheduler works forever, explicitly exit */");
+       outmethod.println(  "      exit( 0 );");
+      }
+
+      outmethod.println(    "      break;");
+      outmethod.println(    "");
+    }
+
+    // default case should never be taken, error out
+    outmethod.println(      "    default:");
+    outmethod.println(      "      printf(\"Error: unknown SESE class ID in invoke method.\\n\");");
+    outmethod.println(      "      exit(-30);");
+    outmethod.println(      "      break;");
+    outmethod.println(      "  }");
+    outmethod.println(      "  return NULL;");
+    outmethod.println(      "}\n\n");
+  }
+
+
   protected void generateCode(FlatNode first,
                               FlatMethod fm,
                               LocalityBinding lb,
                              Set<FlatNode> stopset,
                               PrintWriter output, boolean firstpass) {
 
-    // for any method, allocate temps to use when
-    // issuing a new SESE sometime during the execution
-    // of that method, whether it be a user-defined method
-    // or a method representing the body of an SESE
-    // TODO: only do this if we know the method actually
-    // contains an SESE issue, not currently an annotation    
-    if( state.MLP ) {
-      output.println("   SESErecord*     tempSESE;");
-      output.println("   invokeSESEargs* tempSESEargs;");
-    }    
-
     /* Assign labels to FlatNode's if necessary.*/
     Hashtable<FlatNode, Integer> nodetolabel=assignLabels(first, stopset);
 
     Set<FlatNode> storeset=null;
     HashSet<FlatNode> genset=null;
+    Set<FlatNode> unionset=null;
 
     if (state.DELAYCOMP&&!lb.isAtomic()&&lb.getHasAtomic()) {
       storeset=delaycomp.livecode(lb);
@@ -1922,6 +2104,9 @@ public class BuildCode {
       } else {
        genset.addAll(delaycomp.getNotReady(lb));
       }
+      unionset=new HashSet<FlatNode>();
+      unionset.addAll(storeset);
+      unionset.addAll(genset);
     }
     
     /* Do the actual code generation */
@@ -1962,13 +2147,24 @@ public class BuildCode {
            output.println("primitives->"+tmp.getSafeSymbol()+"="+tmp.getSafeSymbol()+";");
          }
        }
+       if (state.MLP && stopset!=null) {
+         assert first.getPrev( 0 ) instanceof FlatSESEEnterNode;
+         assert current_node       instanceof FlatSESEExitNode;
+         FlatSESEEnterNode fsen = (FlatSESEEnterNode) first.getPrev( 0 );
+         FlatSESEExitNode  fsxn = (FlatSESEExitNode)  current_node;
+         assert fsen.getFlatExit().equals( fsxn );
+         assert fsxn.getFlatEnter().equals( fsen );
+       }
        if (current_node.kind()!=FKind.FlatReturnNode) {
          output.println("   return;");
        }
        current_node=null;
       } else if(current_node.numNext()==1) {
        FlatNode nextnode;
-       if (state.MLP && current_node.kind()==FKind.FlatSESEEnterNode) {
+       if (state.MLP && 
+           current_node.kind()==FKind.FlatSESEEnterNode && 
+           !((FlatSESEEnterNode)current_node).getIsCallerSESEplaceholder()
+          ) {
          FlatSESEEnterNode fsen = (FlatSESEEnterNode)current_node;
          generateFlatNode(fm, lb, current_node, output);
          nextnode=fsen.getFlatExit().getNext(0);
@@ -1989,7 +2185,12 @@ public class BuildCode {
            if (firstpass) {
              //need to store value written by previous node
              if (wrtmp.getType().isPtr()) {
-               output.println("STOREPTR("+generateTemp(fm, wrtmp,lb)+");");
+               //only lock the objects that may actually need locking
+               if (recorddc.getNeedTrans(lb, current_node)) {
+                 output.println("STOREPTR("+generateTemp(fm, wrtmp,lb)+");");
+               } else {
+                 output.println("STOREPTRNOLOCK("+generateTemp(fm, wrtmp,lb)+");");
+               }
              } else {
                output.println("STORE"+wrtmp.getType().getSafeDescriptor()+"("+generateTemp(fm, wrtmp, lb)+");");
              }
@@ -2016,31 +2217,62 @@ public class BuildCode {
       } else if (current_node.numNext()==2) {
        /* Branch */
        if (state.DELAYCOMP) {
+         boolean computeside=false;
          if (firstpass) {
            //need to record which way it should go
-           output.print("   ");
-           if (storeset!=null&&storeset.contains(current_node)) {
-             //need to store which way branch goes
-             generateStoreFlatCondBranch(fm, lb, (FlatCondBranch)current_node, "L"+nodetolabel.get(current_node.getNext(1)), output);
-           } else
-             generateFlatCondBranch(fm, lb, (FlatCondBranch)current_node, "L"+nodetolabel.get(current_node.getNext(1)), output);
+           if (genset==null||genset.contains(current_node)) {
+             if (storeset!=null&&storeset.contains(current_node)) {
+               //need to store which way branch goes
+               generateStoreFlatCondBranch(fm, lb, (FlatCondBranch)current_node, "L"+nodetolabel.get(current_node.getNext(1)), output);
+             } else
+               generateFlatCondBranch(fm, lb, (FlatCondBranch)current_node, "L"+nodetolabel.get(current_node.getNext(1)), output);
+           } else {
+             //which side to execute
+             computeside=true;
+           }
          } else {
-           if (storeset.contains(current_node)) {
+           if (genset.contains(current_node)) {
+             generateFlatCondBranch(fm, lb, (FlatCondBranch)current_node, "L"+nodetolabel.get(current_node.getNext(1)), output);             
+           } else if (storeset.contains(current_node)) {
              //need to do branch
              output.println("RESTOREANDBRANCH(L"+nodetolabel.get(current_node.getNext(1))+");");
+           } else {
+             //which side to execute
+             computeside=true;
+           }
+         }
+         if (computeside) {
+           Set<FlatNode> leftset=DelayComputation.getNext(current_node, 0, unionset, lb,locality, true);
+           int branch=0;
+           if (leftset.size()==0)
+             branch=1;
+           if (visited.contains(current_node.getNext(branch))) {
+             //already visited -- build jump
+             output.println("goto L"+nodetolabel.get(current_node.getNext(branch))+";");
+             current_node=null;
+           } else {
+             current_node=current_node.getNext(branch);
            }
+         } else {
+           if (!visited.contains(current_node.getNext(1)))
+             tovisit.add(current_node.getNext(1));
+           if (visited.contains(current_node.getNext(0))) {
+             output.println("goto L"+nodetolabel.get(current_node.getNext(0))+";");
+             current_node=null;
+           } else 
+             current_node=current_node.getNext(0);
          }
        } else {
          output.print("   ");  
          generateFlatCondBranch(fm, lb, (FlatCondBranch)current_node, "L"+nodetolabel.get(current_node.getNext(1)), output);
+         if (!visited.contains(current_node.getNext(1)))
+           tovisit.add(current_node.getNext(1));
+         if (visited.contains(current_node.getNext(0))) {
+           output.println("goto L"+nodetolabel.get(current_node.getNext(0))+";");
+           current_node=null;
+         } else 
+           current_node=current_node.getNext(0);
        }
-       if (!visited.contains(current_node.getNext(1)))
-         tovisit.add(current_node.getNext(1));
-       if (visited.contains(current_node.getNext(0))) {
-         output.println("goto L"+nodetolabel.get(current_node.getNext(0))+";");
-         current_node=null;
-       } else 
-         current_node=current_node.getNext(0);
       } else throw new Error();
     }
   }
@@ -2114,6 +2346,102 @@ public class BuildCode {
   }
 
   protected void generateFlatNode(FlatMethod fm, LocalityBinding lb, FlatNode fn, PrintWriter output) {
+
+    // insert pre-node actions from the code plan
+    if( state.MLP ) {
+      
+      CodePlan cp = mlpa.getCodePlan( fn );
+      if( cp != null ) {               
+       
+       FlatSESEEnterNode currentSESE = cp.getCurrentSESE();
+       
+       // for each sese and age pair that this parent statement
+       // must stall on, take that child's stall semaphore, the
+       // copying of values comes after the statement
+       Iterator<VariableSourceToken> vstItr = cp.getStallTokens().iterator();
+       while( vstItr.hasNext() ) {
+         VariableSourceToken vst = vstItr.next();
+
+         SESEandAgePair p = new SESEandAgePair( vst.getSESE(), vst.getAge() );
+
+         output.println("   {");
+         output.println("     SESEcommon* common = (SESEcommon*) "+p+";");
+
+         output.println("     pthread_mutex_lock( &(common->lock) );");
+         output.println("     while( common->doneExecuting == FALSE ) {");
+         output.println("       pthread_cond_wait( &(common->doneCond), &(common->lock) );");
+         output.println("     }");
+         output.println("     pthread_mutex_unlock( &(common->lock) );");
+                 
+         //output.println("     psem_take( &(common->stallSem) );");
+
+         // copy things we might have stalled for        
+         output.println("     "+p.getSESE().getSESErecordName()+"* child = ("+
+                                p.getSESE().getSESErecordName()+"*) "+p+";");
+         
+         Iterator<TempDescriptor> tdItr = cp.getCopySet( vst ).iterator();
+         while( tdItr.hasNext() ) {
+           TempDescriptor td = tdItr.next();
+           FlatMethod fmContext;
+           if( currentSESE.getIsCallerSESEplaceholder() ) {
+             fmContext = currentSESE.getfmEnclosing();
+           } else {
+             fmContext = currentSESE.getfmBogus();
+           }
+           output.println("       "+generateTemp( fmContext, td, null )+
+                          " = child->"+vst.getAddrVar().getSafeSymbol()+";");
+         }
+
+         output.println("   }");
+       }
+       
+       // for each variable with a dynamic source, stall just for that variable
+       Iterator<TempDescriptor> dynItr = cp.getDynamicStallSet().iterator();
+       while( dynItr.hasNext() ) {
+         TempDescriptor dynVar = dynItr.next();
+
+         // only stall if the dynamic source is not yourself, denoted by src==NULL
+         // otherwise the dynamic write nodes will have the local var up-to-date
+         output.println("   {");
+         output.println("     if( "+dynVar+"_srcSESE != NULL ) {");
+         output.println("       SESEcommon* common = (SESEcommon*) "+dynVar+"_srcSESE;");
+         output.println("       psem_take( &(common->stallSem) );");
+
+         FlatMethod fmContext;
+         if( currentSESE.getIsCallerSESEplaceholder() ) {
+           fmContext = currentSESE.getfmEnclosing();
+         } else {
+           fmContext = currentSESE.getfmBogus();
+         }
+         output.println("       "+generateTemp( fmContext, dynVar, null )+
+                        " = *(("+dynVar.getType()+"*) ("+
+                        dynVar+"_srcSESE + "+dynVar+"_srcOffset));");
+         
+         output.println("     }");
+         output.println("   }");
+       }
+
+       // for each assignment of a variable to rhs that has a dynamic source,
+       // copy the dynamic sources
+       Iterator dynAssignItr = cp.getDynAssigns().entrySet().iterator();
+       while( dynAssignItr.hasNext() ) {
+         Map.Entry      me  = (Map.Entry)      dynAssignItr.next();
+         TempDescriptor lhs = (TempDescriptor) me.getKey();
+         TempDescriptor rhs = (TempDescriptor) me.getValue();
+         output.println("   "+lhs+"_srcSESE   = "+rhs+"_srcSESE;");
+         output.println("   "+lhs+"_srcOffset = "+rhs+"_srcOffset;");
+       }
+
+       // for each lhs that is dynamic from a non-dynamic source, set the
+       // dynamic source vars to the current SESE
+       dynItr = cp.getDynAssignCurr().iterator();
+       while( dynItr.hasNext() ) {
+         TempDescriptor dynVar = dynItr.next();
+         output.println("   "+dynVar+"_srcSESE = NULL;");
+       }
+      }     
+    }
+
     switch(fn.kind()) {
     case FKind.FlatAtomicEnterNode:
       generateFlatAtomicEnterNode(fm, lb, (FlatAtomicEnterNode) fn, output);
@@ -2134,6 +2462,10 @@ public class BuildCode {
     case FKind.FlatSESEExitNode:
       generateFlatSESEExitNode(fm, lb, (FlatSESEExitNode)fn, output);
       break;
+      
+    case FKind.FlatWriteDynamicVarNode:
+      generateFlatWriteDynamicVarNode(fm, lb, (FlatWriteDynamicVarNode)fn, output);
+      break;
 
     case FKind.FlatGlobalConvNode:
       generateFlatGlobalConvNode(fm, lb, (FlatGlobalConvNode) fn, output);
@@ -2192,10 +2524,13 @@ public class BuildCode {
       break;
 
     case FKind.FlatBackEdge:
-      if ((state.THREAD||state.DSM||state.SINGLETM)&&GENERATEPRECISEGC) {
+      if (((state.THREAD||state.DSM||state.SINGLETM)&&GENERATEPRECISEGC)
+          || (this.state.MULTICOREGC)) {
        if(state.DSM&&locality.getAtomic(lb).get(fn).intValue()>0) {
          output.println("if (needtocollect) checkcollect2("+localsprefixaddr+");");
-       } else
+       } else if(this.state.MULTICOREGC) {
+      output.println("if (gcflag) gc("+localsprefixaddr+");");
+    } else
          output.println("if (needtocollect) checkcollect("+localsprefixaddr+");");
       } else
        output.println("/* nop */");
@@ -2221,17 +2556,13 @@ public class BuildCode {
       throw new Error();
     }
 
+    // insert post-node actions from the code-plan    
     if( state.MLP ) {
-
       CodePlan cp = mlpa.getCodePlan( fn );
-      if( cp != null ) {     
 
-       Set<VariableSourceToken> writeDynamic = cp.getWriteToDynamicSrc();      
-       if( writeDynamic != null ) {
-         
-       }
+      if( cp != null ) {     
       }
-    }
+    }    
   }
 
   public void generateFlatOffsetNode(FlatMethod fm, LocalityBinding lb, FlatOffsetNode fofn, PrintWriter output) {
@@ -2416,9 +2747,11 @@ public class BuildCode {
       if (state.DSM) {
        output.println("TRANSREAD("+generateTemp(fm, fgcn.getSrc(),lb)+", (unsigned int) "+generateTemp(fm, fgcn.getSrc(),lb)+");");
       } else {
-       if ((dc==null)||dc.getNeedTrans(lb, fgcn)) {
+       if ((dc==null)||!state.READSET&&dc.getNeedTrans(lb, fgcn)||state.READSET&&dc.getNeedWriteTrans(lb, fgcn)) {
          //need to do translation
          output.println("TRANSREAD("+generateTemp(fm, fgcn.getSrc(),lb)+", "+generateTemp(fm, fgcn.getSrc(),lb)+", (void *)("+localsprefixaddr+"));");
+       } else if (state.READSET&&dc.getNeedTrans(lb, fgcn)) {
+         output.println("TRANSREADRD("+generateTemp(fm, fgcn.getSrc(),lb)+", "+generateTemp(fm, fgcn.getSrc(),lb)+");");
        }
       }
     } else {
@@ -2559,50 +2892,334 @@ public class BuildCode {
     }
   }
 
-  public void generateFlatSESEEnterNode(FlatMethod fm,  LocalityBinding lb, FlatSESEEnterNode fsen, PrintWriter output) {
+  public void generateFlatSESEEnterNode( FlatMethod fm,  
+                                        LocalityBinding lb, 
+                                        FlatSESEEnterNode fsen, 
+                                        PrintWriter output 
+                                      ) {
+
+    // if MLP flag is off, okay that SESE nodes are in IR graph, 
+    // just skip over them and code generates exactly the same
     if( !state.MLP ) {
-      // SESE nodes can be parsed for normal compilation, just skip over them
       return;
-    }
-    
-    output.println("\n   /* SESE "+fsen.getPrettyIdentifier()+" issue */");
-    output.println("   tempSESE = mlpCreateSESErecord( "+
-                   fsen.getIdentifier()+", "+
-                   "malloc( sizeof( "+fsen.namespaceStructNameString()+") ), "+
-                   "NULL );");
+    }    
 
-    for( int i = 0; i < fsen.numParameters(); ++i ) {
-      TempDescriptor td = fsen.getParameter( i );
-      output.println("   (("+fsen.namespaceStructNameString()+
-                         "*)tempSESE->namespace)->"+td+" = "+td+";");
+    // there may be an SESE in an unreachable method, skip over
+    if( !mlpa.getAllSESEs().contains( fsen ) ) {
+      return;
     }
 
-    output.println("   mlpIssue( tempSESE );");
-    //output.println("   tempSESE = mlpSchedule();");
+    // also, if we have encountered a placeholder, just skip it
+    if( fsen.getIsCallerSESEplaceholder() ) {
+      return;
+    }
 
-    // do a pthread_create wit invokeSESE as the argument
-    // and pack all args into a single void*
-    output.println("   tempSESEargs = malloc( sizeof( invokeSESEargs ) );");
-    output.println("   tempSESEargs->classID = "+fsen.getIdentifier()+";");
-    output.println("   tempSESEargs->invokee = mlpSchedule();");
+    output.println("   {");
 
-    if( fsen.getParent() == null ) {
-      output.println("   tempSESEargs->parent  = NULL;");
+    // set up the parent
+    if( fsen == mlpa.getMainSESE() ) {
+      output.println("     SESEcommon* parentCommon = NULL;");
     } else {
-      output.println("   tempSESEargs->parent  = currentSESE;");
+      if( fsen.getParent() == null ) {
+       System.out.println( "in "+fm+", "+fsen+" has null parent" );
+      }
+      assert fsen.getParent() != null;
+      if( !fsen.getParent().getIsCallerSESEplaceholder() ) {
+       output.println("     SESEcommon* parentCommon = &("+paramsprefix+"->common);");
+      } else {
+       //output.println("     SESEcommon* parentCommon = (SESEcommon*) peekItem( seseCallStack );");
+       output.println("     SESEcommon* parentCommon = seseCaller;");
+      }
+    }
+
+    // before doing anything, lock your own record and increment the running children
+    if( fsen != mlpa.getMainSESE() ) {      
+      output.println("     pthread_mutex_lock( &(parentCommon->lock) );");
+      output.println("     ++(parentCommon->numRunningChildren);");
+      output.println("     pthread_mutex_unlock( &(parentCommon->lock) );");      
+    }
+
+    // just allocate the space for this record
+    output.println("     "+fsen.getSESErecordName()+"* seseToIssue = ("+
+                          fsen.getSESErecordName()+"*) mlpAllocSESErecord( sizeof( "+
+                          fsen.getSESErecordName()+" ) );");
+
+    // and keep the thread-local sese stack up to date
+    //output.println("     addNewItem( seseCallStack, (void*) seseToIssue);");
+
+    // fill in common data
+    output.println("     seseToIssue->common.classID = "+fsen.getIdentifier()+";");
+    output.println("     psem_init( &(seseToIssue->common.stallSem) );");
+
+    output.println("     seseToIssue->common.forwardList = createQueue();");
+    output.println("     seseToIssue->common.unresolvedDependencies = 0;");
+    output.println("     pthread_cond_init( &(seseToIssue->common.doneCond), NULL );");
+    output.println("     seseToIssue->common.doneExecuting = FALSE;");    
+    output.println("     pthread_cond_init( &(seseToIssue->common.runningChildrenCond), NULL );");
+    output.println("     seseToIssue->common.numRunningChildren = 0;");
+    output.println("     seseToIssue->common.parent = parentCommon;");
+
+    // all READY in-vars should be copied now and be done with it
+    Iterator<TempDescriptor> tempItr = fsen.getReadyInVarSet().iterator();
+    while( tempItr.hasNext() ) {
+      TempDescriptor temp = tempItr.next();
+
+      // when we are issuing the main SESE or an SESE with placeholder
+      // caller SESE as parent, generate temp child child's eclosing method,
+      // otherwise use the parent's enclosing method as the context
+      boolean useParentContext = false;
+
+      if( fsen != mlpa.getMainSESE() ) {
+       assert fsen.getParent() != null;
+       if( !fsen.getParent().getIsCallerSESEplaceholder() ) {
+         useParentContext = true;
+       }
+      }
+
+      if( useParentContext ) {
+       output.println("     seseToIssue->"+temp+" = "+
+                      generateTemp( fsen.getParent().getfmBogus(), temp, null )+";");   
+      } else {
+       output.println("     seseToIssue->"+temp+" = "+
+                      generateTemp( fsen.getfmEnclosing(), temp, null )+";");
+      }
     }
 
-    output.println("   invokeSESEmethod( (void*) tempSESEargs );");   
-    output.println("\n");
+    // before potentially adding this SESE to other forwarding lists,
+    //  create it's lock and take it immediately
+    output.println("     pthread_mutex_init( &(seseToIssue->common.lock), NULL );");
+    output.println("     pthread_mutex_lock( &(seseToIssue->common.lock) );");
+
+    if( fsen != mlpa.getMainSESE() ) {
+      // count up outstanding dependencies, static first, then dynamic
+      Iterator<SESEandAgePair> staticSrcsItr = fsen.getStaticInVarSrcs().iterator();
+      while( staticSrcsItr.hasNext() ) {
+       SESEandAgePair srcPair = staticSrcsItr.next();
+       output.println("     {");
+       output.println("       SESEcommon* src = (SESEcommon*)"+srcPair+";");
+       output.println("       pthread_mutex_lock( &(src->lock) );");
+       output.println("       if( !isEmpty( src->forwardList ) &&");
+       output.println("           seseToIssue == peekItem( src->forwardList ) ) {");
+       output.println("         printf( \"This shouldnt already be here\\n\");");
+       output.println("         exit( -1 );");
+       output.println("       }");
+       output.println("       if( !src->doneExecuting ) {");
+       output.println("         addNewItem( src->forwardList, seseToIssue );");
+       output.println("         ++(seseToIssue->common.unresolvedDependencies);");
+       output.println("       }");
+       output.println("       pthread_mutex_unlock( &(src->lock) );");
+       output.println("     }");
+
+       // whether or not it is an outstanding dependency, make sure
+       // to pass the static name to the child's record
+       output.println("     seseToIssue->"+srcPair+" = "+srcPair+";");
+      }
+
+      // dynamic sources might already be accounted for in the static list,
+      // so only add them to forwarding lists if they're not already there
+      Iterator<TempDescriptor> dynVarsItr = fsen.getDynamicInVarSet().iterator();
+      while( dynVarsItr.hasNext() ) {
+       TempDescriptor dynInVar = dynVarsItr.next();
+       output.println("     {");
+       output.println("       SESEcommon* src = (SESEcommon*)"+dynInVar+"_srcSESE;");
+
+       // the dynamic source is NULL if it comes from your own space--you can't pass
+       // the address off to the new child, because you're not done executing and
+       // might change the variable, so copy it right now
+       output.println("       if( src != NULL ) {");
+       output.println("         pthread_mutex_lock( &(src->lock) );");
+       output.println("         if( isEmpty( src->forwardList ) ||");
+       output.println("             seseToIssue != peekItem( src->forwardList ) ) {");
+       output.println("           if( !src->doneExecuting ) {");
+       output.println("             addNewItem( src->forwardList, seseToIssue );");
+       output.println("             ++(seseToIssue->common.unresolvedDependencies);");
+       output.println("           }");
+       output.println("         }");
+       output.println("         pthread_mutex_unlock( &(src->lock) );");       
+       output.println("         seseToIssue->"+dynInVar+"_srcOffset = "+dynInVar+"_srcOffset;");
+       output.println("       } else {");
+
+       boolean useParentContext = false;
+       if( fsen != mlpa.getMainSESE() ) {
+         assert fsen.getParent() != null;
+         if( !fsen.getParent().getIsCallerSESEplaceholder() ) {
+           useParentContext = true;
+         }
+       }       
+       if( useParentContext ) {
+         output.println("         seseToIssue->"+dynInVar+" = "+
+                        generateTemp( fsen.getParent().getfmBogus(), dynInVar, null )+";");
+       } else {
+         output.println("         seseToIssue->"+dynInVar+" = "+
+                        generateTemp( fsen.getfmEnclosing(), dynInVar, null )+";");
+       }
+       
+       output.println("       }");
+       output.println("     }");
+       
+       // even if the value is already copied, make sure your NULL source
+       // gets passed so child knows it already has the dynamic value
+       output.println("     seseToIssue->"+dynInVar+"_srcSESE = "+dynInVar+"_srcSESE;");
+      }
+      
+      // maintain pointers for for finding dynamic SESE 
+      // instances from static names      
+      SESEandAgePair p = new SESEandAgePair( fsen, 0 );
+      if(  fsen.getParent() != null && 
+          //!fsen.getParent().getIsCallerSESEplaceholder() &&
+          fsen.getParent().getNeededStaticNames().contains( p ) 
+       ) {       
+
+       for( int i = fsen.getOldestAgeToTrack(); i > 0; --i ) {
+         SESEandAgePair p1 = new SESEandAgePair( fsen, i   );
+         SESEandAgePair p2 = new SESEandAgePair( fsen, i-1 );
+         output.println("     "+p1+" = "+p2+";");
+       }      
+       output.println("     "+p+" = seseToIssue;");
+      }
+    }
+
+    // if there were no outstanding dependencies, issue here
+    output.println("     if( seseToIssue->common.unresolvedDependencies == 0 ) {");
+    output.println("       workScheduleSubmit( (void*)seseToIssue );");
+    output.println("     }");
+
+    // release this SESE for siblings to update its dependencies or,
+    // eventually, for it to mark itself finished
+    output.println("     pthread_mutex_unlock( &(seseToIssue->common.lock) );");
+    output.println("   }");
+
   }
 
-  public void generateFlatSESEExitNode(FlatMethod fm,  LocalityBinding lb, FlatSESEExitNode fsen, PrintWriter output) {
+  public void generateFlatSESEExitNode( FlatMethod fm,  
+                                       LocalityBinding lb, 
+                                       FlatSESEExitNode fsexn, 
+                                       PrintWriter output
+                                     ) {
+
+    // if MLP flag is off, okay that SESE nodes are in IR graph, 
+    // just skip over them and code generates exactly the same 
     if( !state.MLP ) {
-      // SESE nodes can be parsed for normal compilation, just skip over them
       return;
     }
+
+    // there may be an SESE in an unreachable method, skip over
+    if( !mlpa.getAllSESEs().contains( fsexn.getFlatEnter() ) ) {
+      return;
+    }
+
+    // also, if we have encountered a placeholder, just jump it
+    if( fsexn.getFlatEnter().getIsCallerSESEplaceholder() ) {
+      return;
+    }
+
+    output.println("   /* SESE exiting */");
+
+    String com = paramsprefix+"->common";
+
+    // this SESE cannot be done until all of its children are done
+    // so grab your own lock with the condition variable for watching
+    // that the number of your running children is greater than zero    
+    output.println("   pthread_mutex_lock( &("+com+".lock) );");
+    output.println("   while( "+com+".numRunningChildren > 0 ) {");
+    output.println("     pthread_cond_wait( &("+com+".runningChildrenCond), &("+com+".lock) );");
+    output.println("   }");
+
+    // copy out-set from local temps into the sese record
+    Iterator<TempDescriptor> itr = fsexn.getFlatEnter().getOutVarSet().iterator();
+    while( itr.hasNext() ) {
+      TempDescriptor temp = itr.next();      
+      output.println("   "+paramsprefix+
+                    "->"+temp.getSafeSymbol()+
+                    " = "+temp.getSafeSymbol()+";" );
+    }    
+    
+    // mark yourself done, your SESE data is now read-only
+    output.println("   "+com+".doneExecuting = TRUE;");
+    output.println("   pthread_cond_signal( &("+com+".doneCond) );");
+    output.println("   pthread_mutex_unlock( &("+com+".lock) );");
+
+    // decrement dependency count for all SESE's on your forwarding list
+    output.println("   while( !isEmpty( "+com+".forwardList ) ) {");
+    output.println("     SESEcommon* consumer = (SESEcommon*) getItem( "+com+".forwardList );");
+    output.println("     pthread_mutex_lock( &(consumer->lock) );");
+    output.println("     --(consumer->unresolvedDependencies);");
+    output.println("     if( consumer->unresolvedDependencies == 0 ) {");
+    output.println("       workScheduleSubmit( (void*)consumer );");
+    output.println("     }");
+    output.println("     pthread_mutex_unlock( &(consumer->lock) );");
+    output.println("   }");
+    
+    // if parent is stalling on you, let them know you're done
+    if( fsexn.getFlatEnter() != mlpa.getMainSESE() ) {
+      output.println("   psem_give( &("+paramsprefix+"->common.stallSem) );");
+    }
+
+    // last of all, decrement your parent's number of running children    
+    output.println("   if( "+paramsprefix+"->common.parent != NULL ) {");
+    output.println("     pthread_mutex_lock( &("+paramsprefix+"->common.parent->lock) );");
+    output.println("     --("+paramsprefix+"->common.parent->numRunningChildren);");
+    output.println("     pthread_cond_signal( &("+paramsprefix+"->common.parent->runningChildrenCond) );");
+    output.println("     pthread_mutex_unlock( &("+paramsprefix+"->common.parent->lock) );");
+    output.println("   }");    
+
+    // this is a thread-only variable that can be handled when critical sese-to-sese
+    // data has been taken care of--set sese pointer to remember self over method
+    // calls to a non-zero, invalid address
+    output.println("   seseCaller = (SESEcommon*) 0x1;");    
+  }
+
+  public void generateFlatWriteDynamicVarNode( FlatMethod fm,  
+                                              LocalityBinding lb, 
+                                              FlatWriteDynamicVarNode fwdvn,
+                                              PrintWriter output
+                                            ) {
+    if( !state.MLP ) {
+      // should node should not be in an IR graph if the
+      // MLP flag is not set
+      throw new Error("Unexpected presence of FlatWriteDynamicVarNode");
+    }
+       
+    Hashtable<TempDescriptor, VariableSourceToken> writeDynamic = 
+      fwdvn.getVar2src();
+
+    assert writeDynamic != null;
+
+    Iterator wdItr = writeDynamic.entrySet().iterator();
+    while( wdItr.hasNext() ) {
+      Map.Entry           me     = (Map.Entry)           wdItr.next();
+      TempDescriptor      refVar = (TempDescriptor)      me.getKey();
+      VariableSourceToken vst    = (VariableSourceToken) me.getValue();
+      
+      FlatSESEEnterNode current = fwdvn.getEnclosingSESE();
+
+      // only do this if the variable in question should be tracked,
+      // meaning that it was explicitly added to the dynamic var set
+      if( !current.getDynamicVarSet().contains( vst.getAddrVar() ) ) {
+       continue;
+      }
+
+      SESEandAgePair instance = new SESEandAgePair( vst.getSESE(), vst.getAge() );      
+
+      output.println("   {");
+
+      if( current.equals( vst.getSESE() ) ) {
+       // if the src comes from this SESE, it's a method local variable,
+       // mark src pointer NULL to signify that the var is up-to-date
+       output.println("     "+vst.getAddrVar()+"_srcSESE = NULL;");
+
+      } else {
+       // otherwise we track where it will come from
+       output.println("     "+vst.getAddrVar()+"_srcSESE = "+instance+";");    
+       output.println("     "+vst.getAddrVar()+"_srcOffset = (int) &((("+
+                      vst.getSESE().getSESErecordName()+"*)0)->"+vst.getAddrVar()+");");
+      }
+
+      output.println("   }");
+    }  
   }
 
+  
   private void generateFlatCheckNode(FlatMethod fm,  LocalityBinding lb, FlatCheckNode fcn, PrintWriter output) {
     if (state.CONSCHECK) {
       String specname=fcn.getSpec();
@@ -2628,12 +3245,17 @@ public class BuildCode {
   }
 
   private void generateFlatCall(FlatMethod fm, LocalityBinding lb, FlatCall fc, PrintWriter output) {
+
+    if( state.MLP && !nonSESEpass ) {
+      output.println("     seseCaller = (SESEcommon*)"+paramsprefix+";");
+    }
+
     MethodDescriptor md=fc.getMethod();
-    ParamsObject objectparams=(ParamsObject)paramstable.get(state.DSM||state.SINGLETM ? locality.getBinding(lb, fc) : md);
+    ParamsObject objectparams=(ParamsObject)paramstable.get(lb!=null ? locality.getBinding(lb, fc) : md);
     ClassDescriptor cn=md.getClassDesc();
     output.println("{");
-    if (GENERATEPRECISEGC) {
-      if (state.DSM||state.SINGLETM) {
+    if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
+      if (lb!=null) {
        LocalityBinding fclb=locality.getBinding(lb, fc);
        output.print("       struct "+cn.getSafeSymbol()+fclb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={");
       } else
@@ -2675,7 +3297,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||state.SINGLETM) {
+      if (lb!=null) {
        LocalityBinding fclb=locality.getBinding(lb, fc);
        output.print(cn.getSafeSymbol()+fclb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor());
       } else {
@@ -2691,8 +3313,8 @@ public class BuildCode {
       output.print("(*)(");
 
       boolean printcomma=false;
-      if (GENERATEPRECISEGC) {
-       if (state.DSM||state.SINGLETM) {
+      if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
+       if (lb!=null) {
          LocalityBinding fclb=locality.getBinding(lb, fc);
          output.print("struct "+cn.getSafeSymbol()+fclb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params * ");
        } else
@@ -2712,7 +3334,7 @@ public class BuildCode {
       }
 
 
-      if (state.DSM||state.SINGLETM) {
+      if (lb!=null) {
        LocalityBinding fclb=locality.getBinding(lb, fc);
        output.print("))virtualtable["+generateTemp(fm,fc.getThis(),lb)+"->type*"+maxcount+"+"+virtualcalls.getLocalityNumber(fclb)+"])");
       } else
@@ -2721,12 +3343,12 @@ public class BuildCode {
 
     output.print("(");
     boolean needcomma=false;
-    if (GENERATEPRECISEGC) {
+    if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
       output.print("&__parameterlist__");
       needcomma=true;
     }
 
-    if (!GENERATEPRECISEGC) {
+    if (!GENERATEPRECISEGC && !this.state.MULTICOREGC) {
       if (fc.getThis()!=null) {
        TypeDescriptor ptd=md.getThis().getType();
        if (needcomma)
@@ -2782,9 +3404,13 @@ public class BuildCode {
 
       output.println(dst+"="+ src +"->"+field+ ";");
       if (ffn.getField().getType().isPtr()&&locality.getAtomic(lb).get(ffn).intValue()>0&&
-          ((dc==null)||dc.getNeedTrans(lb, ffn))&&
           locality.getNodePreTempInfo(lb, ffn).get(ffn.getSrc())!=LocalityAnalysis.SCRATCH) {
-       output.println("TRANSREAD("+dst+", "+dst+", (void *) (" + localsprefixaddr + "));");
+       if ((dc==null)||(!state.READSET&&dc.getNeedTrans(lb, ffn))||
+           (state.READSET&&dc.getNeedWriteTrans(lb, ffn))) {
+         output.println("TRANSREAD("+dst+", "+dst+", (void *) (" + localsprefixaddr + "));");
+       } else if (state.READSET&&dc.getNeedTrans(lb, ffn)) {
+         output.println("TRANSREADRD("+dst+", "+dst+");");
+       }
       }
     } else if (state.DSM) {
       Integer status=locality.getNodePreTempInfo(lb,ffn).get(ffn.getSrc());
@@ -2849,6 +3475,7 @@ public class BuildCode {
       boolean srcptr=fsfn.getSrc().getType().isPtr();
       String src=generateTemp(fm,fsfn.getSrc(),lb);
       String dst=generateTemp(fm,fsfn.getDst(),lb);
+      output.println("//"+srcptr+" "+fsfn.getSrc().getType().isNull());
       if (srcptr&&!fsfn.getSrc().getType().isNull()) {
        output.println("{");
        if ((dc==null)||dc.getNeedSrcTrans(lb, fsfn)&&
@@ -2894,7 +3521,7 @@ public class BuildCode {
        /* Link object into list */
        String revertptr=generateTemp(fm, reverttable.get(lb),lb);
        output.println(revertptr+"=revertlist;");
-       if (GENERATEPRECISEGC)
+       if (GENERATEPRECISEGC || this.state.MULTICOREGC)
          output.println("COPY_OBJ((struct garbagelist *)"+localsprefixaddr+",(struct ___Object___ *)"+dst+");");
        else
          output.println("COPY_OBJ("+dst+");");
@@ -2922,7 +3549,7 @@ public class BuildCode {
        String dst=generateTemp(fm, fsfn.getDst(),lb);
        output.println("if(!"+dst+"->"+localcopystr+") {");
        /* Link object into list */
-       if (GENERATEPRECISEGC)
+       if (GENERATEPRECISEGC || this.state.MULTICOREGC)
          output.println("COPY_OBJ((struct garbagelist *)"+localsprefixaddr+",(struct ___Object___ *)"+dst+");");
        else
          output.println("COPY_OBJ("+dst+");");
@@ -2953,9 +3580,12 @@ public class BuildCode {
       output.println(dst +"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex(),lb)+"];");
 
       if (elementtype.isPtr()&&locality.getAtomic(lb).get(fen).intValue()>0&&
-          ((dc==null)||dc.getNeedTrans(lb, fen))&&
           locality.getNodePreTempInfo(lb, fen).get(fen.getSrc())!=LocalityAnalysis.SCRATCH) {
-       output.println("TRANSREAD("+dst+", "+dst+", (void *)(" + localsprefixaddr+"));");
+       if ((dc==null)||!state.READSET&&dc.getNeedTrans(lb, fen)||state.READSET&&dc.getNeedWriteTrans(lb, fen)) {
+         output.println("TRANSREAD("+dst+", "+dst+", (void *)(" + localsprefixaddr+"));");
+       } else if (state.READSET&&dc.getNeedTrans(lb, fen)) {
+         output.println("TRANSREADRD("+dst+", "+dst+");");
+       }
       }
     } else if (state.DSM) {
       Integer status=locality.getNodePreTempInfo(lb,fen).get(fen.getSrc());
@@ -3039,8 +3669,8 @@ public class BuildCode {
        /* Link object into list */
        String revertptr=generateTemp(fm, reverttable.get(lb),lb);
        output.println(revertptr+"=revertlist;");
-       if (GENERATEPRECISEGC)
-         output.println("COPY_OBJ((struct garbagelist *)"+localsprefixaddr+",(struct ___Object___ *)"+dst+");");
+       if ((GENERATEPRECISEGC) || this.state.MULTICOREGC)
+        output.println("COPY_OBJ((struct garbagelist *)"+localsprefixaddr+",(struct ___Object___ *)"+dst+");");
        else
          output.println("COPY_OBJ("+dst+");");
        output.println(dst+"->"+nextobjstr+"="+revertptr+";");
@@ -3061,7 +3691,7 @@ public class BuildCode {
        String dst=generateTemp(fm, fsen.getDst(),lb);
        output.println("if(!"+dst+"->"+localcopystr+") {");
        /* Link object into list */
-       if (GENERATEPRECISEGC)
+       if (GENERATEPRECISEGC || this.state.MULTICOREGC)
          output.println("COPY_OBJ((struct garbagelist *)"+localsprefixaddr+",(struct ___Object___ *)"+dst+");");
        else
          output.println("COPY_OBJ("+dst+");");
@@ -3102,15 +3732,15 @@ public class BuildCode {
       int arrayid=state.getArrayNumber(fn.getType())+state.numClasses();
       if (fn.isGlobal()&&(state.DSM||state.SINGLETM)) {
        output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarrayglobal("+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+");");
-      } else if (GENERATEPRECISEGC) {
+      } else if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
        output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarray("+localsprefixaddr+", "+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+");");
       } else {
        output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarray("+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+");");
       }
     } else {
-      if (fn.isGlobal()) {
+      if (fn.isGlobal()&&(state.DSM||state.SINGLETM)) {
        output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newglobal("+fn.getType().getClassDesc().getId()+");");
-      } else if (GENERATEPRECISEGC) {
+      } else if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
        output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_new("+localsprefixaddr+", "+fn.getType().getClassDesc().getId()+");");
       } else {
        output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_new("+fn.getType().getClassDesc().getId()+");");
@@ -3132,7 +3762,7 @@ public class BuildCode {
   }
 
   private void generateFlatTagDeclaration(FlatMethod fm, LocalityBinding lb, FlatTagDeclaration fn, PrintWriter output) {
-    if (GENERATEPRECISEGC) {
+    if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
       output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_tag("+localsprefixaddr+", "+state.getTagId(fn.getType())+");");
     } else {
       output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_tag("+state.getTagId(fn.getType())+");");
@@ -3179,7 +3809,7 @@ public class BuildCode {
   private void generateFlatCastNode(FlatMethod fm, LocalityBinding lb, FlatCastNode fcn, PrintWriter output) {
     /* TODO: Do type check here */
     if (fcn.getType().isArray()) {
-      throw new Error();
+      output.println(generateTemp(fm,fcn.getDst(),lb)+"=(struct ArrayObject *)"+generateTemp(fm,fcn.getSrc(),lb)+";");
     } else if (fcn.getType().isClass())
       output.println(generateTemp(fm,fcn.getDst(),lb)+"=(struct "+fcn.getType().getSafeSymbol()+" *)"+generateTemp(fm,fcn.getSrc(),lb)+";");
     else
@@ -3190,7 +3820,7 @@ public class BuildCode {
     if (fln.getValue()==null)
       output.println(generateTemp(fm, fln.getDst(),lb)+"=0;");
     else if (fln.getType().getSymbol().equals(TypeUtil.StringClass)) {
-      if (GENERATEPRECISEGC) {
+      if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
        if (state.DSM && locality.getAtomic(lb).get(fln).intValue()>0) {
          //Stash pointer in case of GC
          String revertptr=generateTemp(fm, reverttable.get(lb),lb);
@@ -3271,13 +3901,9 @@ public class BuildCode {
        output.print(cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(");
     } else
       output.print(task.getSafeSymbol()+"(");
-
-    if (addSESErecord) {
-      output.print("SESErecord* currentSESE, ");
-    }
-
+    
     boolean printcomma=false;
-    if (GENERATEPRECISEGC) {
+    if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
       if (md!=null) {
        if (state.DSM||state.SINGLETM) {
          output.print("struct "+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params * "+paramsprefix);
@@ -3301,7 +3927,7 @@ public class BuildCode {
          output.print(temp.getType().getSafeSymbol()+" "+temp.getSafeSymbol());
       }
       output.println(") {");
-    } else if (!GENERATEPRECISEGC) {
+    } else if (!GENERATEPRECISEGC && !this.state.MULTICOREGC) {
       /* Imprecise Task */
       output.println("void * parameterarray[]) {");
       /* Unpack variables */
@@ -3398,7 +4024,7 @@ public class BuildCode {
        Iterator tagit=tagtmps.iterator();
        while(tagit.hasNext()) {
          TempDescriptor tagtmp=(TempDescriptor)tagit.next();
-         if (GENERATEPRECISEGC)
+         if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC))
            output.println("tagclear("+localsprefixaddr+", (struct ___Object___ *)"+generateTemp(fm, temp,lb)+", "+generateTemp(fm,tagtmp,lb)+");");
          else
            output.println("tagclear((struct ___Object___ *)"+generateTemp(fm, temp,lb)+", "+generateTemp(fm,tagtmp,lb)+");");
@@ -3410,7 +4036,7 @@ public class BuildCode {
        Iterator tagit=tagtmps.iterator();
        while(tagit.hasNext()) {
          TempDescriptor tagtmp=(TempDescriptor)tagit.next();
-         if (GENERATEPRECISEGC)
+         if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC))
            output.println("tagset("+localsprefixaddr+", (struct ___Object___ *)"+generateTemp(fm, temp,lb)+", "+generateTemp(fm,tagtmp,lb)+");");
          else
            output.println("tagset((struct ___Object___ *)"+generateTemp(fm, temp, lb)+", "+generateTemp(fm,tagtmp, lb)+");");