From: jjenista Date: Wed, 6 Aug 2008 19:33:14 +0000 (+0000) Subject: Added fields to ReferenceEdgeProperties and combed over all classes that need proper... X-Git-Tag: preEdgeChange~13 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=73dc3aa78b1d145caa868820090dfd6c7ff3f237;p=IRC.git Added fields to ReferenceEdgeProperties and combed over all classes that need proper equals and hashcode methods --- diff --git a/Robust/src/Analysis/OwnershipAnalysis/ChangeTuple.java b/Robust/src/Analysis/OwnershipAnalysis/ChangeTuple.java index 296e578d..ce36f671 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/ChangeTuple.java +++ b/Robust/src/Analysis/OwnershipAnalysis/ChangeTuple.java @@ -31,6 +31,10 @@ public class ChangeTuple extends Canonical public TokenTupleSet getSetToAdd() { return toAdd; } public boolean equals( Object o ) { + if( o == null ) { + return false; + } + if( !(o instanceof ChangeTuple) ) { return false; } diff --git a/Robust/src/Analysis/OwnershipAnalysis/ChangeTupleSet.java b/Robust/src/Analysis/OwnershipAnalysis/ChangeTupleSet.java index 498cda9b..1a91061a 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/ChangeTupleSet.java +++ b/Robust/src/Analysis/OwnershipAnalysis/ChangeTupleSet.java @@ -57,6 +57,10 @@ public class ChangeTupleSet extends Canonical { } public boolean equals( Object o ) { + if( o == null ) { + return false; + } + if( !(o instanceof ChangeTupleSet) ) { return false; } diff --git a/Robust/src/Analysis/OwnershipAnalysis/HeapRegionNode.java b/Robust/src/Analysis/OwnershipAnalysis/HeapRegionNode.java index fdbe1fa9..4b6464d2 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/HeapRegionNode.java +++ b/Robust/src/Analysis/OwnershipAnalysis/HeapRegionNode.java @@ -63,6 +63,9 @@ public class HeapRegionNode extends OwnershipNode { public boolean equals( Object o ) { + if( o == null ) { + return false; + } if( !( o instanceof HeapRegionNode) ) { return false; diff --git a/Robust/src/Analysis/OwnershipAnalysis/LabelNode.java b/Robust/src/Analysis/OwnershipAnalysis/LabelNode.java index 8ae18258..32794060 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/LabelNode.java +++ b/Robust/src/Analysis/OwnershipAnalysis/LabelNode.java @@ -16,6 +16,9 @@ public class LabelNode extends OwnershipNode { } public boolean equals( Object o ) { + if( o == null ) { + return false; + } if( !( o instanceof LabelNode) ) { return false; @@ -30,6 +33,7 @@ public class LabelNode extends OwnershipNode { return td.getNum(); } + public String getTempDescriptorString() { return td.toString(); } diff --git a/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java b/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java index 65b39c93..bd5d6ef9 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java +++ b/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java @@ -361,7 +361,7 @@ public class OwnershipGraph { ReachabilitySet beta2 = rep2.getBeta(); ReferenceEdgeProperties rep = - new ReferenceEdgeProperties( false, + new ReferenceEdgeProperties( null, false, beta1.intersection( beta2 ) ); @@ -435,7 +435,7 @@ public class OwnershipGraph { // finally, create the actual reference edge hrn->hrnSrc ReferenceEdgeProperties repNew - = new ReferenceEdgeProperties( false, + = new ReferenceEdgeProperties( fd, false, repSrc.getBetaNew().pruneBy( hrn.getAlpha() ) ); @@ -487,8 +487,8 @@ public class OwnershipGraph { // and have a reference to themselves, because we can't know the // structure of memory that is passed into the method. We're assuming // the worst here. - addReferenceEdge( lnParam, hrn, new ReferenceEdgeProperties( false, false, beta ) ); - addReferenceEdge( hrn, hrn, new ReferenceEdgeProperties( false, true, beta ) ); + addReferenceEdge( lnParam, hrn, new ReferenceEdgeProperties( null, false, beta ) ); + addReferenceEdge( hrn, hrn, new ReferenceEdgeProperties( null, true, beta ) ); } public void assignTempToNewAllocation( TempDescriptor td, @@ -512,7 +512,7 @@ public class OwnershipGraph { clearReferenceEdgesFrom( dst ); - addReferenceEdge( dst, hrnNewest, new ReferenceEdgeProperties( false, false, hrnNewest.getAlpha() ) ); + addReferenceEdge( dst, hrnNewest, new ReferenceEdgeProperties( null, false, hrnNewest.getAlpha() ) ); } @@ -828,11 +828,7 @@ public class OwnershipGraph { AllocationSite allocSite = i.next(); HeapRegionNode hrnSummary = getSummaryNode ( allocSite ); HeapRegionNode hrnShadowSummary = getShadowSummaryNode( allocSite ); - } - - - - /* + } // in non-static methods there is a "this" pointer // that should be taken into account @@ -885,13 +881,13 @@ public class OwnershipGraph { // and a set of destination heaps in the caller graph, and make // a reference edge in the caller for every possible (src,dst) pair if( !ogCallee.id2hrn.contains( idChildCallee ) ) { - //System.out.println( "Houston, we got a problem." ); - //System.out.println( "idCallee is "+idCallee ); - //System.out.println( "idChildCallee is "+idChildCallee ); + System.out.println( "Houston, we got a problem." ); + System.out.println( "idCallee is "+idCallee ); + System.out.println( "idChildCallee is "+idChildCallee ); try { - writeGraph( "caller", false, false, false ); - ogCallee.writeGraph( "callee", false, false, false ); + writeGraph ( "caller", false, false, false, false ); + ogCallee.writeGraph( "callee", false, false, false, false ); } catch( IOException e ) {} } @@ -922,9 +918,9 @@ public class OwnershipGraph { } } } - */ } + private HashSet getHRNSetThatPossiblyMapToCalleeHRN( OwnershipGraph ogCallee, Integer idCallee, FlatCall fc, diff --git a/Robust/src/Analysis/OwnershipAnalysis/OwnershipNode.java b/Robust/src/Analysis/OwnershipAnalysis/OwnershipNode.java index a216ca7a..14adde19 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/OwnershipNode.java +++ b/Robust/src/Analysis/OwnershipAnalysis/OwnershipNode.java @@ -4,7 +4,9 @@ import IR.*; import IR.Flat.*; import java.util.*; -public class OwnershipNode { +public abstract class OwnershipNode { + + protected Hashtable referencedRegions; public OwnershipNode() { referencedRegions = @@ -12,13 +14,6 @@ public class OwnershipNode { } - /////////////////////////////////////////// - // interface with larger graph - /////////////////////////////////////////// - protected Hashtable - - referencedRegions; - public Iterator setIteratorToReferencedRegions() { Set s = referencedRegions.entrySet(); return s.iterator(); @@ -50,7 +45,8 @@ public class OwnershipNode { return referencedRegions.get( hrn ); } - /////////////////////////////////////////////// - // end interface with larger graph - /////////////////////////////////////////////// + + + abstract public boolean equals( Object o ); + abstract public int hashCode(); } \ No newline at end of file diff --git a/Robust/src/Analysis/OwnershipAnalysis/ReachabilitySet.java b/Robust/src/Analysis/OwnershipAnalysis/ReachabilitySet.java index f7a5721a..08b2b7a8 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/ReachabilitySet.java +++ b/Robust/src/Analysis/OwnershipAnalysis/ReachabilitySet.java @@ -243,6 +243,10 @@ public class ReachabilitySet extends Canonical { public boolean equals( Object o ) { + if( o == null ) { + return false; + } + if( !(o instanceof ReachabilitySet) ) { return false; } diff --git a/Robust/src/Analysis/OwnershipAnalysis/ReferenceEdgeProperties.java b/Robust/src/Analysis/OwnershipAnalysis/ReferenceEdgeProperties.java index 4b85b2af..4e0b0458 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/ReferenceEdgeProperties.java +++ b/Robust/src/Analysis/OwnershipAnalysis/ReferenceEdgeProperties.java @@ -1,8 +1,14 @@ package Analysis.OwnershipAnalysis; +import IR.*; +import IR.Flat.*; + + public class ReferenceEdgeProperties { - protected boolean isUnique; + // a null field descriptor means "any field" + protected FieldDescriptor fieldDesc; + protected boolean isInitialParamReflexive; protected ReachabilitySet beta; @@ -12,29 +18,15 @@ public class ReferenceEdgeProperties { protected HeapRegionNode dst; public ReferenceEdgeProperties() { - this( false, false, null ); + this( null, false, null ); } - public ReferenceEdgeProperties( boolean isUnique ) { - this( isUnique, false, null ); - } - - public ReferenceEdgeProperties( boolean isUnique, - boolean isInitialParamReflexive ) { - this( isUnique, isInitialParamReflexive, null ); - } - - public ReferenceEdgeProperties( boolean isUnique, + public ReferenceEdgeProperties( FieldDescriptor fieldDesc, boolean isInitialParamReflexive, - ReachabilitySet beta) { - this.isUnique = isUnique; - this.isInitialParamReflexive = isInitialParamReflexive; + ReachabilitySet beta ) { - // these members are set by higher-level code - // when this ReferenceEdgeProperties object is - // applied to an edge - this.src = null; - this.dst = null; + this.fieldDesc = fieldDesc; + this.isInitialParamReflexive = isInitialParamReflexive; if( beta != null ) { this.beta = beta; @@ -43,6 +35,14 @@ public class ReferenceEdgeProperties { this.beta = this.beta.makeCanonical(); } + // these members are set by higher-level code + // when this ReferenceEdgeProperties object is + // applied to an edge + this.src = null; + this.dst = null; + + // when edges are not undergoing a transitional operation + // that is changing beta info, betaNew is always empty betaNew = new ReachabilitySet(); betaNew = betaNew.makeCanonical(); } @@ -67,20 +67,20 @@ public class ReferenceEdgeProperties { } - // copying does not copy source and destination members! + // copying does not copy source and destination members! or betaNew public ReferenceEdgeProperties copy() { - return new ReferenceEdgeProperties( isUnique, + return new ReferenceEdgeProperties( fieldDesc, isInitialParamReflexive, beta ); } - - public boolean isUnique() { - return isUnique; + public FieldDescriptor getFieldDesc() { + return fieldDesc; } - public void setIsUnique( boolean isUnique ) { - this.isUnique = isUnique; + + public void setFieldDesc( FieldDescriptor fieldDesc ) { + this.fieldDesc = fieldDesc; } @@ -93,7 +93,6 @@ public class ReferenceEdgeProperties { } - public ReachabilitySet getBeta() { return beta; } @@ -122,24 +121,42 @@ public class ReferenceEdgeProperties { } - public boolean equals( ReferenceEdgeProperties rep ) { - assert rep != null; + public boolean equals( Object o ) { + if( o == null ) { + return false; + } + + if( !(o instanceof ReferenceEdgeProperties) ) { + return false; + } - return isUnique == rep.isUnique() && - isInitialParamReflexive == rep.isInitialParamReflexive(); + ReferenceEdgeProperties rep = (ReferenceEdgeProperties) o; + + // field descriptors maintain the invariant that they are reference comparable + return fieldDesc == rep.fieldDesc && + isInitialParamReflexive == rep.isInitialParamReflexive && + beta.equals( rep.beta ); } + public int hashCode() { + int hash = 0; + if( fieldDesc != null ) { + hash += fieldDesc.getType().hashCode(); + } + hash += beta.hashCode(); + return hash; + } + + public String getBetaString() { return beta.toStringEscapeNewline(); } public String toEdgeLabelString() { String edgeLabel = ""; - /* - if( rep.isUnique() ) { - edgeLabel += "Unq"; + if( fieldDesc != null ) { + edgeLabel += fieldDesc.toStringBrief() + "\\n"; } - */ if( isInitialParamReflexive ) { edgeLabel += "Rflx\\n"; } diff --git a/Robust/src/Analysis/OwnershipAnalysis/TokenTuple.java b/Robust/src/Analysis/OwnershipAnalysis/TokenTuple.java index acaf257d..e8fd95a9 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/TokenTuple.java +++ b/Robust/src/Analysis/OwnershipAnalysis/TokenTuple.java @@ -60,6 +60,10 @@ public class TokenTuple extends Canonical } public boolean equals( Object o ) { + if( o == null ) { + return false; + } + if( !(o instanceof TokenTuple) ) { return false; } diff --git a/Robust/src/Analysis/OwnershipAnalysis/TokenTupleSet.java b/Robust/src/Analysis/OwnershipAnalysis/TokenTupleSet.java index 4bd1a718..fb6ee256 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/TokenTupleSet.java +++ b/Robust/src/Analysis/OwnershipAnalysis/TokenTupleSet.java @@ -100,6 +100,10 @@ public class TokenTupleSet extends Canonical { } public boolean equals( Object o ) { + if( o == null ) { + return false; + } + if( !(o instanceof TokenTupleSet) ) { return false; } diff --git a/Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java b/Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java index a203ca46..6cc5b5b6 100644 --- a/Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java +++ b/Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java @@ -46,7 +46,7 @@ public class Foo { a.x = b.x; } - public void test( Foo p0, Foo p1 ) { + static public void test( Foo p0, Foo p1 ) { Foo f0 = new Foo(); Foo f1 = new Foo(); Foo f2 = new Foo(); @@ -110,15 +110,8 @@ task Startup( StartupObject s{ initialstate } ) { b = c; } */ - - Foo aa = new Foo(); - aa.test( aa, aa ); - - /* - Foo ab = new Foo(); - Foo ac = new Foo(); - Foo ad = new Foo(); + /* aa.x = ab; ab.x = ac; ab.x = aa; @@ -128,6 +121,29 @@ task Startup( StartupObject s{ initialstate } ) { taskexit( s{ !initialstate } ); } + +task methodTest( Foo p0{ f } ) { + + Foo a0; + if( false ) { + a0 = new Foo(); + } else { + a0 = new Foo(); + a0.x = new Foo(); + p0.x = a0; + } + + Foo a1 = new Foo(); + + if( false ) { + p0.x = a1; + } + + Foo.test( a0, a1 ); + + taskexit( p0{ !f } ); +} + /* task NewObject( Foo a{ f }, Foo b{ f } ) {