the last piece for the inheritance checking...
[IRC.git] / Robust / src / Analysis / SSJava / LocationInference.java
index ec8c60492b129128578221f5240e1b60a80e2a93..3224bbe4f64348e2b226687c9abb3a8836a942c7 100644 (file)
@@ -27,6 +27,7 @@ import IR.Operation;
 import IR.State;
 import IR.SymbolTable;
 import IR.TypeDescriptor;
+import IR.TypeUtil;
 import IR.VarDescriptor;
 import IR.Tree.ArrayAccessNode;
 import IR.Tree.AssignmentNode;
@@ -55,14 +56,20 @@ import Util.Pair;
 
 public class LocationInference {
 
+  static int COUNT = 0;
+
   State state;
   SSJavaAnalysis ssjava;
+  TypeUtil tu;
 
   List<ClassDescriptor> temp_toanalyzeList;
   List<MethodDescriptor> temp_toanalyzeMethodList;
   Map<MethodDescriptor, FlowGraph> mapMethodDescriptorToFlowGraph;
 
   LinkedList<MethodDescriptor> toanalyze_methodDescList;
+  Set<ClassDescriptor> toanalyze_classDescSet;
+
+  // InheritanceTree<ClassDescriptor> inheritanceTree;
 
   // map a method descriptor to its set of parameter descriptors
   Map<MethodDescriptor, Set<Descriptor>> mapMethodDescriptorToParamDescSet;
@@ -124,6 +131,16 @@ public class LocationInference {
 
   private Map<MethodDescriptor, Boolean> mapMethodDescriptorToCompositeReturnCase;
 
+  private Map<MethodDescriptor, MethodDescriptor> mapMethodDescToHighestOverriddenMethodDesc;
+
+  private Map<MethodDescriptor, Set<MethodDescriptor>> mapHighestOverriddenMethodDescToMethodDescSet;
+
+  private Map<MethodDescriptor, NTuple<Descriptor>> mapHighestOverriddenMethodDescToReturnLocTuple;
+
+  private Map<MethodDescriptor, NTuple<Descriptor>> mapHighestOverriddenMethodDescToPCLocTuple;
+
+  private Map<MethodDescriptor, Set<NTuple<Descriptor>>> mapHighestOverriddenMethodDescToSetLowerThanPCLoc;
+
   public static final String GLOBALLOC = "GLOBALLOC";
 
   public static final String INTERLOC = "INTERLOC";
@@ -158,9 +175,15 @@ public class LocationInference {
 
   private Stack<String> arrayAccessNodeStack;
 
-  public LocationInference(SSJavaAnalysis ssjava, State state) {
+  private ClassDescriptor rootClassDescriptor;
+
+  private BuildLattice buildLattice;
+
+  public LocationInference(SSJavaAnalysis ssjava, State state, TypeUtil tu) {
     this.ssjava = ssjava;
     this.state = state;
+    this.tu = tu;
+    this.toanalyze_classDescSet = new HashSet<ClassDescriptor>();
     this.temp_toanalyzeList = new ArrayList<ClassDescriptor>();
     this.temp_toanalyzeMethodList = new ArrayList<MethodDescriptor>();
     this.mapMethodDescriptorToFlowGraph = new HashMap<MethodDescriptor, FlowGraph>();
@@ -206,6 +229,22 @@ public class LocationInference {
 
     this.mapMethodDescriptorToCompositeReturnCase = new HashMap<MethodDescriptor, Boolean>();
 
+    mapMethodDescToHighestOverriddenMethodDesc = new HashMap<MethodDescriptor, MethodDescriptor>();
+
+    mapHighestOverriddenMethodDescToSetLowerThanPCLoc =
+        new HashMap<MethodDescriptor, Set<NTuple<Descriptor>>>();
+
+    mapHighestOverriddenMethodDescToMethodDescSet =
+        new HashMap<MethodDescriptor, Set<MethodDescriptor>>();
+
+    mapHighestOverriddenMethodDescToReturnLocTuple =
+        new HashMap<MethodDescriptor, NTuple<Descriptor>>();
+
+    mapHighestOverriddenMethodDescToPCLocTuple =
+        new HashMap<MethodDescriptor, NTuple<Descriptor>>();
+
+    this.buildLattice = new BuildLattice(this);
+
   }
 
   public void setupToAnalyze() {
@@ -265,13 +304,14 @@ public class LocationInference {
 
     _debug_writeFlowGraph();
 
-    // System.exit(0);
+    buildInheritanceTree();
+    calculateReturnPCLocInheritance();
 
     constructHierarchyGraph();
 
-    debug_writeHierarchyDotFiles();
+    addInheritanceConstraintsToHierarchyGraph();
 
-    // System.exit(0);
+    debug_writeHierarchyDotFiles();
 
     simplifyHierarchyGraph();
 
@@ -285,7 +325,8 @@ public class LocationInference {
 
     debug_writeSkeletonCombinationHierarchyDotFiles();
 
-    buildLattice();
+    buildLatticeInheritanceTree();
+    // buildLattice();
 
     debug_writeLattices();
 
@@ -295,10 +336,475 @@ public class LocationInference {
 
     generateAnnoatedCode();
 
+    for (Iterator iterator = cd2lattice.keySet().iterator(); iterator.hasNext();) {
+      ClassDescriptor cd = (ClassDescriptor) iterator.next();
+      SSJavaLattice<String> lattice = getLattice(cd);
+      HierarchyGraph hg = mapDescriptorToHierarchyGraph.get(cd);
+      // System.out.println("~~~\t" + cd + "\t" + lattice.getKeySet().size() + "\t"
+      // + hg.getNodeSet().size());
+    }
+
+    for (Iterator iterator = md2lattice.keySet().iterator(); iterator.hasNext();) {
+      MethodDescriptor md = (MethodDescriptor) iterator.next();
+      SSJavaLattice<String> locOrder = getLattice(md);
+      // writeLatticeDotFile(md.getClassDesc(), md, getMethodLattice(md));
+      HierarchyGraph hg = mapDescriptorToHierarchyGraph.get(md);
+      // System.out.println("~~~\t" + md.getClassDesc() + "_" + md + "\t"
+      // + locOrder.getKeySet().size() + "\t" + hg.getNodeSet().size());
+    }
+
     System.exit(0);
 
   }
 
+  private void calculateReturnPCLocInheritance() {
+    calculateHighestPCLocInheritance();
+    calculateLowestReturnLocInheritance();
+    updateFlowGraphPCReturnLocInheritance();
+  }
+
+  private void updateFlowGraphPCReturnLocInheritance() {
+    Set<MethodDescriptor> keySet = mapHighestOverriddenMethodDescToMethodDescSet.keySet();
+    for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
+      MethodDescriptor highestMethodDesc = (MethodDescriptor) iterator.next();
+
+      if (mapHighestOverriddenMethodDescToMethodDescSet.get(highestMethodDesc).size() == 1) {
+        continue;
+      }
+
+      Set<MethodDescriptor> methodDescSet =
+          mapHighestOverriddenMethodDescToMethodDescSet.get(highestMethodDesc);
+
+      NTuple<Descriptor> highestPCLoc =
+          mapHighestOverriddenMethodDescToPCLocTuple.get(highestMethodDesc);
+
+      NTuple<Descriptor> highestRETURNLoc =
+          mapHighestOverriddenMethodDescToReturnLocTuple.get(highestMethodDesc);
+
+      System.out.println("---highestMethodDesc=" + highestMethodDesc);
+
+      for (Iterator iterator2 = methodDescSet.iterator(); iterator2.hasNext();) {
+        MethodDescriptor md = (MethodDescriptor) iterator2.next();
+        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));
+          }
+
+          FlowNode pcFlowNode = flowGraph.getFlowNode(translateToDescTuple(curPCLoc.getTuple()));
+          pcFlowNode.setBaseTuple(newPCLoc);
+
+          CompositeLocation newPCLocCompLoc =
+              new CompositeLocation(translateToLocTuple(md, newPCLoc));
+          summary.setPCLoc(newPCLocCompLoc);
+        } 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);
+          }
+        }
+
+        // need to update RETURNLOC
+        if (highestRETURNLoc != null) {
+
+          CompositeLocation curRETURNLoc = summary.getRETURNLoc();
+          System.out.println("curRETURNLoc=" + curRETURNLoc);
+
+          // 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));
+          }
+
+          FlowNode returnFlowNode =
+              flowGraph.getFlowNode(translateToDescTuple(curRETURNLoc.getTuple()));
+          returnFlowNode.setBaseTuple(newRETURNLoc);
+
+          CompositeLocation newRETURNLocCompLoc =
+              new CompositeLocation(translateToLocTuple(md, newRETURNLoc));
+          summary.setPCLoc(newRETURNLocCompLoc);
+          System.out.println("md=" + md + "###newRETURNLocCompLoc=" + newRETURNLocCompLoc);
+
+        }
+
+      }
+    }
+  }
+
+  private void calculateHighestPCLocInheritance() {
+
+    Set<MethodDescriptor> keySet = mapHighestOverriddenMethodDescToMethodDescSet.keySet();
+    next: for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
+      MethodDescriptor highestMethodDesc = (MethodDescriptor) iterator.next();
+
+      NTuple<Descriptor> tempTuple = null;
+
+      if (getMethodSummary(highestMethodDesc).getPCLoc() != null) {
+
+        Set<MethodDescriptor> methodDescSet =
+            mapHighestOverriddenMethodDescToMethodDescSet.get(highestMethodDesc);
+
+        for (Iterator iterator2 = methodDescSet.iterator(); iterator2.hasNext();) {
+          MethodDescriptor md = (MethodDescriptor) iterator2.next();
+
+          FlowGraph flowGraph = getFlowGraph(md);
+          if (flowGraph == null) {
+            continue;
+          }
+          Set<FlowNode> paramNodeSet = flowGraph.getParamFlowNodeSet();
+          System.out.println("###md=" + md + "   paramNodeSet=" + paramNodeSet);
+
+          CompositeLocation pcLOC = getMethodSummary(md).getPCLoc();
+
+          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;
+              }
+
+              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());
+              }
+              tempTuple = rTuple;
+            }
+          } else {
+            mapHighestOverriddenMethodDescToPCLocTuple.remove(highestMethodDesc);
+            System.out.println("highest=" + highestMethodDesc + "  HIGHEST PCLOC="
+                + mapHighestOverriddenMethodDescToPCLocTuple.get(highestMethodDesc));
+            continue next;
+          }
+        }
+
+      }
+
+      if (!mapHighestOverriddenMethodDescToPCLocTuple.containsKey(highestMethodDesc)
+          && tempTuple != null) {
+        mapHighestOverriddenMethodDescToPCLocTuple.put(highestMethodDesc, tempTuple);
+      }
+      System.out.println("highest=" + highestMethodDesc + "  HIGHEST PCLOC="
+          + mapHighestOverriddenMethodDescToPCLocTuple.get(highestMethodDesc));
+    }
+
+  }
+
+  private void calculateLowestReturnLocInheritance() {
+
+    Set<MethodDescriptor> keySet = mapHighestOverriddenMethodDescToMethodDescSet.keySet();
+    for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
+      MethodDescriptor highestMethodDesc = (MethodDescriptor) iterator.next();
+
+      NTuple<Descriptor> tempTuple = null;
+
+      if (getMethodSummary(highestMethodDesc).getRETURNLoc() != null) {
+        Set<MethodDescriptor> methodDescSet =
+            mapHighestOverriddenMethodDescToMethodDescSet.get(highestMethodDesc);
+        for (Iterator iterator2 = methodDescSet.iterator(); iterator2.hasNext();) {
+          MethodDescriptor md = (MethodDescriptor) iterator2.next();
+
+          FlowGraph flowGraph = getFlowGraph(md);
+          Set<FlowNode> paramNodeSet = flowGraph.getParamFlowNodeSet();
+          System.out.println("###md=" + md + "   paramNodeSet=" + paramNodeSet);
+
+          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.
+
+            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++;
+                System.out.println("-------" + paramNode + " -> " + returnFlowNode);
+              }
+            }
+
+            int offset = 0;
+            if (!md.isStatic()) {
+              offset = 1;
+            }
+
+            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;
+          }
+
+        }
+
+      }
+
+      if (!mapHighestOverriddenMethodDescToReturnLocTuple.containsKey(highestMethodDesc)
+          && tempTuple != null) {
+        mapHighestOverriddenMethodDescToReturnLocTuple.put(highestMethodDesc, tempTuple);
+      }
+      System.out.println("highest=" + highestMethodDesc + "  rTuple="
+          + mapHighestOverriddenMethodDescToReturnLocTuple.get(highestMethodDesc));
+    }
+
+  }
+
+  private void addMapHighestMethodDescToMethodDesc(MethodDescriptor highest, MethodDescriptor md) {
+    if (!mapHighestOverriddenMethodDescToMethodDescSet.containsKey(highest)) {
+      mapHighestOverriddenMethodDescToMethodDescSet.put(highest, new HashSet<MethodDescriptor>());
+    }
+    mapHighestOverriddenMethodDescToMethodDescSet.get(highest).add(md);
+  }
+
+  private void DFSInheritanceTreeCalculatingHighestOverriddenMethod(ClassDescriptor cd) {
+
+    // ClassDescriptor cd = node.getData();
+
+    for (Iterator iterator = cd.getMethods(); iterator.hasNext();) {
+      MethodDescriptor md = (MethodDescriptor) iterator.next();
+      MethodDescriptor highestMethodDesc = getHighestOverriddenMethod(md.getClassDesc(), md);
+      mapMethodDescToHighestOverriddenMethodDesc.put(md, highestMethodDesc);
+      addMapHighestMethodDescToMethodDesc(highestMethodDesc, md);
+
+    }
+
+    // traverse children
+    Set<ClassDescriptor> children = getDirectSubClasses(cd);
+    for (Iterator iterator = children.iterator(); iterator.hasNext();) {
+      ClassDescriptor child = (ClassDescriptor) iterator.next();
+      DFSInheritanceTreeCalculatingHighestOverriddenMethod(child);
+    }
+
+  }
+
+  private MethodDescriptor getHighestOverriddenMethod(ClassDescriptor curClassDesc,
+      MethodDescriptor curMethodDesc) {
+
+    // Node<ClassDescriptor> curNode = inheritanceTree.getTreeNode(curClassDesc);
+    // Node<ClassDescriptor> parentNode = curNode.getParent();
+    ClassDescriptor parentClassDesc = curClassDesc.getSuperDesc();
+
+    if (parentClassDesc != null) {
+      if (parentClassDesc.getMethodTable().contains(curMethodDesc.getSymbol())) {
+        Set<MethodDescriptor> methodDescSet =
+            parentClassDesc.getMethodTable().getSet(curMethodDesc.getSymbol());
+        for (Iterator iterator = methodDescSet.iterator(); iterator.hasNext();) {
+          MethodDescriptor md = (MethodDescriptor) iterator.next();
+          if (md.matches(curMethodDesc)) {
+            return getHighestOverriddenMethod(parentClassDesc, md);
+          }
+        }
+      }
+      // traverse to the parent!
+      return getHighestOverriddenMethod(parentClassDesc, curMethodDesc);
+    }
+    return curMethodDesc;
+  }
+
+  private void buildInheritanceTree() {
+
+    DFSInheritanceTreeCalculatingHighestOverriddenMethod(rootClassDescriptor);
+
+  }
+
+  private void addInheritanceConstraintsToHierarchyGraph() {
+
+    // DFS the inheritance tree and propagates nodes/edges of parent to child
+
+    // Node<ClassDescriptor> rootNode = inheritanceTree.getRootNode();
+    DFSInheritanceTree(rootClassDescriptor);
+
+  }
+
+  private void DFSInheritanceTree(ClassDescriptor parentClassDescriptor) {
+
+    // ClassDescriptor parentClassDescriptor = parentNode.getData();
+
+    Set<ClassDescriptor> children = getDirectSubClasses(parentClassDescriptor);
+    for (Iterator iterator = children.iterator(); iterator.hasNext();) {
+      ClassDescriptor childClassDescriptor = (ClassDescriptor) iterator.next();
+
+      HierarchyGraph parentGraph = getHierarchyGraph(parentClassDescriptor);
+      HierarchyGraph childGraph = getHierarchyGraph(childClassDescriptor);
+
+      // copies extra information from the parent hierarchy graph
+      Map<HNode, Set<HNode>> parentMergeNodeMap = parentGraph.getMapHNodetoMergeSet();
+      Map<HNode, Set<HNode>> childMergeNodeMap = childGraph.getMapHNodetoMergeSet();
+
+      Set<HNode> keySet = parentMergeNodeMap.keySet();
+      for (Iterator iterator2 = keySet.iterator(); iterator2.hasNext();) {
+        HNode parentKey = (HNode) iterator2.next();
+        if (!childMergeNodeMap.containsKey(parentKey)) {
+          childMergeNodeMap.put(parentKey, new HashSet<HNode>());
+        }
+        childMergeNodeMap.get(parentKey).addAll(parentMergeNodeMap.get(parentKey));
+      }
+
+      // copies nodes/edges from the parent class...
+      Set<HNode> parentNodeSet = parentGraph.getNodeSet();
+      for (Iterator iterator2 = parentNodeSet.iterator(); iterator2.hasNext();) {
+        HNode parentHNode = (HNode) iterator2.next();
+
+        Set<HNode> parentIncomingHNode = parentGraph.getIncomingNodeSet(parentHNode);
+        Set<HNode> parentOutgoingHNode = parentGraph.getOutgoingNodeSet(parentHNode);
+
+        for (Iterator iterator3 = parentIncomingHNode.iterator(); iterator3.hasNext();) {
+          HNode inHNode = (HNode) iterator3.next();
+          childGraph.addEdge(inHNode.getDescriptor(), parentHNode.getDescriptor());
+        }
+
+        for (Iterator iterator3 = parentOutgoingHNode.iterator(); iterator3.hasNext();) {
+          HNode outHNode = (HNode) iterator3.next();
+          childGraph.addEdge(parentHNode.getDescriptor(), outHNode.getDescriptor());
+        }
+
+      }
+
+      // copies nodes/edges from parent methods to overridden methods
+
+      for (Iterator iterator3 = childClassDescriptor.getMethods(); iterator3.hasNext();) {
+        MethodDescriptor childMethodDescriptor = (MethodDescriptor) iterator3.next();
+
+        MethodDescriptor parentMethodDesc =
+            getParentMethodDesc(childMethodDescriptor.getClassDesc(), childMethodDescriptor);
+
+        if (parentMethodDesc != null) {
+
+          HierarchyGraph parentMethodGraph = getHierarchyGraph(parentMethodDesc);
+          HierarchyGraph childMethodGraph = getHierarchyGraph(childMethodDescriptor);
+
+          // copies extra information from the parent hierarchy graph
+          Map<HNode, Set<HNode>> parentMethodMergeNodeMap =
+              parentMethodGraph.getMapHNodetoMergeSet();
+          Map<HNode, Set<HNode>> childMethodMergeNodeMap = childMethodGraph.getMapHNodetoMergeSet();
+
+          Set<HNode> methodKeySet = parentMethodMergeNodeMap.keySet();
+          for (Iterator iterator2 = methodKeySet.iterator(); iterator2.hasNext();) {
+            HNode parentKey = (HNode) iterator2.next();
+            if (!childMethodMergeNodeMap.containsKey(parentKey)) {
+              childMethodMergeNodeMap.put(parentKey, new HashSet<HNode>());
+            }
+            childMethodMergeNodeMap.get(parentKey).addAll(parentMethodMergeNodeMap.get(parentKey));
+          }
+
+          // copies nodes/edges from the parent method...
+          for (Iterator iterator2 = parentMethodGraph.getNodeSet().iterator(); iterator2.hasNext();) {
+            HNode parentHNode = (HNode) iterator2.next();
+
+            Set<HNode> parentIncomingHNode = parentMethodGraph.getIncomingNodeSet(parentHNode);
+            Set<HNode> parentOutgoingHNode = parentMethodGraph.getOutgoingNodeSet(parentHNode);
+
+            for (Iterator iterator4 = parentIncomingHNode.iterator(); iterator4.hasNext();) {
+              HNode inHNode = (HNode) iterator4.next();
+              childMethodGraph.addEdge(inHNode, parentHNode);
+            }
+
+            for (Iterator iterator4 = parentOutgoingHNode.iterator(); iterator4.hasNext();) {
+              HNode outHNode = (HNode) iterator4.next();
+              childMethodGraph.addEdge(parentHNode, outHNode);
+            }
+
+          }
+
+        }
+
+      }
+
+      DFSInheritanceTree(childClassDescriptor);
+    }
+
+  }
+
+  public MethodDescriptor getParentMethodDesc(ClassDescriptor classDesc, MethodDescriptor methodDesc) {
+
+    // Node<ClassDescriptor> childNode = inheritanceTree.getTreeNode(classDesc);
+    ClassDescriptor parentClassDesc = classDesc.getSuperDesc();
+    // Node<ClassDescriptor> parentNode = childNode.getParent();
+
+    if (parentClassDesc != null) {
+      // ClassDescriptor parentClassDesc = parentNode.getData();
+      if (parentClassDesc.getMethodTable().contains(methodDesc.getSymbol())) {
+        Set<MethodDescriptor> methodDescSet =
+            parentClassDesc.getMethodTable().getSet(methodDesc.getSymbol());
+        for (Iterator iterator = methodDescSet.iterator(); iterator.hasNext();) {
+          MethodDescriptor md = (MethodDescriptor) iterator.next();
+          if (md.matches(methodDesc)) {
+            return md;
+          }
+        }
+      }
+
+      // traverse to the parent!
+      getParentMethodDesc(parentClassDesc, methodDesc);
+
+    }
+
+    return null;
+  }
+
   private void checkReturnNodes() {
     LinkedList<MethodDescriptor> methodDescList =
         (LinkedList<MethodDescriptor>) toanalyze_methodDescList.clone();
@@ -330,6 +836,23 @@ public class LocationInference {
         System.out.println("SSJAVA: Updating a flow graph: " + md);
         propagateFlowsFromCalleesWithNoCompositeLocation(md);
       }
+
+      Set<FlowNode> nodeSet = getFlowGraph(md).getNodeSet();
+      for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
+        FlowNode flowNode = (FlowNode) iterator.next();
+        NTuple<Descriptor> descTuple = flowNode.getCurrentDescTuple();
+        NTuple<Location> locTuple = translateToLocTuple(md, descTuple);
+        for (int i = 0; i < locTuple.size(); i++) {
+          Location loc = locTuple.get(i);
+          if (loc.getDescriptor() instanceof ClassDescriptor) {
+            toanalyze_classDescSet.add((ClassDescriptor) loc.getDescriptor());
+          } else if (loc.getDescriptor() instanceof MethodDescriptor) {
+            toanalyze_classDescSet.add(((MethodDescriptor) loc.getDescriptor()).getClassDesc());
+          }
+        }
+
+      }
+
     }
   }
 
