From a96da08b7d38e762701aecd8d080e1b596a1b32e Mon Sep 17 00:00:00 2001 From: jjenista Date: Tue, 8 Apr 2008 20:50:50 +0000 Subject: [PATCH] Fixed a bug in assigning temp to new allocation. Clear other references from the destination temp before assigning a reference to the newest heap region for the allocation site. --- .../OwnershipAnalysis/AllocationSite.java | 6 +- .../OwnershipAnalysis/HeapRegionNode.java | 9 +- .../OwnershipAnalysis/OwnershipGraph.java | 134 +++++++++++------- .../OwnershipAnalysisTest/test01/makefile | 18 ++- .../OwnershipAnalysisTest/test01/test01.java | 15 +- 5 files changed, 121 insertions(+), 61 deletions(-) diff --git a/Robust/src/Analysis/OwnershipAnalysis/AllocationSite.java b/Robust/src/Analysis/OwnershipAnalysis/AllocationSite.java index 469fc425..d6ffc614 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/AllocationSite.java +++ b/Robust/src/Analysis/OwnershipAnalysis/AllocationSite.java @@ -46,6 +46,10 @@ public class AllocationSite { } + public int getAllocationDepth() { + return allocationDepth; + } + public void setIthOldest( int i, Integer id ) { assert i >= 0; assert i < allocationDepth; @@ -79,6 +83,6 @@ public class AllocationSite { } public String toString() { - return "allocSite" + id + "\\n" + type; + return "allocSite" + id; } } diff --git a/Robust/src/Analysis/OwnershipAnalysis/HeapRegionNode.java b/Robust/src/Analysis/OwnershipAnalysis/HeapRegionNode.java index 88758c0d..15b5c442 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/HeapRegionNode.java +++ b/Robust/src/Analysis/OwnershipAnalysis/HeapRegionNode.java @@ -17,9 +17,8 @@ public class HeapRegionNode extends OwnershipNode { this.isNewSummary = isNewSummary; this.description = description; - referencers = new HashSet(); - //analysisRegionAliases = new HashSet(); - memberFields = new HashSet(); + referencers = new HashSet(); + memberFields = new HashSet(); } public HeapRegionNode copy() { @@ -150,7 +149,9 @@ public class HeapRegionNode extends OwnershipNode { return "HRN"+getIDString(); } + // WHY WHY WHY WHY WHY WHY?! public String getDescription() { - return description; + return new String( description ); + //return new String( description+" ID "+getIDString() ); } } diff --git a/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java b/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java index 4e711b49..fba119c8 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java +++ b/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java @@ -90,7 +90,8 @@ public class OwnershipGraph { HeapRegionNode referencee, ReferenceEdgeProperties rep ) { assert referencer != null; - assert referencee != null; + assert referencee != null; + assert rep != null; referencer.addReferencedRegion( referencee, rep ); referencee.addReferencer( referencer ); } @@ -159,12 +160,11 @@ public class OwnershipGraph { HeapRegionNode newReferencee = null; Iterator srcRegionsItr = srcln.setIteratorToReferencedRegions(); while( srcRegionsItr.hasNext() ) { - Map.Entry me = (Map.Entry) srcRegionsItr.next(); - newReferencee = (HeapRegionNode) me.getKey(); - //ReferenceEdgeProperties rep = (ReferenceEdgeProperties) me.getValue(); - ReferenceEdgeProperties rep = new ReferenceEdgeProperties(); - - addReferenceEdge( dstln, newReferencee, rep.copy() ); + Map.Entry me = (Map.Entry) srcRegionsItr.next(); + newReferencee = (HeapRegionNode) me.getKey(); + + ReferenceEdgeProperties rep = new ReferenceEdgeProperties(); + addReferenceEdge( dstln, newReferencee, rep ); } } @@ -185,12 +185,11 @@ public class OwnershipGraph { HeapRegionNode hrnOneHop = null; Iterator hrnRegionsItr = hrn.setIteratorToReferencedRegions(); while( hrnRegionsItr.hasNext() ) { - Map.Entry meH = (Map.Entry) hrnRegionsItr.next(); - hrnOneHop = (HeapRegionNode) meH.getKey(); - //ReferenceEdgeProperties rep = (ReferenceEdgeProperties) meH.getValue(); - ReferenceEdgeProperties rep = new ReferenceEdgeProperties(); + Map.Entry meH = (Map.Entry) hrnRegionsItr.next(); + hrnOneHop = (HeapRegionNode) meH.getKey(); - addReferenceEdge( dstln, hrnOneHop, rep.copy() ); + ReferenceEdgeProperties rep = new ReferenceEdgeProperties(); + addReferenceEdge( dstln, hrnOneHop, rep ); } } } @@ -210,12 +209,11 @@ public class OwnershipGraph { HeapRegionNode hrnSrc = null; Iterator srcRegionsItr = srcln.setIteratorToReferencedRegions(); while( srcRegionsItr.hasNext() ) { - Map.Entry meS = (Map.Entry) srcRegionsItr.next(); - hrnSrc = (HeapRegionNode) meS.getKey(); - //ReferenceEdgeProperties rep = (ReferenceEdgeProperties) meS.getValue(); - ReferenceEdgeProperties rep = new ReferenceEdgeProperties(); + Map.Entry meS = (Map.Entry) srcRegionsItr.next(); + hrnSrc = (HeapRegionNode) meS.getKey(); - addReferenceEdge( hrn, hrnSrc, rep.copy() ); + ReferenceEdgeProperties rep = new ReferenceEdgeProperties(); + addReferenceEdge( hrn, hrnSrc, rep ); } } } @@ -266,7 +264,27 @@ public class OwnershipGraph { LabelNode dst = getLabelNodeFromTemp( td ); + + + /* + try { + if( dude < 9 ) { + writeGraph( "global"+dude+"_0before_assign_"+dst+"_2_"+hrnNewest.getID() ); + } + } catch( Exception e ) {} + */ + + clearReferenceEdgesFrom( dst ); addReferenceEdge( dst, hrnNewest, new ReferenceEdgeProperties( false ) ); + + /* + try { + if( dude < 9 ) { + writeGraph( "global"+dude+"_1after_assign_"+dst+"_2_"+hrnNewest.getID() ); + } + ++dude; + } catch( Exception e ) {} + */ } @@ -284,8 +302,19 @@ public class OwnershipGraph { // site, attempts to retrieve the heap region nodes using the // integer id's contained in the allocation site should always // return non-null heap regions. + + private static int dude = 0; public void age( AllocationSite as ) { + /* + try { + if( dude < 9 ) { + writeGraph( "global"+dude+"_before_age"+as ); + } + //++dude; + } catch( Exception e ) {} + */ + ////////////////////////////////////////////////////////////////// // // move existing references down the line toward @@ -320,22 +349,22 @@ public class OwnershipGraph { false, as.getType().getClassDesc().hasFlags(), true, - as + "\\nsummary" ); + as + "\\n" + as.getType() + "\\nsummary" ); + + for( int i = 0; i < as.getAllocationDepth(); ++i ) { + Integer idIth = as.getIthOldest( i ); + assert !id2hrn.containsKey( idIth ); + createNewHeapRegionNode( idIth, + true, + as.getType().getClassDesc().hasFlags(), + false, + as + "\\n" + as.getType() + "\\n" + i + " oldest" ); + } } // first transfer the references out of alpha_k to alpha_s Integer idK = as.getOldest(); HeapRegionNode hrnK = id2hrn.get( idK ); - - // see comment above about needing to allocate a heap region - // for the context of this ownership graph - if( hrnK == null ) { - hrnK = createNewHeapRegionNode( idK, - true, - as.getType().getClassDesc().hasFlags(), - false, - as + "\\noldest" ); - } HeapRegionNode hrnReferencee = null; Iterator itrReferencee = hrnK.setIteratorToReferencedRegions(); @@ -384,29 +413,12 @@ public class OwnershipGraph { // alpha_0 to alpha_1 before we finish for( int i = allocationDepth - 1; i > 0; --i ) { - // move references from the ith oldest to the i+1 oldest + // move references from the i-1 oldest to the ith oldest Integer idIth = as.getIthOldest( i ); HeapRegionNode hrnI = id2hrn.get( idIth ); Integer idImin1th = as.getIthOldest( i - 1 ); HeapRegionNode hrnImin1 = id2hrn.get( idImin1th ); - // see comment above about needing to allocate a heap region - // for the context of this ownership graph - if( hrnI == null ) { - hrnI = createNewHeapRegionNode( idIth, - true, - as.getType().getClassDesc().hasFlags(), - false, - as + "\\n" + Integer.toString( i ) + "th" ); - } - if( hrnImin1 == null ) { - hrnImin1 = createNewHeapRegionNode( idImin1th, - true, - as.getType().getClassDesc().hasFlags(), - false, - as + "\\n" + Integer.toString( i-1 ) + "th" ); - } - // clear references in and out of node i clearReferenceEdgesFrom( hrnI ); clearReferenceEdgesTo ( hrnI ); @@ -447,7 +459,16 @@ public class OwnershipGraph { // clear all references in and out of newest node clearReferenceEdgesFrom( hrn0 ); - clearReferenceEdgesTo ( hrn0 ); + clearReferenceEdgesTo ( hrn0 ); + + /* + try { + if( dude < 9 ) { + writeGraph( "global"+dude+"_after_age"+as ); + } + ++dude; + } catch( Exception e ) {} + */ } @@ -624,7 +645,6 @@ public class OwnershipGraph { // represents the passed in graph and the suffix // B refers to the graph in this object //////////////////////////////////////////////////// - public void merge( OwnershipGraph og ) { if( og == null ) { @@ -1127,6 +1147,8 @@ public class OwnershipGraph { BufferedWriter bw = new BufferedWriter( new FileWriter( graphName+".dot" ) ); bw.write( "digraph "+graphName+" {\n" ); + //bw.write( " size=\"7.5,10\";\n" ); + // then visit every heap region node HashSet visited = new HashSet(); @@ -1141,8 +1163,10 @@ public class OwnershipGraph { } } - // then visit every label node + bw.write( " graphTitle[label=\""+graphName+"\",shape=box];\n" ); + /* + // then visit every label node s = td2ln.entrySet(); i = s.iterator(); while( i.hasNext() ) { @@ -1168,6 +1192,7 @@ public class OwnershipGraph { } */ + bw.write( "}\n" ); bw.close(); } @@ -1199,8 +1224,10 @@ public class OwnershipGraph { attributes += ",style=filled,fillcolor=lightgrey"; } - attributes += ",label=\"" + - hrn.getDescription() + + attributes += ",label=\"ID" + + hrn.getID() + + "\\n" + + hrn.getDescription() + "\"]"; bw.write( " " + hrn.toString() + attributes + ";\n" ); @@ -1208,10 +1235,10 @@ public class OwnershipGraph { } + /* // go back and let a compile flag control whether the light // gray "referencer" edges are written to dot files. It makes - // the graph cluttered but can be useful for debugging. - /* + // the graph cluttered but can be useful for debugging. OwnershipNode onRef = null; Iterator refItr = hrn.iteratorToReferencers(); while( refItr.hasNext() ) { @@ -1227,6 +1254,7 @@ public class OwnershipGraph { } */ + HeapRegionNode hrnChild = null; Iterator childRegionsItr = hrn.setIteratorToReferencedRegions(); while( childRegionsItr.hasNext() ) { diff --git a/Robust/src/Tests/OwnershipAnalysisTest/test01/makefile b/Robust/src/Tests/OwnershipAnalysisTest/test01/makefile index e4f3c3f7..9168b1cd 100644 --- a/Robust/src/Tests/OwnershipAnalysisTest/test01/makefile +++ b/Robust/src/Tests/OwnershipAnalysisTest/test01/makefile @@ -3,7 +3,7 @@ PROGRAM=test01 SOURCE_FILES=test01.java BUILDSCRIPT=~/research/Robust/src/buildscript -BSFLAGS= -recover -flatirtasks -ownership -enable-assertions +BSFLAGS= -recover -flatirtasks -ownership #-enable-assertions #BSFLAGS= -recover -ownership -enable-assertions all: $(PROGRAM).bin @@ -14,6 +14,20 @@ view: PNGs #eog *Ownership*.png & eog *.png & +printable: + 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 + rm -f *Voo*.dot + rm -f *Baw*.dot + rm -f *COMPLETE.dot + dot2eps *.dot + PNGs: DOTs #rm -f *Startup*.dot rm -f *FlatMethod*.dot @@ -38,3 +52,5 @@ clean: rm -f *~ rm -f *.dot rm -f *.png + rm -f *.ps + rm -f *.eps diff --git a/Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java b/Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java index 26050fc7..161abb19 100644 --- a/Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java +++ b/Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java @@ -51,20 +51,29 @@ public class Foo { // a heap region that is multi-object, flagged, not summary task Startup( StartupObject s{ initialstate } ) { + /* Foo a = new Foo(); Foo b = new Foo(); Foo c = new Foo(); c.ruinSomeFoos( a, b ); + */ + + while( false ) { + Foo a = new Foo(); + a.x = new Foo(); + a.x.x = new Foo(); + } taskexit( s{ !initialstate } ); } +/* + // 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(); Baw b = new Baw(); @@ -105,4 +114,6 @@ task ClobberInitParamReflex( Voo v{ f }, Voo w{ f } ) { v.b = v.bb; taskexit( v{ !f }, w{ !f } ); -} \ No newline at end of file +} + +*/ -- 2.34.1