From: bdemsky Date: Tue, 24 Mar 2009 04:37:13 +0000 (+0000) Subject: cache lots of results instead of recomputing them X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=3308c8872717b36aaa0082b1210a06d508876ddf;p=IRC.git cache lots of results instead of recomputing them --- diff --git a/Robust/src/Analysis/OwnershipAnalysis/Canonical.java b/Robust/src/Analysis/OwnershipAnalysis/Canonical.java index c4e2a09a..0d5d6422 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/Canonical.java +++ b/Robust/src/Analysis/OwnershipAnalysis/Canonical.java @@ -9,12 +9,20 @@ public class Canonical { private static Hashtable canon = new Hashtable(); + 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 unionhash=new Hashtable(); + static Hashtable interhash=new Hashtable(); + static Hashtable lookuphash=new Hashtable(); +} \ 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 index 00000000..0398b87c --- /dev/null +++ b/Robust/src/Analysis/OwnershipAnalysis/CanonicalWrapper.java @@ -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 diff --git a/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java b/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java index dca6db51..96d20cc3 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java +++ b/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java @@ -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 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 index 00000000..3f782562 --- /dev/null +++ b/Robust/src/Analysis/OwnershipAnalysis/ReachOperation.java @@ -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 diff --git a/Robust/src/Analysis/OwnershipAnalysis/ReachabilitySet.java b/Robust/src/Analysis/OwnershipAnalysis/ReachabilitySet.java index 03c56c08..acee8068 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/ReachabilitySet.java +++ b/Robust/src/Analysis/OwnershipAnalysis/ReachabilitySet.java @@ -119,14 +119,28 @@ public class ReachabilitySet extends Canonical { return false; } - private static Hashtable unionhash=new Hashtable(); - private static Hashtable interhash=new Hashtable(); + 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 can=new Hashtable(); - - 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 diff --git a/Robust/src/Analysis/OwnershipAnalysis/TokenTupleSet.java b/Robust/src/Analysis/OwnershipAnalysis/TokenTupleSet.java index 3451c8e8..1b89d119 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/TokenTupleSet.java +++ b/Robust/src/Analysis/OwnershipAnalysis/TokenTupleSet.java @@ -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); }