Prune edges by field name and type when mapping from callee to caller
authorjjenista <jjenista>
Fri, 29 Aug 2008 23:24:00 +0000 (23:24 +0000)
committerjjenista <jjenista>
Fri, 29 Aug 2008 23:24:00 +0000 (23:24 +0000)
Robust/src/Analysis/OwnershipAnalysis/OwnershipGraph.java
Robust/src/Tests/OwnershipAnalysisTest/test01/test01.java

index ff8e20c92131ad9faa75be2df9493016d8682e46..72cc326ba8762194b302bc316e82735310e15602 100644 (file)
@@ -1280,31 +1280,60 @@ public class OwnershipGraph {
          edgeNewInCallerTemplate.applyBetaNew();
 
 
-
          // So now make a set of possible source heaps in the caller graph
          // and a set of destination heaps in the caller graph, and make
          // a reference edge in the caller for every possible (src,dst) pair
          HashSet<HeapRegionNode> possibleCallerSrcs =
            getHRNSetThatPossiblyMapToCalleeHRN(ogCallee,
                                                (HeapRegionNode) edgeCallee.getSrc(),
-                                               true,
                                                paramIndex2reachableCallerNodes);
 
          HashSet<HeapRegionNode> possibleCallerDsts =
            getHRNSetThatPossiblyMapToCalleeHRN(ogCallee,
                                                edgeCallee.getDst(),
-                                               false,
                                                paramIndex2reachableCallerNodes);
+         
 
          // make every possible pair of {srcSet} -> {dstSet} edges in the caller
          Iterator srcItr = possibleCallerSrcs.iterator();
          while( srcItr.hasNext() ) {
            HeapRegionNode src = (HeapRegionNode) srcItr.next();
 
+           // check that if this source node has a definite type that
+           // it also has the appropriate field, otherwise prune this
+           AllocationSite asSrc = src.getAllocationSite();
+           if( asSrc != null ) {
+             boolean foundField = false;             
+             Iterator fieldsSrcItr = asSrc.getType().getClassDesc().getFields();
+             while( fieldsSrcItr.hasNext() ) {
+               FieldDescriptor fd = (FieldDescriptor) fieldsSrcItr.next();
+               if( fd == edgeCallee.getFieldDesc() ) {
+                 foundField = true;
+                 break;
+               }
+             }
+             if( !foundField ) {
+               // prune this source node possibility
+               continue;
+             }
+           }
+
            Iterator dstItr = possibleCallerDsts.iterator();
            while( dstItr.hasNext() ) {
              HeapRegionNode dst = (HeapRegionNode) dstItr.next();
 
+             // check if this dst node has a definite type and
+             // if it matches the callee edge
+             AllocationSite asDst = dst.getAllocationSite();
+             if( asDst != null && edgeCallee.getFieldDesc() != null ) {
+               if( asDst.getType() == null && edgeCallee.getFieldDesc().getType() != null ) { continue; }
+               if( asDst.getType() != null && edgeCallee.getFieldDesc().getType() == null ) { continue; }
+               if( asDst.getType() != null && edgeCallee.getFieldDesc().getType() != null ) {
+                 if( !asDst.getType().equals( edgeCallee.getFieldDesc().getType() ) ) { continue; }
+               }
+             }       
+
+             // otherwise the caller src and dst pair can match the edge, so make it
              ReferenceEdge edgeNewInCaller = edgeNewInCallerTemplate.copy();
              edgeNewInCaller.setSrc(src);
              edgeNewInCaller.setDst(dst);
@@ -1358,13 +1387,26 @@ public class OwnershipGraph {
        HashSet<HeapRegionNode> assignCallerRhs =
          getHRNSetThatPossiblyMapToCalleeHRN(ogCallee,
                                              edgeCallee.getDst(),
-                                             false,
                                              paramIndex2reachableCallerNodes);
 
        Iterator<HeapRegionNode> itrHrn = assignCallerRhs.iterator();
        while( itrHrn.hasNext() ) {
          HeapRegionNode hrnCaller = itrHrn.next();
         
+         // check if this dst node has a definite type and
+         // if it matches the callee edge
+         // check if this dst node has a definite type and
+         // if it matches the callee edge
+         AllocationSite asDst = hrnCaller.getAllocationSite();
+         if( asDst != null && edgeCallee.getFieldDesc() != null ) {
+           if( asDst.getType() == null && edgeCallee.getFieldDesc().getType() != null ) { continue; }
+           if( asDst.getType() != null && edgeCallee.getFieldDesc().getType() == null ) { continue; }
+           if( asDst.getType() != null && edgeCallee.getFieldDesc().getType() != null ) {
+             if( !asDst.getType().equals( edgeCallee.getFieldDesc().getType() ) ) { continue; }
+           }
+         }           
+
+         // otherwise caller node can match callee edge, so make it
          ReferenceEdge edgeNewInCaller = edgeNewInCallerTemplate.copy();
          edgeNewInCaller.setSrc(lnLhsCaller);
          edgeNewInCaller.setDst(hrnCaller);
@@ -1672,7 +1714,6 @@ public class OwnershipGraph {
   private HashSet<HeapRegionNode>
   getHRNSetThatPossiblyMapToCalleeHRN(OwnershipGraph ogCallee,
                                       HeapRegionNode hrnCallee,
-                                      boolean mapFromSrc,
                                       Hashtable<Integer, HashSet<HeapRegionNode> > paramIndex2reachableCallerNodes
                                       ) {
 
@@ -1712,8 +1753,6 @@ public class OwnershipGraph {
       // so it maps to a whole mess of heap regions
       assert paramIndex2reachableCallerNodes.containsKey(paramIndexCallee);
       possibleCallerHRNs = paramIndex2reachableCallerNodes.get(paramIndexCallee);
-
-      // TODO PRUNE BY TYPE/FIELD NAME!!
     }
 
     return possibleCallerHRNs;
index a432b9147bcb363e5a22b87a60759614ecab3d8c..3a5396b8d73b70bdd95dddf83b54f86ee441e9d8 100644 (file)
@@ -1,8 +1,10 @@
-/*
+
 public class Parameter {
   flag w;
-  int a, b;
-  Parameter f, g;
+  int a;
+  int b;
+  Parameter f;
+  Parameter g;
   Penguin p;
   Foo h;
   
@@ -13,7 +15,8 @@ public class Parameter {
 }
 
 public class Penguin {
-  int x, y;
+  int x;
+  int y;
   Foo h;    
   
   public Penguin() { x = 0; y = 0; }
@@ -46,17 +49,6 @@ public class Baw {
   
   public void doTheBaw( Voo v ) { v = new Voo(); }
 }
-*/
-
-
-task ObjectChainByMethodCalls( Foo a{ f } ) {
-
-  Foo f = a.getAFoo();
-  Foo g = a.newFooChain( f );
-  // g -> f
-
-  taskexit( a{ !f } );
-}
 
 
 public class Foo {
@@ -67,7 +59,7 @@ public class Foo {
   public Foo x;
   public Foo y;
   public Foo z;
-
+  public Baw b;
 
   public Foo getAFoo() {
     return new Foo();
@@ -339,8 +331,19 @@ task strongUpdates( Foo p0{ f } ) {
     
     taskexit( p0{ !f } );
 }
+
+
+task ObjectChainByMethodCalls( Foo a{ f } ) {
+
+  Foo f = a.getAFoo();
+  Foo g = a.newFooChain( f );
+  // g -> f
+
+  taskexit( a{ !f } );
+}
 */
 
+/*
 task arrayAssignments( Foo a{ f } ) {
 
   Foo f[] = new Foo[3];
@@ -355,6 +358,31 @@ task arrayAssignments( Foo a{ f } ) {
 
   taskexit( a{ !f } );
 }
+*/
+
+public class Zool {
+  public Zool() {}
+
+  public static void FooToBaw( Baw x, Foo y ) {
+    x.f.b = y.b;
+  }
+}
+
+task showPrunedEdgesInMethodCall( Foo a{ f } ) {
+
+  Foo b = new Foo();
+  b.x   = a;
+  b.y   = new Foo();
+  b.b   = new Baw();
+
+  Baw c = new Baw();
+  c.f   = new Foo();
+  c.f.b = new Baw();
+  
+  Zool.FooToBaw( c, b );
+
+  taskexit( a{ !f } );
+}
 
 /*
 task methodTest( Foo p0{ f } ) {