import java.util.Map;
import java.util.Set;
+import IR.ClassDescriptor;
import IR.Descriptor;
import IR.MethodDescriptor;
import IR.NameDescriptor;
private Map<HNode, TripleItem> mapSharedNodeToTripleItem;
private Map<HNode, Integer> mapHNodeToHighestIndex;
+ private Map<Descriptor, Map<TripleItem, String>> mapDescToIntermediateLocMap;
+
private Map<Pair<HNode, HNode>, Integer> mapItemToHighestIndex;
public BuildLattice(LocationInference infer) {
this.mapSharedNodeToTripleItem = new HashMap<HNode, TripleItem>();
this.mapHNodeToHighestIndex = new HashMap<HNode, Integer>();
this.mapItemToHighestIndex = new HashMap<Pair<HNode, HNode>, Integer>();
-
+ this.mapDescToIntermediateLocMap = new HashMap<Descriptor, Map<TripleItem, String>>();
}
public SSJavaLattice<String> buildLattice(Descriptor desc) {
HierarchyGraph inputGraph = infer.getSkeletonCombinationHierarchyGraph(desc);
LocationSummary locSummary = infer.getLocationSummary(desc);
+ HierarchyGraph naiveGraph = infer.getSimpleHierarchyGraph(desc);
+
+ // I don't think we need to keep the below if statement anymore
+ // because hierarchy graph does not have any composite location
Set<HNode> nodeSetWithCompositeLocation = new HashSet<HNode>();
if (desc instanceof MethodDescriptor) {
FlowGraph flowGraph = infer.getFlowGraph((MethodDescriptor) desc);
}
+ // /////////////////////////////////////////////////////////////////////////////////////
+ // lattice generation for the native approach
+
+ if (infer.state.SSJAVA_INFER_NAIVE_WRITEDOTS) {
+ BasisSet naiveBasisSet = naiveGraph.computeBasisSet(nodeSetWithCompositeLocation);
+
+ Family naiveFamily = generateFamily(naiveBasisSet);
+ Map<Set<Integer>, Set<Set<Integer>>> naive_mapImSucc =
+ coveringGraph(naiveBasisSet, naiveFamily);
+
+ SSJavaLattice<String> naive_lattice =
+ buildLattice(desc, naiveBasisSet, naiveGraph, null, naive_mapImSucc);
+ LocationInference.numLocationsNaive += naive_lattice.getKeySet().size();
+ infer.addNaiveLattice(desc, naive_lattice);
+ }
+
+ // /////////////////////////////////////////////////////////////////////////////////////
+
+ // lattice generation for the proposed approach
BasisSet basisSet = inputGraph.computeBasisSet(nodeSetWithCompositeLocation);
- debug_print(inputGraph);
+ // debug_print(inputGraph);
Family family = generateFamily(basisSet);
Map<Set<Integer>, Set<Set<Integer>>> mapImSucc = coveringGraph(basisSet, family);
}
+ public void setIntermediateLocMap(Descriptor desc, Map<TripleItem, String> map) {
+ mapDescToIntermediateLocMap.put(desc, map);
+ }
+
+ public Map<TripleItem, String> getIntermediateLocMap(Descriptor desc) {
+ if (!mapDescToIntermediateLocMap.containsKey(desc)) {
+ mapDescToIntermediateLocMap.put(desc, new HashMap<TripleItem, String>());
+ }
+ return mapDescToIntermediateLocMap.get(desc);
+ }
+
+ private Descriptor getParent(Descriptor desc) {
+ if (desc instanceof MethodDescriptor) {
+ MethodDescriptor md = (MethodDescriptor) desc;
+ ClassDescriptor cd = md.getClassDesc();
+ return infer.getParentMethodDesc(cd, md);
+ } else {
+ return ((ClassDescriptor) desc).getSuperDesc();
+ }
+ }
+
private SSJavaLattice<String> buildLattice(Descriptor desc, BasisSet basisSet,
HierarchyGraph inputGraph, LocationSummary locSummary,
Map<Set<Integer>, Set<Set<Integer>>> mapImSucc) {
+ System.out.println("\nBuild Lattice:" + inputGraph.getName());
+
SSJavaLattice<String> lattice =
new SSJavaLattice<String>(SSJavaAnalysis.TOP, SSJavaAnalysis.BOTTOM);
Set<Descriptor> descSet = inputGraph.getDescSetOfNode(higherNode);
// System.out.println("higherName=" + higherName + " higherNode=" + higherNode + " descSet="
// + descSet);
- for (Iterator iterator2 = descSet.iterator(); iterator2.hasNext();) {
- Descriptor d = (Descriptor) iterator2.next();
- locSummary.addMapHNodeNameToLocationName(d.getSymbol(), higherName);
+
+ if (locSummary != null) {
+ for (Iterator iterator2 = descSet.iterator(); iterator2.hasNext();) {
+ Descriptor d = (Descriptor) iterator2.next();
+ locSummary.addMapHNodeNameToLocationName(d.getSymbol(), higherName);
+ }
}
+
// locSummary.addMapHNodeNameToLocationName(higherName, higherName);
Set<Set<Integer>> lowerSet = mapImSucc.get(higher);
Set<Descriptor> lowerDescSet = inputGraph.getDescSetOfNode(lowerNode);
// System.out.println("lowerName=" + lowerName + " lowerNode=" + lowerNode + " descSet="
// + lowerDescSet);
- for (Iterator iterator3 = lowerDescSet.iterator(); iterator3.hasNext();) {
- Descriptor d = (Descriptor) iterator3.next();
- locSummary.addMapHNodeNameToLocationName(d.getSymbol(), lowerName);
+ if (locSummary != null) {
+ for (Iterator iterator3 = lowerDescSet.iterator(); iterator3.hasNext();) {
+ Descriptor d = (Descriptor) iterator3.next();
+ locSummary.addMapHNodeNameToLocationName(d.getSymbol(), lowerName);
+ }
}
// locSummary.addMapHNodeNameToLocationName(lowerName, lowerName);
public SSJavaLattice<String> insertIntermediateNodesToStraightLine(Descriptor desc,
SSJavaLattice<String> skeletonLattice) {
+ // copy nodes/edges from the parent method/class if possible
+ SSJavaLattice<String> lattice = skeletonLattice.clone();
+
+ Descriptor parentDesc = getParent(desc);
+ if (parentDesc != null) {
+ SSJavaLattice<String> parentLattice = infer.getLattice(parentDesc);
+
+ Map<String, Set<String>> parentMap = parentLattice.getTable();
+ Set<String> parentKeySet = parentMap.keySet();
+ for (Iterator iterator = parentKeySet.iterator(); iterator.hasNext();) {
+ String parentKey = (String) iterator.next();
+ Set<String> parentValueSet = parentMap.get(parentKey);
+ for (Iterator iterator2 = parentValueSet.iterator(); iterator2.hasNext();) {
+ String value = (String) iterator2.next();
+ lattice.put(parentKey, value);
+ }
+ }
+
+ Set<String> parentSharedLocSet = parentLattice.getSharedLocSet();
+ for (Iterator iterator = parentSharedLocSet.iterator(); iterator.hasNext();) {
+ String parentSharedLoc = (String) iterator.next();
+ lattice.addSharedLoc(parentSharedLoc);
+ }
+ }
+
+ // ////
// perform DFS that starts from each skeleton/combination node and ends by another
// skeleton/combination node
HierarchyGraph scGraph = infer.getSkeletonCombinationHierarchyGraph(desc);
LocationSummary locSummary = infer.getLocationSummary(desc);
- SSJavaLattice<String> lattice = skeletonLattice.clone();
-
Set<HNode> visited = new HashSet<HNode>();
Set<HNode> nodeSet = simpleGraph.getNodeSet();
- Map<TripleItem, String> mapIntermediateLoc = new HashMap<TripleItem, String>();
+ Map<TripleItem, String> mapIntermediateLoc = getIntermediateLocMap(desc);
+ // Map<TripleItem, String> mapIntermediateLoc = new HashMap<TripleItem, String>();
// System.out.println("*insert=" + desc);
// System.out.println("***nodeSet=" + nodeSet);
private void debug_print(HierarchyGraph inputGraph) {
System.out.println("\nBuild Lattice:" + inputGraph.getName());
- // System.out.println("Node2Index:\n" + inputGraph.getMapHNodeToUniqueIndex());
- // System.out.println("Node2Basis:\n" + inputGraph.getMapHNodeToBasis());
+ System.out.println("Node2Index:\n" + inputGraph.getMapHNodeToUniqueIndex());
+ System.out.println("Node2Basis:\n" + inputGraph.getMapHNodeToBasis());
}
}