From 124184a0dc778228fb7755af3cf34a21726d3a7e Mon Sep 17 00:00:00 2001 From: jjenista Date: Wed, 20 Feb 2008 22:11:44 +0000 Subject: [PATCH] Changed integration of ownership analysis into Main.java --- .../OwnershipAnalysis/OwnershipAnalysis.java | 136 +++++------------- Robust/src/Main/Main.java | 5 +- .../OwnershipAnalysisTest/test01/makefile | 2 +- 3 files changed, 39 insertions(+), 104 deletions(-) diff --git a/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java b/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java index 9eae3336..d9d362cf 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java +++ b/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java @@ -1,5 +1,6 @@ package Analysis.OwnershipAnalysis; +import Analysis.CallGraph.*; import IR.*; import IR.Flat.*; import java.util.*; @@ -8,22 +9,24 @@ import java.io.*; public class OwnershipAnalysis { - /* // from the compiler - private State state; - private int allocationDepthK; + private State state; + private CallGraph callGraph; + private int allocationDepth; // Use these data structures to track progress of - // processing all methods in the program - private HashSet flatMethodsToVisit; - private Hashtable mapFlatMethodToCompleteOwnershipGraph; - private Hashtable > mapMethodToDependentMethods; + // processing all methods in the program, and by methods + // TaskDescriptor and MethodDescriptor are combined + // together, with a common parent class Descriptor + private HashSet descriptorsToVisit; + private Hashtable mapDescriptorToCompleteOwnershipGraph; // Use these data structures to track progress of one pass of - // processing the FlatNodes in a FlatMethod + // processing the FlatNodes of a particular method private HashSet flatNodesToVisit; private Hashtable mapFlatNodeToOwnershipGraph; - private HashSet returnNodesToCombineForComplete; + private HashSet returnNodesToCombineForCompleteOwnershipGraph; + // for generating unique ownership node ID's throughout the // ownership analysis @@ -37,105 +40,33 @@ public class OwnershipAnalysis { // this analysis generates an ownership graph for every task // in the program - public OwnershipAnalysis( State state ) throws java.io.IOException { - this.state = state; - this.allocationDepthK = 3; - - // the analyzeMethods() function will keep analyzing the contents - // of flatMethodsToVisit until it is empty. The following function - // will generate the method dependencies and put every task (subclass - // of method) in flatMethodsToVisit so the ownership analysis will - // cover at least every task, but might not analyze every method of - // the program if there is no dependency chain back to a task - prepareForAndEnqueueTasks(); - + public OwnershipAnalysis( State state, + CallGraph callGraph, + int allocationDepth ) throws java.io.IOException { + this.state = state; + this.callGraph = callGraph; + this.allocationDepth = allocationDepth; + + mapDescriptorToCompleteOwnershipGraph = + new Hashtable(); + + // initialize methods to visit as the set of + // all tasks + descriptorsToVisit = new HashSet(); + Iterator taskItr = state.getTaskSymbolTable().getDescriptorsIterator(); + while( taskItr.hasNext() ) { + descriptorsToVisit.add( (Descriptor) taskItr.next() ); + } + // as mentioned above, analyze methods one-by-one, possibly revisiting // a method if the methods that it calls are updated analyzeMethods(); } - // run once per program analysis - private void prepareForAndEnqueueTasks() { - flatMethodsToVisit = new HashSet(); - - mapFlatMethodToCompleteOwnershipGraph = - new Hashtable(); - - mapMethodToDependentMethods = - new Hashtable >(); - - // once the dependency map is generated here it - // doesn't need to be modified anymore. It is - // used when a method is updated to enqueue the - // methods that are dependent on the result. They - // may or may not have a different analysis outcome - - // first put all the tasks into the dependency map - Iterator itrTasks = state.getTaskSymbolTable().getDescriptorsIterator(); - while( itrTasks.hasNext() ) { - TaskDescriptor td = itrTasks.next(); - FlatMethod fm = state.getMethodFlat( td ); - - searchFlatMethodForCallNodes( td, fm ); - } - - // then put all the methods of classes into the map - } - - // called on each task and class method before ownership - // analysis is started so the method dependency map can - // be generated - private void searchFlatMethodForCallNodes( Descriptor caller, FlatMethod fm ) { - // borrow this data structure before the ownership - // analysis proper begins in order to search the IR - flatNodesToVisit = new HashSet(); - - flatNodesToVisit.add( fm ); - - while( !flatNodesToVisit.isEmpty() ) { - FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next(); - flatNodesToVisit.remove( fn ); - - if( fn.kind() == FKind.FlatClass ) { - FlatCall fc = (FlatCall) fn; - addMethodDependency( caller, fc.getMethod() ); - } - } - } - - // supports creation of the method dependency map - private void addMethodDependency( Descriptor caller, Descriptor callee ) { - - // the caller is calling the callee so the caller's - // analysis depends on the callee's analysis, - // therefore build a map that looks like this: - // callee: - // - // and only add the dependency if it doesn't already exist - - if( !mapMethodToDependentMethods.containsKey( callee ) ) { - // there is no map entry for this callee, so add it with - // just the caller as the only dependent method and return - mapMethodToDependentMethods.put( callee, caller ); - return; - } - - // if there is already an entry for the callee, check to see - // if the caller is already in the value for that map entry - HashSet dependentMethods = (HashSet) mapMethodToDependentMethods.get( callee ); - - if( !dependentMethods.contains( caller ) ) { - // the caller is not in the set of dependent methods for - // this callee, so add it and return - dependentMethods.add( caller ); - return; - } - - // the dependency was already there, do nothing - } + private void analyzeMethods() throws java.io.IOException { - private void analyzeMethods() throws java.io.IOException { + /* for( Iterator it_tasks=state.getTaskSymbolTable().getDescriptorsIterator(); it_tasks.hasNext(); ) { @@ -158,8 +89,10 @@ public class OwnershipAnalysis { String methodname = td.getSymbol(); analyzeFlatIRGraph( fm, methodname ); } + */ } + /* private OwnershipGraph getGraphFromFlatNode( FlatNode fn ) { if( !flatNodeToOwnershipGraph.containsKey( fn ) ) { flatNodeToOwnershipGraph.put( fn, new OwnershipGraph( newDepthK ) ); @@ -309,5 +242,4 @@ public class OwnershipAnalysis { return "method_"+methodname+"_Ownership_from"+id; } */ - } diff --git a/Robust/src/Main/Main.java b/Robust/src/Main/Main.java index 78d7d61e..93109038 100644 --- a/Robust/src/Main/Main.java +++ b/Robust/src/Main/Main.java @@ -406,7 +406,10 @@ public class Main { } if (state.OWNERSHIP) { - // OwnershipAnalysis oa = new OwnershipAnalysis(state); + CallGraph callGraph = new CallGraph( state ); + int allocationDepth = 3; + OwnershipAnalysis oa = + new OwnershipAnalysis( state, callGraph, allocationDepth ); } System.exit(0); diff --git a/Robust/src/Tests/OwnershipAnalysisTest/test01/makefile b/Robust/src/Tests/OwnershipAnalysisTest/test01/makefile index 0df41740..f2df2c13 100644 --- a/Robust/src/Tests/OwnershipAnalysisTest/test01/makefile +++ b/Robust/src/Tests/OwnershipAnalysisTest/test01/makefile @@ -5,7 +5,7 @@ SOURCE_FILES=test01.java BUILDSCRIPT=~/research/Robust/src/buildscript BSFLAGS= -recover -flatirtasks -ownership -enable-assertions -all: view +all: $(PROGRAM).bin #view view: PNGs eog *flatIRGraph*.png & -- 2.34.1