@@ -409,19 +932,19 @@ public class LocationInference {
       Set<FlowNode> nodeSet = flowGraph.getNodeSet();
       for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
         FlowNode node = (FlowNode) iterator.next();
-        // System.out.println("-node=" + node + "   node.getDescTuple=" + node.getDescTuple());
+        System.out.println("-node=" + node + "   node.getDescTuple=" + node.getDescTuple());
         if (node.getCompositeLocation() != null) {
           CompositeLocation compLoc = node.getCompositeLocation();
           CompositeLocation updatedCompLoc = updateCompositeLocation(compLoc);
           node.setCompositeLocation(updatedCompLoc);
-          // System.out.println("---updatedCompLoc1=" + updatedCompLoc);
+          System.out.println("---updatedCompLoc1=" + updatedCompLoc);
         } else {
           NTuple<Descriptor> descTuple = node.getDescTuple();
-          // System.out.println("update desc=" + descTuple);
+          System.out.println("update desc=" + descTuple);
           CompositeLocation compLoc = convertToCompositeLocation(md, descTuple);
           compLoc = updateCompositeLocation(compLoc);
           node.setCompositeLocation(compLoc);
-          // System.out.println("---updatedCompLoc2=" + compLoc);
+          System.out.println("---updatedCompLoc2=" + compLoc);
         }
 
         if (node.isDeclaratonNode()) {
@@ -452,9 +975,12 @@ public class LocationInference {
       String locName;
       if (!enclosingDesc.equals(GLOBALDESC)) {
         LocationSummary locSummary = getLocationSummary(enclosingDesc);
-        HierarchyGraph scGraph = getSkeletonCombinationHierarchyGraph(enclosingDesc);
+        // HierarchyGraph scGraph = getSkeletonCombinationHierarchyGraph(enclosingDesc);
+        HierarchyGraph scGraph = getSimpleHierarchyGraph(enclosingDesc);
         if (scGraph != null) {
           HNode curNode = scGraph.getCurrentHNode(nodeIdentifier);
+          System.out.println("nodeID=" + nodeIdentifier + " curNode=" + curNode
+              + "  enclosingDesc=" + enclosingDesc);
           if (curNode != null) {
             nodeIdentifier = curNode.getName();
           }
@@ -511,46 +1037,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
@@ -1384,6 +1870,10 @@ public class LocationInference {
     Location lastLocationOfPrefix = curPrefix.get(curPrefix.size() - 1);
     // check whether prefix appears in the list of parameters
     Set<MethodInvokeNode> minSet = mapMethodDescToMethodInvokeNodeSet.get(md);
+    System.out.println("$$$md=" + md + "   minSet=" + minSet);
+    if (minSet == null) {
+      return false;
+    }
     found: for (Iterator iterator = minSet.iterator(); iterator.hasNext();) {
       MethodInvokeNode min = (MethodInvokeNode) iterator.next();
       Map<Integer, NTuple<Descriptor>> map = mapMethodInvokeNodeToArgIdxMap.get(min);
@@ -1609,20 +2099,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();
@@ -1899,6 +2375,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);
@@ -2014,31 +2493,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();
@@ -2048,12 +2502,12 @@ public class LocationInference {
       // HierarchyGraph simpleHierarchyGraph = getSimpleHierarchyGraph(key);
       HierarchyGraph scHierarchyGraph = getSkeletonCombinationHierarchyGraph(key);
       if (key instanceof ClassDescriptor) {
-        writeInferredLatticeDotFile((ClassDescriptor) key, scHierarchyGraph, simpleLattice,
-            "_SIMPLE");
+        // writeInferredLatticeDotFile((ClassDescriptor) key, scHierarchyGraph, simpleLattice,
+        // "_SIMPLE");
       } else if (key instanceof MethodDescriptor) {
         MethodDescriptor md = (MethodDescriptor) key;
-        writeInferredLatticeDotFile(md.getClassDesc(), md, scHierarchyGraph, simpleLattice,
-            "_SIMPLE");
+        // writeInferredLatticeDotFile(md.getClassDesc(), md, scHierarchyGraph, simpleLattice,
+        // "_SIMPLE");
       }
 
       LocationSummary ls = getLocationSummary(key);
@@ -2063,8 +2517,10 @@ public class LocationInference {
     Set<ClassDescriptor> cdKeySet = cd2lattice.keySet();
     for (Iterator iterator = cdKeySet.iterator(); iterator.hasNext();) {
       ClassDescriptor cd = (ClassDescriptor) iterator.next();
+      System.out.println("########cd=" + cd);
       writeInferredLatticeDotFile((ClassDescriptor) cd, getSkeletonCombinationHierarchyGraph(cd),
           cd2lattice.get(cd), "");
+      COUNT += cd2lattice.get(cd).getKeySet().size();
     }
 
     Set<MethodDescriptor> mdKeySet = md2lattice.keySet();
@@ -2072,14 +2528,40 @@ public class LocationInference {
       MethodDescriptor md = (MethodDescriptor) iterator.next();
       writeInferredLatticeDotFile(md.getClassDesc(), md, getSkeletonCombinationHierarchyGraph(md),
           md2lattice.get(md), "");
+      COUNT += md2lattice.get(md).getKeySet().size();
+    }
+    System.out.println("###COUNT=" + COUNT);
+  }
+
+  private void buildLattice(Descriptor desc) {
+    System.out.println("buildLattice=" + desc);
+    SSJavaLattice<String> simpleLattice = buildLattice.buildLattice(desc);
+
+    addMapDescToSimpleLattice(desc, simpleLattice);
+
+    HierarchyGraph simpleHierarchyGraph = getSimpleHierarchyGraph(desc);
+    System.out.println("\n## insertIntermediateNodesToStraightLine:"
+        + simpleHierarchyGraph.getName());
+    SSJavaLattice<String> lattice =
+        buildLattice.insertIntermediateNodesToStraightLine(desc, simpleLattice);
+    lattice.removeRedundantEdges();
+
+    if (desc instanceof ClassDescriptor) {
+      // field lattice
+      cd2lattice.put((ClassDescriptor) desc, lattice);
+      // ssjava.writeLatticeDotFile((ClassDescriptor) desc, null, lattice);
+    } else if (desc instanceof MethodDescriptor) {
+      // method lattice
+      md2lattice.put((MethodDescriptor) desc, lattice);
+      MethodDescriptor md = (MethodDescriptor) desc;
+      ClassDescriptor cd = md.getClassDesc();
+      // ssjava.writeLatticeDotFile(cd, md, lattice);
     }
 
   }
 
   private void buildLattice() {
 
-    BuildLattice buildLattice = new BuildLattice(this);
-
     Set<Descriptor> keySet = mapDescriptorToCombineSkeletonHierarchyGraph.keySet();
     for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
       Descriptor desc = (Descriptor) iterator.next();
@@ -2107,18 +2589,67 @@ public class LocationInference {
         // ssjava.writeLatticeDotFile(cd, md, lattice);
       }
 
-      // System.out.println("\nSSJAVA: Insering Combination Nodes:" + desc);
-      // HierarchyGraph skeletonGraph = getSkeletonHierarchyGraph(desc);
-      // HierarchyGraph skeletonGraphWithCombinationNode =
-      // skeletonGraph.clone();
-      // skeletonGraphWithCombinationNode.setName(desc + "_SC");
-      //
-      // HierarchyGraph simpleHierarchyGraph = getSimpleHierarchyGraph(desc);
-      // System.out.println("Identifying Combination Nodes:");
-      // skeletonGraphWithCombinationNode.insertCombinationNodesToGraph(simpleHierarchyGraph);
-      // skeletonGraphWithCombinationNode.simplifySkeletonCombinationHierarchyGraph();
-      // mapDescriptorToCombineSkeletonHierarchyGraph.put(desc,
-      // skeletonGraphWithCombinationNode);
+    }
+
+  }
+
+  private void buildLatticeInheritanceTree() {
+    // DFS the inheritance tree and propagates lattice nodes/edges from the parent to children
+    // Node<ClassDescriptor> rootNode = inheritanceTree.getRootNode();
+    DFSBuildLatticeInheritanceTree(rootClassDescriptor);
+  }
+
+  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);
+    if (children == null) {
+      children = new HashSet<ClassDescriptor>();
+    }
+
+    for (Iterator iterator = children.iterator(); iterator.hasNext();) {
+      ClassDescriptor child = (ClassDescriptor) iterator.next();
+      if (toanalyze_classDescSet.contains(child)) {
+        result.add(child);
+      }
+    }
+
+    return result;
+  }
+
+  private void DFSBuildLatticeInheritanceTree(ClassDescriptor cd) {
+    // ClassDescriptor cd = node.getData();
+
+    ClassDescriptor parentClassDesc = cd.getSuperDesc();
+    if (parentClassDesc != null) {
+      Map<TripleItem, String> parentMap = buildLattice.getIntermediateLocMap(parentClassDesc);
+      buildLattice.setIntermediateLocMap(cd, parentMap);
+    }
+
+    buildLattice(cd);
+
+    for (Iterator iterator = cd.getMethods(); iterator.hasNext();) {
+      MethodDescriptor md = (MethodDescriptor) iterator.next();
+      if (toanalyze_methodDescList.contains(md)) {
+        MethodDescriptor parentMethodDesc = getParentMethodDesc(md.getClassDesc(), md);
+        if (parentMethodDesc != null) {
+          Map<TripleItem, String> parentMap = buildLattice.getIntermediateLocMap(parentMethodDesc);
+          buildLattice.setIntermediateLocMap(md, parentMap);
+        }
+        buildLattice(md);
+      }
+    }
+
+    // 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);
+      }
+
     }
 
   }
@@ -2147,15 +2678,17 @@ public class LocationInference {
     Set<Descriptor> keySet = mapDescriptorToSkeletonHierarchyGraph.keySet();
     for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
       Descriptor desc = (Descriptor) iterator.next();
-      System.out.println("\nSSJAVA: Insering Combination Nodes:" + desc);
+      System.out.println("\nSSJAVA: Inserting Combination Nodes:" + desc);
       HierarchyGraph skeletonGraph = getSkeletonHierarchyGraph(desc);
       HierarchyGraph skeletonGraphWithCombinationNode = skeletonGraph.clone();
       skeletonGraphWithCombinationNode.setName(desc + "_SC");
 
       HierarchyGraph simpleHierarchyGraph = getSimpleHierarchyGraph(desc);
-      System.out.println("Identifying Combination Nodes:");
       skeletonGraphWithCombinationNode.insertCombinationNodesToGraph(simpleHierarchyGraph);
-      skeletonGraphWithCombinationNode.simplifySkeletonCombinationHierarchyGraph();
+      // skeletonGraphWithCombinationNode.insertCombinationNodesToGraph(simpleHierarchyGraph,
+      // skeletonGraph);
+      // skeletonGraphWithCombinationNode.simplifySkeletonCombinationHierarchyGraph();
+      skeletonGraphWithCombinationNode.removeRedundantEdges();
       mapDescriptorToCombineSkeletonHierarchyGraph.put(desc, skeletonGraphWithCombinationNode);
     }
   }
@@ -2169,13 +2702,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();
@@ -2193,6 +2837,7 @@ public class LocationInference {
       Descriptor desc = (Descriptor) iterator.next();
       getHierarchyGraph(desc).writeGraph();
       getSimpleHierarchyGraph(desc).writeGraph();
+      getSimpleHierarchyGraph(desc).writeGraph(true);
     }
 
   }
