Method scheduling handles recursion and dependency.
authorjjenista <jjenista>
Fri, 29 Feb 2008 20:41:39 +0000 (20:41 +0000)
committerjjenista <jjenista>
Fri, 29 Feb 2008 20:41:39 +0000 (20:41 +0000)
Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java
Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java
Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java

index 1f85dde243e7fafd4b11440b42e4f4232afe87b8..81ae21c012d272875f1e7d9c392f9bf8fb4d73b5 100644 (file)
@@ -49,19 +49,51 @@ public class OwnershipAnalysis {
        mapFlatNewToAllocationSite =
            new Hashtable<FlatNew, AllocationSite>();
 
-       // initialize methods to visit as the set of all tasks
        descriptorsToVisit = new HashSet<Descriptor>();
+
+       // use this set to prevent infinite recursion when
+       // 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
        Iterator taskItr = state.getTaskSymbolTable().getDescriptorsIterator();
        while( taskItr.hasNext() ) {
            Descriptor d = (Descriptor) taskItr.next();
            descriptorsToVisit.add( d );
-       }       
+
+           // recursively find all callees from this task
+           scheduleAllCallees( calleesScheduled, d );
+       }
        
        // as mentioned above, analyze methods one-by-one, possibly revisiting
        // a method if the methods that it calls are updated
        analyzeMethods();
     }
 
+    private void scheduleAllCallees( HashSet<Descriptor> calleesScheduled,
+                                    Descriptor d ) {
+       if( calleesScheduled.contains( d ) ) {
+           return;
+       }
+       calleesScheduled.add( d );
+
+       Set callees = callGraph.getCalleeSet( d );
+       if( callees == null ) {
+           return;
+       }
+
+       Iterator methItr = callees.iterator();
+       while( methItr.hasNext() ) {
+           MethodDescriptor md = (MethodDescriptor) methItr.next();
+           descriptorsToVisit.add( md );
+
+           // recursively find all callees from this task
+           scheduleAllCallees( calleesScheduled, md );
+       }
+    }
+
 
     // manage the set of tasks and methods to be analyzed
     // and be sure to reschedule tasks/methods when the methods
@@ -104,8 +136,9 @@ public class OwnershipAnalysis {
                if( d instanceof MethodDescriptor ) {
                    MethodDescriptor md = (MethodDescriptor) d;
                    Set dependents = callGraph.getCallerSet( md );
-                   System.out.println( "  Caller set is: " + dependents );
-                   descriptorsToVisit.addAll( dependents );
+                   if( dependents != null ) {
+                       descriptorsToVisit.addAll( dependents );
+                   }
                }
            }
        }
@@ -202,14 +235,13 @@ public class OwnershipAnalysis {
        case FKind.FlatMethod:
            FlatMethod fm = (FlatMethod) fn;
 
-           if( isTask ) {
-               // add method parameters to the list of heap regions
-               // and remember names for analysis
-               for( int i = 0; i < fm.numParameters(); ++i ) {
-                   TempDescriptor tdParam = fm.getParameter( i );
-                   og.taskParameterAllocation( tdParam );
-                   //og.addAnalysisRegion( tdParam );
-               }
+           // there should only be one FlatMethod node as the
+           // parent of all other FlatNode objects, so take
+           // the opportunity to construct the initial graph by
+           // adding parameters labels to new heap regions
+           for( int i = 0; i < fm.numParameters(); ++i ) {
+               TempDescriptor tdParam = fm.getParameter( i );          
+               og.parameterAllocation( isTask, tdParam );
            }
            break;
            
@@ -268,9 +300,10 @@ public class OwnershipAnalysis {
            */
 
        case FKind.FlatCall:
-           FlatCall         fc = (FlatCall) fn;
-           MethodDescriptor md = fc.getMethod();
-           descriptorsToVisit.add( md );
+           //FlatCall         fc = (FlatCall) fn;
+           //MethodDescriptor md = fc.getMethod();
+           //descriptorsToVisit.add( md );
+           //System.out.println( "    Descs to visit: " + descriptorsToVisit );
            break;
 
        case FKind.FlatReturnNode:
index c32f2e0ac9c01a839e80034b3c3e2aa942facda3..63e839802b7230c49b507a682dbed82455cdac24 100644 (file)
@@ -202,11 +202,11 @@ public class OwnershipGraph {
        return hrn;
     }
 
-    public void taskParameterAllocation( TempDescriptor td ) {
+    public void parameterAllocation( boolean isTask, TempDescriptor td ) {
        assert td != null;
 
        LabelNode      lnParam = getLabelNodeFromTemp( td );
-       HeapRegionNode hrn     = createNewHeapRegionNode( null, false, true, false );
+       HeapRegionNode hrn     = createNewHeapRegionNode( null, false, isTask, false );
        heapRoots.put( hrn.getID(), hrn );
 
        addReferenceEdge( lnParam, hrn, new ReferenceEdgeProperties( false ) );
index b08e42112e273f4adfc8815880781342fc1a3d00..8bac13c23c63fb728143a76b56ca033af2a5991f 100644 (file)
@@ -6,19 +6,16 @@ public class Parameter {
        a = 0; b = 0; f = null; g = null;
     }
 
-    public void foo() { a = 1; }
+    public void bar() { foo(); }
+    public void foo() { bar(); }
 }
 
 task Startup( StartupObject s{ initialstate } ) {
-    Parameter p1 = new Parameter(){!w};
-    Parameter p2 = new Parameter(){!w};
-    taskexit( s{ !initialstate } );
-}
 
-task DoStuff( Parameter p{!w} ) {
+    Parameter p = new Parameter(){!w};
     p.foo();
 
-    taskexit( p{w} );
+    taskexit( s{ !initialstate } );
 }
 
 /*