callee elements brought into caller get predicates from caller element that satisfied...
authorjjenista <jjenista>
Tue, 9 Mar 2010 01:05:31 +0000 (01:05 +0000)
committerjjenista <jjenista>
Tue, 9 Mar 2010 01:05:31 +0000 (01:05 +0000)
Robust/src/Analysis/Disjoint/ExistPred.java
Robust/src/Analysis/Disjoint/ExistPredSet.java
Robust/src/Analysis/Disjoint/ReachGraph.java
Robust/src/Tests/disjoint/predicateTest2/makefile
Robust/src/Tests/disjoint/predicateTest2/test.java

index bc7988fbe57d5a1e12ff086dd5dc749fc53bf55e..b9952a7a70d061c09c7c24a15b140995cbbb0ff3 100644 (file)
@@ -156,36 +156,42 @@ public class ExistPred extends Canonical {
 
 
   // only consider the subest of the caller elements that
-  // are reachable by callee when testing predicates
-  public boolean isSatisfiedBy( ReachGraph rg,
-                                Set<HeapRegionNode> calleeReachableNodes,
-                                Set<RefEdge>        calleeReachableEdges   
-                                ) {
+  // are reachable by callee when testing predicates--if THIS
+  // predicate is satisfied, return the predicate set of the 
+  // element that satisfied it, or null for false
+  public ExistPredSet isSatisfiedBy( ReachGraph rg,
+                                     Set<HeapRegionNode> calleeReachableNodes,
+                                     Set<RefEdge>        calleeReachableEdges   
+                                     ) {
 
     if( predType == TYPE_TRUE ) {
-      return true;
+      return ExistPredSet.factory( ExistPred.factory() );
     }
 
     if( predType == TYPE_NODE ) {
       // first find node
       HeapRegionNode hrn = rg.id2hrn.get( n_hrnID );
       if( hrn == null ) {
-        return false;
+        return null;
       }
 
       if( !calleeReachableNodes.contains( hrn ) ) {
-        return false;
+        return null;
       }
 
       // when the state is null it is not part of the
       // predicate, so we've already satisfied
       if( ne_state == null ) {
-        return true;
+        return hrn.getPreds();
       }
 
       // otherwise look for state too
       // TODO: contains OR containsSuperSet OR containsWithZeroes??
-      return hrn.getAlpha().contains( ne_state );
+      if( hrn.getAlpha().contains( ne_state ) ) {
+        return hrn.getPreds();
+      }
+
+      return null;
     }
     
     if( predType == TYPE_EDGE ) {
@@ -203,7 +209,7 @@ public class ExistPred extends Canonical {
     
       // the source is not present in graph
       if( vnSrc == null && hrnSrc == null ) {
-        return false;
+        return null;
       }
 
       RefSrcNode rsn;
@@ -211,7 +217,7 @@ public class ExistPred extends Canonical {
         rsn = vnSrc;
       } else {
         if( !calleeReachableNodes.contains( hrnSrc ) ) {
-          return false;
+          return null;
         }
         rsn = hrnSrc;
       }
@@ -219,11 +225,11 @@ public class ExistPred extends Canonical {
       // is the destination present?
       HeapRegionNode hrnDst = rg.id2hrn.get( e_hrnDstID );
       if( hrnDst == null ) {
-        return false;
+        return null;
       }
 
       if( !calleeReachableNodes.contains( hrnDst ) ) {
-        return false;
+        return null;
       }
 
       // is there an edge between them with the given
@@ -233,22 +239,26 @@ public class ExistPred extends Canonical {
                                          e_type, 
                                          e_field );
       if( edge == null ) {
-        return false;
+        return null;
       }
                                                 
       if( !calleeReachableEdges.contains( edge ) ) {
-        return false;
+        return null;
       }
 
       // when state is null it is not part of the predicate
       // so we've satisfied the edge existence
       if( ne_state == null ) {
-        return true;
+        return edge.getPreds();
       }
       
       // otherwise look for state too
       // TODO: contains OR containsSuperSet OR containsWithZeroes??
-      return hrnDst.getAlpha().contains( ne_state );
+      if( hrnDst.getAlpha().contains( ne_state ) ) {
+        return edge.getPreds();
+      }
+
+      return null;
     }
 
     throw new Error( "Unknown predicate type" );
index 4268c1a233597a150d135b8e5365bcb5f29c3ae8..968e63881fad4372ae6b25aad45ec05fd46c1829 100644 (file)
@@ -52,20 +52,30 @@ public class ExistPredSet extends Canonical {
 
   // only consider the subest of the caller elements that
   // are reachable by callee when testing predicates
-  public boolean isSatisfiedBy( ReachGraph          rg,
-                                Set<HeapRegionNode> calleeReachableNodes,
-                                Set<RefEdge>        calleeReachableEdges                                
-                                ) {
+  public ExistPredSet isSatisfiedBy( ReachGraph          rg,
+                                     Set<HeapRegionNode> calleeReachableNodes,
+                                     Set<RefEdge>        calleeReachableEdges                                
+                                     ) {
+    ExistPredSet predsOut = null;
+    
     Iterator<ExistPred> predItr = preds.iterator();
     while( predItr.hasNext() ) {
-      if( predItr.next().isSatisfiedBy( rg,
-                                        calleeReachableNodes,
-                                        calleeReachableEdges )
-          ) {
-        return true;
+      ExistPredSet predsFromSatisfier =
+        predItr.next().isSatisfiedBy( rg,
+                                      calleeReachableNodes,
+                                      calleeReachableEdges );
+
+      if( predsFromSatisfier != null ) {
+        if( predsOut == null ) {
+          predsOut = predsFromSatisfier;
+        } else {
+          predsOut = Canonical.join( predsOut,
+                                     predsFromSatisfier );
+        }
       }
     }
-    return false;
+    
+    return predsOut;
   }
 
 
index a2a3fdcf5bd63d174f2aacb129ae01b04006cc4e..26484096eae7e5143fee73afd6c005dd15b81e1d 100644 (file)
@@ -375,7 +375,7 @@ public class ReachGraph {
        TypeDescriptor tdNewEdge =
          mostSpecificType( edgeHrn.getType(), 
                            hrnHrn.getType() 
-                           );       
+                           );
          
        RefEdge edgeNew = new RefEdge( lnX,
                                        hrnHrn,
@@ -385,7 +385,7 @@ public class ReachGraph {
                                        predsTrue
                                        );
        
-       addRefEdge( lnX, hrnHrn, edgeNew );     
+       addRefEdge( lnX, hrnHrn, edgeNew );
       }
     }
 
@@ -1405,6 +1405,8 @@ public class ReachGraph {
     return rg;
   }  
 
+
+
   public void 
     resolveMethodCall( FlatCall            fc,        
                        FlatMethod          fm,        
@@ -1437,11 +1439,11 @@ public class ReachGraph {
 
 
     // 1. mark what callee elements have satisfied predicates
-    Set<HeapRegionNode> calleeNodesSatisfied =
-      new HashSet<HeapRegionNode>();
+    Hashtable<HeapRegionNode, ExistPredSet> calleeNodesSatisfied =
+      new Hashtable<HeapRegionNode, ExistPredSet>();
     
-    Set<RefEdge>        calleeEdgesSatisfied =
-      new HashSet<RefEdge>();
+    Hashtable<RefEdge, ExistPredSet> calleeEdgesSatisfied =
+      new Hashtable<RefEdge, ExistPredSet>();
 
     Iterator meItr = rgCallee.id2hrn.entrySet().iterator();
     while( meItr.hasNext() ) {
@@ -1449,24 +1451,38 @@ public class ReachGraph {
       Integer        id        = (Integer)        me.getKey();
       HeapRegionNode hrnCallee = (HeapRegionNode) me.getValue();
     
-      if( hrnCallee.getPreds().isSatisfiedBy( this,
-                                              callerNodesCopiedToCallee,
-                                              callerEdgesCopiedToCallee
-                                              )
-          ) {
-        calleeNodesSatisfied.add( hrnCallee );
+      ExistPredSet predsIfSatis = 
+        hrnCallee.getPreds().isSatisfiedBy( this,
+                                            callerNodesCopiedToCallee,
+                                            callerEdgesCopiedToCallee
+                                            );
+      if( predsIfSatis != null ) {
+        calleeNodesSatisfied.put( hrnCallee, predsIfSatis );
+      } else {
+        // otherwise don't bother looking at edges from this node
+        continue;
       }
 
       Iterator<RefEdge> reItr = hrnCallee.iteratorToReferencees();
       while( reItr.hasNext() ) {
         RefEdge reCallee = reItr.next();
+
+        ExistPredSet ifDst = 
+          reCallee.getDst().getPreds().isSatisfiedBy( this,
+                                                      callerNodesCopiedToCallee,
+                                                      callerEdgesCopiedToCallee
+                                                      );
+        if( ifDst == null ) {
+          continue;
+        }
         
-        if( reCallee.getPreds().isSatisfiedBy( this,
-                                               callerNodesCopiedToCallee,
-                                               callerEdgesCopiedToCallee
-                                               )
-            ) {
-          calleeEdgesSatisfied.add( reCallee );
+        predsIfSatis = 
+          reCallee.getPreds().isSatisfiedBy( this,
+                                             callerNodesCopiedToCallee,
+                                             callerEdgesCopiedToCallee
+                                             );
+        if( predsIfSatis != null ) {
+          calleeEdgesSatisfied.put( reCallee, predsIfSatis );
         }        
       }
     }
@@ -1481,13 +1497,23 @@ public class ReachGraph {
       Iterator<RefEdge> reItr = vnCallee.iteratorToReferencees();
       while( reItr.hasNext() ) {
         RefEdge reCallee = reItr.next();
-        
-        if( reCallee.getPreds().isSatisfiedBy( this,
-                                               callerNodesCopiedToCallee,
-                                               callerEdgesCopiedToCallee
-                                               )
-            ) {
-          calleeEdgesSatisfied.add( reCallee );
+
+        ExistPredSet ifDst = 
+          reCallee.getDst().getPreds().isSatisfiedBy( this,
+                                                      callerNodesCopiedToCallee,
+                                                      callerEdgesCopiedToCallee
+                                                      );
+        if( ifDst == null ) {
+          continue;
+        }
+
+        ExistPredSet predsIfSatis = 
+          reCallee.getPreds().isSatisfiedBy( this,
+                                             callerNodesCopiedToCallee,
+                                             callerEdgesCopiedToCallee
+                                             );
+        if( predsIfSatis != null ) {
+          calleeEdgesSatisfied.put( reCallee, predsIfSatis );
         }        
       }
     }
@@ -1503,12 +1529,19 @@ public class ReachGraph {
 
 
 
-    // 3. callee elements with satisfied preds come in
+    // 3. callee elements with satisfied preds come in, note that
+    //    the mapping of elements satisfied to preds is like this:
+    //    A callee element EE has preds EEp that are satisfied by
+    //    some caller element ER.  We bring EE into the caller
+    //    context as ERee with the preds of ER, namely ERp, which
+    //    in the following algorithm is the value in the mapping
 
     // 3.a) nodes
-    hrnItr = calleeNodesSatisfied.iterator();
-    while( hrnItr.hasNext() ) {
-      HeapRegionNode hrnCallee = hrnItr.next();
+    Iterator satisItr = calleeNodesSatisfied.entrySet().iterator();
+    while( satisItr.hasNext() ) {
+      Map.Entry      me        = (Map.Entry)      satisItr.next();
+      HeapRegionNode hrnCallee = (HeapRegionNode) me.getKey();
+      ExistPredSet   preds     = (ExistPredSet)   me.getValue();
 
       if( hrnCallee.isOutOfContext() ) {
         continue;
@@ -1526,23 +1559,22 @@ public class ReachGraph {
                                    hrnCallee.getAllocSite(),   // allocation site                       
                                    hrnCallee.getInherent(),    // inherent reach
                                    null,                       // current reach                 
-                                   predsEmpty,                 // predicates
+                                   preds,                      // predicates
                                    hrnCallee.getDescription()  // description
                                    );                                        
       }
 
       // TODO: alpha should be some rewritten version of callee in caller context
       hrnCaller.setAlpha( rsetEmpty );
-
-      // TODO: predicates should be exact same from caller version that satisfied
-      hrnCaller.setPreds( predsTrue );
     }
 
 
     // 3.b) callee -> callee edges
-    Iterator<RefEdge> reItr = calleeEdgesSatisfied.iterator();
-    while( reItr.hasNext() ) {
-      RefEdge reCallee = reItr.next();
+    satisItr = calleeEdgesSatisfied.entrySet().iterator();
+    while( satisItr.hasNext() ) {
+      Map.Entry    me       = (Map.Entry)    satisItr.next();
+      RefEdge      reCallee = (RefEdge)      me.getKey();
+      ExistPredSet preds    = (ExistPredSet) me.getValue();
 
       RefSrcNode rsnCallee = reCallee.getSrc();
       RefSrcNode rsnCaller;
@@ -1564,20 +1596,20 @@ public class ReachGraph {
         HeapRegionNode hrnSrcCallee = (HeapRegionNode) reCallee.getSrc();
         rsnCaller = id2hrn.get( hrnSrcCallee.getID() );
       }
-            
+      
       assert rsnCaller != null;
       
       HeapRegionNode hrnDstCallee = reCallee.getDst();
       HeapRegionNode hrnDstCaller = id2hrn.get( hrnDstCallee.getID() );
       assert hrnDstCaller != null;
       
-      // TODO: beta rewrites, preds from satisfier in caller
+      // TODO: beta rewrites
       RefEdge reCaller = new RefEdge( rsnCaller,
                                       hrnDstCaller,
                                       reCallee.getType(),
                                       reCallee.getField(),
                                       rsetEmpty,
-                                      predsTrue
+                                      preds
                                       );
 
 
index 0f5ef2621529f304255d7aeae322803faf66742a..1c4574a3da6bcd5951e9497dac66b14286771d07 100644 (file)
@@ -3,9 +3,10 @@ PROGRAM=test
 SOURCE_FILES=$(PROGRAM).java
 
 BUILDSCRIPT=~/research/Robust/src/buildscript
+DEBUGFLAGS= -disjoint-debug-callsite addSomething main 1
 #DEBUGFLAGS= -disjoint-debug-callsite addBar addSomething 1
-#DEBUGFLAGS= -disjoint-debug-callsite Bar    addBar       1
-DEBUGFLAGS=
+#DEBUGFLAGS= -disjoint-debug-callsite Bar addBar 1
+#DEBUGFLAGS=
 BSFLAGS= -mainclass Test -justanalyze -disjoint -disjoint-k 2 -disjoint-write-dots final -disjoint-write-ihms -disjoint-alias-file aliases.txt normal -enable-assertions
 
 all: $(PROGRAM).bin
index deec67596adbbfde356d1b10bc3d042b31118873..1e2aa7adce09b6b8dd112e11825e67d813c9d7c0 100644 (file)
@@ -19,14 +19,15 @@ public class Test {
   }   
 
   public static void addSomething( Foo f ) {
-    addBar( f );
+    f.b = new Bar();
+    //addBar( f );
   }
 
   public static void addBar( Foo g ) {
-    if( true ) {
-      g.b = new Bar();
-    } else {
-      g.b = new Bar();
-    }
+    //if( true ) {
+    //g.b = new Bar();
+    //} else {
+    //g.b = new Bar();
+    //}
   }
 }