@@ -2497,6 +3142,19 @@ public class LocationInference {
           NTuple<Descriptor> srcCurTuple = srcNode.getCurrentDescTuple();
           NTuple<Descriptor> dstCurTuple = dstNode.getCurrentDescTuple();
 
+          // //////////////////////////
+          // inheritance check
+          if (mapMethodDescToHighestOverriddenMethodDesc.containsKey(md)) {
+
+            MethodDescriptor highestOverriddenMethodDesc =
+                mapMethodDescToHighestOverriddenMethodDesc.get(md);
+
+            if (srcCurTuple.get(srcCurTuple.size() - 1).getSymbol().startsWith(PCLOC)) {
+            }
+
+          }
+          // //////////////////////////
+
           System.out.println("-srcCurTuple=" + srcCurTuple + "  dstCurTuple=" + dstCurTuple
               + "  srcNode=" + srcNode + "   dstNode=" + dstNode);
 
@@ -3279,35 +3937,50 @@ public class LocationInference {
     }
   }
 
-  private boolean coversAllParamters(MethodDescriptor md, FlowGraph fg,
-      Set<NTuple<Location>> paramLocTupleHavingInFlowSet) {
+  private int countFirstDescriptorSetSize(Set<NTuple<Location>> set) {
 
-    int numParam = fg.getNumParameters();
-    int size = paramLocTupleHavingInFlowSet.size();
+    Set<Descriptor> descSet = new HashSet<Descriptor>();
 
-    if (!md.isStatic()) {
+    for (Iterator iterator = set.iterator(); iterator.hasNext();) {
+      NTuple<Location> locTuple = (NTuple<Location>) iterator.next();
+      descSet.add(locTuple.get(0).getLocDescriptor());
+    }
 
-      // if the method is not static && there is a parameter composite location &&
-      // it is started with 'this',
-      // paramLocTupleHavingInFlowSet need to have 'this' parameter.
+    return descSet.size();
+  }
 
-      FlowNode thisParamNode = fg.getParamFlowNode(0);
-      NTuple<Location> thisParamLocTuple =
-          translateToLocTuple(md, thisParamNode.getCurrentDescTuple());
+  private boolean coversAllParamters(MethodDescriptor md, FlowGraph fg,
+      Set<NTuple<Location>> paramLocTupleHavingInFlowSet) {
 
-      if (!paramLocTupleHavingInFlowSet.contains(thisParamLocTuple)) {
+    int numParam = fg.getNumParameters();
+    // int size = paramLocTupleHavingInFlowSet.size();
+    int size = countFirstDescriptorSetSize(paramLocTupleHavingInFlowSet);
 
-        for (Iterator iterator = paramLocTupleHavingInFlowSet.iterator(); iterator.hasNext();) {
-          NTuple<Location> paramTuple = (NTuple<Location>) iterator.next();
-          if (paramTuple.size() > 1 && paramTuple.get(0).getLocDescriptor().equals(md.getThis())) {
-            // paramLocTupleHavingInFlowSet.add(thisParamLocTuple);
-            // break;
-            size++;
-          }
-        }
+    System.out.println("numParam=" + numParam + "     size=" + size);
 
-      }
-    }
+    // if (!md.isStatic()) {
+    //
+    // // if the method is not static && there is a parameter composite location &&
+    // // it is started with 'this',
+    // // paramLocTupleHavingInFlowSet need to have 'this' parameter.
+    //
+    // FlowNode thisParamNode = fg.getParamFlowNode(0);
+    // NTuple<Location> thisParamLocTuple =
+    // translateToLocTuple(md, thisParamNode.getCurrentDescTuple());
+    //
+    // if (!paramLocTupleHavingInFlowSet.contains(thisParamLocTuple)) {
+    //
+    // for (Iterator iterator = paramLocTupleHavingInFlowSet.iterator(); iterator.hasNext();) {
+    // NTuple<Location> paramTuple = (NTuple<Location>) iterator.next();
+    // if (paramTuple.size() > 1 && paramTuple.get(0).getLocDescriptor().equals(md.getThis())) {
+    // // paramLocTupleHavingInFlowSet.add(thisParamLocTuple);
+    // // break;
+    // size++;
+    // }
+    // }
+    //
+    // }
+    // }
 
     if (size == numParam) {
       return true;
@@ -4020,7 +4693,7 @@ public class LocationInference {
     return false;
   }
 
-  private SSJavaLattice<String> getLattice(Descriptor d) {
+  public SSJavaLattice<String> getLattice(Descriptor d) {
     if (d instanceof MethodDescriptor) {
       return getMethodLattice((MethodDescriptor) d);
     } else {
@@ -4107,6 +4780,11 @@ public class LocationInference {
     while (!toAnalyzeIsEmpty()) {
       ClassDescriptor cd = toAnalyzeNext();
 
+      if (cd.getClassName().equals("Object")) {
+        rootClassDescriptor = cd;
+        // inheritanceTree = new InheritanceTree<ClassDescriptor>(cd);
+      }
+
       setupToAnalazeMethod(cd);
       temp_toanalyzeMethodList.removeAll(visited);
 
@@ -4643,7 +5321,7 @@ public class LocationInference {
   private void analyzeFlowIfStatementNode(MethodDescriptor md, SymbolTable nametable,
       IfStatementNode isn, NodeTupleSet implicitFlowTupleSet) {
 
-    System.out.println("analyzeFlowIfStatementNode=" + isn.printNode(0));
+    // System.out.println("analyzeFlowIfStatementNode=" + isn.printNode(0));
 
     NodeTupleSet condTupleNode = new NodeTupleSet();
     analyzeFlowExpressionNode(md, nametable, isn.getCondition(), condTupleNode, null,
@@ -5833,13 +6511,15 @@ public class LocationInference {
     String fileName = "lattice_";
     if (md != null) {
       fileName +=
-      /* cd.getSymbol().replaceAll("[\\W_]", "") + "_" + */md.toString().replaceAll("[\\W_]", "");
+          cd.getSymbol().replaceAll("[\\W_]", "") + "_" + md.toString().replaceAll("[\\W_]", "");
     } else {
       fileName += cd.getSymbol().replaceAll("[\\W_]", "");
     }
 
     fileName += nameSuffix;
 
+    System.out.println("***lattice=" + fileName + "    setsize=" + locOrder.getKeySet().size());
+
     Set<Pair<String, String>> pairSet = locOrder.getOrderingPairSet();
 
     Set<String> addedLocSet = new HashSet<String>();