changes on global composite assignment translation and pcloc generation
authoryeom <yeom>
Sat, 20 Oct 2012 06:26:37 +0000 (06:26 +0000)
committeryeom <yeom>
Sat, 20 Oct 2012 06:26:37 +0000 (06:26 +0000)
Robust/src/Analysis/SSJava/BuildLattice.java
Robust/src/Analysis/SSJava/FlowDownCheck.java
Robust/src/Analysis/SSJava/FlowGraph.java
Robust/src/Analysis/SSJava/LocationInference.java

index de569443291e459a4539c2616c03d97a59739790..2df41320b448f7dae328ff70a693ff5fdc94a8ac 100644 (file)
@@ -257,6 +257,7 @@ public class BuildLattice {
       Set<HNode> visited, Map<TripleItem, String> mapIntermediateLoc, LocationSummary locSummary,
       HNode cnode) {
 
       Set<HNode> visited, Map<TripleItem, String> mapIntermediateLoc, LocationSummary locSummary,
       HNode cnode) {
 
+    System.out.println("expandCombinationNode=" + cnode);
     // expand the combination node 'outNode'
     // here we need to expand the corresponding combination location in the lattice
     HNode combinationNodeInSCGraph = getCombinationNodeInSCGraph(desc, cnode);
     // expand the combination node 'outNode'
     // here we need to expand the corresponding combination location in the lattice
     HNode combinationNodeInSCGraph = getCombinationNodeInSCGraph(desc, cnode);
@@ -292,9 +293,9 @@ public class BuildLattice {
           mapIntermediateLoc, 1, locSummary, cnode);
     } else {
       endCombNodeSet.add(LocationInference.BOTTOMHNODE);
           mapIntermediateLoc, 1, locSummary, cnode);
     } else {
       endCombNodeSet.add(LocationInference.BOTTOMHNODE);
-      System.out.println("---endCombNodeSet is zero");
-      System.out.println("---endNodeSetFromSimpleGraph=" + endNodeSetFromSimpleGraph);
-      System.out.println("---incoming=" + simpleGraph.getIncomingNodeSet(cnode));
+      // System.out.println("---endCombNodeSet is zero");
+      // System.out.println("---endNodeSetFromSimpleGraph=" + endNodeSetFromSimpleGraph);
+      // System.out.println("---incoming=" + simpleGraph.getIncomingNodeSet(cnode));
       recurDFS(desc, lattice, combinationNodeInSCGraph, endCombNodeSet, visited,
           mapIntermediateLoc, 1, locSummary, cnode);
 
       recurDFS(desc, lattice, combinationNodeInSCGraph, endCombNodeSet, visited,
           mapIntermediateLoc, 1, locSummary, cnode);
 
@@ -511,18 +512,32 @@ public class BuildLattice {
     }
     locSummary.addMapHNodeNameToLocationName(curNode.getName(), locName);
 
     }
     locSummary.addMapHNodeNameToLocationName(curNode.getName(), locName);
 
-    // System.out.println("-TripleItem=" + item);
-    // System.out.println("-curNode=" + curNode.getName() + " locName=" + locName);
+    if (curNode.isSharedNode()) {
+      lattice.addSharedLoc(locName);
+    }
+    System.out.println("-TripleItem=" + item);
+    System.out.println("-curNode=" + curNode.getName() + " S=" + curNode.isSharedNode()
+        + " locName=" + locName);
 
     Set<HNode> outSet = graph.getOutgoingNodeSet(curNode);
     for (Iterator iterator2 = outSet.iterator(); iterator2.hasNext();) {
       HNode outNode = (HNode) iterator2.next();
 
     Set<HNode> outSet = graph.getOutgoingNodeSet(curNode);
     for (Iterator iterator2 = outSet.iterator(); iterator2.hasNext();) {
       HNode outNode = (HNode) iterator2.next();
+      // System.out.println("recurDFS outNode=" + outNode);
+      // System.out.println("---cur combinationNodeInSCGraph=" + combinationNodeInSCGraph);
+      // System.out.println("---outNode combinationNodeInSCGraph="
+      // + getCombinationNodeInSCGraph(desc, outNode));
       if (!outNode.isSkeleton() && !visited.contains(outNode)) {
       if (!outNode.isSkeleton() && !visited.contains(outNode)) {
-        if (combinationNodeInSCGraph.equals(getCombinationNodeInSCGraph(desc, outNode))) {
-          visited.add(outNode);
-          recurDFS(desc, lattice, combinationNodeInSCGraph, endNodeSet, visited,
-              mapIntermediateLoc, idx + 1, locSummary, outNode);
+        if (outNode.isCombinationNode()) {
+          // check whether the next combination node is different from the current node
+          if (combinationNodeInSCGraph.equals(getCombinationNodeInSCGraph(desc, outNode))) {
+            visited.add(outNode);
+            recurDFS(desc, lattice, combinationNodeInSCGraph, endNodeSet, visited,
+                mapIntermediateLoc, idx + 1, locSummary, outNode);
+          } else {
+            expandCombinationNode(desc, lattice, visited, mapIntermediateLoc, locSummary, outNode);
+          }
         }
         }
+
       }
     }
 
       }
     }
 
