From ce668fac9745b666e401dc1a036754da8af3564c Mon Sep 17 00:00:00 2001 From: yeom Date: Wed, 15 Aug 2012 02:45:30 +0000 Subject: [PATCH] changes. --- Robust/src/Analysis/SSJava/FlowGraph.java | 36 +- .../Analysis/SSJava/LocationInference.java | 409 +++++++++++++----- .../Analysis/SSJava/MethodLocationInfo.java | 10 + .../src/Analysis/SSJava/SSJavaAnalysis.java | 1 + 4 files changed, 352 insertions(+), 104 deletions(-) diff --git a/Robust/src/Analysis/SSJava/FlowGraph.java b/Robust/src/Analysis/SSJava/FlowGraph.java index 8522f2ef..39d70614 100644 --- a/Robust/src/Analysis/SSJava/FlowGraph.java +++ b/Robust/src/Analysis/SSJava/FlowGraph.java @@ -34,6 +34,9 @@ public class FlowGraph { // maps a paramter descriptor to its index Map mapParamDescToIdx; + + Map mapIdxToFlowNode; + boolean debug = true; public FlowGraph(MethodDescriptor md, Map mapParamDescToIdx) { @@ -46,6 +49,7 @@ public class FlowGraph { this.mapParamDescToIdx = new HashMap(); this.mapParamDescToIdx.putAll(mapParamDescToIdx); this.returnNodeSet = new HashSet(); + this.mapIdxToFlowNode = new HashMap(); if (!md.isStatic()) { // create a node for 'this' varialbe @@ -58,6 +62,25 @@ public class FlowGraph { thisVarNode = thisNode; } + setupMapIdxToDesc(); + + } + + private void setupMapIdxToDesc() { + + Set descSet = mapParamDescToIdx.keySet(); + for (Iterator iterator = descSet.iterator(); iterator.hasNext();) { + Descriptor paramDesc = (Descriptor) iterator.next(); + int idx = mapParamDescToIdx.get(paramDesc); + NTuple descTuple = new NTuple(); + descTuple.add(paramDesc); + mapIdxToFlowNode.put(idx, getFlowNode(descTuple)); + } + + } + + public FlowNode getParamFlowNode(int idx) { + return mapIdxToFlowNode.get(idx); } public Set getNodeSet() { @@ -90,7 +113,16 @@ public class FlowGraph { } public boolean isParamDesc(Descriptor desc) { - return mapParamDescToIdx.containsKey(desc); + + if (mapParamDescToIdx.containsKey(desc)) { + int idx = mapParamDescToIdx.get(desc); + if (!md.isStatic() && idx == 0) { + return false; + } + return true; + } + + return false; } public boolean hasEdge(NTuple fromDescTuple, NTuple toDescTuple) { @@ -183,7 +215,7 @@ public class FlowGraph { } - public void setReturnFlowNode(NTuple tuple) { + public void addReturnFlowNode(NTuple tuple) { if (!mapDescTupleToInferNode.containsKey(tuple)) { createNewFlowNode(tuple); diff --git a/Robust/src/Analysis/SSJava/LocationInference.java b/Robust/src/Analysis/SSJava/LocationInference.java index 6404a8f9..0716bc33 100644 --- a/Robust/src/Analysis/SSJava/LocationInference.java +++ b/Robust/src/Analysis/SSJava/LocationInference.java @@ -85,6 +85,8 @@ public class LocationInference { private Map> mapMethodToCalleeSet; + private Map> mapMethodDescToParamNodeFlowsToReturnValue; + private Map> mapFileNameToLineVector; private Map mapDescToDefinitionLine; @@ -122,17 +124,19 @@ public class LocationInference { this.mapFileNameToLineVector = new HashMap>(); this.mapDescToDefinitionLine = new HashMap(); + this.mapMethodDescToParamNodeFlowsToReturnValue = + new HashMap>(); } public void setupToAnalyze() { SymbolTable classtable = state.getClassSymbolTable(); toanalyzeList.clear(); toanalyzeList.addAll(classtable.getValueSet()); - Collections.sort(toanalyzeList, new Comparator() { - public int compare(ClassDescriptor o1, ClassDescriptor o2) { - return o1.getClassName().compareToIgnoreCase(o2.getClassName()); - } - }); + // Collections.sort(toanalyzeList, new Comparator() { + // public int compare(ClassDescriptor o1, ClassDescriptor o2) { + // return o1.getClassName().compareToIgnoreCase(o2.getClassName()); + // } + // }); } public void setupToAnalazeMethod(ClassDescriptor cd) { @@ -309,11 +313,18 @@ public class LocationInference { if (desc instanceof MethodDescriptor) { TypeDescriptor returnType = ((MethodDescriptor) desc).getReturnType(); + + MethodLocationInfo methodLocInfo = getMethodLocationInfo((MethodDescriptor) desc); + if (returnType != null && (!returnType.isVoid())) { - rtr += "\n@RETURNLOC(\"RETURNLOC\")"; + rtr += + "\n@RETURNLOC(\"" + generateLocationAnnoatation(methodLocInfo.getReturnLoc()) + "\")"; } - rtr += "\n@THISLOC(\"this\")\n@PCLOC(\"PCLOC\")\n@GLOBALLOC(\"GLOBALLOC\")"; + rtr += "\n@THISLOC(\"this\")\n@GLOBALLOC(\"GLOBALLOC\")"; + if (lattice.containsKey("PCLOC")) { + rtr += "\n@PCLOC(\"PCLOC\")"; + } } return rtr; @@ -365,7 +376,7 @@ public class LocationInference { String locAnnotationStr; if (inferLocMap.containsKey(fd)) { CompositeLocation inferLoc = inferLocMap.get(fd); - locAnnotationStr = generateLocationAnnoatation(inferLoc); + locAnnotationStr = "@LOC(\"" + generateLocationAnnoatation(inferLoc) + "\")"; } else { // if the field is not accssed by SS part, just assigns dummy // location @@ -398,7 +409,7 @@ public class LocationInference { Descriptor localVarDesc = (Descriptor) iterator.next(); CompositeLocation inferLoc = methodInferLocMap.get(localVarDesc); - String locAnnotationStr = generateLocationAnnoatation(inferLoc); + String locAnnotationStr = "@LOC(\"" + generateLocationAnnoatation(inferLoc) + "\")"; if (!isParameter(md, localVarDesc)) { if (mapDescToDefinitionLine.containsKey(localVarDesc)) { @@ -414,8 +425,16 @@ public class LocationInference { } } else { String methodDefStr = sourceVec.get(methodDefLine); - int idx = methodDefStr.indexOf(generateVarDeclaration((VarDescriptor) localVarDesc)); + + int idx = + getParamLocation(methodDefStr, + generateVarDeclaration((VarDescriptor) localVarDesc)); + + System.out.println("#methodDefStr=" + methodDefStr + " localVar=" + + generateVarDeclaration((VarDescriptor) localVarDesc) + " idx=" + idx); + assert (idx != -1); + String annoatedStr = methodDefStr.substring(0, idx) + locAnnotationStr + " " + methodDefStr.substring(idx); @@ -436,6 +455,20 @@ public class LocationInference { codeGen(); } + private int getParamLocation(String methodStr, String paramStr) { + + String pattern = paramStr + ","; + + int idx = methodStr.indexOf(pattern); + if (idx != -1) { + return idx; + } else { + pattern = paramStr + ")"; + return methodStr.indexOf(pattern); + } + + } + private String generateVarDeclaration(VarDescriptor varDesc) { TypeDescriptor td = varDesc.getType(); @@ -451,8 +484,8 @@ public class LocationInference { } private String generateLocationAnnoatation(CompositeLocation loc) { - String rtr = "@LOC(\""; + String rtr = ""; // method location Location methodLoc = loc.get(0); rtr += methodLoc.getLocIdentifier(); @@ -462,7 +495,6 @@ public class LocationInference { rtr += "," + element.getDescriptor().getSymbol() + "." + element.getLocIdentifier(); } - rtr += "\")"; return rtr; } @@ -877,36 +909,139 @@ public class LocationInference { methodInfo.addMapParamIdxToInferLoc(idx + offset, inferParamLoc); } - // calculate the initial program counter location - // PC location is higher than location types of all parameters - String pcLocSymbol = "PCLOC"; Map mapParamToLoc = methodInfo.getMapParamIdxToInferLoc(); Set keySet = mapParamToLoc.keySet(); - for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { - Integer paramIdx = (Integer) iterator.next(); - CompositeLocation inferLoc = mapParamToLoc.get(paramIdx); - String paramLocLocalSymbol = inferLoc.get(0).getLocIdentifier(); - if (!methodLattice.isGreaterThan(pcLocSymbol, paramLocLocalSymbol)) { - addRelationHigherToLower(methodLattice, methodInfo, pcLocSymbol, paramLocLocalSymbol); + + if (!ssjava.getMethodContainingSSJavaLoop().equals(md)) { + // calculate the initial program counter location + // PC location is higher than location types of all parameters + String pcLocSymbol = "PCLOC"; + for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { + Integer paramIdx = (Integer) iterator.next(); + CompositeLocation inferLoc = mapParamToLoc.get(paramIdx); + String paramLocLocalSymbol = inferLoc.get(0).getLocIdentifier(); + if (!methodLattice.isGreaterThan(pcLocSymbol, paramLocLocalSymbol)) { + addRelationHigherToLower(methodLattice, methodInfo, pcLocSymbol, paramLocLocalSymbol); + + Set higherLocSet = getHigherLocSymbolThan(methodLattice, paramLocLocalSymbol); + higherLocSet.remove(pcLocSymbol); + for (Iterator iterator2 = higherLocSet.iterator(); iterator2.hasNext();) { + String loc = (String) iterator2.next(); + addRelationHigherToLower(methodLattice, methodInfo, pcLocSymbol, loc); + } + } } } // calculate a return location - // the return location type is lower than all parameters + // the return location type is lower than all parameters and location types + // of return values if (!md.getReturnType().isVoid()) { - String returnLocSymbol = "RETURNLOC"; + // first, generate the set of return value location types that starts with + // 'this' reference - for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { - Integer paramIdx = (Integer) iterator.next(); - CompositeLocation inferLoc = mapParamToLoc.get(paramIdx); - String paramLocLocalSymbol = inferLoc.get(0).getLocIdentifier(); - if (!methodLattice.isGreaterThan(paramLocLocalSymbol, returnLocSymbol)) { - addRelationHigherToLower(methodLattice, methodInfo, paramLocLocalSymbol, returnLocSymbol); + Set inferFieldReturnLocSet = new HashSet(); + + Set paramFlowNode = getParamNodeFlowingToReturnValue(md); + Set inferParamLocSet = new HashSet(); + if (paramFlowNode != null) { + for (Iterator iterator = paramFlowNode.iterator(); iterator.hasNext();) { + FlowNode fn = (FlowNode) iterator.next(); + CompositeLocation inferLoc = + generateInferredCompositeLocation(methodInfo, getFlowGraph(md).getLocationTuple(fn)); + inferParamLocSet.add(inferLoc); + } + } + + Set returnNodeSet = fg.getReturnNodeSet(); + skip: for (Iterator iterator = returnNodeSet.iterator(); iterator.hasNext();) { + FlowNode returnNode = (FlowNode) iterator.next(); + CompositeLocation inferReturnLoc = + generateInferredCompositeLocation(methodInfo, fg.getLocationTuple(returnNode)); + System.out.println("@inferReturnLoc=" + inferReturnLoc); + if (inferReturnLoc.get(0).getLocIdentifier().equals("this")) { + // if the location type of the return value matches "this" reference + // then, check whether this return value is equal to/lower than all of + // parameters that possibly flow into the return values + for (Iterator iterator2 = inferParamLocSet.iterator(); iterator2.hasNext();) { + CompositeLocation paramInferLoc = (CompositeLocation) iterator2.next(); + + if ((!paramInferLoc.equals(inferReturnLoc)) + && !isGreaterThan(methodLattice, paramInferLoc, inferReturnLoc)) { + continue skip; + } + } + inferFieldReturnLocSet.add(inferReturnLoc); + + } + } + + if (inferFieldReturnLocSet.size() > 0) { + + CompositeLocation returnLoc = getLowest(methodLattice, inferFieldReturnLocSet); + methodInfo.setReturnLoc(returnLoc); + + } else { + String returnLocSymbol = "RETURNLOC"; + CompositeLocation returnLocInferLoc = + new CompositeLocation(new Location(md, returnLocSymbol)); + methodInfo.setReturnLoc(returnLocInferLoc); + + for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { + Integer paramIdx = (Integer) iterator.next(); + CompositeLocation inferLoc = mapParamToLoc.get(paramIdx); + String paramLocLocalSymbol = inferLoc.get(0).getLocIdentifier(); + if (!methodLattice.isGreaterThan(paramLocLocalSymbol, returnLocSymbol)) { + addRelationHigherToLower(methodLattice, methodInfo, paramLocLocalSymbol, + returnLocSymbol); + } + } + + for (Iterator iterator = returnNodeSet.iterator(); iterator.hasNext();) { + FlowNode returnNode = (FlowNode) iterator.next(); + CompositeLocation inferLoc = + generateInferredCompositeLocation(methodInfo, fg.getLocationTuple(returnNode)); + if (!isGreaterThan(methodLattice, inferLoc, returnLocInferLoc)) { + addRelation(methodLattice, methodInfo, inferLoc, returnLocInferLoc); + } } + } + + } + + } + + private Set getHigherLocSymbolThan(SSJavaLattice lattice, String loc) { + Set higherLocSet = new HashSet(); + + Set locSet = lattice.getTable().keySet(); + for (Iterator iterator = locSet.iterator(); iterator.hasNext();) { + String element = (String) iterator.next(); + if (lattice.isGreaterThan(element, loc) && (!element.equals(lattice.getTopItem()))) { + higherLocSet.add(element); + } + } + return higherLocSet; + } + + private CompositeLocation getLowest(SSJavaLattice methodLattice, + Set set) { + + CompositeLocation lowest = set.iterator().next(); + + if (set.size() == 1) { + return lowest; } + for (Iterator iterator = set.iterator(); iterator.hasNext();) { + CompositeLocation loc = (CompositeLocation) iterator.next(); + if (isGreaterThan(methodLattice, lowest, loc)) { + lowest = loc; + } + } + return lowest; } private boolean isGreaterThan(SSJavaLattice methodLattice, CompositeLocation comp1, @@ -1075,7 +1210,6 @@ public class LocationInference { for (int i = 0; i < localVarInferLoc.getSize(); i++) { inferLoc.addLocation(localVarInferLoc.get(i)); } - // System.out.println("@@@@@localVarInferLoc=" + localVarInferLoc); for (int i = 1; i < tuple.size(); i++) { Location cur = tuple.get(i); @@ -1316,6 +1450,9 @@ public class LocationInference { } }); + System.out.println("prefixList=" + prefixList); + System.out.println("reachableNodeSet=" + reachableNodeSet); + // find out reachable nodes that have the longest common prefix for (int i = 0; i < prefixList.size(); i++) { NTuple curPrefix = prefixList.get(i); @@ -1359,6 +1496,7 @@ public class LocationInference { if (inferLocation.getTuple().startsWith(curPrefix)) { // the same infer location is already existed. no need to do // anything + System.out.println("NO ATTEMPT TO HAVE A COMPOSITE LOCATION curPrefix=" + curPrefix); return true; } else { // assign a new composite location @@ -1423,6 +1561,7 @@ public class LocationInference { } + System.out.println("curPrefix=" + curPrefix); System.out.println("ASSIGN NEW COMPOSITE LOCATION =" + newInferLocation + " to " + flowNode); @@ -1668,7 +1807,9 @@ public class LocationInference { return cd2lattice.get(cd); } - public void constructFlowGraph() { + public LinkedList computeMethodList() { + + Set toSort = new HashSet(); setupToAnalyze(); @@ -1685,10 +1826,6 @@ public class LocationInference { MethodDescriptor md = toAnalyzeMethodNext(); if ((!visited.contains(md)) && (ssjava.needTobeAnnotated(md) || reachableCallee.contains(md))) { - if (state.SSJAVADEBUG) { - System.out.println(); - System.out.println("SSJAVA: Constructing a flow graph: " + md); - } // creates a mapping from a method descriptor to virtual methods Set setPossibleCallees = new HashSet(); @@ -1715,25 +1852,48 @@ public class LocationInference { mapMethodToCalleeSet.put(md, needToAnalyzeCalleeSet); - // creates a mapping from a parameter descriptor to its index - Map mapParamDescToIdx = new HashMap(); - int offset = md.isStatic() ? 0 : 1; - for (int i = 0; i < md.numParameters(); i++) { - Descriptor paramDesc = (Descriptor) md.getParameter(i); - mapParamDescToIdx.put(paramDesc, new Integer(i + offset)); - } - - FlowGraph fg = new FlowGraph(md, mapParamDescToIdx); - mapMethodDescriptorToFlowGraph.put(md, fg); - visited.add(md); - analyzeMethodBody(cd, md); + toSort.add(md); } } } + return ssjava.topologicalSort(toSort); + + } + + public void constructFlowGraph() { + + LinkedList methodDescList = computeMethodList(); + + while (!methodDescList.isEmpty()) { + MethodDescriptor md = methodDescList.removeLast(); + if (state.SSJAVADEBUG) { + System.out.println(); + System.out.println("SSJAVA: Constructing a flow graph: " + md); + + // creates a mapping from a parameter descriptor to its index + Map mapParamDescToIdx = new HashMap(); + int offset = 0; + if (!md.isStatic()) { + offset = 1; + mapParamDescToIdx.put(md.getThis(), 0); + } + + for (int i = 0; i < md.numParameters(); i++) { + Descriptor paramDesc = (Descriptor) md.getParameter(i); + mapParamDescToIdx.put(paramDesc, new Integer(i + offset)); + } + + FlowGraph fg = new FlowGraph(md, mapParamDescToIdx); + mapMethodDescriptorToFlowGraph.put(md, fg); + + analyzeMethodBody(md.getClassDesc(), md); + } + } _debug_printGraph(); + } private void analyzeMethodBody(ClassDescriptor cd, MethodDescriptor md) { @@ -1816,7 +1976,7 @@ public class LocationInference { // annotate the elements of the node set as the return location for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) { NTuple returnDescTuple = (NTuple) iterator.next(); - fg.setReturnFlowNode(returnDescTuple); + fg.addReturnFlowNode(returnDescTuple); for (Iterator iterator2 = implicitFlowTupleSet.iterator(); iterator2.hasNext();) { NTuple implicitFlowDescTuple = (NTuple) iterator2.next(); fg.addValueFlowEdge(implicitFlowDescTuple, returnDescTuple); @@ -1966,7 +2126,8 @@ public class LocationInference { break; case Kind.MethodInvokeNode: - analyzeFlowMethodInvokeNode(md, nametable, (MethodInvokeNode) en, implicitFlowTupleSet); + analyzeFlowMethodInvokeNode(md, nametable, (MethodInvokeNode) en, nodeSet, + implicitFlowTupleSet); break; case Kind.TertiaryNode: @@ -2035,12 +2196,30 @@ public class LocationInference { set.add(min); } + private void addParamNodeFlowingToReturnValue(MethodDescriptor md, FlowNode fn) { + + if (!mapMethodDescToParamNodeFlowsToReturnValue.containsKey(md)) { + mapMethodDescToParamNodeFlowsToReturnValue.put(md, new HashSet()); + } + mapMethodDescToParamNodeFlowsToReturnValue.get(md).add(fn); + } + + private Set getParamNodeFlowingToReturnValue(MethodDescriptor md) { + return mapMethodDescToParamNodeFlowsToReturnValue.get(md); + } + private void analyzeFlowMethodInvokeNode(MethodDescriptor md, SymbolTable nametable, - MethodInvokeNode min, NodeTupleSet implicitFlowTupleSet) { + MethodInvokeNode min, NodeTupleSet nodeSet, NodeTupleSet implicitFlowTupleSet) { + + System.out.println("analyzeFlowMethodInvokeNode=" + min.printNode(0)); + + if (nodeSet == null) { + nodeSet = new NodeTupleSet(); + } addMapCallerMethodDescToMethodInvokeNodeSet(md, min); - MethodDescriptor calleeMD = min.getMethod(); + MethodDescriptor calleeMethodDesc = min.getMethod(); NameDescriptor baseName = min.getBaseName(); boolean isSystemout = false; @@ -2048,69 +2227,92 @@ public class LocationInference { isSystemout = baseName.getSymbol().equals("System.out"); } - if (!ssjava.isSSJavaUtil(calleeMD.getClassDesc()) && !ssjava.isTrustMethod(calleeMD) - && !calleeMD.getModifiers().isNative() && !isSystemout) { + if (!ssjava.isSSJavaUtil(calleeMethodDesc.getClassDesc()) + && !ssjava.isTrustMethod(calleeMethodDesc) && !calleeMethodDesc.getModifiers().isNative() + && !isSystemout) { + + FlowGraph calleeFlowGraph = getFlowGraph(calleeMethodDesc); + Set calleeReturnSet = calleeFlowGraph.getReturnNodeSet(); - // CompositeLocation baseLocation = null; if (min.getExpression() != null) { NodeTupleSet baseNodeSet = new NodeTupleSet(); analyzeFlowExpressionNode(md, nametable, min.getExpression(), baseNodeSet, null, implicitFlowTupleSet, false); - } else { - if (min.getMethod().isStatic()) { - // String globalLocId = ssjava.getMethodLattice(md).getGlobalLoc(); - // if (globalLocId == null) { - // throw new - // Error("Method lattice does not define global variable location at " - // + generateErrorMessage(md.getClassDesc(), min)); - // } - // baseLocation = new CompositeLocation(new Location(md, - // globalLocId)); - } else { - // 'this' var case - // String thisLocId = ssjava.getMethodLattice(md).getThisLoc(); - // baseLocation = new CompositeLocation(new Location(md, thisLocId)); + if (!min.getMethod().isStatic()) { + addArgIdxMap(min, 0, baseNodeSet); + // System.out.println("arg idx=0 argTupleSet=" + baseNodeSet); + + for (Iterator iterator = calleeReturnSet.iterator(); iterator.hasNext();) { + FlowNode returnNode = (FlowNode) iterator.next(); + NTuple returnDescTuple = returnNode.getDescTuple(); + if (returnDescTuple.startsWith(calleeMethodDesc.getThis())) { + // the location type of the return value is started with 'this' + // reference + for (Iterator> baseIter = baseNodeSet.iterator(); baseIter + .hasNext();) { + NTuple baseTuple = baseIter.next(); + NTuple inFlowTuple = new NTuple(baseTuple.getList()); + inFlowTuple.addAll(returnDescTuple.subList(1, returnDescTuple.size())); + nodeSet.addTuple(inFlowTuple); + } + } else { + Set inFlowSet = calleeFlowGraph.getIncomingFlowNodeSet(returnNode); + for (Iterator iterator2 = inFlowSet.iterator(); iterator2.hasNext();) { + FlowNode inFlowNode = (FlowNode) iterator2.next(); + if (inFlowNode.getDescTuple().startsWith(calleeMethodDesc.getThis())) { + nodeSet.addTupleSet(baseNodeSet); + } + } + } + } } } - // constraint case: - // if (constraint != null) { - // int compareResult = - // CompositeLattice.compare(constraint, baseLocation, true, - // generateErrorMessage(cd, min)); - // if (compareResult != ComparisonResult.GREATER) { - // // if the current constraint is higher than method's THIS location - // // no need to check constraints! - // CompositeLocation calleeConstraint = - // translateCallerLocToCalleeLoc(calleeMD, baseLocation, constraint); - // // System.out.println("check method body for constraint:" + calleeMD + - // // " calleeConstraint=" - // // + calleeConstraint); - // checkMethodBody(calleeMD.getClassDesc(), calleeMD, calleeConstraint); - // } - // } + // analyze parameter flows - analyzeFlowMethodParameters(md, nametable, min); + if (min.numArgs() > 0) { - // checkCalleeConstraints(md, nametable, min, baseLocation, constraint); + int offset; + if (min.getMethod().isStatic()) { + offset = 0; + } else { + offset = 1; + } - // checkCallerArgumentLocationConstraints(md, nametable, min, - // baseLocation, constraint); + for (int i = 0; i < min.numArgs(); i++) { + ExpressionNode en = min.getArg(i); + int idx = i + offset; + NodeTupleSet argTupleSet = new NodeTupleSet(); + analyzeFlowExpressionNode(calleeMethodDesc, nametable, en, argTupleSet, false); + // if argument is liternal node, argTuple is set to NULL. + addArgIdxMap(min, idx, argTupleSet); + // System.out.println("arg idx=" + (idx) + " argTupleSet=" + + // argTupleSet); + FlowNode paramNode = calleeFlowGraph.getParamFlowNode(idx); + if (hasInFlowTo(calleeFlowGraph, paramNode, calleeReturnSet)) { + addParamNodeFlowingToReturnValue(calleeMethodDesc, paramNode); + nodeSet.addTupleSet(argTupleSet); + } + } - if (min.getMethod().getReturnType() != null && !min.getMethod().getReturnType().isVoid()) { - // If method has a return value, compute the highest possible return - // location in the caller's perspective - // CompositeLocation ceilingLoc = - // computeCeilingLocationForCaller(md, nametable, min, baseLocation, - // constraint); - // return ceilingLoc; } + } - // return new CompositeLocation(Location.createTopLocation(md)); + } + private boolean hasInFlowTo(FlowGraph fg, FlowNode inNode, Set nodeSet) { + // return true if inNode has in-flows to nodeSet + Set reachableSet = fg.getReachableFlowNodeSet(inNode); + for (Iterator iterator = reachableSet.iterator(); iterator.hasNext();) { + FlowNode fn = (FlowNode) iterator.next(); + if (nodeSet.contains(fn)) { + return true; + } + } + return false; } private NodeTupleSet getNodeTupleSetByArgIdx(MethodInvokeNode min, int idx) { @@ -2127,7 +2329,7 @@ public class LocationInference { } private void analyzeFlowMethodParameters(MethodDescriptor callermd, SymbolTable nametable, - MethodInvokeNode min) { + MethodInvokeNode min, NodeTupleSet nodeSet) { if (min.numArgs() > 0) { @@ -2136,11 +2338,12 @@ public class LocationInference { offset = 0; } else { offset = 1; - NTuple thisArgTuple = new NTuple(); - thisArgTuple.add(callermd.getThis()); - NodeTupleSet argTupleSet = new NodeTupleSet(); - argTupleSet.addTuple(thisArgTuple); - addArgIdxMap(min, 0, argTupleSet); + // NTuple thisArgTuple = new NTuple(); + // thisArgTuple.add(callermd.getThis()); + // NodeTupleSet argTupleSet = new NodeTupleSet(); + // argTupleSet.addTuple(thisArgTuple); + // addArgIdxMap(min, 0, argTupleSet); + // nodeSet.addTuple(thisArgTuple); } for (int i = 0; i < min.numArgs(); i++) { @@ -2149,6 +2352,8 @@ public class LocationInference { analyzeFlowExpressionNode(callermd, nametable, en, argTupleSet, false); // if argument is liternal node, argTuple is set to NULL. addArgIdxMap(min, i + offset, argTupleSet); + System.out.println("arg idx=" + (i + offset) + " argTupleSet=" + argTupleSet); + nodeSet.addTupleSet(argTupleSet); } } diff --git a/Robust/src/Analysis/SSJava/MethodLocationInfo.java b/Robust/src/Analysis/SSJava/MethodLocationInfo.java index 61140b49..7435c187 100644 --- a/Robust/src/Analysis/SSJava/MethodLocationInfo.java +++ b/Robust/src/Analysis/SSJava/MethodLocationInfo.java @@ -13,6 +13,16 @@ public class MethodLocationInfo extends LocationInfo { String returnLocName; String thisLocName; CompositeLocation pcLoc; + CompositeLocation returnLoc; + + public CompositeLocation getReturnLoc() { + return returnLoc; + } + + public void setReturnLoc(CompositeLocation returnLoc) { + this.returnLoc = returnLoc; + } + String globalLocName; Map mapParamIdxToInferLoc; diff --git a/Robust/src/Analysis/SSJava/SSJavaAnalysis.java b/Robust/src/Analysis/SSJava/SSJavaAnalysis.java index 84c8b3e3..84915295 100644 --- a/Robust/src/Analysis/SSJava/SSJavaAnalysis.java +++ b/Robust/src/Analysis/SSJava/SSJavaAnalysis.java @@ -146,6 +146,7 @@ public class SSJavaAnalysis { } if (state.SSJAVAINFER) { inference(); + System.exit(0); } else { parseLocationAnnotation(); doFlowDownCheck(); -- 2.34.1