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
--- /dev/null
+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
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 =
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 =
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
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
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();
--- /dev/null
+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
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;
+ }
}
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;
}
}
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();
rsOut.possibleReachabilities.add(tts);
}
}
- ro.c=rsOut.makeCanonical();
+ ro.c=rsOut=rsOut.makeCanonical();
interhash.put(ro,ro);
- return ro.c;
+ return rsOut;
}
}
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() );
}
}
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() );
}
}
}
public ReachabilitySet exhaustiveArityCombinations() {
- ReachabilitySet rsOut = new ReachabilitySet();
+ ReachabilitySet rsOut = (new ReachabilitySet()).makeCanonical();
int numDimensions = this.possibleReachabilities.size();
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 = "[";
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
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;
+ }
}
public TokenTupleSet add(TokenTuple tt) {
assert tt != null;
- TokenTupleSet ttsOut = new TokenTupleSet(tt);
- return ttsOut.union(this);
+ return this.union(tt);
}