Map<NTuple<Location>, GlobalFlowNode> mapLocTupleToNode;
Map<GlobalFlowNode, Set<GlobalFlowNode>> mapFlowNodeToOutNodeSet;
+ Map<GlobalFlowNode, Set<GlobalFlowNode>> mapFlowNodeToInNodeSet;
Map<Location, CompositeLocation> mapLocationToInferCompositeLocation;
this.md = md;
this.mapLocTupleToNode = new HashMap<NTuple<Location>, GlobalFlowNode>();
this.mapFlowNodeToOutNodeSet = new HashMap<GlobalFlowNode, Set<GlobalFlowNode>>();
+ this.mapFlowNodeToInNodeSet = new HashMap<GlobalFlowNode, Set<GlobalFlowNode>>();
+
this.mapLocationToInferCompositeLocation = new HashMap<Location, CompositeLocation>();
}
CompositeLocation oldCompLoc = mapLocationToInferCompositeLocation.get(loc);
if (newCompLoc.getSize() == oldCompLoc.getSize()) {
- for (int i = 0; i < oldCompLoc.getSize(); i++) {
+ for (int i = 0; i < oldCompLoc.getSize() - 1; i++) {
Location oldLocElement = oldCompLoc.get(i);
Location newLocElement = newCompLoc.get(i);
}
mapFlowNodeToOutNodeSet.get(fromNode).add(toNode);
+ if (!mapFlowNodeToInNodeSet.containsKey(toNode)) {
+ mapFlowNodeToInNodeSet.put(toNode, new HashSet<GlobalFlowNode>());
+ }
+ mapFlowNodeToInNodeSet.get(toNode).add(fromNode);
+
System.out.println("create a global edge from " + fromNode + " to " + toNode);
}
+ public Set<GlobalFlowNode> getInNodeSet(GlobalFlowNode node) {
+ if (!mapFlowNodeToInNodeSet.containsKey(node)) {
+ mapFlowNodeToInNodeSet.put(node, new HashSet<GlobalFlowNode>());
+ }
+ return mapFlowNodeToInNodeSet.get(node);
+ }
+
public Set<GlobalFlowNode> getNodeSet() {
Set<GlobalFlowNode> nodeSet = new HashSet<GlobalFlowNode>();
nodeSet.addAll(mapLocTupleToNode.values());
}
+ public Set<GlobalFlowNode> getIncomingNodeSetByPrefix(Location prefix) {
+
+ Set<GlobalFlowNode> incomingNodeSet = new HashSet<GlobalFlowNode>();
+
+ for (Iterator iterator = getNodeSet().iterator(); iterator.hasNext();) {
+ GlobalFlowNode curNode = (GlobalFlowNode) iterator.next();
+ Set<GlobalFlowNode> outNodeSet = getOutNodeSet(curNode);
+
+ for (Iterator iterator2 = outNodeSet.iterator(); iterator2.hasNext();) {
+ GlobalFlowNode outNode = (GlobalFlowNode) iterator2.next();
+
+ if (outNode.getLocTuple().startsWith(prefix)) {
+ incomingNodeSet.add(curNode);
+ recurIncomingNodeSetByPrefix(prefix, curNode, incomingNodeSet);
+ }
+
+ }
+ }
+
+ return incomingNodeSet;
+
+ }
+
+ private void recurIncomingNodeSetByPrefix(Location prefix, GlobalFlowNode node,
+ Set<GlobalFlowNode> visited) {
+
+ Set<GlobalFlowNode> inNodeSet = getInNodeSet(node);
+
+ for (Iterator iterator = inNodeSet.iterator(); iterator.hasNext();) {
+ GlobalFlowNode curNode = (GlobalFlowNode) iterator.next();
+
+ if (!curNode.getLocTuple().startsWith(prefix) && !visited.contains(curNode)) {
+ visited.add(curNode);
+ recurIncomingNodeSetByPrefix(prefix, curNode, visited);
+ }
+ }
+
+ }
+
+ public Set<GlobalFlowNode> getReachableNodeSetByPrefix(Location prefix) {
+
+ Set<GlobalFlowNode> reachableNodeSet = new HashSet<GlobalFlowNode>();
+
+ for (Iterator iterator = getNodeSet().iterator(); iterator.hasNext();) {
+ GlobalFlowNode curNode = (GlobalFlowNode) iterator.next();
+
+ if (curNode.getLocTuple().startsWith(prefix)) {
+ Set<GlobalFlowNode> outNodeSet = getOutNodeSet(curNode);
+ for (Iterator iterator2 = outNodeSet.iterator(); iterator2.hasNext();) {
+ GlobalFlowNode outNode = (GlobalFlowNode) iterator2.next();
+ if (!outNode.getLocTuple().startsWith(prefix) && !reachableNodeSet.contains(outNode)) {
+ reachableNodeSet.add(outNode);
+ recurReachableNodeSetByPrefix(prefix, outNode, reachableNodeSet);
+ }
+
+ }
+ }
+ }
+
+ return reachableNodeSet;
+ }
+
+ private void recurReachableNodeSetByPrefix(Location prefix, GlobalFlowNode node,
+ Set<GlobalFlowNode> reachableNodeSet) {
+ Set<GlobalFlowNode> outNodeSet = getOutNodeSet(node);
+ for (Iterator iterator = outNodeSet.iterator(); iterator.hasNext();) {
+ GlobalFlowNode outNode = (GlobalFlowNode) iterator.next();
+ if (!outNode.getLocTuple().startsWith(prefix) && !reachableNodeSet.contains(outNode)) {
+ reachableNodeSet.add(outNode);
+ recurReachableNodeSetByPrefix(prefix, outNode, reachableNodeSet);
+ }
+ }
+ }
+
public Set<GlobalFlowNode> getReachableNodeSetFrom(GlobalFlowNode node) {
Set<GlobalFlowNode> reachableNodeSet = new HashSet<GlobalFlowNode>();
// constructGlobalFlowGraph();
- System.exit(0);
-
constructHierarchyGraph();
debug_writeHierarchyDotFiles();
FlowGraph callerFlowGraph = getFlowGraph(mdCaller);
Map<Location, CompositeLocation> callerMapLocToCompLoc =
callerGlobalFlowGraph.getMapLocationToInferCompositeLocation();
+ System.out.println("---callerMapLocToCompLoc=" + callerMapLocToCompLoc);
Set<Location> methodLocSet = callerMapLocToCompLoc.keySet();
for (Iterator iterator = methodLocSet.iterator(); iterator.hasNext();) {
Location methodLoc = (Location) iterator.next();
NTuple<Location> baseLocTuple =
translateToLocTuple(mdCaller, mapMethodInvokeNodeToBaseTuple.get(min));
- System.out.println("-translate caller infer composite loc to callee=" + mdCallee);
+ System.out.println("\n-translate caller infer composite loc to callee=" + mdCallee
+ + " baseLocTuple=" + baseLocTuple);
Set<Location> keySet = callerMapLocToCompLoc.keySet();
for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
Location key = (Location) iterator.next();
CompositeLocation callerCompLoc = callerMapLocToCompLoc.get(key);
- if (!key.getDescriptor().equals(mdCaller)
- && callerCompLoc.getTuple().startsWith(baseLocTuple)) {
+ if (!key.getDescriptor().equals(mdCaller)) {
+ System.out.println("--- caller key=" + key + " callerCompLoc=" + callerCompLoc);
+
+ // && callerCompLoc.getTuple().startsWith(baseLocTuple)) {
// need to translate to the callee side
- // System.out.println("need to translate callerCompLoc=" + callerCompLoc +
- // " with baseTuple="
- // + baseLocTuple);
+
// TODO
- CompositeLocation newCalleeCompLoc =
- translateCompositeLocationToCallee(callerCompLoc, baseLocTuple, mdCallee);
- calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, newCalleeCompLoc);
- System.out.println("---callee loc=" + key + " newCalleeCompLoc=" + newCalleeCompLoc);
+ CompositeLocation newCalleeCompLoc;
+ if (callerCompLoc.getTuple().startsWith(baseLocTuple)) {
+ System.out.println("---need to translate callerCompLoc=" + callerCompLoc
+ + " with baseTuple=" + baseLocTuple);
+ newCalleeCompLoc =
+ translateCompositeLocationToCallee(callerCompLoc, baseLocTuple, mdCallee);
+
+ calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, newCalleeCompLoc);
+ System.out.println("---callee loc=" + key + " newCalleeCompLoc=" + newCalleeCompLoc);
+ } else {
+ // newCalleeCompLoc = callerCompLoc.clone();
+ }
+
}
}
// If the location of an argument has a composite location
// need to assign a proper composite location to the corresponding callee parameter
- System.out.println("-translate arg composite location to callee param:");
+ System.out.println("\n-translate arg composite location to callee param. min="
+ + min.printNode(0));
Map<Integer, NTuple<Descriptor>> mapIdxToArgTuple = mapMethodInvokeNodeToArgIdxMap.get(min);
Set<Integer> idxSet = mapIdxToArgTuple.keySet();
for (Iterator iterator = idxSet.iterator(); iterator.hasNext();) {
}
NTuple<Descriptor> argTuple = mapIdxToArgTuple.get(idx);
+ if (argTuple.size() > 0) {
+ // check if an arg tuple has been already assigned to a composite location
+ NTuple<Location> argLocTuple = translateToLocTuple(mdCaller, argTuple);
+ Location argLocalLoc = argLocTuple.get(0);
- // check if an arg tuple has been already assigned to a composite location
- NTuple<Location> argLocTuple = translateToLocTuple(mdCaller, argTuple);
- Location argLocalLoc = argLocTuple.get(0);
+ // if (!isPrimitiveType(argTuple)) {
+ if (callerMapLocToCompLoc.containsKey(argLocalLoc)) {
- // if (!isPrimitiveType(argTuple)) {
- if (callerMapLocToCompLoc.containsKey(argLocalLoc)) {
+ CompositeLocation callerCompLoc = callerMapLocToCompLoc.get(argLocalLoc);
+ for (int i = 1; i < argLocTuple.size(); i++) {
+ callerCompLoc.addLocation(argLocTuple.get(i));
+ }
- CompositeLocation callerCompLoc = callerMapLocToCompLoc.get(argLocalLoc);
- for (int i = 1; i < argLocTuple.size(); i++) {
- callerCompLoc.addLocation(argLocTuple.get(i));
- }
+ if (callerCompLoc.getTuple().startsWith(baseLocTuple)) {
- if (callerCompLoc.getTuple().startsWith(baseLocTuple)) {
+ FlowNode calleeParamFlowNode = calleeFlowGraph.getParamFlowNode(idx);
+ NTuple<Descriptor> calleeParamDescTuple = calleeParamFlowNode.getDescTuple();
+ NTuple<Location> calleeParamLocTuple =
+ translateToLocTuple(mdCallee, calleeParamDescTuple);
- FlowNode calleeParamFlowNode = calleeFlowGraph.getParamFlowNode(idx);
- NTuple<Descriptor> calleeParamDescTuple = calleeParamFlowNode.getDescTuple();
- NTuple<Location> calleeParamLocTuple =
- translateToLocTuple(mdCallee, calleeParamDescTuple);
+ System.out.println("---need to translate callerCompLoc=" + callerCompLoc
+ + " with baseTuple=" + baseLocTuple + " calleeParamLocTuple="
+ + calleeParamLocTuple);
- CompositeLocation newCalleeCompLoc =
- translateCompositeLocationToCallee(callerCompLoc, baseLocTuple, mdCallee);
+ CompositeLocation newCalleeCompLoc =
+ translateCompositeLocationToCallee(callerCompLoc, baseLocTuple, mdCallee);
- calleeGlobalGraph.addMapLocationToInferCompositeLocation(calleeParamLocTuple.get(0),
- newCalleeCompLoc);
+ calleeGlobalGraph.addMapLocationToInferCompositeLocation(calleeParamLocTuple.get(0),
+ newCalleeCompLoc);
- System.out.println("###need to assign composite location to=" + calleeParamDescTuple
- + " with baseTuple=" + baseLocTuple);
- System.out.println("---newCalleeCompLoc=" + newCalleeCompLoc);
- }
+ System.out.println("---callee loc=" + calleeParamLocTuple.get(0)
+ + " newCalleeCompLoc=" + newCalleeCompLoc);
+ // System.out.println("###need to assign composite location to=" + calleeParamDescTuple
+ // + " with baseTuple=" + baseLocTuple);
+ }
+
+ }
}
}
CompositeLocation newCalleeCompLoc = new CompositeLocation();
- // replace the last element of the caller compLoc with the 'this' location of the callee
- for (int i = 0; i < baseLocTuple.size() - 1; i++) {
- newCalleeCompLoc.addLocation(baseLocTuple.get(i));
- }
-
Location calleeThisLoc = new Location(mdCallee, mdCallee.getThis());
newCalleeCompLoc.addLocation(calleeThisLoc);
+ // remove the base tuple from the caller
+ // ex; In the method invoation foo.bar.methodA(), the callee will have the composite location
+ // ,which is relative to the 'this' variable, <THIS,...>
for (int i = baseLocTuple.size(); i < callerCompLoc.getSize(); i++) {
newCalleeCompLoc.addLocation(callerCompLoc.get(i));
}
MethodDescriptor methodDescEventLoop = ssjava.getMethodContainingSSJavaLoop();
GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(methodDescEventLoop);
- Set<NTuple<Location>> prefixSet = new HashSet<NTuple<Location>>();
+ Set<Location> calculatedPrefixSet = new HashSet<Location>();
Set<GlobalFlowNode> nodeSet = globalFlowGraph.getNodeSet();
next: for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
GlobalFlowNode node = (GlobalFlowNode) iterator.next();
- Set<GlobalFlowNode> incomingNodeSet = globalFlowGraph.getIncomingNodeSet(node);
+
+ Location prefixLoc = node.getLocTuple().get(0);
+
+ if (calculatedPrefixSet.contains(prefixLoc)) {
+ // the prefix loc has been already assigned to a composite location
+ continue;
+ }
+
+ calculatedPrefixSet.add(prefixLoc);
+
+ // Set<GlobalFlowNode> incomingNodeSet = globalFlowGraph.getIncomingNodeSet(node);
List<NTuple<Location>> prefixList = calculatePrefixList(globalFlowGraph, node);
- Set<GlobalFlowNode> reachNodeSet = globalFlowGraph.getReachableNodeSetFrom(node);
- // System.out.println("node=" + node + " inNodeSet=" + incomingNodeSet
- // + " reachableNodeSet=" + reachNodeSet);
+ Set<GlobalFlowNode> reachableNodeSet =
+ globalFlowGraph.getReachableNodeSetByPrefix(node.getLocTuple().get(0));
+ // Set<GlobalFlowNode> reachNodeSet = globalFlowGraph.getReachableNodeSetFrom(node);
+
+ // System.out.println("node=" + node + " prefixList=" + prefixList + " reachableNodeSet="
+ // + reachableNodeSet);
for (int i = 0; i < prefixList.size(); i++) {
NTuple<Location> curPrefix = prefixList.get(i);
Set<NTuple<Location>> reachableCommonPrefixSet = new HashSet<NTuple<Location>>();
- for (Iterator iterator2 = reachNodeSet.iterator(); iterator2.hasNext();) {
+ for (Iterator iterator2 = reachableNodeSet.iterator(); iterator2.hasNext();) {
GlobalFlowNode reachNode = (GlobalFlowNode) iterator2.next();
if (reachNode.getLocTuple().startsWith(curPrefix)) {
reachableCommonPrefixSet.add(reachNode.getLocTuple());
if (!reachableCommonPrefixSet.isEmpty()) {
- // TODO
- if (!node.getLocTuple().startsWith(curPrefix.get(0))) {
+ MethodDescriptor curPrefixFirstElementMethodDesc =
+ (MethodDescriptor) curPrefix.get(0).getDescriptor();
+
+ MethodDescriptor nodePrefixLocFirstElementMethodDesc =
+ (MethodDescriptor) prefixLoc.getDescriptor();
+
+ if (curPrefixFirstElementMethodDesc.equals(nodePrefixLocFirstElementMethodDesc)
+ || isTransitivelyCalledFrom(nodePrefixLocFirstElementMethodDesc,
+ curPrefixFirstElementMethodDesc)) {
+
+ // TODO
+ // if (!node.getLocTuple().startsWith(curPrefix.get(0))) {
+
+ Location curPrefixLocalLoc = curPrefix.get(0);
+ if (globalFlowGraph.mapLocationToInferCompositeLocation.containsKey(curPrefixLocalLoc)) {
+ // in this case, the local variable of the current prefix has already got a composite
+ // location
+ // so we just ignore the current composite location.
+
+ // System.out.println("HERE WE DO NOT ASSIGN A COMPOSITE LOCATION TO =" + node
+ // + " DUE TO " + curPrefix);
+
+ continue next;
+ }
+
+ Location targetLocalLoc = node.getLocTuple().get(0);
+ // CompositeLocation curCompLoc = globalFlowGraph.getCompositeLocation(targetLocalLoc);
+ // if ((curPrefix.size() + 1) > curCompLoc.getSize()) {
+
CompositeLocation newCompLoc = generateCompositeLocation(curPrefix);
System.out.println("NEED TO ASSIGN COMP LOC TO " + node + " with prefix=" + curPrefix);
System.out.println("- newCompLoc=" + newCompLoc);
-
- Location targetLocalLoc = node.getLocTuple().get(0);
globalFlowGraph.addMapLocationToInferCompositeLocation(targetLocalLoc, newCompLoc);
+ // }
continue next;
+ // }
+
}
}
private List<NTuple<Location>> calculatePrefixList(GlobalFlowGraph graph, GlobalFlowNode node) {
- System.out.println("\n##### calculatePrefixList=" + node);
+ System.out.println("\n##### calculatePrefixList node=" + node);
- Set<GlobalFlowNode> incomingNodeSet = graph.getIncomingNodeSet(node);
+ MethodDescriptor md = graph.getMethodDescriptor();
+
+ Set<GlobalFlowNode> incomingNodeSetPrefix =
+ graph.getIncomingNodeSetByPrefix(node.getLocTuple().get(0));
+ // System.out.println("incomingNodeSetPrefix=" + incomingNodeSetPrefix);
+ //
+ // Set<GlobalFlowNode> reachableNodeSetPrefix =
+ // graph.getReachableNodeSetByPrefix(node.getLocTuple().get(0));
+ // System.out.println("reachableNodeSetPrefix=" + reachableNodeSetPrefix);
List<NTuple<Location>> prefixList = new ArrayList<NTuple<Location>>();
- for (Iterator iterator = incomingNodeSet.iterator(); iterator.hasNext();) {
+ for (Iterator iterator = incomingNodeSetPrefix.iterator(); iterator.hasNext();) {
GlobalFlowNode inNode = (GlobalFlowNode) iterator.next();
NTuple<Location> inNodeTuple = inNode.getLocTuple();
}
});
return prefixList;
+
+ // List<NTuple<Location>> prefixList = new ArrayList<NTuple<Location>>();
+ //
+ // for (Iterator iterator = incomingNodeSet.iterator(); iterator.hasNext();) {
+ // GlobalFlowNode inNode = (GlobalFlowNode) iterator.next();
+ // NTuple<Location> inNodeTuple = inNode.getLocTuple();
+ //
+ // for (int i = 1; i < inNodeTuple.size(); i++) {
+ // NTuple<Location> prefix = inNodeTuple.subList(0, i);
+ // if (!prefixList.contains(prefix)) {
+ // prefixList.add(prefix);
+ // }
+ // }
+ // }
+ //
+ // Collections.sort(prefixList, new Comparator<NTuple<Location>>() {
+ // public int compare(NTuple<Location> arg0, NTuple<Location> arg1) {
+ // int s0 = arg0.size();
+ // int s1 = arg1.size();
+ // if (s0 > s1) {
+ // return -1;
+ // } else if (s0 == s1) {
+ // return 0;
+ // } else {
+ // return 1;
+ // }
+ // }
+ // });
+ // return prefixList;
}
private GlobalFlowGraph constructSubGlobalFlowGraph(FlowGraph flowGraph) {
NTuple<Location> locTuple = new NTuple<Location>();
Descriptor enclosingDesc = md;
- System.out.println("md=" + md + " descTuple=" + descTuple);
+ // System.out.println("md=" + md + " descTuple=" + descTuple);
for (int i = 0; i < descTuple.size(); i++) {
Descriptor desc = descTuple.get(i);
NTuple<Location> callerSrcNodeLocTuple =
translateToCallerLocTuple(min, mdCallee, mdCaller, calleeSrcNode.getLocTuple());
-
if (callerSrcNodeLocTuple != null) {
Set<GlobalFlowNode> outNodeSet = calleeSubGlobalGraph.getOutNodeSet(calleeSrcNode);
// parameters
Set<FlowNode> localReachSet = calleeFlowGraph.getLocalReachFlowNodeSetFrom(paramNode1);
+ System.out.println("-param1=" + paramNode1 + " is higher than param2=" + paramNode2);
+ System.out.println("-- localReachSet from param1=" + localReachSet);
- if (arg1Tuple.size() > 0 && arg2Tuple.size() > 2 && localReachSet.contains(paramNode2)) {
+ if (arg1Tuple.size() > 0 && arg2Tuple.size() > 0 && localReachSet.contains(paramNode2)) {
// need to propagate an ordering relation s.t. arg1 is higher
// than arg2
- System.out.println("-param1=" + paramNode1 + " is higher than param2=" + paramNode2);
System.out
.println("-arg1Tuple=" + arg1Tuple + " is higher than arg2Tuple=" + arg2Tuple);
NTuple<Descriptor> srcCurTuple = srcNode.getCurrentDescTuple();
NTuple<Descriptor> dstCurTuple = dstNode.getCurrentDescTuple();
+ System.out.println("srcCurTuple=" + srcCurTuple + " dstCurTuple=" + dstCurTuple);
if (srcCurTuple.get(idx).equals(dstCurTuple.get(idx)) && srcCurTuple.size() > (idx + 1)
&& dstCurTuple.size() > (idx + 1)) {
// value flow between fields: we don't need to add a binary relation
if (idx == 0) {
classDesc = ((VarDescriptor) desc).getType().getClassDesc();
} else {
- classDesc = ((FieldDescriptor) desc).getType().getClassDesc();
- }
+ if (desc instanceof FieldDescriptor) {
+ classDesc = ((FieldDescriptor) desc).getType().getClassDesc();
+ } else {
+ // TODO: need to handle a location descriptor case
+ classDesc = null;
+ }
+ }
extractFlowsBetweenFields(classDesc, srcNode, dstNode, idx + 1);
} else {
}
+ public boolean isTransitivelyCalledFrom(MethodDescriptor callee, MethodDescriptor caller) {
+ // if the callee is transitively invoked from the caller
+ // return true;
+
+ int callerIdx = toanalyze_methodDescList.indexOf(caller);
+ int calleeIdx = toanalyze_methodDescList.indexOf(callee);
+
+ if (callerIdx < calleeIdx) {
+ return true;
+ }
+
+ return false;
+
+ }
+
public void constructFlowGraph() {
System.out.println("");