1 package Analysis.SSJava;
3 import java.io.BufferedReader;
4 import java.io.BufferedWriter;
5 import java.io.FileReader;
6 import java.io.FileWriter;
7 import java.io.IOException;
8 import java.util.ArrayList;
9 import java.util.Collections;
10 import java.util.Comparator;
11 import java.util.HashMap;
12 import java.util.HashSet;
13 import java.util.Iterator;
14 import java.util.LinkedList;
15 import java.util.List;
18 import java.util.Stack;
19 import java.util.Vector;
21 import IR.ClassDescriptor;
23 import IR.FieldDescriptor;
24 import IR.MethodDescriptor;
25 import IR.NameDescriptor;
28 import IR.SymbolTable;
29 import IR.TypeDescriptor;
30 import IR.VarDescriptor;
31 import IR.Tree.ArrayAccessNode;
32 import IR.Tree.AssignmentNode;
33 import IR.Tree.BlockExpressionNode;
34 import IR.Tree.BlockNode;
35 import IR.Tree.BlockStatementNode;
36 import IR.Tree.CastNode;
37 import IR.Tree.CreateObjectNode;
38 import IR.Tree.DeclarationNode;
39 import IR.Tree.ExpressionNode;
40 import IR.Tree.FieldAccessNode;
41 import IR.Tree.IfStatementNode;
43 import IR.Tree.LiteralNode;
44 import IR.Tree.LoopNode;
45 import IR.Tree.MethodInvokeNode;
46 import IR.Tree.NameNode;
47 import IR.Tree.OpNode;
48 import IR.Tree.ReturnNode;
49 import IR.Tree.SubBlockNode;
50 import IR.Tree.SwitchBlockNode;
51 import IR.Tree.SwitchStatementNode;
52 import IR.Tree.TertiaryNode;
53 import IR.Tree.TreeNode;
56 public class LocationInference {
59 SSJavaAnalysis ssjava;
61 List<ClassDescriptor> temp_toanalyzeList;
62 List<MethodDescriptor> temp_toanalyzeMethodList;
63 Map<MethodDescriptor, FlowGraph> mapMethodDescriptorToFlowGraph;
65 LinkedList<MethodDescriptor> toanalyze_methodDescList;
67 // map a method descriptor to its set of parameter descriptors
68 Map<MethodDescriptor, Set<Descriptor>> mapMethodDescriptorToParamDescSet;
70 // keep current descriptors to visit in fixed-point interprocedural analysis,
71 private Stack<MethodDescriptor> methodDescriptorsToVisitStack;
73 // map a class descriptor to a field lattice
74 private Map<ClassDescriptor, SSJavaLattice<String>> cd2lattice;
76 // map a method descriptor to a method lattice
77 private Map<MethodDescriptor, SSJavaLattice<String>> md2lattice;
79 // map a method/class descriptor to a hierarchy graph
80 private Map<Descriptor, HierarchyGraph> mapDescriptorToHierarchyGraph;
82 // map a method/class descriptor to a skeleton hierarchy graph
83 private Map<Descriptor, HierarchyGraph> mapDescriptorToSkeletonHierarchyGraph;
85 private Map<Descriptor, HierarchyGraph> mapDescriptorToSimpleHierarchyGraph;
87 // map a method/class descriptor to a skeleton hierarchy graph with combination nodes
88 private Map<Descriptor, HierarchyGraph> mapDescriptorToCombineSkeletonHierarchyGraph;
90 // map a descriptor to a simple lattice
91 private Map<Descriptor, SSJavaLattice<String>> mapDescriptorToSimpleLattice;
93 // map a method descriptor to the set of method invocation nodes which are
94 // invoked by the method descriptor
95 private Map<MethodDescriptor, Set<MethodInvokeNode>> mapMethodDescriptorToMethodInvokeNodeSet;
97 private Map<MethodInvokeNode, Map<Integer, NTuple<Descriptor>>> mapMethodInvokeNodeToArgIdxMap;
99 private Map<MethodInvokeNode, NTuple<Descriptor>> mapMethodInvokeNodeToBaseTuple;
101 private Map<MethodDescriptor, MethodLocationInfo> mapMethodDescToMethodLocationInfo;
103 private Map<ClassDescriptor, LocationInfo> mapClassToLocationInfo;
105 private Map<MethodDescriptor, Set<MethodDescriptor>> mapMethodToCalleeSet;
107 private Map<MethodDescriptor, Set<FlowNode>> mapMethodDescToParamNodeFlowsToReturnValue;
109 private Map<String, Vector<String>> mapFileNameToLineVector;
111 private Map<Descriptor, Integer> mapDescToDefinitionLine;
113 private Map<Descriptor, LocationSummary> mapDescToLocationSummary;
115 // maps a method descriptor to a sub global flow graph that captures all value flows caused by the
116 // set of callees reachable from the method
117 private Map<MethodDescriptor, GlobalFlowGraph> mapMethodDescriptorToSubGlobalFlowGraph;
119 private Map<MethodInvokeNode, Map<NTuple<Descriptor>, NTuple<Descriptor>>> mapMethodInvokeNodeToMapCallerArgToCalleeArg;
121 public static final String GLOBALLOC = "GLOBALLOC";
123 public static final String TOPLOC = "TOPLOC";
125 public static final String INTERLOC = "INTERLOC";
127 public static final String PCLOC = "PCLOC";
129 public static final String RLOC = "RLOC";
131 public static final Descriptor GLOBALDESC = new NameDescriptor(GLOBALLOC);
133 public static final Descriptor TOPDESC = new NameDescriptor(TOPLOC);
135 public static final Descriptor RETURNLOC = new NameDescriptor(RLOC);
137 public static String newline = System.getProperty("line.separator");
139 LocationInfo curMethodInfo;
141 boolean debug = true;
143 public static int locSeed = 0;
145 public LocationInference(SSJavaAnalysis ssjava, State state) {
146 this.ssjava = ssjava;
148 this.temp_toanalyzeList = new ArrayList<ClassDescriptor>();
149 this.temp_toanalyzeMethodList = new ArrayList<MethodDescriptor>();
150 this.mapMethodDescriptorToFlowGraph = new HashMap<MethodDescriptor, FlowGraph>();
151 this.cd2lattice = new HashMap<ClassDescriptor, SSJavaLattice<String>>();
152 this.md2lattice = new HashMap<MethodDescriptor, SSJavaLattice<String>>();
153 this.methodDescriptorsToVisitStack = new Stack<MethodDescriptor>();
154 this.mapMethodDescriptorToMethodInvokeNodeSet =
155 new HashMap<MethodDescriptor, Set<MethodInvokeNode>>();
156 this.mapMethodInvokeNodeToArgIdxMap =
157 new HashMap<MethodInvokeNode, Map<Integer, NTuple<Descriptor>>>();
158 this.mapMethodDescToMethodLocationInfo = new HashMap<MethodDescriptor, MethodLocationInfo>();
159 this.mapMethodToCalleeSet = new HashMap<MethodDescriptor, Set<MethodDescriptor>>();
160 this.mapClassToLocationInfo = new HashMap<ClassDescriptor, LocationInfo>();
162 this.mapFileNameToLineVector = new HashMap<String, Vector<String>>();
163 this.mapDescToDefinitionLine = new HashMap<Descriptor, Integer>();
164 this.mapMethodDescToParamNodeFlowsToReturnValue =
165 new HashMap<MethodDescriptor, Set<FlowNode>>();
167 this.mapDescriptorToHierarchyGraph = new HashMap<Descriptor, HierarchyGraph>();
168 this.mapMethodInvokeNodeToBaseTuple = new HashMap<MethodInvokeNode, NTuple<Descriptor>>();
170 this.mapDescriptorToSkeletonHierarchyGraph = new HashMap<Descriptor, HierarchyGraph>();
171 this.mapDescriptorToCombineSkeletonHierarchyGraph = new HashMap<Descriptor, HierarchyGraph>();
172 this.mapDescriptorToSimpleHierarchyGraph = new HashMap<Descriptor, HierarchyGraph>();
174 this.mapDescriptorToSimpleLattice = new HashMap<Descriptor, SSJavaLattice<String>>();
176 this.mapDescToLocationSummary = new HashMap<Descriptor, LocationSummary>();
178 this.mapMethodDescriptorToSubGlobalFlowGraph = new HashMap<MethodDescriptor, GlobalFlowGraph>();
180 this.mapMethodInvokeNodeToMapCallerArgToCalleeArg =
181 new HashMap<MethodInvokeNode, Map<NTuple<Descriptor>, NTuple<Descriptor>>>();
185 public void setupToAnalyze() {
186 SymbolTable classtable = state.getClassSymbolTable();
187 temp_toanalyzeList.clear();
188 temp_toanalyzeList.addAll(classtable.getValueSet());
189 // Collections.sort(toanalyzeList, new Comparator<ClassDescriptor>() {
190 // public int compare(ClassDescriptor o1, ClassDescriptor o2) {
191 // return o1.getClassName().compareToIgnoreCase(o2.getClassName());
196 public void setupToAnalazeMethod(ClassDescriptor cd) {
198 SymbolTable methodtable = cd.getMethodTable();
199 temp_toanalyzeMethodList.clear();
200 temp_toanalyzeMethodList.addAll(methodtable.getValueSet());
201 Collections.sort(temp_toanalyzeMethodList, new Comparator<MethodDescriptor>() {
202 public int compare(MethodDescriptor o1, MethodDescriptor o2) {
203 return o1.getSymbol().compareToIgnoreCase(o2.getSymbol());
208 public boolean toAnalyzeMethodIsEmpty() {
209 return temp_toanalyzeMethodList.isEmpty();
212 public boolean toAnalyzeIsEmpty() {
213 return temp_toanalyzeList.isEmpty();
216 public ClassDescriptor toAnalyzeNext() {
217 return temp_toanalyzeList.remove(0);
220 public MethodDescriptor toAnalyzeMethodNext() {
221 return temp_toanalyzeMethodList.remove(0);
224 public void inference() {
226 // construct value flow graph
227 constructFlowGraph();
229 assignCompositeLocation();
233 constructHierarchyGraph();
235 debug_writeHierarchyDotFiles();
237 // calculate RETURNLOC,PCLOC
238 calculateExtraLocations();
240 simplifyHierarchyGraph();
242 debug_writeSimpleHierarchyDotFiles();
244 constructSkeletonHierarchyGraph();
246 debug_writeSkeletonHierarchyDotFiles();
248 insertCombinationNodes();
250 debug_writeSkeletonCombinationHierarchyDotFiles();
254 debug_writeLattices();
256 updateCompositeLocationAssignments();
258 generateMethodSummary();
260 generateAnnoatedCode();
266 public Map<NTuple<Descriptor>, NTuple<Descriptor>> getMapCallerArgToCalleeParam(
267 MethodInvokeNode min) {
269 if (!mapMethodInvokeNodeToMapCallerArgToCalleeArg.containsKey(min)) {
270 mapMethodInvokeNodeToMapCallerArgToCalleeArg.put(min,
271 new HashMap<NTuple<Descriptor>, NTuple<Descriptor>>());
274 return mapMethodInvokeNodeToMapCallerArgToCalleeArg.get(min);
277 public void addMapCallerArgToCalleeParam(MethodInvokeNode min, NTuple<Descriptor> callerArg,
278 NTuple<Descriptor> calleeParam) {
279 getMapCallerArgToCalleeParam(min).put(callerArg, calleeParam);
282 private void assignCompositeLocation() {
283 calculateGlobalValueFlowCompositeLocation();
284 translateCompositeLocationAssignmentToFlowGraph();
287 private void translateCompositeLocationAssignmentToFlowGraph() {
288 System.out.println("\nSSJAVA: Translate composite location assignments to flow graphs:");
289 MethodDescriptor methodEventLoopDesc = ssjava.getMethodContainingSSJavaLoop();
290 translateCompositeLocationAssignmentToFlowGraph(methodEventLoopDesc);
294 private void updateCompositeLocationAssignments() {
296 LinkedList<MethodDescriptor> methodDescList =
297 (LinkedList<MethodDescriptor>) toanalyze_methodDescList.clone();
299 while (!methodDescList.isEmpty()) {
300 MethodDescriptor md = methodDescList.removeLast();
302 System.out.println("\n#updateCompositeLocationAssignments=" + md);
304 FlowGraph flowGraph = getFlowGraph(md);
306 MethodSummary methodSummary = getMethodSummary(md);
308 Set<FlowNode> nodeSet = flowGraph.getNodeSet();
309 for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
310 FlowNode node = (FlowNode) iterator.next();
311 System.out.println("-node=" + node + " node.getDescTuple=" + node.getDescTuple());
312 if (node.getCompositeLocation() != null) {
313 CompositeLocation compLoc = node.getCompositeLocation();
314 CompositeLocation updatedCompLoc = updateCompositeLocation(compLoc);
315 node.setCompositeLocation(updatedCompLoc);
316 System.out.println("---updatedCompLoc1=" + updatedCompLoc);
318 NTuple<Descriptor> descTuple = node.getDescTuple();
319 CompositeLocation compLoc = convertToCompositeLocation(md, descTuple);
320 compLoc = updateCompositeLocation(compLoc);
321 node.setCompositeLocation(compLoc);
322 System.out.println("---updatedCompLoc2=" + compLoc);
325 if (node.isDeclaratonNode()) {
326 Descriptor localVarDesc = node.getDescTuple().get(0);
327 CompositeLocation compLoc = updateCompositeLocation(node.getCompositeLocation());
328 methodSummary.addMapVarNameToInferCompLoc(localVarDesc, compLoc);
332 // update PCLOC and RETURNLOC if they have a composite location assignment
333 if (methodSummary.getRETURNLoc() != null) {
334 methodSummary.setRETURNLoc(updateCompositeLocation(methodSummary.getRETURNLoc()));
336 if (methodSummary.getPCLoc() != null) {
337 methodSummary.setPCLoc(updateCompositeLocation(methodSummary.getPCLoc()));
344 private CompositeLocation updateCompositeLocation(CompositeLocation compLoc) {
345 CompositeLocation updatedCompLoc = new CompositeLocation();
346 for (int i = 0; i < compLoc.getSize(); i++) {
347 Location loc = compLoc.get(i);
348 String nodeIdentifier = loc.getLocIdentifier();
349 Descriptor enclosingDesc = loc.getDescriptor();
351 if (!enclosingDesc.equals(GLOBALDESC)) {
352 LocationSummary locSummary = getLocationSummary(enclosingDesc);
353 HierarchyGraph hierarchyGraph = getSimpleHierarchyGraph(enclosingDesc);
354 if (hierarchyGraph != null) {
356 HNode curNode = hierarchyGraph.getCurrentHNode(nodeIdentifier);
357 if (curNode != null) {
358 nodeIdentifier = curNode.getName();
361 locName = locSummary.getLocationName(nodeIdentifier);
363 locName = nodeIdentifier;
365 Location updatedLoc = new Location(enclosingDesc, locName);
366 updatedCompLoc.addLocation(updatedLoc);
369 return updatedCompLoc;
372 private void translateCompositeLocationAssignmentToFlowGraph(MethodDescriptor mdCaller) {
374 // First, assign a composite location to a node in the flow graph
375 GlobalFlowGraph callerGlobalFlowGraph = getSubGlobalFlowGraph(mdCaller);
377 FlowGraph callerFlowGraph = getFlowGraph(mdCaller);
378 Map<Location, CompositeLocation> callerMapLocToCompLoc =
379 callerGlobalFlowGraph.getMapLocationToInferCompositeLocation();
380 Set<Location> methodLocSet = callerMapLocToCompLoc.keySet();
381 for (Iterator iterator = methodLocSet.iterator(); iterator.hasNext();) {
382 Location methodLoc = (Location) iterator.next();
383 if (methodLoc.getDescriptor().equals(mdCaller)) {
384 CompositeLocation inferCompLoc = callerMapLocToCompLoc.get(methodLoc);
385 assignCompositeLocationToFlowGraph(callerFlowGraph, methodLoc, inferCompLoc);
389 Set<MethodInvokeNode> minSet = mapMethodDescriptorToMethodInvokeNodeSet.get(mdCaller);
391 Set<MethodDescriptor> calleeSet = new HashSet<MethodDescriptor>();
392 for (Iterator iterator = minSet.iterator(); iterator.hasNext();) {
393 MethodInvokeNode min = (MethodInvokeNode) iterator.next();
394 // need to translate a composite location that is started with the base
396 translateMapLocationToInferCompositeLocationToCalleeGraph(callerGlobalFlowGraph, min);
397 calleeSet.add(min.getMethod());
400 for (Iterator iterator = calleeSet.iterator(); iterator.hasNext();) {
401 MethodDescriptor callee = (MethodDescriptor) iterator.next();
402 translateCompositeLocationAssignmentToFlowGraph(callee);
407 public void assignCompositeLocationToFlowGraph(FlowGraph flowGraph, Location loc,
408 CompositeLocation inferCompLoc) {
409 Descriptor localDesc = loc.getLocDescriptor();
411 Set<FlowNode> nodeSet = flowGraph.getNodeSet();
412 for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
413 FlowNode node = (FlowNode) iterator.next();
414 if (node.getDescTuple().startsWith(localDesc)) {
415 // need to assign the inferred composite location to this node
416 CompositeLocation newCompLoc = generateCompositeLocation(node.getDescTuple(), inferCompLoc);
417 node.setCompositeLocation(newCompLoc);
418 System.out.println("SET Node=" + node + " inferCompLoc=" + newCompLoc);
423 private CompositeLocation generateCompositeLocation(NTuple<Descriptor> nodeDescTuple,
424 CompositeLocation inferCompLoc) {
426 System.out.println("generateCompositeLocation=" + nodeDescTuple + " with inferCompLoc="
429 CompositeLocation newCompLoc = new CompositeLocation();
430 for (int i = 0; i < inferCompLoc.getSize(); i++) {
431 newCompLoc.addLocation(inferCompLoc.get(i));
434 Descriptor lastDescOfPrefix = nodeDescTuple.get(0);
435 Descriptor enclosingDescriptor;
436 if (lastDescOfPrefix instanceof InterDescriptor) {
437 enclosingDescriptor = null;
439 enclosingDescriptor = ((VarDescriptor) lastDescOfPrefix).getType().getClassDesc();
442 for (int i = 1; i < nodeDescTuple.size(); i++) {
443 Descriptor desc = nodeDescTuple.get(i);
444 Location locElement = new Location(enclosingDescriptor, desc);
445 newCompLoc.addLocation(locElement);
447 enclosingDescriptor = ((FieldDescriptor) desc).getClassDescriptor();
453 private void translateMapLocationToInferCompositeLocationToCalleeGraph(
454 GlobalFlowGraph callerGraph, MethodInvokeNode min) {
456 MethodDescriptor mdCallee = min.getMethod();
457 MethodDescriptor mdCaller = callerGraph.getMethodDescriptor();
458 Map<Location, CompositeLocation> callerMapLocToCompLoc =
459 callerGraph.getMapLocationToInferCompositeLocation();
461 FlowGraph calleeFlowGraph = getFlowGraph(mdCallee);
462 GlobalFlowGraph calleeGlobalGraph = getSubGlobalFlowGraph(mdCallee);
464 NTuple<Location> baseLocTuple = null;
465 if (mapMethodInvokeNodeToBaseTuple.containsKey(min)) {
466 baseLocTuple = translateToLocTuple(mdCaller, mapMethodInvokeNodeToBaseTuple.get(min));
469 // System.out.println("\n-translate caller infer composite loc to callee=" + mdCallee
470 // + " baseLocTuple=" + baseLocTuple);
471 Set<Location> keySet = callerMapLocToCompLoc.keySet();
472 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
473 Location key = (Location) iterator.next();
474 CompositeLocation callerCompLoc = callerMapLocToCompLoc.get(key);
476 if (!key.getDescriptor().equals(mdCaller)) {
478 CompositeLocation newCalleeCompLoc;
479 if (baseLocTuple != null && callerCompLoc.getTuple().startsWith(baseLocTuple)) {
480 // System.out.println("---need to translate callerCompLoc=" + callerCompLoc
481 // + " with baseTuple=" + baseLocTuple);
483 translateCompositeLocationToCallee(callerCompLoc, baseLocTuple, mdCallee);
485 calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, newCalleeCompLoc);
486 // System.out.println("---callee loc=" + key + " newCalleeCompLoc=" + newCalleeCompLoc);
488 // check if it is the global access
489 Location compLocFirstElement = callerCompLoc.getTuple().get(0);
490 if (compLocFirstElement.getDescriptor().equals(mdCallee)
491 && compLocFirstElement.getLocDescriptor().equals(GLOBALDESC)) {
493 newCalleeCompLoc = new CompositeLocation();
494 Location newMethodLoc = new Location(mdCallee, GLOBALDESC);
496 newCalleeCompLoc.addLocation(newMethodLoc);
497 for (int i = 1; i < callerCompLoc.getSize(); i++) {
498 newCalleeCompLoc.addLocation(callerCompLoc.get(i));
500 calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, newCalleeCompLoc);
509 // System.out.println("-----*AFTER TRANSLATING COMP LOC MAPPING, CALLEE MAPPING="
510 // + calleeGlobalGraph.getMapLocationToInferCompositeLocation());
512 // If the location of an argument has a composite location
513 // need to assign a proper composite location to the corresponding callee parameter
514 // System.out.println("---translate arg composite location to callee param. min="
515 // + min.printNode(0));
516 Map<Integer, NTuple<Descriptor>> mapIdxToArgTuple = mapMethodInvokeNodeToArgIdxMap.get(min);
517 Set<Integer> idxSet = mapIdxToArgTuple.keySet();
518 for (Iterator iterator = idxSet.iterator(); iterator.hasNext();) {
519 Integer idx = (Integer) iterator.next();
521 if (idx == 0 && !min.getMethod().isStatic()) {
525 NTuple<Descriptor> argTuple = mapIdxToArgTuple.get(idx);
526 if (argTuple.size() > 0) {
527 // check if an arg tuple has been already assigned to a composite location
528 NTuple<Location> argLocTuple = translateToLocTuple(mdCaller, argTuple);
529 Location argLocalLoc = argLocTuple.get(0);
531 // if (!isPrimitiveType(argTuple)) {
532 if (callerMapLocToCompLoc.containsKey(argLocalLoc)) {
534 CompositeLocation callerCompLoc = callerMapLocToCompLoc.get(argLocalLoc);
535 for (int i = 1; i < argLocTuple.size(); i++) {
536 callerCompLoc.addLocation(argLocTuple.get(i));
539 if (baseLocTuple != null && callerCompLoc.getTuple().startsWith(baseLocTuple)) {
541 FlowNode calleeParamFlowNode = calleeFlowGraph.getParamFlowNode(idx);
542 NTuple<Descriptor> calleeParamDescTuple = calleeParamFlowNode.getDescTuple();
543 NTuple<Location> calleeParamLocTuple =
544 translateToLocTuple(mdCallee, calleeParamDescTuple);
546 System.out.println("---need to translate callerCompLoc=" + callerCompLoc
547 + " with baseTuple=" + baseLocTuple + " calleeParamLocTuple="
548 + calleeParamLocTuple);
550 CompositeLocation newCalleeCompLoc =
551 translateCompositeLocationToCallee(callerCompLoc, baseLocTuple, mdCallee);
553 calleeGlobalGraph.addMapLocationToInferCompositeLocation(calleeParamLocTuple.get(0),
556 System.out.println("---callee loc=" + calleeParamLocTuple.get(0)
557 + " newCalleeCompLoc=" + newCalleeCompLoc);
559 // System.out.println("###need to assign composite location to=" + calleeParamDescTuple
560 // + " with baseTuple=" + baseLocTuple);
570 private boolean isPrimitiveType(NTuple<Descriptor> argTuple) {
572 Descriptor lastDesc = argTuple.get(argTuple.size() - 1);
574 if (lastDesc instanceof FieldDescriptor) {
575 return ((FieldDescriptor) lastDesc).getType().isPrimitive();
576 } else if (lastDesc instanceof VarDescriptor) {
577 return ((VarDescriptor) lastDesc).getType().isPrimitive();
583 private CompositeLocation translateCompositeLocationToCallee(CompositeLocation callerCompLoc,
584 NTuple<Location> baseLocTuple, MethodDescriptor mdCallee) {
586 CompositeLocation newCalleeCompLoc = new CompositeLocation();
588 Location calleeThisLoc = new Location(mdCallee, mdCallee.getThis());
589 newCalleeCompLoc.addLocation(calleeThisLoc);
591 // remove the base tuple from the caller
592 // ex; In the method invoation foo.bar.methodA(), the callee will have the composite location
593 // ,which is relative to the 'this' variable, <THIS,...>
594 for (int i = baseLocTuple.size(); i < callerCompLoc.getSize(); i++) {
595 newCalleeCompLoc.addLocation(callerCompLoc.get(i));
598 return newCalleeCompLoc;
602 private void calculateGlobalValueFlowCompositeLocation() {
604 System.out.println("SSJAVA: Calculate composite locations in the global value flow graph");
605 MethodDescriptor methodDescEventLoop = ssjava.getMethodContainingSSJavaLoop();
606 GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(methodDescEventLoop);
608 Set<Location> calculatedPrefixSet = new HashSet<Location>();
610 Set<GlobalFlowNode> nodeSet = globalFlowGraph.getNodeSet();
612 next: for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
613 GlobalFlowNode node = (GlobalFlowNode) iterator.next();
615 Location prefixLoc = node.getLocTuple().get(0);
617 if (calculatedPrefixSet.contains(prefixLoc)) {
618 // the prefix loc has been already assigned to a composite location
622 calculatedPrefixSet.add(prefixLoc);
624 // Set<GlobalFlowNode> incomingNodeSet = globalFlowGraph.getIncomingNodeSet(node);
625 List<NTuple<Location>> prefixList = calculatePrefixList(globalFlowGraph, node);
627 Set<GlobalFlowNode> reachableNodeSet =
628 globalFlowGraph.getReachableNodeSetByPrefix(node.getLocTuple().get(0));
629 // Set<GlobalFlowNode> reachNodeSet = globalFlowGraph.getReachableNodeSetFrom(node);
631 // System.out.println("node=" + node + " prefixList=" + prefixList + " reachableNodeSet="
632 // + reachableNodeSet);
634 for (int i = 0; i < prefixList.size(); i++) {
635 NTuple<Location> curPrefix = prefixList.get(i);
636 Set<NTuple<Location>> reachableCommonPrefixSet = new HashSet<NTuple<Location>>();
638 for (Iterator iterator2 = reachableNodeSet.iterator(); iterator2.hasNext();) {
639 GlobalFlowNode reachNode = (GlobalFlowNode) iterator2.next();
640 if (reachNode.getLocTuple().startsWith(curPrefix)) {
641 reachableCommonPrefixSet.add(reachNode.getLocTuple());
645 if (!reachableCommonPrefixSet.isEmpty()) {
647 MethodDescriptor curPrefixFirstElementMethodDesc =
648 (MethodDescriptor) curPrefix.get(0).getDescriptor();
650 MethodDescriptor nodePrefixLocFirstElementMethodDesc =
651 (MethodDescriptor) prefixLoc.getDescriptor();
653 if (curPrefixFirstElementMethodDesc.equals(nodePrefixLocFirstElementMethodDesc)
654 || isTransitivelyCalledFrom(nodePrefixLocFirstElementMethodDesc,
655 curPrefixFirstElementMethodDesc)) {
658 // if (!node.getLocTuple().startsWith(curPrefix.get(0))) {
660 Location curPrefixLocalLoc = curPrefix.get(0);
661 if (globalFlowGraph.mapLocationToInferCompositeLocation.containsKey(curPrefixLocalLoc)) {
662 // in this case, the local variable of the current prefix has already got a composite
664 // so we just ignore the current composite location.
666 // System.out.println("HERE WE DO NOT ASSIGN A COMPOSITE LOCATION TO =" + node
667 // + " DUE TO " + curPrefix);
672 Location targetLocalLoc = node.getLocTuple().get(0);
673 // CompositeLocation curCompLoc = globalFlowGraph.getCompositeLocation(targetLocalLoc);
674 // if ((curPrefix.size() + 1) > curCompLoc.getSize()) {
676 CompositeLocation newCompLoc = generateCompositeLocation(curPrefix);
677 System.out.println("NEED TO ASSIGN COMP LOC TO " + node + " with prefix=" + curPrefix);
678 System.out.println("- newCompLoc=" + newCompLoc);
679 globalFlowGraph.addMapLocationToInferCompositeLocation(targetLocalLoc, newCompLoc);
692 // Set<GlobalFlowNode> inNodeSet =
693 // graph.getIncomingNodeSetWithPrefix(prefix);
694 // System.out.println("inNodeSet=" + inNodeSet + " from=" + node);
697 private void assignCompositeLocation(CompositeLocation compLocPrefix, GlobalFlowNode node) {
698 CompositeLocation newCompLoc = compLocPrefix.clone();
699 NTuple<Location> locTuple = node.getLocTuple();
700 for (int i = 1; i < locTuple.size(); i++) {
701 newCompLoc.addLocation(locTuple.get(i));
703 node.setInferCompositeLocation(newCompLoc);
706 private List<NTuple<Location>> calculatePrefixList(GlobalFlowGraph graph, GlobalFlowNode node) {
708 System.out.println("\n##### calculatePrefixList node=" + node);
710 Set<GlobalFlowNode> incomingNodeSetPrefix =
711 graph.getIncomingNodeSetByPrefix(node.getLocTuple().get(0));
712 // System.out.println("incomingNodeSetPrefix=" + incomingNodeSetPrefix);
714 // Set<GlobalFlowNode> reachableNodeSetPrefix =
715 // graph.getReachableNodeSetByPrefix(node.getLocTuple().get(0));
716 // System.out.println("reachableNodeSetPrefix=" + reachableNodeSetPrefix);
718 List<NTuple<Location>> prefixList = new ArrayList<NTuple<Location>>();
720 for (Iterator iterator = incomingNodeSetPrefix.iterator(); iterator.hasNext();) {
721 GlobalFlowNode inNode = (GlobalFlowNode) iterator.next();
722 NTuple<Location> inNodeTuple = inNode.getLocTuple();
724 for (int i = 1; i < inNodeTuple.size(); i++) {
725 NTuple<Location> prefix = inNodeTuple.subList(0, i);
726 if (!prefixList.contains(prefix)) {
727 prefixList.add(prefix);
732 Collections.sort(prefixList, new Comparator<NTuple<Location>>() {
733 public int compare(NTuple<Location> arg0, NTuple<Location> arg1) {
734 int s0 = arg0.size();
735 int s1 = arg1.size();
738 } else if (s0 == s1) {
746 // remove a prefix which is not suitable for generating composite location
747 Location localVarLoc = node.getLocTuple().get(0);
748 MethodDescriptor md = (MethodDescriptor) localVarLoc.getDescriptor();
749 ClassDescriptor cd = md.getClassDesc();
753 Set<NTuple<Location>> toberemoved = new HashSet<NTuple<Location>>();
754 for (int i = 0; i < prefixList.size(); i++) {
755 NTuple<Location> prefixLocTuple = prefixList.get(i);
756 if (!containsClassDesc(cd, prefixLocTuple)) {
757 toberemoved.add(prefixLocTuple);
761 prefixList.removeAll(toberemoved);
765 // List<NTuple<Location>> prefixList = new ArrayList<NTuple<Location>>();
767 // for (Iterator iterator = incomingNodeSet.iterator(); iterator.hasNext();) {
768 // GlobalFlowNode inNode = (GlobalFlowNode) iterator.next();
769 // NTuple<Location> inNodeTuple = inNode.getLocTuple();
771 // for (int i = 1; i < inNodeTuple.size(); i++) {
772 // NTuple<Location> prefix = inNodeTuple.subList(0, i);
773 // if (!prefixList.contains(prefix)) {
774 // prefixList.add(prefix);
779 // Collections.sort(prefixList, new Comparator<NTuple<Location>>() {
780 // public int compare(NTuple<Location> arg0, NTuple<Location> arg1) {
781 // int s0 = arg0.size();
782 // int s1 = arg1.size();
785 // } else if (s0 == s1) {
792 // return prefixList;
795 private boolean containsClassDesc(ClassDescriptor cd, NTuple<Location> prefixLocTuple) {
796 for (int i = 0; i < prefixLocTuple.size(); i++) {
797 Location loc = prefixLocTuple.get(i);
798 Descriptor locDesc = loc.getLocDescriptor();
799 if (locDesc != null) {
800 ClassDescriptor type = getClassTypeDescriptor(locDesc);
801 if (type != null && type.equals(cd)) {
809 private GlobalFlowGraph constructSubGlobalFlowGraph(FlowGraph flowGraph) {
811 MethodDescriptor md = flowGraph.getMethodDescriptor();
813 GlobalFlowGraph globalGraph = new GlobalFlowGraph(md);
815 // Set<FlowNode> nodeSet = flowGraph.getNodeSet();
816 Set<FlowEdge> edgeSet = flowGraph.getEdgeSet();
818 for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) {
820 FlowEdge edge = (FlowEdge) iterator.next();
821 NTuple<Descriptor> srcDescTuple = edge.getInitTuple();
822 NTuple<Descriptor> dstDescTuple = edge.getEndTuple();
824 // here only keep the first element(method location) of the descriptor
826 NTuple<Location> srcLocTuple = translateToLocTuple(md, srcDescTuple);
827 // Location srcMethodLoc = srcLocTuple.get(0);
828 // Descriptor srcVarDesc = srcMethodLoc.getLocDescriptor();
829 // // if (flowGraph.isParamDesc(srcVarDesc) &&
830 // (!srcVarDesc.equals(md.getThis()))) {
831 // if (!srcVarDesc.equals(md.getThis())) {
832 // srcLocTuple = new NTuple<Location>();
833 // Location loc = new Location(md, srcVarDesc);
834 // srcLocTuple.add(loc);
837 NTuple<Location> dstLocTuple = translateToLocTuple(md, dstDescTuple);
838 // Location dstMethodLoc = dstLocTuple.get(0);
839 // Descriptor dstVarDesc = dstMethodLoc.getLocDescriptor();
840 // if (!dstVarDesc.equals(md.getThis())) {
841 // dstLocTuple = new NTuple<Location>();
842 // Location loc = new Location(md, dstVarDesc);
843 // dstLocTuple.add(loc);
846 globalGraph.addValueFlowEdge(srcLocTuple, dstLocTuple);
853 private NTuple<Location> translateToLocTuple(MethodDescriptor md, NTuple<Descriptor> descTuple) {
855 NTuple<Location> locTuple = new NTuple<Location>();
857 Descriptor enclosingDesc = md;
858 // System.out.println("md=" + md + " descTuple=" + descTuple);
859 for (int i = 0; i < descTuple.size(); i++) {
860 Descriptor desc = descTuple.get(i);
862 Location loc = new Location(enclosingDesc, desc);
865 if (desc instanceof VarDescriptor) {
866 enclosingDesc = ((VarDescriptor) desc).getType().getClassDesc();
867 } else if (desc instanceof FieldDescriptor) {
868 enclosingDesc = ((FieldDescriptor) desc).getType().getClassDesc();
870 // TODO: inter descriptor case
871 enclosingDesc = desc;
880 private void addValueFlowsFromCalleeSubGlobalFlowGraph(MethodDescriptor mdCaller,
881 GlobalFlowGraph subGlobalFlowGraph) {
883 // the transformation for a call site propagates flows through parameters
884 // if the method is virtual, it also grab all relations from any possible
887 Set<MethodInvokeNode> setMethodInvokeNode = getMethodInvokeNodeSet(mdCaller);
889 for (Iterator iterator = setMethodInvokeNode.iterator(); iterator.hasNext();) {
890 MethodInvokeNode min = (MethodInvokeNode) iterator.next();
891 MethodDescriptor mdCallee = min.getMethod();
892 Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
893 if (mdCallee.isStatic()) {
894 setPossibleCallees.add(mdCallee);
896 Set<MethodDescriptor> calleeSet = ssjava.getCallGraph().getMethods(mdCallee);
897 // removes method descriptors that are not invoked by the caller
898 calleeSet.retainAll(mapMethodToCalleeSet.get(mdCaller));
899 setPossibleCallees.addAll(calleeSet);
902 for (Iterator iterator2 = setPossibleCallees.iterator(); iterator2.hasNext();) {
903 MethodDescriptor possibleMdCallee = (MethodDescriptor) iterator2.next();
904 propagateValueFlowsToCallerFromSubGlobalFlowGraph(min, mdCaller, possibleMdCallee);
911 private void propagateValueFlowsToCallerFromSubGlobalFlowGraph(MethodInvokeNode min,
912 MethodDescriptor mdCaller, MethodDescriptor possibleMdCallee) {
914 System.out.println("---propagate from " + min.printNode(0) + " to caller=" + mdCaller);
915 FlowGraph calleeFlowGraph = getFlowGraph(possibleMdCallee);
916 Map<Integer, NTuple<Descriptor>> mapIdxToArg = mapMethodInvokeNodeToArgIdxMap.get(min);
918 System.out.println("-----mapMethodInvokeNodeToArgIdxMap.get(min)="
919 + mapMethodInvokeNodeToArgIdxMap.get(min));
920 Set<Integer> keySet = mapIdxToArg.keySet();
921 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
922 Integer idx = (Integer) iterator.next();
923 NTuple<Descriptor> argDescTuple = mapIdxToArg.get(idx);
924 if (argDescTuple.size() > 0) {
925 NTuple<Location> argLocTuple = translateToLocTuple(mdCaller, argDescTuple);
926 NTuple<Descriptor> paramDescTuple = calleeFlowGraph.getParamFlowNode(idx).getDescTuple();
927 NTuple<Location> paramLocTuple = translateToLocTuple(possibleMdCallee, paramDescTuple);
928 addMapCallerArgToCalleeParam(min, argDescTuple, paramDescTuple);
932 NTuple<Descriptor> baseTuple = mapMethodInvokeNodeToBaseTuple.get(min);
933 GlobalFlowGraph calleeSubGlobalGraph = getSubGlobalFlowGraph(possibleMdCallee);
934 Set<GlobalFlowNode> calleeNodeSet = calleeSubGlobalGraph.getNodeSet();
935 for (Iterator iterator = calleeNodeSet.iterator(); iterator.hasNext();) {
936 GlobalFlowNode calleeNode = (GlobalFlowNode) iterator.next();
937 addValueFlowFromCalleeNode(min, mdCaller, possibleMdCallee, calleeNode);
940 // int numParam = calleeFlowGraph.getNumParameters();
941 // for (int idx = 0; idx < numParam; idx++) {
943 // FlowNode paramNode = calleeFlowGraph.getParamFlowNode(idx);
945 // NTuple<Location> paramLocTuple =
946 // translateToLocTuple(possibleMdCallee, paramNode.getCurrentDescTuple());
948 // GlobalFlowNode globalParamNode =
949 // calleeSubGlobalGraph.getFlowNode(paramLocTuple);
951 // NTuple<Descriptor> argTuple =
952 // mapMethodInvokeNodeToArgIdxMap.get(min).get(idx);
954 // NTuple<Location> argLocTuple = translateToLocTuple(mdCaller, argTuple);
956 // System.out.println("argTupleSet=" + argLocTuple + " param=" +
958 // // here, it adds all value flows reachable from the paramNode in the
959 // callee's flow graph
961 // addValueFlowsFromCalleeParam(mdCaller, argLocTuple, baseLocTuple,
967 // // FlowGraph callerSubGlobalGraph = getSubGlobalFlowGraph(mdCaller);
968 // // FlowGraph calleeSubGlobalGraph =
969 // getSubGlobalFlowGraph(possibleMdCallee);
971 // // int numParam = calleeSubGlobalGraph.getNumParameters();
972 // // for (int idx = 0; idx < numParam; idx++) {
973 // // FlowNode paramNode = calleeSubGlobalGraph.getParamFlowNode(idx);
974 // // NTuple<Descriptor> argTuple =
975 // mapMethodInvokeNodeToArgIdxMap.get(min).get(idx);
976 // // System.out.println("argTupleSet=" + argTuple + " param=" +
978 // // // here, it adds all value flows reachable from the paramNode in the
979 // callee's flow graph
980 // // addValueFlowsFromCalleeParam(min, calleeSubGlobalGraph, paramNode,
981 // callerSubGlobalGraph,
982 // // argTuple, baseTuple);
987 private void addValueFlowFromCalleeNode(MethodInvokeNode min, MethodDescriptor mdCaller,
988 MethodDescriptor mdCallee, GlobalFlowNode calleeSrcNode) {
990 GlobalFlowGraph calleeSubGlobalGraph = getSubGlobalFlowGraph(mdCallee);
991 GlobalFlowGraph callerSubGlobalGraph = getSubGlobalFlowGraph(mdCaller);
993 NTuple<Location> callerSrcNodeLocTuple =
994 translateToCallerLocTuple(min, mdCallee, mdCaller, calleeSrcNode.getLocTuple());
996 if (callerSrcNodeLocTuple != null) {
997 Set<GlobalFlowNode> outNodeSet = calleeSubGlobalGraph.getOutNodeSet(calleeSrcNode);
999 for (Iterator iterator = outNodeSet.iterator(); iterator.hasNext();) {
1000 GlobalFlowNode outNode = (GlobalFlowNode) iterator.next();
1001 NTuple<Location> callerDstNodeLocTuple =
1002 translateToCallerLocTuple(min, mdCallee, mdCaller, outNode.getLocTuple());
1003 if (callerDstNodeLocTuple != null) {
1004 callerSubGlobalGraph.addValueFlowEdge(callerSrcNodeLocTuple, callerDstNodeLocTuple);
1011 private NTuple<Location> translateToCallerLocTuple(MethodInvokeNode min,
1012 MethodDescriptor mdCallee, MethodDescriptor mdCaller, NTuple<Location> nodeLocTuple) {
1013 // this method will return the same nodeLocTuple if the corresponding argument is literal
1016 FlowGraph calleeFlowGraph = getFlowGraph(mdCallee);
1018 NTuple<Descriptor> nodeDescTuple = translateToDescTuple(nodeLocTuple);
1019 if (calleeFlowGraph.isParameter(nodeDescTuple)) {
1020 int paramIdx = calleeFlowGraph.getParamIdx(nodeDescTuple);
1021 NTuple<Descriptor> argDescTuple = mapMethodInvokeNodeToArgIdxMap.get(min).get(paramIdx);
1023 if (isPrimitive(nodeLocTuple.get(0).getLocDescriptor())) {
1024 // the type of argument is primitive.
1025 return nodeLocTuple.clone();
1027 NTuple<Location> argLocTuple = translateToLocTuple(mdCaller, argDescTuple);
1029 NTuple<Location> callerLocTuple = new NTuple<Location>();
1031 callerLocTuple.addAll(argLocTuple);
1032 for (int i = 1; i < nodeLocTuple.size(); i++) {
1033 callerLocTuple.add(nodeLocTuple.get(i));
1035 return callerLocTuple;
1037 return nodeLocTuple.clone();
1042 public static boolean isPrimitive(Descriptor desc) {
1044 if (desc instanceof FieldDescriptor) {
1045 return ((FieldDescriptor) desc).getType().isPrimitive();
1046 } else if (desc instanceof VarDescriptor) {
1047 return ((VarDescriptor) desc).getType().isPrimitive();
1048 } else if (desc instanceof InterDescriptor) {
1055 private NTuple<Descriptor> translateToDescTuple(NTuple<Location> locTuple) {
1057 NTuple<Descriptor> descTuple = new NTuple<Descriptor>();
1058 for (int i = 0; i < locTuple.size(); i++) {
1059 descTuple.add(locTuple.get(i).getLocDescriptor());
1065 private void addValueFlowsFromCalleeParam(MethodDescriptor mdCaller,
1066 NTuple<Location> argLocTuple, NTuple<Location> baseLocTuple, MethodDescriptor mdCallee,
1067 GlobalFlowNode globalParamNode) {
1069 Set<GlobalFlowNode> visited = new HashSet<GlobalFlowNode>();
1070 visited.add(globalParamNode);
1071 recurAddValueFlowsFromCalleeParam(mdCaller, argLocTuple, baseLocTuple, mdCallee,
1076 private void recurAddValueFlowsFromCalleeParam(MethodDescriptor mdCaller,
1077 NTuple<Location> argLocTuple, NTuple<Location> baseLocTuple, MethodDescriptor mdCallee,
1078 GlobalFlowNode calleeCurNode) {
1080 // FlowGraph calleeFlowGraph = getFlowGraph(mdCallee);
1081 // GlobalFlowGraph calleeSubGlobalGraph = getSubGlobalFlowGraph(mdCallee);
1083 // NTuple<Location> curNodeLocTuple = calleeCurNode.getLocTuple();
1084 // NTuple<Descriptor> curNodeDescTuple = calleeCurNode.getDescTuple();
1085 // if (calleeFlowGraph.isParameter(curNodeDescTuple)) {
1086 // curNodeLocTuple = translateToCaller(argLocTuple, curNodeLocTuple);
1089 // Set<GlobalFlowNode> outNodeSet =
1090 // calleeSubGlobalGraph.getOutNodeSet(calleeCurNode);
1091 // for (Iterator iterator = outNodeSet.iterator(); iterator.hasNext();) {
1092 // GlobalFlowNode outNode = (GlobalFlowNode) iterator.next();
1094 // NTuple<Location> curNodeLocTuple = calleeCurNode.getLocTuple();
1095 // NTuple<Descriptor> curNodeDescTuple = calleeCurNode.getDescTuple();
1096 // if (calleeFlowGraph.isParameter(curNodeDescTuple)) {
1097 // curNodeLocTuple = translateToCaller(argLocTuple, curNodeLocTuple);
1100 // outNode.getDescTuple();
1102 // if (calleeFlowGraph.is)
1104 // if (calleeSubGlobalGraph.isParameter(srcDescTuple)) {
1105 // // destination node is started with 'parameter'
1106 // // need to translate it in terms of the caller's a node
1108 // translateToCaller(min, calleeSubGlobalGraph.getParamIdx(srcDescTuple),
1114 // Set<FlowEdge> edgeSet =
1115 // calleeSubGlobalGraph.getOutEdgeSetStartingFrom(calleeSrcNode);
1116 // for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) {
1117 // FlowEdge flowEdge = (FlowEdge) iterator.next();
1119 // NTuple<Descriptor> srcDescTuple = flowEdge.getInitTuple();
1120 // NTuple<Descriptor> dstDescTuple = flowEdge.getEndTuple();
1122 // FlowNode dstNode = calleeSubGlobalGraph.getFlowNode(dstDescTuple);
1124 // if (calleeSubGlobalGraph.isParameter(srcDescTuple)) {
1125 // // destination node is started with 'parameter'
1126 // // need to translate it in terms of the caller's a node
1128 // translateToCaller(min, calleeSubGlobalGraph.getParamIdx(srcDescTuple),
1132 // if (calleeSubGlobalGraph.isParameter(dstDescTuple)) {
1133 // // destination node is started with 'parameter'
1134 // // need to translate it in terms of the caller's a node
1136 // translateToCaller(min, calleeSubGlobalGraph.getParamIdx(dstDescTuple),
1140 // callerSubGlobalGraph.addValueFlowEdge(srcDescTuple, dstDescTuple);
1142 // if (!visited.contains(dstNode)) {
1143 // visited.add(dstNode);
1144 // recurAddValueFlowsFromCalleeParam(min, calleeSubGlobalGraph, dstNode,
1145 // callerSubGlobalGraph,
1146 // dstDescTuple, visited, baseTuple);
1153 private NTuple<Location> translateToCaller(NTuple<Location> argLocTuple,
1154 NTuple<Location> curNodeLocTuple) {
1156 NTuple<Location> callerLocTuple = new NTuple<Location>();
1158 callerLocTuple.addAll(argLocTuple);
1159 for (int i = 1; i < curNodeLocTuple.size(); i++) {
1160 callerLocTuple.add(curNodeLocTuple.get(i));
1163 return callerLocTuple;
1166 private void recurAddValueFlowsFromCalleeParam(MethodInvokeNode min,
1167 FlowGraph calleeSubGlobalGraph, FlowNode calleeSrcNode, FlowGraph callerSubGlobalGraph,
1168 NTuple<Descriptor> callerSrcTuple, Set<FlowNode> visited, NTuple<Descriptor> baseTuple) {
1170 MethodDescriptor mdCallee = calleeSubGlobalGraph.getMethodDescriptor();
1172 // Set<FlowEdge> edgeSet =
1173 // calleeSubGlobalGraph.getOutEdgeSet(calleeSrcNode);
1174 Set<FlowEdge> edgeSet = calleeSubGlobalGraph.getOutEdgeSetStartingFrom(calleeSrcNode);
1175 for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) {
1176 FlowEdge flowEdge = (FlowEdge) iterator.next();
1178 NTuple<Descriptor> srcDescTuple = flowEdge.getInitTuple();
1179 NTuple<Descriptor> dstDescTuple = flowEdge.getEndTuple();
1181 FlowNode dstNode = calleeSubGlobalGraph.getFlowNode(dstDescTuple);
1183 if (calleeSubGlobalGraph.isParameter(srcDescTuple)) {
1184 // destination node is started with 'parameter'
1185 // need to translate it in terms of the caller's a node
1187 translateToCaller(min, calleeSubGlobalGraph.getParamIdx(srcDescTuple), srcDescTuple);
1190 if (calleeSubGlobalGraph.isParameter(dstDescTuple)) {
1191 // destination node is started with 'parameter'
1192 // need to translate it in terms of the caller's a node
1194 translateToCaller(min, calleeSubGlobalGraph.getParamIdx(dstDescTuple), dstDescTuple);
1197 callerSubGlobalGraph.addValueFlowEdge(srcDescTuple, dstDescTuple);
1199 if (!visited.contains(dstNode)) {
1200 visited.add(dstNode);
1201 recurAddValueFlowsFromCalleeParam(min, calleeSubGlobalGraph, dstNode, callerSubGlobalGraph,
1202 dstDescTuple, visited, baseTuple);
1209 private NTuple<Descriptor> translateToCaller(MethodInvokeNode min, int paramIdx,
1210 NTuple<Descriptor> srcDescTuple) {
1212 NTuple<Descriptor> callerTuple = new NTuple<Descriptor>();
1214 NTuple<Descriptor> argTuple = mapMethodInvokeNodeToArgIdxMap.get(min).get(paramIdx);
1216 for (int i = 0; i < argTuple.size(); i++) {
1217 callerTuple.add(argTuple.get(i));
1220 for (int i = 1; i < srcDescTuple.size(); i++) {
1221 callerTuple.add(srcDescTuple.get(i));
1227 private NTuple<Descriptor> traslateToCalleeParamTupleToCallerArgTuple(
1228 NTuple<Descriptor> calleeInitTuple, NTuple<Descriptor> callerSrcTuple) {
1230 NTuple<Descriptor> callerInitTuple = new NTuple<Descriptor>();
1232 for (int i = 0; i < callerSrcTuple.size(); i++) {
1233 callerInitTuple.add(callerSrcTuple.get(i));
1236 for (int i = 1; i < calleeInitTuple.size(); i++) {
1237 callerInitTuple.add(calleeInitTuple.get(i));
1240 return callerInitTuple;
1243 public LocationSummary getLocationSummary(Descriptor d) {
1244 if (!mapDescToLocationSummary.containsKey(d)) {
1245 if (d instanceof MethodDescriptor) {
1246 mapDescToLocationSummary.put(d, new MethodSummary((MethodDescriptor) d));
1247 } else if (d instanceof ClassDescriptor) {
1248 mapDescToLocationSummary.put(d, new FieldSummary());
1251 return mapDescToLocationSummary.get(d);
1254 private void generateMethodSummary() {
1256 Set<MethodDescriptor> keySet = md2lattice.keySet();
1257 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
1258 MethodDescriptor md = (MethodDescriptor) iterator.next();
1260 System.out.println("\nSSJAVA: generate method summary: " + md);
1262 FlowGraph flowGraph = getFlowGraph(md);
1263 MethodSummary methodSummary = getMethodSummary(md);
1265 HierarchyGraph scGraph = getSkeletonCombinationHierarchyGraph(md);
1267 // set the 'this' reference location
1268 if (!md.isStatic()) {
1269 System.out.println("setThisLocName=" + scGraph.getHNode(md.getThis()).getName());
1270 methodSummary.setThisLocName(scGraph.getHNode(md.getThis()).getName());
1273 // set the 'global' reference location if needed
1274 if (methodSummary.hasGlobalAccess()) {
1275 methodSummary.setGlobalLocName(scGraph.getHNode(GLOBALDESC).getName());
1278 // construct a parameter mapping that maps a parameter descriptor to an
1279 // inferred composite location
1280 for (int paramIdx = 0; paramIdx < flowGraph.getNumParameters(); paramIdx++) {
1281 FlowNode flowNode = flowGraph.getParamFlowNode(paramIdx);
1282 CompositeLocation inferredCompLoc = flowNode.getCompositeLocation();
1283 // NTuple<Descriptor> descTuple = flowNode.getDescTuple();
1285 // CompositeLocation assignedCompLoc = flowNode.getCompositeLocation();
1286 // CompositeLocation inferredCompLoc;
1287 // if (assignedCompLoc != null) {
1288 // inferredCompLoc = translateCompositeLocation(assignedCompLoc);
1290 // Descriptor locDesc = descTuple.get(0);
1291 // Location loc = new Location(md, locDesc.getSymbol());
1292 // loc.setLocDescriptor(locDesc);
1293 // inferredCompLoc = new CompositeLocation(loc);
1295 System.out.println("-paramIdx=" + paramIdx + " infer=" + inferredCompLoc);
1296 System.out.println("-flowNode inferLoc=" + flowNode.getCompositeLocation());
1298 Descriptor localVarDesc = flowNode.getDescTuple().get(0);
1299 methodSummary.addMapVarNameToInferCompLoc(localVarDesc, inferredCompLoc);
1300 methodSummary.addMapParamIdxToInferLoc(paramIdx, inferredCompLoc);
1307 private boolean hasOrderingRelation(NTuple<Location> locTuple1, NTuple<Location> locTuple2) {
1309 int size = locTuple1.size() >= locTuple2.size() ? locTuple2.size() : locTuple1.size();
1311 for (int idx = 0; idx < size; idx++) {
1312 Location loc1 = locTuple1.get(idx);
1313 Location loc2 = locTuple2.get(idx);
1315 Descriptor desc1 = loc1.getDescriptor();
1316 Descriptor desc2 = loc2.getDescriptor();
1318 if (!desc1.equals(desc2)) {
1319 throw new Error("Fail to compare " + locTuple1 + " and " + locTuple2);
1322 Descriptor locDesc1 = loc1.getLocDescriptor();
1323 Descriptor locDesc2 = loc2.getLocDescriptor();
1325 HierarchyGraph hierarchyGraph = getHierarchyGraph(desc1);
1327 HNode node1 = hierarchyGraph.getHNode(locDesc1);
1328 HNode node2 = hierarchyGraph.getHNode(locDesc2);
1330 System.out.println("---node1=" + node1 + " node2=" + node2);
1331 System.out.println("---hierarchyGraph.getIncomingNodeSet(node2)="
1332 + hierarchyGraph.getIncomingNodeSet(node2));
1334 if (locDesc1.equals(locDesc2)) {
1336 } else if (!hierarchyGraph.getIncomingNodeSet(node2).contains(node1)
1337 && !hierarchyGraph.getIncomingNodeSet(node1).contains(node2)) {
1349 private boolean isHigherThan(NTuple<Location> locTuple1, NTuple<Location> locTuple2) {
1351 int size = locTuple1.size() >= locTuple2.size() ? locTuple2.size() : locTuple1.size();
1353 for (int idx = 0; idx < size; idx++) {
1354 Location loc1 = locTuple1.get(idx);
1355 Location loc2 = locTuple2.get(idx);
1357 Descriptor desc1 = loc1.getDescriptor();
1358 Descriptor desc2 = loc2.getDescriptor();
1360 if (!desc1.equals(desc2)) {
1361 throw new Error("Fail to compare " + locTuple1 + " and " + locTuple2);
1364 Descriptor locDesc1 = loc1.getLocDescriptor();
1365 Descriptor locDesc2 = loc2.getLocDescriptor();
1367 HierarchyGraph hierarchyGraph = getHierarchyGraph(desc1);
1369 HNode node1 = hierarchyGraph.getHNode(locDesc1);
1370 HNode node2 = hierarchyGraph.getHNode(locDesc2);
1372 System.out.println("---node1=" + node1 + " node2=" + node2);
1373 System.out.println("---hierarchyGraph.getIncomingNodeSet(node2)="
1374 + hierarchyGraph.getIncomingNodeSet(node2));
1376 if (locDesc1.equals(locDesc2)) {
1378 } else if (hierarchyGraph.getIncomingNodeSet(node2).contains(node1)) {
1389 private CompositeLocation translateCompositeLocation(CompositeLocation compLoc) {
1390 CompositeLocation newCompLoc = new CompositeLocation();
1392 // System.out.println("compLoc=" + compLoc);
1393 for (int i = 0; i < compLoc.getSize(); i++) {
1394 Location loc = compLoc.get(i);
1395 Descriptor enclosingDescriptor = loc.getDescriptor();
1396 Descriptor locDescriptor = loc.getLocDescriptor();
1398 HNode hnode = getHierarchyGraph(enclosingDescriptor).getHNode(locDescriptor);
1399 // System.out.println("-hnode=" + hnode + " from=" + locDescriptor +
1400 // " enclosingDescriptor="
1401 // + enclosingDescriptor);
1402 // System.out.println("-getLocationSummary(enclosingDescriptor)="
1403 // + getLocationSummary(enclosingDescriptor));
1404 String locName = getLocationSummary(enclosingDescriptor).getLocationName(hnode.getName());
1405 // System.out.println("-locName=" + locName);
1406 Location newLoc = new Location(enclosingDescriptor, locName);
1407 newLoc.setLocDescriptor(locDescriptor);
1408 newCompLoc.addLocation(newLoc);
1414 private void debug_writeLattices() {
1416 Set<Descriptor> keySet = mapDescriptorToSimpleLattice.keySet();
1417 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
1418 Descriptor key = (Descriptor) iterator.next();
1419 SSJavaLattice<String> simpleLattice = mapDescriptorToSimpleLattice.get(key);
1420 // HierarchyGraph simpleHierarchyGraph = getSimpleHierarchyGraph(key);
1421 HierarchyGraph scHierarchyGraph = getSkeletonCombinationHierarchyGraph(key);
1422 if (key instanceof ClassDescriptor) {
1423 writeInferredLatticeDotFile((ClassDescriptor) key, scHierarchyGraph, simpleLattice,
1425 } else if (key instanceof MethodDescriptor) {
1426 MethodDescriptor md = (MethodDescriptor) key;
1427 writeInferredLatticeDotFile(md.getClassDesc(), md, scHierarchyGraph, simpleLattice,
1431 LocationSummary ls = getLocationSummary(key);
1432 System.out.println("####LOC SUMMARY=" + key + "\n" + ls.getMapHNodeNameToLocationName());
1435 Set<ClassDescriptor> cdKeySet = cd2lattice.keySet();
1436 for (Iterator iterator = cdKeySet.iterator(); iterator.hasNext();) {
1437 ClassDescriptor cd = (ClassDescriptor) iterator.next();
1438 writeInferredLatticeDotFile((ClassDescriptor) cd, getSkeletonCombinationHierarchyGraph(cd),
1439 cd2lattice.get(cd), "");
1442 Set<MethodDescriptor> mdKeySet = md2lattice.keySet();
1443 for (Iterator iterator = mdKeySet.iterator(); iterator.hasNext();) {
1444 MethodDescriptor md = (MethodDescriptor) iterator.next();
1445 writeInferredLatticeDotFile(md.getClassDesc(), md, getSkeletonCombinationHierarchyGraph(md),
1446 md2lattice.get(md), "");
1451 private void buildLattice() {
1453 BuildLattice buildLattice = new BuildLattice(this);
1455 Set<Descriptor> keySet = mapDescriptorToCombineSkeletonHierarchyGraph.keySet();
1456 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
1457 Descriptor desc = (Descriptor) iterator.next();
1459 SSJavaLattice<String> simpleLattice = buildLattice.buildLattice(desc);
1461 addMapDescToSimpleLattice(desc, simpleLattice);
1463 HierarchyGraph simpleHierarchyGraph = getSimpleHierarchyGraph(desc);
1464 System.out.println("\n## insertIntermediateNodesToStraightLine:"
1465 + simpleHierarchyGraph.getName());
1466 SSJavaLattice<String> lattice =
1467 buildLattice.insertIntermediateNodesToStraightLine(desc, simpleLattice);
1468 lattice.removeRedundantEdges();
1470 if (desc instanceof ClassDescriptor) {
1472 cd2lattice.put((ClassDescriptor) desc, lattice);
1473 // ssjava.writeLatticeDotFile((ClassDescriptor) desc, null, lattice);
1474 } else if (desc instanceof MethodDescriptor) {
1476 md2lattice.put((MethodDescriptor) desc, lattice);
1477 MethodDescriptor md = (MethodDescriptor) desc;
1478 ClassDescriptor cd = md.getClassDesc();
1479 // ssjava.writeLatticeDotFile(cd, md, lattice);
1482 // System.out.println("\nSSJAVA: Insering Combination Nodes:" + desc);
1483 // HierarchyGraph skeletonGraph = getSkeletonHierarchyGraph(desc);
1484 // HierarchyGraph skeletonGraphWithCombinationNode =
1485 // skeletonGraph.clone();
1486 // skeletonGraphWithCombinationNode.setName(desc + "_SC");
1488 // HierarchyGraph simpleHierarchyGraph = getSimpleHierarchyGraph(desc);
1489 // System.out.println("Identifying Combination Nodes:");
1490 // skeletonGraphWithCombinationNode.insertCombinationNodesToGraph(simpleHierarchyGraph);
1491 // skeletonGraphWithCombinationNode.simplifySkeletonCombinationHierarchyGraph();
1492 // mapDescriptorToCombineSkeletonHierarchyGraph.put(desc,
1493 // skeletonGraphWithCombinationNode);
1498 public void addMapDescToSimpleLattice(Descriptor desc, SSJavaLattice<String> lattice) {
1499 mapDescriptorToSimpleLattice.put(desc, lattice);
1502 public SSJavaLattice<String> getSimpleLattice(Descriptor desc) {
1503 return mapDescriptorToSimpleLattice.get(desc);
1506 private void simplifyHierarchyGraph() {
1507 Set<Descriptor> keySet = mapDescriptorToHierarchyGraph.keySet();
1508 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
1509 Descriptor desc = (Descriptor) iterator.next();
1510 HierarchyGraph simpleHierarchyGraph = getHierarchyGraph(desc).clone();
1511 simpleHierarchyGraph.setName(desc + "_SIMPLE");
1512 simpleHierarchyGraph.removeRedundantEdges();
1513 // simpleHierarchyGraph.simplifyHierarchyGraph();
1514 mapDescriptorToSimpleHierarchyGraph.put(desc, simpleHierarchyGraph);
1518 private void insertCombinationNodes() {
1519 Set<Descriptor> keySet = mapDescriptorToSkeletonHierarchyGraph.keySet();
1520 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
1521 Descriptor desc = (Descriptor) iterator.next();
1522 System.out.println("\nSSJAVA: Insering Combination Nodes:" + desc);
1523 HierarchyGraph skeletonGraph = getSkeletonHierarchyGraph(desc);
1524 HierarchyGraph skeletonGraphWithCombinationNode = skeletonGraph.clone();
1525 skeletonGraphWithCombinationNode.setName(desc + "_SC");
1527 HierarchyGraph simpleHierarchyGraph = getSimpleHierarchyGraph(desc);
1528 System.out.println("Identifying Combination Nodes:");
1529 skeletonGraphWithCombinationNode.insertCombinationNodesToGraph(simpleHierarchyGraph);
1530 skeletonGraphWithCombinationNode.simplifySkeletonCombinationHierarchyGraph();
1531 mapDescriptorToCombineSkeletonHierarchyGraph.put(desc, skeletonGraphWithCombinationNode);
1535 private void constructSkeletonHierarchyGraph() {
1536 Set<Descriptor> keySet = mapDescriptorToHierarchyGraph.keySet();
1537 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
1538 Descriptor desc = (Descriptor) iterator.next();
1539 HierarchyGraph simpleGraph = getSimpleHierarchyGraph(desc);
1540 HierarchyGraph skeletonGraph = simpleGraph.generateSkeletonGraph();
1541 skeletonGraph.setMapDescToHNode(simpleGraph.getMapDescToHNode());
1542 skeletonGraph.setMapHNodeToDescSet(simpleGraph.getMapHNodeToDescSet());
1543 skeletonGraph.simplifyHierarchyGraph();
1544 // skeletonGraph.combineRedundantNodes(false);
1545 // skeletonGraph.removeRedundantEdges();
1546 mapDescriptorToSkeletonHierarchyGraph.put(desc, skeletonGraph);
1550 private void debug_writeHierarchyDotFiles() {
1552 Set<Descriptor> keySet = mapDescriptorToHierarchyGraph.keySet();
1553 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
1554 Descriptor desc = (Descriptor) iterator.next();
1555 getHierarchyGraph(desc).writeGraph();
1560 private void debug_writeSimpleHierarchyDotFiles() {
1562 Set<Descriptor> keySet = mapDescriptorToHierarchyGraph.keySet();
1563 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
1564 Descriptor desc = (Descriptor) iterator.next();
1565 getHierarchyGraph(desc).writeGraph();
1566 getSimpleHierarchyGraph(desc).writeGraph();
1571 private void debug_writeSkeletonHierarchyDotFiles() {
1573 Set<Descriptor> keySet = mapDescriptorToHierarchyGraph.keySet();
1574 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
1575 Descriptor desc = (Descriptor) iterator.next();
1576 getSkeletonHierarchyGraph(desc).writeGraph();
1581 private void debug_writeSkeletonCombinationHierarchyDotFiles() {
1583 Set<Descriptor> keySet = mapDescriptorToHierarchyGraph.keySet();
1584 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
1585 Descriptor desc = (Descriptor) iterator.next();
1586 getSkeletonCombinationHierarchyGraph(desc).writeGraph();
1591 public HierarchyGraph getSimpleHierarchyGraph(Descriptor d) {
1592 return mapDescriptorToSimpleHierarchyGraph.get(d);
1595 private HierarchyGraph getSkeletonHierarchyGraph(Descriptor d) {
1596 if (!mapDescriptorToSkeletonHierarchyGraph.containsKey(d)) {
1597 mapDescriptorToSkeletonHierarchyGraph.put(d, new HierarchyGraph(d));
1599 return mapDescriptorToSkeletonHierarchyGraph.get(d);
1602 public HierarchyGraph getSkeletonCombinationHierarchyGraph(Descriptor d) {
1603 if (!mapDescriptorToCombineSkeletonHierarchyGraph.containsKey(d)) {
1604 mapDescriptorToCombineSkeletonHierarchyGraph.put(d, new HierarchyGraph(d));
1606 return mapDescriptorToCombineSkeletonHierarchyGraph.get(d);
1609 private void constructHierarchyGraph() {
1611 // do fixed-point analysis
1614 LinkedList<MethodDescriptor> descriptorListToAnalyze = ssjava.getSortedDescriptors();
1616 // Collections.sort(descriptorListToAnalyze, new
1617 // Comparator<MethodDescriptor>() {
1618 // public int compare(MethodDescriptor o1, MethodDescriptor o2) {
1619 // return o1.getSymbol().compareToIgnoreCase(o2.getSymbol());
1623 // current descriptors to visit in fixed-point interprocedural analysis,
1624 // prioritized by dependency in the call graph
1625 methodDescriptorsToVisitStack.clear();
1627 Set<MethodDescriptor> methodDescriptorToVistSet = new HashSet<MethodDescriptor>();
1628 methodDescriptorToVistSet.addAll(descriptorListToAnalyze);
1630 while (!descriptorListToAnalyze.isEmpty()) {
1631 MethodDescriptor md = descriptorListToAnalyze.removeFirst();
1632 methodDescriptorsToVisitStack.add(md);
1635 // analyze scheduled methods until there are no more to visit
1636 while (!methodDescriptorsToVisitStack.isEmpty()) {
1637 // start to analyze leaf node
1638 MethodDescriptor md = methodDescriptorsToVisitStack.pop();
1640 HierarchyGraph hierarchyGraph = new HierarchyGraph(md);
1641 // MethodSummary methodSummary = new MethodSummary(md);
1643 // MethodLocationInfo methodInfo = new MethodLocationInfo(md);
1644 // curMethodInfo = methodInfo;
1646 System.out.println();
1647 System.out.println("SSJAVA: Construcing the hierarchy graph from " + md);
1649 constructHierarchyGraph(md, hierarchyGraph);
1651 HierarchyGraph prevHierarchyGraph = getHierarchyGraph(md);
1652 // MethodSummary prevMethodSummary = getMethodSummary(md);
1654 if (!hierarchyGraph.equals(prevHierarchyGraph)) {
1656 mapDescriptorToHierarchyGraph.put(md, hierarchyGraph);
1657 // mapDescToLocationSummary.put(md, methodSummary);
1659 // results for callee changed, so enqueue dependents caller for
1661 Iterator<MethodDescriptor> depsItr = ssjava.getDependents(md).iterator();
1662 while (depsItr.hasNext()) {
1663 MethodDescriptor methodNext = depsItr.next();
1664 if (!methodDescriptorsToVisitStack.contains(methodNext)
1665 && methodDescriptorToVistSet.contains(methodNext)) {
1666 methodDescriptorsToVisitStack.add(methodNext);
1675 while (!toAnalyzeIsEmpty()) {
1676 ClassDescriptor cd = toAnalyzeNext();
1677 HierarchyGraph graph = getHierarchyGraph(cd);
1678 for (Iterator iter = cd.getFields(); iter.hasNext();) {
1679 FieldDescriptor fieldDesc = (FieldDescriptor) iter.next();
1680 if (!(fieldDesc.isStatic() && fieldDesc.isFinal())) {
1681 graph.getHNode(fieldDesc);
1688 private HierarchyGraph getHierarchyGraph(Descriptor d) {
1689 if (!mapDescriptorToHierarchyGraph.containsKey(d)) {
1690 mapDescriptorToHierarchyGraph.put(d, new HierarchyGraph(d));
1692 return mapDescriptorToHierarchyGraph.get(d);
1695 private void constructHierarchyGraph(MethodDescriptor md, HierarchyGraph methodGraph) {
1697 // visit each node of method flow graph
1698 FlowGraph fg = getFlowGraph(md);
1699 Set<FlowNode> nodeSet = fg.getNodeSet();
1701 Set<Descriptor> paramDescSet = fg.getMapParamDescToIdx().keySet();
1702 for (Iterator iterator = paramDescSet.iterator(); iterator.hasNext();) {
1703 Descriptor desc = (Descriptor) iterator.next();
1704 methodGraph.getHNode(desc).setSkeleton(true);
1707 // for the method lattice, we need to look at the first element of
1708 // NTuple<Descriptor>
1709 boolean hasGlobalAccess = false;
1710 for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
1711 FlowNode srcNode = (FlowNode) iterator.next();
1713 // if the srcNode is started with the global descriptor
1714 // need to set as a skeleton node
1715 if (!hasGlobalAccess && srcNode.getDescTuple().startsWith(GLOBALDESC)) {
1716 hasGlobalAccess = true;
1719 Set<FlowEdge> outEdgeSet = fg.getOutEdgeSet(srcNode);
1720 for (Iterator iterator2 = outEdgeSet.iterator(); iterator2.hasNext();) {
1721 FlowEdge outEdge = (FlowEdge) iterator2.next();
1722 FlowNode dstNode = outEdge.getDst();
1724 NTuple<Descriptor> srcNodeTuple = srcNode.getDescTuple();
1725 NTuple<Descriptor> dstNodeTuple = dstNode.getDescTuple();
1727 if (outEdge.getInitTuple().equals(srcNodeTuple)
1728 && outEdge.getEndTuple().equals(dstNodeTuple)) {
1730 NTuple<Descriptor> srcCurTuple = srcNode.getCurrentDescTuple();
1731 NTuple<Descriptor> dstCurTuple = dstNode.getCurrentDescTuple();
1733 if ((srcCurTuple.size() > 1 && dstCurTuple.size() > 1)
1734 && srcCurTuple.get(0).equals(dstCurTuple.get(0))) {
1736 // value flows between fields
1737 Descriptor desc = srcCurTuple.get(0);
1738 ClassDescriptor classDesc;
1740 if (desc.equals(GLOBALDESC)) {
1741 classDesc = md.getClassDesc();
1743 VarDescriptor varDesc = (VarDescriptor) srcCurTuple.get(0);
1744 classDesc = varDesc.getType().getClassDesc();
1746 extractFlowsBetweenFields(classDesc, srcNode, dstNode, 1);
1749 // value flow between local var - local var or local var - field
1751 Descriptor srcDesc = srcCurTuple.get(0);
1752 Descriptor dstDesc = dstCurTuple.get(0);
1754 methodGraph.addEdge(srcDesc, dstDesc);
1756 if (fg.isParamDesc(srcDesc)) {
1757 methodGraph.setParamHNode(srcDesc);
1759 if (fg.isParamDesc(dstDesc)) {
1760 methodGraph.setParamHNode(dstDesc);
1769 // If the method accesses static fields
1770 // set hasGloabalAccess true in the method summary.
1771 if (hasGlobalAccess) {
1772 getMethodSummary(md).setHasGlobalAccess();
1774 methodGraph.getHNode(GLOBALDESC).setSkeleton(true);
1778 private MethodSummary getMethodSummary(MethodDescriptor md) {
1779 if (!mapDescToLocationSummary.containsKey(md)) {
1780 mapDescToLocationSummary.put(md, new MethodSummary(md));
1782 return (MethodSummary) mapDescToLocationSummary.get(md);
1785 private void addMapClassDefinitionToLineNum(ClassDescriptor cd, String strLine, int lineNum) {
1787 String classSymbol = cd.getSymbol();
1788 int idx = classSymbol.lastIndexOf("$");
1790 classSymbol = classSymbol.substring(idx + 1);
1793 String pattern = "class " + classSymbol + " ";
1794 if (strLine.indexOf(pattern) != -1) {
1795 mapDescToDefinitionLine.put(cd, lineNum);
1799 private void addMapMethodDefinitionToLineNum(Set<MethodDescriptor> methodSet, String strLine,
1801 for (Iterator iterator = methodSet.iterator(); iterator.hasNext();) {
1802 MethodDescriptor md = (MethodDescriptor) iterator.next();
1803 String pattern = md.getMethodDeclaration();
1804 if (strLine.indexOf(pattern) != -1) {
1805 mapDescToDefinitionLine.put(md, lineNum);
1806 methodSet.remove(md);
1813 private void readOriginalSourceFiles() {
1815 SymbolTable classtable = state.getClassSymbolTable();
1817 Set<ClassDescriptor> classDescSet = new HashSet<ClassDescriptor>();
1818 classDescSet.addAll(classtable.getValueSet());
1821 // inefficient implement. it may re-visit the same file if the file
1822 // contains more than one class definitions.
1823 for (Iterator iterator = classDescSet.iterator(); iterator.hasNext();) {
1824 ClassDescriptor cd = (ClassDescriptor) iterator.next();
1826 Set<MethodDescriptor> methodSet = new HashSet<MethodDescriptor>();
1827 methodSet.addAll(cd.getMethodTable().getValueSet());
1829 String sourceFileName = cd.getSourceFileName();
1830 Vector<String> lineVec = new Vector<String>();
1832 mapFileNameToLineVector.put(sourceFileName, lineVec);
1834 BufferedReader in = new BufferedReader(new FileReader(sourceFileName));
1837 lineVec.add(""); // the index is started from 1.
1838 while ((strLine = in.readLine()) != null) {
1839 lineVec.add(lineNum, strLine);
1840 addMapClassDefinitionToLineNum(cd, strLine, lineNum);
1841 addMapMethodDefinitionToLineNum(methodSet, strLine, lineNum);
1847 } catch (IOException e) {
1848 e.printStackTrace();
1853 private String generateLatticeDefinition(Descriptor desc) {
1855 Set<String> sharedLocSet = new HashSet<String>();
1857 SSJavaLattice<String> lattice = getLattice(desc);
1858 String rtr = "@LATTICE(\"";
1860 Map<String, Set<String>> map = lattice.getTable();
1861 Set<String> keySet = map.keySet();
1862 boolean first = true;
1863 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
1864 String key = (String) iterator.next();
1865 if (!key.equals(lattice.getTopItem())) {
1866 Set<String> connectedSet = map.get(key);
1868 if (connectedSet.size() == 1) {
1869 if (connectedSet.iterator().next().equals(lattice.getBottomItem())) {
1877 if (lattice.isSharedLoc(key)) {
1878 rtr += "," + key + "*";
1883 for (Iterator iterator2 = connectedSet.iterator(); iterator2.hasNext();) {
1884 String loc = (String) iterator2.next();
1885 if (!loc.equals(lattice.getBottomItem())) {
1892 rtr += loc + "<" + key;
1893 if (lattice.isSharedLoc(key) && (!sharedLocSet.contains(key))) {
1894 rtr += "," + key + "*";
1895 sharedLocSet.add(key);
1897 if (lattice.isSharedLoc(loc) && (!sharedLocSet.contains(loc))) {
1898 rtr += "," + loc + "*";
1899 sharedLocSet.add(loc);
1909 if (desc instanceof MethodDescriptor) {
1910 System.out.println("#EXTRA LOC DECLARATION GEN=" + desc);
1912 MethodSummary methodSummary = getMethodSummary((MethodDescriptor) desc);
1914 if (!ssjava.getMethodContainingSSJavaLoop().equals(desc)) {
1915 TypeDescriptor returnType = ((MethodDescriptor) desc).getReturnType();
1916 if (returnType != null && (!returnType.isVoid())) {
1918 "\n@RETURNLOC(\"" + generateLocationAnnoatation(methodSummary.getRETURNLoc()) + "\")";
1920 CompositeLocation pcLoc = methodSummary.getPCLoc();
1921 if ((pcLoc != null) && (!pcLoc.get(0).isTop())) {
1922 rtr += "\n@PCLOC(\"" + generateLocationAnnoatation(pcLoc) + "\")";
1926 rtr += "\n@THISLOC(\"" + methodSummary.getThisLocName() + "\")";
1927 rtr += "\n@GLOBALLOC(\"" + methodSummary.getGlobalLocName() + "\")";
1934 private void generateAnnoatedCode() {
1936 readOriginalSourceFiles();
1939 while (!toAnalyzeIsEmpty()) {
1940 ClassDescriptor cd = toAnalyzeNext();
1942 setupToAnalazeMethod(cd);
1944 String sourceFileName = cd.getSourceFileName();
1946 if (cd.isInterface()) {
1950 int classDefLine = mapDescToDefinitionLine.get(cd);
1951 Vector<String> sourceVec = mapFileNameToLineVector.get(sourceFileName);
1953 LocationSummary fieldLocSummary = getLocationSummary(cd);
1955 String fieldLatticeDefStr = generateLatticeDefinition(cd);
1956 String annoatedSrc = fieldLatticeDefStr + newline + sourceVec.get(classDefLine);
1957 sourceVec.set(classDefLine, annoatedSrc);
1959 // generate annotations for field declarations
1960 // Map<Descriptor, CompositeLocation> inferLocMap = fieldLocInfo.getMapDescToInferLocation();
1961 Map<String, String> mapFieldNameToLocName = fieldLocSummary.getMapHNodeNameToLocationName();
1963 for (Iterator iter = cd.getFields(); iter.hasNext();) {
1964 FieldDescriptor fd = (FieldDescriptor) iter.next();
1966 String locAnnotationStr;
1967 // CompositeLocation inferLoc = inferLocMap.get(fd);
1968 String locName = mapFieldNameToLocName.get(fd.getSymbol());
1970 if (locName != null) {
1971 // infer loc is null if the corresponding field is static and final
1972 // locAnnotationStr = "@LOC(\"" + generateLocationAnnoatation(inferLoc) + "\")";
1973 locAnnotationStr = "@LOC(\"" + locName + "\")";
1974 int fdLineNum = fd.getLineNum();
1975 String orgFieldDeclarationStr = sourceVec.get(fdLineNum);
1976 String fieldDeclaration = fd.toString();
1977 fieldDeclaration = fieldDeclaration.substring(0, fieldDeclaration.length() - 1);
1978 String annoatedStr = locAnnotationStr + " " + orgFieldDeclarationStr;
1979 sourceVec.set(fdLineNum, annoatedStr);
1984 while (!toAnalyzeMethodIsEmpty()) {
1985 MethodDescriptor md = toAnalyzeMethodNext();
1987 if (!ssjava.needTobeAnnotated(md)) {
1991 SSJavaLattice<String> methodLattice = md2lattice.get(md);
1992 if (methodLattice != null) {
1994 int methodDefLine = md.getLineNum();
1996 // MethodLocationInfo methodLocInfo = getMethodLocationInfo(md);
1997 // Map<Descriptor, CompositeLocation> methodInferLocMap =
1998 // methodLocInfo.getMapDescToInferLocation();
2000 MethodSummary methodSummary = getMethodSummary(md);
2002 Map<Descriptor, CompositeLocation> mapVarDescToInferLoc =
2003 methodSummary.getMapVarDescToInferCompositeLocation();
2004 System.out.println("-----md=" + md);
2005 System.out.println("-----mapVarDescToInferLoc=" + mapVarDescToInferLoc);
2007 Set<Descriptor> localVarDescSet = mapVarDescToInferLoc.keySet();
2009 Set<String> localLocElementSet = methodLattice.getElementSet();
2011 for (Iterator iterator = localVarDescSet.iterator(); iterator.hasNext();) {
2012 Descriptor localVarDesc = (Descriptor) iterator.next();
2013 System.out.println("-------localVarDesc=" + localVarDesc);
2014 CompositeLocation inferLoc = mapVarDescToInferLoc.get(localVarDesc);
2016 String localLocIdentifier = inferLoc.get(0).getLocIdentifier();
2017 if (!localLocElementSet.contains(localLocIdentifier)) {
2018 methodLattice.put(localLocIdentifier);
2021 String locAnnotationStr = "@LOC(\"" + generateLocationAnnoatation(inferLoc) + "\")";
2023 if (!isParameter(md, localVarDesc)) {
2024 if (mapDescToDefinitionLine.containsKey(localVarDesc)) {
2025 int varLineNum = mapDescToDefinitionLine.get(localVarDesc);
2026 String orgSourceLine = sourceVec.get(varLineNum);
2028 orgSourceLine.indexOf(generateVarDeclaration((VarDescriptor) localVarDesc));
2030 String annoatedStr =
2031 orgSourceLine.substring(0, idx) + locAnnotationStr + " "
2032 + orgSourceLine.substring(idx);
2033 sourceVec.set(varLineNum, annoatedStr);
2036 String methodDefStr = sourceVec.get(methodDefLine);
2039 getParamLocation(methodDefStr,
2040 generateVarDeclaration((VarDescriptor) localVarDesc));
2044 String annoatedStr =
2045 methodDefStr.substring(0, idx) + locAnnotationStr + " "
2046 + methodDefStr.substring(idx);
2047 sourceVec.set(methodDefLine, annoatedStr);
2052 // check if the lattice has to have the location type for the this
2055 // boolean needToAddthisRef = hasThisReference(md);
2056 // if (localLocElementSet.contains("this")) {
2057 // methodLattice.put("this");
2060 String methodLatticeDefStr = generateLatticeDefinition(md);
2061 String annoatedStr = methodLatticeDefStr + newline + sourceVec.get(methodDefLine);
2062 sourceVec.set(methodDefLine, annoatedStr);
2072 private boolean hasThisReference(MethodDescriptor md) {
2074 FlowGraph fg = getFlowGraph(md);
2075 Set<FlowNode> nodeSet = fg.getNodeSet();
2076 for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
2077 FlowNode flowNode = (FlowNode) iterator.next();
2078 if (flowNode.getDescTuple().get(0).equals(md.getThis())) {
2086 private int getParamLocation(String methodStr, String paramStr) {
2088 String pattern = paramStr + ",";
2090 int idx = methodStr.indexOf(pattern);
2094 pattern = paramStr + ")";
2095 return methodStr.indexOf(pattern);
2100 private String generateVarDeclaration(VarDescriptor varDesc) {
2102 TypeDescriptor td = varDesc.getType();
2103 String rtr = td.toString();
2105 for (int i = 0; i < td.getArrayCount(); i++) {
2109 rtr += " " + varDesc.getName();
2114 private String generateLocationAnnoatation(CompositeLocation loc) {
2115 System.out.println("loc=" + loc);
2118 Location methodLoc = loc.get(0);
2119 rtr += methodLoc.getLocIdentifier();
2121 for (int i = 1; i < loc.getSize(); i++) {
2122 Location element = loc.get(i);
2123 rtr += "," + element.getDescriptor().getSymbol() + "." + element.getLocIdentifier();
2129 private boolean isParameter(MethodDescriptor md, Descriptor localVarDesc) {
2130 return getFlowGraph(md).isParamDesc(localVarDesc);
2133 private String extractFileName(String fileName) {
2134 int idx = fileName.lastIndexOf("/");
2138 return fileName.substring(idx + 1);
2143 private void codeGen() {
2145 Set<String> originalFileNameSet = mapFileNameToLineVector.keySet();
2146 for (Iterator iterator = originalFileNameSet.iterator(); iterator.hasNext();) {
2147 String orgFileName = (String) iterator.next();
2148 String outputFileName = extractFileName(orgFileName);
2150 Vector<String> sourceVec = mapFileNameToLineVector.get(orgFileName);
2154 FileWriter fileWriter = new FileWriter("./infer/" + outputFileName);
2155 BufferedWriter out = new BufferedWriter(fileWriter);
2157 for (int i = 0; i < sourceVec.size(); i++) {
2158 out.write(sourceVec.get(i));
2162 } catch (IOException e) {
2163 e.printStackTrace();
2170 private void checkLattices() {
2172 LinkedList<MethodDescriptor> descriptorListToAnalyze = ssjava.getSortedDescriptors();
2174 // current descriptors to visit in fixed-point interprocedural analysis,
2176 // dependency in the call graph
2177 methodDescriptorsToVisitStack.clear();
2179 // descriptorListToAnalyze.removeFirst();
2181 Set<MethodDescriptor> methodDescriptorToVistSet = new HashSet<MethodDescriptor>();
2182 methodDescriptorToVistSet.addAll(descriptorListToAnalyze);
2184 while (!descriptorListToAnalyze.isEmpty()) {
2185 MethodDescriptor md = descriptorListToAnalyze.removeFirst();
2186 checkLatticesOfVirtualMethods(md);
2191 private void debug_writeLatticeDotFile() {
2192 // generate lattice dot file
2196 while (!toAnalyzeIsEmpty()) {
2197 ClassDescriptor cd = toAnalyzeNext();
2199 setupToAnalazeMethod(cd);
2201 SSJavaLattice<String> classLattice = cd2lattice.get(cd);
2202 if (classLattice != null) {
2203 ssjava.writeLatticeDotFile(cd, null, classLattice);
2204 debug_printDescriptorToLocNameMapping(cd);
2207 while (!toAnalyzeMethodIsEmpty()) {
2208 MethodDescriptor md = toAnalyzeMethodNext();
2209 SSJavaLattice<String> methodLattice = md2lattice.get(md);
2210 if (methodLattice != null) {
2211 ssjava.writeLatticeDotFile(cd, md, methodLattice);
2212 debug_printDescriptorToLocNameMapping(md);
2219 private void debug_printDescriptorToLocNameMapping(Descriptor desc) {
2221 LocationInfo info = getLocationInfo(desc);
2222 System.out.println("## " + desc + " ##");
2223 System.out.println(info.getMapDescToInferLocation());
2224 LocationInfo locInfo = getLocationInfo(desc);
2225 System.out.println("mapping=" + locInfo.getMapLocSymbolToDescSet());
2226 System.out.println("###################");
2230 private void inferLattices() {
2233 private void calculateExtraLocations() {
2234 LinkedList<MethodDescriptor> descriptorListToAnalyze = ssjava.getSortedDescriptors();
2235 for (Iterator iterator = descriptorListToAnalyze.iterator(); iterator.hasNext();) {
2236 MethodDescriptor md = (MethodDescriptor) iterator.next();
2237 if (!ssjava.getMethodContainingSSJavaLoop().equals(md)) {
2238 calculateExtraLocations(md);
2243 private void checkLatticesOfVirtualMethods(MethodDescriptor md) {
2245 if (!md.isStatic()) {
2246 Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
2247 setPossibleCallees.addAll(ssjava.getCallGraph().getMethods(md));
2249 for (Iterator iterator = setPossibleCallees.iterator(); iterator.hasNext();) {
2250 MethodDescriptor mdCallee = (MethodDescriptor) iterator.next();
2251 if (!md.equals(mdCallee)) {
2252 checkConsistency(md, mdCallee);
2260 private void checkConsistency(MethodDescriptor md1, MethodDescriptor md2) {
2262 // check that two lattice have the same relations between parameters(+PC
2263 // LOC, GLOBAL_LOC RETURN LOC)
2265 List<CompositeLocation> list1 = new ArrayList<CompositeLocation>();
2266 List<CompositeLocation> list2 = new ArrayList<CompositeLocation>();
2268 MethodLocationInfo locInfo1 = getMethodLocationInfo(md1);
2269 MethodLocationInfo locInfo2 = getMethodLocationInfo(md2);
2271 Map<Integer, CompositeLocation> paramMap1 = locInfo1.getMapParamIdxToInferLoc();
2272 Map<Integer, CompositeLocation> paramMap2 = locInfo2.getMapParamIdxToInferLoc();
2274 int numParam = locInfo1.getMapParamIdxToInferLoc().keySet().size();
2276 // add location types of paramters
2277 for (int idx = 0; idx < numParam; idx++) {
2278 list1.add(paramMap1.get(Integer.valueOf(idx)));
2279 list2.add(paramMap2.get(Integer.valueOf(idx)));
2282 // add program counter location
2283 list1.add(locInfo1.getPCLoc());
2284 list2.add(locInfo2.getPCLoc());
2286 if (!md1.getReturnType().isVoid()) {
2287 // add return value location
2288 CompositeLocation rtrLoc1 = getMethodLocationInfo(md1).getReturnLoc();
2289 CompositeLocation rtrLoc2 = getMethodLocationInfo(md2).getReturnLoc();
2294 // add global location type
2295 if (md1.isStatic()) {
2296 CompositeLocation globalLoc1 =
2297 new CompositeLocation(new Location(md1, locInfo1.getGlobalLocName()));
2298 CompositeLocation globalLoc2 =
2299 new CompositeLocation(new Location(md2, locInfo2.getGlobalLocName()));
2300 list1.add(globalLoc1);
2301 list2.add(globalLoc2);
2304 for (int i = 0; i < list1.size(); i++) {
2305 CompositeLocation locA1 = list1.get(i);
2306 CompositeLocation locA2 = list2.get(i);
2307 for (int k = 0; k < list1.size(); k++) {
2309 CompositeLocation locB1 = list1.get(k);
2310 CompositeLocation locB2 = list2.get(k);
2311 boolean r1 = isGreaterThan(getLattice(md1), locA1, locB1);
2313 boolean r2 = isGreaterThan(getLattice(md1), locA2, locB2);
2316 throw new Error("The method " + md1 + " is not consistent with the method " + md2
2317 + ".:: They have a different ordering relation between locations (" + locA1 + ","
2318 + locB1 + ") and (" + locA2 + "," + locB2 + ").");
2326 private String getSymbol(int idx, FlowNode node) {
2327 Descriptor desc = node.getDescTuple().get(idx);
2328 return desc.getSymbol();
2331 private Descriptor getDescriptor(int idx, FlowNode node) {
2332 Descriptor desc = node.getDescTuple().get(idx);
2336 private void calculatePCLOC(MethodDescriptor md) {
2338 System.out.println("#calcualtePCLOC");
2339 MethodSummary methodSummary = getMethodSummary(md);
2340 FlowGraph fg = getFlowGraph(md);
2341 Map<Integer, CompositeLocation> mapParamToLoc = methodSummary.getMapParamIdxToInferLoc();
2343 // calculate the initial program counter location
2344 // PC location is higher than location types of parameters which has incoming flows.
2346 Set<NTuple<Location>> paramLocTupleHavingInFlowSet = new HashSet<NTuple<Location>>();
2347 Set<NTuple<Location>> paramLocTupleNOTHavingInFlowSet = new HashSet<NTuple<Location>>();
2349 int numParams = fg.getNumParameters();
2350 for (int i = 0; i < numParams; i++) {
2351 FlowNode paramFlowNode = fg.getParamFlowNode(i);
2352 Descriptor prefix = paramFlowNode.getDescTuple().get(0);
2353 NTuple<Descriptor> paramDescTuple = paramFlowNode.getCurrentDescTuple();
2354 NTuple<Location> paramLocTuple = translateToLocTuple(md, paramDescTuple);
2356 if (fg.getIncomingNodeSetByPrefix(prefix).size() > 0) {
2357 // parameter has in-value flows
2358 paramLocTupleHavingInFlowSet.add(paramLocTuple);
2360 paramLocTupleNOTHavingInFlowSet.add(paramLocTuple);
2365 if (paramLocTupleHavingInFlowSet.size() > 0
2366 && !coversAllParamters(md, fg, paramLocTupleHavingInFlowSet)) {
2368 // Here, generates a location in the method lattice that is higher than the
2369 // paramLocTupleHavingInFlowSet
2370 NTuple<Location> pcLocTuple =
2371 generateLocTupleRelativeTo(md, paramLocTupleHavingInFlowSet, PCLOC);
2373 int pcLocTupleIdx = pcLocTuple.size() - 1;
2374 Location pcLoc = pcLocTuple.get(pcLocTupleIdx);
2375 Descriptor pcDesc = pcLoc.getLocDescriptor();
2376 Descriptor enclosingDesc = pcLocTuple.get(pcLocTupleIdx).getDescriptor();
2378 HierarchyGraph hierarchyGraph = getHierarchyGraph(enclosingDesc);
2379 HNode pcNode = hierarchyGraph.getHNode(pcDesc);
2380 pcNode.setSkeleton(true);
2382 // add ordering relations s.t. PCLOC is higher than all of parameters with incoming flows
2383 // and lower than paramters which do not have any incoming flows
2384 for (Iterator iterator = paramLocTupleHavingInFlowSet.iterator(); iterator.hasNext();) {
2385 NTuple<Location> paramLocTuple = (NTuple<Location>) iterator.next();
2386 if (paramLocTuple.size() > pcLocTupleIdx) {
2387 Descriptor lowerDesc = paramLocTuple.get(pcLocTupleIdx).getLocDescriptor();
2388 hierarchyGraph.addEdge(pcDesc, lowerDesc);
2392 for (Iterator iterator = paramLocTupleNOTHavingInFlowSet.iterator(); iterator.hasNext();) {
2393 NTuple<Location> paramLocTuple = (NTuple<Location>) iterator.next();
2394 if (paramLocTuple.size() > pcLocTupleIdx) {
2395 Descriptor higherDesc = paramLocTuple.get(pcLocTupleIdx).getLocDescriptor();
2396 hierarchyGraph.addEdge(higherDesc, pcDesc);
2400 System.out.println("pcLoc=" + pcLoc);
2402 methodSummary.setPCLoc(new CompositeLocation(pcLocTuple));
2406 private boolean coversAllParamters(MethodDescriptor md, FlowGraph fg,
2407 Set<NTuple<Location>> paramLocTupleHavingInFlowSet) {
2409 int numParam = fg.getNumParameters();
2410 int size = paramLocTupleHavingInFlowSet.size();
2412 if (!md.isStatic()) {
2414 // if the method is not static && there is a parameter composite location &&
2415 // it is started with 'this',
2416 // paramLocTupleHavingInFlowSet need to have 'this' parameter.
2418 FlowNode thisParamNode = fg.getParamFlowNode(0);
2419 NTuple<Location> thisParamLocTuple =
2420 translateToLocTuple(md, thisParamNode.getCurrentDescTuple());
2422 if (!paramLocTupleHavingInFlowSet.contains(thisParamLocTuple)) {
2424 for (Iterator iterator = paramLocTupleHavingInFlowSet.iterator(); iterator.hasNext();) {
2425 NTuple<Location> paramTuple = (NTuple<Location>) iterator.next();
2426 if (paramTuple.size() > 1 && paramTuple.get(0).getLocDescriptor().equals(md.getThis())) {
2427 // paramLocTupleHavingInFlowSet.add(thisParamLocTuple);
2436 if (size == numParam) {
2444 private void calculateRETURNLOC(MethodDescriptor md) {
2446 System.out.println("#calculateRETURNLOC= " + md);
2447 // calculate a return location:
2448 // the return location type is lower than all parameters and the location of return values
2450 MethodSummary methodSummary = getMethodSummary(md);
2452 FlowGraph fg = getFlowGraph(md);
2454 Map<Integer, CompositeLocation> mapParamToLoc = methodSummary.getMapParamIdxToInferLoc();
2455 Set<Integer> paramIdxSet = mapParamToLoc.keySet();
2457 if (!md.getReturnType().isVoid()) {
2458 // first, generate the set of return value location types that starts
2459 // with 'this' reference
2461 Set<NTuple<Location>> inferFieldReturnLocSet = new HashSet<NTuple<Location>>();
2463 Set<FlowNode> paramFlowNodeFlowingToReturnValueSet = getParamNodeFlowingToReturnValue(md);
2464 System.out.println("paramFlowNodeFlowingToReturnValueSet="
2465 + paramFlowNodeFlowingToReturnValueSet);
2467 Set<NTuple<Location>> locFlowingToReturnValueSet = new HashSet<NTuple<Location>>();
2468 for (Iterator iterator = paramFlowNodeFlowingToReturnValueSet.iterator(); iterator.hasNext();) {
2469 FlowNode fn = (FlowNode) iterator.next();
2471 NTuple<Descriptor> paramDescTuple = fn.getCurrentDescTuple();
2472 NTuple<Location> paramLocTuple = translateToLocTuple(md, paramDescTuple);
2474 locFlowingToReturnValueSet.add(paramLocTuple);
2477 Set<FlowNode> returnNodeSet = fg.getReturnNodeSet();
2478 for (Iterator iterator = returnNodeSet.iterator(); iterator.hasNext();) {
2479 FlowNode returnNode = (FlowNode) iterator.next();
2480 NTuple<Descriptor> returnDescTuple = returnNode.getCurrentDescTuple();
2481 NTuple<Location> returnLocTuple = translateToLocTuple(md, returnDescTuple);
2482 locFlowingToReturnValueSet.add(returnLocTuple);
2484 System.out.println("locFlowingToReturnValueSet=" + locFlowingToReturnValueSet);
2486 // Here, generates a return location in the method lattice that is lower than the
2487 // locFlowingToReturnValueSet
2488 NTuple<Location> returnLocTuple =
2489 generateLocTupleRelativeTo(md, locFlowingToReturnValueSet, RLOC);
2491 System.out.println("returnLocTuple=" + returnLocTuple);
2493 int returnLocTupleIdx = returnLocTuple.size() - 1;
2494 Location returnLoc = returnLocTuple.get(returnLocTupleIdx);
2495 Descriptor returnDesc = returnLoc.getLocDescriptor();
2496 Descriptor enclosingDesc = returnLocTuple.get(returnLocTupleIdx).getDescriptor();
2498 HierarchyGraph hierarchyGraph = getHierarchyGraph(enclosingDesc);
2499 HNode returnNode = hierarchyGraph.getHNode(returnDesc);
2500 returnNode.setSkeleton(true);
2502 for (Iterator iterator = locFlowingToReturnValueSet.iterator(); iterator.hasNext();) {
2503 NTuple<Location> locTuple = (NTuple<Location>) iterator.next();
2504 Descriptor higherDesc = locTuple.get(returnLocTupleIdx).getLocDescriptor();
2505 hierarchyGraph.addEdge(higherDesc, returnDesc);
2508 methodSummary.setRETURNLoc(new CompositeLocation(returnLocTuple));
2510 // skip: for (Iterator iterator = returnNodeSet.iterator(); iterator.hasNext();) {
2511 // FlowNode returnNode = (FlowNode) iterator.next();
2513 // NTuple<Descriptor> returnDescTuple = returnNode.getCurrentDescTuple();
2514 // NTuple<Location> returnLocTuple = translateToLocTuple(md, returnDescTuple);
2516 // if (returnLocTuple.get(0).getLocDescriptor().equals(md.getThis())) {
2517 // // if the location type of the return value matches "this" reference
2518 // // then, check whether this return value is equal to/lower than all
2519 // // of parameters that possibly flow into the return values
2520 // for (Iterator iterator2 = inferParamLocSet.iterator(); iterator2.hasNext();) {
2521 // CompositeLocation paramInferLoc = (CompositeLocation) iterator2.next();
2523 // if ((!paramInferLoc.equals(returnLocTuple))
2524 // && !isGreaterThan(methodLattice, paramInferLoc, inferReturnLoc)) {
2528 // inferFieldReturnLocSet.add(returnLocTuple);
2533 // if (inferFieldReturnLocSet.size() > 0) {
2535 // // CompositeLocation returnLoc = getLowest(methodLattice, inferFieldReturnLocSet);
2536 // CompositeLocation returnLoc = null;
2537 // if (returnLoc == null) {
2538 // // in this case, assign <'this',bottom> to the RETURNLOC
2539 // returnLoc = new CompositeLocation(new Location(md, md.getThis().getSymbol()));
2540 // returnLoc.addLocation(new Location(md.getClassDesc(), getLattice(md.getClassDesc())
2541 // .getBottomItem()));
2543 // methodInfo.setReturnLoc(returnLoc);
2546 // String returnLocSymbol = "RETURNLOC";
2547 // CompositeLocation returnLocInferLoc =
2548 // new CompositeLocation(new Location(md, returnLocSymbol));
2549 // methodInfo.setReturnLoc(returnLocInferLoc);
2551 // for (Iterator iterator = paramIdxSet.iterator(); iterator.hasNext();) {
2552 // Integer paramIdx = (Integer) iterator.next();
2553 // CompositeLocation inferLoc = mapParamToLoc.get(paramIdx);
2554 // String paramLocLocalSymbol = inferLoc.get(0).getLocIdentifier();
2555 // if (!methodLattice.isGreaterThan(paramLocLocalSymbol, returnLocSymbol)) {
2557 // // addRelationHigherToLower(methodLattice, methodInfo,
2558 // // paramLocLocalSymbol,
2559 // // returnLocSymbol);
2563 // for (Iterator iterator = returnNodeSet.iterator(); iterator.hasNext();) {
2564 // FlowNode returnNode = (FlowNode) iterator.next();
2565 // CompositeLocation inferLoc =
2566 // generateInferredCompositeLocation(methodInfo, fg.getLocationTuple(returnNode));
2567 // if (!isGreaterThan(methodLattice, inferLoc, returnLocInferLoc)) {
2569 // // addRelation(methodLattice, methodInfo, inferLoc,
2570 // // returnLocInferLoc);
2579 private void calculateExtraLocations(MethodDescriptor md) {
2580 // calcualte pcloc, returnloc,...
2582 System.out.println("\nSSJAVA:Calculate PCLOC/RETURNLOC locations: " + md);
2585 calculateRETURNLOC(md);
2589 private NTuple<Location> generateLocTupleRelativeTo(MethodDescriptor md,
2590 Set<NTuple<Location>> paramLocTupleHavingInFlowSet, String locNamePrefix) {
2592 System.out.println("-generateLocTupleRelativeTo=" + paramLocTupleHavingInFlowSet);
2594 NTuple<Location> higherLocTuple = new NTuple<Location>();
2596 VarDescriptor thisVarDesc = md.getThis();
2597 // check if all paramter loc tuple is started with 'this' reference
2598 boolean hasParamNotStartedWithThisRef = false;
2602 Set<NTuple<Location>> paramLocTupleStartedWithThis = new HashSet<NTuple<Location>>();
2604 for (Iterator iterator = paramLocTupleHavingInFlowSet.iterator(); iterator.hasNext();) {
2605 NTuple<Location> paramLocTuple = (NTuple<Location>) iterator.next();
2606 if (!paramLocTuple.get(0).getLocDescriptor().equals(thisVarDesc)) {
2607 hasParamNotStartedWithThisRef = true;
2608 } else if (paramLocTuple.size() > 1) {
2609 paramLocTupleStartedWithThis.add(paramLocTuple);
2610 if (minSize == 0 || minSize > paramLocTuple.size()) {
2611 minSize = paramLocTuple.size();
2616 System.out.println("---paramLocTupleStartedWithThis=" + paramLocTupleStartedWithThis);
2617 Descriptor enclosingDesc = md;
2618 if (hasParamNotStartedWithThisRef) {
2619 // in this case, PCLOC will be the local location
2621 // all parameter is started with 'this', so PCLOC will be set relative to the composite
2622 // location started with 'this'.
2623 for (int idx = 0; idx < minSize - 1; idx++) {
2624 Set<Descriptor> locDescSet = new HashSet<Descriptor>();
2625 Location curLoc = null;
2626 NTuple<Location> paramLocTuple = null;
2627 for (Iterator iterator = paramLocTupleStartedWithThis.iterator(); iterator.hasNext();) {
2628 paramLocTuple = (NTuple<Location>) iterator.next();
2629 System.out.println("-----paramLocTuple=" + paramLocTuple + " idx=" + idx);
2630 curLoc = paramLocTuple.get(idx);
2631 Descriptor locDesc = curLoc.getLocDescriptor();
2632 locDescSet.add(locDesc);
2634 System.out.println("-----locDescSet=" + locDescSet + " idx=" + idx);
2635 if (locDescSet.size() != 1) {
2638 Location newLocElement = new Location(curLoc.getDescriptor(), curLoc.getLocDescriptor());
2639 higherLocTuple.add(newLocElement);
2640 enclosingDesc = getClassTypeDescriptor(curLoc.getLocDescriptor());
2645 String pcLocIdentifier = locNamePrefix + (locSeed++);
2646 NameDescriptor pcLocDesc = new NameDescriptor(pcLocIdentifier);
2647 Location newLoc = new Location(enclosingDesc, pcLocDesc);
2648 higherLocTuple.add(newLoc);
2650 System.out.println("---new loc tuple=" + higherLocTuple);
2652 return higherLocTuple;
2656 public ClassDescriptor getClassTypeDescriptor(Descriptor in) {
2658 if (in instanceof VarDescriptor) {
2659 return ((VarDescriptor) in).getType().getClassDesc();
2660 } else if (in instanceof FieldDescriptor) {
2661 return ((FieldDescriptor) in).getType().getClassDesc();
2663 // else if (in instanceof LocationDescriptor) {
2664 // // here is the case that the descriptor 'in' is the last element of the assigned composite
2666 // return ((VarDescriptor) locTuple.get(0).getLocDescriptor()).getType().getClassDesc();
2674 private Set<NTuple<Location>> calculateHighestLocTupleSet(
2675 Set<NTuple<Location>> paramLocTupleHavingInFlowSet) {
2677 Set<NTuple<Location>> highestSet = new HashSet<NTuple<Location>>();
2679 Iterator<NTuple<Location>> iterator = paramLocTupleHavingInFlowSet.iterator();
2680 NTuple<Location> highest = iterator.next();
2682 for (; iterator.hasNext();) {
2683 NTuple<Location> curLocTuple = (NTuple<Location>) iterator.next();
2684 if (isHigherThan(curLocTuple, highest)) {
2685 System.out.println(curLocTuple + " is greater than " + highest);
2686 highest = curLocTuple;
2690 highestSet.add(highest);
2692 MethodDescriptor md = (MethodDescriptor) highest.get(0).getDescriptor();
2693 VarDescriptor thisVarDesc = md.getThis();
2695 System.out.println("highest=" + highest);
2697 for (Iterator<NTuple<Location>> iter = paramLocTupleHavingInFlowSet.iterator(); iter.hasNext();) {
2698 NTuple<Location> curLocTuple = iter.next();
2700 if (!curLocTuple.equals(highest) && !hasOrderingRelation(highest, curLocTuple)) {
2702 System.out.println("add it to the highest set=" + curLocTuple);
2703 highestSet.add(curLocTuple);
2712 private void calculateExtraLocations2(MethodDescriptor md) {
2713 // calcualte pcloc, returnloc,...
2715 SSJavaLattice<String> methodLattice = getMethodLattice(md);
2716 MethodLocationInfo methodInfo = getMethodLocationInfo(md);
2717 FlowGraph fg = getFlowGraph(md);
2718 Set<FlowNode> nodeSet = fg.getNodeSet();
2720 for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
2721 FlowNode flowNode = (FlowNode) iterator.next();
2722 if (flowNode.isDeclaratonNode()) {
2723 CompositeLocation inferLoc = methodInfo.getInferLocation(flowNode.getDescTuple().get(0));
2724 String locIdentifier = inferLoc.get(0).getLocIdentifier();
2725 if (!methodLattice.containsKey(locIdentifier)) {
2726 methodLattice.put(locIdentifier);
2732 Map<Integer, CompositeLocation> mapParamToLoc = methodInfo.getMapParamIdxToInferLoc();
2733 Set<Integer> paramIdxSet = mapParamToLoc.keySet();
2735 if (!ssjava.getMethodContainingSSJavaLoop().equals(md)) {
2736 // calculate the initial program counter location
2737 // PC location is higher than location types of all parameters
2738 String pcLocSymbol = "PCLOC";
2740 Set<CompositeLocation> paramInFlowSet = new HashSet<CompositeLocation>();
2742 for (Iterator iterator = paramIdxSet.iterator(); iterator.hasNext();) {
2743 Integer paramIdx = (Integer) iterator.next();
2745 FlowNode paramFlowNode = fg.getParamFlowNode(paramIdx);
2747 if (fg.getIncomingFlowNodeSet(paramFlowNode).size() > 0) {
2748 // parameter has in-value flows
2749 CompositeLocation inferLoc = mapParamToLoc.get(paramIdx);
2750 paramInFlowSet.add(inferLoc);
2754 if (paramInFlowSet.size() > 0) {
2755 CompositeLocation lowestLoc = getLowest(methodLattice, paramInFlowSet);
2756 assert (lowestLoc != null);
2757 methodInfo.setPCLoc(lowestLoc);
2762 // calculate a return location
2763 // the return location type is lower than all parameters and location
2766 if (!md.getReturnType().isVoid()) {
2767 // first, generate the set of return value location types that starts
2771 Set<CompositeLocation> inferFieldReturnLocSet = new HashSet<CompositeLocation>();
2773 Set<FlowNode> paramFlowNode = getParamNodeFlowingToReturnValue(md);
2774 Set<CompositeLocation> inferParamLocSet = new HashSet<CompositeLocation>();
2775 if (paramFlowNode != null) {
2776 for (Iterator iterator = paramFlowNode.iterator(); iterator.hasNext();) {
2777 FlowNode fn = (FlowNode) iterator.next();
2778 CompositeLocation inferLoc =
2779 generateInferredCompositeLocation(methodInfo, getFlowGraph(md).getLocationTuple(fn));
2780 inferParamLocSet.add(inferLoc);
2784 Set<FlowNode> returnNodeSet = fg.getReturnNodeSet();
2786 skip: for (Iterator iterator = returnNodeSet.iterator(); iterator.hasNext();) {
2787 FlowNode returnNode = (FlowNode) iterator.next();
2788 CompositeLocation inferReturnLoc =
2789 generateInferredCompositeLocation(methodInfo, fg.getLocationTuple(returnNode));
2790 if (inferReturnLoc.get(0).getLocIdentifier().equals("this")) {
2791 // if the location type of the return value matches "this" reference
2792 // then, check whether this return value is equal to/lower than all
2794 // parameters that possibly flow into the return values
2795 for (Iterator iterator2 = inferParamLocSet.iterator(); iterator2.hasNext();) {
2796 CompositeLocation paramInferLoc = (CompositeLocation) iterator2.next();
2798 if ((!paramInferLoc.equals(inferReturnLoc))
2799 && !isGreaterThan(methodLattice, paramInferLoc, inferReturnLoc)) {
2803 inferFieldReturnLocSet.add(inferReturnLoc);
2808 if (inferFieldReturnLocSet.size() > 0) {
2810 CompositeLocation returnLoc = getLowest(methodLattice, inferFieldReturnLocSet);
2811 if (returnLoc == null) {
2812 // in this case, assign <'this',bottom> to the RETURNLOC
2813 returnLoc = new CompositeLocation(new Location(md, md.getThis().getSymbol()));
2814 returnLoc.addLocation(new Location(md.getClassDesc(), getLattice(md.getClassDesc())
2817 methodInfo.setReturnLoc(returnLoc);
2820 String returnLocSymbol = "RETURNLOC";
2821 CompositeLocation returnLocInferLoc =
2822 new CompositeLocation(new Location(md, returnLocSymbol));
2823 methodInfo.setReturnLoc(returnLocInferLoc);
2825 for (Iterator iterator = paramIdxSet.iterator(); iterator.hasNext();) {
2826 Integer paramIdx = (Integer) iterator.next();
2827 CompositeLocation inferLoc = mapParamToLoc.get(paramIdx);
2828 String paramLocLocalSymbol = inferLoc.get(0).getLocIdentifier();
2829 if (!methodLattice.isGreaterThan(paramLocLocalSymbol, returnLocSymbol)) {
2831 // addRelationHigherToLower(methodLattice, methodInfo,
2832 // paramLocLocalSymbol,
2833 // returnLocSymbol);
2837 for (Iterator iterator = returnNodeSet.iterator(); iterator.hasNext();) {
2838 FlowNode returnNode = (FlowNode) iterator.next();
2839 CompositeLocation inferLoc =
2840 generateInferredCompositeLocation(methodInfo, fg.getLocationTuple(returnNode));
2841 if (!isGreaterThan(methodLattice, inferLoc, returnLocInferLoc)) {
2843 // addRelation(methodLattice, methodInfo, inferLoc,
2844 // returnLocInferLoc);
2853 private Set<String> getHigherLocSymbolThan(SSJavaLattice<String> lattice, String loc) {
2854 Set<String> higherLocSet = new HashSet<String>();
2856 Set<String> locSet = lattice.getTable().keySet();
2857 for (Iterator iterator = locSet.iterator(); iterator.hasNext();) {
2858 String element = (String) iterator.next();
2859 if (lattice.isGreaterThan(element, loc) && (!element.equals(lattice.getTopItem()))) {
2860 higherLocSet.add(element);
2863 return higherLocSet;
2866 private CompositeLocation getLowest(SSJavaLattice<String> methodLattice,
2867 Set<CompositeLocation> set) {
2869 CompositeLocation lowest = set.iterator().next();
2871 if (set.size() == 1) {
2875 for (Iterator iterator = set.iterator(); iterator.hasNext();) {
2876 CompositeLocation loc = (CompositeLocation) iterator.next();
2878 if ((!loc.equals(lowest)) && (!isComparable(methodLattice, lowest, loc))) {
2879 // if there is a case where composite locations are incomparable, just
2884 if ((!loc.equals(lowest)) && isGreaterThan(methodLattice, lowest, loc)) {
2891 private boolean isComparable(SSJavaLattice<String> methodLattice, CompositeLocation comp1,
2892 CompositeLocation comp2) {
2894 int size = comp1.getSize() >= comp2.getSize() ? comp2.getSize() : comp1.getSize();
2896 for (int idx = 0; idx < size; idx++) {
2897 Location loc1 = comp1.get(idx);
2898 Location loc2 = comp2.get(idx);
2900 Descriptor desc1 = loc1.getDescriptor();
2901 Descriptor desc2 = loc2.getDescriptor();
2903 if (!desc1.equals(desc2)) {
2904 throw new Error("Fail to compare " + comp1 + " and " + comp2);
2907 String symbol1 = loc1.getLocIdentifier();
2908 String symbol2 = loc2.getLocIdentifier();
2910 SSJavaLattice<String> lattice;
2912 lattice = methodLattice;
2914 lattice = getLattice(desc1);
2917 if (symbol1.equals(symbol2)) {
2919 } else if (!lattice.isComparable(symbol1, symbol2)) {
2928 private boolean isGreaterThan(SSJavaLattice<String> methodLattice, CompositeLocation comp1,
2929 CompositeLocation comp2) {
2931 int size = comp1.getSize() >= comp2.getSize() ? comp2.getSize() : comp1.getSize();
2933 for (int idx = 0; idx < size; idx++) {
2934 Location loc1 = comp1.get(idx);
2935 Location loc2 = comp2.get(idx);
2937 Descriptor desc1 = loc1.getDescriptor();
2938 Descriptor desc2 = loc2.getDescriptor();
2940 if (!desc1.equals(desc2)) {
2941 throw new Error("Fail to compare " + comp1 + " and " + comp2);
2944 String symbol1 = loc1.getLocIdentifier();
2945 String symbol2 = loc2.getLocIdentifier();
2947 SSJavaLattice<String> lattice;
2949 lattice = methodLattice;
2951 lattice = getLattice(desc1);
2954 if (symbol1.equals(symbol2)) {
2956 } else if (lattice.isGreaterThan(symbol1, symbol2)) {
2967 private void contributeCalleeFlows(MethodInvokeNode min, MethodDescriptor mdCaller,
2968 MethodDescriptor mdCallee) {
2970 System.out.println("\n##contributeCalleeFlows callee=" + mdCallee + "TO caller=" + mdCaller);
2972 getSubGlobalFlowGraph(mdCallee);
2976 private GlobalFlowGraph getSubGlobalFlowGraph(MethodDescriptor md) {
2977 return mapMethodDescriptorToSubGlobalFlowGraph.get(md);
2980 private void propagateFlowsToCallerWithNoCompositeLocation(MethodInvokeNode min,
2981 MethodDescriptor mdCaller, MethodDescriptor mdCallee) {
2983 // if the parameter A reaches to the parameter B
2984 // then, add an edge the argument A -> the argument B to the caller's flow
2987 FlowGraph calleeFlowGraph = getFlowGraph(mdCallee);
2988 FlowGraph callerFlowGraph = getFlowGraph(mdCaller);
2989 int numParam = calleeFlowGraph.getNumParameters();
2991 for (int i = 0; i < numParam; i++) {
2992 for (int k = 0; k < numParam; k++) {
2996 FlowNode paramNode1 = calleeFlowGraph.getParamFlowNode(i);
2997 FlowNode paramNode2 = calleeFlowGraph.getParamFlowNode(k);
2999 NTuple<Descriptor> arg1Tuple = getNodeTupleByArgIdx(min, i);
3000 NTuple<Descriptor> arg2Tuple = getNodeTupleByArgIdx(min, k);
3002 // check if the callee propagates an ordering constraints through
3005 Set<FlowNode> localReachSet = calleeFlowGraph.getLocalReachFlowNodeSetFrom(paramNode1);
3006 // System.out.println("-param1=" + paramNode1 + " is higher than param2=" + paramNode2);
3007 // System.out.println("-- localReachSet from param1=" + localReachSet);
3009 if (arg1Tuple.size() > 0 && arg2Tuple.size() > 0 && localReachSet.contains(paramNode2)) {
3010 // need to propagate an ordering relation s.t. arg1 is higher
3014 // .println("-arg1Tuple=" + arg1Tuple + " is higher than arg2Tuple=" + arg2Tuple);
3016 // otherwise, flows between method/field locations...
3017 callerFlowGraph.addValueFlowEdge(arg1Tuple, arg2Tuple);
3018 // System.out.println("arg1=" + arg1Tuple + " arg2=" + arg2Tuple);
3022 System.out.println();
3026 // System.out.println("##\n");
3030 private void propagateFlowsToCaller(MethodInvokeNode min, MethodDescriptor mdCaller,
3031 MethodDescriptor mdCallee) {
3033 System.out.println("\n##PROPAGATE callee=" + mdCallee + "TO caller=" + mdCaller);
3035 // if the parameter A reaches to the parameter B
3036 // then, add an edge the argument A -> the argument B to the caller's flow
3040 // also if a parameter is a composite location and is started with "this"
3042 // need to make sure that the corresponding argument is higher than the
3043 // translated location of
3046 FlowGraph calleeFlowGraph = getFlowGraph(mdCallee);
3047 FlowGraph callerFlowGraph = getFlowGraph(mdCaller);
3048 int numParam = calleeFlowGraph.getNumParameters();
3050 for (int i = 0; i < numParam; i++) {
3051 for (int k = 0; k < numParam; k++) {
3055 FlowNode paramNode1 = calleeFlowGraph.getParamFlowNode(i);
3056 FlowNode paramNode2 = calleeFlowGraph.getParamFlowNode(k);
3058 System.out.println("param1=" + paramNode1 + " curDescTuple="
3059 + paramNode1.getCurrentDescTuple());
3060 System.out.println("param2=" + paramNode2 + " curDescTuple="
3061 + paramNode2.getCurrentDescTuple());
3063 // TODO: deprecated method
3064 // NodeTupleSet tupleSetArg1 = getNodeTupleSetByArgIdx(min, i);
3065 // NodeTupleSet tupleSetArg2 = getNodeTupleSetByArgIdx(min, k);
3066 NodeTupleSet tupleSetArg1 = null;
3067 NodeTupleSet tupleSetArg2 = null;
3069 for (Iterator<NTuple<Descriptor>> iter1 = tupleSetArg1.iterator(); iter1.hasNext();) {
3070 NTuple<Descriptor> arg1Tuple = iter1.next();
3072 for (Iterator<NTuple<Descriptor>> iter2 = tupleSetArg2.iterator(); iter2.hasNext();) {
3073 NTuple<Descriptor> arg2Tuple = iter2.next();
3075 // check if the callee propagates an ordering constraints through
3078 Set<FlowNode> localReachSet =
3079 calleeFlowGraph.getLocalReachFlowNodeSetFrom(paramNode1);
3081 if (localReachSet.contains(paramNode2)) {
3082 // need to propagate an ordering relation s.t. arg1 is higher
3086 .println("-param1=" + paramNode1 + " is higher than param2=" + paramNode2);
3087 System.out.println("-arg1Tuple=" + arg1Tuple + " is higher than arg2Tuple="
3090 if (!min.getMethod().isStatic()) {
3091 // check if this is the case that values flow to/from the
3092 // current object reference 'this'
3094 NTuple<Descriptor> baseTuple = mapMethodInvokeNodeToBaseTuple.get(min);
3095 Descriptor baseRef = baseTuple.get(baseTuple.size() - 1);
3097 System.out.println("paramNode1.getCurrentDescTuple()="
3098 + paramNode1.getCurrentDescTuple());
3099 // calculate the prefix of the argument
3101 if (arg2Tuple.size() == 1 && arg2Tuple.get(0).equals(baseRef)) {
3102 // in this case, the callee flow causes a caller flow to the
3103 // object whose method
3106 if (!paramNode1.getCurrentDescTuple().startsWith(mdCallee.getThis())) {
3107 // check whether ???
3109 NTuple<Descriptor> param1Prefix =
3110 calculatePrefixForParam(callerFlowGraph, calleeFlowGraph, min, arg1Tuple,
3113 if (param1Prefix != null && param1Prefix.startsWith(mdCallee.getThis())) {
3114 // in this case, we need to create a new edge
3115 // 'this.FIELD'->'this'
3116 // but we couldn't... instead we assign a new composite
3118 // with 'this' reference to the corresponding parameter
3120 CompositeLocation compLocForParam1 =
3121 generateCompositeLocation(mdCallee, param1Prefix);
3124 .println("set comp loc=" + compLocForParam1 + " to " + paramNode1);
3125 paramNode1.setCompositeLocation(compLocForParam1);
3127 // then, we need to make sure that the corresponding
3128 // argument in the caller
3129 // is required to be higher than or equal to the
3130 // translated parameter
3133 NTuple<Descriptor> translatedParamTuple =
3134 translateCompositeLocationToCaller(min, compLocForParam1);
3136 // TODO : check if the arg >= the tranlated parameter
3138 System.out.println("add a flow edge= " + arg1Tuple + "->"
3139 + translatedParamTuple);
3140 callerFlowGraph.addValueFlowEdge(arg1Tuple, translatedParamTuple);
3147 // param1 has already been assigned a composite location
3149 System.out.println("--param1 has already been assigned a composite location");
3150 CompositeLocation compLocForParam1 = paramNode1.getCompositeLocation();
3151 NTuple<Descriptor> translatedParamTuple =
3152 translateCompositeLocationToCaller(min, compLocForParam1);
3154 // TODO : check if the arg >= the tranlated parameter
3156 System.out.println("add a flow edge= " + arg1Tuple + "->"
3157 + translatedParamTuple);
3158 callerFlowGraph.addValueFlowEdge(arg1Tuple, translatedParamTuple);
3164 } else if (arg1Tuple.size() == 1 && arg1Tuple.get(0).equals(baseRef)) {
3165 // in this case, the callee flow causes a caller flow
3166 // originated from the object
3168 // method is invoked.
3170 System.out.println("###FROM CASE");
3172 if (!paramNode2.getCurrentDescTuple().startsWith(mdCallee.getThis())) {
3174 NTuple<Descriptor> param2Prefix =
3175 calculatePrefixForParam(callerFlowGraph, calleeFlowGraph, min, arg2Tuple,
3178 if (param2Prefix != null && param2Prefix.startsWith(mdCallee.getThis())) {
3179 // in this case, we need to create a new edge 'this' ->
3180 // 'this.FIELD' but we couldn't... instead we assign the
3182 // parameter a new composite location started with
3185 CompositeLocation compLocForParam2 =
3186 generateCompositeLocation(mdCallee, param2Prefix);
3188 // System.out.println("set comp loc=" + compLocForParam2
3190 // " to " + paramNode2);
3191 paramNode1.setCompositeLocation(compLocForParam2);
3199 // otherwise, flows between method/field locations...
3200 callerFlowGraph.addValueFlowEdge(arg1Tuple, arg2Tuple);
3201 System.out.println("arg1=" + arg1Tuple + " arg2=" + arg2Tuple);
3208 System.out.println();
3212 System.out.println("##\n");
3215 private NTuple<Descriptor> translateCompositeLocationToCaller(MethodInvokeNode min,
3216 CompositeLocation compLocForParam1) {
3217 NTuple<Descriptor> baseTuple = mapMethodInvokeNodeToBaseTuple.get(min);
3219 NTuple<Descriptor> tuple = new NTuple<Descriptor>();
3221 for (int i = 0; i < baseTuple.size(); i++) {
3222 tuple.add(baseTuple.get(i));
3225 for (int i = 1; i < compLocForParam1.getSize(); i++) {
3226 Location loc = compLocForParam1.get(i);
3227 tuple.add(loc.getLocDescriptor());
3233 private CompositeLocation generateCompositeLocation(NTuple<Location> prefixLocTuple) {
3235 System.out.println("generateCompositeLocation=" + prefixLocTuple);
3237 CompositeLocation newCompLoc = new CompositeLocation();
3238 for (int i = 0; i < prefixLocTuple.size(); i++) {
3239 newCompLoc.addLocation(prefixLocTuple.get(i));
3242 Descriptor lastDescOfPrefix = prefixLocTuple.get(prefixLocTuple.size() - 1).getLocDescriptor();
3244 ClassDescriptor enclosingDescriptor;
3245 if (lastDescOfPrefix instanceof FieldDescriptor) {
3246 enclosingDescriptor = ((FieldDescriptor) lastDescOfPrefix).getType().getClassDesc();
3247 // System.out.println("enclosingDescriptor0=" + enclosingDescriptor);
3248 } else if (lastDescOfPrefix.equals(GLOBALDESC)) {
3249 MethodDescriptor currentMethodDesc = (MethodDescriptor) prefixLocTuple.get(0).getDescriptor();
3250 enclosingDescriptor = currentMethodDesc.getClassDesc();
3252 // var descriptor case
3253 enclosingDescriptor = ((VarDescriptor) lastDescOfPrefix).getType().getClassDesc();
3255 // System.out.println("enclosingDescriptor=" + enclosingDescriptor);
3257 LocationDescriptor newLocDescriptor = generateNewLocationDescriptor();
3258 newLocDescriptor.setEnclosingClassDesc(enclosingDescriptor);
3260 Location newLoc = new Location(enclosingDescriptor, newLocDescriptor.getSymbol());
3261 newLoc.setLocDescriptor(newLocDescriptor);
3262 newCompLoc.addLocation(newLoc);
3264 // System.out.println("--newCompLoc=" + newCompLoc);
3268 private CompositeLocation generateCompositeLocation(MethodDescriptor md,
3269 NTuple<Descriptor> paramPrefix) {
3271 System.out.println("generateCompositeLocation=" + paramPrefix);
3273 CompositeLocation newCompLoc = convertToCompositeLocation(md, paramPrefix);
3275 Descriptor lastDescOfPrefix = paramPrefix.get(paramPrefix.size() - 1);
3276 // System.out.println("lastDescOfPrefix=" + lastDescOfPrefix + " kind="
3277 // + lastDescOfPrefix.getClass());
3278 ClassDescriptor enclosingDescriptor;
3279 if (lastDescOfPrefix instanceof FieldDescriptor) {
3280 enclosingDescriptor = ((FieldDescriptor) lastDescOfPrefix).getType().getClassDesc();
3281 // System.out.println("enclosingDescriptor0=" + enclosingDescriptor);
3283 // var descriptor case
3284 enclosingDescriptor = ((VarDescriptor) lastDescOfPrefix).getType().getClassDesc();
3286 // System.out.println("enclosingDescriptor=" + enclosingDescriptor);
3288 LocationDescriptor newLocDescriptor = generateNewLocationDescriptor();
3289 newLocDescriptor.setEnclosingClassDesc(enclosingDescriptor);
3291 Location newLoc = new Location(enclosingDescriptor, newLocDescriptor.getSymbol());
3292 newLoc.setLocDescriptor(newLocDescriptor);
3293 newCompLoc.addLocation(newLoc);
3295 // System.out.println("--newCompLoc=" + newCompLoc);
3299 private NTuple<Descriptor> calculatePrefixForParam(FlowGraph callerFlowGraph,
3300 FlowGraph calleeFlowGraph, MethodInvokeNode min, NTuple<Descriptor> arg1Tuple,
3301 FlowNode paramNode1) {
3303 NTuple<Descriptor> baseTuple = mapMethodInvokeNodeToBaseTuple.get(min);
3304 Descriptor baseRef = baseTuple.get(baseTuple.size() - 1);
3305 System.out.println("baseRef=" + baseRef);
3307 FlowNode flowNodeArg1 = callerFlowGraph.getFlowNode(arg1Tuple);
3308 List<NTuple<Descriptor>> callerPrefixList = calculatePrefixList(callerFlowGraph, flowNodeArg1);
3309 System.out.println("callerPrefixList=" + callerPrefixList);
3311 List<NTuple<Descriptor>> prefixList = calculatePrefixList(calleeFlowGraph, paramNode1);
3312 System.out.println("###prefixList from node=" + paramNode1 + " =" + prefixList);
3314 List<NTuple<Descriptor>> calleePrefixList =
3315 translatePrefixListToCallee(baseRef, min.getMethod(), callerPrefixList);
3317 System.out.println("calleePrefixList=" + calleePrefixList);
3319 Set<FlowNode> reachNodeSetFromParam1 = calleeFlowGraph.getReachFlowNodeSetFrom(paramNode1);
3320 System.out.println("reachNodeSetFromParam1=" + reachNodeSetFromParam1);
3322 for (int i = 0; i < calleePrefixList.size(); i++) {
3323 NTuple<Descriptor> curPrefix = calleePrefixList.get(i);
3324 Set<NTuple<Descriptor>> reachableCommonPrefixSet = new HashSet<NTuple<Descriptor>>();
3326 for (Iterator iterator2 = reachNodeSetFromParam1.iterator(); iterator2.hasNext();) {
3327 FlowNode reachNode = (FlowNode) iterator2.next();
3328 if (reachNode.getCurrentDescTuple().startsWith(curPrefix)) {
3329 reachableCommonPrefixSet.add(reachNode.getCurrentDescTuple());
3333 if (!reachableCommonPrefixSet.isEmpty()) {
3334 System.out.println("###REACHABLECOMONPREFIX=" + reachableCommonPrefixSet
3335 + " with curPreFix=" + curPrefix);
3344 private List<NTuple<Descriptor>> translatePrefixListToCallee(Descriptor baseRef,
3345 MethodDescriptor mdCallee, List<NTuple<Descriptor>> callerPrefixList) {
3347 List<NTuple<Descriptor>> calleePrefixList = new ArrayList<NTuple<Descriptor>>();
3349 for (int i = 0; i < callerPrefixList.size(); i++) {
3350 NTuple<Descriptor> prefix = callerPrefixList.get(i);
3351 if (prefix.startsWith(baseRef)) {
3352 NTuple<Descriptor> calleePrefix = new NTuple<Descriptor>();
3353 calleePrefix.add(mdCallee.getThis());
3354 for (int k = 1; k < prefix.size(); k++) {
3355 calleePrefix.add(prefix.get(k));
3357 calleePrefixList.add(calleePrefix);
3361 return calleePrefixList;
3365 private List<NTuple<Descriptor>> calculatePrefixList(FlowGraph flowGraph, FlowNode flowNode) {
3367 System.out.println("\n##### calculatePrefixList=" + flowNode);
3369 Set<FlowNode> inNodeSet = flowGraph.getIncomingFlowNodeSet(flowNode);
3370 inNodeSet.add(flowNode);
3372 System.out.println("inNodeSet=" + inNodeSet);
3374 List<NTuple<Descriptor>> prefixList = new ArrayList<NTuple<Descriptor>>();
3376 for (Iterator iterator = inNodeSet.iterator(); iterator.hasNext();) {
3377 FlowNode inNode = (FlowNode) iterator.next();
3379 NTuple<Descriptor> inNodeTuple = inNode.getCurrentDescTuple();
3381 // CompositeLocation inNodeInferredLoc =
3382 // generateInferredCompositeLocation(methodInfo, inNodeTuple);
3383 // NTuple<Location> inNodeInferredLocTuple = inNodeInferredLoc.getTuple();
3385 for (int i = 1; i < inNodeTuple.size(); i++) {
3386 NTuple<Descriptor> prefix = inNodeTuple.subList(0, i);
3387 if (!prefixList.contains(prefix)) {
3388 prefixList.add(prefix);
3393 Collections.sort(prefixList, new Comparator<NTuple<Descriptor>>() {
3394 public int compare(NTuple<Descriptor> arg0, NTuple<Descriptor> arg1) {
3395 int s0 = arg0.size();
3396 int s1 = arg1.size();
3399 } else if (s0 == s1) {
3411 public CompositeLocation convertToCompositeLocation(MethodDescriptor md, NTuple<Descriptor> tuple) {
3413 CompositeLocation compLoc = new CompositeLocation();
3415 Descriptor enclosingDescriptor = md;
3417 for (int i = 0; i < tuple.size(); i++) {
3418 Descriptor curDescriptor = tuple.get(i);
3419 Location locElement = new Location(enclosingDescriptor, curDescriptor.getSymbol());
3420 locElement.setLocDescriptor(curDescriptor);
3421 compLoc.addLocation(locElement);
3423 if (curDescriptor instanceof VarDescriptor) {
3424 enclosingDescriptor = md.getClassDesc();
3425 } else if (curDescriptor instanceof NameDescriptor) {
3426 // it is "GLOBAL LOC" case!
3427 enclosingDescriptor = GLOBALDESC;
3428 } else if (curDescriptor instanceof InterDescriptor) {
3429 enclosingDescriptor = null;
3431 enclosingDescriptor = ((FieldDescriptor) curDescriptor).getClassDescriptor();
3439 private LocationDescriptor generateNewLocationDescriptor() {
3440 return new LocationDescriptor("Loc" + (locSeed++));
3443 private int getPrefixIndex(NTuple<Descriptor> tuple1, NTuple<Descriptor> tuple2) {
3445 // return the index where the prefix shared by tuple1 and tuple2 is ended
3446 // if there is no prefix shared by both of them, return -1
3448 int minSize = tuple1.size();
3449 if (minSize > tuple2.size()) {
3450 minSize = tuple2.size();
3454 for (int i = 0; i < minSize; i++) {
3455 if (!tuple1.get(i).equals(tuple2.get(i))) {
3465 private CompositeLocation generateInferredCompositeLocation(MethodLocationInfo methodInfo,
3466 NTuple<Location> tuple) {
3468 // first, retrieve inferred location by the local var descriptor
3469 CompositeLocation inferLoc = new CompositeLocation();
3471 CompositeLocation localVarInferLoc =
3472 methodInfo.getInferLocation(tuple.get(0).getLocDescriptor());
3474 localVarInferLoc.get(0).setLocDescriptor(tuple.get(0).getLocDescriptor());
3476 for (int i = 0; i < localVarInferLoc.getSize(); i++) {
3477 inferLoc.addLocation(localVarInferLoc.get(i));
3480 for (int i = 1; i < tuple.size(); i++) {
3481 Location cur = tuple.get(i);
3482 Descriptor enclosingDesc = cur.getDescriptor();
3483 Descriptor curDesc = cur.getLocDescriptor();
3485 Location inferLocElement;
3486 if (curDesc == null) {
3487 // in this case, we have a newly generated location.
3488 inferLocElement = new Location(enclosingDesc, cur.getLocIdentifier());
3490 String fieldLocSymbol =
3491 getLocationInfo(enclosingDesc).getInferLocation(curDesc).get(0).getLocIdentifier();
3492 inferLocElement = new Location(enclosingDesc, fieldLocSymbol);
3493 inferLocElement.setLocDescriptor(curDesc);
3496 inferLoc.addLocation(inferLocElement);
3500 assert (inferLoc.get(0).getLocDescriptor().getSymbol() == inferLoc.get(0).getLocIdentifier());
3504 public LocationInfo getLocationInfo(Descriptor d) {
3505 if (d instanceof MethodDescriptor) {
3506 return getMethodLocationInfo((MethodDescriptor) d);
3508 return getFieldLocationInfo((ClassDescriptor) d);
3512 private MethodLocationInfo getMethodLocationInfo(MethodDescriptor md) {
3514 if (!mapMethodDescToMethodLocationInfo.containsKey(md)) {
3515 mapMethodDescToMethodLocationInfo.put(md, new MethodLocationInfo(md));
3518 return mapMethodDescToMethodLocationInfo.get(md);
3522 private LocationInfo getFieldLocationInfo(ClassDescriptor cd) {
3524 if (!mapClassToLocationInfo.containsKey(cd)) {
3525 mapClassToLocationInfo.put(cd, new LocationInfo(cd));
3528 return mapClassToLocationInfo.get(cd);
3532 private void addPrefixMapping(Map<NTuple<Location>, Set<NTuple<Location>>> map,
3533 NTuple<Location> prefix, NTuple<Location> element) {
3535 if (!map.containsKey(prefix)) {
3536 map.put(prefix, new HashSet<NTuple<Location>>());
3538 map.get(prefix).add(element);
3541 private boolean containsNonPrimitiveElement(Set<Descriptor> descSet) {
3542 for (Iterator iterator = descSet.iterator(); iterator.hasNext();) {
3543 Descriptor desc = (Descriptor) iterator.next();
3545 if (desc.equals(LocationInference.GLOBALDESC)) {
3547 } else if (desc instanceof VarDescriptor) {
3548 if (!((VarDescriptor) desc).getType().isPrimitive()) {
3551 } else if (desc instanceof FieldDescriptor) {
3552 if (!((FieldDescriptor) desc).getType().isPrimitive()) {
3561 private SSJavaLattice<String> getLattice(Descriptor d) {
3562 if (d instanceof MethodDescriptor) {
3563 return getMethodLattice((MethodDescriptor) d);
3565 return getFieldLattice((ClassDescriptor) d);
3569 private SSJavaLattice<String> getMethodLattice(MethodDescriptor md) {
3570 if (!md2lattice.containsKey(md)) {
3571 md2lattice.put(md, new SSJavaLattice<String>(SSJavaAnalysis.TOP, SSJavaAnalysis.BOTTOM));
3573 return md2lattice.get(md);
3576 private void setMethodLattice(MethodDescriptor md, SSJavaLattice<String> lattice) {
3577 md2lattice.put(md, lattice);
3580 private void extractFlowsBetweenFields(ClassDescriptor cd, FlowNode srcNode, FlowNode dstNode,
3583 NTuple<Descriptor> srcCurTuple = srcNode.getCurrentDescTuple();
3584 NTuple<Descriptor> dstCurTuple = dstNode.getCurrentDescTuple();
3586 if (srcCurTuple.get(idx).equals(dstCurTuple.get(idx)) && srcCurTuple.size() > (idx + 1)
3587 && dstCurTuple.size() > (idx + 1)) {
3588 // value flow between fields: we don't need to add a binary relation
3591 Descriptor desc = srcCurTuple.get(idx);
3592 ClassDescriptor classDesc;
3595 classDesc = ((VarDescriptor) desc).getType().getClassDesc();
3597 if (desc instanceof FieldDescriptor) {
3598 classDesc = ((FieldDescriptor) desc).getType().getClassDesc();
3600 // this case is that the local variable has a composite location assignment
3601 // the following element after the composite location to the local variable
3602 // has the enclosing descriptor of the local variable
3603 Descriptor localDesc = srcNode.getDescTuple().get(0);
3604 classDesc = ((VarDescriptor) localDesc).getType().getClassDesc();
3607 extractFlowsBetweenFields(classDesc, srcNode, dstNode, idx + 1);
3611 Descriptor srcFieldDesc = srcCurTuple.get(idx);
3612 Descriptor dstFieldDesc = dstCurTuple.get(idx);
3615 getHierarchyGraph(cd).addEdge(srcFieldDesc, dstFieldDesc);
3621 public SSJavaLattice<String> getFieldLattice(ClassDescriptor cd) {
3622 if (!cd2lattice.containsKey(cd)) {
3623 cd2lattice.put(cd, new SSJavaLattice<String>(SSJavaAnalysis.TOP, SSJavaAnalysis.BOTTOM));
3625 return cd2lattice.get(cd);
3628 public LinkedList<MethodDescriptor> computeMethodList() {
3630 Set<MethodDescriptor> toSort = new HashSet<MethodDescriptor>();
3634 Set<MethodDescriptor> visited = new HashSet<MethodDescriptor>();
3635 Set<MethodDescriptor> reachableCallee = new HashSet<MethodDescriptor>();
3637 while (!toAnalyzeIsEmpty()) {
3638 ClassDescriptor cd = toAnalyzeNext();
3640 setupToAnalazeMethod(cd);
3641 temp_toanalyzeMethodList.removeAll(visited);
3643 while (!toAnalyzeMethodIsEmpty()) {
3644 MethodDescriptor md = toAnalyzeMethodNext();
3645 if ((!visited.contains(md))
3646 && (ssjava.needTobeAnnotated(md) || reachableCallee.contains(md))) {
3648 // creates a mapping from a method descriptor to virtual methods
3649 Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
3650 if (md.isStatic()) {
3651 setPossibleCallees.add(md);
3653 setPossibleCallees.addAll(ssjava.getCallGraph().getMethods(md));
3656 Set<MethodDescriptor> calleeSet = ssjava.getCallGraph().getCalleeSet(md);
3657 Set<MethodDescriptor> needToAnalyzeCalleeSet = new HashSet<MethodDescriptor>();
3659 for (Iterator iterator = calleeSet.iterator(); iterator.hasNext();) {
3660 MethodDescriptor calleemd = (MethodDescriptor) iterator.next();
3661 if ((!ssjava.isTrustMethod(calleemd))
3662 && (!ssjava.isSSJavaUtil(calleemd.getClassDesc()))) {
3663 if (!visited.contains(calleemd)) {
3664 temp_toanalyzeMethodList.add(calleemd);
3666 reachableCallee.add(calleemd);
3667 needToAnalyzeCalleeSet.add(calleemd);
3671 mapMethodToCalleeSet.put(md, needToAnalyzeCalleeSet);
3680 return ssjava.topologicalSort(toSort);
3684 public boolean isTransitivelyCalledFrom(MethodDescriptor callee, MethodDescriptor caller) {
3685 // if the callee is transitively invoked from the caller
3688 int callerIdx = toanalyze_methodDescList.indexOf(caller);
3689 int calleeIdx = toanalyze_methodDescList.indexOf(callee);
3691 if (callerIdx < calleeIdx) {
3699 public void constructFlowGraph() {
3701 System.out.println("");
3702 toanalyze_methodDescList = computeMethodList();
3704 LinkedList<MethodDescriptor> methodDescList =
3705 (LinkedList<MethodDescriptor>) toanalyze_methodDescList.clone();
3707 System.out.println("@@@methodDescList=" + methodDescList);
3710 while (!methodDescList.isEmpty()) {
3711 MethodDescriptor md = methodDescList.removeLast();
3712 if (state.SSJAVADEBUG) {
3713 System.out.println();
3714 System.out.println("SSJAVA: Constructing a flow graph: " + md);
3716 // creates a mapping from a parameter descriptor to its index
3717 Map<Descriptor, Integer> mapParamDescToIdx = new HashMap<Descriptor, Integer>();
3719 if (!md.isStatic()) {
3721 mapParamDescToIdx.put(md.getThis(), 0);
3724 for (int i = 0; i < md.numParameters(); i++) {
3725 Descriptor paramDesc = (Descriptor) md.getParameter(i);
3726 mapParamDescToIdx.put(paramDesc, new Integer(i + offset));
3729 FlowGraph fg = new FlowGraph(md, mapParamDescToIdx);
3730 mapMethodDescriptorToFlowGraph.put(md, fg);
3732 analyzeMethodBody(md.getClassDesc(), md);
3734 // System.out.println("##constructSubGlobalFlowGraph");
3735 // GlobalFlowGraph subGlobalFlowGraph = constructSubGlobalFlowGraph(fg);
3736 // mapMethodDescriptorToSubGlobalFlowGraph.put(md, subGlobalFlowGraph);
3739 // System.out.println("##addValueFlowsFromCalleeSubGlobalFlowGraph");
3740 // addValueFlowsFromCalleeSubGlobalFlowGraph(md, subGlobalFlowGraph);
3741 // subGlobalFlowGraph.writeGraph("_SUBGLOBAL");
3743 // propagateFlowsFromCalleesWithNoCompositeLocation(md);
3747 // _debug_printGraph();
3749 methodDescList = (LinkedList<MethodDescriptor>) toanalyze_methodDescList.clone();
3751 while (!methodDescList.isEmpty()) {
3752 MethodDescriptor md = methodDescList.removeLast();
3753 if (state.SSJAVADEBUG) {
3754 System.out.println();
3755 System.out.println("SSJAVA: Constructing a sub global flow graph: " + md);
3757 GlobalFlowGraph subGlobalFlowGraph = constructSubGlobalFlowGraph(getFlowGraph(md));
3758 mapMethodDescriptorToSubGlobalFlowGraph.put(md, subGlobalFlowGraph);
3761 System.out.println("-add Value Flows From CalleeSubGlobalFlowGraph");
3762 addValueFlowsFromCalleeSubGlobalFlowGraph(md, subGlobalFlowGraph);
3763 subGlobalFlowGraph.writeGraph("_SUBGLOBAL");
3765 System.out.println("-propagate Flows From Callees With No CompositeLocation");
3766 propagateFlowsFromCalleesWithNoCompositeLocation(md);
3773 private Set<MethodInvokeNode> getMethodInvokeNodeSet(MethodDescriptor md) {
3774 if (!mapMethodDescriptorToMethodInvokeNodeSet.containsKey(md)) {
3775 mapMethodDescriptorToMethodInvokeNodeSet.put(md, new HashSet<MethodInvokeNode>());
3777 return mapMethodDescriptorToMethodInvokeNodeSet.get(md);
3780 private void constructSubGlobalFlowGraph(MethodDescriptor md) {
3782 FlowGraph flowGraph = getFlowGraph(md);
3784 Set<MethodInvokeNode> setMethodInvokeNode = getMethodInvokeNodeSet(md);
3786 for (Iterator<MethodInvokeNode> iter = setMethodInvokeNode.iterator(); iter.hasNext();) {
3787 MethodInvokeNode min = iter.next();
3788 propagateFlowsFromMethodInvokeNode(md, min);
3793 private void propagateFlowsFromMethodInvokeNode(MethodDescriptor mdCaller, MethodInvokeNode min) {
3794 // the transformation for a call site propagates flows through parameters
3795 // if the method is virtual, it also grab all relations from any possible
3798 MethodDescriptor mdCallee = min.getMethod();
3799 Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
3800 if (mdCallee.isStatic()) {
3801 setPossibleCallees.add(mdCallee);
3803 Set<MethodDescriptor> calleeSet = ssjava.getCallGraph().getMethods(mdCallee);
3804 // removes method descriptors that are not invoked by the caller
3805 calleeSet.retainAll(mapMethodToCalleeSet.get(mdCaller));
3806 setPossibleCallees.addAll(calleeSet);
3809 for (Iterator iterator2 = setPossibleCallees.iterator(); iterator2.hasNext();) {
3810 MethodDescriptor possibleMdCallee = (MethodDescriptor) iterator2.next();
3811 contributeCalleeFlows(min, mdCaller, possibleMdCallee);
3816 private void assignCompositeLocation(MethodDescriptor md) {
3818 FlowGraph flowGraph = getFlowGraph(md);
3820 Set<FlowNode> nodeSet = flowGraph.getNodeSet();
3822 next: for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
3823 FlowNode flowNode = (FlowNode) iterator.next();
3825 // assign a composite location only to the local variable
3826 if (flowNode.getCurrentDescTuple().size() == 1) {
3828 List<NTuple<Descriptor>> prefixList = calculatePrefixList(flowGraph, flowNode);
3829 Set<FlowNode> reachSet = flowGraph.getReachFlowNodeSetFrom(flowNode);
3831 for (int i = 0; i < prefixList.size(); i++) {
3832 NTuple<Descriptor> curPrefix = prefixList.get(i);
3833 Set<NTuple<Descriptor>> reachableCommonPrefixSet = new HashSet<NTuple<Descriptor>>();
3835 for (Iterator iterator2 = reachSet.iterator(); iterator2.hasNext();) {
3836 FlowNode reachNode = (FlowNode) iterator2.next();
3837 if (reachNode.getCurrentDescTuple().startsWith(curPrefix)) {
3838 reachableCommonPrefixSet.add(reachNode.getCurrentDescTuple());
3842 if (!reachableCommonPrefixSet.isEmpty()) {
3843 System.out.println("NEED TO ASSIGN COMP LOC TO " + flowNode + " with prefix="
3845 CompositeLocation newCompLoc = generateCompositeLocation(md, curPrefix);
3846 flowNode.setCompositeLocation(newCompLoc);
3857 private void propagateFlowsFromCalleesWithNoCompositeLocation(MethodDescriptor mdCaller) {
3859 // the transformation for a call site propagates flows through parameters
3860 // if the method is virtual, it also grab all relations from any possible
3863 Set<MethodInvokeNode> setMethodInvokeNode =
3864 mapMethodDescriptorToMethodInvokeNodeSet.get(mdCaller);
3866 if (setMethodInvokeNode != null) {
3868 for (Iterator iterator = setMethodInvokeNode.iterator(); iterator.hasNext();) {
3869 MethodInvokeNode min = (MethodInvokeNode) iterator.next();
3870 MethodDescriptor mdCallee = min.getMethod();
3871 Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
3872 if (mdCallee.isStatic()) {
3873 setPossibleCallees.add(mdCallee);
3875 Set<MethodDescriptor> calleeSet = ssjava.getCallGraph().getMethods(mdCallee);
3876 // removes method descriptors that are not invoked by the caller
3877 calleeSet.retainAll(mapMethodToCalleeSet.get(mdCaller));
3878 setPossibleCallees.addAll(calleeSet);
3881 for (Iterator iterator2 = setPossibleCallees.iterator(); iterator2.hasNext();) {
3882 MethodDescriptor possibleMdCallee = (MethodDescriptor) iterator2.next();
3883 propagateFlowsToCallerWithNoCompositeLocation(min, mdCaller, possibleMdCallee);
3891 private void propagateFlowsFromCallees(MethodDescriptor mdCaller) {
3893 // the transformation for a call site propagates flows through parameters
3894 // if the method is virtual, it also grab all relations from any possible
3897 Set<MethodInvokeNode> setMethodInvokeNode =
3898 mapMethodDescriptorToMethodInvokeNodeSet.get(mdCaller);
3900 if (setMethodInvokeNode != null) {
3902 for (Iterator iterator = setMethodInvokeNode.iterator(); iterator.hasNext();) {
3903 MethodInvokeNode min = (MethodInvokeNode) iterator.next();
3904 MethodDescriptor mdCallee = min.getMethod();
3905 Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
3906 if (mdCallee.isStatic()) {
3907 setPossibleCallees.add(mdCallee);
3909 Set<MethodDescriptor> calleeSet = ssjava.getCallGraph().getMethods(mdCallee);
3910 // removes method descriptors that are not invoked by the caller
3911 calleeSet.retainAll(mapMethodToCalleeSet.get(mdCaller));
3912 setPossibleCallees.addAll(calleeSet);
3915 for (Iterator iterator2 = setPossibleCallees.iterator(); iterator2.hasNext();) {
3916 MethodDescriptor possibleMdCallee = (MethodDescriptor) iterator2.next();
3917 propagateFlowsToCaller(min, mdCaller, possibleMdCallee);
3925 private void analyzeMethodBody(ClassDescriptor cd, MethodDescriptor md) {
3926 BlockNode bn = state.getMethodBody(md);
3927 NodeTupleSet implicitFlowTupleSet = new NodeTupleSet();
3928 analyzeFlowBlockNode(md, md.getParameterTable(), bn, implicitFlowTupleSet);
3931 private void analyzeFlowBlockNode(MethodDescriptor md, SymbolTable nametable, BlockNode bn,
3932 NodeTupleSet implicitFlowTupleSet) {
3934 bn.getVarTable().setParent(nametable);
3935 for (int i = 0; i < bn.size(); i++) {
3936 BlockStatementNode bsn = bn.get(i);
3937 analyzeBlockStatementNode(md, bn.getVarTable(), bsn, implicitFlowTupleSet);
3942 private void analyzeBlockStatementNode(MethodDescriptor md, SymbolTable nametable,
3943 BlockStatementNode bsn, NodeTupleSet implicitFlowTupleSet) {
3945 switch (bsn.kind()) {
3946 case Kind.BlockExpressionNode:
3947 analyzeBlockExpressionNode(md, nametable, (BlockExpressionNode) bsn, implicitFlowTupleSet);
3950 case Kind.DeclarationNode:
3951 analyzeFlowDeclarationNode(md, nametable, (DeclarationNode) bsn, implicitFlowTupleSet);
3954 case Kind.IfStatementNode:
3955 analyzeFlowIfStatementNode(md, nametable, (IfStatementNode) bsn, implicitFlowTupleSet);
3959 analyzeFlowLoopNode(md, nametable, (LoopNode) bsn, implicitFlowTupleSet);
3962 case Kind.ReturnNode:
3963 analyzeFlowReturnNode(md, nametable, (ReturnNode) bsn, implicitFlowTupleSet);
3966 case Kind.SubBlockNode:
3967 analyzeFlowSubBlockNode(md, nametable, (SubBlockNode) bsn, implicitFlowTupleSet);
3970 case Kind.ContinueBreakNode:
3973 case Kind.SwitchStatementNode:
3974 analyzeSwitchStatementNode(md, nametable, (SwitchStatementNode) bsn, implicitFlowTupleSet);
3981 private void analyzeSwitchBlockNode(MethodDescriptor md, SymbolTable nametable,
3982 SwitchBlockNode sbn, NodeTupleSet implicitFlowTupleSet) {
3984 analyzeFlowBlockNode(md, nametable, sbn.getSwitchBlockStatement(), implicitFlowTupleSet);
3988 private void analyzeSwitchStatementNode(MethodDescriptor md, SymbolTable nametable,
3989 SwitchStatementNode ssn, NodeTupleSet implicitFlowTupleSet) {
3991 NodeTupleSet condTupleNode = new NodeTupleSet();
3992 analyzeFlowExpressionNode(md, nametable, ssn.getCondition(), condTupleNode, null,
3993 implicitFlowTupleSet, false);
3995 NodeTupleSet newImplicitTupleSet = new NodeTupleSet();
3997 newImplicitTupleSet.addTupleSet(implicitFlowTupleSet);
3998 newImplicitTupleSet.addTupleSet(condTupleNode);
4000 if (newImplicitTupleSet.size() > 1) {
4001 // need to create an intermediate node for the GLB of conditional
4002 // locations & implicit flows
4003 NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
4004 for (Iterator<NTuple<Descriptor>> idxIter = newImplicitTupleSet.iterator(); idxIter.hasNext();) {
4005 NTuple<Descriptor> tuple = idxIter.next();
4006 addFlowGraphEdge(md, tuple, interTuple);
4008 newImplicitTupleSet.clear();
4009 newImplicitTupleSet.addTuple(interTuple);
4012 BlockNode sbn = ssn.getSwitchBody();
4013 for (int i = 0; i < sbn.size(); i++) {
4014 analyzeSwitchBlockNode(md, nametable, (SwitchBlockNode) sbn.get(i), newImplicitTupleSet);
4019 private void analyzeFlowSubBlockNode(MethodDescriptor md, SymbolTable nametable,
4020 SubBlockNode sbn, NodeTupleSet implicitFlowTupleSet) {
4021 analyzeFlowBlockNode(md, nametable, sbn.getBlockNode(), implicitFlowTupleSet);
4024 private void analyzeFlowReturnNode(MethodDescriptor md, SymbolTable nametable, ReturnNode rn,
4025 NodeTupleSet implicitFlowTupleSet) {
4027 ExpressionNode returnExp = rn.getReturnExpression();
4029 if (returnExp != null) {
4030 NodeTupleSet nodeSet = new NodeTupleSet();
4031 // if a return expression returns a literal value, nodeSet is empty
4032 analyzeFlowExpressionNode(md, nametable, returnExp, nodeSet, false);
4033 FlowGraph fg = getFlowGraph(md);
4035 // if (implicitFlowTupleSet.size() == 1
4037 // fg.getFlowNode(implicitFlowTupleSet.iterator().next()).isIntermediate())
4040 // // since there is already an intermediate node for the GLB of implicit
4042 // // we don't need to create another intermediate node.
4043 // // just re-use the intermediate node for implicit flows.
4045 // FlowNode meetNode =
4046 // fg.getFlowNode(implicitFlowTupleSet.iterator().next());
4048 // for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
4049 // NTuple<Descriptor> returnNodeTuple = (NTuple<Descriptor>)
4051 // fg.addValueFlowEdge(returnNodeTuple, meetNode.getDescTuple());
4056 NodeTupleSet currentFlowTupleSet = new NodeTupleSet();
4058 // add tuples from return node
4059 currentFlowTupleSet.addTupleSet(nodeSet);
4061 // add tuples corresponding to the current implicit flows
4062 currentFlowTupleSet.addTupleSet(implicitFlowTupleSet);
4064 if (currentFlowTupleSet.size() > 1) {
4065 FlowNode meetNode = fg.createIntermediateNode();
4066 for (Iterator iterator = currentFlowTupleSet.iterator(); iterator.hasNext();) {
4067 NTuple<Descriptor> currentFlowTuple = (NTuple<Descriptor>) iterator.next();
4068 fg.addValueFlowEdge(currentFlowTuple, meetNode.getDescTuple());
4070 fg.addReturnFlowNode(meetNode.getDescTuple());
4071 } else if (currentFlowTupleSet.size() == 1) {
4072 NTuple<Descriptor> tuple = currentFlowTupleSet.iterator().next();
4073 fg.addReturnFlowNode(tuple);
4080 private void analyzeFlowLoopNode(MethodDescriptor md, SymbolTable nametable, LoopNode ln,
4081 NodeTupleSet implicitFlowTupleSet) {
4083 if (ln.getType() == LoopNode.WHILELOOP || ln.getType() == LoopNode.DOWHILELOOP) {
4085 NodeTupleSet condTupleNode = new NodeTupleSet();
4086 analyzeFlowExpressionNode(md, nametable, ln.getCondition(), condTupleNode, null,
4087 implicitFlowTupleSet, false);
4089 NodeTupleSet newImplicitTupleSet = new NodeTupleSet();
4091 newImplicitTupleSet.addTupleSet(implicitFlowTupleSet);
4092 newImplicitTupleSet.addTupleSet(condTupleNode);
4094 if (newImplicitTupleSet.size() > 1) {
4095 // need to create an intermediate node for the GLB of conditional
4096 // locations & implicit flows
4097 NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
4098 for (Iterator<NTuple<Descriptor>> idxIter = newImplicitTupleSet.iterator(); idxIter
4100 NTuple<Descriptor> tuple = idxIter.next();
4101 addFlowGraphEdge(md, tuple, interTuple);
4103 newImplicitTupleSet.clear();
4104 newImplicitTupleSet.addTuple(interTuple);
4109 // System.out.println("condTupleNode="+condTupleNode);
4110 // NTuple<Descriptor> interTuple =
4111 // getFlowGraph(md).createIntermediateNode().getDescTuple();
4113 // for (Iterator<NTuple<Descriptor>> idxIter = condTupleNode.iterator();
4114 // idxIter.hasNext();) {
4115 // NTuple<Descriptor> tuple = idxIter.next();
4116 // addFlowGraphEdge(md, tuple, interTuple);
4119 // for (Iterator<NTuple<Descriptor>> idxIter =
4120 // implicitFlowTupleSet.iterator(); idxIter
4122 // NTuple<Descriptor> tuple = idxIter.next();
4123 // addFlowGraphEdge(md, tuple, interTuple);
4126 // NodeTupleSet newImplicitSet = new NodeTupleSet();
4127 // newImplicitSet.addTuple(interTuple);
4128 analyzeFlowBlockNode(md, nametable, ln.getBody(), newImplicitTupleSet);
4131 // condTupleNode.addTupleSet(implicitFlowTupleSet);
4133 // add edges from condNodeTupleSet to all nodes of conditional nodes
4134 // analyzeFlowBlockNode(md, nametable, ln.getBody(), condTupleNode);
4137 // check 'for loop' case
4138 BlockNode bn = ln.getInitializer();
4139 bn.getVarTable().setParent(nametable);
4140 for (int i = 0; i < bn.size(); i++) {
4141 BlockStatementNode bsn = bn.get(i);
4142 analyzeBlockStatementNode(md, bn.getVarTable(), bsn, implicitFlowTupleSet);
4145 NodeTupleSet condTupleNode = new NodeTupleSet();
4146 analyzeFlowExpressionNode(md, bn.getVarTable(), ln.getCondition(), condTupleNode, null,
4147 implicitFlowTupleSet, false);
4150 NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
4152 for (Iterator<NTuple<Descriptor>> idxIter = condTupleNode.iterator(); idxIter.hasNext();) {
4153 NTuple<Descriptor> tuple = idxIter.next();
4154 addFlowGraphEdge(md, tuple, interTuple);
4157 for (Iterator<NTuple<Descriptor>> idxIter = implicitFlowTupleSet.iterator(); idxIter
4159 NTuple<Descriptor> tuple = idxIter.next();
4160 addFlowGraphEdge(md, tuple, interTuple);
4163 NodeTupleSet newImplicitSet = new NodeTupleSet();
4164 newImplicitSet.addTuple(interTuple);
4165 analyzeFlowBlockNode(md, bn.getVarTable(), ln.getUpdate(), newImplicitSet);
4166 analyzeFlowBlockNode(md, bn.getVarTable(), ln.getBody(), newImplicitSet);
4169 // condTupleNode.addTupleSet(implicitFlowTupleSet);
4171 // analyzeFlowBlockNode(md, bn.getVarTable(), ln.getUpdate(),
4173 // analyzeFlowBlockNode(md, bn.getVarTable(), ln.getBody(),
4180 private void analyzeFlowIfStatementNode(MethodDescriptor md, SymbolTable nametable,
4181 IfStatementNode isn, NodeTupleSet implicitFlowTupleSet) {
4183 // System.out.println("analyzeFlowIfStatementNode=" + isn.printNode(0));
4185 NodeTupleSet condTupleNode = new NodeTupleSet();
4186 analyzeFlowExpressionNode(md, nametable, isn.getCondition(), condTupleNode, null,
4187 implicitFlowTupleSet, false);
4189 NodeTupleSet newImplicitTupleSet = new NodeTupleSet();
4191 newImplicitTupleSet.addTupleSet(implicitFlowTupleSet);
4192 newImplicitTupleSet.addTupleSet(condTupleNode);
4194 // System.out.println("condTupleNode=" + condTupleNode);
4195 // System.out.println("implicitFlowTupleSet=" + implicitFlowTupleSet);
4196 // System.out.println("newImplicitTupleSet=" + newImplicitTupleSet);
4198 if (newImplicitTupleSet.size() > 1) {
4200 // need to create an intermediate node for the GLB of conditional locations & implicit flows
4201 NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
4202 for (Iterator<NTuple<Descriptor>> idxIter = newImplicitTupleSet.iterator(); idxIter.hasNext();) {
4203 NTuple<Descriptor> tuple = idxIter.next();
4204 addFlowGraphEdge(md, tuple, interTuple);
4206 newImplicitTupleSet.clear();
4207 newImplicitTupleSet.addTuple(interTuple);
4210 analyzeFlowBlockNode(md, nametable, isn.getTrueBlock(), newImplicitTupleSet);
4212 if (isn.getFalseBlock() != null) {
4213 analyzeFlowBlockNode(md, nametable, isn.getFalseBlock(), newImplicitTupleSet);
4218 private void analyzeFlowDeclarationNode(MethodDescriptor md, SymbolTable nametable,
4219 DeclarationNode dn, NodeTupleSet implicitFlowTupleSet) {
4221 VarDescriptor vd = dn.getVarDescriptor();
4222 mapDescToDefinitionLine.put(vd, dn.getNumLine());
4223 NTuple<Descriptor> tupleLHS = new NTuple<Descriptor>();
4225 FlowNode fn = getFlowGraph(md).createNewFlowNode(tupleLHS);
4226 fn.setDeclarationNode();
4228 if (dn.getExpression() != null) {
4230 NodeTupleSet nodeSetRHS = new NodeTupleSet();
4231 analyzeFlowExpressionNode(md, nametable, dn.getExpression(), nodeSetRHS, null,
4232 implicitFlowTupleSet, false);
4234 // creates edges from RHS to LHS
4235 NTuple<Descriptor> interTuple = null;
4236 if (nodeSetRHS.size() > 1) {
4237 interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
4240 for (Iterator<NTuple<Descriptor>> iter = nodeSetRHS.iterator(); iter.hasNext();) {
4241 NTuple<Descriptor> fromTuple = iter.next();
4242 addFlowGraphEdge(md, fromTuple, interTuple, tupleLHS);
4245 // creates edges from implicitFlowTupleSet to LHS
4246 for (Iterator<NTuple<Descriptor>> iter = implicitFlowTupleSet.iterator(); iter.hasNext();) {
4247 NTuple<Descriptor> implicitTuple = iter.next();
4248 addFlowGraphEdge(md, implicitTuple, tupleLHS);
4255 private void analyzeBlockExpressionNode(MethodDescriptor md, SymbolTable nametable,
4256 BlockExpressionNode ben, NodeTupleSet implicitFlowTupleSet) {
4257 analyzeFlowExpressionNode(md, nametable, ben.getExpression(), null, null, implicitFlowTupleSet,
4261 private NTuple<Descriptor> analyzeFlowExpressionNode(MethodDescriptor md, SymbolTable nametable,
4262 ExpressionNode en, NodeTupleSet nodeSet, boolean isLHS) {
4263 return analyzeFlowExpressionNode(md, nametable, en, nodeSet, null, new NodeTupleSet(), isLHS);
4266 private NTuple<Descriptor> analyzeFlowExpressionNode(MethodDescriptor md, SymbolTable nametable,
4267 ExpressionNode en, NodeTupleSet nodeSet, NTuple<Descriptor> base,
4268 NodeTupleSet implicitFlowTupleSet, boolean isLHS) {
4270 // note that expression node can create more than one flow node
4271 // nodeSet contains of flow nodes
4272 // base is always assigned to null except the case of a name node!
4274 NTuple<Descriptor> flowTuple;
4276 switch (en.kind()) {
4278 case Kind.AssignmentNode:
4279 analyzeFlowAssignmentNode(md, nametable, (AssignmentNode) en, nodeSet, base,
4280 implicitFlowTupleSet);
4283 case Kind.FieldAccessNode:
4285 analyzeFlowFieldAccessNode(md, nametable, (FieldAccessNode) en, nodeSet, base,
4286 implicitFlowTupleSet, isLHS);
4287 if (flowTuple != null) {
4288 nodeSet.addTuple(flowTuple);
4293 NodeTupleSet nameNodeSet = new NodeTupleSet();
4295 analyzeFlowNameNode(md, nametable, (NameNode) en, nameNodeSet, base, implicitFlowTupleSet);
4296 if (flowTuple != null) {
4297 nodeSet.addTuple(flowTuple);
4302 analyzeFlowOpNode(md, nametable, (OpNode) en, nodeSet, implicitFlowTupleSet);
4305 case Kind.CreateObjectNode:
4306 analyzeCreateObjectNode(md, nametable, (CreateObjectNode) en);
4309 case Kind.ArrayAccessNode:
4310 analyzeFlowArrayAccessNode(md, nametable, (ArrayAccessNode) en, nodeSet, isLHS);
4313 case Kind.LiteralNode:
4314 analyzeLiteralNode(md, nametable, (LiteralNode) en);
4317 case Kind.MethodInvokeNode:
4318 analyzeFlowMethodInvokeNode(md, nametable, (MethodInvokeNode) en, nodeSet,
4319 implicitFlowTupleSet);
4322 case Kind.TertiaryNode:
4323 analyzeFlowTertiaryNode(md, nametable, (TertiaryNode) en, nodeSet, implicitFlowTupleSet);
4327 analyzeFlowCastNode(md, nametable, (CastNode) en, nodeSet, base, implicitFlowTupleSet);
4329 // case Kind.InstanceOfNode:
4330 // checkInstanceOfNode(md, nametable, (InstanceOfNode) en, td);
4333 // case Kind.ArrayInitializerNode:
4334 // checkArrayInitializerNode(md, nametable, (ArrayInitializerNode) en,
4338 // case Kind.ClassTypeNode:
4339 // checkClassTypeNode(md, nametable, (ClassTypeNode) en, td);
4342 // case Kind.OffsetNode:
4343 // checkOffsetNode(md, nametable, (OffsetNode)en, td);
4351 private void analyzeFlowCastNode(MethodDescriptor md, SymbolTable nametable, CastNode cn,
4352 NodeTupleSet nodeSet, NTuple<Descriptor> base, NodeTupleSet implicitFlowTupleSet) {
4354 analyzeFlowExpressionNode(md, nametable, cn.getExpression(), nodeSet, base,
4355 implicitFlowTupleSet, false);
4359 private void analyzeFlowTertiaryNode(MethodDescriptor md, SymbolTable nametable, TertiaryNode tn,
4360 NodeTupleSet nodeSet, NodeTupleSet implicitFlowTupleSet) {
4362 NodeTupleSet tertiaryTupleNode = new NodeTupleSet();
4363 analyzeFlowExpressionNode(md, nametable, tn.getCond(), tertiaryTupleNode, null,
4364 implicitFlowTupleSet, false);
4366 // add edges from tertiaryTupleNode to all nodes of conditional nodes
4367 tertiaryTupleNode.addTupleSet(implicitFlowTupleSet);
4368 analyzeFlowExpressionNode(md, nametable, tn.getTrueExpr(), tertiaryTupleNode, null,
4369 implicitFlowTupleSet, false);
4371 analyzeFlowExpressionNode(md, nametable, tn.getFalseExpr(), tertiaryTupleNode, null,
4372 implicitFlowTupleSet, false);
4374 nodeSet.addTupleSet(tertiaryTupleNode);
4378 private void addMapCallerMethodDescToMethodInvokeNodeSet(MethodDescriptor caller,
4379 MethodInvokeNode min) {
4380 Set<MethodInvokeNode> set = mapMethodDescriptorToMethodInvokeNodeSet.get(caller);
4382 set = new HashSet<MethodInvokeNode>();
4383 mapMethodDescriptorToMethodInvokeNodeSet.put(caller, set);
4388 private void addParamNodeFlowingToReturnValue(MethodDescriptor md, FlowNode fn) {
4390 if (!mapMethodDescToParamNodeFlowsToReturnValue.containsKey(md)) {
4391 mapMethodDescToParamNodeFlowsToReturnValue.put(md, new HashSet<FlowNode>());
4393 mapMethodDescToParamNodeFlowsToReturnValue.get(md).add(fn);
4396 private Set<FlowNode> getParamNodeFlowingToReturnValue(MethodDescriptor md) {
4398 if (!mapMethodDescToParamNodeFlowsToReturnValue.containsKey(md)) {
4399 mapMethodDescToParamNodeFlowsToReturnValue.put(md, new HashSet<FlowNode>());
4402 return mapMethodDescToParamNodeFlowsToReturnValue.get(md);
4405 private void analyzeFlowMethodInvokeNode(MethodDescriptor md, SymbolTable nametable,
4406 MethodInvokeNode min, NodeTupleSet nodeSet, NodeTupleSet implicitFlowTupleSet) {
4408 System.out.println("analyzeFlowMethodInvokeNode=" + min.printNode(0));
4410 mapMethodInvokeNodeToArgIdxMap.put(min, new HashMap<Integer, NTuple<Descriptor>>());
4412 if (nodeSet == null) {
4413 nodeSet = new NodeTupleSet();
4416 MethodDescriptor calleeMethodDesc = min.getMethod();
4418 NameDescriptor baseName = min.getBaseName();
4419 boolean isSystemout = false;
4420 if (baseName != null) {
4421 isSystemout = baseName.getSymbol().equals("System.out");
4424 if (!ssjava.isSSJavaUtil(calleeMethodDesc.getClassDesc())
4425 && !ssjava.isTrustMethod(calleeMethodDesc) && !isSystemout) {
4427 addMapCallerMethodDescToMethodInvokeNodeSet(md, min);
4429 FlowGraph calleeFlowGraph = getFlowGraph(calleeMethodDesc);
4430 Set<FlowNode> calleeReturnSet = calleeFlowGraph.getReturnNodeSet();
4432 // System.out.println("-calleeReturnSet=" + calleeReturnSet);
4434 if (min.getExpression() != null) {
4436 NodeTupleSet baseNodeSet = new NodeTupleSet();
4437 analyzeFlowExpressionNode(md, nametable, min.getExpression(), baseNodeSet, null,
4438 implicitFlowTupleSet, false);
4440 assert (baseNodeSet.size() == 1);
4441 NTuple<Descriptor> baseTuple = baseNodeSet.iterator().next();
4442 mapMethodInvokeNodeToBaseTuple.put(min, baseTuple);
4444 if (!min.getMethod().isStatic()) {
4445 addArgIdxMap(min, 0, baseTuple);
4447 for (Iterator iterator = calleeReturnSet.iterator(); iterator.hasNext();) {
4448 FlowNode returnNode = (FlowNode) iterator.next();
4449 NTuple<Descriptor> returnDescTuple = returnNode.getDescTuple();
4450 if (returnDescTuple.startsWith(calleeMethodDesc.getThis())) {
4451 // the location type of the return value is started with 'this'
4453 NTuple<Descriptor> inFlowTuple = new NTuple<Descriptor>(baseTuple.getList());
4454 inFlowTuple.addAll(returnDescTuple.subList(1, returnDescTuple.size()));
4455 nodeSet.addTuple(inFlowTuple);
4458 Set<FlowNode> inFlowSet = calleeFlowGraph.getIncomingFlowNodeSet(returnNode);
4459 // System.out.println("inFlowSet=" + inFlowSet + " from retrunNode=" + returnNode);
4460 for (Iterator iterator2 = inFlowSet.iterator(); iterator2.hasNext();) {
4461 FlowNode inFlowNode = (FlowNode) iterator2.next();
4462 if (inFlowNode.getDescTuple().startsWith(calleeMethodDesc.getThis())) {
4463 nodeSet.addTupleSet(baseNodeSet);
4472 // analyze parameter flows
4474 if (min.numArgs() > 0) {
4477 if (min.getMethod().isStatic()) {
4483 for (int i = 0; i < min.numArgs(); i++) {
4484 ExpressionNode en = min.getArg(i);
4485 int idx = i + offset;
4486 NodeTupleSet argTupleSet = new NodeTupleSet();
4487 analyzeFlowExpressionNode(md, nametable, en, argTupleSet, false);
4488 // if argument is liternal node, argTuple is set to NULL
4490 NTuple<Descriptor> argTuple = new NTuple<Descriptor>();
4491 if (argTupleSet.size() > 1) {
4492 NTuple<Descriptor> interTuple =
4493 getFlowGraph(md).createIntermediateNode().getDescTuple();
4494 for (Iterator<NTuple<Descriptor>> idxIter = argTupleSet.iterator(); idxIter.hasNext();) {
4495 NTuple<Descriptor> tuple = idxIter.next();
4496 addFlowGraphEdge(md, tuple, interTuple);
4498 argTuple = interTuple;
4499 } else if (argTupleSet.size() == 1) {
4500 argTuple = argTupleSet.iterator().next();
4502 argTuple = new NTuple<Descriptor>();
4505 addArgIdxMap(min, idx, argTuple);
4507 FlowNode paramNode = calleeFlowGraph.getParamFlowNode(idx);
4508 if (hasInFlowTo(calleeFlowGraph, paramNode, calleeReturnSet)
4509 || calleeMethodDesc.getModifiers().isNative()) {
4510 addParamNodeFlowingToReturnValue(calleeMethodDesc, paramNode);
4511 nodeSet.addTupleSet(argTupleSet);
4517 // propagateFlowsFromCallee(min, md, min.getMethod());
4519 System.out.println("min nodeSet=" + nodeSet);
4524 private boolean hasInFlowTo(FlowGraph fg, FlowNode inNode, Set<FlowNode> nodeSet) {
4525 // return true if inNode has in-flows to nodeSet
4527 // Set<FlowNode> reachableSet = fg.getReachFlowNodeSetFrom(inNode);
4528 Set<FlowNode> reachableSet = fg.getReachableSetFrom(inNode.getDescTuple());
4529 System.out.println("inNode=" + inNode + " reachalbeSet=" + reachableSet);
4531 for (Iterator iterator = reachableSet.iterator(); iterator.hasNext();) {
4532 FlowNode fn = (FlowNode) iterator.next();
4533 if (nodeSet.contains(fn)) {
4540 private NTuple<Descriptor> getNodeTupleByArgIdx(MethodInvokeNode min, int idx) {
4541 return mapMethodInvokeNodeToArgIdxMap.get(min).get(new Integer(idx));
4544 private void addArgIdxMap(MethodInvokeNode min, int idx, NTuple<Descriptor> argTuple /*
4548 Map<Integer, NTuple<Descriptor>> mapIdxToTuple = mapMethodInvokeNodeToArgIdxMap.get(min);
4549 if (mapIdxToTuple == null) {
4550 mapIdxToTuple = new HashMap<Integer, NTuple<Descriptor>>();
4551 mapMethodInvokeNodeToArgIdxMap.put(min, mapIdxToTuple);
4553 mapIdxToTuple.put(new Integer(idx), argTuple);
4556 private void analyzeLiteralNode(MethodDescriptor md, SymbolTable nametable, LiteralNode en) {
4560 private void analyzeFlowArrayAccessNode(MethodDescriptor md, SymbolTable nametable,
4561 ArrayAccessNode aan, NodeTupleSet nodeSet, boolean isLHS) {
4563 NodeTupleSet expNodeTupleSet = new NodeTupleSet();
4564 NTuple<Descriptor> base =
4565 analyzeFlowExpressionNode(md, nametable, aan.getExpression(), expNodeTupleSet, isLHS);
4567 NodeTupleSet idxNodeTupleSet = new NodeTupleSet();
4568 analyzeFlowExpressionNode(md, nametable, aan.getIndex(), idxNodeTupleSet, isLHS);
4571 // need to create an edge from idx to array
4572 for (Iterator<NTuple<Descriptor>> idxIter = idxNodeTupleSet.iterator(); idxIter.hasNext();) {
4573 NTuple<Descriptor> idxTuple = idxIter.next();
4574 for (Iterator<NTuple<Descriptor>> arrIter = expNodeTupleSet.iterator(); arrIter.hasNext();) {
4575 NTuple<Descriptor> arrTuple = arrIter.next();
4576 getFlowGraph(md).addValueFlowEdge(idxTuple, arrTuple);
4580 nodeSet.addTupleSet(expNodeTupleSet);
4582 nodeSet.addTupleSet(expNodeTupleSet);
4583 nodeSet.addTupleSet(idxNodeTupleSet);
4587 private void analyzeCreateObjectNode(MethodDescriptor md, SymbolTable nametable,
4588 CreateObjectNode en) {
4589 // TODO Auto-generated method stub
4593 private void analyzeFlowOpNode(MethodDescriptor md, SymbolTable nametable, OpNode on,
4594 NodeTupleSet nodeSet, NodeTupleSet implicitFlowTupleSet) {
4596 NodeTupleSet leftOpSet = new NodeTupleSet();
4597 NodeTupleSet rightOpSet = new NodeTupleSet();
4600 analyzeFlowExpressionNode(md, nametable, on.getLeft(), leftOpSet, null, implicitFlowTupleSet,
4603 if (on.getRight() != null) {
4605 analyzeFlowExpressionNode(md, nametable, on.getRight(), rightOpSet, null,
4606 implicitFlowTupleSet, false);
4609 Operation op = on.getOp();
4611 switch (op.getOp()) {
4613 case Operation.UNARYPLUS:
4614 case Operation.UNARYMINUS:
4615 case Operation.LOGIC_NOT:
4617 nodeSet.addTupleSet(leftOpSet);
4620 case Operation.LOGIC_OR:
4621 case Operation.LOGIC_AND:
4622 case Operation.COMP:
4623 case Operation.BIT_OR:
4624 case Operation.BIT_XOR:
4625 case Operation.BIT_AND:
4626 case Operation.ISAVAILABLE:
4627 case Operation.EQUAL:
4628 case Operation.NOTEQUAL:
4635 case Operation.MULT:
4638 case Operation.LEFTSHIFT:
4639 case Operation.RIGHTSHIFT:
4640 case Operation.URIGHTSHIFT:
4642 // there are two operands
4643 nodeSet.addTupleSet(leftOpSet);
4644 nodeSet.addTupleSet(rightOpSet);
4648 throw new Error(op.toString());
4653 private NTuple<Descriptor> analyzeFlowNameNode(MethodDescriptor md, SymbolTable nametable,
4654 NameNode nn, NodeTupleSet nodeSet, NTuple<Descriptor> base, NodeTupleSet implicitFlowTupleSet) {
4656 // System.out.println("analyzeFlowNameNode=" + nn.printNode(0));
4659 base = new NTuple<Descriptor>();
4662 NameDescriptor nd = nn.getName();
4664 if (nd.getBase() != null) {
4666 analyzeFlowExpressionNode(md, nametable, nn.getExpression(), nodeSet, base,
4667 implicitFlowTupleSet, false);
4669 // base node has the top location
4673 String varname = nd.toString();
4674 if (varname.equals("this")) {
4676 base.add(md.getThis());
4680 Descriptor d = (Descriptor) nametable.get(varname);
4682 if (d instanceof VarDescriptor) {
4683 VarDescriptor vd = (VarDescriptor) d;
4685 } else if (d instanceof FieldDescriptor) {
4686 // the type of field descriptor has a location!
4687 FieldDescriptor fd = (FieldDescriptor) d;
4688 if (fd.isStatic()) {
4690 // if it is 'static final', no need to have flow node for the TOP
4694 // if 'static', assign the default GLOBAL LOCATION to the first
4695 // element of the tuple
4696 base.add(GLOBALDESC);
4699 // the location of field access starts from this, followed by field
4701 base.add(md.getThis());
4705 } else if (d == null) {
4706 // access static field
4707 base.add(GLOBALDESC);
4708 base.add(nn.getField());
4711 // FieldDescriptor fd = nn.getField();addFlowGraphEdge
4713 // MethodLattice<String> localLattice = ssjava.getMethodLattice(md);
4714 // String globalLocId = localLattice.getGlobalLoc();
4715 // if (globalLocId == null) {
4717 // Error("Method lattice does not define global variable location at "
4718 // + generateErrorMessage(md.getClassDesc(), nn));
4720 // loc.addLocation(new Location(md, globalLocId));
4722 // Location fieldLoc = (Location) fd.getType().getExtension();
4723 // loc.addLocation(fieldLoc);
4729 getFlowGraph(md).createNewFlowNode(base);
4735 private NTuple<Descriptor> analyzeFlowFieldAccessNode(MethodDescriptor md, SymbolTable nametable,
4736 FieldAccessNode fan, NodeTupleSet nodeSet, NTuple<Descriptor> base,
4737 NodeTupleSet implicitFlowTupleSet, boolean isLHS) {
4739 ExpressionNode left = fan.getExpression();
4740 TypeDescriptor ltd = left.getType();
4741 FieldDescriptor fd = fan.getField();
4743 String varName = null;
4744 if (left.kind() == Kind.NameNode) {
4745 NameDescriptor nd = ((NameNode) left).getName();
4746 varName = nd.toString();
4749 if (ltd.isClassNameRef() || (varName != null && varName.equals("this"))) {
4750 // using a class name directly or access using this
4751 if (fd.isStatic() && fd.isFinal()) {
4756 NodeTupleSet idxNodeTupleSet = new NodeTupleSet();
4758 if (left instanceof ArrayAccessNode) {
4760 ArrayAccessNode aan = (ArrayAccessNode) left;
4761 left = aan.getExpression();
4762 analyzeFlowExpressionNode(md, nametable, aan.getIndex(), idxNodeTupleSet, base,
4763 implicitFlowTupleSet, isLHS);
4765 nodeSet.addTupleSet(idxNodeTupleSet);
4768 analyzeFlowExpressionNode(md, nametable, left, nodeSet, base, implicitFlowTupleSet, isLHS);
4771 // in this case, field is TOP location
4775 NTuple<Descriptor> flowFieldTuple = new NTuple<Descriptor>(base.toList());
4777 if (!left.getType().isPrimitive()) {
4779 if (!fd.getSymbol().equals("length")) {
4780 // array.length access, just have the location of the array
4781 flowFieldTuple.add(fd);
4782 nodeSet.removeTuple(base);
4786 getFlowGraph(md).createNewFlowNode(flowFieldTuple);
4789 for (Iterator<NTuple<Descriptor>> idxIter = idxNodeTupleSet.iterator(); idxIter.hasNext();) {
4790 NTuple<Descriptor> idxTuple = idxIter.next();
4791 getFlowGraph(md).addValueFlowEdge(idxTuple, flowFieldTuple);
4794 return flowFieldTuple;
4800 private void debug_printTreeNode(TreeNode tn) {
4802 System.out.println("DEBUG: " + tn.printNode(0) + " line#=" + tn.getNumLine());
4806 private void analyzeFlowAssignmentNode(MethodDescriptor md, SymbolTable nametable,
4807 AssignmentNode an, NodeTupleSet nodeSet, NTuple<Descriptor> base,
4808 NodeTupleSet implicitFlowTupleSet) {
4810 NodeTupleSet nodeSetRHS = new NodeTupleSet();
4811 NodeTupleSet nodeSetLHS = new NodeTupleSet();
4813 boolean postinc = true;
4814 if (an.getOperation().getBaseOp() == null
4815 || (an.getOperation().getBaseOp().getOp() != Operation.POSTINC && an.getOperation()
4816 .getBaseOp().getOp() != Operation.POSTDEC)) {
4819 // if LHS is array access node, need to capture value flows between an array
4820 // and its index value
4821 analyzeFlowExpressionNode(md, nametable, an.getDest(), nodeSetLHS, null, implicitFlowTupleSet,
4825 // analyze value flows of rhs expression
4826 analyzeFlowExpressionNode(md, nametable, an.getSrc(), nodeSetRHS, null, implicitFlowTupleSet,
4829 // System.out.println("-analyzeFlowAssignmentNode=" + an.printNode(0));
4830 // System.out.println("-nodeSetLHS=" + nodeSetLHS);
4831 // System.out.println("-nodeSetRHS=" + nodeSetRHS);
4832 // System.out.println("-implicitFlowTupleSet=" + implicitFlowTupleSet);
4833 // System.out.println("-");
4835 if (an.getOperation().getOp() >= 2 && an.getOperation().getOp() <= 12) {
4836 // if assignment contains OP+EQ operator, creates edges from LHS to LHS
4838 for (Iterator<NTuple<Descriptor>> iter = nodeSetLHS.iterator(); iter.hasNext();) {
4839 NTuple<Descriptor> fromTuple = iter.next();
4840 for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
4841 NTuple<Descriptor> toTuple = iter2.next();
4842 addFlowGraphEdge(md, fromTuple, toTuple);
4847 // creates edges from RHS to LHS
4848 NTuple<Descriptor> interTuple = null;
4849 if (nodeSetRHS.size() > 1) {
4850 interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
4853 for (Iterator<NTuple<Descriptor>> iter = nodeSetRHS.iterator(); iter.hasNext();) {
4854 NTuple<Descriptor> fromTuple = iter.next();
4855 for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
4856 NTuple<Descriptor> toTuple = iter2.next();
4857 addFlowGraphEdge(md, fromTuple, interTuple, toTuple);
4861 // creates edges from implicitFlowTupleSet to LHS
4862 for (Iterator<NTuple<Descriptor>> iter = implicitFlowTupleSet.iterator(); iter.hasNext();) {
4863 NTuple<Descriptor> fromTuple = iter.next();
4864 for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
4865 NTuple<Descriptor> toTuple = iter2.next();
4866 addFlowGraphEdge(md, fromTuple, toTuple);
4873 for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
4874 NTuple<Descriptor> tuple = iter2.next();
4875 addFlowGraphEdge(md, tuple, tuple);
4878 // creates edges from implicitFlowTupleSet to LHS
4879 for (Iterator<NTuple<Descriptor>> iter = implicitFlowTupleSet.iterator(); iter.hasNext();) {
4880 NTuple<Descriptor> fromTuple = iter.next();
4881 for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
4882 NTuple<Descriptor> toTuple = iter2.next();
4883 addFlowGraphEdge(md, fromTuple, toTuple);
4889 if (nodeSet != null) {
4890 nodeSet.addTupleSet(nodeSetLHS);
4894 public FlowGraph getFlowGraph(MethodDescriptor md) {
4895 return mapMethodDescriptorToFlowGraph.get(md);
4898 private boolean addFlowGraphEdge(MethodDescriptor md, NTuple<Descriptor> from,
4899 NTuple<Descriptor> to) {
4900 FlowGraph graph = getFlowGraph(md);
4901 graph.addValueFlowEdge(from, to);
4905 private void addFlowGraphEdge(MethodDescriptor md, NTuple<Descriptor> from,
4906 NTuple<Descriptor> inter, NTuple<Descriptor> to) {
4908 FlowGraph graph = getFlowGraph(md);
4910 if (inter != null) {
4911 graph.addValueFlowEdge(from, inter);
4912 graph.addValueFlowEdge(inter, to);
4914 graph.addValueFlowEdge(from, to);
4919 public void writeInferredLatticeDotFile(ClassDescriptor cd, HierarchyGraph simpleHierarchyGraph,
4920 SSJavaLattice<String> locOrder, String nameSuffix) {
4921 writeInferredLatticeDotFile(cd, null, simpleHierarchyGraph, locOrder, nameSuffix);
4924 public void writeInferredLatticeDotFile(ClassDescriptor cd, MethodDescriptor md,
4925 HierarchyGraph simpleHierarchyGraph, SSJavaLattice<String> locOrder, String nameSuffix) {
4927 String fileName = "lattice_";
4930 cd.getSymbol().replaceAll("[\\W_]", "") + "_" + md.toString().replaceAll("[\\W_]", "");
4932 fileName += cd.getSymbol().replaceAll("[\\W_]", "");
4935 fileName += nameSuffix;
4937 Set<Pair<String, String>> pairSet = locOrder.getOrderingPairSet();
4939 Set<String> addedLocSet = new HashSet<String>();
4941 if (pairSet.size() > 0) {
4943 BufferedWriter bw = new BufferedWriter(new FileWriter(fileName + ".dot"));
4945 bw.write("digraph " + fileName + " {\n");
4947 for (Iterator iterator = pairSet.iterator(); iterator.hasNext();) {
4948 // pair is in the form of <higher, lower>
4949 Pair<String, String> pair = (Pair<String, String>) iterator.next();
4951 String highLocId = pair.getFirst();
4952 String lowLocId = pair.getSecond();
4954 if (!addedLocSet.contains(highLocId)) {
4955 addedLocSet.add(highLocId);
4956 drawNode(bw, locOrder, simpleHierarchyGraph, highLocId);
4959 if (!addedLocSet.contains(lowLocId)) {
4960 addedLocSet.add(lowLocId);
4961 drawNode(bw, locOrder, simpleHierarchyGraph, lowLocId);
4964 bw.write(highLocId + " -> " + lowLocId + ";\n");
4969 } catch (IOException e) {
4970 e.printStackTrace();
4977 private String convertMergeSetToString(HierarchyGraph graph, Set<HNode> mergeSet) {
4979 for (Iterator iterator = mergeSet.iterator(); iterator.hasNext();) {
4980 HNode merged = (HNode) iterator.next();
4981 if (merged.isMergeNode()) {
4982 str += convertMergeSetToString(graph, graph.getMapHNodetoMergeSet().get(merged));
4984 str += " " + merged.getName();
4990 private void drawNode(BufferedWriter bw, SSJavaLattice<String> lattice, HierarchyGraph graph,
4991 String locName) throws IOException {
4993 HNode node = graph.getHNode(locName);
5000 if (lattice.isSharedLoc(locName)) {
5001 prettyStr = locName + "*";
5003 prettyStr = locName;
5006 if (node.isMergeNode()) {
5007 Set<HNode> mergeSet = graph.getMapHNodetoMergeSet().get(node);
5008 prettyStr += ":" + convertMergeSetToString(graph, mergeSet);
5010 bw.write(locName + " [label=\"" + prettyStr + "\"]" + ";\n");
5013 public void _debug_printGraph() {
5014 Set<MethodDescriptor> keySet = mapMethodDescriptorToFlowGraph.keySet();
5016 for (Iterator<MethodDescriptor> iterator = keySet.iterator(); iterator.hasNext();) {
5017 MethodDescriptor md = (MethodDescriptor) iterator.next();
5018 FlowGraph fg = mapMethodDescriptorToFlowGraph.get(md);
5021 } catch (IOException e) {
5022 e.printStackTrace();
5030 class CyclicFlowException extends Exception {
5034 class InterDescriptor extends Descriptor {
5036 public InterDescriptor(String name) {