From: jjenista Date: Tue, 9 Mar 2010 01:05:31 +0000 (+0000) Subject: callee elements brought into caller get predicates from caller element that satisfied... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=cc80c71130e4c0c0d82acbad0928ca2b295657ce;p=IRC.git callee elements brought into caller get predicates from caller element that satisfied them, properly, also bug fix for edges from nodes that aren't satisifed from throwing a null pointer exception --- diff --git a/Robust/src/Analysis/Disjoint/ExistPred.java b/Robust/src/Analysis/Disjoint/ExistPred.java index bc7988fb..b9952a7a 100644 --- a/Robust/src/Analysis/Disjoint/ExistPred.java +++ b/Robust/src/Analysis/Disjoint/ExistPred.java @@ -156,36 +156,42 @@ public class ExistPred extends Canonical { // only consider the subest of the caller elements that - // are reachable by callee when testing predicates - public boolean isSatisfiedBy( ReachGraph rg, - Set calleeReachableNodes, - Set calleeReachableEdges - ) { + // are reachable by callee when testing predicates--if THIS + // predicate is satisfied, return the predicate set of the + // element that satisfied it, or null for false + public ExistPredSet isSatisfiedBy( ReachGraph rg, + Set calleeReachableNodes, + Set calleeReachableEdges + ) { if( predType == TYPE_TRUE ) { - return true; + return ExistPredSet.factory( ExistPred.factory() ); } if( predType == TYPE_NODE ) { // first find node HeapRegionNode hrn = rg.id2hrn.get( n_hrnID ); if( hrn == null ) { - return false; + return null; } if( !calleeReachableNodes.contains( hrn ) ) { - return false; + return null; } // when the state is null it is not part of the // predicate, so we've already satisfied if( ne_state == null ) { - return true; + return hrn.getPreds(); } // otherwise look for state too // TODO: contains OR containsSuperSet OR containsWithZeroes?? - return hrn.getAlpha().contains( ne_state ); + if( hrn.getAlpha().contains( ne_state ) ) { + return hrn.getPreds(); + } + + return null; } if( predType == TYPE_EDGE ) { @@ -203,7 +209,7 @@ public class ExistPred extends Canonical { // the source is not present in graph if( vnSrc == null && hrnSrc == null ) { - return false; + return null; } RefSrcNode rsn; @@ -211,7 +217,7 @@ public class ExistPred extends Canonical { rsn = vnSrc; } else { if( !calleeReachableNodes.contains( hrnSrc ) ) { - return false; + return null; } rsn = hrnSrc; } @@ -219,11 +225,11 @@ public class ExistPred extends Canonical { // is the destination present? HeapRegionNode hrnDst = rg.id2hrn.get( e_hrnDstID ); if( hrnDst == null ) { - return false; + return null; } if( !calleeReachableNodes.contains( hrnDst ) ) { - return false; + return null; } // is there an edge between them with the given @@ -233,22 +239,26 @@ public class ExistPred extends Canonical { e_type, e_field ); if( edge == null ) { - return false; + return null; } if( !calleeReachableEdges.contains( edge ) ) { - return false; + return null; } // when state is null it is not part of the predicate // so we've satisfied the edge existence if( ne_state == null ) { - return true; + return edge.getPreds(); } // otherwise look for state too // TODO: contains OR containsSuperSet OR containsWithZeroes?? - return hrnDst.getAlpha().contains( ne_state ); + if( hrnDst.getAlpha().contains( ne_state ) ) { + return edge.getPreds(); + } + + return null; } throw new Error( "Unknown predicate type" ); diff --git a/Robust/src/Analysis/Disjoint/ExistPredSet.java b/Robust/src/Analysis/Disjoint/ExistPredSet.java index 4268c1a2..968e6388 100644 --- a/Robust/src/Analysis/Disjoint/ExistPredSet.java +++ b/Robust/src/Analysis/Disjoint/ExistPredSet.java @@ -52,20 +52,30 @@ public class ExistPredSet extends Canonical { // only consider the subest of the caller elements that // are reachable by callee when testing predicates - public boolean isSatisfiedBy( ReachGraph rg, - Set calleeReachableNodes, - Set calleeReachableEdges - ) { + public ExistPredSet isSatisfiedBy( ReachGraph rg, + Set calleeReachableNodes, + Set calleeReachableEdges + ) { + ExistPredSet predsOut = null; + Iterator predItr = preds.iterator(); while( predItr.hasNext() ) { - if( predItr.next().isSatisfiedBy( rg, - calleeReachableNodes, - calleeReachableEdges ) - ) { - return true; + ExistPredSet predsFromSatisfier = + predItr.next().isSatisfiedBy( rg, + calleeReachableNodes, + calleeReachableEdges ); + + if( predsFromSatisfier != null ) { + if( predsOut == null ) { + predsOut = predsFromSatisfier; + } else { + predsOut = Canonical.join( predsOut, + predsFromSatisfier ); + } } } - return false; + + return predsOut; } diff --git a/Robust/src/Analysis/Disjoint/ReachGraph.java b/Robust/src/Analysis/Disjoint/ReachGraph.java index a2a3fdcf..26484096 100644 --- a/Robust/src/Analysis/Disjoint/ReachGraph.java +++ b/Robust/src/Analysis/Disjoint/ReachGraph.java @@ -375,7 +375,7 @@ public class ReachGraph { TypeDescriptor tdNewEdge = mostSpecificType( edgeHrn.getType(), hrnHrn.getType() - ); + ); RefEdge edgeNew = new RefEdge( lnX, hrnHrn, @@ -385,7 +385,7 @@ public class ReachGraph { predsTrue ); - addRefEdge( lnX, hrnHrn, edgeNew ); + addRefEdge( lnX, hrnHrn, edgeNew ); } } @@ -1405,6 +1405,8 @@ public class ReachGraph { return rg; } + + public void resolveMethodCall( FlatCall fc, FlatMethod fm, @@ -1437,11 +1439,11 @@ public class ReachGraph { // 1. mark what callee elements have satisfied predicates - Set calleeNodesSatisfied = - new HashSet(); + Hashtable calleeNodesSatisfied = + new Hashtable(); - Set calleeEdgesSatisfied = - new HashSet(); + Hashtable calleeEdgesSatisfied = + new Hashtable(); Iterator meItr = rgCallee.id2hrn.entrySet().iterator(); while( meItr.hasNext() ) { @@ -1449,24 +1451,38 @@ public class ReachGraph { Integer id = (Integer) me.getKey(); HeapRegionNode hrnCallee = (HeapRegionNode) me.getValue(); - if( hrnCallee.getPreds().isSatisfiedBy( this, - callerNodesCopiedToCallee, - callerEdgesCopiedToCallee - ) - ) { - calleeNodesSatisfied.add( hrnCallee ); + ExistPredSet predsIfSatis = + hrnCallee.getPreds().isSatisfiedBy( this, + callerNodesCopiedToCallee, + callerEdgesCopiedToCallee + ); + if( predsIfSatis != null ) { + calleeNodesSatisfied.put( hrnCallee, predsIfSatis ); + } else { + // otherwise don't bother looking at edges from this node + continue; } Iterator reItr = hrnCallee.iteratorToReferencees(); while( reItr.hasNext() ) { RefEdge reCallee = reItr.next(); + + ExistPredSet ifDst = + reCallee.getDst().getPreds().isSatisfiedBy( this, + callerNodesCopiedToCallee, + callerEdgesCopiedToCallee + ); + if( ifDst == null ) { + continue; + } - if( reCallee.getPreds().isSatisfiedBy( this, - callerNodesCopiedToCallee, - callerEdgesCopiedToCallee - ) - ) { - calleeEdgesSatisfied.add( reCallee ); + predsIfSatis = + reCallee.getPreds().isSatisfiedBy( this, + callerNodesCopiedToCallee, + callerEdgesCopiedToCallee + ); + if( predsIfSatis != null ) { + calleeEdgesSatisfied.put( reCallee, predsIfSatis ); } } } @@ -1481,13 +1497,23 @@ public class ReachGraph { Iterator reItr = vnCallee.iteratorToReferencees(); while( reItr.hasNext() ) { RefEdge reCallee = reItr.next(); - - if( reCallee.getPreds().isSatisfiedBy( this, - callerNodesCopiedToCallee, - callerEdgesCopiedToCallee - ) - ) { - calleeEdgesSatisfied.add( reCallee ); + + ExistPredSet ifDst = + reCallee.getDst().getPreds().isSatisfiedBy( this, + callerNodesCopiedToCallee, + callerEdgesCopiedToCallee + ); + if( ifDst == null ) { + continue; + } + + ExistPredSet predsIfSatis = + reCallee.getPreds().isSatisfiedBy( this, + callerNodesCopiedToCallee, + callerEdgesCopiedToCallee + ); + if( predsIfSatis != null ) { + calleeEdgesSatisfied.put( reCallee, predsIfSatis ); } } } @@ -1503,12 +1529,19 @@ public class ReachGraph { - // 3. callee elements with satisfied preds come in + // 3. callee elements with satisfied preds come in, note that + // the mapping of elements satisfied to preds is like this: + // A callee element EE has preds EEp that are satisfied by + // some caller element ER. We bring EE into the caller + // context as ERee with the preds of ER, namely ERp, which + // in the following algorithm is the value in the mapping // 3.a) nodes - hrnItr = calleeNodesSatisfied.iterator(); - while( hrnItr.hasNext() ) { - HeapRegionNode hrnCallee = hrnItr.next(); + Iterator satisItr = calleeNodesSatisfied.entrySet().iterator(); + while( satisItr.hasNext() ) { + Map.Entry me = (Map.Entry) satisItr.next(); + HeapRegionNode hrnCallee = (HeapRegionNode) me.getKey(); + ExistPredSet preds = (ExistPredSet) me.getValue(); if( hrnCallee.isOutOfContext() ) { continue; @@ -1526,23 +1559,22 @@ public class ReachGraph { hrnCallee.getAllocSite(), // allocation site hrnCallee.getInherent(), // inherent reach null, // current reach - predsEmpty, // predicates + preds, // predicates hrnCallee.getDescription() // description ); } // TODO: alpha should be some rewritten version of callee in caller context hrnCaller.setAlpha( rsetEmpty ); - - // TODO: predicates should be exact same from caller version that satisfied - hrnCaller.setPreds( predsTrue ); } // 3.b) callee -> callee edges - Iterator reItr = calleeEdgesSatisfied.iterator(); - while( reItr.hasNext() ) { - RefEdge reCallee = reItr.next(); + satisItr = calleeEdgesSatisfied.entrySet().iterator(); + while( satisItr.hasNext() ) { + Map.Entry me = (Map.Entry) satisItr.next(); + RefEdge reCallee = (RefEdge) me.getKey(); + ExistPredSet preds = (ExistPredSet) me.getValue(); RefSrcNode rsnCallee = reCallee.getSrc(); RefSrcNode rsnCaller; @@ -1564,20 +1596,20 @@ public class ReachGraph { HeapRegionNode hrnSrcCallee = (HeapRegionNode) reCallee.getSrc(); rsnCaller = id2hrn.get( hrnSrcCallee.getID() ); } - + assert rsnCaller != null; HeapRegionNode hrnDstCallee = reCallee.getDst(); HeapRegionNode hrnDstCaller = id2hrn.get( hrnDstCallee.getID() ); assert hrnDstCaller != null; - // TODO: beta rewrites, preds from satisfier in caller + // TODO: beta rewrites RefEdge reCaller = new RefEdge( rsnCaller, hrnDstCaller, reCallee.getType(), reCallee.getField(), rsetEmpty, - predsTrue + preds ); diff --git a/Robust/src/Tests/disjoint/predicateTest2/makefile b/Robust/src/Tests/disjoint/predicateTest2/makefile index 0f5ef262..1c4574a3 100644 --- a/Robust/src/Tests/disjoint/predicateTest2/makefile +++ b/Robust/src/Tests/disjoint/predicateTest2/makefile @@ -3,9 +3,10 @@ PROGRAM=test SOURCE_FILES=$(PROGRAM).java BUILDSCRIPT=~/research/Robust/src/buildscript +DEBUGFLAGS= -disjoint-debug-callsite addSomething main 1 #DEBUGFLAGS= -disjoint-debug-callsite addBar addSomething 1 -#DEBUGFLAGS= -disjoint-debug-callsite Bar addBar 1 -DEBUGFLAGS= +#DEBUGFLAGS= -disjoint-debug-callsite Bar addBar 1 +#DEBUGFLAGS= BSFLAGS= -mainclass Test -justanalyze -disjoint -disjoint-k 2 -disjoint-write-dots final -disjoint-write-ihms -disjoint-alias-file aliases.txt normal -enable-assertions all: $(PROGRAM).bin diff --git a/Robust/src/Tests/disjoint/predicateTest2/test.java b/Robust/src/Tests/disjoint/predicateTest2/test.java index deec6759..1e2aa7ad 100644 --- a/Robust/src/Tests/disjoint/predicateTest2/test.java +++ b/Robust/src/Tests/disjoint/predicateTest2/test.java @@ -19,14 +19,15 @@ public class Test { } public static void addSomething( Foo f ) { - addBar( f ); + f.b = new Bar(); + //addBar( f ); } public static void addBar( Foo g ) { - if( true ) { - g.b = new Bar(); - } else { - g.b = new Bar(); - } + //if( true ) { + //g.b = new Bar(); + //} else { + //g.b = new Bar(); + //} } }