From 5f06b717dfa1768e957b980029387db5b0c6097c Mon Sep 17 00:00:00 2001 From: jjenista Date: Tue, 13 Nov 2007 19:47:11 +0000 Subject: [PATCH] Basic ownership analysis and a simple alias test added. --- .../OwnershipAnalysis/OwnershipAnalysis.java | 72 +++++++------------ .../OwnershipAnalysisTest/test01/makefile | 28 ++++++++ .../OwnershipAnalysisTest/test01/test01.java | 29 ++++++++ 3 files changed, 82 insertions(+), 47 deletions(-) create mode 100644 Robust/src/Tests/OwnershipAnalysisTest/test01/makefile create mode 100644 Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java diff --git a/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java b/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java index 0b9a0c68..0315ac1a 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java +++ b/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java @@ -9,55 +9,45 @@ import java.io.*; public class OwnershipAnalysis { private State state; - - private BufferedWriter flatbw; - private HashSet visited; private HashSet toVisit; - + private int labelindex; private Hashtable flatnodetolabel; + private Hashtable flatNodeToOwnershipGraph; // this analysis generates an ownership graph for every task // in the program public OwnershipAnalysis(State state) throws java.io.IOException { - this.state=state; - - System.out.println( "Performing Ownership Analysis..." ); + this.state=state; - // analyzeTasks(); + analyzeTasks(); } - /* public void analyzeTasks() throws java.io.IOException { - for(Iterator it_tasks=state.getTaskSymbolTable().getDescriptorsIterator();it_tasks.hasNext();) { - - // extract task data and flat IR graph of the task - TaskDescriptor td = (TaskDescriptor)it_tasks.next(); - FlatMethod fm = state.getMethodFlat(td); - String taskname=td.getSymbol(); - - // give every node in the flat IR graph a unique label - // so a human being can inspect the graph and verify - // correctness - flatnodetolabel=new Hashtable(); - visited=new HashSet(); - labelindex=0; - labelFlatNodes(fm); + for( Iterator it_tasks=state.getTaskSymbolTable().getDescriptorsIterator(); + it_tasks.hasNext(); + ) { // initialize the mapping of flat nodes to ownership graphs // every flat node in the IR graph has its own ownership graph flatNodeToOwnershipGraph = new Hashtable(); - flatbw=new BufferedWriter(new FileWriter("task"+taskname+"_FlatIR.dot")); - flatbw.write("digraph Task"+taskname+" {\n"); + TaskDescriptor td = (TaskDescriptor)it_tasks.next(); + FlatMethod fm = state.getMethodFlat( td ); - analyzeFlatIRGraph(fm,taskname); + // give every node in the flat IR graph a unique label + // so a human being can inspect the graph and verify + // correctness + flatnodetolabel = new Hashtable(); + visited = new HashSet(); + labelindex = 0; + labelFlatNodes( fm ); - flatbw.write("}\n"); - flatbw.close(); + String taskname = td.getSymbol(); + analyzeFlatIRGraph( fm, taskname ); } } @@ -94,26 +84,25 @@ public class OwnershipAnalysis { OwnershipGraph og = getGraphFromFlat( fn ); if( fn.kind() == FKind.FlatMethod ) { - - // FlatMethod does not have toString - flatbw.write( makeDotNodeDec( taskname, flatnodetolabel.get(fn), fn.getClass().getName(), "FlatMethod" ) ); - FlatMethod fmd = (FlatMethod) fn; - // the FlatMethod is the top-level node, so take the opportunity to - // generate regions of the heap for each parameter to start the + // the FlatMethod is the top-level node, so generate + // regions of the heap for each parameter to start the // analysis for( int i = 0; i < fmd.numParameters(); ++i ) { TempDescriptor tdParam = fmd.getParameter( i ); og.newHeapRegion( tdParam ); } - } else { - flatbw.write( makeDotNodeDec( taskname, flatnodetolabel.get(fn), fn.getClass().getName(), fn.toString() ) ); } TempDescriptor src; TempDescriptor dst; FieldDescriptor fld; switch(fn.kind()) { + + case FKind.FlatMethod: + og.writeGraph( makeNodeName( taskname, flatnodetolabel.get(fn), "Method" ) ); + break; + case FKind.FlatOpNode: FlatOpNode fon = (FlatOpNode) fn; if(fon.getOp().getOp()==Operation.ASSIGN) { @@ -153,8 +142,6 @@ public class OwnershipAnalysis { for(int i=0;i node"+flatnodetolabel.get(nn)+";\n" ); - if( !visited.contains( nn ) ) { // FIX THE COPY!!!!!!!!!!!!!!! //flatNodeToOwnershipGraph.put( nn, og.copy() ); @@ -169,13 +156,4 @@ public class OwnershipAnalysis { String s = String.format( "%05d", id ); return "task"+taskname+"_FN"+s+"_"+type; } - - private String makeDotNodeDec( String taskname, Integer id, String type, String details ) { - if( details == null ) { - return " node"+id+"[label=\""+makeNodeName(taskname,id,type)+"\"];\n"; - } else { - return " node"+id+"[label=\""+makeNodeName(taskname,id,type)+"\\n"+details+"\"];\n"; - } - } - */ } diff --git a/Robust/src/Tests/OwnershipAnalysisTest/test01/makefile b/Robust/src/Tests/OwnershipAnalysisTest/test01/makefile new file mode 100644 index 00000000..40a71515 --- /dev/null +++ b/Robust/src/Tests/OwnershipAnalysisTest/test01/makefile @@ -0,0 +1,28 @@ +PROGRAM=test01 + +SOURCE_FILES=test01.java + +BUILDSCRIPT=~/research/Robust/src/buildscript + + +all: view + +view: PNGs + eog *flatIRGraph*.png & + eog *FN*.png & + +PNGs: DOTs + rm -f graph*.dot + d2p *.dot + +DOTs: $(PROGRAM).bin + +$(PROGRAM).bin: $(SOURCE_FILES) + $(BUILDSCRIPT) -recover -flatirtasks -ownership -o $(PROGRAM) $(SOURCE_FILES) + +clean: + rm -f $(PROGRAM).bin + rm -fr tmpbuilddirectory + rm -f *~ + rm -f *.dot + rm -f *.png diff --git a/Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java b/Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java new file mode 100644 index 00000000..1eff12be --- /dev/null +++ b/Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java @@ -0,0 +1,29 @@ +public class Thing { int z; public Thing(){} } + +public class P1 { + public P1(){} + flag a; + int x; + Thing m; +} + +public class P2 { + public P2(){} + flag b; + int y; + Thing n; +} + +task Startup( StartupObject s{ initialstate } ) { + P1 p1 = new P1(){}; + P2 p2 = new P2(){}; + taskexit( s{ !initialstate } ); +} + + +task A( P1 p1{!a}, P2 p2{!b} ) +{ + p1.m = p2.n; + + taskexit( p1{a}, p2{b} ); +} \ No newline at end of file -- 2.34.1