changes.
authoryeom <yeom>
Sat, 27 Oct 2012 05:25:09 +0000 (05:25 +0000)
committeryeom <yeom>
Sat, 27 Oct 2012 05:25:09 +0000 (05:25 +0000)
Robust/src/Analysis/SSJava/BuildLattice.java
Robust/src/Analysis/SSJava/FlowDownCheck.java
Robust/src/Analysis/SSJava/LocationInference.java
Robust/src/Analysis/SSJava/LocationSummary.java

index 2df41320b448f7dae328ff70a693ff5fdc94a8ac..fdf3d89d05d4448227300979d38aaf4f405c225f 100644 (file)
@@ -13,9 +13,11 @@ import Util.Pair;
 public class BuildLattice {
 
   private LocationInference infer;
 public class BuildLattice {
 
   private LocationInference infer;
+  private Map<HNode, TripleItem> mapSharedNodeToTripleItem;
 
   public BuildLattice(LocationInference infer) {
     this.infer = infer;
 
   public BuildLattice(LocationInference infer) {
     this.infer = infer;
+    this.mapSharedNodeToTripleItem = new HashMap<HNode, TripleItem>();
   }
 
   public SSJavaLattice<String> buildLattice(Descriptor desc) {
   }
 
   public SSJavaLattice<String> buildLattice(Descriptor desc) {
@@ -144,6 +146,8 @@ public class BuildLattice {
     // perform DFS that starts from each skeleton/combination node and ends by another
     // skeleton/combination node
 
     // perform DFS that starts from each skeleton/combination node and ends by another
     // skeleton/combination node
 
+    mapSharedNodeToTripleItem.clear();
+
     HierarchyGraph simpleGraph = infer.getSimpleHierarchyGraph(desc);
     HierarchyGraph scGraph = infer.getSkeletonCombinationHierarchyGraph(desc);
     LocationSummary locSummary = infer.getLocationSummary(desc);
     HierarchyGraph simpleGraph = infer.getSimpleHierarchyGraph(desc);
     HierarchyGraph scGraph = infer.getSkeletonCombinationHierarchyGraph(desc);
     LocationSummary locSummary = infer.getLocationSummary(desc);
@@ -249,10 +253,64 @@ public class BuildLattice {
       }
     }
 
       }
     }
 
+    // add shared locations
+    Set<HNode> sharedNodeSet = mapSharedNodeToTripleItem.keySet();
+    for (Iterator iterator = sharedNodeSet.iterator(); iterator.hasNext();) {
+      HNode sharedNode = (HNode) iterator.next();
+      TripleItem item = mapSharedNodeToTripleItem.get(sharedNode);
+      String nonSharedLocName = mapIntermediateLoc.get(item);
+      System.out.println("sharedNode=" + sharedNode + "    locName=" + nonSharedLocName);
+
+      String newLocName;
+      if (locSummary.getHNodeNameSetByLatticeLoationName(nonSharedLocName) != null
+          && !lattice.isSharedLoc(nonSharedLocName)) {
+        // need to generate a new shared location in the lattice, which is one level lower than the
+        // 'locName' location
+        newLocName = "ILOC" + (LocationInference.locSeed++);
+
+        // Set<String> aboveElementSet = getAboveElementSet(lattice, locName);
+        Set<String> belowElementSet = new HashSet<String>();
+        belowElementSet.addAll(lattice.get(nonSharedLocName));
+
+        System.out.println("nonSharedLocName=" + nonSharedLocName + "   belowElementSet="
+            + belowElementSet + "  newLocName=" + newLocName);
+
+        lattice.insertNewLocationBetween(nonSharedLocName, belowElementSet, newLocName);
+      } else {
+        newLocName = nonSharedLocName;
+      }
+
+      lattice.addSharedLoc(newLocName);
+      HierarchyGraph graph = infer.getSimpleHierarchyGraph(desc);
+      Set<Descriptor> descSet = graph.getDescSetOfNode(sharedNode);
+      for (Iterator iterator2 = descSet.iterator(); iterator2.hasNext();) {
+        Descriptor d = (Descriptor) iterator2.next();
+        locSummary.addMapHNodeNameToLocationName(d.getSymbol(), newLocName);
+      }
+      locSummary.addMapHNodeNameToLocationName(sharedNode.getName(), newLocName);
+
+    }
+
     return lattice;
 
   }
 
     return lattice;
 
   }
 
