Bug fix that param2id tables need to initialized for every method before starting...
authorjjenista <jjenista>
Thu, 7 Aug 2008 18:37:09 +0000 (18:37 +0000)
committerjjenista <jjenista>
Thu, 7 Aug 2008 18:37:09 +0000 (18:37 +0000)
Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java
Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java
Robust/src/Analysis/OwnershipAnalysis/ReachabilitySet.java

index 016929e88a0d8c6695ca3652e7ec25d5aae2f775..8e04335ba1a8cc7ae8e9d4173f67be57a0a6fabe 100644 (file)
@@ -206,6 +206,7 @@ public class OwnershipAnalysis {
        // traversing the call graph
        HashSet<Descriptor> calleesScheduled = new HashSet<Descriptor>();
 
+
        // initialize methods to visit as the set of all tasks in the
        // program and then any method that could be called starting
        // from those tasks
@@ -218,6 +219,26 @@ public class OwnershipAnalysis {
            scheduleAllCallees( calleesScheduled, d );
        }
        
+       // before beginning analysis, initialize every scheduled method
+       // with an ownership graph that has populated parameter index tables
+       // by analyzing the first node which is always a FlatMethod node
+       Iterator<Descriptor> dItr = calleesScheduled.iterator();
+       while( dItr.hasNext() ) {
+           Descriptor     d  = dItr.next();
+           OwnershipGraph og = new OwnershipGraph( allocationDepth );
+           
+           FlatMethod fm;
+           if( d instanceof MethodDescriptor ) {
+               fm = state.getMethodFlat( (MethodDescriptor) d );
+           } else {
+               assert d instanceof TaskDescriptor;
+               fm = state.getMethodFlat( (TaskDescriptor) d );
+           }
+
+           analyzeFlatNode( d, fm, null, og );
+           mapDescriptorToCompleteOwnershipGraph.put( d, og );
+       }
+
        // as mentioned above, analyze methods one-by-one, possibly revisiting
        // a method if the methods that it calls are updated
        analyzeMethods();
@@ -317,11 +338,6 @@ public class OwnershipAnalysis {
        // the final ownership graph result to return as an empty set
        returnNodesToCombineForCompleteOwnershipGraph = new HashSet<FlatReturnNode>();
 
-
-       // DEBUG
-       //int x = 0;
-
-
        while( !flatNodesToVisit.isEmpty() ) {
            FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next();
            flatNodesToVisit.remove( fn );
@@ -355,20 +371,6 @@ public class OwnershipAnalysis {
            if( !og.equals( ogPrev ) ) {
                setGraphForFlatNode( fn, og );
 
-               // DEBUG
-               /*
-               ++x;    
-
-               if( x > 5000 ) {
-               String s = String.format( "%04d", x );
-               og.writeGraph( "debug"+s, false, false );
-               }
-
-               if( x == 5020 ) {
-                   System.exit( -1 );
-               }
-               */
-
                for( int i = 0; i < fn.numNext(); i++ ) {
                    FlatNode nn = fn.getNext( i );                
                    flatNodesToVisit.add( nn );
index bd5d6ef9c74663dd71e092bb0695e37638945e49..a955920e176e8bd1531cd6ca01681cd862eea581 100644 (file)
@@ -823,9 +823,9 @@ public class OwnershipGraph {
 
        // verify the existence of allocation sites and their
        // shadows from the callee in the context of this caller graph
-       Iterator<AllocationSite> i = ogCallee.allocationSites.iterator();
-       while( i.hasNext() ) {
-           AllocationSite allocSite = i.next();    
+       Iterator<AllocationSite> asItr = ogCallee.allocationSites.iterator();
+       while( asItr.hasNext() ) {
+           AllocationSite allocSite        = asItr.next();    
            HeapRegionNode hrnSummary       = getSummaryNode      ( allocSite );
            HeapRegionNode hrnShadowSummary = getShadowSummaryNode( allocSite );
        }      
@@ -838,6 +838,63 @@ public class OwnershipGraph {
            assert fc.numArgs() + 1 == fm.numParameters();
        }
 
+       // make a change set to translate callee tokens into caller tokens
+       ChangeTupleSet C = new ChangeTupleSet().makeCanonical();
+
+       for( int i = 0; i < fm.numParameters(); ++i ) {
+           
+           Integer indexParam = new Integer( i );
+
+           System.out.println( "In method "+fm+ " on param "+indexParam );
+
+           assert ogCallee.paramIndex2id.containsKey( indexParam );        
+           Integer idParam = ogCallee.paramIndex2id.get( indexParam );
+
+           assert ogCallee.id2hrn.containsKey( idParam );
+           HeapRegionNode hrnParam = ogCallee.id2hrn.get( idParam );
+           assert hrnParam != null;
+
+           TokenTupleSet calleeTokenToMatch = 
+               new TokenTupleSet( new TokenTuple( hrnParam ) ).makeCanonical();
+
+           
+           // now depending on whether the callee is static or not
+           // we need to account for a "this" argument in order to
+           // find the matching argument in the caller context
+           TempDescriptor argTemp;
+           if( isStatic ) {
+               argTemp = fc.getArg( indexParam );
+           } else {
+               if( indexParam == 0 ) {
+                   argTemp = fc.getThis();
+               } else {
+                   argTemp = fc.getArg( indexParam - 1 );
+               }
+           }
+           
+           LabelNode argLabel = getLabelNodeFromTemp( argTemp );
+           Iterator argHeapRegionsItr = argLabel.setIteratorToReferencedRegions();
+           while( argHeapRegionsItr.hasNext() ) {
+               Map.Entry meArg                = (Map.Entry)               argHeapRegionsItr.next();
+               HeapRegionNode argHeapRegion   = (HeapRegionNode)          meArg.getKey();
+               ReferenceEdgeProperties repArg = (ReferenceEdgeProperties) meArg.getValue();
+               
+               Iterator<TokenTupleSet> ttsItr = repArg.getBeta().iterator();
+               while( ttsItr.hasNext() ) {
+                   TokenTupleSet callerTokensToReplace = ttsItr.next();
+
+                   ChangeTuple ct = new ChangeTuple( calleeTokenToMatch,
+                                                     callerTokensToReplace ).makeCanonical();
+
+                   C = C.union( ct );
+               }
+           }
+       }
+
+       System.out.println( "Applying method call "+fm );
+       System.out.println( "  Change: "+C );
+
+
        // the heap regions represented by the arguments (caller graph)
        // and heap regions for the parameters (callee graph)
        // don't correspond to each other by heap region ID.  In fact,
@@ -992,7 +1049,7 @@ public class OwnershipGraph {
 
        mergeOwnershipNodes ( og );
        mergeReferenceEdges ( og );
-       mergeId2paramIndex  ( og );
+       mergeId2paramIndex  ( og );     
        mergeAllocationSites( og );
     }
 
index 08b2b7a81db5d54ca334d6ccb9187c02aa3dd26e..3adead1006dd00b35700c65b80879acea84c2348 100644 (file)
@@ -12,8 +12,6 @@ public class ReachabilitySet extends Canonical {
 
     public ReachabilitySet() {
        possibleReachabilities = new HashSet<TokenTupleSet>();
-       //TokenTupleSet ttsEmpty = new TokenTupleSet().makeCanonical();
-       //possibleReachabilities.add( ttsEmpty );       
     }
 
     public ReachabilitySet( TokenTupleSet tts ) {