From d266a573b3fb272201027262eeb75ad40b4ea647 Mon Sep 17 00:00:00 2001 From: jjenista Date: Wed, 11 May 2011 21:29:50 +0000 Subject: [PATCH] differentiate between analysis says something points-to nothing verus analysis doesn't care what something points-to --- .../Analysis/Disjoint/DisjointAnalysis.java | 50 ++++++++++++++++--- .../src/Analysis/Disjoint/HeapAnalysis.java | 9 ++++ Robust/src/Analysis/Disjoint/ReachGraph.java | 38 +++++++++++--- .../src/IR/Flat/BCXPointsToCheckVRuntime.java | 40 +++++++++++---- 4 files changed, 113 insertions(+), 24 deletions(-) diff --git a/Robust/src/Analysis/Disjoint/DisjointAnalysis.java b/Robust/src/Analysis/Disjoint/DisjointAnalysis.java index 6f706d11..a2bf09fc 100644 --- a/Robust/src/Analysis/Disjoint/DisjointAnalysis.java +++ b/Robust/src/Analysis/Disjoint/DisjointAnalysis.java @@ -5,6 +5,7 @@ import Analysis.Liveness; import Analysis.ArrayReferencees; import Analysis.OoOJava.Accessible; import Analysis.OoOJava.RBlockRelationAnalysis; +import Analysis.FlatIRGraph.*; import IR.*; import IR.Flat.*; import IR.Tree.Modifiers; @@ -1994,16 +1995,51 @@ public class DisjointAnalysis implements HeapAnalysis { ); TempDescriptor cmdLineArgs = - new TempDescriptor("args", + new TempDescriptor("analysisEntryTemp_args", mdSourceEntry.getParamType(0) ); - FlatNew fn = + FlatNew fnArgs = new FlatNew(mdSourceEntry.getParamType(0), cmdLineArgs, false // is global ); - this.constructedCmdLineArgsNew = fn; + this.constructedCmdLineArgsNew = fnArgs; + + + // jjenista - we might want to model more of the initial context + // someday, so keep this trickery in that case. For now, this analysis + // ignores immutable types which includes String, so the following flat + // nodes will not add anything to the reach graph. + // + //TempDescriptor anArg = + // new TempDescriptor("analysisEntryTemp_arg", + // mdSourceEntry.getParamType(0).dereference() + // ); + // + //FlatNew fnArg = + // new FlatNew(mdSourceEntry.getParamType(0).dereference(), + // anArg, + // false // is global + // ); + // + //TempDescriptor index = + // new TempDescriptor("analysisEntryTemp_index", + // new TypeDescriptor(TypeDescriptor.INT) + // ); + // + //FlatLiteralNode fl = + // new FlatLiteralNode(new TypeDescriptor(TypeDescriptor.INT), + // new Integer( 0 ), + // index + // ); + // + //FlatSetElementNode fse = + // new FlatSetElementNode(cmdLineArgs, + // index, + // anArg + // ); + TempDescriptor[] sourceEntryArgs = new TempDescriptor[1]; sourceEntryArgs[0] = cmdLineArgs; @@ -2024,8 +2060,8 @@ public class DisjointAnalysis implements HeapAnalysis { fe ); - this.fmAnalysisEntry.addNext(fn); - fn.addNext(fc); + this.fmAnalysisEntry.addNext(fnArgs); + fnArgs.addNext(fc); fc.addNext(frn); frn.addNext(fe); } @@ -2765,7 +2801,7 @@ public class DisjointAnalysis implements HeapAnalysis { return null; } - return rgAtEnter.canPointTo( x, f.getSymbol() ); + return rgAtEnter.canPointTo( x, f.getSymbol(), f.getType() ); } @@ -2780,6 +2816,6 @@ public class DisjointAnalysis implements HeapAnalysis { assert x.getType() != null; assert x.getType().isArray(); - return rgAtEnter.canPointTo( x, arrayElementFieldName ); + return rgAtEnter.canPointTo( x, arrayElementFieldName, x.getType().dereference() ); } } diff --git a/Robust/src/Analysis/Disjoint/HeapAnalysis.java b/Robust/src/Analysis/Disjoint/HeapAnalysis.java index aaee0c3f..1228c9c6 100644 --- a/Robust/src/Analysis/Disjoint/HeapAnalysis.java +++ b/Robust/src/Analysis/Disjoint/HeapAnalysis.java @@ -19,6 +19,15 @@ public interface HeapAnalysis { // a field or element dereference you get a hashtable // where the keys are allocs for the variables and the // values are from following the second hop + // NOTE: if the set of Alloc's that something can point + // to is DONTCARE, this will mean "the analysis doesn't care + // what it points to" so the client shouldn't either, NOT + // interpreting it as "it can't point to anything." The + // meaning "it can't point to anything" will be represented + // by an empty set of Alloc. + static public final Set DONTCARE_PTR = new HashSet(); + static public final Hashtable< Alloc, Set > DONTCARE_DREF = new Hashtable< Alloc, Set >(); + public Set canPointToAt( TempDescriptor x, FlatNode programPoint ); diff --git a/Robust/src/Analysis/Disjoint/ReachGraph.java b/Robust/src/Analysis/Disjoint/ReachGraph.java index 6cd946f9..ca2616e0 100644 --- a/Robust/src/Analysis/Disjoint/ReachGraph.java +++ b/Robust/src/Analysis/Disjoint/ReachGraph.java @@ -5194,17 +5194,24 @@ public class ReachGraph { public Set canPointTo( TempDescriptor x ) { - VariableNode vn = getVariableNodeNoMutation( x ); - if( vn == null ) { - return null; + + if( !DisjointAnalysis.shouldAnalysisTrack( x.getType() ) ) { + // if we don't care to track it, return null which means + // "a client of this result shouldn't care either" + return HeapAnalysis.DONTCARE_PTR; } Set out = new HashSet(); + VariableNode vn = getVariableNodeNoMutation( x ); + if( vn == null ) { + // the empty set means "can't point to anything" + return out; + } + Iterator edgeItr = vn.iteratorToReferencees(); while( edgeItr.hasNext() ) { HeapRegionNode hrn = edgeItr.next().getDst(); - out.add( hrn.getAllocSite() ); } @@ -5214,20 +5221,35 @@ public class ReachGraph { public Hashtable< Alloc, Set > canPointTo( TempDescriptor x, - String field ) { + String field, + TypeDescriptor fieldType ) { + + if( !DisjointAnalysis.shouldAnalysisTrack( x.getType() ) ) { + // if we don't care to track it, return null which means + // "a client of this result shouldn't care either" + return HeapAnalysis.DONTCARE_DREF; + } + + Hashtable< Alloc, Set > out = new Hashtable< Alloc, Set >(); VariableNode vn = getVariableNodeNoMutation( x ); if( vn == null ) { - return null; + // the empty set means "can't point to anything" + return out; } - Hashtable< Alloc, Set > out = new Hashtable< Alloc, Set >(); Iterator edgeItr = vn.iteratorToReferencees(); while( edgeItr.hasNext() ) { HeapRegionNode hrn = edgeItr.next().getDst(); + Alloc key = hrn.getAllocSite(); - Alloc key = hrn.getAllocSite(); + if( !DisjointAnalysis.shouldAnalysisTrack( fieldType ) ) { + // if we don't care to track it, put no entry which means + // "a client of this result shouldn't care either" + out.put( key, HeapAnalysis.DONTCARE_PTR ); + continue; + } Set moreValues = new HashSet(); Iterator edgeItr2 = hrn.iteratorToReferencees(); diff --git a/Robust/src/IR/Flat/BCXPointsToCheckVRuntime.java b/Robust/src/IR/Flat/BCXPointsToCheckVRuntime.java index ce47b099..9cfca997 100644 --- a/Robust/src/IR/Flat/BCXPointsToCheckVRuntime.java +++ b/Robust/src/IR/Flat/BCXPointsToCheckVRuntime.java @@ -189,11 +189,20 @@ public class BCXPointsToCheckVRuntime implements BuildCodeExtension { TempDescriptor x, Set targetsByAnalysis ) { + assert targetsByAnalysis != null; + + output.println( "" ); output.println( "// asserts vs. heap results (DEBUG)" ); - if( targetsByAnalysis == null || - targetsByAnalysis.isEmpty() ) { + + if( targetsByAnalysis == HeapAnalysis.DONTCARE_PTR ) { + output.println( "// ANALYSIS DIDN'T CARE WHAT "+x+" POINTS-TO" ); + return; + } + + + if( targetsByAnalysis.isEmpty() ) { output.println( "assert( "+ buildCode.generateTemp( context, x )+ " == NULL );\n" ); @@ -228,13 +237,20 @@ public class BCXPointsToCheckVRuntime implements BuildCodeExtension { FieldDescriptor f, // this null OR TempDescriptor i, // this null Hashtable< Alloc, Set > targetsByAnalysis ) { - + assert targetsByAnalysis != null; + assert f == null || i == null; output.println( "// asserts vs. heap results (DEBUG)" ); + + + if( targetsByAnalysis == HeapAnalysis.DONTCARE_DREF ) { + output.println( "// ANALYSIS DIDN'T CARE WHAT "+x+" POINTS-TO" ); + return; + } + - if( targetsByAnalysis == null || - targetsByAnalysis.isEmpty() ) { + if( targetsByAnalysis.isEmpty() ) { output.println( "assert( "+ buildCode.generateTemp( context, x )+ " == NULL );\n" ); @@ -274,10 +290,14 @@ public class BCXPointsToCheckVRuntime implements BuildCodeExtension { output.print( "case "+ k.getUniqueAllocSiteID()+ - ": assert( allocsiteOneHop == -1" ); - + ":" ); + Set hopTargets = targetsByAnalysis.get( k ); - if( hopTargets != null ) { + if( hopTargets == HeapAnalysis.DONTCARE_PTR ) { + output.print( "/* ANALYSIS DOESN'T CARE */" ); + + } else { + output.print( "assert( allocsiteOneHop == -1" ); if( !hopTargets.isEmpty() ) { output.print( " || " ); @@ -294,9 +314,11 @@ public class BCXPointsToCheckVRuntime implements BuildCodeExtension { output.print( " || " ); } } + + output.print( " );" ); } - output.println( " ); break;" ); + output.println( " break;" ); } output.println( " default: assert( 0 ); break;" ); -- 2.34.1