// 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);
}
CompositeLocation localVarInferLoc =
methodInfo.getInferLocation(tuple.get(0).getLocDescriptor());
+ localVarInferLoc.get(0).setLocDescriptor(tuple.get(0).getLocDescriptor());
+
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);
Descriptor enclosingDesc = cur.getDescriptor();
Descriptor curDesc = cur.getLocDescriptor();
- String fieldLocSymbol =
- getLocationInfo(enclosingDesc).getInferLocation(curDesc).get(0).getLocIdentifier();
- Location inferLocElement = new Location(enclosingDesc, fieldLocSymbol);
+ Location inferLocElement;
+ if (curDesc == null) {
+ // in this case, we have a newly generated location.
+ // System.out.println("!!! generated location=" +
+ // cur.getLocIdentifier());
+ inferLocElement = new Location(enclosingDesc, cur.getLocIdentifier());
+ } else {
+ String fieldLocSymbol =
+ getLocationInfo(enclosingDesc).getInferLocation(curDesc).get(0).getLocIdentifier();
+ inferLocElement = new Location(enclosingDesc, fieldLocSymbol);
+ inferLocElement.setLocDescriptor(curDesc);
+ }
inferLoc.addLocation(inferLocElement);
}
+ assert (inferLoc.get(0).getLocDescriptor().getSymbol() == inferLoc.get(0).getLocIdentifier());
return inferLoc;
}
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();
// add a new binary relation of dstNode < srcNode
FlowGraph flowGraph = getFlowGraph(md);
-
- calculateCompositeLocation(flowGraph, methodLattice, methodInfo, srcNode);
-
- CompositeLocation srcInferLoc =
- generateInferredCompositeLocation(methodInfo, flowGraph.getLocationTuple(srcNode));
- CompositeLocation dstInferLoc =
- generateInferredCompositeLocation(methodInfo, flowGraph.getLocationTuple(dstNode));
-
try {
+ System.out.println("***** src composite case::");
+ calculateCompositeLocation(flowGraph, methodLattice, methodInfo, srcNode);
+
+ CompositeLocation srcInferLoc =
+ 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
// for the destination node
+ System.out.println("***** dst composite case::");
calculateCompositeLocation(flowGraph, methodLattice, methodInfo, dstNode);
- dstInferLoc =
+ CompositeLocation srcInferLoc =
+ generateInferredCompositeLocation(methodInfo, flowGraph.getLocationTuple(srcNode));
+ CompositeLocation dstInferLoc =
generateInferredCompositeLocation(methodInfo, flowGraph.getLocationTuple(dstNode));
try {
addRelation(methodLattice, methodInfo, srcInferLoc, dstInferLoc);
// check if it is the case of shared location
if (srcInferLoc.getSize() == (idx + 1) && dstInferLoc.getSize() == (idx + 1)) {
Location inferLocElement = srcInferLoc.get(idx);
+ System.out.println("SET SHARED LOCATION=" + inferLocElement);
getLattice(inferLocElement.getDescriptor())
.addSharedLoc(inferLocElement.getLocIdentifier());
} else if (srcInferLoc.getSize() > (idx + 1) && dstInferLoc.getSize() > (idx + 1)) {
throws CyclicFlowException {
Descriptor localVarDesc = flowNode.getDescTuple().get(0);
+ NTuple<Location> flowNodelocTuple = flowGraph.getLocationTuple(flowNode);
+
+ if (localVarDesc.equals(methodInfo.getMethodDesc())) {
+ return false;
+ }
Set<FlowNode> inNodeSet = flowGraph.getIncomingFlowNodeSet(flowNode);
Set<FlowNode> reachableNodeSet = flowGraph.getReachableFlowNodeSet(flowNode);
Map<NTuple<Location>, Set<NTuple<Location>>> mapPrefixToIncomingLocTupleSet =
new HashMap<NTuple<Location>, Set<NTuple<Location>>>();
- Set<FlowNode> localInNodeSet = new HashSet<FlowNode>();
- Set<FlowNode> localOutNodeSet = new HashSet<FlowNode>();
-
- CompositeLocation flowNodeInferLoc =
- generateInferredCompositeLocation(methodInfo, flowGraph.getLocationTuple(flowNode));
-
List<NTuple<Location>> prefixList = new ArrayList<NTuple<Location>>();
for (Iterator iterator = inNodeSet.iterator(); iterator.hasNext();) {
FlowNode inNode = (FlowNode) iterator.next();
- NTuple<Location> inTuple = flowGraph.getLocationTuple(inNode);
+ NTuple<Location> inNodeTuple = flowGraph.getLocationTuple(inNode);
- if (inTuple.size() > 1) {
- for (int i = 1; i < inTuple.size(); i++) {
- NTuple<Location> prefix = inTuple.subList(0, i);
- if (!prefixList.contains(prefix)) {
- prefixList.add(prefix);
- }
- addPrefixMapping(mapPrefixToIncomingLocTupleSet, prefix, inTuple);
+ CompositeLocation inNodeInferredLoc =
+ generateInferredCompositeLocation(methodInfo, inNodeTuple);
+
+ NTuple<Location> inNodeInferredLocTuple = inNodeInferredLoc.getTuple();
+
+ for (int i = 1; i < inNodeInferredLocTuple.size(); i++) {
+ NTuple<Location> prefix = inNodeInferredLocTuple.subList(0, i);
+ if (!prefixList.contains(prefix)) {
+ prefixList.add(prefix);
}
- } else {
- localInNodeSet.add(inNode);
+ addPrefixMapping(mapPrefixToIncomingLocTupleSet, prefix, inNodeInferredLocTuple);
}
}
}
});
- for (Iterator iterator2 = reachableNodeSet.iterator(); iterator2.hasNext();) {
- FlowNode reachableNode = (FlowNode) iterator2.next();
- if (reachableNode.getDescTuple().size() == 1) {
- localOutNodeSet.add(reachableNode);
- }
- }
-
// find out reachable nodes that have the longest common prefix
for (int i = 0; i < prefixList.size(); i++) {
NTuple<Location> curPrefix = prefixList.get(i);
for (Iterator iterator2 = reachableNodeSet.iterator(); iterator2.hasNext();) {
FlowNode reachableNode = (FlowNode) iterator2.next();
NTuple<Location> reachLocTuple = flowGraph.getLocationTuple(reachableNode);
- if (reachLocTuple.startsWith(curPrefix)) {
+ CompositeLocation reachLocInferLoc =
+ generateInferredCompositeLocation(methodInfo, reachLocTuple);
+ if (reachLocInferLoc.getTuple().startsWith(curPrefix)) {
reachableCommonPrefixSet.add(reachLocTuple);
}
}
- // check if the lattice has the relation in which higher prefix is
- // actually lower than the current node
- CompositeLocation prefixInferLoc = generateInferredCompositeLocation(methodInfo, curPrefix);
- if (isGreaterThan(methodLattice, flowNodeInferLoc, prefixInferLoc)) {
- reachableCommonPrefixSet.add(curPrefix);
- }
-
if (!reachableCommonPrefixSet.isEmpty()) {
// found reachable nodes that start with the prefix curPrefix
// need to assign a composite location
SSJavaLattice<String> lattice = getLattice(desc);
LocationInfo locInfo = getLocationInfo(desc);
- // CompositeLocation inferLocation =
- // methodInfo.getInferLocation(flowNode);
- CompositeLocation inferLocation = methodInfo.getInferLocation(localVarDesc);
+ CompositeLocation inferLocation =
+ generateInferredCompositeLocation(methodInfo, flowNodelocTuple);
- String newlyInsertedLocName;
- if (inferLocation.getSize() == 1) {
- // need to replace the old local location with a new composite
- // location
+ // methodInfo.getInferLocation(localVarDesc);
+ CompositeLocation newInferLocation = new CompositeLocation();
- String oldMethodLocationSymbol = inferLocation.get(0).getLocIdentifier();
+ if (inferLocation.getTuple().startsWith(curPrefix)) {
+ // the same infer location is already existed. no need to do
+ // anything
+ return true;
+ } else {
+ // assign a new composite location
+ // String oldMethodLocationSymbol =
+ // inferLocation.get(0).getLocIdentifier();
String newLocSymbol = "Loc" + (SSJavaLattice.seed++);
- inferLocation = new CompositeLocation();
for (int locIdx = 0; locIdx < curPrefix.size(); locIdx++) {
- inferLocation.addLocation(curPrefix.get(locIdx));
+ newInferLocation.addLocation(curPrefix.get(locIdx));
}
- Location fieldLoc = new Location(desc, newLocSymbol);
- inferLocation.addLocation(fieldLoc);
+ Location newLocationElement = new Location(desc, newLocSymbol);
+ newInferLocation.addLocation(newLocationElement);
- methodInfo.mapDescriptorToLocation(localVarDesc, inferLocation);
- addMapLocSymbolToInferredLocation(methodInfo.md, localVarDesc, inferLocation);
- methodInfo.removeMaplocalVarToLocSet(localVarDesc);
-
- String newMethodLocationSymbol = curPrefix.get(0).getLocIdentifier();
-
- replaceOldLocWithNewLoc(methodLattice, oldMethodLocationSymbol, newMethodLocationSymbol);
+ // maps local variable to location types of the common prefix
+ methodInfo.mapDescriptorToLocation(localVarDesc, newInferLocation.clone());
- } else {
+ // methodInfo.mapDescriptorToLocation(localVarDesc, newInferLocation);
+ addMapLocSymbolToInferredLocation(methodInfo.getMethodDesc(), localVarDesc,
+ newInferLocation);
+ methodInfo.removeMaplocalVarToLocSet(localVarDesc);
- String localLocName = methodInfo.getInferLocation(localVarDesc).get(0).getLocIdentifier();
- return true;
+ // add the field/var descriptor to the set of the location symbol
+ int lastIdx = flowNode.getDescTuple().size() - 1;
+ Descriptor lastFlowNodeDesc = flowNode.getDescTuple().get(lastIdx);
+ Descriptor enclosinglastLastFlowNodeDesc = flowNodelocTuple.get(lastIdx).getDescriptor();
+
+ CompositeLocation newlyInferredLocForFlowNode =
+ generateInferredCompositeLocation(methodInfo, flowNodelocTuple);
+ Location lastInferLocElement =
+ newlyInferredLocForFlowNode.get(newlyInferredLocForFlowNode.getSize() - 1);
+ Descriptor enclosingLastInferLocElement = lastInferLocElement.getDescriptor();
+
+ // getLocationInfo(enclosingLastInferLocElement).addMapLocSymbolToDescSet(
+ // lastInferLocElement.getLocIdentifier(), lastFlowNodeDesc);
+ getLocationInfo(enclosingLastInferLocElement).addMapLocSymbolToRelatedInferLoc(
+ lastInferLocElement.getLocIdentifier(), enclosinglastLastFlowNodeDesc,
+ 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);
+ // }
}
- newlyInsertedLocName = inferLocation.get(inferLocation.getSize() - 1).getLocIdentifier();
+ System.out.println("ASSIGN NEW COMPOSITE LOCATION =" + newInferLocation + " to "
+ + flowNode);
+ String newlyInsertedLocName =
+ 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();
-
Location loc = tuple.get(idx);
- String higher = locInfo.getFieldInferLocation(loc.getLocDescriptor()).getLocIdentifier();
- System.out.println("--");
- System.out.println("add in-flow relation:");
+ String higher = loc.getLocIdentifier();
addRelationHigherToLower(lattice, locInfo, higher, newlyInsertedLocName);
}
- System.out.println("end of add-inflow relation");
-
- for (Iterator iterator = localInNodeSet.iterator(); iterator.hasNext();) {
- FlowNode localNode = (FlowNode) iterator.next();
-
- if (localNode.equals(flowNode)) {
- continue;
- }
-
- CompositeLocation inNodeInferLoc =
- generateInferredCompositeLocation(methodInfo, flowGraph.getLocationTuple(localNode));
-
- if (isCompositeLocation(inNodeInferLoc)) {
- // need to make sure that newLocSymbol is lower than the infernode
- // location in the field lattice
- System.out.println("--- srcNode=" + localNode + " dstNode=" + flowNode);
- addRelation(methodLattice, methodInfo, inNodeInferLoc, inferLocation);
-
- }
-
- }
+ System.out.println("-- add out flow");
for (Iterator iterator = reachableCommonPrefixSet.iterator(); iterator.hasNext();) {
NTuple<Location> tuple = (NTuple<Location>) iterator.next();
if (tuple.size() > idx) {
Location loc = tuple.get(idx);
- String lower = locInfo.getFieldInferLocation(loc.getLocDescriptor()).getLocIdentifier();
- // lattice.addRelationHigherToLower(newlyInsertedLocName, lower);
- System.out.println("add out-flow relation:");
+ String lower = loc.getLocIdentifier();
+ // String lower =
+ // locInfo.getFieldInferLocation(loc.getLocDescriptor()).getLocIdentifier();
addRelationHigherToLower(lattice, locInfo, newlyInsertedLocName, lower);
}
}
- System.out.println("end of add out-flow relation");
-
- for (Iterator iterator = localOutNodeSet.iterator(); iterator.hasNext();) {
- FlowNode localOutNode = (FlowNode) iterator.next();
-
- if (localOutNode.equals(flowNode)) {
- continue;
- }
-
- CompositeLocation outNodeInferLoc =
- generateInferredCompositeLocation(methodInfo,
- 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);
-
- addRelation(methodLattice, methodInfo, inferLocation, outNodeInferLoc);
-
- }
- }
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);
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);
for (Iterator iterator2 = inferLocSet.iterator(); iterator2.hasNext();) {
Pair<Descriptor, Descriptor> pair = (Pair<Descriptor, Descriptor>) iterator2.next();
Descriptor enclosingDesc = pair.getFirst();
locElement.setLocIdentifier(newSharedLoc);
locInfo.addMapLocSymbolToRelatedInferLoc(newSharedLoc, enclosingDesc, desc);
+ if (curMethodInfo.md.equals(enclosingDesc)) {
+ inferLoc = curMethodInfo.getInferLocation(desc);
+ } else {
+ inferLoc = getLocationInfo(enclosingDesc).getInferLocation(desc);
+ }
+ 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);
- getFlowGraph(md).createNewFlowNode(base);
- return base;
+ if (isLHS) {
+ for (Iterator<NTuple<Descriptor>> idxIter = idxNodeTupleSet.iterator(); idxIter.hasNext();) {
+ NTuple<Descriptor> idxTuple = idxIter.next();
+ getFlowGraph(md).addValueFlowEdge(idxTuple, flowFieldTuple);
+ }
+ }
+
+ 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) {