Implement a more sorphisticated execution strategy for static blocks. Tested with...
[IRC.git] / Robust / src / IR / Flat / BuildCode.java
index aa242605bb0bf1afe66b90d8a31162a22cf658d7..d549aa3d7e27d591a43857084c7f185dd610a594 100644 (file)
@@ -6,6 +6,7 @@ import IR.Tree.DNFFlagAtom;
 import IR.Tree.TagExpressionList;
 import IR.Tree.OffsetNode;
 import IR.*;
+
 import java.util.*;
 import java.io.*;
 
@@ -23,16 +24,26 @@ import Analysis.Locality.DCWrapper;
 import Analysis.Locality.DelayComputation;
 import Analysis.Locality.BranchAnalysis;
 import Analysis.CallGraph.CallGraph;
+import Analysis.Disjoint.AllocSite;
+import Analysis.Disjoint.Effect;
+import Analysis.Disjoint.ReachGraph;
+import Analysis.Disjoint.Taint;
+import Analysis.OoOJava.OoOJavaAnalysis;
 import Analysis.Prefetch.*;
 import Analysis.Loops.WriteBarrier;
 import Analysis.Loops.GlobalFieldType;
 import Analysis.Locality.TypeAnalysis;
 import Analysis.MLP.ConflictGraph;
+import Analysis.MLP.ConflictNode;
 import Analysis.MLP.MLPAnalysis;
 import Analysis.MLP.ParentChildConflictsMap;
+import Analysis.MLP.SESELock;
+import Analysis.MLP.SESEWaitingQueue;
 import Analysis.MLP.VariableSourceToken;
+import Analysis.MLP.VSTWrapper;
 import Analysis.MLP.CodePlan;
 import Analysis.MLP.SESEandAgePair;
+import Analysis.MLP.WaitingElement;
 
 public class BuildCode {
   State state;
@@ -66,10 +77,13 @@ public class BuildCode {
   SafetyAnalysis sa;
   PrefetchAnalysis pa;
   MLPAnalysis mlpa;
+  OoOJavaAnalysis oooa;
+  String maxTaskRecSizeStr="__maxTaskRecSize___";
   String mlperrstr = "if(status != 0) { "+
     "sprintf(errmsg, \"MLP error at %s:%d\", __FILE__, __LINE__); "+
     "perror(errmsg); exit(-1); }";
   boolean nonSESEpass=true;
+  RuntimeConflictResolver rcr = null;
   WriteBarrier wb;
   DiscoverConflicts dc;
   DiscoverConflicts recorddc;
@@ -78,21 +92,22 @@ public class BuildCode {
 
 
   public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, SafetyAnalysis sa, PrefetchAnalysis pa) {
-    this(st, temptovar, typeutil, null, sa, pa, null);
+    this(st, temptovar, typeutil, null, sa, pa, null, null);
   }
 
-  public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, SafetyAnalysis sa, PrefetchAnalysis pa, MLPAnalysis mlpa) {
-    this(st, temptovar, typeutil, null, sa, pa, mlpa);
+  public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, SafetyAnalysis sa, PrefetchAnalysis pa, MLPAnalysis mlpa, OoOJavaAnalysis oooa) {
+    this(st, temptovar, typeutil, null, sa, pa, mlpa, oooa);
   }
 
-  public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality, PrefetchAnalysis pa, MLPAnalysis mlpa) {
-    this(st, temptovar, typeutil, locality, null, pa, mlpa);
+  public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality, PrefetchAnalysis pa, MLPAnalysis mlpa, OoOJavaAnalysis oooa) {
+    this(st, temptovar, typeutil, locality, null, pa, mlpa, oooa);
   }
 
