got the hooks in place to get taints for rblocks
[IRC.git] / Robust / src / Analysis / Disjoint / ReachGraph.java
index cce95f49432da9bf5488e22fc24e54c75afd5626..127ca15937edfeb7e136b748b9e24d41b7524e12 100644 (file)
@@ -18,7 +18,7 @@ public class ReachGraph {
   // some frequently used reachability constants
   protected static final ReachState rstateEmpty        = ReachState.factory();
   protected static final ReachSet   rsetEmpty          = ReachSet.factory();
-  protected static final ReachSet   rsetWithEmptyState = ReachSet.factory( rstateEmpty );
+  protected static final ReachSet   rsetWithEmptyState = Canonical.makePredsTrue(ReachSet.factory( rstateEmpty ));
 
   // predicate constants
   protected static final ExistPred    predTrue   = ExistPred.factory(); // if no args, true
@@ -79,6 +79,8 @@ public class ReachGraph {
     return this.id2hrn.get( hrn.getID() ) == hrn;
   }
 
+  
+
 
 
   // the reason for this method is to have the option
@@ -90,7 +92,6 @@ public class ReachGraph {
     createNewHeapRegionNode( Integer        id,
                             boolean        isSingleObject,
                             boolean        isNewSummary,
-                            boolean        isFlagged,
                              boolean        isOutOfContext,
                             TypeDescriptor type,
                             AllocSite      allocSite,
@@ -100,8 +101,6 @@ public class ReachGraph {
                             String         description
                              ) {
 
-    boolean markForAnalysis = isFlagged;
-
     TypeDescriptor typeToUse = null;
     if( allocSite != null ) {
       typeToUse = allocSite.getType();
@@ -110,9 +109,18 @@ public class ReachGraph {
       typeToUse = type;
     }
 
-    if( allocSite != null && allocSite.getDisjointAnalysisId() != null ) {
+    boolean markForAnalysis = false;
+    if( allocSite != null && allocSite.isFlagged() ) {
       markForAnalysis = true;
     }
+    
+    if( allocSite == null ) {
+      assert !markForAnalysis;
+
+    } else if( markForAnalysis != allocSite.isFlagged() ) {
+      assert false;
+    }
+
 
     if( id == null ) {
       id = DisjointAnalysis.generateUniqueHeapRegionNodeID();
@@ -121,15 +129,17 @@ public class ReachGraph {
     if( inherent == null ) {
       if( markForAnalysis ) {
        inherent = 
-          ReachSet.factory(
-                           ReachState.factory(
-                                              ReachTuple.factory( id,
-                                                                  !isSingleObject,
-                                                                  ReachTuple.ARITY_ONE,
-                                                                  false // out-of-context
-                                                                  )
-                                              )
-                           );
+          Canonical.makePredsTrue(
+                                  ReachSet.factory(
+                                                   ReachState.factory(
+                                                                      ReachTuple.factory( id,
+                                                                                          !isSingleObject,
+                                                                                          ReachTuple.ARITY_ONE,
+                                                                                          false // out-of-context
+                                                                                          )
+                                                                      )
+                                                   )
+                                  );
       } else {
        inherent = rsetWithEmptyState;
       }
@@ -139,11 +149,8 @@ public class ReachGraph {
       alpha = inherent;
     }
 
-    if( preds == null ) {
-      // TODO: do this right?  For out-of-context nodes?
-      preds = ExistPredSet.factory();
-    }
-    
+    assert preds != null;
+
     HeapRegionNode hrn = new HeapRegionNode( id,
                                             isSingleObject,
                                             markForAnalysis,
@@ -218,6 +225,15 @@ public class ReachGraph {
        
     referencer.removeReferencee( edge );
     referencee.removeReferencer( edge );
+
+    // TODO
+
+//    int oldTaint=edge.getTaintIdentifier();
+//    if(referencer instanceof HeapRegionNode){
+//     depropagateTaintIdentifier((HeapRegionNode)referencer,oldTaint,new HashSet<HeapRegionNode>());
+//    }
+
+
   }
 
   protected void clearRefEdgesFrom( RefSrcNode     referencer,
@@ -293,6 +309,47 @@ public class ReachGraph {
     }
   }
 
+  // this is a common operation in many transfer functions: we want
+  // to add an edge, but if there is already such an edge we should
+  // merge the properties of the existing and the new edges
+  protected void addEdgeOrMergeWithExisting( RefEdge edgeNew ) {
+
+    RefSrcNode src = edgeNew.getSrc();
+    assert belongsToThis( src );
+
+    HeapRegionNode dst = edgeNew.getDst();
+    assert belongsToThis( dst );
+
+    // look to see if an edge with same field exists
+    // and merge with it, otherwise just add the edge
+    RefEdge edgeExisting = src.getReferenceTo( dst, 
+                                               edgeNew.getType(),
+                                               edgeNew.getField() 
+                                               );
+       
+    if( edgeExisting != null ) {
+      edgeExisting.setBeta(
+                           Canonical.unionORpreds( edgeExisting.getBeta(),
+                                                   edgeNew.getBeta()
+                                                   )
+                           );
+      edgeExisting.setPreds(
+                            Canonical.join( edgeExisting.getPreds(),
+                                            edgeNew.getPreds()
+                                            )
+                            );
+      edgeExisting.setTaints(
+                             Canonical.unionORpreds( edgeExisting.getTaints(),
+                                                     edgeNew.getTaints()
+                                                     )
+                             );
+      
+    } else {                     
+      addRefEdge( src, dst, edgeNew );
+    }
+  }
+
+
 
   ////////////////////////////////////////////////////
   //
@@ -413,10 +470,11 @@ public class ReachGraph {
                                        tdNewEdge,
                                        null,
                                        Canonical.intersection( betaY, betaHrn ),
-                                       predsTrue
+                                       predsTrue,
+                                       edgeY.getTaints()
                                        );
-       
-       addRefEdge( lnX, hrnHrn, edgeNew );
+
+        addEdgeOrMergeWithExisting( edgeNew );
       }
     }
 
@@ -557,37 +615,21 @@ public class ReachGraph {
                            hrnY.getType()
                            );  
 
-       RefEdge edgeNew = new RefEdge( hrnX,
-                                       hrnY,
-                                       tdNewEdge,
-                                       f.getSymbol(),
-                                       Canonical.pruneBy( edgeY.getBeta(),
-                                                          hrnX.getAlpha() 
-                                                          ),
-                                       predsTrue
-                                       );
+       RefEdge edgeNew = 
+          new RefEdge( hrnX,
+                       hrnY,
+                       tdNewEdge,
+                       f.getSymbol(),
+                       Canonical.makePredsTrue(
+                                               Canonical.pruneBy( edgeY.getBeta(),
+                                                                  hrnX.getAlpha() 
+                                                                  )
+                                               ),
+                       predsTrue,
+                       edgeY.getTaints()
+                       );
 
-       // look to see if an edge with same field exists
-       // and merge with it, otherwise just add the edge
-       RefEdge edgeExisting = hrnX.getReferenceTo( hrnY, 
-                                                    tdNewEdge,
-                                                    f.getSymbol() );
-       
-       if( edgeExisting != null ) {
-         edgeExisting.setBeta(
-                               Canonical.union( edgeExisting.getBeta(),
-                                                edgeNew.getBeta()
-                                                )
-                               );
-          edgeExisting.setPreds(
-                                Canonical.join( edgeExisting.getPreds(),
-                                                edgeNew.getPreds()
-                                                )
-                                );
-       
-        } else {                         
-         addRefEdge( hrnX, hrnY, edgeNew );
-       }
+        addEdgeOrMergeWithExisting( edgeNew );
       }
     }
 
@@ -653,7 +695,8 @@ public class ReachGraph {
                    type,                 // type
                    null,                 // field name
                    hrnNewest.getAlpha(), // beta
-                   predsTrue             // predicates
+                   predsTrue,            // predicates
+                   TaintSet.factory()    // taints
                    );
 
     addRefEdge( lnX, hrnNewest, edgeNew );
@@ -769,25 +812,12 @@ public class ReachGraph {
 
     if( hrnSummary == null ) {
 
-      boolean hasFlags = false;
-      if( as.getType().isClass() ) {
-       hasFlags = as.getType().getClassDesc().hasFlags();
-      }
-      
-      if( as.getFlag() ){
-        hasFlags = as.getFlag();
-      }
-
       String strDesc = as.toStringForDOT()+"\\nsummary";
-      if( shadow ) {
-        strDesc += " shadow";
-      }
 
       hrnSummary = 
         createNewHeapRegionNode( idSummary,    // id or null to generate a new one 
                                  false,        // single object?                
-                                 true,         // summary?      
-                                 hasFlags,     // flagged?
+                                 true,         // summary?                       
                                  false,        // out-of-context?
                                  as.getType(), // type                          
                                  as,           // allocation site                       
@@ -817,24 +847,11 @@ public class ReachGraph {
     
     if( hrnIth == null ) {
 
-      boolean hasFlags = false;
-      if( as.getType().isClass() ) {
-        hasFlags = as.getType().getClassDesc().hasFlags();
-      }
-      
-      if( as.getFlag() ){
-        hasFlags = as.getFlag();
-      }
-
       String strDesc = as.toStringForDOT()+"\\n"+i+" oldest";
-      if( shadow ) {
-        strDesc += " shadow";
-      }
 
       hrnIth = createNewHeapRegionNode( idIth,        // id or null to generate a new one 
                                         true,        // single object?                  
                                         false,       // summary?                        
-                                        hasFlags,     // flagged?                       
                                         false,        // out-of-context?
                                         as.getType(), // type                           
                                         as,          // allocation site                         
@@ -881,7 +898,7 @@ public class ReachGraph {
        // otherwise an edge from the referencer to hrnSummary exists already
        // and the edge referencer->hrn should be merged with it
        edgeSummary.setBeta( 
-                            Canonical.union( edgeMerged.getBeta(),
+                            Canonical.unionORpreds( edgeMerged.getBeta(),
                                              edgeSummary.getBeta() 
                                              ) 
                              );
@@ -915,7 +932,7 @@ public class ReachGraph {
        // otherwise an edge from the referencer to alpha_S exists already
        // and the edge referencer->alpha_K should be merged with it
        edgeSummary.setBeta( 
-                            Canonical.union( edgeMerged.getBeta(),
+                            Canonical.unionORpreds( edgeMerged.getBeta(),
                                              edgeSummary.getBeta() 
                                              ) 
                              );
@@ -929,7 +946,7 @@ public class ReachGraph {
 
     // then merge hrn reachability into hrnSummary
     hrnSummary.setAlpha( 
-                        Canonical.union( hrnSummary.getAlpha(),
+                        Canonical.unionORpreds( hrnSummary.getAlpha(),
                                          hrn.getAlpha() 
                                          )
                          );
@@ -1080,8 +1097,10 @@ public class ReachGraph {
        Iterator<ChangeTuple> itrCprime = C.iterator();
        while( itrCprime.hasNext() ) {
          ChangeTuple c = itrCprime.next();
-         if( edgeF.getBeta().contains( c.getSetToMatch() ) ) {
-           changesToPass = Canonical.union( changesToPass, c );
+         if( edgeF.getBeta().containsIgnorePreds( c.getStateToMatch() ) 
+              != null
+              ) {
+           changesToPass = Canonical.add( changesToPass, c );
          }
        }
 
@@ -1123,7 +1142,7 @@ public class ReachGraph {
       // but this propagation may be only one of many concurrent
       // possible changes, so keep a running union with the node's
       // partially updated new alpha set
-      n.setAlphaNew( Canonical.union( n.getAlphaNew(),
+      n.setAlphaNew( Canonical.unionORpreds( n.getAlphaNew(),
                                       localDelta 
                                       )
                      );
@@ -1160,8 +1179,10 @@ public class ReachGraph {
       Iterator<ChangeTuple> itrC = C.iterator();
       while( itrC.hasNext() ) {
        ChangeTuple c = itrC.next();
-       if( edgeE.getBeta().contains( c.getSetToMatch() ) ) {
-         changesToPass = Canonical.union( changesToPass, c );
+       if( edgeE.getBeta().containsIgnorePreds( c.getStateToMatch() ) 
+            != null
+            ) {
+         changesToPass = Canonical.add( changesToPass, c );
        }
       }
 
@@ -1212,7 +1233,7 @@ public class ReachGraph {
       // but this propagation may be only one of many concurrent
       // possible changes, so keep a running union with the edge's
       // partially updated new beta set
-      e.setBetaNew( Canonical.union( e.getBetaNew(),
+      e.setBetaNew( Canonical.unionORpreds( e.getBetaNew(),
                                      localDelta  
                                      )
                     );
@@ -1222,6 +1243,43 @@ public class ReachGraph {
   }
 
 
+  public void taintLiveTemps( FlatSESEEnterNode sese, 
+                              Set<TempDescriptor> liveTemps
+                              ) {
+
+    System.out.println( "At "+sese+" with: "+liveTemps );
+
+    Iterator<TempDescriptor> tdItr = liveTemps.iterator();
+    while( tdItr.hasNext() ) {
+      TempDescriptor td = tdItr.next();
+      VariableNode   vn = td2vn.get( td );
+
+      Iterator<RefEdge> reItr = vn.iteratorToReferencees();
+      while( reItr.hasNext() ) {
+        RefEdge re = reItr.next();
+
+        // these new sese (rblock) taints should
+        // have empty predicates so they never propagate
+        // out to callers
+        Taint t = Taint.factory( sese,
+                                 td,
+                                 re.getDst().getAllocSite(),
+                                 ExistPredSet.factory()
+                                 );
+
+        re.setTaints( Canonical.add( re.getTaints(),
+                                     t 
+                                     )
+                      );
+      }
+    }
+  }
+
+  public void removeInContextTaints( FlatSESEEnterNode sese ) {
+    
+  }
+
+
   // used in makeCalleeView below to decide if there is
   // already an appropriate out-of-context edge in a callee
   // view graph for merging, or null if a new one will be added
@@ -1280,15 +1338,9 @@ public class ReachGraph {
 
   // used below to convert a ReachSet to its callee-context
   // equivalent with respect to allocation sites in this graph
-  protected ReachSet toCalleeContext( Set<ReachTuple> oocTuples,
-                                      ReachSet        rs,
-                                      Integer         hrnID,
-                                      TempDescriptor  tdSrc,
-                                      Integer         hrnSrcID,
-                                      Integer         hrnDstID,
-                                      TypeDescriptor  type,
-                                      String          field,
-                                      boolean         outOfContext
+  protected ReachSet toCalleeContext( ReachSet      rs,
+                                      ExistPredSet  preds,
+                                      Set<HrnIdOoc> oocHrnIdOoc2callee
                                       ) {
     ReachSet out = ReachSet.factory();
    
@@ -1307,9 +1359,13 @@ public class ReachGraph {
         while( rtItr.hasNext() ) {
           ReachTuple rt = rtItr.next();
 
-          // only translate this tuple if it is in the out-context bag
-          if( !oocTuples.contains( rt ) ) {
-            stateNew = Canonical.union( stateNew, rt );
+          // only translate this tuple if it is
+          // in the out-callee-context bag
+          HrnIdOoc hio = new HrnIdOoc( rt.getHrnID(),
+                                       rt.isOutOfContext()
+                                       );
+          if( !oocHrnIdOoc2callee.contains( hio ) ) {
+            stateNew = Canonical.add( stateNew, rt );
             continue;
           }
 
@@ -1331,20 +1387,20 @@ public class ReachGraph {
       
           if( age == AllocSite.AGE_notInThisSite ) {
             // things not from the site just go back in
-            stateNew = Canonical.union( stateNew, rt );
+            stateNew = Canonical.add( stateNew, rt );
 
           } else if( age == AllocSite.AGE_summary ||
                      rt.isOutOfContext()
                      ) {
             // the in-context summary and all existing out-of-context
             // stuff all become
-            stateNew = Canonical.union( stateNew,
-                                        ReachTuple.factory( as.getSummary(),
-                                                            true, // multi
-                                                            rt.getArity(),
-                                                            true  // out-of-context
-                                                            )
-                                        );
+            stateNew = Canonical.add( stateNew,
+                                      ReachTuple.factory( as.getSummary(),
+                                                          true, // multi
+                                                          rt.getArity(),
+                                                          true  // out-of-context
+                                                          )
+                                      );
           } else {
             // otherwise everything else just goes to an out-of-context
             // version, everything else the same
@@ -1353,46 +1409,20 @@ public class ReachGraph {
 
             assert !rt.isMultiObject();
 
-            stateNew = Canonical.union( stateNew,
-                                        ReachTuple.factory( rt.getHrnID(),
-                                                            rt.isMultiObject(),
-                                                            rt.getArity(),
-                                                            true  // out-of-context
-                                                            )
-                                        );        
+            stateNew = Canonical.add( stateNew,
+                                      ReachTuple.factory( rt.getHrnID(),
+                                                          rt.isMultiObject(),
+                                                          rt.getArity(),
+                                                          true  // out-of-context
+                                                          )
+                                      );        
           }
         }
         
         stateCallee = stateNew;
       }
-
-
-      ExistPredSet preds;
-
-      if( outOfContext ) {
-        preds = predsEmpty;
-      } else {
-        ExistPred pred;
-        if( hrnID != null ) {
-          assert tdSrc    == null;
-          assert hrnSrcID == null;
-          assert hrnDstID == null;
-          pred = ExistPred.factory( hrnID, 
-                                    stateCaller );
-        } else {
-          assert tdSrc != null || hrnSrcID != null;
-          assert hrnDstID != null;
-          pred = ExistPred.factory( tdSrc,
-                                    hrnSrcID,
-                                    hrnDstID,
-                                    type,
-                                    field,
-                                    stateCaller,
-                                    false );
-        }
-        preds = ExistPredSet.factory( pred );
-      }
       
+      // attach the passed in preds
       stateCallee = Canonical.attach( stateCallee,
                                       preds );
 
@@ -1413,6 +1443,12 @@ public class ReachGraph {
                      ) {
     ReachSet out = ReachSet.factory();
 
+    // when the mapping is null it means there were no
+    // predicates satisfied
+    if( calleeStatesSatisfied == null ) {
+      return out;
+    }
+
     Iterator<ReachState> itr = rs.iterator();
     while( itr.hasNext() ) {
       ReachState stateCallee = itr.next();
@@ -1427,8 +1463,8 @@ public class ReachGraph {
         Iterator<AllocSite> asItr = allocSites.iterator();
         while( asItr.hasNext() ) {
           AllocSite as = asItr.next();
-          rsCaller = Canonical.toCallerContext( rs, as );
-        }
+          rsCaller = Canonical.toCallerContext( rsCaller, as );
+        }     
         
         // then before adding each derived, now caller-context
         // states to the output, attach the appropriate pred
@@ -1439,17 +1475,18 @@ public class ReachGraph {
           stateCaller = Canonical.attach( stateCaller,
                                           calleeStatesSatisfied.get( stateCallee )
                                           );        
-          out = Canonical.union( out,
-                                 stateCaller
-                                 );
+          out = Canonical.add( out,
+                               stateCaller
+                               );
         }
       }
-    }
-    
+    }    
+
     assert out.isCanonical();
     return out;
   }
 
+
   // used below to convert a ReachSet to an equivalent
   // version with shadow IDs merged into unshadowed IDs
   protected ReachSet unshadow( ReachSet rs ) {
@@ -1464,6 +1501,45 @@ public class ReachGraph {
   }
 
 
+  // used below to convert a TaintSet to its caller-context
+  // equivalent, just eliminate Taints with bad preds
+  protected TaintSet 
+    toCallerContext( TaintSet                       ts,
+                     Hashtable<Taint, ExistPredSet> calleeTaintsSatisfied 
+                     ) {
+    TaintSet out = TaintSet.factory();
+
+    // when the mapping is null it means there were no
+    // predicates satisfied
+    if( calleeTaintsSatisfied == null ) {
+      return out;
+    }
+
+    Iterator<Taint> itr = ts.iterator();
+    while( itr.hasNext() ) {
+      Taint tCallee = itr.next();
+
+      if( calleeTaintsSatisfied.containsKey( tCallee ) ) {
+        
+        Taint tCaller = 
+          Canonical.attach( Taint.factory( tCallee.sese,
+                                           tCallee.insetVar,
+                                           tCallee.allocSite ),
+                            calleeTaintsSatisfied.get( tCallee )
+                            );
+        out = Canonical.add( out,
+                             tCaller
+                             );
+      }     
+    }    
+    
+    assert out.isCanonical();
+    return out;
+  }
+
+
+
+
   // use this method to make a new reach graph that is
   // what heap the FlatMethod callee from the FlatCall 
   // would start with reaching from its arguments in
@@ -1538,9 +1614,10 @@ public class ReachGraph {
     } // end iterating over parameters as starting points
 
 
-    // now collect out-of-context reach tuples and 
-    // more out-of-context edges
-    Set<ReachTuple> oocTuples = new HashSet<ReachTuple>();
+    // now collect out-of-callee-context IDs and 
+    // map them to whether the ID is out of the caller
+    // context as well
+    Set<HrnIdOoc> oocHrnIdOoc2callee = new HashSet<HrnIdOoc>();
 
     Iterator<Integer> itrInContext = 
       callerNodeIDsCopiedToCallee.iterator();
@@ -1587,13 +1664,15 @@ public class ReachGraph {
           while( rtItr.hasNext() ) {
             ReachTuple rt = rtItr.next();
 
-            oocTuples.add( rt );
+            oocHrnIdOoc2callee.add( new HrnIdOoc( rt.getHrnID(),
+                                                  rt.isOutOfContext()
+                                                  )
+                                    );
           }
         }
       }
     }
 
-
     // the callee view is a new graph: DON'T MODIFY *THIS* graph
     ReachGraph rg = new ReachGraph();
 
@@ -1611,20 +1690,17 @@ public class ReachGraph {
       rg.createNewHeapRegionNode( hrnCaller.getID(),
                                   hrnCaller.isSingleObject(),
                                   hrnCaller.isNewSummary(),
-                                  hrnCaller.isFlagged(),
                                   false, // out-of-context?
                                   hrnCaller.getType(),
                                   hrnCaller.getAllocSite(),
-                                  toCalleeContext( oocTuples,
-                                                   hrnCaller.getInherent(),      // in state
-                                                   hrnCaller.getID(),            // node pred
-                                                   null, null, null, null, null, // edge pred
-                                                   false ),                      // ooc pred
-                                  toCalleeContext( oocTuples,
-                                                   hrnCaller.getAlpha(),         // in state
-                                                   hrnCaller.getID(),            // node pred
-                                                   null, null, null, null, null, // edge pred
-                                                   false ),                      // ooc pred
+                                  toCalleeContext( hrnCaller.getInherent(),
+                                                   preds,
+                                                   oocHrnIdOoc2callee 
+                                                   ),
+                                  toCalleeContext( hrnCaller.getAlpha(),
+                                                   preds,
+                                                   oocHrnIdOoc2callee 
+                                                   ),
                                   preds,
                                   hrnCaller.getDescription()
                                   );
@@ -1638,42 +1714,44 @@ public class ReachGraph {
       RefEdge   reArg = (RefEdge)   me.getKey();
       Integer   index = (Integer)   me.getValue();
       
-      TempDescriptor arg = fmCallee.getParameter( index );
+      VariableNode   vnCaller  = (VariableNode) reArg.getSrc();
+      TempDescriptor argCaller = vnCaller.getTempDescriptor();
       
-      VariableNode vnCallee = 
-        rg.getVariableNodeFromTemp( arg );
+      TempDescriptor paramCallee = fmCallee.getParameter( index );      
+      VariableNode   vnCallee    = rg.getVariableNodeFromTemp( paramCallee );
       
       HeapRegionNode hrnDstCaller = reArg.getDst();
       HeapRegionNode hrnDstCallee = rg.id2hrn.get( hrnDstCaller.getID() );
       assert hrnDstCallee != null;
       
       ExistPred pred =
-        ExistPred.factory( arg,
+        ExistPred.factory( argCaller,
                            null, 
                            hrnDstCallee.getID(),
                            reArg.getType(),
                            reArg.getField(),
                            null,
-                           false ); // out-of-context
+                           true,  // out-of-callee-context
+                           false  // out-of-caller-context
+                           );
       
       ExistPredSet preds = 
         ExistPredSet.factory( pred );
       
+      TaintSet taints =
+        TaintSet.factory();
+
       RefEdge reCallee = 
         new RefEdge( vnCallee,
                      hrnDstCallee,
                      reArg.getType(),
                      reArg.getField(),
-                     toCalleeContext( oocTuples,
-                                      reArg.getBeta(),      // in state
-                                      null,                 // node pred
-                                      arg,                  // edge pred
-                                      null,                 // edge pred
-                                      hrnDstCallee.getID(), // edge pred
-                                      reArg.getType(),      // edge pred
-                                      reArg.getField(),     // edge pred
-                                      false ),              // ooc pred
-                     preds
+                     toCalleeContext( reArg.getBeta(),
+                                      preds,
+                                      oocHrnIdOoc2callee
+                                      ),
+                     preds,
+                     taints
                      );
       
       rg.addRefEdge( vnCallee,
@@ -1703,7 +1781,9 @@ public class ReachGraph {
                            reCaller.getType(),
                            reCaller.getField(),
                            null,
-                           false ); // out-of-context
+                           false, // out-of-callee-context
+                           false  // out-of-caller-context
+                           );
       
       ExistPredSet preds = 
         ExistPredSet.factory( pred );
@@ -1713,16 +1793,12 @@ public class ReachGraph {
                      hrnDstCallee,
                      reCaller.getType(),
                      reCaller.getField(),
-                     toCalleeContext( oocTuples,
-                                      reCaller.getBeta(),   // in state
-                                      null,                 // node pred
-                                      null,                 // edge pred
-                                      hrnSrcCallee.getID(), // edge pred
-                                      hrnDstCallee.getID(), // edge pred
-                                      reCaller.getType(),   // edge pred
-                                      reCaller.getField(),  // edge pred
-                                      false ),              // ooc pred
-                     preds
+                     toCalleeContext( reCaller.getBeta(),
+                                      preds,
+                                      oocHrnIdOoc2callee 
+                                      ),
+                     preds,
+                     TaintSet.factory() // no taints for in-context edges
                      );
       
       rg.addRefEdge( hrnSrcCallee,
@@ -1744,19 +1820,30 @@ public class ReachGraph {
       ReachSet       oocReach;
       TempDescriptor oocPredSrcTemp = null;
       Integer        oocPredSrcID   = null;
+      boolean        outOfCalleeContext;
+      boolean        outOfCallerContext;
 
       if( rsnCaller instanceof VariableNode ) {
         VariableNode vnCaller = (VariableNode) rsnCaller;
         oocNodeType    = null;
         oocReach       = rsetEmpty;
         oocPredSrcTemp = vnCaller.getTempDescriptor();
+        outOfCalleeContext = true;
+        outOfCallerContext = false;
 
       } else {
         HeapRegionNode hrnSrcCaller = (HeapRegionNode) rsnCaller;
         assert !callerNodeIDsCopiedToCallee.contains( hrnSrcCaller.getID() );
         oocNodeType  = hrnSrcCaller.getType();
         oocReach     = hrnSrcCaller.getAlpha(); 
-        oocPredSrcID = hrnSrcCaller.getID();        
+        oocPredSrcID = hrnSrcCaller.getID();
+        if( hrnSrcCaller.isOutOfContext() ) {
+          outOfCalleeContext = false;
+          outOfCallerContext = true;
+        } else {
+          outOfCalleeContext = true;
+          outOfCallerContext = false;
+        }
       }
 
       ExistPred pred =
@@ -1766,7 +1853,9 @@ public class ReachGraph {
                            reCaller.getType(),
                            reCaller.getField(),
                            null,
-                           true ); // out-of-context
+                           outOfCalleeContext,
+                           outOfCallerContext
+                           );
 
       ExistPredSet preds = 
         ExistPredSet.factory( pred );
@@ -1798,22 +1887,17 @@ public class ReachGraph {
             rg.createNewHeapRegionNode( null,  // ID
                                         false, // single object?
                                         false, // new summary?
-                                        false, // flagged?
                                         true,  // out-of-context?
                                         oocNodeType,
                                         null,  // alloc site, shouldn't be used
-                                        toCalleeContext( oocTuples, 
-                                                         oocReach,                     // in state
-                                                         null,                         // node pred
-                                                         null, null, null, null, null, // edge pred
-                                                         true                          // ooc pred
-                                                         ), // inherent
-                                        toCalleeContext( oocTuples,
-                                                         oocReach,                     // in state
-                                                         null,                         // node pred
-                                                         null, null, null, null, null, // edge pred
-                                                         true                          // ooc pred
-                                                         ), // alpha
+                                        toCalleeContext( oocReach,               
+                                                         preds,
+                                                         oocHrnIdOoc2callee
+                                                         ),
+                                        toCalleeContext( oocReach,
+                                                         preds,
+                                                         oocHrnIdOoc2callee
+                                                         ),
                                         preds,
                                         "out-of-context"
                                         );       
@@ -1831,77 +1915,90 @@ public class ReachGraph {
               rg.createNewHeapRegionNode( oocHrnID,  // ID
                                           false, // single object?
                                           false, // new summary?
-                                          false, // flagged?
                                           true,  // out-of-context?
                                           oocNodeType,
                                           null,  // alloc site, shouldn't be used
-                                          toCalleeContext( oocTuples,
-                                                           oocReach,                     // in state
-                                                           null,                         // node pred
-                                                           null, null, null, null, null, // edge pred
-                                                           true                          // ooc pred
-                                                           ), // inherent
-                                          toCalleeContext( oocTuples,
-                                                           oocReach,                     // in state
-                                                           null,                         // node pred
-                                                           null, null, null, null, null, // edge pred
-                                                           true                          // ooc pred
-                                                           ), // alpha
+                                          toCalleeContext( oocReach,
+                                                           preds,
+                                                           oocHrnIdOoc2callee
+                                                           ),
+                                          toCalleeContext( oocReach,
+                                                           preds,
+                                                           oocHrnIdOoc2callee
+                                                           ),
                                           preds,
                                           "out-of-context"
                                           );       
+
+          } else {
+            // otherwise it is there, so merge reachability
+            hrnCalleeAndOutContext.setAlpha( Canonical.unionORpreds( hrnCalleeAndOutContext.getAlpha(),
+                                                                     toCalleeContext( oocReach,
+                                                                                      preds,
+                                                                                      oocHrnIdOoc2callee
+                                                                                      )
+                                                                     )
+                                             );
           }
         }
 
+        assert hrnCalleeAndOutContext.reachHasOnlyOOC();
+
         rg.addRefEdge( hrnCalleeAndOutContext,
                        hrnDstCallee,
                        new RefEdge( hrnCalleeAndOutContext,
                                     hrnDstCallee,
                                     reCaller.getType(),
                                     reCaller.getField(),
-                                    toCalleeContext( oocTuples,
-                                                     reCaller.getBeta(),   // in state
-                                                     null,                 // node pred
-                                                     oocPredSrcTemp,       // edge pred
-                                                     oocPredSrcID,         // edge pred
-                                                     hrnDstCaller.getID(), // edge pred
-                                                     reCaller.getType(),   // edge pred
-                                                     reCaller.getField(),  // edge pred
-                                                     false                 // ooc pred
+                                    toCalleeContext( reCaller.getBeta(),
+                                                     preds,
+                                                     oocHrnIdOoc2callee
                                                      ),
-                                    preds
+                                    preds,
+                                    TaintSet.factory() // no taints
                                     )
                        );              
         
         } else {
         // the out-of-context edge already exists
-        oocEdgeExisting.setBeta( Canonical.union( oocEdgeExisting.getBeta(),
-                                                  toCalleeContext( oocTuples,
-                                                                   reCaller.getBeta(),   // in state
-                                                                   null,                 // node pred
-                                                                   oocPredSrcTemp,       // edge pred
-                                                                   oocPredSrcID,         // edge pred
-                                                                   hrnDstCaller.getID(), // edge pred
-                                                                   reCaller.getType(),   // edge pred
-                                                                   reCaller.getField(),  // edge pred
-                                                                   false                 // ooc pred
-                                                                   )
+        oocEdgeExisting.setBeta( Canonical.unionORpreds( oocEdgeExisting.getBeta(),
+                                                         toCalleeContext( reCaller.getBeta(),
+                                                                          preds,
+                                                                          oocHrnIdOoc2callee
+                                                                          )
                                                   )
                                  );         
           
         oocEdgeExisting.setPreds( Canonical.join( oocEdgeExisting.getPreds(),
-                                                  reCaller.getPreds()
+                                                  preds
                                                   )
                                   );          
+
+        HeapRegionNode hrnCalleeAndOutContext =
+          (HeapRegionNode) oocEdgeExisting.getSrc();
+        hrnCalleeAndOutContext.setAlpha( Canonical.unionORpreds( hrnCalleeAndOutContext.getAlpha(),
+                                                                 toCalleeContext( oocReach,
+                                                                                  preds,
+                                                                                  oocHrnIdOoc2callee
+                                                                                  )
+                                                                 )
+                                         );
         
+        assert hrnCalleeAndOutContext.reachHasOnlyOOC();
       }                
     }
 
 
     if( writeDebugDOTs ) {    
-      try {
-        rg.writeGraph( "calleeview", true, false, false, true, true );
-      } catch( IOException e ) {}
+      debugGraphPrefix = String.format( "call%03d", debugCallSiteVisitCounter );
+      rg.writeGraph( debugGraphPrefix+"calleeview", 
+                     resolveMethodDebugDOTwriteLabels,    
+                     resolveMethodDebugDOTselectTemps,    
+                     resolveMethodDebugDOTpruneGarbage,
+                     resolveMethodDebugDOThideReach,
+                     resolveMethodDebugDOThideSubsetReach,
+                     resolveMethodDebugDOThidePreds,
+                     resolveMethodDebugDOThideEdgeTaints );      
     }
 
     return rg;
@@ -1911,6 +2008,21 @@ public class ReachGraph {
     new Hashtable<String, Integer>();
 
 
+  // useful since many graphs writes in the method call debug code
+  private static boolean resolveMethodDebugDOTwriteLabels     = true;
+  private static boolean resolveMethodDebugDOTselectTemps     = true;
+  private static boolean resolveMethodDebugDOTpruneGarbage    = true;
+  private static boolean resolveMethodDebugDOThideReach       = true;
+  private static boolean resolveMethodDebugDOThideSubsetReach = true;
+  private static boolean resolveMethodDebugDOThidePreds       = true;
+  private static boolean resolveMethodDebugDOThideEdgeTaints  = true;
+
+  static String debugGraphPrefix;
+  static int debugCallSiteVisitCounter;
+  static int debugCallSiteVisitStartCapture;
+  static int debugCallSiteNumVisitsToCapture;
+  static boolean debugCallSiteStopAfter;
+  
 
   public void 
     resolveMethodCall( FlatCall     fc,        
@@ -1920,18 +2032,36 @@ public class ReachGraph {
                        boolean      writeDebugDOTs
                        ) {
 
-
     if( writeDebugDOTs ) {
-      try {
-        rgCallee.writeGraph( "callee", 
-                             true, false, false, true, true );
-        writeGraph( "caller00In", 
-                    true, false, false, true, true, 
-                    callerNodeIDsCopiedToCallee );
-      } catch( IOException e ) {}
+      System.out.println( "  Writing out visit "+
+                          debugCallSiteVisitCounter+
+                          " to debug call site" );
+
+      debugGraphPrefix = String.format( "call%03d", 
+                                        debugCallSiteVisitCounter );
+      
+      rgCallee.writeGraph( debugGraphPrefix+"callee", 
+                           resolveMethodDebugDOTwriteLabels,    
+                           resolveMethodDebugDOTselectTemps,    
+                           resolveMethodDebugDOTpruneGarbage,   
+                           resolveMethodDebugDOThideReach,
+                           resolveMethodDebugDOThideSubsetReach,
+                           resolveMethodDebugDOThidePreds,
+                           resolveMethodDebugDOThideEdgeTaints );
+      
+      writeGraph( debugGraphPrefix+"caller00In",  
+                  resolveMethodDebugDOTwriteLabels,    
+                  resolveMethodDebugDOTselectTemps,    
+                  resolveMethodDebugDOTpruneGarbage,   
+                  resolveMethodDebugDOThideReach,
+                  resolveMethodDebugDOThideSubsetReach,
+                  resolveMethodDebugDOThidePreds,
+                  resolveMethodDebugDOThideEdgeTaints,
+                  callerNodeIDsCopiedToCallee );
     }
 
 
+
     // method call transfer function steps:
     // 1. Use current callee-reachable heap (CRH) to test callee 
     //    predicates and mark what will be coming in.
@@ -1945,7 +2075,6 @@ public class ReachGraph {
     // 5. Global sweep it.
 
 
-
     // 1. mark what callee elements have satisfied predicates
     Hashtable<HeapRegionNode, ExistPredSet> calleeNodesSatisfied =
       new Hashtable<HeapRegionNode, ExistPredSet>();
@@ -1953,12 +2082,22 @@ public class ReachGraph {
     Hashtable<RefEdge, ExistPredSet> calleeEdgesSatisfied =
       new Hashtable<RefEdge, ExistPredSet>();
 
-    Hashtable<ReachState, ExistPredSet> calleeStatesSatisfied =
-      new Hashtable<ReachState, ExistPredSet>();
+    Hashtable< HeapRegionNode, Hashtable<ReachState, ExistPredSet> >
+      calleeNode2calleeStatesSatisfied =
+      new Hashtable< HeapRegionNode, Hashtable<ReachState, ExistPredSet> >();
+
+    Hashtable< RefEdge, Hashtable<ReachState, ExistPredSet> >
+      calleeEdge2calleeStatesSatisfied =
+      new Hashtable< RefEdge, Hashtable<ReachState, ExistPredSet> >();
+
+    Hashtable< RefEdge, Hashtable<Taint, ExistPredSet> >
+      calleeEdge2calleeTaintsSatisfied =
+      new Hashtable< RefEdge, Hashtable<Taint, ExistPredSet> >();
 
     Hashtable< RefEdge, Set<RefSrcNode> > calleeEdges2oocCallerSrcMatches =
       new Hashtable< RefEdge, Set<RefSrcNode> >();
 
+
     Iterator meItr = rgCallee.id2hrn.entrySet().iterator();
     while( meItr.hasNext() ) {
       Map.Entry      me        = (Map.Entry)      meItr.next();
@@ -1973,6 +2112,7 @@ public class ReachGraph {
         hrnCallee.getPreds().isSatisfiedBy( this,
                                             callerNodeIDsCopiedToCallee
                                             );
+
       if( predsIfSatis != null ) {
         calleeNodesSatisfied.put( hrnCallee, predsIfSatis );
       } else {
@@ -1990,8 +2130,14 @@ public class ReachGraph {
           stateCallee.getPreds().isSatisfiedBy( this,
                                                 callerNodeIDsCopiedToCallee
                                                 );
-        if( predsIfSatis != null ) {
+        if( predsIfSatis != null ) {          
+          assert calleeNode2calleeStatesSatisfied.get( hrnCallee ) == null;
+          
+          Hashtable<ReachState, ExistPredSet> calleeStatesSatisfied =
+            new Hashtable<ReachState, ExistPredSet>();
           calleeStatesSatisfied.put( stateCallee, predsIfSatis );
+
+          calleeNode2calleeStatesSatisfied.put( hrnCallee, calleeStatesSatisfied );            
         } 
       }
 
@@ -2005,75 +2151,124 @@ public class ReachGraph {
         // have an (out-of-context heap region -> in-context heap region)
         // abstraction in the callEE, so its true we never need to
         // look at a (var node -> heap region) edge in callee to bring
-        // those over for the call site transfer.  What about (param var->heap region)
+        // those over for the call site transfer, except for the special
+        // case of *RETURN var* -> heap region edges.
+        // What about (param var->heap region)
         // edges in callee? They are dealt with below this loop.
-        // So, yes, at this point skip (var->region) edges in callee
+
         if( rsnCallee instanceof VariableNode ) {
-          continue;
-        }        
+          
+          // looking for the return-value variable only 
+          VariableNode vnCallee = (VariableNode) rsnCallee;
+          if( vnCallee.getTempDescriptor() != tdReturn ) {
+            continue;
+          }
+
+          TempDescriptor returnTemp = fc.getReturnTemp();
+          if( returnTemp == null ||
+              !DisjointAnalysis.shouldAnalysisTrack( returnTemp.getType() ) 
+              ) {
+            continue;
+          }
+                                         
+          // note that the assignment of the return value is to a
+          // variable in the caller which is out-of-context with
+          // respect to the callee
+          VariableNode vnLhsCaller = getVariableNodeFromTemp( returnTemp );
+          Set<RefSrcNode> rsnCallers = new HashSet<RefSrcNode>();
+          rsnCallers.add( vnLhsCaller  );
+          calleeEdges2oocCallerSrcMatches.put( reCallee, rsnCallers );
 
-        // first see if the source is out-of-context, and only
-        // proceed with this edge if we find some caller-context
-        // matches
-        HeapRegionNode hrnSrcCallee = (HeapRegionNode) rsnCallee;
-        boolean matchedOutOfContext = false;
+          
+        } else {
+          // for HeapRegionNode callee sources...
+
+          // first see if the source is out-of-context, and only
+          // proceed with this edge if we find some caller-context
+          // matches
+          HeapRegionNode hrnSrcCallee = (HeapRegionNode) rsnCallee;
+          boolean matchedOutOfContext = false;
+          
+          if( !hrnSrcCallee.isOutOfContext() ) {          
 
-        if( hrnSrcCallee.isOutOfContext() ) {          
+            predsIfSatis = 
+              hrnSrcCallee.getPreds().isSatisfiedBy( this,
+                                                     callerNodeIDsCopiedToCallee
+                                                     );          
+            if( predsIfSatis != null ) {
+              calleeNodesSatisfied.put( hrnSrcCallee, predsIfSatis );
+            } else {
+              // otherwise forget this edge
+              continue;
+            }          
+      
+          } else {
+            // hrnSrcCallee is out-of-context
 
-          assert !calleeEdges2oocCallerSrcMatches.containsKey( reCallee );
-          Set<RefSrcNode> rsnCallers = new HashSet<RefSrcNode>();            
+            assert !calleeEdges2oocCallerSrcMatches.containsKey( reCallee );
 
-          HeapRegionNode hrnDstCaller = this.id2hrn.get( hrnCallee.getID() );
-          Iterator<RefEdge> reDstItr = hrnDstCaller.iteratorToReferencers();
-          while( reDstItr.hasNext() ) {
-            // the edge and field (either possibly null) must match
-            RefEdge reCaller = reDstItr.next();
+            Set<RefSrcNode> rsnCallers = new HashSet<RefSrcNode>();            
 
-            if( !reCaller.typeEquals ( reCallee.getType()  ) ||
-                !reCaller.fieldEquals( reCallee.getField() ) 
-                ) {
+            // is the target node in the caller?
+            HeapRegionNode hrnDstCaller = this.id2hrn.get( hrnCallee.getID() );
+            if( hrnDstCaller == null ) {
               continue;
-            }
-            
-            RefSrcNode rsnCaller = reCaller.getSrc();
-            if( rsnCaller instanceof VariableNode ) {
-              // a variable node matches an OOC region with null type
-              if( hrnSrcCallee.getType() != null ) {
+            }          
+
+            Iterator<RefEdge> reDstItr = hrnDstCaller.iteratorToReferencers();
+            while( reDstItr.hasNext() ) {
+              // the edge and field (either possibly null) must match
+              RefEdge reCaller = reDstItr.next();
+
+              if( !reCaller.typeEquals ( reCallee.getType()  ) ||
+                  !reCaller.fieldEquals( reCallee.getField() ) 
+                  ) {
                 continue;
               }
+            
+              RefSrcNode rsnCaller = reCaller.getSrc();
+              if( rsnCaller instanceof VariableNode ) {
 
-            } else {
-              // otherwise types should match
-              HeapRegionNode hrnCallerSrc = (HeapRegionNode) rsnCaller;
-              if( hrnSrcCallee.getType() == null ) {
-                if( hrnCallerSrc.getType() != null ) {
+                // a variable node matches an OOC region with null type
+                if( hrnSrcCallee.getType() != null ) {
                   continue;
                 }
+
               } else {
-                if( !hrnSrcCallee.getType().equals( hrnCallerSrc.getType() ) ) {
-                  continue;
+                // otherwise types should match
+                HeapRegionNode hrnCallerSrc = (HeapRegionNode) rsnCaller;
+                if( hrnSrcCallee.getType() == null ) {
+                  if( hrnCallerSrc.getType() != null ) {
+                    continue;
+                  }
+                } else {
+                  if( !hrnSrcCallee.getType().equals( hrnCallerSrc.getType() ) ) {
+                    continue;
+                  }
                 }
               }
+
+              rsnCallers.add( rsnCaller );
+              matchedOutOfContext = true;
             }
 
-            rsnCallers.add( rsnCaller );
-            matchedOutOfContext = true;
+            if( !rsnCallers.isEmpty() ) {
+              calleeEdges2oocCallerSrcMatches.put( reCallee, rsnCallers );
+            }
           }
 
-          if( !rsnCallers.isEmpty() ) {
-            calleeEdges2oocCallerSrcMatches.put( reCallee, rsnCallers );
+          if( hrnSrcCallee.isOutOfContext() &&
+              !matchedOutOfContext ) {
+            continue;
           }
         }
 
-        if( hrnSrcCallee.isOutOfContext() &&
-            !matchedOutOfContext ) {
-          continue;
-        }
         
         predsIfSatis = 
           reCallee.getPreds().isSatisfiedBy( this,
                                              callerNodeIDsCopiedToCallee
                                              );
+
         if( predsIfSatis != null ) {
           calleeEdgesSatisfied.put( reCallee, predsIfSatis );
 
@@ -2088,68 +2283,49 @@ public class ReachGraph {
                                                     callerNodeIDsCopiedToCallee
                                                     );
             if( predsIfSatis != null ) {
+              assert calleeEdge2calleeStatesSatisfied.get( reCallee ) == null;
+              
+              Hashtable<ReachState, ExistPredSet> calleeStatesSatisfied =
+                new Hashtable<ReachState, ExistPredSet>();
               calleeStatesSatisfied.put( stateCallee, predsIfSatis );
+              
+              calleeEdge2calleeStatesSatisfied.put( reCallee, calleeStatesSatisfied );
             } 
           }
 
-        }        
-
-      }
-    }
-
-    // test param -> HRN edges, also
-    for( int i = 0; i < fmCallee.numParameters(); ++i ) {
-
-      // parameter defined here is the symbol in the callee
-      TempDescriptor tdParam  = fmCallee.getParameter( i );
-      VariableNode   vnCallee = rgCallee.getVariableNodeFromTemp( tdParam );
-
-      Iterator<RefEdge> reItr = vnCallee.iteratorToReferencees();
-      while( reItr.hasNext() ) {
-        RefEdge reCallee = reItr.next();
-        
-        ExistPredSet ifDst = 
-          reCallee.getDst().getPreds().isSatisfiedBy( this,
-                                                      callerNodeIDsCopiedToCallee
-                                                      );
-        if( ifDst == null ) {
-          continue;
-        }
-        
-        ExistPredSet predsIfSatis = 
-          reCallee.getPreds().isSatisfiedBy( this,
-                                             callerNodeIDsCopiedToCallee
-                                             );
-        if( predsIfSatis != null ) {
-          calleeEdgesSatisfied.put( reCallee, predsIfSatis );
+          // since the edge is coming over, find out which taints
+          // on it should come over, too          
+          Iterator<Taint> tItr = reCallee.getTaints().iterator();
+          while( tItr.hasNext() ) {
+            Taint tCallee = tItr.next();
 
-          // since the edge is coming over, find out which reach
-          // states on it should come over, too
-          Iterator<ReachState> stateItr = reCallee.getBeta().iterator();
-          while( stateItr.hasNext() ) {
-            ReachState stateCallee = stateItr.next();
-            
             predsIfSatis = 
-              stateCallee.getPreds().isSatisfiedBy( this,
-                                                    callerNodeIDsCopiedToCallee
-                                                    );
+              tCallee.getPreds().isSatisfiedBy( this,
+                                                callerNodeIDsCopiedToCallee
+                                                );
             if( predsIfSatis != null ) {
-              calleeStatesSatisfied.put( stateCallee, predsIfSatis );
+              assert calleeEdge2calleeTaintsSatisfied.get( reCallee ) == null;
+              
+              Hashtable<Taint, ExistPredSet> calleeTaintsSatisfied =
+                new Hashtable<Taint, ExistPredSet>();
+              calleeTaintsSatisfied.put( tCallee, predsIfSatis );
+              
+              calleeEdge2calleeTaintsSatisfied.put( reCallee, calleeTaintsSatisfied );
             } 
           }
-
         }        
       }
     }
 
-
-
-
     if( writeDebugDOTs ) {
-      try {
-        writeGraph( "caller20BeforeWipe", 
-                    true, false, false, true, true );
-      } catch( IOException e ) {}
+      writeGraph( debugGraphPrefix+"caller20BeforeWipe", 
+                  resolveMethodDebugDOTwriteLabels,    
+                  resolveMethodDebugDOTselectTemps,    
+                  resolveMethodDebugDOTpruneGarbage,   
+                  resolveMethodDebugDOThideReach,
+                  resolveMethodDebugDOThideSubsetReach,
+                  resolveMethodDebugDOThidePreds,
+                  resolveMethodDebugDOThideEdgeTaints );
     }
 
 
@@ -2165,16 +2341,34 @@ public class ReachGraph {
       wipeOut( hrnCaller, true );
     }
 
+    // if we are assigning the return value to something, clobber now
+    // as part of the wipe
+    TempDescriptor returnTemp = fc.getReturnTemp();
+    if( returnTemp != null && 
+        DisjointAnalysis.shouldAnalysisTrack( returnTemp.getType() ) 
+        ) {
+      
+      VariableNode vnLhsCaller = getVariableNodeFromTemp( returnTemp );
+      clearRefEdgesFrom( vnLhsCaller, null, null, true );
+    }
+
+
 
 
     if( writeDebugDOTs ) {
-      try {
-        writeGraph( "caller30BeforeAddingNodes", 
-                    true, false, false, true, true );
-      } catch( IOException e ) {}
+      writeGraph( debugGraphPrefix+"caller30BeforeAddingNodes", 
+                  resolveMethodDebugDOTwriteLabels,    
+                  resolveMethodDebugDOTselectTemps,    
+                  resolveMethodDebugDOTpruneGarbage,   
+                  resolveMethodDebugDOThideReach,
+                  resolveMethodDebugDOThideSubsetReach,
+                  resolveMethodDebugDOThidePreds,
+                  resolveMethodDebugDOThideEdgeTaints );
     }
 
 
+
+
     // 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
@@ -2208,12 +2402,11 @@ public class ReachGraph {
           createNewHeapRegionNode( hrnIDshadow,                // id or null to generate a new one 
                                    hrnCallee.isSingleObject(), // single object?                
                                    hrnCallee.isNewSummary(),   // summary?      
-                                   hrnCallee.isFlagged(),      // flagged?
                                    false,                      // out-of-context?
                                    hrnCallee.getType(),        // type                          
                                    hrnCallee.getAllocSite(),   // allocation site                       
                                    toCallerContext( hrnCallee.getInherent(),
-                                                    calleeStatesSatisfied  ),    // inherent reach
+                                                    calleeNode2calleeStatesSatisfied.get( hrnCallee ) ), // inherent reach
                                    null,                       // current reach                 
                                    predsEmpty,                 // predicates
                                    hrnCallee.getDescription()  // description
@@ -2223,7 +2416,7 @@ public class ReachGraph {
       }
 
       hrnCaller.setAlpha( toCallerContext( hrnCallee.getAlpha(),
-                                           calleeStatesSatisfied 
+                                           calleeNode2calleeStatesSatisfied.get( hrnCallee )
                                            )
                           );
 
@@ -2232,11 +2425,17 @@ public class ReachGraph {
 
 
 
+
+
     if( writeDebugDOTs ) {
-      try {
-        writeGraph( "caller31BeforeAddingEdges", 
-                    true, false, false, true, true );
-      } catch( IOException e ) {}
+      writeGraph( debugGraphPrefix+"caller31BeforeAddingEdges", 
+                  resolveMethodDebugDOTwriteLabels,    
+                  resolveMethodDebugDOTselectTemps,    
+                  resolveMethodDebugDOTpruneGarbage,   
+                  resolveMethodDebugDOThideReach,
+                  resolveMethodDebugDOThideSubsetReach,
+                  resolveMethodDebugDOThidePreds,
+                  resolveMethodDebugDOThideEdgeTaints );
     }
 
 
@@ -2251,6 +2450,7 @@ public class ReachGraph {
 
 
     // 3.b) callee -> callee edges AND out-of-context -> callee
+    //      which includes return temp -> callee edges now, too
     satisItr = calleeEdgesSatisfied.entrySet().iterator();
     while( satisItr.hasNext() ) {
       Map.Entry    me       = (Map.Entry)    satisItr.next();
@@ -2276,7 +2476,13 @@ public class ReachGraph {
       Set<RefSrcNode> oocCallers = 
         calleeEdges2oocCallerSrcMatches.get( reCallee );
 
-      boolean oocEdges = false;
+      if( rsnCallee instanceof HeapRegionNode ) {
+        HeapRegionNode hrnCalleeSrc = (HeapRegionNode) rsnCallee;
+        if( hrnCalleeSrc.isOutOfContext() ) {
+          assert oocCallers != null;
+        }
+      }
+
       
       if( oocCallers == null ) {
         // there are no out-of-context matches, so it's
@@ -2294,11 +2500,12 @@ public class ReachGraph {
             // shouldn't this NEVER HAPPEN?
             assert false;
           }
+
           rsnCallers.add( this.getVariableNodeFromTemp( tdArg ) );
-          oocEdges = true;
 
         } else {
           // otherwise source is in context, one region
+          
           HeapRegionNode hrnSrcCallee = (HeapRegionNode) rsnCallee;
 
           // translate an in-context node to shadow
@@ -2311,23 +2518,7 @@ public class ReachGraph {
           HeapRegionNode hrnSrcCallerShadow =
             this.id2hrn.get( hrnIDSrcShadow );
           
-          if( hrnSrcCallerShadow == null ) {
-            hrnSrcCallerShadow =
-              createNewHeapRegionNode( hrnIDSrcShadow,                // id or null to generate a new one 
-                                       hrnSrcCallee.isSingleObject(), // single object?                 
-                                       hrnSrcCallee.isNewSummary(),   // summary?       
-                                       hrnSrcCallee.isFlagged(),      // flagged?
-                                       false,                         // out-of-context?
-                                       hrnSrcCallee.getType(),        // type                           
-                                       hrnSrcCallee.getAllocSite(),   // allocation site                        
-                                       toCallerContext( hrnSrcCallee.getInherent(),
-                                                        calleeStatesSatisfied ),    // inherent reach
-                                       toCallerContext( hrnSrcCallee.getAlpha(),
-                                                        calleeStatesSatisfied ),       // current reach                 
-                                       predsEmpty,                    // predicates
-                                       hrnSrcCallee.getDescription()  // description
-                                       );                                        
-          }
+          assert hrnSrcCallerShadow != null;        
           
           rsnCallers.add( hrnSrcCallerShadow );
         }
@@ -2337,7 +2528,6 @@ public class ReachGraph {
         // that should NOT be translated to shadow nodes
         assert !oocCallers.isEmpty();
         rsnCallers.addAll( oocCallers );
-        oocEdges = true;
       }
 
       // now make all caller edges we've identified from
@@ -2352,75 +2542,66 @@ public class ReachGraph {
                                         reCallee.getType(),
                                         reCallee.getField(),
                                         toCallerContext( reCallee.getBeta(),
-                                                         calleeStatesSatisfied ),
-                                        preds
+                                                         calleeEdge2calleeStatesSatisfied.get( reCallee ) ),
+                                        preds,
+                                        toCallerContext( reCallee.getTaints(),
+                                                         calleeEdge2calleeTaintsSatisfied.get( reCallee ) )
                                         );
 
         ChangeSet cs = ChangeSet.factory();
         Iterator<ReachState> rsItr = reCaller.getBeta().iterator();
         while( rsItr.hasNext() ) {
-          ReachState   state = rsItr.next();
-          ExistPredSet preds2 = state.getPreds();
-          assert preds2.preds.size() == 1;
+          ReachState   state          = rsItr.next();
+          ExistPredSet predsPreCallee = state.getPreds();
 
           if( state.isEmpty() ) {
             continue;
           }
 
-          ExistPred pred = preds2.preds.iterator().next();
-          ReachState old = pred.ne_state;
-
-          if( old == null ) {
-            old = rstateEmpty;
-          }
+          Iterator<ExistPred> predItr = predsPreCallee.iterator();
+          while( predItr.hasNext() ) {            
+            ExistPred pred = predItr.next();
+            ReachState old = pred.ne_state;
 
-          assert old != null;
+            if( old == null ) {
+              old = rstateEmpty;
+            }
 
-          cs = Canonical.union( cs,
+            cs = Canonical.add( cs,
                                 ChangeTuple.factory( old,
                                                      state
                                                      )
                                 );
-        }
-        
-        // look to see if an edge with same field exists
-        // and merge with it, otherwise just add the edge
-        RefEdge edgeExisting = rsnCaller.getReferenceTo( hrnDstCaller,
-                                                         reCallee.getType(),
-                                                         reCallee.getField()
-                                                         );    
-        if( edgeExisting != null ) {
-          edgeExisting.setBeta(
-                               Canonical.union( edgeExisting.getBeta(),
-                                                reCaller.getBeta()
-                                                )
-                               );
-          edgeExisting.setPreds(
-                                Canonical.join( edgeExisting.getPreds(),
-                                                reCaller.getPreds()
-                                                )
-                                );
-
-          // for reach propagation
-          if( !cs.isEmpty() ) {
-            edgePlannedChanges.put( 
-                                   edgeExisting, 
-                                   Canonical.union( edgePlannedChanges.get( edgeExisting ),
-                                                    cs
-                                                    ) 
-                                    );
           }
-          
-        } else {                         
-          addRefEdge( rsnCaller, hrnDstCaller, reCaller );     
+        }
 
-          // for reach propagation
-          if( !cs.isEmpty() ) {
+        // we're just going to use the convenient "merge-if-exists"
+        // edge call below, but still take a separate look if there
+        // is an existing caller edge to build change sets properly
+        if( !cs.isEmpty() ) {
+          RefEdge edgeExisting = rsnCaller.getReferenceTo( hrnDstCaller,
+                                                           reCallee.getType(),
+                                                           reCallee.getField()
+                                                           );  
+          if( edgeExisting != null ) {
+            ChangeSet csExisting = edgePlannedChanges.get( edgeExisting );
+            if( csExisting == null ) {
+              csExisting = ChangeSet.factory();
+            }
+            edgePlannedChanges.put( edgeExisting, 
+                                    Canonical.union( csExisting,
+                                                     cs
+                                                     ) 
+                                    );                    
+          } else {                       
             edgesForPropagation.add( reCaller );
             assert !edgePlannedChanges.containsKey( reCaller );
-            edgePlannedChanges.put( reCaller, cs );
+            edgePlannedChanges.put( reCaller, cs );        
           }
         }
+
+        // then add new caller edge or merge
+        addEdgeOrMergeWithExisting( reCaller );
       }
     }
 
@@ -2429,118 +2610,45 @@ public class ReachGraph {
 
 
     if( writeDebugDOTs ) {
-      try {
-        writeGraph( "caller35BeforeAssignReturnValue", 
-                    true, false, false, true, true );
-      } catch( IOException e ) {}
+      writeGraph( debugGraphPrefix+"caller38propagateReach", 
+                  resolveMethodDebugDOTwriteLabels,    
+                  resolveMethodDebugDOTselectTemps,    
+                  resolveMethodDebugDOTpruneGarbage,   
+                  resolveMethodDebugDOThideReach,
+                  resolveMethodDebugDOThideSubsetReach,
+                  resolveMethodDebugDOThidePreds,
+                  resolveMethodDebugDOThideEdgeTaints );
     }
 
+    // propagate callee reachability changes to the rest
+    // of the caller graph edges
+    HashSet<RefEdge> edgesUpdated = new HashSet<RefEdge>();
+  
+    propagateTokensOverEdges( edgesForPropagation, // source edges
+                              edgePlannedChanges,  // map src edge to change set
+                              edgesUpdated );      // list of updated edges
+    
+    // commit beta' (beta<-betaNew)
+    Iterator<RefEdge> edgeItr = edgesUpdated.iterator();
+    while( edgeItr.hasNext() ) {
+      edgeItr.next().applyBetaNew();
+    }
 
 
-    // TODO: WAIT! THIS SHOULD BE MERGED INTO OTHER PARTS, BECAUSE
-    // AS IT IS WE'RE NOT VERIFYING PREDICATES OF RETURN VALUE
-    // EDGES, JUST BRINGING THEM ALL!  It'll work for now, over approximation
-    
-    // 3.d) handle return value assignment if needed
-    TempDescriptor returnTemp = fc.getReturnTemp();
-    if( returnTemp != null && !returnTemp.getType().isImmutable() ) {
-
-      VariableNode vnLhsCaller = getVariableNodeFromTemp( returnTemp );
-      clearRefEdgesFrom( vnLhsCaller, null, null, true );
-
-      VariableNode vnReturnCallee = rgCallee.getVariableNodeFromTemp( tdReturn );
-      Iterator<RefEdge> reCalleeItr = vnReturnCallee.iteratorToReferencees();
-      while( reCalleeItr.hasNext() ) {
-       RefEdge        reCallee     = reCalleeItr.next();
-       HeapRegionNode hrnDstCallee = reCallee.getDst();
-
-       // some edge types are not possible return values when we can
-       // see what type variable we are assigning it to
-       if( !isSuperiorType( returnTemp.getType(), reCallee.getType() ) ) {
-         System.out.println( "*** NOT EXPECTING TO SEE THIS: Throwing out "+
-                              reCallee+" for return temp "+returnTemp );
-         // prune
-         continue;
-       }       
-
-        AllocSite asDst = hrnDstCallee.getAllocSite();
-        allocSites.add( asDst );
-
-        Integer hrnIDDstShadow = asDst.getShadowIDfromID( hrnDstCallee.getID() );
-
-        HeapRegionNode hrnDstCaller = id2hrn.get( hrnIDDstShadow );
-        if( hrnDstCaller == null ) {
-          hrnDstCaller =
-            createNewHeapRegionNode( hrnIDDstShadow,                // id or null to generate a new one 
-                                     hrnDstCallee.isSingleObject(), // single object?           
-                                     hrnDstCallee.isNewSummary(),   // summary?         
-                                     hrnDstCallee.isFlagged(),      // flagged?
-                                     false,                         // out-of-context?
-                                     hrnDstCallee.getType(),        // type                             
-                                     hrnDstCallee.getAllocSite(),   // allocation site                  
-                                     toCallerContext( hrnDstCallee.getInherent(),
-                                                      calleeStatesSatisfied  ),    // inherent reach
-                                     toCallerContext( hrnDstCallee.getAlpha(),
-                                                      calleeStatesSatisfied  ),    // current reach                 
-                                     predsTrue,                     // predicates
-                                     hrnDstCallee.getDescription()  // description
-                                     );                                        
-        } else {
-          assert hrnDstCaller.isWiped();
-        }
-
-        TypeDescriptor tdNewEdge =
-          mostSpecificType( reCallee.getType(),
-                            hrnDstCallee.getType(),
-                            hrnDstCaller.getType()
-                            );       
-
-        RefEdge reCaller = new RefEdge( vnLhsCaller,
-                                        hrnDstCaller,
-                                        tdNewEdge,
-                                        null,
-                                        toCallerContext( reCallee.getBeta(),
-                                                         calleeStatesSatisfied ),
-                                        predsTrue
-                                        );
-
-        addRefEdge( vnLhsCaller, hrnDstCaller, reCaller );
-      }
-    }
-
-
-
-    if( writeDebugDOTs ) {
-      try {
-        writeGraph( "caller38propagateReach", 
-                    true, false, false, true, true );
-      } catch( IOException e ) {}
-    }
-
-    // propagate callee reachability changes to the rest
-    // of the caller graph edges
-    HashSet<RefEdge> edgesUpdated = new HashSet<RefEdge>();
-  
-    propagateTokensOverEdges( edgesForPropagation, // source edges
-                              edgePlannedChanges,  // map src edge to change set
-                              edgesUpdated );      // list of updated edges
-    
-    // commit beta' (beta<-betaNew)
-    Iterator<RefEdge> edgeItr = edgesUpdated.iterator();
-    while( edgeItr.hasNext() ) {
-      edgeItr.next().applyBetaNew();
-    }
-
 
 
 
 
 
     if( writeDebugDOTs ) {
-      try {
-        writeGraph( "caller40BeforeShadowMerge", 
-                    true, false, false, true, true );
-      } catch( IOException e ) {}
+      writeGraph( debugGraphPrefix+"caller40BeforeShadowMerge", 
+                  resolveMethodDebugDOTwriteLabels,    
+                  resolveMethodDebugDOTselectTemps,    
+                  resolveMethodDebugDOTpruneGarbage,   
+                  resolveMethodDebugDOThideReach,
+                  resolveMethodDebugDOThideSubsetReach,
+                  resolveMethodDebugDOThidePreds,
+                  resolveMethodDebugDOThideEdgeTaints );
     }
     
 
@@ -2633,11 +2741,19 @@ public class ReachGraph {
     }
 
 
+
+
+
+
     if( writeDebugDOTs ) {
-      try {
-        writeGraph( "caller45BeforeUnshadow", 
-                    true, false, false, true, true );
-      } catch( IOException e ) {}
+      writeGraph( debugGraphPrefix+"caller45BeforeUnshadow", 
+                  resolveMethodDebugDOTwriteLabels,    
+                  resolveMethodDebugDOTselectTemps,    
+                  resolveMethodDebugDOTpruneGarbage,   
+                  resolveMethodDebugDOThideReach,
+                  resolveMethodDebugDOThideSubsetReach,
+                  resolveMethodDebugDOThidePreds,
+                  resolveMethodDebugDOThideEdgeTaints );
     }
     
     
@@ -2657,11 +2773,16 @@ public class ReachGraph {
     
 
 
+
     if( writeDebugDOTs ) {
-      try {
-        writeGraph( "caller50BeforeGlobalSweep", 
-                    true, false, false, true, true );
-      } catch( IOException e ) {}
+      writeGraph( debugGraphPrefix+"caller50BeforeGlobalSweep", 
+                  resolveMethodDebugDOTwriteLabels,    
+                  resolveMethodDebugDOTselectTemps,    
+                  resolveMethodDebugDOTpruneGarbage,   
+                  resolveMethodDebugDOThideReach,
+                  resolveMethodDebugDOThideSubsetReach,
+                  resolveMethodDebugDOThidePreds,
+                  resolveMethodDebugDOThideEdgeTaints );
     }
 
 
@@ -2671,12 +2792,15 @@ public class ReachGraph {
     }
     
 
-
     if( writeDebugDOTs ) {
-      try {
-        writeGraph( "caller90AfterTransfer", 
-                    true, false, false, true, true );
-      } catch( IOException e ) {}
+      writeGraph( debugGraphPrefix+"caller90AfterTransfer", 
+                  resolveMethodDebugDOTwriteLabels,    
+                  resolveMethodDebugDOTselectTemps,    
+                  resolveMethodDebugDOTpruneGarbage,   
+                  resolveMethodDebugDOThideReach,
+                  resolveMethodDebugDOThideSubsetReach,
+                  resolveMethodDebugDOThidePreds,
+                  resolveMethodDebugDOThideEdgeTaints );     
     }
   } 
 
@@ -2839,10 +2963,13 @@ public class ReachGraph {
        assert rsetEmpty.equals( edge.getBetaNew() );
       }      
 
-      // calculate boldB for this flagged node, or out-of-context node
+      // make a mapping of IDs to heap regions they propagate from
       if( hrn.isFlagged() ) {
         assert !hrn.isOutOfContext();
         assert !icID2srcs.containsKey( hrn.getID() );
+
+        // in-context flagged node IDs simply propagate from the
+        // node they name
         Set<HeapRegionNode> srcs = new HashSet<HeapRegionNode>();
         srcs.add( hrn );
         icID2srcs.put( hrn.getID(), srcs );
@@ -2851,6 +2978,13 @@ public class ReachGraph {
       if( hrn.isOutOfContext() ) {
        assert !hrn.isFlagged();
 
+        // the reachability states on an out-of-context
+        // node are not really important (combinations of
+        // IDs or arity)--what matters is that the states
+        // specify which nodes this out-of-context node
+        // stands in for.  For example, if the state [17?, 19*]
+        // appears on the ooc node, it may serve as a source
+        // for node 17? and a source for node 19.
         Iterator<ReachState> stateItr = hrn.getAlpha().iterator();
         while( stateItr.hasNext() ) {
           ReachState state = stateItr.next();
@@ -2935,20 +3069,22 @@ public class ReachGraph {
                                                             );
           
             if( prevResult == null || 
-                Canonical.union( prevResult,
-                                 intersection ).size() > prevResult.size() ) {
+                Canonical.unionORpreds( prevResult,
+                                        intersection ).size() 
+                > prevResult.size() 
+                ) {
             
               if( prevResult == null ) {
                 boldB_f.put( edgePrime, 
-                             Canonical.union( edgePrime.getBeta(),
-                                              intersection 
-                                              )
+                             Canonical.unionORpreds( edgePrime.getBeta(),
+                                                     intersection 
+                                                     )
                              );
               } else {
                 boldB_f.put( edgePrime, 
-                             Canonical.union( prevResult,
-                                              intersection 
-                                              )
+                             Canonical.unionORpreds( prevResult,
+                                                     intersection 
+                                                     )
                              );
               }
               workSetEdges.add( edgePrime );   
@@ -3025,14 +3161,20 @@ public class ReachGraph {
             if( rtOld.isOutOfContext() ) {
               B = boldBooc.get( rtOld.getHrnID() ); 
             } else {
-              assert id2hrn.containsKey( rtOld.getHrnID() );
+
+              if( !id2hrn.containsKey( rtOld.getHrnID() ) ) {
+                // let symbols not in the graph get pruned
+                break;
+              }
+
               B = boldBic.get( rtOld.getHrnID() ); 
             }
 
             if( B != null ) {            
               ReachSet boldB_rtOld_incident = B.get( incidentEdge );
               if( boldB_rtOld_incident != null &&
-                  boldB_rtOld_incident.contains( stateOld ) ) {
+                  boldB_rtOld_incident.containsIgnorePreds( stateOld ) != null
+                  ) {
                 foundState = true;
               }
             }
@@ -3045,9 +3187,9 @@ public class ReachGraph {
 
        // if there is nothing marked, just move on
        if( markedHrnIDs.isEmpty() ) {
-         hrn.setAlphaNew( Canonical.union( hrn.getAlphaNew(),
-                                            stateOld
-                                            )
+         hrn.setAlphaNew( Canonical.add( hrn.getAlphaNew(),
+                                          stateOld
+                                          )
                            );
          continue;
        }
@@ -3060,19 +3202,19 @@ public class ReachGraph {
          ReachTuple rtOld = rtItr.next();
 
          if( !markedHrnIDs.containsTuple( rtOld ) ) {
-           statePruned = Canonical.union( statePruned, rtOld );
+           statePruned = Canonical.add( statePruned, rtOld );
          }
        }
        assert !stateOld.equals( statePruned );
 
-       hrn.setAlphaNew( Canonical.union( hrn.getAlphaNew(),
-                                          statePruned
-                                          )
+       hrn.setAlphaNew( Canonical.add( hrn.getAlphaNew(),
+                                        statePruned
+                                        )
                          );
        ChangeTuple ct = ChangeTuple.factory( stateOld,
                                               statePruned
                                               );
-       cts = Canonical.union( cts, ct );
+       cts = Canonical.add( cts, ct );
       }
 
       // throw change tuple set on all incident edges
@@ -3115,7 +3257,16 @@ public class ReachGraph {
     Iterator<HeapRegionNode> nodeItr = id2hrn.values().iterator();
     while( nodeItr.hasNext() ) {
       HeapRegionNode hrn = nodeItr.next();
-      hrn.applyAlphaNew();
+
+      // as mentioned above, out-of-context nodes only serve
+      // as sources of reach states for the sweep, not part
+      // of the changes
+      if( hrn.isOutOfContext() ) {
+        assert hrn.getAlphaNew().equals( rsetEmpty );
+      } else {
+        hrn.applyAlphaNew();
+      }
+
       Iterator<RefEdge> itrRes = hrn.iteratorToReferencers();
       while( itrRes.hasNext() ) {
        res.add( itrRes.next() );
@@ -3165,13 +3316,16 @@ public class ReachGraph {
                                   edgePrime.getBetaNew() 
                                   );
                    
-       if( Canonical.union( prevResult,
-                             intersection
-                             ).size() > prevResult.size() ) {
+       if( Canonical.unionORpreds( prevResult,
+                                    intersection
+                                    ).size() 
+            > prevResult.size() 
+            ) {
+          
          edge.setBetaNew( 
-                          Canonical.union( prevResult,
-                                           intersection 
-                                           )
+                          Canonical.unionORpreds( prevResult,
+                                                  intersection 
+                                                  )
                            );
          edgeWorkSet.add( edge );
        }       
@@ -3186,23 +3340,132 @@ public class ReachGraph {
   }  
 
 
+  // a useful assertion for debugging:
+  // every in-context tuple on any edge or
+  // any node should name a node that is
+  // part of the graph
+  public boolean inContextTuplesInGraph() {
 
-  ////////////////////////////////////////////////////
-  // high-level merge operations
-  ////////////////////////////////////////////////////
-  public void merge_sameMethodContext( ReachGraph rg ) {
-    // when merging two graphs that abstract the heap
-    // of the same method context, we just call the
-    // basic merge operation
-    merge( rg );
+    Iterator hrnItr = id2hrn.entrySet().iterator();
+    while( hrnItr.hasNext() ) {
+      Map.Entry      me  = (Map.Entry)      hrnItr.next();
+      HeapRegionNode hrn = (HeapRegionNode) me.getValue();
+
+      {
+        Iterator<ReachState> stateItr = hrn.getAlpha().iterator();
+        while( stateItr.hasNext() ) {
+          ReachState state = stateItr.next();
+          
+          Iterator<ReachTuple> rtItr = state.iterator();
+          while( rtItr.hasNext() ) {
+            ReachTuple rt = rtItr.next();
+            
+            if( !rt.isOutOfContext() ) {
+              if( !id2hrn.containsKey( rt.getHrnID() ) ) {
+                System.out.println( rt.getHrnID()+" is missing" );
+                return false;
+              }
+            }
+          }
+        }
+      }
+
+      Iterator<RefEdge> edgeItr = hrn.iteratorToReferencers();
+      while( edgeItr.hasNext() ) {
+        RefEdge edge = edgeItr.next();
+
+        Iterator<ReachState> stateItr = edge.getBeta().iterator();
+        while( stateItr.hasNext() ) {
+          ReachState state = stateItr.next();
+        
+          Iterator<ReachTuple> rtItr = state.iterator();
+          while( rtItr.hasNext() ) {
+            ReachTuple rt = rtItr.next();
+            
+            if( !rt.isOutOfContext() ) {
+              if( !id2hrn.containsKey( rt.getHrnID() ) ) {
+                System.out.println( rt.getHrnID()+" is missing" );
+                return false;
+              }
+            }
+          }
+        }
+      }
+    }
+
+    return true;
   }
 
-  public void merge_diffMethodContext( ReachGraph rg ) {
-    // when merging graphs for abstract heaps in
-    // different method contexts we should:
-    // 1) age the allocation sites?
-    merge( rg );
+
+  // another useful assertion for debugging
+  public boolean noEmptyReachSetsInGraph() {
+    
+    Iterator hrnItr = id2hrn.entrySet().iterator();
+    while( hrnItr.hasNext() ) {
+      Map.Entry      me  = (Map.Entry)      hrnItr.next();
+      HeapRegionNode hrn = (HeapRegionNode) me.getValue();
+
+      if( !hrn.isOutOfContext() && 
+          !hrn.isWiped()        &&
+          hrn.getAlpha().isEmpty() 
+          ) {
+        System.out.println( "!!! "+hrn+" has an empty ReachSet !!!" );
+        return false;
+      }
+
+      Iterator<RefEdge> edgeItr = hrn.iteratorToReferencers();
+      while( edgeItr.hasNext() ) {
+        RefEdge edge = edgeItr.next();
+
+        if( edge.getBeta().isEmpty() ) {
+          System.out.println( "!!! "+edge+" has an empty ReachSet !!!" );
+          return false;
+        }
+      }
+    }
+    
+    return true;
+  }
+
+
+  public boolean everyReachStateWTrue() {
+
+    Iterator hrnItr = id2hrn.entrySet().iterator();
+    while( hrnItr.hasNext() ) {
+      Map.Entry      me  = (Map.Entry)      hrnItr.next();
+      HeapRegionNode hrn = (HeapRegionNode) me.getValue();
+
+      {
+        Iterator<ReachState> stateItr = hrn.getAlpha().iterator();
+        while( stateItr.hasNext() ) {
+          ReachState state = stateItr.next();
+          
+          if( !state.getPreds().equals( predsTrue ) ) {
+            return false;
+          }
+        }
+      }
+
+      Iterator<RefEdge> edgeItr = hrn.iteratorToReferencers();
+      while( edgeItr.hasNext() ) {
+        RefEdge edge = edgeItr.next();
+
+        Iterator<ReachState> stateItr = edge.getBeta().iterator();
+        while( stateItr.hasNext() ) {
+          ReachState state = stateItr.next();
+
+          if( !state.getPreds().equals( predsTrue ) ) {
+            return false;
+          }
+        }
+      }
+    }
+
+    return true;
   }
+  
+
+
 
   ////////////////////////////////////////////////////
   // in merge() and equals() methods the suffix A
@@ -3244,7 +3507,7 @@ public class ReachGraph {
        // so make the new reachability set a union of the
        // nodes' reachability sets
        HeapRegionNode hrnB = id2hrn.get( idA );
-       hrnB.setAlpha( Canonical.union( hrnB.getAlpha(),
+       hrnB.setAlpha( Canonical.unionORpreds( hrnB.getAlpha(),
                                         hrnA.getAlpha() 
                                         )
                        );
@@ -3253,6 +3516,17 @@ public class ReachGraph {
                                        hrnA.getPreds()
                                        )
                        );
+
+
+
+        if( !hrnA.equals( hrnB ) ) {
+          rg.writeGraph( "graphA" );
+          this.writeGraph( "graphB" );
+          throw new Error( "flagged not matching" );
+        }
+
+
+
       }
     }
 
@@ -3326,15 +3600,20 @@ public class ReachGraph {
          // just replace this beta set with the union
          assert edgeToMerge != null;
          edgeToMerge.setBeta(
-                              Canonical.union( edgeToMerge.getBeta(),
-                                               edgeA.getBeta() 
-                                               )
+                              Canonical.unionORpreds( edgeToMerge.getBeta(),
+                                                      edgeA.getBeta() 
+                                                      )
                               );
           edgeToMerge.setPreds(
                                Canonical.join( edgeToMerge.getPreds(),
                                                edgeA.getPreds()
                                                )
                                );
+          edgeToMerge.setTaints(
+                                Canonical.union( edgeToMerge.getTaints(),
+                                                 edgeA.getTaints()
+                                                 )
+                                );
        }
       }
     }
@@ -3390,7 +3669,7 @@ public class ReachGraph {
        // so merge their reachability sets
        else {
          // just replace this beta set with the union
-         edgeToMerge.setBeta( Canonical.union( edgeToMerge.getBeta(),
+         edgeToMerge.setBeta( Canonical.unionORpreds( edgeToMerge.getBeta(),
                                                 edgeA.getBeta()
                                                 )
                                );
@@ -3398,6 +3677,11 @@ public class ReachGraph {
                                                 edgeA.getPreds()
                                                 )
                                 );
+          edgeToMerge.setTaints(
+                                Canonical.union( edgeToMerge.getTaints(),
+                                                 edgeA.getTaints()
+                                                 )
+                                );
        }
       }
     }
@@ -3408,6 +3692,10 @@ public class ReachGraph {
   }
 
 
+
+  static boolean dbgEquals = false;
+
+
   // it is necessary in the equals() member functions
   // to "check both ways" when comparing the data
   // structures of two graphs.  For instance, if all
@@ -3421,18 +3709,30 @@ public class ReachGraph {
   public boolean equals( ReachGraph rg ) {
 
     if( rg == null ) {
+      if( dbgEquals ) {
+        System.out.println( "rg is null" );
+      }
       return false;
     }
     
     if( !areHeapRegionNodesEqual( rg ) ) {
+      if( dbgEquals ) {
+        System.out.println( "hrn not equal" );
+      }
       return false;
     }
 
     if( !areVariableNodesEqual( rg ) ) {
+      if( dbgEquals ) {
+        System.out.println( "vars not equal" );
+      }
       return false;
     }
 
     if( !areRefEdgesEqual( rg ) ) {
+      if( dbgEquals ) {
+        System.out.println( "edges not equal" );
+      }
       return false;
     }
 
@@ -3479,7 +3779,6 @@ public class ReachGraph {
     
     return true;
   }
-  
 
   protected boolean areVariableNodesEqual( ReachGraph rg ) {
 
@@ -3516,6 +3815,10 @@ public class ReachGraph {
       return false;
     }
 
+    if( !areallREinAandBequal( rg, this ) ) {
+      return false;
+    }    
+
     return true;
   }
 
@@ -3629,6 +3932,94 @@ public class ReachGraph {
   }
 
 
+  // can be used to assert monotonicity
+  static public boolean isNoSmallerThan( ReachGraph rgA, 
+                                         ReachGraph rgB ) {
+
+    //System.out.println( "*** Asking if A is no smaller than B ***" );
+
+
+    Iterator iA = rgA.id2hrn.entrySet().iterator();
+    while( iA.hasNext() ) {
+      Map.Entry      meA  = (Map.Entry)      iA.next();
+      Integer        idA  = (Integer)        meA.getKey();
+      HeapRegionNode hrnA = (HeapRegionNode) meA.getValue();
+
+      if( !rgB.id2hrn.containsKey( idA ) ) {
+        System.out.println( "  regions smaller" );
+       return false;
+      }
+
+      //HeapRegionNode hrnB = rgB.id2hrn.get( idA );
+      /* NOT EQUALS, NO SMALLER THAN!
+      if( !hrnA.equalsIncludingAlphaAndPreds( hrnB ) ) {
+        System.out.println( "  regions smaller" );
+       return false;
+      }
+      */
+    }
+    
+    // this works just fine, no smaller than
+    if( !areallVNinAalsoinBandequal( rgA, rgB ) ) {
+      System.out.println( "  vars smaller:" );
+      System.out.println( "    A:"+rgA.td2vn.keySet() );
+      System.out.println( "    B:"+rgB.td2vn.keySet() );
+      return false;
+    }
+
+
+    iA = rgA.id2hrn.entrySet().iterator();
+    while( iA.hasNext() ) {
+      Map.Entry      meA  = (Map.Entry)      iA.next();
+      Integer        idA  = (Integer)        meA.getKey();
+      HeapRegionNode hrnA = (HeapRegionNode) meA.getValue();
+
+      Iterator<RefEdge> reItr = hrnA.iteratorToReferencers();
+      while( reItr.hasNext() ) {
+        RefEdge    edgeA = reItr.next();
+        RefSrcNode rsnA  = edgeA.getSrc();
+
+        // we already checked that nodes were present
+        HeapRegionNode hrnB = rgB.id2hrn.get( hrnA.getID() );
+        assert hrnB != null;
+
+        RefSrcNode rsnB;
+        if( rsnA instanceof VariableNode ) {
+          VariableNode vnA = (VariableNode) rsnA;
+          rsnB = rgB.td2vn.get( vnA.getTempDescriptor() );
+
+        } else {
+          HeapRegionNode hrnSrcA = (HeapRegionNode) rsnA;
+          rsnB = rgB.id2hrn.get( hrnSrcA.getID() );
+        }
+        assert rsnB != null;
+
+        RefEdge edgeB = rsnB.getReferenceTo( hrnB,
+                                             edgeA.getType(),
+                                             edgeA.getField()
+                                             );
+        if( edgeB == null ) {
+          System.out.println( "  edges smaller:" );          
+          return false;
+        }        
+
+        // REMEMBER, IS NO SMALLER THAN
+        /*
+          System.out.println( "  edges smaller" );
+          return false;
+          }
+        */
+
+      }
+    }
+
+    
+    return true;
+  }
+
+
+
+
 
   // this analysis no longer has the "match anything"
   // type which was represented by null
@@ -3748,18 +4139,36 @@ public class ReachGraph {
   
 
 
+  // the default signature for quick-and-dirty debugging
+  public void writeGraph( String graphName ) {
+    writeGraph( graphName,
+                true,  // write labels
+                true,  // label select
+                true,  // prune garbage
+                false, // hide reachability
+                true,  // hide subset reachability
+                true,  // hide predicates
+                true,  // hide edge taints                
+                null   // in-context boundary
+                );
+  }
+
   public void writeGraph( String  graphName,
                           boolean writeLabels,
                           boolean labelSelect,
                           boolean pruneGarbage,
+                          boolean hideReachability,
                           boolean hideSubsetReachability,
+                          boolean hidePredicates,
                           boolean hideEdgeTaints
-                          ) throws java.io.IOException {
+                          ) {
     writeGraph( graphName,
                 writeLabels,
                 labelSelect,
                 pruneGarbage,
+                hideReachability,
                 hideSubsetReachability,
+                hidePredicates,
                 hideEdgeTaints,
                 null );
   }
@@ -3768,128 +4177,149 @@ public class ReachGraph {
                           boolean      writeLabels,
                           boolean      labelSelect,
                           boolean      pruneGarbage,
+                          boolean      hideReachability,
                           boolean      hideSubsetReachability,
+                          boolean      hidePredicates,
                           boolean      hideEdgeTaints,
                           Set<Integer> callerNodeIDsCopiedToCallee
-                          ) throws java.io.IOException {
+                          ) {
     
-    // remove all non-word characters from the graph name so
-    // the filename and identifier in dot don't cause errors
-    graphName = graphName.replaceAll( "[\\W]", "" );
-
-    BufferedWriter bw = 
-      new BufferedWriter( new FileWriter( graphName+".dot" ) );
+    try {
+      // remove all non-word characters from the graph name so
+      // the filename and identifier in dot don't cause errors
+      graphName = graphName.replaceAll( "[\\W]", "" );
 
-    bw.write( "digraph "+graphName+" {\n" );
+      BufferedWriter bw = 
+        new BufferedWriter( new FileWriter( graphName+".dot" ) );
 
+      bw.write( "digraph "+graphName+" {\n" );
 
-    // this is an optional step to form the callee-reachable
-    // "cut-out" into a DOT cluster for visualization
-    if( callerNodeIDsCopiedToCallee != null ) {
-
-      bw.write( "  subgraph cluster0 {\n" );
-      bw.write( "    color=blue;\n" );
-
-      Iterator i = id2hrn.entrySet().iterator();
-      while( i.hasNext() ) {
-        Map.Entry      me  = (Map.Entry)      i.next();
-        HeapRegionNode hrn = (HeapRegionNode) me.getValue();      
+      
+      // this is an optional step to form the callee-reachable
+      // "cut-out" into a DOT cluster for visualization
+      if( callerNodeIDsCopiedToCallee != null ) {
         
-        if( callerNodeIDsCopiedToCallee.contains( hrn.getID() ) ) {
-          bw.write( "    "+hrn.toString()+
-                    hrn.toStringDOT( hideSubsetReachability )+
-                    ";\n" );
+        bw.write( "  subgraph cluster0 {\n" );
+        bw.write( "    color=blue;\n" );
+      
+        Iterator i = id2hrn.entrySet().iterator();
+        while( i.hasNext() ) {
+          Map.Entry      me  = (Map.Entry)      i.next();
+          HeapRegionNode hrn = (HeapRegionNode) me.getValue();      
           
+          if( callerNodeIDsCopiedToCallee.contains( hrn.getID() ) ) {
+            bw.write( "    "+
+                      hrn.toString()+
+                      hrn.toStringDOT( hideReachability,
+                                       hideSubsetReachability,
+                                       hidePredicates )+
+                      ";\n" );            
+          }
         }
+        
+        bw.write( "  }\n" );
       }
-
-      bw.write( "  }\n" );
-    }
-
-
-    Set<HeapRegionNode> visited = new HashSet<HeapRegionNode>();
-
-    // then visit every heap region node    
-    Iterator i = id2hrn.entrySet().iterator();
-    while( i.hasNext() ) {
-      Map.Entry      me  = (Map.Entry)      i.next();
-      HeapRegionNode hrn = (HeapRegionNode) me.getValue();      
-
-      // only visit nodes worth writing out--for instance
-      // not every node at an allocation is referenced
-      // (think of it as garbage-collected), etc.
-      if( !pruneGarbage        ||
-          hrn.isOutOfContext()
-          ) {
-
-       if( !visited.contains( hrn ) ) {
-         traverseHeapRegionNodes( hrn,
-                                   bw,
-                                   null,
-                                   visited,
-                                   hideSubsetReachability,
-                                   hideEdgeTaints,
-                                   callerNodeIDsCopiedToCallee );
-       }
-      }
-    }
-
-    bw.write( "  graphTitle[label=\""+graphName+"\",shape=box];\n" );
-  
-
-    // then visit every label node, useful for debugging
-    if( writeLabels ) {
-      i = td2vn.entrySet().iterator();
+      
+      
+      Set<HeapRegionNode> visited = new HashSet<HeapRegionNode>();
+      
+      // then visit every heap region node    
+      Iterator i = id2hrn.entrySet().iterator();
       while( i.hasNext() ) {
-        Map.Entry    me = (Map.Entry)    i.next();
-        VariableNode vn = (VariableNode) me.getValue();
-        
-        if( labelSelect ) {
-          String labelStr = vn.getTempDescriptorString();
-          if( labelStr.startsWith( "___temp" )     ||
-              labelStr.startsWith( "___dst" )      ||
-              labelStr.startsWith( "___srctmp" )   ||
-              labelStr.startsWith( "___neverused" )
-              ) {
-            continue;
-          }
-        }
+        Map.Entry      me  = (Map.Entry)      i.next();
+        HeapRegionNode hrn = (HeapRegionNode) me.getValue();      
         
-        Iterator<RefEdge> heapRegionsItr = vn.iteratorToReferencees();
-        while( heapRegionsItr.hasNext() ) {
-          RefEdge        edge = heapRegionsItr.next();
-          HeapRegionNode hrn  = edge.getDst();
+        // only visit nodes worth writing out--for instance
+        // not every node at an allocation is referenced
+        // (think of it as garbage-collected), etc.
+        if( !pruneGarbage        ||
+            hrn.isOutOfContext() ||
+            (hrn.isFlagged() && hrn.getID() > 0 && !hrn.isWiped()) // a non-shadow flagged node
+            ) {
           
           if( !visited.contains( hrn ) ) {
             traverseHeapRegionNodes( hrn,
                                      bw,
                                      null,
                                      visited,
+                                     hideReachability,
                                      hideSubsetReachability,
+                                     hidePredicates,
                                      hideEdgeTaints,
                                      callerNodeIDsCopiedToCallee );
           }
+        }
+      }
+      
+      bw.write( "  graphTitle[label=\""+graphName+"\",shape=box];\n" );
+      
+      
+      // then visit every label node, useful for debugging
+      if( writeLabels ) {
+        i = td2vn.entrySet().iterator();
+        while( i.hasNext() ) {
+          Map.Entry    me = (Map.Entry)    i.next();
+          VariableNode vn = (VariableNode) me.getValue();
+          
+          if( labelSelect ) {
+            String labelStr = vn.getTempDescriptorString();
+            if( labelStr.startsWith( "___temp" )     ||
+                labelStr.startsWith( "___dst" )      ||
+                labelStr.startsWith( "___srctmp" )   ||
+                labelStr.startsWith( "___neverused" )
+                ) {
+              continue;
+            }
+          }
+          
+          Iterator<RefEdge> heapRegionsItr = vn.iteratorToReferencees();
+          while( heapRegionsItr.hasNext() ) {
+            RefEdge        edge = heapRegionsItr.next();
+            HeapRegionNode hrn  = edge.getDst();
+          
+            if( !visited.contains( hrn ) ) {
+              traverseHeapRegionNodes( hrn,
+                                       bw,
+                                       null,
+                                       visited,
+                                       hideReachability,
+                                       hideSubsetReachability,
+                                       hidePredicates,
+                                       hideEdgeTaints,
+                                       callerNodeIDsCopiedToCallee );
+            }
           
-          bw.write( "  "+vn.toString()+
-                    " -> "+hrn.toString()+
-                    edge.toStringDOT( hideSubsetReachability, "" )+
-                    ";\n" );
+            bw.write( "  "+vn.toString()+
+                      " -> "+hrn.toString()+
+                      edge.toStringDOT( hideReachability,
+                                        hideSubsetReachability,
+                                        hidePredicates,
+                                        hideEdgeTaints,
+                                        "" )+
+                      ";\n" );
+          }
         }
       }
-    }
     
-    bw.write( "}\n" );
-    bw.close();
+      bw.write( "}\n" );
+      bw.close();
+
+    } catch( IOException e ) {
+      throw new Error( "Error writing out DOT graph "+graphName );
+    }
   }
 
-  protected void traverseHeapRegionNodes( HeapRegionNode      hrn,
-                                          BufferedWriter      bw,
-                                          TempDescriptor      td,
-                                          Set<HeapRegionNode> visited,
-                                          boolean             hideSubsetReachability,
-                                          boolean             hideEdgeTaints,
-                                          Set<Integer>        callerNodeIDsCopiedToCallee
-                                          ) throws java.io.IOException {
+  protected void 
+    traverseHeapRegionNodes( HeapRegionNode      hrn,
+                             BufferedWriter      bw,
+                             TempDescriptor      td,
+                             Set<HeapRegionNode> visited,
+                             boolean             hideReachability,
+                             boolean             hideSubsetReachability,
+                             boolean             hidePredicates,
+                             boolean             hideEdgeTaints,
+                             Set<Integer>        callerNodeIDsCopiedToCallee
+                             ) throws java.io.IOException {
 
     if( visited.contains( hrn ) ) {
       return;
@@ -3902,8 +4332,11 @@ public class ReachGraph {
     if( callerNodeIDsCopiedToCallee == null ||
         !callerNodeIDsCopiedToCallee.contains( hrn.getID() ) 
         ) {
-      bw.write( "  "+hrn.toString()+
-                hrn.toStringDOT( hideSubsetReachability )+
+      bw.write( "  "+
+                hrn.toString()+
+                hrn.toStringDOT( hideReachability,
+                                 hideSubsetReachability,
+                                 hidePredicates )+
                 ";\n" );
     }
 
@@ -3920,25 +4353,41 @@ public class ReachGraph {
             ) {
           bw.write( "  "+hrn.toString()+
                     " -> "+hrnChild.toString()+
-                    edge.toStringDOT( hideSubsetReachability, ",color=blue" )+
+                    edge.toStringDOT( hideReachability,
+                                      hideSubsetReachability,
+                                      hidePredicates,
+                                      hideEdgeTaints,
+                                      ",color=blue" )+
                     ";\n");
         } else if( !callerNodeIDsCopiedToCallee.contains( hrnSrc.getID()       ) &&
                    callerNodeIDsCopiedToCallee.contains( edge.getDst().getID() )
                    ) {
           bw.write( "  "+hrn.toString()+
                     " -> "+hrnChild.toString()+
-                    edge.toStringDOT( hideSubsetReachability, ",color=blue,style=dashed" )+
+                    edge.toStringDOT( hideReachability,
+                                      hideSubsetReachability,
+                                      hidePredicates,
+                                      hideEdgeTaints,
+                                      ",color=blue,style=dashed" )+
                     ";\n");
         } else {
           bw.write( "  "+hrn.toString()+
                     " -> "+hrnChild.toString()+
-                    edge.toStringDOT( hideSubsetReachability, "" )+
+                    edge.toStringDOT( hideReachability,
+                                      hideSubsetReachability,
+                                      hidePredicates,
+                                      hideEdgeTaints,
+                                      "" )+
                     ";\n");
         }
       } else {
         bw.write( "  "+hrn.toString()+
                   " -> "+hrnChild.toString()+
-                  edge.toStringDOT( hideSubsetReachability, "" )+
+                  edge.toStringDOT( hideReachability,
+                                    hideSubsetReachability,
+                                    hidePredicates,
+                                    hideEdgeTaints,
+                                    "" )+
                   ";\n");
       }
       
@@ -3946,10 +4395,355 @@ public class ReachGraph {
                                bw,
                                td,
                                visited,
+                               hideReachability,
                                hideSubsetReachability,
+                               hidePredicates,
                                hideEdgeTaints,
                                callerNodeIDsCopiedToCallee );
     }
   }  
+  
+
+
+
+
+  public Set<HeapRegionNode> findCommonReachableNodes( ReachSet proofOfSharing ) {
+
+    Set<HeapRegionNode> exhibitProofState =
+      new HashSet<HeapRegionNode>();
+
+    Iterator hrnItr = id2hrn.entrySet().iterator();
+    while( hrnItr.hasNext() ) {
+      Map.Entry      me  = (Map.Entry) hrnItr.next();
+      HeapRegionNode hrn = (HeapRegionNode) me.getValue();
+      
+      ReachSet intersection =
+        Canonical.intersection( proofOfSharing,
+                                hrn.getAlpha()
+                                );
+      if( !intersection.isEmpty() ) {
+        assert !hrn.isOutOfContext();
+        exhibitProofState.add( hrn );
+      }
+    }
+    
+    return exhibitProofState;
+  }
+
+        
+  public Set<HeapRegionNode> mayReachSharedObjects(HeapRegionNode hrn1,
+                                                   HeapRegionNode hrn2) {
+    assert hrn1 != null;
+    assert hrn2 != null;
+
+    assert !hrn1.isOutOfContext();
+    assert !hrn2.isOutOfContext();
+
+    assert belongsToThis( hrn1 );
+    assert belongsToThis( hrn2 );
+
+    assert !hrn1.getID().equals( hrn2.getID() );
 
+
+    // then get the various tokens for these heap regions
+    ReachTuple h1 = 
+      ReachTuple.factory( hrn1.getID(),
+                          !hrn1.isSingleObject(), // multi?
+                          ReachTuple.ARITY_ONE, 
+                          false );                // ooc?
+    
+    ReachTuple h1star = null;
+    if( !hrn1.isSingleObject() ) {
+      h1star = 
+        ReachTuple.factory( hrn1.getID(), 
+                            !hrn1.isSingleObject(), 
+                            ReachTuple.ARITY_ZEROORMORE,
+                            false );
+    }
+    
+    ReachTuple h2 = 
+      ReachTuple.factory( hrn2.getID(),
+                          !hrn2.isSingleObject(),
+                          ReachTuple.ARITY_ONE,
+                          false );
+
+    ReachTuple h2star = null;
+    if( !hrn2.isSingleObject() ) {    
+      h2star =
+        ReachTuple.factory( hrn2.getID(), 
+                            !hrn2.isSingleObject(),
+                            ReachTuple.ARITY_ZEROORMORE,
+                            false );
+    }
+
+    // then get the merged beta of all out-going edges from these heap
+    // regions
+
+    ReachSet beta1 = ReachSet.factory();
+    Iterator<RefEdge> itrEdge = hrn1.iteratorToReferencees();
+    while (itrEdge.hasNext()) {
+      RefEdge edge = itrEdge.next();
+      beta1 = Canonical.unionORpreds(beta1, edge.getBeta());
+    }
+
+    ReachSet beta2 = ReachSet.factory();
+    itrEdge = hrn2.iteratorToReferencees();
+    while (itrEdge.hasNext()) {
+      RefEdge edge = itrEdge.next();
+      beta2 = Canonical.unionORpreds(beta2, edge.getBeta());
+    }
+
+    ReachSet proofOfSharing = ReachSet.factory();
+
+    proofOfSharing = 
+      Canonical.unionORpreds( proofOfSharing,
+                              beta1.getStatesWithBoth( h1, h2 )
+                              );
+    proofOfSharing = 
+      Canonical.unionORpreds( proofOfSharing,
+                              beta2.getStatesWithBoth( h1, h2 )
+                              );
+    
+    if( !hrn1.isSingleObject() ) {    
+      proofOfSharing = 
+        Canonical.unionORpreds( proofOfSharing,
+                                beta1.getStatesWithBoth( h1star, h2 )
+                                );
+      proofOfSharing = 
+        Canonical.unionORpreds( proofOfSharing,
+                                beta2.getStatesWithBoth( h1star, h2 )
+                                );      
+    }
+
+    if( !hrn2.isSingleObject() ) {    
+      proofOfSharing = 
+        Canonical.unionORpreds( proofOfSharing,
+                                beta1.getStatesWithBoth( h1, h2star )
+                                );
+      proofOfSharing = 
+        Canonical.unionORpreds( proofOfSharing,
+                                beta2.getStatesWithBoth( h1, h2star )
+                                );
+    }
+
+    if( !hrn1.isSingleObject() &&
+        !hrn2.isSingleObject()
+        ) {    
+      proofOfSharing = 
+        Canonical.unionORpreds( proofOfSharing,
+                                beta1.getStatesWithBoth( h1star, h2star )
+                                );
+      proofOfSharing = 
+        Canonical.unionORpreds( proofOfSharing,
+                                beta2.getStatesWithBoth( h1star, h2star )
+                                );
+    }
+    
+    Set<HeapRegionNode> common = new HashSet<HeapRegionNode>();
+    if( !proofOfSharing.isEmpty() ) {
+      common = findCommonReachableNodes( proofOfSharing );
+      if( !DISABLE_STRONG_UPDATES &&
+          !DISABLE_GLOBAL_SWEEP
+          ) {        
+        assert !common.isEmpty();
+      }
+    }
+
+    return common;
+  }
+
+  // this version of the above method checks whether there is sharing
+  // among the objects in a summary node
+  public Set<HeapRegionNode> mayReachSharedObjects(HeapRegionNode hrn) {
+    assert hrn != null;
+    assert hrn.isNewSummary();
+    assert !hrn.isOutOfContext();
+    assert belongsToThis( hrn );
+
+    ReachTuple hstar =  
+      ReachTuple.factory( hrn.getID(), 
+                          true,    // multi
+                          ReachTuple.ARITY_ZEROORMORE,
+                          false ); // ooc    
+
+    // then get the merged beta of all out-going edges from 
+    // this heap region
+
+    ReachSet beta = ReachSet.factory();
+    Iterator<RefEdge> itrEdge = hrn.iteratorToReferencees();
+    while (itrEdge.hasNext()) {
+      RefEdge edge = itrEdge.next();
+      beta = Canonical.unionORpreds(beta, edge.getBeta());
+    }
+    
+    ReachSet proofOfSharing = ReachSet.factory();
+
+    proofOfSharing = 
+      Canonical.unionORpreds( proofOfSharing,
+                              beta.getStatesWithBoth( hstar, hstar )
+                              );
+    
+    Set<HeapRegionNode> common = new HashSet<HeapRegionNode>();
+    if( !proofOfSharing.isEmpty() ) {
+      common = findCommonReachableNodes( proofOfSharing );
+      if( !DISABLE_STRONG_UPDATES &&
+          !DISABLE_GLOBAL_SWEEP
+          ) {        
+        assert !common.isEmpty();
+      }
+    }
+    
+    return common;
+  }
+
+
+  public Set<HeapRegionNode> mayReachSharedObjects(FlatMethod fm,
+                                                   Integer paramIndex1, 
+                                                   Integer paramIndex2) {
+
+    // get parameter's heap regions
+    TempDescriptor paramTemp1 = fm.getParameter(paramIndex1.intValue());
+    assert this.hasVariable( paramTemp1 );
+    VariableNode paramVar1 = getVariableNodeFromTemp(paramTemp1);
+
+
+    if( !(paramVar1.getNumReferencees() == 1) ) {
+      System.out.println( "\n  fm="+fm+"\n  param="+paramTemp1 );
+      writeGraph( "whatup" );
+    }
+
+
+    assert paramVar1.getNumReferencees() == 1;
+    RefEdge paramEdge1 = paramVar1.iteratorToReferencees().next();
+    HeapRegionNode hrnParam1 = paramEdge1.getDst();
+
+    TempDescriptor paramTemp2 = fm.getParameter(paramIndex2.intValue());
+    assert this.hasVariable( paramTemp2 );
+    VariableNode paramVar2 = getVariableNodeFromTemp(paramTemp2);
+
+    if( !(paramVar2.getNumReferencees() == 1) ) {
+      System.out.println( "\n  fm="+fm+"\n  param="+paramTemp2 );
+      writeGraph( "whatup" );
+    }
+
+    assert paramVar2.getNumReferencees() == 1;
+    RefEdge paramEdge2 = paramVar2.iteratorToReferencees().next();
+    HeapRegionNode hrnParam2 = paramEdge2.getDst();
+
+    Set<HeapRegionNode> common = new HashSet<HeapRegionNode>();
+    common.addAll(mayReachSharedObjects(hrnParam1, hrnParam2));
+
+    return common;
+  }
+
+  public Set<HeapRegionNode> mayReachSharedObjects(FlatMethod fm,
+                                                   Integer paramIndex, 
+                                                   AllocSite as) {
+
+    // get parameter's heap regions
+    TempDescriptor paramTemp = fm.getParameter(paramIndex.intValue());
+    assert this.hasVariable( paramTemp );
+    VariableNode paramVar = getVariableNodeFromTemp(paramTemp);
+    assert paramVar.getNumReferencees() == 1;
+    RefEdge paramEdge = paramVar.iteratorToReferencees().next();
+    HeapRegionNode hrnParam = paramEdge.getDst();
+
+    // get summary node
+    HeapRegionNode hrnSummary=null;
+    if(id2hrn.containsKey(as.getSummary())){
+      // if summary node doesn't exist, ignore this case
+      hrnSummary = id2hrn.get(as.getSummary());
+      assert hrnSummary != null;
+    }
+
+    Set<HeapRegionNode> common  = new HashSet<HeapRegionNode>();
+    if(hrnSummary!=null){
+      common.addAll( mayReachSharedObjects(hrnParam, hrnSummary) );
+    }
+
+    // check for other nodes
+    for (int i = 0; i < as.getAllocationDepth(); ++i) {
+
+      assert id2hrn.containsKey(as.getIthOldest(i));
+      HeapRegionNode hrnIthOldest = id2hrn.get(as.getIthOldest(i));
+      assert hrnIthOldest != null;
+
+      common.addAll(mayReachSharedObjects(hrnParam, hrnIthOldest));
+
+    }
+
+    return common;
+  }
+
+  public Set<HeapRegionNode> mayReachSharedObjects(AllocSite as1,
+                                                   AllocSite as2) {
+
+    // get summary node 1's alpha
+    Integer idSum1 = as1.getSummary();
+    HeapRegionNode hrnSum1=null;
+    if(id2hrn.containsKey(idSum1)){
+      hrnSum1 = id2hrn.get(idSum1);
+    }
+
+    // get summary node 2's alpha
+    Integer idSum2 = as2.getSummary();
+    HeapRegionNode hrnSum2=null;
+    if(id2hrn.containsKey(idSum2)){
+      hrnSum2 = id2hrn.get(idSum2);
+    }
+               
+    Set<HeapRegionNode> common = new HashSet<HeapRegionNode>();
+    if(hrnSum1!=null && hrnSum2!=null && hrnSum1!=hrnSum2){
+      common.addAll(mayReachSharedObjects(hrnSum1, hrnSum2));
+    }
+
+    if(hrnSum1!=null){
+      // ask if objects from this summary share among each other
+      common.addAll(mayReachSharedObjects(hrnSum1));
+    }
+
+    // check sum2 against alloc1 nodes
+    if(hrnSum2!=null){
+      for (int i = 0; i < as1.getAllocationDepth(); ++i) {
+        Integer idI1 = as1.getIthOldest(i);
+        assert id2hrn.containsKey(idI1);
+        HeapRegionNode hrnI1 = id2hrn.get(idI1);
+        assert hrnI1 != null;
+        common.addAll(mayReachSharedObjects(hrnI1, hrnSum2));
+      }
+
+      // also ask if objects from this summary share among each other
+      common.addAll(mayReachSharedObjects(hrnSum2));
+    }
+
+    // check sum1 against alloc2 nodes
+    for (int i = 0; i < as2.getAllocationDepth(); ++i) {
+      Integer idI2 = as2.getIthOldest(i);
+      assert id2hrn.containsKey(idI2);
+      HeapRegionNode hrnI2 = id2hrn.get(idI2);
+      assert hrnI2 != null;
+
+      if(hrnSum1!=null){
+        common.addAll(mayReachSharedObjects(hrnSum1, hrnI2));
+      }
+
+      // while we're at it, do an inner loop for alloc2 vs alloc1 nodes
+      for (int j = 0; j < as1.getAllocationDepth(); ++j) {
+        Integer idI1 = as1.getIthOldest(j);
+
+        // if these are the same site, don't look for the same token, no
+        // alias.
+        // different tokens of the same site could alias together though
+        if (idI1.equals(idI2)) {
+          continue;
+        }
+
+        HeapRegionNode hrnI1 = id2hrn.get(idI1);
+
+        common.addAll(mayReachSharedObjects(hrnI1, hrnI2));
+      }
+    }
+
+    return common;
+  }  
 }