// dependency in the call graph
methodDescriptorsToVisitStack.clear();
- descriptorListToAnalyze.removeFirst();
+ // descriptorListToAnalyze.removeFirst();
Set<MethodDescriptor> methodDescriptorToVistSet = new HashSet<MethodDescriptor>();
methodDescriptorToVistSet.addAll(descriptorListToAnalyze);
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<Descriptor>
- // 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<Descriptor>
+ // // 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);
+ // }
+ // }
+
}
}
}
CompositeLocation inferLoc1 = generateInferredCompositeLocation(methodInfo, tuple1);
CompositeLocation inferLoc2 = generateInferredCompositeLocation(methodInfo, tuple2);
- addRelation(methodLattice, methodInfo, inferLoc1, inferLoc2);
+ // addRelation(methodLattice, methodInfo, inferLoc1, inferLoc2);
+
+ addFlowGraphEdge(mdCaller, argDescTuple1, argDescTuple2);
}
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();
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
throws CyclicFlowException {
Descriptor localVarDesc = flowNode.getDescTuple().get(0);
+ NTuple<Location> flowNodelocTuple = flowGraph.getLocationTuple(flowNode);
if (localVarDesc.equals(methodInfo.getMethodDesc())) {
return false;
SSJavaLattice<String> 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
for (int locIdx = 0; locIdx < curPrefix.size(); locIdx++) {
newInferLocation.addLocation(curPrefix.get(locIdx));
}
- 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);
- }
+ Location newLocationElement = new Location(desc, newLocSymbol);
+ newInferLocation.addLocation(newLocationElement);
- methodInfo.mapDescriptorToLocation(localVarDesc, newInferLocation);
+ // 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,
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();
}
+ System.out.println("-- add out flow");
for (Iterator iterator = reachableCommonPrefixSet.iterator(); iterator.hasNext();) {
NTuple<Location> tuple = (NTuple<Location>) iterator.next();
if (tuple.size() > idx) {
}
}
+ System.out.println("-- add local out flow");
for (Iterator iterator = localOutNodeSet.iterator(); iterator.hasNext();) {
FlowNode localOutNode = (FlowNode) iterator.next();
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);
}
}
+ System.out.println("-- end of add local out flow");
return true;
}
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;
// }
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();
} else {
inferLoc = getLocationInfo(enclosingDesc).getInferLocation(desc);
}
- System.out.println("$$$New Infer Loc=" + inferLoc);
+ System.out.println("---New Infer Loc=" + inferLoc);
}
locInfo.removeRelatedInferLocSet(oldLocSymbol, newSharedLoc);
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:
if (isLHS) {
// need to create an edge from idx to array
-
for (Iterator<NTuple<Descriptor>> idxIter = idxNodeTupleSet.iterator(); idxIter.hasNext();) {
NTuple<Descriptor> idxTuple = idxIter.next();
for (Iterator<NTuple<Descriptor>> arrIter = expNodeTupleSet.iterator(); arrIter.hasNext();) {
}
}
+ 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<Descriptor> flowFieldTuple = new NTuple<Descriptor>(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<NTuple<Descriptor>> idxIter = idxNodeTupleSet.iterator(); idxIter.hasNext();) {
+ NTuple<Descriptor> idxTuple = idxIter.next();
+ getFlowGraph(md).addValueFlowEdge(idxTuple, flowFieldTuple);
+ }
+ }
- getFlowGraph(md).createNewFlowNode(base);
- return base;
+ return flowFieldTuple;
}
}
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();
}
+ if (nodeSet != null) {
+ nodeSet.addTupleSet(nodeSetLHS);
+ }
}
public FlowGraph getFlowGraph(MethodDescriptor md) {