Fixed x.f = y operation
[IRC.git] / Robust / src / Analysis / OwnershipAnalysis / OwnershipGraph.java
index a7a65cd016d70a45c3e1f88da000bc53c783e796..69db25c20faf9782f14dbc906be99fd666133365 100644 (file)
@@ -157,10 +157,10 @@ public class OwnershipGraph {
        }    
     }
     
-    protected void propagateTokens( HeapRegionNode                   nPrime,
-                                   ChangeTupleSet                   c0,
-                                   HashSet<HeapRegionNode>          nodesWithNewAlpha,
-                                   HashSet<ReferenceEdgeProperties> edgesWithNewBeta ) {
+    protected void propagateTokensOverNodes( HeapRegionNode                   nPrime,
+                                            ChangeTupleSet                   c0,
+                                            HashSet<HeapRegionNode>          nodesWithNewAlpha,
+                                            HashSet<ReferenceEdgeProperties> edgesWithNewBeta ) {
 
        HashSet<HeapRegionNode> todoNodes
            = new HashSet<HeapRegionNode>();
@@ -249,7 +249,17 @@ public class OwnershipGraph {
            }
        }
 
+       propagateTokensOverEdges( todoEdges, edgePlannedChanges, nodesWithNewAlpha, edgesWithNewBeta );
+    }
+
+
+    protected void propagateTokensOverEdges( 
+        HashSet<ReferenceEdgeProperties>                   todoEdges,
+        Hashtable<ReferenceEdgeProperties, ChangeTupleSet> edgePlannedChanges,
+        HashSet<HeapRegionNode>                            nodesWithNewAlpha,
+        HashSet<ReferenceEdgeProperties>                   edgesWithNewBeta ) {
        
+
        while( !todoEdges.isEmpty() ) {
            ReferenceEdgeProperties e = todoEdges.iterator().next();
            todoEdges.remove( e );
@@ -400,27 +410,41 @@ public class OwnershipGraph {
                
                ReachabilitySet O = srcln.getReferenceTo( hrnSrc ).getBeta();
 
-               ReferenceEdgeProperties repNew 
-                   = new ReferenceEdgeProperties( false, false, repSrc.getBeta() );
 
-               addReferenceEdge( hrn, hrnSrc, repNew );
+               // propagate tokens over nodes starting from hrnSrc, and it will
+               // take care of propagating back up edges from any touched nodes
+               ChangeTupleSet Cy = O.unionUpArityToChangeSet( R );
+               propagateTokensOverNodes( hrnSrc, Cy, nodesWithNewAlpha, edgesWithNewBeta );
 
 
+               // then propagate back just up the edges from hrn
+               ChangeTupleSet Cx = R.unionUpArityToChangeSet( O );
 
-               ChangeTupleSet Cy = O.unionUpArityToChangeSet( R );
-               //ChangeTupleSet Cx = R.unionUpArityToChangeSet( O );
+               HashSet<ReferenceEdgeProperties> todoEdges = 
+                   new HashSet<ReferenceEdgeProperties>();
 
-               propagateTokens( hrnSrc, Cy, nodesWithNewAlpha, edgesWithNewBeta );
-               //propagateTokens( hrn,    Cx, nodesWithNewAlpha, edgesWithNewBeta );
+               Hashtable<ReferenceEdgeProperties, ChangeTupleSet> edgePlannedChanges =
+                   new Hashtable<ReferenceEdgeProperties, ChangeTupleSet>();
 
-               /*
-               // note that this picks up the beta after the propogation has
-               // been applied
+               Iterator referItr = hrn.iteratorToReferencers();
+               while( referItr.hasNext() ) {
+                   OwnershipNode onRef = (OwnershipNode) referItr.next();
+                   ReferenceEdgeProperties repUpstream = onRef.getReferenceTo( hrn );
+
+                   todoEdges.add( repUpstream );
+                   edgePlannedChanges.put( repUpstream, Cx );
+               }
+
+               propagateTokensOverEdges( todoEdges, 
+                                         edgePlannedChanges,
+                                         nodesWithNewAlpha,
+                                         edgesWithNewBeta );
+
+               // finally, create the actual reference edge hrn->hrnSrc
                ReferenceEdgeProperties repNew 
                    = new ReferenceEdgeProperties( false, false, repSrc.getBetaNew() );
 
                addReferenceEdge( hrn, hrnSrc, repNew );
-               */
            }
        }       
 
@@ -587,26 +611,6 @@ public class OwnershipGraph {
            Map.Entry               me  = (Map.Entry)               itrReferencee.next();
            hrnReferencee               = (HeapRegionNode)          me.getKey();
            ReferenceEdgeProperties rep = (ReferenceEdgeProperties) me.getValue();
-           
-           // determine if another summary node is already referencing this referencee
-           /*
-           boolean       hasSummaryReferencer = false;
-           OwnershipNode onReferencer         = null;
-           Iterator      itrReferencer        = hrnReferencee.iteratorToReferencers();
-           while( itrReferencer.hasNext() ) {
-               onReferencer = (OwnershipNode) itrReferencer.next();
-               if( onReferencer instanceof HeapRegionNode ) {
-                   HeapRegionNode hrnPossibleSummary = (HeapRegionNode) onReferencer;
-                   if( hrnPossibleSummary.isNewSummary() ) {
-                       hasSummaryReferencer = true;
-                   }
-               }
-           }
-
-           addReferenceEdge( hrnSummary,
-                             hrnReferencee,
-                             new ReferenceEdgeProperties( !hasSummaryReferencer ) );
-           */
 
            ReferenceEdgeProperties repSummary = hrnSummary.getReferenceTo( hrnReferencee );
            ReferenceEdgeProperties repMerged = rep.copy();
@@ -644,6 +648,9 @@ public class OwnershipGraph {
            addReferenceEdge( onReferencer, hrnSummary, repMerged );
        }
 
+       // then merge alpha_k reachability into alpha_s
+       hrnSummary.setAlpha( hrnSummary.getAlpha().union( hrnK.getAlpha() ) );
+
        
        // then move down the line of heap region nodes
        // clobbering the ith and transferring all references
@@ -684,6 +691,9 @@ public class OwnershipGraph {
 
                addReferenceEdge( onReferencer, hrnI, rep.copy() );
            }       
+
+           // replace hrnI reachability with hrnImin1
+           hrnI.setAlpha( hrnImin1.getAlpha() );
        }
 
        // as stated above, the newest node alpha_0 should have had its
@@ -697,11 +707,12 @@ public class OwnershipGraph {
        // have touched this node, therefore assert it is non-null
        assert hrn0 != null;
 
+
        // clear all references in and out of newest node
        clearReferenceEdgesFrom( hrn0 );
        clearReferenceEdgesTo  ( hrn0 );
+       
 
-       /*
        // now tokens in reachability sets need to "age" as well
        ReferenceEdgeProperties repToAge = null;
        Iterator itrAllLabelNodes = td2ln.entrySet().iterator();
@@ -717,7 +728,6 @@ public class OwnershipGraph {
                ageTokens( as, repToAge );
            }
        }
-
        HeapRegionNode hrnToAge = null;
        Iterator itrAllHRNodes = id2hrn.entrySet().iterator();
        while( itrAllHRNodes.hasNext() ) {
@@ -734,8 +744,15 @@ public class OwnershipGraph {
                ageTokens( as, repToAge );
            }
        }
-       */
-       
+
+
+       // after tokens have been aged, reset newest node's reachability
+       hrn0.setAlpha( new ReachabilitySet( 
+                          new TokenTupleSet( 
+                              new TokenTuple( hrn0 ) 
+                                           ) 
+                                         ).makeCanonical() 
+                      );
     }
 
     protected void ageTokens( AllocationSite as, ReferenceEdgeProperties rep ) {
@@ -828,9 +845,9 @@ public class OwnershipGraph {
                        //System.out.println( "idCallee is "+idCallee );
                        //System.out.println( "idChildCallee is "+idChildCallee );
                        
-                       try {
-                           writeGraph( "caller", false, false );
-                           ogCallee.writeGraph( "callee", false, false );
+                       try {                       
+                           writeGraph( "caller", false, false, false );
+                           ogCallee.writeGraph( "callee", false, false, false );                           
                        } catch( IOException e ) {}
                    }
 
@@ -1520,6 +1537,7 @@ public class OwnershipGraph {
     public void writeGraph( Descriptor methodDesc,
                            FlatNode   fn,
                            boolean    writeLabels,
+                           boolean    labelSelect,
                            boolean    writeReferencers 
                            ) throws java.io.IOException {
        writeGraph(
@@ -1527,12 +1545,43 @@ public class OwnershipGraph {
                   methodDesc.getNum() +
                   fn.toString(),
                   writeLabels,
+                  labelSelect,
                   writeReferencers
                   );
     }
 
+    public void writeGraph( Descriptor methodDesc,
+                           FlatNode   fn,
+                           boolean    writeLabels,
+                           boolean    writeReferencers 
+                           ) throws java.io.IOException {
+       writeGraph(
+                  methodDesc.getSymbol() +
+                  methodDesc.getNum() +
+                  fn.toString(),
+                  writeLabels,
+                  false,
+                  writeReferencers
+                  );
+    }
+
+    public void writeGraph( Descriptor methodDesc,
+                           boolean    writeLabels,
+                           boolean    writeReferencers 
+                           ) throws java.io.IOException {
+       writeGraph( 
+                  methodDesc.getSymbol() +
+                  methodDesc.getNum() +
+                  "COMPLETE",
+                  writeLabels,
+                  false,
+                  writeReferencers
+                   );
+    }
+
     public void writeGraph( Descriptor methodDesc,
                            boolean    writeLabels,
+                           boolean    labelSelect,
                            boolean    writeReferencers 
                            ) throws java.io.IOException {
        writeGraph( 
@@ -1540,12 +1589,14 @@ public class OwnershipGraph {
                   methodDesc.getNum() +
                   "COMPLETE",
                   writeLabels,
+                  labelSelect,
                   writeReferencers
                    );
     }
 
     public void writeGraph( String graphName,
                            boolean writeLabels,
+                           boolean labelSelect,
                            boolean writeReferencers 
                            ) throws java.io.IOException {
 
@@ -1587,6 +1638,16 @@ public class OwnershipGraph {
                Map.Entry me = (Map.Entry) i.next();
                LabelNode ln = (LabelNode) me.getValue();
                
+               if( labelSelect ) {
+                   String labelStr = ln.getTempDescriptorString();
+                   if( labelStr.startsWith( "___temp"      ) ||
+                       labelStr.startsWith( "___dst"       ) ||
+                       labelStr.startsWith( "___srctmp"   ) ||
+                       labelStr.startsWith( "___neverused" )   ) {
+                       continue;
+                   }
+               }
+
                HeapRegionNode hrn = null;
                Iterator heapRegionsItr = ln.setIteratorToReferencedRegions();
                while( heapRegionsItr.hasNext() ) {