From b7b292c16e2ff414817915b722c3bd538257ec18 Mon Sep 17 00:00:00 2001 From: jjenista Date: Tue, 15 Sep 2009 17:57:58 +0000 Subject: [PATCH] added support for null heap region, doesn't work perfectly because null region gets outgoing edges --- .../OwnershipAnalysis/OwnershipAnalysis.java | 14 ++++++++ .../OwnershipAnalysis/OwnershipGraph.java | 36 +++++++++++++++++++ .../OwnershipAnalysisTest/testBug/makefile | 27 ++++++++++++++ .../OwnershipAnalysisTest/testBug/test.java | 24 +++++++++++++ .../OwnershipAnalysisTest/testNull/makefile | 27 ++++++++++++++ .../OwnershipAnalysisTest/testNull/test.java | 26 ++++++++++++++ 6 files changed, 154 insertions(+) create mode 100644 Robust/src/Tests/OwnershipAnalysisTest/testBug/makefile create mode 100644 Robust/src/Tests/OwnershipAnalysisTest/testBug/test.java create mode 100644 Robust/src/Tests/OwnershipAnalysisTest/testNull/makefile create mode 100644 Robust/src/Tests/OwnershipAnalysisTest/testNull/test.java diff --git a/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java b/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java index 276890f2..f1d1d1c6 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java +++ b/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java @@ -313,6 +313,10 @@ public class OwnershipAnalysis { // reserved IDs for special purposes static private int uniqueIDcount = 10; + // special purpose region for "null" + // included in every graph + static public int nullRegionID = 9; + // Use these data structures to track progress of // processing all methods in the program, and by methods @@ -757,6 +761,16 @@ public class OwnershipAnalysis { } break; + case FKind.FlatLiteralNode: + FlatLiteralNode fln = (FlatLiteralNode) fn; + if( fln.getValue() == null ) { + // when we set something to null, use the special + // "null" heap region as the target + lhs = fln.getDst(); + og.assignTempXEqualToNull(lhs); + } + break; + case FKind.FlatOpNode: FlatOpNode fon = (FlatOpNode) fn; if( fon.getOp().getOp() == Operation.ASSIGN ) { diff --git a/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java b/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java index ed84c1b9..b1a3ef7e 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java +++ b/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java @@ -67,6 +67,9 @@ public class OwnershipGraph { public Hashtable paramIndex2paramTokenSecondaryStar; + public HeapRegionNode hrnNull; + + public OwnershipGraph(int allocationDepth, TypeUtil typeUtil) { this.allocationDepth = allocationDepth; this.typeUtil = typeUtil; @@ -91,6 +94,16 @@ public class OwnershipGraph { paramIndex2paramTokenSecondaryStar = new Hashtable(); allocationSites = new HashSet (); + + hrnNull = createNewHeapRegionNode( OwnershipAnalysis.nullRegionID, + false, + false, + false, + false, + null, + null, + null, + "null" ); } @@ -312,6 +325,23 @@ public class OwnershipGraph { } + public void assignTempXEqualToNull(TempDescriptor x) { + + LabelNode lnX = getLabelNodeFromTemp(x); + + clearReferenceEdgesFrom(lnX, null, null, true); + + ReferenceEdge edgeNew = new ReferenceEdge(lnX, + hrnNull, + null, + null, + false, + null); + + addReferenceEdge(lnX, hrnNull, edgeNew); + } + + public void assignTypedTempXEqualToTempY(TempDescriptor x, TempDescriptor y, TypeDescriptor type) { @@ -3222,6 +3252,12 @@ public class OwnershipGraph { HashSet possibleCallerHRNs = new HashSet(); + if( hrnCallee == ogCallee.hrnNull ) { + // this is the null heap region + possibleCallerHRNs.add( id2hrn.get( hrnCallee.getID() ) ); + return possibleCallerHRNs; + } + Set paramIndicesCallee_p = ogCallee.idPrimary2paramIndexSet .get( hrnCallee.getID() ); Set paramIndicesCallee_s = ogCallee.idSecondary2paramIndexSet.get( hrnCallee.getID() ); diff --git a/Robust/src/Tests/OwnershipAnalysisTest/testBug/makefile b/Robust/src/Tests/OwnershipAnalysisTest/testBug/makefile new file mode 100644 index 00000000..fdfcf351 --- /dev/null +++ b/Robust/src/Tests/OwnershipAnalysisTest/testBug/makefile @@ -0,0 +1,27 @@ +PROGRAM=test + +SOURCE_FILES=$(PROGRAM).java + +BUILDSCRIPT=~/research/Robust/src/buildscript +BSFLAGS= -mainclass Test -justanalyze -ownership -ownallocdepth 1 -ownwritedots final -ownaliasfile aliases.txt -enable-assertions + +all: $(PROGRAM).bin + +view: PNGs + eog *.png & + +PNGs: DOTs + d2p *COMPLETE*.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 + rm -f aliases.txt diff --git a/Robust/src/Tests/OwnershipAnalysisTest/testBug/test.java b/Robust/src/Tests/OwnershipAnalysisTest/testBug/test.java new file mode 100644 index 00000000..a313b764 --- /dev/null +++ b/Robust/src/Tests/OwnershipAnalysisTest/testBug/test.java @@ -0,0 +1,24 @@ +public class Foo { + public Foo() {} + + Bar x; + Bar y; +} + +public class Bar { + public Bar() {} +} + + +public class Test { + + static public void main( String[] args ) { + + Foo foo = new Foo(); + + foo.x = new Bar(); + foo.y = new Bar(); + + Bar a1 = foo.x; + } +} diff --git a/Robust/src/Tests/OwnershipAnalysisTest/testNull/makefile b/Robust/src/Tests/OwnershipAnalysisTest/testNull/makefile new file mode 100644 index 00000000..fdfcf351 --- /dev/null +++ b/Robust/src/Tests/OwnershipAnalysisTest/testNull/makefile @@ -0,0 +1,27 @@ +PROGRAM=test + +SOURCE_FILES=$(PROGRAM).java + +BUILDSCRIPT=~/research/Robust/src/buildscript +BSFLAGS= -mainclass Test -justanalyze -ownership -ownallocdepth 1 -ownwritedots final -ownaliasfile aliases.txt -enable-assertions + +all: $(PROGRAM).bin + +view: PNGs + eog *.png & + +PNGs: DOTs + d2p *COMPLETE*.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 + rm -f aliases.txt diff --git a/Robust/src/Tests/OwnershipAnalysisTest/testNull/test.java b/Robust/src/Tests/OwnershipAnalysisTest/testNull/test.java new file mode 100644 index 00000000..e0b1231b --- /dev/null +++ b/Robust/src/Tests/OwnershipAnalysisTest/testNull/test.java @@ -0,0 +1,26 @@ +public class Foo { + public Foo() {} + + Bar x; + Bar y; +} + +public class Bar { + public Bar() {} +} + + +public class Test { + + static public void main( String[] args ) { + + Foo foo = new Foo(); + + foo.x = new Bar(); + foo.y = new Bar(); + + Bar a1 = foo.x; + + a1 = null; + } +} -- 2.34.1