index 825a7479383e19c9ebe455b07fd238c7277a0f58..8f5ae45ecd19d9c5eeea9c307d3793d6a7d926b0 100644 (file)
@@ -354,14 +354,19 @@ public class FlowDownCheck {
     if (!md.getReturnType().isVoid() && !ssjava.getMethodContainingSSJavaLoop().equals(md)) {
       MethodLattice<String> methodLattice = ssjava.getMethodLattice(md);
       String thisLocId = methodLattice.getThisLoc();
     if (!md.getReturnType().isVoid() && !ssjava.getMethodContainingSSJavaLoop().equals(md)) {
       MethodLattice<String> methodLattice = ssjava.getMethodLattice(md);
       String thisLocId = methodLattice.getThisLoc();
-      if ((!md.isStatic()) && thisLocId == null) {
-        throw new Error("Method '" + md + "' does not have the definition of 'this' location at "
-            + md.getClassDesc().getSourceFileName());
+      if ((!md.isStatic())) {
+
+        if (thisLocId == null) {
+          throw new Error("Method '" + md + "' does not have the definition of 'this' location at "
+              + md.getClassDesc().getSourceFileName());
+        }
+
+        CompositeLocation thisLoc = new CompositeLocation(new Location(md, thisLocId));
+        paramList.add(0, thisLoc);
+        md2ReturnLocGen.put(md, new ReturnLocGenerator(md2ReturnLoc.get(md), md, paramList, md
+            + " of " + cd.getSourceFileName()));
       }
       }
-      CompositeLocation thisLoc = new CompositeLocation(new Location(md, thisLocId));
-      paramList.add(0, thisLoc);
-      md2ReturnLocGen.put(md, new ReturnLocGenerator(md2ReturnLoc.get(md), md, paramList, md
-          + " of " + cd.getSourceFileName()));
+
     }
 
     // fourth, check declarations inside of method
     }
 
     // fourth, check declarations inside of method
@@ -696,15 +701,14 @@ public class FlowDownCheck {
   private CompositeLocation checkLocationFromIfStatementNode(MethodDescriptor md,
       SymbolTable nametable, IfStatementNode isn, CompositeLocation constraint) {
 
   private CompositeLocation checkLocationFromIfStatementNode(MethodDescriptor md,
       SymbolTable nametable, IfStatementNode isn, CompositeLocation constraint) {
 
+    System.out.println("checkLocationFromIfStatementNode="+isn);
     CompositeLocation condLoc =
         checkLocationFromExpressionNode(md, nametable, isn.getCondition(), new CompositeLocation(),
             constraint, false);
 
     CompositeLocation condLoc =
         checkLocationFromExpressionNode(md, nametable, isn.getCondition(), new CompositeLocation(),
             constraint, false);
 
-    System.out.println("checkLocationFromIfStatementNode=" + isn.getCondition().printNode(0));
-    System.out.println("---old constraints=" + constraint);
-    // addLocationType(isn.getCondition().getType(), condLoc);
+    System.out.println("-######old constraint="+constraint);
     constraint = generateNewConstraint(constraint, condLoc);
     constraint = generateNewConstraint(constraint, condLoc);
-    System.out.println("---new constraints=" + constraint);
+    System.out.println("-######new constraint="+constraint);
     checkLocationFromBlockNode(md, nametable, isn.getTrueBlock(), constraint);
 
     if (isn.getFalseBlock() != null) {
     checkLocationFromBlockNode(md, nametable, isn.getTrueBlock(), constraint);
 
     if (isn.getFalseBlock() != null) {
@@ -1016,7 +1020,10 @@ public class FlowDownCheck {
         for (int idx = 0; idx < callerArgList.size(); idx++) {
           CompositeLocation argLocation = callerArgList.get(idx);
 
         for (int idx = 0; idx < callerArgList.size(); idx++) {
           CompositeLocation argLocation = callerArgList.get(idx);
 
-          // need to check that param is higher than PCLOC
+          // if the PC location is lower than an argument location
+          // then, need to check that the callee's the initial location for the PC is also lower
+          // than the corresponding parameter location
+
           if (!argLocation.get(0).isTop()
               && CompositeLattice.compare(argLocation, constraint, true,
                   generateErrorMessage(cd, min)) == ComparisonResult.GREATER) {
           if (!argLocation.get(0).isTop()
               && CompositeLattice.compare(argLocation, constraint, true,
                   generateErrorMessage(cd, min)) == ComparisonResult.GREATER) {
@@ -1024,10 +1031,23 @@ public class FlowDownCheck {
             CompositeLocation paramLocation = calleeParamList.get(idx);
 
             int paramCompareResult =
             CompositeLocation paramLocation = calleeParamList.get(idx);
 
             int paramCompareResult =
-                CompositeLattice.compare(calleePCLOC, paramLocation, true,
+                CompositeLattice.compare(paramLocation, calleePCLOC, true,
                     generateErrorMessage(cd, min));
                     generateErrorMessage(cd, min));
-
-            if (paramCompareResult == ComparisonResult.GREATER) {
+            // CompositeLattice.compare(calleePCLOC, paramLocation, true,
+            // generateErrorMessage(cd, min));
+
+            System.out.println("-CHECKPCLOC:");
+            System.out.println("---ARG LOC="
+                + argLocation
+                + " callerPCLOC="
+                + constraint
+                + " result="
+                + CompositeLattice.compare(argLocation, constraint, true,
+                    generateErrorMessage(cd, min)));
+            System.out.println("---PARAM LOC=" + paramLocation + " calleePCLOC=" + calleePCLOC
+                + " paramCompareResult=" + paramCompareResult);
+
+            if (paramCompareResult != ComparisonResult.GREATER) {
               throw new Error(
                   "The program counter location "
                       + constraint
               throw new Error(
                   "The program counter location "
                       + constraint
@@ -1206,11 +1226,8 @@ public class FlowDownCheck {
 
     MethodLattice<String> calleeLattice = ssjava.getMethodLattice(calleemd);
 
 
     MethodLattice<String> calleeLattice = ssjava.getMethodLattice(calleemd);
 
-    // System.out.println("checkCalleeConstraints=" + calleemd + " calleeLattice.getThisLoc()="
-    // + calleeLattice.getThisLoc());
-
-    CompositeLocation calleeThisLoc =
-        new CompositeLocation(new Location(calleemd, calleeLattice.getThisLoc()));
+    System.out.println("checkCalleeConstraints=" + calleemd + " calleeLattice.getThisLoc()="
+        + calleeLattice.getThisLoc());
 
     List<CompositeLocation> callerArgList = new ArrayList<CompositeLocation>();
     List<CompositeLocation> calleeParamList = new ArrayList<CompositeLocation>();
 
     List<CompositeLocation> callerArgList = new ArrayList<CompositeLocation>();
     List<CompositeLocation> calleeParamList = new ArrayList<CompositeLocation>();
@@ -1234,8 +1251,11 @@ public class FlowDownCheck {
 
       // setup callee params set
       // first, add callee's this location
 
       // setup callee params set
       // first, add callee's this location
-      if (!calleemd.isStatic())
+      if (!calleemd.isStatic()) {
+        CompositeLocation calleeThisLoc =
+            new CompositeLocation(new Location(calleemd, calleeLattice.getThisLoc()));
         calleeParamList.add(calleeThisLoc);
         calleeParamList.add(calleeThisLoc);
+      }
       // second, add callee's parameters
       for (int i = 0; i < calleemd.numParameters(); i++) {
         VarDescriptor calleevd = (VarDescriptor) calleemd.getParameter(i);
       // second, add callee's parameters
       for (int i = 0; i < calleemd.numParameters(); i++) {
         VarDescriptor calleevd = (VarDescriptor) calleemd.getParameter(i);
@@ -1517,6 +1537,7 @@ public class FlowDownCheck {
 
       }
     }
 
       }
     }
+
     return loc;
   }
 
     return loc;
   }
 
@@ -1524,6 +1545,7 @@ public class FlowDownCheck {
       SymbolTable nametable, FieldAccessNode fan, CompositeLocation loc,
       CompositeLocation constraint) {
 
       SymbolTable nametable, FieldAccessNode fan, CompositeLocation loc,
       CompositeLocation constraint) {
 
+
     ExpressionNode left = fan.getExpression();
     TypeDescriptor ltd = left.getType();
 
     ExpressionNode left = fan.getExpression();
     TypeDescriptor ltd = left.getType();
 
@@ -1565,6 +1587,7 @@ public class FlowDownCheck {
 
     inputGLB.add(loc);
     loc = CompositeLattice.calculateGLB(inputGLB, generateErrorMessage(md.getClassDesc(), fan));
 
     inputGLB.add(loc);
     loc = CompositeLattice.calculateGLB(inputGLB, generateErrorMessage(md.getClassDesc(), fan));
+
     return loc;
   }
 
     return loc;
   }
 
@@ -1608,6 +1631,8 @@ public class FlowDownCheck {
 
   private CompositeLocation checkLocationFromAssignmentNode(MethodDescriptor md,
       SymbolTable nametable, AssignmentNode an, CompositeLocation loc, CompositeLocation constraint) {
 
   private CompositeLocation checkLocationFromAssignmentNode(MethodDescriptor md,
       SymbolTable nametable, AssignmentNode an, CompositeLocation loc, CompositeLocation constraint) {
+
+
     ClassDescriptor cd = md.getClassDesc();
 
     Set<CompositeLocation> inputGLBSet = new HashSet<CompositeLocation>();
     ClassDescriptor cd = md.getClassDesc();
 
     Set<CompositeLocation> inputGLBSet = new HashSet<CompositeLocation>();
@@ -1635,6 +1660,7 @@ public class FlowDownCheck {
           checkLocationFromExpressionNode(md, nametable, an.getSrc(), new CompositeLocation(),
               constraint, false);
 
           checkLocationFromExpressionNode(md, nametable, an.getSrc(), new CompositeLocation(),
               constraint, false);
 
+
       if (an.getOperation().getOp() >= 2 && an.getOperation().getOp() <= 12) {
         // if assignment contains OP+EQ operator, need to merge location types
         // of LHS & RHS into the RHS
       if (an.getOperation().getOp() >= 2 && an.getOperation().getOp() <= 12) {
         // if assignment contains OP+EQ operator, need to merge location types
         // of LHS & RHS into the RHS
index d5de559852936f02440119f7098cf730ef7daeb6..77ec3d14feef03ac9e4ddb2140a3f757458164d1 100644 (file)
@@ -231,6 +231,10 @@ public class FlowGraph {
     FlowNode fromNode = getFlowNode(fromDescTuple);
     FlowNode toNode = getFlowNode(toDescTuple);
 
     FlowNode fromNode = getFlowNode(fromDescTuple);
     FlowNode toNode = getFlowNode(toDescTuple);
 
+    if (toNode.getDescTuple().get(0).equals(LocationInference.LITERALDESC)) {
+      return;
+    }
+
     // System.out.println("create an edge from " + fromNode + " to " + toNode);
 
     int fromTupleSize = fromDescTuple.size();
     // System.out.println("create an edge from " + fromNode + " to " + toNode);
 
     int fromTupleSize = fromDescTuple.size();
index 6594444c987a90ec76aef8c5baf42b6c875cae56..f09b930d3c5e77d4d94044408a0c3f19a8e009c6 100644 (file)
@@ -236,6 +236,8 @@ public class LocationInference {
 
     assignCompositeLocation();
 
 
     assignCompositeLocation();
 
+    updateFlowGraph();
+
     // calculate RETURNLOC,PCLOC
     calculateExtraLocations();
 
     // calculate RETURNLOC,PCLOC
     calculateExtraLocations();
 
@@ -273,6 +275,21 @@ public class LocationInference {
 
   }
 
 
   }
 
+  private void updateFlowGraph() {
+
+    LinkedList<MethodDescriptor> methodDescList =
+        (LinkedList<MethodDescriptor>) toanalyze_methodDescList.clone();
+
+    while (!methodDescList.isEmpty()) {
+      MethodDescriptor md = methodDescList.removeLast();
+      if (state.SSJAVADEBUG) {
+        System.out.println();
+        System.out.println("SSJAVA: Updating a flow graph: " + md);
+        propagateFlowsFromCalleesWithNoCompositeLocation(md);
+      }
+    }
+  }
+
   public Map<NTuple<Descriptor>, NTuple<Descriptor>> getMapCallerArgToCalleeParam(
       MethodInvokeNode min) {
 
   public Map<NTuple<Descriptor>, NTuple<Descriptor>> getMapCallerArgToCalleeParam(
       MethodInvokeNode min) {
 
@@ -468,6 +485,8 @@ public class LocationInference {
     Map<Location, CompositeLocation> callerMapLocToCompLoc =
         callerGraph.getMapLocationToInferCompositeLocation();
 
     Map<Location, CompositeLocation> callerMapLocToCompLoc =
         callerGraph.getMapLocationToInferCompositeLocation();
 
+    Map<Integer, NTuple<Descriptor>> mapIdxToArgTuple = mapMethodInvokeNodeToArgIdxMap.get(min);
+
     FlowGraph calleeFlowGraph = getFlowGraph(mdCallee);
     GlobalFlowGraph calleeGlobalGraph = getSubGlobalFlowGraph(mdCallee);
 
     FlowGraph calleeFlowGraph = getFlowGraph(mdCallee);
     GlobalFlowGraph calleeGlobalGraph = getSubGlobalFlowGraph(mdCallee);
 
@@ -476,8 +495,11 @@ public class LocationInference {
       baseLocTuple = translateToLocTuple(mdCaller, mapMethodInvokeNodeToBaseTuple.get(min));
     }
 
       baseLocTuple = translateToLocTuple(mdCaller, mapMethodInvokeNodeToBaseTuple.get(min));
     }
 
-    // System.out.println("\n-translate caller infer composite loc to callee=" + mdCallee
-    // + " baseLocTuple=" + baseLocTuple);
+    System.out.println("\n-#translate caller=" + mdCaller + " infer composite loc to callee="
+        + mdCallee + " baseLocTuple=" + baseLocTuple);
+    // System.out.println("-mapIdxToArgTuple=" + mapIdxToArgTuple);
+    // System.out.println("-callerMapLocToCompLoc=" + callerMapLocToCompLoc);
+
     Set<Location> keySet = callerMapLocToCompLoc.keySet();
     for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
       Location key = (Location) iterator.next();
     Set<Location> keySet = callerMapLocToCompLoc.keySet();
     for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
       Location key = (Location) iterator.next();
@@ -487,14 +509,18 @@ public class LocationInference {
 
         CompositeLocation newCalleeCompLoc;
         if (baseLocTuple != null && callerCompLoc.getTuple().startsWith(baseLocTuple)) {
 
         CompositeLocation newCalleeCompLoc;
         if (baseLocTuple != null && callerCompLoc.getTuple().startsWith(baseLocTuple)) {
-          // System.out.println("---need to translate callerCompLoc=" + callerCompLoc
+          // System.out.println("-----need to translate callerCompLoc=" + callerCompLoc
           // + " with baseTuple=" + baseLocTuple);
           newCalleeCompLoc =
               translateCompositeLocationToCallee(callerCompLoc, baseLocTuple, mdCallee);
 
           calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, newCalleeCompLoc);
           // + " with baseTuple=" + baseLocTuple);
           newCalleeCompLoc =
               translateCompositeLocationToCallee(callerCompLoc, baseLocTuple, mdCallee);
 
           calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, newCalleeCompLoc);
-          // System.out.println("---callee loc=" + key + "  newCalleeCompLoc=" + newCalleeCompLoc);
+          System.out.println("---key=" + key + "  callerCompLoc=" + callerCompLoc
+              + "  newCalleeCompLoc=" + newCalleeCompLoc);
+          System.out.println("-----baseLoctuple=" + baseLocTuple);
+          System.out.println("-----caller=" + mdCaller + "    callee=" + mdCallee);
         } else {
         } else {
+          System.out.println("2");
           // check if it is the global access
           Location compLocFirstElement = callerCompLoc.getTuple().get(0);
           if (compLocFirstElement.getDescriptor().equals(mdCallee)
           // check if it is the global access
           Location compLocFirstElement = callerCompLoc.getTuple().get(0);
           if (compLocFirstElement.getDescriptor().equals(mdCallee)
@@ -508,6 +534,33 @@ public class LocationInference {
               newCalleeCompLoc.addLocation(callerCompLoc.get(i));
             }
             calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, newCalleeCompLoc);
               newCalleeCompLoc.addLocation(callerCompLoc.get(i));
             }
             calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, newCalleeCompLoc);
+            System.out.println("---key=" + key + "  callerCompLoc=" + callerCompLoc
+                + "  newCalleeCompLoc=" + newCalleeCompLoc);
+            System.out.println("-----caller=" + mdCaller + "    callee=" + mdCallee);
+
+          } else {
+            int paramIdx = getParamIdx(callerCompLoc, mapIdxToArgTuple);
+            if (paramIdx == -1) {
+              continue;
+            }
+            NTuple<Descriptor> argTuple = mapIdxToArgTuple.get(paramIdx);
+
+            FlowNode paramFlowNode = calleeFlowGraph.getParamFlowNode(paramIdx);
+            System.out.println("-----paramIdx=" + paramIdx + "  paramFlowNode=" + paramFlowNode);
+            NTuple<Location> paramLocTuple =
+                translateToLocTuple(mdCallee, paramFlowNode.getDescTuple());
+            newCalleeCompLoc = new CompositeLocation();
+            for (int i = 0; i < paramLocTuple.size(); i++) {
+              newCalleeCompLoc.addLocation(paramLocTuple.get(i));
+            }
+            for (int i = argTuple.size(); i < callerCompLoc.getSize(); i++) {
+              newCalleeCompLoc.addLocation(callerCompLoc.get(i));
+            }
+            calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, newCalleeCompLoc);
+            System.out.println("---key=" + key + "  callerCompLoc=" + callerCompLoc
+                + "  newCalleeCompLoc=" + newCalleeCompLoc);
+            System.out.println("------argTuple=" + argTuple);
+            System.out.println("-----caller=" + mdCaller + "    callee=" + mdCallee);
 
           }
 
 
           }
 
@@ -523,7 +576,6 @@ public class LocationInference {
     // need to assign a proper composite location to the corresponding callee parameter
     // System.out.println("---translate arg composite location to callee param. min="
     // + min.printNode(0));
     // need to assign a proper composite location to the corresponding callee parameter
     // System.out.println("---translate arg composite location to callee param. min="
     // + min.printNode(0));
-    Map<Integer, NTuple<Descriptor>> mapIdxToArgTuple = mapMethodInvokeNodeToArgIdxMap.get(min);
     Set<Integer> idxSet = mapIdxToArgTuple.keySet();
     for (Iterator iterator = idxSet.iterator(); iterator.hasNext();) {
       Integer idx = (Integer) iterator.next();
     Set<Integer> idxSet = mapIdxToArgTuple.keySet();
     for (Iterator iterator = idxSet.iterator(); iterator.hasNext();) {
       Integer idx = (Integer) iterator.next();
@@ -577,6 +629,24 @@ public class LocationInference {
 
   }
 
 
   }
 
+  private int getParamIdx(CompositeLocation compLoc,
+      Map<Integer, NTuple<Descriptor>> mapIdxToArgTuple) {
+
+    // if the composite location is started with the argument descriptor
+    // return the argument's index. o.t. return -1
+
+    Set<Integer> keySet = mapIdxToArgTuple.keySet();
+    for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
+      Integer key = (Integer) iterator.next();
+      NTuple<Descriptor> argTuple = mapIdxToArgTuple.get(key);
+      if (translateToDescTuple(compLoc.getTuple()).startsWith(argTuple)) {
+        return key.intValue();
+      }
+    }
+
+    return -1;
+  }
+
   private boolean isPrimitiveType(NTuple<Descriptor> argTuple) {
 
     Descriptor lastDesc = argTuple.get(argTuple.size() - 1);
   private boolean isPrimitiveType(NTuple<Descriptor> argTuple) {
 
     Descriptor lastDesc = argTuple.get(argTuple.size() - 1);
@@ -585,9 +655,11 @@ public class LocationInference {
       return ((FieldDescriptor) lastDesc).getType().isPrimitive();
     } else if (lastDesc instanceof VarDescriptor) {
       return ((VarDescriptor) lastDesc).getType().isPrimitive();
       return ((FieldDescriptor) lastDesc).getType().isPrimitive();
     } else if (lastDesc instanceof VarDescriptor) {
       return ((VarDescriptor) lastDesc).getType().isPrimitive();
+    } else if (lastDesc instanceof InterDescriptor) {
+      return true;
     }
 
     }
 
-    return true;
+    return false;
   }
 
   private CompositeLocation translateCompositeLocationToCallee(CompositeLocation callerCompLoc,
   }
 
   private CompositeLocation translateCompositeLocationToCallee(CompositeLocation callerCompLoc,
@@ -2382,7 +2454,7 @@ public class LocationInference {
 
   private void calculatePCLOC(MethodDescriptor md) {
 
 
   private void calculatePCLOC(MethodDescriptor md) {
 
-    System.out.println("#calcualtePCLOC");
+    System.out.println("#CalculatePCLOC");
     MethodSummary methodSummary = getMethodSummary(md);
     FlowGraph fg = getFlowGraph(md);
     Map<Integer, CompositeLocation> mapParamToLoc = methodSummary.getMapParamIdxToInferLoc();
     MethodSummary methodSummary = getMethodSummary(md);
     FlowGraph fg = getFlowGraph(md);
     Map<Integer, CompositeLocation> mapParamToLoc = methodSummary.getMapParamIdxToInferLoc();
@@ -2401,19 +2473,34 @@ public class LocationInference {
       NTuple<Descriptor> paramDescTuple = paramFlowNode.getCurrentDescTuple();
       NTuple<Location> paramLocTuple = translateToLocTuple(md, paramDescTuple);
 
       NTuple<Descriptor> paramDescTuple = paramFlowNode.getCurrentDescTuple();
       NTuple<Location> paramLocTuple = translateToLocTuple(md, paramDescTuple);
 
-      if (fg.getIncomingNodeSetByPrefix(prefix).size() > 0) {
+      Set<FlowNode> inNodeToParamSet = fg.getIncomingNodeSetByPrefix(prefix);
+      if (inNodeToParamSet.size() > 0) {
         // parameter has in-value flows
         // parameter has in-value flows
-        paramLocTupleHavingInFlowSet.add(paramLocTuple);
+
+        for (Iterator iterator = inNodeToParamSet.iterator(); iterator.hasNext();) {
+          FlowNode inNode = (FlowNode) iterator.next();
+          Set<FlowEdge> outEdgeSet = fg.getOutEdgeSet(inNode);
+          for (Iterator iterator2 = outEdgeSet.iterator(); iterator2.hasNext();) {
+            FlowEdge flowEdge = (FlowEdge) iterator2.next();
+            if (flowEdge.getEndTuple().startsWith(prefix)) {
+              NTuple<Location> paramLocTupleWithIncomingFlow =
+                  translateToLocTuple(md, flowEdge.getEndTuple());
+              paramLocTupleHavingInFlowSet.add(paramLocTupleWithIncomingFlow);
+            }
+          }
+        }
+
+        // paramLocTupleHavingInFlowSet.add(paramLocTuple);
       } else {
         // paramNodeNOThavingInFlowSet.add(fg.getFlowNode(paramDescTuple));
         paramDescNOTHavingInFlowSet.add(prefix);
       }
     }
 
       } else {
         // paramNodeNOThavingInFlowSet.add(fg.getFlowNode(paramDescTuple));
         paramDescNOTHavingInFlowSet.add(prefix);
       }
     }
 
-    System.out.println("paramNodeNOThavingInFlowSet=" + paramDescNOTHavingInFlowSet);
+    System.out.println("paramLocTupleHavingInFlowSet=" + paramLocTupleHavingInFlowSet);
 
     if (paramLocTupleHavingInFlowSet.size() > 0
 
     if (paramLocTupleHavingInFlowSet.size() > 0
-        && !coversAllParamters(md, fg, paramLocTupleHavingInFlowSet)) {
+    /* && !coversAllParamters(md, fg, paramLocTupleHavingInFlowSet) */) {
 
       // Here, generates a location in the method lattice that is higher than the
       // paramLocTupleHavingInFlowSet
 
       // Here, generates a location in the method lattice that is higher than the
       // paramLocTupleHavingInFlowSet
@@ -2623,10 +2710,21 @@ public class LocationInference {
 
     Set<NTuple<Location>> paramLocTupleStartedWithThis = new HashSet<NTuple<Location>>();
 
 
     Set<NTuple<Location>> paramLocTupleStartedWithThis = new HashSet<NTuple<Location>>();
 
-    for (Iterator iterator = paramLocTupleHavingInFlowSet.iterator(); iterator.hasNext();) {
+    next: for (Iterator iterator = paramLocTupleHavingInFlowSet.iterator(); iterator.hasNext();) {
       NTuple<Location> paramLocTuple = (NTuple<Location>) iterator.next();
       NTuple<Location> paramLocTuple = (NTuple<Location>) iterator.next();
-      if (!paramLocTuple.get(0).getLocDescriptor().equals(thisVarDesc)) {
+      Descriptor paramLocalDesc = paramLocTuple.get(0).getLocDescriptor();
+      if (!paramLocalDesc.equals(thisVarDesc)) {
+
+        Set<FlowNode> inNodeSet = getFlowGraph(md).getIncomingNodeSetByPrefix(paramLocalDesc);
+        for (Iterator iterator2 = inNodeSet.iterator(); iterator2.hasNext();) {
+          FlowNode flowNode = (FlowNode) iterator2.next();
+          if (flowNode.getDescTuple().startsWith(thisVarDesc)) {
+            System.out.println("paramLocTuple=" + paramLocTuple + " is lower than THIS");
+            continue next;
+          }
+        }
         hasParamNotStartedWithThisRef = true;
         hasParamNotStartedWithThisRef = true;
+
       } else if (paramLocTuple.size() > 1) {
         paramLocTupleStartedWithThis.add(paramLocTuple);
         if (minSize == 0 || minSize > paramLocTuple.size()) {
       } else if (paramLocTuple.size() > 1) {
         paramLocTupleStartedWithThis.add(paramLocTuple);
         if (minSize == 0 || minSize > paramLocTuple.size()) {
@@ -3025,27 +3123,56 @@ public class LocationInference {
           // parameters
 
           Set<FlowNode> localReachSet = calleeFlowGraph.getLocalReachFlowNodeSetFrom(paramNode1);
           // parameters
 
           Set<FlowNode> localReachSet = calleeFlowGraph.getLocalReachFlowNodeSetFrom(paramNode1);
-          // System.out.println("-param1=" + paramNode1 + " is higher than param2=" + paramNode2);
+          System.out.println("-param1=" + paramNode1 + " is higher than param2=" + paramNode2);
           // System.out.println("-- localReachSet from param1=" + localReachSet);
 
           // System.out.println("-- localReachSet from param1=" + localReachSet);
 
+          NTuple<Descriptor> paramDescTuple1 = paramNode1.getCurrentDescTuple();
+          NTuple<Descriptor> paramDescTuple2 = paramNode2.getCurrentDescTuple();
+
+          System.out.println("-param1CurTuple=" + paramDescTuple1 + " param2CurTuple="
+              + paramDescTuple2);
+          if (paramDescTuple1.get(0).equals(paramDescTuple2.get(0))) {
+            // if two parameters share the same prefix
+            // it already has been assigned to a composite location
+            // so we don't need to add an additional ordering relation caused by these two
+            // paramters.
+            continue;
+          }
+
           if (arg1Tuple.size() > 0 && arg2Tuple.size() > 0 && localReachSet.contains(paramNode2)) {
             // need to propagate an ordering relation s.t. arg1 is higher
             // than arg2
 
           if (arg1Tuple.size() > 0 && arg2Tuple.size() > 0 && localReachSet.contains(paramNode2)) {
             // need to propagate an ordering relation s.t. arg1 is higher
             // than arg2
 
+            // add a new flow between the corresponding arguments.
+            callerFlowGraph.addValueFlowEdge(arg1Tuple, arg2Tuple);
+            System.out.println("arg1=" + arg1Tuple + "   arg2=" + arg2Tuple);
+
             // System.out
             // .println("-arg1Tuple=" + arg1Tuple + " is higher than arg2Tuple=" + arg2Tuple);
 
             // System.out
             // .println("-arg1Tuple=" + arg1Tuple + " is higher than arg2Tuple=" + arg2Tuple);
 
-            // otherwise, flows between method/field locations...
-            callerFlowGraph.addValueFlowEdge(arg1Tuple, arg2Tuple);
-            // System.out.println("arg1=" + arg1Tuple + "   arg2=" + arg2Tuple);
-
           }
 
           System.out.println();
         }
       }
     }
           }
 
           System.out.println();
         }
       }
     }
-    // System.out.println("##\n");
+
+    // if a parameter has a composite location and the first element of the parameter location
+    // matches the callee's 'this'
+    // we have a more specific constraint: the caller's corresponding argument is higher than the
+    // parameter location which is translated into the caller
+
+    for (int idx = 0; idx < numParam; idx++) {
+      FlowNode paramNode = calleeFlowGraph.getParamFlowNode(idx);
+      CompositeLocation compLoc = paramNode.getCompositeLocation();
+      if (compLoc != null) {
+        System.out.println("$$$COMPLOC CASE=" + compLoc);
+        NTuple<Descriptor> argTuple = getNodeTupleByArgIdx(min, idx);
+        NTuple<Descriptor> translatedParamTuple = translateCompositeLocationToCaller(min, compLoc);
+        System.out.println("add a flow edge= " + argTuple + "->" + translatedParamTuple);
+        callerFlowGraph.addValueFlowEdge(argTuple, translatedParamTuple);
+      }
+    }
 
   }
 
 
   }
 
@@ -3244,7 +3371,7 @@ public class LocationInference {
       tuple.add(baseTuple.get(i));
     }
 
       tuple.add(baseTuple.get(i));
     }
 
-    for (int i = 1; i < compLocForParam1.getSize(); i++) {
+    for (int i = baseTuple.size(); i < compLocForParam1.getSize(); i++) {
       Location loc = compLocForParam1.get(i);
       tuple.add(loc.getLocDescriptor());
     }
       Location loc = compLocForParam1.get(i);
       tuple.add(loc.getLocDescriptor());
     }
@@ -3784,8 +3911,8 @@ public class LocationInference {
         addValueFlowsFromCalleeSubGlobalFlowGraph(md, subGlobalFlowGraph);
         subGlobalFlowGraph.writeGraph("_SUBGLOBAL");
 
         addValueFlowsFromCalleeSubGlobalFlowGraph(md, subGlobalFlowGraph);
         subGlobalFlowGraph.writeGraph("_SUBGLOBAL");
 
-        System.out.println("-propagate Flows From Callees With No CompositeLocation");
-        propagateFlowsFromCalleesWithNoCompositeLocation(md);
+        // System.out.println("-propagate Flows From Callees With No CompositeLocation");
+        // propagateFlowsFromCalleesWithNoCompositeLocation(md);
 
       }
     }
 
       }
     }
@@ -4022,6 +4149,7 @@ public class LocationInference {
     if (needToGenerateInterLoc(newImplicitTupleSet)) {
       // need to create an intermediate node for the GLB of conditional
       // locations & implicit flows
     if (needToGenerateInterLoc(newImplicitTupleSet)) {
       // need to create an intermediate node for the GLB of conditional
       // locations & implicit flows
+
       NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
       for (Iterator<NTuple<Descriptor>> idxIter = newImplicitTupleSet.iterator(); idxIter.hasNext();) {
         NTuple<Descriptor> tuple = idxIter.next();
       NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
       for (Iterator<NTuple<Descriptor>> idxIter = newImplicitTupleSet.iterator(); idxIter.hasNext();) {
         NTuple<Descriptor> tuple = idxIter.next();
@@ -4087,7 +4215,7 @@ public class LocationInference {
       System.out.println("---currentFlowTupleSet=" + currentFlowTupleSet);
 
       if (needToGenerateInterLoc(currentFlowTupleSet)) {
       System.out.println("---currentFlowTupleSet=" + currentFlowTupleSet);
 
       if (needToGenerateInterLoc(currentFlowTupleSet)) {
-        System.out.println("---needToGenerateInterLoc");
+        System.out.println("8");
         FlowNode meetNode = fg.createIntermediateNode();
         for (Iterator iterator = currentFlowTupleSet.iterator(); iterator.hasNext();) {
           NTuple<Descriptor> currentFlowTuple = (NTuple<Descriptor>) iterator.next();
         FlowNode meetNode = fg.createIntermediateNode();
         for (Iterator iterator = currentFlowTupleSet.iterator(); iterator.hasNext();) {
           NTuple<Descriptor> currentFlowTuple = (NTuple<Descriptor>) iterator.next();
@@ -4149,6 +4277,7 @@ public class LocationInference {
       if (needToGenerateInterLoc(newImplicitTupleSet)) {
         // need to create an intermediate node for the GLB of conditional
         // locations & implicit flows
       if (needToGenerateInterLoc(newImplicitTupleSet)) {
         // need to create an intermediate node for the GLB of conditional
         // locations & implicit flows
+
         NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
         for (Iterator<NTuple<Descriptor>> idxIter = newImplicitTupleSet.iterator(); idxIter
             .hasNext();) {
         NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
         for (Iterator<NTuple<Descriptor>> idxIter = newImplicitTupleSet.iterator(); idxIter
             .hasNext();) {
@@ -4208,6 +4337,7 @@ public class LocationInference {
       if (needToGenerateInterLoc(newImplicitTupleSet)) {
         // need to create an intermediate node for the GLB of conditional
         // locations & implicit flows
       if (needToGenerateInterLoc(newImplicitTupleSet)) {
         // need to create an intermediate node for the GLB of conditional
         // locations & implicit flows
+
         NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
         for (Iterator<NTuple<Descriptor>> idxIter = newImplicitTupleSet.iterator(); idxIter
             .hasNext();) {
         NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
         for (Iterator<NTuple<Descriptor>> idxIter = newImplicitTupleSet.iterator(); idxIter
             .hasNext();) {
@@ -4253,7 +4383,7 @@ public class LocationInference {
   private void analyzeFlowIfStatementNode(MethodDescriptor md, SymbolTable nametable,
       IfStatementNode isn, NodeTupleSet implicitFlowTupleSet) {
 
   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,
 
     NodeTupleSet condTupleNode = new NodeTupleSet();
     analyzeFlowExpressionNode(md, nametable, isn.getCondition(), condTupleNode, null,
@@ -4264,9 +4394,9 @@ public class LocationInference {
     newImplicitTupleSet.addTupleSet(implicitFlowTupleSet);
     newImplicitTupleSet.addTupleSet(condTupleNode);
 
     newImplicitTupleSet.addTupleSet(implicitFlowTupleSet);
     newImplicitTupleSet.addTupleSet(condTupleNode);
 
-    // System.out.println("condTupleNode=" + condTupleNode);
-    // System.out.println("implicitFlowTupleSet=" + implicitFlowTupleSet);
-    // System.out.println("newImplicitTupleSet=" + newImplicitTupleSet);
+    // System.out.println("-condTupleNode=" + condTupleNode);
+    // System.out.println("-implicitFlowTupleSet=" + implicitFlowTupleSet);
+    // System.out.println("-newImplicitTupleSet=" + newImplicitTupleSet);
 
     if (needToGenerateInterLoc(newImplicitTupleSet)) {
 
 
     if (needToGenerateInterLoc(newImplicitTupleSet)) {
 
@@ -4307,6 +4437,7 @@ public class LocationInference {
       // creates edges from RHS to LHS
       NTuple<Descriptor> interTuple = null;
       if (needToGenerateInterLoc(nodeSetRHS)) {
       // creates edges from RHS to LHS
       NTuple<Descriptor> interTuple = null;
       if (needToGenerateInterLoc(nodeSetRHS)) {
+
         interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
       }
 
         interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
       }
 
@@ -4478,8 +4609,6 @@ public class LocationInference {
   private void analyzeFlowMethodInvokeNode(MethodDescriptor md, SymbolTable nametable,
       MethodInvokeNode min, NodeTupleSet nodeSet, NodeTupleSet implicitFlowTupleSet) {
 
   private void analyzeFlowMethodInvokeNode(MethodDescriptor md, SymbolTable nametable,
       MethodInvokeNode min, NodeTupleSet nodeSet, NodeTupleSet implicitFlowTupleSet) {
 
-    System.out.println("analyzeFlowMethodInvokeNode=" + min.printNode(0));
-
     mapMethodInvokeNodeToArgIdxMap.put(min, new HashMap<Integer, NTuple<Descriptor>>());
 
     if (nodeSet == null) {
     mapMethodInvokeNodeToArgIdxMap.put(min, new HashMap<Integer, NTuple<Descriptor>>());
 
     if (nodeSet == null) {
@@ -4541,7 +4670,6 @@ public class LocationInference {
         }
 
       }
         }
 
       }
-
       // analyze parameter flows
 
       if (min.numArgs() > 0) {
       // analyze parameter flows
 
       if (min.numArgs() > 0) {
@@ -4578,6 +4706,19 @@ public class LocationInference {
           addArgIdxMap(min, idx, argTuple);
 
           FlowNode paramNode = calleeFlowGraph.getParamFlowNode(idx);
           addArgIdxMap(min, idx, argTuple);
 
           FlowNode paramNode = calleeFlowGraph.getParamFlowNode(idx);
+
+          // check whether a param node in the callee graph has incoming flows
+          // if it has incoming flows, the corresponding arg should be lower than the current PC
+          // Descriptor prefix = paramNode.getDescTuple().get(0);
+          // if (calleeFlowGraph.getIncomingNodeSetByPrefix(prefix).size() > 0) {
+          // for (Iterator<NTuple<Descriptor>> iterator = implicitFlowTupleSet.iterator(); iterator
+          // .hasNext();) {
+          // NTuple<Descriptor> pcTuple = iterator.next();
+          // System.out.println("add edge pcTuple =" + pcTuple + " -> " + argTuple);
+          // addFlowGraphEdge(md, pcTuple, argTuple);
+          // }
+          // }
+
           if (hasInFlowTo(calleeFlowGraph, paramNode, calleeReturnSet)
               || calleeMethodDesc.getModifiers().isNative()) {
             addParamNodeFlowingToReturnValue(calleeMethodDesc, paramNode);
           if (hasInFlowTo(calleeFlowGraph, paramNode, calleeReturnSet)
               || calleeMethodDesc.getModifiers().isNative()) {
             addParamNodeFlowingToReturnValue(calleeMethodDesc, paramNode);
@@ -4599,7 +4740,7 @@ public class LocationInference {
 
     // Set<FlowNode> reachableSet = fg.getReachFlowNodeSetFrom(inNode);
     Set<FlowNode> reachableSet = fg.getReachableSetFrom(inNode.getDescTuple());
 
     // Set<FlowNode> reachableSet = fg.getReachFlowNodeSetFrom(inNode);
     Set<FlowNode> reachableSet = fg.getReachableSetFrom(inNode.getDescTuple());
-    System.out.println("inNode=" + inNode + "  reachalbeSet=" + reachableSet);
+    // System.out.println("inNode=" + inNode + "  reachalbeSet=" + reachableSet);
 
     for (Iterator iterator = reachableSet.iterator(); iterator.hasNext();) {
       FlowNode fn = (FlowNode) iterator.next();
 
     for (Iterator iterator = reachableSet.iterator(); iterator.hasNext();) {
       FlowNode fn = (FlowNode) iterator.next();
@@ -4745,8 +4886,6 @@ public class LocationInference {
   private NTuple<Descriptor> analyzeFlowNameNode(MethodDescriptor md, SymbolTable nametable,
       NameNode nn, NodeTupleSet nodeSet, NTuple<Descriptor> base, NodeTupleSet implicitFlowTupleSet) {
 
   private NTuple<Descriptor> analyzeFlowNameNode(MethodDescriptor md, SymbolTable nametable,
       NameNode nn, NodeTupleSet nodeSet, NTuple<Descriptor> base, NodeTupleSet implicitFlowTupleSet) {
 
-    System.out.println("analyzeFlowNameNode=" + nn.printNode(0));
-
     if (base == null) {
       base = new NTuple<Descriptor>();
     }
     if (base == null) {
       base = new NTuple<Descriptor>();
     }