From: jjenista Date: Tue, 11 Mar 2008 20:31:22 +0000 (+0000) Subject: Fixed bug that heap regions from allocation sites are properly passed X-Git-Tag: preEdgeChange~235 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=bf065f7ae015d6625892f2e3bf1c2e6dfabf9416;p=IRC.git Fixed bug that heap regions from allocation sites are properly passed along when referenced in another ownership graph. Preliminary testing of allocation sites looks fine. --- diff --git a/Robust/src/Analysis/OwnershipAnalysis/HeapRegionNode.java b/Robust/src/Analysis/OwnershipAnalysis/HeapRegionNode.java index fd317186..88758c0d 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/HeapRegionNode.java +++ b/Robust/src/Analysis/OwnershipAnalysis/HeapRegionNode.java @@ -9,11 +9,13 @@ public class HeapRegionNode extends OwnershipNode { public HeapRegionNode( Integer id, boolean isSingleObject, boolean isFlagged, - boolean isNewSummary ) { + boolean isNewSummary, + String description ) { this.id = id; this.isSingleObject = isSingleObject; this.isFlagged = isFlagged; this.isNewSummary = isNewSummary; + this.description = description; referencers = new HashSet(); //analysisRegionAliases = new HashSet(); @@ -24,7 +26,8 @@ public class HeapRegionNode extends OwnershipNode { return new HeapRegionNode( id, isSingleObject, isFlagged, - isNewSummary ); + isNewSummary, + description ); } @@ -43,7 +46,8 @@ public class HeapRegionNode extends OwnershipNode { return id.equals( hrn.getID() ) && isSingleObject == hrn.isSingleObject() && isFlagged == hrn.isFlagged() && - isNewSummary == hrn.isNewSummary(); + isNewSummary == hrn.isNewSummary() && + description.equals( hrn.getDescription() ); } ///////////////// // end equality @@ -136,6 +140,8 @@ public class HeapRegionNode extends OwnershipNode { // for writing out + String description; + public String getIDString() { return id.toString(); } @@ -143,4 +149,8 @@ public class HeapRegionNode extends OwnershipNode { public String toString() { return "HRN"+getIDString(); } + + public String getDescription() { + return description; + } } diff --git a/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java b/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java index 0b71c573..c9327b4b 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java +++ b/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java @@ -176,7 +176,8 @@ public class OwnershipGraph { createNewHeapRegionNode( Integer id, boolean isSingleObject, boolean isFlagged, - boolean isNewSummary ) { + boolean isNewSummary, + String description ) { if( id == null ) { id = OwnershipAnalysis.generateUniqueHeapRegionNodeID(); @@ -185,7 +186,8 @@ public class OwnershipGraph { HeapRegionNode hrn = new HeapRegionNode( id, isSingleObject, isFlagged, - isNewSummary ); + isNewSummary, + description ); id2hrn.put( id, hrn ); return hrn; } @@ -195,8 +197,8 @@ public class OwnershipGraph { assert td != null; LabelNode lnParam = getLabelNodeFromTemp( td ); - HeapRegionNode hrn = createNewHeapRegionNode( null, false, isTask, false ); - heapRoots.put( hrn.getID(), hrn ); + HeapRegionNode hrn = createNewHeapRegionNode( null, false, isTask, false, "param" ); + //heapRoots.put( hrn.getID(), hrn ); addReferenceEdge( lnParam, hrn, new ReferenceEdgeProperties( false ) ); addReferenceEdge( hrn, hrn, new ReferenceEdgeProperties( false ) ); @@ -270,7 +272,7 @@ public class OwnershipGraph { // in different ownership graphs that represents the same part of an // allocation site if( hrnSummary == null ) { - hrnSummary = createNewHeapRegionNode( idSummary, false, false, true ); + hrnSummary = createNewHeapRegionNode( idSummary, false, false, true, "summary" ); } // first transfer the references out of alpha_k to alpha_s @@ -280,7 +282,7 @@ public class OwnershipGraph { // see comment above about needing to allocate a heap region // for the context of this ownership graph if( hrnK == null ) { - hrnK = createNewHeapRegionNode( idK, true, false, false ); + hrnK = createNewHeapRegionNode( idK, true, false, false, "alpha" ); } HeapRegionNode hrnReferencee = null; @@ -339,10 +341,10 @@ public class OwnershipGraph { // see comment above about needing to allocate a heap region // for the context of this ownership graph if( hrnI == null ) { - hrnI = createNewHeapRegionNode( idIth, true, false, false ); + hrnI = createNewHeapRegionNode( idIth, true, false, false, "alpha" ); } if( hrnImin1 == null ) { - hrnImin1 = createNewHeapRegionNode( idImin1th, true, false, false ); + hrnImin1 = createNewHeapRegionNode( idImin1th, true, false, false, "alpha" ); } // clear references in and out of node i @@ -404,7 +406,7 @@ public class OwnershipGraph { mergeOwnershipNodes ( og ); mergeReferenceEdges ( og ); - mergeHeapRoots ( og ); + //mergeHeapRoots ( og ); //mergeAnalysisRegions( og ); //mergeNewClusters ( og ); } @@ -552,6 +554,7 @@ public class OwnershipGraph { } } + /* protected void mergeHeapRoots( OwnershipGraph og ) { Set sA = og.heapRoots.entrySet(); Iterator iA = sA.iterator(); @@ -567,6 +570,7 @@ public class OwnershipGraph { } } } + */ /* protected void mergeAnalysisRegions( OwnershipGraph og ) { @@ -652,9 +656,11 @@ public class OwnershipGraph { return false; } + /* if( !areHeapRootsEqual( og ) ) { return false; } + */ /* if( !areAnalysisRegionLabelsEqual( og ) ) { @@ -914,6 +920,7 @@ public class OwnershipGraph { return true; } + /* protected boolean areHeapRootsEqual( OwnershipGraph og ) { if( og.heapRoots.size() != heapRoots.size() ) { return false; @@ -943,6 +950,8 @@ public class OwnershipGraph { return true; } + */ + /* protected boolean areAnalysisRegionLabelsEqual( OwnershipGraph og ) { @@ -1044,12 +1053,15 @@ public class OwnershipGraph { // then visit every heap region node HashSet visited = new HashSet(); - Set s = heapRoots.entrySet(); + //Set s = heapRoots.entrySet(); + Set s = id2hrn.entrySet(); Iterator i = s.iterator(); while( i.hasNext() ) { Map.Entry me = (Map.Entry) i.next(); HeapRegionNode hrn = (HeapRegionNode) me.getValue(); - traverseHeapRegionNodes( VISIT_HRN_WRITE_FULL, hrn, bw, null, visited ); + if( !visited.contains( hrn ) ) { + traverseHeapRegionNodes( VISIT_HRN_WRITE_FULL, hrn, bw, null, visited ); + } } // then visit every label node @@ -1136,25 +1148,26 @@ public class OwnershipGraph { switch( mode ) { case VISIT_HRN_WRITE_FULL: - String isSingleObjectStr = "isSingleObject"; + String isSingleObjectStr = "Single"; if( !hrn.isSingleObject() ) { - isSingleObjectStr = "!isSingleObject"; + isSingleObjectStr = "!Single"; } - String isFlaggedStr = "isFlagged"; + String isFlaggedStr = "Flagged"; if( !hrn.isFlagged() ) { - isFlaggedStr = "!isFlagged"; + isFlaggedStr = "!Flagged"; } - String isNewSummaryStr = "isNewSummary"; + String isNewSummaryStr = "Summary"; if( !hrn.isNewSummary() ) { - isNewSummaryStr = "!isNewSummary"; + isNewSummaryStr = "!Summary"; } - bw.write( " " + hrn.toString() + - "[shape=box,label=\"" + isFlaggedStr + - "\\n" + isSingleObjectStr + - "\\n" + isNewSummaryStr + + bw.write( " " + hrn.toString() + + "[shape=box,label=\"" + hrn.getDescription() + + "\\n" + isFlaggedStr + + "\\n" + isSingleObjectStr + + "\\n" + isNewSummaryStr + "\"];\n" ); break; @@ -1188,6 +1201,7 @@ public class OwnershipGraph { */ } + /* OwnershipNode onRef = null; Iterator refItr = hrn.iteratorToReferencers(); while( refItr.hasNext() ) { @@ -1201,7 +1215,7 @@ public class OwnershipGraph { break; } } - + */ HeapRegionNode hrnChild = null; Iterator childRegionsItr = hrn.setIteratorToReferencedRegions(); diff --git a/Robust/src/Tests/OwnershipAnalysisTest/README b/Robust/src/Tests/OwnershipAnalysisTest/README new file mode 100644 index 00000000..488a7826 --- /dev/null +++ b/Robust/src/Tests/OwnershipAnalysisTest/README @@ -0,0 +1,20 @@ +test01 + This test program contains many tasks that +individually illustrate the correctness of different +ownership analysis elements. The program source code +includes comments that describe what the final ownership +graphs for each task should be. These are sort of like +unit tests for the individual operations performed during +ownership analysis. + +test02 + This test program contains many tasks that are +named to indicate whether they purposefully create aliases +or not. This test comes from the top-down approach to see +that the individual operations of the ownership analysis +work together to produce the correct results. + +testGraph + This test program puts some ownership graph +objects and some supporting data in a vacuum to test +the critical merge() and equals() members. diff --git a/Robust/src/Tests/OwnershipAnalysisTest/test01/makefile b/Robust/src/Tests/OwnershipAnalysisTest/test01/makefile index 3250e18e..e4f3c3f7 100644 --- a/Robust/src/Tests/OwnershipAnalysisTest/test01/makefile +++ b/Robust/src/Tests/OwnershipAnalysisTest/test01/makefile @@ -9,7 +9,7 @@ BSFLAGS= -recover -flatirtasks -ownership -enable-assertions all: $(PROGRAM).bin view: PNGs - #eog *flatIRGraph*.png & + eog *flatIRGraph*.png & #eog *FN*.png & #eog *Ownership*.png & eog *.png & @@ -23,6 +23,8 @@ PNGs: DOTs rm -f *FlatCall*.dot rm -f *Parameter*.dot rm -f *Penguin*.dot + rm -f *Voo*.dot + rm -f *Baw*.dot d2p *.dot DOTs: $(PROGRAM).bin diff --git a/Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java b/Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java index 1e03e52c..dbe9ed9d 100644 --- a/Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java +++ b/Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java @@ -1,3 +1,4 @@ +/* public class Parameter { flag w; int a, b; @@ -17,164 +18,61 @@ public class Penguin { public void bar() { x = 1; } } +*/ -task Startup( StartupObject s{ initialstate } ) { - - /* - Parameter p = new Parameter(){!w}; - p.foo(); - - Penguin g = new Penguin(); - g.bar(); - */ - - Parameter p; - - for( int i = 0; i < 3; ++i ) { - p = new Parameter(); - p.penguin = new Penguin(); - p.penguin.bar(); - } - - p = null; - - taskexit( s{ !initialstate } ); -} - -/* -task aliasFromObjectAssignment - ( Parameter p1{!w}, Parameter p2{!w} ) { - - p1.f = p2.g; - - taskexit( p1{w}, p2{w} ); -} - -task noAliasFromPrimitiveAssignment - ( Parameter p1{!w}, Parameter p2{!w} ) { - - p1.a = p2.b; +public class Voo { + flag f; int x; Baw b; - taskexit( p1{w}, p2{w} ); + public Voo() {} } -task aliasWithTwoLinks - ( Parameter p1{!w}, Parameter p2{!w} ) { - - Parameter j = p1.f; - p2.f = j; +public class Baw { + flag g; int y; - taskexit( p1{w}, p2{w} ); + public Baw() {} } -task aliasWithThreeLinks - ( Parameter p1{!w}, Parameter p2{!w} ) { - - Parameter j = p1.f; - Parameter k = j; - p2.f = k; - taskexit( p1{w}, p2{w} ); +// this empty task should still create a non-empty +// ownership graph showing parameter allocation +// look for the parameter s as a label referencing +// a heap region that is multi-object, flagged, not summary +task Startup( StartupObject s{ initialstate } ) { + taskexit( s{ !initialstate } ); } -task noAliasBreakLinks - ( Parameter p1{!w}, Parameter p2{!w} ) { - - Parameter j = p1.f; - Parameter k = j; - k = p2.f; - p2.f = k; +// this task allocates a new object, so there should +// be a heap region for the parameter, and several +// heap regions for the allocation site, but the label +// merely points to the newest region +task NewObject( Voo v{ f } ) { + Voo w = new Voo(); - taskexit( p1{w}, p2{w} ); + taskexit( v{ !f } ); } -task possibleAliasConditional - ( Parameter p1{!w}, Parameter p2{!w} ) { - - Parameter y; +// this task +task Branch( Voo v{ f } ) { + Voo w = new Voo(); + Baw j = new Baw(); + Baw k = new Baw(); - if( p1.a == 0 ) { - y = p1.f; + if( v.x == 0 ) { + w.b = j; } else { - y = p2.f; - } - - p2.g = y; - - taskexit( p1{w}, p2{w} ); -} -*/ - -/* -task bunchOfPaths - ( Parameter p1{!w}, Parameter p2{!w} ) { - - Parameter y; - - for( int i =0; i < 100; ++i ) { - - if( y == p1 ) { - Parameter z; - - for( int j = 0; i < 50; ++j ) { - if( z == y ) { - p1.f = y; - } else { - z = p2.g; - } - - p1.f = z; - } - - y = p1.g; - } else { - - p2.f = y; - } + w.b = k; } - p1.f = p2.g; - - - taskexit( p1{w}, p2{w} ); + taskexit( v{ !f } ); } -*/ - -/* -task literalTest( Parameter p1{!w} ) { - Parameter x = null; - int y = 5; - String s = "Dude"; - taskexit( p1{w} ); -} -task newNoAlias - ( Parameter p1{!w}, Parameter p2{!w} ) { +task NewInLoop( Voo v{ f } ) { + Voo w = new Voo(); - for( int i = 0; i < 1; ++i ) { - p1.f = new Parameter(); + for( int i = 0; i < 10; ++i ) { + w.b = new Baw(); } - taskexit( p1{w}, p2{w} ); -} - -task newPossibleAlias - ( Parameter p1{!w}, Parameter p2{!w} ) { - - Parameter x, y; - - for( int i = 0; i < 1; ++i ) { - p1.f = new Parameter(); - if( true ) { - x = p1.f; - } else { - y = p1.f; - } - } - - p2.f = y; - - taskexit( p1{w}, p2{w} ); + taskexit( v{ !f } ); } -*/ \ No newline at end of file diff --git a/Robust/src/Tests/OwnershipAnalysisTest/test02/makefile b/Robust/src/Tests/OwnershipAnalysisTest/test02/makefile new file mode 100644 index 00000000..b93cb876 --- /dev/null +++ b/Robust/src/Tests/OwnershipAnalysisTest/test02/makefile @@ -0,0 +1,38 @@ +PROGRAM=test02 + +SOURCE_FILES=test02.java + +BUILDSCRIPT=~/research/Robust/src/buildscript +BSFLAGS= -recover -flatirtasks -ownership -enable-assertions +#BSFLAGS= -recover -ownership -enable-assertions + +all: $(PROGRAM).bin + +view: PNGs + #eog *flatIRGraph*.png & + #eog *FN*.png & + #eog *Ownership*.png & + eog *.png & + +PNGs: DOTs + #rm -f *Startup*.dot + rm -f *FlatMethod*.dot + rm -f *FlatOpNode*.dot + rm -f *FlatFieldNode*.dot + rm -f *FlatSetFieldNode*.dot + rm -f *FlatCall*.dot + rm -f *Parameter*.dot + rm -f *Penguin*.dot + d2p *.dot + +DOTs: $(PROGRAM).bin + +$(PROGRAM).bin: $(SOURCE_FILES) + $(BUILDSCRIPT) $(BSFLAGS) -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/test02/test02.java b/Robust/src/Tests/OwnershipAnalysisTest/test02/test02.java new file mode 100644 index 00000000..1e03e52c --- /dev/null +++ b/Robust/src/Tests/OwnershipAnalysisTest/test02/test02.java @@ -0,0 +1,180 @@ +public class Parameter { + flag w; + int a, b; + Parameter f, g; + Penguin penguin; + + public Parameter() { a = 0; b = 0; f = null; g = null; } + + public void bar() { foo(); } + public void foo() { bar(); } +} + +public class Penguin { + int x, y; + + public Penguin() { x = 0; y = 0; } + + public void bar() { x = 1; } +} + +task Startup( StartupObject s{ initialstate } ) { + + /* + Parameter p = new Parameter(){!w}; + p.foo(); + + Penguin g = new Penguin(); + g.bar(); + */ + + Parameter p; + + for( int i = 0; i < 3; ++i ) { + p = new Parameter(); + p.penguin = new Penguin(); + p.penguin.bar(); + } + + p = null; + + taskexit( s{ !initialstate } ); +} + +/* +task aliasFromObjectAssignment + ( Parameter p1{!w}, Parameter p2{!w} ) { + + p1.f = p2.g; + + taskexit( p1{w}, p2{w} ); +} + +task noAliasFromPrimitiveAssignment + ( Parameter p1{!w}, Parameter p2{!w} ) { + + p1.a = p2.b; + + taskexit( p1{w}, p2{w} ); +} + +task aliasWithTwoLinks + ( Parameter p1{!w}, Parameter p2{!w} ) { + + Parameter j = p1.f; + p2.f = j; + + taskexit( p1{w}, p2{w} ); +} + +task aliasWithThreeLinks + ( Parameter p1{!w}, Parameter p2{!w} ) { + + Parameter j = p1.f; + Parameter k = j; + p2.f = k; + + taskexit( p1{w}, p2{w} ); +} + +task noAliasBreakLinks + ( Parameter p1{!w}, Parameter p2{!w} ) { + + Parameter j = p1.f; + Parameter k = j; + k = p2.f; + p2.f = k; + + taskexit( p1{w}, p2{w} ); +} + +task possibleAliasConditional + ( Parameter p1{!w}, Parameter p2{!w} ) { + + Parameter y; + + if( p1.a == 0 ) { + y = p1.f; + } else { + y = p2.f; + } + + p2.g = y; + + taskexit( p1{w}, p2{w} ); +} +*/ + +/* +task bunchOfPaths + ( Parameter p1{!w}, Parameter p2{!w} ) { + + Parameter y; + + for( int i =0; i < 100; ++i ) { + + if( y == p1 ) { + Parameter z; + + for( int j = 0; i < 50; ++j ) { + if( z == y ) { + p1.f = y; + } else { + z = p2.g; + } + + p1.f = z; + } + + y = p1.g; + } else { + + p2.f = y; + } + } + + p1.f = p2.g; + + + taskexit( p1{w}, p2{w} ); +} +*/ + +/* +task literalTest( Parameter p1{!w} ) { + Parameter x = null; + int y = 5; + String s = "Dude"; + + taskexit( p1{w} ); +} + +task newNoAlias + ( Parameter p1{!w}, Parameter p2{!w} ) { + + for( int i = 0; i < 1; ++i ) { + p1.f = new Parameter(); + } + + taskexit( p1{w}, p2{w} ); +} + +task newPossibleAlias + ( Parameter p1{!w}, Parameter p2{!w} ) { + + Parameter x, y; + + for( int i = 0; i < 1; ++i ) { + p1.f = new Parameter(); + if( true ) { + x = p1.f; + } else { + y = p1.f; + } + } + + p2.f = y; + + taskexit( p1{w}, p2{w} ); +} +*/ \ No newline at end of file