-  public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality, SafetyAnalysis sa, PrefetchAnalysis pa, MLPAnalysis mlpa) {
+  public BuildCode(State st, Hashtable temptovar, TypeUtil typeutil, LocalityAnalysis locality, SafetyAnalysis sa, PrefetchAnalysis pa, MLPAnalysis mlpa, OoOJavaAnalysis oooa) {
     this.sa=sa;
     this.pa=pa;
     this.mlpa=mlpa;
+    this.oooa=oooa;
     state=st;
     callgraph=new CallGraph(state);
     if (state.SINGLETM)
@@ -144,6 +159,7 @@ public class BuildCode {
     PrintWriter outtaskdefs=null;
     PrintWriter outoptionalarrays=null;
     PrintWriter optionalheaders=null;
+    PrintWriter outglobaldefs=null;
 
     try {
       if (state.SANDBOX) {
@@ -152,6 +168,7 @@ public class BuildCode {
       outstructs=new PrintWriter(new FileOutputStream(PREFIX+"structdefs.h"), true);
       outmethodheader=new PrintWriter(new FileOutputStream(PREFIX+"methodheaders.h"), true);
       outclassdefs=new PrintWriter(new FileOutputStream(PREFIX+"classdefs.h"), true);
+      outglobaldefs=new PrintWriter(new FileOutputStream(PREFIX+"globaldefs.h"), true);
       outmethod=new PrintWriter(new FileOutputStream(PREFIX+"methods.c"), true);
       outvirtual=new PrintWriter(new FileOutputStream(PREFIX+"virtualtable.h"), true);
       if (state.TASK) {
@@ -173,6 +190,9 @@ public class BuildCode {
     /* Build the virtual dispatch tables */
     buildVirtualTables(outvirtual);
 
+    /* Tag the methods that are invoked by static blocks */
+    tagMethodInvokedByStaticBlock();
+    
     /* Output includes */
     outmethodheader.println("#ifndef METHODHEADERS_H");
     outmethodheader.println("#define METHODHEADERS_H");
@@ -194,12 +214,20 @@ public class BuildCode {
       outmethodheader.println("#include \"abortreaders.h\"");
       outmethodheader.println("#include <setjmp.h>");
     }
-    if (state.MLP) {
+    if (state.MLP || state.OOOJAVA) {
       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\"");
+      outmethodheader.println("#include \"memPool.h\"");
+
+      if (state.RCR) 
+       outmethodheader.println("#include \"rcr_runtime.h\"");
+
+      // spit out a global to inform all worker threads with
+      // the maximum size is for any task record
+      outmethodheader.println("extern int "+maxTaskRecSizeStr+";");
     }
 
     /* Output Structures */
@@ -207,15 +235,30 @@ public class BuildCode {
 
     // Output the C class declarations
     // These could mutually reference each other
-    outputClassDeclarations(outclassdefs);
+    
+    outglobaldefs.println("#ifndef __GLOBALDEF_H_");
+    outglobaldefs.println("#define __GLOBALDEF_H_");
+    outglobaldefs.println("");
+    outglobaldefs.println("struct global_defs_t {");
+    
+    outclassdefs.println("#ifndef __CLASSDEF_H_");
+    outclassdefs.println("#define __CLASSDEF_H_");
+    outputClassDeclarations(outclassdefs, outglobaldefs);
 
     // Output function prototypes and structures for parameters
     Iterator it=state.getClassSymbolTable().getDescriptorsIterator();
     while(it.hasNext()) {
       ClassDescriptor cn=(ClassDescriptor)it.next();
-      generateCallStructs(cn, outclassdefs, outstructs, outmethodheader);
+      generateCallStructs(cn, outclassdefs, outstructs, outmethodheader, outglobaldefs);
     }
+    outclassdefs.println("#endif");
     outclassdefs.close();
+    outglobaldefs.println("};");
+    outglobaldefs.println("");
+    outglobaldefs.println("extern struct global_defs_t * global_defs_p;");
+    outglobaldefs.println("#endif");
+    outglobaldefs.flush();
+    outglobaldefs.close();
 
     if (state.TASK) {
       /* Map flags to integers */
@@ -233,13 +276,32 @@ public class BuildCode {
       outputTaskTypes(outtask);
     }
 
-    if( state.MLP ) {
+    if( state.MLP || state.OOOJAVA) {      
       // 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 );
+      
+      Iterator<FlatSESEEnterNode> seseit;
+      if(state.MLP){
+        seseit=mlpa.getAllSESEs().iterator();
+      }else{
+        seseit=oooa.getAllSESEs().iterator();
+      }
+      
+      //TODO signal the object that will report errors
+      if(state.RCR) {
+        try {
+          rcr = new RuntimeConflictResolver(PREFIX, oooa);
+          rcr.setGlobalEffects(oooa.getDisjointAnalysis().getEffectsAnalysis().getAllEffects());
+        } catch (FileNotFoundException e) {
+          System.out.println("Runtime Conflict Resolver could not create output file.");
+        }
+       rcr.init();
+      }
+      
+      while(seseit.hasNext()){
+        FlatSESEEnterNode fsen = seseit.next();
+        initializeSESE( fsen );
       }
     }
 
@@ -247,14 +309,25 @@ public class BuildCode {
     outputMethods(outmethod);
 
     // Output function prototypes and structures for SESE's and code
-    if( state.MLP ) {
+    if( state.MLP || state.OOOJAVA ) {
+
+      // spit out a global to inform all worker threads with
+      // the maximum size is for any task record
+      outmethod.println("int "+maxTaskRecSizeStr+" = 0;");
 
       // used to differentiate, during code generation, whether we are
       // passing over SESE body code, or non-SESE code
       nonSESEpass = false;
 
-      // first generate code for each sese's internals
-      for(Iterator<FlatSESEEnterNode> seseit=mlpa.getAllSESEs().iterator();seseit.hasNext();) {
+      // first generate code for each sese's internals     
+      Iterator<FlatSESEEnterNode> seseit;
+      if(state.MLP){
+        seseit=mlpa.getAllSESEs().iterator();
+      }else{
+        seseit=oooa.getAllSESEs().iterator();
+      }
+      
+      while(seseit.hasNext()) {
        FlatSESEEnterNode fsen = seseit.next();
        generateMethodSESE(fsen, null, outstructs, outmethodheader, outmethod);
       }
@@ -293,27 +366,103 @@ public class BuildCode {
     outmethod.close();
     outstructs.println("#endif");
     outstructs.close();
+    if(rcr != null) {
+      rcr.close();
+      System.out.println("Runtime Conflict Resolver Done.");
+    }  
+  }
+  
+  /* This method goes though the call graph and tag those methods that are 
+   * invoked inside static blocks
+   */
+  protected void tagMethodInvokedByStaticBlock() {
+    Iterator it_sclasses = this.state.getSClassSymbolTable().getDescriptorsIterator();
+    MethodDescriptor current_md=null;
+    HashSet tovisit=new HashSet();
+    HashSet visited=new HashSet();
+    
+    while(it_sclasses.hasNext()) {
+      ClassDescriptor cd = (ClassDescriptor)it_sclasses.next();
+      MethodDescriptor md = (MethodDescriptor)cd.getMethodTable().get("staticblocks");
+      tovisit.add(md);
+    }
+    
+    while(!tovisit.isEmpty()) {
+      current_md=(MethodDescriptor)tovisit.iterator().next();
+      tovisit.remove(current_md);
+      visited.add(current_md);
+      Iterator it_callee = this.callgraph.getCalleeSet(current_md).iterator();
+      while(it_callee.hasNext()) {
+        Descriptor d = (Descriptor)it_callee.next();
+        if(d instanceof MethodDescriptor) {
+          if(!visited.contains(d)) {
+            ((MethodDescriptor)d).setIsInvokedByStatic(true);
+            tovisit.add(d);
+          }
+        }
+      }
+    }
   }
   
+  /* This code generates code for each static block and static field 
+   * initialization.*/
+  protected void outputStaticBlocks(PrintWriter outmethod) {
+    //  execute all the static blocks and all the static field initializations
+    // TODO
+  }
 
   /* This code just generates the main C method for java programs.
    * The main C method packs up the arguments into a string array
    * and passes it to the java main method. */
 
-  private void outputMainMethod(PrintWriter outmethod) {
+  protected void outputMainMethod(PrintWriter outmethod) {
     outmethod.println("int main(int argc, const char *argv[]) {");
     outmethod.println("  int i;");
+    
+    outputStaticBlocks(outmethod);
+
+    if (state.MLP || state.OOOJAVA) {
+
+      // do a calculation to determine which task record
+      // is the largest, store that as a global value for
+      // allocating records
+      Iterator<FlatSESEEnterNode> seseit;
+      if(state.MLP){
+        seseit=mlpa.getAllSESEs().iterator();
+      }else{
+        seseit=oooa.getAllSESEs().iterator();
+      }      
+      while(seseit.hasNext()){
+        FlatSESEEnterNode fsen = seseit.next();
+        outmethod.println("if( sizeof( "+fsen.getSESErecordName()+
+                          " ) > "+maxTaskRecSizeStr+
+                          " ) { "+maxTaskRecSizeStr+
+                          " = sizeof( "+fsen.getSESErecordName()+
+                          " ); }" );
+      }
+      
+      outmethod.println("  runningSESE = NULL;");
 
-    if (state.MLP) {
-      //outmethod.println("  pthread_once( &mlpOnceObj, mlpInitOncePerThread );");
       outmethod.println("  workScheduleInit( "+state.MLP_NUMCORES+", invokeSESEmethod );");
+      
+      //initializes data structures needed for the RCR traverser
+      if(state.RCR && rcr != null) {
+        outmethod.println("  initializeStructsRCR();");
+      }
     }
 
     if (state.DSM) {
-      outmethod.println("#ifdef TRANSSTATS \n");
-      outmethod.println("handle();\n");
-      outmethod.println("#endif\n");
+      if (state.DSMRECOVERYSTATS) {
+        outmethod.println("#ifdef RECOVERYSTATS \n");
+        outmethod.println("handle();\n");
+        outmethod.println("#endif\n");
+      } else {
+        outmethod.println("#if defined(TRANSSTATS) || defined(RECOVERYSTATS) \n");
+        outmethod.println("handle();\n");
+        outmethod.println("#endif\n");
+      }
     }
+    
     if (state.THREAD||state.DSM||state.SINGLETM) {
       outmethod.println("initializethreads();");
     }
@@ -356,7 +505,7 @@ public class BuildCode {
        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};");
+    outmethod.println("1, NULL,"+"stringarray};");
       if (state.DSM||state.SINGLETM)
        outmethod.println("     "+cd.getSafeSymbol()+locality.getMain().getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"(& __parameterlist__);");
       else
@@ -381,7 +530,8 @@ public class BuildCode {
     }
 
     if (state.DSM||state.SINGLETM) {
-      outmethod.println("#ifdef TRANSSTATS \n");
+      //outmethod.println("#if defined(TRANSSTATS) || defined(RECOVERYSTATS) \n");
+      outmethod.println("#if defined(TRANSSTATS) \n");
       outmethod.println("printf(\"******  Transaction Stats   ******\\n\");");
       outmethod.println("printf(\"numTransCommit= %d\\n\", numTransCommit);");
       outmethod.println("printf(\"numTransAbort= %d\\n\", numTransAbort);");
@@ -417,7 +567,7 @@ public class BuildCode {
     if (state.THREAD||state.SINGLETM)
       outmethod.println("pthread_exit(NULL);");
 
-    if (state.MLP) {
+    if (state.MLP || state.OOOJAVA ) {
       outmethod.println("  workScheduleBegin();");
     }
 
@@ -464,6 +614,11 @@ public class BuildCode {
     outmethod.println("#include \"methodheaders.h\"");
     outmethod.println("#include \"virtualtable.h\"");
     outmethod.println("#include \"runtime.h\"");
+
+    // always include: compiler directives will leave out
+    // instrumentation when option is not set
+    outmethod.println("#include \"coreprof/coreprof.h\"");
+
     if (state.SANDBOX) {
       outmethod.println("#include \"sandboxdefs.c\"");
     }
@@ -475,7 +630,9 @@ public class BuildCode {
       outmethod.println("#include \"localobjects.h\"");
     }
     if(state.MULTICORE) {
-      outmethod.println("#include \"task.h\"");
+      if(state.TASK) {
+        outmethod.println("#include \"task.h\"");
+      }
          outmethod.println("#include \"multicoreruntime.h\"");
          outmethod.println("#include \"runtime_arch.h\"");
     }
@@ -487,14 +644,20 @@ public class BuildCode {
     if (state.CONSCHECK) {
       outmethod.println("#include \"checkers.h\"");
     }
-    if (state.MLP) {
+    if (state.MLP || state.OOOJAVA ) {
       outmethod.println("#include <stdlib.h>");
       outmethod.println("#include <stdio.h>");
       outmethod.println("#include \"mlp_runtime.h\"");
       outmethod.println("#include \"psemaphore.h\"");
+      
+      if( state.RCR ) {
+        outmethod.println("#include \"trqueue.h\"");
+        outmethod.println("#include \"RuntimeConflictResolver.h\"");
+        outmethod.println("#include \"rcr_runtime.h\"");
+      }
     }
 
-
+    outmethod.println("struct global_defs_t * global_defs_p;");
     //Store the sizes of classes & array elements
     generateSizeArray(outmethod);
 
@@ -544,10 +707,14 @@ public class BuildCode {
     outstructs.println("#define INTPTR int");
     outstructs.println("#endif");
     outstructs.println("#endif");
-    if( state.MLP ) {
+    if( state.MLP || state.OOOJAVA ) {
       outstructs.println("#include \"mlp_runtime.h\"");
       outstructs.println("#include \"psemaphore.h\"");
     }
+    if (state.RCR) {
+      outstructs.println("#include \"rcr_runtime.h\"");
+    }
+
 
     /* Output #defines that the runtime uses to determine type
      * numbers for various objects it needs */
@@ -602,7 +769,7 @@ public class BuildCode {
     }
   }
 
-  protected void outputClassDeclarations(PrintWriter outclassdefs) {
+  protected void outputClassDeclarations(PrintWriter outclassdefs, PrintWriter outglobaldefs) {
     if (state.THREAD||state.DSM||state.SINGLETM)
       outclassdefs.println("#include <pthread.h>");
     outclassdefs.println("#ifndef INTPTR");
@@ -625,6 +792,10 @@ public class BuildCode {
     //Print out definition for array type
     outclassdefs.println("struct "+arraytype+" {");
     outclassdefs.println("  int type;");
+    if(state.MLP || state.OOOJAVA ){
+      outclassdefs.println("  int oid;");
+      outclassdefs.println("  int allocsite;");
+    }
     if (state.EVENTMONITOR) {
       outclassdefs.println("  int objuid;");
     }
@@ -633,6 +804,13 @@ public class BuildCode {
       outclassdefs.println("  void * lockentry;");
       outclassdefs.println("  int lockcount;");
     }
+    if(state.MGC) {
+      outclassdefs.println("  int mutex;");  
+      outclassdefs.println("  int objlock;");
+      if(state.MULTICOREGC) {
+        outclassdefs.println("  int marked;");
+      }
+    } 
     if (state.TASK) {
       outclassdefs.println("  int flag;");
       if(!state.MULTICORE) {
@@ -651,7 +829,7 @@ public class BuildCode {
        outclassdefs.println("  int * fses;");
       }
     }
-    printClassStruct(typeutil.getClass(TypeUtil.ObjectClass), outclassdefs);
+    printClassStruct(typeutil.getClass(TypeUtil.ObjectClass), outclassdefs, outglobaldefs);
 
     if (state.STMARRAY) {
       outclassdefs.println("  int lowindex;");
@@ -669,6 +847,8 @@ public class BuildCode {
     outclassdefs.println("extern int hasflags[];");
     outclassdefs.println("extern unsigned INTPTR * pointerarray[];");
     outclassdefs.println("extern int supertypes[];");
+    outclassdefs.println("#include \"globaldefs.h\"");
+    outclassdefs.println("");
   }
 
   /** Prints out definitions for generic task structures */
@@ -965,7 +1145,12 @@ public class BuildCode {
       outclassdefs.println("#endif\n");
     }
     outclassdefs.print("#endif\n");
+
     outclassdefs.print("int numprefetchsites = " + pa.prefetchsiteid + ";\n");
+    if(this.state.MLP || state.OOOJAVA ){
+       outclassdefs.print("extern __thread int oid;\n");
+       outclassdefs.print("extern int numWorkers;\n");
+    }
 
     Iterator it=state.getClassSymbolTable().getDescriptorsIterator();
     cdarray=new ClassDescriptor[state.numClasses()];
@@ -1293,11 +1478,11 @@ public class BuildCode {
 
   /** Force consistent field ordering between inherited classes. */
 
-  private void printClassStruct(ClassDescriptor cn, PrintWriter classdefout) {
+  private void printClassStruct(ClassDescriptor cn, PrintWriter classdefout, PrintWriter globaldefout) {
 
     ClassDescriptor sp=cn.getSuperDesc();
     if (sp!=null)
-      printClassStruct(sp, classdefout);
+      printClassStruct(sp, classdefout, globaldefout);
 
     if (!fieldorder.containsKey(cn)) {
       Vector fields=new Vector();
@@ -1310,12 +1495,23 @@ public class BuildCode {
       }
     }
     Vector fields=(Vector)fieldorder.get(cn);
+    
+    if((cn.getNumStaticFields() != 0) || (cn.getNumStaticBlocks() != 0)) {
+      // this class has static fields/blocks, need to add a global flag to 
+      // indicate if its static fields have been initialized and/or if its
+      // static blocks have been executed
+      globaldefout.println("  int "+cn.getSafeSymbol()+"static_block_exe_flag;");
+    }
 
     for(int i=0; i<fields.size(); i++) {
       FieldDescriptor fd=(FieldDescriptor)fields.get(i);
       if (fd.getType().isClass()||fd.getType().isArray())
        classdefout.println("  struct "+fd.getType().getSafeSymbol()+" * "+fd.getSafeSymbol()+";");
-      else
+      else if(fd.isStatic()) {
+        // static field
+        globaldefout.println("  "+fd.getType().getSafeSymbol()+ " "+cn.getSafeSymbol()+fd.getSafeSymbol()+";");
+        classdefout.println("  "+fd.getType().getSafeSymbol()+" * "+fd.getSafeSymbol()+";");
+      } else
        classdefout.println("  "+fd.getType().getSafeSymbol()+" "+fd.getSafeSymbol()+";");
     }
   }
@@ -1358,10 +1554,14 @@ public class BuildCode {
    * passed in (when PRECISE GC is enabled) and (2) function
    * prototypes for the methods */
 
-  protected void generateCallStructs(ClassDescriptor cn, PrintWriter classdefout, PrintWriter output, PrintWriter headersout) {
+  protected void generateCallStructs(ClassDescriptor cn, PrintWriter classdefout, PrintWriter output, PrintWriter headersout, PrintWriter globaldefout) {
     /* Output class structure */
     classdefout.println("struct "+cn.getSafeSymbol()+" {");
     classdefout.println("  int type;");
+    if(state.MLP || state.OOOJAVA){
+      classdefout.println("  int oid;");
+      classdefout.println("  int allocsite;");
+    }
     if (state.EVENTMONITOR) {
       classdefout.println("  int objuid;");
     }
@@ -1370,7 +1570,13 @@ public class BuildCode {
       classdefout.println("  void * lockentry;");
       classdefout.println("  int lockcount;");
     }
-
+    if(state.MGC) {
+      classdefout.println("  int mutex;");  
+      classdefout.println("  int objlock;");
+      if(state.MULTICOREGC) {
+        classdefout.println("  int marked;");
+      }
+    } 
     if (state.TASK) {
       classdefout.println("  int flag;");
       if((!state.MULTICORE) || (cn.getSymbol().equals("TagDescriptor"))) {
@@ -1389,7 +1595,7 @@ public class BuildCode {
        classdefout.println("  int * fses;");
       }
     }
-    printClassStruct(cn, classdefout);
+    printClassStruct(cn, classdefout, globaldefout);
     classdefout.println("};\n");
 
     if (state.DSM||state.SINGLETM) {
@@ -1437,8 +1643,8 @@ public class BuildCode {
        output.println("struct "+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params {");
       else
        output.println("struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params {");
-      output.println("  INTPTR size;");
-      output.println("  void * next;");
+      output.println("  int size;");
+      output.println("  void * next;");      
       for(int i=0; i<objectparams.numPointers(); i++) {
        TempDescriptor temp=objectparams.getPointer(i);
        output.println("  struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol()+";");
@@ -1462,7 +1668,7 @@ public class BuildCode {
        output.println("struct "+cn.getSafeSymbol()+lb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals {");
       else
        output.println("struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals {");
-      output.println("  INTPTR size;");
+      output.println("  int size;");
       output.println("  void * next;");
       for(int i=0; i<objecttemps.numPointers(); i++) {
        TempDescriptor temp=objecttemps.getPointer(i);
@@ -1540,8 +1746,7 @@ public class BuildCode {
       /* Output parameter structure */
       if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
        output.println("struct "+task.getSafeSymbol()+"_params {");
-
-       output.println("  INTPTR size;");
+       output.println("  int size;");
        output.println("  void * next;");
        for(int i=0; i<objectparams.numPointers(); i++) {
          TempDescriptor temp=objectparams.getPointer(i);
@@ -1557,7 +1762,7 @@ public class BuildCode {
       /* Output temp structure */
       if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
        output.println("struct "+task.getSafeSymbol()+"_locals {");
-       output.println("  INTPTR size;");
+       output.println("  int size;");
        output.println("  void * next;");
        for(int i=0; i<objecttemps.numPointers(); i++) {
          TempDescriptor temp=objecttemps.getPointer(i);
@@ -1718,7 +1923,6 @@ public class BuildCode {
        output.print("   struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_locals "+localsprefix+"={");
       else
        output.print("   struct "+task.getSafeSymbol()+"_locals "+localsprefix+"={");
-
       output.print(objecttemp.numPointers()+",");
       output.print(paramsprefix);
       for(int j=0; j<objecttemp.numPointers(); j++)
@@ -1738,16 +1942,18 @@ public class BuildCode {
     }
 
 
-    if( state.MLP ) {      
+    if( state.MLP || state.OOOJAVA ) {      
       if( fm.getNext(0) instanceof FlatSESEEnterNode ) {
        FlatSESEEnterNode callerSESEplaceholder = (FlatSESEEnterNode) fm.getNext( 0 );
-       if( callerSESEplaceholder != mlpa.getMainSESE() ) {
+       if( (state.MLP && callerSESEplaceholder != mlpa.getMainSESE()) ||  
+           (state.OOOJAVA && callerSESEplaceholder != oooa.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+";");
+           SESEandAgePair pair = pItr.next();
+           output.println("   void* "+pair+" = NULL;");
          }
 
          // declare variables for tracking dynamic sources
@@ -1755,41 +1961,72 @@ public class BuildCode {
          Iterator<TempDescriptor> dynSrcItr = callerSESEplaceholder.getDynamicVarSet().iterator();
          while( dynSrcItr.hasNext() ) {
            TempDescriptor dynSrcVar = dynSrcItr.next();
-           output.println("   void* "+dynSrcVar+"_srcSESE;");
-           output.println("   int   "+dynSrcVar+"_srcOffset;");
+           output.println("   SESEcommon*  "+dynSrcVar+"_srcSESE = NULL;");
+           output.println("   INTPTR       "+dynSrcVar+"_srcOffset = 0x1;");
          }    
        }
       }
       
       // set up related allocation sites's waiting queues
       // eom
-      output.println("   /* set up waiting queues */");
-      output.println("   int numRelatedAllocSites=0;");                
-      ConflictGraph graph=null;
-      graph=mlpa.getConflictGraphResults().get(fm);
-      if(graph!=null){
-         Set<Long> allocSet=graph.getAllocationSiteIDSet();
-         
-         if(allocSet.size()>0){
-                 output.println("   numRelatedAllocSites="+allocSet.size()+";");                 
-                 output.println("   seseCaller->numRelatedAllocSites=numRelatedAllocSites;");            
-                 output.println("   seseCaller->allocSiteArray=mlpCreateAllocSiteArray(numRelatedAllocSites);");
-                 int idx=0;
-                 for (Iterator iterator = allocSet.iterator(); iterator.hasNext();) {
-                        Long allocID = (Long) iterator.next();
-                       output.println("   seseCaller->allocSiteArray["+idx+"].id="+allocID+";");
-                       idx++;
-                 }
-                 output.println();
-         }
+      if(state.MLP){
+        ConflictGraph graph = null;
+        graph = mlpa.getConflictGraphResults().get(fm);
+        if (graph != null && graph.hasConflictEdge()) {
+          output.println("   /* set up waiting queues */");
+          output.println("   int numMemoryQueue=0;");
+          output.println("   int memoryQueueItemID=0;");
+          HashSet<SESELock> lockSet = mlpa.getConflictGraphLockMap().get(
+              graph);
+          System.out.println("#lockSet="+lockSet.hashCode());
+          System.out.println("lockset="+lockSet);
+          for (Iterator iterator = lockSet.iterator(); iterator.hasNext();) {
+            SESELock seseLock = (SESELock) iterator.next();
+            System.out.println("id="+seseLock.getID());
+            System.out.println("#="+seseLock);
+          }
+          System.out.println("size="+lockSet.size());
+          if (lockSet.size() > 0) {
+            output.println("   numMemoryQueue=" + lockSet.size() + ";");
+            output.println("   runningSESE->numMemoryQueue=numMemoryQueue;");
+            output.println("   runningSESE->memoryQueueArray=mlpCreateMemoryQueueArray(numMemoryQueue);");
+            output.println();
+          }
+        }
+      }else{
+        FlatSESEEnterNode callerSESEplaceholder = (FlatSESEEnterNode) fm.getNext( 0 );
+        if(callerSESEplaceholder!= oooa.getMainSESE()){
+          Analysis.OoOJava.ConflictGraph graph = oooa.getConflictGraph(callerSESEplaceholder);       
+          if (graph != null && graph.hasConflictEdge()) {          
+            output.println("   // set up waiting queues ");
+            output.println("   int numMemoryQueue=0;");
+            output.println("   int memoryQueueItemID=0;");
+            Set<Analysis.OoOJava.SESELock> lockSet = oooa.getLockMappings(graph);
+            System.out.println("#lockSet="+lockSet.hashCode());
+            System.out.println("lockset="+lockSet);
+            for (Iterator iterator = lockSet.iterator(); iterator.hasNext();) {
+              Analysis.OoOJava.SESELock seseLock = (Analysis.OoOJava.SESELock) iterator.next();
+              System.out.println("id="+seseLock.getID());
+              System.out.println("#="+seseLock);
+            }
+            System.out.println("size="+lockSet.size());
+            if (lockSet.size() > 0) {
+              output.println("   numMemoryQueue=" + lockSet.size() + ";");
+              output.println("   runningSESE->numMemoryQueue=numMemoryQueue;");
+              output.println("   runningSESE->memoryQueueArray=mlpCreateMemoryQueueArray(numMemoryQueue);");
+              output.println();
+            }
+          }
+        }
       }
-    }
+        
+    }    
 
 
     /* 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.MLP||state.OOOJAVA||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)) {
@@ -1802,6 +2039,28 @@ public class BuildCode {
        }
       }
     }
+    
+    if(fm.getMethod().isStaticBlock()) {
+      // a static block, check if it has been executed
+      output.println("  if(global_defs_p->" + cn.getSafeSymbol()+"static_block_exe_flag != 0) {");
+      output.println("    return;");
+      output.println("  }");
+      output.println("");
+    }
+    if((!fm.getMethod().isStaticBlock()) && (fm.getMethod().getReturnType() == null) && (cn != null)){
+      // is a constructor, check and output initialization of the static fields
+      // here does not initialize the static fields of the class, instead it 
+      // redirect the corresponding fields in the object to the global_defs_p
+      Vector fields=(Vector)fieldorder.get(cn);
+
+      for(int i=0; i<fields.size(); i++) {
+        FieldDescriptor fd=(FieldDescriptor)fields.get(i);
+        if(fd.isStatic()) {
+          // static field
+          output.println(generateTemp(fm,fm.getParameter(0),lb)+"->"+fd.getSafeSymbol()+"=&(global_defs_p->"+cn.getSafeSymbol()+fd.getSafeSymbol()+");");
+        }
+      }
+    }
 
     generateCode(fm.getNext(0), fm, lb, null, output, true);
 
@@ -1869,6 +2128,18 @@ public class BuildCode {
     }
   }
 
+  // used when generating the specific SESE record struct
+  // to remember the FIRST field name of sese records 
+  // that the current SESE depends on--we need to know the
+  // offset to the first one for garbage collection
+  protected void addingDepRecField( FlatSESEEnterNode fsen,
+                                    String            field ) {
+    if( fsen.getFirstDepRecField() == null ) {
+      fsen.setFirstDepRecField( field );
+    }
+    fsen.incNumDepRecs();
+  }
+
   protected void generateMethodSESE(FlatSESEEnterNode fsen,
                                     LocalityBinding lb,
                                     PrintWriter outputStructs,
@@ -1885,15 +2156,11 @@ public class BuildCode {
                          fsen.getmdBogus().getSafeSymbol()+"_"+
                          fsen.getmdBogus().getSafeMethodDescriptor()+
                          "_locals {");
-    outputStructs.println("  INTPTR size;");
+    outputStructs.println("  int size;");
     outputStructs.println("  void * next;");
     for(int i=0; i<objecttemps.numPointers(); i++) {
       TempDescriptor temp=objecttemps.getPointer(i);
 
-      if( fsen.getPrettyIdentifier().equals( "calc" ) ) {
-       System.out.println( "  got a pointer "+temp );
-      }
-
       if (temp.getType().isNull())
         outputStructs.println("  void * "+temp.getSafeSymbol()+";");
       else
@@ -1904,6 +2171,27 @@ public class BuildCode {
     outputStructs.println("};\n");
 
     
+    // divide in-set and out-set into objects and primitives to prep
+    // for the record generation just below
+    Set<TempDescriptor> inSetAndOutSet = new HashSet<TempDescriptor>();
+    inSetAndOutSet.addAll( fsen.getInVarSet() );
+    inSetAndOutSet.addAll( fsen.getOutVarSet() );
+
+    Set<TempDescriptor> inSetAndOutSetObjs  = new HashSet<TempDescriptor>();
+    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() ) {
+        inSetAndOutSetObjs.add( temp );
+      } else {
+       inSetAndOutSetPrims.add( temp );
+      }
+    }
+
+
     // generate the SESE record structure
     outputStructs.println(fsen.getSESErecordName()+" {");
     
@@ -1913,57 +2201,85 @@ public class BuildCode {
     outputStructs.println("  SESEcommon common;");
 
     // then garbage list stuff
-    outputStructs.println("  INTPTR size;");
+    outputStructs.println("  /* next is in-set and out-set objects that look like a garbage list */");
+    outputStructs.println("  int 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() );
+    // I think that the set of TempDescriptors inSetAndOutSetObjs
+    // calculated above should match the pointer object params
+    // used in the following code, but let's just leave the working
+    // implementation unless there is actually a problem...
 
-    Set<TempDescriptor> inSetAndOutSetPrims = new HashSet<TempDescriptor>();
+    Vector<TempDescriptor> inset=fsen.getInVarsForDynamicCoarseConflictResolution();
+    for(int i=0; i<inset.size();i++) {
+      TempDescriptor temp=inset.get(i);
+      if (temp.getType().isNull())
+       outputStructs.println("  void * "+temp.getSafeSymbol()+
+                             ";  /* in-or-out-set obj in gl */");
+      else
+       outputStructs.println("  struct "+temp.getType().getSafeSymbol()+" * "+
+                             temp.getSafeSymbol()+"; /* in-or-out-set obj in gl */");
+    }
 
-    Iterator<TempDescriptor> itr = inSetAndOutSet.iterator();
-    while( itr.hasNext() ) {
-      TempDescriptor temp = itr.next();
-      TypeDescriptor type = temp.getType();
-      if( !type.isPtr() ) {
-       inSetAndOutSetPrims.add( temp );
+    for(int i=0; i<objectparams.numPointers(); i++) {
+      TempDescriptor temp=objectparams.getPointer(i);
+      if (!inset.contains(temp)) {
+       if (temp.getType().isNull())
+         outputStructs.println("  void * "+temp.getSafeSymbol()+
+                               ";  /* in-or-out-set obj in gl */");
+       else
+         outputStructs.println("  struct "+temp.getType().getSafeSymbol()+" * "+
+                               temp.getSafeSymbol()+"; /* in-or-out-set obj in gl */");
       }
     }
+    
+    outputStructs.println("  /* next is primitives for in-set and out-set and dynamic tracking */");
 
     Iterator<TempDescriptor> itrPrims = inSetAndOutSetPrims.iterator();
     while( itrPrims.hasNext() ) {
       TempDescriptor temp = itrPrims.next();
       TypeDescriptor type = temp.getType();
-      outputStructs.println("  "+temp.getType().getSafeSymbol()+" "+temp.getSafeSymbol()+";");
+      if(type.isPrimitive()){
+         outputStructs.println("  "+temp.getType().getSafeSymbol()+" "+temp.getSafeSymbol()+"; /* in-set or out-set primitive */");
+      }      
     }
+    
+    // note that the sese record pointer will be added below, just primitive part of tracking here
+    Iterator<TempDescriptor> itrDynInVars = fsen.getDynamicInVarSet().iterator();
+    while( itrDynInVars.hasNext() ) {
+      TempDescriptor dynInVar = itrDynInVars.next();
+      outputStructs.println("  INTPTR "+dynInVar+"_srcOffset; /* dynamic tracking primitive */");
+    }  
+    
+    
+    outputStructs.println("  /* everything after this should be pointers to an SESE record */" );
 
-    for(int i=0; i<objectparams.numPointers(); i++) {
-      TempDescriptor temp=objectparams.getPointer(i);
-      if (temp.getType().isNull())
-        outputStructs.println("  void * "+temp.getSafeSymbol()+";");
-      else
-        outputStructs.println("  struct "+temp.getType().getSafeSymbol()+" * "+temp.getSafeSymbol()+";");
+    // other half of info for dynamic tracking, the SESE record pointer
+    itrDynInVars = fsen.getDynamicInVarSet().iterator();
+    while( itrDynInVars.hasNext() ) {
+      TempDescriptor dynInVar = itrDynInVars.next();
+      String depRecField = dynInVar+"_srcSESE";
+      outputStructs.println("  SESEcommon* "+depRecField+";");
+      addingDepRecField( fsen, depRecField );
+    }  
+    
+    // statically known sese sources are record pointers, too
+    Iterator<SESEandAgePair> itrStaticInVarSrcs = fsen.getStaticInVarSrcs().iterator();
+    while( itrStaticInVarSrcs.hasNext() ) {
+      SESEandAgePair srcPair = itrStaticInVarSrcs.next();
+      outputStructs.println("  "+srcPair.getSESE().getSESErecordName()+"* "+srcPair+";");
+      addingDepRecField(fsen, srcPair.toString());
+    }
+
+    if (state.RCR) {
+      if (inset.size()!=0)
+       outputStructs.println("struct rcrRecord rcrRecords["+inset.size()+"];");
     }
     
+    if( fsen.getFirstDepRecField() != null ) {
+      outputStructs.println("  /* compiler believes first dependent SESE record field above is: "+
+                            fsen.getFirstDepRecField()+" */" );
+    }
     outputStructs.println("};\n");
 
     
@@ -1995,12 +2311,13 @@ public class BuildCode {
     output.print(fsen.getSESErecordName()+"* "+paramsprefix);
     output.println("){\n");
 
+
     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("(void*) &("+paramsprefix+"->size)");
+      output.print("&(((SESEcommon*)(___params___))[1])");
       for(int j=0; j<objecttemp.numPointers(); j++)
        output.print(", NULL");
       output.println("};");
@@ -2023,8 +2340,8 @@ public class BuildCode {
     output.println("   /* static SESE names */");
     Iterator<SESEandAgePair> pItr = fsen.getNeededStaticNames().iterator();
     while( pItr.hasNext() ) {
-      SESEandAgePair p = pItr.next();
-      output.println("   void* "+p+";");
+      SESEandAgePair pair = pItr.next();
+      output.println("   SESEcommon* "+pair+" = NULL;");
     }
 
     // declare variables for tracking dynamic sources
@@ -2032,8 +2349,8 @@ public class BuildCode {
     Iterator<TempDescriptor> dynSrcItr = fsen.getDynamicVarSet().iterator();
     while( dynSrcItr.hasNext() ) {
       TempDescriptor dynSrcVar = dynSrcItr.next();
-      output.println("   void* "+dynSrcVar+"_srcSESE;");
-      output.println("   int   "+dynSrcVar+"_srcOffset;");
+      output.println("   SESEcommon*  "+dynSrcVar+"_srcSESE = NULL;");
+      output.println("   INTPTR       "+dynSrcVar+"_srcOffset = 0x1;");
     }    
 
     // declare local temps for in-set primitives, and if it is
@@ -2062,66 +2379,100 @@ public class BuildCode {
       if( !type.isPtr() && !fsen.getInVarSet().contains( temp ) ) {
        output.println("   "+type+" "+temp+";");       
       }
-    }    
+    }
+
+
+    // initialize thread-local var to a the task's record, which is fused
+    // with the param list
+    output.println("   ");
+    output.println("   // code of this task's body should use this to access the running task record");
+    output.println("   runningSESE = &(___params___->common);");
+    output.println("   ");
     
-    // set up related allocation sites's waiting queues
+    // setup memory queue
     // eom
-    output.println("   /* set up waiting queues */");
-    output.println("   int numRelatedAllocSites=0;");                  
-    ConflictGraph graph=null;
-    graph=mlpa.getConflictGraphResults().get(fsen);
-       if (graph != null) {
-               output.println("   {");
-               output.println("   SESEcommon* parentCommon = &(___params___->common);");
-               Set<Long> allocSet = graph.getAllocationSiteIDSet();
-               if (allocSet.size() > 0) {
-                       output.println("   numRelatedAllocSites=" + allocSet.size()
-                                       + ";");
-                       output
-                                       .println("   parentCommon->numRelatedAllocSites=numRelatedAllocSites;");
-                       output
-                                       .println("   parentCommon->allocSiteArray=mlpCreateAllocSiteArray(numRelatedAllocSites);");
-                       int idx = 0;
-                       for (Iterator iterator = allocSet.iterator(); iterator
-                                       .hasNext();) {
-                               Long allocID = (Long) iterator.next();
-                               output.println("   parentCommon->allocSiteArray[" + idx
-                                               + "].id=" + allocID + ";");
-                               idx++;
-                       }
-                       output.println();
-               }
-               output.println("   }");
+    if(state.OOOJAVA){
+      output.println("   // set up memory queues ");
+      output.println("   int numMemoryQueue=0;");
+      output.println("   int memoryQueueItemID=0;");
+      Analysis.OoOJava.ConflictGraph graph = oooa.getConflictGraph(fsen);
+      if (graph != null && graph.hasConflictEdge()) {
+       output.println("   {");
+       Set<Analysis.OoOJava.SESELock> lockSet = oooa.getLockMappings(graph);
+       System.out.println("#lockSet="+lockSet);
+       if (lockSet.size() > 0) {
+         output.println("   numMemoryQueue=" + lockSet.size() + ";");
+         output.println("   runningSESE->numMemoryQueue=numMemoryQueue;");
+         output.println("   runningSESE->memoryQueueArray=mlpCreateMemoryQueueArray(numMemoryQueue);");
+         output.println();
        }
-    
+       output.println("   }");
+      }
+    } else {
+      output.println("   // set up memory queues ");
+      output.println("   int numMemoryQueue=0;");
+      output.println("   int memoryQueueItemID=0;");
+      ConflictGraph graph = null;
+      graph = mlpa.getConflictGraphResults().get(fsen);
+      if (graph != null && graph.hasConflictEdge()) {
+        output.println("   {");
+        HashSet<SESELock> lockSet = mlpa.getConflictGraphLockMap().get(
+            graph);
+        System.out.println("#lockSet="+lockSet);
+
+        if (lockSet.size() > 0) {
+          output.println("   numMemoryQueue=" + lockSet.size() + "; ");
+          output.println("   runningSESE->numMemoryQueue=numMemoryQueue;");
+          output.println("   runningSESE->memoryQueueArray=mlpCreateMemoryQueueArray(numMemoryQueue);");
+          output.println();
+        }
+        output.println("   }");
+      }
+    }
+
+
+    // set up a task's mem pool to recycle the allocation of children tasks
+    // don't bother if the task never has children (a leaf task)
+    output.println( "#ifndef OOO_DISABLE_TASKMEMPOOL" );
+    if( !fsen.getIsLeafSESE() ) {
+      output.println("   runningSESE->taskRecordMemPool = poolcreate( "+
+                     maxTaskRecSizeStr+" );");
+    } else {
+      // make it clear we purposefully did not initialize this
+      output.println("   runningSESE->taskRecordMemPool = (MemPool*)0x1;");
+    }
+    output.println( "#endif // OOO_DISABLE_TASKMEMPOOL" );
+
 
     // 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
+    output.println("   // copy variables from static sources");
     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 )+
+      output.println("   "+generateTemp( fsen.getfmBogus(), temp, null )+
                     " = "+paramsprefix+"->"+srcPair+"->"+vst.getAddrVar()+";");
-
+    }
+    
+    output.println("   // decrement references to static sources");
+    for( Iterator<SESEandAgePair> pairItr = fsen.getStaticInVarSrcs().iterator(); pairItr.hasNext(); ) {
+      SESEandAgePair srcPair = pairItr.next();
+      output.println("#ifndef OOO_DISABLE_TASKMEMPOOL" );
+      output.println("   {");
+      output.println("     SESEcommon* src = &("+paramsprefix+"->"+srcPair+"->common);");
+      output.println("     RELEASE_REFERENCE_TO( src );");
       output.println("   }");
+      output.println("#endif // OOO_DISABLE_TASKMEMPOOL" );
     }
 
+
     // dynamic vars come from an SESE and src
+    output.println("     // copy variables from dynamic sources");
     tempItr = fsen.getDynamicInVarSet().iterator();
     while( tempItr.hasNext() ) {
       TempDescriptor temp = tempItr.next();
@@ -2130,14 +2481,6 @@ public class BuildCode {
       // 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*";
@@ -2148,11 +2491,16 @@ public class BuildCode {
       }
       
       output.println("     "+generateTemp( fsen.getfmBogus(), temp, null )+
-                    " = *(("+typeStr+"*) ("+
+                    " = *(("+typeStr+"*) ((void*)"+
                     paramsprefix+"->"+temp+"_srcSESE + "+
                     paramsprefix+"->"+temp+"_srcOffset));");
 
-      // or if the source was our parent, its in the record to grab
+      output.println("#ifndef OOO_DISABLE_TASKMEMPOOL" );
+      output.println("     SESEcommon* src = "+paramsprefix+"->"+temp+"_srcSESE;");
+      output.println("     RELEASE_REFERENCE_TO( src );");
+      output.println("#endif // OOO_DISABLE_TASKMEMPOOL" );
+
+      // or if the source was our parent, its already in our record to grab
       output.println("   } else {");
       output.println("     "+generateTemp( fsen.getfmBogus(), temp, null )+
                           " = "+paramsprefix+"->"+temp+";");
@@ -2162,18 +2510,23 @@ public class BuildCode {
     // Check to see if we need to do a GC if this is a
     // multi-threaded program...    
     if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
+       output.println("if (unlikely(needtocollect)) checkcollect("+localsprefixaddr+");");
       //Don't bother if we aren't in recursive methods...The loops case will catch it
-      if (callgraph.getAllMethods(md).contains(md)) {
-        if(this.state.MULTICOREGC) {
-          output.println("if(gcflag) gc("+localsprefixaddr+");");
-        } else {
-         output.println("if (unlikely(needtocollect)) checkcollect("+localsprefixaddr+");");
-       }
-      }
+//      if (callgraph.getAllMethods(md).contains(md)) {
+//        if(this.state.MULTICOREGC) {
+//          output.println("if(gcflag) gc("+localsprefixaddr+");");
+//        } else {
+//       output.println("if (unlikely(needtocollect)) checkcollect("+localsprefixaddr+");");
+//     }
+//      }
     }    
 
-    // initialize thread-local var to a non-zero, invalid address
-    output.println("   seseCaller = (SESEcommon*) 0x2;");
+    if( state.COREPROF ) {
+      output.println("#ifdef CP_EVENTID_TASKEXECUTE");
+      output.println("   CP_LOGEVENT( CP_EVENTID_TASKEXECUTE, CP_EVENTTYPE_BEGIN );");
+      output.println("#endif");
+    }
+
     HashSet<FlatNode> exitset=new HashSet<FlatNode>();
     exitset.add(seseExit);    
     generateCode(fsen.getNext(0), fm, null, exitset, output, true);
@@ -2200,15 +2553,26 @@ public class BuildCode {
     // 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();) {
+    Iterator<FlatSESEEnterNode> seseit;
+    if(state.MLP){
+      seseit=mlpa.getAllSESEs().iterator();
+    }else{
+      seseit=oooa.getAllSESEs().iterator();
+    }
+    while(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() ) ) {
+      if( (state.MLP && fsen.equals( mlpa.getMainSESE() )) || 
+          (state.OOOJAVA && fsen.equals( oooa.getMainSESE() ))
+      ) {
        outmethod.println(  "      /* work scheduler works forever, explicitly exit */");
+        outmethod.println(  "      CP_EXIT();");
+        outmethod.println(  "      CP_DUMP();");       
+        outmethod.println(  "      workScheduleExit();");
        outmethod.println(  "      exit( 0 );");
       }
 
@@ -2230,8 +2594,9 @@ public class BuildCode {
   protected void generateCode(FlatNode first,
                               FlatMethod fm,
                               LocalityBinding lb,
-                             Set<FlatNode> stopset,
-                              PrintWriter output, boolean firstpass) {
+                              Set<FlatNode> stopset,
+                              PrintWriter output, 
+                              boolean firstpass) {
 
     /* Assign labels to FlatNode's if necessary.*/
 
@@ -2310,7 +2675,7 @@ public class BuildCode {
            output.println("primitives->"+tmp.getSafeSymbol()+"="+tmp.getSafeSymbol()+";");
          }
        }
-       if (state.MLP && stopset!=null) {
+       if ((state.MLP || state.OOOJAVA) && stopset!=null) {
          assert first.getPrev( 0 ) instanceof FlatSESEEnterNode;
          assert current_node       instanceof FlatSESEExitNode;
          FlatSESEEnterNode fsen = (FlatSESEEnterNode) first.getPrev( 0 );
@@ -2319,12 +2684,17 @@ public class BuildCode {
          assert fsxn.getFlatEnter().equals( fsen );
        }
        if (current_node.kind()!=FKind.FlatReturnNode) {
+      if((fm.getMethod() != null) && (fm.getMethod().isStaticBlock())) {
+        // a static block, check if it has been executed
+        output.println("  global_defs_p->" + fm.getMethod().getClassDesc().getSafeSymbol()+"static_block_exe_flag = 1;");
+        output.println("");
+      }
          output.println("   return;");
        }
        current_node=null;
       } else if(current_node.numNext()==1) {
        FlatNode nextnode;
-       if (state.MLP && 
+       if ((state.MLP|| state.OOOJAVA) && 
            current_node.kind()==FKind.FlatSESEEnterNode && 
            !((FlatSESEEnterNode)current_node).getIsCallerSESEplaceholder()
           ) {
@@ -2592,7 +2962,6 @@ public class BuildCode {
     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();
     }
 
@@ -2610,10 +2979,16 @@ 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 ) {
+    if( state.MLP|| state.OOOJAVA ) {
       
-      CodePlan cp = mlpa.getCodePlan( fn );
-      if( cp != null ) {               
+      CodePlan cp;
+      if(state.MLP){
+        cp = mlpa.getCodePlan( fn );
+      }else{
+        cp = oooa.getCodePlan(fn);
+      }
+
+      if( cp != null ) {
        
        FlatSESEEnterNode currentSESE = cp.getCurrentSESE();
        
@@ -2624,23 +2999,31 @@ public class BuildCode {
        while( vstItr.hasNext() ) {
          VariableSourceToken vst = vstItr.next();
 
-         SESEandAgePair p = new SESEandAgePair( vst.getSESE(), vst.getAge() );
+         SESEandAgePair pair = 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("     "+pair.getSESE().getSESErecordName()+"* child = ("+
+                         pair.getSESE().getSESErecordName()+"*) "+pair+";");
+
+         output.println("     SESEcommon* childCom = (SESEcommon*) "+pair+";");
+
+          if( state.COREPROF ) {
+            output.println("#ifdef CP_EVENTID_TASKSTALLVAR");
+            output.println("     CP_LOGEVENT( CP_EVENTID_TASKSTALLVAR, CP_EVENTTYPE_BEGIN );");
+            output.println("#endif");
+          }
+
+         output.println("     pthread_mutex_lock( &(childCom->lock) );");
+         output.println("     if( childCom->doneExecuting == FALSE ) {");
+          output.println("       psem_reset( &runningSESEstallSem );");
+         output.println("       childCom->parentsStallSem = &runningSESEstallSem;");
+         output.println("       pthread_mutex_unlock( &(childCom->lock) );");
+         output.println("       psem_take( &runningSESEstallSem, (struct garbagelist *)&___locals___ );");
+         output.println("     } else {");
+         output.println("       pthread_mutex_unlock( &(childCom->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+";");
-         
+         // copy things we might have stalled for                
          Iterator<TempDescriptor> tdItr = cp.getCopySet( vst ).iterator();
          while( tdItr.hasNext() ) {
            TempDescriptor td = tdItr.next();
@@ -2654,9 +3037,15 @@ public class BuildCode {
                           " = child->"+vst.getAddrVar().getSafeSymbol()+";");
          }
 
+          if( state.COREPROF ) {
+            output.println("#ifdef CP_EVENTID_TASKSTALLVAR");
+            output.println("     CP_LOGEVENT( CP_EVENTID_TASKSTALLVAR, CP_EVENTTYPE_END );");
+            output.println("#endif");
+          }
+
          output.println("   }");
        }
-       
+  
        // for each variable with a dynamic source, stall just for that variable
        Iterator<TempDescriptor> dynItr = cp.getDynamicStallSet().iterator();
        while( dynItr.hasNext() ) {
@@ -2666,8 +3055,24 @@ public class BuildCode {
          // 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) );");
+
+         output.println("       SESEcommon* childCom = (SESEcommon*) "+dynVar+"_srcSESE;");
+
+          if( state.COREPROF ) {
+            output.println("#ifdef CP_EVENTID_TASKSTALLVAR");
+            output.println("       CP_LOGEVENT( CP_EVENTID_TASKSTALLVAR, CP_EVENTTYPE_BEGIN );");
+            output.println("#endif");
+          }
+
+         output.println("     pthread_mutex_lock( &(childCom->lock) );");
+         output.println("     if( childCom->doneExecuting == FALSE ) {");
+          output.println("       psem_reset( &runningSESEstallSem );");
+         output.println("       childCom->parentsStallSem = &runningSESEstallSem;");
+         output.println("       pthread_mutex_unlock( &(childCom->lock) );");
+         output.println("       psem_take( &runningSESEstallSem, (struct garbagelist *)&___locals___ );");
+         output.println("     } else {");
+         output.println("       pthread_mutex_unlock( &(childCom->lock) );");
+         output.println("     }");
 
          FlatMethod fmContext;
          if( currentSESE.getIsCallerSESEplaceholder() ) {
@@ -2675,10 +3080,27 @@ public class BuildCode {
          } else {
            fmContext = currentSESE.getfmBogus();
          }
-         output.println("       "+generateTemp( fmContext, dynVar, null )+
-                        " = *(("+dynVar.getType()+"*) ("+
-                        dynVar+"_srcSESE + "+dynVar+"_srcOffset));");
          
+         TypeDescriptor type = dynVar.getType();
+          String typeStr;
+          if( type.isNull() ) {
+            typeStr = "void*";
+          } else if( type.isClass() || type.isArray() ) {
+            typeStr = "struct "+type.getSafeSymbol()+"*";
+          } else {
+            typeStr = type.getSafeSymbol();
+          }
+      
+         output.println("       "+generateTemp( fmContext, dynVar, null )+
+                         " = *(("+typeStr+"*) ((void*)"+
+                         dynVar+"_srcSESE + "+dynVar+"_srcOffset));");
+
+          if( state.COREPROF ) {
+            output.println("#ifdef CP_EVENTID_TASKSTALLVAR");
+            output.println("       CP_LOGEVENT( CP_EVENTID_TASKSTALLVAR, CP_EVENTTYPE_END );");
+            output.println("#endif");
+          }
+
          output.println("     }");
          output.println("   }");
        }
@@ -2690,51 +3112,144 @@ public class BuildCode {
          Map.Entry      me  = (Map.Entry)      dynAssignItr.next();
          TempDescriptor lhs = (TempDescriptor) me.getKey();
          TempDescriptor rhs = (TempDescriptor) me.getValue();
+
+          output.println("   {");
+          output.println("   SESEcommon* oldSrc = "+lhs+"_srcSESE;");
+          
          output.println("   "+lhs+"_srcSESE   = "+rhs+"_srcSESE;");
          output.println("   "+lhs+"_srcOffset = "+rhs+"_srcOffset;");
+
+          // no matter what we did above, track reference count of whatever
+          // this variable pointed to, do release last in case we're just
+          // copying the same value in because 1->2->1 is safe but ref count
+          // 1->0->1 has a window where it looks like it should be free'd
+          output.println("#ifndef OOO_DISABLE_TASKMEMPOOL" );
+          output.println("     if( "+rhs+"_srcSESE != NULL ) {");
+          output.println("       ADD_REFERENCE_TO( "+rhs+"_srcSESE );");
+          output.println("     }");
+          output.println("     if( oldSrc != NULL ) {");
+          output.println("       RELEASE_REFERENCE_TO( oldSrc );");
+          output.println("     }");
+          output.println("   }");
+          output.println("#endif // OOO_DISABLE_TASKMEMPOOL" );
        }
 
        // 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;");
+         TempDescriptor dynVar = dynItr.next();          
+          assert currentSESE.getDynamicVarSet().contains( dynVar );
+
+          // first release a reference to current record
+          output.println("#ifndef OOO_DISABLE_TASKMEMPOOL" );
+          output.println("   if( "+dynVar+"_srcSESE != NULL ) {");
+          output.println("     RELEASE_REFERENCE_TO( oldSrc );");
+          output.println("   }");
+          output.println("#endif // OOO_DISABLE_TASKMEMPOOL" );
+
+          output.println("   "+dynVar+"_srcSESE = NULL;");
        }
-      }     
-      
-      // eom
-      // handling stall site
-      ParentChildConflictsMap conflictsMap=mlpa.getConflictsResults().get(fn);
-               if (conflictsMap != null) {
        
-                       Set<Long> allocSet = conflictsMap
-                                       .getAllocationSiteIDSetofStallSite();
-       
-                       if (allocSet.size() > 0) {
-                               output.println("   /*  stall on parent's stall sites */");
-                               output.println("  {");
-                               output.println("     pthread_mutex_lock( &(seseCaller->lock) );");
-                               output.println("     psem_init( &(seseCaller->memoryStallSiteSem) );");
-                               output.println("     int qIdx;");
-                               output.println("     int takeCount=0;");
-                               for (Iterator iterator = allocSet.iterator(); iterator
-                                               .hasNext();) {
-                                       Long allocID = (Long) iterator.next();
-                                       output.println("     qIdx=getQueueIdx(seseCaller->allocSiteArray,numRelatedAllocSites,"
-                                                                       + allocID + ");");
-                                       output.println("     if(qIdx!=-1 && !isEmpty(seseCaller->allocSiteArray[qIdx].waitingQueue)){");
-                                       output.println("        addNewItemBack(seseCaller->allocSiteArray[qIdx].waitingQueue,seseCaller);");
-                                       output.println("        takeCount++;");
-                                       output.println("     }");
-                               }
-                               output.println("     pthread_mutex_unlock( &(seseCaller->lock) );");
-                               output.println("     if( takeCount>0 ){");
-                               output.println("        psem_take( &(seseCaller->memoryStallSiteSem) );");
-                               output.println("     }");
-                               output.println("  }");
-                       }
-               }
+        // eom
+        // handling stall site
+        if (state.OOOJAVA) {
+          Analysis.OoOJava.ConflictGraph graph = oooa.getConflictGraph(currentSESE);
+          if(graph!=null){
+            Set<Analysis.OoOJava.SESELock> seseLockSet = oooa.getLockMappings(graph);
+            Set<Analysis.OoOJava.WaitingElement> waitingElementSet =
+              graph.getStallSiteWaitingElementSet(fn, seseLockSet);
+            
+            if(waitingElementSet.size()>0){
+              output.println("// stall on parent's stall sites ");
+              output.println("   {");
+              output.println("     REntry* rentry;");
+          
+              for (Iterator iterator = waitingElementSet.iterator(); iterator.hasNext();) {
+                Analysis.OoOJava.WaitingElement waitingElement = (Analysis.OoOJava.WaitingElement) iterator.next();
+               if( waitingElement.getStatus() >= ConflictNode.COARSE ){
+                  output.println("     rentry=mlpCreateREntry("+ waitingElement.getStatus()+ ", runningSESE);");
+                }else{
+                  output.println("     rentry=mlpCreateFineREntry("+ waitingElement.getStatus()+ ", runningSESE,  (void*)&" +generateTemp(fm,waitingElement.getTempDesc(),lb)+ ");");
+                }         
+                output.println("     psem_init( &(rentry->parentStallSem) );");
+                output.println("     rentry->queue=runningSESE->memoryQueueArray["+ waitingElement.getQueueID()+ "];");
+                output.println("     if(ADDRENTRY(runningSESE->memoryQueueArray["+ waitingElement.getQueueID()
+                           + "],rentry)==NOTREADY){");
+                if( state.COREPROF ) {
+                  output.println("#ifdef CP_EVENTID_TASKSTALLMEM");
+                  output.println("        CP_LOGEVENT( CP_EVENTID_TASKSTALLMEM, CP_EVENTTYPE_BEGIN );");
+                  output.println("#endif");
+                }
+                output.println("        psem_take( &(rentry->parentStallSem), (struct garbagelist *)&___locals___ );");
+                if( state.COREPROF ) {
+                  output.println("#ifdef CP_EVENTID_TASKSTALLMEM");
+                  output.println("        CP_LOGEVENT( CP_EVENTID_TASKSTALLMEM, CP_EVENTTYPE_END );");
+                  output.println("#endif");
+                }
+                output.println("     }  ");
+                
+                if(state.RCR) {
+                  output.println("   "+rcr.getTraverserInvocation(waitingElement.getTempDesc(), 
+                      generateTemp(fm, waitingElement.getTempDesc(), null), fn));
+                }
+              }
+              output.println("   }");
+            }
+          }
+        }else{
+          ParentChildConflictsMap conflictsMap = mlpa.getConflictsResults().get(fn);
+          if (conflictsMap != null) {
+            Set<Long> allocSet = conflictsMap.getAllocationSiteIDSetofStallSite();
+            if (allocSet.size() > 0) {
+              FlatNode enclosingFlatNode=null;
+              if( currentSESE.getIsCallerSESEplaceholder() && currentSESE.getParent()==null){
+                enclosingFlatNode=currentSESE.getfmEnclosing();
+              }else{
+                enclosingFlatNode=currentSESE;
+              }                                                
+              ConflictGraph graph=mlpa.getConflictGraphResults().get(enclosingFlatNode);
+              HashSet<SESELock> seseLockSet=mlpa.getConflictGraphLockMap().get(graph);
+              Set<WaitingElement> waitingElementSet=graph.getStallSiteWaitingElementSet(conflictsMap, seseLockSet);
+                       
+              if(waitingElementSet.size()>0){
+                output.println("// stall on parent's stall sites ");
+                output.println("   {");
+                output.println("     REntry* rentry;");
+                               
+                for (Iterator iterator = waitingElementSet.iterator(); iterator.hasNext();) {
+                  WaitingElement waitingElement = (WaitingElement) iterator.next();
+                                       
+                  if( waitingElement.getStatus() >= ConflictNode.COARSE ){
+                    // HERE! a parent might conflict with a child
+                    output.println("     rentry=mlpCreateREntry("+ waitingElement.getStatus()+ ", runningSESE);");
+                  }else{
+                    output.println("     rentry=mlpCreateFineREntry("+ waitingElement.getStatus()+ ", runningSESE,  (void*)&___locals___."+ waitingElement.getDynID() + ");");
+                  }                                    
+                  output.println("     psem_init( &(rentry->parentStallSem) );");
+                  output.println("     rentry->queue=runningSESE->memoryQueueArray["+ waitingElement.getQueueID()+ "];");
+                  output
+                    .println("     if(ADDRENTRY(runningSESE->memoryQueueArray["+ waitingElement.getQueueID()
+                             + "],rentry)==NOTREADY){");
+                  if( state.COREPROF ) {
+                    output.println("#ifdef CP_EVENTID_TASKSTALLMEM");
+                    output.println("        CP_LOGEVENT( CP_EVENTID_TASKSTALLMEM, CP_EVENTTYPE_BEGIN );");
+                    output.println("#endif");
+                  }
+                  output.println("        psem_take( &(rentry->parentStallSem), (struct garbagelist *)&___locals___ );");
+                  if( state.COREPROF ) {
+                    output.println("#ifdef CP_EVENTID_TASKSTALLMEM");
+                    output.println("        CP_LOGEVENT( CP_EVENTID_TASKSTALLMEM, CP_EVENTTYPE_END );");
+                    output.println("#endif");
+                  }
+                  output.println("     }  ");
+                }
+                output.println("   }");
+              }
+            }
+          }    
+       }
+      }
     }
 
     switch(fn.kind()) {
@@ -2814,6 +3329,11 @@ public class BuildCode {
       output.println("/* nop */");
       break;
 
+    case FKind.FlatGenReachNode:
+      // this node is just for generating a reach graph
+      // in disjointness analysis at a particular program point
+      break;
+
     case FKind.FlatExit:
       output.println("/* exit */");
       break;
@@ -2822,7 +3342,10 @@ public class BuildCode {
       if (state.SINGLETM&&state.SANDBOX&&(locality.getAtomic(lb).get(fn).intValue()>0)) {
        output.println("if (unlikely((--transaction_check_counter)<=0)) checkObjects();");
       }
-      if (((state.THREAD||state.DSM||state.SINGLETM)&&GENERATEPRECISEGC)
+      if(state.DSM&&state.SANDBOX&&(locality.getAtomic(lb).get(fn).intValue()>0)) {
+        output.println("if (unlikely((--transaction_check_counter)<=0)) checkObjects();");
+      }
+      if (((state.MLP|| state.OOOJAVA||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+");");
@@ -2855,13 +3378,15 @@ public class BuildCode {
       throw new Error();
     }
 
-    // insert post-node actions from the code-plan    
-    if( state.MLP ) {
+    // insert post-node actions from the code-plan
+    /*
+    if( state.MLP) {
       CodePlan cp = mlpa.getCodePlan( fn );
 
       if( cp != null ) {     
       }
-    }    
+    }
+    */
   }
 
   public void generateFlatOffsetNode(FlatMethod fm, LocalityBinding lb, FlatOffsetNode fofn, PrintWriter output) {
@@ -3239,17 +3764,16 @@ public class BuildCode {
   public void generateFlatSESEEnterNode( FlatMethod fm,  
                                         LocalityBinding lb, 
                                         FlatSESEEnterNode fsen, 
-                                        PrintWriter output 
-                                      ) {
-
+                                        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 ) {
+    if( !(state.MLP || state.OOOJAVA) ) {
       return;
     }    
-
     // there may be an SESE in an unreachable method, skip over
-    if( !mlpa.getAllSESEs().contains( fsen ) ) {
+    if( (state.MLP && !mlpa.getAllSESEs().contains( fsen )) ||
+        (state.OOOJAVA && !oooa.getAllSESEs().contains(fsen))
+    ) {
       return;
     }
 
@@ -3260,48 +3784,91 @@ public class BuildCode {
 
     output.println("   {");
 
-    // set up the parent
-    if( fsen == mlpa.getMainSESE() ) {
-      output.println("     SESEcommon* parentCommon = NULL;");
+    if( state.COREPROF ) {
+      output.println("#ifdef CP_EVENTID_TASKDISPATCH");
+      output.println("     CP_LOGEVENT( CP_EVENTID_TASKDISPATCH, CP_EVENTTYPE_BEGIN );");
+      output.println("#endif");
+    }
+
+
+    // before doing anything, lock your own record and increment the running children
+    if( (state.MLP     && fsen != mlpa.getMainSESE()) || 
+        (state.OOOJAVA && fsen != oooa.getMainSESE())
+    ) {      
+      output.println("     atomic_inc(&(runningSESE->numRunningChildren));");
+    }
+
+    // allocate the space for this record
+    output.println( "#ifndef OOO_DISABLE_TASKMEMPOOL" );
+
+    output.println( "#ifdef CP_EVENTID_POOLALLOC");
+    output.println( "     CP_LOGEVENT( CP_EVENTID_POOLALLOC, CP_EVENTTYPE_BEGIN );");
+    output.println( "#endif");
+    if( (state.MLP     && fsen != mlpa.getMainSESE()) || 
+        (state.OOOJAVA && fsen != oooa.getMainSESE())
+        ) {
+      output.println("     "+
+                     fsen.getSESErecordName()+"* seseToIssue = ("+
+                     fsen.getSESErecordName()+"*) poolalloc( runningSESE->taskRecordMemPool );");
     } else {
-      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;");
-      }
+      output.println("     "+
+                     fsen.getSESErecordName()+"* seseToIssue = ("+
+                     fsen.getSESErecordName()+"*) mlpAllocSESErecord( sizeof( "+
+                     fsen.getSESErecordName()+" ) );");
+    }
+    output.println( "#ifdef CP_EVENTID_POOLALLOC");
+    output.println( "     CP_LOGEVENT( CP_EVENTID_POOLALLOC, CP_EVENTTYPE_END );");
+    output.println( "#endif");
+
+    output.println( "#else // OOO_DISABLE_TASKMEMPOOL" );
+      output.println("     "+
+                     fsen.getSESErecordName()+"* seseToIssue = ("+
+                     fsen.getSESErecordName()+"*) mlpAllocSESErecord( sizeof( "+
+                     fsen.getSESErecordName()+" ) );");
+    output.println( "#endif // OOO_DISABLE_TASKMEMPOOL" );
+
+
+    // set up the SESE in-set and out-set objects, which look
+    // like a garbage list
+    output.println("     struct garbagelist * gl= (struct garbagelist *)&(((SESEcommon*)(seseToIssue))[1]);");
+    output.println("     gl->size="+calculateSizeOfSESEParamList(fsen)+";");
+    output.println("     gl->next = NULL;");
+
+    // there are pointers to SESE records the newly-issued SESE
+    // will use to get values it depends on them for--how many
+    // are there, and what is the offset from the total SESE
+    // record to the first dependent record pointer?
+    output.println("     seseToIssue->common.numDependentSESErecords="+
+                   fsen.getNumDepRecs()+";");
+    
+    // we only need this (and it will only compile) when the number of dependent
+    // SESE records is non-zero
+    if( fsen.getFirstDepRecField() != null ) {
+      output.println("     seseToIssue->common.offsetToDepSESErecords=(INTPTR)sizeof("+
+                     fsen.getSESErecordName()+") - (INTPTR)&((("+
+                     fsen.getSESErecordName()+"*)0)->"+fsen.getFirstDepRecField()+");"
+                     );
     }
     
-    // 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) );");      
+    if (state.RCR&&fsen.getInVarsForDynamicCoarseConflictResolution().size()>0) {
+      output.println("    seseToIssue->common.offsetToParamRecords=(INTPTR)sizeof("+fsen.getSESErecordName()+") - (INTPTR) & ((("+fsen.getSESErecordName()+"*)0)->rcrRecords);");
     }
 
-    // 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("     int localCount=0;");
     output.println("     seseToIssue->common.classID = "+fsen.getIdentifier()+";");
-    output.println("     psem_init( &(seseToIssue->common.stallSem) );");
-
+    output.println("     seseToIssue->common.parentsStallSem = NULL;");
     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.unresolvedDependencies = 10000;");
     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;");
+    output.println("     seseToIssue->common.parent = runningSESE;");
+    // start with refCount = 2, one being the count that the child itself
+    // will decrement when it retires, to say it is done using its own
+    // record, and the other count is for the parent that will remember
+    // the static name of this new child below
+    output.println("     seseToIssue->common.refCount = 2;");
 
     // all READY in-vars should be copied now and be done with it
     Iterator<TempDescriptor> tempItr = fsen.getReadyInVarSet().iterator();
@@ -3313,7 +3880,9 @@ public class BuildCode {
       // otherwise use the parent's enclosing method as the context
       boolean useParentContext = false;
 
-      if( fsen != mlpa.getMainSESE() ) {
+      if( (state.MLP && fsen != mlpa.getMainSESE()) || 
+          (state.OOOJAVA && fsen != oooa.getMainSESE())     
+      ) {
        assert fsen.getParent() != null;
        if( !fsen.getParent().getIsCallerSESEplaceholder() ) {
          useParentContext = true;
@@ -3329,67 +3898,14 @@ public class BuildCode {
       }
     }
     
-    // count up memory conflict dependencies,
-    // eom
-    ConflictGraph graph=null;
-    FlatSESEEnterNode parent=fsen.getParent();
-    if(parent!=null){
-        if(parent.isCallerSESEplaceholder){
-               graph=mlpa.getConflictGraphResults().get(parent.getfmEnclosing());
-        }else{
-               graph=mlpa.getConflictGraphResults().get(parent);
-        }
-    }
-               if (graph != null) {
-                       output.println();
-                       output.println("     /*add waiting queue element*/");
-
-                       Set<Long> allocSet = graph.getAllocationSiteIDSetBySESEID(fsen
-                                       .getIdentifier());
-                       if (allocSet.size() > 0) {
-                               output.println("     {");
-                               output
-                                               .println("     pthread_mutex_lock( &(parentCommon->lock) );");
-
-                               for (Iterator iterator = allocSet.iterator(); iterator
-                                               .hasNext();) {
-                                       Long allocID = (Long) iterator.next();
-                                       output
-                                                       .println("     addWaitingQueueElement(parentCommon->allocSiteArray,numRelatedAllocSites,"
-                                                                       + allocID
-                                                                       + ",seseToIssue);");
-                                       output
-                                                       .println("     ++(seseToIssue->common.unresolvedDependencies);");
-                               }
-                               output
-                                               .println("     pthread_mutex_unlock( &(parentCommon->lock) );");
-                               output.println("     }");
-                       }
-                       
-                       output.println("     /*decide whether it is runnable or not in regarding to memory conflicts*/");
-                       output.println("     {");
-                       output.println("     int idx;");
-                       output.println("              pthread_mutex_lock( &(parentCommon->lock)  );");
-                       output.println("     for(idx = 0 ; idx < numRelatedAllocSites ; idx++){");
-                       output.println("        struct Queue *allocQueue=parentCommon->allocSiteArray[idx].waitingQueue;");
-                       output.println("        if(allocQueue->head!=NULL){");
-                       output.println("           SESEcommon* item=peekItem(parentCommon->allocSiteArray[idx].waitingQueue);");
-                       output.println("           if(item->classID==seseToIssue->common.classID){");
-                       output.println("              --(seseToIssue->common.unresolvedDependencies);");
-                       output.println("           }");
-                       output.println("        }");
-                       output.println("     }");
-                       output.println("              pthread_mutex_unlock( &(parentCommon->lock)  );");
-                       output.println("     }");
-                       output.println();
-               }
-
     // before potentially adding this SESE to other forwarding lists,
-    //  create it's lock and take it immediately
+    // create it's lock
     output.println("     pthread_mutex_init( &(seseToIssue->common.lock), NULL );");
-    output.println("     pthread_mutex_lock( &(seseToIssue->common.lock) );");
 
-    if( fsen != mlpa.getMainSESE() ) {
+  
+    if( (state.MLP && fsen != mlpa.getMainSESE()) ||
+        (state.OOOJAVA && fsen != oooa.getMainSESE())    
+    ) {
       // count up outstanding dependencies, static first, then dynamic
       Iterator<SESEandAgePair> staticSrcsItr = fsen.getStaticInVarSrcs().iterator();
       while( staticSrcsItr.hasNext() ) {
@@ -3397,23 +3913,24 @@ public class BuildCode {
        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("       }");
+        // FORWARD TODO
        output.println("       if( !src->doneExecuting ) {");
-       output.println("         addNewItem( src->forwardList, seseToIssue );");
-       output.println("         ++(seseToIssue->common.unresolvedDependencies);");
+        output.println("         addNewItem( src->forwardList, seseToIssue );");       
+       output.println("         ++(localCount);");
        output.println("       }");
+        output.println("#ifndef OOO_DISABLE_TASKMEMPOOL" );
+        output.println("       ADD_REFERENCE_TO( src );");
+        output.println("#endif" );
        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+";");
+       output.println("     seseToIssue->"+srcPair+" = "+
+                       "("+srcPair.getSESE().getSESErecordName()+"*)"+
+                       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();
@@ -3427,19 +3944,27 @@ public class BuildCode {
        // might change the variable, so copy it right now
        output.println("       if( src != NULL ) {");
        output.println("         pthread_mutex_lock( &(src->lock) );");
+
+        // FORWARD TODO
+
        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("             ++(localCount);");
        output.println("           }");
        output.println("         }");
+        output.println("#ifndef OOO_DISABLE_TASKMEMPOOL" );
+        output.println("         ADD_REFERENCE_TO( src );");
+        output.println("#endif" );
        output.println("         pthread_mutex_unlock( &(src->lock) );");       
        output.println("         seseToIssue->"+dynInVar+"_srcOffset = "+dynInVar+"_srcOffset;");
        output.println("       } else {");
 
        boolean useParentContext = false;
-       if( fsen != mlpa.getMainSESE() ) {
+       if( (state.MLP && fsen != mlpa.getMainSESE()) || 
+           (state.OOOJAVA && fsen != oooa.getMainSESE())       
+       ) {
          assert fsen.getParent() != null;
          if( !fsen.getParent().getIsCallerSESEplaceholder() ) {
            useParentContext = true;
@@ -3460,46 +3985,354 @@ public class BuildCode {
        // 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 
+
+
+      // maintain pointers for finding dynamic SESE 
       // instances from static names      
-      SESEandAgePair p = new SESEandAgePair( fsen, 0 );
+      SESEandAgePair pairNewest = new SESEandAgePair( fsen, 0 );
+      SESEandAgePair pairOldest = new SESEandAgePair( fsen, fsen.getOldestAgeToTrack() );
       if(  fsen.getParent() != null && 
-          //!fsen.getParent().getIsCallerSESEplaceholder() &&
-          fsen.getParent().getNeededStaticNames().contains( p ) 
+          fsen.getParent().getNeededStaticNames().contains( pairNewest ) 
        ) {       
+        output.println("     {");
+        output.println("#ifndef OOO_DISABLE_TASKMEMPOOL" );
+        output.println("       SESEcommon* oldest = "+pairOldest+";");
+        output.println("#endif // OOO_DISABLE_TASKMEMPOOL" );
 
        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+";");
+         SESEandAgePair pair1 = new SESEandAgePair( fsen, i   );
+         SESEandAgePair pair2 = new SESEandAgePair( fsen, i-1 );
+         output.println("       "+pair1+" = "+pair2+";");
        }      
-       output.println("     "+p+" = seseToIssue;");
+       output.println("       "+pairNewest+" = &(seseToIssue->common);");
+
+        // no need to add a reference to whatever is the newest record, because
+        // we initialized seseToIssue->refCount to *2*
+        // but release a reference to whatever was the oldest BEFORE the shift
+        output.println("#ifndef OOO_DISABLE_TASKMEMPOOL" );
+        output.println("       if( oldest != NULL ) {");
+        output.println("         RELEASE_REFERENCE_TO( oldest );");
+        output.println("       }");
+        output.println("#endif // OOO_DISABLE_TASKMEMPOOL" );
+        output.println("     }");
+      }
+
+
+
+      if( state.COREPROF ) {
+        output.println("#ifdef CP_EVENTID_PREPAREMEMQ");
+        output.println("     CP_LOGEVENT( CP_EVENTID_PREPAREMEMQ, CP_EVENTTYPE_BEGIN );");
+        output.println("#endif");
+      }
+
+
+      ////////////////
+      // count up memory conflict dependencies,
+      if(state.RCR) {
+       dispatchMEMRC(fm, lb, fsen, output);
+      } else if(state.OOOJAVA){
+        FlatSESEEnterNode parent = fsen.getParent();
+        Analysis.OoOJava.ConflictGraph graph = oooa.getConflictGraph(parent);
+        if (graph != null && graph.hasConflictEdge()) {
+          Set<Analysis.OoOJava.SESELock> seseLockSet = oooa.getLockMappings(graph);
+          output.println();
+          output.println("     //add memory queue element");
+          Analysis.OoOJava.SESEWaitingQueue seseWaitingQueue=
+            graph.getWaitingElementSetBySESEID(fsen.getIdentifier(), seseLockSet);
+          if(seseWaitingQueue.getWaitingElementSize()>0) {
+            output.println("     {");
+            output.println("       REntry* rentry=NULL;");
+            output.println("       INTPTR* pointer=NULL;");
+            output.println("       seseToIssue->common.rentryIdx=0;");
+
+            Set<Integer> queueIDSet=seseWaitingQueue.getQueueIDSet();
+            for (Iterator iterator = queueIDSet.iterator(); iterator.hasNext();) {
+              Integer key = (Integer) iterator.next();
+              int queueID=key.intValue();
+              Set<Analysis.OoOJava.WaitingElement> waitingQueueSet =  
+                seseWaitingQueue.getWaitingElementSet(queueID);
+              int enqueueType=seseWaitingQueue.getType(queueID);
+              if(enqueueType==SESEWaitingQueue.EXCEPTION) {
+                output.println("       INITIALIZEBUF(runningSESE->memoryQueueArray[" + queueID+ "]);");
+              }
+              for (Iterator iterator2 = waitingQueueSet.iterator(); iterator2.hasNext();) {
+                Analysis.OoOJava.WaitingElement waitingElement 
+                  = (Analysis.OoOJava.WaitingElement) iterator2.next();
+                if (waitingElement.getStatus() >= ConflictNode.COARSE) {
+                  output.println("       rentry=mlpCreateREntry("
+                                 + waitingElement.getStatus()
+                                 + ", &(seseToIssue->common));");
+                } else {
+                  TempDescriptor td = waitingElement.getTempDesc();
+                  // decide whether waiting element is dynamic or static
+                  if (fsen.getDynamicInVarSet().contains(td)) {
+                    // dynamic in-var case
+                    output.println("       pointer=seseToIssue->"
+                                   + waitingElement.getDynID()
+                                   + "_srcSESE+seseToIssue->"
+                                   + waitingElement.getDynID()
+                                   + "_srcOffset;");
+                    output.println("       rentry=mlpCreateFineREntry("
+                                   + waitingElement.getStatus()
+                                   + ", &(seseToIssue->common),  pointer );");
+                  } else if (fsen.getStaticInVarSet().contains(td)) {
+                    // static in-var case
+                    VariableSourceToken vst = fsen.getStaticInVarSrc(td);
+                    if (vst != null) {
+  
+                      String srcId = "SESE_" + vst.getSESE().getPrettyIdentifier()
+                        + vst.getSESE().getIdentifier()
+                        + "_" + vst.getAge();
+                      output.println("       pointer=(void*)&seseToIssue->"
+                                     + srcId
+                                     + "->"
+                                     + waitingElement
+                                     .getDynID()
+                                     + ";");
+                      output.println("       rentry=mlpCreateFineREntry("
+                                     + waitingElement.getStatus()
+                                     + ", &(seseToIssue->common),  pointer );");
+                    }
+                  } else {
+                    output.println("       rentry=mlpCreateFineREntry("
+                                   + waitingElement.getStatus()
+                                   + ", &(seseToIssue->common), (void*)&seseToIssue->"
+                                   + waitingElement.getDynID()
+                                   + ");");
+                  }
+                }
+                output.println("       rentry->queue=runningSESE->memoryQueueArray["
+                               + waitingElement.getQueueID()
+                               + "];");
+                
+                if(enqueueType==SESEWaitingQueue.NORMAL){
+                  output.println("       seseToIssue->common.rentryArray[seseToIssue->common.rentryIdx++]=rentry;");
+                  output.println("       if(ADDRENTRY(runningSESE->memoryQueueArray["
+                                 + waitingElement.getQueueID()
+                                 + "],rentry)==NOTREADY) {");
+                  output.println("          localCount++;");
+                  output.println("       }");
+               } else {
+                  output.println("       ADDRENTRYTOBUF(runningSESE->memoryQueueArray[" + waitingElement.getQueueID() + "],rentry);");
+                }
+              }
+              if(enqueueType!=SESEWaitingQueue.NORMAL){
+                output.println("       localCount+=RESOLVEBUF(runningSESE->memoryQueueArray["
+                               + queueID+ "],&seseToIssue->common);");
+              }       
+            }
+            output.println("     }");
+          }
+          output.println();
+        }
+      } else {
+       ConflictGraph graph = null;
+       FlatSESEEnterNode parent = fsen.getParent();
+       if (parent != null) {
+          if (parent.isCallerSESEplaceholder) {
+            graph = mlpa.getConflictGraphResults().get(parent.getfmEnclosing());
+          } else {
+            graph = mlpa.getConflictGraphResults().get(parent);
+          }
+       }
+        if (graph != null && graph.hasConflictEdge()) {
+          HashSet<SESELock> seseLockSet = mlpa.getConflictGraphLockMap()
+            .get(graph);
+          output.println();
+          output.println("     //add memory queue element");
+          SESEWaitingQueue seseWaitingQueue=graph.getWaitingElementSetBySESEID(fsen.getIdentifier(),
+                                                                               seseLockSet);
+          if(seseWaitingQueue.getWaitingElementSize()>0){
+            output.println("     {");
+            output.println("     REntry* rentry=NULL;");
+            output.println("     INTPTR* pointer=NULL;");
+            output.println("     seseToIssue->common.rentryIdx=0;");
+
+            Set<Integer> queueIDSet=seseWaitingQueue.getQueueIDSet();
+            for (Iterator iterator = queueIDSet.iterator(); iterator
+                   .hasNext();) {
+              Integer key = (Integer) iterator.next();
+              int queueID=key.intValue();
+              Set<WaitingElement> waitingQueueSet =  seseWaitingQueue.getWaitingElementSet(queueID);
+              int enqueueType=seseWaitingQueue.getType(queueID);
+              if(enqueueType==SESEWaitingQueue.EXCEPTION){
+                output.println("     INITIALIZEBUF(runningSESE->memoryQueueArray["
+                               + queueID+ "]);");
+              }
+              for (Iterator iterator2 = waitingQueueSet.iterator(); iterator2
+                     .hasNext();) {
+                WaitingElement waitingElement = (WaitingElement) iterator2
+                  .next();
+                if (waitingElement.getStatus() >= ConflictNode.COARSE) {
+                  output.println("     rentry=mlpCreateREntry("
+                                 + waitingElement.getStatus()
+                                 + ", &(seseToIssue->common));");
+                } else {
+                  TempDescriptor td = waitingElement
+                    .getTempDesc();
+                  // decide whether waiting element is dynamic or
+                  // static
+                  if (fsen.getDynamicInVarSet().contains(td)) {
+                    // dynamic in-var case
+                    output.println("     pointer=seseToIssue->"
+                                   + waitingElement.getDynID()
+                                   + "_srcSESE+seseToIssue->"
+                                   + waitingElement.getDynID()
+                                   + "_srcOffset;");
+                    output
+                      .println("     rentry=mlpCreateFineREntry("
+                               + waitingElement
+                               .getStatus()
+                               + ", &(seseToIssue->common),  pointer );");
+                  } else if (fsen.getStaticInVarSet()
+                             .contains(td)) {
+                    // static in-var case
+                    VariableSourceToken vst = fsen
+                      .getStaticInVarSrc(td);
+                    if (vst != null) {
+  
+                      String srcId = "SESE_"
+                        + vst.getSESE()
+                        .getPrettyIdentifier()
+                        + vst.getSESE().getIdentifier()
+                        + "_" + vst.getAge();
+                      output
+                        .println("     pointer=(void*)&seseToIssue->"
+                                 + srcId
+                                 + "->"
+                                 + waitingElement
+                                 .getDynID()
+                                 + ";");
+                      output
+                        .println("     rentry=mlpCreateFineREntry("
+                                 + waitingElement
+                                 .getStatus()
+                                 + ", &(seseToIssue->common),  pointer );");
+  
+                    }
+                  } else {
+                    output
+                      .println("     rentry=mlpCreateFineREntry("
+                               + waitingElement
+                               .getStatus()
+                               + ", &(seseToIssue->common),  (void*)&seseToIssue->"
+                               + waitingElement.getDynID()
+                               + ");");
+                  }
+                }
+                output
+                  .println("     rentry->queue=runningSESE->memoryQueueArray["
+                           + waitingElement.getQueueID()
+                           + "];");
+                                                       
+                if(enqueueType==SESEWaitingQueue.NORMAL){
+                  output
+                    .println("     seseToIssue->common.rentryArray[seseToIssue->common.rentryIdx++]=rentry;");
+                  output
+                    .println("     if(ADDRENTRY(runningSESE->memoryQueueArray["
+                             + waitingElement.getQueueID()
+                             + "],rentry)==NOTREADY){");
+                  output.println("        ++(localCount);");
+                  output.println("     } ");
+                }else{
+                  output
+                    .println("     ADDRENTRYTOBUF(runningSESE->memoryQueueArray["
+                             + waitingElement.getQueueID()
+                             + "],rentry);");
+                }
+              }
+              if(enqueueType!=SESEWaitingQueue.NORMAL){
+                output.println("     localCount+=RESOLVEBUF(runningSESE->memoryQueueArray["
+                               + queueID+ "],&seseToIssue->common);");
+              }
+            }
+            output.println("     }");
+          }
+          output.println();
+        }
       }
+    }
+
+    if( state.COREPROF ) {
+      output.println("#ifdef CP_EVENTID_PREPAREMEMQ");
+      output.println("     CP_LOGEVENT( CP_EVENTID_PREPAREMEMQ, CP_EVENTTYPE_END );");
+      output.println("#endif");
+    }
+
+    // Enqueue Task Record
+    if (state.RCR) {
+      output.println("    enqueueTR(TRqueue, (void *)seseToIssue);");
     }
 
     // if there were no outstanding dependencies, issue here
-    output.println("     if( seseToIssue->common.unresolvedDependencies == 0 ) {");
+    output.println("     if(  atomic_sub_and_test(10000-localCount,&(seseToIssue->common.unresolvedDependencies) ) ) {");
     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) );");
+    
+
+    if( state.COREPROF ) {
+      output.println("#ifdef CP_EVENTID_TASKDISPATCH");
+      output.println("     CP_LOGEVENT( CP_EVENTID_TASKDISPATCH, CP_EVENTTYPE_END );");
+      output.println("#endif");
+    }
+
     output.println("   }");
     
   }
 
-  public void generateFlatSESEExitNode( FlatMethod fm,  
-                                       LocalityBinding lb, 
-                                       FlatSESEExitNode fsexn, 
-                                       PrintWriter output
-                                     ) {
+  void dispatchMEMRC(FlatMethod fm,  LocalityBinding lb, FlatSESEEnterNode fsen, PrintWriter output) {
+    FlatSESEEnterNode parent = fsen.getParent();
+    Analysis.OoOJava.ConflictGraph graph = oooa.getConflictGraph(parent);
+    if (graph != null && graph.hasConflictEdge()) {
+      Set<Analysis.OoOJava.SESELock> seseLockSet = oooa.getLockMappings(graph);
+      Analysis.OoOJava.SESEWaitingQueue seseWaitingQueue=graph.getWaitingElementSetBySESEID(fsen.getIdentifier(), seseLockSet);
+      if(seseWaitingQueue.getWaitingElementSize()>0) {
+       output.println("     {");
+       output.println("       REntry* rentry=NULL;");
+       output.println("       INTPTR* pointer=NULL;");
+       output.println("       seseToIssue->common.rentryIdx=0;");
+       output.println("       int dispCount;");
+       Vector<TempDescriptor> invars=fsen.getInVarsForDynamicCoarseConflictResolution();
+       for(int i=0;i<invars.size();i++) {
+         TempDescriptor td=invars.get(i);
+         Set<Analysis.OoOJava.WaitingElement> weset=seseWaitingQueue.getWaitingElementSet(td);
+         int numqueues=weset.size();
+         output.println("      seseToIssue->rcrRecords["+i+"].flag="+numqueues+";");
+         output.println("      dispCount=0;");
+         for(Iterator<Analysis.OoOJava.WaitingElement> wtit=weset.iterator();wtit.hasNext();) {
+           Analysis.OoOJava.WaitingElement waitingElement=wtit.next();
+           int queueID=waitingElement.getQueueID();
+           assert(waitingElement.getStatus()>=ConflictNode.COARSE);
+           output.println("       rentry=mlpCreateREntry(" + waitingElement.getStatus() + ", &(seseToIssue->common));");
+           output.println("       seseToIssue->common.rentryArray[seseToIssue->common.rentryIdx++]=rentry;");
+           output.println("       if(ADDRENTRY(runningSESE->memoryQueueArray["+ waitingElement.getQueueID()+ "],rentry)==READY) {");
+           output.println("          dispCount++;");
+           output.println("       }");
+         }
+         output.println("     if(!dispCount || !atomic_sub_and_test(dispCount,&(seseToIssue->rcrRecords["+i+"].flag)))");
+         output.println("       localCount++;");
+         if (fsen.getDynamicInVarSet().contains(td)) {
+           // dynamic in-var case
+           //output.println("       pointer=seseToIssue->" + waitingElement.getDynID()+ "_srcSESE+seseToIssue->"+ waitingElement.getDynID()+ "_srcOffset;");
+           //output.println("       rentry=mlpCreateFineREntry("+ waitingElement.getStatus()+ ", &(seseToIssue->common),  pointer );");
+         }
+       }
+       output.println("    }");
+      }
+    }
+  }
+
+  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 ) {
+    if( ! (state.MLP || state.OOOJAVA) ) {
       return;
     }
 
@@ -3507,7 +4340,9 @@ public class BuildCode {
     FlatSESEEnterNode fsen = fsexn.getFlatEnter();
 
     // there may be an SESE in an unreachable method, skip over
-    if( !mlpa.getAllSESEs().contains( fsen ) ) {
+    if( (state.MLP && !mlpa.getAllSESEs().contains( fsen ))  ||
+        (state.OOOJAVA && !oooa.getAllSESEs().contains( fsen ))
+    ) {
       return;
     }
 
@@ -3515,33 +4350,54 @@ public class BuildCode {
     if( fsen.getIsCallerSESEplaceholder() ) {
       return;
     }
+    
+    if( state.COREPROF ) {
+      output.println("#ifdef CP_EVENTID_TASKEXECUTE");
+      output.println("   CP_LOGEVENT( CP_EVENTID_TASKEXECUTE, CP_EVENTTYPE_END );");
+      output.println("#endif");
+    }
 
     output.println("   /* SESE exiting */");
 
-    String com = paramsprefix+"->common";
+    if( state.COREPROF ) {
+      output.println("#ifdef CP_EVENTID_TASKRETIRE");
+      output.println("   CP_LOGEVENT( CP_EVENTID_TASKRETIRE, CP_EVENTTYPE_BEGIN );");
+      output.println("#endif");
+    }
+    
 
     // 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("   pthread_mutex_lock( &(runningSESE->lock) );");
+    output.println("   if( runningSESE->numRunningChildren > 0 ) {");
+    output.println("     stopforgc( (struct garbagelist *)&___locals___ );");
+    output.println("     do {");
+    output.println("       pthread_cond_wait( &(runningSESE->runningChildrenCond), &(runningSESE->lock) );");
+    output.println("     } while( runningSESE->numRunningChildren > 0 );");
+    output.println("     restartaftergc();");
     output.println("   }");
 
+
     // copy out-set from local temps into the sese record
     Iterator<TempDescriptor> itr = fsen.getOutVarSet().iterator();
     while( itr.hasNext() ) {
       TempDescriptor temp = itr.next();
 
-      // only have to do this for primitives
-      if( !temp.getType().isPrimitive() ) {
+      // only have to do this for primitives non-arrays
+      if( !(
+            temp.getType().isPrimitive() && !temp.getType().isArray()
+           )
+        ) {
        continue;
       }
 
       // have to determine the context enclosing this sese
       boolean useParentContext = false;
 
-      if( fsen != mlpa.getMainSESE() ) {
+      if( (state.MLP &&fsen != mlpa.getMainSESE()) || 
+          (state.OOOJAVA &&fsen != oooa.getMainSESE())
+      ) {
        assert fsen.getParent() != null;
        if( !fsen.getParent().getIsCallerSESEplaceholder() ) {
          useParentContext = true;
@@ -3560,129 +4416,173 @@ public class BuildCode {
                     " = "+from+";");
     }    
     
-    // 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) );");
+    // mark yourself done, your task data is now read-only
+    output.println("   runningSESE->doneExecuting = TRUE;");
+
+    // if parent is stalling on you, let them know you're done
+    if( (state.MLP && fsexn.getFlatEnter() != mlpa.getMainSESE()) || 
+        (state.OOOJAVA &&  fsexn.getFlatEnter() != oooa.getMainSESE())    
+    ) {
+      output.println("   if( runningSESE->parentsStallSem != NULL ) {");
+      output.println("     psem_give( runningSESE->parentsStallSem );");
+      output.println("   }");
+    }
+
+    output.println("   pthread_mutex_unlock( &(runningSESE->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 ) {");
+
+    // FORWARD TODO
+    output.println("   while( !isEmpty( runningSESE->forwardList ) ) {");
+    output.println("     SESEcommon* consumer = (SESEcommon*) getItem( runningSESE->forwardList );");
+    
+   
+    output.println("     if(consumer->rentryIdx>0){");
+    output.println("        // resolved null pointer");
+    output.println("        int idx;");
+    output.println("        for(idx=0;idx<consumer->rentryIdx;idx++){");
+    output.println("           resolvePointer(consumer->rentryArray[idx]);");
+    output.println("        }");
+    output.println("     }");
+    
+    
+    output.println("     if( atomic_sub_and_test( 1, &(consumer->unresolvedDependencies) ) ){");
     output.println("       workScheduleSubmit( (void*)consumer );");
     output.println("     }");
-    output.println("     pthread_mutex_unlock( &(consumer->lock) );");
     output.println("   }");
     
+    
     // eom
     // clean up its lock element from waiting queue, and decrement dependency count for next SESE block
-    if( fsen != mlpa.getMainSESE() ) {
-       output.println();    
-        output.println("   /* check memory dependency*/");
-       output.println("  {");
-       output.println("   pthread_mutex_lock( &(___params___->common.parent->lock) );");
-       output.println("   int idx;");
-       output.println("   int giveCount=0;");
-       output.println("   for(idx = 0 ; idx < ___params___->common.parent->numRelatedAllocSites ; idx++){");
-       output.println("      if(!isEmpty(___params___->common.parent->allocSiteArray[idx].waitingQueue)){");
-       output.println("     SESEcommon* item=peekItem(___params___->common.parent->allocSiteArray[idx].waitingQueue);");
-       output.println("     if( item->classID == ___params___->common.classID ){");
-       output.println("        struct QueueItem* qItem=findItem(___params___->common.parent->allocSiteArray[idx].waitingQueue,item);");
-       output.println("        removeItem(___params___->common.parent->allocSiteArray[idx].waitingQueue,qItem);");
-       output.println("        if( !isEmpty(___params___->common.parent->allocSiteArray[idx].waitingQueue) ){");
-       output.println("           SESEcommon* nextItem=peekItem(___params___->common.parent->allocSiteArray[idx].waitingQueue);");
-       output.println("           if(nextItem->classID==___params___->common.parent->classID){");
-       output.println("              struct QueueItem* stallItem=findItem(___params___->common.parent->allocSiteArray[idx].waitingQueue,nextItem);");
-       output.println("              removeItem(___params___->common.parent->allocSiteArray[idx].waitingQueue,stallItem);");
-       output.println("              giveCount++;");
-       output.println("           }else{");
-       output.println("              pthread_mutex_lock( &(nextItem->lock) );");
-       output.println("              --(nextItem->unresolvedDependencies);");
-       output.println("              if( nextItem->unresolvedDependencies == 0){");
-       output.println("                 workScheduleSubmit( (void*)nextItem);");
-       output.println("              }");
-       output.println("              pthread_mutex_unlock( &(nextItem->lock) );");
-       output.println("           }");
-       output.println("        }");
-       output.println("     }");
-       output.println("     }");
-       output.println("  }");
-       output.println("  pthread_mutex_unlock( &(___params___->common.parent->lock)  );");
-       output.println("  if(giveCount>0){");
-       output.println("    psem_give(&(___params___->common.parent->memoryStallSiteSem));");
-       output.println("  }");
-       output.println("  }");
+    if( (state.MLP && fsen != mlpa.getMainSESE()) ||
+        (state.OOOJAVA && fsen != oooa.getMainSESE())
+    ) {
+       
+               output.println();
+               output.println("   /* check memory dependency*/");
+               output.println("  {");                  
+               output.println("      int idx;");
+               output.println("      for(idx=0;idx<___params___->common.rentryIdx;idx++){");
+               output.println("           REntry* re=___params___->common.rentryArray[idx];");
+               output.println("           RETIRERENTRY(re->queue,re);");
+               output.println("      }");
+               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;");    
+    output.println("   if( runningSESE->parent != NULL ) {");
+    output.println("     if( atomic_sub_and_test( 1, &(runningSESE->parent->numRunningChildren) ) ) {");
+    output.println("       pthread_mutex_lock  ( &(runningSESE->parent->lock) );");
+    output.println("       pthread_cond_signal ( &(runningSESE->parent->runningChildrenCond) );");
+    output.println("       pthread_mutex_unlock( &(runningSESE->parent->lock) );");
+    output.println("     }");
+    output.println("   }");
+
+    // a task has variables to track static/dynamic instances
+    // that serve as sources, release the parent's ref of each
+    // non-null var of these types
+    output.println("   // releasing static SESEs");
+    output.println("#ifndef OOO_DISABLE_TASKMEMPOOL" );
+    Iterator<SESEandAgePair> pItr = fsen.getNeededStaticNames().iterator();
+    while( pItr.hasNext() ) {
+      SESEandAgePair pair = pItr.next();
+      output.println("   if( "+pair+" != NULL ) {");
+      output.println("     RELEASE_REFERENCE_TO( "+pair+" );");
+      output.println("   }");
+    }
+    output.println("   // releasing dynamic variable sources");
+    Iterator<TempDescriptor> dynSrcItr = fsen.getDynamicVarSet().iterator();
+    while( dynSrcItr.hasNext() ) {
+      TempDescriptor dynSrcVar = dynSrcItr.next();
+      output.println("   if( "+dynSrcVar+"_srcSESE != NULL ) {");
+      output.println("     RELEASE_REFERENCE_TO( "+dynSrcVar+"_srcSESE );");
+      output.println("   }");
+    }    
+    // destroy this task's mempool if it is not a leaf task
+    if( !fsen.getIsLeafSESE() ) {
+      output.println("     pooldestroy( runningSESE->taskRecordMemPool );");
+    }
+    output.println("#endif // OOO_DISABLE_TASKMEMPOOL" );
+
+
+    // if this is not the Main sese (which has no parent) then return
+    // THIS task's record to the PARENT'S task record pool, and only if
+    // the reference count is now zero
+    if( (state.MLP     && fsen != mlpa.getMainSESE()) || 
+        (state.OOOJAVA && fsen != oooa.getMainSESE())
+        ) {
+      output.println("#ifndef OOO_DISABLE_TASKMEMPOOL" );
+      output.println("   RELEASE_REFERENCE_TO( runningSESE );");
+      output.println("#endif // OOO_DISABLE_TASKMEMPOOL" );
+    } else {
+      // the main task has no parent, just free its record
+      output.println("   mlpFreeSESErecord( runningSESE );");
+    }
     
-  }
+    // as this thread is wrapping up the task, make sure the thread-local var
+    // for the currently running task record references an invalid task
+    output.println("   runningSESE = (SESEcommon*) 0x1;");
 
+    if( state.COREPROF ) {
+      output.println("#ifdef CP_EVENTID_TASKRETIRE");
+      output.println("   CP_LOGEVENT( CP_EVENTID_TASKRETIRE, CP_EVENTTYPE_END );");
+      output.println("#endif");
+    }
+  }
   public void generateFlatWriteDynamicVarNode( FlatMethod fm,  
                                               LocalityBinding lb, 
                                               FlatWriteDynamicVarNode fwdvn,
                                               PrintWriter output
                                             ) {
-    if( !state.MLP ) {
+    if( !(state.MLP || state.OOOJAVA) ) {
       // 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();
+    Hashtable<TempDescriptor, VSTWrapper> 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() );      
+      Map.Entry           me     = (Map.Entry)      wdItr.next();
+      TempDescriptor      refVar = (TempDescriptor) me.getKey();
+      VSTWrapper          vstW   = (VSTWrapper)     me.getValue();
+      VariableSourceToken vst    =                  vstW.vst;
 
-      output.println("   {");
+      output.println("     {");
+      output.println("       SESEcommon* oldSrc = "+refVar+"_srcSESE;");
 
-      if( current.equals( vst.getSESE() ) ) {
-       // if the src comes from this SESE, it's a method local variable,
+      if( vst == null ) {
+       // if there is no given source, this variable is ready so
        // mark src pointer NULL to signify that the var is up-to-date
-       output.println("     "+vst.getAddrVar()+"_srcSESE = NULL;");
-
+       output.println("       "+refVar+"_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()+");");
-      }
+        // otherwise we track where it will come from
+        SESEandAgePair instance = new SESEandAgePair( vst.getSESE(), vst.getAge() );
+        output.println("       "+refVar+"_srcSESE = "+instance+";");    
+        output.println("       "+refVar+"_srcOffset = (INTPTR) &((("+
+                       vst.getSESE().getSESErecordName()+"*)0)->"+vst.getAddrVar()+");");
+      }
+
+      // no matter what we did above, track reference count of whatever
+      // this variable pointed to, do release last in case we're just
+      // copying the same value in because 1->2->1 is safe but ref count
+      // 1->0->1 has a window where it looks like it should be free'd
+      output.println("#ifndef OOO_DISABLE_TASKMEMPOOL" );
+      output.println("       if( "+refVar+"_srcSESE != NULL ) {");
+      output.println("         ADD_REFERENCE_TO( "+refVar+"_srcSESE );");
+      output.println("       }");
+      output.println("       if( oldSrc != NULL ) {");
+      output.println("         RELEASE_REFERENCE_TO( oldSrc );");
+      output.println("       }");
+      output.println("#endif // OOO_DISABLE_TASKMEMPOOL" );
 
-      output.println("   }");
+      output.println("     }");
     }  
   }
 
@@ -3713,13 +4613,43 @@ 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(lb!=null ? locality.getBinding(lb, fc) : md);
     ClassDescriptor cn=md.getClassDesc();
+    
+    // if the called method is a static block or a static method or a constructor
+    // need to check if it can be invoked inside some static block
+    if((md.isStatic() || md.isStaticBlock() || md.isConstructor()) && 
+        ((fm.getMethod().isStaticBlock()) || (fm.getMethod().isInvokedByStatic()))) {
+      if(!md.isInvokedByStatic()) {
+        System.err.println("Error: a method that is invoked inside a static block is not tagged!");
+      }
+      // is a static block or is invoked in some static block
+      ClassDescriptor cd = fm.getMethod().getClassDesc();
+      if(cd == cn) {
+        // the same class, do nothing
+        // TODO may want to invoke static field initialization here
+      } else {
+        if((cn.getNumStaticFields() != 0) || (cn.getNumStaticBlocks() != 0)) {
+          // need to check if the class' static fields have been initialized and/or
+          // its static blocks have been executed
+          output.println("#ifdef MGC_STATIC_INIT_CHECK");
+          output.println("if(global_defs_p->" + cn.getSafeSymbol()+"static_block_exe_flag == 0) {");
+          if(cn.getNumStaticFields() != 0) {
+            // TODO add static field initialization here
+          }
+          if(cn.getNumStaticBlocks() != 0) {
+            MethodDescriptor t_md = (MethodDescriptor)cn.getMethodTable().get("staticblocks");
+            output.println("  "+cn.getSafeSymbol()+t_md.getSafeSymbol()+"_"+t_md.getSafeMethodDescriptor()+"();");
+          } else {
+            output.println("  global_defs_p->" + cn.getSafeSymbol()+"static_block_exe_flag = 1;");
+          }
+          output.println("}");
+          output.println("#endif // MGC_STATIC_INIT_CHECK"); 
+        }
+      }
+    }
+    
     output.println("{");
     if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
       if (lb!=null) {
@@ -3727,7 +4657,6 @@ public class BuildCode {
        output.print("       struct "+cn.getSafeSymbol()+fclb.getSignature()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={");
       } else
        output.print("       struct "+cn.getSafeSymbol()+md.getSafeSymbol()+"_"+md.getSafeMethodDescriptor()+"_params __parameterlist__={");
-
       output.print(objectparams.numPointers());
       output.print(", "+localsprefixaddr);
       if (md.getThis()!=null) {
@@ -3817,7 +4746,12 @@ public class BuildCode {
 
     if (!GENERATEPRECISEGC && !this.state.MULTICOREGC) {
       if (fc.getThis()!=null) {
-       TypeDescriptor ptd=md.getThis().getType();
+       TypeDescriptor ptd=null;
+    if(md.getThis() != null) {
+      ptd = md.getThis().getType();
+    } else {
+      ptd = fc.getThis().getType();
+    }
        if (needcomma)
          output.print(",");
        if (ptd.isClass()&&!ptd.isArray())
@@ -3934,8 +4868,51 @@ public class BuildCode {
        output.println(generateTemp(fm, ffn.getDst(),lb)+"="+ generateTemp(fm,ffn.getSrc(),lb)+"->"+ ffn.getField().getSafeSymbol()+";");
       } else
        throw new Error("Read from non-global/non-local in:"+lb.getExplanation());
-    } else
-      output.println(generateTemp(fm, ffn.getDst(),lb)+"="+ generateTemp(fm,ffn.getSrc(),lb)+"->"+ ffn.getField().getSafeSymbol()+";");
+    } else{
+// DEBUG       if(!ffn.getDst().getType().isPrimitive()){
+// DEBUG               output.println("within((void*)"+generateTemp(fm,ffn.getSrc(),lb)+"->"+ ffn.getField().getSafeSymbol()+");");
+// DEBUG       } 
+      if(ffn.getField().isStatic()) {
+        // static field
+        if((fm.getMethod().isStaticBlock()) || (fm.getMethod().isInvokedByStatic())) {
+          // is a static block or is invoked in some static block
+          ClassDescriptor cd = fm.getMethod().getClassDesc();
+          ClassDescriptor cn = ffn.getSrc().getType().getClassDesc();
+          if(cd == cn) {
+            // the same class, do nothing
+            // TODO may want to invoke static field initialization here
+          } else {
+            if((cn.getNumStaticFields() != 0) || (cn.getNumStaticBlocks() != 0)) {
+              // need to check if the class' static fields have been initialized and/or
+              // its static blocks have been executed
+              output.println("#ifdef MGC_STATIC_INIT_CHECK");
+              output.println("if(global_defs_p->" + cn.getSafeSymbol()+"static_block_exe_flag == 0) {");
+              if(cn.getNumStaticFields() != 0) {
+                // TODO add static field initialization here
+              }
+              if(cn.getNumStaticBlocks() != 0) {
+                MethodDescriptor t_md = (MethodDescriptor)cn.getMethodTable().get("staticblocks");
+                output.println("  "+cn.getSafeSymbol()+t_md.getSafeSymbol()+"_"+t_md.getSafeMethodDescriptor()+"();");
+              } else {
+                output.println("  global_defs_p->" + cn.getSafeSymbol()+"static_block_exe_flag = 1;");
+              }
+              output.println("}");
+              output.println("#endif // MGC_STATIC_INIT_CHECK"); 
+            }
+          }
+        }
+        // redirect to the global_defs_p structure
+        if(ffn.getSrc().getType().isStatic()) {
+          // reference to the static field with Class name
+          output.println(generateTemp(fm, ffn.getDst(),lb)+"=global_defs_p->"+ ffn.getSrc().getType().getClassDesc().getSafeSymbol()+ffn.getField().getSafeSymbol()+";");
+        } else {
+          output.println(generateTemp(fm, ffn.getDst(),lb)+"=*"+ generateTemp(fm,ffn.getSrc(),lb)+"->"+ ffn.getField().getSafeSymbol()+";");
+        }
+        //output.println(generateTemp(fm, ffn.getDst(),lb)+"=global_defs_p->"+ffn.getSrc().getType().getClassDesc().getSafeSymbol()+"->"+ ffn.getField().getSafeSymbol()+";");
+      } else {
+        output.println(generateTemp(fm, ffn.getDst(),lb)+"="+ generateTemp(fm,ffn.getSrc(),lb)+"->"+ ffn.getField().getSafeSymbol()+";");
+      }
+    }
   }
 
 
@@ -4032,7 +5009,49 @@ public class BuildCode {
        output.println(fcrevert+"=(struct ___Object___ *)"+dst+";");
        output.println("}");
       }
-      output.println(generateTemp(fm, fsfn.getDst(),lb)+"->"+ fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc(),lb)+";");
+      
+// DEBUG       if(!fsfn.getField().getType().isPrimitive()){
+// DEBUG               output.println("within((void*)"+generateTemp(fm,fsfn.getSrc(),lb)+");");
+// DEBUG   }  
+      if(fsfn.getField().isStatic()) {
+        // static field
+        if((fm.getMethod().isStaticBlock()) || (fm.getMethod().isInvokedByStatic())) {
+          // is a static block or is invoked in some static block
+          ClassDescriptor cd = fm.getMethod().getClassDesc();
+          ClassDescriptor cn = fsfn.getDst().getType().getClassDesc();
+          if(cd == cn) {
+            // the same class, do nothing
+            // TODO may want to invoke static field initialization here
+          } else {
+            if((cn.getNumStaticFields() != 0) || (cn.getNumStaticBlocks() != 0)) {
+              // need to check if the class' static fields have been initialized and/or
+              // its static blocks have been executed
+              output.println("#ifdef MGC_STATIC_INIT_CHECK");
+              output.println("if(global_defs_p->" + cn.getSafeSymbol()+"static_block_exe_flag == 0) {");
+              if(cn.getNumStaticFields() != 0) {
+                // TODO add static field initialization here
+              }
+              if(cn.getNumStaticBlocks() != 0) {
+                MethodDescriptor t_md = (MethodDescriptor)cn.getMethodTable().get("staticblocks");
+                output.println("  "+cn.getSafeSymbol()+t_md.getSafeSymbol()+"_"+t_md.getSafeMethodDescriptor()+"();");
+              } else {
+                output.println("  global_defs_p->" + cn.getSafeSymbol()+"static_block_exe_flag = 1;");
+              }
+              output.println("}");
+              output.println("#endif // MGC_STATIC_INIT_CHECK"); 
+            }
+          }
+        }
+        // redirect to the global_defs_p structure
+        if(fsfn.getDst().getType().isStatic()) {
+          // reference to the static field with Class name
+          output.println("global_defs_p->" + fsfn.getDst().getType().getClassDesc().getSafeSymbol() + fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc(),lb)+";");
+        } else {
+          output.println("*"+generateTemp(fm, fsfn.getDst(),lb)+"->"+ fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc(),lb)+";");
+        }
+      } else {
+        output.println(generateTemp(fm, fsfn.getDst(),lb)+"->"+ fsfn.getField().getSafeSymbol()+"="+ generateTemp(fm,fsfn.getSrc(),lb)+";");
+      }
     }
   }
 
@@ -4093,7 +5112,8 @@ public class BuildCode {
       } else
        throw new Error("Read from non-global/non-local in:"+lb.getExplanation());
     } else {
-      output.println(generateTemp(fm, fen.getDst(),lb)+"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex(),lb)+"];");
+// DEBUG output.println("within((void*)"+generateTemp(fm,fen.getSrc(),lb)+");");
+        output.println(generateTemp(fm, fen.getDst(),lb)+"=(("+ type+"*)(((char *) &("+ generateTemp(fm,fen.getSrc(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fen.getIndex(),lb)+"];");
     }
   }
 
@@ -4195,6 +5215,7 @@ public class BuildCode {
        output.println(fcrevert+"=(struct ___Object___ *)"+dst+";");
        output.println("}");
       }
+// DEBUG      output.println("within((void*)"+generateTemp(fm,fsen.getDst(),lb)+");");
       output.println("(("+type +"*)(((char *) &("+ generateTemp(fm,fsen.getDst(),lb)+"->___length___))+sizeof(int)))["+generateTemp(fm, fsen.getIndex(),lb)+"]="+generateTemp(fm,fsen.getSrc(),lb)+";");
     }
   }
@@ -4229,7 +5250,12 @@ public class BuildCode {
       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) || (this.state.MULTICOREGC)) {
-       output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarray("+localsprefixaddr+", "+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+");");
+         if(this.state.MLP || state.OOOJAVA){
+            output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newarray_mlp("+localsprefixaddr+", "+arrayid+", "+generateTemp(fm, fn.getSize(),lb)+", oid, "+oooa.getDisjointAnalysis().getAllocationSiteFromFlatNew(fn).getUniqueAllocSiteID()+");");
+       output.println("    oid += numWorkers;");
+         }else{
+    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)+");");
       }
@@ -4237,7 +5263,12 @@ public class BuildCode {
       if (fn.isGlobal()&&(state.DSM||state.SINGLETM)) {
        output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_newglobal("+fn.getType().getClassDesc().getId()+");");
       } else if ((GENERATEPRECISEGC) || (this.state.MULTICOREGC)) {
-       output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_new("+localsprefixaddr+", "+fn.getType().getClassDesc().getId()+");");
+         if (this.state.MLP || state.OOOJAVA){
+       output.println(generateTemp(fm,fn.getDst(),lb)+"=allocate_new_mlp("+localsprefixaddr+", "+fn.getType().getClassDesc().getId()+", oid, "+oooa.getDisjointAnalysis().getAllocationSiteFromFlatNew(fn).getUniqueAllocSiteID()+");");
+       output.println("    oid += numWorkers;");
+         } else {
+    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()+");");
       }
@@ -4350,6 +5381,11 @@ public class BuildCode {
   }
 
   protected void generateFlatReturnNode(FlatMethod fm, LocalityBinding lb, FlatReturnNode frn, PrintWriter output) {
+    if((fm.getMethod() != null) && (fm.getMethod().isStaticBlock())) {
+      // a static block, check if it has been executed
+      output.println("  global_defs_p->" + fm.getMethod().getClassDesc().getSafeSymbol()+"static_block_exe_flag = 1;");
+      output.println("");
+    }
     if (frn.getReturnTemp()!=null) {
       if (frn.getReturnTemp().getType().isPtr())
        output.println("return (struct "+fm.getMethod().getReturnType().getSafeSymbol()+"*)"+generateTemp(fm, frn.getReturnTemp(), lb)+";");
@@ -4984,6 +6020,72 @@ public class BuildCode {
 
   protected void outputTransCode(PrintWriter output) {
   }
+  
+  private int calculateSizeOfSESEParamList(FlatSESEEnterNode fsen){
+         
+         Set<TempDescriptor> tdSet=new HashSet<TempDescriptor>();
+         
+         for (Iterator iterator = fsen.getInVarSet().iterator(); iterator.hasNext();) {
+               TempDescriptor tempDescriptor = (TempDescriptor) iterator.next();
+               if(!tempDescriptor.getType().isPrimitive() || tempDescriptor.getType().isArray()){
+                       tdSet.add(tempDescriptor);
+               }       
+         }
+         
+         for (Iterator iterator = fsen.getOutVarSet().iterator(); iterator.hasNext();) {
+                       TempDescriptor tempDescriptor = (TempDescriptor) iterator.next();
+                       if(!tempDescriptor.getType().isPrimitive() || tempDescriptor.getType().isArray()){
+                               tdSet.add(tempDescriptor);
+                       }       
+         }       
+                 
+         return tdSet.size();
+  }
+  
+  private String calculateSizeOfSESEParamSize(FlatSESEEnterNode fsen){
+    HashMap <String,Integer> map=new HashMap();
+    HashSet <TempDescriptor> processed=new HashSet<TempDescriptor>();
+    String rtr="";
+         
+    // 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 );
+      }
+    }
+           
+    Iterator<TempDescriptor> itrPrims = inSetAndOutSetPrims.iterator();
+    while( itrPrims.hasNext() ) {
+      TempDescriptor temp = itrPrims.next();
+      TypeDescriptor type = temp.getType();
+      if(type.isPrimitive()){
+        Integer count=map.get(type.getSymbol());
+        if(count==null){
+          count=new Integer(1);
+          map.put(type.getSymbol(), count);
+        }else{
+          map.put(type.getSymbol(), new Integer(count.intValue()+1));
+        }
+      }      
+    }
+         
+    Set<String> keySet=map.keySet();
+    for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
+      String key = (String) iterator.next();
+      rtr+="+sizeof("+key+")*"+map.get(key);
+    }
+    return  rtr;
+  }
+
 }