X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=Robust%2Fsrc%2FAnalysis%2FOwnershipAnalysis%2FTokenTupleSet.java;h=334b7d56d2af9102796adaaae4758d040208a87b;hb=ac6191b514c0e54b468623bf868134e1ce809df5;hp=e52a92d25ebc8692070caeb5903b5aef80d312ad;hpb=b9df1caacff3dbe5959bc12e0e6ba46500fcd3e2;p=IRC.git diff --git a/Robust/src/Analysis/OwnershipAnalysis/TokenTupleSet.java b/Robust/src/Analysis/OwnershipAnalysis/TokenTupleSet.java index e52a92d2..334b7d56 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/TokenTupleSet.java +++ b/Robust/src/Analysis/OwnershipAnalysis/TokenTupleSet.java @@ -8,180 +8,180 @@ import java.io.*; public class TokenTupleSet extends Canonical { - private HashSet tokenTuples; + private HashSet tokenTuples; - public TokenTupleSet() { - tokenTuples = new HashSet(); - } + public TokenTupleSet() { + tokenTuples = new HashSet(); + } - public TokenTupleSet( TokenTuple tt ) { - this(); - assert tt != null; - tokenTuples.add( tt ); - } + public TokenTupleSet(TokenTuple tt) { + this(); + assert tt != null; + tokenTuples.add(tt); + } - public TokenTupleSet( TokenTupleSet tts ) { - assert tts != null; - // okay to clone, TokenTuple and TokenTupleSet should be canonical - tokenTuples = (HashSet) tts.tokenTuples.clone(); - } + public TokenTupleSet(TokenTupleSet tts) { + assert tts != null; + // okay to clone, TokenTuple and TokenTupleSet should be canonical + tokenTuples = (HashSet)tts.tokenTuples.clone(); + } - public TokenTupleSet makeCanonical() { - return (TokenTupleSet) Canonical.makeCanonical( this ); - } + public TokenTupleSet makeCanonical() { + return (TokenTupleSet) Canonical.makeCanonical(this); + } - public Iterator iterator() { - return tokenTuples.iterator(); - } + public Iterator iterator() { + return tokenTuples.iterator(); + } - public boolean isEmpty() { - return tokenTuples.isEmpty(); - } + public boolean isEmpty() { + return tokenTuples.isEmpty(); + } - public boolean isSubset( TokenTupleSet ttsIn ) { - assert ttsIn != null; - return ttsIn.tokenTuples.containsAll( this.tokenTuples ); - } + public boolean isSubset(TokenTupleSet ttsIn) { + assert ttsIn != null; + return ttsIn.tokenTuples.containsAll(this.tokenTuples); + } - public boolean containsTuple( TokenTuple tt ) { - assert tt != null; - return tokenTuples.contains( tt ); - } + public boolean containsTuple(TokenTuple tt) { + assert tt != null; + return tokenTuples.contains(tt); + } - public TokenTupleSet union( TokenTupleSet ttsIn ) { - assert ttsIn != null; - TokenTupleSet ttsOut = new TokenTupleSet( this ); - ttsOut.tokenTuples.addAll( ttsIn.tokenTuples ); - return ttsOut.makeCanonical(); - } + public TokenTupleSet union(TokenTupleSet ttsIn) { + assert ttsIn != null; + TokenTupleSet ttsOut = new TokenTupleSet(this); + ttsOut.tokenTuples.addAll(ttsIn.tokenTuples); + return ttsOut.makeCanonical(); + } - public TokenTupleSet add( TokenTuple tt ) { - assert tt != null; - TokenTupleSet ttsOut = new TokenTupleSet( tt ); - return ttsOut.union( this ); - } + public TokenTupleSet add(TokenTuple tt) { + assert tt != null; + TokenTupleSet ttsOut = new TokenTupleSet(tt); + return ttsOut.union(this); + } - // this should only be done with a multiple-object heap region's token! - public TokenTupleSet increaseArity( Integer token ) { - assert token != null; - TokenTupleSet ttsOut = new TokenTupleSet( this ); - TokenTuple tt - = new TokenTuple( token, true, TokenTuple.ARITY_ONE ).makeCanonical(); - if( ttsOut.tokenTuples.contains( tt ) ) { - ttsOut.tokenTuples.remove( tt ); - ttsOut.tokenTuples.add( - new TokenTuple( token, true, TokenTuple.ARITY_MANY ).makeCanonical() - ); - } - - return ttsOut.makeCanonical(); + // this should only be done with a multiple-object heap region's token! + public TokenTupleSet increaseArity(Integer token) { + assert token != null; + TokenTupleSet ttsOut = new TokenTupleSet(this); + TokenTuple tt + = new TokenTuple(token, true, TokenTuple.ARITY_ONE).makeCanonical(); + if( ttsOut.tokenTuples.contains(tt) ) { + ttsOut.tokenTuples.remove(tt); + ttsOut.tokenTuples.add( + new TokenTuple(token, true, TokenTuple.ARITY_MANY).makeCanonical() + ); } + return ttsOut.makeCanonical(); + } - public boolean equals( Object o ) { - if( o == null ) { - return false; - } - - if( !(o instanceof TokenTupleSet) ) { - return false; - } - TokenTupleSet tts = (TokenTupleSet) o; - return tokenTuples.equals( tts.tokenTuples ); + public boolean equals(Object o) { + if( o == null ) { + return false; } - public int hashCode() { - return tokenTuples.hashCode(); + if( !(o instanceof TokenTupleSet) ) { + return false; } + TokenTupleSet tts = (TokenTupleSet) o; + return tokenTuples.equals(tts.tokenTuples); + } - // this should be a hash table so we can do this by key - public boolean containsToken( Integer token ) { - assert token != null; + public int hashCode() { + return tokenTuples.hashCode(); + } - Iterator itr = tokenTuples.iterator(); - while( itr.hasNext() ) { - TokenTuple tt = (TokenTuple) itr.next(); - if( token.equals( tt.getToken() ) ) { - return true; - } - } - return false; - } + // this should be a hash table so we can do this by key + public boolean containsToken(Integer token) { + assert token != null; - public TokenTupleSet ageTokens( AllocationSite as ) { - assert as != null; + Iterator itr = tokenTuples.iterator(); + while( itr.hasNext() ) { + TokenTuple tt = (TokenTuple) itr.next(); + if( token.equals(tt.getToken() ) ) { + return true; + } + } + return false; + } - TokenTupleSet ttsOut = new TokenTupleSet(); - TokenTuple ttSummary = null; - boolean foundOldest = false; + public TokenTupleSet ageTokens(AllocationSite as) { + assert as != null; - Iterator itrT = this.iterator(); - while( itrT.hasNext() ) { - TokenTuple tt = (TokenTuple) itrT.next(); + TokenTupleSet ttsOut = new TokenTupleSet(); - Integer token = tt.getToken(); - int age = as.getAge( token ); + TokenTuple ttSummary = null; + boolean foundOldest = false; - // summary tokens and tokens not associated with - // the site should be left alone - if( age == AllocationSite.AGE_notInThisSite ) { - ttsOut.tokenTuples.add( tt ); + Iterator itrT = this.iterator(); + while( itrT.hasNext() ) { + TokenTuple tt = (TokenTuple) itrT.next(); - } else { - if( age == AllocationSite.AGE_summary ) { - // remember the summary tuple, but don't add it - // we may combine it with the oldest tuple - ttSummary = tt; + Integer token = tt.getToken(); + int age = as.getAge(token); - } else if( age == AllocationSite.AGE_oldest ) { - // found an oldest token, again just remember - // for later - foundOldest = true; + // summary tokens and tokens not associated with + // the site should be left alone + if( age == AllocationSite.AGE_notInThisSite ) { + ttsOut.tokenTuples.add(tt); - } else { - // otherwise, we change this token to the - // next older token - Integer tokenToChangeTo = as.getIthOldest( age + 1 ); - TokenTuple ttAged = tt.changeTokenTo( tokenToChangeTo ); - ttsOut.tokenTuples.add( ttAged ); - } + } else { + if( age == AllocationSite.AGE_summary ) { + // remember the summary tuple, but don't add it + // we may combine it with the oldest tuple + ttSummary = tt; - } - } + } else if( age == AllocationSite.AGE_oldest ) { + // found an oldest token, again just remember + // for later + foundOldest = true; - // there are four cases to consider here - // 1. we found a summary tuple and no oldest tuple - // Here we just pass the summary unchanged - // 2. we found an oldest tuple, no summary - // Make a new, arity-one summary tuple - // 3. we found both a summary and an oldest - // Merge them by increasing arity of summary - // 4. (not handled) we found neither, do nothing - if ( ttSummary != null && !foundOldest ) { - ttsOut.tokenTuples.add( ttSummary ); - - } else if( ttSummary == null && foundOldest ) { - ttsOut.tokenTuples.add( new TokenTuple( as.getSummary(), - true, - TokenTuple.ARITY_ONE ).makeCanonical() ); - - } else if( ttSummary != null && foundOldest ) { - ttsOut.tokenTuples.add( ttSummary.increaseArity() ); + } else { + // otherwise, we change this token to the + // next older token + Integer tokenToChangeTo = as.getIthOldest(age + 1); + TokenTuple ttAged = tt.changeTokenTo(tokenToChangeTo); + ttsOut.tokenTuples.add(ttAged); } - return ttsOut.makeCanonical(); + } } + // there are four cases to consider here + // 1. we found a summary tuple and no oldest tuple + // Here we just pass the summary unchanged + // 2. we found an oldest tuple, no summary + // Make a new, arity-one summary tuple + // 3. we found both a summary and an oldest + // Merge them by increasing arity of summary + // 4. (not handled) we found neither, do nothing + if ( ttSummary != null && !foundOldest ) { + ttsOut.tokenTuples.add(ttSummary); + + } else if( ttSummary == null && foundOldest ) { + ttsOut.tokenTuples.add(new TokenTuple(as.getSummary(), + true, + TokenTuple.ARITY_ONE).makeCanonical() ); - public String toString() { - return tokenTuples.toString(); + } else if( ttSummary != null && foundOldest ) { + ttsOut.tokenTuples.add(ttSummary.increaseArity() ); } + + return ttsOut.makeCanonical(); + } + + + public String toString() { + return tokenTuples.toString(); + } }