bringing analysis up to clean model, buildcode is left
[IRC.git] / Robust / src / IR / Flat / FlatSESEEnterNode.java
index cd0d17a1e9b68126c73b4a75cc2dd63350e0c20e..b087785dd00670fd219136d9c719594ada47c1d0 100644 (file)
@@ -1,12 +1,18 @@
 package IR.Flat;
-import Analysis.MLP.VariableSourceToken;
-import Analysis.MLP.VarSrcTokTable;
-import Analysis.MLP.SESEandAgePair;
-import IR.MethodDescriptor;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Set;
+import java.util.Vector;
+import java.util.Iterator;
+import java.util.Collection;
+import Analysis.OoOJava.VariableSourceToken;
+import Analysis.OoOJava.SESEandAgePair;
+import Analysis.OwnershipAnalysis.HeapRegionNode;
 import IR.ClassDescriptor;
+import IR.FieldDescriptor;
+import IR.MethodDescriptor;
 import IR.TypeDescriptor;
 import IR.Tree.SESENode;
-import java.util.*;
 
 public class FlatSESEEnterNode extends FlatNode {
   
@@ -17,24 +23,58 @@ public class FlatSESEEnterNode extends FlatNode {
   private   int               id;
   protected FlatSESEExitNode  exit;
   protected SESENode          treeNode;
-  protected FlatSESEEnterNode parent;
-  protected Integer           oldestAgeToTrack;
 
+  // a leaf tasks simply has no children, ever
+  protected static final int ISLEAF_UNINIT = 1;
+  protected static final int ISLEAF_FALSE  = 2;
+  protected static final int ISLEAF_TRUE   = 3;
+  protected int isLeafSESE;
+
+  // there is only one main sese that is implicit
+  // (spliced in by the compiler around whole program)
+  protected boolean isMainSESE;
+
+  // this is a useful static name for whichever task
+  // invoked the current local method context
+  protected boolean isCallerProxySESE;
+
+  // all children tasks, INCLUDING those that are reachable
+  // by calling methods
   protected Set<FlatSESEEnterNode> children;
-  protected Set<TempDescriptor>    inVars;
-  protected Set<TempDescriptor>    outVars;
+  
+  // all possible parents
+  protected Set<FlatSESEEnterNode> parents;
+
+  // sometimes it is useful to know the locally defined
+  // parent or children of an SESE for various analysis,
+  // and by local it is one SESE nested within another
+  // in a single method context
+  protected Set<FlatSESEEnterNode> localChildren;  
+  protected FlatSESEEnterNode localParent;
 
-  protected Set<SESEandAgePair>    needStaticNameInCode;
 
-  protected Set<SESEandAgePair>    staticInVarSrcs;
+  protected Set<TempDescriptor> inVars;
+  protected Set<TempDescriptor> outVars;
 
-  protected Set<TempDescriptor>    readyInVars;
-  protected Set<TempDescriptor>    staticInVars;
-  protected Set<TempDescriptor>    dynamicInVars;  
+  protected Set<TempDescriptor> readyInVars;
+  protected Set<TempDescriptor> staticInVars;
+  protected Set<TempDescriptor> dynamicInVars;  
+
+  protected Set<SESEandAgePair> staticInVarSrcs;
 
   protected Hashtable<TempDescriptor, VariableSourceToken> staticInVar2src;
+
+  // get the oldest age of this task that other contexts
+  // have a static name for when tracking variables
+  protected Integer oldestAgeToTrack;
   
 
+  // a subset of the in-set variables that shouuld be traversed during
+  // the dynamic coarse grained conflict strategy, remember them here so
+  // buildcode can be dumb and just gen the traversals
+  protected Vector<TempDescriptor> inVarsForDynamicCoarseConflictResolution;
+
+
   // scope info for this SESE
   protected FlatMethod       fmEnclosing;
   protected MethodDescriptor mdEnclosing;
@@ -45,23 +85,45 @@ public class FlatSESEEnterNode extends FlatNode {
   protected FlatMethod       fmBogus;
   protected MethodDescriptor mdBogus;
 
+  // used during code generation to calculate an offset
+  // into the SESE-specific record, specifically to the
+  // first field in a sequence of pointers to other SESE
+  // records which is relevant to garbage collection
+  protected String firstDepRecField;
+  protected int    numDepRecs;
+  
 
   public FlatSESEEnterNode( SESENode sn ) {
     this.id              = identifier++;
     treeNode             = sn;
-    parent               = null;
-    oldestAgeToTrack     = new Integer( 0 );
-
     children             = new HashSet<FlatSESEEnterNode>();
+    parents              = new HashSet<FlatSESEEnterNode>();
+    localChildren        = new HashSet<FlatSESEEnterNode>();
+    localParent          = null;
     inVars               = new HashSet<TempDescriptor>();
     outVars              = new HashSet<TempDescriptor>();
-    needStaticNameInCode = new HashSet<SESEandAgePair>();
-    staticInVarSrcs      = new HashSet<SESEandAgePair>();
     readyInVars          = new HashSet<TempDescriptor>();
     staticInVars         = new HashSet<TempDescriptor>();
     dynamicInVars        = new HashSet<TempDescriptor>();
+    staticInVarSrcs      = new HashSet<SESEandAgePair>();
+    oldestAgeToTrack     = new Integer( 0 );
 
     staticInVar2src = new Hashtable<TempDescriptor, VariableSourceToken>();
+
+    inVarsForDynamicCoarseConflictResolution = new Vector<TempDescriptor>();
+    
+    
+    fmEnclosing = null;
+    mdEnclosing = null;
+    cdEnclosing = null;
+
+    isLeafSESE = ISLEAF_UNINIT;
+
+    isMainSESE        = false;
+    isCallerProxySESE = false;
+
+    firstDepRecField = null;
+    numDepRecs       = 0;
   }
 
   public void rewriteUse() {
@@ -78,6 +140,22 @@ public class FlatSESEEnterNode extends FlatNode {
     return exit;
   }
 
+  public void setIsMainSESE() {
+    isMainSESE = true;
+  }
+
+  public boolean getIsMainSESE() {
+    return isMainSESE;
+  }
+
+  public void setIsCallerProxySESE() {
+    isCallerProxySESE = true;
+  }
+
+  public boolean getIsCallerProxySESE() {
+    return isCallerProxySESE;
+  }
+
   public int kind() {
     return FKind.FlatSESEEnterNode;
   }
@@ -90,8 +168,8 @@ public class FlatSESEEnterNode extends FlatNode {
     return id;
   }
 
-  public String getPrettyIdentifier() {    
-    if( treeNode.getID() != null ) {
+  public String getPrettyIdentifier() {
+    if( treeNode != null && treeNode.getID() != null ) {
       return treeNode.getID();
     }     
     return ""+id;
@@ -100,25 +178,64 @@ public class FlatSESEEnterNode extends FlatNode {
   public String toString() {
     return "sese "+getPrettyIdentifier()+" enter";
   }
+  
+  public String toPrettyString() {
+    return "sese "+getPrettyIdentifier()+getIdentifier();
+  }
+
+
+  public void mustTrackAtLeastAge( Integer age ) {
+    if( age > oldestAgeToTrack ) {
+      oldestAgeToTrack = new Integer( age );
+    }    
+  }
+
+  public Integer getOldestAgeToTrack() {
+    return oldestAgeToTrack;
+  }
+
+
+  public void addParent( FlatSESEEnterNode parent ) {
+    parents.add( parent );
+  }
+
+  public Set<FlatSESEEnterNode> getParents() {
+    return parents;
+  }
 
-  public void setParent( FlatSESEEnterNode parent ) {
-    this.parent = parent;
+  public void setLocalParent( FlatSESEEnterNode parent ) {
+    localParent = parent;
   }
 
-  public FlatSESEEnterNode getParent() {
-    return parent;
+  public FlatSESEEnterNode getLocalParent() {
+    return localParent;
   }
 
   public void addChild( FlatSESEEnterNode child ) {
     children.add( child );
   }
 
+  public void addChildren( Set<FlatSESEEnterNode> batch ) {
+    children.addAll( batch );
+  }
+
   public Set<FlatSESEEnterNode> getChildren() {
     return children;
   }
 
+  public void addLocalChild( FlatSESEEnterNode child ) {
+    localChildren.add( child );
+  }
+
+  public Set<FlatSESEEnterNode> getLocalChildren() {
+    return localChildren;
+  }
+
+
+
   public void addInVar( TempDescriptor td ) {
-    inVars.add( td );
+    if (!inVars.contains(td))
+      inVars.add( td );
   }
 
   public void addOutVar( TempDescriptor td ) {
@@ -126,7 +243,7 @@ public class FlatSESEEnterNode extends FlatNode {
   }
 
   public void addInVarSet( Set<TempDescriptor> s ) {
-    inVars.addAll( s );
+    inVars.addAll(s);
   }
 
   public void addOutVarSet( Set<TempDescriptor> s ) {
@@ -184,14 +301,6 @@ public class FlatSESEEnterNode extends FlatNode {
     return outVars;
   }
 
-  public void addNeededStaticName( SESEandAgePair p ) {
-    needStaticNameInCode.add( p );
-  }
-
-  public Set<SESEandAgePair> getNeededStaticNames() {
-    return needStaticNameInCode;
-  }
-
   public void addStaticInVarSrc( SESEandAgePair p ) {
     staticInVarSrcs.add( p );
   }
@@ -233,15 +342,6 @@ public class FlatSESEEnterNode extends FlatNode {
     return dynamicInVars;
   }
 
-  public void mustTrackAtLeastAge( Integer age ) {
-    if( age > oldestAgeToTrack ) {
-      oldestAgeToTrack = new Integer( age );
-    }    
-  }
-
-  public Integer getOldestAgeToTrack() {
-    return oldestAgeToTrack;
-  }
 
   public void setfmEnclosing( FlatMethod fm ) { fmEnclosing = fm; }
   public FlatMethod getfmEnclosing() { return fmEnclosing; }
@@ -281,4 +381,65 @@ public class FlatSESEEnterNode extends FlatNode {
       mdBogus.getSafeMethodDescriptor()+
       "_SESErec";
   }
+
+  public boolean equals( Object o ) {
+    if( o == null ) {
+      return false;
+    }
+
+    if( !(o instanceof FlatSESEEnterNode) ) {
+      return false;
+    }
+
+    FlatSESEEnterNode fsen = (FlatSESEEnterNode) o;
+    return id == fsen.id;
+  }
+
+  public int hashCode() {
+    return 31*id;
+  }
+  
+
+
+  public void setFirstDepRecField( String field ) {
+    firstDepRecField = field;
+  }
+
+  public String getFirstDepRecField() {
+    return firstDepRecField;
+  }
+
+  public void incNumDepRecs() {
+    ++numDepRecs;
+  }
+
+  public int getNumDepRecs() {
+    return numDepRecs;
+  }
+  
+  public Vector<TempDescriptor> getInVarsForDynamicCoarseConflictResolution() {
+    return inVarsForDynamicCoarseConflictResolution;
+  }
+  
+  public void addInVarForDynamicCoarseConflictResolution(TempDescriptor inVar) {
+    if (!inVarsForDynamicCoarseConflictResolution.contains(inVar))
+      inVarsForDynamicCoarseConflictResolution.add(inVar);
+  }
+  
+  public void setIsLeafSESE( boolean isLeaf ) {
+    if( isLeaf ) {
+      isLeafSESE = ISLEAF_TRUE;
+    } else {
+      isLeafSESE = ISLEAF_FALSE;
+    }
+  }
+
+  public boolean getIsLeafSESE() {
+    if( isLeafSESE == ISLEAF_UNINIT ) {
+      throw new Error( "isLeafSESE uninitialized" );
+    }
+
+    return isLeafSESE == ISLEAF_TRUE;
+  }
+
 }