changes + add two more benchmarks without annotations
[IRC.git] / Robust / src / Analysis / SSJava / LocationInference.java
index 9ebbde3828d577fec209bc7a285dd96944e87e3d..6575d4bad7708eca4a0669d04875f7e06c32dd4e 100644 (file)
@@ -560,7 +560,6 @@ public class LocationInference {
       //
       // update return flow nodes in the caller
       CompositeLocation returnLoc = getMethodSummary(mdCallee).getRETURNLoc();
-
       System.out.println("### min=" + min.printNode(0) + "  returnLoc=" + returnLoc);
       if (returnLoc != null && returnLoc.get(0).getLocDescriptor().equals(mdCallee.getThis())
           && returnLoc.getSize() > 1) {
@@ -573,6 +572,20 @@ public class LocationInference {
         }
         System.out.println("###NEW RETURN TUPLE FOR CALLER=" + newReturnTuple);
         callerFlowGraph.getFlowReturnNode(min).setNewTuple(newReturnTuple);
+      } else {
+        // if the return loc set was empty and later pcloc was connected to the return loc
+        // need to make sure that return loc reflects to this changes.
+        FlowReturnNode flowReturnNode = callerFlowGraph.getFlowReturnNode(min);
+        if (flowReturnNode != null && flowReturnNode.getReturnTupleSet().isEmpty()) {
+
+          if (needToUpdateReturnLocHolder(min.getMethod(), flowReturnNode)) {
+            NTuple<Descriptor> baseTuple = mapMethodInvokeNodeToBaseTuple.get(min);
+            NTuple<Descriptor> newReturnTuple = baseTuple.clone();
+            flowReturnNode.addTuple(newReturnTuple);
+          }
+
+        }
+
       }
 
     }
@@ -584,6 +597,23 @@ public class LocationInference {
 
   }
 
