changes: now it generates simple lattice without having intermediate nodes for the...
authoryeom <yeom>
Tue, 9 Oct 2012 00:01:24 +0000 (00:01 +0000)
committeryeom <yeom>
Tue, 9 Oct 2012 00:01:24 +0000 (00:01 +0000)
Robust/src/Analysis/SSJava/BuildLattice.java
Robust/src/Analysis/SSJava/GlobalFlowGraph.java
Robust/src/Analysis/SSJava/GlobalFlowNode.java
Robust/src/Analysis/SSJava/LocationInference.java
Robust/src/Analysis/SSJava/SSJavaLattice.java

index 264699c3767c0757e50887ff0b6978b2b6c3db40..52a2bf9c188f6857e4a5be2850f4df45460f888f 100644 (file)
@@ -118,6 +118,8 @@ public class BuildLattice {
     Set<HNode> nodeSet = simpleGraph.getNodeSet();
 
     Map<TripleItem, String> mapIntermediateLoc = new HashMap<TripleItem, String>();
+
+
     for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
       HNode node = (HNode) iterator.next();
       if (node.isSkeleton() && (!visited.contains(node))) {
@@ -205,19 +207,22 @@ public class BuildLattice {
         }
       } else if (!node.isSkeleton() && !node.isCombinationNode() && !node.isMergeNode()
           && !visited.contains(node)) {
-        // an intermediate node 'node' is located between "TOP" location and a skeleton node
+        // an intermediate node 'node' may be located between "TOP" location and a skeleton node
+        // but there is no such a case.
+
+        // Set<HNode> outNodeSet = simpleGraph.getOutgoingNodeSet(node);
+        // Set<String> belowSkeletonLocNameSet = new HashSet<String>();
+        // for (Iterator iterator2 = outNodeSet.iterator(); iterator2.hasNext();) {
+        // HNode outNode = (HNode) iterator2.next();
+        // if (outNode.isSkeleton()) {
+        // belowSkeletonLocNameSet.add(scGraph.getCurrentHNode(outNode).getName());
+        // }
+        // }
+        // String newLocName = "ILOC" + (seed++);
+        // lattice.insertNewLocationBetween(lattice.getTopItem(), belowSkeletonLocNameSet,
+        // newLocName);
+        // locSummary.addMapHNodeNameToLocationName(node.getName(), newLocName);
 
-        Set<HNode> outNodeSet = simpleGraph.getOutgoingNodeSet(node);
-        Set<String> belowSkeletonLocNameSet = new HashSet<String>();
-        for (Iterator iterator2 = outNodeSet.iterator(); iterator2.hasNext();) {
-          HNode outNode = (HNode) iterator2.next();
-          if (outNode.isSkeleton()) {
-            belowSkeletonLocNameSet.add(scGraph.getCurrentHNode(outNode).getName());
-          }
-        }
-        String newLocName = "ILOC" + (seed++);
-        lattice.insertNewLocationBetween(lattice.getTopItem(), belowSkeletonLocNameSet, newLocName);
-        locSummary.addMapHNodeNameToLocationName(node.getName(), newLocName);
       }
     }
 
