From 78a14d01d4b27a3e6e5f42c3bdb382a708426e96 Mon Sep 17 00:00:00 2001 From: yeom Date: Fri, 10 Aug 2012 23:54:56 +0000 Subject: [PATCH] bug fixes on the flow graph. --- Robust/src/Analysis/SSJava/FlowGraph.java | 1 - .../Analysis/SSJava/LocationInference.java | 90 ++++++++++++------- Robust/src/Analysis/SSJava/NodeTupleSet.java | 4 + Robust/src/Analysis/SSJava/SSJavaLattice.java | 1 - 4 files changed, 60 insertions(+), 36 deletions(-) diff --git a/Robust/src/Analysis/SSJava/FlowGraph.java b/Robust/src/Analysis/SSJava/FlowGraph.java index de7cf348..9018489c 100644 --- a/Robust/src/Analysis/SSJava/FlowGraph.java +++ b/Robust/src/Analysis/SSJava/FlowGraph.java @@ -160,7 +160,6 @@ public class FlowGraph { public FlowNode createNewFlowNode(NTuple tuple) { if (!mapDescTupleToInferNode.containsKey(tuple)) { - FlowNode node = new FlowNode(tuple, isParameter(tuple)); mapDescTupleToInferNode.put(tuple, node); nodeSet.add(node); diff --git a/Robust/src/Analysis/SSJava/LocationInference.java b/Robust/src/Analysis/SSJava/LocationInference.java index d28772bb..1294cf85 100644 --- a/Robust/src/Analysis/SSJava/LocationInference.java +++ b/Robust/src/Analysis/SSJava/LocationInference.java @@ -478,28 +478,36 @@ public class LocationInference { VarDescriptor varDesc = (VarDescriptor) srcNodeTuple.get(0); classDesc = varDesc.getType().getClassDesc(); } - extractRelationFromFieldFlows(classDesc, srcNode, dstNode, 1); - } else if (srcNodeTuple.size() == 1 || dstNodeTuple.size() == 1) { - // for the method lattice, we need to look at the first element of - // NTuple - // in this case, take a look at connected nodes at the local level - addRelationToLattice(md, methodLattice, methodInfo, srcNode, dstNode); } else { - - if (!srcNode.getDescTuple().get(0).equals(dstNode.getDescTuple().get(0))) { - // in this case, take a look at connected nodes at the local level - addRelationToLattice(md, methodLattice, methodInfo, srcNode, dstNode); - } else { - Descriptor srcDesc = srcNode.getDescTuple().get(0); - Descriptor dstDesc = dstNode.getDescTuple().get(0); - recursivelyAddCompositeRelation(md, fg, methodInfo, srcNode, dstNode, srcDesc, - dstDesc); - // recursiveAddRelationToLattice(1, md, srcNode, dstNode); - } + // value flow between local var - local var or local var - field + addRelationToLattice(md, methodLattice, methodInfo, srcNode, dstNode); } + // else if (srcNodeTuple.size() == 1 || dstNodeTuple.size() == 1) { + // // for the method lattice, we need to look at the first element of + // // NTuple + // // in this case, take a look at connected nodes at the local level + // addRelationToLattice(md, methodLattice, methodInfo, srcNode, + // dstNode); + // } else { + // if + // (!srcNode.getDescTuple().get(0).equals(dstNode.getDescTuple().get(0))) + // { + // // in this case, take a look at connected nodes at the local level + // addRelationToLattice(md, methodLattice, methodInfo, srcNode, + // dstNode); + // } else { + // Descriptor srcDesc = srcNode.getDescTuple().get(0); + // Descriptor dstDesc = dstNode.getDescTuple().get(0); + // recursivelyAddCompositeRelation(md, fg, methodInfo, srcNode, + // dstNode, srcDesc, + // dstDesc); + // // recursiveAddRelationToLattice(1, md, srcNode, dstNode); + // } + // } + } } } @@ -823,7 +831,6 @@ public class LocationInference { generateInferredCompositeLocation(methodInfo, flowGraph.getLocationTuple(srcNode)); CompositeLocation dstInferLoc = generateInferredCompositeLocation(methodInfo, flowGraph.getLocationTuple(dstNode)); - addRelation(methodLattice, methodInfo, srcInferLoc, dstInferLoc); } catch (CyclicFlowException e) { // there is a cyclic value flow... try to calculate a composite location @@ -917,6 +924,7 @@ public class LocationInference { throws CyclicFlowException { Descriptor localVarDesc = flowNode.getDescTuple().get(0); + NTuple flowNodelocTuple = flowGraph.getLocationTuple(flowNode); if (localVarDesc.equals(methodInfo.getMethodDesc())) { return false; @@ -1020,9 +1028,14 @@ public class LocationInference { SSJavaLattice lattice = getLattice(desc); LocationInfo locInfo = getLocationInfo(desc); - CompositeLocation inferLocation = methodInfo.getInferLocation(localVarDesc); + CompositeLocation inferLocation = + generateInferredCompositeLocation(methodInfo, flowNodelocTuple); + + // methodInfo.getInferLocation(localVarDesc); CompositeLocation newInferLocation = new CompositeLocation(); + System.out.println("PREV INFER LOCATION=" + inferLocation + " curPrefix=" + + curPrefix); if (inferLocation.getTuple().startsWith(curPrefix)) { // the same infer location is already existed. no need to do // anything @@ -1036,13 +1049,13 @@ public class LocationInference { for (int locIdx = 0; locIdx < curPrefix.size(); locIdx++) { newInferLocation.addLocation(curPrefix.get(locIdx)); } - Location fieldLoc = new Location(desc, newLocSymbol); - newInferLocation.addLocation(fieldLoc); + Location newLocationElement = new Location(desc, newLocSymbol); + newInferLocation.addLocation(newLocationElement); - if (flowNode.getDescTuple().size() == 1) { - // maps local variable to location types of the common prefix - methodInfo.mapDescriptorToLocation(localVarDesc, newInferLocation.clone()); - } + // if (flowNode.getDescTuple().size() == 1) { + // maps local variable to location types of the common prefix + methodInfo.mapDescriptorToLocation(localVarDesc, newInferLocation.clone()); + // } // methodInfo.mapDescriptorToLocation(localVarDesc, newInferLocation); addMapLocSymbolToInferredLocation(methodInfo.getMethodDesc(), localVarDesc, @@ -1144,8 +1157,6 @@ public class LocationInference { flowGraph.getLocationTuple(localOutNode)); if (isCompositeLocation(outNodeInferLoc)) { - // need to make sure that newLocSymbol is higher than the infernode - // location System.out.println("--- srcNode=" + flowNode + " dstNode=" + localOutNode); addRelationToLattice(methodInfo.getMethodDesc(), methodLattice, methodInfo, flowNode, localOutNode); @@ -1873,7 +1884,6 @@ public class LocationInference { if (isLHS) { // need to create an edge from idx to array - for (Iterator> idxIter = idxNodeTupleSet.iterator(); idxIter.hasNext();) { NTuple idxTuple = idxIter.next(); for (Iterator> arrIter = expNodeTupleSet.iterator(); arrIter.hasNext();) { @@ -2057,32 +2067,44 @@ public class LocationInference { } } + NodeTupleSet idxNodeTupleSet = new NodeTupleSet(); if (left instanceof ArrayAccessNode) { ArrayAccessNode aan = (ArrayAccessNode) left; left = aan.getExpression(); - analyzeFlowExpressionNode(md, nametable, aan.getIndex(), nodeSet, base, implicitFlowTupleSet, - isLHS); + analyzeFlowExpressionNode(md, nametable, aan.getIndex(), idxNodeTupleSet, base, + implicitFlowTupleSet, isLHS); + nodeSet.addTupleSet(idxNodeTupleSet); } - // fanNodeSet base = analyzeFlowExpressionNode(md, nametable, left, nodeSet, base, implicitFlowTupleSet, isLHS); + if (base == null) { // in this case, field is TOP location return null; } else { + NTuple flowFieldTuple = new NTuple(base.toList()); + if (!left.getType().isPrimitive()) { if (!fd.getSymbol().equals("length")) { // array.length access, just have the location of the array - base.add(fd); + flowFieldTuple.add(fd); + nodeSet.removeTuple(base); } } + getFlowGraph(md).createNewFlowNode(flowFieldTuple); + + if (isLHS) { + for (Iterator> idxIter = idxNodeTupleSet.iterator(); idxIter.hasNext();) { + NTuple idxTuple = idxIter.next(); + getFlowGraph(md).addValueFlowEdge(idxTuple, flowFieldTuple); + } + } - getFlowGraph(md).createNewFlowNode(base); - return base; + return flowFieldTuple; } diff --git a/Robust/src/Analysis/SSJava/NodeTupleSet.java b/Robust/src/Analysis/SSJava/NodeTupleSet.java index 3040a15a..eaa0e6e9 100644 --- a/Robust/src/Analysis/SSJava/NodeTupleSet.java +++ b/Robust/src/Analysis/SSJava/NodeTupleSet.java @@ -28,6 +28,10 @@ public class NodeTupleSet { list.add(tuple); } + public void removeTuple(NTuple tuple) { + list.remove(tuple); + } + public Iterator> iterator() { return list.iterator(); } diff --git a/Robust/src/Analysis/SSJava/SSJavaLattice.java b/Robust/src/Analysis/SSJava/SSJavaLattice.java index 89ca9af5..e2c85f29 100644 --- a/Robust/src/Analysis/SSJava/SSJavaLattice.java +++ b/Robust/src/Analysis/SSJava/SSJavaLattice.java @@ -91,7 +91,6 @@ public class SSJavaLattice extends Lattice { getInBetweenElements(cur, end, elementSet); } } - System.out.println(" start=" + start + " end=" + end + " element=" + elementSet); } public void mergeIntoSharedLocation(Set cycleSet, T newLoc) { -- 2.34.1