changes to analysis..
authorbdemsky <bdemsky>
Tue, 16 Jun 2009 22:08:00 +0000 (22:08 +0000)
committerbdemsky <bdemsky>
Tue, 16 Jun 2009 22:08:00 +0000 (22:08 +0000)
Robust/src/Analysis/Locality/DelayComputation.java

index 5a8fe1ae03679fa6af36f16e5af230901a7407ea..211f6659220a178e3e93dc89082754adf34dd4e9 100644 (file)
@@ -15,12 +15,14 @@ public class DelayComputation {
   LocalityAnalysis locality;
   TypeAnalysis typeanalysis;
   GlobalFieldType gft;
   LocalityAnalysis locality;
   TypeAnalysis typeanalysis;
   GlobalFieldType gft;
+  DiscoverConflicts dcopts;
 
 
-  public DelayComputation(LocalityAnalysis locality, State state, TypeAnalysis typeanalysis, GlobalFieldType gft) {
+  public DelayComputation(LocalityAnalysis locality, State state, TypeAnalysis typeanalysis, GlobalFieldType gft, DiscoverConflicts dcopts) {
     this.locality=locality;
     this.state=state;
     this.typeanalysis=typeanalysis;
     this.gft=gft;
     this.locality=locality;
     this.state=state;
     this.typeanalysis=typeanalysis;
     this.gft=gft;
+    this.dcopts=dcopts;
   }
 
   public void doAnalysis() {
   }
 
   public void doAnalysis() {
@@ -33,6 +35,7 @@ public class DelayComputation {
   public void analyzeMethod(LocalityBinding lb) {
     MethodDescriptor md=lb.getMethod();
     FlatMethod fm=state.getMethodFlat(md);
   public void analyzeMethod(LocalityBinding lb) {
     MethodDescriptor md=lb.getMethod();
     FlatMethod fm=state.getMethodFlat(md);
+    System.out.println("Analyzing "+md);
     HashSet<FlatNode> cannotdelay=new HashSet<FlatNode>();
     Hashtable<FlatNode, Integer> atomictable=locality.getAtomic(lb);
     if (lb.isAtomic()) {
     HashSet<FlatNode> cannotdelay=new HashSet<FlatNode>();
     Hashtable<FlatNode, Integer> atomictable=locality.getAtomic(lb);
     if (lb.isAtomic()) {
@@ -179,7 +182,31 @@ public class DelayComputation {
        /* Do we read from arrays */
        if (fn.kind()==FKind.FlatElementNode) {
          //have to do expansion
        /* Do we read from arrays */
        if (fn.kind()==FKind.FlatElementNode) {
          //have to do expansion
-         nodelayarrayrdset.addAll(typeanalysis.expand(((FlatSetElementNode)fn).getSrc().getType()));     
+         nodelayarrayrdset.addAll(typeanalysis.expand(((FlatElementNode)fn).getSrc().getType()));        
+       }
+      } else {
+       //Need to know which objects to lock on
+       switch(fn.kind()) {
+       case FKind.FlatSetFieldNode: {
+         FlatSetFieldNode fsfn=(FlatSetFieldNode)fn;
+         nodelaytempset.add(fsfn.getDst());
+         break;
+       }
+       case FKind.FlatSetElementNode: {
+         FlatSetElementNode fsen=(FlatSetElementNode)fn;
+         nodelaytempset.add(fsen.getDst());
+         break;
+       }
+       case FKind.FlatFieldNode: {
+         FlatFieldNode ffn=(FlatFieldNode)fn;
+         nodelaytempset.add(ffn.getSrc());
+         break;
+       }
+       case FKind.FlatElementNode: {
+         FlatElementNode fen=(FlatElementNode)fn;
+         nodelaytempset.add(fen.getSrc());
+         break;
+       }
        }
       }
       
        }
       }
       
@@ -222,7 +249,106 @@ public class DelayComputation {
       if (changed)
        for(int i=0;i<fn.numPrev();i++)
          toanalyze.add(fn.getPrev(i));
       if (changed)
        for(int i=0;i<fn.numPrev();i++)
          toanalyze.add(fn.getPrev(i));
-    } //end of while loop
+    }//end of while loop
+    HashSet<FlatNode> notreadyset=computeNotReadySet(lb, cannotdelay);
+    HashSet<FlatNode> atomicset=new HashSet<FlatNode>();
+    for(Iterator<FlatNode> fnit=fm.getNodeSet().iterator();fnit.hasNext();) {
+      FlatNode fn=fnit.next();
+      boolean isatomic=atomictable.get(fn).intValue()>0;
+      if (isatomic)
+       atomicset.add(fn);
+    }
+    atomicset.removeAll(notreadyset);
+    atomicset.removeAll(cannotdelay);
+    System.out.println("-----------------------------------------------------");
+    System.out.println(md);
+    System.out.println("Cannot delay set:"+cannotdelay);
+    System.out.println("Not ready set:"+notreadyset);
+    System.out.println("Other:"+atomicset);
+    
 
 
+    //We now have:
+    //(1) Cannot delay set -- stuff that must be done before commit
+    //(2) Not ready set -- stuff that must wait until commit
+    //(3) everything else -- stuff that should be done before commit
   } //end of method
   } //end of method
+
+  public HashSet<FlatNode> computeNotReadySet(LocalityBinding lb, HashSet<FlatNode> cannotdelay) {
+    //You are in not ready set if:
+    //I. You read a not ready temp
+
+    //II. You read a field or element and both (A) you are not in the
+    //cannot delay set and (B) you do a transactional access to object
+    MethodDescriptor md=lb.getMethod();
+    FlatMethod fm=state.getMethodFlat(md);
+    Hashtable<FlatNode, Integer> atomictable=locality.getAtomic(lb);
+
+    HashSet<FlatNode> notreadynodes=new HashSet<FlatNode>();
+    HashSet<FlatNode> toanalyze=new HashSet<FlatNode>();
+    toanalyze.addAll(fm.getNodeSet());
+    Hashtable<FlatNode, HashSet<TempDescriptor>> notreadymap=new Hashtable<FlatNode, HashSet<TempDescriptor>>();
+    
+    while(!toanalyze.isEmpty()) {
+      FlatNode fn=toanalyze.iterator().next();
+      toanalyze.remove(fn);
+      boolean isatomic=atomictable.get(fn).intValue()>0;
+
+      if (!isatomic)
+       continue;
+
+      //Compute initial notready set
+      HashSet<TempDescriptor> notreadyset=new HashSet<TempDescriptor>();
+      for(int i=0;i<fn.numPrev();i++) {
+       if (notreadymap.containsKey(fn.getPrev(i)))
+         notreadyset.addAll(notreadymap.get(fn.getPrev(i)));
+      }
+      
+      //Are we ready
+      boolean notready=false;
+
+      //Test our read set first
+      TempDescriptor readset[]=fn.readsTemps();
+      for(int i=0;i<readset.length;i++) {
+       TempDescriptor tmp=readset[i];
+       if (notreadyset.contains(tmp)) {
+         notready=true;
+         break;
+       }
+      }
+
+      if (!notready&&!cannotdelay.contains(fn)&&
+         (fn.kind()==FKind.FlatFieldNode||fn.kind()==FKind.FlatElementNode)&&
+         dcopts.getNeedTrans(lb, fn)) {
+       notready=true;
+      }
+
+      //Fix up things based on our status
+      if (notready) {
+       //add us to the list
+       notreadynodes.add(fn);
+       //Add our writes
+       TempDescriptor writeset[]=fn.writesTemps();
+       for(int i=0;i<writeset.length;i++) {
+         TempDescriptor tmp=writeset[i];
+         notreadyset.add(tmp);
+       }
+      } else {
+       //Kill our writes
+       TempDescriptor writeset[]=fn.writesTemps();
+       for(int i=0;i<writeset.length;i++) {
+         TempDescriptor tmp=writeset[i];
+         notreadyset.remove(tmp);
+       }
+      }
+      
+      //See if we need to propagate changes
+      if (!notreadymap.containsKey(fn)||
+         !notreadymap.get(fn).equals(notreadyset)) {
+       notreadymap.put(fn, notreadyset);
+       for(int i=0;i<fn.numNext();i++)
+         toanalyze.add(fn.getNext(i));
+      }
+    } //end of while
+    return notreadynodes;
+  } //end of computeNotReadySet
 } //end of class
\ No newline at end of file
 } //end of class
\ No newline at end of file