changes.
authoryeom <yeom>
Fri, 10 Aug 2012 01:50:41 +0000 (01:50 +0000)
committeryeom <yeom>
Fri, 10 Aug 2012 01:50:41 +0000 (01:50 +0000)
Robust/src/Analysis/SSJava/LocationInference.java
Robust/src/Analysis/SSJava/LocationInfo.java
Robust/src/Analysis/SSJava/SSJavaLattice.java

index ed44790338a728bd8dd34eb3a511a62304a3d751..d28772bb818b1eefdf14f4237788cdda80aeb438 100644 (file)
@@ -274,7 +274,7 @@ public class LocationInference {
     // dependency in the call graph
     methodDescriptorsToVisitStack.clear();
 
-    descriptorListToAnalyze.removeFirst();
+    // descriptorListToAnalyze.removeFirst();
 
     Set<MethodDescriptor> methodDescriptorToVistSet = new HashSet<MethodDescriptor>();
     methodDescriptorToVistSet.addAll(descriptorListToAnalyze);
@@ -690,7 +690,9 @@ public class LocationInference {
                 CompositeLocation inferLoc1 = generateInferredCompositeLocation(methodInfo, tuple1);
                 CompositeLocation inferLoc2 = generateInferredCompositeLocation(methodInfo, tuple2);
 
-                addRelation(methodLattice, methodInfo, inferLoc1, inferLoc2);
+                // addRelation(methodLattice, methodInfo, inferLoc1, inferLoc2);
+
+                addFlowGraphEdge(mdCaller, argDescTuple1, argDescTuple2);
 
               }
 
@@ -750,7 +752,8 @@ public class LocationInference {
   private void addRelation(SSJavaLattice<String> methodLattice, MethodLocationInfo methodInfo,
       CompositeLocation srcInferLoc, CompositeLocation dstInferLoc) throws CyclicFlowException {
 
-    System.out.println("--- srcInferLoc=" + srcInferLoc + "  dstInferLoc=" + dstInferLoc);
+    System.out.println("addRelation --- srcInferLoc=" + srcInferLoc + "  dstInferLoc="
+        + dstInferLoc);
     String srcLocalLocSymbol = srcInferLoc.get(0).getLocIdentifier();
     String dstLocalLocSymbol = dstInferLoc.get(0).getLocIdentifier();
 
@@ -1036,42 +1039,67 @@ public class LocationInference {
           Location fieldLoc = new Location(desc, newLocSymbol);
           newInferLocation.addLocation(fieldLoc);
 
-          NTuple<Location> locTuple = flowGraph.getLocationTuple(flowNode);
-          for (int tidx = 1; tidx < locTuple.size(); tidx++) {
-            Location cur = locTuple.get(tidx);
-            Descriptor enclosingDesc = cur.getDescriptor();
-            Descriptor curDesc = cur.getLocDescriptor();
-            Location inferLocElement;
-            if (curDesc == null) {
-              // in this case, we have a newly generated location.
-              inferLocElement = new Location(enclosingDesc, cur.getLocIdentifier());
-            } else {
-              String fieldLocSymbol =
-                  getLocationInfo(enclosingDesc).getInferLocation(curDesc).get(0)
-                      .getLocIdentifier();
-              inferLocElement = new Location(enclosingDesc, fieldLocSymbol);
-              inferLocElement.setLocDescriptor(curDesc);
-            }
-            newInferLocation.addLocation(inferLocElement);
+          if (flowNode.getDescTuple().size() == 1) {
+            // maps local variable to location types of the common prefix
+            methodInfo.mapDescriptorToLocation(localVarDesc, newInferLocation.clone());
           }
 
-          methodInfo.mapDescriptorToLocation(localVarDesc, newInferLocation);
+          // methodInfo.mapDescriptorToLocation(localVarDesc, newInferLocation);
           addMapLocSymbolToInferredLocation(methodInfo.getMethodDesc(), localVarDesc,
               newInferLocation);
           methodInfo.removeMaplocalVarToLocSet(localVarDesc);
 
+          // add the field/var descriptor to the set of the location symbol
+          int flowNodeTupleSize = flowNode.getDescTuple().size();
+          Descriptor lastFlowNodeDesc = flowNode.getDescTuple().get(flowNodeTupleSize - 1);
+          int inferLocSize = newInferLocation.getSize();
+          Location lastLoc = newInferLocation.get(inferLocSize - 1);
+          Descriptor enclosingDesc = lastLoc.getDescriptor();
+          getLocationInfo(enclosingDesc).addMapLocSymbolToDescSet(lastLoc.getLocIdentifier(),
+              lastFlowNodeDesc);
+
+          // clean up the previous location
+          // Location prevInferLocElement =
+          // inferLocation.get(inferLocation.getSize() - 1);
+          // Descriptor prevEnclosingDesc = prevInferLocElement.getDescriptor();
+          //
+          // SSJavaLattice<String> targetLattice;
+          // LocationInfo targetInfo;
+          // if (prevEnclosingDesc.equals(methodInfo.getMethodDesc())) {
+          // targetLattice = methodLattice;
+          // targetInfo = methodInfo;
+          // } else {
+          // targetLattice = getLattice(prevInferLocElement.getDescriptor());
+          // targetInfo = getLocationInfo(prevInferLocElement.getDescriptor());
+          // }
+          //
+          // Set<Pair<Descriptor, Descriptor>> associstedDescSet =
+          // targetInfo.getRelatedInferLocSet(prevInferLocElement.getLocIdentifier());
+          //
+          // if (associstedDescSet.size() == 1) {
+          // targetLattice.remove(prevInferLocElement.getLocIdentifier());
+          // } else {
+          // associstedDescSet.remove(lastFlowNodeDesc);
+          // }
+
         }
 
+        System.out.println("ASSIGN NEW COMPOSITE LOCATION =" + newInferLocation + "    to "
+            + flowNode);
+
         String newlyInsertedLocName =
-            newInferLocation.get(inferLocation.getSize() - 1).getLocIdentifier();
+            newInferLocation.get(newInferLocation.getSize() - 1).getLocIdentifier();
 
+        System.out.println("-- add in-flow");
         for (Iterator iterator = incomingCommonPrefixSet.iterator(); iterator.hasNext();) {
           NTuple<Location> tuple = (NTuple<Location>) iterator.next();
+          System.out.println("--in-flow tuple=" + tuple);
           Location loc = tuple.get(idx);
           String higher = locInfo.getFieldInferLocation(loc.getLocDescriptor()).getLocIdentifier();
           addRelationHigherToLower(lattice, locInfo, higher, newlyInsertedLocName);
         }
 
+        System.out.println("-- add local in-flow");
         for (Iterator iterator = localInNodeSet.iterator(); iterator.hasNext();) {
           FlowNode localNode = (FlowNode) iterator.next();
 
@@ -1093,6 +1121,7 @@ public class LocationInference {
 
         }
 
+        System.out.println("-- add out flow");
         for (Iterator iterator = reachableCommonPrefixSet.iterator(); iterator.hasNext();) {
           NTuple<Location> tuple = (NTuple<Location>) iterator.next();
           if (tuple.size() > idx) {
@@ -1102,6 +1131,7 @@ public class LocationInference {
           }
         }
 
+        System.out.println("-- add local out flow");
         for (Iterator iterator = localOutNodeSet.iterator(); iterator.hasNext();) {
           FlowNode localOutNode = (FlowNode) iterator.next();
 
@@ -1122,6 +1152,7 @@ public class LocationInference {
 
           }
         }
+        System.out.println("-- end of add local out flow");
 
         return true;
       }
@@ -1168,6 +1199,8 @@ public class LocationInference {
   private void addRelationHigherToLower(SSJavaLattice<String> lattice, LocationInfo locInfo,
       String higher, String lower) throws CyclicFlowException {
 
+    System.out.println("---addRelationHigherToLower " + higher + " -> " + lower
+        + " to the lattice of " + locInfo.getDescIdentifier());
     // if (higher.equals(lower) && lattice.isSharedLoc(higher)) {
     // return;
     // }
@@ -1196,14 +1229,14 @@ public class LocationInference {
 
       String newSharedLoc = "SharedLoc" + (SSJavaLattice.seed++);
 
-      System.out.println("$$$ASSIGN NEW SHARED LOC=" + newSharedLoc + "   to  " + cycleElementSet);
+      System.out.println("---ASSIGN NEW SHARED LOC=" + newSharedLoc + "   to  " + cycleElementSet);
       lattice.mergeIntoSharedLocation(cycleElementSet, newSharedLoc);
 
       for (Iterator iterator = cycleElementSet.iterator(); iterator.hasNext();) {
         String oldLocSymbol = (String) iterator.next();
 
         Set<Pair<Descriptor, Descriptor>> inferLocSet = locInfo.getRelatedInferLocSet(oldLocSymbol);
-        System.out.println("$$$update related locations=" + inferLocSet);
+        System.out.println("---update related locations=" + inferLocSet);
         for (Iterator iterator2 = inferLocSet.iterator(); iterator2.hasNext();) {
           Pair<Descriptor, Descriptor> pair = (Pair<Descriptor, Descriptor>) iterator2.next();
           Descriptor enclosingDesc = pair.getFirst();
@@ -1226,7 +1259,7 @@ public class LocationInference {
           } else {
             inferLoc = getLocationInfo(enclosingDesc).getInferLocation(desc);
           }
-          System.out.println("$$$New Infer Loc=" + inferLoc);
+          System.out.println("---New Infer Loc=" + inferLoc);
 
         }
         locInfo.removeRelatedInferLocSet(oldLocSymbol, newSharedLoc);
@@ -1597,7 +1630,8 @@ public class LocationInference {
     switch (en.kind()) {
 
     case Kind.AssignmentNode:
-      analyzeFlowAssignmentNode(md, nametable, (AssignmentNode) en, base, implicitFlowTupleSet);
+      analyzeFlowAssignmentNode(md, nametable, (AssignmentNode) en, nodeSet, base,
+          implicitFlowTupleSet);
       break;
 
     case Kind.FieldAccessNode:
@@ -2061,7 +2095,8 @@ public class LocationInference {
   }
 
   private void analyzeFlowAssignmentNode(MethodDescriptor md, SymbolTable nametable,
-      AssignmentNode an, NTuple<Descriptor> base, NodeTupleSet implicitFlowTupleSet) {
+      AssignmentNode an, NodeTupleSet nodeSet, NTuple<Descriptor> base,
+      NodeTupleSet implicitFlowTupleSet) {
 
     NodeTupleSet nodeSetRHS = new NodeTupleSet();
     NodeTupleSet nodeSetLHS = new NodeTupleSet();
@@ -2135,6 +2170,9 @@ public class LocationInference {
 
     }
 
+    if (nodeSet != null) {
+      nodeSet.addTupleSet(nodeSetLHS);
+    }
   }
 
   public FlowGraph getFlowGraph(MethodDescriptor md) {
index 048f5cf1c492f013245ab92f560245df71f5ded5..12f8d38bceb200e8fdc4d1e8aab8f10c80e60eb7 100644 (file)
@@ -2,7 +2,6 @@ package Analysis.SSJava;
 
 import java.util.HashMap;
 import java.util.HashSet;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 
@@ -30,6 +29,15 @@ public class LocationInfo {
     this.cd = cd;
   }
 
+  public Descriptor getDescIdentifier() {
+    if (md != null) {
+      return md;
+    }
+    {
+      return cd;
+    }
+  }
+
   public Map<String, Set<Descriptor>> getMapLocSymbolToDescSet() {
     return mapLocSymbolToDescSet;
   }
@@ -97,6 +105,7 @@ public class LocationInfo {
   public void removeRelatedInferLocSet(String oldLocSymbol, String newSharedLoc) {
     Set<Descriptor> descSet = getDescSet(oldLocSymbol);
     getDescSet(newSharedLoc).addAll(descSet);
+    // getRelatedInferLocSet(newSharedLoc).addAll(getRelatedInferLocSet(oldLocSymbol));
     mapLocSymbolToDescSet.remove(oldLocSymbol);
     mapLocSymbolToRelatedInferLocSet.remove(oldLocSymbol);
   }
index c7b89709142052a64b51db96a750558a38ca59eb..89ca9af541c0a4ee5ffbc4fcbe04a86b249c9872 100644 (file)
@@ -91,6 +91,7 @@ public class SSJavaLattice<T> extends Lattice<T> {
         getInBetweenElements(cur, end, elementSet);
       }
     }
+    System.out.println("            start=" + start + " end=" + end + "   element=" + elementSet);
   }
 
   public void mergeIntoSharedLocation(Set<T> cycleSet, T newLoc) {
@@ -149,6 +150,34 @@ public class SSJavaLattice<T> extends Lattice<T> {
 
   }
 
+  public void remove(T loc) {
+
+    Set<T> keySet = getKeySet();
+
+    Set<T> inSet = new HashSet<T>();
+    for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
+      T keyElement = (T) iterator.next();
+      Set<T> connectedSet = get(keyElement);
+      if (connectedSet.contains(loc)) {
+        inSet.add(loc);
+        connectedSet.remove(loc);
+      }
+    }
+
+    Set<T> outSet = get(loc);
+
+    for (Iterator iterator = inSet.iterator(); iterator.hasNext();) {
+      T in = (T) iterator.next();
+      for (Iterator iterator2 = outSet.iterator(); iterator2.hasNext();) {
+        T out = (T) iterator2.next();
+        put(in, out);
+      }
+    }
+
+    getTable().remove(loc);
+
+  }
+
   public void substituteLocation(T oldLoc, T newLoc) {
     // the new location is going to take all relations of the old location
     if (!getKeySet().contains(newLoc)) {