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<MethodInvokeNode, Set<NTuple<Location>>> mapMethodInvokeNodeToPCLocTupleSet;
103 private Map<MethodDescriptor, MethodLocationInfo> mapMethodDescToMethodLocationInfo;
105 private Map<ClassDescriptor, LocationInfo> mapClassToLocationInfo;
107 private Map<MethodDescriptor, Set<MethodDescriptor>> mapMethodToCalleeSet;
109 private Map<MethodDescriptor, Set<FlowNode>> mapMethodDescToParamNodeFlowsToReturnValue;
111 private Map<String, Vector<String>> mapFileNameToLineVector;
113 private Map<Descriptor, Integer> mapDescToDefinitionLine;
115 private Map<Descriptor, LocationSummary> mapDescToLocationSummary;
117 private Map<MethodDescriptor, Set<MethodInvokeNode>> mapMethodDescToMethodInvokeNodeSet;
119 // maps a method descriptor to a sub global flow graph that captures all value flows caused by the
120 // set of callees reachable from the method
121 private Map<MethodDescriptor, GlobalFlowGraph> mapMethodDescriptorToSubGlobalFlowGraph;
123 private Map<MethodInvokeNode, Map<NTuple<Descriptor>, NTuple<Descriptor>>> mapMethodInvokeNodeToMapCallerArgToCalleeArg;
125 private Map<MethodDescriptor, Boolean> mapMethodDescriptorToCompositeReturnCase;
127 public static final String GLOBALLOC = "GLOBALLOC";
129 public static final String INTERLOC = "INTERLOC";
131 public static final String PCLOC = "_PCLOC_";
133 public static final String RLOC = "_RLOC_";
135 public static final Descriptor GLOBALDESC = new NameDescriptor(GLOBALLOC);
137 public static final Descriptor TOPDESC = new NameDescriptor(SSJavaAnalysis.TOP);
139 public static final Descriptor BOTTOMDESC = new NameDescriptor(SSJavaAnalysis.BOTTOM);
141 public static final Descriptor RETURNLOC = new NameDescriptor(RLOC);
143 public static final Descriptor LITERALDESC = new NameDescriptor("LITERAL");
145 public static final HNode TOPHNODE = new HNode(TOPDESC);
147 public static final HNode BOTTOMHNODE = new HNode(BOTTOMDESC);
149 public static String newline = System.getProperty("line.separator");
151 LocationInfo curMethodInfo;
153 private boolean hasChanges = false;
155 boolean debug = true;
157 public static int locSeed = 0;
159 private Stack<String> arrayAccessNodeStack;
161 public LocationInference(SSJavaAnalysis ssjava, State state) {
162 this.ssjava = ssjava;
164 this.temp_toanalyzeList = new ArrayList<ClassDescriptor>();
165 this.temp_toanalyzeMethodList = new ArrayList<MethodDescriptor>();
166 this.mapMethodDescriptorToFlowGraph = new HashMap<MethodDescriptor, FlowGraph>();
167 this.cd2lattice = new HashMap<ClassDescriptor, SSJavaLattice<String>>();
168 this.md2lattice = new HashMap<MethodDescriptor, SSJavaLattice<String>>();
169 this.methodDescriptorsToVisitStack = new Stack<MethodDescriptor>();
170 this.mapMethodDescriptorToMethodInvokeNodeSet =
171 new HashMap<MethodDescriptor, Set<MethodInvokeNode>>();
172 this.mapMethodInvokeNodeToArgIdxMap =
173 new HashMap<MethodInvokeNode, Map<Integer, NTuple<Descriptor>>>();
174 this.mapMethodDescToMethodLocationInfo = new HashMap<MethodDescriptor, MethodLocationInfo>();
175 this.mapMethodToCalleeSet = new HashMap<MethodDescriptor, Set<MethodDescriptor>>();
176 this.mapClassToLocationInfo = new HashMap<ClassDescriptor, LocationInfo>();
178 this.mapFileNameToLineVector = new HashMap<String, Vector<String>>();
179 this.mapDescToDefinitionLine = new HashMap<Descriptor, Integer>();
180 this.mapMethodDescToParamNodeFlowsToReturnValue =
181 new HashMap<MethodDescriptor, Set<FlowNode>>();
183 this.mapDescriptorToHierarchyGraph = new HashMap<Descriptor, HierarchyGraph>();
184 this.mapMethodInvokeNodeToBaseTuple = new HashMap<MethodInvokeNode, NTuple<Descriptor>>();
186 this.mapDescriptorToSkeletonHierarchyGraph = new HashMap<Descriptor, HierarchyGraph>();
187 this.mapDescriptorToCombineSkeletonHierarchyGraph = new HashMap<Descriptor, HierarchyGraph>();
188 this.mapDescriptorToSimpleHierarchyGraph = new HashMap<Descriptor, HierarchyGraph>();
190 this.mapDescriptorToSimpleLattice = new HashMap<Descriptor, SSJavaLattice<String>>();
192 this.mapDescToLocationSummary = new HashMap<Descriptor, LocationSummary>();
194 this.mapMethodDescriptorToSubGlobalFlowGraph = new HashMap<MethodDescriptor, GlobalFlowGraph>();
196 this.mapMethodInvokeNodeToMapCallerArgToCalleeArg =
197 new HashMap<MethodInvokeNode, Map<NTuple<Descriptor>, NTuple<Descriptor>>>();
199 this.mapMethodInvokeNodeToPCLocTupleSet =
200 new HashMap<MethodInvokeNode, Set<NTuple<Location>>>();
202 this.arrayAccessNodeStack = new Stack<String>();
204 this.mapMethodDescToMethodInvokeNodeSet =
205 new HashMap<MethodDescriptor, Set<MethodInvokeNode>>();
207 this.mapMethodDescriptorToCompositeReturnCase = new HashMap<MethodDescriptor, Boolean>();
211 public void setupToAnalyze() {
212 SymbolTable classtable = state.getClassSymbolTable();
213 temp_toanalyzeList.clear();
214 temp_toanalyzeList.addAll(classtable.getValueSet());
215 // Collections.sort(toanalyzeList, new Comparator<ClassDescriptor>() {
216 // public int compare(ClassDescriptor o1, ClassDescriptor o2) {
217 // return o1.getClassName().compareToIgnoreCase(o2.getClassName());
222 public void setupToAnalazeMethod(ClassDescriptor cd) {
224 SymbolTable methodtable = cd.getMethodTable();
225 temp_toanalyzeMethodList.clear();
226 temp_toanalyzeMethodList.addAll(methodtable.getValueSet());
227 Collections.sort(temp_toanalyzeMethodList, new Comparator<MethodDescriptor>() {
228 public int compare(MethodDescriptor o1, MethodDescriptor o2) {
229 return o1.getSymbol().compareToIgnoreCase(o2.getSymbol());
234 public boolean toAnalyzeMethodIsEmpty() {
235 return temp_toanalyzeMethodList.isEmpty();
238 public boolean toAnalyzeIsEmpty() {
239 return temp_toanalyzeList.isEmpty();
242 public ClassDescriptor toAnalyzeNext() {
243 return temp_toanalyzeList.remove(0);
246 public MethodDescriptor toAnalyzeMethodNext() {
247 return temp_toanalyzeMethodList.remove(0);
250 public void inference() {
254 // construct value flow graph
255 constructFlowGraph();
257 constructGlobalFlowGraph();
261 assignCompositeLocation();
263 calculateExtraLocations();
264 addAdditionalOrderingConstraints();
266 _debug_writeFlowGraph();
270 constructHierarchyGraph();
272 debug_writeHierarchyDotFiles();
276 simplifyHierarchyGraph();
278 debug_writeSimpleHierarchyDotFiles();
280 constructSkeletonHierarchyGraph();
282 debug_writeSkeletonHierarchyDotFiles();
284 insertCombinationNodes();
286 debug_writeSkeletonCombinationHierarchyDotFiles();
290 debug_writeLattices();
292 updateCompositeLocationAssignments();
294 generateMethodSummary();
296 generateAnnoatedCode();
302 private void checkReturnNodes() {
303 LinkedList<MethodDescriptor> methodDescList =
304 (LinkedList<MethodDescriptor>) toanalyze_methodDescList.clone();
306 while (!methodDescList.isEmpty()) {
307 MethodDescriptor md = methodDescList.removeLast();
309 if (md.getReturnType() != null && !md.getReturnType().isVoid()) {
310 checkFlowNodeReturnThisField(md);
312 // // in this case, this method will return the composite location that starts with 'this'
313 // FlowGraph flowGraph = getFlowGraph(md);
314 // Set<FlowNode> returnNodeSet = flowGraph.getReturnNodeSet();
321 private void updateFlowGraph() {
323 LinkedList<MethodDescriptor> methodDescList =
324 (LinkedList<MethodDescriptor>) toanalyze_methodDescList.clone();
326 while (!methodDescList.isEmpty()) {
327 MethodDescriptor md = methodDescList.removeLast();
328 if (state.SSJAVADEBUG) {
329 System.out.println();
330 System.out.println("SSJAVA: Updating a flow graph: " + md);
331 propagateFlowsFromCalleesWithNoCompositeLocation(md);
336 public Map<NTuple<Descriptor>, NTuple<Descriptor>> getMapCallerArgToCalleeParam(
337 MethodInvokeNode min) {
339 if (!mapMethodInvokeNodeToMapCallerArgToCalleeArg.containsKey(min)) {
340 mapMethodInvokeNodeToMapCallerArgToCalleeArg.put(min,
341 new HashMap<NTuple<Descriptor>, NTuple<Descriptor>>());
344 return mapMethodInvokeNodeToMapCallerArgToCalleeArg.get(min);
347 public void addMapCallerArgToCalleeParam(MethodInvokeNode min, NTuple<Descriptor> callerArg,
348 NTuple<Descriptor> calleeParam) {
349 getMapCallerArgToCalleeParam(min).put(callerArg, calleeParam);
352 private void assignCompositeLocation() {
353 calculateGlobalValueFlowCompositeLocation();
354 translateCompositeLocationAssignmentToFlowGraph();
357 private void translateCompositeLocationAssignmentToFlowGraph() {
358 System.out.println("\nSSJAVA: Translate composite location assignments to flow graphs:");
359 MethodDescriptor methodEventLoopDesc = ssjava.getMethodContainingSSJavaLoop();
360 translateCompositeLocationAssignmentToFlowGraph(methodEventLoopDesc);
363 private void translateCompositeLocationAssignmentToFlowGraph2() {
364 System.out.println("\nSSJAVA: Translate composite location assignments to flow graphs:");
365 MethodDescriptor methodEventLoopDesc = ssjava.getMethodContainingSSJavaLoop();
366 translateCompositeLocationAssignmentToFlowGraph(methodEventLoopDesc);
369 private void addAdditionalOrderingConstraints() {
370 System.out.println("\nSSJAVA: Add addtional ordering constriants:");
371 MethodDescriptor methodEventLoopDesc = ssjava.getMethodContainingSSJavaLoop();
372 addAddtionalOrderingConstraints(methodEventLoopDesc);
373 // calculateReturnHolderLocation();
376 private void calculateReturnHolderLocation() {
377 LinkedList<MethodDescriptor> methodDescList =
378 (LinkedList<MethodDescriptor>) toanalyze_methodDescList.clone();
380 while (!methodDescList.isEmpty()) {
381 MethodDescriptor md = methodDescList.removeLast();
383 FlowGraph fg = getFlowGraph(md);
384 Set<FlowNode> nodeSet = fg.getNodeSet();
385 for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
386 FlowNode flowNode = (FlowNode) iterator.next();
387 if (flowNode.isFromHolder()) {
388 calculateCompositeLocationFromFlowGraph(md, flowNode);
395 private void updateCompositeLocationAssignments() {
397 LinkedList<MethodDescriptor> methodDescList =
398 (LinkedList<MethodDescriptor>) toanalyze_methodDescList.clone();
400 while (!methodDescList.isEmpty()) {
401 MethodDescriptor md = methodDescList.removeLast();
403 // System.out.println("\n#updateCompositeLocationAssignments=" + md);
405 FlowGraph flowGraph = getFlowGraph(md);
407 MethodSummary methodSummary = getMethodSummary(md);
409 Set<FlowNode> nodeSet = flowGraph.getNodeSet();
410 for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
411 FlowNode node = (FlowNode) iterator.next();
412 System.out.println("-node=" + node + " node.getDescTuple=" + node.getDescTuple());
413 if (node.getCompositeLocation() != null) {
414 CompositeLocation compLoc = node.getCompositeLocation();
415 CompositeLocation updatedCompLoc = updateCompositeLocation(compLoc);
416 node.setCompositeLocation(updatedCompLoc);
417 System.out.println("---updatedCompLoc1=" + updatedCompLoc);
419 NTuple<Descriptor> descTuple = node.getDescTuple();
420 System.out.println("update desc=" + descTuple);
421 CompositeLocation compLoc = convertToCompositeLocation(md, descTuple);
422 compLoc = updateCompositeLocation(compLoc);
423 node.setCompositeLocation(compLoc);
424 System.out.println("---updatedCompLoc2=" + compLoc);
427 if (node.isDeclaratonNode()) {
428 Descriptor localVarDesc = node.getDescTuple().get(0);
429 CompositeLocation compLoc = updateCompositeLocation(node.getCompositeLocation());
430 methodSummary.addMapVarNameToInferCompLoc(localVarDesc, compLoc);
434 // update PCLOC and RETURNLOC if they have a composite location assignment
435 if (methodSummary.getRETURNLoc() != null) {
436 methodSummary.setRETURNLoc(updateCompositeLocation(methodSummary.getRETURNLoc()));
438 if (methodSummary.getPCLoc() != null) {
439 methodSummary.setPCLoc(updateCompositeLocation(methodSummary.getPCLoc()));
446 private CompositeLocation updateCompositeLocation(CompositeLocation compLoc) {
447 CompositeLocation updatedCompLoc = new CompositeLocation();
448 for (int i = 0; i < compLoc.getSize(); i++) {
449 Location loc = compLoc.get(i);
450 String nodeIdentifier = loc.getLocIdentifier();
451 Descriptor enclosingDesc = loc.getDescriptor();
453 if (!enclosingDesc.equals(GLOBALDESC)) {
454 LocationSummary locSummary = getLocationSummary(enclosingDesc);
455 // HierarchyGraph scGraph = getSkeletonCombinationHierarchyGraph(enclosingDesc);
456 HierarchyGraph scGraph = getSimpleHierarchyGraph(enclosingDesc);
457 if (scGraph != null) {
458 HNode curNode = scGraph.getCurrentHNode(nodeIdentifier);
459 System.out.println("nodeID=" + nodeIdentifier + " curNode=" + curNode
460 + " enclosingDesc=" + enclosingDesc);
461 if (curNode != null) {
462 nodeIdentifier = curNode.getName();
465 locName = locSummary.getLocationName(nodeIdentifier);
467 locName = nodeIdentifier;
469 Location updatedLoc = new Location(enclosingDesc, locName);
470 updatedCompLoc.addLocation(updatedLoc);
473 return updatedCompLoc;
476 private void translateCompositeLocationAssignmentToFlowGraph(MethodDescriptor mdCaller) {
478 // System.out.println("\n\n###translateCompositeLocationAssignmentToFlowGraph mdCaller="
481 // First, assign a composite location to a node in the flow graph
482 GlobalFlowGraph callerGlobalFlowGraph = getSubGlobalFlowGraph(mdCaller);
484 FlowGraph callerFlowGraph = getFlowGraph(mdCaller);
485 Map<Location, CompositeLocation> callerMapLocToCompLoc =
486 callerGlobalFlowGraph.getMapLocationToInferCompositeLocation();
488 Set<Location> methodLocSet = callerMapLocToCompLoc.keySet();
489 for (Iterator iterator = methodLocSet.iterator(); iterator.hasNext();) {
490 Location methodLoc = (Location) iterator.next();
491 if (methodLoc.getDescriptor().equals(mdCaller)) {
492 CompositeLocation inferCompLoc = callerMapLocToCompLoc.get(methodLoc);
493 assignCompositeLocationToFlowGraph(callerFlowGraph, methodLoc, inferCompLoc);
497 Set<MethodInvokeNode> minSet = mapMethodDescriptorToMethodInvokeNodeSet.get(mdCaller);
499 Set<MethodDescriptor> calleeSet = new HashSet<MethodDescriptor>();
500 for (Iterator iterator = minSet.iterator(); iterator.hasNext();) {
501 MethodInvokeNode min = (MethodInvokeNode) iterator.next();
502 // need to translate a composite location that is started with the base
504 translateMapLocationToInferCompositeLocationToCalleeGraph(callerGlobalFlowGraph, min);
505 MethodDescriptor mdCallee = min.getMethod();
506 calleeSet.add(mdCallee);
510 for (Iterator iterator = calleeSet.iterator(); iterator.hasNext();) {
511 MethodDescriptor callee = (MethodDescriptor) iterator.next();
512 translateCompositeLocationAssignmentToFlowGraph(callee);
517 private CompositeLocation translateArgCompLocToParamCompLoc(MethodInvokeNode min,
518 CompositeLocation argCompLoc) {
520 System.out.println("--------translateArgCompLocToParamCompLoc argCompLoc=" + argCompLoc);
521 MethodDescriptor mdCallee = min.getMethod();
522 FlowGraph calleeFlowGraph = getFlowGraph(mdCallee);
524 NTuple<Location> argLocTuple = argCompLoc.getTuple();
525 Location argLocalLoc = argLocTuple.get(0);
527 Map<Integer, NTuple<Descriptor>> mapIdxToArgTuple = mapMethodInvokeNodeToArgIdxMap.get(min);
528 Set<Integer> idxSet = mapIdxToArgTuple.keySet();
529 for (Iterator iterator2 = idxSet.iterator(); iterator2.hasNext();) {
530 Integer idx = (Integer) iterator2.next();
532 if (idx == 0 && !min.getMethod().isStatic()) {
536 NTuple<Descriptor> argTuple = mapIdxToArgTuple.get(idx);
537 if (argTuple.size() > 0 && argTuple.get(0).equals(argLocalLoc.getLocDescriptor())) {
538 // it matches with the current argument composite location
539 // so what is the corresponding parameter local descriptor?
540 FlowNode paramNode = calleeFlowGraph.getParamFlowNode(idx);
541 // System.out.println("----------found paramNode=" + paramNode);
542 NTuple<Descriptor> paramDescTuple = paramNode.getCurrentDescTuple();
544 NTuple<Location> newParamTupleFromArgTuple = translateToLocTuple(mdCallee, paramDescTuple);
545 for (int i = 1; i < argLocTuple.size(); i++) {
546 newParamTupleFromArgTuple.add(argLocTuple.get(i));
549 // System.out.println("-----------newParamTuple=" + newParamTupleFromArgTuple);
550 return new CompositeLocation(newParamTupleFromArgTuple);
557 private void addAddtionalOrderingConstraints(MethodDescriptor mdCaller) {
559 // First, assign a composite location to a node in the flow graph
560 GlobalFlowGraph callerGlobalFlowGraph = getSubGlobalFlowGraph(mdCaller);
562 FlowGraph callerFlowGraph = getFlowGraph(mdCaller);
563 Map<Location, CompositeLocation> callerMapLocToCompLoc =
564 callerGlobalFlowGraph.getMapLocationToInferCompositeLocation();
565 Set<Location> methodLocSet = callerMapLocToCompLoc.keySet();
567 Set<MethodInvokeNode> minSet = mapMethodDescriptorToMethodInvokeNodeSet.get(mdCaller);
569 Set<MethodDescriptor> calleeSet = new HashSet<MethodDescriptor>();
570 for (Iterator iterator = minSet.iterator(); iterator.hasNext();) {
571 MethodInvokeNode min = (MethodInvokeNode) iterator.next();
572 MethodDescriptor mdCallee = min.getMethod();
573 calleeSet.add(mdCallee);
576 // add an additional ordering constraint
577 // if the first element of a parameter composite location matches 'this' reference,
578 // the corresponding argument in the caller is required to be higher than the translated
579 // parameter location in the caller lattice
581 // addOrderingConstraintFromCompLocParamToArg(mdCaller, min);
584 // update return flow nodes in the caller
585 CompositeLocation returnLoc = getMethodSummary(mdCallee).getRETURNLoc();
586 System.out.println("### min=" + min.printNode(0) + " returnLoc=" + returnLoc);
587 if (returnLoc != null && returnLoc.get(0).getLocDescriptor().equals(mdCallee.getThis())
588 && returnLoc.getSize() > 1) {
589 System.out.println("###RETURN COMP LOC=" + returnLoc);
590 NTuple<Location> returnLocTuple = returnLoc.getTuple();
591 NTuple<Descriptor> baseTuple = mapMethodInvokeNodeToBaseTuple.get(min);
592 System.out.println("###basetuple=" + baseTuple);
593 NTuple<Descriptor> newReturnTuple = baseTuple.clone();
594 for (int i = 1; i < returnLocTuple.size(); i++) {
595 newReturnTuple.add(returnLocTuple.get(i).getLocDescriptor());
597 System.out.println("###NEW RETURN TUPLE FOR CALLER=" + newReturnTuple);
599 FlowReturnNode holderNode = callerFlowGraph.getFlowReturnNode(min);
600 NodeTupleSet holderTupleSet =
601 getNodeTupleSetFromReturnNode(getFlowGraph(mdCaller), holderNode);
603 callerFlowGraph.getFlowReturnNode(min).setNewTuple(newReturnTuple);
605 // then need to remove old constraints
607 System.out.println("###REMOVE OLD CONSTRAINTS=" + holderNode);
608 for (Iterator<NTuple<Descriptor>> iter = holderTupleSet.iterator(); iter.hasNext();) {
609 NTuple<Descriptor> tupleFromHolder = iter.next();
610 Set<FlowEdge> holderOutEdge = callerFlowGraph.getOutEdgeSet(holderNode);
611 for (Iterator iterator2 = holderOutEdge.iterator(); iterator2.hasNext();) {
612 FlowEdge outEdge = (FlowEdge) iterator2.next();
613 NTuple<Descriptor> toberemovedTuple = outEdge.getEndTuple();
614 // System.out.println("---remove " + tupleFromHolder + " -> " + toberemovedTuple);
615 callerFlowGraph.removeEdge(tupleFromHolder, toberemovedTuple);
620 // if the return loc set was empty and later pcloc was connected to the return loc
621 // need to make sure that return loc reflects to this changes.
622 FlowReturnNode flowReturnNode = callerFlowGraph.getFlowReturnNode(min);
623 if (flowReturnNode != null && flowReturnNode.getReturnTupleSet().isEmpty()) {
625 if (needToUpdateReturnLocHolder(min.getMethod(), flowReturnNode)) {
626 NTuple<Descriptor> baseTuple = mapMethodInvokeNodeToBaseTuple.get(min);
627 NTuple<Descriptor> newReturnTuple = baseTuple.clone();
628 flowReturnNode.addTuple(newReturnTuple);
637 for (Iterator iterator = calleeSet.iterator(); iterator.hasNext();) {
638 MethodDescriptor callee = (MethodDescriptor) iterator.next();
639 addAddtionalOrderingConstraints(callee);
644 private boolean needToUpdateReturnLocHolder(MethodDescriptor mdCallee,
645 FlowReturnNode flowReturnNode) {
646 FlowGraph fg = getFlowGraph(mdCallee);
647 MethodSummary summary = getMethodSummary(mdCallee);
648 CompositeLocation returnCompLoc = summary.getRETURNLoc();
649 NTuple<Descriptor> returnDescTuple = translateToDescTuple(returnCompLoc.getTuple());
650 Set<FlowNode> incomingNodeToReturnNode =
651 fg.getIncomingFlowNodeSet(fg.getFlowNode(returnDescTuple));
652 for (Iterator iterator = incomingNodeToReturnNode.iterator(); iterator.hasNext();) {
653 FlowNode inNode = (FlowNode) iterator.next();
654 if (inNode.getDescTuple().get(0).equals(mdCallee.getThis())) {
661 private void addMapMethodDescToMethodInvokeNodeSet(MethodInvokeNode min) {
662 MethodDescriptor md = min.getMethod();
663 if (!mapMethodDescToMethodInvokeNodeSet.containsKey(md)) {
664 mapMethodDescToMethodInvokeNodeSet.put(md, new HashSet<MethodInvokeNode>());
666 mapMethodDescToMethodInvokeNodeSet.get(md).add(min);
669 private Set<MethodInvokeNode> getMethodInvokeNodeSetByMethodDesc(MethodDescriptor md) {
670 if (!mapMethodDescToMethodInvokeNodeSet.containsKey(md)) {
671 mapMethodDescToMethodInvokeNodeSet.put(md, new HashSet<MethodInvokeNode>());
673 return mapMethodDescToMethodInvokeNodeSet.get(md);
676 private void addOrderingConstraintFromCompLocParamToArg(MethodDescriptor mdCaller,
677 MethodInvokeNode min) {
678 System.out.println("-addOrderingConstraintFromCompLocParamToArg=" + min.printNode(0));
680 GlobalFlowGraph globalGraph = getSubGlobalFlowGraph(ssjava.getMethodContainingSSJavaLoop());
682 Set<NTuple<Location>> pcLocTupleSet = getPCLocTupleSet(min);
684 MethodDescriptor mdCallee = min.getMethod();
686 FlowGraph calleeFlowGraph = getFlowGraph(mdCallee);
687 for (int idx = 0; idx < calleeFlowGraph.getNumParameters(); idx++) {
688 FlowNode paramNode = calleeFlowGraph.getParamFlowNode(idx);
689 NTuple<Location> globalParamLocTuple =
690 translateToLocTuple(mdCallee, paramNode.getDescTuple());
691 translateToLocTuple(mdCallee, paramNode.getDescTuple());
692 CompositeLocation compLoc = paramNode.getCompositeLocation();
693 System.out.println("---paramNode=" + paramNode + " compLoc=" + compLoc);
694 if (compLoc != null) {
695 NTuple<Descriptor> argTuple = getNodeTupleByArgIdx(min, idx);
696 NTuple<Location> globalArgLocTuple = translateToLocTuple(mdCaller, argTuple);
698 if (!isLiteralValueLocTuple(globalArgLocTuple)
699 && !isLiteralValueLocTuple(globalParamLocTuple)) {
700 if (!globalGraph.hasValueFlowEdge(globalArgLocTuple, globalParamLocTuple)) {
701 System.out.println("----- add global flow globalArgLocTuple=" + globalArgLocTuple
702 + "-> globalParamLocTuple=" + globalParamLocTuple);
704 globalGraph.addValueFlowEdge(globalArgLocTuple, globalParamLocTuple);
708 for (Iterator iterator = pcLocTupleSet.iterator(); iterator.hasNext();) {
709 NTuple<Location> pcLocTuple = (NTuple<Location>) iterator.next();
711 if (!isLiteralValueLocTuple(pcLocTuple) && !isLiteralValueLocTuple(globalParamLocTuple)) {
712 if (!globalGraph.hasValueFlowEdge(pcLocTuple, globalParamLocTuple)) {
714 .println("----- add global flow PCLOC="
716 + "-> globalParamLocTu!globalArgLocTuple.get(0).getLocDescriptor().equals(LITERALDESC)ple="
717 + globalParamLocTuple);
720 globalGraph.addValueFlowEdge(pcLocTuple, globalParamLocTuple);
729 private boolean isLiteralValueLocTuple(NTuple<Location> locTuple) {
730 return locTuple.get(0).getLocDescriptor().equals(LITERALDESC);
733 public void assignCompositeLocationToFlowGraph(FlowGraph flowGraph, Location loc,
734 CompositeLocation inferCompLoc) {
735 Descriptor localDesc = loc.getLocDescriptor();
737 Set<FlowNode> nodeSet = flowGraph.getNodeSet();
738 for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
739 FlowNode node = (FlowNode) iterator.next();
740 if (node.getDescTuple().startsWith(localDesc)
741 && !node.getDescTuple().get(0).equals(LITERALDESC)) {
742 // need to assign the inferred composite location to this node
743 CompositeLocation newCompLoc = generateCompositeLocation(node.getDescTuple(), inferCompLoc);
744 node.setCompositeLocation(newCompLoc);
745 System.out.println("SET Node=" + node + " inferCompLoc=" + newCompLoc);
750 private CompositeLocation generateCompositeLocation(NTuple<Descriptor> nodeDescTuple,
751 CompositeLocation inferCompLoc) {
753 System.out.println("generateCompositeLocation=" + nodeDescTuple + " with inferCompLoc="
756 MethodDescriptor md = (MethodDescriptor) inferCompLoc.get(0).getDescriptor();
758 CompositeLocation newCompLoc = new CompositeLocation();
759 for (int i = 0; i < inferCompLoc.getSize(); i++) {
760 newCompLoc.addLocation(inferCompLoc.get(i));
763 Descriptor lastDescOfPrefix = nodeDescTuple.get(0);
764 Descriptor enclosingDescriptor;
765 if (lastDescOfPrefix instanceof InterDescriptor) {
766 enclosingDescriptor = getFlowGraph(md).getEnclosingDescriptor(lastDescOfPrefix);
768 enclosingDescriptor = ((VarDescriptor) lastDescOfPrefix).getType().getClassDesc();
771 for (int i = 1; i < nodeDescTuple.size(); i++) {
772 Descriptor desc = nodeDescTuple.get(i);
773 Location locElement = new Location(enclosingDescriptor, desc);
774 newCompLoc.addLocation(locElement);
776 enclosingDescriptor = ((FieldDescriptor) desc).getClassDescriptor();
782 private void translateMapLocationToInferCompositeLocationToCalleeGraph(
783 GlobalFlowGraph callerGraph, MethodInvokeNode min) {
785 MethodDescriptor mdCallee = min.getMethod();
786 MethodDescriptor mdCaller = callerGraph.getMethodDescriptor();
787 Map<Location, CompositeLocation> callerMapLocToCompLoc =
788 callerGraph.getMapLocationToInferCompositeLocation();
790 Map<Integer, NTuple<Descriptor>> mapIdxToArgTuple = mapMethodInvokeNodeToArgIdxMap.get(min);
792 FlowGraph calleeFlowGraph = getFlowGraph(mdCallee);
793 GlobalFlowGraph calleeGlobalGraph = getSubGlobalFlowGraph(mdCallee);
795 NTuple<Location> baseLocTuple = null;
796 if (mapMethodInvokeNodeToBaseTuple.containsKey(min)) {
797 baseLocTuple = translateToLocTuple(mdCaller, mapMethodInvokeNodeToBaseTuple.get(min));
800 // System.out.println("\n-#translate caller=" + mdCaller + " infer composite loc to callee="
801 // + mdCallee + " baseLocTuple=" + baseLocTuple);
803 Set<Location> keySet = callerMapLocToCompLoc.keySet();
804 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
805 Location key = (Location) iterator.next();
806 CompositeLocation callerCompLoc = callerMapLocToCompLoc.get(key);
808 if (!key.getDescriptor().equals(mdCaller)) {
810 CompositeLocation newCalleeCompLoc;
811 if (baseLocTuple != null && callerCompLoc.getTuple().startsWith(baseLocTuple)) {
812 // System.out.println("-----need to translate callerCompLoc=" + callerCompLoc
813 // + " with baseTuple=" + baseLocTuple);
815 translateCompositeLocationToCallee(callerCompLoc, baseLocTuple, mdCallee);
817 calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, newCalleeCompLoc);
818 // System.out.println("1---key=" + key + " callerCompLoc=" + callerCompLoc
819 // + " newCalleeCompLoc=" + newCalleeCompLoc);
820 // System.out.println("-----caller=" + mdCaller + " callee=" + mdCallee);
821 if (!newCalleeCompLoc.get(0).getDescriptor().equals(mdCallee)) {
825 // System.out.println("-----baseLoctuple=" + baseLocTuple);
827 // check if it is the global access
828 Location compLocFirstElement = callerCompLoc.getTuple().get(0);
829 if (compLocFirstElement.getDescriptor().equals(mdCallee)
830 && compLocFirstElement.getLocDescriptor().equals(GLOBALDESC)) {
832 newCalleeCompLoc = new CompositeLocation();
833 Location newMethodLoc = new Location(mdCallee, GLOBALDESC);
835 newCalleeCompLoc.addLocation(newMethodLoc);
836 for (int i = 1; i < callerCompLoc.getSize(); i++) {
837 newCalleeCompLoc.addLocation(callerCompLoc.get(i));
839 calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, newCalleeCompLoc);
840 // System.out.println("2---key=" + key + " callerCompLoc=" + callerCompLoc
841 // + " newCalleeCompLoc=" + newCalleeCompLoc);
842 // System.out.println("-----caller=" + mdCaller + " callee=" + mdCallee);
845 int paramIdx = getParamIdx(callerCompLoc, mapIdxToArgTuple);
846 if (paramIdx == -1) {
847 // here, the first element of the current composite location comes from the current
849 // so transfer the same composite location to the callee
850 if (!calleeGlobalGraph.contrainsInferCompositeLocationMapKey(key)) {
851 if (callerCompLoc.get(0).getDescriptor().equals(mdCallee)) {
852 // System.out.println("3---key=" + key + " callerCompLoc=" + callerCompLoc
853 // + " newCalleeCompLoc=" + callerCompLoc);
854 // System.out.println("-----caller=" + mdCaller + " callee=" + mdCallee);
855 calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, callerCompLoc);
857 // System.out.println("3---SKIP key=" + key + " callerCompLoc=" + callerCompLoc);
863 // It is the case where two parameters have relative orderings between them by having
864 // composite locations
865 // if we found the param idx, it means that the first part of the caller composite
866 // location corresponds to the one of arguments.
867 // for example, if the caller argument is <<caller.this>,<Decoder.br>>
868 // and the current caller composite location mapping
869 // <<caller.this>,<Decoder.br>,<Br.value>>
870 // and the parameter which matches with the caller argument is 'Br brParam'
871 // then, the translated callee composite location will be <<callee.brParam>,<Br.value>>
872 NTuple<Descriptor> argTuple = mapIdxToArgTuple.get(paramIdx);
874 FlowNode paramFlowNode = calleeFlowGraph.getParamFlowNode(paramIdx);
875 NTuple<Location> paramLocTuple =
876 translateToLocTuple(mdCallee, paramFlowNode.getDescTuple());
877 newCalleeCompLoc = new CompositeLocation();
878 for (int i = 0; i < paramLocTuple.size(); i++) {
879 newCalleeCompLoc.addLocation(paramLocTuple.get(i));
881 for (int i = argTuple.size(); i < callerCompLoc.getSize(); i++) {
882 newCalleeCompLoc.addLocation(callerCompLoc.get(i));
884 calleeGlobalGraph.addMapLocationToInferCompositeLocation(key, newCalleeCompLoc);
885 // System.out.println("4---key=" + key + " callerCompLoc=" + callerCompLoc
886 // + " newCalleeCompLoc=" + newCalleeCompLoc);
887 // System.out.println("-----caller=" + mdCaller + " callee=" + mdCallee);
896 System.out.println("#ASSIGN COMP LOC TO CALLEE PARAMS: callee=" + mdCallee + " caller="
898 // If the location of an argument has a composite location
899 // need to assign a proper composite location to the corresponding callee parameter
900 Set<Integer> idxSet = mapIdxToArgTuple.keySet();
901 for (Iterator iterator = idxSet.iterator(); iterator.hasNext();) {
902 Integer idx = (Integer) iterator.next();
904 if (idx == 0 && !min.getMethod().isStatic()) {
908 NTuple<Descriptor> argTuple = mapIdxToArgTuple.get(idx);
909 System.out.println("-argTuple=" + argTuple + " idx=" + idx);
910 if (argTuple.size() > 0) {
911 // check if an arg tuple has been already assigned to a composite location
912 NTuple<Location> argLocTuple = translateToLocTuple(mdCaller, argTuple);
913 Location argLocalLoc = argLocTuple.get(0);
915 // if (!isPrimitiveType(argTuple)) {
916 if (callerMapLocToCompLoc.containsKey(argLocalLoc)) {
918 CompositeLocation callerCompLoc = callerMapLocToCompLoc.get(argLocalLoc);
919 for (int i = 1; i < argLocTuple.size(); i++) {
920 callerCompLoc.addLocation(argLocTuple.get(i));
923 System.out.println("---callerCompLoc=" + callerCompLoc);
925 // if (baseLocTuple != null && callerCompLoc.getTuple().startsWith(baseLocTuple)) {
927 FlowNode calleeParamFlowNode = calleeFlowGraph.getParamFlowNode(idx);
929 NTuple<Descriptor> calleeParamDescTuple = calleeParamFlowNode.getDescTuple();
930 NTuple<Location> calleeParamLocTuple =
931 translateToLocTuple(mdCallee, calleeParamDescTuple);
933 int refParamIdx = getParamIdx(callerCompLoc, mapIdxToArgTuple);
934 System.out.println("-----paramIdx=" + refParamIdx);
935 if (refParamIdx == 0 && !mdCallee.isStatic()) {
937 System.out.println("-------need to translate callerCompLoc=" + callerCompLoc
938 + " with baseTuple=" + baseLocTuple + " calleeParamLocTuple="
939 + calleeParamLocTuple);
941 CompositeLocation newCalleeCompLoc =
942 translateCompositeLocationToCallee(callerCompLoc, baseLocTuple, mdCallee);
944 calleeGlobalGraph.addMapLocationToInferCompositeLocation(calleeParamLocTuple.get(0),
947 System.out.println("---------key=" + calleeParamLocTuple.get(0) + " callerCompLoc="
948 + callerCompLoc + " newCalleeCompLoc=" + newCalleeCompLoc);
950 } else if (refParamIdx != -1) {
951 // the first element of an argument composite location matches with one of paramtere
952 // composite locations
954 System.out.println("-------param match case=");
956 NTuple<Descriptor> argTupleRef = mapIdxToArgTuple.get(refParamIdx);
957 FlowNode refParamFlowNode = calleeFlowGraph.getParamFlowNode(refParamIdx);
958 NTuple<Location> refParamLocTuple =
959 translateToLocTuple(mdCallee, refParamFlowNode.getDescTuple());
961 System.out.println("---------refParamLocTuple=" + refParamLocTuple
962 + " from argTupleRef=" + argTupleRef);
964 CompositeLocation newCalleeCompLoc = new CompositeLocation();
965 for (int i = 0; i < refParamLocTuple.size(); i++) {
966 newCalleeCompLoc.addLocation(refParamLocTuple.get(i));
968 for (int i = argTupleRef.size(); i < callerCompLoc.getSize(); i++) {
969 newCalleeCompLoc.addLocation(callerCompLoc.get(i));
972 calleeGlobalGraph.addMapLocationToInferCompositeLocation(calleeParamLocTuple.get(0),
975 calleeParamFlowNode.setCompositeLocation(newCalleeCompLoc);
976 System.out.println("-----------key=" + calleeParamLocTuple.get(0) + " callerCompLoc="
977 + callerCompLoc + " newCalleeCompLoc=" + newCalleeCompLoc);
980 CompositeLocation newCalleeCompLoc =
981 calculateCompositeLocationFromSubGlobalGraph(mdCallee, calleeParamFlowNode);
982 if (newCalleeCompLoc != null) {
983 calleeGlobalGraph.addMapLocationToInferCompositeLocation(calleeParamLocTuple.get(0),
985 calleeParamFlowNode.setCompositeLocation(newCalleeCompLoc);
989 System.out.println("-----------------calleeParamFlowNode="
990 + calleeParamFlowNode.getCompositeLocation());
1001 private CompositeLocation calculateCompositeLocationFromSubGlobalGraph(MethodDescriptor md,
1002 FlowNode paramNode) {
1004 System.out.println("#############################################################");
1005 System.out.println("calculateCompositeLocationFromSubGlobalGraph=" + paramNode);
1007 GlobalFlowGraph subGlobalFlowGraph = getSubGlobalFlowGraph(md);
1008 NTuple<Location> paramLocTuple = translateToLocTuple(md, paramNode.getDescTuple());
1009 GlobalFlowNode paramGlobalNode = subGlobalFlowGraph.getFlowNode(paramLocTuple);
1011 List<NTuple<Location>> prefixList = calculatePrefixList(subGlobalFlowGraph, paramGlobalNode);
1013 Location prefixLoc = paramLocTuple.get(0);
1015 Set<GlobalFlowNode> reachableNodeSet =
1016 subGlobalFlowGraph.getReachableNodeSetByPrefix(paramGlobalNode.getLocTuple().get(0));
1017 // Set<GlobalFlowNode> reachNodeSet = globalFlowGraph.getReachableNodeSetFrom(node);
1019 // System.out.println("node=" + node + " prefixList=" + prefixList);
1021 for (int i = 0; i < prefixList.size(); i++) {
1022 NTuple<Location> curPrefix = prefixList.get(i);
1023 Set<NTuple<Location>> reachableCommonPrefixSet = new HashSet<NTuple<Location>>();
1025 for (Iterator iterator2 = reachableNodeSet.iterator(); iterator2.hasNext();) {
1026 GlobalFlowNode reachNode = (GlobalFlowNode) iterator2.next();
1027 if (reachNode.getLocTuple().startsWith(curPrefix)) {
1028 reachableCommonPrefixSet.add(reachNode.getLocTuple());
1031 // System.out.println("reachableCommonPrefixSet=" + reachableCommonPrefixSet);
1033 if (!reachableCommonPrefixSet.isEmpty()) {
1035 MethodDescriptor curPrefixFirstElementMethodDesc =
1036 (MethodDescriptor) curPrefix.get(0).getDescriptor();
1038 MethodDescriptor nodePrefixLocFirstElementMethodDesc =
1039 (MethodDescriptor) prefixLoc.getDescriptor();
1041 // System.out.println("curPrefixFirstElementMethodDesc=" +
1042 // curPrefixFirstElementMethodDesc);
1043 // System.out.println("nodePrefixLocFirstElementMethodDesc="
1044 // + nodePrefixLocFirstElementMethodDesc);
1046 if (curPrefixFirstElementMethodDesc.equals(nodePrefixLocFirstElementMethodDesc)
1047 || isTransitivelyCalledFrom(nodePrefixLocFirstElementMethodDesc,
1048 curPrefixFirstElementMethodDesc)) {
1051 // if (!node.getLocTuple().startsWith(curPrefix.get(0))) {
1053 Location curPrefixLocalLoc = curPrefix.get(0);
1054 if (subGlobalFlowGraph.mapLocationToInferCompositeLocation.containsKey(curPrefixLocalLoc)) {
1055 // in this case, the local variable of the current prefix has already got a composite
1057 // so we just ignore the current composite location.
1059 // System.out.println("HERE WE DO NOT ASSIGN A COMPOSITE LOCATION TO =" + node
1060 // + " DUE TO " + curPrefix);
1064 if (!needToGenerateCompositeLocation(paramGlobalNode, curPrefix)) {
1065 System.out.println("NO NEED TO GENERATE COMP LOC to " + paramGlobalNode
1066 + " with prefix=" + curPrefix);
1070 Location targetLocalLoc = paramGlobalNode.getLocTuple().get(0);
1071 CompositeLocation newCompLoc = generateCompositeLocation(curPrefix);
1072 System.out.println("NEED TO ASSIGN COMP LOC TO " + paramGlobalNode + " with prefix="
1074 System.out.println("-targetLocalLoc=" + targetLocalLoc + " - newCompLoc=" + newCompLoc);
1076 // makes sure that a newly generated location appears in the hierarchy graph
1077 for (int compIdx = 0; compIdx < newCompLoc.getSize(); compIdx++) {
1078 Location curLoc = newCompLoc.get(compIdx);
1079 getHierarchyGraph(curLoc.getDescriptor()).getHNode(curLoc.getLocDescriptor());
1082 subGlobalFlowGraph.addMapLocationToInferCompositeLocation(targetLocalLoc, newCompLoc);
1094 private int getParamIdx(CompositeLocation compLoc,
1095 Map<Integer, NTuple<Descriptor>> mapIdxToArgTuple) {
1097 // if the composite location is started with the argument descriptor
1098 // return the argument's index. o.t. return -1
1100 Set<Integer> keySet = mapIdxToArgTuple.keySet();
1101 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
1102 Integer key = (Integer) iterator.next();
1103 NTuple<Descriptor> argTuple = mapIdxToArgTuple.get(key);
1104 if (argTuple.size() > 0 && translateToDescTuple(compLoc.getTuple()).startsWith(argTuple)) {
1105 System.out.println("compLoc.getTuple=" + compLoc + " is started with " + argTuple);
1106 return key.intValue();
1113 private boolean isPrimitiveType(NTuple<Descriptor> argTuple) {
1115 Descriptor lastDesc = argTuple.get(argTuple.size() - 1);
1117 if (lastDesc instanceof FieldDescriptor) {
1118 return ((FieldDescriptor) lastDesc).getType().isPrimitive();
1119 } else if (lastDesc instanceof VarDescriptor) {
1120 return ((VarDescriptor) lastDesc).getType().isPrimitive();
1121 } else if (lastDesc instanceof InterDescriptor) {
1128 private CompositeLocation translateCompositeLocationToCallee(CompositeLocation callerCompLoc,
1129 NTuple<Location> baseLocTuple, MethodDescriptor mdCallee) {
1131 CompositeLocation newCalleeCompLoc = new CompositeLocation();
1133 Location calleeThisLoc = new Location(mdCallee, mdCallee.getThis());
1134 newCalleeCompLoc.addLocation(calleeThisLoc);
1136 // remove the base tuple from the caller
1137 // ex; In the method invoation foo.bar.methodA(), the callee will have the composite location
1138 // ,which is relative to the 'this' variable, <THIS,...>
1139 for (int i = baseLocTuple.size(); i < callerCompLoc.getSize(); i++) {
1140 newCalleeCompLoc.addLocation(callerCompLoc.get(i));
1143 return newCalleeCompLoc;
1147 private void calculateGlobalValueFlowCompositeLocation() {
1149 System.out.println("SSJAVA: Calculate composite locations in the global value flow graph");
1150 MethodDescriptor methodDescEventLoop = ssjava.getMethodContainingSSJavaLoop();
1151 GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(methodDescEventLoop);
1153 Set<Location> calculatedPrefixSet = new HashSet<Location>();
1155 Set<GlobalFlowNode> nodeSet = globalFlowGraph.getNodeSet();
1157 next: for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
1158 GlobalFlowNode node = (GlobalFlowNode) iterator.next();
1160 Location prefixLoc = node.getLocTuple().get(0);
1162 if (calculatedPrefixSet.contains(prefixLoc)) {
1163 // the prefix loc has been already assigned to a composite location
1167 calculatedPrefixSet.add(prefixLoc);
1169 // Set<GlobalFlowNode> incomingNodeSet = globalFlowGraph.getIncomingNodeSet(node);
1170 List<NTuple<Location>> prefixList = calculatePrefixList(globalFlowGraph, node);
1172 Set<GlobalFlowNode> reachableNodeSet =
1173 globalFlowGraph.getReachableNodeSetByPrefix(node.getLocTuple().get(0));
1174 // Set<GlobalFlowNode> reachNodeSet = globalFlowGraph.getReachableNodeSetFrom(node);
1176 // System.out.println("node=" + node + " prefixList=" + prefixList);
1177 System.out.println("---prefixList=" + prefixList);
1179 nextprefix: for (int i = 0; i < prefixList.size(); i++) {
1180 NTuple<Location> curPrefix = prefixList.get(i);
1181 System.out.println("---curPrefix=" + curPrefix);
1182 Set<NTuple<Location>> reachableCommonPrefixSet = new HashSet<NTuple<Location>>();
1184 for (Iterator iterator2 = reachableNodeSet.iterator(); iterator2.hasNext();) {
1185 GlobalFlowNode reachNode = (GlobalFlowNode) iterator2.next();
1186 if (reachNode.getLocTuple().startsWith(curPrefix)) {
1187 reachableCommonPrefixSet.add(reachNode.getLocTuple());
1190 // System.out.println("reachableCommonPrefixSet=" + reachableCommonPrefixSet);
1192 if (!reachableCommonPrefixSet.isEmpty()) {
1194 MethodDescriptor curPrefixFirstElementMethodDesc =
1195 (MethodDescriptor) curPrefix.get(0).getDescriptor();
1197 MethodDescriptor nodePrefixLocFirstElementMethodDesc =
1198 (MethodDescriptor) prefixLoc.getDescriptor();
1200 // System.out.println("curPrefixFirstElementMethodDesc=" +
1201 // curPrefixFirstElementMethodDesc);
1202 // System.out.println("nodePrefixLocFirstElementMethodDesc="
1203 // + nodePrefixLocFirstElementMethodDesc);
1205 if (curPrefixFirstElementMethodDesc.equals(nodePrefixLocFirstElementMethodDesc)
1206 || isTransitivelyCalledFrom(nodePrefixLocFirstElementMethodDesc,
1207 curPrefixFirstElementMethodDesc)) {
1210 // if (!node.getLocTuple().startsWith(curPrefix.get(0))) {
1212 Location curPrefixLocalLoc = curPrefix.get(0);
1213 if (globalFlowGraph.mapLocationToInferCompositeLocation.containsKey(curPrefixLocalLoc)) {
1214 // in this case, the local variable of the current prefix has already got a composite
1216 // so we just ignore the current composite location.
1218 // System.out.println("HERE WE DO NOT ASSIGN A COMPOSITE LOCATION TO =" + node
1219 // + " DUE TO " + curPrefix);
1224 if (!needToGenerateCompositeLocation(node, curPrefix)) {
1225 System.out.println("NO NEED TO GENERATE COMP LOC to " + node + " with prefix="
1227 // System.out.println("prefixList=" + prefixList);
1228 // System.out.println("reachableNodeSet=" + reachableNodeSet);
1229 continue nextprefix;
1232 Location targetLocalLoc = node.getLocTuple().get(0);
1233 CompositeLocation newCompLoc = generateCompositeLocation(curPrefix);
1234 System.out.println("NEED TO ASSIGN COMP LOC TO " + node + " with prefix=" + curPrefix);
1235 System.out.println("-targetLocalLoc=" + targetLocalLoc + " - newCompLoc="
1237 globalFlowGraph.addMapLocationToInferCompositeLocation(targetLocalLoc, newCompLoc);
1252 private boolean checkFlowNodeReturnThisField(MethodDescriptor md) {
1254 MethodDescriptor methodDescEventLoop = ssjava.getMethodContainingSSJavaLoop();
1255 GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(methodDescEventLoop);
1257 FlowGraph flowGraph = getFlowGraph(md);
1259 ClassDescriptor enclosingDesc = getClassTypeDescriptor(md.getThis());
1260 if (enclosingDesc == null) {
1265 Set<FlowNode> returnNodeSet = flowGraph.getReturnNodeSet();
1266 Set<GlobalFlowNode> globalReturnNodeSet = new HashSet<GlobalFlowNode>();
1267 for (Iterator iterator = returnNodeSet.iterator(); iterator.hasNext();) {
1268 FlowNode flowNode = (FlowNode) iterator.next();
1269 NTuple<Location> locTuple = translateToLocTuple(md, flowNode.getDescTuple());
1270 GlobalFlowNode globalReturnNode = globalFlowGraph.getFlowNode(locTuple);
1271 globalReturnNodeSet.add(globalReturnNode);
1273 List<NTuple<Location>> prefixList = calculatePrefixList(globalFlowGraph, globalReturnNode);
1274 for (int i = 0; i < prefixList.size(); i++) {
1275 NTuple<Location> curPrefix = prefixList.get(i);
1276 ClassDescriptor cd =
1277 getClassTypeDescriptor(curPrefix.get(curPrefix.size() - 1).getLocDescriptor());
1278 if (cd != null && cd.equals(enclosingDesc)) {
1286 if (count == returnNodeSet.size()) {
1287 // in this case, all return nodes in the method returns values coming from a location that
1288 // starts with "this"
1290 System.out.println("$$$SET RETURN LOC TRUE=" + md);
1291 mapMethodDescriptorToCompositeReturnCase.put(md, Boolean.TRUE);
1293 // NameDescriptor returnLocDesc = new NameDescriptor("RLOC" + (locSeed++));
1294 // NTuple<Descriptor> rDescTuple = new NTuple<Descriptor>();
1295 // rDescTuple.add(md.getThis());
1296 // rDescTuple.add(returnLocDesc);
1298 // for (Iterator iterator = returnNodeSet.iterator(); iterator.hasNext();) {
1299 // FlowNode rnode = (FlowNode) iterator.next();
1300 // flowGraph.addValueFlowEdge(rnode.getDescTuple(), rDescTuple);
1303 // getMethodSummary(md).setRETURNLoc(new CompositeLocation(translateToLocTuple(md,
1307 mapMethodDescriptorToCompositeReturnCase.put(md, Boolean.FALSE);
1310 return mapMethodDescriptorToCompositeReturnCase.get(md).booleanValue();
1314 private boolean needToGenerateCompositeLocation(GlobalFlowNode node, NTuple<Location> curPrefix) {
1315 // return true if there is a path between a node to which we want to give a composite location
1316 // and nodes which start with curPrefix
1318 System.out.println("---needToGenerateCompositeLocation curPrefix=" + curPrefix);
1320 Location targetLocalLoc = node.getLocTuple().get(0);
1322 MethodDescriptor md = (MethodDescriptor) targetLocalLoc.getDescriptor();
1323 FlowGraph flowGraph = getFlowGraph(md);
1325 FlowNode flowNode = flowGraph.getFlowNode(node.getDescTuple());
1326 Set<FlowNode> reachableSet = flowGraph.getReachFlowNodeSetFrom(flowNode);
1328 Set<FlowNode> paramNodeSet = flowGraph.getParamFlowNodeSet();
1329 for (Iterator iterator = paramNodeSet.iterator(); iterator.hasNext();) {
1330 FlowNode paramFlowNode = (FlowNode) iterator.next();
1331 if (curPrefix.startsWith(translateToLocTuple(md, paramFlowNode.getDescTuple()))) {
1336 if (targetLocalLoc.getLocDescriptor() instanceof InterDescriptor) {
1337 Pair<MethodInvokeNode, Integer> pair =
1338 ((InterDescriptor) targetLocalLoc.getLocDescriptor()).getMethodArgIdxPair();
1341 System.out.println("$$$TARGETLOCALLOC HOLDER=" + targetLocalLoc);
1343 MethodInvokeNode min = pair.getFirst();
1344 Integer paramIdx = pair.getSecond();
1345 MethodDescriptor mdCallee = min.getMethod();
1347 FlowNode paramNode = getFlowGraph(mdCallee).getParamFlowNode(paramIdx);
1348 if (checkNodeReachToReturnNode(mdCallee, paramNode)) {
1356 GlobalFlowGraph subGlobalFlowGraph = getSubGlobalFlowGraph(md);
1357 Set<GlobalFlowNode> subGlobalReachableSet = subGlobalFlowGraph.getReachableNodeSetFrom(node);
1359 if (!md.isStatic()) {
1360 ClassDescriptor currentMethodThisType = getClassTypeDescriptor(md.getThis());
1361 for (int i = 0; i < curPrefix.size(); i++) {
1362 ClassDescriptor prefixType = getClassTypeDescriptor(curPrefix.get(i).getLocDescriptor());
1363 if (prefixType != null && prefixType.equals(currentMethodThisType)) {
1364 System.out.println("PREFIX TYPE MATCHES WITH=" + currentMethodThisType);
1366 if (mapMethodDescriptorToCompositeReturnCase.containsKey(md)) {
1367 boolean hasCompReturnLocWithThis =
1368 mapMethodDescriptorToCompositeReturnCase.get(md).booleanValue();
1369 if (hasCompReturnLocWithThis) {
1370 if (checkNodeReachToReturnNode(md, flowNode)) {
1376 for (Iterator iterator3 = subGlobalReachableSet.iterator(); iterator3.hasNext();) {
1377 GlobalFlowNode subGlobalReachalbeNode = (GlobalFlowNode) iterator3.next();
1378 if (subGlobalReachalbeNode.getLocTuple().get(0).getLocDescriptor().equals(md.getThis())) {
1379 System.out.println("PREFIX FOUND=" + subGlobalReachalbeNode);
1387 Location lastLocationOfPrefix = curPrefix.get(curPrefix.size() - 1);
1388 // check whether prefix appears in the list of parameters
1389 Set<MethodInvokeNode> minSet = mapMethodDescToMethodInvokeNodeSet.get(md);
1390 found: for (Iterator iterator = minSet.iterator(); iterator.hasNext();) {
1391 MethodInvokeNode min = (MethodInvokeNode) iterator.next();
1392 Map<Integer, NTuple<Descriptor>> map = mapMethodInvokeNodeToArgIdxMap.get(min);
1393 Set<Integer> keySet = map.keySet();
1394 // System.out.println("min=" + min.printNode(0));
1396 for (Iterator iterator2 = keySet.iterator(); iterator2.hasNext();) {
1397 Integer argIdx = (Integer) iterator2.next();
1398 NTuple<Descriptor> argTuple = map.get(argIdx);
1400 if (!(!md.isStatic() && argIdx == 0)) {
1401 // if the argTuple is empty, we don't need to do with anything(LITERAL CASE).
1402 if (argTuple.size() > 0
1403 && argTuple.get(argTuple.size() - 1).equals(lastLocationOfPrefix.getLocDescriptor())) {
1404 NTuple<Location> locTuple =
1405 translateToLocTuple(md, flowGraph.getParamFlowNode(argIdx).getDescTuple());
1406 lastLocationOfPrefix = locTuple.get(0);
1407 System.out.println("ARG CASE=" + locTuple);
1408 for (Iterator iterator3 = subGlobalReachableSet.iterator(); iterator3.hasNext();) {
1409 GlobalFlowNode subGlobalReachalbeNode = (GlobalFlowNode) iterator3.next();
1410 // NTuple<Location> locTuple = translateToLocTuple(md, reachalbeNode.getDescTuple());
1411 NTuple<Location> globalReachlocTuple = subGlobalReachalbeNode.getLocTuple();
1412 for (int i = 0; i < globalReachlocTuple.size(); i++) {
1413 if (globalReachlocTuple.get(i).equals(lastLocationOfPrefix)) {
1414 System.out.println("ARG " + argTuple + " IS MATCHED WITH="
1415 + lastLocationOfPrefix);
1428 private boolean checkNodeReachToReturnNode(MethodDescriptor md, FlowNode node) {
1430 FlowGraph flowGraph = getFlowGraph(md);
1431 Set<FlowNode> reachableSet = flowGraph.getReachFlowNodeSetFrom(node);
1432 if (mapMethodDescriptorToCompositeReturnCase.containsKey(md)) {
1433 boolean hasCompReturnLocWithThis =
1434 mapMethodDescriptorToCompositeReturnCase.get(md).booleanValue();
1436 if (hasCompReturnLocWithThis) {
1437 for (Iterator iterator = flowGraph.getReturnNodeSet().iterator(); iterator.hasNext();) {
1438 FlowNode returnFlowNode = (FlowNode) iterator.next();
1439 if (reachableSet.contains(returnFlowNode)) {
1448 private void assignCompositeLocation(CompositeLocation compLocPrefix, GlobalFlowNode node) {
1449 CompositeLocation newCompLoc = compLocPrefix.clone();
1450 NTuple<Location> locTuple = node.getLocTuple();
1451 for (int i = 1; i < locTuple.size(); i++) {
1452 newCompLoc.addLocation(locTuple.get(i));
1454 node.setInferCompositeLocation(newCompLoc);
1457 private List<NTuple<Location>> calculatePrefixList(GlobalFlowGraph graph, GlobalFlowNode node) {
1459 System.out.println("\n##### calculatePrefixList node=" + node);
1461 Set<GlobalFlowNode> incomingNodeSetPrefix =
1462 graph.getIncomingNodeSetByPrefix(node.getLocTuple().get(0));
1463 // System.out.println("---incomingNodeSetPrefix=" + incomingNodeSetPrefix);
1465 Set<GlobalFlowNode> reachableNodeSetPrefix =
1466 graph.getReachableNodeSetByPrefix(node.getLocTuple().get(0));
1467 // System.out.println("---reachableNodeSetPrefix=" + reachableNodeSetPrefix);
1469 List<NTuple<Location>> prefixList = new ArrayList<NTuple<Location>>();
1471 for (Iterator iterator = incomingNodeSetPrefix.iterator(); iterator.hasNext();) {
1472 GlobalFlowNode inNode = (GlobalFlowNode) iterator.next();
1473 NTuple<Location> inNodeTuple = inNode.getLocTuple();
1475 if (inNodeTuple.get(0).getLocDescriptor() instanceof InterDescriptor
1476 || inNodeTuple.get(0).getLocDescriptor().equals(GLOBALDESC)) {
1480 for (int i = 1; i < inNodeTuple.size(); i++) {
1481 NTuple<Location> prefix = inNodeTuple.subList(0, i);
1482 if (!prefixList.contains(prefix)) {
1483 prefixList.add(prefix);
1488 Collections.sort(prefixList, new Comparator<NTuple<Location>>() {
1489 public int compare(NTuple<Location> arg0, NTuple<Location> arg1) {
1490 int s0 = arg0.size();
1491 int s1 = arg1.size();
1494 } else if (s0 == s1) {
1506 private CompositeLocation calculateCompositeLocationFromFlowGraph(MethodDescriptor md,
1509 System.out.println("#############################################################");
1510 System.out.println("calculateCompositeLocationFromFlowGraph=" + node);
1512 FlowGraph flowGraph = getFlowGraph(md);
1513 // NTuple<Location> paramLocTuple = translateToLocTuple(md, paramNode.getDescTuple());
1514 // GlobalFlowNode paramGlobalNode = subGlobalFlowGraph.getFlowNode(paramLocTuple);
1516 List<NTuple<Location>> prefixList = calculatePrefixListFlowGraph(flowGraph, node);
1518 // Set<GlobalFlowNode> reachableNodeSet =
1519 // subGlobalFlowGraph.getReachableNodeSetByPrefix(paramGlobalNode.getLocTuple().get(0));
1521 Set<FlowNode> reachableNodeSet =
1522 flowGraph.getReachableSetFrom(node.getDescTuple().subList(0, 1));
1524 // Set<GlobalFlowNode> reachNodeSet = globalFlowGraph.getReachableNodeSetFrom(node);
1526 // System.out.println("node=" + node + " prefixList=" + prefixList);
1528 for (int i = 0; i < prefixList.size(); i++) {
1529 NTuple<Location> curPrefix = prefixList.get(i);
1530 Set<NTuple<Location>> reachableCommonPrefixSet = new HashSet<NTuple<Location>>();
1532 for (Iterator iterator2 = reachableNodeSet.iterator(); iterator2.hasNext();) {
1533 FlowNode reachNode = (FlowNode) iterator2.next();
1534 NTuple<Location> reachLocTuple = translateToLocTuple(md, reachNode.getCurrentDescTuple());
1535 if (reachLocTuple.startsWith(curPrefix)) {
1536 reachableCommonPrefixSet.add(reachLocTuple);
1539 // System.out.println("reachableCommonPrefixSet=" + reachableCommonPrefixSet);
1541 if (!reachableCommonPrefixSet.isEmpty()) {
1543 MethodDescriptor curPrefixFirstElementMethodDesc =
1544 (MethodDescriptor) curPrefix.get(0).getDescriptor();
1546 Location curPrefixLocalLoc = curPrefix.get(0);
1548 Location targetLocalLoc = new Location(md, node.getDescTuple().get(0));
1549 // Location targetLocalLoc = paramGlobalNode.getLocTuple().get(0);
1551 CompositeLocation newCompLoc = generateCompositeLocation(curPrefix);
1552 System.out.println("NEED2ASSIGN COMP LOC TO " + node + " with prefix=" + curPrefix);
1553 System.out.println("-targetLocalLoc=" + targetLocalLoc + " - newCompLoc=" + newCompLoc);
1555 node.setCompositeLocation(newCompLoc);
1565 private List<NTuple<Location>> calculatePrefixListFlowGraph(FlowGraph graph, FlowNode node) {
1567 System.out.println("\n##### calculatePrefixList node=" + node);
1569 MethodDescriptor md = graph.getMethodDescriptor();
1570 Set<FlowNode> incomingNodeSetPrefix =
1571 graph.getIncomingNodeSetByPrefix(node.getDescTuple().get(0));
1572 // System.out.println("---incomingNodeSetPrefix=" + incomingNodeSetPrefix);
1574 Set<FlowNode> reachableNodeSetPrefix =
1575 graph.getReachableSetFrom(node.getDescTuple().subList(0, 1));
1576 // System.out.println("---reachableNodeSetPrefix=" + reachableNodeSetPrefix);
1578 List<NTuple<Location>> prefixList = new ArrayList<NTuple<Location>>();
1580 for (Iterator iterator = incomingNodeSetPrefix.iterator(); iterator.hasNext();) {
1581 FlowNode inNode = (FlowNode) iterator.next();
1582 NTuple<Location> inNodeTuple = translateToLocTuple(md, inNode.getCurrentDescTuple());
1584 // if (inNodeTuple.get(0).getLocDescriptor() instanceof InterDescriptor
1585 // || inNodeTuple.get(0).getLocDescriptor().equals(GLOBALDESC)) {
1589 for (int i = 1; i < inNodeTuple.size(); i++) {
1590 NTuple<Location> prefix = inNodeTuple.subList(0, i);
1591 if (!prefixList.contains(prefix)) {
1592 prefixList.add(prefix);
1597 Collections.sort(prefixList, new Comparator<NTuple<Location>>() {
1598 public int compare(NTuple<Location> arg0, NTuple<Location> arg1) {
1599 int s0 = arg0.size();
1600 int s1 = arg1.size();
1603 } else if (s0 == s1) {
1615 private boolean containsClassDesc(ClassDescriptor cd, NTuple<Location> prefixLocTuple) {
1616 for (int i = 0; i < prefixLocTuple.size(); i++) {
1617 Location loc = prefixLocTuple.get(i);
1618 Descriptor locDesc = loc.getLocDescriptor();
1619 if (locDesc != null) {
1620 ClassDescriptor type = getClassTypeDescriptor(locDesc);
1621 if (type != null && type.equals(cd)) {
1629 private GlobalFlowGraph constructSubGlobalFlowGraph(FlowGraph flowGraph) {
1631 MethodDescriptor md = flowGraph.getMethodDescriptor();
1633 GlobalFlowGraph globalGraph = getSubGlobalFlowGraph(md);
1635 // Set<FlowNode> nodeSet = flowGraph.getNodeSet();
1636 Set<FlowEdge> edgeSet = flowGraph.getEdgeSet();
1638 for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) {
1640 FlowEdge edge = (FlowEdge) iterator.next();
1641 NTuple<Descriptor> srcDescTuple = edge.getInitTuple();
1642 NTuple<Descriptor> dstDescTuple = edge.getEndTuple();
1644 if (flowGraph.getFlowNode(srcDescTuple) instanceof FlowReturnNode
1645 || flowGraph.getFlowNode(dstDescTuple) instanceof FlowReturnNode) {
1649 // here only keep the first element(method location) of the descriptor
1651 NTuple<Location> srcLocTuple = translateToLocTuple(md, srcDescTuple);
1652 NTuple<Location> dstLocTuple = translateToLocTuple(md, dstDescTuple);
1654 globalGraph.addValueFlowEdge(srcLocTuple, dstLocTuple);
1661 private NTuple<Location> translateToLocTuple(MethodDescriptor md, NTuple<Descriptor> descTuple) {
1663 NTuple<Location> locTuple = new NTuple<Location>();
1665 Descriptor enclosingDesc = md;
1666 for (int i = 0; i < descTuple.size(); i++) {
1667 Descriptor desc = descTuple.get(i);
1669 Location loc = new Location(enclosingDesc, desc);
1672 if (desc instanceof VarDescriptor) {
1673 enclosingDesc = ((VarDescriptor) desc).getType().getClassDesc();
1674 } else if (desc instanceof FieldDescriptor) {
1675 enclosingDesc = ((FieldDescriptor) desc).getType().getClassDesc();
1677 enclosingDesc = desc;
1686 private void addValueFlowsFromCalleeSubGlobalFlowGraph(MethodDescriptor mdCaller) {
1688 // the transformation for a call site propagates flows through parameters
1689 // if the method is virtual, it also grab all relations from any possible
1692 Set<MethodInvokeNode> setMethodInvokeNode = getMethodInvokeNodeSet(mdCaller);
1694 for (Iterator iterator = setMethodInvokeNode.iterator(); iterator.hasNext();) {
1695 MethodInvokeNode min = (MethodInvokeNode) iterator.next();
1696 MethodDescriptor mdCallee = min.getMethod();
1697 Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
1698 if (mdCallee.isStatic()) {
1699 setPossibleCallees.add(mdCallee);
1701 Set<MethodDescriptor> calleeSet = ssjava.getCallGraph().getMethods(mdCallee);
1702 // removes method descriptors that are not invoked by the caller
1703 calleeSet.retainAll(mapMethodToCalleeSet.get(mdCaller));
1704 setPossibleCallees.addAll(calleeSet);
1707 for (Iterator iterator2 = setPossibleCallees.iterator(); iterator2.hasNext();) {
1708 MethodDescriptor possibleMdCallee = (MethodDescriptor) iterator2.next();
1709 propagateValueFlowsToCallerFromSubGlobalFlowGraph(min, mdCaller, possibleMdCallee);
1716 private void propagateValueFlowsToCallerFromSubGlobalFlowGraph(MethodInvokeNode min,
1717 MethodDescriptor mdCaller, MethodDescriptor possibleMdCallee) {
1719 System.out.println("---propagate from " + min.printNode(0) + " to caller=" + mdCaller);
1720 FlowGraph calleeFlowGraph = getFlowGraph(possibleMdCallee);
1721 Map<Integer, NTuple<Descriptor>> mapIdxToArg = mapMethodInvokeNodeToArgIdxMap.get(min);
1723 System.out.println("-----mapMethodInvokeNodeToArgIdxMap.get(min)="
1724 + mapMethodInvokeNodeToArgIdxMap.get(min));
1726 Set<Integer> keySet = mapIdxToArg.keySet();
1727 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
1728 Integer idx = (Integer) iterator.next();
1729 NTuple<Descriptor> argDescTuple = mapIdxToArg.get(idx);
1730 if (argDescTuple.size() > 0) {
1731 NTuple<Location> argLocTuple = translateToLocTuple(mdCaller, argDescTuple);
1732 NTuple<Descriptor> paramDescTuple = calleeFlowGraph.getParamFlowNode(idx).getDescTuple();
1733 NTuple<Location> paramLocTuple = translateToLocTuple(possibleMdCallee, paramDescTuple);
1734 System.out.println("-------paramDescTuple=" + paramDescTuple + "->argDescTuple="
1736 addMapCallerArgToCalleeParam(min, argDescTuple, paramDescTuple);
1740 // addValueFlowBetweenParametersToCaller(min, mdCaller, possibleMdCallee);
1742 NTuple<Descriptor> baseTuple = mapMethodInvokeNodeToBaseTuple.get(min);
1743 GlobalFlowGraph calleeSubGlobalGraph = getSubGlobalFlowGraph(possibleMdCallee);
1744 Set<GlobalFlowNode> calleeNodeSet = calleeSubGlobalGraph.getNodeSet();
1745 for (Iterator iterator = calleeNodeSet.iterator(); iterator.hasNext();) {
1746 GlobalFlowNode calleeNode = (GlobalFlowNode) iterator.next();
1747 addValueFlowFromCalleeNode(min, mdCaller, possibleMdCallee, calleeNode);
1750 System.out.println("$$$GLOBAL PC LOC ADD=" + mdCaller);
1751 Set<NTuple<Location>> pcLocTupleSet = mapMethodInvokeNodeToPCLocTupleSet.get(min);
1752 System.out.println("---pcLocTupleSet=" + pcLocTupleSet);
1753 GlobalFlowGraph callerSubGlobalGraph = getSubGlobalFlowGraph(mdCaller);
1754 for (Iterator iterator = calleeNodeSet.iterator(); iterator.hasNext();) {
1755 GlobalFlowNode calleeNode = (GlobalFlowNode) iterator.next();
1756 if (calleeNode.isParamNodeWithIncomingFlows()) {
1757 System.out.println("calleeNode.getLocTuple()" + calleeNode.getLocTuple());
1758 NTuple<Location> callerSrcNodeLocTuple =
1759 translateToCallerLocTuple(min, possibleMdCallee, mdCaller, calleeNode.getLocTuple());
1760 System.out.println("---callerSrcNodeLocTuple=" + callerSrcNodeLocTuple);
1761 if (callerSrcNodeLocTuple != null && callerSrcNodeLocTuple.size() > 0) {
1762 for (Iterator iterator2 = pcLocTupleSet.iterator(); iterator2.hasNext();) {
1763 NTuple<Location> pcLocTuple = (NTuple<Location>) iterator2.next();
1765 callerSubGlobalGraph.addValueFlowEdge(pcLocTuple, callerSrcNodeLocTuple);
1774 private void addValueFlowFromCalleeNode(MethodInvokeNode min, MethodDescriptor mdCaller,
1775 MethodDescriptor mdCallee, GlobalFlowNode calleeSrcNode) {
1777 GlobalFlowGraph calleeSubGlobalGraph = getSubGlobalFlowGraph(mdCallee);
1778 GlobalFlowGraph callerSubGlobalGraph = getSubGlobalFlowGraph(mdCaller);
1780 System.out.println("$addValueFlowFromCalleeNode calleeSrcNode=" + calleeSrcNode);
1782 NTuple<Location> callerSrcNodeLocTuple =
1783 translateToCallerLocTuple(min, mdCallee, mdCaller, calleeSrcNode.getLocTuple());
1784 System.out.println("---callerSrcNodeLocTuple=" + callerSrcNodeLocTuple);
1786 if (callerSrcNodeLocTuple != null && callerSrcNodeLocTuple.size() > 0) {
1788 Set<GlobalFlowNode> outNodeSet = calleeSubGlobalGraph.getOutNodeSet(calleeSrcNode);
1790 for (Iterator iterator = outNodeSet.iterator(); iterator.hasNext();) {
1791 GlobalFlowNode outNode = (GlobalFlowNode) iterator.next();
1792 NTuple<Location> callerDstNodeLocTuple =
1793 translateToCallerLocTuple(min, mdCallee, mdCaller, outNode.getLocTuple());
1794 // System.out.println("outNode=" + outNode + " callerDstNodeLocTuple="
1795 // + callerDstNodeLocTuple);
1796 if (callerSrcNodeLocTuple != null && callerDstNodeLocTuple != null
1797 && callerSrcNodeLocTuple.size() > 0 && callerDstNodeLocTuple.size() > 0) {
1798 callerSubGlobalGraph.addValueFlowEdge(callerSrcNodeLocTuple, callerDstNodeLocTuple);
1805 private NTuple<Location> translateToCallerLocTuple(MethodInvokeNode min,
1806 MethodDescriptor mdCallee, MethodDescriptor mdCaller, NTuple<Location> nodeLocTuple) {
1807 // this method will return the same nodeLocTuple if the corresponding argument is literal
1810 // System.out.println("translateToCallerLocTuple=" + nodeLocTuple);
1812 FlowGraph calleeFlowGraph = getFlowGraph(mdCallee);
1813 NTuple<Descriptor> nodeDescTuple = translateToDescTuple(nodeLocTuple);
1814 if (calleeFlowGraph.isParameter(nodeDescTuple)) {
1815 int paramIdx = calleeFlowGraph.getParamIdx(nodeDescTuple);
1816 NTuple<Descriptor> argDescTuple = mapMethodInvokeNodeToArgIdxMap.get(min).get(paramIdx);
1818 // if (isPrimitive(nodeLocTuple.get(0).getLocDescriptor())) {
1819 // // the type of argument is primitive.
1820 // return nodeLocTuple.clone();
1822 // System.out.println("paramIdx=" + paramIdx + " argDescTuple=" + argDescTuple + " from min="
1823 // + min.printNode(0));
1824 NTuple<Location> argLocTuple = translateToLocTuple(mdCaller, argDescTuple);
1826 NTuple<Location> callerLocTuple = new NTuple<Location>();
1828 callerLocTuple.addAll(argLocTuple);
1829 for (int i = 1; i < nodeLocTuple.size(); i++) {
1830 callerLocTuple.add(nodeLocTuple.get(i));
1832 return callerLocTuple;
1834 return nodeLocTuple.clone();
1839 public static boolean isPrimitive(Descriptor desc) {
1841 if (desc instanceof FieldDescriptor) {
1842 return ((FieldDescriptor) desc).getType().isPrimitive();
1843 } else if (desc instanceof VarDescriptor) {
1844 return ((VarDescriptor) desc).getType().isPrimitive();
1845 } else if (desc instanceof InterDescriptor) {
1852 public static boolean isReference(Descriptor desc) {
1854 if (desc instanceof FieldDescriptor) {
1856 TypeDescriptor type = ((FieldDescriptor) desc).getType();
1857 if (type.isArray()) {
1858 return !type.isPrimitive();
1860 return type.isPtr();
1863 } else if (desc instanceof VarDescriptor) {
1864 TypeDescriptor type = ((VarDescriptor) desc).getType();
1865 if (type.isArray()) {
1866 return !type.isPrimitive();
1868 return type.isPtr();
1875 private NTuple<Descriptor> translateToDescTuple(NTuple<Location> locTuple) {
1877 NTuple<Descriptor> descTuple = new NTuple<Descriptor>();
1878 for (int i = 0; i < locTuple.size(); i++) {
1879 descTuple.add(locTuple.get(i).getLocDescriptor());
1885 public LocationSummary getLocationSummary(Descriptor d) {
1886 if (!mapDescToLocationSummary.containsKey(d)) {
1887 if (d instanceof MethodDescriptor) {
1888 mapDescToLocationSummary.put(d, new MethodSummary((MethodDescriptor) d));
1889 } else if (d instanceof ClassDescriptor) {
1890 mapDescToLocationSummary.put(d, new FieldSummary());
1893 return mapDescToLocationSummary.get(d);
1896 private void generateMethodSummary() {
1898 Set<MethodDescriptor> keySet = md2lattice.keySet();
1899 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
1900 MethodDescriptor md = (MethodDescriptor) iterator.next();
1902 System.out.println("\nSSJAVA: generate method summary: " + md);
1904 FlowGraph flowGraph = getFlowGraph(md);
1905 MethodSummary methodSummary = getMethodSummary(md);
1907 HierarchyGraph scGraph = getSkeletonCombinationHierarchyGraph(md);
1909 // set the 'this' reference location
1910 if (!md.isStatic()) {
1911 System.out.println("setThisLocName=" + scGraph.getHNode(md.getThis()).getName());
1912 methodSummary.setThisLocName(scGraph.getHNode(md.getThis()).getName());
1915 // set the 'global' reference location if needed
1916 if (methodSummary.hasGlobalAccess()) {
1917 methodSummary.setGlobalLocName(scGraph.getHNode(GLOBALDESC).getName());
1920 // construct a parameter mapping that maps a parameter descriptor to an
1921 // inferred composite location
1922 for (int paramIdx = 0; paramIdx < flowGraph.getNumParameters(); paramIdx++) {
1923 FlowNode flowNode = flowGraph.getParamFlowNode(paramIdx);
1924 CompositeLocation inferredCompLoc =
1925 updateCompositeLocation(flowNode.getCompositeLocation());
1926 System.out.println("-paramIdx=" + paramIdx + " infer=" + inferredCompLoc + " original="
1927 + flowNode.getCompositeLocation());
1929 Descriptor localVarDesc = flowNode.getDescTuple().get(0);
1930 methodSummary.addMapVarNameToInferCompLoc(localVarDesc, inferredCompLoc);
1931 methodSummary.addMapParamIdxToInferLoc(paramIdx, inferredCompLoc);
1938 private boolean hasOrderingRelation(NTuple<Location> locTuple1, NTuple<Location> locTuple2) {
1940 int size = locTuple1.size() >= locTuple2.size() ? locTuple2.size() : locTuple1.size();
1942 for (int idx = 0; idx < size; idx++) {
1943 Location loc1 = locTuple1.get(idx);
1944 Location loc2 = locTuple2.get(idx);
1946 Descriptor desc1 = loc1.getDescriptor();
1947 Descriptor desc2 = loc2.getDescriptor();
1949 if (!desc1.equals(desc2)) {
1950 throw new Error("Fail to compare " + locTuple1 + " and " + locTuple2);
1953 Descriptor locDesc1 = loc1.getLocDescriptor();
1954 Descriptor locDesc2 = loc2.getLocDescriptor();
1956 HierarchyGraph hierarchyGraph = getHierarchyGraph(desc1);
1958 HNode node1 = hierarchyGraph.getHNode(locDesc1);
1959 HNode node2 = hierarchyGraph.getHNode(locDesc2);
1961 System.out.println("---node1=" + node1 + " node2=" + node2);
1962 System.out.println("---hierarchyGraph.getIncomingNodeSet(node2)="
1963 + hierarchyGraph.getIncomingNodeSet(node2));
1965 if (locDesc1.equals(locDesc2)) {
1967 } else if (!hierarchyGraph.getIncomingNodeSet(node2).contains(node1)
1968 && !hierarchyGraph.getIncomingNodeSet(node1).contains(node2)) {
1980 private boolean isHigherThan(NTuple<Location> locTuple1, NTuple<Location> locTuple2) {
1982 int size = locTuple1.size() >= locTuple2.size() ? locTuple2.size() : locTuple1.size();
1984 for (int idx = 0; idx < size; idx++) {
1985 Location loc1 = locTuple1.get(idx);
1986 Location loc2 = locTuple2.get(idx);
1988 Descriptor desc1 = loc1.getDescriptor();
1989 Descriptor desc2 = loc2.getDescriptor();
1991 if (!desc1.equals(desc2)) {
1992 throw new Error("Fail to compare " + locTuple1 + " and " + locTuple2);
1995 Descriptor locDesc1 = loc1.getLocDescriptor();
1996 Descriptor locDesc2 = loc2.getLocDescriptor();
1998 HierarchyGraph hierarchyGraph = getHierarchyGraph(desc1);
2000 HNode node1 = hierarchyGraph.getHNode(locDesc1);
2001 HNode node2 = hierarchyGraph.getHNode(locDesc2);
2003 System.out.println("---node1=" + node1 + " node2=" + node2);
2004 System.out.println("---hierarchyGraph.getIncomingNodeSet(node2)="
2005 + hierarchyGraph.getIncomingNodeSet(node2));
2007 if (locDesc1.equals(locDesc2)) {
2009 } else if (hierarchyGraph.getIncomingNodeSet(node2).contains(node1)) {
2020 private CompositeLocation translateCompositeLocation(CompositeLocation compLoc) {
2021 CompositeLocation newCompLoc = new CompositeLocation();
2023 // System.out.println("compLoc=" + compLoc);
2024 for (int i = 0; i < compLoc.getSize(); i++) {
2025 Location loc = compLoc.get(i);
2026 Descriptor enclosingDescriptor = loc.getDescriptor();
2027 Descriptor locDescriptor = loc.getLocDescriptor();
2029 HNode hnode = getHierarchyGraph(enclosingDescriptor).getHNode(locDescriptor);
2030 // System.out.println("-hnode=" + hnode + " from=" + locDescriptor +
2031 // " enclosingDescriptor="
2032 // + enclosingDescriptor);
2033 // System.out.println("-getLocationSummary(enclosingDescriptor)="
2034 // + getLocationSummary(enclosingDescriptor));
2035 String locName = getLocationSummary(enclosingDescriptor).getLocationName(hnode.getName());
2036 // System.out.println("-locName=" + locName);
2037 Location newLoc = new Location(enclosingDescriptor, locName);
2038 newLoc.setLocDescriptor(locDescriptor);
2039 newCompLoc.addLocation(newLoc);
2045 private void debug_writeLattices() {
2047 Set<Descriptor> keySet = mapDescriptorToSimpleLattice.keySet();
2048 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
2049 Descriptor key = (Descriptor) iterator.next();
2050 SSJavaLattice<String> simpleLattice = mapDescriptorToSimpleLattice.get(key);
2051 // HierarchyGraph simpleHierarchyGraph = getSimpleHierarchyGraph(key);
2052 HierarchyGraph scHierarchyGraph = getSkeletonCombinationHierarchyGraph(key);
2053 if (key instanceof ClassDescriptor) {
2054 writeInferredLatticeDotFile((ClassDescriptor) key, scHierarchyGraph, simpleLattice,
2056 } else if (key instanceof MethodDescriptor) {
2057 MethodDescriptor md = (MethodDescriptor) key;
2058 writeInferredLatticeDotFile(md.getClassDesc(), md, scHierarchyGraph, simpleLattice,
2062 LocationSummary ls = getLocationSummary(key);
2063 System.out.println("####LOC SUMMARY=" + key + "\n" + ls.getMapHNodeNameToLocationName());
2066 Set<ClassDescriptor> cdKeySet = cd2lattice.keySet();
2067 for (Iterator iterator = cdKeySet.iterator(); iterator.hasNext();) {
2068 ClassDescriptor cd = (ClassDescriptor) iterator.next();
2069 writeInferredLatticeDotFile((ClassDescriptor) cd, getSkeletonCombinationHierarchyGraph(cd),
2070 cd2lattice.get(cd), "");
2073 Set<MethodDescriptor> mdKeySet = md2lattice.keySet();
2074 for (Iterator iterator = mdKeySet.iterator(); iterator.hasNext();) {
2075 MethodDescriptor md = (MethodDescriptor) iterator.next();
2076 writeInferredLatticeDotFile(md.getClassDesc(), md, getSkeletonCombinationHierarchyGraph(md),
2077 md2lattice.get(md), "");
2082 private void buildLattice() {
2084 BuildLattice buildLattice = new BuildLattice(this);
2086 Set<Descriptor> keySet = mapDescriptorToCombineSkeletonHierarchyGraph.keySet();
2087 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
2088 Descriptor desc = (Descriptor) iterator.next();
2090 SSJavaLattice<String> simpleLattice = buildLattice.buildLattice(desc);
2092 addMapDescToSimpleLattice(desc, simpleLattice);
2094 HierarchyGraph simpleHierarchyGraph = getSimpleHierarchyGraph(desc);
2095 System.out.println("\n## insertIntermediateNodesToStraightLine:"
2096 + simpleHierarchyGraph.getName());
2097 SSJavaLattice<String> lattice =
2098 buildLattice.insertIntermediateNodesToStraightLine(desc, simpleLattice);
2099 lattice.removeRedundantEdges();
2101 if (desc instanceof ClassDescriptor) {
2103 cd2lattice.put((ClassDescriptor) desc, lattice);
2104 // ssjava.writeLatticeDotFile((ClassDescriptor) desc, null, lattice);
2105 } else if (desc instanceof MethodDescriptor) {
2107 md2lattice.put((MethodDescriptor) desc, lattice);
2108 MethodDescriptor md = (MethodDescriptor) desc;
2109 ClassDescriptor cd = md.getClassDesc();
2110 // ssjava.writeLatticeDotFile(cd, md, lattice);
2113 // System.out.println("\nSSJAVA: Insering Combination Nodes:" + desc);
2114 // HierarchyGraph skeletonGraph = getSkeletonHierarchyGraph(desc);
2115 // HierarchyGraph skeletonGraphWithCombinationNode =
2116 // skeletonGraph.clone();
2117 // skeletonGraphWithCombinationNode.setName(desc + "_SC");
2119 // HierarchyGraph simpleHierarchyGraph = getSimpleHierarchyGraph(desc);
2120 // System.out.println("Identifying Combination Nodes:");
2121 // skeletonGraphWithCombinationNode.insertCombinationNodesToGraph(simpleHierarchyGraph);
2122 // skeletonGraphWithCombinationNode.simplifySkeletonCombinationHierarchyGraph();
2123 // mapDescriptorToCombineSkeletonHierarchyGraph.put(desc,
2124 // skeletonGraphWithCombinationNode);
2129 public void addMapDescToSimpleLattice(Descriptor desc, SSJavaLattice<String> lattice) {
2130 mapDescriptorToSimpleLattice.put(desc, lattice);
2133 public SSJavaLattice<String> getSimpleLattice(Descriptor desc) {
2134 return mapDescriptorToSimpleLattice.get(desc);
2137 private void simplifyHierarchyGraph() {
2138 Set<Descriptor> keySet = mapDescriptorToHierarchyGraph.keySet();
2139 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
2140 Descriptor desc = (Descriptor) iterator.next();
2141 // System.out.println("SSJAVA: remove redundant edges: " + desc);
2142 HierarchyGraph simpleHierarchyGraph = getHierarchyGraph(desc).clone();
2143 simpleHierarchyGraph.setName(desc + "_SIMPLE");
2144 simpleHierarchyGraph.removeRedundantEdges();
2145 mapDescriptorToSimpleHierarchyGraph.put(desc, simpleHierarchyGraph);
2149 private void insertCombinationNodes() {
2150 Set<Descriptor> keySet = mapDescriptorToSkeletonHierarchyGraph.keySet();
2151 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
2152 Descriptor desc = (Descriptor) iterator.next();
2153 System.out.println("\nSSJAVA: Inserting Combination Nodes:" + desc);
2154 HierarchyGraph skeletonGraph = getSkeletonHierarchyGraph(desc);
2155 HierarchyGraph skeletonGraphWithCombinationNode = skeletonGraph.clone();
2156 skeletonGraphWithCombinationNode.setName(desc + "_SC");
2158 HierarchyGraph simpleHierarchyGraph = getSimpleHierarchyGraph(desc);
2159 skeletonGraphWithCombinationNode.insertCombinationNodesToGraph(simpleHierarchyGraph);
2160 // skeletonGraphWithCombinationNode.insertCombinationNodesToGraph(simpleHierarchyGraph,
2162 // skeletonGraphWithCombinationNode.simplifySkeletonCombinationHierarchyGraph();
2163 skeletonGraphWithCombinationNode.removeRedundantEdges();
2164 mapDescriptorToCombineSkeletonHierarchyGraph.put(desc, skeletonGraphWithCombinationNode);
2168 private void constructSkeletonHierarchyGraph() {
2169 Set<Descriptor> keySet = mapDescriptorToHierarchyGraph.keySet();
2170 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
2171 Descriptor desc = (Descriptor) iterator.next();
2172 System.out.println("SSJAVA: Constructing Skeleton Hierarchy Graph: " + desc);
2173 HierarchyGraph simpleGraph = getSimpleHierarchyGraph(desc);
2174 HierarchyGraph skeletonGraph = simpleGraph.generateSkeletonGraph();
2175 skeletonGraph.setMapDescToHNode(simpleGraph.getMapDescToHNode());
2176 skeletonGraph.setMapHNodeToDescSet(simpleGraph.getMapHNodeToDescSet());
2177 skeletonGraph.simplifyHierarchyGraph();
2178 // skeletonGraph.combineRedundantNodes(false);
2179 // skeletonGraph.removeRedundantEdges();
2180 mapDescriptorToSkeletonHierarchyGraph.put(desc, skeletonGraph);
2184 private void debug_writeHierarchyDotFiles() {
2186 Set<Descriptor> keySet = mapDescriptorToHierarchyGraph.keySet();
2187 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
2188 Descriptor desc = (Descriptor) iterator.next();
2189 getHierarchyGraph(desc).writeGraph();
2194 private void debug_writeSimpleHierarchyDotFiles() {
2196 Set<Descriptor> keySet = mapDescriptorToHierarchyGraph.keySet();
2197 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
2198 Descriptor desc = (Descriptor) iterator.next();
2199 getHierarchyGraph(desc).writeGraph();
2200 getSimpleHierarchyGraph(desc).writeGraph();
2201 getSimpleHierarchyGraph(desc).writeGraph(true);
2206 private void debug_writeSkeletonHierarchyDotFiles() {
2208 Set<Descriptor> keySet = mapDescriptorToHierarchyGraph.keySet();
2209 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
2210 Descriptor desc = (Descriptor) iterator.next();
2211 getSkeletonHierarchyGraph(desc).writeGraph();
2216 private void debug_writeSkeletonCombinationHierarchyDotFiles() {
2218 Set<Descriptor> keySet = mapDescriptorToHierarchyGraph.keySet();
2219 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
2220 Descriptor desc = (Descriptor) iterator.next();
2221 getSkeletonCombinationHierarchyGraph(desc).writeGraph();
2226 public HierarchyGraph getSimpleHierarchyGraph(Descriptor d) {
2227 return mapDescriptorToSimpleHierarchyGraph.get(d);
2230 private HierarchyGraph getSkeletonHierarchyGraph(Descriptor d) {
2231 if (!mapDescriptorToSkeletonHierarchyGraph.containsKey(d)) {
2232 mapDescriptorToSkeletonHierarchyGraph.put(d, new HierarchyGraph(d));
2234 return mapDescriptorToSkeletonHierarchyGraph.get(d);
2237 public HierarchyGraph getSkeletonCombinationHierarchyGraph(Descriptor d) {
2238 if (!mapDescriptorToCombineSkeletonHierarchyGraph.containsKey(d)) {
2239 mapDescriptorToCombineSkeletonHierarchyGraph.put(d, new HierarchyGraph(d));
2241 return mapDescriptorToCombineSkeletonHierarchyGraph.get(d);
2244 private void constructHierarchyGraph() {
2246 LinkedList<MethodDescriptor> methodDescList =
2247 (LinkedList<MethodDescriptor>) toanalyze_methodDescList.clone();
2249 while (!methodDescList.isEmpty()) {
2250 MethodDescriptor md = methodDescList.removeLast();
2251 if (state.SSJAVADEBUG) {
2252 HierarchyGraph hierarchyGraph = new HierarchyGraph(md);
2253 System.out.println();
2254 System.out.println("SSJAVA: Construcing the hierarchy graph from " + md);
2255 constructHierarchyGraph(md, hierarchyGraph);
2256 mapDescriptorToHierarchyGraph.put(md, hierarchyGraph);
2262 while (!toAnalyzeIsEmpty()) {
2263 ClassDescriptor cd = toAnalyzeNext();
2264 HierarchyGraph graph = getHierarchyGraph(cd);
2265 for (Iterator iter = cd.getFields(); iter.hasNext();) {
2266 FieldDescriptor fieldDesc = (FieldDescriptor) iter.next();
2267 if (!(fieldDesc.isStatic() && fieldDesc.isFinal())) {
2268 graph.getHNode(fieldDesc);
2273 Set<Descriptor> keySet = mapDescriptorToHierarchyGraph.keySet();
2274 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
2275 Descriptor key = (Descriptor) iterator.next();
2276 HierarchyGraph graph = getHierarchyGraph(key);
2278 Set<HNode> nodeToBeConnected = new HashSet<HNode>();
2279 for (Iterator iterator2 = graph.getNodeSet().iterator(); iterator2.hasNext();) {
2280 HNode node = (HNode) iterator2.next();
2281 if (!node.isSkeleton() && !node.isCombinationNode()) {
2282 if (graph.getIncomingNodeSet(node).size() == 0) {
2283 nodeToBeConnected.add(node);
2288 for (Iterator iterator2 = nodeToBeConnected.iterator(); iterator2.hasNext();) {
2289 HNode node = (HNode) iterator2.next();
2290 System.out.println("NEED TO BE CONNECTED TO TOP=" + node);
2291 graph.addEdge(graph.getHNode(TOPDESC), node);
2298 private void constructHierarchyGraph2() {
2300 // do fixed-point analysis
2302 LinkedList<MethodDescriptor> descriptorListToAnalyze = ssjava.getSortedDescriptors();
2304 // Collections.sort(descriptorListToAnalyze, new
2305 // Comparator<MethodDescriptor>() {
2306 // public int compare(MethodDescriptor o1, MethodDescriptor o2) {
2307 // return o1.getSymbol().compareToIgnoreCase(o2.getSymbol());
2311 // current descriptors to visit in fixed-point interprocedural analysis,
2312 // prioritized by dependency in the call graph
2313 methodDescriptorsToVisitStack.clear();
2315 Set<MethodDescriptor> methodDescriptorToVistSet = new HashSet<MethodDescriptor>();
2316 methodDescriptorToVistSet.addAll(descriptorListToAnalyze);
2318 while (!descriptorListToAnalyze.isEmpty()) {
2319 MethodDescriptor md = descriptorListToAnalyze.removeFirst();
2320 methodDescriptorsToVisitStack.add(md);
2323 // analyze scheduled methods until there are no more to visit
2324 while (!methodDescriptorsToVisitStack.isEmpty()) {
2325 // start to analyze leaf node
2326 MethodDescriptor md = methodDescriptorsToVisitStack.pop();
2328 HierarchyGraph hierarchyGraph = new HierarchyGraph(md);
2329 // MethodSummary methodSummary = new MethodSummary(md);
2331 // MethodLocationInfo methodInfo = new MethodLocationInfo(md);
2332 // curMethodInfo = methodInfo;
2334 System.out.println();
2335 System.out.println("SSJAVA: Construcing the hierarchy graph from " + md);
2337 constructHierarchyGraph(md, hierarchyGraph);
2339 HierarchyGraph prevHierarchyGraph = getHierarchyGraph(md);
2340 // MethodSummary prevMethodSummary = getMethodSummary(md);
2342 if (!hierarchyGraph.equals(prevHierarchyGraph)) {
2344 mapDescriptorToHierarchyGraph.put(md, hierarchyGraph);
2345 // mapDescToLocationSummary.put(md, methodSummary);
2347 // results for callee changed, so enqueue dependents caller for
2349 Iterator<MethodDescriptor> depsItr = ssjava.getDependents(md).iterator();
2350 while (depsItr.hasNext()) {
2351 MethodDescriptor methodNext = depsItr.next();
2352 if (!methodDescriptorsToVisitStack.contains(methodNext)
2353 && methodDescriptorToVistSet.contains(methodNext)) {
2354 methodDescriptorsToVisitStack.add(methodNext);
2363 while (!toAnalyzeIsEmpty()) {
2364 ClassDescriptor cd = toAnalyzeNext();
2365 HierarchyGraph graph = getHierarchyGraph(cd);
2366 for (Iterator iter = cd.getFields(); iter.hasNext();) {
2367 FieldDescriptor fieldDesc = (FieldDescriptor) iter.next();
2368 if (!(fieldDesc.isStatic() && fieldDesc.isFinal())) {
2369 graph.getHNode(fieldDesc);
2374 Set<Descriptor> keySet = mapDescriptorToHierarchyGraph.keySet();
2375 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
2376 Descriptor key = (Descriptor) iterator.next();
2377 HierarchyGraph graph = getHierarchyGraph(key);
2379 Set<HNode> nodeToBeConnected = new HashSet<HNode>();
2380 for (Iterator iterator2 = graph.getNodeSet().iterator(); iterator2.hasNext();) {
2381 HNode node = (HNode) iterator2.next();
2382 if (!node.isSkeleton() && !node.isCombinationNode()) {
2383 if (graph.getIncomingNodeSet(node).size() == 0) {
2384 nodeToBeConnected.add(node);
2389 for (Iterator iterator2 = nodeToBeConnected.iterator(); iterator2.hasNext();) {
2390 HNode node = (HNode) iterator2.next();
2391 System.out.println("NEED TO BE CONNECTED TO TOP=" + node);
2392 graph.addEdge(graph.getHNode(TOPDESC), node);
2399 private HierarchyGraph getHierarchyGraph(Descriptor d) {
2400 if (!mapDescriptorToHierarchyGraph.containsKey(d)) {
2401 mapDescriptorToHierarchyGraph.put(d, new HierarchyGraph(d));
2403 return mapDescriptorToHierarchyGraph.get(d);
2406 private void constructHierarchyGraph(MethodDescriptor md, HierarchyGraph methodGraph) {
2408 // visit each node of method flow graph
2409 FlowGraph fg = getFlowGraph(md);
2410 // Set<FlowNode> nodeSet = fg.getNodeSet();
2412 Set<FlowEdge> edgeSet = fg.getEdgeSet();
2414 Set<Descriptor> paramDescSet = fg.getMapParamDescToIdx().keySet();
2415 for (Iterator iterator = paramDescSet.iterator(); iterator.hasNext();) {
2416 Descriptor desc = (Descriptor) iterator.next();
2417 methodGraph.getHNode(desc).setSkeleton(true);
2420 // for the method lattice, we need to look at the first element of
2421 // NTuple<Descriptor>
2422 boolean hasGlobalAccess = false;
2423 // for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
2424 // FlowNode originalSrcNode = (FlowNode) iterator.next();
2425 for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) {
2426 FlowEdge edge = (FlowEdge) iterator.next();
2428 FlowNode originalSrcNode = fg.getFlowNode(edge.getInitTuple());
2429 Set<FlowNode> sourceNodeSet = new HashSet<FlowNode>();
2430 if (originalSrcNode instanceof FlowReturnNode) {
2431 FlowReturnNode rnode = (FlowReturnNode) originalSrcNode;
2432 System.out.println("rnode=" + rnode);
2433 Set<NTuple<Descriptor>> tupleSet = rnode.getReturnTupleSet();
2434 for (Iterator iterator2 = tupleSet.iterator(); iterator2.hasNext();) {
2435 NTuple<Descriptor> nTuple = (NTuple<Descriptor>) iterator2.next();
2436 sourceNodeSet.add(fg.getFlowNode(nTuple));
2437 System.out.println("&&&SOURCE fg.getFlowNode(nTuple)=" + fg.getFlowNode(nTuple));
2440 sourceNodeSet.add(originalSrcNode);
2443 // System.out.println("---sourceNodeSet=" + sourceNodeSet + " from originalSrcNode="
2444 // + originalSrcNode);
2446 for (Iterator iterator3 = sourceNodeSet.iterator(); iterator3.hasNext();) {
2447 FlowNode srcNode = (FlowNode) iterator3.next();
2449 NTuple<Descriptor> srcNodeTuple = srcNode.getDescTuple();
2450 Descriptor srcLocalDesc = srcNodeTuple.get(0);
2452 if (srcLocalDesc instanceof InterDescriptor
2453 && ((InterDescriptor) srcLocalDesc).getMethodArgIdxPair() != null) {
2455 if (srcNode.getCompositeLocation() == null) {
2460 // if the srcNode is started with the global descriptor
2461 // need to set as a skeleton node
2462 if (!hasGlobalAccess && srcNode.getDescTuple().startsWith(GLOBALDESC)) {
2463 hasGlobalAccess = true;
2466 // Set<FlowEdge> outEdgeSet = fg.getOutEdgeSet(originalSrcNode);
2467 // for (Iterator iterator2 = outEdgeSet.iterator(); iterator2.hasNext();) {
2468 // FlowEdge outEdge = (FlowEdge) iterator2.next();
2469 // FlowNode originalDstNode = outEdge.getDst();
2470 FlowNode originalDstNode = fg.getFlowNode(edge.getEndTuple());
2472 Set<FlowNode> dstNodeSet = new HashSet<FlowNode>();
2473 if (originalDstNode instanceof FlowReturnNode) {
2474 FlowReturnNode rnode = (FlowReturnNode) originalDstNode;
2475 // System.out.println("\n-returnNode=" + rnode);
2476 Set<NTuple<Descriptor>> tupleSet = rnode.getReturnTupleSet();
2477 for (Iterator iterator4 = tupleSet.iterator(); iterator4.hasNext();) {
2478 NTuple<Descriptor> nTuple = (NTuple<Descriptor>) iterator4.next();
2479 dstNodeSet.add(fg.getFlowNode(nTuple));
2480 System.out.println("&&&DST fg.getFlowNode(nTuple)=" + fg.getFlowNode(nTuple));
2483 dstNodeSet.add(originalDstNode);
2485 // System.out.println("---dstNodeSet=" + dstNodeSet);
2486 for (Iterator iterator4 = dstNodeSet.iterator(); iterator4.hasNext();) {
2487 FlowNode dstNode = (FlowNode) iterator4.next();
2489 NTuple<Descriptor> dstNodeTuple = dstNode.getDescTuple();
2490 Descriptor dstLocalDesc = dstNodeTuple.get(0);
2492 if (dstLocalDesc instanceof InterDescriptor
2493 && ((InterDescriptor) dstLocalDesc).getMethodArgIdxPair() != null) {
2494 if (dstNode.getCompositeLocation() == null) {
2495 System.out.println("%%%%%%%%%%%%%SKIP=" + dstNode);
2500 // if (outEdge.getInitTuple().equals(srcNodeTuple)
2501 // && outEdge.getEndTuple().equals(dstNodeTuple)) {
2503 NTuple<Descriptor> srcCurTuple = srcNode.getCurrentDescTuple();
2504 NTuple<Descriptor> dstCurTuple = dstNode.getCurrentDescTuple();
2506 System.out.println("-srcCurTuple=" + srcCurTuple + " dstCurTuple=" + dstCurTuple
2507 + " srcNode=" + srcNode + " dstNode=" + dstNode);
2509 // srcCurTuple = translateBaseTuple(srcNode, srcCurTuple);
2510 // dstCurTuple = translateBaseTuple(dstNode, dstCurTuple);
2512 if ((srcCurTuple.size() > 1 && dstCurTuple.size() > 1)
2513 && srcCurTuple.get(0).equals(dstCurTuple.get(0))) {
2515 // value flows between fields
2516 Descriptor desc = srcCurTuple.get(0);
2517 ClassDescriptor classDesc;
2519 if (desc.equals(GLOBALDESC)) {
2520 classDesc = md.getClassDesc();
2522 VarDescriptor varDesc = (VarDescriptor) srcCurTuple.get(0);
2523 classDesc = varDesc.getType().getClassDesc();
2525 extractFlowsBetweenFields(classDesc, srcNode, dstNode, 1);
2527 } else if ((srcCurTuple.size() == 1 && dstCurTuple.size() == 1)
2528 || ((srcCurTuple.size() > 1 || dstCurTuple.size() > 1) && !srcCurTuple.get(0).equals(
2529 dstCurTuple.get(0)))) {
2531 // value flow between a primitive local var - a primitive local var or local var -
2534 Descriptor srcDesc = srcCurTuple.get(0);
2535 Descriptor dstDesc = dstCurTuple.get(0);
2537 methodGraph.addEdge(srcDesc, dstDesc);
2539 if (fg.isParamDesc(srcDesc)) {
2540 methodGraph.setParamHNode(srcDesc);
2542 if (fg.isParamDesc(dstDesc)) {
2543 methodGraph.setParamHNode(dstDesc);
2557 // If the method accesses static fields
2558 // set hasGloabalAccess true in the method summary.
2559 if (hasGlobalAccess) {
2560 getMethodSummary(md).setHasGlobalAccess();
2562 methodGraph.getHNode(GLOBALDESC).setSkeleton(true);
2564 if (ssjava.getMethodContainingSSJavaLoop().equals(md)) {
2565 // if the current method contains the event loop
2566 // we need to set all nodes of the hierarchy graph as a skeleton node
2567 Set<HNode> hnodeSet = methodGraph.getNodeSet();
2568 for (Iterator iterator = hnodeSet.iterator(); iterator.hasNext();) {
2569 HNode hnode = (HNode) iterator.next();
2570 hnode.setSkeleton(true);
2576 private NTuple<Descriptor> translateBaseTuple(FlowNode flowNode, NTuple<Descriptor> inTuple) {
2578 if (flowNode.getBaseTuple() != null) {
2580 NTuple<Descriptor> translatedTuple = new NTuple<Descriptor>();
2582 NTuple<Descriptor> baseTuple = flowNode.getBaseTuple();
2584 for (int i = 0; i < baseTuple.size(); i++) {
2585 translatedTuple.add(baseTuple.get(i));
2588 for (int i = 1; i < inTuple.size(); i++) {
2589 translatedTuple.add(inTuple.get(i));
2592 System.out.println("------TRANSLATED " + inTuple + " -> " + translatedTuple);
2593 return translatedTuple;
2601 private MethodSummary getMethodSummary(MethodDescriptor md) {
2602 if (!mapDescToLocationSummary.containsKey(md)) {
2603 mapDescToLocationSummary.put(md, new MethodSummary(md));
2605 return (MethodSummary) mapDescToLocationSummary.get(md);
2608 private void addMapClassDefinitionToLineNum(ClassDescriptor cd, String strLine, int lineNum) {
2610 String classSymbol = cd.getSymbol();
2611 int idx = classSymbol.lastIndexOf("$");
2613 classSymbol = classSymbol.substring(idx + 1);
2616 String pattern = "class " + classSymbol + " ";
2617 if (strLine.indexOf(pattern) != -1) {
2618 mapDescToDefinitionLine.put(cd, lineNum);
2622 private void addMapMethodDefinitionToLineNum(Set<MethodDescriptor> methodSet, String strLine,
2624 for (Iterator iterator = methodSet.iterator(); iterator.hasNext();) {
2625 MethodDescriptor md = (MethodDescriptor) iterator.next();
2626 String pattern = md.getMethodDeclaration();
2627 if (strLine.indexOf(pattern) != -1) {
2628 mapDescToDefinitionLine.put(md, lineNum);
2629 methodSet.remove(md);
2636 private void readOriginalSourceFiles() {
2638 SymbolTable classtable = state.getClassSymbolTable();
2640 Set<ClassDescriptor> classDescSet = new HashSet<ClassDescriptor>();
2641 classDescSet.addAll(classtable.getValueSet());
2644 // inefficient implement. it may re-visit the same file if the file
2645 // contains more than one class definitions.
2646 for (Iterator iterator = classDescSet.iterator(); iterator.hasNext();) {
2647 ClassDescriptor cd = (ClassDescriptor) iterator.next();
2649 Set<MethodDescriptor> methodSet = new HashSet<MethodDescriptor>();
2650 methodSet.addAll(cd.getMethodTable().getValueSet());
2652 String sourceFileName = cd.getSourceFileName();
2653 Vector<String> lineVec = new Vector<String>();
2655 mapFileNameToLineVector.put(sourceFileName, lineVec);
2657 BufferedReader in = new BufferedReader(new FileReader(sourceFileName));
2660 lineVec.add(""); // the index is started from 1.
2661 while ((strLine = in.readLine()) != null) {
2662 lineVec.add(lineNum, strLine);
2663 addMapClassDefinitionToLineNum(cd, strLine, lineNum);
2664 addMapMethodDefinitionToLineNum(methodSet, strLine, lineNum);
2670 } catch (IOException e) {
2671 e.printStackTrace();
2676 private String generateLatticeDefinition(Descriptor desc) {
2678 Set<String> sharedLocSet = new HashSet<String>();
2680 SSJavaLattice<String> lattice = getLattice(desc);
2681 String rtr = "@LATTICE(\"";
2683 Map<String, Set<String>> map = lattice.getTable();
2684 Set<String> keySet = map.keySet();
2685 boolean first = true;
2686 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
2687 String key = (String) iterator.next();
2688 if (!key.equals(lattice.getTopItem())) {
2689 Set<String> connectedSet = map.get(key);
2691 if (connectedSet.size() == 1) {
2692 if (connectedSet.iterator().next().equals(lattice.getBottomItem())) {
2700 if (lattice.isSharedLoc(key)) {
2701 rtr += "," + key + "*";
2706 for (Iterator iterator2 = connectedSet.iterator(); iterator2.hasNext();) {
2707 String loc = (String) iterator2.next();
2708 if (!loc.equals(lattice.getBottomItem())) {
2715 rtr += loc + "<" + key;
2716 if (lattice.isSharedLoc(key) && (!sharedLocSet.contains(key))) {
2717 rtr += "," + key + "*";
2718 sharedLocSet.add(key);
2720 if (lattice.isSharedLoc(loc) && (!sharedLocSet.contains(loc))) {
2721 rtr += "," + loc + "*";
2722 sharedLocSet.add(loc);
2730 if (desc instanceof MethodDescriptor) {
2731 System.out.println("#EXTRA LOC DECLARATION GEN=" + desc);
2733 MethodDescriptor md = (MethodDescriptor) desc;
2734 MethodSummary methodSummary = getMethodSummary(md);
2736 TypeDescriptor returnType = ((MethodDescriptor) desc).getReturnType();
2737 if (!ssjava.getMethodContainingSSJavaLoop().equals(desc) && returnType != null
2738 && (!returnType.isVoid())) {
2739 CompositeLocation returnLoc = methodSummary.getRETURNLoc();
2740 if (returnLoc.getSize() == 1) {
2741 String returnLocStr = generateLocationAnnoatation(methodSummary.getRETURNLoc());
2742 if (rtr.indexOf(returnLocStr) == -1) {
2743 rtr += "," + returnLocStr;
2749 if (!ssjava.getMethodContainingSSJavaLoop().equals(desc)) {
2750 if (returnType != null && (!returnType.isVoid())) {
2752 "\n@RETURNLOC(\"" + generateLocationAnnoatation(methodSummary.getRETURNLoc()) + "\")";
2755 CompositeLocation pcLoc = methodSummary.getPCLoc();
2756 if ((pcLoc != null) && (!pcLoc.get(0).isTop())) {
2757 rtr += "\n@PCLOC(\"" + generateLocationAnnoatation(pcLoc) + "\")";
2761 if (!md.isStatic()) {
2762 rtr += "\n@THISLOC(\"" + methodSummary.getThisLocName() + "\")";
2764 rtr += "\n@GLOBALLOC(\"" + methodSummary.getGlobalLocName() + "\")";
2773 private void generateAnnoatedCode() {
2775 readOriginalSourceFiles();
2778 while (!toAnalyzeIsEmpty()) {
2779 ClassDescriptor cd = toAnalyzeNext();
2781 setupToAnalazeMethod(cd);
2783 String sourceFileName = cd.getSourceFileName();
2785 if (cd.isInterface()) {
2789 int classDefLine = mapDescToDefinitionLine.get(cd);
2790 Vector<String> sourceVec = mapFileNameToLineVector.get(sourceFileName);
2792 LocationSummary fieldLocSummary = getLocationSummary(cd);
2794 String fieldLatticeDefStr = generateLatticeDefinition(cd);
2795 String annoatedSrc = fieldLatticeDefStr + newline + sourceVec.get(classDefLine);
2796 sourceVec.set(classDefLine, annoatedSrc);
2798 // generate annotations for field declarations
2799 // Map<Descriptor, CompositeLocation> inferLocMap = fieldLocInfo.getMapDescToInferLocation();
2800 Map<String, String> mapFieldNameToLocName = fieldLocSummary.getMapHNodeNameToLocationName();
2802 for (Iterator iter = cd.getFields(); iter.hasNext();) {
2803 FieldDescriptor fd = (FieldDescriptor) iter.next();
2805 String locAnnotationStr;
2806 // CompositeLocation inferLoc = inferLocMap.get(fd);
2807 String locName = mapFieldNameToLocName.get(fd.getSymbol());
2809 if (locName != null) {
2810 // infer loc is null if the corresponding field is static and final
2811 // locAnnotationStr = "@LOC(\"" + generateLocationAnnoatation(inferLoc) + "\")";
2812 locAnnotationStr = "@LOC(\"" + locName + "\")";
2813 int fdLineNum = fd.getLineNum();
2814 String orgFieldDeclarationStr = sourceVec.get(fdLineNum);
2815 String fieldDeclaration = fd.toString();
2816 fieldDeclaration = fieldDeclaration.substring(0, fieldDeclaration.length() - 1);
2817 String annoatedStr = locAnnotationStr + " " + orgFieldDeclarationStr;
2818 sourceVec.set(fdLineNum, annoatedStr);
2823 while (!toAnalyzeMethodIsEmpty()) {
2824 MethodDescriptor md = toAnalyzeMethodNext();
2826 if (!ssjava.needTobeAnnotated(md)) {
2830 SSJavaLattice<String> methodLattice = md2lattice.get(md);
2831 if (methodLattice != null) {
2833 int methodDefLine = md.getLineNum();
2835 // MethodLocationInfo methodLocInfo = getMethodLocationInfo(md);
2836 // Map<Descriptor, CompositeLocation> methodInferLocMap =
2837 // methodLocInfo.getMapDescToInferLocation();
2839 MethodSummary methodSummary = getMethodSummary(md);
2841 Map<Descriptor, CompositeLocation> mapVarDescToInferLoc =
2842 methodSummary.getMapVarDescToInferCompositeLocation();
2843 System.out.println("-----md=" + md);
2844 System.out.println("-----mapVarDescToInferLoc=" + mapVarDescToInferLoc);
2846 Set<Descriptor> localVarDescSet = mapVarDescToInferLoc.keySet();
2848 Set<String> localLocElementSet = methodLattice.getElementSet();
2850 for (Iterator iterator = localVarDescSet.iterator(); iterator.hasNext();) {
2851 Descriptor localVarDesc = (Descriptor) iterator.next();
2852 System.out.println("-------localVarDesc=" + localVarDesc);
2853 CompositeLocation inferLoc = mapVarDescToInferLoc.get(localVarDesc);
2855 String localLocIdentifier = inferLoc.get(0).getLocIdentifier();
2856 if (!localLocElementSet.contains(localLocIdentifier)) {
2857 methodLattice.put(localLocIdentifier);
2860 String locAnnotationStr = "@LOC(\"" + generateLocationAnnoatation(inferLoc) + "\")";
2862 if (!isParameter(md, localVarDesc)) {
2863 if (mapDescToDefinitionLine.containsKey(localVarDesc)) {
2864 int varLineNum = mapDescToDefinitionLine.get(localVarDesc);
2865 String orgSourceLine = sourceVec.get(varLineNum);
2866 System.out.println("varLineNum=" + varLineNum + " org src=" + orgSourceLine);
2868 orgSourceLine.indexOf(generateVarDeclaration((VarDescriptor) localVarDesc));
2869 System.out.println("idx=" + idx
2870 + " generateVarDeclaration((VarDescriptor) localVarDesc)="
2871 + generateVarDeclaration((VarDescriptor) localVarDesc));
2873 String annoatedStr =
2874 orgSourceLine.substring(0, idx) + locAnnotationStr + " "
2875 + orgSourceLine.substring(idx);
2876 sourceVec.set(varLineNum, annoatedStr);
2879 String methodDefStr = sourceVec.get(methodDefLine);
2882 getParamLocation(methodDefStr,
2883 generateVarDeclaration((VarDescriptor) localVarDesc));
2884 System.out.println("methodDefStr=" + methodDefStr + " localVarDesc=" + localVarDesc
2888 String annoatedStr =
2889 methodDefStr.substring(0, idx) + locAnnotationStr + " "
2890 + methodDefStr.substring(idx);
2891 sourceVec.set(methodDefLine, annoatedStr);
2896 // check if the lattice has to have the location type for the this
2899 // boolean needToAddthisRef = hasThisReference(md);
2900 // if (localLocElementSet.contains("this")) {
2901 // methodLattice.put("this");
2904 String methodLatticeDefStr = generateLatticeDefinition(md);
2905 String annoatedStr = methodLatticeDefStr + newline + sourceVec.get(methodDefLine);
2906 sourceVec.set(methodDefLine, annoatedStr);
2916 private boolean hasThisReference(MethodDescriptor md) {
2918 FlowGraph fg = getFlowGraph(md);
2919 Set<FlowNode> nodeSet = fg.getNodeSet();
2920 for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
2921 FlowNode flowNode = (FlowNode) iterator.next();
2922 if (flowNode.getDescTuple().get(0).equals(md.getThis())) {
2930 private int getParamLocation(String methodStr, String paramStr) {
2932 String pattern = paramStr + ",";
2934 int idx = methodStr.indexOf(pattern);
2938 pattern = paramStr + ")";
2939 return methodStr.indexOf(pattern);
2944 private String generateVarDeclaration(VarDescriptor varDesc) {
2946 TypeDescriptor td = varDesc.getType();
2947 String rtr = td.toString();
2949 for (int i = 0; i < td.getArrayCount(); i++) {
2953 rtr += " " + varDesc.getName();
2958 private String generateLocationAnnoatation(CompositeLocation loc) {
2961 Location methodLoc = loc.get(0);
2962 rtr += methodLoc.getLocIdentifier();
2964 for (int i = 1; i < loc.getSize(); i++) {
2965 Location element = loc.get(i);
2966 rtr += "," + element.getDescriptor().getSymbol() + "." + element.getLocIdentifier();
2972 private boolean isParameter(MethodDescriptor md, Descriptor localVarDesc) {
2973 return getFlowGraph(md).isParamDesc(localVarDesc);
2976 private String extractFileName(String fileName) {
2977 int idx = fileName.lastIndexOf("/");
2981 return fileName.substring(idx + 1);
2986 private void codeGen() {
2988 Set<String> originalFileNameSet = mapFileNameToLineVector.keySet();
2989 for (Iterator iterator = originalFileNameSet.iterator(); iterator.hasNext();) {
2990 String orgFileName = (String) iterator.next();
2991 String outputFileName = extractFileName(orgFileName);
2993 Vector<String> sourceVec = mapFileNameToLineVector.get(orgFileName);
2997 FileWriter fileWriter = new FileWriter("./infer/" + outputFileName);
2998 BufferedWriter out = new BufferedWriter(fileWriter);
3000 for (int i = 0; i < sourceVec.size(); i++) {
3001 out.write(sourceVec.get(i));
3005 } catch (IOException e) {
3006 e.printStackTrace();
3013 private void checkLattices() {
3015 LinkedList<MethodDescriptor> descriptorListToAnalyze = ssjava.getSortedDescriptors();
3017 // current descriptors to visit in fixed-point interprocedural analysis,
3019 // dependency in the call graph
3020 methodDescriptorsToVisitStack.clear();
3022 // descriptorListToAnalyze.removeFirst();
3024 Set<MethodDescriptor> methodDescriptorToVistSet = new HashSet<MethodDescriptor>();
3025 methodDescriptorToVistSet.addAll(descriptorListToAnalyze);
3027 while (!descriptorListToAnalyze.isEmpty()) {
3028 MethodDescriptor md = descriptorListToAnalyze.removeFirst();
3029 checkLatticesOfVirtualMethods(md);
3034 private void debug_writeLatticeDotFile() {
3035 // generate lattice dot file
3039 while (!toAnalyzeIsEmpty()) {
3040 ClassDescriptor cd = toAnalyzeNext();
3042 setupToAnalazeMethod(cd);
3044 SSJavaLattice<String> classLattice = cd2lattice.get(cd);
3045 if (classLattice != null) {
3046 ssjava.writeLatticeDotFile(cd, null, classLattice);
3047 debug_printDescriptorToLocNameMapping(cd);
3050 while (!toAnalyzeMethodIsEmpty()) {
3051 MethodDescriptor md = toAnalyzeMethodNext();
3052 SSJavaLattice<String> methodLattice = md2lattice.get(md);
3053 if (methodLattice != null) {
3054 ssjava.writeLatticeDotFile(cd, md, methodLattice);
3055 debug_printDescriptorToLocNameMapping(md);
3062 private void debug_printDescriptorToLocNameMapping(Descriptor desc) {
3064 LocationInfo info = getLocationInfo(desc);
3065 System.out.println("## " + desc + " ##");
3066 System.out.println(info.getMapDescToInferLocation());
3067 LocationInfo locInfo = getLocationInfo(desc);
3068 System.out.println("mapping=" + locInfo.getMapLocSymbolToDescSet());
3069 System.out.println("###################");
3073 private void calculateExtraLocations() {
3075 LinkedList<MethodDescriptor> methodDescList = ssjava.getSortedDescriptors();
3076 for (Iterator iterator = methodDescList.iterator(); iterator.hasNext();) {
3077 MethodDescriptor md = (MethodDescriptor) iterator.next();
3078 if (!ssjava.getMethodContainingSSJavaLoop().equals(md)) {
3079 calculateExtraLocations(md);
3085 private void checkLatticesOfVirtualMethods(MethodDescriptor md) {
3087 if (!md.isStatic()) {
3088 Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
3089 setPossibleCallees.addAll(ssjava.getCallGraph().getMethods(md));
3091 for (Iterator iterator = setPossibleCallees.iterator(); iterator.hasNext();) {
3092 MethodDescriptor mdCallee = (MethodDescriptor) iterator.next();
3093 if (!md.equals(mdCallee)) {
3094 checkConsistency(md, mdCallee);
3102 private void checkConsistency(MethodDescriptor md1, MethodDescriptor md2) {
3104 // check that two lattice have the same relations between parameters(+PC
3105 // LOC, GLOBAL_LOC RETURN LOC)
3107 List<CompositeLocation> list1 = new ArrayList<CompositeLocation>();
3108 List<CompositeLocation> list2 = new ArrayList<CompositeLocation>();
3110 MethodLocationInfo locInfo1 = getMethodLocationInfo(md1);
3111 MethodLocationInfo locInfo2 = getMethodLocationInfo(md2);
3113 Map<Integer, CompositeLocation> paramMap1 = locInfo1.getMapParamIdxToInferLoc();
3114 Map<Integer, CompositeLocation> paramMap2 = locInfo2.getMapParamIdxToInferLoc();
3116 int numParam = locInfo1.getMapParamIdxToInferLoc().keySet().size();
3118 // add location types of paramters
3119 for (int idx = 0; idx < numParam; idx++) {
3120 list1.add(paramMap1.get(Integer.valueOf(idx)));
3121 list2.add(paramMap2.get(Integer.valueOf(idx)));
3124 // add program counter location
3125 list1.add(locInfo1.getPCLoc());
3126 list2.add(locInfo2.getPCLoc());
3128 if (!md1.getReturnType().isVoid()) {
3129 // add return value location
3130 CompositeLocation rtrLoc1 = getMethodLocationInfo(md1).getReturnLoc();
3131 CompositeLocation rtrLoc2 = getMethodLocationInfo(md2).getReturnLoc();
3136 // add global location type
3137 if (md1.isStatic()) {
3138 CompositeLocation globalLoc1 =
3139 new CompositeLocation(new Location(md1, locInfo1.getGlobalLocName()));
3140 CompositeLocation globalLoc2 =
3141 new CompositeLocation(new Location(md2, locInfo2.getGlobalLocName()));
3142 list1.add(globalLoc1);
3143 list2.add(globalLoc2);
3146 for (int i = 0; i < list1.size(); i++) {
3147 CompositeLocation locA1 = list1.get(i);
3148 CompositeLocation locA2 = list2.get(i);
3149 for (int k = 0; k < list1.size(); k++) {
3151 CompositeLocation locB1 = list1.get(k);
3152 CompositeLocation locB2 = list2.get(k);
3153 boolean r1 = isGreaterThan(getLattice(md1), locA1, locB1);
3155 boolean r2 = isGreaterThan(getLattice(md1), locA2, locB2);
3158 throw new Error("The method " + md1 + " is not consistent with the method " + md2
3159 + ".:: They have a different ordering relation between locations (" + locA1 + ","
3160 + locB1 + ") and (" + locA2 + "," + locB2 + ").");
3168 private String getSymbol(int idx, FlowNode node) {
3169 Descriptor desc = node.getDescTuple().get(idx);
3170 return desc.getSymbol();
3173 private Descriptor getDescriptor(int idx, FlowNode node) {
3174 Descriptor desc = node.getDescTuple().get(idx);
3178 private void calculatePCLOC(MethodDescriptor md) {
3180 System.out.println("#CalculatePCLOC");
3181 MethodSummary methodSummary = getMethodSummary(md);
3182 FlowGraph fg = getFlowGraph(md);
3183 Map<Integer, CompositeLocation> mapParamToLoc = methodSummary.getMapParamIdxToInferLoc();
3185 // calculate the initial program counter location
3186 // PC location is higher than location types of parameters which has incoming flows.
3188 Set<NTuple<Location>> paramLocTupleHavingInFlowSet = new HashSet<NTuple<Location>>();
3189 Set<Descriptor> paramDescNOTHavingInFlowSet = new HashSet<Descriptor>();
3190 // Set<FlowNode> paramNodeNOThavingInFlowSet = new HashSet<FlowNode>();
3192 int numParams = fg.getNumParameters();
3193 for (int i = 0; i < numParams; i++) {
3194 FlowNode paramFlowNode = fg.getParamFlowNode(i);
3195 Descriptor prefix = paramFlowNode.getDescTuple().get(0);
3196 NTuple<Descriptor> paramDescTuple = paramFlowNode.getCurrentDescTuple();
3197 NTuple<Location> paramLocTuple = translateToLocTuple(md, paramDescTuple);
3199 Set<FlowNode> inNodeToParamSet = fg.getIncomingNodeSetByPrefix(prefix);
3200 if (inNodeToParamSet.size() > 0) {
3201 // parameter has in-value flows
3203 for (Iterator iterator = inNodeToParamSet.iterator(); iterator.hasNext();) {
3204 FlowNode inNode = (FlowNode) iterator.next();
3205 Set<FlowEdge> outEdgeSet = fg.getOutEdgeSet(inNode);
3206 for (Iterator iterator2 = outEdgeSet.iterator(); iterator2.hasNext();) {
3207 FlowEdge flowEdge = (FlowEdge) iterator2.next();
3208 if (flowEdge.getEndTuple().startsWith(prefix)) {
3209 NTuple<Location> paramLocTupleWithIncomingFlow =
3210 translateToLocTuple(md, flowEdge.getEndTuple());
3211 paramLocTupleHavingInFlowSet.add(paramLocTupleWithIncomingFlow);
3216 // paramLocTupleHavingInFlowSet.add(paramLocTuple);
3218 // paramNodeNOThavingInFlowSet.add(fg.getFlowNode(paramDescTuple));
3219 paramDescNOTHavingInFlowSet.add(prefix);
3223 System.out.println("paramLocTupleHavingInFlowSet=" + paramLocTupleHavingInFlowSet);
3225 if (paramLocTupleHavingInFlowSet.size() > 0
3226 && !coversAllParamters(md, fg, paramLocTupleHavingInFlowSet)) {
3228 // Here, generates a location in the method lattice that is higher than the
3229 // paramLocTupleHavingInFlowSet
3230 NTuple<Location> pcLocTuple =
3231 generateLocTupleRelativeTo(md, paramLocTupleHavingInFlowSet, PCLOC);
3233 NTuple<Descriptor> pcDescTuple = translateToDescTuple(pcLocTuple);
3235 // System.out.println("pcLoc=" + pcLocTuple);
3237 CompositeLocation curPCLoc = methodSummary.getPCLoc();
3238 if (curPCLoc.get(0).isTop() || pcLocTuple.size() > curPCLoc.getSize()) {
3239 methodSummary.setPCLoc(new CompositeLocation(pcLocTuple));
3241 Set<FlowNode> flowNodeLowerthanPCLocSet = new HashSet<FlowNode>();
3242 GlobalFlowGraph subGlobalFlowGraph = getSubGlobalFlowGraph(md);
3243 // add ordering relations s.t. PCLOC is higher than all flow nodes except the set of
3244 // parameters that do not have incoming flows
3245 for (Iterator iterator = fg.getNodeSet().iterator(); iterator.hasNext();) {
3246 FlowNode node = (FlowNode) iterator.next();
3248 if (!(node instanceof FlowReturnNode)) {
3249 if (!paramDescNOTHavingInFlowSet.contains(node.getCurrentDescTuple().get(0))) {
3250 flowNodeLowerthanPCLocSet.add(node);
3251 fg.addValueFlowEdge(pcDescTuple, node.getDescTuple());
3253 subGlobalFlowGraph.addValueFlowEdge(pcLocTuple,
3254 translateToLocTuple(md, node.getDescTuple()));
3257 System.out.println("***SKIP PCLOC -> RETURNLOC=" + node);
3261 fg.getFlowNode(translateToDescTuple(pcLocTuple)).setSkeleton(true);
3263 if (pcLocTuple.get(0).getLocDescriptor().equals(md.getThis())) {
3264 System.out.println("#########################################");
3265 for (Iterator iterator = flowNodeLowerthanPCLocSet.iterator(); iterator.hasNext();) {
3266 FlowNode lowerNode = (FlowNode) iterator.next();
3267 if (lowerNode.getDescTuple().size() == 1 && lowerNode.getCompositeLocation() == null) {
3268 NTuple<Location> lowerLocTuple = translateToLocTuple(md, lowerNode.getDescTuple());
3269 CompositeLocation newComp =
3270 calculateCompositeLocationFromSubGlobalGraph(md, lowerNode);
3271 if (newComp != null) {
3272 subGlobalFlowGraph.addMapLocationToInferCompositeLocation(lowerLocTuple.get(0),
3274 lowerNode.setCompositeLocation(newComp);
3275 System.out.println("NEW COMP LOC=" + newComp + " to lowerNode=" + lowerNode);
3288 private int countFirstDescriptorSetSize(Set<NTuple<Location>> set) {
3290 Set<Descriptor> descSet = new HashSet<Descriptor>();
3292 for (Iterator iterator = set.iterator(); iterator.hasNext();) {
3293 NTuple<Location> locTuple = (NTuple<Location>) iterator.next();
3294 descSet.add(locTuple.get(0).getLocDescriptor());
3297 return descSet.size();
3300 private boolean coversAllParamters(MethodDescriptor md, FlowGraph fg,
3301 Set<NTuple<Location>> paramLocTupleHavingInFlowSet) {
3303 int numParam = fg.getNumParameters();
3304 // int size = paramLocTupleHavingInFlowSet.size();
3305 int size = countFirstDescriptorSetSize(paramLocTupleHavingInFlowSet);
3307 System.out.println("numParam=" + numParam + " size=" + size);
3309 // if (!md.isStatic()) {
3311 // // if the method is not static && there is a parameter composite location &&
3312 // // it is started with 'this',
3313 // // paramLocTupleHavingInFlowSet need to have 'this' parameter.
3315 // FlowNode thisParamNode = fg.getParamFlowNode(0);
3316 // NTuple<Location> thisParamLocTuple =
3317 // translateToLocTuple(md, thisParamNode.getCurrentDescTuple());
3319 // if (!paramLocTupleHavingInFlowSet.contains(thisParamLocTuple)) {
3321 // for (Iterator iterator = paramLocTupleHavingInFlowSet.iterator(); iterator.hasNext();) {
3322 // NTuple<Location> paramTuple = (NTuple<Location>) iterator.next();
3323 // if (paramTuple.size() > 1 && paramTuple.get(0).getLocDescriptor().equals(md.getThis())) {
3324 // // paramLocTupleHavingInFlowSet.add(thisParamLocTuple);
3333 if (size == numParam) {
3341 private void calculateRETURNLOC(MethodDescriptor md) {
3343 System.out.println("#calculateRETURNLOC= " + md);
3345 // calculate a return location:
3346 // the return location type is lower than all parameters and the location of return values
3347 MethodSummary methodSummary = getMethodSummary(md);
3348 // if (methodSummary.getRETURNLoc() != null) {
3349 // System.out.println("$HERE?");
3353 FlowGraph fg = getFlowGraph(md);
3354 Map<Integer, CompositeLocation> mapParamToLoc = methodSummary.getMapParamIdxToInferLoc();
3355 Set<Integer> paramIdxSet = mapParamToLoc.keySet();
3357 if (md.getReturnType() != null && !md.getReturnType().isVoid()) {
3358 // first, generate the set of return value location types that starts
3359 // with 'this' reference
3361 Set<FlowNode> paramFlowNodeFlowingToReturnValueSet = getParamNodeFlowingToReturnValue(md);
3362 // System.out.println("paramFlowNodeFlowingToReturnValueSet="
3363 // + paramFlowNodeFlowingToReturnValueSet);
3365 Set<NTuple<Location>> tupleToBeHigherThanReturnLocSet = new HashSet<NTuple<Location>>();
3366 for (Iterator iterator = paramFlowNodeFlowingToReturnValueSet.iterator(); iterator.hasNext();) {
3367 FlowNode fn = (FlowNode) iterator.next();
3368 NTuple<Descriptor> paramDescTuple = fn.getCurrentDescTuple();
3369 tupleToBeHigherThanReturnLocSet.add(translateToLocTuple(md, paramDescTuple));
3372 Set<FlowNode> returnNodeSet = fg.getReturnNodeSet();
3373 for (Iterator iterator = returnNodeSet.iterator(); iterator.hasNext();) {
3374 FlowNode returnNode = (FlowNode) iterator.next();
3375 NTuple<Descriptor> returnDescTuple = returnNode.getCurrentDescTuple();
3376 tupleToBeHigherThanReturnLocSet.add(translateToLocTuple(md, returnDescTuple));
3378 System.out.println("-flow graph's returnNodeSet=" + returnNodeSet);
3379 System.out.println("tupleSetToBeHigherThanReturnLoc=" + tupleToBeHigherThanReturnLocSet);
3381 // Here, generates a return location in the method lattice that is lower than the
3382 // locFlowingToReturnValueSet
3383 NTuple<Location> returnLocTuple =
3384 generateLocTupleRelativeTo(md, tupleToBeHigherThanReturnLocSet, RLOC);
3386 // System.out.println("returnLocTuple=" + returnLocTuple);
3387 NTuple<Descriptor> returnDescTuple = translateToDescTuple(returnLocTuple);
3388 CompositeLocation curReturnLoc = methodSummary.getRETURNLoc();
3389 if (curReturnLoc == null || returnDescTuple.size() > curReturnLoc.getSize()) {
3390 methodSummary.setRETURNLoc(new CompositeLocation(returnLocTuple));
3392 for (Iterator iterator = tupleToBeHigherThanReturnLocSet.iterator(); iterator.hasNext();) {
3393 NTuple<Location> higherTuple = (NTuple<Location>) iterator.next();
3394 fg.addValueFlowEdge(translateToDescTuple(higherTuple), returnDescTuple);
3396 fg.getFlowNode(returnDescTuple).setSkeleton(true);
3400 // makes sure that PCLOC is higher than RETURNLOC
3401 CompositeLocation pcLoc = methodSummary.getPCLoc();
3402 if (!pcLoc.get(0).isTop()) {
3403 NTuple<Descriptor> pcLocDescTuple = translateToDescTuple(pcLoc.getTuple());
3404 fg.addValueFlowEdge(pcLocDescTuple, returnDescTuple);
3411 private void calculateExtraLocations(MethodDescriptor md) {
3412 // calcualte pcloc, returnloc,...
3414 System.out.println("\nSSJAVA:Calculate PCLOC/RETURNLOC locations: " + md);
3417 calculateRETURNLOC(md);
3421 private NTuple<Location> generateLocTupleRelativeTo(MethodDescriptor md,
3422 Set<NTuple<Location>> paramLocTupleHavingInFlowSet, String locNamePrefix) {
3424 // System.out.println("-generateLocTupleRelativeTo=" + paramLocTupleHavingInFlowSet);
3426 NTuple<Location> higherLocTuple = new NTuple<Location>();
3428 VarDescriptor thisVarDesc = md.getThis();
3429 // check if all paramter loc tuple is started with 'this' reference
3430 boolean hasParamNotStartedWithThisRef = false;
3434 Set<NTuple<Location>> paramLocTupleStartedWithThis = new HashSet<NTuple<Location>>();
3436 next: for (Iterator iterator = paramLocTupleHavingInFlowSet.iterator(); iterator.hasNext();) {
3437 NTuple<Location> paramLocTuple = (NTuple<Location>) iterator.next();
3438 Descriptor paramLocalDesc = paramLocTuple.get(0).getLocDescriptor();
3439 if (!paramLocalDesc.equals(thisVarDesc)) {
3441 Set<FlowNode> inNodeSet = getFlowGraph(md).getIncomingNodeSetByPrefix(paramLocalDesc);
3442 for (Iterator iterator2 = inNodeSet.iterator(); iterator2.hasNext();) {
3443 FlowNode flowNode = (FlowNode) iterator2.next();
3444 if (flowNode.getDescTuple().startsWith(thisVarDesc)) {
3445 // System.out.println("paramLocTuple=" + paramLocTuple + " is lower than THIS");
3449 hasParamNotStartedWithThisRef = true;
3451 } else if (paramLocTuple.size() > 1) {
3452 paramLocTupleStartedWithThis.add(paramLocTuple);
3453 if (minSize == 0 || minSize > paramLocTuple.size()) {
3454 minSize = paramLocTuple.size();
3459 // System.out.println("---paramLocTupleStartedWithThis=" + paramLocTupleStartedWithThis);
3460 Descriptor enclosingDesc = md;
3461 if (hasParamNotStartedWithThisRef) {
3462 // in this case, PCLOC will be the local location
3464 // all parameter is started with 'this', so PCLOC will be set relative to the composite
3465 // location started with 'this'.
3466 // for (int idx = 0; idx < minSize - 1; idx++) {
3467 for (int idx = 0; idx < 1; idx++) {
3468 Set<Descriptor> locDescSet = new HashSet<Descriptor>();
3469 Location curLoc = null;
3470 NTuple<Location> paramLocTuple = null;
3471 for (Iterator iterator = paramLocTupleStartedWithThis.iterator(); iterator.hasNext();) {
3472 paramLocTuple = (NTuple<Location>) iterator.next();
3473 // System.out.println("-----paramLocTuple=" + paramLocTuple + " idx=" + idx);
3474 curLoc = paramLocTuple.get(idx);
3475 Descriptor locDesc = curLoc.getLocDescriptor();
3476 locDescSet.add(locDesc);
3478 // System.out.println("-----locDescSet=" + locDescSet + " idx=" + idx);
3479 if (locDescSet.size() != 1) {
3482 Location newLocElement = new Location(curLoc.getDescriptor(), curLoc.getLocDescriptor());
3483 System.out.println("newLocElement" + newLocElement);
3484 higherLocTuple.add(newLocElement);
3485 enclosingDesc = getClassTypeDescriptor(curLoc.getLocDescriptor());
3490 String locIdentifier = locNamePrefix + (locSeed++);
3491 NameDescriptor locDesc = new NameDescriptor(locIdentifier);
3492 Location newLoc = new Location(enclosingDesc, locDesc);
3493 higherLocTuple.add(newLoc);
3494 System.out.println("---new loc tuple=" + higherLocTuple);
3496 return higherLocTuple;
3500 public ClassDescriptor getClassTypeDescriptor(Descriptor in) {
3502 if (in instanceof VarDescriptor) {
3503 return ((VarDescriptor) in).getType().getClassDesc();
3504 } else if (in instanceof FieldDescriptor) {
3505 return ((FieldDescriptor) in).getType().getClassDesc();
3507 // else if (in instanceof LocationDescriptor) {
3508 // // here is the case that the descriptor 'in' is the last element of the assigned composite
3510 // return ((VarDescriptor) locTuple.get(0).getLocDescriptor()).getType().getClassDesc();
3518 private Set<NTuple<Location>> calculateHighestLocTupleSet(
3519 Set<NTuple<Location>> paramLocTupleHavingInFlowSet) {
3521 Set<NTuple<Location>> highestSet = new HashSet<NTuple<Location>>();
3523 Iterator<NTuple<Location>> iterator = paramLocTupleHavingInFlowSet.iterator();
3524 NTuple<Location> highest = iterator.next();
3526 for (; iterator.hasNext();) {
3527 NTuple<Location> curLocTuple = (NTuple<Location>) iterator.next();
3528 if (isHigherThan(curLocTuple, highest)) {
3529 // System.out.println(curLocTuple + " is greater than " + highest);
3530 highest = curLocTuple;
3534 highestSet.add(highest);
3536 MethodDescriptor md = (MethodDescriptor) highest.get(0).getDescriptor();
3537 VarDescriptor thisVarDesc = md.getThis();
3539 // System.out.println("highest=" + highest);
3541 for (Iterator<NTuple<Location>> iter = paramLocTupleHavingInFlowSet.iterator(); iter.hasNext();) {
3542 NTuple<Location> curLocTuple = iter.next();
3544 if (!curLocTuple.equals(highest) && !hasOrderingRelation(highest, curLocTuple)) {
3546 // System.out.println("add it to the highest set=" + curLocTuple);
3547 highestSet.add(curLocTuple);
3556 private Set<String> getHigherLocSymbolThan(SSJavaLattice<String> lattice, String loc) {
3557 Set<String> higherLocSet = new HashSet<String>();
3559 Set<String> locSet = lattice.getTable().keySet();
3560 for (Iterator iterator = locSet.iterator(); iterator.hasNext();) {
3561 String element = (String) iterator.next();
3562 if (lattice.isGreaterThan(element, loc) && (!element.equals(lattice.getTopItem()))) {
3563 higherLocSet.add(element);
3566 return higherLocSet;
3569 private CompositeLocation getLowest(SSJavaLattice<String> methodLattice,
3570 Set<CompositeLocation> set) {
3572 CompositeLocation lowest = set.iterator().next();
3574 if (set.size() == 1) {
3578 for (Iterator iterator = set.iterator(); iterator.hasNext();) {
3579 CompositeLocation loc = (CompositeLocation) iterator.next();
3581 if ((!loc.equals(lowest)) && (!isComparable(methodLattice, lowest, loc))) {
3582 // if there is a case where composite locations are incomparable, just
3587 if ((!loc.equals(lowest)) && isGreaterThan(methodLattice, lowest, loc)) {
3594 private boolean isComparable(SSJavaLattice<String> methodLattice, CompositeLocation comp1,
3595 CompositeLocation comp2) {
3597 int size = comp1.getSize() >= comp2.getSize() ? comp2.getSize() : comp1.getSize();
3599 for (int idx = 0; idx < size; idx++) {
3600 Location loc1 = comp1.get(idx);
3601 Location loc2 = comp2.get(idx);
3603 Descriptor desc1 = loc1.getDescriptor();
3604 Descriptor desc2 = loc2.getDescriptor();
3606 if (!desc1.equals(desc2)) {
3607 throw new Error("Fail to compare " + comp1 + " and " + comp2);
3610 String symbol1 = loc1.getLocIdentifier();
3611 String symbol2 = loc2.getLocIdentifier();
3613 SSJavaLattice<String> lattice;
3615 lattice = methodLattice;
3617 lattice = getLattice(desc1);
3620 if (symbol1.equals(symbol2)) {
3622 } else if (!lattice.isComparable(symbol1, symbol2)) {
3631 private boolean isGreaterThan(SSJavaLattice<String> methodLattice, CompositeLocation comp1,
3632 CompositeLocation comp2) {
3634 int size = comp1.getSize() >= comp2.getSize() ? comp2.getSize() : comp1.getSize();
3636 for (int idx = 0; idx < size; idx++) {
3637 Location loc1 = comp1.get(idx);
3638 Location loc2 = comp2.get(idx);
3640 Descriptor desc1 = loc1.getDescriptor();
3641 Descriptor desc2 = loc2.getDescriptor();
3643 if (!desc1.equals(desc2)) {
3644 throw new Error("Fail to compare " + comp1 + " and " + comp2);
3647 String symbol1 = loc1.getLocIdentifier();
3648 String symbol2 = loc2.getLocIdentifier();
3650 SSJavaLattice<String> lattice;
3652 lattice = methodLattice;
3654 lattice = getLattice(desc1);
3657 if (symbol1.equals(symbol2)) {
3659 } else if (lattice.isGreaterThan(symbol1, symbol2)) {
3670 private GlobalFlowGraph getSubGlobalFlowGraph(MethodDescriptor md) {
3672 if (!mapMethodDescriptorToSubGlobalFlowGraph.containsKey(md)) {
3673 mapMethodDescriptorToSubGlobalFlowGraph.put(md, new GlobalFlowGraph(md));
3675 return mapMethodDescriptorToSubGlobalFlowGraph.get(md);
3678 private void propagateFlowsToCallerWithNoCompositeLocation(MethodInvokeNode min,
3679 MethodDescriptor mdCaller, MethodDescriptor mdCallee) {
3681 System.out.println("-propagateFlowsToCallerWithNoCompositeLocation=" + min.printNode(0));
3682 // if the parameter A reaches to the parameter B
3683 // then, add an edge the argument A -> the argument B to the caller's flow
3686 FlowGraph calleeFlowGraph = getFlowGraph(mdCallee);
3687 FlowGraph callerFlowGraph = getFlowGraph(mdCaller);
3688 int numParam = calleeFlowGraph.getNumParameters();
3690 for (int i = 0; i < numParam; i++) {
3691 for (int k = 0; k < numParam; k++) {
3695 FlowNode paramNode1 = calleeFlowGraph.getParamFlowNode(i);
3696 FlowNode paramNode2 = calleeFlowGraph.getParamFlowNode(k);
3698 NTuple<Descriptor> arg1Tuple = getNodeTupleByArgIdx(min, i);
3699 NTuple<Descriptor> arg2Tuple = getNodeTupleByArgIdx(min, k);
3701 // check if the callee propagates an ordering constraints through
3704 // Set<FlowNode> localReachSet = calleeFlowGraph.getLocalReachFlowNodeSetFrom(paramNode1);
3705 Set<FlowNode> localReachSet =
3706 calleeFlowGraph.getReachableSetFrom(paramNode1.getDescTuple());
3708 NTuple<Descriptor> paramDescTuple1 = paramNode1.getCurrentDescTuple();
3709 NTuple<Descriptor> paramDescTuple2 = paramNode2.getCurrentDescTuple();
3711 // System.out.println("-param1CurTuple=" + paramDescTuple1 + " param2CurTuple="
3712 // + paramDescTuple2);
3713 // System.out.println("-- localReachSet from param1=" + localReachSet);
3715 if (paramDescTuple1.get(0).equals(paramDescTuple2.get(0))) {
3716 // if two parameters share the same prefix
3717 // it already has been assigned to a composite location
3718 // so we don't need to add an additional ordering relation caused by these two
3723 if (arg1Tuple.size() > 0 && arg2Tuple.size() > 0
3724 && containsPrefix(paramNode2.getDescTuple().get(0), localReachSet)) {
3725 // need to propagate an ordering relation s.t. arg1 is higher
3727 // System.out.println("-param1=" + paramNode1 + " is higher than param2=" + paramNode2);
3729 // add a new flow between the corresponding arguments.
3730 callerFlowGraph.addValueFlowEdge(arg1Tuple, arg2Tuple);
3731 // System.out.println("arg1=" + arg1Tuple + " arg2=" + arg2Tuple);
3734 // .println("-arg1Tuple=" + arg1Tuple + " is higher than arg2Tuple=" + arg2Tuple);
3738 // System.out.println();
3743 // if a parameter has a composite location and the first element of the parameter location
3744 // matches the callee's 'this'
3745 // we have a more specific constraint: the caller's corresponding argument is higher than the
3746 // parameter location which is translated into the caller
3748 for (int idx = 0; idx < numParam; idx++) {
3749 FlowNode paramNode = calleeFlowGraph.getParamFlowNode(idx);
3750 CompositeLocation compLoc = paramNode.getCompositeLocation();
3751 System.out.println("paramNode=" + paramNode + " compLoc=" + compLoc);
3752 if (compLoc != null && compLoc.get(0).getLocDescriptor().equals(min.getMethod().getThis())) {
3753 System.out.println("$$$COMPLOC CASE=" + compLoc + " idx=" + idx);
3755 NTuple<Descriptor> argTuple = getNodeTupleByArgIdx(min, idx);
3756 System.out.println("--- argTuple=" + argTuple + " current compLoc="
3757 + callerFlowGraph.getFlowNode(argTuple).getCompositeLocation());
3759 NTuple<Descriptor> translatedParamTuple =
3760 translateCompositeLocationToCaller(idx, min, compLoc);
3761 System.out.println("add a flow edge= " + argTuple + "->" + translatedParamTuple);
3762 callerFlowGraph.addValueFlowEdge(argTuple, translatedParamTuple);
3764 Set<NTuple<Location>> pcLocTupleSet = getPCLocTupleSet(min);
3765 for (Iterator iterator = pcLocTupleSet.iterator(); iterator.hasNext();) {
3766 NTuple<Location> pcLocTuple = (NTuple<Location>) iterator.next();
3767 callerFlowGraph.addValueFlowEdge(translateToDescTuple(pcLocTuple), translatedParamTuple);
3775 private boolean containsPrefix(Descriptor prefixDesc, Set<FlowNode> set) {
3777 for (Iterator iterator = set.iterator(); iterator.hasNext();) {
3778 FlowNode flowNode = (FlowNode) iterator.next();
3779 if (flowNode.getDescTuple().startsWith(prefixDesc)) {
3780 System.out.println("FOUND=" + flowNode);
3787 private NTuple<Descriptor> translateCompositeLocationToCaller(int idx, MethodInvokeNode min,
3788 CompositeLocation compLocForParam1) {
3790 NTuple<Descriptor> baseTuple = mapMethodInvokeNodeToBaseTuple.get(min);
3792 NTuple<Descriptor> tuple = new NTuple<Descriptor>();
3793 for (int i = 0; i < baseTuple.size(); i++) {
3794 tuple.add(baseTuple.get(i));
3797 for (int i = 1; i < compLocForParam1.getSize(); i++) {
3798 Location loc = compLocForParam1.get(i);
3799 tuple.add(loc.getLocDescriptor());
3805 private CompositeLocation generateCompositeLocation(NTuple<Location> prefixLocTuple) {
3807 System.out.println("generateCompositeLocation=" + prefixLocTuple);
3809 CompositeLocation newCompLoc = new CompositeLocation();
3810 for (int i = 0; i < prefixLocTuple.size(); i++) {
3811 newCompLoc.addLocation(prefixLocTuple.get(i));
3814 Descriptor lastDescOfPrefix = prefixLocTuple.get(prefixLocTuple.size() - 1).getLocDescriptor();
3816 ClassDescriptor enclosingDescriptor;
3817 if (lastDescOfPrefix instanceof FieldDescriptor) {
3818 enclosingDescriptor = ((FieldDescriptor) lastDescOfPrefix).getType().getClassDesc();
3819 // System.out.println("enclosingDescriptor0=" + enclosingDescriptor);
3820 } else if (lastDescOfPrefix.equals(GLOBALDESC)) {
3821 MethodDescriptor currentMethodDesc = (MethodDescriptor) prefixLocTuple.get(0).getDescriptor();
3822 enclosingDescriptor = currentMethodDesc.getClassDesc();
3824 // var descriptor case
3825 enclosingDescriptor = ((VarDescriptor) lastDescOfPrefix).getType().getClassDesc();
3827 // System.out.println("enclosingDescriptor=" + enclosingDescriptor);
3829 LocationDescriptor newLocDescriptor = generateNewLocationDescriptor();
3830 newLocDescriptor.setEnclosingClassDesc(enclosingDescriptor);
3832 Location newLoc = new Location(enclosingDescriptor, newLocDescriptor.getSymbol());
3833 newLoc.setLocDescriptor(newLocDescriptor);
3834 newCompLoc.addLocation(newLoc);
3836 // System.out.println("--newCompLoc=" + newCompLoc);
3840 private CompositeLocation generateCompositeLocation(MethodDescriptor md,
3841 NTuple<Descriptor> paramPrefix) {
3843 System.out.println("generateCompositeLocation=" + paramPrefix);
3845 CompositeLocation newCompLoc = convertToCompositeLocation(md, paramPrefix);
3847 Descriptor lastDescOfPrefix = paramPrefix.get(paramPrefix.size() - 1);
3848 // System.out.println("lastDescOfPrefix=" + lastDescOfPrefix + " kind="
3849 // + lastDescOfPrefix.getClass());
3850 ClassDescriptor enclosingDescriptor;
3851 if (lastDescOfPrefix instanceof FieldDescriptor) {
3852 enclosingDescriptor = ((FieldDescriptor) lastDescOfPrefix).getType().getClassDesc();
3853 // System.out.println("enclosingDescriptor0=" + enclosingDescriptor);
3855 // var descriptor case
3856 enclosingDescriptor = ((VarDescriptor) lastDescOfPrefix).getType().getClassDesc();
3858 // System.out.println("enclosingDescriptor=" + enclosingDescriptor);
3860 LocationDescriptor newLocDescriptor = generateNewLocationDescriptor();
3861 newLocDescriptor.setEnclosingClassDesc(enclosingDescriptor);
3863 Location newLoc = new Location(enclosingDescriptor, newLocDescriptor.getSymbol());
3864 newLoc.setLocDescriptor(newLocDescriptor);
3865 newCompLoc.addLocation(newLoc);
3867 // System.out.println("--newCompLoc=" + newCompLoc);
3871 private List<NTuple<Descriptor>> translatePrefixListToCallee(Descriptor baseRef,
3872 MethodDescriptor mdCallee, List<NTuple<Descriptor>> callerPrefixList) {
3874 List<NTuple<Descriptor>> calleePrefixList = new ArrayList<NTuple<Descriptor>>();
3876 for (int i = 0; i < callerPrefixList.size(); i++) {
3877 NTuple<Descriptor> prefix = callerPrefixList.get(i);
3878 if (prefix.startsWith(baseRef)) {
3879 NTuple<Descriptor> calleePrefix = new NTuple<Descriptor>();
3880 calleePrefix.add(mdCallee.getThis());
3881 for (int k = 1; k < prefix.size(); k++) {
3882 calleePrefix.add(prefix.get(k));
3884 calleePrefixList.add(calleePrefix);
3888 return calleePrefixList;
3892 public CompositeLocation convertToCompositeLocation(MethodDescriptor md, NTuple<Descriptor> tuple) {
3894 CompositeLocation compLoc = new CompositeLocation();
3896 Descriptor enclosingDescriptor = md;
3898 for (int i = 0; i < tuple.size(); i++) {
3899 Descriptor curDescriptor = tuple.get(i);
3900 Location locElement = new Location(enclosingDescriptor, curDescriptor.getSymbol());
3901 locElement.setLocDescriptor(curDescriptor);
3902 compLoc.addLocation(locElement);
3904 if (curDescriptor instanceof VarDescriptor) {
3905 enclosingDescriptor = md.getClassDesc();
3906 } else if (curDescriptor instanceof FieldDescriptor) {
3907 enclosingDescriptor = ((FieldDescriptor) curDescriptor).getClassDescriptor();
3908 } else if (curDescriptor instanceof NameDescriptor) {
3909 // it is "GLOBAL LOC" case!
3910 enclosingDescriptor = GLOBALDESC;
3911 } else if (curDescriptor instanceof InterDescriptor) {
3912 enclosingDescriptor = getFlowGraph(md).getEnclosingDescriptor(curDescriptor);
3914 enclosingDescriptor = null;
3922 private LocationDescriptor generateNewLocationDescriptor() {
3923 return new LocationDescriptor("Loc" + (locSeed++));
3926 private int getPrefixIndex(NTuple<Descriptor> tuple1, NTuple<Descriptor> tuple2) {
3928 // return the index where the prefix shared by tuple1 and tuple2 is ended
3929 // if there is no prefix shared by both of them, return -1
3931 int minSize = tuple1.size();
3932 if (minSize > tuple2.size()) {
3933 minSize = tuple2.size();
3937 for (int i = 0; i < minSize; i++) {
3938 if (!tuple1.get(i).equals(tuple2.get(i))) {
3948 private CompositeLocation generateInferredCompositeLocation(MethodLocationInfo methodInfo,
3949 NTuple<Location> tuple) {
3951 // first, retrieve inferred location by the local var descriptor
3952 CompositeLocation inferLoc = new CompositeLocation();
3954 CompositeLocation localVarInferLoc =
3955 methodInfo.getInferLocation(tuple.get(0).getLocDescriptor());
3957 localVarInferLoc.get(0).setLocDescriptor(tuple.get(0).getLocDescriptor());
3959 for (int i = 0; i < localVarInferLoc.getSize(); i++) {
3960 inferLoc.addLocation(localVarInferLoc.get(i));
3963 for (int i = 1; i < tuple.size(); i++) {
3964 Location cur = tuple.get(i);
3965 Descriptor enclosingDesc = cur.getDescriptor();
3966 Descriptor curDesc = cur.getLocDescriptor();
3968 Location inferLocElement;
3969 if (curDesc == null) {
3970 // in this case, we have a newly generated location.
3971 inferLocElement = new Location(enclosingDesc, cur.getLocIdentifier());
3973 String fieldLocSymbol =
3974 getLocationInfo(enclosingDesc).getInferLocation(curDesc).get(0).getLocIdentifier();
3975 inferLocElement = new Location(enclosingDesc, fieldLocSymbol);
3976 inferLocElement.setLocDescriptor(curDesc);
3979 inferLoc.addLocation(inferLocElement);
3983 assert (inferLoc.get(0).getLocDescriptor().getSymbol() == inferLoc.get(0).getLocIdentifier());
3987 public LocationInfo getLocationInfo(Descriptor d) {
3988 if (d instanceof MethodDescriptor) {
3989 return getMethodLocationInfo((MethodDescriptor) d);
3991 return getFieldLocationInfo((ClassDescriptor) d);
3995 private MethodLocationInfo getMethodLocationInfo(MethodDescriptor md) {
3997 if (!mapMethodDescToMethodLocationInfo.containsKey(md)) {
3998 mapMethodDescToMethodLocationInfo.put(md, new MethodLocationInfo(md));
4001 return mapMethodDescToMethodLocationInfo.get(md);
4005 private LocationInfo getFieldLocationInfo(ClassDescriptor cd) {
4007 if (!mapClassToLocationInfo.containsKey(cd)) {
4008 mapClassToLocationInfo.put(cd, new LocationInfo(cd));
4011 return mapClassToLocationInfo.get(cd);
4015 private void addPrefixMapping(Map<NTuple<Location>, Set<NTuple<Location>>> map,
4016 NTuple<Location> prefix, NTuple<Location> element) {
4018 if (!map.containsKey(prefix)) {
4019 map.put(prefix, new HashSet<NTuple<Location>>());
4021 map.get(prefix).add(element);
4024 private boolean containsNonPrimitiveElement(Set<Descriptor> descSet) {
4025 for (Iterator iterator = descSet.iterator(); iterator.hasNext();) {
4026 Descriptor desc = (Descriptor) iterator.next();
4028 if (desc.equals(LocationInference.GLOBALDESC)) {
4030 } else if (desc instanceof VarDescriptor) {
4031 if (!((VarDescriptor) desc).getType().isPrimitive()) {
4034 } else if (desc instanceof FieldDescriptor) {
4035 if (!((FieldDescriptor) desc).getType().isPrimitive()) {
4044 private SSJavaLattice<String> getLattice(Descriptor d) {
4045 if (d instanceof MethodDescriptor) {
4046 return getMethodLattice((MethodDescriptor) d);
4048 return getFieldLattice((ClassDescriptor) d);
4052 private SSJavaLattice<String> getMethodLattice(MethodDescriptor md) {
4053 if (!md2lattice.containsKey(md)) {
4054 md2lattice.put(md, new SSJavaLattice<String>(SSJavaAnalysis.TOP, SSJavaAnalysis.BOTTOM));
4056 return md2lattice.get(md);
4059 private void setMethodLattice(MethodDescriptor md, SSJavaLattice<String> lattice) {
4060 md2lattice.put(md, lattice);
4063 private void extractFlowsBetweenFields(ClassDescriptor cd, FlowNode srcNode, FlowNode dstNode,
4066 NTuple<Descriptor> srcCurTuple = srcNode.getCurrentDescTuple();
4067 NTuple<Descriptor> dstCurTuple = dstNode.getCurrentDescTuple();
4069 if (srcCurTuple.get(idx).equals(dstCurTuple.get(idx)) && srcCurTuple.size() > (idx + 1)
4070 && dstCurTuple.size() > (idx + 1)) {
4071 // value flow between fields: we don't need to add a binary relation
4074 Descriptor desc = srcCurTuple.get(idx);
4075 ClassDescriptor classDesc;
4078 classDesc = ((VarDescriptor) desc).getType().getClassDesc();
4080 if (desc instanceof FieldDescriptor) {
4081 classDesc = ((FieldDescriptor) desc).getType().getClassDesc();
4083 // this case is that the local variable has a composite location assignment
4084 // the following element after the composite location to the local variable
4085 // has the enclosing descriptor of the local variable
4086 Descriptor localDesc = srcNode.getDescTuple().get(0);
4087 classDesc = ((VarDescriptor) localDesc).getType().getClassDesc();
4090 extractFlowsBetweenFields(classDesc, srcNode, dstNode, idx + 1);
4094 Descriptor srcFieldDesc = srcCurTuple.get(idx);
4095 Descriptor dstFieldDesc = dstCurTuple.get(idx);
4097 System.out.println("srcFieldDesc=" + srcFieldDesc + " dstFieldDesc=" + dstFieldDesc
4099 if (!srcFieldDesc.equals(dstFieldDesc)) {
4101 System.out.println("-ADD EDGE");
4102 getHierarchyGraph(cd).addEdge(srcFieldDesc, dstFieldDesc);
4103 } else if (!isReference(srcFieldDesc) && !isReference(dstFieldDesc)) {
4104 System.out.println("-ADD EDGE");
4105 getHierarchyGraph(cd).addEdge(srcFieldDesc, dstFieldDesc);
4112 public SSJavaLattice<String> getFieldLattice(ClassDescriptor cd) {
4113 if (!cd2lattice.containsKey(cd)) {
4114 cd2lattice.put(cd, new SSJavaLattice<String>(SSJavaAnalysis.TOP, SSJavaAnalysis.BOTTOM));
4116 return cd2lattice.get(cd);
4119 public LinkedList<MethodDescriptor> computeMethodList() {
4121 Set<MethodDescriptor> toSort = new HashSet<MethodDescriptor>();
4125 Set<MethodDescriptor> visited = new HashSet<MethodDescriptor>();
4126 Set<MethodDescriptor> reachableCallee = new HashSet<MethodDescriptor>();
4128 while (!toAnalyzeIsEmpty()) {
4129 ClassDescriptor cd = toAnalyzeNext();
4131 setupToAnalazeMethod(cd);
4132 temp_toanalyzeMethodList.removeAll(visited);
4134 while (!toAnalyzeMethodIsEmpty()) {
4135 MethodDescriptor md = toAnalyzeMethodNext();
4136 if ((!visited.contains(md))
4137 && (ssjava.needTobeAnnotated(md) || reachableCallee.contains(md))) {
4139 // creates a mapping from a method descriptor to virtual methods
4140 Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
4141 if (md.isStatic()) {
4142 setPossibleCallees.add(md);
4144 setPossibleCallees.addAll(ssjava.getCallGraph().getMethods(md));
4147 Set<MethodDescriptor> calleeSet = ssjava.getCallGraph().getCalleeSet(md);
4148 Set<MethodDescriptor> needToAnalyzeCalleeSet = new HashSet<MethodDescriptor>();
4150 for (Iterator iterator = calleeSet.iterator(); iterator.hasNext();) {
4151 MethodDescriptor calleemd = (MethodDescriptor) iterator.next();
4152 if ((!ssjava.isTrustMethod(calleemd))
4153 && (!ssjava.isSSJavaUtil(calleemd.getClassDesc()))
4154 && (!calleemd.getModifiers().isNative())) {
4155 if (!visited.contains(calleemd)) {
4156 temp_toanalyzeMethodList.add(calleemd);
4158 reachableCallee.add(calleemd);
4159 needToAnalyzeCalleeSet.add(calleemd);
4163 mapMethodToCalleeSet.put(md, needToAnalyzeCalleeSet);
4172 return ssjava.topologicalSort(toSort);
4176 public boolean isTransitivelyCalledFrom(MethodDescriptor callee, MethodDescriptor caller) {
4177 // if the callee is transitively invoked from the caller
4180 int callerIdx = toanalyze_methodDescList.indexOf(caller);
4181 int calleeIdx = toanalyze_methodDescList.indexOf(callee);
4183 if (callerIdx < calleeIdx) {
4191 public void constructFlowGraph() {
4193 System.out.println("");
4194 toanalyze_methodDescList = computeMethodList();
4196 // hack... it seems that there is a problem with topological sorting.
4197 // so String.toString(Object o) is appeared too higher in the call chain.
4198 MethodDescriptor mdToString = null;
4199 for (Iterator iterator = toanalyze_methodDescList.iterator(); iterator.hasNext();) {
4200 MethodDescriptor md = (MethodDescriptor) iterator.next();
4201 if (md.toString().equals("public static String String.valueOf(Object o)")) {
4206 if (mdToString != null) {
4207 toanalyze_methodDescList.remove(mdToString);
4208 toanalyze_methodDescList.addLast(mdToString);
4211 LinkedList<MethodDescriptor> methodDescList =
4212 (LinkedList<MethodDescriptor>) toanalyze_methodDescList.clone();
4214 System.out.println("@@@methodDescList=" + methodDescList);
4217 while (!methodDescList.isEmpty()) {
4218 MethodDescriptor md = methodDescList.removeLast();
4219 if (state.SSJAVADEBUG) {
4220 System.out.println();
4221 System.out.println("SSJAVA: Constructing a flow graph: " + md);
4223 // creates a mapping from a parameter descriptor to its index
4224 Map<Descriptor, Integer> mapParamDescToIdx = new HashMap<Descriptor, Integer>();
4226 if (!md.isStatic()) {
4228 mapParamDescToIdx.put(md.getThis(), 0);
4231 for (int i = 0; i < md.numParameters(); i++) {
4232 Descriptor paramDesc = (Descriptor) md.getParameter(i);
4233 mapParamDescToIdx.put(paramDesc, new Integer(i + offset));
4236 FlowGraph fg = new FlowGraph(md, mapParamDescToIdx);
4237 mapMethodDescriptorToFlowGraph.put(md, fg);
4239 analyzeMethodBody(md.getClassDesc(), md);
4241 // System.out.println("##constructSubGlobalFlowGraph");
4242 // GlobalFlowGraph subGlobalFlowGraph = constructSubGlobalFlowGraph(fg);
4243 // mapMethodDescriptorToSubGlobalFlowGraph.put(md, subGlobalFlowGraph);
4246 // System.out.println("##addValueFlowsFromCalleeSubGlobalFlowGraph");
4247 // addValueFlowsFromCalleeSubGlobalFlowGraph(md, subGlobalFlowGraph);
4248 // subGlobalFlowGraph.writeGraph("_SUBGLOBAL");
4250 // propagateFlowsFromCalleesWithNoCompositeLocation(md);
4253 // _debug_printGraph();
4257 private void constructGlobalFlowGraph() {
4258 LinkedList<MethodDescriptor> methodDescList =
4259 (LinkedList<MethodDescriptor>) toanalyze_methodDescList.clone();
4261 while (!methodDescList.isEmpty()) {
4262 MethodDescriptor md = methodDescList.removeLast();
4263 if (state.SSJAVADEBUG) {
4264 System.out.println();
4265 System.out.println("SSJAVA: Constructing a sub global flow graph: " + md);
4267 constructSubGlobalFlowGraph(getFlowGraph(md));
4270 System.out.println("-add Value Flows From CalleeSubGlobalFlowGraph");
4271 addValueFlowsFromCalleeSubGlobalFlowGraph(md);
4272 // subGlobalFlowGraph.writeGraph("_SUBGLOBAL");
4274 // System.out.println("-propagate Flows From Callees With No CompositeLocation");
4275 // propagateFlowsFromCalleesWithNoCompositeLocation(md);
4277 // mark if a parameter has incoming flows
4278 checkParamNodesInSubGlobalFlowGraph(md);
4284 private void checkParamNodesInSubGlobalFlowGraph(MethodDescriptor md) {
4285 GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(md);
4286 FlowGraph flowGraph = getFlowGraph(md);
4288 Set<FlowNode> paramFlowNodeSet = flowGraph.getParamFlowNodeSet();
4289 for (Iterator iterator = paramFlowNodeSet.iterator(); iterator.hasNext();) {
4290 FlowNode paramFlowNode = (FlowNode) iterator.next();
4291 System.out.println("paramFlowNode=" + paramFlowNode);
4292 NTuple<Descriptor> paramDescTuple = paramFlowNode.getDescTuple();
4293 NTuple<Location> paramLocTuple = translateToLocTuple(md, paramDescTuple);
4294 GlobalFlowNode paramGlobalNode = globalFlowGraph.getFlowNode(paramLocTuple);
4296 Set<GlobalFlowNode> incomingNodeSet =
4297 globalFlowGraph.getIncomingNodeSetByPrefix(paramLocTuple.get(0));
4299 if (incomingNodeSet.size() > 0) {
4300 paramGlobalNode.setParamNodeWithIncomingFlows(true);
4306 private Set<MethodInvokeNode> getMethodInvokeNodeSet(MethodDescriptor md) {
4307 if (!mapMethodDescriptorToMethodInvokeNodeSet.containsKey(md)) {
4308 mapMethodDescriptorToMethodInvokeNodeSet.put(md, new HashSet<MethodInvokeNode>());
4310 return mapMethodDescriptorToMethodInvokeNodeSet.get(md);
4313 private void propagateFlowsFromCalleesWithNoCompositeLocation(MethodDescriptor mdCaller) {
4315 // the transformation for a call site propagates flows through parameters
4316 // if the method is virtual, it also grab all relations from any possible
4319 Set<MethodInvokeNode> setMethodInvokeNode =
4320 mapMethodDescriptorToMethodInvokeNodeSet.get(mdCaller);
4322 if (setMethodInvokeNode != null) {
4324 for (Iterator iterator = setMethodInvokeNode.iterator(); iterator.hasNext();) {
4325 MethodInvokeNode min = (MethodInvokeNode) iterator.next();
4326 MethodDescriptor mdCallee = min.getMethod();
4327 Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
4328 if (mdCallee.isStatic()) {
4329 setPossibleCallees.add(mdCallee);
4331 Set<MethodDescriptor> calleeSet = ssjava.getCallGraph().getMethods(mdCallee);
4332 // removes method descriptors that are not invoked by the caller
4333 calleeSet.retainAll(mapMethodToCalleeSet.get(mdCaller));
4334 setPossibleCallees.addAll(calleeSet);
4337 for (Iterator iterator2 = setPossibleCallees.iterator(); iterator2.hasNext();) {
4338 MethodDescriptor possibleMdCallee = (MethodDescriptor) iterator2.next();
4339 propagateFlowsToCallerWithNoCompositeLocation(min, mdCaller, possibleMdCallee);
4347 private void analyzeMethodBody(ClassDescriptor cd, MethodDescriptor md) {
4348 BlockNode bn = state.getMethodBody(md);
4349 NodeTupleSet implicitFlowTupleSet = new NodeTupleSet();
4350 analyzeFlowBlockNode(md, md.getParameterTable(), bn, implicitFlowTupleSet);
4353 private void analyzeFlowBlockNode(MethodDescriptor md, SymbolTable nametable, BlockNode bn,
4354 NodeTupleSet implicitFlowTupleSet) {
4356 bn.getVarTable().setParent(nametable);
4357 for (int i = 0; i < bn.size(); i++) {
4358 BlockStatementNode bsn = bn.get(i);
4359 analyzeBlockStatementNode(md, bn.getVarTable(), bsn, implicitFlowTupleSet);
4364 private void analyzeBlockStatementNode(MethodDescriptor md, SymbolTable nametable,
4365 BlockStatementNode bsn, NodeTupleSet implicitFlowTupleSet) {
4367 switch (bsn.kind()) {
4368 case Kind.BlockExpressionNode:
4369 analyzeBlockExpressionNode(md, nametable, (BlockExpressionNode) bsn, implicitFlowTupleSet);
4372 case Kind.DeclarationNode:
4373 analyzeFlowDeclarationNode(md, nametable, (DeclarationNode) bsn, implicitFlowTupleSet);
4376 case Kind.IfStatementNode:
4377 analyzeFlowIfStatementNode(md, nametable, (IfStatementNode) bsn, implicitFlowTupleSet);
4381 analyzeFlowLoopNode(md, nametable, (LoopNode) bsn, implicitFlowTupleSet);
4384 case Kind.ReturnNode:
4385 analyzeFlowReturnNode(md, nametable, (ReturnNode) bsn, implicitFlowTupleSet);
4388 case Kind.SubBlockNode:
4389 analyzeFlowSubBlockNode(md, nametable, (SubBlockNode) bsn, implicitFlowTupleSet);
4392 case Kind.ContinueBreakNode:
4395 case Kind.SwitchStatementNode:
4396 analyzeSwitchStatementNode(md, nametable, (SwitchStatementNode) bsn, implicitFlowTupleSet);
4403 private void analyzeSwitchBlockNode(MethodDescriptor md, SymbolTable nametable,
4404 SwitchBlockNode sbn, NodeTupleSet implicitFlowTupleSet) {
4406 analyzeFlowBlockNode(md, nametable, sbn.getSwitchBlockStatement(), implicitFlowTupleSet);
4410 private void analyzeSwitchStatementNode(MethodDescriptor md, SymbolTable nametable,
4411 SwitchStatementNode ssn, NodeTupleSet implicitFlowTupleSet) {
4413 NodeTupleSet condTupleNode = new NodeTupleSet();
4414 analyzeFlowExpressionNode(md, nametable, ssn.getCondition(), condTupleNode, null,
4415 implicitFlowTupleSet, false);
4417 NodeTupleSet newImplicitTupleSet = new NodeTupleSet();
4419 newImplicitTupleSet.addTupleSet(implicitFlowTupleSet);
4420 newImplicitTupleSet.addTupleSet(condTupleNode);
4422 if (needToGenerateInterLoc(newImplicitTupleSet)) {
4423 // need to create an intermediate node for the GLB of conditional
4424 // locations & implicit flows
4425 System.out.println("10");
4427 NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
4428 for (Iterator<NTuple<Descriptor>> idxIter = newImplicitTupleSet.iterator(); idxIter.hasNext();) {
4429 NTuple<Descriptor> tuple = idxIter.next();
4430 addFlowGraphEdge(md, tuple, interTuple);
4432 newImplicitTupleSet.clear();
4433 newImplicitTupleSet.addTuple(interTuple);
4436 BlockNode sbn = ssn.getSwitchBody();
4437 for (int i = 0; i < sbn.size(); i++) {
4438 analyzeSwitchBlockNode(md, nametable, (SwitchBlockNode) sbn.get(i), newImplicitTupleSet);
4443 private void analyzeFlowSubBlockNode(MethodDescriptor md, SymbolTable nametable,
4444 SubBlockNode sbn, NodeTupleSet implicitFlowTupleSet) {
4445 analyzeFlowBlockNode(md, nametable, sbn.getBlockNode(), implicitFlowTupleSet);
4448 private void analyzeFlowReturnNode(MethodDescriptor md, SymbolTable nametable, ReturnNode rn,
4449 NodeTupleSet implicitFlowTupleSet) {
4451 // System.out.println("-analyzeFlowReturnNode=" + rn.printNode(0));
4452 ExpressionNode returnExp = rn.getReturnExpression();
4454 if (returnExp != null) {
4455 NodeTupleSet nodeSet = new NodeTupleSet();
4456 // if a return expression returns a literal value, nodeSet is empty
4457 analyzeFlowExpressionNode(md, nametable, returnExp, nodeSet, false);
4458 FlowGraph fg = getFlowGraph(md);
4460 // if (implicitFlowTupleSet.size() == 1
4462 // fg.getFlowNode(implicitFlowTupleSet.iterator().next()).isIntermediate())
4465 // // since there is already an intermediate node for the GLB of implicit
4467 // // we don't need to create another intermediate node.
4468 // // just re-use the intermediate node for implicit flows.
4470 // FlowNode meetNode =
4471 // fg.getFlowNode(implicitFlowTupleSet.iterator().next());
4473 // for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
4474 // NTuple<Descriptor> returnNodeTuple = (NTuple<Descriptor>)
4476 // fg.addValueFlowEdge(returnNodeTuple, meetNode.getDescTuple());
4481 NodeTupleSet currentFlowTupleSet = new NodeTupleSet();
4483 // add tuples from return node
4484 currentFlowTupleSet.addTupleSet(nodeSet);
4486 // add tuples corresponding to the current implicit flows
4487 currentFlowTupleSet.addTupleSet(implicitFlowTupleSet);
4489 // System.out.println("---currentFlowTupleSet=" + currentFlowTupleSet);
4491 if (needToGenerateInterLoc(currentFlowTupleSet)) {
4492 System.out.println("9");
4494 FlowNode meetNode = fg.createIntermediateNode();
4495 for (Iterator iterator = currentFlowTupleSet.iterator(); iterator.hasNext();) {
4496 NTuple<Descriptor> currentFlowTuple = (NTuple<Descriptor>) iterator.next();
4497 fg.addValueFlowEdge(currentFlowTuple, meetNode.getDescTuple());
4499 fg.addReturnFlowNode(meetNode.getDescTuple());
4501 // currentFlowTupleSet = removeLiteralTuple(currentFlowTupleSet);
4502 for (Iterator iterator = currentFlowTupleSet.iterator(); iterator.hasNext();) {
4503 NTuple<Descriptor> currentFlowTuple = (NTuple<Descriptor>) iterator.next();
4504 fg.addReturnFlowNode(currentFlowTuple);
4512 private NodeTupleSet removeLiteralTuple(NodeTupleSet inSet) {
4513 NodeTupleSet tupleSet = new NodeTupleSet();
4514 for (Iterator<NTuple<Descriptor>> iter = inSet.iterator(); iter.hasNext();) {
4515 NTuple<Descriptor> tuple = iter.next();
4516 if (!tuple.get(0).equals(LITERALDESC)) {
4517 tupleSet.addTuple(tuple);
4523 private boolean needToGenerateInterLoc(NodeTupleSet tupleSet) {
4525 for (Iterator<NTuple<Descriptor>> iter = tupleSet.iterator(); iter.hasNext();) {
4526 NTuple<Descriptor> descTuple = iter.next();
4527 if (!descTuple.get(0).equals(LITERALDESC)) {
4532 System.out.println("needToGenerateInterLoc=" + tupleSet + " size=" + size);
4539 private void analyzeFlowLoopNode(MethodDescriptor md, SymbolTable nametable, LoopNode ln,
4540 NodeTupleSet implicitFlowTupleSet) {
4542 if (ln.getType() == LoopNode.WHILELOOP || ln.getType() == LoopNode.DOWHILELOOP) {
4544 NodeTupleSet condTupleNode = new NodeTupleSet();
4545 analyzeFlowExpressionNode(md, nametable, ln.getCondition(), condTupleNode, null,
4546 implicitFlowTupleSet, false);
4548 NodeTupleSet newImplicitTupleSet = new NodeTupleSet();
4550 newImplicitTupleSet.addTupleSet(implicitFlowTupleSet);
4551 newImplicitTupleSet.addTupleSet(condTupleNode);
4553 newImplicitTupleSet.addGlobalFlowTupleSet(implicitFlowTupleSet.getGlobalLocTupleSet());
4554 newImplicitTupleSet.addGlobalFlowTupleSet(condTupleNode.getGlobalLocTupleSet());
4556 if (needToGenerateInterLoc(newImplicitTupleSet)) {
4557 // need to create an intermediate node for the GLB of conditional
4558 // locations & implicit flows
4559 System.out.println("6");
4561 NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
4562 for (Iterator<NTuple<Descriptor>> idxIter = newImplicitTupleSet.iterator(); idxIter
4564 NTuple<Descriptor> tuple = idxIter.next();
4565 addFlowGraphEdge(md, tuple, interTuple);
4567 newImplicitTupleSet.clear();
4568 newImplicitTupleSet.addTuple(interTuple);
4573 // System.out.println("condTupleNode="+condTupleNode);
4574 // NTuple<Descriptor> interTuple =
4575 // getFlowGraph(md).createIntermediateNode().getDescTuple();
4577 // for (Iterator<NTuple<Descriptor>> idxIter = condTupleNode.iterator();
4578 // idxIter.hasNext();) {
4579 // NTuple<Descriptor> tuple = idxIter.next();
4580 // addFlowGraphEdge(md, tuple, interTuple);
4583 // for (Iterator<NTuple<Descriptor>> idxIter =
4584 // implicitFlowTupleSet.iterator(); idxIter
4586 // NTuple<Descriptor> tuple = idxIter.next();
4587 // addFlowGraphEdge(md, tuple, interTuple);
4590 // NodeTupleSet newImplicitSet = new NodeTupleSet();
4591 // newImplicitSet.addTuple(interTuple);
4592 analyzeFlowBlockNode(md, nametable, ln.getBody(), newImplicitTupleSet);
4595 // condTupleNode.addTupleSet(implicitFlowTupleSet);
4597 // add edges from condNodeTupleSet to all nodes of conditional nodes
4598 // analyzeFlowBlockNode(md, nametable, ln.getBody(), condTupleNode);
4601 // check 'for loop' case
4602 BlockNode bn = ln.getInitializer();
4603 bn.getVarTable().setParent(nametable);
4604 for (int i = 0; i < bn.size(); i++) {
4605 BlockStatementNode bsn = bn.get(i);
4606 analyzeBlockStatementNode(md, bn.getVarTable(), bsn, implicitFlowTupleSet);
4609 NodeTupleSet condTupleNode = new NodeTupleSet();
4610 analyzeFlowExpressionNode(md, bn.getVarTable(), ln.getCondition(), condTupleNode, null,
4611 implicitFlowTupleSet, false);
4613 NodeTupleSet newImplicitTupleSet = new NodeTupleSet();
4614 newImplicitTupleSet.addTupleSet(implicitFlowTupleSet);
4615 newImplicitTupleSet.addTupleSet(condTupleNode);
4617 if (needToGenerateInterLoc(newImplicitTupleSet)) {
4618 // need to create an intermediate node for the GLB of conditional
4619 // locations & implicit flows
4620 System.out.println("7");
4622 NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
4623 for (Iterator<NTuple<Descriptor>> idxIter = newImplicitTupleSet.iterator(); idxIter
4625 NTuple<Descriptor> tuple = idxIter.next();
4626 addFlowGraphEdge(md, tuple, interTuple);
4628 newImplicitTupleSet.clear();
4629 newImplicitTupleSet.addTuple(interTuple);
4634 // NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
4636 // for (Iterator<NTuple<Descriptor>> idxIter = condTupleNode.iterator(); idxIter.hasNext();) {
4637 // NTuple<Descriptor> tuple = idxIter.next();
4638 // addFlowGraphEdge(md, tuple, interTuple);
4641 // for (Iterator<NTuple<Descriptor>> idxIter = implicitFlowTupleSet.iterator(); idxIter
4643 // NTuple<Descriptor> tuple = idxIter.next();
4644 // addFlowGraphEdge(md, tuple, interTuple);
4647 // NodeTupleSet newImplicitSet = new NodeTupleSet();
4648 // newImplicitSet.addTuple(interTuple);
4649 analyzeFlowBlockNode(md, bn.getVarTable(), ln.getUpdate(), newImplicitTupleSet);
4650 analyzeFlowBlockNode(md, bn.getVarTable(), ln.getBody(), newImplicitTupleSet);
4653 // condTupleNode.addTupleSet(implicitFlowTupleSet);
4655 // analyzeFlowBlockNode(md, bn.getVarTable(), ln.getUpdate(),
4657 // analyzeFlowBlockNode(md, bn.getVarTable(), ln.getBody(),
4664 private void analyzeFlowIfStatementNode(MethodDescriptor md, SymbolTable nametable,
4665 IfStatementNode isn, NodeTupleSet implicitFlowTupleSet) {
4667 // System.out.println("analyzeFlowIfStatementNode=" + isn.printNode(0));
4669 NodeTupleSet condTupleNode = new NodeTupleSet();
4670 analyzeFlowExpressionNode(md, nametable, isn.getCondition(), condTupleNode, null,
4671 implicitFlowTupleSet, false);
4673 NodeTupleSet newImplicitTupleSet = new NodeTupleSet();
4675 newImplicitTupleSet.addTupleSet(implicitFlowTupleSet);
4676 newImplicitTupleSet.addTupleSet(condTupleNode);
4678 // System.out.println("$$$GGGcondTupleNode=" + condTupleNode.getGlobalLocTupleSet());
4679 // System.out.println("-condTupleNode=" + condTupleNode);
4680 // System.out.println("-implicitFlowTupleSet=" + implicitFlowTupleSet);
4681 // System.out.println("-newImplicitTupleSet=" + newImplicitTupleSet);
4683 if (needToGenerateInterLoc(newImplicitTupleSet)) {
4684 System.out.println("5");
4686 // need to create an intermediate node for the GLB of conditional locations & implicit flows
4687 NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
4688 for (Iterator<NTuple<Descriptor>> idxIter = newImplicitTupleSet.iterator(); idxIter.hasNext();) {
4689 NTuple<Descriptor> tuple = idxIter.next();
4690 addFlowGraphEdge(md, tuple, interTuple);
4692 newImplicitTupleSet.clear();
4693 newImplicitTupleSet.addTuple(interTuple);
4696 // GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(md);
4697 // for (Iterator<NTuple<Location>> iterator = condTupleNode.globalIterator();
4698 // iterator.hasNext();) {
4699 // NTuple<Location> calleeReturnLocTuple = iterator.next();
4700 // for (Iterator<NTuple<Descriptor>> iter2 = newImplicitTupleSet.iterator(); iter2.hasNext();) {
4701 // NTuple<Descriptor> callerImplicitTuple = iter2.next();
4702 // globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
4703 // translateToLocTuple(md, callerImplicitTuple));
4706 newImplicitTupleSet.addGlobalFlowTupleSet(condTupleNode.getGlobalLocTupleSet());
4708 analyzeFlowBlockNode(md, nametable, isn.getTrueBlock(), newImplicitTupleSet);
4710 if (isn.getFalseBlock() != null) {
4711 analyzeFlowBlockNode(md, nametable, isn.getFalseBlock(), newImplicitTupleSet);
4716 private void analyzeFlowDeclarationNode(MethodDescriptor md, SymbolTable nametable,
4717 DeclarationNode dn, NodeTupleSet implicitFlowTupleSet) {
4719 VarDescriptor vd = dn.getVarDescriptor();
4720 mapDescToDefinitionLine.put(vd, dn.getNumLine());
4721 NTuple<Descriptor> tupleLHS = new NTuple<Descriptor>();
4723 FlowNode fn = getFlowGraph(md).createNewFlowNode(tupleLHS);
4724 fn.setDeclarationNode();
4726 if (dn.getExpression() != null) {
4727 System.out.println("-analyzeFlowDeclarationNode=" + dn.printNode(0));
4729 NodeTupleSet nodeSetRHS = new NodeTupleSet();
4730 analyzeFlowExpressionNode(md, nametable, dn.getExpression(), nodeSetRHS, null,
4731 implicitFlowTupleSet, false);
4733 // creates edges from RHS to LHS
4734 NTuple<Descriptor> interTuple = null;
4735 if (needToGenerateInterLoc(nodeSetRHS)) {
4736 System.out.println("3");
4737 interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
4740 for (Iterator<NTuple<Descriptor>> iter = nodeSetRHS.iterator(); iter.hasNext();) {
4741 NTuple<Descriptor> fromTuple = iter.next();
4742 System.out.println("fromTuple=" + fromTuple + " interTuple=" + interTuple + " tupleLSH="
4744 addFlowGraphEdge(md, fromTuple, interTuple, tupleLHS);
4747 // creates edges from implicitFlowTupleSet to LHS
4748 for (Iterator<NTuple<Descriptor>> iter = implicitFlowTupleSet.iterator(); iter.hasNext();) {
4749 NTuple<Descriptor> implicitTuple = iter.next();
4750 addFlowGraphEdge(md, implicitTuple, tupleLHS);
4753 GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(md);
4754 for (Iterator<NTuple<Location>> iterator = nodeSetRHS.globalIterator(); iterator.hasNext();) {
4755 NTuple<Location> calleeReturnLocTuple = iterator.next();
4757 globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, translateToLocTuple(md, tupleLHS));
4760 for (Iterator<NTuple<Location>> iterator = implicitFlowTupleSet.globalIterator(); iterator
4762 NTuple<Location> implicitGlobalTuple = iterator.next();
4764 globalFlowGraph.addValueFlowEdge(implicitGlobalTuple, translateToLocTuple(md, tupleLHS));
4767 System.out.println("-nodeSetRHS=" + nodeSetRHS);
4768 System.out.println("-implicitFlowTupleSet=" + implicitFlowTupleSet);
4774 private void analyzeBlockExpressionNode(MethodDescriptor md, SymbolTable nametable,
4775 BlockExpressionNode ben, NodeTupleSet implicitFlowTupleSet) {
4776 analyzeFlowExpressionNode(md, nametable, ben.getExpression(), null, null, implicitFlowTupleSet,
4780 private NTuple<Descriptor> analyzeFlowExpressionNode(MethodDescriptor md, SymbolTable nametable,
4781 ExpressionNode en, NodeTupleSet nodeSet, boolean isLHS) {
4782 return analyzeFlowExpressionNode(md, nametable, en, nodeSet, null, new NodeTupleSet(), isLHS);
4785 private NTuple<Descriptor> analyzeFlowExpressionNode(MethodDescriptor md, SymbolTable nametable,
4786 ExpressionNode en, NodeTupleSet nodeSet, NTuple<Descriptor> base,
4787 NodeTupleSet implicitFlowTupleSet, boolean isLHS) {
4789 // System.out.println("en=" + en.printNode(0) + " class=" + en.getClass());
4791 // note that expression node can create more than one flow node
4792 // nodeSet contains of flow nodes
4793 // base is always assigned to null except the case of a name node!
4794 NTuple<Descriptor> flowTuple;
4795 switch (en.kind()) {
4796 case Kind.AssignmentNode:
4797 analyzeFlowAssignmentNode(md, nametable, (AssignmentNode) en, nodeSet, base,
4798 implicitFlowTupleSet);
4801 case Kind.FieldAccessNode:
4803 analyzeFlowFieldAccessNode(md, nametable, (FieldAccessNode) en, nodeSet, base,
4804 implicitFlowTupleSet, isLHS);
4805 if (flowTuple != null) {
4806 nodeSet.addTuple(flowTuple);
4811 NodeTupleSet nameNodeSet = new NodeTupleSet();
4813 analyzeFlowNameNode(md, nametable, (NameNode) en, nameNodeSet, base, implicitFlowTupleSet);
4814 if (flowTuple != null) {
4815 nodeSet.addTuple(flowTuple);
4820 analyzeFlowOpNode(md, nametable, (OpNode) en, nodeSet, implicitFlowTupleSet);
4823 case Kind.CreateObjectNode:
4824 analyzeCreateObjectNode(md, nametable, (CreateObjectNode) en);
4827 case Kind.ArrayAccessNode:
4828 analyzeFlowArrayAccessNode(md, nametable, (ArrayAccessNode) en, nodeSet, isLHS);
4831 case Kind.LiteralNode:
4832 analyzeFlowLiteralNode(md, nametable, (LiteralNode) en, nodeSet);
4835 case Kind.MethodInvokeNode:
4836 analyzeFlowMethodInvokeNode(md, nametable, (MethodInvokeNode) en, nodeSet,
4837 implicitFlowTupleSet);
4840 case Kind.TertiaryNode:
4841 analyzeFlowTertiaryNode(md, nametable, (TertiaryNode) en, nodeSet, implicitFlowTupleSet);
4845 analyzeFlowCastNode(md, nametable, (CastNode) en, nodeSet, base, implicitFlowTupleSet);
4847 // case Kind.InstanceOfNode:
4848 // checkInstanceOfNode(md, nametable, (InstanceOfNode) en, td);
4851 // case Kind.ArrayInitializerNode:
4852 // checkArrayInitializerNode(md, nametable, (ArrayInitializerNode) en,
4856 // case Kind.ClassTypeNode:
4857 // checkClassTypeNode(md, nametable, (ClassTypeNode) en, td);
4860 // case Kind.OffsetNode:
4861 // checkOffsetNode(md, nametable, (OffsetNode)en, td);
4870 private void analyzeFlowCastNode(MethodDescriptor md, SymbolTable nametable, CastNode cn,
4871 NodeTupleSet nodeSet, NTuple<Descriptor> base, NodeTupleSet implicitFlowTupleSet) {
4873 analyzeFlowExpressionNode(md, nametable, cn.getExpression(), nodeSet, base,
4874 implicitFlowTupleSet, false);
4878 private void analyzeFlowTertiaryNode(MethodDescriptor md, SymbolTable nametable, TertiaryNode tn,
4879 NodeTupleSet nodeSet, NodeTupleSet implicitFlowTupleSet) {
4881 // System.out.println("analyzeFlowTertiaryNode=" + tn.printNode(0));
4883 NodeTupleSet tertiaryTupleNode = new NodeTupleSet();
4884 analyzeFlowExpressionNode(md, nametable, tn.getCond(), tertiaryTupleNode, null,
4885 implicitFlowTupleSet, false);
4887 NodeTupleSet newImplicitTupleSet = new NodeTupleSet();
4888 newImplicitTupleSet.addTupleSet(implicitFlowTupleSet);
4889 newImplicitTupleSet.addTupleSet(tertiaryTupleNode);
4891 // System.out.println("$$$GGGcondTupleNode=" + tertiaryTupleNode.getGlobalLocTupleSet());
4892 // System.out.println("-tertiaryTupleNode=" + tertiaryTupleNode);
4893 // System.out.println("-implicitFlowTupleSet=" + implicitFlowTupleSet);
4894 // System.out.println("-newImplicitTupleSet=" + newImplicitTupleSet);
4896 if (needToGenerateInterLoc(newImplicitTupleSet)) {
4897 System.out.println("15");
4898 // need to create an intermediate node for the GLB of conditional locations & implicit flows
4899 NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
4900 for (Iterator<NTuple<Descriptor>> idxIter = newImplicitTupleSet.iterator(); idxIter.hasNext();) {
4901 NTuple<Descriptor> tuple = idxIter.next();
4902 addFlowGraphEdge(md, tuple, interTuple);
4904 newImplicitTupleSet.clear();
4905 newImplicitTupleSet.addTuple(interTuple);
4908 newImplicitTupleSet.addGlobalFlowTupleSet(tertiaryTupleNode.getGlobalLocTupleSet());
4910 System.out.println("---------newImplicitTupleSet=" + newImplicitTupleSet);
4911 // add edges from tertiaryTupleNode to all nodes of conditional nodes
4912 // tertiaryTupleNode.addTupleSet(implicitFlowTupleSet);
4913 analyzeFlowExpressionNode(md, nametable, tn.getTrueExpr(), tertiaryTupleNode, null,
4914 newImplicitTupleSet, false);
4916 analyzeFlowExpressionNode(md, nametable, tn.getFalseExpr(), tertiaryTupleNode, null,
4917 newImplicitTupleSet, false);
4919 nodeSet.addGlobalFlowTupleSet(tertiaryTupleNode.getGlobalLocTupleSet());
4920 nodeSet.addTupleSet(tertiaryTupleNode);
4922 System.out.println("#tertiary node set=" + nodeSet);
4925 private void addMapCallerMethodDescToMethodInvokeNodeSet(MethodDescriptor caller,
4926 MethodInvokeNode min) {
4927 Set<MethodInvokeNode> set = mapMethodDescriptorToMethodInvokeNodeSet.get(caller);
4929 set = new HashSet<MethodInvokeNode>();
4930 mapMethodDescriptorToMethodInvokeNodeSet.put(caller, set);
4935 private void addParamNodeFlowingToReturnValue(MethodDescriptor md, FlowNode fn) {
4937 if (!mapMethodDescToParamNodeFlowsToReturnValue.containsKey(md)) {
4938 mapMethodDescToParamNodeFlowsToReturnValue.put(md, new HashSet<FlowNode>());
4940 mapMethodDescToParamNodeFlowsToReturnValue.get(md).add(fn);
4943 private Set<FlowNode> getParamNodeFlowingToReturnValue(MethodDescriptor md) {
4945 if (!mapMethodDescToParamNodeFlowsToReturnValue.containsKey(md)) {
4946 mapMethodDescToParamNodeFlowsToReturnValue.put(md, new HashSet<FlowNode>());
4949 return mapMethodDescToParamNodeFlowsToReturnValue.get(md);
4952 private Set<NTuple<Location>> getPCLocTupleSet(MethodInvokeNode min) {
4953 if (!mapMethodInvokeNodeToPCLocTupleSet.containsKey(min)) {
4954 mapMethodInvokeNodeToPCLocTupleSet.put(min, new HashSet<NTuple<Location>>());
4956 return mapMethodInvokeNodeToPCLocTupleSet.get(min);
4959 private void analyzeFlowMethodInvokeNode(MethodDescriptor mdCaller, SymbolTable nametable,
4960 MethodInvokeNode min, NodeTupleSet nodeSet, NodeTupleSet implicitFlowTupleSet) {
4962 System.out.println("analyzeFlowMethodInvokeNode=" + min.printNode(0));
4964 if (!toanalyze_methodDescList.contains(min.getMethod())) {
4968 addMapMethodDescToMethodInvokeNodeSet(min);
4970 Set<NTuple<Location>> pcLocTupleSet = getPCLocTupleSet(min);
4971 for (Iterator iterator = implicitFlowTupleSet.iterator(); iterator.hasNext();) {
4972 NTuple<Descriptor> pcDescTuple = (NTuple<Descriptor>) iterator.next();
4973 if (!pcDescTuple.get(0).equals(LITERALDESC)) {
4974 // here we don't need to add the literal value as a PC location
4975 pcLocTupleSet.add(translateToLocTuple(mdCaller, pcDescTuple));
4979 mapMethodInvokeNodeToArgIdxMap.put(min, new HashMap<Integer, NTuple<Descriptor>>());
4981 if (nodeSet == null) {
4982 nodeSet = new NodeTupleSet();
4985 MethodDescriptor mdCallee = min.getMethod();
4987 NameDescriptor baseName = min.getBaseName();
4988 boolean isSystemout = false;
4989 if (baseName != null) {
4990 isSystemout = baseName.getSymbol().equals("System.out");
4993 if (!ssjava.isSSJavaUtil(mdCallee.getClassDesc()) && !ssjava.isTrustMethod(mdCallee)
4996 addMapCallerMethodDescToMethodInvokeNodeSet(mdCaller, min);
4998 FlowGraph calleeFlowGraph = getFlowGraph(mdCallee);
4999 System.out.println("mdCallee=" + mdCallee + " calleeFlowGraph=" + calleeFlowGraph);
5000 Set<FlowNode> calleeReturnSet = calleeFlowGraph.getReturnNodeSet();
5002 System.out.println("---calleeReturnSet=" + calleeReturnSet);
5004 NodeTupleSet tupleSet = new NodeTupleSet();
5006 if (min.getExpression() != null) {
5008 NodeTupleSet baseNodeSet = new NodeTupleSet();
5009 analyzeFlowExpressionNode(mdCaller, nametable, min.getExpression(), baseNodeSet, null,
5010 implicitFlowTupleSet, false);
5011 System.out.println("baseNodeSet=" + baseNodeSet);
5013 assert (baseNodeSet.size() == 1);
5014 NTuple<Descriptor> baseTuple = baseNodeSet.iterator().next();
5015 if (baseTuple.get(0) instanceof InterDescriptor) {
5016 if (baseTuple.size() > 1) {
5019 FlowNode interNode = getFlowGraph(mdCaller).getFlowNode(baseTuple);
5020 baseTuple = translateBaseTuple(interNode, baseTuple);
5022 mapMethodInvokeNodeToBaseTuple.put(min, baseTuple);
5024 if (!min.getMethod().isStatic()) {
5025 addArgIdxMap(min, 0, baseTuple);
5027 for (Iterator iterator = calleeReturnSet.iterator(); iterator.hasNext();) {
5028 FlowNode returnNode = (FlowNode) iterator.next();
5029 NTuple<Descriptor> returnDescTuple = returnNode.getDescTuple();
5030 if (returnDescTuple.startsWith(mdCallee.getThis())) {
5031 // the location type of the return value is started with 'this'
5033 NTuple<Descriptor> inFlowTuple = new NTuple<Descriptor>(baseTuple.getList());
5035 if (inFlowTuple.get(0) instanceof InterDescriptor) {
5036 // min.getExpression()
5041 inFlowTuple.addAll(returnDescTuple.subList(1, returnDescTuple.size()));
5042 // nodeSet.addTuple(inFlowTuple);
5043 System.out.println("1CREATE A NEW TUPLE=" + inFlowTuple + " from="
5044 + mdCallee.getThis());
5045 // tupleSet.addTuple(inFlowTuple);
5046 tupleSet.addTuple(baseTuple);
5049 System.out.println("returnNode=" + returnNode);
5050 Set<FlowNode> inFlowSet = calleeFlowGraph.getIncomingFlowNodeSet(returnNode);
5051 // System.out.println("inFlowSet=" + inFlowSet + " from retrunNode=" + returnNode);
5052 for (Iterator iterator2 = inFlowSet.iterator(); iterator2.hasNext();) {
5053 FlowNode inFlowNode = (FlowNode) iterator2.next();
5054 if (inFlowNode.getDescTuple().startsWith(mdCallee.getThis())) {
5055 // nodeSet.addTupleSet(baseNodeSet);
5056 System.out.println("2CREATE A NEW TUPLE=" + baseNodeSet + " from="
5057 + mdCallee.getThis());
5058 tupleSet.addTupleSet(baseNodeSet);
5066 // analyze parameter flows
5068 if (min.numArgs() > 0) {
5071 if (min.getMethod().isStatic()) {
5077 for (int i = 0; i < min.numArgs(); i++) {
5078 ExpressionNode en = min.getArg(i);
5079 int idx = i + offset;
5080 NodeTupleSet argTupleSet = new NodeTupleSet();
5081 analyzeFlowExpressionNode(mdCaller, nametable, en, argTupleSet, false);
5082 // if argument is liternal node, argTuple is set to NULL
5083 System.out.println("---arg idx=" + idx + " argTupleSet=" + argTupleSet);
5084 NTuple<Descriptor> argTuple = generateArgTuple(mdCaller, argTupleSet);
5086 // if an argument is literal value,
5087 // we need to create an itermediate node so that we could assign a composite location to
5088 // that node if needed
5089 if (argTuple.size() > 0
5090 && (argTuple.get(0).equals(GLOBALDESC) || argTuple.get(0).equals(LITERALDESC))) {
5092 * System.out.println("***GLOBAL ARG TUPLE CASE=" + argTuple); System.out.println("8");
5094 * NTuple<Descriptor> interTuple =
5095 * getFlowGraph(mdCaller).createIntermediateNode().getDescTuple(); ((InterDescriptor)
5096 * interTuple.get(0)).setMethodArgIdxPair(min, idx); addFlowGraphEdge(mdCaller,
5097 * argTuple, interTuple); argTuple = interTuple; addArgIdxMap(min, idx, argTuple);
5098 * System.out.println("new min mapping i=" + idx + " ->" + argTuple);
5100 argTuple = new NTuple<Descriptor>();
5103 addArgIdxMap(min, idx, argTuple);
5105 FlowNode paramNode = calleeFlowGraph.getParamFlowNode(idx);
5107 // check whether a param node in the callee graph has incoming flows
5108 // if it has incoming flows, the corresponding arg should be lower than the current PC
5109 // Descriptor prefix = paramNode.getDescTuple().get(0);
5110 // if (calleeFlowGraph.getIncomingNodeSetByPrefix(prefix).size() > 0) {
5111 // for (Iterator<NTuple<Descriptor>> iterator = implicitFlowTupleSet.iterator(); iterator
5113 // NTuple<Descriptor> pcTuple = iterator.next();
5114 // System.out.println("add edge pcTuple =" + pcTuple + " -> " + argTuple);
5115 // addFlowGraphEdge(md, pcTuple, argTuple);
5119 System.out.println("paramNode=" + paramNode + " calleeReturnSet=" + calleeReturnSet);
5120 if (hasInFlowTo(calleeFlowGraph, paramNode, calleeReturnSet)
5121 || mdCallee.getModifiers().isNative()) {
5122 addParamNodeFlowingToReturnValue(mdCallee, paramNode);
5123 // nodeSet.addTupleSet(argTupleSet);
5124 System.out.println("3CREATE A NEW TUPLE=" + argTupleSet + " from=" + paramNode);
5125 tupleSet.addTupleSet(argTupleSet);
5131 if (mdCallee.getReturnType() != null && !mdCallee.getReturnType().isVoid()) {
5132 FlowReturnNode returnHolderNode = getFlowGraph(mdCaller).createReturnNode(min);
5134 if (needToGenerateInterLoc(tupleSet)) {
5135 System.out.println("20");
5136 FlowGraph fg = getFlowGraph(mdCaller);
5137 FlowNode interNode = fg.createIntermediateNode();
5138 interNode.setFormHolder(true);
5140 NTuple<Descriptor> interTuple = interNode.getDescTuple();
5142 for (Iterator iterator = tupleSet.iterator(); iterator.hasNext();) {
5143 NTuple<Descriptor> tuple = (NTuple<Descriptor>) iterator.next();
5145 Set<NTuple<Descriptor>> addSet = new HashSet<NTuple<Descriptor>>();
5146 FlowNode node = fg.getFlowNode(tuple);
5147 if (node instanceof FlowReturnNode) {
5148 addSet.addAll(fg.getReturnTupleSet(((FlowReturnNode) node).getReturnTupleSet()));
5152 for (Iterator iterator2 = addSet.iterator(); iterator2.hasNext();) {
5153 NTuple<Descriptor> higher = (NTuple<Descriptor>) iterator2.next();
5154 addFlowGraphEdge(mdCaller, higher, interTuple);
5158 returnHolderNode.addTuple(interTuple);
5160 nodeSet.addTuple(interTuple);
5161 System.out.println("ADD TUPLESET=" + interTuple + " to returnnode=" + returnHolderNode);
5164 returnHolderNode.addTupleSet(tupleSet);
5165 System.out.println("ADD TUPLESET=" + tupleSet + " to returnnode=" + returnHolderNode);
5167 // setNode.addTupleSet(tupleSet);
5168 // NodeTupleSet setFromReturnNode=new NodeTupleSet();
5169 // setFromReturnNode.addTuple(tuple);
5171 NodeTupleSet holderTupleSet =
5172 getNodeTupleSetFromReturnNode(getFlowGraph(mdCaller), returnHolderNode);
5174 System.out.println("HOLDER TUPLe SET=" + holderTupleSet);
5175 nodeSet.addTupleSet(holderTupleSet);
5177 nodeSet.addTuple(returnHolderNode.getDescTuple());
5180 // propagateFlowsFromCallee(min, md, min.getMethod());
5182 // when generating the global flow graph,
5183 // we need to add ordering relations from the set of callee return loc tuple to LHS of the
5184 // caller assignment
5185 for (Iterator iterator = calleeReturnSet.iterator(); iterator.hasNext();) {
5186 FlowNode calleeReturnNode = (FlowNode) iterator.next();
5187 NTuple<Location> calleeReturnLocTuple =
5188 translateToLocTuple(mdCallee, calleeReturnNode.getDescTuple());
5189 System.out.println("calleeReturnLocTuple=" + calleeReturnLocTuple);
5190 NTuple<Location> transaltedToCaller =
5191 translateToCallerLocTuple(min, mdCallee, mdCaller, calleeReturnLocTuple);
5192 // System.out.println("translateToCallerLocTuple="
5193 // + translateToCallerLocTuple(min, mdCallee, mdCaller, calleeReturnLocTuple));
5194 if (transaltedToCaller.size() > 0) {
5195 nodeSet.addGlobalFlowTuple(translateToCallerLocTuple(min, mdCallee, mdCaller,
5196 calleeReturnLocTuple));
5200 System.out.println("min nodeSet=" + nodeSet);
5206 private NodeTupleSet getNodeTupleSetFromReturnNode(FlowGraph fg, FlowReturnNode node) {
5207 NodeTupleSet nts = new NodeTupleSet();
5209 Set<NTuple<Descriptor>> returnSet = node.getReturnTupleSet();
5211 for (Iterator iterator = returnSet.iterator(); iterator.hasNext();) {
5212 NTuple<Descriptor> tuple = (NTuple<Descriptor>) iterator.next();
5213 FlowNode flowNode = fg.getFlowNode(tuple);
5214 if (flowNode instanceof FlowReturnNode) {
5215 returnSet.addAll(recurGetNode(fg, (FlowReturnNode) flowNode));
5217 returnSet.add(tuple);
5221 for (Iterator iterator = returnSet.iterator(); iterator.hasNext();) {
5222 NTuple<Descriptor> nTuple = (NTuple<Descriptor>) iterator.next();
5223 nts.addTuple(nTuple);
5230 private Set<NTuple<Descriptor>> recurGetNode(FlowGraph fg, FlowReturnNode rnode) {
5232 Set<NTuple<Descriptor>> tupleSet = new HashSet<NTuple<Descriptor>>();
5234 Set<NTuple<Descriptor>> returnSet = rnode.getReturnTupleSet();
5235 for (Iterator iterator = returnSet.iterator(); iterator.hasNext();) {
5236 NTuple<Descriptor> tuple = (NTuple<Descriptor>) iterator.next();
5237 FlowNode flowNode = fg.getFlowNode(tuple);
5238 if (flowNode instanceof FlowReturnNode) {
5239 tupleSet.addAll(recurGetNode(fg, (FlowReturnNode) flowNode));
5241 tupleSet.add(tuple);
5247 private NTuple<Descriptor> generateArgTuple(MethodDescriptor mdCaller, NodeTupleSet argTupleSet) {
5251 // if argTupleSet is empty, it comes from the top location
5252 if (argTupleSet.size() == 0) {
5253 NTuple<Descriptor> descTuple = new NTuple<Descriptor>();
5254 descTuple.add(LITERALDESC);
5258 Set<NTuple<Descriptor>> argTupleSetNonLiteral = new HashSet<NTuple<Descriptor>>();
5260 for (Iterator<NTuple<Descriptor>> iter = argTupleSet.iterator(); iter.hasNext();) {
5261 NTuple<Descriptor> descTuple = iter.next();
5262 if (!descTuple.get(0).equals(LITERALDESC)) {
5263 argTupleSetNonLiteral.add(descTuple);
5267 if (argTupleSetNonLiteral.size() > 1) {
5268 System.out.println("11");
5270 NTuple<Descriptor> interTuple =
5271 getFlowGraph(mdCaller).createIntermediateNode().getDescTuple();
5272 for (Iterator<NTuple<Descriptor>> idxIter = argTupleSet.iterator(); idxIter.hasNext();) {
5273 NTuple<Descriptor> tuple = idxIter.next();
5274 addFlowGraphEdge(mdCaller, tuple, interTuple);
5277 } else if (argTupleSetNonLiteral.size() == 1) {
5278 return argTupleSetNonLiteral.iterator().next();
5280 return argTupleSet.iterator().next();
5285 private boolean hasInFlowTo(FlowGraph fg, FlowNode inNode, Set<FlowNode> nodeSet) {
5286 // return true if inNode has in-flows to nodeSet
5288 if (nodeSet.contains(inNode)) {
5289 // in this case, the method directly returns a parameter variable.
5292 // Set<FlowNode> reachableSet = fg.getReachFlowNodeSetFrom(inNode);
5293 Set<FlowNode> reachableSet = fg.getReachableSetFrom(inNode.getDescTuple());
5294 // System.out.println("inNode=" + inNode + " reachalbeSet=" + reachableSet);
5296 for (Iterator iterator = reachableSet.iterator(); iterator.hasNext();) {
5297 FlowNode fn = (FlowNode) iterator.next();
5298 if (nodeSet.contains(fn)) {
5305 private NTuple<Descriptor> getNodeTupleByArgIdx(MethodInvokeNode min, int idx) {
5306 return mapMethodInvokeNodeToArgIdxMap.get(min).get(new Integer(idx));
5309 private void addArgIdxMap(MethodInvokeNode min, int idx, NTuple<Descriptor> argTuple /*
5313 Map<Integer, NTuple<Descriptor>> mapIdxToTuple = mapMethodInvokeNodeToArgIdxMap.get(min);
5314 if (mapIdxToTuple == null) {
5315 mapIdxToTuple = new HashMap<Integer, NTuple<Descriptor>>();
5316 mapMethodInvokeNodeToArgIdxMap.put(min, mapIdxToTuple);
5318 mapIdxToTuple.put(new Integer(idx), argTuple);
5321 private void analyzeFlowLiteralNode(MethodDescriptor md, SymbolTable nametable, LiteralNode en,
5322 NodeTupleSet nodeSet) {
5323 NTuple<Descriptor> tuple = new NTuple<Descriptor>();
5324 tuple.add(LITERALDESC);
5325 nodeSet.addTuple(tuple);
5328 private void analyzeFlowArrayAccessNode(MethodDescriptor md, SymbolTable nametable,
5329 ArrayAccessNode aan, NodeTupleSet nodeSet, boolean isLHS) {
5331 System.out.println("analyzeFlowArrayAccessNode aan=" + aan.printNode(0));
5332 String currentArrayAccessNodeExpStr = aan.printNode(0);
5333 arrayAccessNodeStack.push(aan.printNode(0));
5335 NodeTupleSet expNodeTupleSet = new NodeTupleSet();
5336 NTuple<Descriptor> base =
5337 analyzeFlowExpressionNode(md, nametable, aan.getExpression(), expNodeTupleSet, isLHS);
5338 System.out.println("-base=" + base);
5340 nodeSet.setMethodInvokeBaseDescTuple(base);
5341 NodeTupleSet idxNodeTupleSet = new NodeTupleSet();
5342 analyzeFlowExpressionNode(md, nametable, aan.getIndex(), idxNodeTupleSet, isLHS);
5344 arrayAccessNodeStack.pop();
5347 // need to create an edge from idx to array
5348 for (Iterator<NTuple<Descriptor>> idxIter = idxNodeTupleSet.iterator(); idxIter.hasNext();) {
5349 NTuple<Descriptor> idxTuple = idxIter.next();
5350 for (Iterator<NTuple<Descriptor>> arrIter = expNodeTupleSet.iterator(); arrIter.hasNext();) {
5351 NTuple<Descriptor> arrTuple = arrIter.next();
5352 getFlowGraph(md).addValueFlowEdge(idxTuple, arrTuple);
5356 GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(md);
5357 for (Iterator<NTuple<Location>> iterator = idxNodeTupleSet.globalIterator(); iterator
5359 NTuple<Location> calleeReturnLocTuple = iterator.next();
5360 for (Iterator<NTuple<Descriptor>> arrIter = expNodeTupleSet.iterator(); arrIter.hasNext();) {
5361 NTuple<Descriptor> arrTuple = arrIter.next();
5363 globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, translateToLocTuple(md, arrTuple));
5367 nodeSet.addTupleSet(expNodeTupleSet);
5370 NodeTupleSet nodeSetArrayAccessExp = new NodeTupleSet();
5372 nodeSetArrayAccessExp.addTupleSet(expNodeTupleSet);
5373 nodeSetArrayAccessExp.addTupleSet(idxNodeTupleSet);
5375 if (arrayAccessNodeStack.isEmpty()
5376 || !arrayAccessNodeStack.peek().startsWith(currentArrayAccessNodeExpStr)) {
5378 if (needToGenerateInterLoc(nodeSetArrayAccessExp)) {
5379 System.out.println("1");
5380 FlowNode interNode = getFlowGraph(md).createIntermediateNode();
5381 NTuple<Descriptor> interTuple = interNode.getDescTuple();
5383 for (Iterator<NTuple<Descriptor>> iter = nodeSetArrayAccessExp.iterator(); iter.hasNext();) {
5384 NTuple<Descriptor> higherTuple = iter.next();
5385 addFlowGraphEdge(md, higherTuple, interTuple);
5387 nodeSetArrayAccessExp.clear();
5388 nodeSetArrayAccessExp.addTuple(interTuple);
5389 FlowGraph fg = getFlowGraph(md);
5391 System.out.println("base=" + base);
5393 fg.addMapInterLocNodeToEnclosingDescriptor(interTuple.get(0),
5394 getClassTypeDescriptor(base.get(base.size() - 1)));
5395 interNode.setBaseTuple(base);
5400 nodeSet.addGlobalFlowTupleSet(idxNodeTupleSet.getGlobalLocTupleSet());
5401 nodeSet.addTupleSet(nodeSetArrayAccessExp);
5407 private void analyzeCreateObjectNode(MethodDescriptor md, SymbolTable nametable,
5408 CreateObjectNode en) {
5409 // TODO Auto-generated method stub
5413 private void analyzeFlowOpNode(MethodDescriptor md, SymbolTable nametable, OpNode on,
5414 NodeTupleSet nodeSet, NodeTupleSet implicitFlowTupleSet) {
5416 NodeTupleSet leftOpSet = new NodeTupleSet();
5417 NodeTupleSet rightOpSet = new NodeTupleSet();
5419 System.out.println("analyzeFlowOpNode=" + on.printNode(0));
5422 analyzeFlowExpressionNode(md, nametable, on.getLeft(), leftOpSet, null, implicitFlowTupleSet,
5424 System.out.println("--leftOpSet=" + leftOpSet);
5426 if (on.getRight() != null) {
5428 analyzeFlowExpressionNode(md, nametable, on.getRight(), rightOpSet, null,
5429 implicitFlowTupleSet, false);
5431 System.out.println("--rightOpSet=" + rightOpSet);
5433 Operation op = on.getOp();
5435 switch (op.getOp()) {
5437 case Operation.UNARYPLUS:
5438 case Operation.UNARYMINUS:
5439 case Operation.LOGIC_NOT:
5441 nodeSet.addTupleSet(leftOpSet);
5444 case Operation.LOGIC_OR:
5445 case Operation.LOGIC_AND:
5446 case Operation.COMP:
5447 case Operation.BIT_OR:
5448 case Operation.BIT_XOR:
5449 case Operation.BIT_AND:
5450 case Operation.ISAVAILABLE:
5451 case Operation.EQUAL:
5452 case Operation.NOTEQUAL:
5459 case Operation.MULT:
5462 case Operation.LEFTSHIFT:
5463 case Operation.RIGHTSHIFT:
5464 case Operation.URIGHTSHIFT:
5466 // there are two operands
5467 nodeSet.addTupleSet(leftOpSet);
5468 nodeSet.addTupleSet(rightOpSet);
5470 nodeSet.addGlobalFlowTupleSet(leftOpSet.getGlobalLocTupleSet());
5471 nodeSet.addGlobalFlowTupleSet(rightOpSet.getGlobalLocTupleSet());
5476 throw new Error(op.toString());
5481 private NTuple<Descriptor> analyzeFlowNameNode(MethodDescriptor md, SymbolTable nametable,
5482 NameNode nn, NodeTupleSet nodeSet, NTuple<Descriptor> base, NodeTupleSet implicitFlowTupleSet) {
5485 base = new NTuple<Descriptor>();
5488 NameDescriptor nd = nn.getName();
5490 if (nd.getBase() != null) {
5492 analyzeFlowExpressionNode(md, nametable, nn.getExpression(), nodeSet, base,
5493 implicitFlowTupleSet, false);
5495 // base node has the top location
5499 String varname = nd.toString();
5500 if (varname.equals("this")) {
5502 base.add(md.getThis());
5506 Descriptor d = (Descriptor) nametable.get(varname);
5508 if (d instanceof VarDescriptor) {
5509 VarDescriptor vd = (VarDescriptor) d;
5511 } else if (d instanceof FieldDescriptor) {
5512 // the type of field descriptor has a location!
5513 FieldDescriptor fd = (FieldDescriptor) d;
5514 if (fd.isStatic()) {
5516 // if it is 'static final', no need to have flow node for the TOP
5520 // if 'static', assign the default GLOBAL LOCATION to the first
5521 // element of the tuple
5522 base.add(GLOBALDESC);
5525 // the location of field access starts from this, followed by field
5527 base.add(md.getThis());
5531 } else if (d == null) {
5532 // access static field
5533 base.add(GLOBALDESC);
5534 base.add(nn.getField());
5537 // FieldDescriptor fd = nn.getField();addFlowGraphEdge
5539 // MethodLattice<String> localLattice = ssjava.getMethodLattice(md);
5540 // String globalLocId = localLattice.getGlobalLoc();
5541 // if (globalLocId == null) {
5543 // Error("Method lattice does not define global variable location at "
5544 // + generateErrorMessage(md.getClassDesc(), nn));
5546 // loc.addLocation(new Location(md, globalLocId));
5548 // Location fieldLoc = (Location) fd.getType().getExtension();
5549 // loc.addLocation(fieldLoc);
5555 getFlowGraph(md).createNewFlowNode(base);
5561 private NTuple<Descriptor> analyzeFlowFieldAccessNode(MethodDescriptor md, SymbolTable nametable,
5562 FieldAccessNode fan, NodeTupleSet nodeSet, NTuple<Descriptor> base,
5563 NodeTupleSet implicitFlowTupleSet, boolean isLHS) {
5564 // System.out.println("analyzeFlowFieldAccessNode=" + fan.printNode(0));
5566 String currentArrayAccessNodeExpStr = null;
5567 ExpressionNode left = fan.getExpression();
5568 TypeDescriptor ltd = left.getType();
5569 FieldDescriptor fd = fan.getField();
5570 ArrayAccessNode aan = null;
5572 String varName = null;
5573 if (left.kind() == Kind.NameNode) {
5574 NameDescriptor nd = ((NameNode) left).getName();
5575 varName = nd.toString();
5578 if (ltd.isClassNameRef() || (varName != null && varName.equals("this"))) {
5579 // using a class name directly or access using this
5580 if (fd.isStatic() && fd.isFinal()) {
5585 NodeTupleSet idxNodeTupleSet = new NodeTupleSet();
5587 boolean isArrayCase = false;
5588 if (left instanceof ArrayAccessNode) {
5591 aan = (ArrayAccessNode) left;
5593 currentArrayAccessNodeExpStr = aan.printNode(0);
5594 arrayAccessNodeStack.push(currentArrayAccessNodeExpStr);
5596 left = aan.getExpression();
5597 analyzeFlowExpressionNode(md, nametable, aan.getIndex(), idxNodeTupleSet, base,
5598 implicitFlowTupleSet, isLHS);
5602 analyzeFlowExpressionNode(md, nametable, left, nodeSet, base, implicitFlowTupleSet, isLHS);
5605 // in this case, field is TOP location
5609 NTuple<Descriptor> flowFieldTuple = new NTuple<Descriptor>(base.toList());
5611 if (!left.getType().isPrimitive()) {
5612 if (!fd.getSymbol().equals("length")) {
5613 // array.length access, just have the location of the array
5614 flowFieldTuple.add(fd);
5615 nodeSet.removeTuple(base);
5618 getFlowGraph(md).createNewFlowNode(flowFieldTuple);
5621 for (Iterator<NTuple<Descriptor>> idxIter = idxNodeTupleSet.iterator(); idxIter.hasNext();) {
5622 NTuple<Descriptor> idxTuple = idxIter.next();
5623 getFlowGraph(md).addValueFlowEdge(idxTuple, flowFieldTuple);
5626 GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(md);
5627 for (Iterator<NTuple<Location>> iterator = idxNodeTupleSet.globalIterator(); iterator
5629 NTuple<Location> calleeReturnLocTuple = iterator.next();
5631 globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
5632 translateToLocTuple(md, flowFieldTuple));
5636 nodeSet.addTupleSet(idxNodeTupleSet);
5638 // if it is the array case and not the LHS case
5640 arrayAccessNodeStack.pop();
5642 if (arrayAccessNodeStack.isEmpty()
5643 || !arrayAccessNodeStack.peek().startsWith(currentArrayAccessNodeExpStr)) {
5644 NodeTupleSet nodeSetArrayAccessExp = new NodeTupleSet();
5646 nodeSetArrayAccessExp.addTuple(flowFieldTuple);
5647 nodeSetArrayAccessExp.addTupleSet(idxNodeTupleSet);
5648 nodeSetArrayAccessExp.addTupleSet(nodeSet);
5650 if (needToGenerateInterLoc(nodeSetArrayAccessExp)) {
5651 System.out.println("4");
5652 System.out.println("nodeSetArrayAccessExp=" + nodeSetArrayAccessExp);
5653 // System.out.println("idxNodeTupleSet.getGlobalLocTupleSet()="
5654 // + idxNodeTupleSet.getGlobalLocTupleSet());
5656 NTuple<Descriptor> interTuple =
5657 getFlowGraph(md).createIntermediateNode().getDescTuple();
5659 for (Iterator<NTuple<Descriptor>> iter = nodeSetArrayAccessExp.iterator(); iter
5661 NTuple<Descriptor> higherTuple = iter.next();
5662 addFlowGraphEdge(md, higherTuple, interTuple);
5665 FlowGraph fg = getFlowGraph(md);
5666 fg.addMapInterLocNodeToEnclosingDescriptor(interTuple.get(0),
5667 getClassTypeDescriptor(base.get(base.size() - 1)));
5670 flowFieldTuple = interTuple;
5672 nodeSet.addGlobalFlowTupleSet(idxNodeTupleSet.getGlobalLocTupleSet());
5678 return flowFieldTuple;
5683 private void debug_printTreeNode(TreeNode tn) {
5685 System.out.println("DEBUG: " + tn.printNode(0) + " line#=" + tn.getNumLine());
5689 private void analyzeFlowAssignmentNode(MethodDescriptor md, SymbolTable nametable,
5690 AssignmentNode an, NodeTupleSet nodeSet, NTuple<Descriptor> base,
5691 NodeTupleSet implicitFlowTupleSet) {
5693 NodeTupleSet nodeSetRHS = new NodeTupleSet();
5694 NodeTupleSet nodeSetLHS = new NodeTupleSet();
5696 boolean postinc = true;
5697 if (an.getOperation().getBaseOp() == null
5698 || (an.getOperation().getBaseOp().getOp() != Operation.POSTINC && an.getOperation()
5699 .getBaseOp().getOp() != Operation.POSTDEC)) {
5702 // if LHS is array access node, need to capture value flows between an array
5703 // and its index value
5704 analyzeFlowExpressionNode(md, nametable, an.getDest(), nodeSetLHS, null, implicitFlowTupleSet,
5708 // analyze value flows of rhs expression
5709 analyzeFlowExpressionNode(md, nametable, an.getSrc(), nodeSetRHS, null, implicitFlowTupleSet,
5712 System.out.println("-analyzeFlowAssignmentNode=" + an.printNode(0));
5713 System.out.println("-nodeSetLHS=" + nodeSetLHS);
5714 System.out.println("-nodeSetRHS=" + nodeSetRHS);
5715 System.out.println("-implicitFlowTupleSet=" + implicitFlowTupleSet);
5716 // System.out.println("-");
5718 if (an.getOperation().getOp() >= 2 && an.getOperation().getOp() <= 12) {
5719 // if assignment contains OP+EQ operator, creates edges from LHS to LHS
5721 for (Iterator<NTuple<Descriptor>> iter = nodeSetLHS.iterator(); iter.hasNext();) {
5722 NTuple<Descriptor> fromTuple = iter.next();
5723 for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
5724 NTuple<Descriptor> toTuple = iter2.next();
5725 addFlowGraphEdge(md, fromTuple, toTuple);
5730 // creates edges from RHS to LHS
5731 NTuple<Descriptor> interTuple = null;
5732 if (needToGenerateInterLoc(nodeSetRHS)) {
5733 System.out.println("2");
5734 interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
5737 for (Iterator<NTuple<Descriptor>> iter = nodeSetRHS.iterator(); iter.hasNext();) {
5738 NTuple<Descriptor> fromTuple = iter.next();
5739 for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
5740 NTuple<Descriptor> toTuple = iter2.next();
5741 addFlowGraphEdge(md, fromTuple, interTuple, toTuple);
5745 // creates edges from implicitFlowTupleSet to LHS
5746 for (Iterator<NTuple<Descriptor>> iter = implicitFlowTupleSet.iterator(); iter.hasNext();) {
5747 NTuple<Descriptor> fromTuple = iter.next();
5748 for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
5749 NTuple<Descriptor> toTuple = iter2.next();
5750 addFlowGraphEdge(md, fromTuple, toTuple);
5754 // create global flow edges if the callee gives return value flows to the caller
5755 GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(md);
5756 for (Iterator<NTuple<Location>> iterator = nodeSetRHS.globalIterator(); iterator.hasNext();) {
5757 NTuple<Location> calleeReturnLocTuple = iterator.next();
5758 for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
5759 NTuple<Descriptor> callerLHSTuple = iter2.next();
5760 System.out.println("$$$ GLOBAL FLOW ADD=" + calleeReturnLocTuple + " -> "
5761 + translateToLocTuple(md, callerLHSTuple));
5763 globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
5764 translateToLocTuple(md, callerLHSTuple));
5768 for (Iterator<NTuple<Location>> iterator = implicitFlowTupleSet.globalIterator(); iterator
5770 NTuple<Location> calleeReturnLocTuple = iterator.next();
5771 for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
5772 NTuple<Descriptor> callerLHSTuple = iter2.next();
5774 globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
5775 translateToLocTuple(md, callerLHSTuple));
5776 System.out.println("$$$ GLOBAL FLOW PCLOC ADD=" + calleeReturnLocTuple + " -> "
5777 + translateToLocTuple(md, callerLHSTuple));
5784 for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
5785 NTuple<Descriptor> tuple = iter2.next();
5786 addFlowGraphEdge(md, tuple, tuple);
5789 // creates edges from implicitFlowTupleSet to LHS
5790 for (Iterator<NTuple<Descriptor>> iter = implicitFlowTupleSet.iterator(); iter.hasNext();) {
5791 NTuple<Descriptor> fromTuple = iter.next();
5792 for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
5793 NTuple<Descriptor> toTuple = iter2.next();
5794 addFlowGraphEdge(md, fromTuple, toTuple);
5798 GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(md);
5799 for (Iterator<NTuple<Location>> iterator = implicitFlowTupleSet.globalIterator(); iterator
5801 NTuple<Location> calleeReturnLocTuple = iterator.next();
5802 for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
5803 NTuple<Descriptor> callerLHSTuple = iter2.next();
5804 globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
5805 translateToLocTuple(md, callerLHSTuple));
5806 System.out.println("$$$ GLOBAL FLOW PC ADD=" + calleeReturnLocTuple + " -> "
5807 + translateToLocTuple(md, callerLHSTuple));
5813 if (nodeSet != null) {
5814 nodeSet.addTupleSet(nodeSetLHS);
5815 nodeSet.addGlobalFlowTupleSet(nodeSetLHS.getGlobalLocTupleSet());
5819 public FlowGraph getFlowGraph(MethodDescriptor md) {
5820 return mapMethodDescriptorToFlowGraph.get(md);
5823 private boolean addFlowGraphEdge(MethodDescriptor md, NTuple<Descriptor> from,
5824 NTuple<Descriptor> to) {
5825 FlowGraph graph = getFlowGraph(md);
5826 graph.addValueFlowEdge(from, to);
5830 private void addFlowGraphEdge(MethodDescriptor md, NTuple<Descriptor> from,
5831 NTuple<Descriptor> inter, NTuple<Descriptor> to) {
5833 FlowGraph graph = getFlowGraph(md);
5835 if (inter != null) {
5836 graph.addValueFlowEdge(from, inter);
5837 graph.addValueFlowEdge(inter, to);
5839 graph.addValueFlowEdge(from, to);
5844 public void writeInferredLatticeDotFile(ClassDescriptor cd, HierarchyGraph simpleHierarchyGraph,
5845 SSJavaLattice<String> locOrder, String nameSuffix) {
5846 System.out.println("@cd=" + cd);
5847 System.out.println("@sharedLoc=" + locOrder.getSharedLocSet());
5848 writeInferredLatticeDotFile(cd, null, simpleHierarchyGraph, locOrder, nameSuffix);
5851 public void writeInferredLatticeDotFile(ClassDescriptor cd, MethodDescriptor md,
5852 HierarchyGraph simpleHierarchyGraph, SSJavaLattice<String> locOrder, String nameSuffix) {
5854 String fileName = "lattice_";
5857 /* cd.getSymbol().replaceAll("[\\W_]", "") + "_" + */md.toString().replaceAll("[\\W_]", "");
5859 fileName += cd.getSymbol().replaceAll("[\\W_]", "");
5862 fileName += nameSuffix;
5864 Set<Pair<String, String>> pairSet = locOrder.getOrderingPairSet();
5866 Set<String> addedLocSet = new HashSet<String>();
5868 if (pairSet.size() > 0) {
5870 BufferedWriter bw = new BufferedWriter(new FileWriter(fileName + ".dot"));
5872 bw.write("digraph " + fileName + " {\n");
5874 for (Iterator iterator = pairSet.iterator(); iterator.hasNext();) {
5875 // pair is in the form of <higher, lower>
5876 Pair<String, String> pair = (Pair<String, String>) iterator.next();
5878 String highLocId = pair.getFirst();
5879 String lowLocId = pair.getSecond();
5880 if (!addedLocSet.contains(highLocId)) {
5881 addedLocSet.add(highLocId);
5882 drawNode(bw, locOrder, simpleHierarchyGraph, highLocId);
5885 if (!addedLocSet.contains(lowLocId)) {
5886 addedLocSet.add(lowLocId);
5887 drawNode(bw, locOrder, simpleHierarchyGraph, lowLocId);
5890 bw.write(highLocId + " -> " + lowLocId + ";\n");
5895 } catch (IOException e) {
5896 e.printStackTrace();
5903 private String convertMergeSetToString(HierarchyGraph graph, Set<HNode> mergeSet) {
5905 for (Iterator iterator = mergeSet.iterator(); iterator.hasNext();) {
5906 HNode merged = (HNode) iterator.next();
5907 if (merged.isMergeNode()) {
5908 str += convertMergeSetToString(graph, graph.getMapHNodetoMergeSet().get(merged));
5910 str += " " + merged.getName();
5916 private void drawNode(BufferedWriter bw, SSJavaLattice<String> lattice, HierarchyGraph graph,
5917 String locName) throws IOException {
5920 if (lattice.isSharedLoc(locName)) {
5921 prettyStr = locName + "*";
5923 prettyStr = locName;
5925 // HNode node = graph.getHNode(locName);
5926 // if (node != null && node.isMergeNode()) {
5927 // Set<HNode> mergeSet = graph.getMapHNodetoMergeSet().get(node);
5928 // prettyStr += ":" + convertMergeSetToString(graph, mergeSet);
5930 bw.write(locName + " [label=\"" + prettyStr + "\"]" + ";\n");
5933 public void _debug_writeFlowGraph() {
5934 Set<MethodDescriptor> keySet = mapMethodDescriptorToFlowGraph.keySet();
5936 for (Iterator<MethodDescriptor> iterator = keySet.iterator(); iterator.hasNext();) {
5937 MethodDescriptor md = (MethodDescriptor) iterator.next();
5938 FlowGraph fg = mapMethodDescriptorToFlowGraph.get(md);
5939 GlobalFlowGraph subGlobalFlowGraph = getSubGlobalFlowGraph(md);
5942 subGlobalFlowGraph.writeGraph("_SUBGLOBAL");
5943 } catch (IOException e) {
5944 e.printStackTrace();
5952 class CyclicFlowException extends Exception {
5956 class InterDescriptor extends Descriptor {
5958 Pair<MethodInvokeNode, Integer> minArgIdxPair;
5960 public InterDescriptor(String name) {
5964 public void setMethodArgIdxPair(MethodInvokeNode min, int idx) {
5965 minArgIdxPair = new Pair<MethodInvokeNode, Integer>(min, new Integer(idx));
5968 public Pair<MethodInvokeNode, Integer> getMethodArgIdxPair() {
5969 return minArgIdxPair;