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();
1734 if ((srcCurTuple.size() > 1 && dstCurTuple.size() > 1)
1735 && srcCurTuple.get(0).equals(dstCurTuple.get(0))) {
1737 // value flows between fields
1738 Descriptor desc = srcCurTuple.get(0);
1739 ClassDescriptor classDesc;
1741 if (desc.equals(GLOBALDESC)) {
1742 classDesc = md.getClassDesc();
1744 VarDescriptor varDesc = (VarDescriptor) srcCurTuple.get(0);
1745 classDesc = varDesc.getType().getClassDesc();
1747 extractFlowsBetweenFields(classDesc, srcNode, dstNode, 1);
1750 // value flow between local var - local var or local var - field
1752 Descriptor srcDesc = srcCurTuple.get(0);
1753 Descriptor dstDesc = dstCurTuple.get(0);
1755 methodGraph.addEdge(srcDesc, dstDesc);
1757 if (fg.isParamDesc(srcDesc)) {
1758 methodGraph.setParamHNode(srcDesc);
1760 if (fg.isParamDesc(dstDesc)) {
1761 methodGraph.setParamHNode(dstDesc);
1770 // If the method accesses static fields
1771 // set hasGloabalAccess true in the method summary.
1772 if (hasGlobalAccess) {
1773 getMethodSummary(md).setHasGlobalAccess();
1775 methodGraph.getHNode(GLOBALDESC).setSkeleton(true);
1779 private MethodSummary getMethodSummary(MethodDescriptor md) {
1780 if (!mapDescToLocationSummary.containsKey(md)) {
1781 mapDescToLocationSummary.put(md, new MethodSummary(md));
1783 return (MethodSummary) mapDescToLocationSummary.get(md);
1786 private void addMapClassDefinitionToLineNum(ClassDescriptor cd, String strLine, int lineNum) {
1788 String classSymbol = cd.getSymbol();
1789 int idx = classSymbol.lastIndexOf("$");
1791 classSymbol = classSymbol.substring(idx + 1);
1794 String pattern = "class " + classSymbol + " ";
1795 if (strLine.indexOf(pattern) != -1) {
1796 mapDescToDefinitionLine.put(cd, lineNum);
1800 private void addMapMethodDefinitionToLineNum(Set<MethodDescriptor> methodSet, String strLine,
1802 for (Iterator iterator = methodSet.iterator(); iterator.hasNext();) {
1803 MethodDescriptor md = (MethodDescriptor) iterator.next();
1804 String pattern = md.getMethodDeclaration();
1805 if (strLine.indexOf(pattern) != -1) {
1806 mapDescToDefinitionLine.put(md, lineNum);
1807 methodSet.remove(md);
1814 private void readOriginalSourceFiles() {
1816 SymbolTable classtable = state.getClassSymbolTable();
1818 Set<ClassDescriptor> classDescSet = new HashSet<ClassDescriptor>();
1819 classDescSet.addAll(classtable.getValueSet());
1822 // inefficient implement. it may re-visit the same file if the file
1823 // contains more than one class definitions.
1824 for (Iterator iterator = classDescSet.iterator(); iterator.hasNext();) {
1825 ClassDescriptor cd = (ClassDescriptor) iterator.next();
1827 Set<MethodDescriptor> methodSet = new HashSet<MethodDescriptor>();
1828 methodSet.addAll(cd.getMethodTable().getValueSet());
1830 String sourceFileName = cd.getSourceFileName();
1831 Vector<String> lineVec = new Vector<String>();
1833 mapFileNameToLineVector.put(sourceFileName, lineVec);
1835 BufferedReader in = new BufferedReader(new FileReader(sourceFileName));
1838 lineVec.add(""); // the index is started from 1.
1839 while ((strLine = in.readLine()) != null) {
1840 lineVec.add(lineNum, strLine);
1841 addMapClassDefinitionToLineNum(cd, strLine, lineNum);
1842 addMapMethodDefinitionToLineNum(methodSet, strLine, lineNum);
1848 } catch (IOException e) {
1849 e.printStackTrace();
1854 private String generateLatticeDefinition(Descriptor desc) {
1856 Set<String> sharedLocSet = new HashSet<String>();
1858 SSJavaLattice<String> lattice = getLattice(desc);
1859 String rtr = "@LATTICE(\"";
1861 Map<String, Set<String>> map = lattice.getTable();
1862 Set<String> keySet = map.keySet();
1863 boolean first = true;
1864 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
1865 String key = (String) iterator.next();
1866 if (!key.equals(lattice.getTopItem())) {
1867 Set<String> connectedSet = map.get(key);
1869 if (connectedSet.size() == 1) {
1870 if (connectedSet.iterator().next().equals(lattice.getBottomItem())) {
1878 if (lattice.isSharedLoc(key)) {
1879 rtr += "," + key + "*";
1884 for (Iterator iterator2 = connectedSet.iterator(); iterator2.hasNext();) {
1885 String loc = (String) iterator2.next();
1886 if (!loc.equals(lattice.getBottomItem())) {
1893 rtr += loc + "<" + key;
1894 if (lattice.isSharedLoc(key) && (!sharedLocSet.contains(key))) {
1895 rtr += "," + key + "*";
1896 sharedLocSet.add(key);
1898 if (lattice.isSharedLoc(loc) && (!sharedLocSet.contains(loc))) {
1899 rtr += "," + loc + "*";
1900 sharedLocSet.add(loc);
1910 if (desc instanceof MethodDescriptor) {
1911 System.out.println("#EXTRA LOC DECLARATION GEN=" + desc);
1913 MethodSummary methodSummary = getMethodSummary((MethodDescriptor) desc);
1915 if (!ssjava.getMethodContainingSSJavaLoop().equals(desc)) {
1916 TypeDescriptor returnType = ((MethodDescriptor) desc).getReturnType();
1917 if (returnType != null && (!returnType.isVoid())) {
1919 "\n@RETURNLOC(\"" + generateLocationAnnoatation(methodSummary.getRETURNLoc()) + "\")";
1921 CompositeLocation pcLoc = methodSummary.getPCLoc();
1922 if ((pcLoc != null) && (!pcLoc.get(0).isTop())) {
1923 rtr += "\n@PCLOC(\"" + generateLocationAnnoatation(pcLoc) + "\")";
1927 rtr += "\n@THISLOC(\"" + methodSummary.getThisLocName() + "\")";
1928 rtr += "\n@GLOBALLOC(\"" + methodSummary.getGlobalLocName() + "\")";
1935 private void generateAnnoatedCode() {
1937 readOriginalSourceFiles();
1940 while (!toAnalyzeIsEmpty()) {
1941 ClassDescriptor cd = toAnalyzeNext();
1943 setupToAnalazeMethod(cd);
1945 String sourceFileName = cd.getSourceFileName();
1947 if (cd.isInterface()) {
1951 int classDefLine = mapDescToDefinitionLine.get(cd);
1952 Vector<String> sourceVec = mapFileNameToLineVector.get(sourceFileName);
1954 LocationSummary fieldLocSummary = getLocationSummary(cd);
1956 String fieldLatticeDefStr = generateLatticeDefinition(cd);
1957 String annoatedSrc = fieldLatticeDefStr + newline + sourceVec.get(classDefLine);
1958 sourceVec.set(classDefLine, annoatedSrc);
1960 // generate annotations for field declarations
1961 // Map<Descriptor, CompositeLocation> inferLocMap = fieldLocInfo.getMapDescToInferLocation();
1962 Map<String, String> mapFieldNameToLocName = fieldLocSummary.getMapHNodeNameToLocationName();
1964 for (Iterator iter = cd.getFields(); iter.hasNext();) {
1965 FieldDescriptor fd = (FieldDescriptor) iter.next();
1967 String locAnnotationStr;
1968 // CompositeLocation inferLoc = inferLocMap.get(fd);
1969 String locName = mapFieldNameToLocName.get(fd.getSymbol());
1971 if (locName != null) {
1972 // infer loc is null if the corresponding field is static and final
1973 // locAnnotationStr = "@LOC(\"" + generateLocationAnnoatation(inferLoc) + "\")";
1974 locAnnotationStr = "@LOC(\"" + locName + "\")";
1975 int fdLineNum = fd.getLineNum();
1976 String orgFieldDeclarationStr = sourceVec.get(fdLineNum);
1977 String fieldDeclaration = fd.toString();
1978 fieldDeclaration = fieldDeclaration.substring(0, fieldDeclaration.length() - 1);
1979 String annoatedStr = locAnnotationStr + " " + orgFieldDeclarationStr;
1980 sourceVec.set(fdLineNum, annoatedStr);
1985 while (!toAnalyzeMethodIsEmpty()) {
1986 MethodDescriptor md = toAnalyzeMethodNext();
1988 if (!ssjava.needTobeAnnotated(md)) {
1992 SSJavaLattice<String> methodLattice = md2lattice.get(md);
1993 if (methodLattice != null) {
1995 int methodDefLine = md.getLineNum();
1997 // MethodLocationInfo methodLocInfo = getMethodLocationInfo(md);
1998 // Map<Descriptor, CompositeLocation> methodInferLocMap =
1999 // methodLocInfo.getMapDescToInferLocation();
2001 MethodSummary methodSummary = getMethodSummary(md);
2003 Map<Descriptor, CompositeLocation> mapVarDescToInferLoc =
2004 methodSummary.getMapVarDescToInferCompositeLocation();
2005 System.out.println("-----md=" + md);
2006 System.out.println("-----mapVarDescToInferLoc=" + mapVarDescToInferLoc);
2008 Set<Descriptor> localVarDescSet = mapVarDescToInferLoc.keySet();
2010 Set<String> localLocElementSet = methodLattice.getElementSet();
2012 for (Iterator iterator = localVarDescSet.iterator(); iterator.hasNext();) {
2013 Descriptor localVarDesc = (Descriptor) iterator.next();
2014 System.out.println("-------localVarDesc=" + localVarDesc);
2015 CompositeLocation inferLoc = mapVarDescToInferLoc.get(localVarDesc);
2017 String localLocIdentifier = inferLoc.get(0).getLocIdentifier();
2018 if (!localLocElementSet.contains(localLocIdentifier)) {
2019 methodLattice.put(localLocIdentifier);
2022 String locAnnotationStr = "@LOC(\"" + generateLocationAnnoatation(inferLoc) + "\")";
2024 if (!isParameter(md, localVarDesc)) {
2025 if (mapDescToDefinitionLine.containsKey(localVarDesc)) {
2026 int varLineNum = mapDescToDefinitionLine.get(localVarDesc);
2027 String orgSourceLine = sourceVec.get(varLineNum);
2029 orgSourceLine.indexOf(generateVarDeclaration((VarDescriptor) localVarDesc));
2031 String annoatedStr =
2032 orgSourceLine.substring(0, idx) + locAnnotationStr + " "
2033 + orgSourceLine.substring(idx);
2034 sourceVec.set(varLineNum, annoatedStr);
2037 String methodDefStr = sourceVec.get(methodDefLine);
2040 getParamLocation(methodDefStr,
2041 generateVarDeclaration((VarDescriptor) localVarDesc));
2045 String annoatedStr =
2046 methodDefStr.substring(0, idx) + locAnnotationStr + " "
2047 + methodDefStr.substring(idx);
2048 sourceVec.set(methodDefLine, annoatedStr);
2053 // check if the lattice has to have the location type for the this
2056 // boolean needToAddthisRef = hasThisReference(md);
2057 // if (localLocElementSet.contains("this")) {
2058 // methodLattice.put("this");
2061 String methodLatticeDefStr = generateLatticeDefinition(md);
2062 String annoatedStr = methodLatticeDefStr + newline + sourceVec.get(methodDefLine);
2063 sourceVec.set(methodDefLine, annoatedStr);
2073 private boolean hasThisReference(MethodDescriptor md) {
2075 FlowGraph fg = getFlowGraph(md);
2076 Set<FlowNode> nodeSet = fg.getNodeSet();
2077 for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
2078 FlowNode flowNode = (FlowNode) iterator.next();
2079 if (flowNode.getDescTuple().get(0).equals(md.getThis())) {
2087 private int getParamLocation(String methodStr, String paramStr) {
2089 String pattern = paramStr + ",";
2091 int idx = methodStr.indexOf(pattern);
2095 pattern = paramStr + ")";
2096 return methodStr.indexOf(pattern);
2101 private String generateVarDeclaration(VarDescriptor varDesc) {
2103 TypeDescriptor td = varDesc.getType();
2104 String rtr = td.toString();
2106 for (int i = 0; i < td.getArrayCount(); i++) {
2110 rtr += " " + varDesc.getName();
2115 private String generateLocationAnnoatation(CompositeLocation loc) {
2116 System.out.println("loc=" + loc);
2119 Location methodLoc = loc.get(0);
2120 rtr += methodLoc.getLocIdentifier();
2122 for (int i = 1; i < loc.getSize(); i++) {
2123 Location element = loc.get(i);
2124 rtr += "," + element.getDescriptor().getSymbol() + "." + element.getLocIdentifier();
2130 private boolean isParameter(MethodDescriptor md, Descriptor localVarDesc) {
2131 return getFlowGraph(md).isParamDesc(localVarDesc);
2134 private String extractFileName(String fileName) {
2135 int idx = fileName.lastIndexOf("/");
2139 return fileName.substring(idx + 1);
2144 private void codeGen() {
2146 Set<String> originalFileNameSet = mapFileNameToLineVector.keySet();
2147 for (Iterator iterator = originalFileNameSet.iterator(); iterator.hasNext();) {
2148 String orgFileName = (String) iterator.next();
2149 String outputFileName = extractFileName(orgFileName);
2151 Vector<String> sourceVec = mapFileNameToLineVector.get(orgFileName);
2155 FileWriter fileWriter = new FileWriter("./infer/" + outputFileName);
2156 BufferedWriter out = new BufferedWriter(fileWriter);
2158 for (int i = 0; i < sourceVec.size(); i++) {
2159 out.write(sourceVec.get(i));
2163 } catch (IOException e) {
2164 e.printStackTrace();
2171 private void checkLattices() {
2173 LinkedList<MethodDescriptor> descriptorListToAnalyze = ssjava.getSortedDescriptors();
2175 // current descriptors to visit in fixed-point interprocedural analysis,
2177 // dependency in the call graph
2178 methodDescriptorsToVisitStack.clear();
2180 // descriptorListToAnalyze.removeFirst();
2182 Set<MethodDescriptor> methodDescriptorToVistSet = new HashSet<MethodDescriptor>();
2183 methodDescriptorToVistSet.addAll(descriptorListToAnalyze);
2185 while (!descriptorListToAnalyze.isEmpty()) {
2186 MethodDescriptor md = descriptorListToAnalyze.removeFirst();
2187 checkLatticesOfVirtualMethods(md);
2192 private void debug_writeLatticeDotFile() {
2193 // generate lattice dot file
2197 while (!toAnalyzeIsEmpty()) {
2198 ClassDescriptor cd = toAnalyzeNext();
2200 setupToAnalazeMethod(cd);
2202 SSJavaLattice<String> classLattice = cd2lattice.get(cd);
2203 if (classLattice != null) {
2204 ssjava.writeLatticeDotFile(cd, null, classLattice);
2205 debug_printDescriptorToLocNameMapping(cd);
2208 while (!toAnalyzeMethodIsEmpty()) {
2209 MethodDescriptor md = toAnalyzeMethodNext();
2210 SSJavaLattice<String> methodLattice = md2lattice.get(md);
2211 if (methodLattice != null) {
2212 ssjava.writeLatticeDotFile(cd, md, methodLattice);
2213 debug_printDescriptorToLocNameMapping(md);
2220 private void debug_printDescriptorToLocNameMapping(Descriptor desc) {
2222 LocationInfo info = getLocationInfo(desc);
2223 System.out.println("## " + desc + " ##");
2224 System.out.println(info.getMapDescToInferLocation());
2225 LocationInfo locInfo = getLocationInfo(desc);
2226 System.out.println("mapping=" + locInfo.getMapLocSymbolToDescSet());
2227 System.out.println("###################");
2231 private void inferLattices() {
2234 private void calculateExtraLocations() {
2235 LinkedList<MethodDescriptor> descriptorListToAnalyze = ssjava.getSortedDescriptors();
2236 for (Iterator iterator = descriptorListToAnalyze.iterator(); iterator.hasNext();) {
2237 MethodDescriptor md = (MethodDescriptor) iterator.next();
2238 if (!ssjava.getMethodContainingSSJavaLoop().equals(md)) {
2239 calculateExtraLocations(md);
2244 private void checkLatticesOfVirtualMethods(MethodDescriptor md) {
2246 if (!md.isStatic()) {
2247 Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
2248 setPossibleCallees.addAll(ssjava.getCallGraph().getMethods(md));
2250 for (Iterator iterator = setPossibleCallees.iterator(); iterator.hasNext();) {
2251 MethodDescriptor mdCallee = (MethodDescriptor) iterator.next();
2252 if (!md.equals(mdCallee)) {
2253 checkConsistency(md, mdCallee);
2261 private void checkConsistency(MethodDescriptor md1, MethodDescriptor md2) {
2263 // check that two lattice have the same relations between parameters(+PC
2264 // LOC, GLOBAL_LOC RETURN LOC)
2266 List<CompositeLocation> list1 = new ArrayList<CompositeLocation>();
2267 List<CompositeLocation> list2 = new ArrayList<CompositeLocation>();
2269 MethodLocationInfo locInfo1 = getMethodLocationInfo(md1);
2270 MethodLocationInfo locInfo2 = getMethodLocationInfo(md2);
2272 Map<Integer, CompositeLocation> paramMap1 = locInfo1.getMapParamIdxToInferLoc();
2273 Map<Integer, CompositeLocation> paramMap2 = locInfo2.getMapParamIdxToInferLoc();
2275 int numParam = locInfo1.getMapParamIdxToInferLoc().keySet().size();
2277 // add location types of paramters
2278 for (int idx = 0; idx < numParam; idx++) {
2279 list1.add(paramMap1.get(Integer.valueOf(idx)));
2280 list2.add(paramMap2.get(Integer.valueOf(idx)));
2283 // add program counter location
2284 list1.add(locInfo1.getPCLoc());
2285 list2.add(locInfo2.getPCLoc());
2287 if (!md1.getReturnType().isVoid()) {
2288 // add return value location
2289 CompositeLocation rtrLoc1 = getMethodLocationInfo(md1).getReturnLoc();
2290 CompositeLocation rtrLoc2 = getMethodLocationInfo(md2).getReturnLoc();
2295 // add global location type
2296 if (md1.isStatic()) {
2297 CompositeLocation globalLoc1 =
2298 new CompositeLocation(new Location(md1, locInfo1.getGlobalLocName()));
2299 CompositeLocation globalLoc2 =
2300 new CompositeLocation(new Location(md2, locInfo2.getGlobalLocName()));
2301 list1.add(globalLoc1);
2302 list2.add(globalLoc2);
2305 for (int i = 0; i < list1.size(); i++) {
2306 CompositeLocation locA1 = list1.get(i);
2307 CompositeLocation locA2 = list2.get(i);
2308 for (int k = 0; k < list1.size(); k++) {
2310 CompositeLocation locB1 = list1.get(k);
2311 CompositeLocation locB2 = list2.get(k);
2312 boolean r1 = isGreaterThan(getLattice(md1), locA1, locB1);
2314 boolean r2 = isGreaterThan(getLattice(md1), locA2, locB2);
2317 throw new Error("The method " + md1 + " is not consistent with the method " + md2
2318 + ".:: They have a different ordering relation between locations (" + locA1 + ","
2319 + locB1 + ") and (" + locA2 + "," + locB2 + ").");
2327 private String getSymbol(int idx, FlowNode node) {
2328 Descriptor desc = node.getDescTuple().get(idx);
2329 return desc.getSymbol();
2332 private Descriptor getDescriptor(int idx, FlowNode node) {
2333 Descriptor desc = node.getDescTuple().get(idx);
2337 private void calculatePCLOC(MethodDescriptor md) {
2339 System.out.println("#calcualtePCLOC");
2340 MethodSummary methodSummary = getMethodSummary(md);
2341 FlowGraph fg = getFlowGraph(md);
2342 Map<Integer, CompositeLocation> mapParamToLoc = methodSummary.getMapParamIdxToInferLoc();
2344 // calculate the initial program counter location
2345 // PC location is higher than location types of parameters which has incoming flows.
2347 Set<NTuple<Location>> paramLocTupleHavingInFlowSet = 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);
2354 if (fg.getIncomingNodeSetByPrefix(prefix).size() > 0) {
2355 // parameter has in-value flows
2356 NTuple<Descriptor> paramDescTuple = paramFlowNode.getCurrentDescTuple();
2357 NTuple<Location> paramLocTuple = translateToLocTuple(md, paramDescTuple);
2358 paramLocTupleHavingInFlowSet.add(paramLocTuple);
2362 System.out.println("paramLocTupleHavingInFlowSet=" + paramLocTupleHavingInFlowSet);
2364 if (paramLocTupleHavingInFlowSet.size() > 0
2365 && !coversAllParamters(md, fg, paramLocTupleHavingInFlowSet)) {
2367 // Here, generates a location in the method lattice that is higher than the
2368 // paramLocTupleHavingInFlowSet
2369 NTuple<Location> pcLocTuple =
2370 generateLocTupleRelativeTo(md, paramLocTupleHavingInFlowSet, PCLOC);
2372 int pcLocTupleIdx = pcLocTuple.size() - 1;
2373 Location pcLoc = pcLocTuple.get(pcLocTupleIdx);
2374 Descriptor pcDesc = pcLoc.getLocDescriptor();
2375 Descriptor enclosingDesc = pcLocTuple.get(pcLocTupleIdx).getDescriptor();
2377 HierarchyGraph hierarchyGraph = getHierarchyGraph(enclosingDesc);
2378 HNode pcNode = hierarchyGraph.getHNode(pcDesc);
2379 pcNode.setSkeleton(true);
2381 for (Iterator iterator = paramLocTupleHavingInFlowSet.iterator(); iterator.hasNext();) {
2382 NTuple<Location> paramLocTuple = (NTuple<Location>) iterator.next();
2383 if (paramLocTuple.size() > pcLocTupleIdx) {
2384 Descriptor lowerDesc = paramLocTuple.get(pcLocTupleIdx).getLocDescriptor();
2385 hierarchyGraph.addEdge(pcDesc, lowerDesc);
2389 System.out.println("pcLoc=" + pcLoc);
2391 methodSummary.setPCLoc(new CompositeLocation(pcLocTuple));
2395 private boolean coversAllParamters(MethodDescriptor md, FlowGraph fg,
2396 Set<NTuple<Location>> paramLocTupleHavingInFlowSet) {
2398 int numParam = fg.getNumParameters();
2399 int size = paramLocTupleHavingInFlowSet.size();
2401 if (!md.isStatic()) {
2403 // if the method is not static && there is a parameter composite location &&
2404 // it is started with 'this',
2405 // paramLocTupleHavingInFlowSet need to have 'this' parameter.
2407 FlowNode thisParamNode = fg.getParamFlowNode(0);
2408 NTuple<Location> thisParamLocTuple =
2409 translateToLocTuple(md, thisParamNode.getCurrentDescTuple());
2411 if (!paramLocTupleHavingInFlowSet.contains(thisParamLocTuple)) {
2413 for (Iterator iterator = paramLocTupleHavingInFlowSet.iterator(); iterator.hasNext();) {
2414 NTuple<Location> paramTuple = (NTuple<Location>) iterator.next();
2415 if (paramTuple.size() > 1 && paramTuple.get(0).getLocDescriptor().equals(md.getThis())) {
2416 // paramLocTupleHavingInFlowSet.add(thisParamLocTuple);
2425 if (size == numParam) {
2433 private void calculateRETURNLOC(MethodDescriptor md) {
2435 System.out.println("#calculateRETURNLOC= " + md);
2436 // calculate a return location:
2437 // the return location type is lower than all parameters and the location of return values
2439 MethodSummary methodSummary = getMethodSummary(md);
2441 FlowGraph fg = getFlowGraph(md);
2443 Map<Integer, CompositeLocation> mapParamToLoc = methodSummary.getMapParamIdxToInferLoc();
2444 Set<Integer> paramIdxSet = mapParamToLoc.keySet();
2446 if (!md.getReturnType().isVoid()) {
2447 // first, generate the set of return value location types that starts
2448 // with 'this' reference
2450 Set<NTuple<Location>> inferFieldReturnLocSet = new HashSet<NTuple<Location>>();
2452 Set<FlowNode> paramFlowNodeFlowingToReturnValueSet = getParamNodeFlowingToReturnValue(md);
2453 System.out.println("paramFlowNodeFlowingToReturnValueSet="
2454 + paramFlowNodeFlowingToReturnValueSet);
2456 Set<NTuple<Location>> locFlowingToReturnValueSet = new HashSet<NTuple<Location>>();
2457 for (Iterator iterator = paramFlowNodeFlowingToReturnValueSet.iterator(); iterator.hasNext();) {
2458 FlowNode fn = (FlowNode) iterator.next();
2460 NTuple<Descriptor> paramDescTuple = fn.getCurrentDescTuple();
2461 NTuple<Location> paramLocTuple = translateToLocTuple(md, paramDescTuple);
2463 locFlowingToReturnValueSet.add(paramLocTuple);
2466 Set<FlowNode> returnNodeSet = fg.getReturnNodeSet();
2467 for (Iterator iterator = returnNodeSet.iterator(); iterator.hasNext();) {
2468 FlowNode returnNode = (FlowNode) iterator.next();
2469 NTuple<Descriptor> returnDescTuple = returnNode.getCurrentDescTuple();
2470 NTuple<Location> returnLocTuple = translateToLocTuple(md, returnDescTuple);
2471 locFlowingToReturnValueSet.add(returnLocTuple);
2473 System.out.println("locFlowingToReturnValueSet=" + locFlowingToReturnValueSet);
2475 // Here, generates a return location in the method lattice that is lower than the
2476 // locFlowingToReturnValueSet
2477 NTuple<Location> returnLocTuple =
2478 generateLocTupleRelativeTo(md, locFlowingToReturnValueSet, RLOC);
2480 System.out.println("returnLocTuple=" + returnLocTuple);
2482 int returnLocTupleIdx = returnLocTuple.size() - 1;
2483 Location returnLoc = returnLocTuple.get(returnLocTupleIdx);
2484 Descriptor returnDesc = returnLoc.getLocDescriptor();
2485 Descriptor enclosingDesc = returnLocTuple.get(returnLocTupleIdx).getDescriptor();
2487 HierarchyGraph hierarchyGraph = getHierarchyGraph(enclosingDesc);
2488 HNode returnNode = hierarchyGraph.getHNode(returnDesc);
2489 returnNode.setSkeleton(true);
2491 for (Iterator iterator = locFlowingToReturnValueSet.iterator(); iterator.hasNext();) {
2492 NTuple<Location> locTuple = (NTuple<Location>) iterator.next();
2493 Descriptor higherDesc = locTuple.get(returnLocTupleIdx).getLocDescriptor();
2494 hierarchyGraph.addEdge(higherDesc, returnDesc);
2497 methodSummary.setRETURNLoc(new CompositeLocation(returnLocTuple));
2499 // skip: for (Iterator iterator = returnNodeSet.iterator(); iterator.hasNext();) {
2500 // FlowNode returnNode = (FlowNode) iterator.next();
2502 // NTuple<Descriptor> returnDescTuple = returnNode.getCurrentDescTuple();
2503 // NTuple<Location> returnLocTuple = translateToLocTuple(md, returnDescTuple);
2505 // if (returnLocTuple.get(0).getLocDescriptor().equals(md.getThis())) {
2506 // // if the location type of the return value matches "this" reference
2507 // // then, check whether this return value is equal to/lower than all
2508 // // of parameters that possibly flow into the return values
2509 // for (Iterator iterator2 = inferParamLocSet.iterator(); iterator2.hasNext();) {
2510 // CompositeLocation paramInferLoc = (CompositeLocation) iterator2.next();
2512 // if ((!paramInferLoc.equals(returnLocTuple))
2513 // && !isGreaterThan(methodLattice, paramInferLoc, inferReturnLoc)) {
2517 // inferFieldReturnLocSet.add(returnLocTuple);
2522 // if (inferFieldReturnLocSet.size() > 0) {
2524 // // CompositeLocation returnLoc = getLowest(methodLattice, inferFieldReturnLocSet);
2525 // CompositeLocation returnLoc = null;
2526 // if (returnLoc == null) {
2527 // // in this case, assign <'this',bottom> to the RETURNLOC
2528 // returnLoc = new CompositeLocation(new Location(md, md.getThis().getSymbol()));
2529 // returnLoc.addLocation(new Location(md.getClassDesc(), getLattice(md.getClassDesc())
2530 // .getBottomItem()));
2532 // methodInfo.setReturnLoc(returnLoc);
2535 // String returnLocSymbol = "RETURNLOC";
2536 // CompositeLocation returnLocInferLoc =
2537 // new CompositeLocation(new Location(md, returnLocSymbol));
2538 // methodInfo.setReturnLoc(returnLocInferLoc);
2540 // for (Iterator iterator = paramIdxSet.iterator(); iterator.hasNext();) {
2541 // Integer paramIdx = (Integer) iterator.next();
2542 // CompositeLocation inferLoc = mapParamToLoc.get(paramIdx);
2543 // String paramLocLocalSymbol = inferLoc.get(0).getLocIdentifier();
2544 // if (!methodLattice.isGreaterThan(paramLocLocalSymbol, returnLocSymbol)) {
2546 // // addRelationHigherToLower(methodLattice, methodInfo,
2547 // // paramLocLocalSymbol,
2548 // // returnLocSymbol);
2552 // for (Iterator iterator = returnNodeSet.iterator(); iterator.hasNext();) {
2553 // FlowNode returnNode = (FlowNode) iterator.next();
2554 // CompositeLocation inferLoc =
2555 // generateInferredCompositeLocation(methodInfo, fg.getLocationTuple(returnNode));
2556 // if (!isGreaterThan(methodLattice, inferLoc, returnLocInferLoc)) {
2558 // // addRelation(methodLattice, methodInfo, inferLoc,
2559 // // returnLocInferLoc);
2568 private void calculateExtraLocations(MethodDescriptor md) {
2569 // calcualte pcloc, returnloc,...
2571 System.out.println("\nSSJAVA:Calculate PCLOC/RETURNLOC locations: " + md);
2574 calculateRETURNLOC(md);
2578 private NTuple<Location> generateLocTupleRelativeTo(MethodDescriptor md,
2579 Set<NTuple<Location>> paramLocTupleHavingInFlowSet, String locNamePrefix) {
2581 System.out.println("-generateLocTupleRelativeTo=" + paramLocTupleHavingInFlowSet);
2583 NTuple<Location> higherLocTuple = new NTuple<Location>();
2585 VarDescriptor thisVarDesc = md.getThis();
2586 // check if all paramter loc tuple is started with 'this' reference
2587 boolean hasParamNotStartedWithThisRef = false;
2591 Set<NTuple<Location>> paramLocTupleStartedWithThis = new HashSet<NTuple<Location>>();
2593 for (Iterator iterator = paramLocTupleHavingInFlowSet.iterator(); iterator.hasNext();) {
2594 NTuple<Location> paramLocTuple = (NTuple<Location>) iterator.next();
2595 if (!paramLocTuple.get(0).getLocDescriptor().equals(thisVarDesc)) {
2596 hasParamNotStartedWithThisRef = true;
2597 } else if (paramLocTuple.size() > 1) {
2598 paramLocTupleStartedWithThis.add(paramLocTuple);
2599 if (minSize == 0 || minSize > paramLocTuple.size()) {
2600 minSize = paramLocTuple.size();
2605 System.out.println("---paramLocTupleStartedWithThis=" + paramLocTupleStartedWithThis);
2606 Descriptor enclosingDesc = md;
2607 if (hasParamNotStartedWithThisRef) {
2608 // in this case, PCLOC will be the local location
2610 // all parameter is started with 'this', so PCLOC will be set relative to the composite
2611 // location started with 'this'.
2612 for (int idx = 0; idx < minSize - 1; idx++) {
2613 Set<Descriptor> locDescSet = new HashSet<Descriptor>();
2614 Location curLoc = null;
2615 NTuple<Location> paramLocTuple = null;
2616 for (Iterator iterator = paramLocTupleStartedWithThis.iterator(); iterator.hasNext();) {
2617 paramLocTuple = (NTuple<Location>) iterator.next();
2618 System.out.println("-----paramLocTuple=" + paramLocTuple + " idx=" + idx);
2619 curLoc = paramLocTuple.get(idx);
2620 Descriptor locDesc = curLoc.getLocDescriptor();
2621 locDescSet.add(locDesc);
2623 System.out.println("-----locDescSet=" + locDescSet + " idx=" + idx);
2624 if (locDescSet.size() != 1) {
2627 Location newLocElement = new Location(curLoc.getDescriptor(), curLoc.getLocDescriptor());
2628 higherLocTuple.add(newLocElement);
2629 enclosingDesc = getClassTypeDescriptor(curLoc.getLocDescriptor());
2634 String pcLocIdentifier = locNamePrefix + (locSeed++);
2635 NameDescriptor pcLocDesc = new NameDescriptor(pcLocIdentifier);
2636 Location newLoc = new Location(enclosingDesc, pcLocDesc);
2637 higherLocTuple.add(newLoc);
2639 System.out.println("---new loc tuple=" + higherLocTuple);
2641 return higherLocTuple;
2645 public ClassDescriptor getClassTypeDescriptor(Descriptor in) {
2647 if (in instanceof VarDescriptor) {
2648 return ((VarDescriptor) in).getType().getClassDesc();
2649 } else if (in instanceof FieldDescriptor) {
2650 return ((FieldDescriptor) in).getType().getClassDesc();
2652 // else if (in instanceof LocationDescriptor) {
2653 // // here is the case that the descriptor 'in' is the last element of the assigned composite
2655 // return ((VarDescriptor) locTuple.get(0).getLocDescriptor()).getType().getClassDesc();
2663 private Set<NTuple<Location>> calculateHighestLocTupleSet(
2664 Set<NTuple<Location>> paramLocTupleHavingInFlowSet) {
2666 Set<NTuple<Location>> highestSet = new HashSet<NTuple<Location>>();
2668 Iterator<NTuple<Location>> iterator = paramLocTupleHavingInFlowSet.iterator();
2669 NTuple<Location> highest = iterator.next();
2671 for (; iterator.hasNext();) {
2672 NTuple<Location> curLocTuple = (NTuple<Location>) iterator.next();
2673 if (isHigherThan(curLocTuple, highest)) {
2674 System.out.println(curLocTuple + " is greater than " + highest);
2675 highest = curLocTuple;
2679 highestSet.add(highest);
2681 MethodDescriptor md = (MethodDescriptor) highest.get(0).getDescriptor();
2682 VarDescriptor thisVarDesc = md.getThis();
2684 System.out.println("highest=" + highest);
2686 for (Iterator<NTuple<Location>> iter = paramLocTupleHavingInFlowSet.iterator(); iter.hasNext();) {
2687 NTuple<Location> curLocTuple = iter.next();
2689 if (!curLocTuple.equals(highest) && !hasOrderingRelation(highest, curLocTuple)) {
2691 System.out.println("add it to the highest set=" + curLocTuple);
2692 highestSet.add(curLocTuple);
2701 private void calculateExtraLocations2(MethodDescriptor md) {
2702 // calcualte pcloc, returnloc,...
2704 SSJavaLattice<String> methodLattice = getMethodLattice(md);
2705 MethodLocationInfo methodInfo = getMethodLocationInfo(md);
2706 FlowGraph fg = getFlowGraph(md);
2707 Set<FlowNode> nodeSet = fg.getNodeSet();
2709 for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
2710 FlowNode flowNode = (FlowNode) iterator.next();
2711 if (flowNode.isDeclaratonNode()) {
2712 CompositeLocation inferLoc = methodInfo.getInferLocation(flowNode.getDescTuple().get(0));
2713 String locIdentifier = inferLoc.get(0).getLocIdentifier();
2714 if (!methodLattice.containsKey(locIdentifier)) {
2715 methodLattice.put(locIdentifier);
2721 Map<Integer, CompositeLocation> mapParamToLoc = methodInfo.getMapParamIdxToInferLoc();
2722 Set<Integer> paramIdxSet = mapParamToLoc.keySet();
2724 if (!ssjava.getMethodContainingSSJavaLoop().equals(md)) {
2725 // calculate the initial program counter location
2726 // PC location is higher than location types of all parameters
2727 String pcLocSymbol = "PCLOC";
2729 Set<CompositeLocation> paramInFlowSet = new HashSet<CompositeLocation>();
2731 for (Iterator iterator = paramIdxSet.iterator(); iterator.hasNext();) {
2732 Integer paramIdx = (Integer) iterator.next();
2734 FlowNode paramFlowNode = fg.getParamFlowNode(paramIdx);
2736 if (fg.getIncomingFlowNodeSet(paramFlowNode).size() > 0) {
2737 // parameter has in-value flows
2738 CompositeLocation inferLoc = mapParamToLoc.get(paramIdx);
2739 paramInFlowSet.add(inferLoc);
2743 if (paramInFlowSet.size() > 0) {
2744 CompositeLocation lowestLoc = getLowest(methodLattice, paramInFlowSet);
2745 assert (lowestLoc != null);
2746 methodInfo.setPCLoc(lowestLoc);
2751 // calculate a return location
2752 // the return location type is lower than all parameters and location
2755 if (!md.getReturnType().isVoid()) {
2756 // first, generate the set of return value location types that starts
2760 Set<CompositeLocation> inferFieldReturnLocSet = new HashSet<CompositeLocation>();
2762 Set<FlowNode> paramFlowNode = getParamNodeFlowingToReturnValue(md);
2763 Set<CompositeLocation> inferParamLocSet = new HashSet<CompositeLocation>();
2764 if (paramFlowNode != null) {
2765 for (Iterator iterator = paramFlowNode.iterator(); iterator.hasNext();) {
2766 FlowNode fn = (FlowNode) iterator.next();
2767 CompositeLocation inferLoc =
2768 generateInferredCompositeLocation(methodInfo, getFlowGraph(md).getLocationTuple(fn));
2769 inferParamLocSet.add(inferLoc);
2773 Set<FlowNode> returnNodeSet = fg.getReturnNodeSet();
2775 skip: for (Iterator iterator = returnNodeSet.iterator(); iterator.hasNext();) {
2776 FlowNode returnNode = (FlowNode) iterator.next();
2777 CompositeLocation inferReturnLoc =
2778 generateInferredCompositeLocation(methodInfo, fg.getLocationTuple(returnNode));
2779 if (inferReturnLoc.get(0).getLocIdentifier().equals("this")) {
2780 // if the location type of the return value matches "this" reference
2781 // then, check whether this return value is equal to/lower than all
2783 // parameters that possibly flow into the return values
2784 for (Iterator iterator2 = inferParamLocSet.iterator(); iterator2.hasNext();) {
2785 CompositeLocation paramInferLoc = (CompositeLocation) iterator2.next();
2787 if ((!paramInferLoc.equals(inferReturnLoc))
2788 && !isGreaterThan(methodLattice, paramInferLoc, inferReturnLoc)) {
2792 inferFieldReturnLocSet.add(inferReturnLoc);
2797 if (inferFieldReturnLocSet.size() > 0) {
2799 CompositeLocation returnLoc = getLowest(methodLattice, inferFieldReturnLocSet);
2800 if (returnLoc == null) {
2801 // in this case, assign <'this',bottom> to the RETURNLOC
2802 returnLoc = new CompositeLocation(new Location(md, md.getThis().getSymbol()));
2803 returnLoc.addLocation(new Location(md.getClassDesc(), getLattice(md.getClassDesc())
2806 methodInfo.setReturnLoc(returnLoc);
2809 String returnLocSymbol = "RETURNLOC";
2810 CompositeLocation returnLocInferLoc =
2811 new CompositeLocation(new Location(md, returnLocSymbol));
2812 methodInfo.setReturnLoc(returnLocInferLoc);
2814 for (Iterator iterator = paramIdxSet.iterator(); iterator.hasNext();) {
2815 Integer paramIdx = (Integer) iterator.next();
2816 CompositeLocation inferLoc = mapParamToLoc.get(paramIdx);
2817 String paramLocLocalSymbol = inferLoc.get(0).getLocIdentifier();
2818 if (!methodLattice.isGreaterThan(paramLocLocalSymbol, returnLocSymbol)) {
2820 // addRelationHigherToLower(methodLattice, methodInfo,
2821 // paramLocLocalSymbol,
2822 // returnLocSymbol);
2826 for (Iterator iterator = returnNodeSet.iterator(); iterator.hasNext();) {
2827 FlowNode returnNode = (FlowNode) iterator.next();
2828 CompositeLocation inferLoc =
2829 generateInferredCompositeLocation(methodInfo, fg.getLocationTuple(returnNode));
2830 if (!isGreaterThan(methodLattice, inferLoc, returnLocInferLoc)) {
2832 // addRelation(methodLattice, methodInfo, inferLoc,
2833 // returnLocInferLoc);
2842 private Set<String> getHigherLocSymbolThan(SSJavaLattice<String> lattice, String loc) {
2843 Set<String> higherLocSet = new HashSet<String>();
2845 Set<String> locSet = lattice.getTable().keySet();
2846 for (Iterator iterator = locSet.iterator(); iterator.hasNext();) {
2847 String element = (String) iterator.next();
2848 if (lattice.isGreaterThan(element, loc) && (!element.equals(lattice.getTopItem()))) {
2849 higherLocSet.add(element);
2852 return higherLocSet;
2855 private CompositeLocation getLowest(SSJavaLattice<String> methodLattice,
2856 Set<CompositeLocation> set) {
2858 CompositeLocation lowest = set.iterator().next();
2860 if (set.size() == 1) {
2864 for (Iterator iterator = set.iterator(); iterator.hasNext();) {
2865 CompositeLocation loc = (CompositeLocation) iterator.next();
2867 if ((!loc.equals(lowest)) && (!isComparable(methodLattice, lowest, loc))) {
2868 // if there is a case where composite locations are incomparable, just
2873 if ((!loc.equals(lowest)) && isGreaterThan(methodLattice, lowest, loc)) {
2880 private boolean isComparable(SSJavaLattice<String> methodLattice, CompositeLocation comp1,
2881 CompositeLocation comp2) {
2883 int size = comp1.getSize() >= comp2.getSize() ? comp2.getSize() : comp1.getSize();
2885 for (int idx = 0; idx < size; idx++) {
2886 Location loc1 = comp1.get(idx);
2887 Location loc2 = comp2.get(idx);
2889 Descriptor desc1 = loc1.getDescriptor();
2890 Descriptor desc2 = loc2.getDescriptor();
2892 if (!desc1.equals(desc2)) {
2893 throw new Error("Fail to compare " + comp1 + " and " + comp2);
2896 String symbol1 = loc1.getLocIdentifier();
2897 String symbol2 = loc2.getLocIdentifier();
2899 SSJavaLattice<String> lattice;
2901 lattice = methodLattice;
2903 lattice = getLattice(desc1);
2906 if (symbol1.equals(symbol2)) {
2908 } else if (!lattice.isComparable(symbol1, symbol2)) {
2917 private boolean isGreaterThan(SSJavaLattice<String> methodLattice, CompositeLocation comp1,
2918 CompositeLocation comp2) {
2920 int size = comp1.getSize() >= comp2.getSize() ? comp2.getSize() : comp1.getSize();
2922 for (int idx = 0; idx < size; idx++) {
2923 Location loc1 = comp1.get(idx);
2924 Location loc2 = comp2.get(idx);
2926 Descriptor desc1 = loc1.getDescriptor();
2927 Descriptor desc2 = loc2.getDescriptor();
2929 if (!desc1.equals(desc2)) {
2930 throw new Error("Fail to compare " + comp1 + " and " + comp2);
2933 String symbol1 = loc1.getLocIdentifier();
2934 String symbol2 = loc2.getLocIdentifier();
2936 SSJavaLattice<String> lattice;
2938 lattice = methodLattice;
2940 lattice = getLattice(desc1);
2943 if (symbol1.equals(symbol2)) {
2945 } else if (lattice.isGreaterThan(symbol1, symbol2)) {
2956 private void contributeCalleeFlows(MethodInvokeNode min, MethodDescriptor mdCaller,
2957 MethodDescriptor mdCallee) {
2959 System.out.println("\n##contributeCalleeFlows callee=" + mdCallee + "TO caller=" + mdCaller);
2961 getSubGlobalFlowGraph(mdCallee);
2965 private GlobalFlowGraph getSubGlobalFlowGraph(MethodDescriptor md) {
2966 return mapMethodDescriptorToSubGlobalFlowGraph.get(md);
2969 private void propagateFlowsToCallerWithNoCompositeLocation(MethodInvokeNode min,
2970 MethodDescriptor mdCaller, MethodDescriptor mdCallee) {
2972 // if the parameter A reaches to the parameter B
2973 // then, add an edge the argument A -> the argument B to the caller's flow
2976 FlowGraph calleeFlowGraph = getFlowGraph(mdCallee);
2977 FlowGraph callerFlowGraph = getFlowGraph(mdCaller);
2978 int numParam = calleeFlowGraph.getNumParameters();
2980 for (int i = 0; i < numParam; i++) {
2981 for (int k = 0; k < numParam; k++) {
2985 FlowNode paramNode1 = calleeFlowGraph.getParamFlowNode(i);
2986 FlowNode paramNode2 = calleeFlowGraph.getParamFlowNode(k);
2988 NTuple<Descriptor> arg1Tuple = getNodeTupleByArgIdx(min, i);
2989 NTuple<Descriptor> arg2Tuple = getNodeTupleByArgIdx(min, k);
2991 // check if the callee propagates an ordering constraints through
2994 Set<FlowNode> localReachSet = calleeFlowGraph.getLocalReachFlowNodeSetFrom(paramNode1);
2995 // System.out.println("-param1=" + paramNode1 + " is higher than param2=" + paramNode2);
2996 // System.out.println("-- localReachSet from param1=" + localReachSet);
2998 if (arg1Tuple.size() > 0 && arg2Tuple.size() > 0 && localReachSet.contains(paramNode2)) {
2999 // need to propagate an ordering relation s.t. arg1 is higher
3003 // .println("-arg1Tuple=" + arg1Tuple + " is higher than arg2Tuple=" + arg2Tuple);
3005 // otherwise, flows between method/field locations...
3006 callerFlowGraph.addValueFlowEdge(arg1Tuple, arg2Tuple);
3007 // System.out.println("arg1=" + arg1Tuple + " arg2=" + arg2Tuple);
3011 System.out.println();
3015 // System.out.println("##\n");
3019 private void propagateFlowsToCaller(MethodInvokeNode min, MethodDescriptor mdCaller,
3020 MethodDescriptor mdCallee) {
3022 System.out.println("\n##PROPAGATE callee=" + mdCallee + "TO caller=" + mdCaller);
3024 // if the parameter A reaches to the parameter B
3025 // then, add an edge the argument A -> the argument B to the caller's flow
3029 // also if a parameter is a composite location and is started with "this"
3031 // need to make sure that the corresponding argument is higher than the
3032 // translated location of
3035 FlowGraph calleeFlowGraph = getFlowGraph(mdCallee);
3036 FlowGraph callerFlowGraph = getFlowGraph(mdCaller);
3037 int numParam = calleeFlowGraph.getNumParameters();
3039 for (int i = 0; i < numParam; i++) {
3040 for (int k = 0; k < numParam; k++) {
3044 FlowNode paramNode1 = calleeFlowGraph.getParamFlowNode(i);
3045 FlowNode paramNode2 = calleeFlowGraph.getParamFlowNode(k);
3047 System.out.println("param1=" + paramNode1 + " curDescTuple="
3048 + paramNode1.getCurrentDescTuple());
3049 System.out.println("param2=" + paramNode2 + " curDescTuple="
3050 + paramNode2.getCurrentDescTuple());
3052 // TODO: deprecated method
3053 // NodeTupleSet tupleSetArg1 = getNodeTupleSetByArgIdx(min, i);
3054 // NodeTupleSet tupleSetArg2 = getNodeTupleSetByArgIdx(min, k);
3055 NodeTupleSet tupleSetArg1 = null;
3056 NodeTupleSet tupleSetArg2 = null;
3058 for (Iterator<NTuple<Descriptor>> iter1 = tupleSetArg1.iterator(); iter1.hasNext();) {
3059 NTuple<Descriptor> arg1Tuple = iter1.next();
3061 for (Iterator<NTuple<Descriptor>> iter2 = tupleSetArg2.iterator(); iter2.hasNext();) {
3062 NTuple<Descriptor> arg2Tuple = iter2.next();
3064 // check if the callee propagates an ordering constraints through
3067 Set<FlowNode> localReachSet =
3068 calleeFlowGraph.getLocalReachFlowNodeSetFrom(paramNode1);
3070 if (localReachSet.contains(paramNode2)) {
3071 // need to propagate an ordering relation s.t. arg1 is higher
3075 .println("-param1=" + paramNode1 + " is higher than param2=" + paramNode2);
3076 System.out.println("-arg1Tuple=" + arg1Tuple + " is higher than arg2Tuple="
3079 if (!min.getMethod().isStatic()) {
3080 // check if this is the case that values flow to/from the
3081 // current object reference 'this'
3083 NTuple<Descriptor> baseTuple = mapMethodInvokeNodeToBaseTuple.get(min);
3084 Descriptor baseRef = baseTuple.get(baseTuple.size() - 1);
3086 System.out.println("paramNode1.getCurrentDescTuple()="
3087 + paramNode1.getCurrentDescTuple());
3088 // calculate the prefix of the argument
3090 if (arg2Tuple.size() == 1 && arg2Tuple.get(0).equals(baseRef)) {
3091 // in this case, the callee flow causes a caller flow to the
3092 // object whose method
3095 if (!paramNode1.getCurrentDescTuple().startsWith(mdCallee.getThis())) {
3096 // check whether ???
3098 NTuple<Descriptor> param1Prefix =
3099 calculatePrefixForParam(callerFlowGraph, calleeFlowGraph, min, arg1Tuple,
3102 if (param1Prefix != null && param1Prefix.startsWith(mdCallee.getThis())) {
3103 // in this case, we need to create a new edge
3104 // 'this.FIELD'->'this'
3105 // but we couldn't... instead we assign a new composite
3107 // with 'this' reference to the corresponding parameter
3109 CompositeLocation compLocForParam1 =
3110 generateCompositeLocation(mdCallee, param1Prefix);
3113 .println("set comp loc=" + compLocForParam1 + " to " + paramNode1);
3114 paramNode1.setCompositeLocation(compLocForParam1);
3116 // then, we need to make sure that the corresponding
3117 // argument in the caller
3118 // is required to be higher than or equal to the
3119 // translated parameter
3122 NTuple<Descriptor> translatedParamTuple =
3123 translateCompositeLocationToCaller(min, compLocForParam1);
3125 // TODO : check if the arg >= the tranlated parameter
3127 System.out.println("add a flow edge= " + arg1Tuple + "->"
3128 + translatedParamTuple);
3129 callerFlowGraph.addValueFlowEdge(arg1Tuple, translatedParamTuple);
3136 // param1 has already been assigned a composite location
3138 System.out.println("--param1 has already been assigned a composite location");
3139 CompositeLocation compLocForParam1 = paramNode1.getCompositeLocation();
3140 NTuple<Descriptor> translatedParamTuple =
3141 translateCompositeLocationToCaller(min, compLocForParam1);
3143 // TODO : check if the arg >= the tranlated parameter
3145 System.out.println("add a flow edge= " + arg1Tuple + "->"
3146 + translatedParamTuple);
3147 callerFlowGraph.addValueFlowEdge(arg1Tuple, translatedParamTuple);
3153 } else if (arg1Tuple.size() == 1 && arg1Tuple.get(0).equals(baseRef)) {
3154 // in this case, the callee flow causes a caller flow
3155 // originated from the object
3157 // method is invoked.
3159 System.out.println("###FROM CASE");
3161 if (!paramNode2.getCurrentDescTuple().startsWith(mdCallee.getThis())) {
3163 NTuple<Descriptor> param2Prefix =
3164 calculatePrefixForParam(callerFlowGraph, calleeFlowGraph, min, arg2Tuple,
3167 if (param2Prefix != null && param2Prefix.startsWith(mdCallee.getThis())) {
3168 // in this case, we need to create a new edge 'this' ->
3169 // 'this.FIELD' but we couldn't... instead we assign the
3171 // parameter a new composite location started with
3174 CompositeLocation compLocForParam2 =
3175 generateCompositeLocation(mdCallee, param2Prefix);
3177 // System.out.println("set comp loc=" + compLocForParam2
3179 // " to " + paramNode2);
3180 paramNode1.setCompositeLocation(compLocForParam2);
3188 // otherwise, flows between method/field locations...
3189 callerFlowGraph.addValueFlowEdge(arg1Tuple, arg2Tuple);
3190 System.out.println("arg1=" + arg1Tuple + " arg2=" + arg2Tuple);
3197 System.out.println();
3201 System.out.println("##\n");
3204 private NTuple<Descriptor> translateCompositeLocationToCaller(MethodInvokeNode min,
3205 CompositeLocation compLocForParam1) {
3206 NTuple<Descriptor> baseTuple = mapMethodInvokeNodeToBaseTuple.get(min);
3208 NTuple<Descriptor> tuple = new NTuple<Descriptor>();
3210 for (int i = 0; i < baseTuple.size(); i++) {
3211 tuple.add(baseTuple.get(i));
3214 for (int i = 1; i < compLocForParam1.getSize(); i++) {
3215 Location loc = compLocForParam1.get(i);
3216 tuple.add(loc.getLocDescriptor());
3222 private CompositeLocation generateCompositeLocation(NTuple<Location> prefixLocTuple) {
3224 System.out.println("generateCompositeLocation=" + prefixLocTuple);
3226 CompositeLocation newCompLoc = new CompositeLocation();
3227 for (int i = 0; i < prefixLocTuple.size(); i++) {
3228 newCompLoc.addLocation(prefixLocTuple.get(i));
3231 Descriptor lastDescOfPrefix = prefixLocTuple.get(prefixLocTuple.size() - 1).getLocDescriptor();
3233 ClassDescriptor enclosingDescriptor;
3234 if (lastDescOfPrefix instanceof FieldDescriptor) {
3235 enclosingDescriptor = ((FieldDescriptor) lastDescOfPrefix).getType().getClassDesc();
3236 // System.out.println("enclosingDescriptor0=" + enclosingDescriptor);
3237 } else if (lastDescOfPrefix.equals(GLOBALDESC)) {
3238 MethodDescriptor currentMethodDesc = (MethodDescriptor) prefixLocTuple.get(0).getDescriptor();
3239 enclosingDescriptor = currentMethodDesc.getClassDesc();
3241 // var descriptor case
3242 enclosingDescriptor = ((VarDescriptor) lastDescOfPrefix).getType().getClassDesc();
3244 // System.out.println("enclosingDescriptor=" + enclosingDescriptor);
3246 LocationDescriptor newLocDescriptor = generateNewLocationDescriptor();
3247 newLocDescriptor.setEnclosingClassDesc(enclosingDescriptor);
3249 Location newLoc = new Location(enclosingDescriptor, newLocDescriptor.getSymbol());
3250 newLoc.setLocDescriptor(newLocDescriptor);
3251 newCompLoc.addLocation(newLoc);
3253 // System.out.println("--newCompLoc=" + newCompLoc);
3257 private CompositeLocation generateCompositeLocation(MethodDescriptor md,
3258 NTuple<Descriptor> paramPrefix) {
3260 System.out.println("generateCompositeLocation=" + paramPrefix);
3262 CompositeLocation newCompLoc = convertToCompositeLocation(md, paramPrefix);
3264 Descriptor lastDescOfPrefix = paramPrefix.get(paramPrefix.size() - 1);
3265 // System.out.println("lastDescOfPrefix=" + lastDescOfPrefix + " kind="
3266 // + lastDescOfPrefix.getClass());
3267 ClassDescriptor enclosingDescriptor;
3268 if (lastDescOfPrefix instanceof FieldDescriptor) {
3269 enclosingDescriptor = ((FieldDescriptor) lastDescOfPrefix).getType().getClassDesc();
3270 // System.out.println("enclosingDescriptor0=" + enclosingDescriptor);
3272 // var descriptor case
3273 enclosingDescriptor = ((VarDescriptor) lastDescOfPrefix).getType().getClassDesc();
3275 // System.out.println("enclosingDescriptor=" + enclosingDescriptor);
3277 LocationDescriptor newLocDescriptor = generateNewLocationDescriptor();
3278 newLocDescriptor.setEnclosingClassDesc(enclosingDescriptor);
3280 Location newLoc = new Location(enclosingDescriptor, newLocDescriptor.getSymbol());
3281 newLoc.setLocDescriptor(newLocDescriptor);
3282 newCompLoc.addLocation(newLoc);
3284 // System.out.println("--newCompLoc=" + newCompLoc);
3288 private NTuple<Descriptor> calculatePrefixForParam(FlowGraph callerFlowGraph,
3289 FlowGraph calleeFlowGraph, MethodInvokeNode min, NTuple<Descriptor> arg1Tuple,
3290 FlowNode paramNode1) {
3292 NTuple<Descriptor> baseTuple = mapMethodInvokeNodeToBaseTuple.get(min);
3293 Descriptor baseRef = baseTuple.get(baseTuple.size() - 1);
3294 System.out.println("baseRef=" + baseRef);
3296 FlowNode flowNodeArg1 = callerFlowGraph.getFlowNode(arg1Tuple);
3297 List<NTuple<Descriptor>> callerPrefixList = calculatePrefixList(callerFlowGraph, flowNodeArg1);
3298 System.out.println("callerPrefixList=" + callerPrefixList);
3300 List<NTuple<Descriptor>> prefixList = calculatePrefixList(calleeFlowGraph, paramNode1);
3301 System.out.println("###prefixList from node=" + paramNode1 + " =" + prefixList);
3303 List<NTuple<Descriptor>> calleePrefixList =
3304 translatePrefixListToCallee(baseRef, min.getMethod(), callerPrefixList);
3306 System.out.println("calleePrefixList=" + calleePrefixList);
3308 Set<FlowNode> reachNodeSetFromParam1 = calleeFlowGraph.getReachFlowNodeSetFrom(paramNode1);
3309 System.out.println("reachNodeSetFromParam1=" + reachNodeSetFromParam1);
3311 for (int i = 0; i < calleePrefixList.size(); i++) {
3312 NTuple<Descriptor> curPrefix = calleePrefixList.get(i);
3313 Set<NTuple<Descriptor>> reachableCommonPrefixSet = new HashSet<NTuple<Descriptor>>();
3315 for (Iterator iterator2 = reachNodeSetFromParam1.iterator(); iterator2.hasNext();) {
3316 FlowNode reachNode = (FlowNode) iterator2.next();
3317 if (reachNode.getCurrentDescTuple().startsWith(curPrefix)) {
3318 reachableCommonPrefixSet.add(reachNode.getCurrentDescTuple());
3322 if (!reachableCommonPrefixSet.isEmpty()) {
3323 System.out.println("###REACHABLECOMONPREFIX=" + reachableCommonPrefixSet
3324 + " with curPreFix=" + curPrefix);
3333 private List<NTuple<Descriptor>> translatePrefixListToCallee(Descriptor baseRef,
3334 MethodDescriptor mdCallee, List<NTuple<Descriptor>> callerPrefixList) {
3336 List<NTuple<Descriptor>> calleePrefixList = new ArrayList<NTuple<Descriptor>>();
3338 for (int i = 0; i < callerPrefixList.size(); i++) {
3339 NTuple<Descriptor> prefix = callerPrefixList.get(i);
3340 if (prefix.startsWith(baseRef)) {
3341 NTuple<Descriptor> calleePrefix = new NTuple<Descriptor>();
3342 calleePrefix.add(mdCallee.getThis());
3343 for (int k = 1; k < prefix.size(); k++) {
3344 calleePrefix.add(prefix.get(k));
3346 calleePrefixList.add(calleePrefix);
3350 return calleePrefixList;
3354 private List<NTuple<Descriptor>> calculatePrefixList(FlowGraph flowGraph, FlowNode flowNode) {
3356 System.out.println("\n##### calculatePrefixList=" + flowNode);
3358 Set<FlowNode> inNodeSet = flowGraph.getIncomingFlowNodeSet(flowNode);
3359 inNodeSet.add(flowNode);
3361 System.out.println("inNodeSet=" + inNodeSet);
3363 List<NTuple<Descriptor>> prefixList = new ArrayList<NTuple<Descriptor>>();
3365 for (Iterator iterator = inNodeSet.iterator(); iterator.hasNext();) {
3366 FlowNode inNode = (FlowNode) iterator.next();
3368 NTuple<Descriptor> inNodeTuple = inNode.getCurrentDescTuple();
3370 // CompositeLocation inNodeInferredLoc =
3371 // generateInferredCompositeLocation(methodInfo, inNodeTuple);
3372 // NTuple<Location> inNodeInferredLocTuple = inNodeInferredLoc.getTuple();
3374 for (int i = 1; i < inNodeTuple.size(); i++) {
3375 NTuple<Descriptor> prefix = inNodeTuple.subList(0, i);
3376 if (!prefixList.contains(prefix)) {
3377 prefixList.add(prefix);
3382 Collections.sort(prefixList, new Comparator<NTuple<Descriptor>>() {
3383 public int compare(NTuple<Descriptor> arg0, NTuple<Descriptor> arg1) {
3384 int s0 = arg0.size();
3385 int s1 = arg1.size();
3388 } else if (s0 == s1) {
3400 public CompositeLocation convertToCompositeLocation(MethodDescriptor md, NTuple<Descriptor> tuple) {
3402 CompositeLocation compLoc = new CompositeLocation();
3404 Descriptor enclosingDescriptor = md;
3406 for (int i = 0; i < tuple.size(); i++) {
3407 Descriptor curDescriptor = tuple.get(i);
3408 Location locElement = new Location(enclosingDescriptor, curDescriptor.getSymbol());
3409 locElement.setLocDescriptor(curDescriptor);
3410 compLoc.addLocation(locElement);
3412 if (curDescriptor instanceof VarDescriptor) {
3413 enclosingDescriptor = md.getClassDesc();
3414 } else if (curDescriptor instanceof NameDescriptor) {
3415 // it is "GLOBAL LOC" case!
3416 enclosingDescriptor = GLOBALDESC;
3417 } else if (curDescriptor instanceof InterDescriptor) {
3418 enclosingDescriptor = null;
3420 enclosingDescriptor = ((FieldDescriptor) curDescriptor).getClassDescriptor();
3428 private LocationDescriptor generateNewLocationDescriptor() {
3429 return new LocationDescriptor("Loc" + (locSeed++));
3432 private int getPrefixIndex(NTuple<Descriptor> tuple1, NTuple<Descriptor> tuple2) {
3434 // return the index where the prefix shared by tuple1 and tuple2 is ended
3435 // if there is no prefix shared by both of them, return -1
3437 int minSize = tuple1.size();
3438 if (minSize > tuple2.size()) {
3439 minSize = tuple2.size();
3443 for (int i = 0; i < minSize; i++) {
3444 if (!tuple1.get(i).equals(tuple2.get(i))) {
3454 private CompositeLocation generateInferredCompositeLocation(MethodLocationInfo methodInfo,
3455 NTuple<Location> tuple) {
3457 // first, retrieve inferred location by the local var descriptor
3458 CompositeLocation inferLoc = new CompositeLocation();
3460 CompositeLocation localVarInferLoc =
3461 methodInfo.getInferLocation(tuple.get(0).getLocDescriptor());
3463 localVarInferLoc.get(0).setLocDescriptor(tuple.get(0).getLocDescriptor());
3465 for (int i = 0; i < localVarInferLoc.getSize(); i++) {
3466 inferLoc.addLocation(localVarInferLoc.get(i));
3469 for (int i = 1; i < tuple.size(); i++) {
3470 Location cur = tuple.get(i);
3471 Descriptor enclosingDesc = cur.getDescriptor();
3472 Descriptor curDesc = cur.getLocDescriptor();
3474 Location inferLocElement;
3475 if (curDesc == null) {
3476 // in this case, we have a newly generated location.
3477 inferLocElement = new Location(enclosingDesc, cur.getLocIdentifier());
3479 String fieldLocSymbol =
3480 getLocationInfo(enclosingDesc).getInferLocation(curDesc).get(0).getLocIdentifier();
3481 inferLocElement = new Location(enclosingDesc, fieldLocSymbol);
3482 inferLocElement.setLocDescriptor(curDesc);
3485 inferLoc.addLocation(inferLocElement);
3489 assert (inferLoc.get(0).getLocDescriptor().getSymbol() == inferLoc.get(0).getLocIdentifier());
3493 public LocationInfo getLocationInfo(Descriptor d) {
3494 if (d instanceof MethodDescriptor) {
3495 return getMethodLocationInfo((MethodDescriptor) d);
3497 return getFieldLocationInfo((ClassDescriptor) d);
3501 private MethodLocationInfo getMethodLocationInfo(MethodDescriptor md) {
3503 if (!mapMethodDescToMethodLocationInfo.containsKey(md)) {
3504 mapMethodDescToMethodLocationInfo.put(md, new MethodLocationInfo(md));
3507 return mapMethodDescToMethodLocationInfo.get(md);
3511 private LocationInfo getFieldLocationInfo(ClassDescriptor cd) {
3513 if (!mapClassToLocationInfo.containsKey(cd)) {
3514 mapClassToLocationInfo.put(cd, new LocationInfo(cd));
3517 return mapClassToLocationInfo.get(cd);
3521 private void addPrefixMapping(Map<NTuple<Location>, Set<NTuple<Location>>> map,
3522 NTuple<Location> prefix, NTuple<Location> element) {
3524 if (!map.containsKey(prefix)) {
3525 map.put(prefix, new HashSet<NTuple<Location>>());
3527 map.get(prefix).add(element);
3530 private boolean containsNonPrimitiveElement(Set<Descriptor> descSet) {
3531 for (Iterator iterator = descSet.iterator(); iterator.hasNext();) {
3532 Descriptor desc = (Descriptor) iterator.next();
3534 if (desc.equals(LocationInference.GLOBALDESC)) {
3536 } else if (desc instanceof VarDescriptor) {
3537 if (!((VarDescriptor) desc).getType().isPrimitive()) {
3540 } else if (desc instanceof FieldDescriptor) {
3541 if (!((FieldDescriptor) desc).getType().isPrimitive()) {
3550 private SSJavaLattice<String> getLattice(Descriptor d) {
3551 if (d instanceof MethodDescriptor) {
3552 return getMethodLattice((MethodDescriptor) d);
3554 return getFieldLattice((ClassDescriptor) d);
3558 private SSJavaLattice<String> getMethodLattice(MethodDescriptor md) {
3559 if (!md2lattice.containsKey(md)) {
3560 md2lattice.put(md, new SSJavaLattice<String>(SSJavaAnalysis.TOP, SSJavaAnalysis.BOTTOM));
3562 return md2lattice.get(md);
3565 private void setMethodLattice(MethodDescriptor md, SSJavaLattice<String> lattice) {
3566 md2lattice.put(md, lattice);
3569 private void extractFlowsBetweenFields(ClassDescriptor cd, FlowNode srcNode, FlowNode dstNode,
3572 NTuple<Descriptor> srcCurTuple = srcNode.getCurrentDescTuple();
3573 NTuple<Descriptor> dstCurTuple = dstNode.getCurrentDescTuple();
3575 if (srcCurTuple.get(idx).equals(dstCurTuple.get(idx)) && srcCurTuple.size() > (idx + 1)
3576 && dstCurTuple.size() > (idx + 1)) {
3577 // value flow between fields: we don't need to add a binary relation
3580 Descriptor desc = srcCurTuple.get(idx);
3581 ClassDescriptor classDesc;
3584 classDesc = ((VarDescriptor) desc).getType().getClassDesc();
3586 if (desc instanceof FieldDescriptor) {
3587 classDesc = ((FieldDescriptor) desc).getType().getClassDesc();
3589 // this case is that the local variable has a composite location assignment
3590 // the following element after the composite location to the local variable
3591 // has the enclosing descriptor of the local variable
3592 Descriptor localDesc = srcNode.getDescTuple().get(0);
3593 classDesc = ((VarDescriptor) localDesc).getType().getClassDesc();
3596 extractFlowsBetweenFields(classDesc, srcNode, dstNode, idx + 1);
3600 Descriptor srcFieldDesc = srcCurTuple.get(idx);
3601 Descriptor dstFieldDesc = dstCurTuple.get(idx);
3604 getHierarchyGraph(cd).addEdge(srcFieldDesc, dstFieldDesc);
3610 public SSJavaLattice<String> getFieldLattice(ClassDescriptor cd) {
3611 if (!cd2lattice.containsKey(cd)) {
3612 cd2lattice.put(cd, new SSJavaLattice<String>(SSJavaAnalysis.TOP, SSJavaAnalysis.BOTTOM));
3614 return cd2lattice.get(cd);
3617 public LinkedList<MethodDescriptor> computeMethodList() {
3619 Set<MethodDescriptor> toSort = new HashSet<MethodDescriptor>();
3623 Set<MethodDescriptor> visited = new HashSet<MethodDescriptor>();
3624 Set<MethodDescriptor> reachableCallee = new HashSet<MethodDescriptor>();
3626 while (!toAnalyzeIsEmpty()) {
3627 ClassDescriptor cd = toAnalyzeNext();
3629 setupToAnalazeMethod(cd);
3630 temp_toanalyzeMethodList.removeAll(visited);
3632 while (!toAnalyzeMethodIsEmpty()) {
3633 MethodDescriptor md = toAnalyzeMethodNext();
3634 if ((!visited.contains(md))
3635 && (ssjava.needTobeAnnotated(md) || reachableCallee.contains(md))) {
3637 // creates a mapping from a method descriptor to virtual methods
3638 Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
3639 if (md.isStatic()) {
3640 setPossibleCallees.add(md);
3642 setPossibleCallees.addAll(ssjava.getCallGraph().getMethods(md));
3645 Set<MethodDescriptor> calleeSet = ssjava.getCallGraph().getCalleeSet(md);
3646 Set<MethodDescriptor> needToAnalyzeCalleeSet = new HashSet<MethodDescriptor>();
3648 for (Iterator iterator = calleeSet.iterator(); iterator.hasNext();) {
3649 MethodDescriptor calleemd = (MethodDescriptor) iterator.next();
3650 if ((!ssjava.isTrustMethod(calleemd))
3651 && (!ssjava.isSSJavaUtil(calleemd.getClassDesc()))) {
3652 if (!visited.contains(calleemd)) {
3653 temp_toanalyzeMethodList.add(calleemd);
3655 reachableCallee.add(calleemd);
3656 needToAnalyzeCalleeSet.add(calleemd);
3660 mapMethodToCalleeSet.put(md, needToAnalyzeCalleeSet);
3669 return ssjava.topologicalSort(toSort);
3673 public boolean isTransitivelyCalledFrom(MethodDescriptor callee, MethodDescriptor caller) {
3674 // if the callee is transitively invoked from the caller
3677 int callerIdx = toanalyze_methodDescList.indexOf(caller);
3678 int calleeIdx = toanalyze_methodDescList.indexOf(callee);
3680 if (callerIdx < calleeIdx) {
3688 public void constructFlowGraph() {
3690 System.out.println("");
3691 toanalyze_methodDescList = computeMethodList();
3693 LinkedList<MethodDescriptor> methodDescList =
3694 (LinkedList<MethodDescriptor>) toanalyze_methodDescList.clone();
3696 System.out.println("@@@methodDescList=" + methodDescList);
3699 while (!methodDescList.isEmpty()) {
3700 MethodDescriptor md = methodDescList.removeLast();
3701 if (state.SSJAVADEBUG) {
3702 System.out.println();
3703 System.out.println("SSJAVA: Constructing a flow graph: " + md);
3705 // creates a mapping from a parameter descriptor to its index
3706 Map<Descriptor, Integer> mapParamDescToIdx = new HashMap<Descriptor, Integer>();
3708 if (!md.isStatic()) {
3710 mapParamDescToIdx.put(md.getThis(), 0);
3713 for (int i = 0; i < md.numParameters(); i++) {
3714 Descriptor paramDesc = (Descriptor) md.getParameter(i);
3715 mapParamDescToIdx.put(paramDesc, new Integer(i + offset));
3718 FlowGraph fg = new FlowGraph(md, mapParamDescToIdx);
3719 mapMethodDescriptorToFlowGraph.put(md, fg);
3721 analyzeMethodBody(md.getClassDesc(), md);
3723 // System.out.println("##constructSubGlobalFlowGraph");
3724 // GlobalFlowGraph subGlobalFlowGraph = constructSubGlobalFlowGraph(fg);
3725 // mapMethodDescriptorToSubGlobalFlowGraph.put(md, subGlobalFlowGraph);
3728 // System.out.println("##addValueFlowsFromCalleeSubGlobalFlowGraph");
3729 // addValueFlowsFromCalleeSubGlobalFlowGraph(md, subGlobalFlowGraph);
3730 // subGlobalFlowGraph.writeGraph("_SUBGLOBAL");
3732 // propagateFlowsFromCalleesWithNoCompositeLocation(md);
3736 // _debug_printGraph();
3738 methodDescList = (LinkedList<MethodDescriptor>) toanalyze_methodDescList.clone();
3740 while (!methodDescList.isEmpty()) {
3741 MethodDescriptor md = methodDescList.removeLast();
3742 if (state.SSJAVADEBUG) {
3743 System.out.println();
3744 System.out.println("SSJAVA: Constructing a sub global flow graph: " + md);
3746 GlobalFlowGraph subGlobalFlowGraph = constructSubGlobalFlowGraph(getFlowGraph(md));
3747 mapMethodDescriptorToSubGlobalFlowGraph.put(md, subGlobalFlowGraph);
3750 System.out.println("-add Value Flows From CalleeSubGlobalFlowGraph");
3751 addValueFlowsFromCalleeSubGlobalFlowGraph(md, subGlobalFlowGraph);
3752 subGlobalFlowGraph.writeGraph("_SUBGLOBAL");
3754 System.out.println("-propagate Flows From Callees With No CompositeLocation");
3755 propagateFlowsFromCalleesWithNoCompositeLocation(md);
3762 private Set<MethodInvokeNode> getMethodInvokeNodeSet(MethodDescriptor md) {
3763 if (!mapMethodDescriptorToMethodInvokeNodeSet.containsKey(md)) {
3764 mapMethodDescriptorToMethodInvokeNodeSet.put(md, new HashSet<MethodInvokeNode>());
3766 return mapMethodDescriptorToMethodInvokeNodeSet.get(md);
3769 private void constructSubGlobalFlowGraph(MethodDescriptor md) {
3771 FlowGraph flowGraph = getFlowGraph(md);
3773 Set<MethodInvokeNode> setMethodInvokeNode = getMethodInvokeNodeSet(md);
3775 for (Iterator<MethodInvokeNode> iter = setMethodInvokeNode.iterator(); iter.hasNext();) {
3776 MethodInvokeNode min = iter.next();
3777 propagateFlowsFromMethodInvokeNode(md, min);
3782 private void propagateFlowsFromMethodInvokeNode(MethodDescriptor mdCaller, MethodInvokeNode min) {
3783 // the transformation for a call site propagates flows through parameters
3784 // if the method is virtual, it also grab all relations from any possible
3787 MethodDescriptor mdCallee = min.getMethod();
3788 Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
3789 if (mdCallee.isStatic()) {
3790 setPossibleCallees.add(mdCallee);
3792 Set<MethodDescriptor> calleeSet = ssjava.getCallGraph().getMethods(mdCallee);
3793 // removes method descriptors that are not invoked by the caller
3794 calleeSet.retainAll(mapMethodToCalleeSet.get(mdCaller));
3795 setPossibleCallees.addAll(calleeSet);
3798 for (Iterator iterator2 = setPossibleCallees.iterator(); iterator2.hasNext();) {
3799 MethodDescriptor possibleMdCallee = (MethodDescriptor) iterator2.next();
3800 contributeCalleeFlows(min, mdCaller, possibleMdCallee);
3805 private void assignCompositeLocation(MethodDescriptor md) {
3807 FlowGraph flowGraph = getFlowGraph(md);
3809 Set<FlowNode> nodeSet = flowGraph.getNodeSet();
3811 next: for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
3812 FlowNode flowNode = (FlowNode) iterator.next();
3814 // assign a composite location only to the local variable
3815 if (flowNode.getCurrentDescTuple().size() == 1) {
3817 List<NTuple<Descriptor>> prefixList = calculatePrefixList(flowGraph, flowNode);
3818 Set<FlowNode> reachSet = flowGraph.getReachFlowNodeSetFrom(flowNode);
3820 for (int i = 0; i < prefixList.size(); i++) {
3821 NTuple<Descriptor> curPrefix = prefixList.get(i);
3822 Set<NTuple<Descriptor>> reachableCommonPrefixSet = new HashSet<NTuple<Descriptor>>();
3824 for (Iterator iterator2 = reachSet.iterator(); iterator2.hasNext();) {
3825 FlowNode reachNode = (FlowNode) iterator2.next();
3826 if (reachNode.getCurrentDescTuple().startsWith(curPrefix)) {
3827 reachableCommonPrefixSet.add(reachNode.getCurrentDescTuple());
3831 if (!reachableCommonPrefixSet.isEmpty()) {
3832 System.out.println("NEED TO ASSIGN COMP LOC TO " + flowNode + " with prefix="
3834 CompositeLocation newCompLoc = generateCompositeLocation(md, curPrefix);
3835 flowNode.setCompositeLocation(newCompLoc);
3846 private void propagateFlowsFromCalleesWithNoCompositeLocation(MethodDescriptor mdCaller) {
3848 // the transformation for a call site propagates flows through parameters
3849 // if the method is virtual, it also grab all relations from any possible
3852 Set<MethodInvokeNode> setMethodInvokeNode =
3853 mapMethodDescriptorToMethodInvokeNodeSet.get(mdCaller);
3855 if (setMethodInvokeNode != null) {
3857 for (Iterator iterator = setMethodInvokeNode.iterator(); iterator.hasNext();) {
3858 MethodInvokeNode min = (MethodInvokeNode) iterator.next();
3859 MethodDescriptor mdCallee = min.getMethod();
3860 Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
3861 if (mdCallee.isStatic()) {
3862 setPossibleCallees.add(mdCallee);
3864 Set<MethodDescriptor> calleeSet = ssjava.getCallGraph().getMethods(mdCallee);
3865 // removes method descriptors that are not invoked by the caller
3866 calleeSet.retainAll(mapMethodToCalleeSet.get(mdCaller));
3867 setPossibleCallees.addAll(calleeSet);
3870 for (Iterator iterator2 = setPossibleCallees.iterator(); iterator2.hasNext();) {
3871 MethodDescriptor possibleMdCallee = (MethodDescriptor) iterator2.next();
3872 propagateFlowsToCallerWithNoCompositeLocation(min, mdCaller, possibleMdCallee);
3880 private void propagateFlowsFromCallees(MethodDescriptor mdCaller) {
3882 // the transformation for a call site propagates flows through parameters
3883 // if the method is virtual, it also grab all relations from any possible
3886 Set<MethodInvokeNode> setMethodInvokeNode =
3887 mapMethodDescriptorToMethodInvokeNodeSet.get(mdCaller);
3889 if (setMethodInvokeNode != null) {
3891 for (Iterator iterator = setMethodInvokeNode.iterator(); iterator.hasNext();) {
3892 MethodInvokeNode min = (MethodInvokeNode) iterator.next();
3893 MethodDescriptor mdCallee = min.getMethod();
3894 Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
3895 if (mdCallee.isStatic()) {
3896 setPossibleCallees.add(mdCallee);
3898 Set<MethodDescriptor> calleeSet = ssjava.getCallGraph().getMethods(mdCallee);
3899 // removes method descriptors that are not invoked by the caller
3900 calleeSet.retainAll(mapMethodToCalleeSet.get(mdCaller));
3901 setPossibleCallees.addAll(calleeSet);
3904 for (Iterator iterator2 = setPossibleCallees.iterator(); iterator2.hasNext();) {
3905 MethodDescriptor possibleMdCallee = (MethodDescriptor) iterator2.next();
3906 propagateFlowsToCaller(min, mdCaller, possibleMdCallee);
3914 private void analyzeMethodBody(ClassDescriptor cd, MethodDescriptor md) {
3915 BlockNode bn = state.getMethodBody(md);
3916 NodeTupleSet implicitFlowTupleSet = new NodeTupleSet();
3917 analyzeFlowBlockNode(md, md.getParameterTable(), bn, implicitFlowTupleSet);
3920 private void analyzeFlowBlockNode(MethodDescriptor md, SymbolTable nametable, BlockNode bn,
3921 NodeTupleSet implicitFlowTupleSet) {
3923 bn.getVarTable().setParent(nametable);
3924 for (int i = 0; i < bn.size(); i++) {
3925 BlockStatementNode bsn = bn.get(i);
3926 analyzeBlockStatementNode(md, bn.getVarTable(), bsn, implicitFlowTupleSet);
3931 private void analyzeBlockStatementNode(MethodDescriptor md, SymbolTable nametable,
3932 BlockStatementNode bsn, NodeTupleSet implicitFlowTupleSet) {
3934 switch (bsn.kind()) {
3935 case Kind.BlockExpressionNode:
3936 analyzeBlockExpressionNode(md, nametable, (BlockExpressionNode) bsn, implicitFlowTupleSet);
3939 case Kind.DeclarationNode:
3940 analyzeFlowDeclarationNode(md, nametable, (DeclarationNode) bsn, implicitFlowTupleSet);
3943 case Kind.IfStatementNode:
3944 analyzeFlowIfStatementNode(md, nametable, (IfStatementNode) bsn, implicitFlowTupleSet);
3948 analyzeFlowLoopNode(md, nametable, (LoopNode) bsn, implicitFlowTupleSet);
3951 case Kind.ReturnNode:
3952 analyzeFlowReturnNode(md, nametable, (ReturnNode) bsn, implicitFlowTupleSet);
3955 case Kind.SubBlockNode:
3956 analyzeFlowSubBlockNode(md, nametable, (SubBlockNode) bsn, implicitFlowTupleSet);
3959 case Kind.ContinueBreakNode:
3962 case Kind.SwitchStatementNode:
3963 analyzeSwitchStatementNode(md, nametable, (SwitchStatementNode) bsn, implicitFlowTupleSet);
3970 private void analyzeSwitchBlockNode(MethodDescriptor md, SymbolTable nametable,
3971 SwitchBlockNode sbn, NodeTupleSet implicitFlowTupleSet) {
3973 analyzeFlowBlockNode(md, nametable, sbn.getSwitchBlockStatement(), implicitFlowTupleSet);
3977 private void analyzeSwitchStatementNode(MethodDescriptor md, SymbolTable nametable,
3978 SwitchStatementNode ssn, NodeTupleSet implicitFlowTupleSet) {
3980 NodeTupleSet condTupleNode = new NodeTupleSet();
3981 analyzeFlowExpressionNode(md, nametable, ssn.getCondition(), condTupleNode, null,
3982 implicitFlowTupleSet, false);
3984 NodeTupleSet newImplicitTupleSet = new NodeTupleSet();
3986 newImplicitTupleSet.addTupleSet(implicitFlowTupleSet);
3987 newImplicitTupleSet.addTupleSet(condTupleNode);
3989 if (newImplicitTupleSet.size() > 1) {
3990 // need to create an intermediate node for the GLB of conditional
3991 // locations & implicit flows
3992 NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
3993 for (Iterator<NTuple<Descriptor>> idxIter = newImplicitTupleSet.iterator(); idxIter.hasNext();) {
3994 NTuple<Descriptor> tuple = idxIter.next();
3995 addFlowGraphEdge(md, tuple, interTuple);
3997 newImplicitTupleSet.clear();
3998 newImplicitTupleSet.addTuple(interTuple);
4001 BlockNode sbn = ssn.getSwitchBody();
4002 for (int i = 0; i < sbn.size(); i++) {
4003 analyzeSwitchBlockNode(md, nametable, (SwitchBlockNode) sbn.get(i), newImplicitTupleSet);
4008 private void analyzeFlowSubBlockNode(MethodDescriptor md, SymbolTable nametable,
4009 SubBlockNode sbn, NodeTupleSet implicitFlowTupleSet) {
4010 analyzeFlowBlockNode(md, nametable, sbn.getBlockNode(), implicitFlowTupleSet);
4013 private void analyzeFlowReturnNode(MethodDescriptor md, SymbolTable nametable, ReturnNode rn,
4014 NodeTupleSet implicitFlowTupleSet) {
4016 ExpressionNode returnExp = rn.getReturnExpression();
4018 if (returnExp != null) {
4019 NodeTupleSet nodeSet = new NodeTupleSet();
4020 // if a return expression returns a literal value, nodeSet is empty
4021 analyzeFlowExpressionNode(md, nametable, returnExp, nodeSet, false);
4022 FlowGraph fg = getFlowGraph(md);
4024 // if (implicitFlowTupleSet.size() == 1
4026 // fg.getFlowNode(implicitFlowTupleSet.iterator().next()).isIntermediate())
4029 // // since there is already an intermediate node for the GLB of implicit
4031 // // we don't need to create another intermediate node.
4032 // // just re-use the intermediate node for implicit flows.
4034 // FlowNode meetNode =
4035 // fg.getFlowNode(implicitFlowTupleSet.iterator().next());
4037 // for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
4038 // NTuple<Descriptor> returnNodeTuple = (NTuple<Descriptor>)
4040 // fg.addValueFlowEdge(returnNodeTuple, meetNode.getDescTuple());
4045 NodeTupleSet currentFlowTupleSet = new NodeTupleSet();
4047 // add tuples from return node
4048 currentFlowTupleSet.addTupleSet(nodeSet);
4050 // add tuples corresponding to the current implicit flows
4051 currentFlowTupleSet.addTupleSet(implicitFlowTupleSet);
4053 if (currentFlowTupleSet.size() > 1) {
4054 FlowNode meetNode = fg.createIntermediateNode();
4055 for (Iterator iterator = currentFlowTupleSet.iterator(); iterator.hasNext();) {
4056 NTuple<Descriptor> currentFlowTuple = (NTuple<Descriptor>) iterator.next();
4057 fg.addValueFlowEdge(currentFlowTuple, meetNode.getDescTuple());
4059 fg.addReturnFlowNode(meetNode.getDescTuple());
4060 } else if (currentFlowTupleSet.size() == 1) {
4061 NTuple<Descriptor> tuple = currentFlowTupleSet.iterator().next();
4062 fg.addReturnFlowNode(tuple);
4069 private void analyzeFlowLoopNode(MethodDescriptor md, SymbolTable nametable, LoopNode ln,
4070 NodeTupleSet implicitFlowTupleSet) {
4072 if (ln.getType() == LoopNode.WHILELOOP || ln.getType() == LoopNode.DOWHILELOOP) {
4074 NodeTupleSet condTupleNode = new NodeTupleSet();
4075 analyzeFlowExpressionNode(md, nametable, ln.getCondition(), condTupleNode, null,
4076 implicitFlowTupleSet, false);
4078 NodeTupleSet newImplicitTupleSet = new NodeTupleSet();
4080 newImplicitTupleSet.addTupleSet(implicitFlowTupleSet);
4081 newImplicitTupleSet.addTupleSet(condTupleNode);
4083 if (newImplicitTupleSet.size() > 1) {
4084 // need to create an intermediate node for the GLB of conditional
4085 // locations & implicit flows
4086 NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
4087 for (Iterator<NTuple<Descriptor>> idxIter = newImplicitTupleSet.iterator(); idxIter
4089 NTuple<Descriptor> tuple = idxIter.next();
4090 addFlowGraphEdge(md, tuple, interTuple);
4092 newImplicitTupleSet.clear();
4093 newImplicitTupleSet.addTuple(interTuple);
4098 // System.out.println("condTupleNode="+condTupleNode);
4099 // NTuple<Descriptor> interTuple =
4100 // getFlowGraph(md).createIntermediateNode().getDescTuple();
4102 // for (Iterator<NTuple<Descriptor>> idxIter = condTupleNode.iterator();
4103 // idxIter.hasNext();) {
4104 // NTuple<Descriptor> tuple = idxIter.next();
4105 // addFlowGraphEdge(md, tuple, interTuple);
4108 // for (Iterator<NTuple<Descriptor>> idxIter =
4109 // implicitFlowTupleSet.iterator(); idxIter
4111 // NTuple<Descriptor> tuple = idxIter.next();
4112 // addFlowGraphEdge(md, tuple, interTuple);
4115 // NodeTupleSet newImplicitSet = new NodeTupleSet();
4116 // newImplicitSet.addTuple(interTuple);
4117 analyzeFlowBlockNode(md, nametable, ln.getBody(), newImplicitTupleSet);
4120 // condTupleNode.addTupleSet(implicitFlowTupleSet);
4122 // add edges from condNodeTupleSet to all nodes of conditional nodes
4123 // analyzeFlowBlockNode(md, nametable, ln.getBody(), condTupleNode);
4126 // check 'for loop' case
4127 BlockNode bn = ln.getInitializer();
4128 bn.getVarTable().setParent(nametable);
4129 for (int i = 0; i < bn.size(); i++) {
4130 BlockStatementNode bsn = bn.get(i);
4131 analyzeBlockStatementNode(md, bn.getVarTable(), bsn, implicitFlowTupleSet);
4134 NodeTupleSet condTupleNode = new NodeTupleSet();
4135 analyzeFlowExpressionNode(md, bn.getVarTable(), ln.getCondition(), condTupleNode, null,
4136 implicitFlowTupleSet, false);
4139 NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
4141 for (Iterator<NTuple<Descriptor>> idxIter = condTupleNode.iterator(); idxIter.hasNext();) {
4142 NTuple<Descriptor> tuple = idxIter.next();
4143 addFlowGraphEdge(md, tuple, interTuple);
4146 for (Iterator<NTuple<Descriptor>> idxIter = implicitFlowTupleSet.iterator(); idxIter
4148 NTuple<Descriptor> tuple = idxIter.next();
4149 addFlowGraphEdge(md, tuple, interTuple);
4152 NodeTupleSet newImplicitSet = new NodeTupleSet();
4153 newImplicitSet.addTuple(interTuple);
4154 analyzeFlowBlockNode(md, bn.getVarTable(), ln.getUpdate(), newImplicitSet);
4155 analyzeFlowBlockNode(md, bn.getVarTable(), ln.getBody(), newImplicitSet);
4158 // condTupleNode.addTupleSet(implicitFlowTupleSet);
4160 // analyzeFlowBlockNode(md, bn.getVarTable(), ln.getUpdate(),
4162 // analyzeFlowBlockNode(md, bn.getVarTable(), ln.getBody(),
4169 private void analyzeFlowIfStatementNode(MethodDescriptor md, SymbolTable nametable,
4170 IfStatementNode isn, NodeTupleSet implicitFlowTupleSet) {
4172 // System.out.println("analyzeFlowIfStatementNode=" + isn.printNode(0));
4174 NodeTupleSet condTupleNode = new NodeTupleSet();
4175 analyzeFlowExpressionNode(md, nametable, isn.getCondition(), condTupleNode, null,
4176 implicitFlowTupleSet, false);
4178 NodeTupleSet newImplicitTupleSet = new NodeTupleSet();
4180 newImplicitTupleSet.addTupleSet(implicitFlowTupleSet);
4181 newImplicitTupleSet.addTupleSet(condTupleNode);
4183 // System.out.println("condTupleNode=" + condTupleNode);
4184 // System.out.println("implicitFlowTupleSet=" + implicitFlowTupleSet);
4185 // System.out.println("newImplicitTupleSet=" + newImplicitTupleSet);
4187 if (newImplicitTupleSet.size() > 1) {
4189 // need to create an intermediate node for the GLB of conditional locations & implicit flows
4190 NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
4191 for (Iterator<NTuple<Descriptor>> idxIter = newImplicitTupleSet.iterator(); idxIter.hasNext();) {
4192 NTuple<Descriptor> tuple = idxIter.next();
4193 addFlowGraphEdge(md, tuple, interTuple);
4195 newImplicitTupleSet.clear();
4196 newImplicitTupleSet.addTuple(interTuple);
4199 analyzeFlowBlockNode(md, nametable, isn.getTrueBlock(), newImplicitTupleSet);
4201 if (isn.getFalseBlock() != null) {
4202 analyzeFlowBlockNode(md, nametable, isn.getFalseBlock(), newImplicitTupleSet);
4207 private void analyzeFlowDeclarationNode(MethodDescriptor md, SymbolTable nametable,
4208 DeclarationNode dn, NodeTupleSet implicitFlowTupleSet) {
4210 VarDescriptor vd = dn.getVarDescriptor();
4211 mapDescToDefinitionLine.put(vd, dn.getNumLine());
4212 NTuple<Descriptor> tupleLHS = new NTuple<Descriptor>();
4214 FlowNode fn = getFlowGraph(md).createNewFlowNode(tupleLHS);
4215 fn.setDeclarationNode();
4217 if (dn.getExpression() != null) {
4219 NodeTupleSet nodeSetRHS = new NodeTupleSet();
4220 analyzeFlowExpressionNode(md, nametable, dn.getExpression(), nodeSetRHS, null,
4221 implicitFlowTupleSet, false);
4223 // creates edges from RHS to LHS
4224 NTuple<Descriptor> interTuple = null;
4225 if (nodeSetRHS.size() > 1) {
4226 interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
4229 for (Iterator<NTuple<Descriptor>> iter = nodeSetRHS.iterator(); iter.hasNext();) {
4230 NTuple<Descriptor> fromTuple = iter.next();
4231 addFlowGraphEdge(md, fromTuple, interTuple, tupleLHS);
4234 // creates edges from implicitFlowTupleSet to LHS
4235 for (Iterator<NTuple<Descriptor>> iter = implicitFlowTupleSet.iterator(); iter.hasNext();) {
4236 NTuple<Descriptor> implicitTuple = iter.next();
4237 addFlowGraphEdge(md, implicitTuple, tupleLHS);
4244 private void analyzeBlockExpressionNode(MethodDescriptor md, SymbolTable nametable,
4245 BlockExpressionNode ben, NodeTupleSet implicitFlowTupleSet) {
4246 analyzeFlowExpressionNode(md, nametable, ben.getExpression(), null, null, implicitFlowTupleSet,
4250 private NTuple<Descriptor> analyzeFlowExpressionNode(MethodDescriptor md, SymbolTable nametable,
4251 ExpressionNode en, NodeTupleSet nodeSet, boolean isLHS) {
4252 return analyzeFlowExpressionNode(md, nametable, en, nodeSet, null, new NodeTupleSet(), isLHS);
4255 private NTuple<Descriptor> analyzeFlowExpressionNode(MethodDescriptor md, SymbolTable nametable,
4256 ExpressionNode en, NodeTupleSet nodeSet, NTuple<Descriptor> base,
4257 NodeTupleSet implicitFlowTupleSet, boolean isLHS) {
4259 // note that expression node can create more than one flow node
4260 // nodeSet contains of flow nodes
4261 // base is always assigned to null except the case of a name node!
4263 NTuple<Descriptor> flowTuple;
4265 switch (en.kind()) {
4267 case Kind.AssignmentNode:
4268 analyzeFlowAssignmentNode(md, nametable, (AssignmentNode) en, nodeSet, base,
4269 implicitFlowTupleSet);
4272 case Kind.FieldAccessNode:
4274 analyzeFlowFieldAccessNode(md, nametable, (FieldAccessNode) en, nodeSet, base,
4275 implicitFlowTupleSet, isLHS);
4276 if (flowTuple != null) {
4277 nodeSet.addTuple(flowTuple);
4282 NodeTupleSet nameNodeSet = new NodeTupleSet();
4284 analyzeFlowNameNode(md, nametable, (NameNode) en, nameNodeSet, base, implicitFlowTupleSet);
4285 if (flowTuple != null) {
4286 nodeSet.addTuple(flowTuple);
4291 analyzeFlowOpNode(md, nametable, (OpNode) en, nodeSet, implicitFlowTupleSet);
4294 case Kind.CreateObjectNode:
4295 analyzeCreateObjectNode(md, nametable, (CreateObjectNode) en);
4298 case Kind.ArrayAccessNode:
4299 analyzeFlowArrayAccessNode(md, nametable, (ArrayAccessNode) en, nodeSet, isLHS);
4302 case Kind.LiteralNode:
4303 analyzeLiteralNode(md, nametable, (LiteralNode) en);
4306 case Kind.MethodInvokeNode:
4307 analyzeFlowMethodInvokeNode(md, nametable, (MethodInvokeNode) en, nodeSet,
4308 implicitFlowTupleSet);
4311 case Kind.TertiaryNode:
4312 analyzeFlowTertiaryNode(md, nametable, (TertiaryNode) en, nodeSet, implicitFlowTupleSet);
4316 analyzeFlowCastNode(md, nametable, (CastNode) en, nodeSet, base, implicitFlowTupleSet);
4318 // case Kind.InstanceOfNode:
4319 // checkInstanceOfNode(md, nametable, (InstanceOfNode) en, td);
4322 // case Kind.ArrayInitializerNode:
4323 // checkArrayInitializerNode(md, nametable, (ArrayInitializerNode) en,
4327 // case Kind.ClassTypeNode:
4328 // checkClassTypeNode(md, nametable, (ClassTypeNode) en, td);
4331 // case Kind.OffsetNode:
4332 // checkOffsetNode(md, nametable, (OffsetNode)en, td);
4340 private void analyzeFlowCastNode(MethodDescriptor md, SymbolTable nametable, CastNode cn,
4341 NodeTupleSet nodeSet, NTuple<Descriptor> base, NodeTupleSet implicitFlowTupleSet) {
4343 analyzeFlowExpressionNode(md, nametable, cn.getExpression(), nodeSet, base,
4344 implicitFlowTupleSet, false);
4348 private void analyzeFlowTertiaryNode(MethodDescriptor md, SymbolTable nametable, TertiaryNode tn,
4349 NodeTupleSet nodeSet, NodeTupleSet implicitFlowTupleSet) {
4351 NodeTupleSet tertiaryTupleNode = new NodeTupleSet();
4352 analyzeFlowExpressionNode(md, nametable, tn.getCond(), tertiaryTupleNode, null,
4353 implicitFlowTupleSet, false);
4355 // add edges from tertiaryTupleNode to all nodes of conditional nodes
4356 tertiaryTupleNode.addTupleSet(implicitFlowTupleSet);
4357 analyzeFlowExpressionNode(md, nametable, tn.getTrueExpr(), tertiaryTupleNode, null,
4358 implicitFlowTupleSet, false);
4360 analyzeFlowExpressionNode(md, nametable, tn.getFalseExpr(), tertiaryTupleNode, null,
4361 implicitFlowTupleSet, false);
4363 nodeSet.addTupleSet(tertiaryTupleNode);
4367 private void addMapCallerMethodDescToMethodInvokeNodeSet(MethodDescriptor caller,
4368 MethodInvokeNode min) {
4369 Set<MethodInvokeNode> set = mapMethodDescriptorToMethodInvokeNodeSet.get(caller);
4371 set = new HashSet<MethodInvokeNode>();
4372 mapMethodDescriptorToMethodInvokeNodeSet.put(caller, set);
4377 private void addParamNodeFlowingToReturnValue(MethodDescriptor md, FlowNode fn) {
4379 if (!mapMethodDescToParamNodeFlowsToReturnValue.containsKey(md)) {
4380 mapMethodDescToParamNodeFlowsToReturnValue.put(md, new HashSet<FlowNode>());
4382 mapMethodDescToParamNodeFlowsToReturnValue.get(md).add(fn);
4385 private Set<FlowNode> getParamNodeFlowingToReturnValue(MethodDescriptor md) {
4387 if (!mapMethodDescToParamNodeFlowsToReturnValue.containsKey(md)) {
4388 mapMethodDescToParamNodeFlowsToReturnValue.put(md, new HashSet<FlowNode>());
4391 return mapMethodDescToParamNodeFlowsToReturnValue.get(md);
4394 private void analyzeFlowMethodInvokeNode(MethodDescriptor md, SymbolTable nametable,
4395 MethodInvokeNode min, NodeTupleSet nodeSet, NodeTupleSet implicitFlowTupleSet) {
4397 System.out.println("analyzeFlowMethodInvokeNode=" + min.printNode(0));
4399 mapMethodInvokeNodeToArgIdxMap.put(min, new HashMap<Integer, NTuple<Descriptor>>());
4401 if (nodeSet == null) {
4402 nodeSet = new NodeTupleSet();
4405 MethodDescriptor calleeMethodDesc = min.getMethod();
4407 NameDescriptor baseName = min.getBaseName();
4408 boolean isSystemout = false;
4409 if (baseName != null) {
4410 isSystemout = baseName.getSymbol().equals("System.out");
4413 if (!ssjava.isSSJavaUtil(calleeMethodDesc.getClassDesc())
4414 && !ssjava.isTrustMethod(calleeMethodDesc) && !isSystemout) {
4416 addMapCallerMethodDescToMethodInvokeNodeSet(md, min);
4418 FlowGraph calleeFlowGraph = getFlowGraph(calleeMethodDesc);
4419 Set<FlowNode> calleeReturnSet = calleeFlowGraph.getReturnNodeSet();
4421 // System.out.println("-calleeReturnSet=" + calleeReturnSet);
4423 if (min.getExpression() != null) {
4425 NodeTupleSet baseNodeSet = new NodeTupleSet();
4426 analyzeFlowExpressionNode(md, nametable, min.getExpression(), baseNodeSet, null,
4427 implicitFlowTupleSet, false);
4429 assert (baseNodeSet.size() == 1);
4430 NTuple<Descriptor> baseTuple = baseNodeSet.iterator().next();
4431 mapMethodInvokeNodeToBaseTuple.put(min, baseTuple);
4433 if (!min.getMethod().isStatic()) {
4434 addArgIdxMap(min, 0, baseTuple);
4436 for (Iterator iterator = calleeReturnSet.iterator(); iterator.hasNext();) {
4437 FlowNode returnNode = (FlowNode) iterator.next();
4438 NTuple<Descriptor> returnDescTuple = returnNode.getDescTuple();
4439 if (returnDescTuple.startsWith(calleeMethodDesc.getThis())) {
4440 // the location type of the return value is started with 'this'
4442 NTuple<Descriptor> inFlowTuple = new NTuple<Descriptor>(baseTuple.getList());
4443 inFlowTuple.addAll(returnDescTuple.subList(1, returnDescTuple.size()));
4444 nodeSet.addTuple(inFlowTuple);
4447 Set<FlowNode> inFlowSet = calleeFlowGraph.getIncomingFlowNodeSet(returnNode);
4448 // System.out.println("inFlowSet=" + inFlowSet + " from retrunNode=" + returnNode);
4449 for (Iterator iterator2 = inFlowSet.iterator(); iterator2.hasNext();) {
4450 FlowNode inFlowNode = (FlowNode) iterator2.next();
4451 if (inFlowNode.getDescTuple().startsWith(calleeMethodDesc.getThis())) {
4452 nodeSet.addTupleSet(baseNodeSet);
4461 // analyze parameter flows
4463 if (min.numArgs() > 0) {
4466 if (min.getMethod().isStatic()) {
4472 for (int i = 0; i < min.numArgs(); i++) {
4473 ExpressionNode en = min.getArg(i);
4474 int idx = i + offset;
4475 NodeTupleSet argTupleSet = new NodeTupleSet();
4476 analyzeFlowExpressionNode(md, nametable, en, argTupleSet, false);
4477 // if argument is liternal node, argTuple is set to NULL
4479 NTuple<Descriptor> argTuple = new NTuple<Descriptor>();
4480 if (argTupleSet.size() > 1) {
4481 NTuple<Descriptor> interTuple =
4482 getFlowGraph(md).createIntermediateNode().getDescTuple();
4483 for (Iterator<NTuple<Descriptor>> idxIter = argTupleSet.iterator(); idxIter.hasNext();) {
4484 NTuple<Descriptor> tuple = idxIter.next();
4485 addFlowGraphEdge(md, tuple, interTuple);
4487 argTuple = interTuple;
4488 } else if (argTupleSet.size() == 1) {
4489 argTuple = argTupleSet.iterator().next();
4491 argTuple = new NTuple<Descriptor>();
4494 addArgIdxMap(min, idx, argTuple);
4496 FlowNode paramNode = calleeFlowGraph.getParamFlowNode(idx);
4497 if (hasInFlowTo(calleeFlowGraph, paramNode, calleeReturnSet)
4498 || calleeMethodDesc.getModifiers().isNative()) {
4499 addParamNodeFlowingToReturnValue(calleeMethodDesc, paramNode);
4500 nodeSet.addTupleSet(argTupleSet);
4506 // propagateFlowsFromCallee(min, md, min.getMethod());
4508 System.out.println("min nodeSet=" + nodeSet);
4513 private boolean hasInFlowTo(FlowGraph fg, FlowNode inNode, Set<FlowNode> nodeSet) {
4514 // return true if inNode has in-flows to nodeSet
4516 // Set<FlowNode> reachableSet = fg.getReachFlowNodeSetFrom(inNode);
4517 Set<FlowNode> reachableSet = fg.getReachableSetFrom(inNode.getDescTuple());
4518 System.out.println("inNode=" + inNode + " reachalbeSet=" + reachableSet);
4520 for (Iterator iterator = reachableSet.iterator(); iterator.hasNext();) {
4521 FlowNode fn = (FlowNode) iterator.next();
4522 if (nodeSet.contains(fn)) {
4529 private NTuple<Descriptor> getNodeTupleByArgIdx(MethodInvokeNode min, int idx) {
4530 return mapMethodInvokeNodeToArgIdxMap.get(min).get(new Integer(idx));
4533 private void addArgIdxMap(MethodInvokeNode min, int idx, NTuple<Descriptor> argTuple /*
4537 Map<Integer, NTuple<Descriptor>> mapIdxToTuple = mapMethodInvokeNodeToArgIdxMap.get(min);
4538 if (mapIdxToTuple == null) {
4539 mapIdxToTuple = new HashMap<Integer, NTuple<Descriptor>>();
4540 mapMethodInvokeNodeToArgIdxMap.put(min, mapIdxToTuple);
4542 mapIdxToTuple.put(new Integer(idx), argTuple);
4545 private void analyzeLiteralNode(MethodDescriptor md, SymbolTable nametable, LiteralNode en) {
4549 private void analyzeFlowArrayAccessNode(MethodDescriptor md, SymbolTable nametable,
4550 ArrayAccessNode aan, NodeTupleSet nodeSet, boolean isLHS) {
4552 NodeTupleSet expNodeTupleSet = new NodeTupleSet();
4553 NTuple<Descriptor> base =
4554 analyzeFlowExpressionNode(md, nametable, aan.getExpression(), expNodeTupleSet, isLHS);
4556 NodeTupleSet idxNodeTupleSet = new NodeTupleSet();
4557 analyzeFlowExpressionNode(md, nametable, aan.getIndex(), idxNodeTupleSet, isLHS);
4560 // need to create an edge from idx to array
4561 for (Iterator<NTuple<Descriptor>> idxIter = idxNodeTupleSet.iterator(); idxIter.hasNext();) {
4562 NTuple<Descriptor> idxTuple = idxIter.next();
4563 for (Iterator<NTuple<Descriptor>> arrIter = expNodeTupleSet.iterator(); arrIter.hasNext();) {
4564 NTuple<Descriptor> arrTuple = arrIter.next();
4565 getFlowGraph(md).addValueFlowEdge(idxTuple, arrTuple);
4569 nodeSet.addTupleSet(expNodeTupleSet);
4571 nodeSet.addTupleSet(expNodeTupleSet);
4572 nodeSet.addTupleSet(idxNodeTupleSet);
4576 private void analyzeCreateObjectNode(MethodDescriptor md, SymbolTable nametable,
4577 CreateObjectNode en) {
4578 // TODO Auto-generated method stub
4582 private void analyzeFlowOpNode(MethodDescriptor md, SymbolTable nametable, OpNode on,
4583 NodeTupleSet nodeSet, NodeTupleSet implicitFlowTupleSet) {
4585 NodeTupleSet leftOpSet = new NodeTupleSet();
4586 NodeTupleSet rightOpSet = new NodeTupleSet();
4589 analyzeFlowExpressionNode(md, nametable, on.getLeft(), leftOpSet, null, implicitFlowTupleSet,
4592 if (on.getRight() != null) {
4594 analyzeFlowExpressionNode(md, nametable, on.getRight(), rightOpSet, null,
4595 implicitFlowTupleSet, false);
4598 Operation op = on.getOp();
4600 switch (op.getOp()) {
4602 case Operation.UNARYPLUS:
4603 case Operation.UNARYMINUS:
4604 case Operation.LOGIC_NOT:
4606 nodeSet.addTupleSet(leftOpSet);
4609 case Operation.LOGIC_OR:
4610 case Operation.LOGIC_AND:
4611 case Operation.COMP:
4612 case Operation.BIT_OR:
4613 case Operation.BIT_XOR:
4614 case Operation.BIT_AND:
4615 case Operation.ISAVAILABLE:
4616 case Operation.EQUAL:
4617 case Operation.NOTEQUAL:
4624 case Operation.MULT:
4627 case Operation.LEFTSHIFT:
4628 case Operation.RIGHTSHIFT:
4629 case Operation.URIGHTSHIFT:
4631 // there are two operands
4632 nodeSet.addTupleSet(leftOpSet);
4633 nodeSet.addTupleSet(rightOpSet);
4637 throw new Error(op.toString());
4642 private NTuple<Descriptor> analyzeFlowNameNode(MethodDescriptor md, SymbolTable nametable,
4643 NameNode nn, NodeTupleSet nodeSet, NTuple<Descriptor> base, NodeTupleSet implicitFlowTupleSet) {
4645 // System.out.println("analyzeFlowNameNode=" + nn.printNode(0));
4648 base = new NTuple<Descriptor>();
4651 NameDescriptor nd = nn.getName();
4653 if (nd.getBase() != null) {
4655 analyzeFlowExpressionNode(md, nametable, nn.getExpression(), nodeSet, base,
4656 implicitFlowTupleSet, false);
4658 // base node has the top location
4662 String varname = nd.toString();
4663 if (varname.equals("this")) {
4665 base.add(md.getThis());
4669 Descriptor d = (Descriptor) nametable.get(varname);
4671 if (d instanceof VarDescriptor) {
4672 VarDescriptor vd = (VarDescriptor) d;
4674 } else if (d instanceof FieldDescriptor) {
4675 // the type of field descriptor has a location!
4676 FieldDescriptor fd = (FieldDescriptor) d;
4677 if (fd.isStatic()) {
4679 // if it is 'static final', no need to have flow node for the TOP
4683 // if 'static', assign the default GLOBAL LOCATION to the first
4684 // element of the tuple
4685 base.add(GLOBALDESC);
4688 // the location of field access starts from this, followed by field
4690 base.add(md.getThis());
4694 } else if (d == null) {
4695 // access static field
4696 base.add(GLOBALDESC);
4697 base.add(nn.getField());
4700 // FieldDescriptor fd = nn.getField();addFlowGraphEdge
4702 // MethodLattice<String> localLattice = ssjava.getMethodLattice(md);
4703 // String globalLocId = localLattice.getGlobalLoc();
4704 // if (globalLocId == null) {
4706 // Error("Method lattice does not define global variable location at "
4707 // + generateErrorMessage(md.getClassDesc(), nn));
4709 // loc.addLocation(new Location(md, globalLocId));
4711 // Location fieldLoc = (Location) fd.getType().getExtension();
4712 // loc.addLocation(fieldLoc);
4718 getFlowGraph(md).createNewFlowNode(base);
4724 private NTuple<Descriptor> analyzeFlowFieldAccessNode(MethodDescriptor md, SymbolTable nametable,
4725 FieldAccessNode fan, NodeTupleSet nodeSet, NTuple<Descriptor> base,
4726 NodeTupleSet implicitFlowTupleSet, boolean isLHS) {
4728 ExpressionNode left = fan.getExpression();
4729 TypeDescriptor ltd = left.getType();
4730 FieldDescriptor fd = fan.getField();
4732 String varName = null;
4733 if (left.kind() == Kind.NameNode) {
4734 NameDescriptor nd = ((NameNode) left).getName();
4735 varName = nd.toString();
4738 if (ltd.isClassNameRef() || (varName != null && varName.equals("this"))) {
4739 // using a class name directly or access using this
4740 if (fd.isStatic() && fd.isFinal()) {
4745 NodeTupleSet idxNodeTupleSet = new NodeTupleSet();
4747 if (left instanceof ArrayAccessNode) {
4749 ArrayAccessNode aan = (ArrayAccessNode) left;
4750 left = aan.getExpression();
4751 analyzeFlowExpressionNode(md, nametable, aan.getIndex(), idxNodeTupleSet, base,
4752 implicitFlowTupleSet, isLHS);
4754 nodeSet.addTupleSet(idxNodeTupleSet);
4757 analyzeFlowExpressionNode(md, nametable, left, nodeSet, base, implicitFlowTupleSet, isLHS);
4760 // in this case, field is TOP location
4764 NTuple<Descriptor> flowFieldTuple = new NTuple<Descriptor>(base.toList());
4766 if (!left.getType().isPrimitive()) {
4768 if (!fd.getSymbol().equals("length")) {
4769 // array.length access, just have the location of the array
4770 flowFieldTuple.add(fd);
4771 nodeSet.removeTuple(base);
4775 getFlowGraph(md).createNewFlowNode(flowFieldTuple);
4778 for (Iterator<NTuple<Descriptor>> idxIter = idxNodeTupleSet.iterator(); idxIter.hasNext();) {
4779 NTuple<Descriptor> idxTuple = idxIter.next();
4780 getFlowGraph(md).addValueFlowEdge(idxTuple, flowFieldTuple);
4783 return flowFieldTuple;
4789 private void debug_printTreeNode(TreeNode tn) {
4791 System.out.println("DEBUG: " + tn.printNode(0) + " line#=" + tn.getNumLine());
4795 private void analyzeFlowAssignmentNode(MethodDescriptor md, SymbolTable nametable,
4796 AssignmentNode an, NodeTupleSet nodeSet, NTuple<Descriptor> base,
4797 NodeTupleSet implicitFlowTupleSet) {
4799 NodeTupleSet nodeSetRHS = new NodeTupleSet();
4800 NodeTupleSet nodeSetLHS = new NodeTupleSet();
4802 boolean postinc = true;
4803 if (an.getOperation().getBaseOp() == null
4804 || (an.getOperation().getBaseOp().getOp() != Operation.POSTINC && an.getOperation()
4805 .getBaseOp().getOp() != Operation.POSTDEC)) {
4808 // if LHS is array access node, need to capture value flows between an array
4809 // and its index value
4810 analyzeFlowExpressionNode(md, nametable, an.getDest(), nodeSetLHS, null, implicitFlowTupleSet,
4814 // analyze value flows of rhs expression
4815 analyzeFlowExpressionNode(md, nametable, an.getSrc(), nodeSetRHS, null, implicitFlowTupleSet,
4818 // System.out.println("-analyzeFlowAssignmentNode=" + an.printNode(0));
4819 // System.out.println("-nodeSetLHS=" + nodeSetLHS);
4820 // System.out.println("-nodeSetRHS=" + nodeSetRHS);
4821 // System.out.println("-implicitFlowTupleSet=" + implicitFlowTupleSet);
4822 // System.out.println("-");
4824 if (an.getOperation().getOp() >= 2 && an.getOperation().getOp() <= 12) {
4825 // if assignment contains OP+EQ operator, creates edges from LHS to LHS
4827 for (Iterator<NTuple<Descriptor>> iter = nodeSetLHS.iterator(); iter.hasNext();) {
4828 NTuple<Descriptor> fromTuple = iter.next();
4829 for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
4830 NTuple<Descriptor> toTuple = iter2.next();
4831 addFlowGraphEdge(md, fromTuple, toTuple);
4836 // creates edges from RHS to LHS
4837 NTuple<Descriptor> interTuple = null;
4838 if (nodeSetRHS.size() > 1) {
4839 interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
4842 for (Iterator<NTuple<Descriptor>> iter = nodeSetRHS.iterator(); iter.hasNext();) {
4843 NTuple<Descriptor> fromTuple = iter.next();
4844 for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
4845 NTuple<Descriptor> toTuple = iter2.next();
4846 addFlowGraphEdge(md, fromTuple, interTuple, toTuple);
4850 // creates edges from implicitFlowTupleSet to LHS
4851 for (Iterator<NTuple<Descriptor>> iter = implicitFlowTupleSet.iterator(); iter.hasNext();) {
4852 NTuple<Descriptor> fromTuple = iter.next();
4853 for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
4854 NTuple<Descriptor> toTuple = iter2.next();
4855 addFlowGraphEdge(md, fromTuple, toTuple);
4862 for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
4863 NTuple<Descriptor> tuple = iter2.next();
4864 addFlowGraphEdge(md, tuple, tuple);
4867 // creates edges from implicitFlowTupleSet to LHS
4868 for (Iterator<NTuple<Descriptor>> iter = implicitFlowTupleSet.iterator(); iter.hasNext();) {
4869 NTuple<Descriptor> fromTuple = iter.next();
4870 for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
4871 NTuple<Descriptor> toTuple = iter2.next();
4872 addFlowGraphEdge(md, fromTuple, toTuple);
4878 if (nodeSet != null) {
4879 nodeSet.addTupleSet(nodeSetLHS);
4883 public FlowGraph getFlowGraph(MethodDescriptor md) {
4884 return mapMethodDescriptorToFlowGraph.get(md);
4887 private boolean addFlowGraphEdge(MethodDescriptor md, NTuple<Descriptor> from,
4888 NTuple<Descriptor> to) {
4889 FlowGraph graph = getFlowGraph(md);
4890 graph.addValueFlowEdge(from, to);
4894 private void addFlowGraphEdge(MethodDescriptor md, NTuple<Descriptor> from,
4895 NTuple<Descriptor> inter, NTuple<Descriptor> to) {
4897 FlowGraph graph = getFlowGraph(md);
4899 if (inter != null) {
4900 graph.addValueFlowEdge(from, inter);
4901 graph.addValueFlowEdge(inter, to);
4903 graph.addValueFlowEdge(from, to);
4908 public void writeInferredLatticeDotFile(ClassDescriptor cd, HierarchyGraph simpleHierarchyGraph,
4909 SSJavaLattice<String> locOrder, String nameSuffix) {
4910 writeInferredLatticeDotFile(cd, null, simpleHierarchyGraph, locOrder, nameSuffix);
4913 public void writeInferredLatticeDotFile(ClassDescriptor cd, MethodDescriptor md,
4914 HierarchyGraph simpleHierarchyGraph, SSJavaLattice<String> locOrder, String nameSuffix) {
4916 String fileName = "lattice_";
4919 cd.getSymbol().replaceAll("[\\W_]", "") + "_" + md.toString().replaceAll("[\\W_]", "");
4921 fileName += cd.getSymbol().replaceAll("[\\W_]", "");
4924 fileName += nameSuffix;
4926 Set<Pair<String, String>> pairSet = locOrder.getOrderingPairSet();
4928 Set<String> addedLocSet = new HashSet<String>();
4930 if (pairSet.size() > 0) {
4932 BufferedWriter bw = new BufferedWriter(new FileWriter(fileName + ".dot"));
4934 bw.write("digraph " + fileName + " {\n");
4936 for (Iterator iterator = pairSet.iterator(); iterator.hasNext();) {
4937 // pair is in the form of <higher, lower>
4938 Pair<String, String> pair = (Pair<String, String>) iterator.next();
4940 String highLocId = pair.getFirst();
4941 String lowLocId = pair.getSecond();
4943 if (!addedLocSet.contains(highLocId)) {
4944 addedLocSet.add(highLocId);
4945 drawNode(bw, locOrder, simpleHierarchyGraph, highLocId);
4948 if (!addedLocSet.contains(lowLocId)) {
4949 addedLocSet.add(lowLocId);
4950 drawNode(bw, locOrder, simpleHierarchyGraph, lowLocId);
4953 bw.write(highLocId + " -> " + lowLocId + ";\n");
4958 } catch (IOException e) {
4959 e.printStackTrace();
4966 private String convertMergeSetToString(HierarchyGraph graph, Set<HNode> mergeSet) {
4968 for (Iterator iterator = mergeSet.iterator(); iterator.hasNext();) {
4969 HNode merged = (HNode) iterator.next();
4970 if (merged.isMergeNode()) {
4971 str += convertMergeSetToString(graph, graph.getMapHNodetoMergeSet().get(merged));
4973 str += " " + merged.getName();
4979 private void drawNode(BufferedWriter bw, SSJavaLattice<String> lattice, HierarchyGraph graph,
4980 String locName) throws IOException {
4982 HNode node = graph.getHNode(locName);
4989 if (lattice.isSharedLoc(locName)) {
4990 prettyStr = locName + "*";
4992 prettyStr = locName;
4995 if (node.isMergeNode()) {
4996 Set<HNode> mergeSet = graph.getMapHNodetoMergeSet().get(node);
4997 prettyStr += ":" + convertMergeSetToString(graph, mergeSet);
4999 bw.write(locName + " [label=\"" + prettyStr + "\"]" + ";\n");
5002 public void _debug_printGraph() {
5003 Set<MethodDescriptor> keySet = mapMethodDescriptorToFlowGraph.keySet();
5005 for (Iterator<MethodDescriptor> iterator = keySet.iterator(); iterator.hasNext();) {
5006 MethodDescriptor md = (MethodDescriptor) iterator.next();
5007 FlowGraph fg = mapMethodDescriptorToFlowGraph.get(md);
5010 } catch (IOException e) {
5011 e.printStackTrace();
5019 class CyclicFlowException extends Exception {
5023 class InterDescriptor extends Descriptor {
5025 public InterDescriptor(String name) {