cache lots of results instead of recomputing them
authorbdemsky <bdemsky>
Tue, 24 Mar 2009 04:37:13 +0000 (04:37 +0000)
committerbdemsky <bdemsky>
Tue, 24 Mar 2009 04:37:13 +0000 (04:37 +0000)
Robust/src/Analysis/OwnershipAnalysis/Canonical.java
Robust/src/Analysis/OwnershipAnalysis/CanonicalWrapper.java [new file with mode: 0644]
Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java
Robust/src/Analysis/OwnershipAnalysis/ReachOperation.java [new file with mode: 0644]
Robust/src/Analysis/OwnershipAnalysis/ReachabilitySet.java
Robust/src/Analysis/OwnershipAnalysis/TokenTupleSet.java

index c4e2a09a15df6d36b9be8f181bc60d0fa3316f82..0d5d64228cd241e5a340869a9289bdf3201e90d5 100644 (file)
@@ -9,12 +9,20 @@ public class Canonical {
 
   private static Hashtable<Canonical, Canonical> canon = new Hashtable<Canonical, Canonical>();
 
+  int canonicalvalue;
+    private static int canonicalcount=1;
+
   public static Canonical makeCanonical(Canonical c) {
+
     if( canon.containsKey(c) ) {
       return canon.get(c);
     }
-
+    c.canonicalvalue=canonicalcount++;
     canon.put(c, c);
     return c;
   }
-}
+
+    static Hashtable<ReachOperation, ReachOperation> unionhash=new Hashtable<ReachOperation, ReachOperation>();
+    static Hashtable<ReachOperation, ReachOperation> interhash=new Hashtable<ReachOperation, ReachOperation>();
+    static Hashtable<CanonicalWrapper, CanonicalWrapper> lookuphash=new Hashtable<CanonicalWrapper, CanonicalWrapper>();
+}
\ No newline at end of file
diff --git a/Robust/src/Analysis/OwnershipAnalysis/CanonicalWrapper.java b/Robust/src/Analysis/OwnershipAnalysis/CanonicalWrapper.java
new file mode 100644 (file)
index 0000000..0398b87
--- /dev/null
@@ -0,0 +1,18 @@
+package Analysis.OwnershipAnalysis;
+
+public class CanonicalWrapper {
+    Canonical a;
+    public Canonical b;
+    
+    public CanonicalWrapper(Canonical a) {
+       assert a.canonicalvalue!=0;
+       this.a=a;
+    }
+    public int hashCode() {
+       return a.canonicalvalue;
+    }
+    public boolean equals(Object o) {
+       CanonicalWrapper ro=(CanonicalWrapper)o;
+       return ro.a.canonicalvalue==a.canonicalvalue;
+    }
+}
\ No newline at end of file
index dca6db518b136796c426edf04414f62be60c9289..96d20cc3cca2f4280eb935436c61c6a4d47934ef 100644 (file)
@@ -651,10 +651,10 @@ public class OwnershipGraph {
     ReachabilitySet betaSoup;
     if( createSecondaryRegion ) {
       TokenTupleSet tts1 = new TokenTupleSet( ttSecondary ).makeCanonical();
-      TokenTupleSet tts2 = new TokenTupleSet( ttPrimary   ).union( ttSecondary );   
-      betaSoup = new ReachabilitySet().union( tts0 ).union( tts1 ).union( tts2 );
+      TokenTupleSet tts2 = new TokenTupleSet( ttPrimary   ).makeCanonical().union( ttSecondary );   
+      betaSoup = ReachabilitySet.factory( tts0 ).union( tts1 ).union( tts2 );
     } else {
-      betaSoup = new ReachabilitySet().union( tts0 );
+      betaSoup = ReachabilitySet.factory( tts0 );
     }
 
     ReferenceEdge edgeFromLabel =
@@ -838,8 +838,8 @@ public class OwnershipGraph {
     
     TokenTupleSet tts0 = new TokenTupleSet( ttPrimary ).makeCanonical();
     TokenTupleSet tts1 = new TokenTupleSet( ttAliased ).makeCanonical();
-    TokenTupleSet tts2 = new TokenTupleSet( ttPrimary ).union( ttAliased );   
-    ReachabilitySet betaSoup = new ReachabilitySet().union( tts0 ).union( tts1 ).union( tts2 );
+    TokenTupleSet tts2 = new TokenTupleSet( ttPrimary ).makeCanonical().union( ttAliased );   
+    ReachabilitySet betaSoup = ReachabilitySet.factory( tts0 ).union( tts1 ).union( tts2 );
 
 
     ReferenceEdge edgeFromLabel =
@@ -916,8 +916,8 @@ public class OwnershipGraph {
       
       TokenTupleSet ttsI  = new TokenTupleSet( ttPrimaryI ).makeCanonical();
       TokenTupleSet ttsA  = new TokenTupleSet( ttAliased  ).makeCanonical();
-      TokenTupleSet ttsIA = new TokenTupleSet( ttPrimaryI ).union( ttAliased );   
-      ReachabilitySet betaSoup = new ReachabilitySet().union( ttsI ).union( ttsA ).union( ttsIA );
+      TokenTupleSet ttsIA = new TokenTupleSet( ttPrimaryI ).makeCanonical().union( ttAliased );   
+      ReachabilitySet betaSoup = ReachabilitySet.factory( ttsI ).union( ttsA ).union( ttsIA );
 
 
       // calculate whether fields of this aliased parameter are able to
@@ -1026,7 +1026,7 @@ public class OwnershipGraph {
            TokenTupleSet ttsIJ  = ttsI.union( ttsJ );
            TokenTupleSet ttsAJ  = ttsA.union( ttsJ );
            TokenTupleSet ttsIAJ = ttsIA.union( ttsJ );
-           ReachabilitySet betaSoupWJ = new ReachabilitySet().union( ttsJ ).union( ttsIJ ).union( ttsAJ ).union( ttsIAJ );
+           ReachabilitySet betaSoupWJ = ReachabilitySet.factory( ttsJ ).union( ttsIJ ).union( ttsAJ ).union( ttsIAJ );
 
            ReferenceEdge edgePrimaryI2PrimaryJ =
              new ReferenceEdge( primaryI,       // src
@@ -4047,14 +4047,14 @@ public class OwnershipGraph {
                                        TokenTuple.ARITY_ZEROORMORE).makeCanonical();
 
     // then get the merged beta of all out-going edges from these heap regions
-    ReachabilitySet beta1 = new ReachabilitySet();
+    ReachabilitySet beta1 = new ReachabilitySet().makeCanonical();
     Iterator<ReferenceEdge> itrEdge = hrn1.iteratorToReferencees();
     while( itrEdge.hasNext() ) {
       ReferenceEdge edge = itrEdge.next();
       beta1 = beta1.union( edge.getBeta() );
     }
 
-    ReachabilitySet beta2 = new ReachabilitySet();
+    ReachabilitySet beta2 = new ReachabilitySet().makeCanonical();
     itrEdge = hrn2.iteratorToReferencees();
     while( itrEdge.hasNext() ) {
       ReferenceEdge edge = itrEdge.next();
diff --git a/Robust/src/Analysis/OwnershipAnalysis/ReachOperation.java b/Robust/src/Analysis/OwnershipAnalysis/ReachOperation.java
new file mode 100644 (file)
index 0000000..3f78256
--- /dev/null
@@ -0,0 +1,23 @@
+package Analysis.OwnershipAnalysis;
+
+public class ReachOperation {
+    Canonical a;
+    Canonical b;
+    public Canonical c;
+
+    public ReachOperation(Canonical a, Canonical b) {
+       assert a.canonicalvalue!=0;
+       assert b.canonicalvalue!=0;
+       this.a=a;
+       this.b=b;
+    }
+    
+    public int hashCode() {
+       return a.canonicalvalue^(b.canonicalvalue<<1);
+    }
+    public boolean equals(Object o) {
+       ReachOperation ro=(ReachOperation)o;
+       return ro.a.canonicalvalue==a.canonicalvalue&&
+           ro.b.canonicalvalue==b.canonicalvalue;
+    }
+}
\ No newline at end of file
index 03c56c080c5dcee3b6fbfa2c628ee8d9be84e689..acee806800aff4793f8ab251e6038074be93cca4 100644 (file)
@@ -119,14 +119,28 @@ public class ReachabilitySet extends Canonical {
     return false;
   }
 
-    private static Hashtable<ReachOperation, ReachOperation> unionhash=new Hashtable<ReachOperation, ReachOperation>();
-    private static Hashtable<ReachOperation, ReachOperation> interhash=new Hashtable<ReachOperation, ReachOperation>();
+    public static ReachabilitySet factory(TokenTupleSet tts) {
+      CanonicalWrapper cw=new CanonicalWrapper(tts);
+      if (lookuphash.containsKey(cw))
+         return (ReachabilitySet)lookuphash.get(cw).b;
+      ReachabilitySet rs=new ReachabilitySet(tts);
+      rs=rs.makeCanonical();
+      cw.b=rs;
+      lookuphash.put(cw,cw);
+      return rs;
+  }
 
     public ReachabilitySet union(TokenTupleSet ttsIn) {
-       assert ttsIn != null;
-       ReachabilitySet rsOut = new ReachabilitySet(this);
-       rsOut.possibleReachabilities.add(ttsIn);
-       return rsOut.makeCanonical();
+       ReachOperation ro=new ReachOperation(this, ttsIn);
+       if (unionhash.containsKey(ro)) {
+           return (ReachabilitySet) unionhash.get(ro).c;
+       } else {
+           ReachabilitySet rsOut = new ReachabilitySet(this);
+           rsOut.possibleReachabilities.add(ttsIn);
+           ro.c=rsOut=rsOut.makeCanonical();
+           unionhash.put(ro,ro);
+           return rsOut;
+       }
     }
 
 
@@ -138,13 +152,13 @@ public class ReachabilitySet extends Canonical {
 
     ReachOperation ro=new ReachOperation(this, rsIn);
     if (unionhash.containsKey(ro))
-       return unionhash.get(ro).c;
+       return (ReachabilitySet) unionhash.get(ro).c;
     else {
        ReachabilitySet rsOut = new ReachabilitySet(this);
        rsOut.possibleReachabilities.addAll(rsIn.possibleReachabilities);
-       ro.c=rsOut.makeCanonical();
+       ro.c=rsOut=rsOut.makeCanonical();
        unionhash.put(ro, ro);
-       return ro.c;
+       return rsOut;
     }
   }
 
@@ -156,7 +170,7 @@ public class ReachabilitySet extends Canonical {
 
     ReachOperation ro=new ReachOperation(this, rsIn);
     if (interhash.containsKey(ro))
-       return interhash.get(ro).c;
+       return (ReachabilitySet) interhash.get(ro).c;
     else {
        ReachabilitySet rsOut = new ReachabilitySet();
        Iterator i = this.iterator();
@@ -166,9 +180,9 @@ public class ReachabilitySet extends Canonical {
                rsOut.possibleReachabilities.add(tts);
            }
        }
-       ro.c=rsOut.makeCanonical();
+       ro.c=rsOut=rsOut.makeCanonical();
        interhash.put(ro,ro);
-       return ro.c;
+       return rsOut;
     }
   }
 
@@ -257,9 +271,9 @@ public class ReachabilitySet extends Canonical {
          TokenTuple ttO = o.containsToken(ttR.getToken() );
 
          if( ttO != null ) {
-           theUnion = theUnion.union(new TokenTupleSet(ttR.unionArity(ttO) ) ).makeCanonical();
+             theUnion = theUnion.union((new TokenTupleSet(ttR.unionArity(ttO)).makeCanonical() ) );
          } else {
-           theUnion = theUnion.union(new TokenTupleSet(ttR) ).makeCanonical();
+             theUnion = theUnion.union((new TokenTupleSet(ttR)).makeCanonical() );
          }
        }
 
@@ -269,12 +283,12 @@ public class ReachabilitySet extends Canonical {
          TokenTuple ttR = theUnion.containsToken(ttO.getToken() );
 
          if( ttR == null ) {
-           theUnion = theUnion.union(new TokenTupleSet(ttO) ).makeCanonical();
+             theUnion = theUnion.union(new TokenTupleSet(ttO).makeCanonical() );
          }
        }
 
        if( !theUnion.isEmpty() ) {
-         ctsOut = ctsOut.union(new ChangeTupleSet(new ChangeTuple(o, theUnion) ) );
+           ctsOut = ctsOut.union((new ChangeTupleSet(new ChangeTuple(o, theUnion) )).makeCanonical() );
        }
       }
     }
@@ -358,7 +372,7 @@ public class ReachabilitySet extends Canonical {
 
 
   public ReachabilitySet exhaustiveArityCombinations() {
-    ReachabilitySet rsOut = new ReachabilitySet();
+      ReachabilitySet rsOut = (new ReachabilitySet()).makeCanonical();
 
     int numDimensions = this.possibleReachabilities.size();
 
@@ -472,22 +486,6 @@ public class ReachabilitySet extends Canonical {
     return s;
   }
 
-    private static Hashtable <Canonical, Canonical> can=new Hashtable<Canonical, Canonical>();
-
-    private static int canonicalcount=0;
-
-    int canonicalvalue;
-
-  public static Canonical makeCanonical(Canonical c) {
-      if (can.containsKey(c)) {
-         return can.get(c);
-      } else {
-         ((ReachabilitySet)c).canonicalvalue=canonicalcount++;
-         can.put(c,c);
-         return c;
-      }
-  }
-
   public String toString() {
     String s = "[";
 
@@ -503,23 +501,3 @@ public class ReachabilitySet extends Canonical {
     return s;
   }
 }
-
-
-class ReachOperation {
-    ReachabilitySet a;
-    ReachabilitySet b;
-    ReachabilitySet c;
-
-    ReachOperation(ReachabilitySet a, ReachabilitySet b) {
-       this.a=a;
-       this.b=b;
-    }
-    public int hashCode() {
-       return a.canonicalvalue^(b.canonicalvalue<<1);
-    }
-    public boolean equals(Object o) {
-       ReachOperation ro=(ReachOperation)o;
-       return ro.a.canonicalvalue==a.canonicalvalue&&
-           ro.b.canonicalvalue==b.canonicalvalue;
-    }
-}
\ No newline at end of file
index 3451c8e8737da3a928e9adb93df0cce97047a698..1b89d119b15a80fdf5f0427fb1b9bf0c42793f2f 100644 (file)
@@ -88,16 +88,30 @@ public class TokenTupleSet extends Canonical {
 
   public TokenTupleSet union(TokenTuple ttIn) {
     assert ttIn != null;
-    TokenTupleSet ttsOut = new TokenTupleSet(this);
-    ttsOut.tokenTuples.add(ttIn);
-    return ttsOut.makeCanonical();
+    ReachOperation ro=new ReachOperation(this, ttIn);
+    if (unionhash.containsKey(ro))
+       return (TokenTupleSet) unionhash.get(ro).c;
+    else {
+       TokenTupleSet ttsOut = new TokenTupleSet(this);
+       ttsOut.tokenTuples.add(ttIn);
+       ro.c=ttsOut=ttsOut.makeCanonical();
+       unionhash.put(ro,ro);
+       return ttsOut;
+    }
   }
 
   public TokenTupleSet union(TokenTupleSet ttsIn) {
     assert ttsIn != null;
-    TokenTupleSet ttsOut = new TokenTupleSet(this);
-    ttsOut.tokenTuples.addAll(ttsIn.tokenTuples);
-    return ttsOut.makeCanonical();
+    ReachOperation ro=new ReachOperation(this, ttsIn);
+    if (unionhash.containsKey(ro)) {
+       return (TokenTupleSet) unionhash.get(ro).c;
+    } else {
+       TokenTupleSet ttsOut = new TokenTupleSet(this);
+       ttsOut.tokenTuples.addAll(ttsIn.tokenTuples);
+       ro.c=ttsOut=ttsOut.makeCanonical();
+       unionhash.put(ro,ro);
+       return ttsOut;
+    }
   }
 
 
@@ -133,8 +147,7 @@ public class TokenTupleSet extends Canonical {
 
   public TokenTupleSet add(TokenTuple tt) {
     assert tt != null;
-    TokenTupleSet ttsOut = new TokenTupleSet(tt);
-    return ttsOut.union(this);
+    return this.union(tt);
   }