X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=Robust%2Fsrc%2FAnalysis%2FSSJava%2FLocationInference.java;h=b2bd43fcf6f85a4a21564989a9766738ed61a875;hb=5e5c10a2592a9acd282a1ae27bdf7468beb12e90;hp=20a2fa5d0b26fcf3ff57aca617274c5e53184812;hpb=ce5159c8570f28f7b37e2a19c6c62d01c501b2c2;p=IRC.git diff --git a/Robust/src/Analysis/SSJava/LocationInference.java b/Robust/src/Analysis/SSJava/LocationInference.java index 20a2fa5d..b2bd43fc 100644 --- a/Robust/src/Analysis/SSJava/LocationInference.java +++ b/Robust/src/Analysis/SSJava/LocationInference.java @@ -77,6 +77,9 @@ public class LocationInference { // keep current descriptors to visit in fixed-point interprocedural analysis, private Stack methodDescriptorsToVisitStack; + // map a descriptor to a naive lattice + private Map> desc2naiveLattice; + // map a class descriptor to a field lattice private Map> cd2lattice; @@ -181,6 +184,9 @@ public class LocationInference { private BuildLattice buildLattice; + public static int numLocationsSInfer = 0; + public static int numLocationsNaive = 0; + public LocationInference(SSJavaAnalysis ssjava, State state, TypeUtil tu) { this.ssjava = ssjava; this.state = state; @@ -191,6 +197,8 @@ public class LocationInference { this.mapMethodDescriptorToFlowGraph = new HashMap(); this.cd2lattice = new HashMap>(); this.md2lattice = new HashMap>(); + this.desc2naiveLattice = new HashMap>(); + this.methodDescriptorsToVisitStack = new Stack(); this.mapMethodDescriptorToMethodInvokeNodeSet = new HashMap>(); @@ -312,8 +320,6 @@ public class LocationInference { buildInheritanceTree(); calculateReturnPCLocInheritance(); -// System.exit(0); - constructHierarchyGraph(); addInheritanceConstraintsToHierarchyGraph(); @@ -360,6 +366,11 @@ public class LocationInference { // + locOrder.getKeySet().size() + "\t" + hg.getNodeSet().size()); } + if (state.SSJAVA_INFER_NAIVE_WRITEDOTS) { + System.out.println("The number of elements: Naive=" + numLocationsNaive); + } + System.out.println("The number of elements: SInfer=" + numLocationsSInfer); + System.exit(0); } @@ -389,23 +400,25 @@ public class LocationInference { NTuple highestRETURNLocDescTuple = mapHighestOverriddenMethodDescToReturnLocTuple.get(highestMethodDesc); - System.out.println("---updateFlowGraphPCReturnLocInheritance=" + highestMethodDesc); - System.out.println("-----highestPCLoc=" + highestPCLocDescTuple); - System.out.println("-----highestRETURNLoc=" + highestRETURNLocDescTuple); + // System.out.println("\n$$$$$$$$$$$$$$$$updateFlowGraphPCReturnLocInheritance=" + // + highestMethodDesc); + // System.out.println("-----highestPCLoc=" + highestPCLocDescTuple); + // System.out.println("-----highestRETURNLoc=" + highestRETURNLocDescTuple); for (Iterator iterator2 = methodDescSet.iterator(); iterator2.hasNext();) { MethodDescriptor md = (MethodDescriptor) iterator2.next(); + // System.out.println("\n --------MD=" + md); FlowGraph flowGraph = getFlowGraph(md); MethodSummary summary = getMethodSummary(md); CompositeLocation curPCLoc = summary.getPCLoc(); NTuple curPCDescTuple = translateToDescTuple(curPCLoc.getTuple()); - System.out.println("md=" + md + " curPCLoc=" + curPCLoc); - System.out.println("highestPCLoc=" + highestPCLocDescTuple); + // System.out.println("md=" + md + " curPCLoc=" + curPCLoc); + // System.out.println("highestPCLoc=" + highestPCLocDescTuple); if (highestPCLocDescTuple == null) { // this case: PCLOC is top - System.out.println("###SET PCLOC AS TOP"); + // System.out.println("###SET PCLOC AS TOP"); if (curPCDescTuple != null && !curPCLoc.get(0).isTop()) { FlowNode pcFlowNode = flowGraph.getFlowNode(curPCDescTuple); flowGraph.removeNode(pcFlowNode); @@ -423,10 +436,8 @@ public class LocationInference { FlowNode pcFlowNode = flowGraph.getFlowNode(curPCDescTuple); flowGraph.updateTuple(pcFlowNode, newPCDescTuple); // flowGraph.removeNode(pcFlowNode); - System.out.println("####UPDATE PCLOC=" + newPCDescTuple); Set> descSetLowerThanPCLoc = mapHighestOverriddenMethodDescToSetLowerThanPCLoc.get(highestMethodDesc); - System.out.println("####descSetLowerThanPCLoc=" + descSetLowerThanPCLoc); for (Iterator iterator3 = descSetLowerThanPCLoc.iterator(); iterator3.hasNext();) { NTuple lowerNTuple = (NTuple) iterator3.next(); flowGraph.addValueFlowEdge(newPCDescTuple, lowerNTuple); @@ -434,8 +445,6 @@ public class LocationInference { CompositeLocation newPCCompLoc = new CompositeLocation(translateToLocTuple(md, newPCDescTuple)); summary.setPCLoc(newPCCompLoc); - } else { - System.out.println("####DO NOTHING!:)"); } } @@ -444,7 +453,6 @@ public class LocationInference { if (highestRETURNLocDescTuple != null) { CompositeLocation curRETURNLoc = summary.getRETURNLoc(); NTuple curReturnDescTuple = translateToDescTuple(curRETURNLoc.getTuple()); - System.out.println("curRETURNLoc=" + curRETURNLoc); if (!curReturnDescTuple.equals(highestRETURNLocDescTuple)) { // handle the case that RETURNLOC is started with 'this'... @@ -457,12 +465,10 @@ public class LocationInference { } FlowNode returnFlowNode = flowGraph.getFlowNode(curReturnDescTuple); - System.out.println("####UPDATE RETURNLOC=" + newRETURNLocDescTuple); flowGraph.updateTuple(returnFlowNode, newRETURNLocDescTuple); Set> descSetHigherThanRETURNLoc = mapHighestOverriddenMethodDescToSetHigherThanRETURNLoc.get(highestMethodDesc); - System.out.println("####descSetLowerThanPCLoc=" + descSetHigherThanRETURNLoc); for (Iterator iterator3 = descSetHigherThanRETURNLoc.iterator(); iterator3.hasNext();) { NTuple higherNTuple = (NTuple) iterator3.next(); flowGraph.addValueFlowEdge(higherNTuple, newRETURNLocDescTuple); @@ -470,20 +476,9 @@ public class LocationInference { CompositeLocation newRETURNLocCompLoc = new CompositeLocation(translateToLocTuple(md, newRETURNLocDescTuple)); - summary.setPCLoc(newRETURNLocCompLoc); - System.out.println("md=" + md + "###newRETURNLocCompLoc=" + newRETURNLocCompLoc); - } else { - System.out.println("####DO NOTHING!:)"); + summary.setRETURNLoc(newRETURNLocCompLoc); } } - - -// try { -// flowGraph.writeGraph("2"); -// } catch (IOException e) { -// // TODO Auto-generated catch block -// e.printStackTrace(); -// } } } } @@ -506,7 +501,8 @@ public class LocationInference { mapHighestOverriddenMethodDescToMethodDescSet.get(highestMethodDesc); if (methodDescSet.size() > 1) { - System.out.println("---method desc set=" + methodDescSet + " from=" + highestMethodDesc); + // System.out.println("---method desc set=" + methodDescSet + " from=" + + // highestMethodDesc); } else { continue next; } @@ -519,10 +515,10 @@ public class LocationInference { continue; } Set paramNodeSet = flowGraph.getParamFlowNodeSet(); - System.out.println("###md=" + md + " paramNodeSet=" + paramNodeSet); + // System.out.println("###md=" + md + " paramNodeSet=" + paramNodeSet); CompositeLocation pcLOC = getMethodSummary(md).getPCLoc(); - System.out.println("---pcLOC=" + pcLOC); + // System.out.println("---pcLOC=" + pcLOC); if (md.equals(highestMethodDesc)) { mapHighestOverriddenMethodDescToPCLocTuple.put(highestMethodDesc, @@ -539,10 +535,8 @@ public class LocationInference { if (flowGraph.getReachableSetFrom(pcFlowNode.getCurrentDescTuple().subList(0, 1)) .contains(paramNode)) { count++; - System.out.println("-------" + pcFlowNode + " -> " + paramNode); } } - System.out.println("$$$ pcLOC=" + pcLOC + " count higher=" + count); mapMethodDescToParamCount.put(md, count); } else { @@ -559,8 +553,6 @@ public class LocationInference { FlowNode flowNode = (FlowNode) iterator3.next(); descTupleSetLowerThanPC.add(flowNode.getCurrentDescTuple()); } - System.out.println("###TOP CASE"); - System.out.println("descTupleSetLowerThanPC=" + descTupleSetLowerThanPC); mapHighestOverriddenMethodDescToSetLowerThanPCLoc.put(highestMethodDesc, descTupleSetLowerThanPC); @@ -568,7 +560,6 @@ public class LocationInference { } } - System.out.println("#INDENTIFY WHICH METHOD..."); // identify which method in the inheritance chain has the highest PCLOC // basically, finds a method that has the highest count or TOP location int highestCount = -1; @@ -598,8 +589,6 @@ public class LocationInference { reachableParamNodeSet.add(flowNode); } - System.out.println(flowNode + " is PARAM=" - + flowGraph.isParameter(flowNode.getCurrentDescTuple())); } Set> descTupleSetLowerThanPC = new HashSet>(); @@ -615,11 +604,11 @@ public class LocationInference { } - System.out.println("####################################"); - System.out.println(" highest=" + highestMethodDesc + " HIGHEST PCLOC=" - + mapHighestOverriddenMethodDescToPCLocTuple.get(highestMethodDesc)); - System.out.println(" setLowerThanPCLoc=" - + mapHighestOverriddenMethodDescToSetLowerThanPCLoc.get(highestMethodDesc)); + // System.out.println("####################################"); + // System.out.println(" highest=" + highestMethodDesc + " HIGHEST PCLOC=" + // + mapHighestOverriddenMethodDescToPCLocTuple.get(highestMethodDesc)); + // System.out.println(" setLowerThanPCLoc=" + // + mapHighestOverriddenMethodDescToSetLowerThanPCLoc.get(highestMethodDesc)); } } @@ -631,87 +620,80 @@ public class LocationInference { Map mapMethodDescToParamCount = new HashMap(); - for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { + next: for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { MethodDescriptor highestMethodDesc = (MethodDescriptor) iterator.next(); - NTuple tempTuple = null; - - if (getMethodSummary(highestMethodDesc).getRETURNLoc() != null) { - - System.out.println("---calculateLowestReturnLocInheritance=" + highestMethodDesc); + Set methodDescSet = + mapHighestOverriddenMethodDescToMethodDescSet.get(highestMethodDesc); - Set methodDescSet = - mapHighestOverriddenMethodDescToMethodDescSet.get(highestMethodDesc); + if (methodDescSet.size() > 1 && getMethodSummary(highestMethodDesc).getRETURNLoc() != null) { + } else { + continue next; + } - for (Iterator iterator2 = methodDescSet.iterator(); iterator2.hasNext();) { - MethodDescriptor md = (MethodDescriptor) iterator2.next(); + for (Iterator iterator2 = methodDescSet.iterator(); iterator2.hasNext();) { + MethodDescriptor md = (MethodDescriptor) iterator2.next(); - FlowGraph flowGraph = getFlowGraph(md); - Set paramNodeSet = flowGraph.getParamFlowNodeSet(); - System.out.println("###md=" + md + " paramNodeSet=" + paramNodeSet + " returnLoc=" - + getMethodSummary(md).getRETURNLoc()); + FlowGraph flowGraph = getFlowGraph(md); + Set paramNodeSet = flowGraph.getParamFlowNodeSet(); - CompositeLocation returnLoc = getMethodSummary(md).getRETURNLoc(); + CompositeLocation returnLoc = getMethodSummary(md).getRETURNLoc(); - FlowNode returnFlowNode = - flowGraph.getFlowNode(translateToDescTuple(returnLoc.getTuple())); + FlowNode returnFlowNode = flowGraph.getFlowNode(translateToDescTuple(returnLoc.getTuple())); - int count = 0; - for (Iterator iterator3 = paramNodeSet.iterator(); iterator3.hasNext();) { - FlowNode paramNode = (FlowNode) iterator3.next(); - if (flowGraph.getReachableSetFrom(paramNode.getCurrentDescTuple().subList(0, 1)) - .contains(returnFlowNode)) { - count++; - } + int count = 0; + for (Iterator iterator3 = paramNodeSet.iterator(); iterator3.hasNext();) { + FlowNode paramNode = (FlowNode) iterator3.next(); + if (flowGraph.getReachableSetFrom(paramNode.getCurrentDescTuple().subList(0, 1)) + .contains(returnFlowNode)) { + count++; } - mapMethodDescToParamCount.put(md, count); - System.out.println("###returnLoc=" + returnLoc + " count higher=" + count); } + mapMethodDescToParamCount.put(md, count); + // System.out.println("###returnLoc=" + returnLoc + " count higher=" + count); + } - System.out.println("#INDENTIFY WHICH METHOD..."); - // identify which method in the inheritance chain has the highest PCLOC - // basically, finds a method that has the highest count or TOP location - int highestCount = -1; - MethodDescriptor methodDescHighestCount = null; - for (Iterator iterator2 = methodDescSet.iterator(); iterator2.hasNext();) { - MethodDescriptor methodDesc = (MethodDescriptor) iterator2.next(); - int curCount = mapMethodDescToParamCount.get(methodDesc).intValue(); - if (highestCount < curCount) { - highestCount = curCount; - methodDescHighestCount = methodDesc; - } + // identify which method in the inheritance chain has the highest PCLOC + // basically, finds a method that has the highest count or TOP location + int highestCount = -1; + MethodDescriptor methodDescHighestCount = null; + for (Iterator iterator2 = methodDescSet.iterator(); iterator2.hasNext();) { + MethodDescriptor methodDesc = (MethodDescriptor) iterator2.next(); + int curCount = mapMethodDescToParamCount.get(methodDesc).intValue(); + if (highestCount < curCount) { + highestCount = curCount; + methodDescHighestCount = methodDesc; } + } - if (methodDescHighestCount != null) { - FlowGraph flowGraph = getFlowGraph(methodDescHighestCount); - CompositeLocation returnLOC = getMethodSummary(methodDescHighestCount).getRETURNLoc(); - NTuple returnLocTuple = translateToDescTuple(returnLOC.getTuple()); - FlowNode returnFlowNode = flowGraph.getFlowNode(returnLocTuple); - - Set curMethodParamNodeSet = flowGraph.getParamFlowNodeSet(); - Set> descTupleSetHigherThanPC = new HashSet>(); - for (Iterator iterator3 = curMethodParamNodeSet.iterator(); iterator3.hasNext();) { - FlowNode paramNode = (FlowNode) iterator3.next(); - if (flowGraph.getReachableSetFrom(paramNode.getCurrentDescTuple().subList(0, 1)) - .contains(returnFlowNode)) { - descTupleSetHigherThanPC.add(paramNode.getCurrentDescTuple()); - } - } - - mapHighestOverriddenMethodDescToReturnLocTuple.put(highestMethodDesc, returnLocTuple); - mapHighestOverriddenMethodDescToSetHigherThanRETURNLoc.put(highestMethodDesc, - descTupleSetHigherThanPC); + if (methodDescHighestCount != null) { + FlowGraph flowGraph = getFlowGraph(methodDescHighestCount); + CompositeLocation returnLOC = getMethodSummary(methodDescHighestCount).getRETURNLoc(); + NTuple returnLocTuple = translateToDescTuple(returnLOC.getTuple()); + FlowNode returnFlowNode = flowGraph.getFlowNode(returnLocTuple); + Set curMethodParamNodeSet = flowGraph.getParamFlowNodeSet(); + Set> descTupleSetHigherThanPC = new HashSet>(); + for (Iterator iterator3 = curMethodParamNodeSet.iterator(); iterator3.hasNext();) { + FlowNode paramNode = (FlowNode) iterator3.next(); + if (flowGraph.getReachableSetFrom(paramNode.getCurrentDescTuple().subList(0, 1)) + .contains(returnFlowNode)) { + descTupleSetHigherThanPC.add(paramNode.getCurrentDescTuple()); + } } - System.out.println("####################################"); - System.out.println(" highest=" + highestMethodDesc + " LOWEST RETURNLOC=" - + mapHighestOverriddenMethodDescToReturnLocTuple.get(highestMethodDesc)); - System.out.println(" setHigherThanReturnLoc=" - + mapHighestOverriddenMethodDescToSetHigherThanRETURNLoc.get(highestMethodDesc)); + mapHighestOverriddenMethodDescToReturnLocTuple.put(highestMethodDesc, returnLocTuple); + mapHighestOverriddenMethodDescToSetHigherThanRETURNLoc.put(highestMethodDesc, + descTupleSetHigherThanPC); } + // System.out.println("####################################"); + // System.out.println(" highest=" + highestMethodDesc + " LOWEST RETURNLOC=" + // + mapHighestOverriddenMethodDescToReturnLocTuple.get(highestMethodDesc)); + // System.out.println(" setHigherThanReturnLoc=" + // + mapHighestOverriddenMethodDescToSetHigherThanRETURNLoc.get(highestMethodDesc)); + } } @@ -939,6 +921,14 @@ public class LocationInference { } + private void addSuperClasses(ClassDescriptor cd) { + ClassDescriptor parentClassDesc = cd.getSuperDesc(); + if (parentClassDesc != null) { + toanalyze_classDescSet.add(parentClassDesc); + addSuperClasses(parentClassDesc); + } + } + private void updateFlowGraph() { LinkedList methodDescList = @@ -960,7 +950,9 @@ public class LocationInference { for (int i = 0; i < locTuple.size(); i++) { Location loc = locTuple.get(i); if (loc.getDescriptor() instanceof ClassDescriptor) { - toanalyze_classDescSet.add((ClassDescriptor) loc.getDescriptor()); + ClassDescriptor classDesc = (ClassDescriptor) loc.getDescriptor(); + toanalyze_classDescSet.add(classDesc); + addSuperClasses(classDesc); } else if (loc.getDescriptor() instanceof MethodDescriptor) { toanalyze_classDescSet.add(((MethodDescriptor) loc.getDescriptor()).getClassDesc()); } @@ -1047,19 +1039,19 @@ public class LocationInference { Set nodeSet = flowGraph.getNodeSet(); for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) { FlowNode node = (FlowNode) iterator.next(); - System.out.println("-node=" + node + " node.getDescTuple=" + node.getDescTuple()); + // System.out.println("-node=" + node + " node.getDescTuple=" + node.getDescTuple()); if (node.getCompositeLocation() != null) { CompositeLocation compLoc = node.getCompositeLocation(); CompositeLocation updatedCompLoc = updateCompositeLocation(compLoc); node.setCompositeLocation(updatedCompLoc); - System.out.println("---updatedCompLoc1=" + updatedCompLoc); + // System.out.println("---updatedCompLoc1=" + updatedCompLoc); } else { NTuple descTuple = node.getDescTuple(); - System.out.println("update desc=" + descTuple); + // System.out.println("update desc=" + descTuple); CompositeLocation compLoc = convertToCompositeLocation(md, descTuple); compLoc = updateCompositeLocation(compLoc); node.setCompositeLocation(compLoc); - System.out.println("---updatedCompLoc2=" + compLoc); + // System.out.println("---updatedCompLoc2=" + compLoc); } if (node.isDeclaratonNode()) { @@ -1094,8 +1086,8 @@ public class LocationInference { HierarchyGraph scGraph = getSimpleHierarchyGraph(enclosingDesc); if (scGraph != null) { HNode curNode = scGraph.getCurrentHNode(nodeIdentifier); - System.out.println("nodeID=" + nodeIdentifier + " curNode=" + curNode - + " enclosingDesc=" + enclosingDesc); + // System.out.println("nodeID=" + nodeIdentifier + " curNode=" + curNode + // + " enclosingDesc=" + enclosingDesc); if (curNode != null) { nodeIdentifier = curNode.getName(); } @@ -1181,18 +1173,18 @@ public class LocationInference { // // update return flow nodes in the caller CompositeLocation returnLoc = getMethodSummary(mdCallee).getRETURNLoc(); - System.out.println("### min=" + min.printNode(0) + " returnLoc=" + returnLoc); + // System.out.println("### min=" + min.printNode(0) + " returnLoc=" + returnLoc); if (returnLoc != null && returnLoc.get(0).getLocDescriptor().equals(mdCallee.getThis()) && returnLoc.getSize() > 1) { - System.out.println("###RETURN COMP LOC=" + returnLoc); + // System.out.println("###RETURN COMP LOC=" + returnLoc); NTuple returnLocTuple = returnLoc.getTuple(); NTuple baseTuple = mapMethodInvokeNodeToBaseTuple.get(min); - System.out.println("###basetuple=" + baseTuple); + // System.out.println("###basetuple=" + baseTuple); NTuple newReturnTuple = baseTuple.clone(); for (int i = 1; i < returnLocTuple.size(); i++) { newReturnTuple.add(returnLocTuple.get(i).getLocDescriptor()); } - System.out.println("###NEW RETURN TUPLE FOR CALLER=" + newReturnTuple); + // System.out.println("###NEW RETURN TUPLE FOR CALLER=" + newReturnTuple); FlowReturnNode holderNode = callerFlowGraph.getFlowReturnNode(min); NodeTupleSet holderTupleSet = @@ -1202,7 +1194,7 @@ public class LocationInference { // then need to remove old constraints // TODO SAT - System.out.println("###REMOVE OLD CONSTRAINTS=" + holderNode); + // System.out.println("###REMOVE OLD CONSTRAINTS=" + holderNode); for (Iterator> iter = holderTupleSet.iterator(); iter.hasNext();) { NTuple tupleFromHolder = iter.next(); Set holderOutEdge = callerFlowGraph.getOutEdgeSet(holderNode); @@ -1271,63 +1263,6 @@ public class LocationInference { return mapMethodDescToMethodInvokeNodeSet.get(md); } - private void addOrderingConstraintFromCompLocParamToArg(MethodDescriptor mdCaller, - MethodInvokeNode min) { - System.out.println("-addOrderingConstraintFromCompLocParamToArg=" + min.printNode(0)); - - GlobalFlowGraph globalGraph = getSubGlobalFlowGraph(ssjava.getMethodContainingSSJavaLoop()); - - Set> pcLocTupleSet = getPCLocTupleSet(min); - - MethodDescriptor mdCallee = min.getMethod(); - - FlowGraph calleeFlowGraph = getFlowGraph(mdCallee); - for (int idx = 0; idx < calleeFlowGraph.getNumParameters(); idx++) { - FlowNode paramNode = calleeFlowGraph.getParamFlowNode(idx); - NTuple globalParamLocTuple = - translateToLocTuple(mdCallee, paramNode.getDescTuple()); - translateToLocTuple(mdCallee, paramNode.getDescTuple()); - CompositeLocation compLoc = paramNode.getCompositeLocation(); - System.out.println("---paramNode=" + paramNode + " compLoc=" + compLoc); - if (compLoc != null) { - NTuple argTuple = getNodeTupleByArgIdx(min, idx); - NTuple globalArgLocTuple = translateToLocTuple(mdCaller, argTuple); - - if (!isLiteralValueLocTuple(globalArgLocTuple) - && !isLiteralValueLocTuple(globalParamLocTuple)) { - if (!globalGraph.hasValueFlowEdge(globalArgLocTuple, globalParamLocTuple)) { - System.out.println("----- add global flow globalArgLocTuple=" + globalArgLocTuple - + "-> globalParamLocTuple=" + globalParamLocTuple); - hasChanges = true; - globalGraph.addValueFlowEdge(globalArgLocTuple, globalParamLocTuple); - } - } - - for (Iterator iterator = pcLocTupleSet.iterator(); iterator.hasNext();) { - NTuple pcLocTuple = (NTuple) iterator.next(); - - if (!isLiteralValueLocTuple(pcLocTuple) && !isLiteralValueLocTuple(globalParamLocTuple)) { - if (!globalGraph.hasValueFlowEdge(pcLocTuple, globalParamLocTuple)) { - System.out - .println("----- add global flow PCLOC=" - + pcLocTuple - + "-> globalParamLocTu!globalArgLocTuple.get(0).getLocDescriptor().equals(LITERALDESC)ple=" - + globalParamLocTuple); - hasChanges = true; - - globalGraph.addValueFlowEdge(pcLocTuple, globalParamLocTuple); - } - } - - } - } - } - } - - private boolean isLiteralValueLocTuple(NTuple locTuple) { - return locTuple.get(0).getLocDescriptor().equals(LITERALDESC); - } - public void assignCompositeLocationToFlowGraph(FlowGraph flowGraph, Location loc, CompositeLocation inferCompLoc) { Descriptor localDesc = loc.getLocDescriptor(); @@ -1340,7 +1275,7 @@ public class LocationInference { // need to assign the inferred composite location to this node CompositeLocation newCompLoc = generateCompositeLocation(node.getDescTuple(), inferCompLoc); node.setCompositeLocation(newCompLoc); - System.out.println("SET Node=" + node + " inferCompLoc=" + newCompLoc); + // System.out.println("SET Node=" + node + " inferCompLoc=" + newCompLoc); } } } @@ -1348,8 +1283,8 @@ public class LocationInference { private CompositeLocation generateCompositeLocation(NTuple nodeDescTuple, CompositeLocation inferCompLoc) { - System.out.println("generateCompositeLocation=" + nodeDescTuple + " with inferCompLoc=" - + inferCompLoc); + // System.out.println("generateCompositeLocation=" + nodeDescTuple + " with inferCompLoc=" + // + inferCompLoc); MethodDescriptor md = (MethodDescriptor) inferCompLoc.get(0).getDescriptor(); @@ -1491,8 +1426,8 @@ public class LocationInference { } } - System.out.println("#ASSIGN COMP LOC TO CALLEE PARAMS: callee=" + mdCallee + " caller=" - + mdCaller); + // System.out.println("#ASSIGN COMP LOC TO CALLEE PARAMS: callee=" + mdCallee + " caller=" + // + mdCaller); // If the location of an argument has a composite location // need to assign a proper composite location to the corresponding callee parameter Set idxSet = mapIdxToArgTuple.keySet(); @@ -1504,7 +1439,7 @@ public class LocationInference { } NTuple argTuple = mapIdxToArgTuple.get(idx); - System.out.println("-argTuple=" + argTuple + " idx=" + idx); + // System.out.println("-argTuple=" + argTuple + " idx=" + idx); if (argTuple.size() > 0) { // check if an arg tuple has been already assigned to a composite location NTuple argLocTuple = translateToLocTuple(mdCaller, argTuple); @@ -1518,7 +1453,7 @@ public class LocationInference { callerCompLoc.addLocation(argLocTuple.get(i)); } - System.out.println("---callerCompLoc=" + callerCompLoc); + // System.out.println("---callerCompLoc=" + callerCompLoc); // if (baseLocTuple != null && callerCompLoc.getTuple().startsWith(baseLocTuple)) { @@ -1529,12 +1464,12 @@ public class LocationInference { translateToLocTuple(mdCallee, calleeParamDescTuple); int refParamIdx = getParamIdx(callerCompLoc, mapIdxToArgTuple); - System.out.println("-----paramIdx=" + refParamIdx); + // System.out.println("-----paramIdx=" + refParamIdx); if (refParamIdx == 0 && !mdCallee.isStatic()) { - System.out.println("-------need to translate callerCompLoc=" + callerCompLoc - + " with baseTuple=" + baseLocTuple + " calleeParamLocTuple=" - + calleeParamLocTuple); + // System.out.println("-------need to translate callerCompLoc=" + callerCompLoc + // + " with baseTuple=" + baseLocTuple + " calleeParamLocTuple=" + // + calleeParamLocTuple); CompositeLocation newCalleeCompLoc = translateCompositeLocationToCallee(callerCompLoc, baseLocTuple, mdCallee); @@ -1542,22 +1477,22 @@ public class LocationInference { calleeGlobalGraph.addMapLocationToInferCompositeLocation(calleeParamLocTuple.get(0), newCalleeCompLoc); - System.out.println("---------key=" + calleeParamLocTuple.get(0) + " callerCompLoc=" - + callerCompLoc + " newCalleeCompLoc=" + newCalleeCompLoc); + // System.out.println("---------key=" + calleeParamLocTuple.get(0) + " callerCompLoc=" + // + callerCompLoc + " newCalleeCompLoc=" + newCalleeCompLoc); } else if (refParamIdx != -1) { // the first element of an argument composite location matches with one of paramtere // composite locations - System.out.println("-------param match case="); + // System.out.println("-------param match case="); NTuple argTupleRef = mapIdxToArgTuple.get(refParamIdx); FlowNode refParamFlowNode = calleeFlowGraph.getParamFlowNode(refParamIdx); NTuple refParamLocTuple = translateToLocTuple(mdCallee, refParamFlowNode.getDescTuple()); - System.out.println("---------refParamLocTuple=" + refParamLocTuple - + " from argTupleRef=" + argTupleRef); + // System.out.println("---------refParamLocTuple=" + refParamLocTuple + // + " from argTupleRef=" + argTupleRef); CompositeLocation newCalleeCompLoc = new CompositeLocation(); for (int i = 0; i < refParamLocTuple.size(); i++) { @@ -1571,8 +1506,9 @@ public class LocationInference { newCalleeCompLoc); calleeParamFlowNode.setCompositeLocation(newCalleeCompLoc); - System.out.println("-----------key=" + calleeParamLocTuple.get(0) + " callerCompLoc=" - + callerCompLoc + " newCalleeCompLoc=" + newCalleeCompLoc); + // System.out.println("-----------key=" + calleeParamLocTuple.get(0) + + // " callerCompLoc=" + // + callerCompLoc + " newCalleeCompLoc=" + newCalleeCompLoc); } else { CompositeLocation newCalleeCompLoc = @@ -1584,8 +1520,8 @@ public class LocationInference { } } - System.out.println("-----------------calleeParamFlowNode=" - + calleeParamFlowNode.getCompositeLocation()); + // System.out.println("-----------------calleeParamFlowNode=" + // + calleeParamFlowNode.getCompositeLocation()); // } @@ -1599,8 +1535,8 @@ public class LocationInference { private CompositeLocation calculateCompositeLocationFromSubGlobalGraph(MethodDescriptor md, FlowNode paramNode) { - System.out.println("#############################################################"); - System.out.println("calculateCompositeLocationFromSubGlobalGraph=" + paramNode); + // System.out.println("#############################################################"); + // System.out.println("calculateCompositeLocationFromSubGlobalGraph=" + paramNode); GlobalFlowGraph subGlobalFlowGraph = getSubGlobalFlowGraph(md); NTuple paramLocTuple = translateToLocTuple(md, paramNode.getDescTuple()); @@ -1660,16 +1596,17 @@ public class LocationInference { } if (!needToGenerateCompositeLocation(paramGlobalNode, curPrefix)) { - System.out.println("NO NEED TO GENERATE COMP LOC to " + paramGlobalNode - + " with prefix=" + curPrefix); + // System.out.println("NO NEED TO GENERATE COMP LOC to " + paramGlobalNode + // + " with prefix=" + curPrefix); return null; } Location targetLocalLoc = paramGlobalNode.getLocTuple().get(0); CompositeLocation newCompLoc = generateCompositeLocation(curPrefix); - System.out.println("NEED TO ASSIGN COMP LOC TO " + paramGlobalNode + " with prefix=" - + curPrefix); - System.out.println("-targetLocalLoc=" + targetLocalLoc + " - newCompLoc=" + newCompLoc); + // System.out.println("NEED TO ASSIGN COMP LOC TO " + paramGlobalNode + " with prefix=" + // + curPrefix); + // System.out.println("-targetLocalLoc=" + targetLocalLoc + " - newCompLoc=" + + // newCompLoc); // makes sure that a newly generated location appears in the hierarchy graph for (int compIdx = 0; compIdx < newCompLoc.getSize(); compIdx++) { @@ -1700,7 +1637,7 @@ public class LocationInference { Integer key = (Integer) iterator.next(); NTuple argTuple = mapIdxToArgTuple.get(key); if (argTuple.size() > 0 && translateToDescTuple(compLoc.getTuple()).startsWith(argTuple)) { - System.out.println("compLoc.getTuple=" + compLoc + " is started with " + argTuple); + // System.out.println("compLoc.getTuple=" + compLoc + " is started with " + argTuple); return key.intValue(); } } @@ -1772,11 +1709,11 @@ public class LocationInference { // Set reachNodeSet = globalFlowGraph.getReachableNodeSetFrom(node); // System.out.println("node=" + node + " prefixList=" + prefixList); - System.out.println("---prefixList=" + prefixList); + // System.out.println("---prefixList=" + prefixList); nextprefix: for (int i = 0; i < prefixList.size(); i++) { NTuple curPrefix = prefixList.get(i); - System.out.println("---curPrefix=" + curPrefix); + // System.out.println("---curPrefix=" + curPrefix); Set> reachableCommonPrefixSet = new HashSet>(); for (Iterator iterator2 = reachableNodeSet.iterator(); iterator2.hasNext();) { @@ -1820,8 +1757,8 @@ public class LocationInference { } if (!needToGenerateCompositeLocation(node, curPrefix)) { - System.out.println("NO NEED TO GENERATE COMP LOC to " + node + " with prefix=" - + curPrefix); + // System.out.println("NO NEED TO GENERATE COMP LOC to " + node + " with prefix=" + // + curPrefix); // System.out.println("prefixList=" + prefixList); // System.out.println("reachableNodeSet=" + reachableNodeSet); continue nextprefix; @@ -1829,9 +1766,10 @@ public class LocationInference { Location targetLocalLoc = node.getLocTuple().get(0); CompositeLocation newCompLoc = generateCompositeLocation(curPrefix); - System.out.println("NEED TO ASSIGN COMP LOC TO " + node + " with prefix=" + curPrefix); - System.out.println("-targetLocalLoc=" + targetLocalLoc + " - newCompLoc=" - + newCompLoc); + // System.out.println("NEED TO ASSIGN COMP LOC TO " + node + " with prefix=" + + // curPrefix); + // System.out.println("-targetLocalLoc=" + targetLocalLoc + " - newCompLoc=" + // + newCompLoc); globalFlowGraph.addMapLocationToInferCompositeLocation(targetLocalLoc, newCompLoc); // } @@ -1885,7 +1823,7 @@ public class LocationInference { // in this case, all return nodes in the method returns values coming from a location that // starts with "this" - System.out.println("$$$SET RETURN LOC TRUE=" + md); + // System.out.println("$$$SET RETURN LOC TRUE=" + md); mapMethodDescriptorToCompositeReturnCase.put(md, Boolean.TRUE); // NameDescriptor returnLocDesc = new NameDescriptor("RLOC" + (locSeed++)); @@ -1913,7 +1851,7 @@ public class LocationInference { // return true if there is a path between a node to which we want to give a composite location // and nodes which start with curPrefix - System.out.println("---needToGenerateCompositeLocation curPrefix=" + curPrefix); + // System.out.println("---needToGenerateCompositeLocation curPrefix=" + curPrefix); Location targetLocalLoc = node.getLocTuple().get(0); @@ -1936,7 +1874,7 @@ public class LocationInference { ((InterDescriptor) targetLocalLoc.getLocDescriptor()).getMethodArgIdxPair(); if (pair != null) { - System.out.println("$$$TARGETLOCALLOC HOLDER=" + targetLocalLoc); + // System.out.println("$$$TARGETLOCALLOC HOLDER=" + targetLocalLoc); MethodInvokeNode min = pair.getFirst(); Integer paramIdx = pair.getSecond(); @@ -1959,7 +1897,7 @@ public class LocationInference { for (int i = 0; i < curPrefix.size(); i++) { ClassDescriptor prefixType = getClassTypeDescriptor(curPrefix.get(i).getLocDescriptor()); if (prefixType != null && prefixType.equals(currentMethodThisType)) { - System.out.println("PREFIX TYPE MATCHES WITH=" + currentMethodThisType); + // System.out.println("PREFIX TYPE MATCHES WITH=" + currentMethodThisType); if (mapMethodDescriptorToCompositeReturnCase.containsKey(md)) { boolean hasCompReturnLocWithThis = @@ -1974,7 +1912,7 @@ public class LocationInference { for (Iterator iterator3 = subGlobalReachableSet.iterator(); iterator3.hasNext();) { GlobalFlowNode subGlobalReachalbeNode = (GlobalFlowNode) iterator3.next(); if (subGlobalReachalbeNode.getLocTuple().get(0).getLocDescriptor().equals(md.getThis())) { - System.out.println("PREFIX FOUND=" + subGlobalReachalbeNode); + // System.out.println("PREFIX FOUND=" + subGlobalReachalbeNode); return true; } } @@ -1985,7 +1923,7 @@ public class LocationInference { Location lastLocationOfPrefix = curPrefix.get(curPrefix.size() - 1); // check whether prefix appears in the list of parameters Set minSet = mapMethodDescToMethodInvokeNodeSet.get(md); - System.out.println("$$$md=" + md + " minSet=" + minSet); + // System.out.println("$$$md=" + md + " minSet=" + minSet); if (minSet == null) { return false; } @@ -2006,15 +1944,15 @@ public class LocationInference { NTuple locTuple = translateToLocTuple(md, flowGraph.getParamFlowNode(argIdx).getDescTuple()); lastLocationOfPrefix = locTuple.get(0); - System.out.println("ARG CASE=" + locTuple); + // System.out.println("ARG CASE=" + locTuple); for (Iterator iterator3 = subGlobalReachableSet.iterator(); iterator3.hasNext();) { GlobalFlowNode subGlobalReachalbeNode = (GlobalFlowNode) iterator3.next(); // NTuple locTuple = translateToLocTuple(md, reachalbeNode.getDescTuple()); NTuple globalReachlocTuple = subGlobalReachalbeNode.getLocTuple(); for (int i = 0; i < globalReachlocTuple.size(); i++) { if (globalReachlocTuple.get(i).equals(lastLocationOfPrefix)) { - System.out.println("ARG " + argTuple + " IS MATCHED WITH=" - + lastLocationOfPrefix); + // System.out.println("ARG " + argTuple + " IS MATCHED WITH=" + // + lastLocationOfPrefix); return true; } } @@ -2058,7 +1996,7 @@ public class LocationInference { private List> calculatePrefixList(GlobalFlowGraph graph, GlobalFlowNode node) { - System.out.println("\n##### calculatePrefixList node=" + node); + // System.out.println("\n##### calculatePrefixList node=" + node); Set incomingNodeSetPrefix = graph.getIncomingNodeSetByPrefix(node.getLocTuple().get(0)); @@ -2108,8 +2046,8 @@ public class LocationInference { private CompositeLocation calculateCompositeLocationFromFlowGraph(MethodDescriptor md, FlowNode node) { - System.out.println("#############################################################"); - System.out.println("calculateCompositeLocationFromFlowGraph=" + node); + // System.out.println("#############################################################"); + // System.out.println("calculateCompositeLocationFromFlowGraph=" + node); FlowGraph flowGraph = getFlowGraph(md); // NTuple paramLocTuple = translateToLocTuple(md, paramNode.getDescTuple()); @@ -2151,8 +2089,9 @@ public class LocationInference { // Location targetLocalLoc = paramGlobalNode.getLocTuple().get(0); CompositeLocation newCompLoc = generateCompositeLocation(curPrefix); - System.out.println("NEED2ASSIGN COMP LOC TO " + node + " with prefix=" + curPrefix); - System.out.println("-targetLocalLoc=" + targetLocalLoc + " - newCompLoc=" + newCompLoc); + // System.out.println("NEED2ASSIGN COMP LOC TO " + node + " with prefix=" + curPrefix); + // System.out.println("-targetLocalLoc=" + targetLocalLoc + " - newCompLoc=" + + // newCompLoc); node.setCompositeLocation(newCompLoc); @@ -2166,7 +2105,7 @@ public class LocationInference { private List> calculatePrefixListFlowGraph(FlowGraph graph, FlowNode node) { - System.out.println("\n##### calculatePrefixList node=" + node); + // System.out.println("\n##### calculatePrefixList node=" + node); MethodDescriptor md = graph.getMethodDescriptor(); Set incomingNodeSetPrefix = @@ -2304,12 +2243,12 @@ public class LocationInference { private void propagateValueFlowsToCallerFromSubGlobalFlowGraph(MethodInvokeNode min, MethodDescriptor mdCaller, MethodDescriptor possibleMdCallee) { - System.out.println("---propagate from " + min.printNode(0) + " to caller=" + mdCaller); + // System.out.println("---propagate from " + min.printNode(0) + " to caller=" + mdCaller); FlowGraph calleeFlowGraph = getFlowGraph(possibleMdCallee); Map> mapIdxToArg = mapMethodInvokeNodeToArgIdxMap.get(min); - System.out.println("-----mapMethodInvokeNodeToArgIdxMap.get(min)=" - + mapMethodInvokeNodeToArgIdxMap.get(min)); + // System.out.println("-----mapMethodInvokeNodeToArgIdxMap.get(min)=" + // + mapMethodInvokeNodeToArgIdxMap.get(min)); Set keySet = mapIdxToArg.keySet(); for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { @@ -2319,8 +2258,8 @@ public class LocationInference { NTuple argLocTuple = translateToLocTuple(mdCaller, argDescTuple); NTuple paramDescTuple = calleeFlowGraph.getParamFlowNode(idx).getDescTuple(); NTuple paramLocTuple = translateToLocTuple(possibleMdCallee, paramDescTuple); - System.out.println("-------paramDescTuple=" + paramDescTuple + "->argDescTuple=" - + argDescTuple); + // System.out.println("-------paramDescTuple=" + paramDescTuple + "->argDescTuple=" + // + argDescTuple); addMapCallerArgToCalleeParam(min, argDescTuple, paramDescTuple); } } @@ -2335,17 +2274,17 @@ public class LocationInference { addValueFlowFromCalleeNode(min, mdCaller, possibleMdCallee, calleeNode); } - System.out.println("$$$GLOBAL PC LOC ADD=" + mdCaller); + // System.out.println("$$$GLOBAL PC LOC ADD=" + mdCaller); Set> pcLocTupleSet = mapMethodInvokeNodeToPCLocTupleSet.get(min); - System.out.println("---pcLocTupleSet=" + pcLocTupleSet); + // System.out.println("---pcLocTupleSet=" + pcLocTupleSet); GlobalFlowGraph callerSubGlobalGraph = getSubGlobalFlowGraph(mdCaller); for (Iterator iterator = calleeNodeSet.iterator(); iterator.hasNext();) { GlobalFlowNode calleeNode = (GlobalFlowNode) iterator.next(); if (calleeNode.isParamNodeWithIncomingFlows()) { - System.out.println("calleeNode.getLocTuple()" + calleeNode.getLocTuple()); + // System.out.println("calleeNode.getLocTuple()" + calleeNode.getLocTuple()); NTuple callerSrcNodeLocTuple = translateToCallerLocTuple(min, possibleMdCallee, mdCaller, calleeNode.getLocTuple()); - System.out.println("---callerSrcNodeLocTuple=" + callerSrcNodeLocTuple); + // System.out.println("---callerSrcNodeLocTuple=" + callerSrcNodeLocTuple); if (callerSrcNodeLocTuple != null && callerSrcNodeLocTuple.size() > 0) { for (Iterator iterator2 = pcLocTupleSet.iterator(); iterator2.hasNext();) { NTuple pcLocTuple = (NTuple) iterator2.next(); @@ -2365,11 +2304,11 @@ public class LocationInference { GlobalFlowGraph calleeSubGlobalGraph = getSubGlobalFlowGraph(mdCallee); GlobalFlowGraph callerSubGlobalGraph = getSubGlobalFlowGraph(mdCaller); - System.out.println("$addValueFlowFromCalleeNode calleeSrcNode=" + calleeSrcNode); + // System.out.println("$addValueFlowFromCalleeNode calleeSrcNode=" + calleeSrcNode); NTuple callerSrcNodeLocTuple = translateToCallerLocTuple(min, mdCallee, mdCaller, calleeSrcNode.getLocTuple()); - System.out.println("---callerSrcNodeLocTuple=" + callerSrcNodeLocTuple); + // System.out.println("---callerSrcNodeLocTuple=" + callerSrcNodeLocTuple); if (callerSrcNodeLocTuple != null && callerSrcNodeLocTuple.size() > 0) { @@ -2499,7 +2438,7 @@ public class LocationInference { // set the 'this' reference location if (!md.isStatic()) { - System.out.println("setThisLocName=" + scGraph.getHNode(md.getThis()).getName()); + // System.out.println("setThisLocName=" + scGraph.getHNode(md.getThis()).getName()); methodSummary.setThisLocName(scGraph.getHNode(md.getThis()).getName()); } @@ -2514,8 +2453,8 @@ public class LocationInference { FlowNode flowNode = flowGraph.getParamFlowNode(paramIdx); CompositeLocation inferredCompLoc = updateCompositeLocation(flowNode.getCompositeLocation()); - System.out.println("-paramIdx=" + paramIdx + " infer=" + inferredCompLoc + " original=" - + flowNode.getCompositeLocation()); + // System.out.println("-paramIdx=" + paramIdx + " infer=" + inferredCompLoc + " original=" + // + flowNode.getCompositeLocation()); Descriptor localVarDesc = flowNode.getDescTuple().get(0); methodSummary.addMapVarNameToInferCompLoc(localVarDesc, inferredCompLoc); @@ -2549,9 +2488,9 @@ public class LocationInference { HNode node1 = hierarchyGraph.getHNode(locDesc1); HNode node2 = hierarchyGraph.getHNode(locDesc2); - System.out.println("---node1=" + node1 + " node2=" + node2); - System.out.println("---hierarchyGraph.getIncomingNodeSet(node2)=" - + hierarchyGraph.getIncomingNodeSet(node2)); + // System.out.println("---node1=" + node1 + " node2=" + node2); + // System.out.println("---hierarchyGraph.getIncomingNodeSet(node2)=" + // + hierarchyGraph.getIncomingNodeSet(node2)); if (locDesc1.equals(locDesc2)) { continue; @@ -2591,9 +2530,9 @@ public class LocationInference { HNode node1 = hierarchyGraph.getHNode(locDesc1); HNode node2 = hierarchyGraph.getHNode(locDesc2); - System.out.println("---node1=" + node1 + " node2=" + node2); - System.out.println("---hierarchyGraph.getIncomingNodeSet(node2)=" - + hierarchyGraph.getIncomingNodeSet(node2)); + // System.out.println("---node1=" + node1 + " node2=" + node2); + // System.out.println("---hierarchyGraph.getIncomingNodeSet(node2)=" + // + hierarchyGraph.getIncomingNodeSet(node2)); if (locDesc1.equals(locDesc2)) { continue; @@ -2626,41 +2565,59 @@ public class LocationInference { } LocationSummary ls = getLocationSummary(key); - System.out.println("####LOC SUMMARY=" + key + "\n" + ls.getMapHNodeNameToLocationName()); + // System.out.println("####LOC SUMMARY=" + key + "\n" + ls.getMapHNodeNameToLocationName()); } Set cdKeySet = cd2lattice.keySet(); for (Iterator iterator = cdKeySet.iterator(); iterator.hasNext();) { ClassDescriptor cd = (ClassDescriptor) iterator.next(); - System.out.println("########cd=" + cd); - writeInferredLatticeDotFile((ClassDescriptor) cd, getSkeletonCombinationHierarchyGraph(cd), - cd2lattice.get(cd), ""); + // System.out.println("########cd=" + cd); + writeInferredLatticeDotFile((ClassDescriptor) cd, cd2lattice.get(cd), ""); COUNT += cd2lattice.get(cd).getKeySet().size(); } Set mdKeySet = md2lattice.keySet(); for (Iterator iterator = mdKeySet.iterator(); iterator.hasNext();) { MethodDescriptor md = (MethodDescriptor) iterator.next(); - writeInferredLatticeDotFile(md.getClassDesc(), md, getSkeletonCombinationHierarchyGraph(md), - md2lattice.get(md), ""); + writeInferredLatticeDotFile(md.getClassDesc(), md, md2lattice.get(md), ""); COUNT += md2lattice.get(md).getKeySet().size(); } System.out.println("###COUNT=" + COUNT); + + Set descKeySet = desc2naiveLattice.keySet(); + for (Iterator iterator = descKeySet.iterator(); iterator.hasNext();) { + Descriptor desc = (Descriptor) iterator.next(); + // System.out.println("########cd=" + cd); + + ClassDescriptor cd_naive; + MethodDescriptor md_naive; + if (desc instanceof ClassDescriptor) { + cd_naive = (ClassDescriptor) desc; + md_naive = null; + } else { + md_naive = (MethodDescriptor) desc; + cd_naive = md_naive.getClassDesc(); + } + + writeInferredLatticeDotFile(cd_naive, md_naive, desc2naiveLattice.get(desc), "_naive"); + } } private void buildLattice(Descriptor desc) { - System.out.println("buildLattice=" + desc); + // System.out.println("buildLattice=" + desc); SSJavaLattice simpleLattice = buildLattice.buildLattice(desc); addMapDescToSimpleLattice(desc, simpleLattice); HierarchyGraph simpleHierarchyGraph = getSimpleHierarchyGraph(desc); - System.out.println("\n## insertIntermediateNodesToStraightLine:" - + simpleHierarchyGraph.getName()); + // System.out.println("\n## insertIntermediateNodesToStraightLine:" + // + simpleHierarchyGraph.getName()); SSJavaLattice lattice = buildLattice.insertIntermediateNodesToStraightLine(desc, simpleLattice); lattice.removeRedundantEdges(); + LocationInference.numLocationsSInfer += lattice.getKeySet().size(); + if (desc instanceof ClassDescriptor) { // field lattice cd2lattice.put((ClassDescriptor) desc, lattice); @@ -2675,6 +2632,7 @@ public class LocationInference { } + // deprecated: it builds method/class lattices without considering class inheritance private void buildLattice() { Set keySet = mapDescriptorToCombineSkeletonHierarchyGraph.keySet(); @@ -2692,6 +2650,8 @@ public class LocationInference { buildLattice.insertIntermediateNodesToStraightLine(desc, simpleLattice); lattice.removeRedundantEdges(); + LocationInference.numLocationsSInfer += lattice.getKeySet().size(); + if (desc instanceof ClassDescriptor) { // field lattice cd2lattice.put((ClassDescriptor) desc, lattice); @@ -2716,7 +2676,6 @@ public class LocationInference { public Set getDirectSubClasses(ClassDescriptor parent) { - System.out.println("$$$toanalyze_classDescSet=" + toanalyze_classDescSet); Set result = new HashSet(); Set children = tu.getDirectSubClasses(parent); @@ -2751,20 +2710,31 @@ public class LocationInference { MethodDescriptor parentMethodDesc = getParentMethodDesc(md.getClassDesc(), md); if (parentMethodDesc != null) { Map parentMap = buildLattice.getIntermediateLocMap(parentMethodDesc); - buildLattice.setIntermediateLocMap(md, parentMap); + Map childMap = new HashMap(); + Set keySet = parentMap.keySet(); + for (Iterator iterator2 = keySet.iterator(); iterator2.hasNext();) { + TripleItem key = (TripleItem) iterator2.next(); + childMap.put(key, parentMap.get(key)); + } + buildLattice.setIntermediateLocMap(md, childMap); } buildLattice(md); } } // traverse children - Set children = getDirectSubClasses(cd); - for (Iterator iterator = children.iterator(); iterator.hasNext();) { - ClassDescriptor classDescriptor = (ClassDescriptor) iterator.next(); - if (toanalyze_classDescSet.contains(classDescriptor)) { - DFSBuildLatticeInheritanceTree(classDescriptor); + Set children = tu.getDirectSubClasses(cd); + if (children != null) { + for (Iterator iterator = children.iterator(); iterator.hasNext();) { + ClassDescriptor classDescriptor = (ClassDescriptor) iterator.next(); + if (toanalyze_classDescSet.contains(classDescriptor)) { + DFSBuildLatticeInheritanceTree(classDescriptor); + } else { + if (classDescriptor.isAbstract()) { + DFSBuildLatticeInheritanceTree(classDescriptor); + } + } } - } } @@ -3041,7 +3011,7 @@ public class LocationInference { for (Iterator iterator2 = nodeToBeConnected.iterator(); iterator2.hasNext();) { HNode node = (HNode) iterator2.next(); - System.out.println("NEED TO BE CONNECTED TO TOP=" + node); + // System.out.println("NEED TO BE CONNECTED TO TOP=" + node); graph.addEdge(graph.getHNode(TOPDESC), node); } @@ -3142,7 +3112,7 @@ public class LocationInference { for (Iterator iterator2 = nodeToBeConnected.iterator(); iterator2.hasNext();) { HNode node = (HNode) iterator2.next(); - System.out.println("NEED TO BE CONNECTED TO TOP=" + node); + // System.out.println("NEED TO BE CONNECTED TO TOP=" + node); graph.addEdge(graph.getHNode(TOPDESC), node); } @@ -3183,12 +3153,12 @@ public class LocationInference { Set sourceNodeSet = new HashSet(); if (originalSrcNode instanceof FlowReturnNode) { FlowReturnNode rnode = (FlowReturnNode) originalSrcNode; - System.out.println("rnode=" + rnode); + // System.out.println("rnode=" + rnode); Set> tupleSet = rnode.getReturnTupleSet(); for (Iterator iterator2 = tupleSet.iterator(); iterator2.hasNext();) { NTuple nTuple = (NTuple) iterator2.next(); sourceNodeSet.add(fg.getFlowNode(nTuple)); - System.out.println("&&&SOURCE fg.getFlowNode(nTuple)=" + fg.getFlowNode(nTuple)); + // System.out.println("&&&SOURCE fg.getFlowNode(nTuple)=" + fg.getFlowNode(nTuple)); } } else { sourceNodeSet.add(originalSrcNode); @@ -3231,7 +3201,7 @@ public class LocationInference { for (Iterator iterator4 = tupleSet.iterator(); iterator4.hasNext();) { NTuple nTuple = (NTuple) iterator4.next(); dstNodeSet.add(fg.getFlowNode(nTuple)); - System.out.println("&&&DST fg.getFlowNode(nTuple)=" + fg.getFlowNode(nTuple)); + // System.out.println("&&&DST fg.getFlowNode(nTuple)=" + fg.getFlowNode(nTuple)); } } else { dstNodeSet.add(originalDstNode); @@ -3246,7 +3216,7 @@ public class LocationInference { if (dstLocalDesc instanceof InterDescriptor && ((InterDescriptor) dstLocalDesc).getMethodArgIdxPair() != null) { if (dstNode.getCompositeLocation() == null) { - System.out.println("%%%%%%%%%%%%%SKIP=" + dstNode); + // System.out.println("%%%%%%%%%%%%%SKIP=" + dstNode); continue; } } @@ -3270,8 +3240,8 @@ public class LocationInference { } // ////////////////////////// - System.out.println("-srcCurTuple=" + srcCurTuple + " dstCurTuple=" + dstCurTuple - + " srcNode=" + srcNode + " dstNode=" + dstNode); + // System.out.println("-srcCurTuple=" + srcCurTuple + " dstCurTuple=" + dstCurTuple + // + " srcNode=" + srcNode + " dstNode=" + dstNode); // srcCurTuple = translateBaseTuple(srcNode, srcCurTuple); // dstCurTuple = translateBaseTuple(dstNode, dstCurTuple); @@ -3356,7 +3326,7 @@ public class LocationInference { translatedTuple.add(inTuple.get(i)); } - System.out.println("------TRANSLATED " + inTuple + " -> " + translatedTuple); + // System.out.println("------TRANSLATED " + inTuple + " -> " + translatedTuple); return translatedTuple; } else { @@ -3449,6 +3419,9 @@ public class LocationInference { Map> map = lattice.getTable(); Set keySet = map.keySet(); + + // System.out.println("@generateLatticeDefinition=" + desc + " map=" + map); + boolean first = true; for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { String key = (String) iterator.next(); @@ -3495,7 +3468,7 @@ public class LocationInference { } if (desc instanceof MethodDescriptor) { - System.out.println("#EXTRA LOC DECLARATION GEN=" + desc); + // System.out.println("#EXTRA LOC DECLARATION GEN=" + desc); MethodDescriptor md = (MethodDescriptor) desc; MethodSummary methodSummary = getMethodSummary(md); @@ -3595,6 +3568,7 @@ public class LocationInference { } SSJavaLattice methodLattice = md2lattice.get(md); + // System.out.println("md=" + md + " methodLattice=" + methodLattice); if (methodLattice != null) { int methodDefLine = md.getLineNum(); @@ -3607,8 +3581,8 @@ public class LocationInference { Map mapVarDescToInferLoc = methodSummary.getMapVarDescToInferCompositeLocation(); - System.out.println("-----md=" + md); - System.out.println("-----mapVarDescToInferLoc=" + mapVarDescToInferLoc); + // System.out.println("-----md=" + md + " methodDefLine=" + methodDefLine); + // System.out.println("-----mapVarDescToInferLoc=" + mapVarDescToInferLoc); Set localVarDescSet = mapVarDescToInferLoc.keySet(); @@ -3616,7 +3590,7 @@ public class LocationInference { for (Iterator iterator = localVarDescSet.iterator(); iterator.hasNext();) { Descriptor localVarDesc = (Descriptor) iterator.next(); - System.out.println("-------localVarDesc=" + localVarDesc); + // System.out.println("-------localVarDesc=" + localVarDesc); CompositeLocation inferLoc = mapVarDescToInferLoc.get(localVarDesc); String localLocIdentifier = inferLoc.get(0).getLocIdentifier(); @@ -3630,12 +3604,12 @@ public class LocationInference { if (mapDescToDefinitionLine.containsKey(localVarDesc)) { int varLineNum = mapDescToDefinitionLine.get(localVarDesc); String orgSourceLine = sourceVec.get(varLineNum); - System.out.println("varLineNum=" + varLineNum + " org src=" + orgSourceLine); + // System.out.println("varLineNum=" + varLineNum + " org src=" + orgSourceLine); int idx = orgSourceLine.indexOf(generateVarDeclaration((VarDescriptor) localVarDesc)); - System.out.println("idx=" + idx - + " generateVarDeclaration((VarDescriptor) localVarDesc)=" - + generateVarDeclaration((VarDescriptor) localVarDesc)); + // System.out.println("idx=" + idx + // + " generateVarDeclaration((VarDescriptor) localVarDesc)=" + // + generateVarDeclaration((VarDescriptor) localVarDesc)); assert (idx != -1); String annoatedStr = orgSourceLine.substring(0, idx) + locAnnotationStr + " " @@ -3648,8 +3622,8 @@ public class LocationInference { int idx = getParamLocation(methodDefStr, generateVarDeclaration((VarDescriptor) localVarDesc)); - System.out.println("methodDefStr=" + methodDefStr + " localVarDesc=" + localVarDesc - + " idx=" + idx); + // System.out.println("methodDefStr=" + methodDefStr + " localVarDesc=" + localVarDesc + // + " idx=" + idx); assert (idx != -1); String annoatedStr = @@ -3811,7 +3785,7 @@ public class LocationInference { SSJavaLattice classLattice = cd2lattice.get(cd); if (classLattice != null) { ssjava.writeLatticeDotFile(cd, null, classLattice); - debug_printDescriptorToLocNameMapping(cd); + // debug_printDescriptorToLocNameMapping(cd); } while (!toAnalyzeMethodIsEmpty()) { @@ -3819,7 +3793,7 @@ public class LocationInference { SSJavaLattice methodLattice = md2lattice.get(md); if (methodLattice != null) { ssjava.writeLatticeDotFile(cd, md, methodLattice); - debug_printDescriptorToLocNameMapping(md); + // debug_printDescriptorToLocNameMapping(md); } } } @@ -3946,7 +3920,7 @@ public class LocationInference { private void calculatePCLOC(MethodDescriptor md) { - System.out.println("#CalculatePCLOC"); + // System.out.println("#CalculatePCLOC"); MethodSummary methodSummary = getMethodSummary(md); FlowGraph fg = getFlowGraph(md); Map mapParamToLoc = methodSummary.getMapParamIdxToInferLoc(); @@ -3989,7 +3963,7 @@ public class LocationInference { } } - System.out.println("paramLocTupleHavingInFlowSet=" + paramLocTupleHavingInFlowSet); + // System.out.println("paramLocTupleHavingInFlowSet=" + paramLocTupleHavingInFlowSet); if (paramLocTupleHavingInFlowSet.size() > 0 && !coversAllParamters(md, fg, paramLocTupleHavingInFlowSet)) { @@ -4023,14 +3997,13 @@ public class LocationInference { translateToLocTuple(md, node.getDescTuple())); } } else { - System.out.println("***SKIP PCLOC -> RETURNLOC=" + node); + // System.out.println("***SKIP PCLOC -> RETURNLOC=" + node); } } fg.getFlowNode(translateToDescTuple(pcLocTuple)).setSkeleton(true); if (pcLocTuple.get(0).getLocDescriptor().equals(md.getThis())) { - System.out.println("#########################################"); for (Iterator iterator = flowNodeLowerthanPCLocSet.iterator(); iterator.hasNext();) { FlowNode lowerNode = (FlowNode) iterator.next(); if (lowerNode.getDescTuple().size() == 1 && lowerNode.getCompositeLocation() == null) { @@ -4041,7 +4014,7 @@ public class LocationInference { subGlobalFlowGraph.addMapLocationToInferCompositeLocation(lowerLocTuple.get(0), newComp); lowerNode.setCompositeLocation(newComp); - System.out.println("NEW COMP LOC=" + newComp + " to lowerNode=" + lowerNode); + // System.out.println("NEW COMP LOC=" + newComp + " to lowerNode=" + lowerNode); } } @@ -4073,7 +4046,7 @@ public class LocationInference { // int size = paramLocTupleHavingInFlowSet.size(); int size = countFirstDescriptorSetSize(paramLocTupleHavingInFlowSet); - System.out.println("numParam=" + numParam + " size=" + size); + // System.out.println("numParam=" + numParam + " size=" + size); // if (!md.isStatic()) { // @@ -4109,7 +4082,7 @@ public class LocationInference { private void calculateRETURNLOC(MethodDescriptor md) { - System.out.println("#calculateRETURNLOC= " + md); + // System.out.println("#calculateRETURNLOC= " + md); // calculate a return location: // the return location type is lower than all parameters and the location of return values @@ -4144,8 +4117,8 @@ public class LocationInference { NTuple returnDescTuple = returnNode.getCurrentDescTuple(); tupleToBeHigherThanReturnLocSet.add(translateToLocTuple(md, returnDescTuple)); } - System.out.println("-flow graph's returnNodeSet=" + returnNodeSet); - System.out.println("tupleSetToBeHigherThanReturnLoc=" + tupleToBeHigherThanReturnLocSet); + // System.out.println("-flow graph's returnNodeSet=" + returnNodeSet); + // System.out.println("tupleSetToBeHigherThanReturnLoc=" + tupleToBeHigherThanReturnLocSet); // Here, generates a return location in the method lattice that is lower than the // locFlowingToReturnValueSet @@ -4249,7 +4222,7 @@ public class LocationInference { break; } Location newLocElement = new Location(curLoc.getDescriptor(), curLoc.getLocDescriptor()); - System.out.println("newLocElement" + newLocElement); + // System.out.println("newLocElement" + newLocElement); higherLocTuple.add(newLocElement); enclosingDesc = getClassTypeDescriptor(curLoc.getLocDescriptor()); } @@ -4260,7 +4233,7 @@ public class LocationInference { NameDescriptor locDesc = new NameDescriptor(locIdentifier); Location newLoc = new Location(enclosingDesc, locDesc); higherLocTuple.add(newLoc); - System.out.println("---new loc tuple=" + higherLocTuple); + // System.out.println("---new loc tuple=" + higherLocTuple); return higherLocTuple; @@ -4447,7 +4420,7 @@ public class LocationInference { private void propagateFlowsToCallerWithNoCompositeLocation(MethodInvokeNode min, MethodDescriptor mdCaller, MethodDescriptor mdCallee) { - System.out.println("-propagateFlowsToCallerWithNoCompositeLocation=" + min.printNode(0)); + // System.out.println("-propagateFlowsToCallerWithNoCompositeLocation=" + min.printNode(0)); // if the parameter A reaches to the parameter B // then, add an edge the argument A -> the argument B to the caller's flow // graph @@ -4517,17 +4490,17 @@ public class LocationInference { for (int idx = 0; idx < numParam; idx++) { FlowNode paramNode = calleeFlowGraph.getParamFlowNode(idx); CompositeLocation compLoc = paramNode.getCompositeLocation(); - System.out.println("paramNode=" + paramNode + " compLoc=" + compLoc); + // System.out.println("paramNode=" + paramNode + " compLoc=" + compLoc); if (compLoc != null && compLoc.get(0).getLocDescriptor().equals(min.getMethod().getThis())) { - System.out.println("$$$COMPLOC CASE=" + compLoc + " idx=" + idx); + // System.out.println("$$$COMPLOC CASE=" + compLoc + " idx=" + idx); NTuple argTuple = getNodeTupleByArgIdx(min, idx); - System.out.println("--- argTuple=" + argTuple + " current compLoc=" - + callerFlowGraph.getFlowNode(argTuple).getCompositeLocation()); + // System.out.println("--- argTuple=" + argTuple + " current compLoc=" + // + callerFlowGraph.getFlowNode(argTuple).getCompositeLocation()); NTuple translatedParamTuple = translateCompositeLocationToCaller(idx, min, compLoc); - System.out.println("add a flow edge= " + argTuple + "->" + translatedParamTuple); + // System.out.println("add a flow edge= " + argTuple + "->" + translatedParamTuple); callerFlowGraph.addValueFlowEdge(argTuple, translatedParamTuple); Set> pcLocTupleSet = getPCLocTupleSet(min); @@ -4546,7 +4519,7 @@ public class LocationInference { for (Iterator iterator = set.iterator(); iterator.hasNext();) { FlowNode flowNode = (FlowNode) iterator.next(); if (flowNode.getDescTuple().startsWith(prefixDesc)) { - System.out.println("FOUND=" + flowNode); + // System.out.println("FOUND=" + flowNode); return true; } } @@ -4573,7 +4546,7 @@ public class LocationInference { private CompositeLocation generateCompositeLocation(NTuple prefixLocTuple) { - System.out.println("generateCompositeLocation=" + prefixLocTuple); + // System.out.println("generateCompositeLocation=" + prefixLocTuple); CompositeLocation newCompLoc = new CompositeLocation(); for (int i = 0; i < prefixLocTuple.size(); i++) { @@ -4609,7 +4582,7 @@ public class LocationInference { private CompositeLocation generateCompositeLocation(MethodDescriptor md, NTuple paramPrefix) { - System.out.println("generateCompositeLocation=" + paramPrefix); + // System.out.println("generateCompositeLocation=" + paramPrefix); CompositeLocation newCompLoc = convertToCompositeLocation(md, paramPrefix); @@ -4863,14 +4836,14 @@ public class LocationInference { Descriptor srcFieldDesc = srcCurTuple.get(idx); Descriptor dstFieldDesc = dstCurTuple.get(idx); - System.out.println("srcFieldDesc=" + srcFieldDesc + " dstFieldDesc=" + dstFieldDesc - + " idx=" + idx); + // System.out.println("srcFieldDesc=" + srcFieldDesc + " dstFieldDesc=" + dstFieldDesc + // + " idx=" + idx); if (!srcFieldDesc.equals(dstFieldDesc)) { // add a new edge - System.out.println("-ADD EDGE"); + // System.out.println("-ADD EDGE"); getHierarchyGraph(cd).addEdge(srcFieldDesc, dstFieldDesc); } else if (!isReference(srcFieldDesc) && !isReference(dstFieldDesc)) { - System.out.println("-ADD EDGE"); + // System.out.println("-ADD EDGE"); getHierarchyGraph(cd).addEdge(srcFieldDesc, dstFieldDesc); } @@ -4969,23 +4942,31 @@ public class LocationInference { // hack... it seems that there is a problem with topological sorting. // so String.toString(Object o) is appeared too higher in the call chain. - // MethodDescriptor mdToString = null; - // for (Iterator iterator = toanalyze_methodDescList.iterator(); iterator.hasNext();) { - // MethodDescriptor md = (MethodDescriptor) iterator.next(); - // if (md.toString().equals("public static String String.valueOf(Object o)")) { - // mdToString = md; - // break; - // } - // } - // if (mdToString != null) { - // toanalyze_methodDescList.remove(mdToString); - // toanalyze_methodDescList.addLast(mdToString); - // } + MethodDescriptor mdToString1 = null; + MethodDescriptor mdToString2 = null; + for (Iterator iterator = toanalyze_methodDescList.iterator(); iterator.hasNext();) { + MethodDescriptor md = (MethodDescriptor) iterator.next(); + if (md.toString().equals("public static String String.valueOf(Object o)")) { + mdToString1 = md; + } + if (md.toString().equals("public String Object.toString()")) { + mdToString2 = md; + } + } + + if (mdToString1 != null) { + toanalyze_methodDescList.remove(mdToString1); + toanalyze_methodDescList.addLast(mdToString1); + } + if (mdToString2 != null) { + toanalyze_methodDescList.remove(mdToString2); + toanalyze_methodDescList.addLast(mdToString2); + } LinkedList methodDescList = (LinkedList) toanalyze_methodDescList.clone(); - System.out.println("@@@methodDescList=" + methodDescList); + // System.out.println("@@@methodDescList=" + methodDescList); // System.exit(0); while (!methodDescList.isEmpty()) { @@ -5041,7 +5022,7 @@ public class LocationInference { constructSubGlobalFlowGraph(getFlowGraph(md)); // TODO - System.out.println("-add Value Flows From CalleeSubGlobalFlowGraph"); + // System.out.println("-add Value Flows From CalleeSubGlobalFlowGraph"); addValueFlowsFromCalleeSubGlobalFlowGraph(md); // subGlobalFlowGraph.writeGraph("_SUBGLOBAL"); @@ -5062,7 +5043,7 @@ public class LocationInference { Set paramFlowNodeSet = flowGraph.getParamFlowNodeSet(); for (Iterator iterator = paramFlowNodeSet.iterator(); iterator.hasNext();) { FlowNode paramFlowNode = (FlowNode) iterator.next(); - System.out.println("paramFlowNode=" + paramFlowNode); + // System.out.println("paramFlowNode=" + paramFlowNode); NTuple paramDescTuple = paramFlowNode.getDescTuple(); NTuple paramLocTuple = translateToLocTuple(md, paramDescTuple); GlobalFlowNode paramGlobalNode = globalFlowGraph.getFlowNode(paramLocTuple); @@ -5196,7 +5177,6 @@ public class LocationInference { if (needToGenerateInterLoc(newImplicitTupleSet)) { // need to create an intermediate node for the GLB of conditional // locations & implicit flows - System.out.println("10"); NTuple interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple(); for (Iterator> idxIter = newImplicitTupleSet.iterator(); idxIter.hasNext();) { @@ -5263,7 +5243,6 @@ public class LocationInference { // System.out.println("---currentFlowTupleSet=" + currentFlowTupleSet); if (needToGenerateInterLoc(currentFlowTupleSet)) { - System.out.println("9"); FlowNode meetNode = fg.createIntermediateNode(); for (Iterator iterator = currentFlowTupleSet.iterator(); iterator.hasNext();) { @@ -5303,7 +5282,7 @@ public class LocationInference { } } if (size > 1) { - System.out.println("needToGenerateInterLoc=" + tupleSet + " size=" + size); + // System.out.println("needToGenerateInterLoc=" + tupleSet + " size=" + size); return true; } else { return false; @@ -5330,7 +5309,6 @@ public class LocationInference { if (needToGenerateInterLoc(newImplicitTupleSet)) { // need to create an intermediate node for the GLB of conditional // locations & implicit flows - System.out.println("6"); NTuple interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple(); for (Iterator> idxIter = newImplicitTupleSet.iterator(); idxIter @@ -5391,7 +5369,6 @@ public class LocationInference { if (needToGenerateInterLoc(newImplicitTupleSet)) { // need to create an intermediate node for the GLB of conditional // locations & implicit flows - System.out.println("7"); NTuple interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple(); for (Iterator> idxIter = newImplicitTupleSet.iterator(); idxIter @@ -5455,7 +5432,6 @@ public class LocationInference { // System.out.println("-newImplicitTupleSet=" + newImplicitTupleSet); if (needToGenerateInterLoc(newImplicitTupleSet)) { - System.out.println("5"); // need to create an intermediate node for the GLB of conditional locations & implicit flows NTuple interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple(); @@ -5498,7 +5474,7 @@ public class LocationInference { fn.setDeclarationNode(); if (dn.getExpression() != null) { - System.out.println("-analyzeFlowDeclarationNode=" + dn.printNode(0)); + // System.out.println("-analyzeFlowDeclarationNode=" + dn.printNode(0)); NodeTupleSet nodeSetRHS = new NodeTupleSet(); analyzeFlowExpressionNode(md, nametable, dn.getExpression(), nodeSetRHS, null, @@ -5507,14 +5483,13 @@ public class LocationInference { // creates edges from RHS to LHS NTuple interTuple = null; if (needToGenerateInterLoc(nodeSetRHS)) { - System.out.println("3"); interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple(); } for (Iterator> iter = nodeSetRHS.iterator(); iter.hasNext();) { NTuple fromTuple = iter.next(); - System.out.println("fromTuple=" + fromTuple + " interTuple=" + interTuple + " tupleLSH=" - + tupleLHS); + // System.out.println("fromTuple=" + fromTuple + " interTuple=" + interTuple + " tupleLSH=" + // + tupleLHS); addFlowGraphEdge(md, fromTuple, interTuple, tupleLHS); } @@ -5538,8 +5513,8 @@ public class LocationInference { globalFlowGraph.addValueFlowEdge(implicitGlobalTuple, translateToLocTuple(md, tupleLHS)); } - System.out.println("-nodeSetRHS=" + nodeSetRHS); - System.out.println("-implicitFlowTupleSet=" + implicitFlowTupleSet); + // System.out.println("-nodeSetRHS=" + nodeSetRHS); + // System.out.println("-implicitFlowTupleSet=" + implicitFlowTupleSet); } @@ -5595,7 +5570,7 @@ public class LocationInference { break; case Kind.CreateObjectNode: - analyzeCreateObjectNode(md, nametable, (CreateObjectNode) en); + analyzeCreateObjectNode(md, nametable, (CreateObjectNode) en, nodeSet, implicitFlowTupleSet); break; case Kind.ArrayAccessNode: @@ -5668,7 +5643,6 @@ public class LocationInference { // System.out.println("-newImplicitTupleSet=" + newImplicitTupleSet); if (needToGenerateInterLoc(newImplicitTupleSet)) { - System.out.println("15"); // need to create an intermediate node for the GLB of conditional locations & implicit flows NTuple interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple(); for (Iterator> idxIter = newImplicitTupleSet.iterator(); idxIter.hasNext();) { @@ -5681,7 +5655,8 @@ public class LocationInference { newImplicitTupleSet.addGlobalFlowTupleSet(tertiaryTupleNode.getGlobalLocTupleSet()); - System.out.println("---------newImplicitTupleSet=" + newImplicitTupleSet); + // System.out.println("---------newImplicitTupleSet=" + newImplicitTupleSet); + // add edges from tertiaryTupleNode to all nodes of conditional nodes // tertiaryTupleNode.addTupleSet(implicitFlowTupleSet); analyzeFlowExpressionNode(md, nametable, tn.getTrueExpr(), tertiaryTupleNode, null, @@ -5693,7 +5668,7 @@ public class LocationInference { nodeSet.addGlobalFlowTupleSet(tertiaryTupleNode.getGlobalLocTupleSet()); nodeSet.addTupleSet(tertiaryTupleNode); - System.out.println("#tertiary node set=" + nodeSet); + // System.out.println("#tertiary node set=" + nodeSet); } private void addMapCallerMethodDescToMethodInvokeNodeSet(MethodDescriptor caller, @@ -5733,7 +5708,7 @@ public class LocationInference { private void analyzeFlowMethodInvokeNode(MethodDescriptor mdCaller, SymbolTable nametable, MethodInvokeNode min, NodeTupleSet nodeSet, NodeTupleSet implicitFlowTupleSet) { - System.out.println("analyzeFlowMethodInvokeNode=" + min.printNode(0)); + // System.out.println("analyzeFlowMethodInvokeNode=" + min.printNode(0)); if (!toanalyze_methodDescList.contains(min.getMethod())) { return; @@ -5770,10 +5745,10 @@ public class LocationInference { addMapCallerMethodDescToMethodInvokeNodeSet(mdCaller, min); FlowGraph calleeFlowGraph = getFlowGraph(mdCallee); - System.out.println("mdCallee=" + mdCallee + " calleeFlowGraph=" + calleeFlowGraph); + // System.out.println("mdCallee=" + mdCallee + " calleeFlowGraph=" + calleeFlowGraph); Set calleeReturnSet = calleeFlowGraph.getReturnNodeSet(); - System.out.println("---calleeReturnSet=" + calleeReturnSet); + // System.out.println("---calleeReturnSet=" + calleeReturnSet); NodeTupleSet tupleSet = new NodeTupleSet(); @@ -5782,7 +5757,7 @@ public class LocationInference { NodeTupleSet baseNodeSet = new NodeTupleSet(); analyzeFlowExpressionNode(mdCaller, nametable, min.getExpression(), baseNodeSet, null, implicitFlowTupleSet, false); - System.out.println("baseNodeSet=" + baseNodeSet); + // System.out.println("baseNodeSet=" + baseNodeSet); assert (baseNodeSet.size() == 1); NTuple baseTuple = baseNodeSet.iterator().next(); @@ -5814,21 +5789,21 @@ public class LocationInference { inFlowTuple.addAll(returnDescTuple.subList(1, returnDescTuple.size())); // nodeSet.addTuple(inFlowTuple); - System.out.println("1CREATE A NEW TUPLE=" + inFlowTuple + " from=" - + mdCallee.getThis()); + // System.out.println("1CREATE A NEW TUPLE=" + inFlowTuple + " from=" + // + mdCallee.getThis()); // tupleSet.addTuple(inFlowTuple); tupleSet.addTuple(baseTuple); } else { // TODO - System.out.println("returnNode=" + returnNode); + // System.out.println("returnNode=" + returnNode); Set inFlowSet = calleeFlowGraph.getIncomingFlowNodeSet(returnNode); // System.out.println("inFlowSet=" + inFlowSet + " from retrunNode=" + returnNode); for (Iterator iterator2 = inFlowSet.iterator(); iterator2.hasNext();) { FlowNode inFlowNode = (FlowNode) iterator2.next(); if (inFlowNode.getDescTuple().startsWith(mdCallee.getThis())) { // nodeSet.addTupleSet(baseNodeSet); - System.out.println("2CREATE A NEW TUPLE=" + baseNodeSet + " from=" - + mdCallee.getThis()); + // System.out.println("2CREATE A NEW TUPLE=" + baseNodeSet + " from=" + // + mdCallee.getThis()); tupleSet.addTupleSet(baseNodeSet); } } @@ -5854,7 +5829,7 @@ public class LocationInference { NodeTupleSet argTupleSet = new NodeTupleSet(); analyzeFlowExpressionNode(mdCaller, nametable, en, argTupleSet, false); // if argument is liternal node, argTuple is set to NULL - System.out.println("---arg idx=" + idx + " argTupleSet=" + argTupleSet); + // System.out.println("---arg idx=" + idx + " argTupleSet=" + argTupleSet); NTuple argTuple = generateArgTuple(mdCaller, argTupleSet); // if an argument is literal value, @@ -5890,12 +5865,12 @@ public class LocationInference { // } // } - System.out.println("paramNode=" + paramNode + " calleeReturnSet=" + calleeReturnSet); + // System.out.println("paramNode=" + paramNode + " calleeReturnSet=" + calleeReturnSet); if (hasInFlowTo(calleeFlowGraph, paramNode, calleeReturnSet) || mdCallee.getModifiers().isNative()) { addParamNodeFlowingToReturnValue(mdCallee, paramNode); // nodeSet.addTupleSet(argTupleSet); - System.out.println("3CREATE A NEW TUPLE=" + argTupleSet + " from=" + paramNode); + // System.out.println("3CREATE A NEW TUPLE=" + argTupleSet + " from=" + paramNode); tupleSet.addTupleSet(argTupleSet); } } @@ -5906,7 +5881,6 @@ public class LocationInference { FlowReturnNode returnHolderNode = getFlowGraph(mdCaller).createReturnNode(min); if (needToGenerateInterLoc(tupleSet)) { - System.out.println("20"); FlowGraph fg = getFlowGraph(mdCaller); FlowNode interNode = fg.createIntermediateNode(); interNode.setFormHolder(true); @@ -5932,11 +5906,12 @@ public class LocationInference { returnHolderNode.addTuple(interTuple); nodeSet.addTuple(interTuple); - System.out.println("ADD TUPLESET=" + interTuple + " to returnnode=" + returnHolderNode); + // System.out.println("ADD TUPLESET=" + interTuple + " to returnnode=" + + // returnHolderNode); } else { returnHolderNode.addTupleSet(tupleSet); - System.out.println("ADD TUPLESET=" + tupleSet + " to returnnode=" + returnHolderNode); + // System.out.println("ADD TUPLESET=" + tupleSet + " to returnnode=" + returnHolderNode); } // setNode.addTupleSet(tupleSet); // NodeTupleSet setFromReturnNode=new NodeTupleSet(); @@ -5945,7 +5920,7 @@ public class LocationInference { NodeTupleSet holderTupleSet = getNodeTupleSetFromReturnNode(getFlowGraph(mdCaller), returnHolderNode); - System.out.println("HOLDER TUPLe SET=" + holderTupleSet); + // System.out.println("HOLDER TUPLE SET=" + holderTupleSet); nodeSet.addTupleSet(holderTupleSet); nodeSet.addTuple(returnHolderNode.getDescTuple()); @@ -5960,7 +5935,7 @@ public class LocationInference { FlowNode calleeReturnNode = (FlowNode) iterator.next(); NTuple calleeReturnLocTuple = translateToLocTuple(mdCallee, calleeReturnNode.getDescTuple()); - System.out.println("calleeReturnLocTuple=" + calleeReturnLocTuple); + // System.out.println("calleeReturnLocTuple=" + calleeReturnLocTuple); NTuple transaltedToCaller = translateToCallerLocTuple(min, mdCallee, mdCaller, calleeReturnLocTuple); // System.out.println("translateToCallerLocTuple=" @@ -5971,7 +5946,7 @@ public class LocationInference { } } - System.out.println("min nodeSet=" + nodeSet); + // System.out.println("min nodeSet=" + nodeSet); } @@ -6039,7 +6014,6 @@ public class LocationInference { } if (argTupleSetNonLiteral.size() > 1) { - System.out.println("11"); NTuple interTuple = getFlowGraph(mdCaller).createIntermediateNode().getDescTuple(); @@ -6102,14 +6076,14 @@ public class LocationInference { private void analyzeFlowArrayAccessNode(MethodDescriptor md, SymbolTable nametable, ArrayAccessNode aan, NodeTupleSet nodeSet, boolean isLHS) { - System.out.println("analyzeFlowArrayAccessNode aan=" + aan.printNode(0)); + // System.out.println("analyzeFlowArrayAccessNode aan=" + aan.printNode(0)); String currentArrayAccessNodeExpStr = aan.printNode(0); arrayAccessNodeStack.push(aan.printNode(0)); NodeTupleSet expNodeTupleSet = new NodeTupleSet(); NTuple base = analyzeFlowExpressionNode(md, nametable, aan.getExpression(), expNodeTupleSet, isLHS); - System.out.println("-base=" + base); + // System.out.println("-base=" + base); nodeSet.setMethodInvokeBaseDescTuple(base); NodeTupleSet idxNodeTupleSet = new NodeTupleSet(); @@ -6150,7 +6124,6 @@ public class LocationInference { || !arrayAccessNodeStack.peek().startsWith(currentArrayAccessNodeExpStr)) { if (needToGenerateInterLoc(nodeSetArrayAccessExp)) { - System.out.println("1"); FlowNode interNode = getFlowGraph(md).createIntermediateNode(); NTuple interTuple = interNode.getDescTuple(); @@ -6162,7 +6135,7 @@ public class LocationInference { nodeSetArrayAccessExp.addTuple(interTuple); FlowGraph fg = getFlowGraph(md); - System.out.println("base=" + base); + // System.out.println("base=" + base); if (base != null) { fg.addMapInterLocNodeToEnclosingDescriptor(interTuple.get(0), getClassTypeDescriptor(base.get(base.size() - 1))); @@ -6179,8 +6152,18 @@ public class LocationInference { } private void analyzeCreateObjectNode(MethodDescriptor md, SymbolTable nametable, - CreateObjectNode en) { - // TODO Auto-generated method stub + CreateObjectNode en, NodeTupleSet nodeSet, NodeTupleSet implicitFlowTupleSet) { + // System.out.println("#analyzeCreateObjectNode=" + en.printNode(0)); + int numArgs = en.numArgs(); + NodeTupleSet argSet = new NodeTupleSet(); + + for (int i = 0; i < numArgs; i++) { + analyzeFlowExpressionNode(md, nametable, en.getArg(i), argSet, null, implicitFlowTupleSet, + false); + } + + // System.out.println("###argSet=" + argSet); + nodeSet.addTupleSet(argSet); } @@ -6190,19 +6173,17 @@ public class LocationInference { NodeTupleSet leftOpSet = new NodeTupleSet(); NodeTupleSet rightOpSet = new NodeTupleSet(); - System.out.println("analyzeFlowOpNode=" + on.printNode(0)); + // System.out.println("analyzeFlowOpNode=" + on.printNode(0)); // left operand analyzeFlowExpressionNode(md, nametable, on.getLeft(), leftOpSet, null, implicitFlowTupleSet, false); - System.out.println("--leftOpSet=" + leftOpSet); if (on.getRight() != null) { // right operand analyzeFlowExpressionNode(md, nametable, on.getRight(), rightOpSet, null, implicitFlowTupleSet, false); } - System.out.println("--rightOpSet=" + rightOpSet); Operation op = on.getOp(); @@ -6422,8 +6403,7 @@ public class LocationInference { nodeSetArrayAccessExp.addTupleSet(nodeSet); if (needToGenerateInterLoc(nodeSetArrayAccessExp)) { - System.out.println("4"); - System.out.println("nodeSetArrayAccessExp=" + nodeSetArrayAccessExp); + // System.out.println("nodeSetArrayAccessExp=" + nodeSetArrayAccessExp); // System.out.println("idxNodeTupleSet.getGlobalLocTupleSet()=" // + idxNodeTupleSet.getGlobalLocTupleSet()); @@ -6483,10 +6463,10 @@ public class LocationInference { analyzeFlowExpressionNode(md, nametable, an.getSrc(), nodeSetRHS, null, implicitFlowTupleSet, false); - System.out.println("-analyzeFlowAssignmentNode=" + an.printNode(0)); - System.out.println("-nodeSetLHS=" + nodeSetLHS); - System.out.println("-nodeSetRHS=" + nodeSetRHS); - System.out.println("-implicitFlowTupleSet=" + implicitFlowTupleSet); + // System.out.println("-analyzeFlowAssignmentNode=" + an.printNode(0)); + // System.out.println("-nodeSetLHS=" + nodeSetLHS); + // System.out.println("-nodeSetRHS=" + nodeSetRHS); + // System.out.println("-implicitFlowTupleSet=" + implicitFlowTupleSet); // System.out.println("-"); if (an.getOperation().getOp() >= 2 && an.getOperation().getOp() <= 12) { @@ -6504,7 +6484,6 @@ public class LocationInference { // creates edges from RHS to LHS NTuple interTuple = null; if (needToGenerateInterLoc(nodeSetRHS)) { - System.out.println("2"); interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple(); } @@ -6531,8 +6510,8 @@ public class LocationInference { NTuple calleeReturnLocTuple = iterator.next(); for (Iterator> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) { NTuple callerLHSTuple = iter2.next(); - System.out.println("$$$ GLOBAL FLOW ADD=" + calleeReturnLocTuple + " -> " - + translateToLocTuple(md, callerLHSTuple)); + // System.out.println("$$$ GLOBAL FLOW ADD=" + calleeReturnLocTuple + " -> " + // + translateToLocTuple(md, callerLHSTuple)); globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, translateToLocTuple(md, callerLHSTuple)); @@ -6547,8 +6526,8 @@ public class LocationInference { globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, translateToLocTuple(md, callerLHSTuple)); - System.out.println("$$$ GLOBAL FLOW PCLOC ADD=" + calleeReturnLocTuple + " -> " - + translateToLocTuple(md, callerLHSTuple)); + // System.out.println("$$$ GLOBAL FLOW PCLOC ADD=" + calleeReturnLocTuple + " -> " + // + translateToLocTuple(md, callerLHSTuple)); } } @@ -6577,8 +6556,8 @@ public class LocationInference { NTuple callerLHSTuple = iter2.next(); globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, translateToLocTuple(md, callerLHSTuple)); - System.out.println("$$$ GLOBAL FLOW PC ADD=" + calleeReturnLocTuple + " -> " - + translateToLocTuple(md, callerLHSTuple)); + // System.out.println("$$$ GLOBAL FLOW PC ADD=" + calleeReturnLocTuple + " -> " + // + translateToLocTuple(md, callerLHSTuple)); } } @@ -6615,15 +6594,15 @@ public class LocationInference { } - public void writeInferredLatticeDotFile(ClassDescriptor cd, HierarchyGraph simpleHierarchyGraph, - SSJavaLattice locOrder, String nameSuffix) { - System.out.println("@cd=" + cd); - System.out.println("@sharedLoc=" + locOrder.getSharedLocSet()); - writeInferredLatticeDotFile(cd, null, simpleHierarchyGraph, locOrder, nameSuffix); + public void writeInferredLatticeDotFile(ClassDescriptor cd, SSJavaLattice locOrder, + String nameSuffix) { + // System.out.println("@cd=" + cd); + // System.out.println("@sharedLoc=" + locOrder.getSharedLocSet()); + writeInferredLatticeDotFile(cd, null, locOrder, nameSuffix); } public void writeInferredLatticeDotFile(ClassDescriptor cd, MethodDescriptor md, - HierarchyGraph simpleHierarchyGraph, SSJavaLattice locOrder, String nameSuffix) { + SSJavaLattice locOrder, String nameSuffix) { String fileName = "lattice_"; if (md != null) { @@ -6655,12 +6634,12 @@ public class LocationInference { String lowLocId = pair.getSecond(); if (!addedLocSet.contains(highLocId)) { addedLocSet.add(highLocId); - drawNode(bw, locOrder, simpleHierarchyGraph, highLocId); + drawNode(bw, locOrder, highLocId); } if (!addedLocSet.contains(lowLocId)) { addedLocSet.add(lowLocId); - drawNode(bw, locOrder, simpleHierarchyGraph, lowLocId); + drawNode(bw, locOrder, lowLocId); } bw.write(highLocId + " -> " + lowLocId + ";\n"); @@ -6689,8 +6668,12 @@ public class LocationInference { return str; } - private void drawNode(BufferedWriter bw, SSJavaLattice lattice, HierarchyGraph graph, - String locName) throws IOException { + public void addNaiveLattice(Descriptor desc, SSJavaLattice lattice) { + desc2naiveLattice.put(desc, lattice); + } + + private void drawNode(BufferedWriter bw, SSJavaLattice lattice, String locName) + throws IOException { String prettyStr; if (lattice.isSharedLoc(locName)) {