changes.
authoryeom <yeom>
Wed, 20 Feb 2013 03:52:41 +0000 (03:52 +0000)
committeryeom <yeom>
Wed, 20 Feb 2013 03:52:41 +0000 (03:52 +0000)
Robust/src/Analysis/SSJava/BuildLattice.java
Robust/src/Analysis/SSJava/HierarchyGraph.java
Robust/src/Analysis/SSJava/LocationInference.java
Robust/src/Analysis/SSJava/SSJavaAnalysis.java

index 61a083274e84e97c7968442d8bc6d5d502d343f8..2d65122ab895463c7f5e9073786e250dbe51813a 100644 (file)
@@ -258,7 +258,7 @@ public class BuildLattice {
       HNode hNode = (HNode) iterator.next();
       if (!hNode.isSkeleton()) {
         // here we need to insert an intermediate node for the hNode
-        System.out.println("local node=" + hNode);
+        System.out.println("\n#local node=" + hNode);
 
         // 1) find the lowest node m in the lattice that is above hnode in the lattice
         // 2) count the number of non-shared nodes d between the hnode and the node m
@@ -268,22 +268,36 @@ public class BuildLattice {
         if (hNode.isDirectCombinationNode()) {
           // this node itself is the lowest node m. it is the first node of the chain
           Set<HNode> combineSet = hierarchyGraph.getCombineSetByCombinationNode(hNode);
+
+          System.out.println("     # direct combine node::combineSkeletonNodeSet=" + combineSet);
+
           SCNode = scGraph.getCombinationNode(combineSet);
           numNonSharedNodes = -1;
         } else {
 
           Set<HNode> aboveSet = new HashSet<HNode>();
           if (hNode.isCombinationNode()) {
+            // the current node is a combination node
             Set<HNode> combineSkeletonNodeSet =
                 hierarchyGraph.getCombineSetByCombinationNode(hNode);
+            System.out.println("     combineSkeletonNodeSet=" + combineSkeletonNodeSet
+                + " combinationNode=" + scGraph.getCombinationNode(combineSkeletonNodeSet));
 
+            scGraph.getCombinationNode(combineSkeletonNodeSet);
+
+            System.out.println("        firstnode="
+                + hierarchyGraph.getFirstNodeOfCombinationNodeChainSet(combineSkeletonNodeSet));
             aboveSet.addAll(hierarchyGraph
                 .getFirstNodeOfCombinationNodeChainSet(combineSkeletonNodeSet));
+
             SCNode = scGraph.getCombinationNode(combineSkeletonNodeSet);
+
           } else {
-            System.out.println("   #######hierarchyGraph.getSkeleteNodeSetReachTo(" + hNode + ")="
-                + hierarchyGraph.getSkeleteNodeSetReachTo(hNode));
+            // the current node is not a combination node
+            // there is only one parent node which should be skeleton node.
 
+            System.out.println("   hierarchyGraph.getSkeleteNodeSetReachTo(" + hNode + ")="
+                + hierarchyGraph.getSkeleteNodeSetReachTo(hNode));
             aboveSet.addAll(hierarchyGraph.getSkeleteNodeSetReachTo(hNode));
             // assert aboveSet.size() == 1;
             SCNode = aboveSet.iterator().next();
@@ -304,14 +318,23 @@ public class BuildLattice {
 
         // 3) convert the node m into a chain of nodes with the last node in the chain having m’s
         // outgoing edges.
-        Set<String> outgoingElements = skeletonLattice.get(SCNode.getName());
-        System.out.println("   SCNODE outgoing=" + outgoingElements);
+        Set<HNode> outgoingSCNodeSet = scGraph.getOutgoingNodeSet(SCNode);
+        System.out.println("   SCNODE outgoing hnode set=" + outgoingSCNodeSet);
+
+        Set<String> outgoingLocNameSet = new HashSet<String>();
+        for (Iterator iterator2 = outgoingSCNodeSet.iterator(); iterator2.hasNext();) {
+          HNode outSCNode = (HNode) iterator2.next();
+          String locName = locSummary.getLocationName(outSCNode.getName());
+          System.out.println("                         outSCNode=" + outSCNode + " -> locName="
+              + locName);
+          outgoingLocNameSet.add(locName);
+        }
 
         // 4) If hnode is not a shared location, check if there already exists a local variable
         // node that has distance d below m along this chain. If such a node
         // does not exist, insert it.
         String locName =
-            getNewLocation(lattice, SCNode.getName(), outgoingElements, numNonSharedNodes,
+            getNewLocation(lattice, SCNode.getName(), outgoingLocNameSet, numNonSharedNodes,
                 hNode.isSharedNode());
         System.out.println("       locName=" + locName);
         locSummary.addMapHNodeNameToLocationName(hNode.getName(), locName);
@@ -346,9 +369,10 @@ public class BuildLattice {
     if (dist == 0 && isShared) {
       // if the node is shared,
       // check if there already exists a shared node that has distance d + 1 on the chain
-      connectedSet = lattice.get(cur);
-      if (connectedSet.equals(endSet)) {
+      if ((cur.equals(lattice.getTopItem()) && connectedSet.containsAll(endSet))
+          || connectedSet.equals(endSet)) {
         // need to insert a new shared location
+        // it is done after this if statement
       } else {
         assert connectedSet.size() == 1;
         String below = connectedSet.iterator().next();
@@ -358,12 +382,15 @@ public class BuildLattice {
       }
 
       // need to insert a new shared location
+      Set<String> newChildSet = new HashSet<String>();
+      newChildSet.addAll(connectedSet);
+
       String newLocName = "ILOC" + (LocationInference.locSeed++);
-      for (Iterator iterator = connectedSet.iterator(); iterator.hasNext();) {
+      for (Iterator iterator = newChildSet.iterator(); iterator.hasNext();) {
         String outNode = (String) iterator.next();
         lattice.put(newLocName, outNode);
       }
-      connectedSet.clear();
+      lattice.get(cur).clear();
       lattice.put(cur, newLocName);
 
       System.out.println("       INSERT NEW SHARED NODE=" + newLocName + " above=" + cur
@@ -376,12 +403,20 @@ public class BuildLattice {
     }
 
     String next;
-    if (connectedSet.equals(endSet)) {
+
+    if (cur.equals(lattice.getTopItem()) || connectedSet.equals(endSet) || endSet.isEmpty()) {
+
+      // if ( (cur.equals(lattice.getTopItem()) && connectedSet.containsAll(endSet))
+      // || connectedSet.equals(endSet)) {
+
       // need to insert a new location
       String newLocName = "ILOC" + (LocationInference.locSeed++);
       connectedSet.clear();
       lattice.put(cur, newLocName);
-      System.out.println("NEW RELATION=" + lattice.get(cur));
+
+      System.out.println("#INSERT NEW RELATION cur=" + cur + " newLocName=" + newLocName + "::"
+          + lattice.get(cur));
+
       for (Iterator iterator = endSet.iterator(); iterator.hasNext();) {
         String endNode = (String) iterator.next();
         lattice.put(newLocName, endNode);
index ed82566eb1dda570adbfb54c9cd50f3cc0dc08c0..4e7c4b57a6a52e3e6e8c7680d70095be7b49a240 100644 (file)
@@ -17,6 +17,8 @@ public class HierarchyGraph {
 
   Descriptor desc;
 
+  boolean isSCgraph;
+
   String name;
 
   // graph structure
@@ -70,6 +72,16 @@ public class HierarchyGraph {
     mapNormalNodeToSCNodeReachToSet = new HashMap<HNode, Set<HNode>>();
 
     mapCombineNodeSetToFirstNodeOfChainSet = new HashMap<Set<HNode>, Set<HNode>>();
+
+    isSCgraph = false;
+  }
+
+  public void setSCGraph(boolean in) {
+    isSCgraph = in;
+  }
+
+  public boolean isSCGraph() {
+    return isSCgraph;
   }
 
   public Descriptor getDesc() {
@@ -763,8 +775,10 @@ public class HierarchyGraph {
   }
 
   public HNode getCombinationNode(Set<HNode> combineSet) {
+    assert isSCGraph();
     if (!mapCombineNodeSetToCombinationNode.containsKey(combineSet)) {
       String name = "COMB" + (LocationInference.locSeed++);
+      System.out.println("-NEW COMB NODE=" + name);
       HNode node = new HNode(name);
       node.setCombinationNode(true);
       nodeSet.add(node);
@@ -795,8 +809,36 @@ public class HierarchyGraph {
       HNode combinationNode = getCombinationNode(combineSet);
       System.out.println("--combinationNode=" + combinationNode + "   combineSet=" + combineSet);
 
-      // System.out.println("--hierarchynodes="
-      // + simpleHierarchyGraph.getCombinationNodeSetByCombineNodeSet(combineSet));
+      System.out.println("--hierarchynodes="
+          + simpleHierarchyGraph.getCombinationNodeSetByCombineNodeSet(combineSet));
+
+      Set<HNode> simpleHNodeSet =
+          simpleHierarchyGraph.getCombinationNodeSetByCombineNodeSet(combineSet);
+
+      // check whether a hnode in the simple hierarchy graph is the first node of the chain
+      // if all incoming combination nodes to the hnode have a different combination set from the
+      // hnode, it is the first node of the chain
+      for (Iterator iterator2 = simpleHNodeSet.iterator(); iterator2.hasNext();) {
+        HNode simpleHNode = (HNode) iterator2.next();
+        boolean isFirstNodeOfChain = true;
+        Set<HNode> incomingNodeSet = simpleHierarchyGraph.getIncomingNodeSet(simpleHNode);
+        for (Iterator iterator3 = incomingNodeSet.iterator(); iterator3.hasNext();) {
+          HNode inNode = (HNode) iterator3.next();
+          if (inNode.isCombinationNode()) {
+            Set<HNode> inNodeCombineSet =
+                simpleHierarchyGraph.getCombineSetByCombinationNode(inNode);
+            if (inNodeCombineSet.equals(combineSet)) {
+              isFirstNodeOfChain = false;
+              break;
+            }
+          }
+        }
+        simpleHNode.setDirectCombinationNode(isFirstNodeOfChain);
+        if (isFirstNodeOfChain) {
+          simpleHierarchyGraph.addFirstNodeOfChain(combineSet, simpleHNode);
+          System.out.println("IT IS THE FIRST NODE OF THE CHAIN:" + simpleHNode);
+        }
+      }
 
       // add an edge from a skeleton node to a combination node
       for (Iterator iterator2 = combineSet.iterator(); iterator2.hasNext();) {
@@ -922,6 +964,10 @@ public class HierarchyGraph {
     return clone;
   }
 
+  public void setMapCombineNodeSetToCombinationNode(Map<Set<HNode>, HNode> in) {
+    mapCombineNodeSetToCombinationNode = in;
+  }
+
   public Map<HNode, Set<HNode>> getMapHNodetoMergeSet() {
     return mapMergeNodetoMergingSet;
   }
@@ -952,31 +998,30 @@ public class HierarchyGraph {
         // + tempSet);
         if (reachToSet.size() > 1) {
           // if (countSkeletonNodes(reachToSet) > 1) {
-          System.out.println("-node=" + node + "  reachToSet=" + reachToSet);
+          System.out.println("\n-node=" + node + "  reachToSet=" + reachToSet);
           System.out.println("-set combinationnode=" + node);
           node.setCombinationNode(true);
           mapCombinationNodeToCombineNodeSet.put(node, reachToSet);
 
           // check if this node is the first node of the chain
-          boolean isFirstNodeOfChain = false;
-          Set<HNode> inNodeSet = getIncomingNodeSet(node);
-          for (Iterator iterator2 = inNodeSet.iterator(); iterator2.hasNext();) {
-            HNode inNode = (HNode) iterator2.next();
-            if (inNode.isSkeleton()) {
-              isFirstNodeOfChain = true;
-            } else if (inNode.isCombinationNode()) {
-              Set<HNode> inNodeReachToSet = getSkeleteNodeSetReachTo(inNode);
-              if (!reachToSet.equals(inNodeReachToSet)) {
-                isFirstNodeOfChain = true;
-              }
-            }
-          }
-
-          if (isFirstNodeOfChain) {
-            node.setDirectCombinationNode(true);
-            addFirstNodeOfChain(reachToSet, node);
-            // System.out.println("IT IS DIRECTLY CONNECTED WITH SC NODES:" + node);
-          }
+          // boolean isFirstNodeOfChain = false;
+          // Set<HNode> inNodeSet = getIncomingNodeSet(node);
+          // for (Iterator iterator2 = inNodeSet.iterator(); iterator2.hasNext();) {
+          // HNode inNode = (HNode) iterator2.next();
+          // if (inNode.isSkeleton()) {
+          // isFirstNodeOfChain = true;
+          // } else if (inNode.isCombinationNode()) {
+          // Set<HNode> inNodeReachToSet = getSkeleteNodeSetReachTo(inNode);
+          // if (!reachToSet.equals(inNodeReachToSet)) {
+          // isFirstNodeOfChain = true;
+          // }
+          // }
+          // }
+          //
+          // if (isFirstNodeOfChain) {
+          // node.setDirectCombinationNode(true);
+          // addFirstNodeOfChain(reachToSet, node);
+          // }
 
         }
       }
index b15742f55874221a52703f4ddf5653a6cb7b39fa..a19f725ef5f7222dbe6f97a1bd745d4a08236762 100644 (file)
@@ -97,8 +97,8 @@ public class LocationInference {
   // map a method/class descriptor to a skeleton hierarchy graph with combination nodes
   private Map<Descriptor, HierarchyGraph> mapDescriptorToCombineSkeletonHierarchyGraph;
 
-  // map a descriptor to a simple lattice
-  private Map<Descriptor, SSJavaLattice<String>> mapDescriptorToSimpleLattice;
+  // map a descriptor to a skeleton lattice
+  private Map<Descriptor, SSJavaLattice<String>> mapDescriptorToSkeletonLattice;
 
   // map a method descriptor to the set of method invocation nodes which are
   // invoked by the method descriptor
@@ -220,7 +220,7 @@ public class LocationInference {
     this.mapDescriptorToCombineSkeletonHierarchyGraph = new HashMap<Descriptor, HierarchyGraph>();
     this.mapDescriptorToSimpleHierarchyGraph = new HashMap<Descriptor, HierarchyGraph>();
 
-    this.mapDescriptorToSimpleLattice = new HashMap<Descriptor, SSJavaLattice<String>>();
+    this.mapDescriptorToSkeletonLattice = new HashMap<Descriptor, SSJavaLattice<String>>();
 
     this.mapDescToLocationSummary = new HashMap<Descriptor, LocationSummary>();
 
@@ -2549,17 +2549,17 @@ public class LocationInference {
 
   private void debug_writeLattices() {
 
-    Set<Descriptor> keySet = mapDescriptorToSimpleLattice.keySet();
+    Set<Descriptor> keySet = mapDescriptorToSkeletonLattice.keySet();
     for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
       Descriptor key = (Descriptor) iterator.next();
-      SSJavaLattice<String> simpleLattice = mapDescriptorToSimpleLattice.get(key);
+      SSJavaLattice<String> skeletonLattice = mapDescriptorToSkeletonLattice.get(key);
       // HierarchyGraph simpleHierarchyGraph = getSimpleHierarchyGraph(key);
       HierarchyGraph scHierarchyGraph = getSkeletonCombinationHierarchyGraph(key);
       if (key instanceof ClassDescriptor) {
-        writeInferredLatticeDotFile((ClassDescriptor) key, simpleLattice, "_SIMPLE");
+        writeInferredLatticeDotFile((ClassDescriptor) key, skeletonLattice, "_SKELETON");
       } else if (key instanceof MethodDescriptor) {
         MethodDescriptor md = (MethodDescriptor) key;
-        writeInferredLatticeDotFile(md.getClassDesc(), md, simpleLattice, "_SIMPLE");
+        writeInferredLatticeDotFile(md.getClassDesc(), md, skeletonLattice, "_SKELETON");
       }
 
       LocationSummary ls = getLocationSummary(key);
@@ -2603,15 +2603,16 @@ public class LocationInference {
 
   private void buildLattice(Descriptor desc) {
     // System.out.println("buildLattice=" + desc);
-    SSJavaLattice<String> simpleLattice = buildLattice.buildLattice(desc);
+    SSJavaLattice<String> skeletonLattice = buildLattice.buildLattice(desc);
 
-    addMapDescToSimpleLattice(desc, simpleLattice);
+    addMapDescToSkeletonLattice(desc, skeletonLattice);
 
+    // write a dot file before everything is done
     if (desc instanceof ClassDescriptor) {
-      writeInferredLatticeDotFile((ClassDescriptor) desc, null, simpleLattice, "_SC");
+      writeInferredLatticeDotFile((ClassDescriptor) desc, null, skeletonLattice, "_SC");
     } else {
       MethodDescriptor md = (MethodDescriptor) desc;
-      writeInferredLatticeDotFile(md.getClassDesc(), md, simpleLattice, "_SC");
+      writeInferredLatticeDotFile(md.getClassDesc(), md, skeletonLattice, "_SC");
     }
 
     HierarchyGraph simpleHierarchyGraph = getSimpleHierarchyGraph(desc);
@@ -2619,7 +2620,7 @@ public class LocationInference {
     // System.out.println("\n## insertIntermediateNodesToStraightLine:"
     // + simpleHierarchyGraph.getName());
     SSJavaLattice<String> lattice =
-        buildLattice.insertIntermediateNodesToStraightLine(desc, simpleLattice);
+        buildLattice.insertIntermediateNodesToStraightLine(desc, skeletonLattice);
 
     if (lattice == null) {
       return;
@@ -2631,13 +2632,13 @@ public class LocationInference {
     if (desc instanceof ClassDescriptor) {
       // field lattice
       cd2lattice.put((ClassDescriptor) desc, lattice);
-      // ssjava.writeLatticeDotFile((ClassDescriptor) desc, null, 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);
+      ssjava.writeLatticeDotFile(cd, md, lattice);
     }
 
   }
@@ -2651,7 +2652,7 @@ public class LocationInference {
 
       SSJavaLattice<String> simpleLattice = buildLattice.buildLattice(desc);
 
-      addMapDescToSimpleLattice(desc, simpleLattice);
+      addMapDescToSkeletonLattice(desc, simpleLattice);
 
       HierarchyGraph simpleHierarchyGraph = getSimpleHierarchyGraph(desc);
       System.out.println("\n## insertIntermediateNodesToStraightLine:"
@@ -2749,12 +2750,12 @@ public class LocationInference {
 
   }
 
-  public void addMapDescToSimpleLattice(Descriptor desc, SSJavaLattice<String> lattice) {
-    mapDescriptorToSimpleLattice.put(desc, lattice);
+  public void addMapDescToSkeletonLattice(Descriptor desc, SSJavaLattice<String> lattice) {
+    mapDescriptorToSkeletonLattice.put(desc, lattice);
   }
 
-  public SSJavaLattice<String> getSimpleLattice(Descriptor desc) {
-    return mapDescriptorToSimpleLattice.get(desc);
+  public SSJavaLattice<String> getSkeletonLattice(Descriptor desc) {
+    return mapDescriptorToSkeletonLattice.get(desc);
   }
 
   private void simplifyHierarchyGraph() {
@@ -2776,6 +2777,7 @@ public class LocationInference {
       System.out.println("\nSSJAVA: Inserting Combination Nodes:" + desc);
       HierarchyGraph skeletonGraph = getSkeletonHierarchyGraph(desc);
       HierarchyGraph skeletonGraphWithCombinationNode = skeletonGraph.clone();
+      skeletonGraphWithCombinationNode.setSCGraph(true);
       skeletonGraphWithCombinationNode.setName(desc + "_SC");
 
       HierarchyGraph simpleHierarchyGraph = getSimpleHierarchyGraph(desc);
index 04aecf9a3ff698faa25a0f6a7f6e8305c9154251..fb9d4d5c3e54729424f8dd9903d55dc8812d427e 100644 (file)
@@ -266,7 +266,7 @@ public class SSJavaAnalysis {
         linearTypeCheckMethodSet.add(md);
       }
     }
-    
+
     linearTypeCheckMethodSet.addAll(sortedDescriptors);
 
   }
@@ -350,6 +350,7 @@ public class SSJavaAnalysis {
                 MethodLattice<String> locOrder =
                     new MethodLattice<String>(SSJavaAnalysis.TOP, SSJavaAnalysis.BOTTOM);
                 md2lattice.put(md, locOrder);
+                System.out.println("parsing method lattice=" + md);
                 parseMethodDefaultLatticeDefinition(cd, an.getValue(), locOrder);
                 writeLatticeDotFile(cd, md, locOrder, "");
               } else if (an.getMarker().equals(TERMINATE)) {