now it works fine with three benchmarks
[IRC.git] / Robust / src / Analysis / SSJava / LocationInference.java
index 18f1d3ed5b8580cb78a9122664b716f3a5a71352..e5487a1de8a93d1ecc8d44f458e7408e1e8b7061 100644 (file)
@@ -135,14 +135,14 @@ public class LocationInference {
 
   private Map<MethodDescriptor, Set<MethodDescriptor>> mapHighestOverriddenMethodDescToMethodDescSet;
 
-  private Map<MethodDescriptor, Set<NTuple<Descriptor>>> mapHighestOverriddenMethodDescToSetHigherThanRLoc;
-
   private Map<MethodDescriptor, NTuple<Descriptor>> mapHighestOverriddenMethodDescToReturnLocTuple;
 
   private Map<MethodDescriptor, NTuple<Descriptor>> mapHighestOverriddenMethodDescToPCLocTuple;
 
   private Map<MethodDescriptor, Set<NTuple<Descriptor>>> mapHighestOverriddenMethodDescToSetLowerThanPCLoc;
 
+  private Map<MethodDescriptor, Set<NTuple<Descriptor>>> mapHighestOverriddenMethodDescToSetHigherThanRETURNLoc;
+
   public static final String GLOBALLOC = "GLOBALLOC";
 
   public static final String INTERLOC = "INTERLOC";
@@ -233,9 +233,6 @@ public class LocationInference {
 
     mapMethodDescToHighestOverriddenMethodDesc = new HashMap<MethodDescriptor, MethodDescriptor>();
 
-    mapHighestOverriddenMethodDescToSetHigherThanRLoc =
-        new HashMap<MethodDescriptor, Set<NTuple<Descriptor>>>();
-
     mapHighestOverriddenMethodDescToSetLowerThanPCLoc =
         new HashMap<MethodDescriptor, Set<NTuple<Descriptor>>>();
 
@@ -248,6 +245,9 @@ public class LocationInference {
     mapHighestOverriddenMethodDescToPCLocTuple =
         new HashMap<MethodDescriptor, NTuple<Descriptor>>();
 
+    mapHighestOverriddenMethodDescToSetHigherThanRETURNLoc =
+        new HashMap<MethodDescriptor, Set<NTuple<Descriptor>>>();
+
     this.buildLattice = new BuildLattice(this);
 
   }
@@ -369,6 +369,7 @@ public class LocationInference {
   }
 
   private void updateFlowGraphPCReturnLocInheritance() {
+
     Set<MethodDescriptor> keySet = mapHighestOverriddenMethodDescToMethodDescSet.keySet();
     for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
       MethodDescriptor highestMethodDesc = (MethodDescriptor) iterator.next();
@@ -380,74 +381,91 @@ public class LocationInference {
       Set<MethodDescriptor> methodDescSet =
           mapHighestOverriddenMethodDescToMethodDescSet.get(highestMethodDesc);
 
-      NTuple<Descriptor> highestPCLoc =
+      NTuple<Descriptor> highestPCLocDescTuple =
           mapHighestOverriddenMethodDescToPCLocTuple.get(highestMethodDesc);
 
-      NTuple<Descriptor> highestRETURNLoc =
+      NTuple<Descriptor> highestRETURNLocDescTuple =
           mapHighestOverriddenMethodDescToReturnLocTuple.get(highestMethodDesc);
 
-      System.out.println("---highestMethodDesc=" + highestMethodDesc);
+      System.out.println("\n$$$$$$$$$$$$$$$$updateFlowGraphPCReturnLocInheritance="
+          + highestMethodDesc);
+      System.out.println("-----highestPCLoc=" + highestPCLocDescTuple);
+      System.out.println("-----highestRETURNLoc=" + highestRETURNLocDescTuple);
 
       for (Iterator iterator2 = methodDescSet.iterator(); iterator2.hasNext();) {
         MethodDescriptor md = (MethodDescriptor) iterator2.next();
+        System.out.println("\n --------MD=" + md);
         FlowGraph flowGraph = getFlowGraph(md);
 
         MethodSummary summary = getMethodSummary(md);
         CompositeLocation curPCLoc = summary.getPCLoc();
-
-        // update PCLOC
-        if (highestPCLoc != null) {
-          // handle the case that PCLOC is started with 'this'...
-          NTuple<Descriptor> newPCLoc = new NTuple<Descriptor>();
-          if (highestPCLoc.size() == 1) {
-            newPCLoc.add(highestPCLoc.get(0));
-          } else {
-            newPCLoc.add(md.getThis());
-            newPCLoc.add(highestPCLoc.get(1));
+        NTuple<Descriptor> curPCDescTuple = translateToDescTuple(curPCLoc.getTuple());
+        System.out.println("md=" + md + "  curPCLoc=" + curPCLoc);
+        System.out.println("highestPCLoc=" + highestPCLocDescTuple);
+
+        if (highestPCLocDescTuple == null) {
+          // this case: PCLOC is top
+          System.out.println("###SET PCLOC AS TOP");
+          if (curPCDescTuple != null && !curPCLoc.get(0).isTop()) {
+            FlowNode pcFlowNode = flowGraph.getFlowNode(curPCDescTuple);
+            flowGraph.removeNode(pcFlowNode);
           }
-
-          FlowNode pcFlowNode = flowGraph.getFlowNode(translateToDescTuple(curPCLoc.getTuple()));
-          pcFlowNode.setBaseTuple(newPCLoc);
-
-          CompositeLocation newPCLocCompLoc =
-              new CompositeLocation(translateToLocTuple(md, newPCLoc));
-          summary.setPCLoc(newPCLocCompLoc);
+          summary.setPCLoc(new CompositeLocation(new Location(md, Location.TOP)));
         } else {
-          // need to remove PCLOC if the overridden method defines it
-          if (curPCLoc != null && !curPCLoc.get(0).isTop()) {
-            System.out.println("md=" + md + "    curPCLoc=" + curPCLoc);
-            FlowNode pcFlowNode = flowGraph.getFlowNode(translateToDescTuple(curPCLoc.getTuple()));
-            System.out.println("#######REMOVE PCLOCNODE=" + pcFlowNode);
-            flowGraph.removeNode(pcFlowNode);
+          NTuple<Descriptor> newPCDescTuple = new NTuple<Descriptor>();
+          if (highestPCLocDescTuple.size() == 1) {
+            newPCDescTuple.add(highestPCLocDescTuple.get(0));
+          } else {
+            newPCDescTuple.add(md.getThis());
+            newPCDescTuple.add(highestPCLocDescTuple.get(1));
+          }
+          if (!curPCDescTuple.equals(newPCDescTuple)) {
+            FlowNode pcFlowNode = flowGraph.getFlowNode(curPCDescTuple);
+            flowGraph.updateTuple(pcFlowNode, newPCDescTuple);
+            // flowGraph.removeNode(pcFlowNode);
+            Set<NTuple<Descriptor>> descSetLowerThanPCLoc =
+                mapHighestOverriddenMethodDescToSetLowerThanPCLoc.get(highestMethodDesc);
+            for (Iterator iterator3 = descSetLowerThanPCLoc.iterator(); iterator3.hasNext();) {
+              NTuple<Descriptor> lowerNTuple = (NTuple<Descriptor>) iterator3.next();
+              flowGraph.addValueFlowEdge(newPCDescTuple, lowerNTuple);
+            }
+            CompositeLocation newPCCompLoc =
+                new CompositeLocation(translateToLocTuple(md, newPCDescTuple));
+            summary.setPCLoc(newPCCompLoc);
           }
-        }
 
-        // need to update RETURNLOC
-        if (highestRETURNLoc != null) {
+        }
 
+        // update return loc
+        if (highestRETURNLocDescTuple != null) {
           CompositeLocation curRETURNLoc = summary.getRETURNLoc();
-          System.out.println("curRETURNLoc=" + curRETURNLoc);
+          NTuple<Descriptor> curReturnDescTuple = translateToDescTuple(curRETURNLoc.getTuple());
 
-          // handle the case that RETURNLOC is started with 'this'...
-          NTuple<Descriptor> newRETURNLoc = new NTuple<Descriptor>();
-          if (highestRETURNLoc.size() == 1) {
-            newRETURNLoc.add(highestRETURNLoc.get(0));
-          } else {
-            newRETURNLoc.add(md.getThis());
-            newRETURNLoc.add(highestRETURNLoc.get(1));
-          }
+          if (!curReturnDescTuple.equals(highestRETURNLocDescTuple)) {
+            // handle the case that RETURNLOC is started with 'this'...
+            NTuple<Descriptor> newRETURNLocDescTuple = new NTuple<Descriptor>();
+            if (highestRETURNLocDescTuple.size() == 1) {
+              newRETURNLocDescTuple.add(highestRETURNLocDescTuple.get(0));
+            } else {
+              newRETURNLocDescTuple.add(md.getThis());
+              newRETURNLocDescTuple.add(highestRETURNLocDescTuple.get(1));
+            }
 
-          FlowNode returnFlowNode =
-              flowGraph.getFlowNode(translateToDescTuple(curRETURNLoc.getTuple()));
-          returnFlowNode.setBaseTuple(newRETURNLoc);
+            FlowNode returnFlowNode = flowGraph.getFlowNode(curReturnDescTuple);
+            flowGraph.updateTuple(returnFlowNode, newRETURNLocDescTuple);
 
-          CompositeLocation newRETURNLocCompLoc =
-              new CompositeLocation(translateToLocTuple(md, newRETURNLoc));
-          summary.setPCLoc(newRETURNLocCompLoc);
-          System.out.println("md=" + md + "###newRETURNLocCompLoc=" + newRETURNLocCompLoc);
+            Set<NTuple<Descriptor>> descSetHigherThanRETURNLoc =
+                mapHighestOverriddenMethodDescToSetHigherThanRETURNLoc.get(highestMethodDesc);
+            for (Iterator iterator3 = descSetHigherThanRETURNLoc.iterator(); iterator3.hasNext();) {
+              NTuple<Descriptor> higherNTuple = (NTuple<Descriptor>) iterator3.next();
+              flowGraph.addValueFlowEdge(higherNTuple, newRETURNLocDescTuple);
+            }
 
+            CompositeLocation newRETURNLocCompLoc =
+                new CompositeLocation(translateToLocTuple(md, newRETURNLocDescTuple));
+            summary.setRETURNLoc(newRETURNLocCompLoc);
+          }
         }
-
       }
     }
   }
@@ -455,6 +473,10 @@ public class LocationInference {
   private void calculateHighestPCLocInheritance() {
 
     Set<MethodDescriptor> keySet = mapHighestOverriddenMethodDescToMethodDescSet.keySet();
+
+    Map<MethodDescriptor, Integer> mapMethodDescToParamCount =
+        new HashMap<MethodDescriptor, Integer>();
+
     next: for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
       MethodDescriptor highestMethodDesc = (MethodDescriptor) iterator.next();
 
@@ -465,6 +487,12 @@ public class LocationInference {
         Set<MethodDescriptor> methodDescSet =
             mapHighestOverriddenMethodDescToMethodDescSet.get(highestMethodDesc);
 
+        if (methodDescSet.size() > 1) {
+          System.out.println("---method desc set=" + methodDescSet + "  from=" + highestMethodDesc);
+        } else {
+          continue next;
+        }
+
         for (Iterator iterator2 = methodDescSet.iterator(); iterator2.hasNext();) {
           MethodDescriptor md = (MethodDescriptor) iterator2.next();
 
@@ -476,66 +504,97 @@ public class LocationInference {
           System.out.println("###md=" + md + "   paramNodeSet=" + paramNodeSet);
 
           CompositeLocation pcLOC = getMethodSummary(md).getPCLoc();
+          System.out.println("---pcLOC=" + pcLOC);
+
+          if (md.equals(highestMethodDesc)) {
+            mapHighestOverriddenMethodDescToPCLocTuple.put(highestMethodDesc,
+                translateToDescTuple(pcLOC.getTuple()));
+          }
 
           if (!pcLOC.get(0).isTop()) {
-            if (pcLOC.getSize() == 1) {
-              // return location is not started with 'this'
-              // check whether the return location is lower than all parameters.
-
-              FlowNode pcFlowNode = flowGraph.getFlowNode(translateToDescTuple(pcLOC.getTuple()));
-
-              int count = 0;
-              for (Iterator iterator3 = paramNodeSet.iterator(); iterator3.hasNext();) {
-                FlowNode paramNode = (FlowNode) iterator3.next();
-                if (flowGraph.getReachableSetFrom(pcFlowNode.getCurrentDescTuple().subList(0, 1))
-                    .contains(paramNode)) {
-                  count++;
-                  System.out.println("-------" + pcFlowNode + " -> " + paramNode);
-                }
-              }
 
-              int offset = 0;
-              if (!md.isStatic()) {
-                offset = 1;
-              }
+            FlowNode pcFlowNode = flowGraph.getFlowNode(translateToDescTuple(pcLOC.getTuple()));
 
-              NTuple<Descriptor> rTuple = new NTuple<Descriptor>();
-              rTuple.add(pcLOC.get(0).getLocDescriptor());
-              if (count == (md.numParameters() + offset)) {
-                // means return loc is lower than a composite location starting with 'this'
-                mapHighestOverriddenMethodDescToPCLocTuple.put(highestMethodDesc, rTuple);
-              } else {
-                if (tempTuple == null) {
-                  tempTuple = rTuple;
-                }
-              }
-            } else {
-              // if the current overridden method has a composite pc loc(size>1)
-              // and it has not yet finalized the pc location,
-              // the highest overridden method would have the composite pc location starting with
-              // 'this'
-              NTuple<Descriptor> rTuple = new NTuple<Descriptor>();
-              for (int i = 0; i < pcLOC.getSize(); i++) {
-                rTuple.add(pcLOC.get(i).getLocDescriptor());
+            int count = 0;
+            for (Iterator iterator3 = paramNodeSet.iterator(); iterator3.hasNext();) {
+              FlowNode paramNode = (FlowNode) iterator3.next();
+              if (flowGraph.getReachableSetFrom(pcFlowNode.getCurrentDescTuple().subList(0, 1))
+                  .contains(paramNode)) {
+                count++;
               }
-              tempTuple = rTuple;
             }
+            mapMethodDescToParamCount.put(md, count);
+
           } else {
+
+            // the PC location is top
+            // if one of pcloc among the method inheritance chain has the TOP,
+            // all methods in the same chain should have the TOP.
             mapHighestOverriddenMethodDescToPCLocTuple.remove(highestMethodDesc);
-            System.out.println("highest=" + highestMethodDesc + "  HIGHEST PCLOC="
-                + mapHighestOverriddenMethodDescToPCLocTuple.get(highestMethodDesc));
+            // System.out.println("highest=" + highestMethodDesc + "  HIGHEST PCLOC="
+            // + mapHighestOverriddenMethodDescToPCLocTuple.get(highestMethodDesc));
+
+            Set<NTuple<Descriptor>> descTupleSetLowerThanPC = new HashSet<NTuple<Descriptor>>();
+            for (Iterator iterator3 = paramNodeSet.iterator(); iterator3.hasNext();) {
+              FlowNode flowNode = (FlowNode) iterator3.next();
+              descTupleSetLowerThanPC.add(flowNode.getCurrentDescTuple());
+            }
+            mapHighestOverriddenMethodDescToSetLowerThanPCLoc.put(highestMethodDesc,
+                descTupleSetLowerThanPC);
+
             continue next;
           }
         }
 
-      }
+        // identify which method in the inheritance chain has the highest PCLOC
+        // basically, finds a method that has the highest count or TOP location
+        int highestCount = -1;
+        MethodDescriptor methodDescHighestCount = null;
+        for (Iterator iterator2 = methodDescSet.iterator(); iterator2.hasNext();) {
+          MethodDescriptor methodDesc = (MethodDescriptor) iterator2.next();
+          if (mapMethodDescToParamCount.containsKey(methodDesc)) {
+            int curCount = mapMethodDescToParamCount.get(methodDesc).intValue();
+            if (highestCount < curCount) {
+              highestCount = curCount;
+              methodDescHighestCount = methodDesc;
+            }
+          }
+        }
+
+        if (methodDescHighestCount != null) {
+          FlowGraph flowGraph = getFlowGraph(methodDescHighestCount);
+          CompositeLocation pcLOC = getMethodSummary(methodDescHighestCount).getPCLoc();
+          FlowNode pcFlowNode = flowGraph.getFlowNode(translateToDescTuple(pcLOC.getTuple()));
+          Set<FlowNode> reachableSet =
+              flowGraph.getReachableSetFrom(pcFlowNode.getCurrentDescTuple().subList(0, 1));
+
+          Set<FlowNode> reachableParamNodeSet = new HashSet<FlowNode>();
+          for (Iterator iterator3 = reachableSet.iterator(); iterator3.hasNext();) {
+            FlowNode flowNode = (FlowNode) iterator3.next();
+            if (flowGraph.isParameter(flowNode.getCurrentDescTuple())) {
+              reachableParamNodeSet.add(flowNode);
+            }
+
+          }
+
+          Set<NTuple<Descriptor>> descTupleSetLowerThanPC = new HashSet<NTuple<Descriptor>>();
+          for (Iterator iterator2 = reachableParamNodeSet.iterator(); iterator2.hasNext();) {
+            FlowNode flowNode = (FlowNode) iterator2.next();
+            descTupleSetLowerThanPC.add(flowNode.getCurrentDescTuple());
+          }
+
+          // mapHighestOverriddenMethodDescToPCLocTuple.remove(highestMethodDesc);
+          mapHighestOverriddenMethodDescToSetLowerThanPCLoc.put(highestMethodDesc,
+              descTupleSetLowerThanPC);
+        }
 
-      if (!mapHighestOverriddenMethodDescToPCLocTuple.containsKey(highestMethodDesc)
-          && tempTuple != null) {
-        mapHighestOverriddenMethodDescToPCLocTuple.put(highestMethodDesc, tempTuple);
       }
-      System.out.println("highest=" + highestMethodDesc + "  HIGHEST PCLOC="
-          + mapHighestOverriddenMethodDescToPCLocTuple.get(highestMethodDesc));
+
+      // System.out.println("####################################");
+      // System.out.println("  highest=" + highestMethodDesc + "  HIGHEST PCLOC="
+      // + mapHighestOverriddenMethodDescToPCLocTuple.get(highestMethodDesc));
+      // System.out.println("  setLowerThanPCLoc="
+      // + mapHighestOverriddenMethodDescToSetLowerThanPCLoc.get(highestMethodDesc));
     }
 
   }
@@ -543,76 +602,84 @@ public class LocationInference {
   private void calculateLowestReturnLocInheritance() {
 
     Set<MethodDescriptor> keySet = mapHighestOverriddenMethodDescToMethodDescSet.keySet();
-    for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
-      MethodDescriptor highestMethodDesc = (MethodDescriptor) iterator.next();
 
-      NTuple<Descriptor> tempTuple = null;
+    Map<MethodDescriptor, Integer> mapMethodDescToParamCount =
+        new HashMap<MethodDescriptor, Integer>();
 
-      if (getMethodSummary(highestMethodDesc).getRETURNLoc() != null) {
-        Set<MethodDescriptor> methodDescSet =
-            mapHighestOverriddenMethodDescToMethodDescSet.get(highestMethodDesc);
-        for (Iterator iterator2 = methodDescSet.iterator(); iterator2.hasNext();) {
-          MethodDescriptor md = (MethodDescriptor) iterator2.next();
+    next: for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
+      MethodDescriptor highestMethodDesc = (MethodDescriptor) iterator.next();
 
-          FlowGraph flowGraph = getFlowGraph(md);
-          Set<FlowNode> paramNodeSet = flowGraph.getParamFlowNodeSet();
-          System.out.println("###md=" + md + "   paramNodeSet=" + paramNodeSet);
+      Set<MethodDescriptor> methodDescSet =
+          mapHighestOverriddenMethodDescToMethodDescSet.get(highestMethodDesc);
 
-          CompositeLocation returnLoc = getMethodSummary(md).getRETURNLoc();
-          if (returnLoc.getSize() == 1) {
-            // return location is not started with 'this'
-            // check whether the return location is lower than all parameters.
+      if (methodDescSet.size() > 1 && getMethodSummary(highestMethodDesc).getRETURNLoc() != null) {
+      } else {
+        continue next;
+      }
 
-            FlowNode returnFlowNode =
-                flowGraph.getFlowNode(translateToDescTuple(returnLoc.getTuple()));
+      for (Iterator iterator2 = methodDescSet.iterator(); iterator2.hasNext();) {
+        MethodDescriptor md = (MethodDescriptor) iterator2.next();
 
-            int count = 0;
-            for (Iterator iterator3 = paramNodeSet.iterator(); iterator3.hasNext();) {
-              FlowNode paramNode = (FlowNode) iterator3.next();
-              if (flowGraph.getReachableSetFrom(paramNode.getCurrentDescTuple().subList(0, 1))
-                  .contains(returnFlowNode)) {
-                count++;
-                System.out.println("-------" + paramNode + " -> " + returnFlowNode);
-              }
-            }
+        FlowGraph flowGraph = getFlowGraph(md);
+        Set<FlowNode> paramNodeSet = flowGraph.getParamFlowNodeSet();
 
-            int offset = 0;
-            if (!md.isStatic()) {
-              offset = 1;
-            }
+        CompositeLocation returnLoc = getMethodSummary(md).getRETURNLoc();
 
-            NTuple<Descriptor> rTuple = new NTuple<Descriptor>();
-            rTuple.add(returnLoc.get(0).getLocDescriptor());
-            if (count == (md.numParameters() + offset)) {
-              // means return loc is lower than a composite location starting with 'this'
-              mapHighestOverriddenMethodDescToReturnLocTuple.put(highestMethodDesc, rTuple);
-            } else {
-              if (tempTuple == null) {
-                tempTuple = rTuple;
-              }
-            }
-          } else {
-            // if the current overridden method has a composite return loc(size>1)
-            // and it has not yet finalized the return location
-            // the highest overridden method has the composite return location starting with
-            // 'this'
-            NTuple<Descriptor> rTuple = new NTuple<Descriptor>();
-            for (int i = 0; i < returnLoc.getSize(); i++) {
-              rTuple.add(returnLoc.get(i).getLocDescriptor());
-            }
-            tempTuple = rTuple;
-          }
+        FlowNode returnFlowNode = flowGraph.getFlowNode(translateToDescTuple(returnLoc.getTuple()));
 
+        int count = 0;
+        for (Iterator iterator3 = paramNodeSet.iterator(); iterator3.hasNext();) {
+          FlowNode paramNode = (FlowNode) iterator3.next();
+          if (flowGraph.getReachableSetFrom(paramNode.getCurrentDescTuple().subList(0, 1))
+              .contains(returnFlowNode)) {
+            count++;
+          }
         }
+        mapMethodDescToParamCount.put(md, count);
+        // System.out.println("###returnLoc=" + returnLoc + "    count higher=" + count);
+      }
 
+      // identify which method in the inheritance chain has the highest PCLOC
+      // basically, finds a method that has the highest count or TOP location
+      int highestCount = -1;
+      MethodDescriptor methodDescHighestCount = null;
+      for (Iterator iterator2 = methodDescSet.iterator(); iterator2.hasNext();) {
+        MethodDescriptor methodDesc = (MethodDescriptor) iterator2.next();
+        int curCount = mapMethodDescToParamCount.get(methodDesc).intValue();
+        if (highestCount < curCount) {
+          highestCount = curCount;
+          methodDescHighestCount = methodDesc;
+        }
       }
 
-      if (!mapHighestOverriddenMethodDescToReturnLocTuple.containsKey(highestMethodDesc)
-          && tempTuple != null) {
-        mapHighestOverriddenMethodDescToReturnLocTuple.put(highestMethodDesc, tempTuple);
+      if (methodDescHighestCount != null) {
+        FlowGraph flowGraph = getFlowGraph(methodDescHighestCount);
+        CompositeLocation returnLOC = getMethodSummary(methodDescHighestCount).getRETURNLoc();
+        NTuple<Descriptor> returnLocTuple = translateToDescTuple(returnLOC.getTuple());
+        FlowNode returnFlowNode = flowGraph.getFlowNode(returnLocTuple);
+
+        Set<FlowNode> curMethodParamNodeSet = flowGraph.getParamFlowNodeSet();
+        Set<NTuple<Descriptor>> descTupleSetHigherThanPC = new HashSet<NTuple<Descriptor>>();
+        for (Iterator iterator3 = curMethodParamNodeSet.iterator(); iterator3.hasNext();) {
+          FlowNode paramNode = (FlowNode) iterator3.next();
+          if (flowGraph.getReachableSetFrom(paramNode.getCurrentDescTuple().subList(0, 1))
+              .contains(returnFlowNode)) {
+            descTupleSetHigherThanPC.add(paramNode.getCurrentDescTuple());
+          }
+        }
+
+        mapHighestOverriddenMethodDescToReturnLocTuple.put(highestMethodDesc, returnLocTuple);
+        mapHighestOverriddenMethodDescToSetHigherThanRETURNLoc.put(highestMethodDesc,
+            descTupleSetHigherThanPC);
+
       }
-      System.out.println("highest=" + highestMethodDesc + "  rTuple="
-          + mapHighestOverriddenMethodDescToReturnLocTuple.get(highestMethodDesc));
+
+      // System.out.println("####################################");
+      // System.out.println("  highest=" + highestMethodDesc + "  LOWEST RETURNLOC="
+      // + mapHighestOverriddenMethodDescToReturnLocTuple.get(highestMethodDesc));
+      // System.out.println("  setHigherThanReturnLoc="
+      // + mapHighestOverriddenMethodDescToSetHigherThanRETURNLoc.get(highestMethodDesc));
+
     }
 
   }
@@ -645,10 +712,6 @@ public class LocationInference {
 
   }
 
-  private void addTupleLowerThanPCLoc(NTuple<Descriptor> tuple) {
-
-  }
-
   private MethodDescriptor getHighestOverriddenMethod(ClassDescriptor curClassDesc,
       MethodDescriptor curMethodDesc) {
 
@@ -699,6 +762,12 @@ public class LocationInference {
       HierarchyGraph parentGraph = getHierarchyGraph(parentClassDescriptor);
       HierarchyGraph childGraph = getHierarchyGraph(childClassDescriptor);
 
+      Set<HNode> parentNodeSet = parentGraph.getNodeSet();
+      for (Iterator iterator2 = parentNodeSet.iterator(); iterator2.hasNext();) {
+        HNode hNode = (HNode) iterator2.next();
+        childGraph.addNode(hNode);
+      }
+
       // copies extra information from the parent hierarchy graph
       Map<HNode, Set<HNode>> parentMergeNodeMap = parentGraph.getMapHNodetoMergeSet();
       Map<HNode, Set<HNode>> childMergeNodeMap = childGraph.getMapHNodetoMergeSet();
@@ -713,7 +782,6 @@ public class LocationInference {
       }
 
       // copies nodes/edges from the parent class...
-      Set<HNode> parentNodeSet = parentGraph.getNodeSet();
       for (Iterator iterator2 = parentNodeSet.iterator(); iterator2.hasNext();) {
         HNode parentHNode = (HNode) iterator2.next();
 
@@ -745,6 +813,12 @@ public class LocationInference {
           HierarchyGraph parentMethodGraph = getHierarchyGraph(parentMethodDesc);
           HierarchyGraph childMethodGraph = getHierarchyGraph(childMethodDescriptor);
 
+          Set<HNode> parentMethodNodeSet = parentMethodGraph.getNodeSet();
+          for (Iterator iterator2 = parentMethodNodeSet.iterator(); iterator2.hasNext();) {
+            HNode hNode = (HNode) iterator2.next();
+            childMethodGraph.addNode(hNode);
+          }
+
           // copies extra information from the parent hierarchy graph
           Map<HNode, Set<HNode>> parentMethodMergeNodeMap =
               parentMethodGraph.getMapHNodetoMergeSet();
@@ -833,6 +907,14 @@ public class LocationInference {
 
   }
 
+  private void addSuperClasses(ClassDescriptor cd) {
+    ClassDescriptor parentClassDesc = cd.getSuperDesc();
+    if (parentClassDesc != null) {
+      toanalyze_classDescSet.add(parentClassDesc);
+      addSuperClasses(parentClassDesc);
+    }
+  }
+
   private void updateFlowGraph() {
 
     LinkedList<MethodDescriptor> methodDescList =
@@ -854,7 +936,9 @@ public class LocationInference {
         for (int i = 0; i < locTuple.size(); i++) {
           Location loc = locTuple.get(i);
           if (loc.getDescriptor() instanceof ClassDescriptor) {
-            toanalyze_classDescSet.add((ClassDescriptor) loc.getDescriptor());
+            ClassDescriptor classDesc = (ClassDescriptor) loc.getDescriptor();
+            toanalyze_classDescSet.add(classDesc);
+            addSuperClasses(classDesc);
           } else if (loc.getDescriptor() instanceof MethodDescriptor) {
             toanalyze_classDescSet.add(((MethodDescriptor) loc.getDescriptor()).getClassDesc());
           }
@@ -1046,46 +1130,6 @@ public class LocationInference {
 
   }
 
-  private CompositeLocation translateArgCompLocToParamCompLoc(MethodInvokeNode min,
-      CompositeLocation argCompLoc) {
-
-    System.out.println("--------translateArgCompLocToParamCompLoc argCompLoc=" + argCompLoc);
-    MethodDescriptor mdCallee = min.getMethod();
-    FlowGraph calleeFlowGraph = getFlowGraph(mdCallee);
-
-    NTuple<Location> argLocTuple = argCompLoc.getTuple();
-    Location argLocalLoc = argLocTuple.get(0);
-
-    Map<Integer, NTuple<Descriptor>> mapIdxToArgTuple = mapMethodInvokeNodeToArgIdxMap.get(min);
-    Set<Integer> idxSet = mapIdxToArgTuple.keySet();
-    for (Iterator iterator2 = idxSet.iterator(); iterator2.hasNext();) {
-      Integer idx = (Integer) iterator2.next();
-
-      if (idx == 0 && !min.getMethod().isStatic()) {
-        continue;
-      }
-
-      NTuple<Descriptor> argTuple = mapIdxToArgTuple.get(idx);
-      if (argTuple.size() > 0 && argTuple.get(0).equals(argLocalLoc.getLocDescriptor())) {
-        // it matches with the current argument composite location
-        // so what is the corresponding parameter local descriptor?
-        FlowNode paramNode = calleeFlowGraph.getParamFlowNode(idx);
-        // System.out.println("----------found paramNode=" + paramNode);
-        NTuple<Descriptor> paramDescTuple = paramNode.getCurrentDescTuple();
-
-        NTuple<Location> newParamTupleFromArgTuple = translateToLocTuple(mdCallee, paramDescTuple);
-        for (int i = 1; i < argLocTuple.size(); i++) {
-          newParamTupleFromArgTuple.add(argLocTuple.get(i));
-        }
-
-        // System.out.println("-----------newParamTuple=" + newParamTupleFromArgTuple);
-        return new CompositeLocation(newParamTupleFromArgTuple);
-
-      }
-    }
-    return null;
-  }
-
   private void addAddtionalOrderingConstraints(MethodDescriptor mdCaller) {
 
     // First, assign a composite location to a node in the flow graph
@@ -2148,20 +2192,6 @@ public class LocationInference {
 
   }
 
-  private boolean containsClassDesc(ClassDescriptor cd, NTuple<Location> prefixLocTuple) {
-    for (int i = 0; i < prefixLocTuple.size(); i++) {
-      Location loc = prefixLocTuple.get(i);
-      Descriptor locDesc = loc.getLocDescriptor();
-      if (locDesc != null) {
-        ClassDescriptor type = getClassTypeDescriptor(locDesc);
-        if (type != null && type.equals(cd)) {
-          return true;
-        }
-      }
-    }
-    return false;
-  }
-
   private GlobalFlowGraph constructSubGlobalFlowGraph(FlowGraph flowGraph) {
 
     MethodDescriptor md = flowGraph.getMethodDescriptor();
@@ -2438,6 +2468,9 @@ public class LocationInference {
       System.out.println("\nSSJAVA: generate method summary: " + md);
 
       FlowGraph flowGraph = getFlowGraph(md);
+      if (flowGraph == null) {
+        continue;
+      }
       MethodSummary methodSummary = getMethodSummary(md);
 
       HierarchyGraph scGraph = getSkeletonCombinationHierarchyGraph(md);
@@ -2553,31 +2586,6 @@ public class LocationInference {
     return false;
   }
 
-  private CompositeLocation translateCompositeLocation(CompositeLocation compLoc) {
-    CompositeLocation newCompLoc = new CompositeLocation();
-
-    // System.out.println("compLoc=" + compLoc);
-    for (int i = 0; i < compLoc.getSize(); i++) {
-      Location loc = compLoc.get(i);
-      Descriptor enclosingDescriptor = loc.getDescriptor();
-      Descriptor locDescriptor = loc.getLocDescriptor();
-
-      HNode hnode = getHierarchyGraph(enclosingDescriptor).getHNode(locDescriptor);
-      // System.out.println("-hnode=" + hnode + "    from=" + locDescriptor +
-      // " enclosingDescriptor="
-      // + enclosingDescriptor);
-      // System.out.println("-getLocationSummary(enclosingDescriptor)="
-      // + getLocationSummary(enclosingDescriptor));
-      String locName = getLocationSummary(enclosingDescriptor).getLocationName(hnode.getName());
-      // System.out.println("-locName=" + locName);
-      Location newLoc = new Location(enclosingDescriptor, locName);
-      newLoc.setLocDescriptor(locDescriptor);
-      newCompLoc.addLocation(newLoc);
-    }
-
-    return newCompLoc;
-  }
-
   private void debug_writeLattices() {
 
     Set<Descriptor> keySet = mapDescriptorToSimpleLattice.keySet();
@@ -2686,7 +2694,6 @@ public class LocationInference {
 
   public Set<ClassDescriptor> getDirectSubClasses(ClassDescriptor parent) {
 
-    System.out.println("$$$toanalyze_classDescSet=" + toanalyze_classDescSet);
     Set<ClassDescriptor> result = new HashSet<ClassDescriptor>();
 
     Set<ClassDescriptor> children = tu.getDirectSubClasses(parent);
@@ -2728,13 +2735,18 @@ public class LocationInference {
     }
 
     // traverse children
-    Set<ClassDescriptor> children = getDirectSubClasses(cd);
-    for (Iterator iterator = children.iterator(); iterator.hasNext();) {
-      ClassDescriptor classDescriptor = (ClassDescriptor) iterator.next();
-      if (toanalyze_classDescSet.contains(classDescriptor)) {
-        DFSBuildLatticeInheritanceTree(classDescriptor);
+    Set<ClassDescriptor> children = tu.getDirectSubClasses(cd);
+    if (children != null) {
+      for (Iterator iterator = children.iterator(); iterator.hasNext();) {
+        ClassDescriptor classDescriptor = (ClassDescriptor) iterator.next();
+        if (toanalyze_classDescSet.contains(classDescriptor)) {
+          DFSBuildLatticeInheritanceTree(classDescriptor);
+        } else {
+          if (classDescriptor.isAbstract()) {
+            DFSBuildLatticeInheritanceTree(classDescriptor);
+          }
+        }
       }
-
     }
 
   }
@@ -2787,13 +2799,124 @@ public class LocationInference {
       HierarchyGraph skeletonGraph = simpleGraph.generateSkeletonGraph();
       skeletonGraph.setMapDescToHNode(simpleGraph.getMapDescToHNode());
       skeletonGraph.setMapHNodeToDescSet(simpleGraph.getMapHNodeToDescSet());
-      skeletonGraph.simplifyHierarchyGraph();
-      // skeletonGraph.combineRedundantNodes(false);
-      // skeletonGraph.removeRedundantEdges();
+      skeletonGraph.simplifyHierarchyGraph(this);
       mapDescriptorToSkeletonHierarchyGraph.put(desc, skeletonGraph);
     }
   }
 
+  private void recurUpAccumulateInheritanceDesc(Descriptor curDesc, Set<Descriptor> set) {
+
+    if (curDesc instanceof ClassDescriptor) {
+      ClassDescriptor cd = (ClassDescriptor) curDesc;
+      ClassDescriptor parentClassDesc = cd.getSuperDesc();
+      if (parentClassDesc != null && !parentClassDesc.equals(rootClassDescriptor)) {
+        set.add(parentClassDesc);
+        recurUpAccumulateInheritanceDesc(parentClassDesc, set);
+      }
+    } else {
+      MethodDescriptor md = (MethodDescriptor) curDesc;
+      ClassDescriptor cd = md.getClassDesc();
+
+      // traverse up
+      ClassDescriptor parentClassDesc = cd.getSuperDesc();
+      if (parentClassDesc != null && !parentClassDesc.equals(rootClassDescriptor)) {
+
+        Set<MethodDescriptor> methodDescSet =
+            parentClassDesc.getMethodTable().getSet(md.getSymbol());
+        for (Iterator iterator = methodDescSet.iterator(); iterator.hasNext();) {
+          MethodDescriptor parentMethodDesc = (MethodDescriptor) iterator.next();
+          if (parentMethodDesc.matches(md)) {
+            set.add(parentMethodDesc);
+            recurUpAccumulateInheritanceDesc(parentMethodDesc, set);
+          }
+        }
+      }
+
+    }
+
+  }
+
+  private void recurDownAccumulateInheritanceDesc(Descriptor curDesc, Set<Descriptor> set) {
+
+    if (curDesc instanceof ClassDescriptor) {
+      ClassDescriptor cd = (ClassDescriptor) curDesc;
+      ClassDescriptor parentClassDesc = cd.getSuperDesc();
+      Set<ClassDescriptor> directSubClasses = tu.getDirectSubClasses(cd);
+      for (Iterator iterator = directSubClasses.iterator(); iterator.hasNext();) {
+        ClassDescriptor child = (ClassDescriptor) iterator.next();
+        recurDownAccumulateInheritanceDesc(child, set);
+      }
+    } else {
+      MethodDescriptor md = (MethodDescriptor) curDesc;
+      ClassDescriptor cd = md.getClassDesc();
+
+      // traverse down
+      Set<ClassDescriptor> directSubClasses = tu.getDirectSubClasses(cd);
+      for (Iterator iterator = directSubClasses.iterator(); iterator.hasNext();) {
+        ClassDescriptor child = (ClassDescriptor) iterator.next();
+
+        Set<MethodDescriptor> methodDescSet = child.getMethodTable().getSet(md.getSymbol());
+        for (Iterator iterator2 = methodDescSet.iterator(); iterator2.hasNext();) {
+          MethodDescriptor childMethodDesc = (MethodDescriptor) iterator2.next();
+          if (childMethodDesc.matches(md)) {
+            set.add(childMethodDesc);
+            recurDownAccumulateInheritanceDesc(childMethodDesc, set);
+          }
+        }
+      }
+
+    }
+
+  }
+
+  private void accumulateInheritanceDesc(Descriptor curDesc, Set<Descriptor> set) {
+
+    recurUpAccumulateInheritanceDesc(curDesc, set);
+    recurDownAccumulateInheritanceDesc(curDesc, set);
+
+  }
+
+  public boolean isValidMergeInheritanceCheck(Descriptor desc, Set<HNode> mergeSet) {
+
+    // set up inheritance chain set...
+    Set<Descriptor> inheritanceDescSet = new HashSet<Descriptor>();
+    recurUpAccumulateInheritanceDesc(desc, inheritanceDescSet);
+
+    nextgraph: for (Iterator iterator = inheritanceDescSet.iterator(); iterator.hasNext();) {
+      Descriptor inheritDesc = (Descriptor) iterator.next();
+
+      if (!desc.equals(inheritDesc)) {
+        HierarchyGraph graph = getSkeletonCombinationHierarchyGraph(inheritDesc);
+
+        // first check whether this graph includes all elements of the merge set
+        for (Iterator iterator2 = mergeSet.iterator(); iterator2.hasNext();) {
+          HNode node = (HNode) iterator2.next();
+          if (!graph.contains(node)) {
+            continue nextgraph;
+          }
+        }
+
+        HNode firstNode = mergeSet.iterator().next();
+
+        Set<HNode> incomingNode = graph.getIncomingNodeSet(firstNode);
+        Set<HNode> outgoingNode = graph.getOutgoingNodeSet(firstNode);
+
+        for (Iterator iterator2 = mergeSet.iterator(); iterator2.hasNext();) {
+          HNode node = (HNode) iterator2.next();
+
+          if (!graph.getIncomingNodeSet(node).equals(incomingNode)
+              || !graph.getOutgoingNodeSet(node).equals(outgoingNode)) {
+            return false;
+          }
+
+        }
+      }
+
+    }
+
+    return true;
+  }
+
   private void debug_writeHierarchyDotFiles() {
 
     Set<Descriptor> keySet = mapDescriptorToHierarchyGraph.keySet();
@@ -3308,6 +3431,9 @@ public class LocationInference {
 
     Map<String, Set<String>> map = lattice.getTable();
     Set<String> keySet = map.keySet();
+
+    System.out.println("@generateLatticeDefinition=" + desc + "      map=" + map);
+
     boolean first = true;
     for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
       String key = (String) iterator.next();
@@ -3454,6 +3580,7 @@ public class LocationInference {
         }
 
         SSJavaLattice<String> methodLattice = md2lattice.get(md);
+        System.out.println("md=" + md + " methodLattice=" + methodLattice);
         if (methodLattice != null) {
 
           int methodDefLine = md.getLineNum();
@@ -3466,7 +3593,7 @@ public class LocationInference {
 
           Map<Descriptor, CompositeLocation> mapVarDescToInferLoc =
               methodSummary.getMapVarDescToInferCompositeLocation();
-          System.out.println("-----md=" + md);
+          System.out.println("-----md=" + md + " methodDefLine=" + methodDefLine);
           System.out.println("-----mapVarDescToInferLoc=" + mapVarDescToInferLoc);
 
           Set<Descriptor> localVarDescSet = mapVarDescToInferLoc.keySet();
@@ -3698,7 +3825,9 @@ public class LocationInference {
 
   private void calculateExtraLocations() {
 
-    LinkedList<MethodDescriptor> methodDescList = ssjava.getSortedDescriptors();
+    // LinkedList<MethodDescriptor> methodDescList = ssjava.getSortedDescriptors();
+    LinkedList<MethodDescriptor> methodDescList =
+        (LinkedList<MethodDescriptor>) toanalyze_methodDescList.clone();
     for (Iterator iterator = methodDescList.iterator(); iterator.hasNext();) {
       MethodDescriptor md = (MethodDescriptor) iterator.next();
       if (!ssjava.getMethodContainingSSJavaLoop().equals(md)) {
@@ -3887,7 +4016,6 @@ public class LocationInference {
         fg.getFlowNode(translateToDescTuple(pcLocTuple)).setSkeleton(true);
 
         if (pcLocTuple.get(0).getLocDescriptor().equals(md.getThis())) {
-          System.out.println("#########################################");
           for (Iterator iterator = flowNodeLowerthanPCLocSet.iterator(); iterator.hasNext();) {
             FlowNode lowerNode = (FlowNode) iterator.next();
             if (lowerNode.getDescTuple().size() == 1 && lowerNode.getCompositeLocation() == null) {
@@ -4826,17 +4954,25 @@ public class LocationInference {
 
     // hack... it seems that there is a problem with topological sorting.
     // so String.toString(Object o) is appeared too higher in the call chain.
-    MethodDescriptor mdToString = null;
+    MethodDescriptor mdToString1 = null;
+    MethodDescriptor mdToString2 = null;
     for (Iterator iterator = toanalyze_methodDescList.iterator(); iterator.hasNext();) {
       MethodDescriptor md = (MethodDescriptor) iterator.next();
       if (md.toString().equals("public static String String.valueOf(Object o)")) {
-        mdToString = md;
-        break;
+        mdToString1 = md;
+      }
+      if (md.toString().equals("public String Object.toString()")) {
+        mdToString2 = md;
       }
     }
-    if (mdToString != null) {
-      toanalyze_methodDescList.remove(mdToString);
-      toanalyze_methodDescList.addLast(mdToString);
+
+    if (mdToString1 != null) {
+      toanalyze_methodDescList.remove(mdToString1);
+      toanalyze_methodDescList.addLast(mdToString1);
+    }
+    if (mdToString2 != null) {
+      toanalyze_methodDescList.remove(mdToString2);
+      toanalyze_methodDescList.addLast(mdToString2);
     }
 
     LinkedList<MethodDescriptor> methodDescList =
@@ -5452,7 +5588,7 @@ public class LocationInference {
       break;
 
     case Kind.CreateObjectNode:
-      analyzeCreateObjectNode(md, nametable, (CreateObjectNode) en);
+      analyzeCreateObjectNode(md, nametable, (CreateObjectNode) en, nodeSet, implicitFlowTupleSet);
       break;
 
     case Kind.ArrayAccessNode:
@@ -6036,9 +6172,20 @@ public class LocationInference {
   }
 
   private void analyzeCreateObjectNode(MethodDescriptor md, SymbolTable nametable,
-      CreateObjectNode en) {
-    // TODO Auto-generated method stub
+      CreateObjectNode en, NodeTupleSet nodeSet, NodeTupleSet implicitFlowTupleSet) {
+    System.out.println("#analyzeCreateObjectNode=" + en.printNode(0));
+    int numArgs = en.numArgs();
+    NodeTupleSet argSet = new NodeTupleSet();
 
+    for (int i = 0; i < numArgs; i++) {
+      analyzeFlowExpressionNode(md, nametable, en.getArg(i), argSet, null, implicitFlowTupleSet,
+          false);
+    }
+
+    System.out.println("###argSet=" + argSet);
+    nodeSet.addTupleSet(argSet);
+
+    // TODO Auto-generated method stub
   }
 
   private void analyzeFlowOpNode(MethodDescriptor md, SymbolTable nametable, OpNode on,