+  private boolean needToUpdateReturnLocHolder(MethodDescriptor mdCallee,
+      FlowReturnNode flowReturnNode) {
+    FlowGraph fg = getFlowGraph(mdCallee);
+    MethodSummary summary = getMethodSummary(mdCallee);
+    CompositeLocation returnCompLoc = summary.getRETURNLoc();
+    NTuple<Descriptor> returnDescTuple = translateToDescTuple(returnCompLoc.getTuple());
+    Set<FlowNode> incomingNodeToReturnNode =
+        fg.getIncomingFlowNodeSet(fg.getFlowNode(returnDescTuple));
+    for (Iterator iterator = incomingNodeToReturnNode.iterator(); iterator.hasNext();) {
+      FlowNode inNode = (FlowNode) iterator.next();
+      if (inNode.getDescTuple().get(0).equals(mdCallee.getThis())) {
+        return true;
+      }
+    }
+    return false;
+  }
+
   private void addMapMethodDescToMethodInvokeNodeSet(MethodInvokeNode min) {
     MethodDescriptor md = min.getMethod();
     if (!mapMethodDescToMethodInvokeNodeSet.containsKey(md)) {
@@ -1344,31 +1374,11 @@ public class LocationInference {
       for (Iterator iterator2 = keySet.iterator(); iterator2.hasNext();) {
         Integer argIdx = (Integer) iterator2.next();
         NTuple<Descriptor> argTuple = map.get(argIdx);
-        // System.out.println("argTuple=" + argTuple);
-        // if (argIdx == 0 && !min.getMethod().isStatic()) {
-        // ClassDescriptor currentMethodThisType = getClassTypeDescriptor(argTuple.get(0));
-        //
-        // for (int i = 0; i < curPrefix.size(); i++) {
-        // ClassDescriptor prefixType =
-        // getClassTypeDescriptor(curPrefix.get(i).getLocDescriptor());
-        // if (prefixType != null && prefixType.equals(currentMethodThisType)) {
-        // System.out.println("PREFIX TYPE MATCHES WITH=" + currentMethodThisType);
-        // for (Iterator iterator3 = subGlobalReachableSet.iterator(); iterator3.hasNext();) {
-        // GlobalFlowNode subGlobalReachalbeNode = (GlobalFlowNode) iterator3.next();
-        // if (subGlobalReachalbeNode.getLocTuple().get(0).getLocDescriptor()
-        // .equals(md.getThis())) {
-        // System.out.println("PREFIX FOUND=" + subGlobalReachalbeNode);
-        // System.out.println("here4?!");
-        //
-        // return true;
-        // }
-        // }
-        // }
-        // }
-        //
-        // }
+
         if (!(!md.isStatic() && argIdx == 0)) {
-          if (argTuple.get(argTuple.size() - 1).equals(lastLocationOfPrefix.getLocDescriptor())) {
+          // if the argTuple is empty, we don't need to do with anything(LITERAL CASE).
+          if (argTuple.size() > 0
+              && argTuple.get(argTuple.size() - 1).equals(lastLocationOfPrefix.getLocDescriptor())) {
             NTuple<Location> locTuple =
                 translateToLocTuple(md, flowGraph.getParamFlowNode(argIdx).getDescTuple());
             lastLocationOfPrefix = locTuple.get(0);
@@ -1776,6 +1786,29 @@ public class LocationInference {
     return false;
   }
 
+  public static boolean isReference(Descriptor desc) {
+
+    if (desc instanceof FieldDescriptor) {
+
+      TypeDescriptor type = ((FieldDescriptor) desc).getType();
+      if (type.isArray()) {
+        return false;
+      } else {
+        return type.isPtr();
+      }
+
+    } else if (desc instanceof VarDescriptor) {
+      TypeDescriptor type = ((VarDescriptor) desc).getType();
+      if (type.isArray()) {
+        return false;
+      } else {
+        return type.isPtr();
+      }
+    }
+
+    return false;
+  }
+
   private NTuple<Descriptor> translateToDescTuple(NTuple<Location> locTuple) {
 
     NTuple<Descriptor> descTuple = new NTuple<Descriptor>();
@@ -3146,9 +3179,11 @@ public class LocationInference {
     // calculate a return location:
     // the return location type is lower than all parameters and the location of return values
     MethodSummary methodSummary = getMethodSummary(md);
-    if (methodSummary.getRETURNLoc() != null) {
-      return;
-    }
+    // if (methodSummary.getRETURNLoc() != null) {
+    // System.out.println("$HERE?");
+    // return;
+    // }
+
     FlowGraph fg = getFlowGraph(md);
     Map<Integer, CompositeLocation> mapParamToLoc = methodSummary.getMapParamIdxToInferLoc();
     Set<Integer> paramIdxSet = mapParamToLoc.keySet();
@@ -3196,6 +3231,13 @@ public class LocationInference {
 
       }
 
+      // makes sure that PCLOC is higher than RETURNLOC
+      CompositeLocation pcLoc = methodSummary.getPCLoc();
+      if (!pcLoc.get(0).isTop()) {
+        NTuple<Descriptor> pcLocDescTuple = translateToDescTuple(pcLoc.getTuple());
+        fg.addValueFlowEdge(pcLocDescTuple, returnDescTuple);
+      }
+
     }
 
   }
@@ -3255,7 +3297,8 @@ public class LocationInference {
     } else {
       // all parameter is started with 'this', so PCLOC will be set relative to the composite
       // location started with 'this'.
-      for (int idx = 0; idx < minSize - 1; idx++) {
+      // for (int idx = 0; idx < minSize - 1; idx++) {
+      for (int idx = 0; idx < 1; idx++) {
         Set<Descriptor> locDescSet = new HashSet<Descriptor>();
         Location curLoc = null;
         NTuple<Location> paramLocTuple = null;
@@ -3887,8 +3930,10 @@ public class LocationInference {
           + "   idx=" + idx);
       if (!srcFieldDesc.equals(dstFieldDesc)) {
         // add a new edge
+        System.out.println("-ADD EDGE");
         getHierarchyGraph(cd).addEdge(srcFieldDesc, dstFieldDesc);
-      } else if (isPrimitive(srcFieldDesc) && isPrimitive(dstFieldDesc)) {
+      } else if (!isReference(srcFieldDesc) && !isReference(dstFieldDesc)) {
+        System.out.println("-ADD EDGE");
         getHierarchyGraph(cd).addEdge(srcFieldDesc, dstFieldDesc);
       }
 
@@ -4827,16 +4872,16 @@ public class LocationInference {
           // that node if needed
           if (argTuple.size() > 0
               && (argTuple.get(0).equals(GLOBALDESC) || argTuple.get(0).equals(LITERALDESC))) {
-            System.out.println("***GLOBAL ARG TUPLE CASE=" + argTuple);
-            System.out.println("8");
-
-            NTuple<Descriptor> interTuple =
-                getFlowGraph(mdCaller).createIntermediateNode().getDescTuple();
-            ((InterDescriptor) interTuple.get(0)).setMethodArgIdxPair(min, idx);
-            addFlowGraphEdge(mdCaller, argTuple, interTuple);
-            argTuple = interTuple;
-            addArgIdxMap(min, idx, argTuple);
-            System.out.println("new min mapping i=" + idx + "  ->" + argTuple);
+            /*
+             * System.out.println("***GLOBAL ARG TUPLE CASE=" + argTuple); System.out.println("8");
+             * 
+             * NTuple<Descriptor> interTuple =
+             * getFlowGraph(mdCaller).createIntermediateNode().getDescTuple(); ((InterDescriptor)
+             * interTuple.get(0)).setMethodArgIdxPair(min, idx); addFlowGraphEdge(mdCaller,
+             * argTuple, interTuple); argTuple = interTuple; addArgIdxMap(min, idx, argTuple);
+             * System.out.println("new min mapping i=" + idx + "  ->" + argTuple);
+             */
+            argTuple = new NTuple<Descriptor>();
           }
 
           addArgIdxMap(min, idx, argTuple);
@@ -5337,10 +5382,10 @@ public class LocationInference {
       analyzeFlowExpressionNode(md, nametable, an.getSrc(), nodeSetRHS, null, implicitFlowTupleSet,
           false);
 
-      // System.out.println("-analyzeFlowAssignmentNode=" + an.printNode(0));
-      // System.out.println("-nodeSetLHS=" + nodeSetLHS);
-      // System.out.println("-nodeSetRHS=" + nodeSetRHS);
-      // System.out.println("-implicitFlowTupleSet=" + implicitFlowTupleSet);
+      System.out.println("-analyzeFlowAssignmentNode=" + an.printNode(0));
+      System.out.println("-nodeSetLHS=" + nodeSetLHS);
+      System.out.println("-nodeSetRHS=" + nodeSetRHS);
+      System.out.println("-implicitFlowTupleSet=" + implicitFlowTupleSet);
       // System.out.println("-");
 
       if (an.getOperation().getOp() >= 2 && an.getOperation().getOp() <= 12) {
@@ -5359,7 +5404,6 @@ public class LocationInference {
       NTuple<Descriptor> interTuple = null;
       if (needToGenerateInterLoc(nodeSetRHS)) {
         System.out.println("2");
-
         interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
       }
 
@@ -5504,7 +5548,6 @@ public class LocationInference {
 
           String highLocId = pair.getFirst();
           String lowLocId = pair.getSecond();
-          System.out.println("addedLocSet=" + addedLocSet);
           if (!addedLocSet.contains(highLocId)) {
             addedLocSet.add(highLocId);
             drawNode(bw, locOrder, simpleHierarchyGraph, highLocId);