HNode hNode = (HNode) iterator.next();
if (!hNode.isSkeleton()) {
// here we need to insert an intermediate node for the hNode
- System.out.println("local node=" + hNode);
+ System.out.println("\n#local node=" + hNode);
// 1) find the lowest node m in the lattice that is above hnode in the lattice
// 2) count the number of non-shared nodes d between the hnode and the node m
if (hNode.isDirectCombinationNode()) {
// this node itself is the lowest node m. it is the first node of the chain
Set<HNode> combineSet = hierarchyGraph.getCombineSetByCombinationNode(hNode);
+
+ System.out.println(" # direct combine node::combineSkeletonNodeSet=" + combineSet);
+
SCNode = scGraph.getCombinationNode(combineSet);
numNonSharedNodes = -1;
} else {
Set<HNode> aboveSet = new HashSet<HNode>();
if (hNode.isCombinationNode()) {
+ // the current node is a combination node
Set<HNode> combineSkeletonNodeSet =
hierarchyGraph.getCombineSetByCombinationNode(hNode);
+ System.out.println(" combineSkeletonNodeSet=" + combineSkeletonNodeSet
+ + " combinationNode=" + scGraph.getCombinationNode(combineSkeletonNodeSet));
+ scGraph.getCombinationNode(combineSkeletonNodeSet);
+
+ System.out.println(" firstnode="
+ + hierarchyGraph.getFirstNodeOfCombinationNodeChainSet(combineSkeletonNodeSet));
aboveSet.addAll(hierarchyGraph
.getFirstNodeOfCombinationNodeChainSet(combineSkeletonNodeSet));
+
SCNode = scGraph.getCombinationNode(combineSkeletonNodeSet);
+
} else {
- System.out.println(" #######hierarchyGraph.getSkeleteNodeSetReachTo(" + hNode + ")="
- + hierarchyGraph.getSkeleteNodeSetReachTo(hNode));
+ // the current node is not a combination node
+ // there is only one parent node which should be skeleton node.
+ System.out.println(" hierarchyGraph.getSkeleteNodeSetReachTo(" + hNode + ")="
+ + hierarchyGraph.getSkeleteNodeSetReachTo(hNode));
aboveSet.addAll(hierarchyGraph.getSkeleteNodeSetReachTo(hNode));
// assert aboveSet.size() == 1;
SCNode = aboveSet.iterator().next();
// 3) convert the node m into a chain of nodes with the last node in the chain having m’s
// outgoing edges.
- Set<String> outgoingElements = skeletonLattice.get(SCNode.getName());
- System.out.println(" SCNODE outgoing=" + outgoingElements);
+ Set<HNode> outgoingSCNodeSet = scGraph.getOutgoingNodeSet(SCNode);
+ System.out.println(" SCNODE outgoing hnode set=" + outgoingSCNodeSet);
+
+ Set<String> outgoingLocNameSet = new HashSet<String>();
+ for (Iterator iterator2 = outgoingSCNodeSet.iterator(); iterator2.hasNext();) {
+ HNode outSCNode = (HNode) iterator2.next();
+ String locName = locSummary.getLocationName(outSCNode.getName());
+ System.out.println(" outSCNode=" + outSCNode + " -> locName="
+ + locName);
+ outgoingLocNameSet.add(locName);
+ }
// 4) If hnode is not a shared location, check if there already exists a local variable
// node that has distance d below m along this chain. If such a node
// does not exist, insert it.
String locName =
- getNewLocation(lattice, SCNode.getName(), outgoingElements, numNonSharedNodes,
+ getNewLocation(lattice, SCNode.getName(), outgoingLocNameSet, numNonSharedNodes,
hNode.isSharedNode());
System.out.println(" locName=" + locName);
locSummary.addMapHNodeNameToLocationName(hNode.getName(), locName);
if (dist == 0 && isShared) {
// if the node is shared,
// check if there already exists a shared node that has distance d + 1 on the chain
- connectedSet = lattice.get(cur);
- if (connectedSet.equals(endSet)) {
+ if ((cur.equals(lattice.getTopItem()) && connectedSet.containsAll(endSet))
+ || connectedSet.equals(endSet)) {
// need to insert a new shared location
+ // it is done after this if statement
} else {
assert connectedSet.size() == 1;
String below = connectedSet.iterator().next();
}
// need to insert a new shared location
+ Set<String> newChildSet = new HashSet<String>();
+ newChildSet.addAll(connectedSet);
+
String newLocName = "ILOC" + (LocationInference.locSeed++);
- for (Iterator iterator = connectedSet.iterator(); iterator.hasNext();) {
+ for (Iterator iterator = newChildSet.iterator(); iterator.hasNext();) {
String outNode = (String) iterator.next();
lattice.put(newLocName, outNode);
}
- connectedSet.clear();
+ lattice.get(cur).clear();
lattice.put(cur, newLocName);
System.out.println(" INSERT NEW SHARED NODE=" + newLocName + " above=" + cur
}
String next;
- if (connectedSet.equals(endSet)) {
+
+ if (cur.equals(lattice.getTopItem()) || connectedSet.equals(endSet) || endSet.isEmpty()) {
+
+ // if ( (cur.equals(lattice.getTopItem()) && connectedSet.containsAll(endSet))
+ // || connectedSet.equals(endSet)) {
+
// need to insert a new location
String newLocName = "ILOC" + (LocationInference.locSeed++);
connectedSet.clear();
lattice.put(cur, newLocName);
- System.out.println("NEW RELATION=" + lattice.get(cur));
+
+ System.out.println("#INSERT NEW RELATION cur=" + cur + " newLocName=" + newLocName + "::"
+ + lattice.get(cur));
+
for (Iterator iterator = endSet.iterator(); iterator.hasNext();) {
String endNode = (String) iterator.next();
lattice.put(newLocName, endNode);
Descriptor desc;
+ boolean isSCgraph;
+
String name;
// graph structure
mapNormalNodeToSCNodeReachToSet = new HashMap<HNode, Set<HNode>>();
mapCombineNodeSetToFirstNodeOfChainSet = new HashMap<Set<HNode>, Set<HNode>>();
+
+ isSCgraph = false;
+ }
+
+ public void setSCGraph(boolean in) {
+ isSCgraph = in;
+ }
+
+ public boolean isSCGraph() {
+ return isSCgraph;
}
public Descriptor getDesc() {
}
public HNode getCombinationNode(Set<HNode> combineSet) {
+ assert isSCGraph();
if (!mapCombineNodeSetToCombinationNode.containsKey(combineSet)) {
String name = "COMB" + (LocationInference.locSeed++);
+ System.out.println("-NEW COMB NODE=" + name);
HNode node = new HNode(name);
node.setCombinationNode(true);
nodeSet.add(node);
HNode combinationNode = getCombinationNode(combineSet);
System.out.println("--combinationNode=" + combinationNode + " combineSet=" + combineSet);
- // System.out.println("--hierarchynodes="
- // + simpleHierarchyGraph.getCombinationNodeSetByCombineNodeSet(combineSet));
+ System.out.println("--hierarchynodes="
+ + simpleHierarchyGraph.getCombinationNodeSetByCombineNodeSet(combineSet));
+
+ Set<HNode> simpleHNodeSet =
+ simpleHierarchyGraph.getCombinationNodeSetByCombineNodeSet(combineSet);
+
+ // check whether a hnode in the simple hierarchy graph is the first node of the chain
+ // if all incoming combination nodes to the hnode have a different combination set from the
+ // hnode, it is the first node of the chain
+ for (Iterator iterator2 = simpleHNodeSet.iterator(); iterator2.hasNext();) {
+ HNode simpleHNode = (HNode) iterator2.next();
+ boolean isFirstNodeOfChain = true;
+ Set<HNode> incomingNodeSet = simpleHierarchyGraph.getIncomingNodeSet(simpleHNode);
+ for (Iterator iterator3 = incomingNodeSet.iterator(); iterator3.hasNext();) {
+ HNode inNode = (HNode) iterator3.next();
+ if (inNode.isCombinationNode()) {
+ Set<HNode> inNodeCombineSet =
+ simpleHierarchyGraph.getCombineSetByCombinationNode(inNode);
+ if (inNodeCombineSet.equals(combineSet)) {
+ isFirstNodeOfChain = false;
+ break;
+ }
+ }
+ }
+ simpleHNode.setDirectCombinationNode(isFirstNodeOfChain);
+ if (isFirstNodeOfChain) {
+ simpleHierarchyGraph.addFirstNodeOfChain(combineSet, simpleHNode);
+ System.out.println("IT IS THE FIRST NODE OF THE CHAIN:" + simpleHNode);
+ }
+ }
// add an edge from a skeleton node to a combination node
for (Iterator iterator2 = combineSet.iterator(); iterator2.hasNext();) {
return clone;
}
+ public void setMapCombineNodeSetToCombinationNode(Map<Set<HNode>, HNode> in) {
+ mapCombineNodeSetToCombinationNode = in;
+ }
+
public Map<HNode, Set<HNode>> getMapHNodetoMergeSet() {
return mapMergeNodetoMergingSet;
}
// + tempSet);
if (reachToSet.size() > 1) {
// if (countSkeletonNodes(reachToSet) > 1) {
- System.out.println("-node=" + node + " reachToSet=" + reachToSet);
+ System.out.println("\n-node=" + node + " reachToSet=" + reachToSet);
System.out.println("-set combinationnode=" + node);
node.setCombinationNode(true);
mapCombinationNodeToCombineNodeSet.put(node, reachToSet);
// check if this node is the first node of the chain
- boolean isFirstNodeOfChain = false;
- Set<HNode> inNodeSet = getIncomingNodeSet(node);
- for (Iterator iterator2 = inNodeSet.iterator(); iterator2.hasNext();) {
- HNode inNode = (HNode) iterator2.next();
- if (inNode.isSkeleton()) {
- isFirstNodeOfChain = true;
- } else if (inNode.isCombinationNode()) {
- Set<HNode> inNodeReachToSet = getSkeleteNodeSetReachTo(inNode);
- if (!reachToSet.equals(inNodeReachToSet)) {
- isFirstNodeOfChain = true;
- }
- }
- }
-
- if (isFirstNodeOfChain) {
- node.setDirectCombinationNode(true);
- addFirstNodeOfChain(reachToSet, node);
- // System.out.println("IT IS DIRECTLY CONNECTED WITH SC NODES:" + node);
- }
+ // boolean isFirstNodeOfChain = false;
+ // Set<HNode> inNodeSet = getIncomingNodeSet(node);
+ // for (Iterator iterator2 = inNodeSet.iterator(); iterator2.hasNext();) {
+ // HNode inNode = (HNode) iterator2.next();
+ // if (inNode.isSkeleton()) {
+ // isFirstNodeOfChain = true;
+ // } else if (inNode.isCombinationNode()) {
+ // Set<HNode> inNodeReachToSet = getSkeleteNodeSetReachTo(inNode);
+ // if (!reachToSet.equals(inNodeReachToSet)) {
+ // isFirstNodeOfChain = true;
+ // }
+ // }
+ // }
+ //
+ // if (isFirstNodeOfChain) {
+ // node.setDirectCombinationNode(true);
+ // addFirstNodeOfChain(reachToSet, node);
+ // }
}
}
// map a method/class descriptor to a skeleton hierarchy graph with combination nodes
private Map<Descriptor, HierarchyGraph> mapDescriptorToCombineSkeletonHierarchyGraph;
- // map a descriptor to a simple lattice
- private Map<Descriptor, SSJavaLattice<String>> mapDescriptorToSimpleLattice;
+ // map a descriptor to a skeleton lattice
+ private Map<Descriptor, SSJavaLattice<String>> mapDescriptorToSkeletonLattice;
// map a method descriptor to the set of method invocation nodes which are
// invoked by the method descriptor
this.mapDescriptorToCombineSkeletonHierarchyGraph = new HashMap<Descriptor, HierarchyGraph>();
this.mapDescriptorToSimpleHierarchyGraph = new HashMap<Descriptor, HierarchyGraph>();
- this.mapDescriptorToSimpleLattice = new HashMap<Descriptor, SSJavaLattice<String>>();
+ this.mapDescriptorToSkeletonLattice = new HashMap<Descriptor, SSJavaLattice<String>>();
this.mapDescToLocationSummary = new HashMap<Descriptor, LocationSummary>();
private void debug_writeLattices() {
- Set<Descriptor> keySet = mapDescriptorToSimpleLattice.keySet();
+ Set<Descriptor> keySet = mapDescriptorToSkeletonLattice.keySet();
for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
Descriptor key = (Descriptor) iterator.next();
- SSJavaLattice<String> simpleLattice = mapDescriptorToSimpleLattice.get(key);
+ SSJavaLattice<String> skeletonLattice = mapDescriptorToSkeletonLattice.get(key);
// HierarchyGraph simpleHierarchyGraph = getSimpleHierarchyGraph(key);
HierarchyGraph scHierarchyGraph = getSkeletonCombinationHierarchyGraph(key);
if (key instanceof ClassDescriptor) {
- writeInferredLatticeDotFile((ClassDescriptor) key, simpleLattice, "_SIMPLE");
+ writeInferredLatticeDotFile((ClassDescriptor) key, skeletonLattice, "_SKELETON");
} else if (key instanceof MethodDescriptor) {
MethodDescriptor md = (MethodDescriptor) key;
- writeInferredLatticeDotFile(md.getClassDesc(), md, simpleLattice, "_SIMPLE");
+ writeInferredLatticeDotFile(md.getClassDesc(), md, skeletonLattice, "_SKELETON");
}
LocationSummary ls = getLocationSummary(key);
private void buildLattice(Descriptor desc) {
// System.out.println("buildLattice=" + desc);
- SSJavaLattice<String> simpleLattice = buildLattice.buildLattice(desc);
+ SSJavaLattice<String> skeletonLattice = buildLattice.buildLattice(desc);
- addMapDescToSimpleLattice(desc, simpleLattice);
+ addMapDescToSkeletonLattice(desc, skeletonLattice);
+ // write a dot file before everything is done
if (desc instanceof ClassDescriptor) {
- writeInferredLatticeDotFile((ClassDescriptor) desc, null, simpleLattice, "_SC");
+ writeInferredLatticeDotFile((ClassDescriptor) desc, null, skeletonLattice, "_SC");
} else {
MethodDescriptor md = (MethodDescriptor) desc;
- writeInferredLatticeDotFile(md.getClassDesc(), md, simpleLattice, "_SC");
+ writeInferredLatticeDotFile(md.getClassDesc(), md, skeletonLattice, "_SC");
}
HierarchyGraph simpleHierarchyGraph = getSimpleHierarchyGraph(desc);
// System.out.println("\n## insertIntermediateNodesToStraightLine:"
// + simpleHierarchyGraph.getName());
SSJavaLattice<String> lattice =
- buildLattice.insertIntermediateNodesToStraightLine(desc, simpleLattice);
+ buildLattice.insertIntermediateNodesToStraightLine(desc, skeletonLattice);
if (lattice == null) {
return;
if (desc instanceof ClassDescriptor) {
// field lattice
cd2lattice.put((ClassDescriptor) desc, lattice);
- // ssjava.writeLatticeDotFile((ClassDescriptor) desc, null, lattice);
+ ssjava.writeLatticeDotFile((ClassDescriptor) desc, null, lattice);
} else if (desc instanceof MethodDescriptor) {
// method lattice
md2lattice.put((MethodDescriptor) desc, lattice);
MethodDescriptor md = (MethodDescriptor) desc;
ClassDescriptor cd = md.getClassDesc();
- // ssjava.writeLatticeDotFile(cd, md, lattice);
+ ssjava.writeLatticeDotFile(cd, md, lattice);
}
}
SSJavaLattice<String> simpleLattice = buildLattice.buildLattice(desc);
- addMapDescToSimpleLattice(desc, simpleLattice);
+ addMapDescToSkeletonLattice(desc, simpleLattice);
HierarchyGraph simpleHierarchyGraph = getSimpleHierarchyGraph(desc);
System.out.println("\n## insertIntermediateNodesToStraightLine:"
}
- public void addMapDescToSimpleLattice(Descriptor desc, SSJavaLattice<String> lattice) {
- mapDescriptorToSimpleLattice.put(desc, lattice);
+ public void addMapDescToSkeletonLattice(Descriptor desc, SSJavaLattice<String> lattice) {
+ mapDescriptorToSkeletonLattice.put(desc, lattice);
}
- public SSJavaLattice<String> getSimpleLattice(Descriptor desc) {
- return mapDescriptorToSimpleLattice.get(desc);
+ public SSJavaLattice<String> getSkeletonLattice(Descriptor desc) {
+ return mapDescriptorToSkeletonLattice.get(desc);
}
private void simplifyHierarchyGraph() {
System.out.println("\nSSJAVA: Inserting Combination Nodes:" + desc);
HierarchyGraph skeletonGraph = getSkeletonHierarchyGraph(desc);
HierarchyGraph skeletonGraphWithCombinationNode = skeletonGraph.clone();
+ skeletonGraphWithCombinationNode.setSCGraph(true);
skeletonGraphWithCombinationNode.setName(desc + "_SC");
HierarchyGraph simpleHierarchyGraph = getSimpleHierarchyGraph(desc);
linearTypeCheckMethodSet.add(md);
}
}
-
+
linearTypeCheckMethodSet.addAll(sortedDescriptors);
}
MethodLattice<String> locOrder =
new MethodLattice<String>(SSJavaAnalysis.TOP, SSJavaAnalysis.BOTTOM);
md2lattice.put(md, locOrder);
+ System.out.println("parsing method lattice=" + md);
parseMethodDefaultLatticeDefinition(cd, an.getValue(), locOrder);
writeLatticeDotFile(cd, md, locOrder, "");
} else if (an.getMarker().equals(TERMINATE)) {