From 1e1642dc7db48d120e0f8eab88268bc6f85c899a Mon Sep 17 00:00:00 2001 From: jjenista Date: Sat, 31 Jan 2009 00:00:02 +0000 Subject: [PATCH] Added disjoint analysis for Java --- .../OwnershipAnalysis/AllocationSite.java | 9 +++- .../OwnershipAnalysis/OwnershipAnalysis.java | 40 ++++++++++++--- .../OwnershipAnalysis/OwnershipGraph.java | 2 +- Robust/src/IR/Flat/BuildFlat.java | 4 +- Robust/src/IR/Flat/FlatNew.java | 23 +++++++++ Robust/src/IR/Tree/BuildIR.java | 6 ++- Robust/src/IR/Tree/CreateObjectNode.java | 8 ++- Robust/src/Lex/Keyword.java | 2 + Robust/src/Lex/Lexer.java | 4 +- Robust/src/Parse/java14.cup | 33 +++++++++++- Robust/src/Tests/mlp/syntaxTest/makefile | 2 +- Robust/src/Tests/mlp/syntaxTest/test.java | 50 +++++++++++-------- 12 files changed, 143 insertions(+), 40 deletions(-) diff --git a/Robust/src/Analysis/OwnershipAnalysis/AllocationSite.java b/Robust/src/Analysis/OwnershipAnalysis/AllocationSite.java index 34864eb7..7829ea11 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/AllocationSite.java +++ b/Robust/src/Analysis/OwnershipAnalysis/AllocationSite.java @@ -28,6 +28,7 @@ public class AllocationSite { protected Vector ithOldest; protected Integer summary; protected FlatNew flatNew; + protected boolean forceAnalyze; public static final int AGE_notInThisSite = 100; public static final int AGE_in_I = 101; @@ -40,11 +41,12 @@ public class AllocationSite { public static final int SHADOWAGE_summary = -103; - public AllocationSite(int allocationDepth, FlatNew flatNew) { + public AllocationSite(int allocationDepth, FlatNew flatNew, boolean forceAnalyze) { assert allocationDepth >= 1; this.allocationDepth = allocationDepth; this.flatNew = flatNew; + this.forceAnalyze = forceAnalyze; ithOldest = new Vector(allocationDepth); id = generateUniqueAllocationSiteID(); @@ -56,6 +58,11 @@ public class AllocationSite { } + public boolean doForceAnalyze() { + return forceAnalyze; + } + + public int getAllocationDepth() { return allocationDepth; } diff --git a/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java b/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java index 68ec11d1..a3b2c3be 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java +++ b/Robust/src/Analysis/OwnershipAnalysis/OwnershipAnalysis.java @@ -280,15 +280,39 @@ public class OwnershipAnalysis { mapMethodContextToNumUpdates = new Hashtable(); } - // initialize methods to visit as the set of all tasks in the - // program and then any method that could be called starting - // from those tasks - Iterator taskItr = state.getTaskSymbolTable().getDescriptorsIterator(); - while( taskItr.hasNext() ) { - Descriptor d = (Descriptor) taskItr.next(); - scheduleAllCallees(d); + + if( state.TASK ) { + // initialize methods to visit as the set of all tasks in the + // program and then any method that could be called starting + // from those tasks + Iterator taskItr = state.getTaskSymbolTable().getDescriptorsIterator(); + while( taskItr.hasNext() ) { + Descriptor d = (Descriptor) taskItr.next(); + scheduleAllCallees(d); + } + + } else { + // we are not in task mode, just normal Java, so start with + // the main method + + // get all classes, get all methods, look for static main, then stop? + + // YOU CAN DEFINE MORE THAN ONE MAIN!!!! + + Iterator classItr = state.getClassSymbolTable().getDescriptorsIterator(); + while( classItr.hasNext() ) { + ClassDescriptor cd = (ClassDescriptor) classItr.next(); + + Iterator methItr = cd.getMethods(); + while( methItr.hasNext() ) { + Descriptor d = (Descriptor) methItr.next(); + scheduleAllCallees(d); + } + } + } + // before beginning analysis, initialize every scheduled method // with an ownership graph that has populated parameter index tables // by analyzing the first node which is always a FlatMethod node @@ -796,7 +820,7 @@ public class OwnershipAnalysis { private AllocationSite getAllocationSiteFromFlatNewPRIVATE(FlatNew fn) { if( !mapFlatNewToAllocationSite.containsKey(fn) ) { - AllocationSite as = new AllocationSite(allocationDepth, fn); + AllocationSite as = new AllocationSite(allocationDepth, fn, fn.isDisjoint()); // the newest nodes are single objects for( int i = 0; i < allocationDepth; ++i ) { diff --git a/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java b/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java index 851b3e70..be552918 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java +++ b/Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java @@ -85,7 +85,7 @@ public class OwnershipGraph { } if( alpha == null ) { - if( isFlagged || isParameter ) { + if( isFlagged || isParameter || allocSite.doForceAnalyze() ) { alpha = new ReachabilitySet( new TokenTuple(id, !isSingleObject, diff --git a/Robust/src/IR/Flat/BuildFlat.java b/Robust/src/IR/Flat/BuildFlat.java index 9ed529d8..7b4edf85 100644 --- a/Robust/src/IR/Flat/BuildFlat.java +++ b/Robust/src/IR/Flat/BuildFlat.java @@ -212,7 +212,7 @@ public class BuildFlat { private NodePair flattenCreateObjectNode(CreateObjectNode con,TempDescriptor out_temp) { TypeDescriptor td=con.getType(); if (!td.isArray()) { - FlatNew fn=new FlatNew(td, out_temp, con.isGlobal()); + FlatNew fn=new FlatNew(td, out_temp, con.isGlobal(), con.isDisjoint()); TempDescriptor[] temps=new TempDescriptor[con.numArgs()]; FlatNode last=fn; // Build arguments @@ -271,7 +271,7 @@ public class BuildFlat { out_temp : TempDescriptor.tempFactory("arg",en.getType()); } - FlatNew fn=new FlatNew(td, out_temp, temps[0], con.isGlobal()); + FlatNew fn=new FlatNew(td, out_temp, temps[0], con.isGlobal(), con.isDisjoint()); last.addNext(fn); if (temps.length>1) { NodePair np=generateNewArrayLoop(temps, td.dereference(), out_temp, 0, con.isGlobal()); diff --git a/Robust/src/IR/Flat/FlatNew.java b/Robust/src/IR/Flat/FlatNew.java index eec4beb4..03f2892d 100644 --- a/Robust/src/IR/Flat/FlatNew.java +++ b/Robust/src/IR/Flat/FlatNew.java @@ -6,12 +6,22 @@ public class FlatNew extends FlatNode { TypeDescriptor type; TempDescriptor size; boolean isglobal; + boolean isdisjoint; public FlatNew(TypeDescriptor type, TempDescriptor dst, boolean isglobal) { this.type=type; this.dst=dst; this.size=null; this.isglobal=isglobal; + this.isdisjoint=false; + } + + public FlatNew(TypeDescriptor type, TempDescriptor dst, boolean isglobal, boolean isdisjoint) { + this.type=type; + this.dst=dst; + this.size=null; + this.isglobal=isglobal; + this.isdisjoint=isdisjoint; } public FlatNew(TypeDescriptor type, TempDescriptor dst, TempDescriptor size, boolean isglobal) { @@ -19,12 +29,25 @@ public class FlatNew extends FlatNode { this.dst=dst; this.size=size; this.isglobal=isglobal; + this.isdisjoint=false; + } + + public FlatNew(TypeDescriptor type, TempDescriptor dst, TempDescriptor size, boolean isglobal, boolean isdisjoint) { + this.type=type; + this.dst=dst; + this.size=size; + this.isglobal=isglobal; + this.isdisjoint=isdisjoint; } public boolean isGlobal() { return isglobal; } + public boolean isDisjoint() { + return isdisjoint; + } + public String toString() { String str = "FlatNew_"+dst.toString()+"= NEW "+type.toString(); if (size!=null) diff --git a/Robust/src/IR/Tree/BuildIR.java b/Robust/src/IR/Tree/BuildIR.java index d577cbb1..342fd897 100644 --- a/Robust/src/IR/Tree/BuildIR.java +++ b/Robust/src/IR/Tree/BuildIR.java @@ -398,7 +398,8 @@ public class BuildIR { TypeDescriptor td=parseTypeDescriptor(pn); Vector args=parseArgumentList(pn); boolean isglobal=pn.getChild("global")!=null; - CreateObjectNode con=new CreateObjectNode(td, isglobal); + boolean isdisjoint=pn.getChild("disjoint")!=null; + CreateObjectNode con=new CreateObjectNode(td, isglobal, isdisjoint); for(int i=0; i