From: yeom Date: Wed, 7 Nov 2012 08:08:54 +0000 (+0000) Subject: changes. X-Git-Url: http://plrg.eecs.uci.edu/git/?p=IRC.git;a=commitdiff_plain;h=9e20e6312d78b49358821f39e34967cabb4a51c3 changes. --- diff --git a/Robust/src/Analysis/SSJava/BuildLattice.java b/Robust/src/Analysis/SSJava/BuildLattice.java index 8c66b13a..cbddb358 100644 --- a/Robust/src/Analysis/SSJava/BuildLattice.java +++ b/Robust/src/Analysis/SSJava/BuildLattice.java @@ -166,6 +166,355 @@ public class BuildLattice { public SSJavaLattice insertIntermediateNodesToStraightLine(Descriptor desc, SSJavaLattice skeletonLattice) { + mapSharedNodeToTripleItem.clear(); + + HierarchyGraph hierarchyGraph = infer.getSimpleHierarchyGraph(desc); + HierarchyGraph scGraph = infer.getSkeletonCombinationHierarchyGraph(desc); + LocationSummary locSummary = infer.getLocationSummary(desc); + SSJavaLattice lattice = skeletonLattice.clone(); + Set visited = new HashSet(); + Set scNodeSet = scGraph.getNodeSet(); + + Map mapIntermediateLoc = new HashMap(); + + for (Iterator iterator = scNodeSet.iterator(); iterator.hasNext();) { + HNode scNode = (HNode) iterator.next(); + Set outHierarchyNodeSet = hierarchyGraph.getOutgoingNodeSet(scNode); + for (Iterator iterator2 = outHierarchyNodeSet.iterator(); iterator2.hasNext();) { + HNode outHierarchyNode = (HNode) iterator2.next(); + + if (!visited.contains(outHierarchyNode)) { + + if (!outHierarchyNode.isCombinationNode() && !outHierarchyNode.isSkeleton()) { + visited.add(outHierarchyNode); + Set outSCNodeSet = scGraph.getOutgoingNodeSet(scNode); + + if (outSCNodeSet.size() > 0) { + // follows the straight line up to another skeleton/combination node + outSCNodeSet = removeTransitivelyReachToNode(desc, scNode, outSCNodeSet); + } else if (outSCNodeSet.size() == 0) { + // the outNode is (directly/transitively) connected to the bottom node + // therefore, we just add a dummy bottom HNode to the endCombNodeSet. + outSCNodeSet.add(LocationInference.BOTTOMHNODE); + } + + recurDFVisitNormalNode(scNode, outSCNodeSet, outHierarchyNode, 1, desc, lattice, + visited, locSummary, mapIntermediateLoc); + } else if (outHierarchyNode.isCombinationNode()) { + visited.add(outHierarchyNode); + expandCombinationNode(desc, lattice, visited, mapIntermediateLoc, locSummary, + outHierarchyNode); + } + + } + + } + + } + + // add shared locations + Set sharedNodeSet = mapSharedNodeToTripleItem.keySet(); + for (Iterator iterator = sharedNodeSet.iterator(); iterator.hasNext();) { + HNode sharedNode = (HNode) iterator.next(); + TripleItem item = mapSharedNodeToTripleItem.get(sharedNode); + String nonSharedLocName = mapIntermediateLoc.get(item); + // System.out.println("sharedNode=" + sharedNode + " locName=" + nonSharedLocName); + + String newLocName; + if (locSummary.getHNodeNameSetByLatticeLoationName(nonSharedLocName) != null + && !lattice.isSharedLoc(nonSharedLocName)) { + // need to generate a new shared location in the lattice, which is one level lower than the + // 'locName' location + newLocName = "ILOC" + (LocationInference.locSeed++); + + // Set aboveElementSet = getAboveElementSet(lattice, locName); + Set belowElementSet = new HashSet(); + belowElementSet.addAll(lattice.get(nonSharedLocName)); + + // System.out.println("nonSharedLocName=" + nonSharedLocName + " belowElementSet=" + // + belowElementSet + " newLocName=" + newLocName); + + lattice.insertNewLocationBetween(nonSharedLocName, belowElementSet, newLocName); + } else { + newLocName = nonSharedLocName; + } + + lattice.addSharedLoc(newLocName); + HierarchyGraph graph = infer.getSimpleHierarchyGraph(desc); + Set descSet = graph.getDescSetOfNode(sharedNode); + for (Iterator iterator2 = descSet.iterator(); iterator2.hasNext();) { + Descriptor d = (Descriptor) iterator2.next(); + locSummary.addMapHNodeNameToLocationName(d.getSymbol(), newLocName); + } + locSummary.addMapHNodeNameToLocationName(sharedNode.getName(), newLocName); + + } + + return lattice; + } + + private void recurDFVisitNormalNode(HNode scStartNode, Set scEndNodeSet, + HNode curHierarchyNode, int idx, Descriptor desc, SSJavaLattice lattice, + Set visited, LocationSummary locSummary, Map mapIntermediateLoc) { + + TripleItem item = new TripleItem(scStartNode, scEndNodeSet, idx); + // System.out.println("item=" + item); + if (!mapIntermediateLoc.containsKey(item)) { + // need to create a new intermediate location in the lattice + String newLocName = "ILOC" + (LocationInference.locSeed++); + String above; + if (idx == 1) { + above = scStartNode.getName(); + } else { + int prevIdx = idx - 1; + TripleItem prevItem = new TripleItem(scStartNode, scEndNodeSet, prevIdx); + above = mapIntermediateLoc.get(prevItem); + } + + Set belowSet = new HashSet(); + for (Iterator iterator = scEndNodeSet.iterator(); iterator.hasNext();) { + HNode endNode = (HNode) iterator.next(); + String locName; + if (locSummary.getMapHNodeNameToLocationName().containsKey(endNode.getName())) { + locName = locSummary.getLocationName(endNode.getName()); + } else { + locName = endNode.getName(); + } + belowSet.add(locName); + } + lattice.insertNewLocationBetween(above, belowSet, newLocName); + + mapIntermediateLoc.put(item, newLocName); + } + + String curLocName = mapIntermediateLoc.get(item); + HierarchyGraph hierarchyGraph = infer.getSimpleHierarchyGraph(desc); + + if (curHierarchyNode.isSharedNode()) { + // if the current node is shared location, add a shared location to the lattice later + mapSharedNodeToTripleItem.put(curHierarchyNode, item); + } else { + Set descSet = hierarchyGraph.getDescSetOfNode(curHierarchyNode); + for (Iterator iterator = descSet.iterator(); iterator.hasNext();) { + Descriptor d = (Descriptor) iterator.next(); + locSummary.addMapHNodeNameToLocationName(d.getSymbol(), curLocName); + } + locSummary.addMapHNodeNameToLocationName(curHierarchyNode.getName(), curLocName); + } + + System.out.println("-TripleItem normal=" + item); + System.out.println("-curNode=" + curHierarchyNode.getName() + " S=" + + curHierarchyNode.isSharedNode() + " locName=" + curLocName + " isC=" + + curHierarchyNode.isCombinationNode()); + + Set outSet = hierarchyGraph.getOutgoingNodeSet(curHierarchyNode); + for (Iterator iterator2 = outSet.iterator(); iterator2.hasNext();) { + HNode outHierarchyNodeFromCurNode = (HNode) iterator2.next(); + + // Set incomingHNodeSetToOutNode = simpleHierarchyGraph.getIncomingNodeSet(outNode); + System.out.println("outHierarchyNodeFromCurNode=" + outHierarchyNodeFromCurNode); + // System.out.println("---incomingHNodeSetToOutNode=" + incomingHNodeSetToOutNode); + + if (outHierarchyNodeFromCurNode.isSkeleton() + || outHierarchyNodeFromCurNode.isCombinationNode()) { + String lowerLocName = locSummary.getLocationName(outHierarchyNodeFromCurNode.getName()); + lattice.addRelationHigherToLower(curLocName, lowerLocName); + } else { + if (visited.containsAll(hierarchyGraph.getIncomingNodeSet(outHierarchyNodeFromCurNode))) { + visited.add(outHierarchyNodeFromCurNode); + int newidx = getCurrentHighestIndex(outHierarchyNodeFromCurNode, idx + 1); + recurDFVisitNormalNode(scStartNode, scEndNodeSet, outHierarchyNodeFromCurNode, newidx, + desc, lattice, visited, locSummary, mapIntermediateLoc); + } else { + System.out.println("NOT RECUR"); + updateHighestIndex(outHierarchyNodeFromCurNode, idx + 1); + } + } + + // if (!outNode.isSkeleton() && !outNode.isCombinationNode() && !visited.contains(outNode)) { + // if (visited.containsAll(simpleHierarchyGraph.getIncomingNodeSet(outNode))) { + // visited.add(outNode); + // int newidx = getCurrentHighestIndex(outNode, idx + 1); + // recurDFSNormalNode(desc, lattice, startNode, endNodeSet, visited, mapIntermediateLoc, + // newidx, locSummary, outNode); + // // recurDFSNormalNode(desc, lattice, startNode, endNodeSet, visited, mapIntermediateLoc, + // // idx + 1, locSummary, outNode); + // } else { + // updateHighestIndex(outNode, idx + 1); + // System.out.println("NOT RECUR"); + // } + // } else if (!outNode.isSkeleton() && outNode.isCombinationNode() && + // !visited.contains(outNode)) { + // if (needToExpandCombinationNode(desc, outNode)) { + // System.out.println("NEED TO"); + // expandCombinationNode(desc, lattice, visited, mapIntermediateLoc, locSummary, outNode); + // } else { + // System.out.println("NOT NEED TO"); + // } + // } + + } + + } + + private void recurDFVisitCombinationNode(HNode scCombNode, Set scEndNodeSet, + HNode curHierarchyCombNode, int idx, Descriptor desc, SSJavaLattice lattice, + Set visited, LocationSummary locSummary, Map mapIntermediateLoc) { + + // Descriptor desc, SSJavaLattice lattice, + // HNode combinationNodeInSCGraph, Set endNodeSet, Set visited, + // Map mapIntermediateLoc, int idx, LocationSummary locSummary, HNode + // curNode) { + + TripleItem item = new TripleItem(scCombNode, scEndNodeSet, idx); + + if (!mapIntermediateLoc.containsKey(item)) { + // need to create a new intermediate location in the lattice + String above; + if (idx == 1) { + String newLocName = scCombNode.getName(); + mapIntermediateLoc.put(item, newLocName); + } else { + String newLocName = "ILOC" + (LocationInference.locSeed++); + int prevIdx = idx - 1; + TripleItem prevItem = new TripleItem(scCombNode, scEndNodeSet, prevIdx); + above = mapIntermediateLoc.get(prevItem); + + Set belowSet = new HashSet(); + for (Iterator iterator = scEndNodeSet.iterator(); iterator.hasNext();) { + HNode endNode = (HNode) iterator.next(); + belowSet.add(endNode.getName()); + } + lattice.insertNewLocationBetween(above, belowSet, newLocName); + mapIntermediateLoc.put(item, newLocName); + } + + } + + HierarchyGraph hierarchyNode = infer.getSimpleHierarchyGraph(desc); + String locName = mapIntermediateLoc.get(item); + if (curHierarchyCombNode.isSharedNode()) { + // if the current node is shared location, add a shared location to the lattice later + mapSharedNodeToTripleItem.put(curHierarchyCombNode, item); + } else { + Set descSet = hierarchyNode.getDescSetOfNode(curHierarchyCombNode); + for (Iterator iterator = descSet.iterator(); iterator.hasNext();) { + Descriptor d = (Descriptor) iterator.next(); + locSummary.addMapHNodeNameToLocationName(d.getSymbol(), locName); + } + locSummary.addMapHNodeNameToLocationName(curHierarchyCombNode.getName(), locName); + } + + System.out.println("-TripleItem=" + item); + System.out.println("-curNode=" + curHierarchyCombNode.getName() + " S=" + + curHierarchyCombNode.isSharedNode() + " locName=" + locName); + + Set outSet = hierarchyNode.getOutgoingNodeSet(curHierarchyCombNode); + for (Iterator iterator2 = outSet.iterator(); iterator2.hasNext();) { + HNode outHierarchyNode = (HNode) iterator2.next(); + + System.out.println("---recurDFS outNode=" + outHierarchyNode); + System.out.println("---outNode combinationNodeInSCGraph=" + + getCombinationNodeInSCGraph(desc, outHierarchyNode)); + + if (outHierarchyNode.isCombinationNode()) { + HNode outCombinationNodeInSCGraph = getCombinationNodeInSCGraph(desc, outHierarchyNode); + if (outCombinationNodeInSCGraph.equals(scCombNode)) { + + Set combineSkeletonNodeSet = + hierarchyNode.getCombineSetByCombinationNode(outHierarchyNode); + Set incomingHNodeSetToOutNode = hierarchyNode.getIncomingNodeSet(outHierarchyNode); + // extract nodes belong to the same combine node + Set incomingCombinedHNodeSet = new HashSet(); + for (Iterator iterator = incomingHNodeSetToOutNode.iterator(); iterator.hasNext();) { + HNode inNode = (HNode) iterator.next(); + if (combineSkeletonNodeSet.contains(inNode)) { + incomingCombinedHNodeSet.add(inNode); + } + } + System.out.println("incomingCombinedHNodeSet=" + incomingCombinedHNodeSet); + if (visited.containsAll(incomingCombinedHNodeSet)) { + visited.add(outHierarchyNode); + System.out.println("-------curIdx=" + (idx + 1)); + int newIdx = getCurrentHighestIndex(outHierarchyNode, idx + 1); + System.out.println("-------newIdx=" + newIdx); + recurDFVisitCombinationNode(scCombNode, scEndNodeSet, outHierarchyNode, newIdx, desc, + lattice, visited, locSummary, mapIntermediateLoc); + } else { + updateHighestIndex(outHierarchyNode, idx + 1); + System.out.println("-----NOT RECUR!"); + } + + } + } + + } + + } + + private void expandCombinationNode(Descriptor desc, SSJavaLattice lattice, + Set visited, Map mapIntermediateLoc, LocationSummary locSummary, + HNode cnode) { + + // expand the combination node 'outNode' + // here we need to expand the corresponding combination location in the lattice + HNode combinationNodeInSCGraph = getCombinationNodeInSCGraph(desc, cnode); + Set endNodeSet = + infer.getSkeletonCombinationHierarchyGraph(desc).getOutgoingNodeSet( + combinationNodeInSCGraph); + + System.out.println("expandCombinationNode=" + cnode + " cnode in scgraph=" + + combinationNodeInSCGraph); + System.out.println("endnodeset=" + endNodeSet); + + if (combinationNodeInSCGraph == null) { + return; + } + + // HierarchyGraph hierarchyGraph = infer.getSimpleHierarchyGraph(desc); + // + // Set combineSkeletonNodeSet = hierarchyGraph.getCombineSetByCombinationNode(cnode); + // + // // System.out.println("combineSkeletonNodeSet=" + combineSkeletonNodeSet); + // + // Set combinationNodeSet = + // hierarchyGraph.getCombinationNodeSetByCombineNodeSet(combineSkeletonNodeSet); + // + // // System.out.println("combinationNodeSet=" + combinationNodeSet); + // + // Set endNodeSetFromSimpleGraph = + // hierarchyGraph.getDirectlyReachableSkeletonCombinationNodeFrom(cnode, combinationNodeSet); + // // System.out.println("-endNodeSetFromSimpleGraph=" + endNodeSetFromSimpleGraph); + // Set endCombNodeSet = new HashSet(); + // for (Iterator iterator3 = endNodeSetFromSimpleGraph.iterator(); iterator3.hasNext();) { + // HNode endNode = (HNode) iterator3.next(); + // endCombNodeSet.add(getCombinationNodeInSCGraph(desc, endNode)); + // } + + visited.add(cnode); + + // follows the straight line up to another skeleton/combination node + if (endNodeSet.size() > 0) { + // System.out.println("---endCombNodeSet=" + endCombNodeSet); + endNodeSet = removeTransitivelyReachToNode(desc, combinationNodeInSCGraph, endNodeSet); + + recurDFVisitCombinationNode(combinationNodeInSCGraph, endNodeSet, cnode, 1, desc, lattice, + visited, locSummary, mapIntermediateLoc); + + } else { + endNodeSet.add(LocationInference.BOTTOMHNODE); + // System.out.println("---endCombNodeSet is zero"); + // System.out.println("---endNodeSetFromSimpleGraph=" + endNodeSetFromSimpleGraph); + // System.out.println("---incoming=" + simpleGraph.getIncomingNodeSet(cnode)); + recurDFVisitCombinationNode(combinationNodeInSCGraph, endNodeSet, cnode, 1, desc, lattice, + visited, locSummary, mapIntermediateLoc); + } + + } + + public SSJavaLattice insertIntermediateNodesToStraightLine2(Descriptor desc, + SSJavaLattice skeletonLattice) { + // perform DFS that starts from each skeleton/combination node and ends by another // skeleton/combination node @@ -200,7 +549,7 @@ public class BuildLattice { if (outNode.isCombinationNode()) { if (visited.containsAll(simpleGraph.getIncomingNodeSet(outNode))) { // if (needToExpandCombinationNode(desc, outNode)) { - expandCombinationNode(desc, lattice, visited, mapIntermediateLoc, locSummary, + expandCombinationNode3(desc, lattice, visited, mapIntermediateLoc, locSummary, outNode); // } } @@ -362,62 +711,6 @@ public class BuildLattice { return true; } - private void expandCombinationNode(Descriptor desc, SSJavaLattice lattice, - Set visited, Map mapIntermediateLoc, LocationSummary locSummary, - HNode cnode) { - - // expand the combination node 'outNode' - // here we need to expand the corresponding combination location in the lattice - HNode combinationNodeInSCGraph = getCombinationNodeInSCGraph(desc, cnode); - - System.out.println("expandCombinationNode=" + cnode + " cnode in scgraph=" - + combinationNodeInSCGraph); - - if (combinationNodeInSCGraph == null) { - return; - } - - HierarchyGraph simpleGraph = infer.getSimpleHierarchyGraph(desc); - - Set combineSkeletonNodeSet = simpleGraph.getCombineSetByCombinationNode(cnode); - - // System.out.println("combineSkeletonNodeSet=" + combineSkeletonNodeSet); - - Set combinationNodeSet = - simpleGraph.getCombinationNodeSetByCombineNodeSet(combineSkeletonNodeSet); - - // System.out.println("combinationNodeSet=" + combinationNodeSet); - - Set endNodeSetFromSimpleGraph = - simpleGraph.getDirectlyReachableSkeletonCombinationNodeFrom(cnode, combinationNodeSet); - // System.out.println("-endNodeSetFromSimpleGraph=" + endNodeSetFromSimpleGraph); - Set endCombNodeSet = new HashSet(); - for (Iterator iterator3 = endNodeSetFromSimpleGraph.iterator(); iterator3.hasNext();) { - HNode endNode = (HNode) iterator3.next(); - endCombNodeSet.add(getCombinationNodeInSCGraph(desc, endNode)); - } - visited.add(cnode); - - // follows the straight line up to another skeleton/combination node - if (endCombNodeSet.size() > 0) { - // System.out.println("---endCombNodeSet=" + endCombNodeSet); - endCombNodeSet = - removeTransitivelyReachToNode(desc, combinationNodeInSCGraph, endCombNodeSet); - - recurDFS(desc, lattice, combinationNodeInSCGraph, endCombNodeSet, visited, - mapIntermediateLoc, 1, locSummary, cnode); - } else { - endCombNodeSet.add(LocationInference.BOTTOMHNODE); - // System.out.println("---endCombNodeSet is zero"); - // System.out.println("---endNodeSetFromSimpleGraph=" + endNodeSetFromSimpleGraph); - // System.out.println("---incoming=" + simpleGraph.getIncomingNodeSet(cnode)); - recurDFS(desc, lattice, combinationNodeInSCGraph, endCombNodeSet, visited, - mapIntermediateLoc, 1, locSummary, cnode); - - } - - } - private Set removeTransitivelyReachToNode(Descriptor desc, HNode startNode, Set endNodeSet) { @@ -508,6 +801,62 @@ public class BuildLattice { return connected.iterator().next(); } + private void expandCombinationNode3(Descriptor desc, SSJavaLattice lattice, + Set visited, Map mapIntermediateLoc, LocationSummary locSummary, + HNode cnode) { + + // expand the combination node 'outNode' + // here we need to expand the corresponding combination location in the lattice + HNode combinationNodeInSCGraph = getCombinationNodeInSCGraph(desc, cnode); + + System.out.println("expandCombinationNode=" + cnode + " cnode in scgraph=" + + combinationNodeInSCGraph); + + if (combinationNodeInSCGraph == null) { + return; + } + + HierarchyGraph simpleGraph = infer.getSimpleHierarchyGraph(desc); + + Set combineSkeletonNodeSet = simpleGraph.getCombineSetByCombinationNode(cnode); + + // System.out.println("combineSkeletonNodeSet=" + combineSkeletonNodeSet); + + Set combinationNodeSet = + simpleGraph.getCombinationNodeSetByCombineNodeSet(combineSkeletonNodeSet); + + // System.out.println("combinationNodeSet=" + combinationNodeSet); + + Set endNodeSetFromSimpleGraph = + simpleGraph.getDirectlyReachableSkeletonCombinationNodeFrom(cnode, combinationNodeSet); + // System.out.println("-endNodeSetFromSimpleGraph=" + endNodeSetFromSimpleGraph); + Set endCombNodeSet = new HashSet(); + for (Iterator iterator3 = endNodeSetFromSimpleGraph.iterator(); iterator3.hasNext();) { + HNode endNode = (HNode) iterator3.next(); + endCombNodeSet.add(getCombinationNodeInSCGraph(desc, endNode)); + } + visited.add(cnode); + + // follows the straight line up to another skeleton/combination node + if (endCombNodeSet.size() > 0) { + // System.out.println("---endCombNodeSet=" + endCombNodeSet); + endCombNodeSet = + removeTransitivelyReachToNode(desc, combinationNodeInSCGraph, endCombNodeSet); + + recurDFS(desc, lattice, combinationNodeInSCGraph, endCombNodeSet, visited, + mapIntermediateLoc, 1, locSummary, cnode); + } else { + endCombNodeSet.add(LocationInference.BOTTOMHNODE); + // System.out.println("---endCombNodeSet is zero"); + // System.out.println("---endNodeSetFromSimpleGraph=" + endNodeSetFromSimpleGraph); + // System.out.println("---incoming=" + simpleGraph.getIncomingNodeSet(cnode)); + recurDFS(desc, lattice, combinationNodeInSCGraph, endCombNodeSet, visited, + mapIntermediateLoc, 1, locSummary, cnode); + + } + + } + private void recurDirectlyReachableNodeFromStartNodeReachToEndNode(HierarchyGraph scGraph, HNode startNode, HNode curNode, Set connected) { @@ -599,7 +948,7 @@ public class BuildLattice { } else if (!outNode.isSkeleton() && outNode.isCombinationNode() && !visited.contains(outNode)) { if (needToExpandCombinationNode(desc, outNode)) { System.out.println("NEED TO"); - expandCombinationNode(desc, lattice, visited, mapIntermediateLoc, locSummary, outNode); + expandCombinationNode3(desc, lattice, visited, mapIntermediateLoc, locSummary, outNode); } else { System.out.println("NOT NEED TO"); } @@ -707,7 +1056,8 @@ public class BuildLattice { } else { if (needToExpandCombinationNode(desc, outNode)) { System.out.println("NEED TO"); - expandCombinationNode(desc, lattice, visited, mapIntermediateLoc, locSummary, outNode); + expandCombinationNode3(desc, lattice, visited, mapIntermediateLoc, locSummary, + outNode); } else { System.out.println("NOT NEED TO"); } diff --git a/Robust/src/Analysis/SSJava/HierarchyGraph.java b/Robust/src/Analysis/SSJava/HierarchyGraph.java index d51e6107..ce62cf57 100644 --- a/Robust/src/Analysis/SSJava/HierarchyGraph.java +++ b/Robust/src/Analysis/SSJava/HierarchyGraph.java @@ -252,6 +252,7 @@ public class HierarchyGraph { skeletonGraph.setMapHNodeToDescSet(getMapHNodeToDescSet()); skeletonGraph.setMapHNodetoMergeSet(getMapHNodetoMergeSet()); skeletonGraph.setMapHNodeToCurrentHNode(getMapHNodeToCurrentHNode()); + skeletonGraph.setMapHNodeNameToCurrentHNode(getMapHNodeNameToCurrentHNode()); return skeletonGraph; @@ -502,6 +503,7 @@ public class HierarchyGraph { } private void addMapHNodeToCurrentHNode(HNode curNode, HNode newNode) { + if (curNode.isMergeNode()) { Set mergingSet = getMergingSet(curNode); mergingSet.add(curNode); @@ -516,6 +518,7 @@ public class HierarchyGraph { mapHNodeToCurrentHNode.put(curNode, newNode); mapHNodeNameToCurrentHNode.put(curNode.getName(), newNode); } + } public HNode getCurrentHNode(HNode node) { @@ -779,7 +782,7 @@ public class HierarchyGraph { Set combineSet = (Set) iterator.next(); // System.out.println("--combineSet=" + combineSet); HNode combinationNode = getCombinationNode(combineSet); - // System.out.println("--combinationNode=" + combinationNode); + System.out.println("--combinationNode=" + combinationNode + " combineSet=" + combineSet); // add an edge from a skeleton node to a combination node for (Iterator iterator2 = combineSet.iterator(); iterator2.hasNext();) { HNode inSkeletonNode = (HNode) iterator2.next(); @@ -848,6 +851,7 @@ public class HierarchyGraph { Set reachToSet = new HashSet(); Set visited = new HashSet(); + // visited.add(node); recurSkeletonReachTo(node, reachToSet, visited); // obsolete! @@ -882,6 +886,7 @@ public class HierarchyGraph { HNode inNode = (HNode) iterator.next(); if (inNode.isSkeleton()) { + visited.add(inNode); reachToSet.add(inNode); } else if (!visited.contains(inNode)) { visited.add(inNode); @@ -1166,10 +1171,18 @@ public class HierarchyGraph { } public void writeGraph() { + writeGraph(false); + } + + public void writeGraph(boolean isSimple) { String graphName = "hierarchy" + name; graphName = graphName.replaceAll("[\\W]", ""); + if (isSimple) { + graphName += "_PAPER"; + } + try { BufferedWriter bw = new BufferedWriter(new FileWriter(graphName + ".dot")); @@ -1186,18 +1199,30 @@ public class HierarchyGraph { if (outSet.size() == 0) { if (!addedNodeSet.contains(u)) { - drawNode(bw, u); + if (!isSimple) { + drawNode(bw, u); + } else { + drawNodeName(bw, u); + } addedNodeSet.add(u); } } else { for (Iterator iterator = outSet.iterator(); iterator.hasNext();) { HNode v = (HNode) iterator.next(); if (!addedNodeSet.contains(u)) { - drawNode(bw, u); + if (!isSimple) { + drawNode(bw, u); + } else { + drawNodeName(bw, u); + } addedNodeSet.add(u); } if (!addedNodeSet.contains(v)) { - drawNode(bw, v); + if (!isSimple) { + drawNode(bw, v); + } else { + drawNodeName(bw, v); + } addedNodeSet.add(v); } bw.write("" + u.getName() + " -> " + v.getName() + ";\n"); @@ -1235,6 +1260,11 @@ public class HierarchyGraph { return str; } + private void drawNodeName(BufferedWriter bw, HNode node) throws IOException { + String nodeName = node.getNamePropertyString(); + bw.write(node.getName() + " [label=\"" + nodeName + "\"]" + ";\n"); + } + private void drawNode(BufferedWriter bw, HNode node) throws IOException { String nodeName; if (node.isMergeNode()) { diff --git a/Robust/src/Analysis/SSJava/LocationInference.java b/Robust/src/Analysis/SSJava/LocationInference.java index ec8c6049..05500e22 100644 --- a/Robust/src/Analysis/SSJava/LocationInference.java +++ b/Robust/src/Analysis/SSJava/LocationInference.java @@ -409,19 +409,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()) { @@ -452,9 +452,12 @@ public class LocationInference { String locName; if (!enclosingDesc.equals(GLOBALDESC)) { LocationSummary locSummary = getLocationSummary(enclosingDesc); - HierarchyGraph scGraph = getSkeletonCombinationHierarchyGraph(enclosingDesc); +// HierarchyGraph scGraph = getSkeletonCombinationHierarchyGraph(enclosingDesc); + HierarchyGraph scGraph = getSimpleHierarchyGraph(enclosingDesc); if (scGraph != null) { HNode curNode = scGraph.getCurrentHNode(nodeIdentifier); + System.out.println("nodeID=" + nodeIdentifier + " curNode=" + curNode + + " enclosingDesc=" + enclosingDesc); if (curNode != null) { nodeIdentifier = curNode.getName(); } @@ -2193,6 +2196,7 @@ public class LocationInference { Descriptor desc = (Descriptor) iterator.next(); getHierarchyGraph(desc).writeGraph(); getSimpleHierarchyGraph(desc).writeGraph(); + getSimpleHierarchyGraph(desc).writeGraph(true); } } @@ -3279,35 +3283,48 @@ public class LocationInference { } } - private boolean coversAllParamters(MethodDescriptor md, FlowGraph fg, - Set> paramLocTupleHavingInFlowSet) { - - int numParam = fg.getNumParameters(); - int size = paramLocTupleHavingInFlowSet.size(); + private int countFirstDescriptorSetSize(Set> set) { - if (!md.isStatic()) { + Set descSet = new HashSet(); - // if the method is not static && there is a parameter composite location && - // it is started with 'this', - // paramLocTupleHavingInFlowSet need to have 'this' parameter. + for (Iterator iterator = set.iterator(); iterator.hasNext();) { + NTuple locTuple = (NTuple) iterator.next(); + descSet.add(locTuple.get(0).getLocDescriptor()); + } - FlowNode thisParamNode = fg.getParamFlowNode(0); - NTuple thisParamLocTuple = - translateToLocTuple(md, thisParamNode.getCurrentDescTuple()); + return descSet.size(); + } - if (!paramLocTupleHavingInFlowSet.contains(thisParamLocTuple)) { + private boolean coversAllParamters(MethodDescriptor md, FlowGraph fg, + Set> paramLocTupleHavingInFlowSet) { - for (Iterator iterator = paramLocTupleHavingInFlowSet.iterator(); iterator.hasNext();) { - NTuple paramTuple = (NTuple) iterator.next(); - if (paramTuple.size() > 1 && paramTuple.get(0).getLocDescriptor().equals(md.getThis())) { - // paramLocTupleHavingInFlowSet.add(thisParamLocTuple); - // break; - size++; - } - } + int numParam = fg.getNumParameters(); + // int size = paramLocTupleHavingInFlowSet.size(); + int size = countFirstDescriptorSetSize(paramLocTupleHavingInFlowSet); - } - } + // if (!md.isStatic()) { + // + // // if the method is not static && there is a parameter composite location && + // // it is started with 'this', + // // paramLocTupleHavingInFlowSet need to have 'this' parameter. + // + // FlowNode thisParamNode = fg.getParamFlowNode(0); + // NTuple thisParamLocTuple = + // translateToLocTuple(md, thisParamNode.getCurrentDescTuple()); + // + // if (!paramLocTupleHavingInFlowSet.contains(thisParamLocTuple)) { + // + // for (Iterator iterator = paramLocTupleHavingInFlowSet.iterator(); iterator.hasNext();) { + // NTuple paramTuple = (NTuple) iterator.next(); + // if (paramTuple.size() > 1 && paramTuple.get(0).getLocDescriptor().equals(md.getThis())) { + // // paramLocTupleHavingInFlowSet.add(thisParamLocTuple); + // // break; + // size++; + // } + // } + // + // } + // } if (size == numParam) { return true;