From: yeom Date: Sun, 14 Oct 2012 00:55:36 +0000 (+0000) Subject: changes. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=aec24fc101dec2a1ece71783932d11eb46704ebe;p=IRC.git changes. --- diff --git a/Robust/src/Analysis/SSJava/BuildLattice.java b/Robust/src/Analysis/SSJava/BuildLattice.java index 621f9efd..b3cdd8ae 100644 --- a/Robust/src/Analysis/SSJava/BuildLattice.java +++ b/Robust/src/Analysis/SSJava/BuildLattice.java @@ -7,6 +7,7 @@ import java.util.Map; import java.util.Set; import IR.Descriptor; +import IR.MethodDescriptor; import Util.Pair; public class BuildLattice { @@ -28,7 +29,30 @@ public class BuildLattice { HierarchyGraph inputGraph = infer.getSkeletonCombinationHierarchyGraph(desc); LocationSummary locSummary = infer.getLocationSummary(desc); - BasisSet basisSet = inputGraph.computeBasisSet(); + Set nodeSetWithCompositeLocation = new HashSet(); + if (desc instanceof MethodDescriptor) { + FlowGraph flowGraph = infer.getFlowGraph((MethodDescriptor) desc); + + for (Iterator iterator = inputGraph.getNodeSet().iterator(); iterator.hasNext();) { + HNode hnode = (HNode) iterator.next(); + Descriptor hnodeDesc = hnode.getDescriptor(); + if (hnodeDesc != null) { + NTuple descTuple = new NTuple(); + descTuple.add(hnodeDesc); + + if (flowGraph.contains(descTuple)) { + FlowNode flowNode = flowGraph.getFlowNode(descTuple); + if (flowNode.getCompositeLocation() != null) { + nodeSetWithCompositeLocation.add(hnode); + } + } + + } + } + + } + + BasisSet basisSet = inputGraph.computeBasisSet(nodeSetWithCompositeLocation); debug_print(inputGraph); Family family = generateFamily(basisSet); @@ -85,7 +109,6 @@ public class BuildLattice { } // locSummary.addMapHNodeNameToLocationName(lowerName, lowerName); - // System.out.println("higherName=" + higherName + " lowerName=" + lowerName); if (higher.size() == 0) { // empty case lattice.put(lowerName); diff --git a/Robust/src/Analysis/SSJava/FlowGraph.java b/Robust/src/Analysis/SSJava/FlowGraph.java index d0a854b8..ca867983 100644 --- a/Robust/src/Analysis/SSJava/FlowGraph.java +++ b/Robust/src/Analysis/SSJava/FlowGraph.java @@ -286,6 +286,10 @@ public class FlowGraph { mapFlowNodeToOutEdgeSet.get(fromNode).add(edge); } + public boolean contains(NTuple descTuple) { + return mapDescTupleToInferNode.containsKey(descTuple); + } + public FlowNode getFlowNode(NTuple descTuple) { if (!mapDescTupleToInferNode.containsKey(descTuple)) { FlowNode node = createNewFlowNode(descTuple); diff --git a/Robust/src/Analysis/SSJava/GlobalFlowGraph.java b/Robust/src/Analysis/SSJava/GlobalFlowGraph.java index ac901bed..1cf59b77 100644 --- a/Robust/src/Analysis/SSJava/GlobalFlowGraph.java +++ b/Robust/src/Analysis/SSJava/GlobalFlowGraph.java @@ -104,7 +104,7 @@ public class GlobalFlowGraph { } mapFlowNodeToInNodeSet.get(toNode).add(fromNode); - System.out.println("create a global edge from " + fromNode + " to " + toNode); + // System.out.println("create a global edge from " + fromNode + " to " + toNode); } diff --git a/Robust/src/Analysis/SSJava/HierarchyGraph.java b/Robust/src/Analysis/SSJava/HierarchyGraph.java index 50744f01..d575f4f4 100644 --- a/Robust/src/Analysis/SSJava/HierarchyGraph.java +++ b/Robust/src/Analysis/SSJava/HierarchyGraph.java @@ -358,7 +358,7 @@ public class HierarchyGraph { for (Iterator iterator = descSet.iterator(); iterator.hasNext();) { Descriptor desc = (Descriptor) iterator.next(); - if (!isPrimitive(desc)) { + if (!LocationInference.isPrimitive(desc)) { return false; } } @@ -368,19 +368,6 @@ public class HierarchyGraph { return false; } - private boolean isPrimitive(Descriptor desc) { - - if (desc instanceof FieldDescriptor) { - return ((FieldDescriptor) desc).getType().isPrimitive(); - } else if (desc instanceof VarDescriptor) { - return ((VarDescriptor) desc).getType().isPrimitive(); - } else if (desc instanceof InterDescriptor) { - return true; - } - - return false; - } - private void addEdgeWithNoCycleCheck(HNode srcHNode, HNode dstHNode) { getIncomingNodeSet(dstHNode).add(srcHNode); getOutgoingNodeSet(srcHNode).add(dstHNode); @@ -991,7 +978,7 @@ public class HierarchyGraph { } } - public BasisSet computeBasisSet() { + public BasisSet computeBasisSet(Set notGenerateSet) { // assign a unique index to a node assignUniqueIndexToNode(); @@ -1000,6 +987,10 @@ public class HierarchyGraph { for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) { HNode node = (HNode) iterator.next(); + if (notGenerateSet.contains(node)) { + System.out.println("%%%SKIP =" + node); + continue; + } Set basis = new HashSet(); basis.addAll(BASISTOPELEMENT); diff --git a/Robust/src/Analysis/SSJava/LocationInference.java b/Robust/src/Analysis/SSJava/LocationInference.java index b1399149..34c1df96 100644 --- a/Robust/src/Analysis/SSJava/LocationInference.java +++ b/Robust/src/Analysis/SSJava/LocationInference.java @@ -285,6 +285,7 @@ public class LocationInference { } private void translateCompositeLocationAssignmentToFlowGraph() { + System.out.println("\nSSJAVA: Translate composite location assignments to flow graphs:"); MethodDescriptor methodEventLoopDesc = ssjava.getMethodContainingSSJavaLoop(); translateCompositeLocationAssignmentToFlowGraph(methodEventLoopDesc); _debug_printGraph(); @@ -323,7 +324,8 @@ public class LocationInference { if (node.isDeclaratonNode()) { Descriptor localVarDesc = node.getDescTuple().get(0); - methodSummary.addMapVarNameToInferCompLoc(localVarDesc, node.getCompositeLocation()); + CompositeLocation compLoc = updateCompositeLocation(node.getCompositeLocation()); + methodSummary.addMapVarNameToInferCompLoc(localVarDesc, compLoc); } } @@ -361,7 +363,6 @@ public class LocationInference { private void translateCompositeLocationAssignmentToFlowGraph(MethodDescriptor mdCaller) { - System.out.println("\n#translateCompositeLocationAssignmentToFlowGraph=" + mdCaller); // First, assign a composite location to a node in the flow graph GlobalFlowGraph callerGlobalFlowGraph = getSubGlobalFlowGraph(mdCaller); @@ -369,7 +370,6 @@ public class LocationInference { FlowGraph callerFlowGraph = getFlowGraph(mdCaller); Map callerMapLocToCompLoc = callerGlobalFlowGraph.getMapLocationToInferCompositeLocation(); - System.out.println("---callerMapLocToCompLoc=" + callerMapLocToCompLoc); Set methodLocSet = callerMapLocToCompLoc.keySet(); for (Iterator iterator = methodLocSet.iterator(); iterator.hasNext();) { Location methodLoc = (Location) iterator.next(); @@ -499,10 +499,13 @@ public class LocationInference { } } + System.out.println("-----*AFTER TRANSLATING COMP LOC MAPPING, CALLEE MAPPING=" + + calleeGlobalGraph.getMapLocationToInferCompositeLocation()); + // 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("\n-translate arg composite location to callee param. min=" - + min.printNode(0)); + // System.out.println("---translate arg composite location to callee param. min=" + // + min.printNode(0)); Map> mapIdxToArgTuple = mapMethodInvokeNodeToArgIdxMap.get(min); Set idxSet = mapIdxToArgTuple.keySet(); for (Iterator iterator = idxSet.iterator(); iterator.hasNext();) { @@ -602,7 +605,6 @@ public class LocationInference { next: for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) { GlobalFlowNode node = (GlobalFlowNode) iterator.next(); - System.out.println("-GlobalFlowNode=" + node); Location prefixLoc = node.getLocTuple().get(0); if (calculatedPrefixSet.contains(prefixLoc)) { @@ -698,8 +700,6 @@ public class LocationInference { System.out.println("\n##### calculatePrefixList node=" + node); - MethodDescriptor md = graph.getMethodDescriptor(); - Set incomingNodeSetPrefix = graph.getIncomingNodeSetByPrefix(node.getLocTuple().get(0)); // System.out.println("incomingNodeSetPrefix=" + incomingNodeSetPrefix); @@ -735,6 +735,24 @@ public class LocationInference { } } }); + + // remove a prefix which is not suitable for generating composite location + Location localVarLoc = node.getLocTuple().get(0); + MethodDescriptor md = (MethodDescriptor) localVarLoc.getDescriptor(); + ClassDescriptor cd = md.getClassDesc(); + + int idx = 0; + + Set> toberemoved = new HashSet>(); + for (int i = 0; i < prefixList.size(); i++) { + NTuple prefixLocTuple = prefixList.get(i); + if (!containsClassDesc(cd, prefixLocTuple)) { + toberemoved.add(prefixLocTuple); + } + } + + prefixList.removeAll(toberemoved); + return prefixList; // List> prefixList = new ArrayList>(); @@ -767,6 +785,20 @@ public class LocationInference { // return prefixList; } + private boolean containsClassDesc(ClassDescriptor cd, NTuple prefixLocTuple) { + for (int i = 0; i < prefixLocTuple.size(); i++) { + Location loc = prefixLocTuple.get(i); + Descriptor locDesc = loc.getLocDescriptor(); + if (locDesc != null) { + ClassDescriptor type = getClassTypeDescriptor(locDesc); + if (type != null && type.equals(cd)) { + return true; + } + } + } + return false; + } + private GlobalFlowGraph constructSubGlobalFlowGraph(FlowGraph flowGraph) { MethodDescriptor md = flowGraph.getMethodDescriptor(); @@ -872,12 +904,11 @@ public class LocationInference { private void propagateValueFlowsToCallerFromSubGlobalFlowGraph(MethodInvokeNode min, MethodDescriptor mdCaller, MethodDescriptor possibleMdCallee) { - System.out.println("propagateValueFlowsToCallerFromSubGlobalFlowGraph=" + min.printNode(0) - + " by 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)=" + System.out.println("-----mapMethodInvokeNodeToArgIdxMap.get(min)=" + mapMethodInvokeNodeToArgIdxMap.get(min)); Set keySet = mapIdxToArg.keySet(); for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { @@ -889,13 +920,11 @@ public class LocationInference { NTuple paramLocTuple = translateToLocTuple(possibleMdCallee, paramDescTuple); addMapCallerArgToCalleeParam(min, argDescTuple, paramDescTuple); } - } NTuple baseTuple = mapMethodInvokeNodeToBaseTuple.get(min); GlobalFlowGraph calleeSubGlobalGraph = getSubGlobalFlowGraph(possibleMdCallee); Set calleeNodeSet = calleeSubGlobalGraph.getNodeSet(); - System.out.println("#calleeNodeSet=" + calleeNodeSet); for (Iterator iterator = calleeNodeSet.iterator(); iterator.hasNext();) { GlobalFlowNode calleeNode = (GlobalFlowNode) iterator.next(); addValueFlowFromCalleeNode(min, mdCaller, possibleMdCallee, calleeNode); @@ -984,8 +1013,8 @@ public class LocationInference { int paramIdx = calleeFlowGraph.getParamIdx(nodeDescTuple); NTuple argDescTuple = mapMethodInvokeNodeToArgIdxMap.get(min).get(paramIdx); - if (argDescTuple.size() == 0) { - // argument is literal + if (isPrimitive(nodeLocTuple.get(0).getLocDescriptor())) { + // the type of argument is primitive. return nodeLocTuple.clone(); } NTuple argLocTuple = translateToLocTuple(mdCaller, argDescTuple); @@ -1003,6 +1032,19 @@ public class LocationInference { } + public static boolean isPrimitive(Descriptor desc) { + + if (desc instanceof FieldDescriptor) { + return ((FieldDescriptor) desc).getType().isPrimitive(); + } else if (desc instanceof VarDescriptor) { + return ((VarDescriptor) desc).getType().isPrimitive(); + } else if (desc instanceof InterDescriptor) { + return true; + } + + return false; + } + private NTuple translateToDescTuple(NTuple locTuple) { NTuple descTuple = new NTuple(); @@ -2919,7 +2961,6 @@ public class LocationInference { private void propagateFlowsToCallerWithNoCompositeLocation(MethodInvokeNode min, MethodDescriptor mdCaller, MethodDescriptor mdCallee) { - System.out.println("\n##PROPAGATE callee=" + mdCallee + "TO caller=" + mdCaller); // if the parameter A reaches to the parameter B // then, add an edge the argument A -> the argument B to the caller's flow @@ -2944,19 +2985,19 @@ public class LocationInference { // parameters Set localReachSet = calleeFlowGraph.getLocalReachFlowNodeSetFrom(paramNode1); - System.out.println("-param1=" + paramNode1 + " is higher than param2=" + paramNode2); - System.out.println("-- localReachSet from param1=" + localReachSet); + // System.out.println("-param1=" + paramNode1 + " is higher than param2=" + paramNode2); + // System.out.println("-- localReachSet from param1=" + localReachSet); 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("-arg1Tuple=" + arg1Tuple + " is higher than arg2Tuple=" + arg2Tuple); + // System.out + // .println("-arg1Tuple=" + arg1Tuple + " is higher than arg2Tuple=" + arg2Tuple); // otherwise, flows between method/field locations... callerFlowGraph.addValueFlowEdge(arg1Tuple, arg2Tuple); - System.out.println("arg1=" + arg1Tuple + " arg2=" + arg2Tuple); + // System.out.println("arg1=" + arg1Tuple + " arg2=" + arg2Tuple); } @@ -2964,7 +3005,7 @@ public class LocationInference { } } } - System.out.println("##\n"); + // System.out.println("##\n"); } @@ -3693,17 +3734,17 @@ public class LocationInference { MethodDescriptor md = methodDescList.removeLast(); if (state.SSJAVADEBUG) { System.out.println(); - System.out.println("SSJAVA: Constructing a flow graph2: " + md); + System.out.println("SSJAVA: Constructing a sub global flow graph: " + md); - System.out.println("##constructSubGlobalFlowGraph"); GlobalFlowGraph subGlobalFlowGraph = constructSubGlobalFlowGraph(getFlowGraph(md)); mapMethodDescriptorToSubGlobalFlowGraph.put(md, subGlobalFlowGraph); // TODO - System.out.println("##addValueFlowsFromCalleeSubGlobalFlowGraph"); + System.out.println("-add Value Flows From CalleeSubGlobalFlowGraph"); addValueFlowsFromCalleeSubGlobalFlowGraph(md, subGlobalFlowGraph); subGlobalFlowGraph.writeGraph("_SUBGLOBAL"); + System.out.println("-propagate Flows From Callees With No CompositeLocation"); propagateFlowsFromCalleesWithNoCompositeLocation(md); } @@ -4121,7 +4162,7 @@ public class LocationInference { private void analyzeFlowIfStatementNode(MethodDescriptor md, SymbolTable nametable, IfStatementNode isn, NodeTupleSet implicitFlowTupleSet) { - System.out.println("analyzeFlowIfStatementNode=" + isn.printNode(0)); + // System.out.println("analyzeFlowIfStatementNode=" + isn.printNode(0)); NodeTupleSet condTupleNode = new NodeTupleSet(); analyzeFlowExpressionNode(md, nametable, isn.getCondition(), condTupleNode, null, @@ -4132,9 +4173,9 @@ public class LocationInference { newImplicitTupleSet.addTupleSet(implicitFlowTupleSet); newImplicitTupleSet.addTupleSet(condTupleNode); - System.out.println("condTupleNode=" + condTupleNode); - System.out.println("implicitFlowTupleSet=" + implicitFlowTupleSet); - System.out.println("newImplicitTupleSet=" + newImplicitTupleSet); + // System.out.println("condTupleNode=" + condTupleNode); + // System.out.println("implicitFlowTupleSet=" + implicitFlowTupleSet); + // System.out.println("newImplicitTupleSet=" + newImplicitTupleSet); if (newImplicitTupleSet.size() > 1) { @@ -4370,7 +4411,7 @@ public class LocationInference { FlowGraph calleeFlowGraph = getFlowGraph(calleeMethodDesc); Set calleeReturnSet = calleeFlowGraph.getReturnNodeSet(); - System.out.println("-calleeReturnSet=" + calleeReturnSet); + // System.out.println("-calleeReturnSet=" + calleeReturnSet); if (min.getExpression() != null) { @@ -4397,7 +4438,7 @@ public class LocationInference { } else { // TODO Set inFlowSet = calleeFlowGraph.getIncomingFlowNodeSet(returnNode); - System.out.println("inFlowSet=" + inFlowSet + " from retrunNode=" + 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(calleeMethodDesc.getThis())) { @@ -4429,7 +4470,6 @@ public class LocationInference { // if argument is liternal node, argTuple is set to NULL NTuple argTuple = new NTuple(); - System.out.println("-argTupleSet=" + argTupleSet + " from en=" + en.printNode(0)); if (argTupleSet.size() > 1) { NTuple interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple(); @@ -4444,12 +4484,10 @@ public class LocationInference { argTuple = new NTuple(); } + addArgIdxMap(min, idx, argTuple); FlowNode paramNode = calleeFlowGraph.getParamFlowNode(idx); - System.out.println("-paramNode=" + paramNode + " hasInFlowTo=" - + hasInFlowTo(calleeFlowGraph, paramNode, calleeReturnSet)); - if (hasInFlowTo(calleeFlowGraph, paramNode, calleeReturnSet) || calleeMethodDesc.getModifiers().isNative()) { addParamNodeFlowingToReturnValue(calleeMethodDesc, paramNode);