From 12af22ba413b80738ce8f8c8de4b72b247d1e4f1 Mon Sep 17 00:00:00 2001 From: jjenista Date: Fri, 29 Feb 2008 20:41:39 +0000 Subject: [PATCH] Method scheduling handles recursion and dependency. --- .../OwnershipAnalysis/OwnershipAnalysis.java | 63 ++++++++++++++----- .../OwnershipAnalysis/OwnershipGraph.java | 4 +- .../OwnershipAnalysisTest/test01/test01.java | 11 ++-- 3 files changed, 54 insertions(+), 24 deletions(-) diff --git a/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java b/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java index 1f85dde2..81ae21c0 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java +++ b/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java @@ -49,19 +49,51 @@ public class OwnershipAnalysis { mapFlatNewToAllocationSite = new Hashtable(); - // initialize methods to visit as the set of all tasks descriptorsToVisit = new HashSet(); + + // use this set to prevent infinite recursion when + // traversing the call graph + HashSet calleesScheduled = new HashSet(); + + // 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 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: diff --git a/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java b/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java index c32f2e0a..63e83980 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java +++ b/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java @@ -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 ) ); diff --git a/Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java b/Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java index b08e4211..8bac13c2 100644 --- a/Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java +++ b/Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java @@ -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 } ); } /* -- 2.34.1