transfer funcs for the R relation of def reach coded, but buggy, results are empty
authorjjenista <jjenista>
Mon, 7 Nov 2011 21:50:35 +0000 (21:50 +0000)
committerjjenista <jjenista>
Mon, 7 Nov 2011 21:50:35 +0000 (21:50 +0000)
Robust/src/Analysis/Disjoint/DefiniteReachAnalysis.java
Robust/src/Analysis/Disjoint/DefiniteReachState.java
Robust/src/Analysis/Disjoint/DisjointAnalysis.java
Robust/src/Tests/disjoint/definite/test.java
Robust/src/Util/MultiViewMap.java

index 6477a8f5269afa572b5ae7082d9014494b70ca44..97f2a4164f2c4ed5b84dd60c5d964b7fb1ba8fef 100644 (file)
@@ -68,11 +68,15 @@ public class DefiniteReachAnalysis {
   public void methodCall( FlatNode fn, 
                           TempDescriptor retVal ) {
     DefiniteReachState state = makeIn( fn );
-    state.methodCall( retVal );
+    if( retVal != null ) {
+      state.methodCall( retVal );
+    }
     fn2state.put( fn, state ); 
   }
 
-
+  public void otherStatement( FlatNode fn ) {
+    fn2state.put( fn, makeIn( fn ) ); 
+  }
 
 
   public void writeState( FlatNode fn, String outputName ) {
index 8006656b7dc65f0a41b102f6441566c93833e767..7ab37d9786c6a590e8a7e80881a1bb911aa19867 100644 (file)
@@ -17,8 +17,10 @@ public class DefiniteReachState {
   // NOTE: Use EdgeKey instead of edges because this analysis's
   // scope is beyond the scope of a single reach graph.
   private static MultiViewMapBuilder<Object> RBuilder;
+  private static BitSet viewRfull;
   private static BitSet viewR0;
   private static BitSet viewR1;
+  private static BitSet viewR2;
   private static BitSet viewR01;
   private MultiViewMap<Object> R;
 
@@ -59,9 +61,11 @@ public class DefiniteReachState {
                                          TempDescriptor.class,
                                          EdgeKey.class },
                                        new JoinOpNop() );
-    viewR0  = RBuilder.addPartialView( 0 );
-    viewR1  = RBuilder.addPartialView( 1 );
-    viewR01 = RBuilder.addPartialView( 0, 1 );
+    viewRfull = RBuilder.getFullView();
+    viewR0    = RBuilder.addPartialView( 0 );
+    viewR1    = RBuilder.addPartialView( 1 );
+    viewR2    = RBuilder.addPartialView( 2 );
+    viewR01   = RBuilder.addPartialView( 0, 1 );
     RBuilder.setCheckTypes( true );
     RBuilder.setCheckConsistency( true );
 
@@ -251,30 +255,34 @@ public class DefiniteReachState {
                       TempDescriptor y,
                       Set<EdgeKey> edgeKeysRemoved,
                       Set<EdgeKey> edgeKeysAdded ) {
-    // I think this should be if there is ANY <w,z>->e' IN Eremove, then kill all <w,z>
-    // R' := (R - {<w,z>->e | <w,z>->e in R, A<w,z>->e' in R, e' notin Eremove}) U
-    //       {<y,x>->e | e in E(x) x {f} x E(y)}
-    // R' = new Map(R)
-    // R'.remove(?); some e's...
-    // R'.put(<y,x>, E(x) x {f} x E(y));
+
+    for( EdgeKey edgeKeyWZ : edgeKeysRemoved ) {
+      R.remove( viewR2, MultiKey.factory( edgeKeyWZ ) );
+    }
+
+    for( EdgeKey edgeKeyXY : edgeKeysAdded ) {
+      R.put( MultiKey.factory( y, x, edgeKeyXY ), MultiViewMap.dummyValue );
+    }
   }
   
   public void newObjectR( TempDescriptor x ) {
-    // R' := (R - <x,*> - <*,x>)
-    // R' = new Map(R)
-    // R'.remove(view0, x);
-    // R'.remove(view1, x);
+    MultiKey keyX = MultiKey.factory( x );
+    R.remove( viewR0, keyX );
+    R.remove( viewR1, keyX );
   }
 
   public void methodCallR( TempDescriptor retVal ) {
-    // R' := (R - <x,*> - <*,x>)
-    // R' = new Map(R)
-    // R'.remove(view0, x);
-    // R'.remove(view1, x);
+    MultiKey keyRetVal = MultiKey.factory( retVal );
+    R.remove( viewR0, keyRetVal );
+    R.remove( viewR1, keyRetVal );
   }
 
   public void mergeR( DefiniteReachState that ) {
-    // R' := <x,y>->e iff its in all incoming edges
+    for( MultiKey key : this.R.get().keySet() ) {
+      if( that.R.get( viewRfull, key ).isEmpty() ) {
+        this.R.remove( viewRfull, key );
+      }
+    }
   }
 
 
@@ -334,7 +342,13 @@ public class DefiniteReachState {
 
 
   public String toString() {
-    StringBuilder s = new StringBuilder( "R_s = {" );
+    StringBuilder s = new StringBuilder();
+
+    s.append( "R = {\n" );
+    s.append( R.toString( 2 ) );
+    s.append( "}\n" );
+
+    //s.append( "R_s = {" );
     //for( TempDescriptor x : Rs.keySet() ) {
     //  s.append( "  "+x+"->"+Rs.get( x ) );
     //}
index 6bde8d8d5f297dbe1207538ee5b84ec6b253213f..37ea420590b6ced2845a2afcc3a1876f29aea3e4 100644 (file)
@@ -1313,6 +1313,12 @@ public class DisjointAnalysis implements HeapAnalysis {
 
 
 
+    
+    boolean didDefReachTransfer = false;    
+
+
+
+
     // use node type to decide what transfer function
     // to apply to the reachability graph
     switch( fn.kind() ) {
@@ -1379,6 +1385,7 @@ public class DisjointAnalysis implements HeapAnalysis {
           params.add( fm.getParameter( i ) );
         }
         definiteReachAnalysis.methodEntry( fn, params );
+        didDefReachTransfer = true;
       }
     } break;
 
@@ -1403,6 +1410,7 @@ public class DisjointAnalysis implements HeapAnalysis {
 
         if( doDefiniteReachAnalysis ) {
           definiteReachAnalysis.copy( fn, lhs, rhs );
+          didDefReachTransfer = true;
         }
       }
       break;
@@ -1430,6 +1438,7 @@ public class DisjointAnalysis implements HeapAnalysis {
 
       if( doDefiniteReachAnalysis ) {
         definiteReachAnalysis.copy( fn, lhs, rhs );
+        didDefReachTransfer = true;
       }
       break;
 
@@ -1468,6 +1477,7 @@ public class DisjointAnalysis implements HeapAnalysis {
 
         if( doDefiniteReachAnalysis ) {
           definiteReachAnalysis.load( fn, lhs, rhs, fld, edgeKeysForLoad );
+          didDefReachTransfer = true;
         }
       }
 
@@ -1530,6 +1540,7 @@ public class DisjointAnalysis implements HeapAnalysis {
                                        rhs,
                                        edgeKeysRemoved,
                                        edgeKeysAdded );
+          didDefReachTransfer = true;
         }
       }
 
@@ -1578,6 +1589,7 @@ public class DisjointAnalysis implements HeapAnalysis {
 
         if( doDefiniteReachAnalysis ) {
           definiteReachAnalysis.load( fn, lhs, rhs, fdElement, edgeKeysForLoad );
+          didDefReachTransfer = true;
         }
       }
 
@@ -1646,6 +1658,7 @@ public class DisjointAnalysis implements HeapAnalysis {
                                        rhs, 
                                        edgeKeysRemoved,
                                        edgeKeysAdded );
+          didDefReachTransfer = true;
         }
       }
 
@@ -1675,6 +1688,7 @@ public class DisjointAnalysis implements HeapAnalysis {
 
         if( doDefiniteReachAnalysis ) {
           definiteReachAnalysis.newObject( fn, lhs );
+          didDefReachTransfer = true;
         }
       }
       break;
@@ -1743,6 +1757,7 @@ public class DisjointAnalysis implements HeapAnalysis {
 
       if( doDefiniteReachAnalysis ) {
         definiteReachAnalysis.methodCall( fn, fc.getReturnTemp() );
+        didDefReachTransfer = true;
       }
 
       
@@ -1931,6 +1946,14 @@ public class DisjointAnalysis implements HeapAnalysis {
     } // end switch
 
 
+
+    if( doDefiniteReachAnalysis && !didDefReachTransfer ) {
+      definiteReachAnalysis.otherStatement( fn );
+    }
+
+
+
+
     // dead variables were removed before the above transfer function
     // was applied, so eliminate heap regions and edges that are no
     // longer part of the abstractly-live heap graph, and sweep up
index 5e6ea0c03086781b4a5663080c297527e602f695..e2f10cc0d1a93a36b2c01b263282d6151d99f2e4 100644 (file)
@@ -33,9 +33,8 @@ public class Test {
     // so we conservatively increase the arity
     // of objects y is reachable from.
     genreach y2;
+    gendefreach y2;
 
-
-    //gendefreach yo;
     System.out.println( x+","+y );
   }
 
index a9ee707fee44b9b47bb4b6c4873a6ba080902ba5..0a0b8878c93f5fab4fc74887f2fd3b3f874238ba 100644 (file)
@@ -138,6 +138,13 @@ public class MultiViewMap<T> {
   }\r
 \r
 \r
+  public Map<MultiKey, T> get() {\r
+    Map<MultiKey, T> fullKey2valueALL = new HashMap<MultiKey, T>();\r
+    fullKey2valueALL.putAll( fullKey2value );\r
+    return fullKey2valueALL;\r
+  }\r
+\r
+\r
   public Map<MultiKey, T> get( final BitSet view, MultiKey partialKey ) {\r
     checkView( view );\r
 \r
@@ -332,4 +339,20 @@ public class MultiViewMap<T> {
 \r
     return true;\r
   }\r
+\r
+  public String toString() {\r
+    return toString( 0 );\r
+  }\r
+\r
+  public String toString( int indent ) {\r
+    StringBuilder s = new StringBuilder();\r
+    \r
+    for( MultiKey key : fullKey2value.keySet() ) {\r
+      for( int i = 0; i < indent; ++i ) {\r
+        s.append( ' ' );\r
+      }\r
+      s.append( key+" -> "+fullKey2value.get( key )+"\n" );\r
+    }\r
+    return s.toString();\r
+  }\r
 }\r