+  private Set<String> getAboveElementSet(SSJavaLattice<String> lattice, String loc) {
+
+    Set<String> aboveSet = new HashSet<String>();
+
+    Map<String, Set<String>> latticeMap = lattice.getTable();
+    Set<String> keySet = latticeMap.keySet();
+    for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
+      String key = (String) iterator.next();
+      if (latticeMap.get(key).contains(loc)) {
+        aboveSet.add(key);
+      }
+    }
+
+    return aboveSet;
+  }
+
   private void expandCombinationNode(Descriptor desc, SSJavaLattice<String> lattice,
       Set<HNode> visited, Map<TripleItem, String> mapIntermediateLoc, LocationSummary locSummary,
       HNode cnode) {
   private void expandCombinationNode(Descriptor desc, SSJavaLattice<String> lattice,
       Set<HNode> visited, Map<TripleItem, String> mapIntermediateLoc, LocationSummary locSummary,
       HNode cnode) {
@@ -442,22 +500,23 @@ public class BuildLattice {
     }
 
     String locName = mapIntermediateLoc.get(item);
     }
 
     String locName = mapIntermediateLoc.get(item);
-
     HierarchyGraph graph = infer.getSimpleHierarchyGraph(desc);
 
     HierarchyGraph graph = infer.getSimpleHierarchyGraph(desc);
 
-    Set<Descriptor> descSet = graph.getDescSetOfNode(curNode);
-    for (Iterator iterator = descSet.iterator(); iterator.hasNext();) {
-      Descriptor d = (Descriptor) iterator.next();
-      locSummary.addMapHNodeNameToLocationName(d.getSymbol(), locName);
-    }
-    locSummary.addMapHNodeNameToLocationName(curNode.getName(), locName);
-
     if (curNode.isSharedNode()) {
     if (curNode.isSharedNode()) {
-      lattice.addSharedLoc(locName);
+      // if the current node is shared location, add a shared location to the lattice later
+      mapSharedNodeToTripleItem.put(curNode, item);
+    } else {
+      Set<Descriptor> descSet = graph.getDescSetOfNode(curNode);
+      for (Iterator iterator = descSet.iterator(); iterator.hasNext();) {
+        Descriptor d = (Descriptor) iterator.next();
+        locSummary.addMapHNodeNameToLocationName(d.getSymbol(), locName);
+      }
+      locSummary.addMapHNodeNameToLocationName(curNode.getName(), locName);
     }
 
     System.out.println("-TripleItem=" + item);
     }
 
     System.out.println("-TripleItem=" + item);
-    System.out.println("-curNode=" + curNode.getName() + " locName=" + locName);
+    System.out.println("-curNode=" + curNode.getName() + " S=" + curNode.isSharedNode()
+        + " locName=" + locName);
 
     Set<HNode> outSet = graph.getOutgoingNodeSet(curNode);
     for (Iterator iterator2 = outSet.iterator(); iterator2.hasNext();) {
 
     Set<HNode> outSet = graph.getOutgoingNodeSet(curNode);
     for (Iterator iterator2 = outSet.iterator(); iterator2.hasNext();) {
@@ -498,23 +557,33 @@ public class BuildLattice {
         }
         lattice.insertNewLocationBetween(above, belowSet, newLocName);
         mapIntermediateLoc.put(item, newLocName);
         }
         lattice.insertNewLocationBetween(above, belowSet, newLocName);
         mapIntermediateLoc.put(item, newLocName);
-
       }
 
     }
 
       }
 
     }
 
+    // TODO
+    // Do we need to skip the combination node and assign a shared location to the next node?
+    // if (idx == 1 && curNode.isSharedNode()) {
+    // System.out.println("THE FIRST COMBINATION NODE EXPANSION IS SHARED!");
+    // recurDFS(desc, lattice, combinationNodeInSCGraph, endNodeSet, visited, mapIntermediateLoc,
+    // idx + 1, locSummary, curNode);
+    // return;
+    // }
+
     HierarchyGraph graph = infer.getSimpleHierarchyGraph(desc);
     String locName = mapIntermediateLoc.get(item);
     HierarchyGraph graph = infer.getSimpleHierarchyGraph(desc);
     String locName = mapIntermediateLoc.get(item);
-    Set<Descriptor> descSet = graph.getDescSetOfNode(curNode);
-    for (Iterator iterator = descSet.iterator(); iterator.hasNext();) {
-      Descriptor d = (Descriptor) iterator.next();
-      locSummary.addMapHNodeNameToLocationName(d.getSymbol(), locName);
-    }
-    locSummary.addMapHNodeNameToLocationName(curNode.getName(), locName);
-
     if (curNode.isSharedNode()) {
     if (curNode.isSharedNode()) {
-      lattice.addSharedLoc(locName);
+      // if the current node is shared location, add a shared location to the lattice later
+      mapSharedNodeToTripleItem.put(curNode, item);
+    } else {
+      Set<Descriptor> descSet = graph.getDescSetOfNode(curNode);
+      for (Iterator iterator = descSet.iterator(); iterator.hasNext();) {
+        Descriptor d = (Descriptor) iterator.next();
+        locSummary.addMapHNodeNameToLocationName(d.getSymbol(), locName);
+      }
+      locSummary.addMapHNodeNameToLocationName(curNode.getName(), locName);
     }
     }
+
     System.out.println("-TripleItem=" + item);
     System.out.println("-curNode=" + curNode.getName() + " S=" + curNode.isSharedNode()
         + " locName=" + locName);
     System.out.println("-TripleItem=" + item);
     System.out.println("-curNode=" + curNode.getName() + " S=" + curNode.isSharedNode()
         + " locName=" + locName);
@@ -713,11 +782,21 @@ class TripleItem {
   public HNode higherNode;
   public Set<HNode> lowerNodeSet;
   public int idx;
   public HNode higherNode;
   public Set<HNode> lowerNodeSet;
   public int idx;
+  public boolean isShared;
 
   public TripleItem(HNode h, Set<HNode> l, int i) {
     higherNode = h;
     lowerNodeSet = l;
     idx = i;
 
   public TripleItem(HNode h, Set<HNode> l, int i) {
     higherNode = h;
     lowerNodeSet = l;
     idx = i;
+    isShared = false;
+  }
+
+  public void setShared(boolean in) {
+    this.isShared = in;
+  }
+
+  public boolean isShared() {
+    return isShared;
   }
 
   public int hashCode() {
   }
 
   public int hashCode() {
@@ -727,6 +806,10 @@ class TripleItem {
       h = higherNode.hashCode();
     }
 
       h = higherNode.hashCode();
     }
 
+    if (isShared) {
+      h++;
+    }
+
     return h + lowerNodeSet.hashCode() + idx;
   }
 
     return h + lowerNodeSet.hashCode() + idx;
   }
 
@@ -735,7 +818,7 @@ class TripleItem {
     if (obj instanceof TripleItem) {
       TripleItem in = (TripleItem) obj;
       if ((higherNode == null || (higherNode != null && higherNode.equals(in.higherNode)))
     if (obj instanceof TripleItem) {
       TripleItem in = (TripleItem) obj;
       if ((higherNode == null || (higherNode != null && higherNode.equals(in.higherNode)))
-          && lowerNodeSet.equals(in.lowerNodeSet) && idx == in.idx) {
+          && lowerNodeSet.equals(in.lowerNodeSet) && idx == in.idx && isShared == in.isShared()) {
         return true;
       }
     }
         return true;
       }
     }
@@ -744,6 +827,10 @@ class TripleItem {
   }
 
   public String toString() {
   }
 
   public String toString() {
-    return higherNode + "-" + idx + "->" + lowerNodeSet;
+    String rtr = higherNode + "-" + idx + "->" + lowerNodeSet;
+    if (isShared) {
+      rtr += " S";
+    }
+    return rtr;
   }
 }
   }
 }
