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: Insering Combination Nodes:" + desc);
2154 HierarchyGraph skeletonGraph = getSkeletonHierarchyGraph(desc);
2155 HierarchyGraph skeletonGraphWithCombinationNode = skeletonGraph.clone();
2156 skeletonGraphWithCombinationNode.setName(desc + "_SC");
2158 HierarchyGraph simpleHierarchyGraph = getSimpleHierarchyGraph(desc);
2159 System.out.println("Identifying Combination Nodes:");
2160 skeletonGraphWithCombinationNode.insertCombinationNodesToGraph(simpleHierarchyGraph);
2161 skeletonGraphWithCombinationNode.simplifySkeletonCombinationHierarchyGraph();
2162 mapDescriptorToCombineSkeletonHierarchyGraph.put(desc, skeletonGraphWithCombinationNode);
2166 private void constructSkeletonHierarchyGraph() {
2167 Set<Descriptor> keySet = mapDescriptorToHierarchyGraph.keySet();
2168 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
2169 Descriptor desc = (Descriptor) iterator.next();
2170 System.out.println("SSJAVA: Constructing Skeleton Hierarchy Graph: " + desc);
2171 HierarchyGraph simpleGraph = getSimpleHierarchyGraph(desc);
2172 HierarchyGraph skeletonGraph = simpleGraph.generateSkeletonGraph();
2173 skeletonGraph.setMapDescToHNode(simpleGraph.getMapDescToHNode());
2174 skeletonGraph.setMapHNodeToDescSet(simpleGraph.getMapHNodeToDescSet());
2175 skeletonGraph.simplifyHierarchyGraph();
2176 // skeletonGraph.combineRedundantNodes(false);
2177 // skeletonGraph.removeRedundantEdges();
2178 mapDescriptorToSkeletonHierarchyGraph.put(desc, skeletonGraph);
2182 private void debug_writeHierarchyDotFiles() {
2184 Set<Descriptor> keySet = mapDescriptorToHierarchyGraph.keySet();
2185 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
2186 Descriptor desc = (Descriptor) iterator.next();
2187 getHierarchyGraph(desc).writeGraph();
2192 private void debug_writeSimpleHierarchyDotFiles() {
2194 Set<Descriptor> keySet = mapDescriptorToHierarchyGraph.keySet();
2195 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
2196 Descriptor desc = (Descriptor) iterator.next();
2197 getHierarchyGraph(desc).writeGraph();
2198 getSimpleHierarchyGraph(desc).writeGraph();
2199 getSimpleHierarchyGraph(desc).writeGraph(true);
2204 private void debug_writeSkeletonHierarchyDotFiles() {
2206 Set<Descriptor> keySet = mapDescriptorToHierarchyGraph.keySet();
2207 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
2208 Descriptor desc = (Descriptor) iterator.next();
2209 getSkeletonHierarchyGraph(desc).writeGraph();
2214 private void debug_writeSkeletonCombinationHierarchyDotFiles() {
2216 Set<Descriptor> keySet = mapDescriptorToHierarchyGraph.keySet();
2217 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
2218 Descriptor desc = (Descriptor) iterator.next();
2219 getSkeletonCombinationHierarchyGraph(desc).writeGraph();
2224 public HierarchyGraph getSimpleHierarchyGraph(Descriptor d) {
2225 return mapDescriptorToSimpleHierarchyGraph.get(d);
2228 private HierarchyGraph getSkeletonHierarchyGraph(Descriptor d) {
2229 if (!mapDescriptorToSkeletonHierarchyGraph.containsKey(d)) {
2230 mapDescriptorToSkeletonHierarchyGraph.put(d, new HierarchyGraph(d));
2232 return mapDescriptorToSkeletonHierarchyGraph.get(d);
2235 public HierarchyGraph getSkeletonCombinationHierarchyGraph(Descriptor d) {
2236 if (!mapDescriptorToCombineSkeletonHierarchyGraph.containsKey(d)) {
2237 mapDescriptorToCombineSkeletonHierarchyGraph.put(d, new HierarchyGraph(d));
2239 return mapDescriptorToCombineSkeletonHierarchyGraph.get(d);
2242 private void constructHierarchyGraph() {
2244 LinkedList<MethodDescriptor> methodDescList =
2245 (LinkedList<MethodDescriptor>) toanalyze_methodDescList.clone();
2247 while (!methodDescList.isEmpty()) {
2248 MethodDescriptor md = methodDescList.removeLast();
2249 if (state.SSJAVADEBUG) {
2250 HierarchyGraph hierarchyGraph = new HierarchyGraph(md);
2251 System.out.println();
2252 System.out.println("SSJAVA: Construcing the hierarchy graph from " + md);
2253 constructHierarchyGraph(md, hierarchyGraph);
2254 mapDescriptorToHierarchyGraph.put(md, hierarchyGraph);
2260 while (!toAnalyzeIsEmpty()) {
2261 ClassDescriptor cd = toAnalyzeNext();
2262 HierarchyGraph graph = getHierarchyGraph(cd);
2263 for (Iterator iter = cd.getFields(); iter.hasNext();) {
2264 FieldDescriptor fieldDesc = (FieldDescriptor) iter.next();
2265 if (!(fieldDesc.isStatic() && fieldDesc.isFinal())) {
2266 graph.getHNode(fieldDesc);
2271 Set<Descriptor> keySet = mapDescriptorToHierarchyGraph.keySet();
2272 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
2273 Descriptor key = (Descriptor) iterator.next();
2274 HierarchyGraph graph = getHierarchyGraph(key);
2276 Set<HNode> nodeToBeConnected = new HashSet<HNode>();
2277 for (Iterator iterator2 = graph.getNodeSet().iterator(); iterator2.hasNext();) {
2278 HNode node = (HNode) iterator2.next();
2279 if (!node.isSkeleton() && !node.isCombinationNode()) {
2280 if (graph.getIncomingNodeSet(node).size() == 0) {
2281 nodeToBeConnected.add(node);
2286 for (Iterator iterator2 = nodeToBeConnected.iterator(); iterator2.hasNext();) {
2287 HNode node = (HNode) iterator2.next();
2288 System.out.println("NEED TO BE CONNECTED TO TOP=" + node);
2289 graph.addEdge(graph.getHNode(TOPDESC), node);
2296 private void constructHierarchyGraph2() {
2298 // do fixed-point analysis
2300 LinkedList<MethodDescriptor> descriptorListToAnalyze = ssjava.getSortedDescriptors();
2302 // Collections.sort(descriptorListToAnalyze, new
2303 // Comparator<MethodDescriptor>() {
2304 // public int compare(MethodDescriptor o1, MethodDescriptor o2) {
2305 // return o1.getSymbol().compareToIgnoreCase(o2.getSymbol());
2309 // current descriptors to visit in fixed-point interprocedural analysis,
2310 // prioritized by dependency in the call graph
2311 methodDescriptorsToVisitStack.clear();
2313 Set<MethodDescriptor> methodDescriptorToVistSet = new HashSet<MethodDescriptor>();
2314 methodDescriptorToVistSet.addAll(descriptorListToAnalyze);
2316 while (!descriptorListToAnalyze.isEmpty()) {
2317 MethodDescriptor md = descriptorListToAnalyze.removeFirst();
2318 methodDescriptorsToVisitStack.add(md);
2321 // analyze scheduled methods until there are no more to visit
2322 while (!methodDescriptorsToVisitStack.isEmpty()) {
2323 // start to analyze leaf node
2324 MethodDescriptor md = methodDescriptorsToVisitStack.pop();
2326 HierarchyGraph hierarchyGraph = new HierarchyGraph(md);
2327 // MethodSummary methodSummary = new MethodSummary(md);
2329 // MethodLocationInfo methodInfo = new MethodLocationInfo(md);
2330 // curMethodInfo = methodInfo;
2332 System.out.println();
2333 System.out.println("SSJAVA: Construcing the hierarchy graph from " + md);
2335 constructHierarchyGraph(md, hierarchyGraph);
2337 HierarchyGraph prevHierarchyGraph = getHierarchyGraph(md);
2338 // MethodSummary prevMethodSummary = getMethodSummary(md);
2340 if (!hierarchyGraph.equals(prevHierarchyGraph)) {
2342 mapDescriptorToHierarchyGraph.put(md, hierarchyGraph);
2343 // mapDescToLocationSummary.put(md, methodSummary);
2345 // results for callee changed, so enqueue dependents caller for
2347 Iterator<MethodDescriptor> depsItr = ssjava.getDependents(md).iterator();
2348 while (depsItr.hasNext()) {
2349 MethodDescriptor methodNext = depsItr.next();
2350 if (!methodDescriptorsToVisitStack.contains(methodNext)
2351 && methodDescriptorToVistSet.contains(methodNext)) {
2352 methodDescriptorsToVisitStack.add(methodNext);
2361 while (!toAnalyzeIsEmpty()) {
2362 ClassDescriptor cd = toAnalyzeNext();
2363 HierarchyGraph graph = getHierarchyGraph(cd);
2364 for (Iterator iter = cd.getFields(); iter.hasNext();) {
2365 FieldDescriptor fieldDesc = (FieldDescriptor) iter.next();
2366 if (!(fieldDesc.isStatic() && fieldDesc.isFinal())) {
2367 graph.getHNode(fieldDesc);
2372 Set<Descriptor> keySet = mapDescriptorToHierarchyGraph.keySet();
2373 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
2374 Descriptor key = (Descriptor) iterator.next();
2375 HierarchyGraph graph = getHierarchyGraph(key);
2377 Set<HNode> nodeToBeConnected = new HashSet<HNode>();
2378 for (Iterator iterator2 = graph.getNodeSet().iterator(); iterator2.hasNext();) {
2379 HNode node = (HNode) iterator2.next();
2380 if (!node.isSkeleton() && !node.isCombinationNode()) {
2381 if (graph.getIncomingNodeSet(node).size() == 0) {
2382 nodeToBeConnected.add(node);
2387 for (Iterator iterator2 = nodeToBeConnected.iterator(); iterator2.hasNext();) {
2388 HNode node = (HNode) iterator2.next();
2389 System.out.println("NEED TO BE CONNECTED TO TOP=" + node);
2390 graph.addEdge(graph.getHNode(TOPDESC), node);
2397 private HierarchyGraph getHierarchyGraph(Descriptor d) {
2398 if (!mapDescriptorToHierarchyGraph.containsKey(d)) {
2399 mapDescriptorToHierarchyGraph.put(d, new HierarchyGraph(d));
2401 return mapDescriptorToHierarchyGraph.get(d);
2404 private void constructHierarchyGraph(MethodDescriptor md, HierarchyGraph methodGraph) {
2406 // visit each node of method flow graph
2407 FlowGraph fg = getFlowGraph(md);
2408 // Set<FlowNode> nodeSet = fg.getNodeSet();
2410 Set<FlowEdge> edgeSet = fg.getEdgeSet();
2412 Set<Descriptor> paramDescSet = fg.getMapParamDescToIdx().keySet();
2413 for (Iterator iterator = paramDescSet.iterator(); iterator.hasNext();) {
2414 Descriptor desc = (Descriptor) iterator.next();
2415 methodGraph.getHNode(desc).setSkeleton(true);
2418 // for the method lattice, we need to look at the first element of
2419 // NTuple<Descriptor>
2420 boolean hasGlobalAccess = false;
2421 // for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
2422 // FlowNode originalSrcNode = (FlowNode) iterator.next();
2423 for (Iterator iterator = edgeSet.iterator(); iterator.hasNext();) {
2424 FlowEdge edge = (FlowEdge) iterator.next();
2426 FlowNode originalSrcNode = fg.getFlowNode(edge.getInitTuple());
2427 Set<FlowNode> sourceNodeSet = new HashSet<FlowNode>();
2428 if (originalSrcNode instanceof FlowReturnNode) {
2429 FlowReturnNode rnode = (FlowReturnNode) originalSrcNode;
2430 System.out.println("rnode=" + rnode);
2431 Set<NTuple<Descriptor>> tupleSet = rnode.getReturnTupleSet();
2432 for (Iterator iterator2 = tupleSet.iterator(); iterator2.hasNext();) {
2433 NTuple<Descriptor> nTuple = (NTuple<Descriptor>) iterator2.next();
2434 sourceNodeSet.add(fg.getFlowNode(nTuple));
2435 System.out.println("&&&SOURCE fg.getFlowNode(nTuple)=" + fg.getFlowNode(nTuple));
2438 sourceNodeSet.add(originalSrcNode);
2441 // System.out.println("---sourceNodeSet=" + sourceNodeSet + " from originalSrcNode="
2442 // + originalSrcNode);
2444 for (Iterator iterator3 = sourceNodeSet.iterator(); iterator3.hasNext();) {
2445 FlowNode srcNode = (FlowNode) iterator3.next();
2447 NTuple<Descriptor> srcNodeTuple = srcNode.getDescTuple();
2448 Descriptor srcLocalDesc = srcNodeTuple.get(0);
2450 if (srcLocalDesc instanceof InterDescriptor
2451 && ((InterDescriptor) srcLocalDesc).getMethodArgIdxPair() != null) {
2453 if (srcNode.getCompositeLocation() == null) {
2458 // if the srcNode is started with the global descriptor
2459 // need to set as a skeleton node
2460 if (!hasGlobalAccess && srcNode.getDescTuple().startsWith(GLOBALDESC)) {
2461 hasGlobalAccess = true;
2464 // Set<FlowEdge> outEdgeSet = fg.getOutEdgeSet(originalSrcNode);
2465 // for (Iterator iterator2 = outEdgeSet.iterator(); iterator2.hasNext();) {
2466 // FlowEdge outEdge = (FlowEdge) iterator2.next();
2467 // FlowNode originalDstNode = outEdge.getDst();
2468 FlowNode originalDstNode = fg.getFlowNode(edge.getEndTuple());
2470 Set<FlowNode> dstNodeSet = new HashSet<FlowNode>();
2471 if (originalDstNode instanceof FlowReturnNode) {
2472 FlowReturnNode rnode = (FlowReturnNode) originalDstNode;
2473 // System.out.println("\n-returnNode=" + rnode);
2474 Set<NTuple<Descriptor>> tupleSet = rnode.getReturnTupleSet();
2475 for (Iterator iterator4 = tupleSet.iterator(); iterator4.hasNext();) {
2476 NTuple<Descriptor> nTuple = (NTuple<Descriptor>) iterator4.next();
2477 dstNodeSet.add(fg.getFlowNode(nTuple));
2478 System.out.println("&&&DST fg.getFlowNode(nTuple)=" + fg.getFlowNode(nTuple));
2481 dstNodeSet.add(originalDstNode);
2483 // System.out.println("---dstNodeSet=" + dstNodeSet);
2484 for (Iterator iterator4 = dstNodeSet.iterator(); iterator4.hasNext();) {
2485 FlowNode dstNode = (FlowNode) iterator4.next();
2487 NTuple<Descriptor> dstNodeTuple = dstNode.getDescTuple();
2488 Descriptor dstLocalDesc = dstNodeTuple.get(0);
2490 if (dstLocalDesc instanceof InterDescriptor
2491 && ((InterDescriptor) dstLocalDesc).getMethodArgIdxPair() != null) {
2492 if (dstNode.getCompositeLocation() == null) {
2493 System.out.println("%%%%%%%%%%%%%SKIP=" + dstNode);
2498 // if (outEdge.getInitTuple().equals(srcNodeTuple)
2499 // && outEdge.getEndTuple().equals(dstNodeTuple)) {
2501 NTuple<Descriptor> srcCurTuple = srcNode.getCurrentDescTuple();
2502 NTuple<Descriptor> dstCurTuple = dstNode.getCurrentDescTuple();
2504 System.out.println("-srcCurTuple=" + srcCurTuple + " dstCurTuple=" + dstCurTuple
2505 + " srcNode=" + srcNode + " dstNode=" + dstNode);
2507 // srcCurTuple = translateBaseTuple(srcNode, srcCurTuple);
2508 // dstCurTuple = translateBaseTuple(dstNode, dstCurTuple);
2510 if ((srcCurTuple.size() > 1 && dstCurTuple.size() > 1)
2511 && srcCurTuple.get(0).equals(dstCurTuple.get(0))) {
2513 // value flows between fields
2514 Descriptor desc = srcCurTuple.get(0);
2515 ClassDescriptor classDesc;
2517 if (desc.equals(GLOBALDESC)) {
2518 classDesc = md.getClassDesc();
2520 VarDescriptor varDesc = (VarDescriptor) srcCurTuple.get(0);
2521 classDesc = varDesc.getType().getClassDesc();
2523 extractFlowsBetweenFields(classDesc, srcNode, dstNode, 1);
2525 } else if ((srcCurTuple.size() == 1 && dstCurTuple.size() == 1)
2526 || ((srcCurTuple.size() > 1 || dstCurTuple.size() > 1) && !srcCurTuple.get(0).equals(
2527 dstCurTuple.get(0)))) {
2529 // value flow between a primitive local var - a primitive local var or local var -
2532 Descriptor srcDesc = srcCurTuple.get(0);
2533 Descriptor dstDesc = dstCurTuple.get(0);
2535 methodGraph.addEdge(srcDesc, dstDesc);
2537 if (fg.isParamDesc(srcDesc)) {
2538 methodGraph.setParamHNode(srcDesc);
2540 if (fg.isParamDesc(dstDesc)) {
2541 methodGraph.setParamHNode(dstDesc);
2555 // If the method accesses static fields
2556 // set hasGloabalAccess true in the method summary.
2557 if (hasGlobalAccess) {
2558 getMethodSummary(md).setHasGlobalAccess();
2560 methodGraph.getHNode(GLOBALDESC).setSkeleton(true);
2562 if (ssjava.getMethodContainingSSJavaLoop().equals(md)) {
2563 // if the current method contains the event loop
2564 // we need to set all nodes of the hierarchy graph as a skeleton node
2565 Set<HNode> hnodeSet = methodGraph.getNodeSet();
2566 for (Iterator iterator = hnodeSet.iterator(); iterator.hasNext();) {
2567 HNode hnode = (HNode) iterator.next();
2568 hnode.setSkeleton(true);
2574 private NTuple<Descriptor> translateBaseTuple(FlowNode flowNode, NTuple<Descriptor> inTuple) {
2576 if (flowNode.getBaseTuple() != null) {
2578 NTuple<Descriptor> translatedTuple = new NTuple<Descriptor>();
2580 NTuple<Descriptor> baseTuple = flowNode.getBaseTuple();
2582 for (int i = 0; i < baseTuple.size(); i++) {
2583 translatedTuple.add(baseTuple.get(i));
2586 for (int i = 1; i < inTuple.size(); i++) {
2587 translatedTuple.add(inTuple.get(i));
2590 System.out.println("------TRANSLATED " + inTuple + " -> " + translatedTuple);
2591 return translatedTuple;
2599 private MethodSummary getMethodSummary(MethodDescriptor md) {
2600 if (!mapDescToLocationSummary.containsKey(md)) {
2601 mapDescToLocationSummary.put(md, new MethodSummary(md));
2603 return (MethodSummary) mapDescToLocationSummary.get(md);
2606 private void addMapClassDefinitionToLineNum(ClassDescriptor cd, String strLine, int lineNum) {
2608 String classSymbol = cd.getSymbol();
2609 int idx = classSymbol.lastIndexOf("$");
2611 classSymbol = classSymbol.substring(idx + 1);
2614 String pattern = "class " + classSymbol + " ";
2615 if (strLine.indexOf(pattern) != -1) {
2616 mapDescToDefinitionLine.put(cd, lineNum);
2620 private void addMapMethodDefinitionToLineNum(Set<MethodDescriptor> methodSet, String strLine,
2622 for (Iterator iterator = methodSet.iterator(); iterator.hasNext();) {
2623 MethodDescriptor md = (MethodDescriptor) iterator.next();
2624 String pattern = md.getMethodDeclaration();
2625 if (strLine.indexOf(pattern) != -1) {
2626 mapDescToDefinitionLine.put(md, lineNum);
2627 methodSet.remove(md);
2634 private void readOriginalSourceFiles() {
2636 SymbolTable classtable = state.getClassSymbolTable();
2638 Set<ClassDescriptor> classDescSet = new HashSet<ClassDescriptor>();
2639 classDescSet.addAll(classtable.getValueSet());
2642 // inefficient implement. it may re-visit the same file if the file
2643 // contains more than one class definitions.
2644 for (Iterator iterator = classDescSet.iterator(); iterator.hasNext();) {
2645 ClassDescriptor cd = (ClassDescriptor) iterator.next();
2647 Set<MethodDescriptor> methodSet = new HashSet<MethodDescriptor>();
2648 methodSet.addAll(cd.getMethodTable().getValueSet());
2650 String sourceFileName = cd.getSourceFileName();
2651 Vector<String> lineVec = new Vector<String>();
2653 mapFileNameToLineVector.put(sourceFileName, lineVec);
2655 BufferedReader in = new BufferedReader(new FileReader(sourceFileName));
2658 lineVec.add(""); // the index is started from 1.
2659 while ((strLine = in.readLine()) != null) {
2660 lineVec.add(lineNum, strLine);
2661 addMapClassDefinitionToLineNum(cd, strLine, lineNum);
2662 addMapMethodDefinitionToLineNum(methodSet, strLine, lineNum);
2668 } catch (IOException e) {
2669 e.printStackTrace();
2674 private String generateLatticeDefinition(Descriptor desc) {
2676 Set<String> sharedLocSet = new HashSet<String>();
2678 SSJavaLattice<String> lattice = getLattice(desc);
2679 String rtr = "@LATTICE(\"";
2681 Map<String, Set<String>> map = lattice.getTable();
2682 Set<String> keySet = map.keySet();
2683 boolean first = true;
2684 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
2685 String key = (String) iterator.next();
2686 if (!key.equals(lattice.getTopItem())) {
2687 Set<String> connectedSet = map.get(key);
2689 if (connectedSet.size() == 1) {
2690 if (connectedSet.iterator().next().equals(lattice.getBottomItem())) {
2698 if (lattice.isSharedLoc(key)) {
2699 rtr += "," + key + "*";
2704 for (Iterator iterator2 = connectedSet.iterator(); iterator2.hasNext();) {
2705 String loc = (String) iterator2.next();
2706 if (!loc.equals(lattice.getBottomItem())) {
2713 rtr += loc + "<" + key;
2714 if (lattice.isSharedLoc(key) && (!sharedLocSet.contains(key))) {
2715 rtr += "," + key + "*";
2716 sharedLocSet.add(key);
2718 if (lattice.isSharedLoc(loc) && (!sharedLocSet.contains(loc))) {
2719 rtr += "," + loc + "*";
2720 sharedLocSet.add(loc);
2728 if (desc instanceof MethodDescriptor) {
2729 System.out.println("#EXTRA LOC DECLARATION GEN=" + desc);
2731 MethodDescriptor md = (MethodDescriptor) desc;
2732 MethodSummary methodSummary = getMethodSummary(md);
2734 TypeDescriptor returnType = ((MethodDescriptor) desc).getReturnType();
2735 if (!ssjava.getMethodContainingSSJavaLoop().equals(desc) && returnType != null
2736 && (!returnType.isVoid())) {
2737 CompositeLocation returnLoc = methodSummary.getRETURNLoc();
2738 if (returnLoc.getSize() == 1) {
2739 String returnLocStr = generateLocationAnnoatation(methodSummary.getRETURNLoc());
2740 if (rtr.indexOf(returnLocStr) == -1) {
2741 rtr += "," + returnLocStr;
2747 if (!ssjava.getMethodContainingSSJavaLoop().equals(desc)) {
2748 if (returnType != null && (!returnType.isVoid())) {
2750 "\n@RETURNLOC(\"" + generateLocationAnnoatation(methodSummary.getRETURNLoc()) + "\")";
2753 CompositeLocation pcLoc = methodSummary.getPCLoc();
2754 if ((pcLoc != null) && (!pcLoc.get(0).isTop())) {
2755 rtr += "\n@PCLOC(\"" + generateLocationAnnoatation(pcLoc) + "\")";
2759 if (!md.isStatic()) {
2760 rtr += "\n@THISLOC(\"" + methodSummary.getThisLocName() + "\")";
2762 rtr += "\n@GLOBALLOC(\"" + methodSummary.getGlobalLocName() + "\")";
2771 private void generateAnnoatedCode() {
2773 readOriginalSourceFiles();
2776 while (!toAnalyzeIsEmpty()) {
2777 ClassDescriptor cd = toAnalyzeNext();
2779 setupToAnalazeMethod(cd);
2781 String sourceFileName = cd.getSourceFileName();
2783 if (cd.isInterface()) {
2787 int classDefLine = mapDescToDefinitionLine.get(cd);
2788 Vector<String> sourceVec = mapFileNameToLineVector.get(sourceFileName);
2790 LocationSummary fieldLocSummary = getLocationSummary(cd);
2792 String fieldLatticeDefStr = generateLatticeDefinition(cd);
2793 String annoatedSrc = fieldLatticeDefStr + newline + sourceVec.get(classDefLine);
2794 sourceVec.set(classDefLine, annoatedSrc);
2796 // generate annotations for field declarations
2797 // Map<Descriptor, CompositeLocation> inferLocMap = fieldLocInfo.getMapDescToInferLocation();
2798 Map<String, String> mapFieldNameToLocName = fieldLocSummary.getMapHNodeNameToLocationName();
2800 for (Iterator iter = cd.getFields(); iter.hasNext();) {
2801 FieldDescriptor fd = (FieldDescriptor) iter.next();
2803 String locAnnotationStr;
2804 // CompositeLocation inferLoc = inferLocMap.get(fd);
2805 String locName = mapFieldNameToLocName.get(fd.getSymbol());
2807 if (locName != null) {
2808 // infer loc is null if the corresponding field is static and final
2809 // locAnnotationStr = "@LOC(\"" + generateLocationAnnoatation(inferLoc) + "\")";
2810 locAnnotationStr = "@LOC(\"" + locName + "\")";
2811 int fdLineNum = fd.getLineNum();
2812 String orgFieldDeclarationStr = sourceVec.get(fdLineNum);
2813 String fieldDeclaration = fd.toString();
2814 fieldDeclaration = fieldDeclaration.substring(0, fieldDeclaration.length() - 1);
2815 String annoatedStr = locAnnotationStr + " " + orgFieldDeclarationStr;
2816 sourceVec.set(fdLineNum, annoatedStr);
2821 while (!toAnalyzeMethodIsEmpty()) {
2822 MethodDescriptor md = toAnalyzeMethodNext();
2824 if (!ssjava.needTobeAnnotated(md)) {
2828 SSJavaLattice<String> methodLattice = md2lattice.get(md);
2829 if (methodLattice != null) {
2831 int methodDefLine = md.getLineNum();
2833 // MethodLocationInfo methodLocInfo = getMethodLocationInfo(md);
2834 // Map<Descriptor, CompositeLocation> methodInferLocMap =
2835 // methodLocInfo.getMapDescToInferLocation();
2837 MethodSummary methodSummary = getMethodSummary(md);
2839 Map<Descriptor, CompositeLocation> mapVarDescToInferLoc =
2840 methodSummary.getMapVarDescToInferCompositeLocation();
2841 System.out.println("-----md=" + md);
2842 System.out.println("-----mapVarDescToInferLoc=" + mapVarDescToInferLoc);
2844 Set<Descriptor> localVarDescSet = mapVarDescToInferLoc.keySet();
2846 Set<String> localLocElementSet = methodLattice.getElementSet();
2848 for (Iterator iterator = localVarDescSet.iterator(); iterator.hasNext();) {
2849 Descriptor localVarDesc = (Descriptor) iterator.next();
2850 System.out.println("-------localVarDesc=" + localVarDesc);
2851 CompositeLocation inferLoc = mapVarDescToInferLoc.get(localVarDesc);
2853 String localLocIdentifier = inferLoc.get(0).getLocIdentifier();
2854 if (!localLocElementSet.contains(localLocIdentifier)) {
2855 methodLattice.put(localLocIdentifier);
2858 String locAnnotationStr = "@LOC(\"" + generateLocationAnnoatation(inferLoc) + "\")";
2860 if (!isParameter(md, localVarDesc)) {
2861 if (mapDescToDefinitionLine.containsKey(localVarDesc)) {
2862 int varLineNum = mapDescToDefinitionLine.get(localVarDesc);
2863 String orgSourceLine = sourceVec.get(varLineNum);
2864 System.out.println("varLineNum=" + varLineNum + " org src=" + orgSourceLine);
2866 orgSourceLine.indexOf(generateVarDeclaration((VarDescriptor) localVarDesc));
2867 System.out.println("idx=" + idx
2868 + " generateVarDeclaration((VarDescriptor) localVarDesc)="
2869 + generateVarDeclaration((VarDescriptor) localVarDesc));
2871 String annoatedStr =
2872 orgSourceLine.substring(0, idx) + locAnnotationStr + " "
2873 + orgSourceLine.substring(idx);
2874 sourceVec.set(varLineNum, annoatedStr);
2877 String methodDefStr = sourceVec.get(methodDefLine);
2880 getParamLocation(methodDefStr,
2881 generateVarDeclaration((VarDescriptor) localVarDesc));
2882 System.out.println("methodDefStr=" + methodDefStr + " localVarDesc=" + localVarDesc
2886 String annoatedStr =
2887 methodDefStr.substring(0, idx) + locAnnotationStr + " "
2888 + methodDefStr.substring(idx);
2889 sourceVec.set(methodDefLine, annoatedStr);
2894 // check if the lattice has to have the location type for the this
2897 // boolean needToAddthisRef = hasThisReference(md);
2898 // if (localLocElementSet.contains("this")) {
2899 // methodLattice.put("this");
2902 String methodLatticeDefStr = generateLatticeDefinition(md);
2903 String annoatedStr = methodLatticeDefStr + newline + sourceVec.get(methodDefLine);
2904 sourceVec.set(methodDefLine, annoatedStr);
2914 private boolean hasThisReference(MethodDescriptor md) {
2916 FlowGraph fg = getFlowGraph(md);
2917 Set<FlowNode> nodeSet = fg.getNodeSet();
2918 for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
2919 FlowNode flowNode = (FlowNode) iterator.next();
2920 if (flowNode.getDescTuple().get(0).equals(md.getThis())) {
2928 private int getParamLocation(String methodStr, String paramStr) {
2930 String pattern = paramStr + ",";
2932 int idx = methodStr.indexOf(pattern);
2936 pattern = paramStr + ")";
2937 return methodStr.indexOf(pattern);
2942 private String generateVarDeclaration(VarDescriptor varDesc) {
2944 TypeDescriptor td = varDesc.getType();
2945 String rtr = td.toString();
2947 for (int i = 0; i < td.getArrayCount(); i++) {
2951 rtr += " " + varDesc.getName();
2956 private String generateLocationAnnoatation(CompositeLocation loc) {
2959 Location methodLoc = loc.get(0);
2960 rtr += methodLoc.getLocIdentifier();
2962 for (int i = 1; i < loc.getSize(); i++) {
2963 Location element = loc.get(i);
2964 rtr += "," + element.getDescriptor().getSymbol() + "." + element.getLocIdentifier();
2970 private boolean isParameter(MethodDescriptor md, Descriptor localVarDesc) {
2971 return getFlowGraph(md).isParamDesc(localVarDesc);
2974 private String extractFileName(String fileName) {
2975 int idx = fileName.lastIndexOf("/");
2979 return fileName.substring(idx + 1);
2984 private void codeGen() {
2986 Set<String> originalFileNameSet = mapFileNameToLineVector.keySet();
2987 for (Iterator iterator = originalFileNameSet.iterator(); iterator.hasNext();) {
2988 String orgFileName = (String) iterator.next();
2989 String outputFileName = extractFileName(orgFileName);
2991 Vector<String> sourceVec = mapFileNameToLineVector.get(orgFileName);
2995 FileWriter fileWriter = new FileWriter("./infer/" + outputFileName);
2996 BufferedWriter out = new BufferedWriter(fileWriter);
2998 for (int i = 0; i < sourceVec.size(); i++) {
2999 out.write(sourceVec.get(i));
3003 } catch (IOException e) {
3004 e.printStackTrace();
3011 private void checkLattices() {
3013 LinkedList<MethodDescriptor> descriptorListToAnalyze = ssjava.getSortedDescriptors();
3015 // current descriptors to visit in fixed-point interprocedural analysis,
3017 // dependency in the call graph
3018 methodDescriptorsToVisitStack.clear();
3020 // descriptorListToAnalyze.removeFirst();
3022 Set<MethodDescriptor> methodDescriptorToVistSet = new HashSet<MethodDescriptor>();
3023 methodDescriptorToVistSet.addAll(descriptorListToAnalyze);
3025 while (!descriptorListToAnalyze.isEmpty()) {
3026 MethodDescriptor md = descriptorListToAnalyze.removeFirst();
3027 checkLatticesOfVirtualMethods(md);
3032 private void debug_writeLatticeDotFile() {
3033 // generate lattice dot file
3037 while (!toAnalyzeIsEmpty()) {
3038 ClassDescriptor cd = toAnalyzeNext();
3040 setupToAnalazeMethod(cd);
3042 SSJavaLattice<String> classLattice = cd2lattice.get(cd);
3043 if (classLattice != null) {
3044 ssjava.writeLatticeDotFile(cd, null, classLattice);
3045 debug_printDescriptorToLocNameMapping(cd);
3048 while (!toAnalyzeMethodIsEmpty()) {
3049 MethodDescriptor md = toAnalyzeMethodNext();
3050 SSJavaLattice<String> methodLattice = md2lattice.get(md);
3051 if (methodLattice != null) {
3052 ssjava.writeLatticeDotFile(cd, md, methodLattice);
3053 debug_printDescriptorToLocNameMapping(md);
3060 private void debug_printDescriptorToLocNameMapping(Descriptor desc) {
3062 LocationInfo info = getLocationInfo(desc);
3063 System.out.println("## " + desc + " ##");
3064 System.out.println(info.getMapDescToInferLocation());
3065 LocationInfo locInfo = getLocationInfo(desc);
3066 System.out.println("mapping=" + locInfo.getMapLocSymbolToDescSet());
3067 System.out.println("###################");
3071 private void calculateExtraLocations() {
3073 LinkedList<MethodDescriptor> methodDescList = ssjava.getSortedDescriptors();
3074 for (Iterator iterator = methodDescList.iterator(); iterator.hasNext();) {
3075 MethodDescriptor md = (MethodDescriptor) iterator.next();
3076 if (!ssjava.getMethodContainingSSJavaLoop().equals(md)) {
3077 calculateExtraLocations(md);
3083 private void checkLatticesOfVirtualMethods(MethodDescriptor md) {
3085 if (!md.isStatic()) {
3086 Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
3087 setPossibleCallees.addAll(ssjava.getCallGraph().getMethods(md));
3089 for (Iterator iterator = setPossibleCallees.iterator(); iterator.hasNext();) {
3090 MethodDescriptor mdCallee = (MethodDescriptor) iterator.next();
3091 if (!md.equals(mdCallee)) {
3092 checkConsistency(md, mdCallee);
3100 private void checkConsistency(MethodDescriptor md1, MethodDescriptor md2) {
3102 // check that two lattice have the same relations between parameters(+PC
3103 // LOC, GLOBAL_LOC RETURN LOC)
3105 List<CompositeLocation> list1 = new ArrayList<CompositeLocation>();
3106 List<CompositeLocation> list2 = new ArrayList<CompositeLocation>();
3108 MethodLocationInfo locInfo1 = getMethodLocationInfo(md1);
3109 MethodLocationInfo locInfo2 = getMethodLocationInfo(md2);
3111 Map<Integer, CompositeLocation> paramMap1 = locInfo1.getMapParamIdxToInferLoc();
3112 Map<Integer, CompositeLocation> paramMap2 = locInfo2.getMapParamIdxToInferLoc();
3114 int numParam = locInfo1.getMapParamIdxToInferLoc().keySet().size();
3116 // add location types of paramters
3117 for (int idx = 0; idx < numParam; idx++) {
3118 list1.add(paramMap1.get(Integer.valueOf(idx)));
3119 list2.add(paramMap2.get(Integer.valueOf(idx)));
3122 // add program counter location
3123 list1.add(locInfo1.getPCLoc());
3124 list2.add(locInfo2.getPCLoc());
3126 if (!md1.getReturnType().isVoid()) {
3127 // add return value location
3128 CompositeLocation rtrLoc1 = getMethodLocationInfo(md1).getReturnLoc();
3129 CompositeLocation rtrLoc2 = getMethodLocationInfo(md2).getReturnLoc();
3134 // add global location type
3135 if (md1.isStatic()) {
3136 CompositeLocation globalLoc1 =
3137 new CompositeLocation(new Location(md1, locInfo1.getGlobalLocName()));
3138 CompositeLocation globalLoc2 =
3139 new CompositeLocation(new Location(md2, locInfo2.getGlobalLocName()));
3140 list1.add(globalLoc1);
3141 list2.add(globalLoc2);
3144 for (int i = 0; i < list1.size(); i++) {
3145 CompositeLocation locA1 = list1.get(i);
3146 CompositeLocation locA2 = list2.get(i);
3147 for (int k = 0; k < list1.size(); k++) {
3149 CompositeLocation locB1 = list1.get(k);
3150 CompositeLocation locB2 = list2.get(k);
3151 boolean r1 = isGreaterThan(getLattice(md1), locA1, locB1);
3153 boolean r2 = isGreaterThan(getLattice(md1), locA2, locB2);
3156 throw new Error("The method " + md1 + " is not consistent with the method " + md2
3157 + ".:: They have a different ordering relation between locations (" + locA1 + ","
3158 + locB1 + ") and (" + locA2 + "," + locB2 + ").");
3166 private String getSymbol(int idx, FlowNode node) {
3167 Descriptor desc = node.getDescTuple().get(idx);
3168 return desc.getSymbol();
3171 private Descriptor getDescriptor(int idx, FlowNode node) {
3172 Descriptor desc = node.getDescTuple().get(idx);
3176 private void calculatePCLOC(MethodDescriptor md) {
3178 System.out.println("#CalculatePCLOC");
3179 MethodSummary methodSummary = getMethodSummary(md);
3180 FlowGraph fg = getFlowGraph(md);
3181 Map<Integer, CompositeLocation> mapParamToLoc = methodSummary.getMapParamIdxToInferLoc();
3183 // calculate the initial program counter location
3184 // PC location is higher than location types of parameters which has incoming flows.
3186 Set<NTuple<Location>> paramLocTupleHavingInFlowSet = new HashSet<NTuple<Location>>();
3187 Set<Descriptor> paramDescNOTHavingInFlowSet = new HashSet<Descriptor>();
3188 // Set<FlowNode> paramNodeNOThavingInFlowSet = new HashSet<FlowNode>();
3190 int numParams = fg.getNumParameters();
3191 for (int i = 0; i < numParams; i++) {
3192 FlowNode paramFlowNode = fg.getParamFlowNode(i);
3193 Descriptor prefix = paramFlowNode.getDescTuple().get(0);
3194 NTuple<Descriptor> paramDescTuple = paramFlowNode.getCurrentDescTuple();
3195 NTuple<Location> paramLocTuple = translateToLocTuple(md, paramDescTuple);
3197 Set<FlowNode> inNodeToParamSet = fg.getIncomingNodeSetByPrefix(prefix);
3198 if (inNodeToParamSet.size() > 0) {
3199 // parameter has in-value flows
3201 for (Iterator iterator = inNodeToParamSet.iterator(); iterator.hasNext();) {
3202 FlowNode inNode = (FlowNode) iterator.next();
3203 Set<FlowEdge> outEdgeSet = fg.getOutEdgeSet(inNode);
3204 for (Iterator iterator2 = outEdgeSet.iterator(); iterator2.hasNext();) {
3205 FlowEdge flowEdge = (FlowEdge) iterator2.next();
3206 if (flowEdge.getEndTuple().startsWith(prefix)) {
3207 NTuple<Location> paramLocTupleWithIncomingFlow =
3208 translateToLocTuple(md, flowEdge.getEndTuple());
3209 paramLocTupleHavingInFlowSet.add(paramLocTupleWithIncomingFlow);
3214 // paramLocTupleHavingInFlowSet.add(paramLocTuple);
3216 // paramNodeNOThavingInFlowSet.add(fg.getFlowNode(paramDescTuple));
3217 paramDescNOTHavingInFlowSet.add(prefix);
3221 System.out.println("paramLocTupleHavingInFlowSet=" + paramLocTupleHavingInFlowSet);
3223 if (paramLocTupleHavingInFlowSet.size() > 0
3224 && !coversAllParamters(md, fg, paramLocTupleHavingInFlowSet)) {
3226 // Here, generates a location in the method lattice that is higher than the
3227 // paramLocTupleHavingInFlowSet
3228 NTuple<Location> pcLocTuple =
3229 generateLocTupleRelativeTo(md, paramLocTupleHavingInFlowSet, PCLOC);
3231 NTuple<Descriptor> pcDescTuple = translateToDescTuple(pcLocTuple);
3233 // System.out.println("pcLoc=" + pcLocTuple);
3235 CompositeLocation curPCLoc = methodSummary.getPCLoc();
3236 if (curPCLoc.get(0).isTop() || pcLocTuple.size() > curPCLoc.getSize()) {
3237 methodSummary.setPCLoc(new CompositeLocation(pcLocTuple));
3239 Set<FlowNode> flowNodeLowerthanPCLocSet = new HashSet<FlowNode>();
3240 GlobalFlowGraph subGlobalFlowGraph = getSubGlobalFlowGraph(md);
3241 // add ordering relations s.t. PCLOC is higher than all flow nodes except the set of
3242 // parameters that do not have incoming flows
3243 for (Iterator iterator = fg.getNodeSet().iterator(); iterator.hasNext();) {
3244 FlowNode node = (FlowNode) iterator.next();
3246 if (!(node instanceof FlowReturnNode)) {
3247 if (!paramDescNOTHavingInFlowSet.contains(node.getCurrentDescTuple().get(0))) {
3248 flowNodeLowerthanPCLocSet.add(node);
3249 fg.addValueFlowEdge(pcDescTuple, node.getDescTuple());
3251 subGlobalFlowGraph.addValueFlowEdge(pcLocTuple,
3252 translateToLocTuple(md, node.getDescTuple()));
3255 System.out.println("***SKIP PCLOC -> RETURNLOC=" + node);
3259 fg.getFlowNode(translateToDescTuple(pcLocTuple)).setSkeleton(true);
3261 if (pcLocTuple.get(0).getLocDescriptor().equals(md.getThis())) {
3262 System.out.println("#########################################");
3263 for (Iterator iterator = flowNodeLowerthanPCLocSet.iterator(); iterator.hasNext();) {
3264 FlowNode lowerNode = (FlowNode) iterator.next();
3265 if (lowerNode.getDescTuple().size() == 1 && lowerNode.getCompositeLocation() == null) {
3266 NTuple<Location> lowerLocTuple = translateToLocTuple(md, lowerNode.getDescTuple());
3267 CompositeLocation newComp =
3268 calculateCompositeLocationFromSubGlobalGraph(md, lowerNode);
3269 if (newComp != null) {
3270 subGlobalFlowGraph.addMapLocationToInferCompositeLocation(lowerLocTuple.get(0),
3272 lowerNode.setCompositeLocation(newComp);
3273 System.out.println("NEW COMP LOC=" + newComp + " to lowerNode=" + lowerNode);
3286 private int countFirstDescriptorSetSize(Set<NTuple<Location>> set) {
3288 Set<Descriptor> descSet = new HashSet<Descriptor>();
3290 for (Iterator iterator = set.iterator(); iterator.hasNext();) {
3291 NTuple<Location> locTuple = (NTuple<Location>) iterator.next();
3292 descSet.add(locTuple.get(0).getLocDescriptor());
3295 return descSet.size();
3298 private boolean coversAllParamters(MethodDescriptor md, FlowGraph fg,
3299 Set<NTuple<Location>> paramLocTupleHavingInFlowSet) {
3301 int numParam = fg.getNumParameters();
3302 // int size = paramLocTupleHavingInFlowSet.size();
3303 int size = countFirstDescriptorSetSize(paramLocTupleHavingInFlowSet);
3305 // if (!md.isStatic()) {
3307 // // if the method is not static && there is a parameter composite location &&
3308 // // it is started with 'this',
3309 // // paramLocTupleHavingInFlowSet need to have 'this' parameter.
3311 // FlowNode thisParamNode = fg.getParamFlowNode(0);
3312 // NTuple<Location> thisParamLocTuple =
3313 // translateToLocTuple(md, thisParamNode.getCurrentDescTuple());
3315 // if (!paramLocTupleHavingInFlowSet.contains(thisParamLocTuple)) {
3317 // for (Iterator iterator = paramLocTupleHavingInFlowSet.iterator(); iterator.hasNext();) {
3318 // NTuple<Location> paramTuple = (NTuple<Location>) iterator.next();
3319 // if (paramTuple.size() > 1 && paramTuple.get(0).getLocDescriptor().equals(md.getThis())) {
3320 // // paramLocTupleHavingInFlowSet.add(thisParamLocTuple);
3329 if (size == numParam) {
3337 private void calculateRETURNLOC(MethodDescriptor md) {
3339 System.out.println("#calculateRETURNLOC= " + md);
3341 // calculate a return location:
3342 // the return location type is lower than all parameters and the location of return values
3343 MethodSummary methodSummary = getMethodSummary(md);
3344 // if (methodSummary.getRETURNLoc() != null) {
3345 // System.out.println("$HERE?");
3349 FlowGraph fg = getFlowGraph(md);
3350 Map<Integer, CompositeLocation> mapParamToLoc = methodSummary.getMapParamIdxToInferLoc();
3351 Set<Integer> paramIdxSet = mapParamToLoc.keySet();
3353 if (md.getReturnType() != null && !md.getReturnType().isVoid()) {
3354 // first, generate the set of return value location types that starts
3355 // with 'this' reference
3357 Set<FlowNode> paramFlowNodeFlowingToReturnValueSet = getParamNodeFlowingToReturnValue(md);
3358 // System.out.println("paramFlowNodeFlowingToReturnValueSet="
3359 // + paramFlowNodeFlowingToReturnValueSet);
3361 Set<NTuple<Location>> tupleToBeHigherThanReturnLocSet = new HashSet<NTuple<Location>>();
3362 for (Iterator iterator = paramFlowNodeFlowingToReturnValueSet.iterator(); iterator.hasNext();) {
3363 FlowNode fn = (FlowNode) iterator.next();
3364 NTuple<Descriptor> paramDescTuple = fn.getCurrentDescTuple();
3365 tupleToBeHigherThanReturnLocSet.add(translateToLocTuple(md, paramDescTuple));
3368 Set<FlowNode> returnNodeSet = fg.getReturnNodeSet();
3369 for (Iterator iterator = returnNodeSet.iterator(); iterator.hasNext();) {
3370 FlowNode returnNode = (FlowNode) iterator.next();
3371 NTuple<Descriptor> returnDescTuple = returnNode.getCurrentDescTuple();
3372 tupleToBeHigherThanReturnLocSet.add(translateToLocTuple(md, returnDescTuple));
3374 System.out.println("-flow graph's returnNodeSet=" + returnNodeSet);
3375 System.out.println("tupleSetToBeHigherThanReturnLoc=" + tupleToBeHigherThanReturnLocSet);
3377 // Here, generates a return location in the method lattice that is lower than the
3378 // locFlowingToReturnValueSet
3379 NTuple<Location> returnLocTuple =
3380 generateLocTupleRelativeTo(md, tupleToBeHigherThanReturnLocSet, RLOC);
3382 // System.out.println("returnLocTuple=" + returnLocTuple);
3383 NTuple<Descriptor> returnDescTuple = translateToDescTuple(returnLocTuple);
3384 CompositeLocation curReturnLoc = methodSummary.getRETURNLoc();
3385 if (curReturnLoc == null || returnDescTuple.size() > curReturnLoc.getSize()) {
3386 methodSummary.setRETURNLoc(new CompositeLocation(returnLocTuple));
3388 for (Iterator iterator = tupleToBeHigherThanReturnLocSet.iterator(); iterator.hasNext();) {
3389 NTuple<Location> higherTuple = (NTuple<Location>) iterator.next();
3390 fg.addValueFlowEdge(translateToDescTuple(higherTuple), returnDescTuple);
3392 fg.getFlowNode(returnDescTuple).setSkeleton(true);
3396 // makes sure that PCLOC is higher than RETURNLOC
3397 CompositeLocation pcLoc = methodSummary.getPCLoc();
3398 if (!pcLoc.get(0).isTop()) {
3399 NTuple<Descriptor> pcLocDescTuple = translateToDescTuple(pcLoc.getTuple());
3400 fg.addValueFlowEdge(pcLocDescTuple, returnDescTuple);
3407 private void calculateExtraLocations(MethodDescriptor md) {
3408 // calcualte pcloc, returnloc,...
3410 System.out.println("\nSSJAVA:Calculate PCLOC/RETURNLOC locations: " + md);
3413 calculateRETURNLOC(md);
3417 private NTuple<Location> generateLocTupleRelativeTo(MethodDescriptor md,
3418 Set<NTuple<Location>> paramLocTupleHavingInFlowSet, String locNamePrefix) {
3420 // System.out.println("-generateLocTupleRelativeTo=" + paramLocTupleHavingInFlowSet);
3422 NTuple<Location> higherLocTuple = new NTuple<Location>();
3424 VarDescriptor thisVarDesc = md.getThis();
3425 // check if all paramter loc tuple is started with 'this' reference
3426 boolean hasParamNotStartedWithThisRef = false;
3430 Set<NTuple<Location>> paramLocTupleStartedWithThis = new HashSet<NTuple<Location>>();
3432 next: for (Iterator iterator = paramLocTupleHavingInFlowSet.iterator(); iterator.hasNext();) {
3433 NTuple<Location> paramLocTuple = (NTuple<Location>) iterator.next();
3434 Descriptor paramLocalDesc = paramLocTuple.get(0).getLocDescriptor();
3435 if (!paramLocalDesc.equals(thisVarDesc)) {
3437 Set<FlowNode> inNodeSet = getFlowGraph(md).getIncomingNodeSetByPrefix(paramLocalDesc);
3438 for (Iterator iterator2 = inNodeSet.iterator(); iterator2.hasNext();) {
3439 FlowNode flowNode = (FlowNode) iterator2.next();
3440 if (flowNode.getDescTuple().startsWith(thisVarDesc)) {
3441 // System.out.println("paramLocTuple=" + paramLocTuple + " is lower than THIS");
3445 hasParamNotStartedWithThisRef = true;
3447 } else if (paramLocTuple.size() > 1) {
3448 paramLocTupleStartedWithThis.add(paramLocTuple);
3449 if (minSize == 0 || minSize > paramLocTuple.size()) {
3450 minSize = paramLocTuple.size();
3455 // System.out.println("---paramLocTupleStartedWithThis=" + paramLocTupleStartedWithThis);
3456 Descriptor enclosingDesc = md;
3457 if (hasParamNotStartedWithThisRef) {
3458 // in this case, PCLOC will be the local location
3460 // all parameter is started with 'this', so PCLOC will be set relative to the composite
3461 // location started with 'this'.
3462 // for (int idx = 0; idx < minSize - 1; idx++) {
3463 for (int idx = 0; idx < 1; idx++) {
3464 Set<Descriptor> locDescSet = new HashSet<Descriptor>();
3465 Location curLoc = null;
3466 NTuple<Location> paramLocTuple = null;
3467 for (Iterator iterator = paramLocTupleStartedWithThis.iterator(); iterator.hasNext();) {
3468 paramLocTuple = (NTuple<Location>) iterator.next();
3469 // System.out.println("-----paramLocTuple=" + paramLocTuple + " idx=" + idx);
3470 curLoc = paramLocTuple.get(idx);
3471 Descriptor locDesc = curLoc.getLocDescriptor();
3472 locDescSet.add(locDesc);
3474 // System.out.println("-----locDescSet=" + locDescSet + " idx=" + idx);
3475 if (locDescSet.size() != 1) {
3478 Location newLocElement = new Location(curLoc.getDescriptor(), curLoc.getLocDescriptor());
3479 System.out.println("newLocElement" + newLocElement);
3480 higherLocTuple.add(newLocElement);
3481 enclosingDesc = getClassTypeDescriptor(curLoc.getLocDescriptor());
3486 String locIdentifier = locNamePrefix + (locSeed++);
3487 NameDescriptor locDesc = new NameDescriptor(locIdentifier);
3488 Location newLoc = new Location(enclosingDesc, locDesc);
3489 higherLocTuple.add(newLoc);
3490 System.out.println("---new loc tuple=" + higherLocTuple);
3492 return higherLocTuple;
3496 public ClassDescriptor getClassTypeDescriptor(Descriptor in) {
3498 if (in instanceof VarDescriptor) {
3499 return ((VarDescriptor) in).getType().getClassDesc();
3500 } else if (in instanceof FieldDescriptor) {
3501 return ((FieldDescriptor) in).getType().getClassDesc();
3503 // else if (in instanceof LocationDescriptor) {
3504 // // here is the case that the descriptor 'in' is the last element of the assigned composite
3506 // return ((VarDescriptor) locTuple.get(0).getLocDescriptor()).getType().getClassDesc();
3514 private Set<NTuple<Location>> calculateHighestLocTupleSet(
3515 Set<NTuple<Location>> paramLocTupleHavingInFlowSet) {
3517 Set<NTuple<Location>> highestSet = new HashSet<NTuple<Location>>();
3519 Iterator<NTuple<Location>> iterator = paramLocTupleHavingInFlowSet.iterator();
3520 NTuple<Location> highest = iterator.next();
3522 for (; iterator.hasNext();) {
3523 NTuple<Location> curLocTuple = (NTuple<Location>) iterator.next();
3524 if (isHigherThan(curLocTuple, highest)) {
3525 // System.out.println(curLocTuple + " is greater than " + highest);
3526 highest = curLocTuple;
3530 highestSet.add(highest);
3532 MethodDescriptor md = (MethodDescriptor) highest.get(0).getDescriptor();
3533 VarDescriptor thisVarDesc = md.getThis();
3535 // System.out.println("highest=" + highest);
3537 for (Iterator<NTuple<Location>> iter = paramLocTupleHavingInFlowSet.iterator(); iter.hasNext();) {
3538 NTuple<Location> curLocTuple = iter.next();
3540 if (!curLocTuple.equals(highest) && !hasOrderingRelation(highest, curLocTuple)) {
3542 // System.out.println("add it to the highest set=" + curLocTuple);
3543 highestSet.add(curLocTuple);
3552 private Set<String> getHigherLocSymbolThan(SSJavaLattice<String> lattice, String loc) {
3553 Set<String> higherLocSet = new HashSet<String>();
3555 Set<String> locSet = lattice.getTable().keySet();
3556 for (Iterator iterator = locSet.iterator(); iterator.hasNext();) {
3557 String element = (String) iterator.next();
3558 if (lattice.isGreaterThan(element, loc) && (!element.equals(lattice.getTopItem()))) {
3559 higherLocSet.add(element);
3562 return higherLocSet;
3565 private CompositeLocation getLowest(SSJavaLattice<String> methodLattice,
3566 Set<CompositeLocation> set) {
3568 CompositeLocation lowest = set.iterator().next();
3570 if (set.size() == 1) {
3574 for (Iterator iterator = set.iterator(); iterator.hasNext();) {
3575 CompositeLocation loc = (CompositeLocation) iterator.next();
3577 if ((!loc.equals(lowest)) && (!isComparable(methodLattice, lowest, loc))) {
3578 // if there is a case where composite locations are incomparable, just
3583 if ((!loc.equals(lowest)) && isGreaterThan(methodLattice, lowest, loc)) {
3590 private boolean isComparable(SSJavaLattice<String> methodLattice, CompositeLocation comp1,
3591 CompositeLocation comp2) {
3593 int size = comp1.getSize() >= comp2.getSize() ? comp2.getSize() : comp1.getSize();
3595 for (int idx = 0; idx < size; idx++) {
3596 Location loc1 = comp1.get(idx);
3597 Location loc2 = comp2.get(idx);
3599 Descriptor desc1 = loc1.getDescriptor();
3600 Descriptor desc2 = loc2.getDescriptor();
3602 if (!desc1.equals(desc2)) {
3603 throw new Error("Fail to compare " + comp1 + " and " + comp2);
3606 String symbol1 = loc1.getLocIdentifier();
3607 String symbol2 = loc2.getLocIdentifier();
3609 SSJavaLattice<String> lattice;
3611 lattice = methodLattice;
3613 lattice = getLattice(desc1);
3616 if (symbol1.equals(symbol2)) {
3618 } else if (!lattice.isComparable(symbol1, symbol2)) {
3627 private boolean isGreaterThan(SSJavaLattice<String> methodLattice, CompositeLocation comp1,
3628 CompositeLocation comp2) {
3630 int size = comp1.getSize() >= comp2.getSize() ? comp2.getSize() : comp1.getSize();
3632 for (int idx = 0; idx < size; idx++) {
3633 Location loc1 = comp1.get(idx);
3634 Location loc2 = comp2.get(idx);
3636 Descriptor desc1 = loc1.getDescriptor();
3637 Descriptor desc2 = loc2.getDescriptor();
3639 if (!desc1.equals(desc2)) {
3640 throw new Error("Fail to compare " + comp1 + " and " + comp2);
3643 String symbol1 = loc1.getLocIdentifier();
3644 String symbol2 = loc2.getLocIdentifier();
3646 SSJavaLattice<String> lattice;
3648 lattice = methodLattice;
3650 lattice = getLattice(desc1);
3653 if (symbol1.equals(symbol2)) {
3655 } else if (lattice.isGreaterThan(symbol1, symbol2)) {
3666 private GlobalFlowGraph getSubGlobalFlowGraph(MethodDescriptor md) {
3668 if (!mapMethodDescriptorToSubGlobalFlowGraph.containsKey(md)) {
3669 mapMethodDescriptorToSubGlobalFlowGraph.put(md, new GlobalFlowGraph(md));
3671 return mapMethodDescriptorToSubGlobalFlowGraph.get(md);
3674 private void propagateFlowsToCallerWithNoCompositeLocation(MethodInvokeNode min,
3675 MethodDescriptor mdCaller, MethodDescriptor mdCallee) {
3677 System.out.println("-propagateFlowsToCallerWithNoCompositeLocation=" + min.printNode(0));
3678 // if the parameter A reaches to the parameter B
3679 // then, add an edge the argument A -> the argument B to the caller's flow
3682 FlowGraph calleeFlowGraph = getFlowGraph(mdCallee);
3683 FlowGraph callerFlowGraph = getFlowGraph(mdCaller);
3684 int numParam = calleeFlowGraph.getNumParameters();
3686 for (int i = 0; i < numParam; i++) {
3687 for (int k = 0; k < numParam; k++) {
3691 FlowNode paramNode1 = calleeFlowGraph.getParamFlowNode(i);
3692 FlowNode paramNode2 = calleeFlowGraph.getParamFlowNode(k);
3694 NTuple<Descriptor> arg1Tuple = getNodeTupleByArgIdx(min, i);
3695 NTuple<Descriptor> arg2Tuple = getNodeTupleByArgIdx(min, k);
3697 // check if the callee propagates an ordering constraints through
3700 // Set<FlowNode> localReachSet = calleeFlowGraph.getLocalReachFlowNodeSetFrom(paramNode1);
3701 Set<FlowNode> localReachSet =
3702 calleeFlowGraph.getReachableSetFrom(paramNode1.getDescTuple());
3704 NTuple<Descriptor> paramDescTuple1 = paramNode1.getCurrentDescTuple();
3705 NTuple<Descriptor> paramDescTuple2 = paramNode2.getCurrentDescTuple();
3707 // System.out.println("-param1CurTuple=" + paramDescTuple1 + " param2CurTuple="
3708 // + paramDescTuple2);
3709 // System.out.println("-- localReachSet from param1=" + localReachSet);
3711 if (paramDescTuple1.get(0).equals(paramDescTuple2.get(0))) {
3712 // if two parameters share the same prefix
3713 // it already has been assigned to a composite location
3714 // so we don't need to add an additional ordering relation caused by these two
3719 if (arg1Tuple.size() > 0 && arg2Tuple.size() > 0
3720 && containsPrefix(paramNode2.getDescTuple().get(0), localReachSet)) {
3721 // need to propagate an ordering relation s.t. arg1 is higher
3723 // System.out.println("-param1=" + paramNode1 + " is higher than param2=" + paramNode2);
3725 // add a new flow between the corresponding arguments.
3726 callerFlowGraph.addValueFlowEdge(arg1Tuple, arg2Tuple);
3727 // System.out.println("arg1=" + arg1Tuple + " arg2=" + arg2Tuple);
3730 // .println("-arg1Tuple=" + arg1Tuple + " is higher than arg2Tuple=" + arg2Tuple);
3734 // System.out.println();
3739 // if a parameter has a composite location and the first element of the parameter location
3740 // matches the callee's 'this'
3741 // we have a more specific constraint: the caller's corresponding argument is higher than the
3742 // parameter location which is translated into the caller
3744 for (int idx = 0; idx < numParam; idx++) {
3745 FlowNode paramNode = calleeFlowGraph.getParamFlowNode(idx);
3746 CompositeLocation compLoc = paramNode.getCompositeLocation();
3747 System.out.println("paramNode=" + paramNode + " compLoc=" + compLoc);
3748 if (compLoc != null && compLoc.get(0).getLocDescriptor().equals(min.getMethod().getThis())) {
3749 System.out.println("$$$COMPLOC CASE=" + compLoc + " idx=" + idx);
3751 NTuple<Descriptor> argTuple = getNodeTupleByArgIdx(min, idx);
3752 System.out.println("--- argTuple=" + argTuple + " current compLoc="
3753 + callerFlowGraph.getFlowNode(argTuple).getCompositeLocation());
3755 NTuple<Descriptor> translatedParamTuple =
3756 translateCompositeLocationToCaller(idx, min, compLoc);
3757 System.out.println("add a flow edge= " + argTuple + "->" + translatedParamTuple);
3758 callerFlowGraph.addValueFlowEdge(argTuple, translatedParamTuple);
3760 Set<NTuple<Location>> pcLocTupleSet = getPCLocTupleSet(min);
3761 for (Iterator iterator = pcLocTupleSet.iterator(); iterator.hasNext();) {
3762 NTuple<Location> pcLocTuple = (NTuple<Location>) iterator.next();
3763 callerFlowGraph.addValueFlowEdge(translateToDescTuple(pcLocTuple), translatedParamTuple);
3771 private boolean containsPrefix(Descriptor prefixDesc, Set<FlowNode> set) {
3773 for (Iterator iterator = set.iterator(); iterator.hasNext();) {
3774 FlowNode flowNode = (FlowNode) iterator.next();
3775 if (flowNode.getDescTuple().startsWith(prefixDesc)) {
3776 System.out.println("FOUND=" + flowNode);
3783 private NTuple<Descriptor> translateCompositeLocationToCaller(int idx, MethodInvokeNode min,
3784 CompositeLocation compLocForParam1) {
3786 NTuple<Descriptor> baseTuple = mapMethodInvokeNodeToBaseTuple.get(min);
3788 NTuple<Descriptor> tuple = new NTuple<Descriptor>();
3789 for (int i = 0; i < baseTuple.size(); i++) {
3790 tuple.add(baseTuple.get(i));
3793 for (int i = 1; i < compLocForParam1.getSize(); i++) {
3794 Location loc = compLocForParam1.get(i);
3795 tuple.add(loc.getLocDescriptor());
3801 private CompositeLocation generateCompositeLocation(NTuple<Location> prefixLocTuple) {
3803 System.out.println("generateCompositeLocation=" + prefixLocTuple);
3805 CompositeLocation newCompLoc = new CompositeLocation();
3806 for (int i = 0; i < prefixLocTuple.size(); i++) {
3807 newCompLoc.addLocation(prefixLocTuple.get(i));
3810 Descriptor lastDescOfPrefix = prefixLocTuple.get(prefixLocTuple.size() - 1).getLocDescriptor();
3812 ClassDescriptor enclosingDescriptor;
3813 if (lastDescOfPrefix instanceof FieldDescriptor) {
3814 enclosingDescriptor = ((FieldDescriptor) lastDescOfPrefix).getType().getClassDesc();
3815 // System.out.println("enclosingDescriptor0=" + enclosingDescriptor);
3816 } else if (lastDescOfPrefix.equals(GLOBALDESC)) {
3817 MethodDescriptor currentMethodDesc = (MethodDescriptor) prefixLocTuple.get(0).getDescriptor();
3818 enclosingDescriptor = currentMethodDesc.getClassDesc();
3820 // var descriptor case
3821 enclosingDescriptor = ((VarDescriptor) lastDescOfPrefix).getType().getClassDesc();
3823 // System.out.println("enclosingDescriptor=" + enclosingDescriptor);
3825 LocationDescriptor newLocDescriptor = generateNewLocationDescriptor();
3826 newLocDescriptor.setEnclosingClassDesc(enclosingDescriptor);
3828 Location newLoc = new Location(enclosingDescriptor, newLocDescriptor.getSymbol());
3829 newLoc.setLocDescriptor(newLocDescriptor);
3830 newCompLoc.addLocation(newLoc);
3832 // System.out.println("--newCompLoc=" + newCompLoc);
3836 private CompositeLocation generateCompositeLocation(MethodDescriptor md,
3837 NTuple<Descriptor> paramPrefix) {
3839 System.out.println("generateCompositeLocation=" + paramPrefix);
3841 CompositeLocation newCompLoc = convertToCompositeLocation(md, paramPrefix);
3843 Descriptor lastDescOfPrefix = paramPrefix.get(paramPrefix.size() - 1);
3844 // System.out.println("lastDescOfPrefix=" + lastDescOfPrefix + " kind="
3845 // + lastDescOfPrefix.getClass());
3846 ClassDescriptor enclosingDescriptor;
3847 if (lastDescOfPrefix instanceof FieldDescriptor) {
3848 enclosingDescriptor = ((FieldDescriptor) lastDescOfPrefix).getType().getClassDesc();
3849 // System.out.println("enclosingDescriptor0=" + enclosingDescriptor);
3851 // var descriptor case
3852 enclosingDescriptor = ((VarDescriptor) lastDescOfPrefix).getType().getClassDesc();
3854 // System.out.println("enclosingDescriptor=" + enclosingDescriptor);
3856 LocationDescriptor newLocDescriptor = generateNewLocationDescriptor();
3857 newLocDescriptor.setEnclosingClassDesc(enclosingDescriptor);
3859 Location newLoc = new Location(enclosingDescriptor, newLocDescriptor.getSymbol());
3860 newLoc.setLocDescriptor(newLocDescriptor);
3861 newCompLoc.addLocation(newLoc);
3863 // System.out.println("--newCompLoc=" + newCompLoc);
3867 private List<NTuple<Descriptor>> translatePrefixListToCallee(Descriptor baseRef,
3868 MethodDescriptor mdCallee, List<NTuple<Descriptor>> callerPrefixList) {
3870 List<NTuple<Descriptor>> calleePrefixList = new ArrayList<NTuple<Descriptor>>();
3872 for (int i = 0; i < callerPrefixList.size(); i++) {
3873 NTuple<Descriptor> prefix = callerPrefixList.get(i);
3874 if (prefix.startsWith(baseRef)) {
3875 NTuple<Descriptor> calleePrefix = new NTuple<Descriptor>();
3876 calleePrefix.add(mdCallee.getThis());
3877 for (int k = 1; k < prefix.size(); k++) {
3878 calleePrefix.add(prefix.get(k));
3880 calleePrefixList.add(calleePrefix);
3884 return calleePrefixList;
3888 public CompositeLocation convertToCompositeLocation(MethodDescriptor md, NTuple<Descriptor> tuple) {
3890 CompositeLocation compLoc = new CompositeLocation();
3892 Descriptor enclosingDescriptor = md;
3894 for (int i = 0; i < tuple.size(); i++) {
3895 Descriptor curDescriptor = tuple.get(i);
3896 Location locElement = new Location(enclosingDescriptor, curDescriptor.getSymbol());
3897 locElement.setLocDescriptor(curDescriptor);
3898 compLoc.addLocation(locElement);
3900 if (curDescriptor instanceof VarDescriptor) {
3901 enclosingDescriptor = md.getClassDesc();
3902 } else if (curDescriptor instanceof FieldDescriptor) {
3903 enclosingDescriptor = ((FieldDescriptor) curDescriptor).getClassDescriptor();
3904 } else if (curDescriptor instanceof NameDescriptor) {
3905 // it is "GLOBAL LOC" case!
3906 enclosingDescriptor = GLOBALDESC;
3907 } else if (curDescriptor instanceof InterDescriptor) {
3908 enclosingDescriptor = getFlowGraph(md).getEnclosingDescriptor(curDescriptor);
3910 enclosingDescriptor = null;
3918 private LocationDescriptor generateNewLocationDescriptor() {
3919 return new LocationDescriptor("Loc" + (locSeed++));
3922 private int getPrefixIndex(NTuple<Descriptor> tuple1, NTuple<Descriptor> tuple2) {
3924 // return the index where the prefix shared by tuple1 and tuple2 is ended
3925 // if there is no prefix shared by both of them, return -1
3927 int minSize = tuple1.size();
3928 if (minSize > tuple2.size()) {
3929 minSize = tuple2.size();
3933 for (int i = 0; i < minSize; i++) {
3934 if (!tuple1.get(i).equals(tuple2.get(i))) {
3944 private CompositeLocation generateInferredCompositeLocation(MethodLocationInfo methodInfo,
3945 NTuple<Location> tuple) {
3947 // first, retrieve inferred location by the local var descriptor
3948 CompositeLocation inferLoc = new CompositeLocation();
3950 CompositeLocation localVarInferLoc =
3951 methodInfo.getInferLocation(tuple.get(0).getLocDescriptor());
3953 localVarInferLoc.get(0).setLocDescriptor(tuple.get(0).getLocDescriptor());
3955 for (int i = 0; i < localVarInferLoc.getSize(); i++) {
3956 inferLoc.addLocation(localVarInferLoc.get(i));
3959 for (int i = 1; i < tuple.size(); i++) {
3960 Location cur = tuple.get(i);
3961 Descriptor enclosingDesc = cur.getDescriptor();
3962 Descriptor curDesc = cur.getLocDescriptor();
3964 Location inferLocElement;
3965 if (curDesc == null) {
3966 // in this case, we have a newly generated location.
3967 inferLocElement = new Location(enclosingDesc, cur.getLocIdentifier());
3969 String fieldLocSymbol =
3970 getLocationInfo(enclosingDesc).getInferLocation(curDesc).get(0).getLocIdentifier();
3971 inferLocElement = new Location(enclosingDesc, fieldLocSymbol);
3972 inferLocElement.setLocDescriptor(curDesc);
3975 inferLoc.addLocation(inferLocElement);
3979 assert (inferLoc.get(0).getLocDescriptor().getSymbol() == inferLoc.get(0).getLocIdentifier());
3983 public LocationInfo getLocationInfo(Descriptor d) {
3984 if (d instanceof MethodDescriptor) {
3985 return getMethodLocationInfo((MethodDescriptor) d);
3987 return getFieldLocationInfo((ClassDescriptor) d);
3991 private MethodLocationInfo getMethodLocationInfo(MethodDescriptor md) {
3993 if (!mapMethodDescToMethodLocationInfo.containsKey(md)) {
3994 mapMethodDescToMethodLocationInfo.put(md, new MethodLocationInfo(md));
3997 return mapMethodDescToMethodLocationInfo.get(md);
4001 private LocationInfo getFieldLocationInfo(ClassDescriptor cd) {
4003 if (!mapClassToLocationInfo.containsKey(cd)) {
4004 mapClassToLocationInfo.put(cd, new LocationInfo(cd));
4007 return mapClassToLocationInfo.get(cd);
4011 private void addPrefixMapping(Map<NTuple<Location>, Set<NTuple<Location>>> map,
4012 NTuple<Location> prefix, NTuple<Location> element) {
4014 if (!map.containsKey(prefix)) {
4015 map.put(prefix, new HashSet<NTuple<Location>>());
4017 map.get(prefix).add(element);
4020 private boolean containsNonPrimitiveElement(Set<Descriptor> descSet) {
4021 for (Iterator iterator = descSet.iterator(); iterator.hasNext();) {
4022 Descriptor desc = (Descriptor) iterator.next();
4024 if (desc.equals(LocationInference.GLOBALDESC)) {
4026 } else if (desc instanceof VarDescriptor) {
4027 if (!((VarDescriptor) desc).getType().isPrimitive()) {
4030 } else if (desc instanceof FieldDescriptor) {
4031 if (!((FieldDescriptor) desc).getType().isPrimitive()) {
4040 private SSJavaLattice<String> getLattice(Descriptor d) {
4041 if (d instanceof MethodDescriptor) {
4042 return getMethodLattice((MethodDescriptor) d);
4044 return getFieldLattice((ClassDescriptor) d);
4048 private SSJavaLattice<String> getMethodLattice(MethodDescriptor md) {
4049 if (!md2lattice.containsKey(md)) {
4050 md2lattice.put(md, new SSJavaLattice<String>(SSJavaAnalysis.TOP, SSJavaAnalysis.BOTTOM));
4052 return md2lattice.get(md);
4055 private void setMethodLattice(MethodDescriptor md, SSJavaLattice<String> lattice) {
4056 md2lattice.put(md, lattice);
4059 private void extractFlowsBetweenFields(ClassDescriptor cd, FlowNode srcNode, FlowNode dstNode,
4062 NTuple<Descriptor> srcCurTuple = srcNode.getCurrentDescTuple();
4063 NTuple<Descriptor> dstCurTuple = dstNode.getCurrentDescTuple();
4065 if (srcCurTuple.get(idx).equals(dstCurTuple.get(idx)) && srcCurTuple.size() > (idx + 1)
4066 && dstCurTuple.size() > (idx + 1)) {
4067 // value flow between fields: we don't need to add a binary relation
4070 Descriptor desc = srcCurTuple.get(idx);
4071 ClassDescriptor classDesc;
4074 classDesc = ((VarDescriptor) desc).getType().getClassDesc();
4076 if (desc instanceof FieldDescriptor) {
4077 classDesc = ((FieldDescriptor) desc).getType().getClassDesc();
4079 // this case is that the local variable has a composite location assignment
4080 // the following element after the composite location to the local variable
4081 // has the enclosing descriptor of the local variable
4082 Descriptor localDesc = srcNode.getDescTuple().get(0);
4083 classDesc = ((VarDescriptor) localDesc).getType().getClassDesc();
4086 extractFlowsBetweenFields(classDesc, srcNode, dstNode, idx + 1);
4090 Descriptor srcFieldDesc = srcCurTuple.get(idx);
4091 Descriptor dstFieldDesc = dstCurTuple.get(idx);
4093 System.out.println("srcFieldDesc=" + srcFieldDesc + " dstFieldDesc=" + dstFieldDesc
4095 if (!srcFieldDesc.equals(dstFieldDesc)) {
4097 System.out.println("-ADD EDGE");
4098 getHierarchyGraph(cd).addEdge(srcFieldDesc, dstFieldDesc);
4099 } else if (!isReference(srcFieldDesc) && !isReference(dstFieldDesc)) {
4100 System.out.println("-ADD EDGE");
4101 getHierarchyGraph(cd).addEdge(srcFieldDesc, dstFieldDesc);
4108 public SSJavaLattice<String> getFieldLattice(ClassDescriptor cd) {
4109 if (!cd2lattice.containsKey(cd)) {
4110 cd2lattice.put(cd, new SSJavaLattice<String>(SSJavaAnalysis.TOP, SSJavaAnalysis.BOTTOM));
4112 return cd2lattice.get(cd);
4115 public LinkedList<MethodDescriptor> computeMethodList() {
4117 Set<MethodDescriptor> toSort = new HashSet<MethodDescriptor>();
4121 Set<MethodDescriptor> visited = new HashSet<MethodDescriptor>();
4122 Set<MethodDescriptor> reachableCallee = new HashSet<MethodDescriptor>();
4124 while (!toAnalyzeIsEmpty()) {
4125 ClassDescriptor cd = toAnalyzeNext();
4127 setupToAnalazeMethod(cd);
4128 temp_toanalyzeMethodList.removeAll(visited);
4130 while (!toAnalyzeMethodIsEmpty()) {
4131 MethodDescriptor md = toAnalyzeMethodNext();
4132 if ((!visited.contains(md))
4133 && (ssjava.needTobeAnnotated(md) || reachableCallee.contains(md))) {
4135 // creates a mapping from a method descriptor to virtual methods
4136 Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
4137 if (md.isStatic()) {
4138 setPossibleCallees.add(md);
4140 setPossibleCallees.addAll(ssjava.getCallGraph().getMethods(md));
4143 Set<MethodDescriptor> calleeSet = ssjava.getCallGraph().getCalleeSet(md);
4144 Set<MethodDescriptor> needToAnalyzeCalleeSet = new HashSet<MethodDescriptor>();
4146 for (Iterator iterator = calleeSet.iterator(); iterator.hasNext();) {
4147 MethodDescriptor calleemd = (MethodDescriptor) iterator.next();
4148 if ((!ssjava.isTrustMethod(calleemd))
4149 && (!ssjava.isSSJavaUtil(calleemd.getClassDesc()))
4150 && (!calleemd.getModifiers().isNative())) {
4151 if (!visited.contains(calleemd)) {
4152 temp_toanalyzeMethodList.add(calleemd);
4154 reachableCallee.add(calleemd);
4155 needToAnalyzeCalleeSet.add(calleemd);
4159 mapMethodToCalleeSet.put(md, needToAnalyzeCalleeSet);
4168 return ssjava.topologicalSort(toSort);
4172 public boolean isTransitivelyCalledFrom(MethodDescriptor callee, MethodDescriptor caller) {
4173 // if the callee is transitively invoked from the caller
4176 int callerIdx = toanalyze_methodDescList.indexOf(caller);
4177 int calleeIdx = toanalyze_methodDescList.indexOf(callee);
4179 if (callerIdx < calleeIdx) {
4187 public void constructFlowGraph() {
4189 System.out.println("");
4190 toanalyze_methodDescList = computeMethodList();
4192 // hack... it seems that there is a problem with topological sorting.
4193 // so String.toString(Object o) is appeared too higher in the call chain.
4194 MethodDescriptor mdToString = null;
4195 for (Iterator iterator = toanalyze_methodDescList.iterator(); iterator.hasNext();) {
4196 MethodDescriptor md = (MethodDescriptor) iterator.next();
4197 if (md.toString().equals("public static String String.valueOf(Object o)")) {
4202 if (mdToString != null) {
4203 toanalyze_methodDescList.remove(mdToString);
4204 toanalyze_methodDescList.addLast(mdToString);
4207 LinkedList<MethodDescriptor> methodDescList =
4208 (LinkedList<MethodDescriptor>) toanalyze_methodDescList.clone();
4210 System.out.println("@@@methodDescList=" + methodDescList);
4213 while (!methodDescList.isEmpty()) {
4214 MethodDescriptor md = methodDescList.removeLast();
4215 if (state.SSJAVADEBUG) {
4216 System.out.println();
4217 System.out.println("SSJAVA: Constructing a flow graph: " + md);
4219 // creates a mapping from a parameter descriptor to its index
4220 Map<Descriptor, Integer> mapParamDescToIdx = new HashMap<Descriptor, Integer>();
4222 if (!md.isStatic()) {
4224 mapParamDescToIdx.put(md.getThis(), 0);
4227 for (int i = 0; i < md.numParameters(); i++) {
4228 Descriptor paramDesc = (Descriptor) md.getParameter(i);
4229 mapParamDescToIdx.put(paramDesc, new Integer(i + offset));
4232 FlowGraph fg = new FlowGraph(md, mapParamDescToIdx);
4233 mapMethodDescriptorToFlowGraph.put(md, fg);
4235 analyzeMethodBody(md.getClassDesc(), md);
4237 // System.out.println("##constructSubGlobalFlowGraph");
4238 // GlobalFlowGraph subGlobalFlowGraph = constructSubGlobalFlowGraph(fg);
4239 // mapMethodDescriptorToSubGlobalFlowGraph.put(md, subGlobalFlowGraph);
4242 // System.out.println("##addValueFlowsFromCalleeSubGlobalFlowGraph");
4243 // addValueFlowsFromCalleeSubGlobalFlowGraph(md, subGlobalFlowGraph);
4244 // subGlobalFlowGraph.writeGraph("_SUBGLOBAL");
4246 // propagateFlowsFromCalleesWithNoCompositeLocation(md);
4249 // _debug_printGraph();
4253 private void constructGlobalFlowGraph() {
4254 LinkedList<MethodDescriptor> methodDescList =
4255 (LinkedList<MethodDescriptor>) toanalyze_methodDescList.clone();
4257 while (!methodDescList.isEmpty()) {
4258 MethodDescriptor md = methodDescList.removeLast();
4259 if (state.SSJAVADEBUG) {
4260 System.out.println();
4261 System.out.println("SSJAVA: Constructing a sub global flow graph: " + md);
4263 constructSubGlobalFlowGraph(getFlowGraph(md));
4266 System.out.println("-add Value Flows From CalleeSubGlobalFlowGraph");
4267 addValueFlowsFromCalleeSubGlobalFlowGraph(md);
4268 // subGlobalFlowGraph.writeGraph("_SUBGLOBAL");
4270 // System.out.println("-propagate Flows From Callees With No CompositeLocation");
4271 // propagateFlowsFromCalleesWithNoCompositeLocation(md);
4273 // mark if a parameter has incoming flows
4274 checkParamNodesInSubGlobalFlowGraph(md);
4280 private void checkParamNodesInSubGlobalFlowGraph(MethodDescriptor md) {
4281 GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(md);
4282 FlowGraph flowGraph = getFlowGraph(md);
4284 Set<FlowNode> paramFlowNodeSet = flowGraph.getParamFlowNodeSet();
4285 for (Iterator iterator = paramFlowNodeSet.iterator(); iterator.hasNext();) {
4286 FlowNode paramFlowNode = (FlowNode) iterator.next();
4287 System.out.println("paramFlowNode=" + paramFlowNode);
4288 NTuple<Descriptor> paramDescTuple = paramFlowNode.getDescTuple();
4289 NTuple<Location> paramLocTuple = translateToLocTuple(md, paramDescTuple);
4290 GlobalFlowNode paramGlobalNode = globalFlowGraph.getFlowNode(paramLocTuple);
4292 Set<GlobalFlowNode> incomingNodeSet =
4293 globalFlowGraph.getIncomingNodeSetByPrefix(paramLocTuple.get(0));
4295 if (incomingNodeSet.size() > 0) {
4296 paramGlobalNode.setParamNodeWithIncomingFlows(true);
4302 private Set<MethodInvokeNode> getMethodInvokeNodeSet(MethodDescriptor md) {
4303 if (!mapMethodDescriptorToMethodInvokeNodeSet.containsKey(md)) {
4304 mapMethodDescriptorToMethodInvokeNodeSet.put(md, new HashSet<MethodInvokeNode>());
4306 return mapMethodDescriptorToMethodInvokeNodeSet.get(md);
4309 private void propagateFlowsFromCalleesWithNoCompositeLocation(MethodDescriptor mdCaller) {
4311 // the transformation for a call site propagates flows through parameters
4312 // if the method is virtual, it also grab all relations from any possible
4315 Set<MethodInvokeNode> setMethodInvokeNode =
4316 mapMethodDescriptorToMethodInvokeNodeSet.get(mdCaller);
4318 if (setMethodInvokeNode != null) {
4320 for (Iterator iterator = setMethodInvokeNode.iterator(); iterator.hasNext();) {
4321 MethodInvokeNode min = (MethodInvokeNode) iterator.next();
4322 MethodDescriptor mdCallee = min.getMethod();
4323 Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
4324 if (mdCallee.isStatic()) {
4325 setPossibleCallees.add(mdCallee);
4327 Set<MethodDescriptor> calleeSet = ssjava.getCallGraph().getMethods(mdCallee);
4328 // removes method descriptors that are not invoked by the caller
4329 calleeSet.retainAll(mapMethodToCalleeSet.get(mdCaller));
4330 setPossibleCallees.addAll(calleeSet);
4333 for (Iterator iterator2 = setPossibleCallees.iterator(); iterator2.hasNext();) {
4334 MethodDescriptor possibleMdCallee = (MethodDescriptor) iterator2.next();
4335 propagateFlowsToCallerWithNoCompositeLocation(min, mdCaller, possibleMdCallee);
4343 private void analyzeMethodBody(ClassDescriptor cd, MethodDescriptor md) {
4344 BlockNode bn = state.getMethodBody(md);
4345 NodeTupleSet implicitFlowTupleSet = new NodeTupleSet();
4346 analyzeFlowBlockNode(md, md.getParameterTable(), bn, implicitFlowTupleSet);
4349 private void analyzeFlowBlockNode(MethodDescriptor md, SymbolTable nametable, BlockNode bn,
4350 NodeTupleSet implicitFlowTupleSet) {
4352 bn.getVarTable().setParent(nametable);
4353 for (int i = 0; i < bn.size(); i++) {
4354 BlockStatementNode bsn = bn.get(i);
4355 analyzeBlockStatementNode(md, bn.getVarTable(), bsn, implicitFlowTupleSet);
4360 private void analyzeBlockStatementNode(MethodDescriptor md, SymbolTable nametable,
4361 BlockStatementNode bsn, NodeTupleSet implicitFlowTupleSet) {
4363 switch (bsn.kind()) {
4364 case Kind.BlockExpressionNode:
4365 analyzeBlockExpressionNode(md, nametable, (BlockExpressionNode) bsn, implicitFlowTupleSet);
4368 case Kind.DeclarationNode:
4369 analyzeFlowDeclarationNode(md, nametable, (DeclarationNode) bsn, implicitFlowTupleSet);
4372 case Kind.IfStatementNode:
4373 analyzeFlowIfStatementNode(md, nametable, (IfStatementNode) bsn, implicitFlowTupleSet);
4377 analyzeFlowLoopNode(md, nametable, (LoopNode) bsn, implicitFlowTupleSet);
4380 case Kind.ReturnNode:
4381 analyzeFlowReturnNode(md, nametable, (ReturnNode) bsn, implicitFlowTupleSet);
4384 case Kind.SubBlockNode:
4385 analyzeFlowSubBlockNode(md, nametable, (SubBlockNode) bsn, implicitFlowTupleSet);
4388 case Kind.ContinueBreakNode:
4391 case Kind.SwitchStatementNode:
4392 analyzeSwitchStatementNode(md, nametable, (SwitchStatementNode) bsn, implicitFlowTupleSet);
4399 private void analyzeSwitchBlockNode(MethodDescriptor md, SymbolTable nametable,
4400 SwitchBlockNode sbn, NodeTupleSet implicitFlowTupleSet) {
4402 analyzeFlowBlockNode(md, nametable, sbn.getSwitchBlockStatement(), implicitFlowTupleSet);
4406 private void analyzeSwitchStatementNode(MethodDescriptor md, SymbolTable nametable,
4407 SwitchStatementNode ssn, NodeTupleSet implicitFlowTupleSet) {
4409 NodeTupleSet condTupleNode = new NodeTupleSet();
4410 analyzeFlowExpressionNode(md, nametable, ssn.getCondition(), condTupleNode, null,
4411 implicitFlowTupleSet, false);
4413 NodeTupleSet newImplicitTupleSet = new NodeTupleSet();
4415 newImplicitTupleSet.addTupleSet(implicitFlowTupleSet);
4416 newImplicitTupleSet.addTupleSet(condTupleNode);
4418 if (needToGenerateInterLoc(newImplicitTupleSet)) {
4419 // need to create an intermediate node for the GLB of conditional
4420 // locations & implicit flows
4421 System.out.println("10");
4423 NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
4424 for (Iterator<NTuple<Descriptor>> idxIter = newImplicitTupleSet.iterator(); idxIter.hasNext();) {
4425 NTuple<Descriptor> tuple = idxIter.next();
4426 addFlowGraphEdge(md, tuple, interTuple);
4428 newImplicitTupleSet.clear();
4429 newImplicitTupleSet.addTuple(interTuple);
4432 BlockNode sbn = ssn.getSwitchBody();
4433 for (int i = 0; i < sbn.size(); i++) {
4434 analyzeSwitchBlockNode(md, nametable, (SwitchBlockNode) sbn.get(i), newImplicitTupleSet);
4439 private void analyzeFlowSubBlockNode(MethodDescriptor md, SymbolTable nametable,
4440 SubBlockNode sbn, NodeTupleSet implicitFlowTupleSet) {
4441 analyzeFlowBlockNode(md, nametable, sbn.getBlockNode(), implicitFlowTupleSet);
4444 private void analyzeFlowReturnNode(MethodDescriptor md, SymbolTable nametable, ReturnNode rn,
4445 NodeTupleSet implicitFlowTupleSet) {
4447 // System.out.println("-analyzeFlowReturnNode=" + rn.printNode(0));
4448 ExpressionNode returnExp = rn.getReturnExpression();
4450 if (returnExp != null) {
4451 NodeTupleSet nodeSet = new NodeTupleSet();
4452 // if a return expression returns a literal value, nodeSet is empty
4453 analyzeFlowExpressionNode(md, nametable, returnExp, nodeSet, false);
4454 FlowGraph fg = getFlowGraph(md);
4456 // if (implicitFlowTupleSet.size() == 1
4458 // fg.getFlowNode(implicitFlowTupleSet.iterator().next()).isIntermediate())
4461 // // since there is already an intermediate node for the GLB of implicit
4463 // // we don't need to create another intermediate node.
4464 // // just re-use the intermediate node for implicit flows.
4466 // FlowNode meetNode =
4467 // fg.getFlowNode(implicitFlowTupleSet.iterator().next());
4469 // for (Iterator iterator = nodeSet.iterator(); iterator.hasNext();) {
4470 // NTuple<Descriptor> returnNodeTuple = (NTuple<Descriptor>)
4472 // fg.addValueFlowEdge(returnNodeTuple, meetNode.getDescTuple());
4477 NodeTupleSet currentFlowTupleSet = new NodeTupleSet();
4479 // add tuples from return node
4480 currentFlowTupleSet.addTupleSet(nodeSet);
4482 // add tuples corresponding to the current implicit flows
4483 currentFlowTupleSet.addTupleSet(implicitFlowTupleSet);
4485 // System.out.println("---currentFlowTupleSet=" + currentFlowTupleSet);
4487 if (needToGenerateInterLoc(currentFlowTupleSet)) {
4488 System.out.println("9");
4490 FlowNode meetNode = fg.createIntermediateNode();
4491 for (Iterator iterator = currentFlowTupleSet.iterator(); iterator.hasNext();) {
4492 NTuple<Descriptor> currentFlowTuple = (NTuple<Descriptor>) iterator.next();
4493 fg.addValueFlowEdge(currentFlowTuple, meetNode.getDescTuple());
4495 fg.addReturnFlowNode(meetNode.getDescTuple());
4497 // currentFlowTupleSet = removeLiteralTuple(currentFlowTupleSet);
4498 for (Iterator iterator = currentFlowTupleSet.iterator(); iterator.hasNext();) {
4499 NTuple<Descriptor> currentFlowTuple = (NTuple<Descriptor>) iterator.next();
4500 fg.addReturnFlowNode(currentFlowTuple);
4508 private NodeTupleSet removeLiteralTuple(NodeTupleSet inSet) {
4509 NodeTupleSet tupleSet = new NodeTupleSet();
4510 for (Iterator<NTuple<Descriptor>> iter = inSet.iterator(); iter.hasNext();) {
4511 NTuple<Descriptor> tuple = iter.next();
4512 if (!tuple.get(0).equals(LITERALDESC)) {
4513 tupleSet.addTuple(tuple);
4519 private boolean needToGenerateInterLoc(NodeTupleSet tupleSet) {
4521 for (Iterator<NTuple<Descriptor>> iter = tupleSet.iterator(); iter.hasNext();) {
4522 NTuple<Descriptor> descTuple = iter.next();
4523 if (!descTuple.get(0).equals(LITERALDESC)) {
4528 System.out.println("needToGenerateInterLoc=" + tupleSet + " size=" + size);
4535 private void analyzeFlowLoopNode(MethodDescriptor md, SymbolTable nametable, LoopNode ln,
4536 NodeTupleSet implicitFlowTupleSet) {
4538 if (ln.getType() == LoopNode.WHILELOOP || ln.getType() == LoopNode.DOWHILELOOP) {
4540 NodeTupleSet condTupleNode = new NodeTupleSet();
4541 analyzeFlowExpressionNode(md, nametable, ln.getCondition(), condTupleNode, null,
4542 implicitFlowTupleSet, false);
4544 NodeTupleSet newImplicitTupleSet = new NodeTupleSet();
4546 newImplicitTupleSet.addTupleSet(implicitFlowTupleSet);
4547 newImplicitTupleSet.addTupleSet(condTupleNode);
4549 newImplicitTupleSet.addGlobalFlowTupleSet(implicitFlowTupleSet.getGlobalLocTupleSet());
4550 newImplicitTupleSet.addGlobalFlowTupleSet(condTupleNode.getGlobalLocTupleSet());
4552 if (needToGenerateInterLoc(newImplicitTupleSet)) {
4553 // need to create an intermediate node for the GLB of conditional
4554 // locations & implicit flows
4555 System.out.println("6");
4557 NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
4558 for (Iterator<NTuple<Descriptor>> idxIter = newImplicitTupleSet.iterator(); idxIter
4560 NTuple<Descriptor> tuple = idxIter.next();
4561 addFlowGraphEdge(md, tuple, interTuple);
4563 newImplicitTupleSet.clear();
4564 newImplicitTupleSet.addTuple(interTuple);
4569 // System.out.println("condTupleNode="+condTupleNode);
4570 // NTuple<Descriptor> interTuple =
4571 // getFlowGraph(md).createIntermediateNode().getDescTuple();
4573 // for (Iterator<NTuple<Descriptor>> idxIter = condTupleNode.iterator();
4574 // idxIter.hasNext();) {
4575 // NTuple<Descriptor> tuple = idxIter.next();
4576 // addFlowGraphEdge(md, tuple, interTuple);
4579 // for (Iterator<NTuple<Descriptor>> idxIter =
4580 // implicitFlowTupleSet.iterator(); idxIter
4582 // NTuple<Descriptor> tuple = idxIter.next();
4583 // addFlowGraphEdge(md, tuple, interTuple);
4586 // NodeTupleSet newImplicitSet = new NodeTupleSet();
4587 // newImplicitSet.addTuple(interTuple);
4588 analyzeFlowBlockNode(md, nametable, ln.getBody(), newImplicitTupleSet);
4591 // condTupleNode.addTupleSet(implicitFlowTupleSet);
4593 // add edges from condNodeTupleSet to all nodes of conditional nodes
4594 // analyzeFlowBlockNode(md, nametable, ln.getBody(), condTupleNode);
4597 // check 'for loop' case
4598 BlockNode bn = ln.getInitializer();
4599 bn.getVarTable().setParent(nametable);
4600 for (int i = 0; i < bn.size(); i++) {
4601 BlockStatementNode bsn = bn.get(i);
4602 analyzeBlockStatementNode(md, bn.getVarTable(), bsn, implicitFlowTupleSet);
4605 NodeTupleSet condTupleNode = new NodeTupleSet();
4606 analyzeFlowExpressionNode(md, bn.getVarTable(), ln.getCondition(), condTupleNode, null,
4607 implicitFlowTupleSet, false);
4609 NodeTupleSet newImplicitTupleSet = new NodeTupleSet();
4610 newImplicitTupleSet.addTupleSet(implicitFlowTupleSet);
4611 newImplicitTupleSet.addTupleSet(condTupleNode);
4613 if (needToGenerateInterLoc(newImplicitTupleSet)) {
4614 // need to create an intermediate node for the GLB of conditional
4615 // locations & implicit flows
4616 System.out.println("7");
4618 NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
4619 for (Iterator<NTuple<Descriptor>> idxIter = newImplicitTupleSet.iterator(); idxIter
4621 NTuple<Descriptor> tuple = idxIter.next();
4622 addFlowGraphEdge(md, tuple, interTuple);
4624 newImplicitTupleSet.clear();
4625 newImplicitTupleSet.addTuple(interTuple);
4630 // NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
4632 // for (Iterator<NTuple<Descriptor>> idxIter = condTupleNode.iterator(); idxIter.hasNext();) {
4633 // NTuple<Descriptor> tuple = idxIter.next();
4634 // addFlowGraphEdge(md, tuple, interTuple);
4637 // for (Iterator<NTuple<Descriptor>> idxIter = implicitFlowTupleSet.iterator(); idxIter
4639 // NTuple<Descriptor> tuple = idxIter.next();
4640 // addFlowGraphEdge(md, tuple, interTuple);
4643 // NodeTupleSet newImplicitSet = new NodeTupleSet();
4644 // newImplicitSet.addTuple(interTuple);
4645 analyzeFlowBlockNode(md, bn.getVarTable(), ln.getUpdate(), newImplicitTupleSet);
4646 analyzeFlowBlockNode(md, bn.getVarTable(), ln.getBody(), newImplicitTupleSet);
4649 // condTupleNode.addTupleSet(implicitFlowTupleSet);
4651 // analyzeFlowBlockNode(md, bn.getVarTable(), ln.getUpdate(),
4653 // analyzeFlowBlockNode(md, bn.getVarTable(), ln.getBody(),
4660 private void analyzeFlowIfStatementNode(MethodDescriptor md, SymbolTable nametable,
4661 IfStatementNode isn, NodeTupleSet implicitFlowTupleSet) {
4663 System.out.println("analyzeFlowIfStatementNode=" + isn.printNode(0));
4665 NodeTupleSet condTupleNode = new NodeTupleSet();
4666 analyzeFlowExpressionNode(md, nametable, isn.getCondition(), condTupleNode, null,
4667 implicitFlowTupleSet, false);
4669 NodeTupleSet newImplicitTupleSet = new NodeTupleSet();
4671 newImplicitTupleSet.addTupleSet(implicitFlowTupleSet);
4672 newImplicitTupleSet.addTupleSet(condTupleNode);
4674 // System.out.println("$$$GGGcondTupleNode=" + condTupleNode.getGlobalLocTupleSet());
4675 // System.out.println("-condTupleNode=" + condTupleNode);
4676 // System.out.println("-implicitFlowTupleSet=" + implicitFlowTupleSet);
4677 // System.out.println("-newImplicitTupleSet=" + newImplicitTupleSet);
4679 if (needToGenerateInterLoc(newImplicitTupleSet)) {
4680 System.out.println("5");
4682 // need to create an intermediate node for the GLB of conditional locations & implicit flows
4683 NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
4684 for (Iterator<NTuple<Descriptor>> idxIter = newImplicitTupleSet.iterator(); idxIter.hasNext();) {
4685 NTuple<Descriptor> tuple = idxIter.next();
4686 addFlowGraphEdge(md, tuple, interTuple);
4688 newImplicitTupleSet.clear();
4689 newImplicitTupleSet.addTuple(interTuple);
4692 // GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(md);
4693 // for (Iterator<NTuple<Location>> iterator = condTupleNode.globalIterator();
4694 // iterator.hasNext();) {
4695 // NTuple<Location> calleeReturnLocTuple = iterator.next();
4696 // for (Iterator<NTuple<Descriptor>> iter2 = newImplicitTupleSet.iterator(); iter2.hasNext();) {
4697 // NTuple<Descriptor> callerImplicitTuple = iter2.next();
4698 // globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
4699 // translateToLocTuple(md, callerImplicitTuple));
4702 newImplicitTupleSet.addGlobalFlowTupleSet(condTupleNode.getGlobalLocTupleSet());
4704 analyzeFlowBlockNode(md, nametable, isn.getTrueBlock(), newImplicitTupleSet);
4706 if (isn.getFalseBlock() != null) {
4707 analyzeFlowBlockNode(md, nametable, isn.getFalseBlock(), newImplicitTupleSet);
4712 private void analyzeFlowDeclarationNode(MethodDescriptor md, SymbolTable nametable,
4713 DeclarationNode dn, NodeTupleSet implicitFlowTupleSet) {
4715 VarDescriptor vd = dn.getVarDescriptor();
4716 mapDescToDefinitionLine.put(vd, dn.getNumLine());
4717 NTuple<Descriptor> tupleLHS = new NTuple<Descriptor>();
4719 FlowNode fn = getFlowGraph(md).createNewFlowNode(tupleLHS);
4720 fn.setDeclarationNode();
4722 if (dn.getExpression() != null) {
4723 System.out.println("-analyzeFlowDeclarationNode=" + dn.printNode(0));
4725 NodeTupleSet nodeSetRHS = new NodeTupleSet();
4726 analyzeFlowExpressionNode(md, nametable, dn.getExpression(), nodeSetRHS, null,
4727 implicitFlowTupleSet, false);
4729 // creates edges from RHS to LHS
4730 NTuple<Descriptor> interTuple = null;
4731 if (needToGenerateInterLoc(nodeSetRHS)) {
4732 System.out.println("3");
4733 interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
4736 for (Iterator<NTuple<Descriptor>> iter = nodeSetRHS.iterator(); iter.hasNext();) {
4737 NTuple<Descriptor> fromTuple = iter.next();
4738 System.out.println("fromTuple=" + fromTuple + " interTuple=" + interTuple + " tupleLSH="
4740 addFlowGraphEdge(md, fromTuple, interTuple, tupleLHS);
4743 // creates edges from implicitFlowTupleSet to LHS
4744 for (Iterator<NTuple<Descriptor>> iter = implicitFlowTupleSet.iterator(); iter.hasNext();) {
4745 NTuple<Descriptor> implicitTuple = iter.next();
4746 addFlowGraphEdge(md, implicitTuple, tupleLHS);
4749 GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(md);
4750 for (Iterator<NTuple<Location>> iterator = nodeSetRHS.globalIterator(); iterator.hasNext();) {
4751 NTuple<Location> calleeReturnLocTuple = iterator.next();
4753 globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, translateToLocTuple(md, tupleLHS));
4756 for (Iterator<NTuple<Location>> iterator = implicitFlowTupleSet.globalIterator(); iterator
4758 NTuple<Location> implicitGlobalTuple = iterator.next();
4760 globalFlowGraph.addValueFlowEdge(implicitGlobalTuple, translateToLocTuple(md, tupleLHS));
4763 System.out.println("-nodeSetRHS=" + nodeSetRHS);
4764 System.out.println("-implicitFlowTupleSet=" + implicitFlowTupleSet);
4770 private void analyzeBlockExpressionNode(MethodDescriptor md, SymbolTable nametable,
4771 BlockExpressionNode ben, NodeTupleSet implicitFlowTupleSet) {
4772 analyzeFlowExpressionNode(md, nametable, ben.getExpression(), null, null, implicitFlowTupleSet,
4776 private NTuple<Descriptor> analyzeFlowExpressionNode(MethodDescriptor md, SymbolTable nametable,
4777 ExpressionNode en, NodeTupleSet nodeSet, boolean isLHS) {
4778 return analyzeFlowExpressionNode(md, nametable, en, nodeSet, null, new NodeTupleSet(), isLHS);
4781 private NTuple<Descriptor> analyzeFlowExpressionNode(MethodDescriptor md, SymbolTable nametable,
4782 ExpressionNode en, NodeTupleSet nodeSet, NTuple<Descriptor> base,
4783 NodeTupleSet implicitFlowTupleSet, boolean isLHS) {
4785 // System.out.println("en=" + en.printNode(0) + " class=" + en.getClass());
4787 // note that expression node can create more than one flow node
4788 // nodeSet contains of flow nodes
4789 // base is always assigned to null except the case of a name node!
4790 NTuple<Descriptor> flowTuple;
4791 switch (en.kind()) {
4792 case Kind.AssignmentNode:
4793 analyzeFlowAssignmentNode(md, nametable, (AssignmentNode) en, nodeSet, base,
4794 implicitFlowTupleSet);
4797 case Kind.FieldAccessNode:
4799 analyzeFlowFieldAccessNode(md, nametable, (FieldAccessNode) en, nodeSet, base,
4800 implicitFlowTupleSet, isLHS);
4801 if (flowTuple != null) {
4802 nodeSet.addTuple(flowTuple);
4807 NodeTupleSet nameNodeSet = new NodeTupleSet();
4809 analyzeFlowNameNode(md, nametable, (NameNode) en, nameNodeSet, base, implicitFlowTupleSet);
4810 if (flowTuple != null) {
4811 nodeSet.addTuple(flowTuple);
4816 analyzeFlowOpNode(md, nametable, (OpNode) en, nodeSet, implicitFlowTupleSet);
4819 case Kind.CreateObjectNode:
4820 analyzeCreateObjectNode(md, nametable, (CreateObjectNode) en);
4823 case Kind.ArrayAccessNode:
4824 analyzeFlowArrayAccessNode(md, nametable, (ArrayAccessNode) en, nodeSet, isLHS);
4827 case Kind.LiteralNode:
4828 analyzeFlowLiteralNode(md, nametable, (LiteralNode) en, nodeSet);
4831 case Kind.MethodInvokeNode:
4832 analyzeFlowMethodInvokeNode(md, nametable, (MethodInvokeNode) en, nodeSet,
4833 implicitFlowTupleSet);
4836 case Kind.TertiaryNode:
4837 analyzeFlowTertiaryNode(md, nametable, (TertiaryNode) en, nodeSet, implicitFlowTupleSet);
4841 analyzeFlowCastNode(md, nametable, (CastNode) en, nodeSet, base, implicitFlowTupleSet);
4843 // case Kind.InstanceOfNode:
4844 // checkInstanceOfNode(md, nametable, (InstanceOfNode) en, td);
4847 // case Kind.ArrayInitializerNode:
4848 // checkArrayInitializerNode(md, nametable, (ArrayInitializerNode) en,
4852 // case Kind.ClassTypeNode:
4853 // checkClassTypeNode(md, nametable, (ClassTypeNode) en, td);
4856 // case Kind.OffsetNode:
4857 // checkOffsetNode(md, nametable, (OffsetNode)en, td);
4866 private void analyzeFlowCastNode(MethodDescriptor md, SymbolTable nametable, CastNode cn,
4867 NodeTupleSet nodeSet, NTuple<Descriptor> base, NodeTupleSet implicitFlowTupleSet) {
4869 analyzeFlowExpressionNode(md, nametable, cn.getExpression(), nodeSet, base,
4870 implicitFlowTupleSet, false);
4874 private void analyzeFlowTertiaryNode(MethodDescriptor md, SymbolTable nametable, TertiaryNode tn,
4875 NodeTupleSet nodeSet, NodeTupleSet implicitFlowTupleSet) {
4877 // System.out.println("analyzeFlowTertiaryNode=" + tn.printNode(0));
4879 NodeTupleSet tertiaryTupleNode = new NodeTupleSet();
4880 analyzeFlowExpressionNode(md, nametable, tn.getCond(), tertiaryTupleNode, null,
4881 implicitFlowTupleSet, false);
4883 NodeTupleSet newImplicitTupleSet = new NodeTupleSet();
4884 newImplicitTupleSet.addTupleSet(implicitFlowTupleSet);
4885 newImplicitTupleSet.addTupleSet(tertiaryTupleNode);
4887 // System.out.println("$$$GGGcondTupleNode=" + tertiaryTupleNode.getGlobalLocTupleSet());
4888 // System.out.println("-tertiaryTupleNode=" + tertiaryTupleNode);
4889 // System.out.println("-implicitFlowTupleSet=" + implicitFlowTupleSet);
4890 // System.out.println("-newImplicitTupleSet=" + newImplicitTupleSet);
4892 if (needToGenerateInterLoc(newImplicitTupleSet)) {
4893 System.out.println("15");
4894 // need to create an intermediate node for the GLB of conditional locations & implicit flows
4895 NTuple<Descriptor> interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
4896 for (Iterator<NTuple<Descriptor>> idxIter = newImplicitTupleSet.iterator(); idxIter.hasNext();) {
4897 NTuple<Descriptor> tuple = idxIter.next();
4898 addFlowGraphEdge(md, tuple, interTuple);
4900 newImplicitTupleSet.clear();
4901 newImplicitTupleSet.addTuple(interTuple);
4904 newImplicitTupleSet.addGlobalFlowTupleSet(tertiaryTupleNode.getGlobalLocTupleSet());
4906 System.out.println("---------newImplicitTupleSet=" + newImplicitTupleSet);
4907 // add edges from tertiaryTupleNode to all nodes of conditional nodes
4908 // tertiaryTupleNode.addTupleSet(implicitFlowTupleSet);
4909 analyzeFlowExpressionNode(md, nametable, tn.getTrueExpr(), tertiaryTupleNode, null,
4910 newImplicitTupleSet, false);
4912 analyzeFlowExpressionNode(md, nametable, tn.getFalseExpr(), tertiaryTupleNode, null,
4913 newImplicitTupleSet, false);
4915 nodeSet.addGlobalFlowTupleSet(tertiaryTupleNode.getGlobalLocTupleSet());
4916 nodeSet.addTupleSet(tertiaryTupleNode);
4918 System.out.println("#tertiary node set=" + nodeSet);
4921 private void addMapCallerMethodDescToMethodInvokeNodeSet(MethodDescriptor caller,
4922 MethodInvokeNode min) {
4923 Set<MethodInvokeNode> set = mapMethodDescriptorToMethodInvokeNodeSet.get(caller);
4925 set = new HashSet<MethodInvokeNode>();
4926 mapMethodDescriptorToMethodInvokeNodeSet.put(caller, set);
4931 private void addParamNodeFlowingToReturnValue(MethodDescriptor md, FlowNode fn) {
4933 if (!mapMethodDescToParamNodeFlowsToReturnValue.containsKey(md)) {
4934 mapMethodDescToParamNodeFlowsToReturnValue.put(md, new HashSet<FlowNode>());
4936 mapMethodDescToParamNodeFlowsToReturnValue.get(md).add(fn);
4939 private Set<FlowNode> getParamNodeFlowingToReturnValue(MethodDescriptor md) {
4941 if (!mapMethodDescToParamNodeFlowsToReturnValue.containsKey(md)) {
4942 mapMethodDescToParamNodeFlowsToReturnValue.put(md, new HashSet<FlowNode>());
4945 return mapMethodDescToParamNodeFlowsToReturnValue.get(md);
4948 private Set<NTuple<Location>> getPCLocTupleSet(MethodInvokeNode min) {
4949 if (!mapMethodInvokeNodeToPCLocTupleSet.containsKey(min)) {
4950 mapMethodInvokeNodeToPCLocTupleSet.put(min, new HashSet<NTuple<Location>>());
4952 return mapMethodInvokeNodeToPCLocTupleSet.get(min);
4955 private void analyzeFlowMethodInvokeNode(MethodDescriptor mdCaller, SymbolTable nametable,
4956 MethodInvokeNode min, NodeTupleSet nodeSet, NodeTupleSet implicitFlowTupleSet) {
4958 System.out.println("analyzeFlowMethodInvokeNode=" + min.printNode(0));
4960 if (!toanalyze_methodDescList.contains(min.getMethod())) {
4964 addMapMethodDescToMethodInvokeNodeSet(min);
4966 Set<NTuple<Location>> pcLocTupleSet = getPCLocTupleSet(min);
4967 for (Iterator iterator = implicitFlowTupleSet.iterator(); iterator.hasNext();) {
4968 NTuple<Descriptor> pcDescTuple = (NTuple<Descriptor>) iterator.next();
4969 if (!pcDescTuple.get(0).equals(LITERALDESC)) {
4970 // here we don't need to add the literal value as a PC location
4971 pcLocTupleSet.add(translateToLocTuple(mdCaller, pcDescTuple));
4975 mapMethodInvokeNodeToArgIdxMap.put(min, new HashMap<Integer, NTuple<Descriptor>>());
4977 if (nodeSet == null) {
4978 nodeSet = new NodeTupleSet();
4981 MethodDescriptor mdCallee = min.getMethod();
4983 NameDescriptor baseName = min.getBaseName();
4984 boolean isSystemout = false;
4985 if (baseName != null) {
4986 isSystemout = baseName.getSymbol().equals("System.out");
4989 if (!ssjava.isSSJavaUtil(mdCallee.getClassDesc()) && !ssjava.isTrustMethod(mdCallee)
4992 addMapCallerMethodDescToMethodInvokeNodeSet(mdCaller, min);
4994 FlowGraph calleeFlowGraph = getFlowGraph(mdCallee);
4995 System.out.println("mdCallee=" + mdCallee + " calleeFlowGraph=" + calleeFlowGraph);
4996 Set<FlowNode> calleeReturnSet = calleeFlowGraph.getReturnNodeSet();
4998 System.out.println("---calleeReturnSet=" + calleeReturnSet);
5000 NodeTupleSet tupleSet = new NodeTupleSet();
5002 if (min.getExpression() != null) {
5004 NodeTupleSet baseNodeSet = new NodeTupleSet();
5005 analyzeFlowExpressionNode(mdCaller, nametable, min.getExpression(), baseNodeSet, null,
5006 implicitFlowTupleSet, false);
5007 System.out.println("baseNodeSet=" + baseNodeSet);
5009 assert (baseNodeSet.size() == 1);
5010 NTuple<Descriptor> baseTuple = baseNodeSet.iterator().next();
5011 if (baseTuple.get(0) instanceof InterDescriptor) {
5012 if (baseTuple.size() > 1) {
5015 FlowNode interNode = getFlowGraph(mdCaller).getFlowNode(baseTuple);
5016 baseTuple = translateBaseTuple(interNode, baseTuple);
5018 mapMethodInvokeNodeToBaseTuple.put(min, baseTuple);
5020 if (!min.getMethod().isStatic()) {
5021 addArgIdxMap(min, 0, baseTuple);
5023 for (Iterator iterator = calleeReturnSet.iterator(); iterator.hasNext();) {
5024 FlowNode returnNode = (FlowNode) iterator.next();
5025 NTuple<Descriptor> returnDescTuple = returnNode.getDescTuple();
5026 if (returnDescTuple.startsWith(mdCallee.getThis())) {
5027 // the location type of the return value is started with 'this'
5029 NTuple<Descriptor> inFlowTuple = new NTuple<Descriptor>(baseTuple.getList());
5031 if (inFlowTuple.get(0) instanceof InterDescriptor) {
5032 // min.getExpression()
5037 inFlowTuple.addAll(returnDescTuple.subList(1, returnDescTuple.size()));
5038 // nodeSet.addTuple(inFlowTuple);
5039 System.out.println("1CREATE A NEW TUPLE=" + inFlowTuple + " from="
5040 + mdCallee.getThis());
5041 // tupleSet.addTuple(inFlowTuple);
5042 tupleSet.addTuple(baseTuple);
5045 System.out.println("returnNode=" + returnNode);
5046 Set<FlowNode> inFlowSet = calleeFlowGraph.getIncomingFlowNodeSet(returnNode);
5047 // System.out.println("inFlowSet=" + inFlowSet + " from retrunNode=" + returnNode);
5048 for (Iterator iterator2 = inFlowSet.iterator(); iterator2.hasNext();) {
5049 FlowNode inFlowNode = (FlowNode) iterator2.next();
5050 if (inFlowNode.getDescTuple().startsWith(mdCallee.getThis())) {
5051 // nodeSet.addTupleSet(baseNodeSet);
5052 System.out.println("2CREATE A NEW TUPLE=" + baseNodeSet + " from="
5053 + mdCallee.getThis());
5054 tupleSet.addTupleSet(baseNodeSet);
5062 // analyze parameter flows
5064 if (min.numArgs() > 0) {
5067 if (min.getMethod().isStatic()) {
5073 for (int i = 0; i < min.numArgs(); i++) {
5074 ExpressionNode en = min.getArg(i);
5075 int idx = i + offset;
5076 NodeTupleSet argTupleSet = new NodeTupleSet();
5077 analyzeFlowExpressionNode(mdCaller, nametable, en, argTupleSet, false);
5078 // if argument is liternal node, argTuple is set to NULL
5079 System.out.println("---arg idx=" + idx + " argTupleSet=" + argTupleSet);
5080 NTuple<Descriptor> argTuple = generateArgTuple(mdCaller, argTupleSet);
5082 // if an argument is literal value,
5083 // we need to create an itermediate node so that we could assign a composite location to
5084 // that node if needed
5085 if (argTuple.size() > 0
5086 && (argTuple.get(0).equals(GLOBALDESC) || argTuple.get(0).equals(LITERALDESC))) {
5088 * System.out.println("***GLOBAL ARG TUPLE CASE=" + argTuple); System.out.println("8");
5090 * NTuple<Descriptor> interTuple =
5091 * getFlowGraph(mdCaller).createIntermediateNode().getDescTuple(); ((InterDescriptor)
5092 * interTuple.get(0)).setMethodArgIdxPair(min, idx); addFlowGraphEdge(mdCaller,
5093 * argTuple, interTuple); argTuple = interTuple; addArgIdxMap(min, idx, argTuple);
5094 * System.out.println("new min mapping i=" + idx + " ->" + argTuple);
5096 argTuple = new NTuple<Descriptor>();
5099 addArgIdxMap(min, idx, argTuple);
5101 FlowNode paramNode = calleeFlowGraph.getParamFlowNode(idx);
5103 // check whether a param node in the callee graph has incoming flows
5104 // if it has incoming flows, the corresponding arg should be lower than the current PC
5105 // Descriptor prefix = paramNode.getDescTuple().get(0);
5106 // if (calleeFlowGraph.getIncomingNodeSetByPrefix(prefix).size() > 0) {
5107 // for (Iterator<NTuple<Descriptor>> iterator = implicitFlowTupleSet.iterator(); iterator
5109 // NTuple<Descriptor> pcTuple = iterator.next();
5110 // System.out.println("add edge pcTuple =" + pcTuple + " -> " + argTuple);
5111 // addFlowGraphEdge(md, pcTuple, argTuple);
5115 System.out.println("paramNode=" + paramNode + " calleeReturnSet=" + calleeReturnSet);
5116 if (hasInFlowTo(calleeFlowGraph, paramNode, calleeReturnSet)
5117 || mdCallee.getModifiers().isNative()) {
5118 addParamNodeFlowingToReturnValue(mdCallee, paramNode);
5119 // nodeSet.addTupleSet(argTupleSet);
5120 System.out.println("3CREATE A NEW TUPLE=" + argTupleSet + " from=" + paramNode);
5121 tupleSet.addTupleSet(argTupleSet);
5127 if (mdCallee.getReturnType() != null && !mdCallee.getReturnType().isVoid()) {
5128 FlowReturnNode returnHolderNode = getFlowGraph(mdCaller).createReturnNode(min);
5130 if (needToGenerateInterLoc(tupleSet)) {
5131 System.out.println("20");
5132 FlowGraph fg = getFlowGraph(mdCaller);
5133 FlowNode interNode = fg.createIntermediateNode();
5134 interNode.setFormHolder(true);
5136 NTuple<Descriptor> interTuple = interNode.getDescTuple();
5138 for (Iterator iterator = tupleSet.iterator(); iterator.hasNext();) {
5139 NTuple<Descriptor> tuple = (NTuple<Descriptor>) iterator.next();
5141 Set<NTuple<Descriptor>> addSet = new HashSet<NTuple<Descriptor>>();
5142 FlowNode node = fg.getFlowNode(tuple);
5143 if (node instanceof FlowReturnNode) {
5144 addSet.addAll(fg.getReturnTupleSet(((FlowReturnNode) node).getReturnTupleSet()));
5148 for (Iterator iterator2 = addSet.iterator(); iterator2.hasNext();) {
5149 NTuple<Descriptor> higher = (NTuple<Descriptor>) iterator2.next();
5150 addFlowGraphEdge(mdCaller, higher, interTuple);
5154 returnHolderNode.addTuple(interTuple);
5156 nodeSet.addTuple(interTuple);
5157 System.out.println("ADD TUPLESET=" + interTuple + " to returnnode=" + returnHolderNode);
5160 returnHolderNode.addTupleSet(tupleSet);
5161 System.out.println("ADD TUPLESET=" + tupleSet + " to returnnode=" + returnHolderNode);
5163 // setNode.addTupleSet(tupleSet);
5164 // NodeTupleSet setFromReturnNode=new NodeTupleSet();
5165 // setFromReturnNode.addTuple(tuple);
5167 NodeTupleSet holderTupleSet =
5168 getNodeTupleSetFromReturnNode(getFlowGraph(mdCaller), returnHolderNode);
5170 System.out.println("HOLDER TUPLe SET=" + holderTupleSet);
5171 nodeSet.addTupleSet(holderTupleSet);
5173 nodeSet.addTuple(returnHolderNode.getDescTuple());
5176 // propagateFlowsFromCallee(min, md, min.getMethod());
5178 // when generating the global flow graph,
5179 // we need to add ordering relations from the set of callee return loc tuple to LHS of the
5180 // caller assignment
5181 for (Iterator iterator = calleeReturnSet.iterator(); iterator.hasNext();) {
5182 FlowNode calleeReturnNode = (FlowNode) iterator.next();
5183 NTuple<Location> calleeReturnLocTuple =
5184 translateToLocTuple(mdCallee, calleeReturnNode.getDescTuple());
5185 System.out.println("calleeReturnLocTuple=" + calleeReturnLocTuple);
5186 NTuple<Location> transaltedToCaller =
5187 translateToCallerLocTuple(min, mdCallee, mdCaller, calleeReturnLocTuple);
5188 // System.out.println("translateToCallerLocTuple="
5189 // + translateToCallerLocTuple(min, mdCallee, mdCaller, calleeReturnLocTuple));
5190 if (transaltedToCaller.size() > 0) {
5191 nodeSet.addGlobalFlowTuple(translateToCallerLocTuple(min, mdCallee, mdCaller,
5192 calleeReturnLocTuple));
5196 System.out.println("min nodeSet=" + nodeSet);
5202 private NodeTupleSet getNodeTupleSetFromReturnNode(FlowGraph fg, FlowReturnNode node) {
5203 NodeTupleSet nts = new NodeTupleSet();
5205 Set<NTuple<Descriptor>> returnSet = node.getReturnTupleSet();
5207 for (Iterator iterator = returnSet.iterator(); iterator.hasNext();) {
5208 NTuple<Descriptor> tuple = (NTuple<Descriptor>) iterator.next();
5209 FlowNode flowNode = fg.getFlowNode(tuple);
5210 if (flowNode instanceof FlowReturnNode) {
5211 returnSet.addAll(recurGetNode(fg, (FlowReturnNode) flowNode));
5213 returnSet.add(tuple);
5217 for (Iterator iterator = returnSet.iterator(); iterator.hasNext();) {
5218 NTuple<Descriptor> nTuple = (NTuple<Descriptor>) iterator.next();
5219 nts.addTuple(nTuple);
5226 private Set<NTuple<Descriptor>> recurGetNode(FlowGraph fg, FlowReturnNode rnode) {
5228 Set<NTuple<Descriptor>> tupleSet = new HashSet<NTuple<Descriptor>>();
5230 Set<NTuple<Descriptor>> returnSet = rnode.getReturnTupleSet();
5231 for (Iterator iterator = returnSet.iterator(); iterator.hasNext();) {
5232 NTuple<Descriptor> tuple = (NTuple<Descriptor>) iterator.next();
5233 FlowNode flowNode = fg.getFlowNode(tuple);
5234 if (flowNode instanceof FlowReturnNode) {
5235 tupleSet.addAll(recurGetNode(fg, (FlowReturnNode) flowNode));
5237 tupleSet.add(tuple);
5243 private NTuple<Descriptor> generateArgTuple(MethodDescriptor mdCaller, NodeTupleSet argTupleSet) {
5247 // if argTupleSet is empty, it comes from the top location
5248 if (argTupleSet.size() == 0) {
5249 NTuple<Descriptor> descTuple = new NTuple<Descriptor>();
5250 descTuple.add(LITERALDESC);
5254 Set<NTuple<Descriptor>> argTupleSetNonLiteral = new HashSet<NTuple<Descriptor>>();
5256 for (Iterator<NTuple<Descriptor>> iter = argTupleSet.iterator(); iter.hasNext();) {
5257 NTuple<Descriptor> descTuple = iter.next();
5258 if (!descTuple.get(0).equals(LITERALDESC)) {
5259 argTupleSetNonLiteral.add(descTuple);
5263 if (argTupleSetNonLiteral.size() > 1) {
5264 System.out.println("11");
5266 NTuple<Descriptor> interTuple =
5267 getFlowGraph(mdCaller).createIntermediateNode().getDescTuple();
5268 for (Iterator<NTuple<Descriptor>> idxIter = argTupleSet.iterator(); idxIter.hasNext();) {
5269 NTuple<Descriptor> tuple = idxIter.next();
5270 addFlowGraphEdge(mdCaller, tuple, interTuple);
5273 } else if (argTupleSetNonLiteral.size() == 1) {
5274 return argTupleSetNonLiteral.iterator().next();
5276 return argTupleSet.iterator().next();
5281 private boolean hasInFlowTo(FlowGraph fg, FlowNode inNode, Set<FlowNode> nodeSet) {
5282 // return true if inNode has in-flows to nodeSet
5284 if (nodeSet.contains(inNode)) {
5285 // in this case, the method directly returns a parameter variable.
5288 // Set<FlowNode> reachableSet = fg.getReachFlowNodeSetFrom(inNode);
5289 Set<FlowNode> reachableSet = fg.getReachableSetFrom(inNode.getDescTuple());
5290 // System.out.println("inNode=" + inNode + " reachalbeSet=" + reachableSet);
5292 for (Iterator iterator = reachableSet.iterator(); iterator.hasNext();) {
5293 FlowNode fn = (FlowNode) iterator.next();
5294 if (nodeSet.contains(fn)) {
5301 private NTuple<Descriptor> getNodeTupleByArgIdx(MethodInvokeNode min, int idx) {
5302 return mapMethodInvokeNodeToArgIdxMap.get(min).get(new Integer(idx));
5305 private void addArgIdxMap(MethodInvokeNode min, int idx, NTuple<Descriptor> argTuple /*
5309 Map<Integer, NTuple<Descriptor>> mapIdxToTuple = mapMethodInvokeNodeToArgIdxMap.get(min);
5310 if (mapIdxToTuple == null) {
5311 mapIdxToTuple = new HashMap<Integer, NTuple<Descriptor>>();
5312 mapMethodInvokeNodeToArgIdxMap.put(min, mapIdxToTuple);
5314 mapIdxToTuple.put(new Integer(idx), argTuple);
5317 private void analyzeFlowLiteralNode(MethodDescriptor md, SymbolTable nametable, LiteralNode en,
5318 NodeTupleSet nodeSet) {
5319 NTuple<Descriptor> tuple = new NTuple<Descriptor>();
5320 tuple.add(LITERALDESC);
5321 nodeSet.addTuple(tuple);
5324 private void analyzeFlowArrayAccessNode(MethodDescriptor md, SymbolTable nametable,
5325 ArrayAccessNode aan, NodeTupleSet nodeSet, boolean isLHS) {
5327 System.out.println("analyzeFlowArrayAccessNode aan=" + aan.printNode(0));
5328 String currentArrayAccessNodeExpStr = aan.printNode(0);
5329 arrayAccessNodeStack.push(aan.printNode(0));
5331 NodeTupleSet expNodeTupleSet = new NodeTupleSet();
5332 NTuple<Descriptor> base =
5333 analyzeFlowExpressionNode(md, nametable, aan.getExpression(), expNodeTupleSet, isLHS);
5334 System.out.println("-base=" + base);
5336 nodeSet.setMethodInvokeBaseDescTuple(base);
5337 NodeTupleSet idxNodeTupleSet = new NodeTupleSet();
5338 analyzeFlowExpressionNode(md, nametable, aan.getIndex(), idxNodeTupleSet, isLHS);
5340 arrayAccessNodeStack.pop();
5343 // need to create an edge from idx to array
5344 for (Iterator<NTuple<Descriptor>> idxIter = idxNodeTupleSet.iterator(); idxIter.hasNext();) {
5345 NTuple<Descriptor> idxTuple = idxIter.next();
5346 for (Iterator<NTuple<Descriptor>> arrIter = expNodeTupleSet.iterator(); arrIter.hasNext();) {
5347 NTuple<Descriptor> arrTuple = arrIter.next();
5348 getFlowGraph(md).addValueFlowEdge(idxTuple, arrTuple);
5352 GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(md);
5353 for (Iterator<NTuple<Location>> iterator = idxNodeTupleSet.globalIterator(); iterator
5355 NTuple<Location> calleeReturnLocTuple = iterator.next();
5356 for (Iterator<NTuple<Descriptor>> arrIter = expNodeTupleSet.iterator(); arrIter.hasNext();) {
5357 NTuple<Descriptor> arrTuple = arrIter.next();
5359 globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple, translateToLocTuple(md, arrTuple));
5363 nodeSet.addTupleSet(expNodeTupleSet);
5366 NodeTupleSet nodeSetArrayAccessExp = new NodeTupleSet();
5368 nodeSetArrayAccessExp.addTupleSet(expNodeTupleSet);
5369 nodeSetArrayAccessExp.addTupleSet(idxNodeTupleSet);
5371 if (arrayAccessNodeStack.isEmpty()
5372 || !arrayAccessNodeStack.peek().startsWith(currentArrayAccessNodeExpStr)) {
5374 if (needToGenerateInterLoc(nodeSetArrayAccessExp)) {
5375 System.out.println("1");
5376 FlowNode interNode = getFlowGraph(md).createIntermediateNode();
5377 NTuple<Descriptor> interTuple = interNode.getDescTuple();
5379 for (Iterator<NTuple<Descriptor>> iter = nodeSetArrayAccessExp.iterator(); iter.hasNext();) {
5380 NTuple<Descriptor> higherTuple = iter.next();
5381 addFlowGraphEdge(md, higherTuple, interTuple);
5383 nodeSetArrayAccessExp.clear();
5384 nodeSetArrayAccessExp.addTuple(interTuple);
5385 FlowGraph fg = getFlowGraph(md);
5387 System.out.println("base=" + base);
5389 fg.addMapInterLocNodeToEnclosingDescriptor(interTuple.get(0),
5390 getClassTypeDescriptor(base.get(base.size() - 1)));
5391 interNode.setBaseTuple(base);
5396 nodeSet.addGlobalFlowTupleSet(idxNodeTupleSet.getGlobalLocTupleSet());
5397 nodeSet.addTupleSet(nodeSetArrayAccessExp);
5403 private void analyzeCreateObjectNode(MethodDescriptor md, SymbolTable nametable,
5404 CreateObjectNode en) {
5405 // TODO Auto-generated method stub
5409 private void analyzeFlowOpNode(MethodDescriptor md, SymbolTable nametable, OpNode on,
5410 NodeTupleSet nodeSet, NodeTupleSet implicitFlowTupleSet) {
5412 NodeTupleSet leftOpSet = new NodeTupleSet();
5413 NodeTupleSet rightOpSet = new NodeTupleSet();
5415 System.out.println("analyzeFlowOpNode=" + on.printNode(0));
5418 analyzeFlowExpressionNode(md, nametable, on.getLeft(), leftOpSet, null, implicitFlowTupleSet,
5420 System.out.println("--leftOpSet=" + leftOpSet);
5422 if (on.getRight() != null) {
5424 analyzeFlowExpressionNode(md, nametable, on.getRight(), rightOpSet, null,
5425 implicitFlowTupleSet, false);
5427 System.out.println("--rightOpSet=" + rightOpSet);
5429 Operation op = on.getOp();
5431 switch (op.getOp()) {
5433 case Operation.UNARYPLUS:
5434 case Operation.UNARYMINUS:
5435 case Operation.LOGIC_NOT:
5437 nodeSet.addTupleSet(leftOpSet);
5440 case Operation.LOGIC_OR:
5441 case Operation.LOGIC_AND:
5442 case Operation.COMP:
5443 case Operation.BIT_OR:
5444 case Operation.BIT_XOR:
5445 case Operation.BIT_AND:
5446 case Operation.ISAVAILABLE:
5447 case Operation.EQUAL:
5448 case Operation.NOTEQUAL:
5455 case Operation.MULT:
5458 case Operation.LEFTSHIFT:
5459 case Operation.RIGHTSHIFT:
5460 case Operation.URIGHTSHIFT:
5462 // there are two operands
5463 nodeSet.addTupleSet(leftOpSet);
5464 nodeSet.addTupleSet(rightOpSet);
5466 nodeSet.addGlobalFlowTupleSet(leftOpSet.getGlobalLocTupleSet());
5467 nodeSet.addGlobalFlowTupleSet(rightOpSet.getGlobalLocTupleSet());
5472 throw new Error(op.toString());
5477 private NTuple<Descriptor> analyzeFlowNameNode(MethodDescriptor md, SymbolTable nametable,
5478 NameNode nn, NodeTupleSet nodeSet, NTuple<Descriptor> base, NodeTupleSet implicitFlowTupleSet) {
5481 base = new NTuple<Descriptor>();
5484 NameDescriptor nd = nn.getName();
5486 if (nd.getBase() != null) {
5488 analyzeFlowExpressionNode(md, nametable, nn.getExpression(), nodeSet, base,
5489 implicitFlowTupleSet, false);
5491 // base node has the top location
5495 String varname = nd.toString();
5496 if (varname.equals("this")) {
5498 base.add(md.getThis());
5502 Descriptor d = (Descriptor) nametable.get(varname);
5504 if (d instanceof VarDescriptor) {
5505 VarDescriptor vd = (VarDescriptor) d;
5507 } else if (d instanceof FieldDescriptor) {
5508 // the type of field descriptor has a location!
5509 FieldDescriptor fd = (FieldDescriptor) d;
5510 if (fd.isStatic()) {
5512 // if it is 'static final', no need to have flow node for the TOP
5516 // if 'static', assign the default GLOBAL LOCATION to the first
5517 // element of the tuple
5518 base.add(GLOBALDESC);
5521 // the location of field access starts from this, followed by field
5523 base.add(md.getThis());
5527 } else if (d == null) {
5528 // access static field
5529 base.add(GLOBALDESC);
5530 base.add(nn.getField());
5533 // FieldDescriptor fd = nn.getField();addFlowGraphEdge
5535 // MethodLattice<String> localLattice = ssjava.getMethodLattice(md);
5536 // String globalLocId = localLattice.getGlobalLoc();
5537 // if (globalLocId == null) {
5539 // Error("Method lattice does not define global variable location at "
5540 // + generateErrorMessage(md.getClassDesc(), nn));
5542 // loc.addLocation(new Location(md, globalLocId));
5544 // Location fieldLoc = (Location) fd.getType().getExtension();
5545 // loc.addLocation(fieldLoc);
5551 getFlowGraph(md).createNewFlowNode(base);
5557 private NTuple<Descriptor> analyzeFlowFieldAccessNode(MethodDescriptor md, SymbolTable nametable,
5558 FieldAccessNode fan, NodeTupleSet nodeSet, NTuple<Descriptor> base,
5559 NodeTupleSet implicitFlowTupleSet, boolean isLHS) {
5560 // System.out.println("analyzeFlowFieldAccessNode=" + fan.printNode(0));
5562 String currentArrayAccessNodeExpStr = null;
5563 ExpressionNode left = fan.getExpression();
5564 TypeDescriptor ltd = left.getType();
5565 FieldDescriptor fd = fan.getField();
5566 ArrayAccessNode aan = null;
5568 String varName = null;
5569 if (left.kind() == Kind.NameNode) {
5570 NameDescriptor nd = ((NameNode) left).getName();
5571 varName = nd.toString();
5574 if (ltd.isClassNameRef() || (varName != null && varName.equals("this"))) {
5575 // using a class name directly or access using this
5576 if (fd.isStatic() && fd.isFinal()) {
5581 NodeTupleSet idxNodeTupleSet = new NodeTupleSet();
5583 boolean isArrayCase = false;
5584 if (left instanceof ArrayAccessNode) {
5587 aan = (ArrayAccessNode) left;
5589 currentArrayAccessNodeExpStr = aan.printNode(0);
5590 arrayAccessNodeStack.push(currentArrayAccessNodeExpStr);
5592 left = aan.getExpression();
5593 analyzeFlowExpressionNode(md, nametable, aan.getIndex(), idxNodeTupleSet, base,
5594 implicitFlowTupleSet, isLHS);
5598 analyzeFlowExpressionNode(md, nametable, left, nodeSet, base, implicitFlowTupleSet, isLHS);
5601 // in this case, field is TOP location
5605 NTuple<Descriptor> flowFieldTuple = new NTuple<Descriptor>(base.toList());
5607 if (!left.getType().isPrimitive()) {
5608 if (!fd.getSymbol().equals("length")) {
5609 // array.length access, just have the location of the array
5610 flowFieldTuple.add(fd);
5611 nodeSet.removeTuple(base);
5614 getFlowGraph(md).createNewFlowNode(flowFieldTuple);
5617 for (Iterator<NTuple<Descriptor>> idxIter = idxNodeTupleSet.iterator(); idxIter.hasNext();) {
5618 NTuple<Descriptor> idxTuple = idxIter.next();
5619 getFlowGraph(md).addValueFlowEdge(idxTuple, flowFieldTuple);
5622 GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(md);
5623 for (Iterator<NTuple<Location>> iterator = idxNodeTupleSet.globalIterator(); iterator
5625 NTuple<Location> calleeReturnLocTuple = iterator.next();
5627 globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
5628 translateToLocTuple(md, flowFieldTuple));
5632 nodeSet.addTupleSet(idxNodeTupleSet);
5634 // if it is the array case and not the LHS case
5636 arrayAccessNodeStack.pop();
5638 if (arrayAccessNodeStack.isEmpty()
5639 || !arrayAccessNodeStack.peek().startsWith(currentArrayAccessNodeExpStr)) {
5640 NodeTupleSet nodeSetArrayAccessExp = new NodeTupleSet();
5642 nodeSetArrayAccessExp.addTuple(flowFieldTuple);
5643 nodeSetArrayAccessExp.addTupleSet(idxNodeTupleSet);
5644 nodeSetArrayAccessExp.addTupleSet(nodeSet);
5646 if (needToGenerateInterLoc(nodeSetArrayAccessExp)) {
5647 System.out.println("4");
5648 System.out.println("nodeSetArrayAccessExp=" + nodeSetArrayAccessExp);
5649 // System.out.println("idxNodeTupleSet.getGlobalLocTupleSet()="
5650 // + idxNodeTupleSet.getGlobalLocTupleSet());
5652 NTuple<Descriptor> interTuple =
5653 getFlowGraph(md).createIntermediateNode().getDescTuple();
5655 for (Iterator<NTuple<Descriptor>> iter = nodeSetArrayAccessExp.iterator(); iter
5657 NTuple<Descriptor> higherTuple = iter.next();
5658 addFlowGraphEdge(md, higherTuple, interTuple);
5661 FlowGraph fg = getFlowGraph(md);
5662 fg.addMapInterLocNodeToEnclosingDescriptor(interTuple.get(0),
5663 getClassTypeDescriptor(base.get(base.size() - 1)));
5666 flowFieldTuple = interTuple;
5668 nodeSet.addGlobalFlowTupleSet(idxNodeTupleSet.getGlobalLocTupleSet());
5674 return flowFieldTuple;
5679 private void debug_printTreeNode(TreeNode tn) {
5681 System.out.println("DEBUG: " + tn.printNode(0) + " line#=" + tn.getNumLine());
5685 private void analyzeFlowAssignmentNode(MethodDescriptor md, SymbolTable nametable,
5686 AssignmentNode an, NodeTupleSet nodeSet, NTuple<Descriptor> base,
5687 NodeTupleSet implicitFlowTupleSet) {
5689 NodeTupleSet nodeSetRHS = new NodeTupleSet();
5690 NodeTupleSet nodeSetLHS = new NodeTupleSet();
5692 boolean postinc = true;
5693 if (an.getOperation().getBaseOp() == null
5694 || (an.getOperation().getBaseOp().getOp() != Operation.POSTINC && an.getOperation()
5695 .getBaseOp().getOp() != Operation.POSTDEC)) {
5698 // if LHS is array access node, need to capture value flows between an array
5699 // and its index value
5700 analyzeFlowExpressionNode(md, nametable, an.getDest(), nodeSetLHS, null, implicitFlowTupleSet,
5704 // analyze value flows of rhs expression
5705 analyzeFlowExpressionNode(md, nametable, an.getSrc(), nodeSetRHS, null, implicitFlowTupleSet,
5708 System.out.println("-analyzeFlowAssignmentNode=" + an.printNode(0));
5709 System.out.println("-nodeSetLHS=" + nodeSetLHS);
5710 System.out.println("-nodeSetRHS=" + nodeSetRHS);
5711 System.out.println("-implicitFlowTupleSet=" + implicitFlowTupleSet);
5712 // System.out.println("-");
5714 if (an.getOperation().getOp() >= 2 && an.getOperation().getOp() <= 12) {
5715 // if assignment contains OP+EQ operator, creates edges from LHS to LHS
5717 for (Iterator<NTuple<Descriptor>> iter = nodeSetLHS.iterator(); iter.hasNext();) {
5718 NTuple<Descriptor> fromTuple = iter.next();
5719 for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
5720 NTuple<Descriptor> toTuple = iter2.next();
5721 addFlowGraphEdge(md, fromTuple, toTuple);
5726 // creates edges from RHS to LHS
5727 NTuple<Descriptor> interTuple = null;
5728 if (needToGenerateInterLoc(nodeSetRHS)) {
5729 System.out.println("2");
5730 interTuple = getFlowGraph(md).createIntermediateNode().getDescTuple();
5733 for (Iterator<NTuple<Descriptor>> iter = nodeSetRHS.iterator(); iter.hasNext();) {
5734 NTuple<Descriptor> fromTuple = iter.next();
5735 for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
5736 NTuple<Descriptor> toTuple = iter2.next();
5737 addFlowGraphEdge(md, fromTuple, interTuple, toTuple);
5741 // creates edges from implicitFlowTupleSet to LHS
5742 for (Iterator<NTuple<Descriptor>> iter = implicitFlowTupleSet.iterator(); iter.hasNext();) {
5743 NTuple<Descriptor> fromTuple = iter.next();
5744 for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
5745 NTuple<Descriptor> toTuple = iter2.next();
5746 addFlowGraphEdge(md, fromTuple, toTuple);
5750 // create global flow edges if the callee gives return value flows to the caller
5751 GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(md);
5752 for (Iterator<NTuple<Location>> iterator = nodeSetRHS.globalIterator(); iterator.hasNext();) {
5753 NTuple<Location> calleeReturnLocTuple = iterator.next();
5754 for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
5755 NTuple<Descriptor> callerLHSTuple = iter2.next();
5756 System.out.println("$$$ GLOBAL FLOW ADD=" + calleeReturnLocTuple + " -> "
5757 + translateToLocTuple(md, callerLHSTuple));
5759 globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
5760 translateToLocTuple(md, callerLHSTuple));
5764 for (Iterator<NTuple<Location>> iterator = implicitFlowTupleSet.globalIterator(); iterator
5766 NTuple<Location> calleeReturnLocTuple = iterator.next();
5767 for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
5768 NTuple<Descriptor> callerLHSTuple = iter2.next();
5770 globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
5771 translateToLocTuple(md, callerLHSTuple));
5772 System.out.println("$$$ GLOBAL FLOW PCLOC ADD=" + calleeReturnLocTuple + " -> "
5773 + translateToLocTuple(md, callerLHSTuple));
5780 for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
5781 NTuple<Descriptor> tuple = iter2.next();
5782 addFlowGraphEdge(md, tuple, tuple);
5785 // creates edges from implicitFlowTupleSet to LHS
5786 for (Iterator<NTuple<Descriptor>> iter = implicitFlowTupleSet.iterator(); iter.hasNext();) {
5787 NTuple<Descriptor> fromTuple = iter.next();
5788 for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
5789 NTuple<Descriptor> toTuple = iter2.next();
5790 addFlowGraphEdge(md, fromTuple, toTuple);
5794 GlobalFlowGraph globalFlowGraph = getSubGlobalFlowGraph(md);
5795 for (Iterator<NTuple<Location>> iterator = implicitFlowTupleSet.globalIterator(); iterator
5797 NTuple<Location> calleeReturnLocTuple = iterator.next();
5798 for (Iterator<NTuple<Descriptor>> iter2 = nodeSetLHS.iterator(); iter2.hasNext();) {
5799 NTuple<Descriptor> callerLHSTuple = iter2.next();
5800 globalFlowGraph.addValueFlowEdge(calleeReturnLocTuple,
5801 translateToLocTuple(md, callerLHSTuple));
5802 System.out.println("$$$ GLOBAL FLOW PC ADD=" + calleeReturnLocTuple + " -> "
5803 + translateToLocTuple(md, callerLHSTuple));
5809 if (nodeSet != null) {
5810 nodeSet.addTupleSet(nodeSetLHS);
5811 nodeSet.addGlobalFlowTupleSet(nodeSetLHS.getGlobalLocTupleSet());
5815 public FlowGraph getFlowGraph(MethodDescriptor md) {
5816 return mapMethodDescriptorToFlowGraph.get(md);
5819 private boolean addFlowGraphEdge(MethodDescriptor md, NTuple<Descriptor> from,
5820 NTuple<Descriptor> to) {
5821 FlowGraph graph = getFlowGraph(md);
5822 graph.addValueFlowEdge(from, to);
5826 private void addFlowGraphEdge(MethodDescriptor md, NTuple<Descriptor> from,
5827 NTuple<Descriptor> inter, NTuple<Descriptor> to) {
5829 FlowGraph graph = getFlowGraph(md);
5831 if (inter != null) {
5832 graph.addValueFlowEdge(from, inter);
5833 graph.addValueFlowEdge(inter, to);
5835 graph.addValueFlowEdge(from, to);
5840 public void writeInferredLatticeDotFile(ClassDescriptor cd, HierarchyGraph simpleHierarchyGraph,
5841 SSJavaLattice<String> locOrder, String nameSuffix) {
5842 System.out.println("@cd=" + cd);
5843 System.out.println("@sharedLoc=" + locOrder.getSharedLocSet());
5844 writeInferredLatticeDotFile(cd, null, simpleHierarchyGraph, locOrder, nameSuffix);
5847 public void writeInferredLatticeDotFile(ClassDescriptor cd, MethodDescriptor md,
5848 HierarchyGraph simpleHierarchyGraph, SSJavaLattice<String> locOrder, String nameSuffix) {
5850 String fileName = "lattice_";
5853 /* cd.getSymbol().replaceAll("[\\W_]", "") + "_" + */md.toString().replaceAll("[\\W_]", "");
5855 fileName += cd.getSymbol().replaceAll("[\\W_]", "");
5858 fileName += nameSuffix;
5860 Set<Pair<String, String>> pairSet = locOrder.getOrderingPairSet();
5862 Set<String> addedLocSet = new HashSet<String>();
5864 if (pairSet.size() > 0) {
5866 BufferedWriter bw = new BufferedWriter(new FileWriter(fileName + ".dot"));
5868 bw.write("digraph " + fileName + " {\n");
5870 for (Iterator iterator = pairSet.iterator(); iterator.hasNext();) {
5871 // pair is in the form of <higher, lower>
5872 Pair<String, String> pair = (Pair<String, String>) iterator.next();
5874 String highLocId = pair.getFirst();
5875 String lowLocId = pair.getSecond();
5876 if (!addedLocSet.contains(highLocId)) {
5877 addedLocSet.add(highLocId);
5878 drawNode(bw, locOrder, simpleHierarchyGraph, highLocId);
5881 if (!addedLocSet.contains(lowLocId)) {
5882 addedLocSet.add(lowLocId);
5883 drawNode(bw, locOrder, simpleHierarchyGraph, lowLocId);
5886 bw.write(highLocId + " -> " + lowLocId + ";\n");
5891 } catch (IOException e) {
5892 e.printStackTrace();
5899 private String convertMergeSetToString(HierarchyGraph graph, Set<HNode> mergeSet) {
5901 for (Iterator iterator = mergeSet.iterator(); iterator.hasNext();) {
5902 HNode merged = (HNode) iterator.next();
5903 if (merged.isMergeNode()) {
5904 str += convertMergeSetToString(graph, graph.getMapHNodetoMergeSet().get(merged));
5906 str += " " + merged.getName();
5912 private void drawNode(BufferedWriter bw, SSJavaLattice<String> lattice, HierarchyGraph graph,
5913 String locName) throws IOException {
5916 if (lattice.isSharedLoc(locName)) {
5917 prettyStr = locName + "*";
5919 prettyStr = locName;
5921 // HNode node = graph.getHNode(locName);
5922 // if (node != null && node.isMergeNode()) {
5923 // Set<HNode> mergeSet = graph.getMapHNodetoMergeSet().get(node);
5924 // prettyStr += ":" + convertMergeSetToString(graph, mergeSet);
5926 bw.write(locName + " [label=\"" + prettyStr + "\"]" + ";\n");
5929 public void _debug_writeFlowGraph() {
5930 Set<MethodDescriptor> keySet = mapMethodDescriptorToFlowGraph.keySet();
5932 for (Iterator<MethodDescriptor> iterator = keySet.iterator(); iterator.hasNext();) {
5933 MethodDescriptor md = (MethodDescriptor) iterator.next();
5934 FlowGraph fg = mapMethodDescriptorToFlowGraph.get(md);
5935 GlobalFlowGraph subGlobalFlowGraph = getSubGlobalFlowGraph(md);
5938 subGlobalFlowGraph.writeGraph("_SUBGLOBAL");
5939 } catch (IOException e) {
5940 e.printStackTrace();
5948 class CyclicFlowException extends Exception {
5952 class InterDescriptor extends Descriptor {
5954 Pair<MethodInvokeNode, Integer> minArgIdxPair;
5956 public InterDescriptor(String name) {
5960 public void setMethodArgIdxPair(MethodInvokeNode min, int idx) {
5961 minArgIdxPair = new Pair<MethodInvokeNode, Integer>(min, new Integer(idx));
5964 public Pair<MethodInvokeNode, Integer> getMethodArgIdxPair() {
5965 return minArgIdxPair;