Tighten up use of canonical objects and halt system if a canonical object's hashcode...
authorjjenista <jjenista>
Wed, 1 Oct 2008 21:51:48 +0000 (21:51 +0000)
committerjjenista <jjenista>
Wed, 1 Oct 2008 21:51:48 +0000 (21:51 +0000)
Robust/src/Analysis/OwnershipAnalysis/ChangeTuple.java
Robust/src/Analysis/OwnershipAnalysis/ChangeTupleSet.java
Robust/src/Analysis/OwnershipAnalysis/HeapRegionNode.java
Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java
Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java
Robust/src/Analysis/OwnershipAnalysis/ReachabilitySet.java
Robust/src/Analysis/OwnershipAnalysis/TokenTuple.java
Robust/src/Analysis/OwnershipAnalysis/TokenTupleSet.java
Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java

index 116db256a06e9af54adff683bcb11cbd2a30ed64..c94a0cc9165477c7c0957db439bd9e085de0111c 100644 (file)
@@ -34,6 +34,7 @@ public class ChangeTuple extends Canonical
     return toAdd;
   }
 
+
   public boolean equals(Object o) {
     if( o == null ) {
       return false;
@@ -49,10 +50,26 @@ public class ChangeTuple extends Canonical
            toAdd.equals(ct.getSetToAdd()   );
   }
 
+  private boolean oldHashSet = false;
+  private int     oldHash    = 0;
   public int hashCode() {
-    return toMatch.hashCode() + toAdd.hashCode()*3;
+    int currentHash = toMatch.hashCode() + toAdd.hashCode()*3;
+
+    if( oldHashSet == false ) {
+      oldHash = currentHash;
+      oldHashSet = true;
+    } else {
+      if( oldHash != currentHash ) {
+       System.out.println( "IF YOU SEE THIS A CANONICAL ChangeTuple CHANGED" );
+       Integer x = null;
+       x.toString();
+      }
+    }
+
+    return currentHash;
   }
 
+
   public String toString() {
     return new String("("+toMatch+" -> "+toAdd+")");
   }
index 32a50de1d4fd3e1b734edf55bd940f48901b1469..4f2fe4a8a1d45dbc38c0174fa76291c4456e4e13 100644 (file)
@@ -60,6 +60,7 @@ public class ChangeTupleSet extends Canonical {
     return ctsIn.changeTuples.containsAll(this.changeTuples);
   }
 
+
   public boolean equals(Object o) {
     if( o == null ) {
       return false;
@@ -73,10 +74,26 @@ public class ChangeTupleSet extends Canonical {
     return changeTuples.equals(cts.changeTuples);
   }
 
+  private boolean oldHashSet = false;
+  private int     oldHash    = 0;
   public int hashCode() {
-    return changeTuples.hashCode();
+    int currentHash = changeTuples.hashCode();
+
+    if( oldHashSet == false ) {
+      oldHash = currentHash;
+      oldHashSet = true;
+    } else {
+      if( oldHash != currentHash ) {
+       System.out.println( "IF YOU SEE THIS A CANONICAL ChangeTupleSet CHANGED" );
+       Integer x = null;
+       x.toString();
+      }
+    }
+
+    return currentHash;
   }
 
+
   public String toString() {
     String s = "[";
 
index f5009b22731466f92e1beb814207a96123ab89e5..e474ad63c446e92f2d874506d8cf0a0a85e315aa 100644 (file)
@@ -172,11 +172,8 @@ public class HeapRegionNode extends OwnershipNode {
 
   public void applyAlphaNew() {
     assert alphaNew != null;
-
     alpha = alphaNew;
-
-    alphaNew = new ReachabilitySet();
-    alphaNew = alphaNew.makeCanonical();
+    alphaNew = new ReachabilitySet().makeCanonical();
   }
 
 
index f28ce12748ca6ff676da5b1323ef6736637c45d7..5972b801fde57e5ede0647cefb3d8d956b599b35 100644 (file)
@@ -421,7 +421,6 @@ public class OwnershipAnalysis {
                            og);
 
 
-
       //debugSnapshot(og,fn);
 
 
@@ -613,10 +612,10 @@ public class OwnershipAnalysis {
   // insert a call to debugSnapshot() somewhere in the analysis to get
   // successive captures of the analysis state
   int debugCounter        = 0;
-  int numStartCountReport = 10000;
-  int freqCountReport     = 10;
-  int iterStartCapture    = 50;
-  int numIterToCapture    = 16;
+  int numStartCountReport = 0;
+  int freqCountReport     = 1000;
+  int iterStartCapture    = 20000;
+  int numIterToCapture    = 400;
   void debugSnapshot( OwnershipGraph og, FlatNode fn ) {
     ++debugCounter;
     if( debugCounter > numStartCountReport &&
@@ -630,7 +629,7 @@ public class OwnershipAnalysis {
        graphName = graphName+fn;
       }
       try {
-       og.writeGraph( graphName, true, true, true, false, false );
+       og.writeGraph( graphName, true, true, false, false, false );
       } catch( Exception e ) {
        System.out.println( "Error writing debug capture." );
        System.exit( 0 );       
index 7e3f6af3d00dc308072ab66fa0d23367a8a6f628..10376cfbd11eee8335489a27e8ba836273005ba5 100644 (file)
@@ -84,12 +84,15 @@ public class OwnershipGraph {
 
     if( alpha == null ) {
       if( isFlagged || isParameter ) {
-       alpha = new ReachabilitySet(new TokenTuple(id,
+       alpha = new ReachabilitySet(
+                                   new TokenTuple(id,
                                                   !isSingleObject,
-                                                  TokenTuple.ARITY_ONE)
+                                                  TokenTuple.ARITY_ONE
+                                                  ).makeCanonical()
                                    ).makeCanonical();
       } else {
-       alpha = new ReachabilitySet(new TokenTupleSet()
+       alpha = new ReachabilitySet(
+                                   new TokenTupleSet().makeCanonical()
                                    ).makeCanonical();
       }
     }
@@ -451,9 +454,13 @@ public class OwnershipGraph {
                                 edgesWithNewBeta);
 
 
-       if( edgeY.getBetaNew().equals( new ReachabilitySet() ) ) {
+       // THIS IS A HACK--NEED TO CHANGE GENERATATION OF BETA-NEW SO THIS DOESN'T
+       // HAPPEN OTHERWISE PROPAGATION FAILS
+       if( edgeY.getBetaNew().equals( new ReachabilitySet().makeCanonical() ) ) {
          edgeY.setBetaNew( new ReachabilitySet( new TokenTupleSet().makeCanonical() ).makeCanonical() );
        }
+       
+
 
        /*
        System.out.println( "---------------------------\n" +
@@ -553,7 +560,8 @@ public class OwnershipGraph {
 
     ReachabilitySet beta = new ReachabilitySet(new TokenTuple(newID,
                                                               true,
-                                                              TokenTuple.ARITY_ONE) );
+                                                              TokenTuple.ARITY_ONE).makeCanonical()
+                                              ).makeCanonical();
 
     // heap regions for parameters are always multiple object (see above)
     // and have a reference to themselves, because we can't know the
@@ -707,13 +715,15 @@ public class OwnershipGraph {
 
     // after tokens have been aged, reset newest node's reachability
     if( hrn0.isFlagged() ) {
-      hrn0.setAlpha(new ReachabilitySet(new TokenTupleSet(
-                                          new TokenTuple(hrn0)
-                                          )
+      hrn0.setAlpha(new ReachabilitySet(
+                                       new TokenTupleSet(
+                                                         new TokenTuple(hrn0).makeCanonical()
+                                                         ).makeCanonical()
                                         ).makeCanonical()
                     );
     } else {
-      hrn0.setAlpha(new ReachabilitySet(new TokenTupleSet()
+      hrn0.setAlpha(new ReachabilitySet(
+                                       new TokenTupleSet().makeCanonical()
                                         ).makeCanonical()
                     );
     }
@@ -942,10 +952,12 @@ public class OwnershipGraph {
     // of new callee nodes and edges, doesn't belong to any parameter
     Integer bogusID = new Integer(-1);
     Integer bogusIndex = new Integer(-1);
-    TokenTuple bogusToken = new TokenTuple(bogusID, true, TokenTuple.ARITY_ONE);
-    TokenTuple bogusTokenPlus = new TokenTuple(bogusID, true, TokenTuple.ARITY_ONEORMORE);
+    TokenTuple bogusToken = new TokenTuple(bogusID, true, TokenTuple.ARITY_ONE).makeCanonical();
+    TokenTuple bogusTokenPlus = new TokenTuple(bogusID, true, TokenTuple.ARITY_ONEORMORE).makeCanonical();
     ReachabilitySet rsIdentity =
-      new ReachabilitySet(new TokenTupleSet(bogusToken).makeCanonical() ).makeCanonical();
+      new ReachabilitySet(
+                         new TokenTupleSet(bogusToken).makeCanonical()
+                         ).makeCanonical();
 
     paramIndex2rewriteH.put(bogusIndex, rsIdentity);
     paramIndex2rewriteJ.put(bogusIndex, rsIdentity);
@@ -1296,7 +1308,8 @@ public class OwnershipGraph {
                                                                    null,
                                                                    edgeCallee.getFieldDesc(),
                                                                    false,
-                                                                   toShadowTokens(ogCallee, edgeCallee.getBeta() )
+                                                                   toShadowTokens(ogCallee,
+                                                                                  edgeCallee.getBeta() )
                                                                    );
          rewriteCallerReachability(bogusIndex,
                                    null,
@@ -1382,7 +1395,8 @@ public class OwnershipGraph {
                                                                  null,
                                                                  edgeCallee.getFieldDesc(),
                                                                  false,
-                                                                 toShadowTokens(ogCallee, edgeCallee.getBeta() )
+                                                                 toShadowTokens(ogCallee,
+                                                                                edgeCallee.getBeta() )
                                                                  );
        rewriteCallerReachability(bogusIndex,
                                  null,
@@ -1574,7 +1588,7 @@ public class OwnershipGraph {
   private ReachabilitySet toShadowTokens(OwnershipGraph ogCallee,
                                          ReachabilitySet rsIn) {
 
-    ReachabilitySet rsOut = new ReachabilitySet(rsIn);
+    ReachabilitySet rsOut = new ReachabilitySet(rsIn).makeCanonical();
 
     Iterator<AllocationSite> allocItr = ogCallee.allocationSites.iterator();
     while( allocItr.hasNext() ) {
index caedeadedb1bd21d4c4b4e24415bbc2eb05eaeb7..143db1a86a95cbd9cc4b40666411704b1d1dc876 100644 (file)
@@ -135,7 +135,7 @@ public class ReachabilitySet extends Canonical {
       while( itrR.hasNext() ) {
        TokenTupleSet r = (TokenTupleSet) itrR.next();
 
-       TokenTupleSet theUnion = new TokenTupleSet();
+       TokenTupleSet theUnion = new TokenTupleSet().makeCanonical();
 
        Iterator itrRelement = r.iterator();
        while( itrRelement.hasNext() ) {
@@ -248,7 +248,7 @@ public class ReachabilitySet extends Canonical {
 
     int numDimensions = this.possibleReachabilities.size();
 
-    if( numDimensions > 6 ) {
+    if( numDimensions > 1 ) {
       // for problems that are too big, punt and use less
       // precise arity for reachability information
       TokenTupleSet ttsImprecise = new TokenTupleSet().makeCanonical();
@@ -259,11 +259,11 @@ public class ReachabilitySet extends Canonical {
        ttsImprecise = ttsImprecise.unionUpArity( ttsUnit.makeArityZeroOrMore() );
       }
 
+      //rsOut = this.union( ttsImprecise );
       rsOut = rsOut.union( ttsImprecise );
       return rsOut;
     }
 
-
     // add an extra digit to detect termination
     int[] digits = new int[numDimensions+1];
 
@@ -322,8 +322,24 @@ public class ReachabilitySet extends Canonical {
     return possibleReachabilities.equals(rs.possibleReachabilities);
   }
 
+
+  private boolean oldHashSet = false;
+  private int     oldHash    = 0;
   public int hashCode() {
-    return possibleReachabilities.hashCode();
+    int currentHash = possibleReachabilities.hashCode();
+
+    if( oldHashSet == false ) {
+      oldHash = currentHash;
+      oldHashSet = true;
+    } else {
+      if( oldHash != currentHash ) {
+       System.out.println( "IF YOU SEE THIS A CANONICAL ReachabilitySet CHANGED" );
+       Integer x = null;
+       x.toString();
+      }
+    }
+
+    return currentHash;
   }
 
 
index 30c07379e9df7fe2a9a6e7a4fd4313e43905d757..83226ad54dbd7bf2cb62825d01c321dd5234d59c 100644 (file)
@@ -109,8 +109,23 @@ public class TokenTuple extends Canonical {
            arity ==     tt.getArity();
   }
 
+  private boolean oldHashSet = false;
+  private int     oldHash    = 0;
   public int hashCode() {
-    return token.intValue()*31 + arity;
+    int currentHash = token.intValue()*31 + arity;
+
+    if( oldHashSet == false ) {
+      oldHash = currentHash;
+      oldHashSet = true;
+    } else {
+      if( oldHash != currentHash ) {
+       System.out.println( "IF YOU SEE THIS A CANONICAL TokenTuple CHANGED" );
+       Integer x = null;
+       x.toString();
+      }
+    }
+
+    return currentHash;
   }
 
 
index af72503a559faf7df83636b3bc7136866df515d2..30f135b335fcc5d8f2c0d8be12986705cb89ab7b 100644 (file)
@@ -51,6 +51,13 @@ 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();
+  }
+
   public TokenTupleSet union(TokenTupleSet ttsIn) {
     assert ttsIn != null;
     TokenTupleSet ttsOut = new TokenTupleSet(this);
@@ -109,8 +116,25 @@ public class TokenTupleSet extends Canonical {
     return tokenTuples.equals(tts.tokenTuples);
   }
 
+
+
+  private boolean oldHashSet = false;
+  private int     oldHash    = 0;
   public int hashCode() {
-    return tokenTuples.hashCode();
+    int currentHash = tokenTuples.hashCode();
+
+    if( oldHashSet == false ) {
+      oldHash = currentHash;
+      oldHashSet = true;
+    } else {
+      if( oldHash != currentHash ) {
+       System.out.println( "IF YOU SEE THIS A CANONICAL TokenTupleSet CHANGED" );
+       Integer x = null;
+       x.toString();
+      }
+    }
+
+    return currentHash;
   }
 
 
@@ -287,13 +311,13 @@ public class TokenTupleSet extends Canonical {
       // summary tokens and tokens not associated with
       // the site should be left alone
       if( age == AllocationSite.AGE_notInThisSite ) {
-       ttsOut.tokenTuples.add(tt);
+       ttsOut = ttsOut.union(tt);
 
       } else if( age == AllocationSite.AGE_summary ) {
-       ttsOut.tokenTuples.add(tt.changeTokenTo(as.getSummaryShadow() ));
+       ttsOut = ttsOut.union(tt.changeTokenTo(as.getSummaryShadow() ));
 
       } else if( age == AllocationSite.AGE_oldest ) {
-       ttsOut.tokenTuples.add(tt.changeTokenTo(as.getOldestShadow() ));
+       ttsOut = ttsOut.union(tt.changeTokenTo(as.getOldestShadow() ));
 
       } else {
        assert age == AllocationSite.AGE_in_I;
@@ -301,7 +325,7 @@ public class TokenTupleSet extends Canonical {
        Integer I = as.getAge(token);
        assert I != null;
 
-       ttsOut.tokenTuples.add(tt.changeTokenTo(as.getIthOldestShadow(I) ));
+       ttsOut = ttsOut.union(tt.changeTokenTo(as.getIthOldestShadow(I) ));
       }
     }
 
@@ -326,7 +350,7 @@ public class TokenTupleSet extends Canonical {
       Iterator<TokenTupleSet> replaceItr = replacements.iterator();
       while( replaceItr.hasNext() ) {
        TokenTupleSet replacement = replaceItr.next();
-       TokenTupleSet replaced = new TokenTupleSet(ttsMinusToken);
+       TokenTupleSet replaced = new TokenTupleSet(ttsMinusToken).makeCanonical();
        replaced = replaced.unionUpArity(replacement);
        rsOut = rsOut.add(replaced);
 
@@ -362,8 +386,7 @@ public class TokenTupleSet extends Canonical {
 
     return ttsOut.makeCanonical();
   }
-
-
   public String toString() {
     return tokenTuples.toString();
   }
index 77510319076c93dc45d50d32db42ea954f5b350c..e4c750abc788d00a47cc8a72cf590540c38d7783 100644 (file)
@@ -3,15 +3,15 @@ public class Parameter {
   flag w;
   int a;
   int b;
-  //Parameter f;
-  //Parameter g;
-  //Penguin p;
-  //Foo h;
+  Parameter f;
+  Parameter g;
+  Penguin p;
+  Foo h;
   
-  public Parameter() {} // a = 0; b = 0; f = null; g = null; }
+  public Parameter() {}
   
-  //public void bar() { foo(); }
-  //public void foo() { bar(); }
+  public void bar() { foo(); }
+  public void foo() { bar(); }
 
   static public void proof( Fooz p0, Fooz p1 ) {
     Fooz c = new Fooz();
@@ -28,7 +28,6 @@ public class Fooz {
   public Fooz x;
 }
 
-/*
 public class Penguin {
   int x;
   int y;
@@ -180,8 +179,15 @@ public class Foo {
     p0.y = p1;
     p1.y = p0;
   }
+
+  static public void m9_( Foo p0, Foo p1 ) {
+    Foo g0 = new Foo();
+
+    p1.x = p1.y;
+    p1.y = g0;
+  }
 }
-*/
+
 
 
 // this empty task should still create a non-empty
@@ -196,20 +202,11 @@ task Startup( StartupObject s{ initialstate } ) {
 
   Parameter.proof( null, null );
 
-  /*
-  int a = 1;
-  int b = 2;
-  int c = 3;
-
-  b = c;
-  a = b;
-  */
-
   taskexit( s{ !initialstate } );
 }
 
-
 /*
+
 task NewObjectA( Foo a{ f }, Foo b{ f } ) {
 
     Foo c = new Foo();
@@ -471,9 +468,8 @@ task getNewFromMethod( Foo p0{ f } ) {
 
   taskexit( p0{ !f } );
 }
-*/
 
-/*
+
 task methodTest01_( Foo p0{ f }, Foo p1{ f } ) {
 
   Foo a0before = new Foo();
@@ -495,9 +491,8 @@ task methodTest01_( Foo p0{ f }, Foo p1{ f } ) {
 
   taskexit( p0{ !f }, p1{ !f } );
 }
-*/
 
-/*
+
 task methodTest02_( Foo p0{ f }, Foo p1{ f } ) {
 
   Foo a0before = new Foo();
@@ -620,7 +615,7 @@ task methodTest06_( Foo p0{ f }, Foo p1{ f } ) {
     a1after.x = new Foo();
   }
 
-  Foo.m6_( a0after, a1after );
+  //Foo.m6_( a0after, a1after );
 
 
   taskexit( p0{ !f }, p1{ !f } );
@@ -657,7 +652,7 @@ task methodTest07_( Foo p0{ f }, Foo p1{ f } ) {
     a1after.x = new Foo();
   }
 
-  Foo.m7_( a0after, a1after );
+  //Foo.m7_( a0after, a1after );
 
 
   taskexit( p0{ !f }, p1{ !f } );
@@ -694,9 +689,47 @@ task methodTest08_( Foo p0{ f }, Foo p1{ f } ) {
     a1after.x = new Foo();
   }
 
-  Foo.m8_( a0after, a1after );
+  //Foo.m8_( a0after, a1after );
 
 
   taskexit( p0{ !f }, p1{ !f } );
 }
 */
+
+
+task methodTest09_( Foo p0{ f }, Foo p1{ f } ) {
+
+  Foo a0before = new Foo();
+  if( false ) {
+    a0before.x = new Foo();
+  } else {
+    a0before.x = new Foo();
+  }
+
+  Foo a0after = new Foo();
+  if( false ) {
+    a0after.x = new Foo();
+  } else {
+    a0after.x = new Foo();
+  }
+
+  Foo a1before = new Foo();
+  if( false ) {
+    a1before.x = new Foo();
+  } else {
+    a1before.x = new Foo();
+  }
+
+  Foo a1after = new Foo();
+  if( false ) {
+    a1after.x = new Foo();
+  } else {
+    a1after.x = new Foo();
+  }
+
+  Foo.m9_( a0after, a1after );
+
+
+  taskexit( p0{ !f }, p1{ !f } );
+}
+