Basic ownership analysis and a simple alias test added.
authorjjenista <jjenista>
Tue, 13 Nov 2007 19:47:11 +0000 (19:47 +0000)
committerjjenista <jjenista>
Tue, 13 Nov 2007 19:47:11 +0000 (19:47 +0000)
Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java
Robust/src/Tests/OwnershipAnalysisTest/test01/makefile [new file with mode: 0644]
Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java [new file with mode: 0644]

index 0b9a0c68975864ef9388012f6fe786a5bb37c26b..0315ac1afb0f4b08ad5b1635b2a67317caf5377e 100644 (file)
@@ -9,55 +9,45 @@ import java.io.*;
 public class OwnershipAnalysis {
 
     private State state;
-
-    private BufferedWriter flatbw;
-
     private HashSet<FlatNode> visited;
     private HashSet<FlatNode> toVisit;
-    
+
     private int labelindex;
     private Hashtable<FlatNode, Integer> flatnodetolabel;
+
     private Hashtable<FlatNode, OwnershipGraph> 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<FlatNode, Integer>();
-           visited=new HashSet<FlatNode>();
-           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<FlatNode, OwnershipGraph>();
 
-           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<FlatNode, Integer>();
+           visited         = new HashSet<FlatNode>();
+           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<fn.numNext();i++) {
                FlatNode nn=fn.getNext(i);
 
-               flatbw.write( "  node"+flatnodetolabel.get(fn)+" -> 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 (file)
index 0000000..40a7151
--- /dev/null
@@ -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 (file)
index 0000000..1eff12b
--- /dev/null
@@ -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