index 35fbd006bb2fa93f887e0b260dce42cd3afc371a..ac901bedfb78ed4bb229fcb0b3f239d012526871 100644 (file)
@@ -19,6 +19,7 @@ public class GlobalFlowGraph {
 
   Map<NTuple<Location>, GlobalFlowNode> mapLocTupleToNode;
   Map<GlobalFlowNode, Set<GlobalFlowNode>> mapFlowNodeToOutNodeSet;
+  Map<GlobalFlowNode, Set<GlobalFlowNode>> mapFlowNodeToInNodeSet;
 
   Map<Location, CompositeLocation> mapLocationToInferCompositeLocation;
 
@@ -26,6 +27,8 @@ public class GlobalFlowGraph {
     this.md = md;
     this.mapLocTupleToNode = new HashMap<NTuple<Location>, GlobalFlowNode>();
     this.mapFlowNodeToOutNodeSet = new HashMap<GlobalFlowNode, Set<GlobalFlowNode>>();
+    this.mapFlowNodeToInNodeSet = new HashMap<GlobalFlowNode, Set<GlobalFlowNode>>();
+
     this.mapLocationToInferCompositeLocation = new HashMap<Location, CompositeLocation>();
   }
 
@@ -59,7 +62,7 @@ public class GlobalFlowGraph {
       CompositeLocation oldCompLoc = mapLocationToInferCompositeLocation.get(loc);
 
       if (newCompLoc.getSize() == oldCompLoc.getSize()) {
-        for (int i = 0; i < oldCompLoc.getSize(); i++) {
+        for (int i = 0; i < oldCompLoc.getSize() - 1; i++) {
           Location oldLocElement = oldCompLoc.get(i);
           Location newLocElement = newCompLoc.get(i);
 
@@ -96,10 +99,22 @@ public class GlobalFlowGraph {
     }
     mapFlowNodeToOutNodeSet.get(fromNode).add(toNode);
 
+    if (!mapFlowNodeToInNodeSet.containsKey(toNode)) {
+      mapFlowNodeToInNodeSet.put(toNode, new HashSet<GlobalFlowNode>());
+    }
+    mapFlowNodeToInNodeSet.get(toNode).add(fromNode);
+
     System.out.println("create a global edge from " + fromNode + " to " + toNode);
 
   }
 
+  public Set<GlobalFlowNode> getInNodeSet(GlobalFlowNode node) {
+    if (!mapFlowNodeToInNodeSet.containsKey(node)) {
+      mapFlowNodeToInNodeSet.put(node, new HashSet<GlobalFlowNode>());
+    }
+    return mapFlowNodeToInNodeSet.get(node);
+  }
+
   public Set<GlobalFlowNode> getNodeSet() {
     Set<GlobalFlowNode> nodeSet = new HashSet<GlobalFlowNode>();
     nodeSet.addAll(mapLocTupleToNode.values());
@@ -202,6 +217,80 @@ public class GlobalFlowGraph {
 
   }
 
+  public Set<GlobalFlowNode> getIncomingNodeSetByPrefix(Location prefix) {
+
+    Set<GlobalFlowNode> incomingNodeSet = new HashSet<GlobalFlowNode>();
+
+    for (Iterator iterator = getNodeSet().iterator(); iterator.hasNext();) {
+      GlobalFlowNode curNode = (GlobalFlowNode) iterator.next();
+      Set<GlobalFlowNode> outNodeSet = getOutNodeSet(curNode);
+
+      for (Iterator iterator2 = outNodeSet.iterator(); iterator2.hasNext();) {
+        GlobalFlowNode outNode = (GlobalFlowNode) iterator2.next();
+
+        if (outNode.getLocTuple().startsWith(prefix)) {
+          incomingNodeSet.add(curNode);
+          recurIncomingNodeSetByPrefix(prefix, curNode, incomingNodeSet);
+        }
+
+      }
+    }
+
+    return incomingNodeSet;
+
+  }
+
+  private void recurIncomingNodeSetByPrefix(Location prefix, GlobalFlowNode node,
+      Set<GlobalFlowNode> visited) {
+
+    Set<GlobalFlowNode> inNodeSet = getInNodeSet(node);
+
+    for (Iterator iterator = inNodeSet.iterator(); iterator.hasNext();) {
+      GlobalFlowNode curNode = (GlobalFlowNode) iterator.next();
+
+      if (!curNode.getLocTuple().startsWith(prefix) && !visited.contains(curNode)) {
+        visited.add(curNode);
+        recurIncomingNodeSetByPrefix(prefix, curNode, visited);
+      }
+    }
+
+  }
+
+  public Set<GlobalFlowNode> getReachableNodeSetByPrefix(Location prefix) {
+
+    Set<GlobalFlowNode> reachableNodeSet = new HashSet<GlobalFlowNode>();
+
+    for (Iterator iterator = getNodeSet().iterator(); iterator.hasNext();) {
+      GlobalFlowNode curNode = (GlobalFlowNode) iterator.next();
+
+      if (curNode.getLocTuple().startsWith(prefix)) {
+        Set<GlobalFlowNode> outNodeSet = getOutNodeSet(curNode);
+        for (Iterator iterator2 = outNodeSet.iterator(); iterator2.hasNext();) {
+          GlobalFlowNode outNode = (GlobalFlowNode) iterator2.next();
+          if (!outNode.getLocTuple().startsWith(prefix) && !reachableNodeSet.contains(outNode)) {
+            reachableNodeSet.add(outNode);
+            recurReachableNodeSetByPrefix(prefix, outNode, reachableNodeSet);
+          }
+
+        }
+      }
+    }
+
+    return reachableNodeSet;
+  }
+
+  private void recurReachableNodeSetByPrefix(Location prefix, GlobalFlowNode node,
+      Set<GlobalFlowNode> reachableNodeSet) {
+    Set<GlobalFlowNode> outNodeSet = getOutNodeSet(node);
+    for (Iterator iterator = outNodeSet.iterator(); iterator.hasNext();) {
+      GlobalFlowNode outNode = (GlobalFlowNode) iterator.next();
+      if (!outNode.getLocTuple().startsWith(prefix) && !reachableNodeSet.contains(outNode)) {
+        reachableNodeSet.add(outNode);
+        recurReachableNodeSetByPrefix(prefix, outNode, reachableNodeSet);
+      }
+    }
+  }
+
   public Set<GlobalFlowNode> getReachableNodeSetFrom(GlobalFlowNode node) {
 
     Set<GlobalFlowNode> reachableNodeSet = new HashSet<GlobalFlowNode>();
index 3f5c72d1ed4c90724deec7c7409070dd9c24c53a..03f96b28fdac672e9052d7c1aa04f429db840701 100644 (file)
@@ -9,9 +9,6 @@ public class GlobalFlowNode {
 
   public GlobalFlowNode(NTuple<Location> in) {
     locTuple = in;
-    if (in.size() == 0) {
-      throw new Error();
-    }
   }
 
   public int hashCode() {
index 0967c58b5986b90f2c47dadfa256bb0390bf1989..26bd8c29a9d8e64bd9138ad83bbeec237eac733b 100644 (file)
@@ -224,8 +224,6 @@ public class LocationInference {
 
     // constructGlobalFlowGraph();
 
-    System.exit(0);
-
     constructHierarchyGraph();
 
     debug_writeHierarchyDotFiles();
@@ -307,6 +305,7 @@ public class LocationInference {
     FlowGraph callerFlowGraph = getFlowGraph(mdCaller);
     Map<Location, CompositeLocation> callerMapLocToCompLoc =
         callerGlobalFlowGraph.getMapLocationToInferCompositeLocation();
+    System.out.println("---callerMapLocToCompLoc=" + callerMapLocToCompLoc);
     Set<Location> methodLocSet = callerMapLocToCompLoc.keySet();
     for (Iterator iterator = methodLocSet.iterator(); iterator.hasNext();) {
       Location methodLoc = (Location) iterator.next();
@@ -399,29 +398,40 @@ public class LocationInference {
     NTuple<Location> baseLocTuple =
         translateToLocTuple(mdCaller, mapMethodInvokeNodeToBaseTuple.get(min));
 
-    System.out.println("-translate caller infer composite loc to callee=" + mdCallee);
+    System.out.println("\n-translate caller infer composite loc to callee=" + mdCallee
+        + " baseLocTuple=" + baseLocTuple);
     Set<Location> keySet = callerMapLocToCompLoc.keySet();
     for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
       Location key = (Location) iterator.next();
       CompositeLocation callerCompLoc = callerMapLocToCompLoc.get(key);
 
-      if (!key.getDescriptor().equals(mdCaller)
-          && callerCompLoc.getTuple().startsWith(baseLocTuple)) {
+      if (!key.getDescriptor().equals(mdCaller)) {
+        System.out.println("--- caller key=" + key + "  callerCompLoc=" + callerCompLoc);
+
+        // && callerCompLoc.getTuple().startsWith(baseLocTuple)) {
         // need to translate to the callee side
-        // System.out.println("need to translate callerCompLoc=" + callerCompLoc +
-        // " with baseTuple="
-        // + baseLocTuple);
+
         // TODO
-        CompositeLocation newCalleeCompLoc =
-            translateCompositeLocationToCallee(callerCompLoc, baseLocTuple, mdCallee);
-        calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, newCalleeCompLoc);
-        System.out.println("---callee loc=" + key + "  newCalleeCompLoc=" + newCalleeCompLoc);
+        CompositeLocation newCalleeCompLoc;
+        if (callerCompLoc.getTuple().startsWith(baseLocTuple)) {
+          System.out.println("---need to translate callerCompLoc=" + callerCompLoc
+              + " with baseTuple=" + baseLocTuple);
+          newCalleeCompLoc =
+              translateCompositeLocationToCallee(callerCompLoc, baseLocTuple, mdCallee);
+
+          calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, newCalleeCompLoc);
+          System.out.println("---callee loc=" + key + "  newCalleeCompLoc=" + newCalleeCompLoc);
+        } else {
+          // newCalleeCompLoc = callerCompLoc.clone();
+        }
+
       }
     }
 
     // If the location of an argument has a composite location
     // need to assign a proper composite location to the corresponding callee parameter
-    System.out.println("-translate arg composite location to callee param:");
+    System.out.println("\n-translate arg composite location to callee param. min="
+        + min.printNode(0));
     Map<Integer, NTuple<Descriptor>> mapIdxToArgTuple = mapMethodInvokeNodeToArgIdxMap.get(min);
     Set<Integer> idxSet = mapIdxToArgTuple.keySet();
     for (Iterator iterator = idxSet.iterator(); iterator.hasNext();) {
@@ -432,37 +442,44 @@ public class LocationInference {
       }
 
       NTuple<Descriptor> argTuple = mapIdxToArgTuple.get(idx);
+      if (argTuple.size() > 0) {
+        // check if an arg tuple has been already assigned to a composite location
+        NTuple<Location> argLocTuple = translateToLocTuple(mdCaller, argTuple);
+        Location argLocalLoc = argLocTuple.get(0);
 
-      // check if an arg tuple has been already assigned to a composite location
-      NTuple<Location> argLocTuple = translateToLocTuple(mdCaller, argTuple);
-      Location argLocalLoc = argLocTuple.get(0);
+        // if (!isPrimitiveType(argTuple)) {
+        if (callerMapLocToCompLoc.containsKey(argLocalLoc)) {
 
-      // if (!isPrimitiveType(argTuple)) {
-      if (callerMapLocToCompLoc.containsKey(argLocalLoc)) {
+          CompositeLocation callerCompLoc = callerMapLocToCompLoc.get(argLocalLoc);
+          for (int i = 1; i < argLocTuple.size(); i++) {
+            callerCompLoc.addLocation(argLocTuple.get(i));
+          }
 
-        CompositeLocation callerCompLoc = callerMapLocToCompLoc.get(argLocalLoc);
-        for (int i = 1; i < argLocTuple.size(); i++) {
-          callerCompLoc.addLocation(argLocTuple.get(i));
-        }
+          if (callerCompLoc.getTuple().startsWith(baseLocTuple)) {
 
-        if (callerCompLoc.getTuple().startsWith(baseLocTuple)) {
+            FlowNode calleeParamFlowNode = calleeFlowGraph.getParamFlowNode(idx);
+            NTuple<Descriptor> calleeParamDescTuple = calleeParamFlowNode.getDescTuple();
+            NTuple<Location> calleeParamLocTuple =
+                translateToLocTuple(mdCallee, calleeParamDescTuple);
 
-          FlowNode calleeParamFlowNode = calleeFlowGraph.getParamFlowNode(idx);
-          NTuple<Descriptor> calleeParamDescTuple = calleeParamFlowNode.getDescTuple();
-          NTuple<Location> calleeParamLocTuple =
-              translateToLocTuple(mdCallee, calleeParamDescTuple);
+            System.out.println("---need to translate callerCompLoc=" + callerCompLoc
+                + " with baseTuple=" + baseLocTuple + "   calleeParamLocTuple="
+                + calleeParamLocTuple);
 
-          CompositeLocation newCalleeCompLoc =
-              translateCompositeLocationToCallee(callerCompLoc, baseLocTuple, mdCallee);
+            CompositeLocation newCalleeCompLoc =
+                translateCompositeLocationToCallee(callerCompLoc, baseLocTuple, mdCallee);
 
-          calleeGlobalGraph.addMapLocationToInferCompositeLocation(calleeParamLocTuple.get(0),
-              newCalleeCompLoc);
+            calleeGlobalGraph.addMapLocationToInferCompositeLocation(calleeParamLocTuple.get(0),
+                newCalleeCompLoc);
 
-          System.out.println("###need to assign composite location to=" + calleeParamDescTuple
-              + " with baseTuple=" + baseLocTuple);
-          System.out.println("---newCalleeCompLoc=" + newCalleeCompLoc);
-        }
+            System.out.println("---callee loc=" + calleeParamLocTuple.get(0)
+                + "  newCalleeCompLoc=" + newCalleeCompLoc);
 
+            // System.out.println("###need to assign composite location to=" + calleeParamDescTuple
+            // + " with baseTuple=" + baseLocTuple);
+          }
+
+        }
       }
 
     }
@@ -487,14 +504,12 @@ public class LocationInference {
 
     CompositeLocation newCalleeCompLoc = new CompositeLocation();
 
-    // replace the last element of the caller compLoc with the 'this' location of the callee
-    for (int i = 0; i < baseLocTuple.size() - 1; i++) {
-      newCalleeCompLoc.addLocation(baseLocTuple.get(i));
-    }
-
     Location calleeThisLoc = new Location(mdCallee, mdCallee.getThis());
     newCalleeCompLoc.addLocation(calleeThisLoc);
 
+    // remove the base tuple from the caller
+    // ex; In the method invoation foo.bar.methodA(), the callee will have the composite location
+    // ,which is relative to the 'this' variable, <THIS,...>
     for (int i = baseLocTuple.size(); i < callerCompLoc.getSize(); i++) {
       newCalleeCompLoc.addLocation(callerCompLoc.get(i));
     }
@@ -558,24 +573,37 @@ public class LocationInference {
     MethodDescriptor methodDescEventLoop = ssjava.getMethodContainingSSJavaLoop();
     GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(methodDescEventLoop);
 
-    Set<NTuple<Location>> prefixSet = new HashSet<NTuple<Location>>();
+    Set<Location> calculatedPrefixSet = new HashSet<Location>();
 
     Set<GlobalFlowNode> nodeSet = globalFlowGraph.getNodeSet();
 
     next: for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
       GlobalFlowNode node = (GlobalFlowNode) iterator.next();
-      Set<GlobalFlowNode> incomingNodeSet = globalFlowGraph.getIncomingNodeSet(node);
+
+      Location prefixLoc = node.getLocTuple().get(0);
+
+      if (calculatedPrefixSet.contains(prefixLoc)) {
+        // the prefix loc has been already assigned to a composite location
+        continue;
+      }
+
+      calculatedPrefixSet.add(prefixLoc);
+
+      // Set<GlobalFlowNode> incomingNodeSet = globalFlowGraph.getIncomingNodeSet(node);
       List<NTuple<Location>> prefixList = calculatePrefixList(globalFlowGraph, node);
-      Set<GlobalFlowNode> reachNodeSet = globalFlowGraph.getReachableNodeSetFrom(node);
 
-      // System.out.println("node=" + node + "    inNodeSet=" + incomingNodeSet
-      // + "   reachableNodeSet=" + reachNodeSet);
+      Set<GlobalFlowNode> reachableNodeSet =
+          globalFlowGraph.getReachableNodeSetByPrefix(node.getLocTuple().get(0));
+      // Set<GlobalFlowNode> reachNodeSet = globalFlowGraph.getReachableNodeSetFrom(node);
+
+      // System.out.println("node=" + node + "    prefixList=" + prefixList + "   reachableNodeSet="
+      // + reachableNodeSet);
 
       for (int i = 0; i < prefixList.size(); i++) {
         NTuple<Location> curPrefix = prefixList.get(i);
         Set<NTuple<Location>> reachableCommonPrefixSet = new HashSet<NTuple<Location>>();
 
-        for (Iterator iterator2 = reachNodeSet.iterator(); iterator2.hasNext();) {
+        for (Iterator iterator2 = reachableNodeSet.iterator(); iterator2.hasNext();) {
           GlobalFlowNode reachNode = (GlobalFlowNode) iterator2.next();
           if (reachNode.getLocTuple().startsWith(curPrefix)) {
             reachableCommonPrefixSet.add(reachNode.getLocTuple());
@@ -584,16 +612,44 @@ public class LocationInference {
 
         if (!reachableCommonPrefixSet.isEmpty()) {
 
-          // TODO
-          if (!node.getLocTuple().startsWith(curPrefix.get(0))) {
+          MethodDescriptor curPrefixFirstElementMethodDesc =
+              (MethodDescriptor) curPrefix.get(0).getDescriptor();
+
+          MethodDescriptor nodePrefixLocFirstElementMethodDesc =
+              (MethodDescriptor) prefixLoc.getDescriptor();
+
+          if (curPrefixFirstElementMethodDesc.equals(nodePrefixLocFirstElementMethodDesc)
+              || isTransitivelyCalledFrom(nodePrefixLocFirstElementMethodDesc,
+                  curPrefixFirstElementMethodDesc)) {
+
+            // TODO
+            // if (!node.getLocTuple().startsWith(curPrefix.get(0))) {
+
+            Location curPrefixLocalLoc = curPrefix.get(0);
+            if (globalFlowGraph.mapLocationToInferCompositeLocation.containsKey(curPrefixLocalLoc)) {
+              // in this case, the local variable of the current prefix has already got a composite
+              // location
+              // so we just ignore the current composite location.
+
+              // System.out.println("HERE WE DO NOT ASSIGN A COMPOSITE LOCATION TO =" + node
+              // + " DUE TO " + curPrefix);
+
+              continue next;
+            }
+
+            Location targetLocalLoc = node.getLocTuple().get(0);
+            // CompositeLocation curCompLoc = globalFlowGraph.getCompositeLocation(targetLocalLoc);
+            // if ((curPrefix.size() + 1) > curCompLoc.getSize()) {
+
             CompositeLocation newCompLoc = generateCompositeLocation(curPrefix);
             System.out.println("NEED TO ASSIGN COMP LOC TO " + node + " with prefix=" + curPrefix);
             System.out.println("- newCompLoc=" + newCompLoc);
-
-            Location targetLocalLoc = node.getLocTuple().get(0);
             globalFlowGraph.addMapLocationToInferCompositeLocation(targetLocalLoc, newCompLoc);
+            // }
 
             continue next;
+            // }
+
           }
 
         }
@@ -617,13 +673,21 @@ public class LocationInference {
 
   private List<NTuple<Location>> calculatePrefixList(GlobalFlowGraph graph, GlobalFlowNode node) {
 
-    System.out.println("\n##### calculatePrefixList=" + node);
+    System.out.println("\n##### calculatePrefixList node=" + node);
 
-    Set<GlobalFlowNode> incomingNodeSet = graph.getIncomingNodeSet(node);
+    MethodDescriptor md = graph.getMethodDescriptor();
+
+    Set<GlobalFlowNode> incomingNodeSetPrefix =
+        graph.getIncomingNodeSetByPrefix(node.getLocTuple().get(0));
+    // System.out.println("incomingNodeSetPrefix=" + incomingNodeSetPrefix);
+    //
+    // Set<GlobalFlowNode> reachableNodeSetPrefix =
+    // graph.getReachableNodeSetByPrefix(node.getLocTuple().get(0));
+    // System.out.println("reachableNodeSetPrefix=" + reachableNodeSetPrefix);
 
     List<NTuple<Location>> prefixList = new ArrayList<NTuple<Location>>();
 
-    for (Iterator iterator = incomingNodeSet.iterator(); iterator.hasNext();) {
+    for (Iterator iterator = incomingNodeSetPrefix.iterator(); iterator.hasNext();) {
       GlobalFlowNode inNode = (GlobalFlowNode) iterator.next();
       NTuple<Location> inNodeTuple = inNode.getLocTuple();
 
@@ -649,6 +713,35 @@ public class LocationInference {
       }
     });
     return prefixList;
+
+    // List<NTuple<Location>> prefixList = new ArrayList<NTuple<Location>>();
+    //
+    // for (Iterator iterator = incomingNodeSet.iterator(); iterator.hasNext();) {
+    // GlobalFlowNode inNode = (GlobalFlowNode) iterator.next();
+    // NTuple<Location> inNodeTuple = inNode.getLocTuple();
+    //
+    // for (int i = 1; i < inNodeTuple.size(); i++) {
+    // NTuple<Location> prefix = inNodeTuple.subList(0, i);
+    // if (!prefixList.contains(prefix)) {
+    // prefixList.add(prefix);
+    // }
+    // }
+    // }
+    //
+    // Collections.sort(prefixList, new Comparator<NTuple<Location>>() {
+    // public int compare(NTuple<Location> arg0, NTuple<Location> arg1) {
+    // int s0 = arg0.size();
+    // int s1 = arg1.size();
+    // if (s0 > s1) {
+    // return -1;
+    // } else if (s0 == s1) {
+    // return 0;
+    // } else {
+    // return 1;
+    // }
+    // }
+    // });
+    // return prefixList;
   }
 
   private GlobalFlowGraph constructSubGlobalFlowGraph(FlowGraph flowGraph) {
@@ -700,7 +793,7 @@ public class LocationInference {
     NTuple<Location> locTuple = new NTuple<Location>();
 
     Descriptor enclosingDesc = md;
-    System.out.println("md=" + md + "  descTuple=" + descTuple);
+    // System.out.println("md=" + md + "  descTuple=" + descTuple);
     for (int i = 0; i < descTuple.size(); i++) {
       Descriptor desc = descTuple.get(i);
 
@@ -841,7 +934,6 @@ public class LocationInference {
     NTuple<Location> callerSrcNodeLocTuple =
         translateToCallerLocTuple(min, mdCallee, mdCaller, calleeSrcNode.getLocTuple());
 
-
     if (callerSrcNodeLocTuple != null) {
       Set<GlobalFlowNode> outNodeSet = calleeSubGlobalGraph.getOutNodeSet(calleeSrcNode);
 
@@ -2350,12 +2442,13 @@ public class LocationInference {
           // parameters
 
           Set<FlowNode> localReachSet = calleeFlowGraph.getLocalReachFlowNodeSetFrom(paramNode1);
+          System.out.println("-param1=" + paramNode1 + " is higher than param2=" + paramNode2);
+          System.out.println("-- localReachSet from param1=" + localReachSet);
 
-          if (arg1Tuple.size() > 0 && arg2Tuple.size() > 2 && localReachSet.contains(paramNode2)) {
+          if (arg1Tuple.size() > 0 && arg2Tuple.size() > 0 && localReachSet.contains(paramNode2)) {
             // need to propagate an ordering relation s.t. arg1 is higher
             // than arg2
 
-            System.out.println("-param1=" + paramNode1 + " is higher than param2=" + paramNode2);
             System.out
                 .println("-arg1Tuple=" + arg1Tuple + " is higher than arg2Tuple=" + arg2Tuple);
 
@@ -2926,6 +3019,7 @@ public class LocationInference {
     NTuple<Descriptor> srcCurTuple = srcNode.getCurrentDescTuple();
     NTuple<Descriptor> dstCurTuple = dstNode.getCurrentDescTuple();
 
+    System.out.println("srcCurTuple=" + srcCurTuple + "  dstCurTuple=" + dstCurTuple);
     if (srcCurTuple.get(idx).equals(dstCurTuple.get(idx)) && srcCurTuple.size() > (idx + 1)
         && dstCurTuple.size() > (idx + 1)) {
       // value flow between fields: we don't need to add a binary relation
@@ -2937,9 +3031,14 @@ public class LocationInference {
       if (idx == 0) {
         classDesc = ((VarDescriptor) desc).getType().getClassDesc();
       } else {
-        classDesc = ((FieldDescriptor) desc).getType().getClassDesc();
-      }
 
+        if (desc instanceof FieldDescriptor) {
+          classDesc = ((FieldDescriptor) desc).getType().getClassDesc();
+        } else {
+          // TODO: need to handle a location descriptor case
+          classDesc = null;
+        }
+      }
       extractFlowsBetweenFields(classDesc, srcNode, dstNode, idx + 1);
 
     } else {
@@ -3017,6 +3116,21 @@ public class LocationInference {
 
   }
 
+  public boolean isTransitivelyCalledFrom(MethodDescriptor callee, MethodDescriptor caller) {
+    // if the callee is transitively invoked from the caller
+    // return true;
+
+    int callerIdx = toanalyze_methodDescList.indexOf(caller);
+    int calleeIdx = toanalyze_methodDescList.indexOf(callee);
+
+    if (callerIdx < calleeIdx) {
+      return true;
+    }
+
+    return false;
+
+  }
+
   public void constructFlowGraph() {
 
     System.out.println("");
index ef1722b7b483663152803fbf0d337f400fe8a276..847cfecbb68e8707130cbb363a28d3d1bb4a8d1d 100644 (file)
@@ -320,6 +320,8 @@ public class SSJavaLattice<T> extends Lattice<T> {
   }
 
   public void insertNewLocationBetween(T higher, Set<T> lowerSet, T newLoc) {
+    System.out.println("---insert new location=" + newLoc + "   between=" + higher + "<->"
+        + lowerSet);
     Set<T> connectedSet = get(higher);
     connectedSet.removeAll(lowerSet);
     connectedSet.add(newLoc);