index 8d699e9bcec421e2cf43ec3d537dcf39963f4c9b..eb7cf77b036c29395429d323076414e79e481b63 100644 (file)
@@ -707,7 +707,7 @@ public class FlowDownCheck {
   private CompositeLocation checkLocationFromIfStatementNode(MethodDescriptor md,
       SymbolTable nametable, IfStatementNode isn, CompositeLocation constraint) {
 
   private CompositeLocation checkLocationFromIfStatementNode(MethodDescriptor md,
       SymbolTable nametable, IfStatementNode isn, CompositeLocation constraint) {
 
-    System.out.println("checkLocationFromIfStatementNode=" + isn);
+    System.out.println("\n\ncheckLocationFromIfStatementNode=" + isn.printNode(0));
     CompositeLocation condLoc =
         checkLocationFromExpressionNode(md, nametable, isn.getCondition(), new CompositeLocation(),
             constraint, false);
     CompositeLocation condLoc =
         checkLocationFromExpressionNode(md, nametable, isn.getCondition(), new CompositeLocation(),
             constraint, false);
@@ -1367,16 +1367,17 @@ public class FlowDownCheck {
       SymbolTable nametable, ArrayAccessNode aan, CompositeLocation constraint, boolean isLHS) {
     System.out.println("aan=" + aan.printNode(0) + "  line#=" + aan.getNumLine());
     ClassDescriptor cd = md.getClassDesc();
       SymbolTable nametable, ArrayAccessNode aan, CompositeLocation constraint, boolean isLHS) {
     System.out.println("aan=" + aan.printNode(0) + "  line#=" + aan.getNumLine());
     ClassDescriptor cd = md.getClassDesc();
-
+    System.out.println("aan.getExpression()=" +aan.getExpression().getClass());
     CompositeLocation arrayLoc =
         checkLocationFromExpressionNode(md, nametable, aan.getExpression(),
             new CompositeLocation(), constraint, isLHS);
     CompositeLocation arrayLoc =
         checkLocationFromExpressionNode(md, nametable, aan.getExpression(),
             new CompositeLocation(), constraint, isLHS);
-
+System.out.println("HERE?");
     // addTypeLocation(aan.getExpression().getType(), arrayLoc);
     CompositeLocation indexLoc =
         checkLocationFromExpressionNode(md, nametable, aan.getIndex(), new CompositeLocation(),
             constraint, isLHS);
     // addTypeLocation(aan.getIndex().getType(), indexLoc);
     // addTypeLocation(aan.getExpression().getType(), arrayLoc);
     CompositeLocation indexLoc =
         checkLocationFromExpressionNode(md, nametable, aan.getIndex(), new CompositeLocation(),
             constraint, isLHS);
     // addTypeLocation(aan.getIndex().getType(), indexLoc);
+    System.out.println("HERE2?");
 
     if (isLHS) {
       if (!CompositeLattice.isGreaterThan(indexLoc, arrayLoc, generateErrorMessage(cd, aan))) {
 
     if (isLHS) {
       if (!CompositeLattice.isGreaterThan(indexLoc, arrayLoc, generateErrorMessage(cd, aan))) {
@@ -1388,7 +1389,11 @@ public class FlowDownCheck {
       Set<CompositeLocation> inputGLB = new HashSet<CompositeLocation>();
       inputGLB.add(arrayLoc);
       inputGLB.add(indexLoc);
       Set<CompositeLocation> inputGLB = new HashSet<CompositeLocation>();
       inputGLB.add(arrayLoc);
       inputGLB.add(indexLoc);
-      return CompositeLattice.calculateGLB(inputGLB, generateErrorMessage(cd, aan));
+      System.out.println("arrayLoc=" + arrayLoc + "   indexLoc=" + indexLoc);
+      CompositeLocation comp =
+          CompositeLattice.calculateGLB(inputGLB, generateErrorMessage(cd, aan));
+      System.out.println("---aan=" + aan.printNode(0) + "  compLoc=" + comp);
+      return comp;
     }
 
   }
     }
 
   }
@@ -1487,7 +1492,7 @@ public class FlowDownCheck {
   private CompositeLocation checkLocationFromNameNode(MethodDescriptor md, SymbolTable nametable,
       NameNode nn, CompositeLocation loc, CompositeLocation constraint) {
 
   private CompositeLocation checkLocationFromNameNode(MethodDescriptor md, SymbolTable nametable,
       NameNode nn, CompositeLocation loc, CompositeLocation constraint) {
 
-    System.out.println("checkLocationFromNameNode nn=" + nn.printNode(0));
+    // System.out.println("checkLocationFromNameNode nn=" + nn.printNode(0));
     NameDescriptor nd = nn.getName();
     if (nd.getBase() != null) {
       loc =
     NameDescriptor nd = nn.getName();
     if (nd.getBase() != null) {
       loc =
@@ -1519,7 +1524,7 @@ public class FlowDownCheck {
       } else if (d instanceof FieldDescriptor) {
         // the type of field descriptor has a location!
         FieldDescriptor fd = (FieldDescriptor) d;
       } else if (d instanceof FieldDescriptor) {
         // the type of field descriptor has a location!
         FieldDescriptor fd = (FieldDescriptor) d;
-        System.out.println("fd=" + fd);
+        // System.out.println("fd=" + fd);
         if (fd.isStatic()) {
           if (fd.isFinal()) {
             // if it is 'static final', the location has TOP since no one can
         if (fd.isStatic()) {
           if (fd.isFinal()) {
             // if it is 'static final', the location has TOP since no one can
@@ -1661,6 +1666,8 @@ public class FlowDownCheck {
   private CompositeLocation checkLocationFromAssignmentNode(MethodDescriptor md,
       SymbolTable nametable, AssignmentNode an, CompositeLocation loc, CompositeLocation constraint) {
 
   private CompositeLocation checkLocationFromAssignmentNode(MethodDescriptor md,
       SymbolTable nametable, AssignmentNode an, CompositeLocation loc, CompositeLocation constraint) {
 
+    System.out.println("\n\ncheckLocationFromAssignmentNode=" + an.printNode(0));
+
     ClassDescriptor cd = md.getClassDesc();
 
     Set<CompositeLocation> inputGLBSet = new HashSet<CompositeLocation>();
     ClassDescriptor cd = md.getClassDesc();
 
     Set<CompositeLocation> inputGLBSet = new HashSet<CompositeLocation>();
@@ -1712,8 +1719,7 @@ public class FlowDownCheck {
         // generateErrorMessage(cd, an));
       }
 
         // generateErrorMessage(cd, an));
       }
 
-      // System.out.println("src=" + srcLocation + "  dest=" + destLocation + "  const=" +
-      // constraint);
+      System.out.println("src=" + srcLocation + "  dest=" + destLocation + "  const=" + constraint);
 
       if (!CompositeLattice.isGreaterThan(srcLocation, destLocation, generateErrorMessage(cd, an))) {
 
 
       if (!CompositeLattice.isGreaterThan(srcLocation, destLocation, generateErrorMessage(cd, an))) {
 
@@ -2257,7 +2263,7 @@ public class FlowDownCheck {
           }
 
           if (innerGLBInput.size() > 0) {
           }
 
           if (innerGLBInput.size() > 0) {
-            System.out.println("######innerGLBInput=" + innerGLBInput);
+            // System.out.println("######innerGLBInput=" + innerGLBInput);
             CompositeLocation innerGLB = CompositeLattice.calculateGLB(innerGLBInput, errMsg);
             for (int idx = 0; idx < innerGLB.getSize(); idx++) {
               glbCompLoc.addLocation(innerGLB.get(idx));
             CompositeLocation innerGLB = CompositeLattice.calculateGLB(innerGLBInput, errMsg);
             for (int idx = 0; idx < innerGLB.getSize(); idx++) {
               glbCompLoc.addLocation(innerGLB.get(idx));
@@ -2280,7 +2286,7 @@ public class FlowDownCheck {
         }
       }
 
         }
       }
 
-      System.out.println("GLB=" + glbCompLoc + "\n");
+      System.out.println("GLB=" + glbCompLoc);
       return glbCompLoc;
 
     }
       return glbCompLoc;
 
     }
index 4f24373511871ac8c4af5369f3839d5a643321b0..a3bee185c15fa32857372218118ba970ab2740bc 100644 (file)
@@ -1357,11 +1357,11 @@ public class LocationInference {
 
     Set<GlobalFlowNode> incomingNodeSetPrefix =
         graph.getIncomingNodeSetByPrefix(node.getLocTuple().get(0));
 
     Set<GlobalFlowNode> incomingNodeSetPrefix =
         graph.getIncomingNodeSetByPrefix(node.getLocTuple().get(0));
-    // System.out.println("---incomingNodeSetPrefix=" + incomingNodeSetPrefix);
+    System.out.println("---incomingNodeSetPrefix=" + incomingNodeSetPrefix);
 
     Set<GlobalFlowNode> reachableNodeSetPrefix =
         graph.getReachableNodeSetByPrefix(node.getLocTuple().get(0));
 
     Set<GlobalFlowNode> reachableNodeSetPrefix =
         graph.getReachableNodeSetByPrefix(node.getLocTuple().get(0));
-    // System.out.println("---reachableNodeSetPrefix=" + reachableNodeSetPrefix);
+    System.out.println("---reachableNodeSetPrefix=" + reachableNodeSetPrefix);
 
     List<NTuple<Location>> prefixList = new ArrayList<NTuple<Location>>();
 
 
     List<NTuple<Location>> prefixList = new ArrayList<NTuple<Location>>();
 
@@ -1772,6 +1772,7 @@ public class LocationInference {
       // // the type of argument is primitive.
       // return nodeLocTuple.clone();
       // }
       // // the type of argument is primitive.
       // return nodeLocTuple.clone();
       // }
+      System.out.println("paramIdx=" + paramIdx + "  argDescTuple=" + argDescTuple);
       NTuple<Location> argLocTuple = translateToLocTuple(mdCaller, argDescTuple);
 
       NTuple<Location> callerLocTuple = new NTuple<Location>();
       NTuple<Location> argLocTuple = translateToLocTuple(mdCaller, argDescTuple);
 
       NTuple<Location> callerLocTuple = new NTuple<Location>();
@@ -2290,7 +2291,9 @@ public class LocationInference {
 
     // visit each node of method flow graph
     FlowGraph fg = getFlowGraph(md);
 
     // visit each node of method flow graph
     FlowGraph fg = getFlowGraph(md);
-    Set<FlowNode> nodeSet = fg.getNodeSet();
+    // Set<FlowNode> nodeSet = fg.getNodeSet();
+
+    Set<FlowEdge> edgeSet = fg.getEdgeSet();
 
     Set<Descriptor> paramDescSet = fg.getMapParamDescToIdx().keySet();
     for (Iterator iterator = paramDescSet.iterator(); iterator.hasNext();) {
 
     Set<Descriptor> paramDescSet = fg.getMapParamDescToIdx().keySet();
     for (Iterator iterator = paramDescSet.iterator(); iterator.hasNext();) {
@@ -2301,9 +2304,12 @@ public class LocationInference {
     // for the method lattice, we need to look at the first element of
     // NTuple<Descriptor>
     boolean hasGlobalAccess = false;
     // for the method lattice, we need to look at the first element of
     // NTuple<Descriptor>
     boolean hasGlobalAccess = false;
-    for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
-      FlowNode originalSrcNode = (FlowNode) iterator.next();
+    // for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
+    // FlowNode originalSrcNode = (FlowNode) iterator.next();
+    for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) {
+      FlowEdge edge = (FlowEdge) iterator.next();
 
 
+      FlowNode originalSrcNode = fg.getFlowNode(edge.getInitTuple());
       Set<FlowNode> sourceNodeSet = new HashSet<FlowNode>();
       if (originalSrcNode instanceof FlowReturnNode) {
         FlowReturnNode rnode = (FlowReturnNode) originalSrcNode;
       Set<FlowNode> sourceNodeSet = new HashSet<FlowNode>();
       if (originalSrcNode instanceof FlowReturnNode) {
         FlowReturnNode rnode = (FlowReturnNode) originalSrcNode;
@@ -2317,7 +2323,9 @@ public class LocationInference {
         sourceNodeSet.add(originalSrcNode);
       }
 
         sourceNodeSet.add(originalSrcNode);
       }
 
-      System.out.println("---sourceNodeSet=" + sourceNodeSet);
+      System.out.println("---sourceNodeSet=" + sourceNodeSet + "  from originalSrcNode="
+          + originalSrcNode);
+
       for (Iterator iterator3 = sourceNodeSet.iterator(); iterator3.hasNext();) {
         FlowNode srcNode = (FlowNode) iterator3.next();
 
       for (Iterator iterator3 = sourceNodeSet.iterator(); iterator3.hasNext();) {
         FlowNode srcNode = (FlowNode) iterator3.next();
 
@@ -2338,81 +2346,86 @@ public class LocationInference {
           hasGlobalAccess = true;
         }
 
           hasGlobalAccess = true;
         }
 
-        Set<FlowEdge> outEdgeSet = fg.getOutEdgeSet(originalSrcNode);
-        for (Iterator iterator2 = outEdgeSet.iterator(); iterator2.hasNext();) {
-          FlowEdge outEdge = (FlowEdge) iterator2.next();
-          FlowNode originalDstNode = outEdge.getDst();
-
-          Set<FlowNode> dstNodeSet = new HashSet<FlowNode>();
-          if (originalDstNode instanceof FlowReturnNode) {
-            FlowReturnNode rnode = (FlowReturnNode) originalDstNode;
-            System.out.println("\n-returnNode=" + rnode);
-            Set<NTuple<Descriptor>> tupleSet = rnode.getTupleSet();
-            for (Iterator iterator4 = tupleSet.iterator(); iterator4.hasNext();) {
-              NTuple<Descriptor> nTuple = (NTuple<Descriptor>) iterator4.next();
-              dstNodeSet.add(fg.getFlowNode(nTuple));
-            }
-          } else {
-            dstNodeSet.add(originalDstNode);
+        // Set<FlowEdge> outEdgeSet = fg.getOutEdgeSet(originalSrcNode);
+        // for (Iterator iterator2 = outEdgeSet.iterator(); iterator2.hasNext();) {
+        // FlowEdge outEdge = (FlowEdge) iterator2.next();
+        // FlowNode originalDstNode = outEdge.getDst();
+        FlowNode originalDstNode = fg.getFlowNode(edge.getEndTuple());
+
+        Set<FlowNode> dstNodeSet = new HashSet<FlowNode>();
+        if (originalDstNode instanceof FlowReturnNode) {
+          FlowReturnNode rnode = (FlowReturnNode) originalDstNode;
+          System.out.println("\n-returnNode=" + rnode);
+          Set<NTuple<Descriptor>> tupleSet = rnode.getTupleSet();
+          for (Iterator iterator4 = tupleSet.iterator(); iterator4.hasNext();) {
+            NTuple<Descriptor> nTuple = (NTuple<Descriptor>) iterator4.next();
+            dstNodeSet.add(fg.getFlowNode(nTuple));
           }
           }
-          System.out.println("---dstNodeSet=" + dstNodeSet);
-          for (Iterator iterator4 = dstNodeSet.iterator(); iterator4.hasNext();) {
-            FlowNode dstNode = (FlowNode) iterator4.next();
-
-            NTuple<Descriptor> dstNodeTuple = dstNode.getDescTuple();
-            Descriptor dstLocalDesc = dstNodeTuple.get(0);
-
-            if (dstLocalDesc instanceof InterDescriptor
-                && ((InterDescriptor) dstLocalDesc).getMethodArgIdxPair() != null) {
-              if (dstNode.getCompositeLocation() == null) {
-                System.out.println("%%%%%%%%%%%%%SKIP=" + dstNode);
-                continue;
-              }
+        } else {
+          dstNodeSet.add(originalDstNode);
+        }
+        System.out.println("---dstNodeSet=" + dstNodeSet);
+        for (Iterator iterator4 = dstNodeSet.iterator(); iterator4.hasNext();) {
+          FlowNode dstNode = (FlowNode) iterator4.next();
+
+          NTuple<Descriptor> dstNodeTuple = dstNode.getDescTuple();
+          Descriptor dstLocalDesc = dstNodeTuple.get(0);
+
+          if (dstLocalDesc instanceof InterDescriptor
+              && ((InterDescriptor) dstLocalDesc).getMethodArgIdxPair() != null) {
+            if (dstNode.getCompositeLocation() == null) {
+              System.out.println("%%%%%%%%%%%%%SKIP=" + dstNode);
+              continue;
             }
             }
+          }
 
 
-            // if (outEdge.getInitTuple().equals(srcNodeTuple)
-            // && outEdge.getEndTuple().equals(dstNodeTuple)) {
+          // if (outEdge.getInitTuple().equals(srcNodeTuple)
+          // && outEdge.getEndTuple().equals(dstNodeTuple)) {
 
 
-            NTuple<Descriptor> srcCurTuple = srcNode.getCurrentDescTuple();
-            NTuple<Descriptor> dstCurTuple = dstNode.getCurrentDescTuple();
+          NTuple<Descriptor> srcCurTuple = srcNode.getCurrentDescTuple();
+          NTuple<Descriptor> dstCurTuple = dstNode.getCurrentDescTuple();
 
 
-            System.out.println("-srcCurTuple=" + srcCurTuple + "  dstCurTuple=" + dstCurTuple);
+          System.out.println("-srcCurTuple=" + srcCurTuple + "  dstCurTuple=" + dstCurTuple);
 
 
-            if ((srcCurTuple.size() > 1 && dstCurTuple.size() > 1)
-                && srcCurTuple.get(0).equals(dstCurTuple.get(0))) {
+          if ((srcCurTuple.size() > 1 && dstCurTuple.size() > 1)
+              && srcCurTuple.get(0).equals(dstCurTuple.get(0))) {
 
 
-              // value flows between fields
-              Descriptor desc = srcCurTuple.get(0);
-              ClassDescriptor classDesc;
+            // value flows between fields
+            Descriptor desc = srcCurTuple.get(0);
+            ClassDescriptor classDesc;
 
 
-              if (desc.equals(GLOBALDESC)) {
-                classDesc = md.getClassDesc();
-              } else {
-                VarDescriptor varDesc = (VarDescriptor) srcCurTuple.get(0);
-                classDesc = varDesc.getType().getClassDesc();
-              }
-              extractFlowsBetweenFields(classDesc, srcNode, dstNode, 1);
+            if (desc.equals(GLOBALDESC)) {
+              classDesc = md.getClassDesc();
+            } else {
+              VarDescriptor varDesc = (VarDescriptor) srcCurTuple.get(0);
+              classDesc = varDesc.getType().getClassDesc();
+            }
+            extractFlowsBetweenFields(classDesc, srcNode, dstNode, 1);
 
 
-            } else if (!srcCurTuple.get(0).equals(dstCurTuple.get(0))) {
-              // value flow between local var - local var or local var - field
+          } else if ((srcCurTuple.size() == 1 && dstCurTuple.size() == 1)
+              || ((srcCurTuple.size() > 1 || dstCurTuple.size() > 1) && !srcCurTuple.get(0).equals(
+                  dstCurTuple.get(0)))) {
 
 
-              Descriptor srcDesc = srcCurTuple.get(0);
-              Descriptor dstDesc = dstCurTuple.get(0);
+            // value flow between a primitive local var - a primitive local var or local var -
+            // field
 
 
-              methodGraph.addEdge(srcDesc, dstDesc);
+            Descriptor srcDesc = srcCurTuple.get(0);
+            Descriptor dstDesc = dstCurTuple.get(0);
 
 
-              if (fg.isParamDesc(srcDesc)) {
-                methodGraph.setParamHNode(srcDesc);
-              }
-              if (fg.isParamDesc(dstDesc)) {
-                methodGraph.setParamHNode(dstDesc);
-              }
+            methodGraph.addEdge(srcDesc, dstDesc);
 
 
+            if (fg.isParamDesc(srcDesc)) {
+              methodGraph.setParamHNode(srcDesc);
+            }
+            if (fg.isParamDesc(dstDesc)) {
+              methodGraph.setParamHNode(dstDesc);
             }
 
             }
 
-            // }
           }
 
           }
 
+          // }
+          // }
+
         }
 
       }
         }
 
       }
@@ -3841,8 +3854,10 @@ public class LocationInference {
       Descriptor srcFieldDesc = srcCurTuple.get(idx);
       Descriptor dstFieldDesc = dstCurTuple.get(idx);
 
       Descriptor srcFieldDesc = srcCurTuple.get(idx);
       Descriptor dstFieldDesc = dstCurTuple.get(idx);
 
-      // add a new edge
-      getHierarchyGraph(cd).addEdge(srcFieldDesc, dstFieldDesc);
+      if (!srcFieldDesc.equals(dstFieldDesc)) {
+        // add a new edge
+        getHierarchyGraph(cd).addEdge(srcFieldDesc, dstFieldDesc);
+      }
 
     }
 
 
     }
 
@@ -4252,6 +4267,7 @@ public class LocationInference {
       }
     }
     if (size > 1) {
       }
     }
     if (size > 1) {
+      System.out.println("needToGenerateInterLoc=" + tupleSet + "  size=" + size);
       return true;
     } else {
       return false;
       return true;
     } else {
       return false;
@@ -4455,12 +4471,13 @@ public class LocationInference {
       NTuple<Descriptor> interTuple = null;
       if (needToGenerateInterLoc(nodeSetRHS)) {
         System.out.println("3");
       NTuple<Descriptor> interTuple = null;
       if (needToGenerateInterLoc(nodeSetRHS)) {
         System.out.println("3");
-
         interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
       }
 
       for (Iterator<NTuple<Descriptor>> iter = nodeSetRHS.iterator(); iter.hasNext();) {
         NTuple<Descriptor> fromTuple = iter.next();
         interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
       }
 
       for (Iterator<NTuple<Descriptor>> iter = nodeSetRHS.iterator(); iter.hasNext();) {
         NTuple<Descriptor> fromTuple = iter.next();
+        System.out.println("fromTuple=" + fromTuple + "  interTuple=" + interTuple + " tupleLSH="
+            + tupleLHS);
         addFlowGraphEdge(md, fromTuple, interTuple, tupleLHS);
       }
 
         addFlowGraphEdge(md, fromTuple, interTuple, tupleLHS);
       }
 
@@ -4586,20 +4603,47 @@ public class LocationInference {
   private void analyzeFlowTertiaryNode(MethodDescriptor md, SymbolTable nametable, TertiaryNode tn,
       NodeTupleSet nodeSet, NodeTupleSet implicitFlowTupleSet) {
 
   private void analyzeFlowTertiaryNode(MethodDescriptor md, SymbolTable nametable, TertiaryNode tn,
       NodeTupleSet nodeSet, NodeTupleSet implicitFlowTupleSet) {
 
+    System.out.println("analyzeFlowTertiaryNode=" + tn.printNode(0));
+
     NodeTupleSet tertiaryTupleNode = new NodeTupleSet();
     analyzeFlowExpressionNode(md, nametable, tn.getCond(), tertiaryTupleNode, null,
         implicitFlowTupleSet, false);
 
     NodeTupleSet tertiaryTupleNode = new NodeTupleSet();
     analyzeFlowExpressionNode(md, nametable, tn.getCond(), tertiaryTupleNode, null,
         implicitFlowTupleSet, false);
 
+    NodeTupleSet newImplicitTupleSet = new NodeTupleSet();
+    newImplicitTupleSet.addTupleSet(implicitFlowTupleSet);
+    newImplicitTupleSet.addTupleSet(tertiaryTupleNode);
+
+    System.out.println("$$$GGGcondTupleNode=" + tertiaryTupleNode.getGlobalLocTupleSet());
+    System.out.println("-tertiaryTupleNode=" + tertiaryTupleNode);
+    System.out.println("-implicitFlowTupleSet=" + implicitFlowTupleSet);
+    System.out.println("-newImplicitTupleSet=" + newImplicitTupleSet);
+
+    if (needToGenerateInterLoc(newImplicitTupleSet)) {
+      System.out.println("15");
+      // need to create an intermediate node for the GLB of conditional locations & implicit flows
+      NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
+      for (Iterator<NTuple<Descriptor>> idxIter = newImplicitTupleSet.iterator(); idxIter.hasNext();) {
+        NTuple<Descriptor> tuple = idxIter.next();
+        addFlowGraphEdge(md, tuple, interTuple);
+      }
+      newImplicitTupleSet.clear();
+      newImplicitTupleSet.addTuple(interTuple);
+    }
+
+    newImplicitTupleSet.addGlobalFlowTupleSet(tertiaryTupleNode.getGlobalLocTupleSet());
+
     // add edges from tertiaryTupleNode to all nodes of conditional nodes
     // add edges from tertiaryTupleNode to all nodes of conditional nodes
-    tertiaryTupleNode.addTupleSet(implicitFlowTupleSet);
+    // tertiaryTupleNode.addTupleSet(implicitFlowTupleSet);
     analyzeFlowExpressionNode(md, nametable, tn.getTrueExpr(), tertiaryTupleNode, null,
     analyzeFlowExpressionNode(md, nametable, tn.getTrueExpr(), tertiaryTupleNode, null,
-        implicitFlowTupleSet, false);
+        newImplicitTupleSet, false);
 
     analyzeFlowExpressionNode(md, nametable, tn.getFalseExpr(), tertiaryTupleNode, null,
 
     analyzeFlowExpressionNode(md, nametable, tn.getFalseExpr(), tertiaryTupleNode, null,
-        implicitFlowTupleSet, false);
+        newImplicitTupleSet, false);
 
 
+    nodeSet.addGlobalFlowTupleSet(tertiaryTupleNode.getGlobalLocTupleSet());
     nodeSet.addTupleSet(tertiaryTupleNode);
 
     nodeSet.addTupleSet(tertiaryTupleNode);
 
+    System.out.println("#tertiary node set=" + nodeSet);
   }
 
   private void addMapCallerMethodDescToMethodInvokeNodeSet(MethodDescriptor caller,
   }
 
   private void addMapCallerMethodDescToMethodInvokeNodeSet(MethodDescriptor caller,
@@ -4681,16 +4725,6 @@ public class LocationInference {
 
       System.out.println("---calleeReturnSet=" + calleeReturnSet);
 
 
       System.out.println("---calleeReturnSet=" + calleeReturnSet);
 
-      // when generating the global flow graph,
-      // we need to add ordering relations from the set of callee return loc tuple to LHS of the
-      // caller assignment
-      for (Iterator iterator = calleeReturnSet.iterator(); iterator.hasNext();) {
-        FlowNode calleeReturnNode = (FlowNode) iterator.next();
-        NTuple<Location> calleeReturnLocTuple =
-            translateToLocTuple(mdCallee, calleeReturnNode.getDescTuple());
-        nodeSet.addGlobalFlowTuple(calleeReturnLocTuple);
-      }
-
       NodeTupleSet tupleSet = new NodeTupleSet();
 
       if (min.getExpression() != null) {
       NodeTupleSet tupleSet = new NodeTupleSet();
 
       if (min.getExpression() != null) {
@@ -4804,7 +4838,20 @@ public class LocationInference {
 
       // propagateFlowsFromCallee(min, md, min.getMethod());
 
 
       // propagateFlowsFromCallee(min, md, min.getMethod());
 
+      // when generating the global flow graph,
+      // we need to add ordering relations from the set of callee return loc tuple to LHS of the
+      // caller assignment
+      for (Iterator iterator = calleeReturnSet.iterator(); iterator.hasNext();) {
+        FlowNode calleeReturnNode = (FlowNode) iterator.next();
+        NTuple<Location> calleeReturnLocTuple =
+            translateToLocTuple(mdCallee, calleeReturnNode.getDescTuple());
+        System.out.println("calleeReturnLocTuple=" + calleeReturnLocTuple);
+        nodeSet.addGlobalFlowTuple(translateToCallerLocTuple(min, mdCallee, mdCaller,
+            calleeReturnLocTuple));
+      }
+
       System.out.println("min nodeSet=" + nodeSet);
       System.out.println("min nodeSet=" + nodeSet);
+
     }
 
   }
     }
 
   }
@@ -5189,12 +5236,13 @@ public class LocationInference {
 
             nodeSetArrayAccessExp.addTuple(flowFieldTuple);
             nodeSetArrayAccessExp.addTupleSet(idxNodeTupleSet);
 
             nodeSetArrayAccessExp.addTuple(flowFieldTuple);
             nodeSetArrayAccessExp.addTupleSet(idxNodeTupleSet);
+            nodeSetArrayAccessExp.addTupleSet(nodeSet);
 
             if (needToGenerateInterLoc(nodeSetArrayAccessExp)) {
               System.out.println("4");
               System.out.println("nodeSetArrayAccessExp=" + nodeSetArrayAccessExp);
 
             if (needToGenerateInterLoc(nodeSetArrayAccessExp)) {
               System.out.println("4");
               System.out.println("nodeSetArrayAccessExp=" + nodeSetArrayAccessExp);
-              System.out.println("idxNodeTupleSet.getGlobalLocTupleSet()="
-                  + idxNodeTupleSet.getGlobalLocTupleSet());
+              // System.out.println("idxNodeTupleSet.getGlobalLocTupleSet()="
+              // + idxNodeTupleSet.getGlobalLocTupleSet());
 
               NTuple<Descriptor> interTuple =
                   getFlowGraph(md).createIntermediateNode().getDescTuple();
 
               NTuple<Descriptor> interTuple =
                   getFlowGraph(md).createIntermediateNode().getDescTuple();
@@ -5204,6 +5252,7 @@ public class LocationInference {
                 NTuple<Descriptor> higherTuple = iter.next();
                 addFlowGraphEdge(md, higherTuple, interTuple);
               }
                 NTuple<Descriptor> higherTuple = iter.next();
                 addFlowGraphEdge(md, higherTuple, interTuple);
               }
+              nodeSet.clear();
               flowFieldTuple = interTuple;
             }
 
               flowFieldTuple = interTuple;
             }
 
@@ -5380,6 +5429,8 @@ public class LocationInference {
 
   public void writeInferredLatticeDotFile(ClassDescriptor cd, HierarchyGraph simpleHierarchyGraph,
       SSJavaLattice<String> locOrder, String nameSuffix) {
 
   public void writeInferredLatticeDotFile(ClassDescriptor cd, HierarchyGraph simpleHierarchyGraph,
       SSJavaLattice<String> locOrder, String nameSuffix) {
+    System.out.println("@cd=" + cd);
+    System.out.println("@sharedLoc=" + locOrder.getSharedLocSet());
     writeInferredLatticeDotFile(cd, null, simpleHierarchyGraph, locOrder, nameSuffix);
   }
 
     writeInferredLatticeDotFile(cd, null, simpleHierarchyGraph, locOrder, nameSuffix);
   }
 
@@ -5412,7 +5463,7 @@ public class LocationInference {
 
           String highLocId = pair.getFirst();
           String lowLocId = pair.getSecond();
 
           String highLocId = pair.getFirst();
           String lowLocId = pair.getSecond();
-
+          System.out.println("addedLocSet=" + addedLocSet);
           if (!addedLocSet.contains(highLocId)) {
             addedLocSet.add(highLocId);
             drawNode(bw, locOrder, simpleHierarchyGraph, highLocId);
           if (!addedLocSet.contains(highLocId)) {
             addedLocSet.add(highLocId);
             drawNode(bw, locOrder, simpleHierarchyGraph, highLocId);
@@ -5452,23 +5503,17 @@ public class LocationInference {
   private void drawNode(BufferedWriter bw, SSJavaLattice<String> lattice, HierarchyGraph graph,
       String locName) throws IOException {
 
   private void drawNode(BufferedWriter bw, SSJavaLattice<String> lattice, HierarchyGraph graph,
       String locName) throws IOException {
 
-    HNode node = graph.getHNode(locName);
-
-    if (node == null) {
-      return;
-    }
-
     String prettyStr;
     if (lattice.isSharedLoc(locName)) {
       prettyStr = locName + "*";
     } else {
       prettyStr = locName;
     }
     String prettyStr;
     if (lattice.isSharedLoc(locName)) {
       prettyStr = locName + "*";
     } else {
       prettyStr = locName;
     }
-
-    if (node.isMergeNode()) {
-      Set<HNode> mergeSet = graph.getMapHNodetoMergeSet().get(node);
-      prettyStr += ":" + convertMergeSetToString(graph, mergeSet);
-    }
+    // HNode node = graph.getHNode(locName);
+    // if (node != null && node.isMergeNode()) {
+    // Set<HNode> mergeSet = graph.getMapHNodetoMergeSet().get(node);
+    // prettyStr += ":" + convertMergeSetToString(graph, mergeSet);
+    // }
     bw.write(locName + " [label=\"" + prettyStr + "\"]" + ";\n");
   }
 
     bw.write(locName + " [label=\"" + prettyStr + "\"]" + ";\n");
   }
 
index f6aefddc367dbdb3bc8ef55ca321583a9d7c1eaa..e0f953a48cf36443b065becc1d60f7a0b4cda37f 100644 (file)
@@ -1,19 +1,32 @@
 package Analysis.SSJava;
 
 import java.util.HashMap;
 package Analysis.SSJava;
 
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Map;
+import java.util.Set;
 
 public abstract class LocationSummary {
 
   Map<String, String> mapHNodeNameToLocationName;
 
 public abstract class LocationSummary {
 
   Map<String, String> mapHNodeNameToLocationName;
+  Map<String, Set<String>> mapLocationNameToHNodeNameSet;
 
   public LocationSummary() {
     mapHNodeNameToLocationName = new HashMap<String, String>();
 
   public LocationSummary() {
     mapHNodeNameToLocationName = new HashMap<String, String>();
+    mapLocationNameToHNodeNameSet = new HashMap<String, Set<String>>();
   }
 
   public void addMapHNodeNameToLocationName(String nodeName, String locName) {
     // System.out.println("nodeName="+nodeName+"  locName="+locName);
     mapHNodeNameToLocationName.put(nodeName, locName);
   }
 
   public void addMapHNodeNameToLocationName(String nodeName, String locName) {
     // System.out.println("nodeName="+nodeName+"  locName="+locName);
     mapHNodeNameToLocationName.put(nodeName, locName);
+
+    if (!mapLocationNameToHNodeNameSet.containsKey(locName)) {
+      mapLocationNameToHNodeNameSet.put(locName, new HashSet<String>());
+    }
+    mapLocationNameToHNodeNameSet.get(locName).add(nodeName);
+  }
+
+  public Set<String> getHNodeNameSetByLatticeLoationName(String locName) {
+    return mapLocationNameToHNodeNameSet.get(locName);
   }
 
   public String getLocationName(String nodeName) {
   }
 
   public String getLocationName(String nodeName) {