1 package Analysis.SSJava;
3 import java.util.Enumeration;
4 import java.util.HashSet;
5 import java.util.Hashtable;
6 import java.util.Iterator;
7 import java.util.LinkedList;
9 import java.util.Stack;
11 import Analysis.Liveness;
12 import Analysis.CallGraph.CallGraph;
13 import Analysis.Loops.LoopFinder;
15 import IR.FieldDescriptor;
16 import IR.MethodDescriptor;
19 import IR.TypeDescriptor;
20 import IR.TypeExtension;
22 import IR.Flat.FlatCall;
23 import IR.Flat.FlatElementNode;
24 import IR.Flat.FlatFieldNode;
25 import IR.Flat.FlatLiteralNode;
26 import IR.Flat.FlatMethod;
27 import IR.Flat.FlatNew;
28 import IR.Flat.FlatNode;
29 import IR.Flat.FlatOpNode;
30 import IR.Flat.FlatSetElementNode;
31 import IR.Flat.FlatSetFieldNode;
32 import IR.Flat.TempDescriptor;
33 import IR.Tree.Modifiers;
35 public class DefinitelyWrittenCheck {
37 SSJavaAnalysis ssjava;
45 // maps a flat node to its WrittenSet: this keeps all heap path overwritten
47 private Hashtable<FlatNode, Set<NTuple<Descriptor>>> mapFlatNodeToMustWriteSet;
49 // maps a temp descriptor to its heap path
50 // each temp descriptor has a unique heap path since we do not allow any
52 private Hashtable<Descriptor, NTuple<Descriptor>> mapHeapPath;
54 // maps a temp descriptor to its composite location
55 private Hashtable<TempDescriptor, NTuple<Location>> mapDescriptorToLocationPath;
57 // maps a flat method to the READ that is the set of heap path that is
58 // expected to be written before method invocation
59 private Hashtable<FlatMethod, Set<NTuple<Descriptor>>> mapFlatMethodToReadSet;
61 // maps a flat method to the must-write set that is the set of heap path that
62 // is overwritten on every possible path during method invocation
63 private Hashtable<FlatMethod, Set<NTuple<Descriptor>>> mapFlatMethodToMustWriteSet;
65 // maps a flat method to the DELETE SET that is a set of heap path to shared
67 // written to but not overwritten by the higher value
68 private Hashtable<FlatMethod, SharedLocMap> mapFlatMethodToDeleteSet;
70 // maps a flat method to the S SET that is a set of heap path to shared
71 // locations that are overwritten by the higher value
72 private Hashtable<FlatMethod, SharedLocMap> mapFlatMethodToSharedLocMap;
74 // maps a flat method to the may-wirte set that is the set of heap path that
75 // might be written to
76 private Hashtable<FlatMethod, Set<NTuple<Descriptor>>> mapFlatMethodToMayWriteSet;
78 // maps a call site to the read set contributed by all callees
79 private Hashtable<FlatNode, Set<NTuple<Descriptor>>> mapFlatNodeToBoundReadSet;
81 // maps a call site to the must write set contributed by all callees
82 private Hashtable<FlatNode, Set<NTuple<Descriptor>>> mapFlatNodeToBoundMustWriteSet;
84 // maps a call site to the may read set contributed by all callees
85 private Hashtable<FlatNode, Set<NTuple<Descriptor>>> mapFlatNodeToBoundMayWriteSet;
87 // points to method containing SSJAVA Loop
88 private MethodDescriptor methodContainingSSJavaLoop;
90 // maps a flatnode to definitely written analysis mapping M
91 private Hashtable<FlatNode, Hashtable<NTuple<Descriptor>, Set<WriteAge>>> mapFlatNodetoEventLoopMap;
93 // maps shared location to the set of descriptors which belong to the shared
96 // keep current descriptors to visit in fixed-point interprocedural analysis,
97 private Stack<MethodDescriptor> methodDescriptorsToVisitStack;
99 // when analyzing flatcall, need to re-schedule set of callee
100 private Set<MethodDescriptor> calleesToEnqueue;
102 private Set<ReadSummary> possibleCalleeReadSummarySetToCaller;
104 public static final String arrayElementFieldName = "___element_";
105 static protected Hashtable<TypeDescriptor, FieldDescriptor> mapTypeToArrayField;
107 // maps a method descriptor to the merged incoming caller's current
109 // it is for setting clearance flag when all read set is overwritten
110 private Hashtable<MethodDescriptor, ReadSummary> mapMethodDescriptorToReadSummary;
112 private Hashtable<MethodDescriptor, MultiSourceMap<NTuple<Location>, NTuple<Descriptor>>> mapMethodToSharedLocCoverSet;
114 private Hashtable<FlatNode, SharedLocMap> mapFlatNodeToSharedLocMapping;
115 private Hashtable<FlatNode, SharedLocMap> mapFlatNodeToDeleteSet;
117 private LoopFinder ssjavaLoop;
118 private Set<FlatNode> loopIncElements;
120 private Set<NTuple<Descriptor>> calleeUnionBoundReadSet;
121 private Set<NTuple<Descriptor>> calleeIntersectBoundMustWriteSet;
122 private Set<NTuple<Descriptor>> calleeUnionBoundMayWriteSet;
123 private SharedLocMap calleeUnionBoundDeleteSet;
124 private SharedLocMap calleeIntersectBoundSharedSet;
126 Set<TempDescriptor> liveInTempSetToEventLoop;
128 private Hashtable<Descriptor, Location> mapDescToLocation;
130 private TempDescriptor LOCAL;
132 public static int MAXAGE = 1;
134 public DefinitelyWrittenCheck(SSJavaAnalysis ssjava, State state) {
136 this.ssjava = ssjava;
137 this.callGraph = ssjava.getCallGraph();
138 this.mapFlatNodeToMustWriteSet = new Hashtable<FlatNode, Set<NTuple<Descriptor>>>();
139 this.mapHeapPath = new Hashtable<Descriptor, NTuple<Descriptor>>();
140 this.mapDescriptorToLocationPath = new Hashtable<TempDescriptor, NTuple<Location>>();
141 this.mapFlatMethodToReadSet = new Hashtable<FlatMethod, Set<NTuple<Descriptor>>>();
142 this.mapFlatMethodToMustWriteSet = new Hashtable<FlatMethod, Set<NTuple<Descriptor>>>();
143 this.mapFlatMethodToMayWriteSet = new Hashtable<FlatMethod, Set<NTuple<Descriptor>>>();
144 this.mapFlatNodetoEventLoopMap =
145 new Hashtable<FlatNode, Hashtable<NTuple<Descriptor>, Set<WriteAge>>>();
146 this.calleeUnionBoundReadSet = new HashSet<NTuple<Descriptor>>();
147 this.calleeIntersectBoundMustWriteSet = new HashSet<NTuple<Descriptor>>();
148 this.calleeUnionBoundMayWriteSet = new HashSet<NTuple<Descriptor>>();
150 this.methodDescriptorsToVisitStack = new Stack<MethodDescriptor>();
151 this.calleesToEnqueue = new HashSet<MethodDescriptor>();
152 this.mapTypeToArrayField = new Hashtable<TypeDescriptor, FieldDescriptor>();
153 this.LOCAL = new TempDescriptor("LOCAL");
154 this.mapDescToLocation = new Hashtable<Descriptor, Location>();
155 this.possibleCalleeReadSummarySetToCaller = new HashSet<ReadSummary>();
156 this.mapMethodDescriptorToReadSummary = new Hashtable<MethodDescriptor, ReadSummary>();
157 this.mapFlatNodeToBoundReadSet = new Hashtable<FlatNode, Set<NTuple<Descriptor>>>();
158 this.mapFlatNodeToBoundMustWriteSet = new Hashtable<FlatNode, Set<NTuple<Descriptor>>>();
159 this.mapFlatNodeToBoundMayWriteSet = new Hashtable<FlatNode, Set<NTuple<Descriptor>>>();
160 this.mapFlatNodeToSharedLocMapping = new Hashtable<FlatNode, SharedLocMap>();
161 this.mapFlatMethodToDeleteSet = new Hashtable<FlatMethod, SharedLocMap>();
162 this.calleeUnionBoundDeleteSet = new SharedLocMap();
163 this.calleeIntersectBoundSharedSet = new SharedLocMap();
164 this.mapFlatMethodToSharedLocMap = new Hashtable<FlatMethod, SharedLocMap>();
165 this.mapMethodToSharedLocCoverSet =
166 new Hashtable<MethodDescriptor, MultiSourceMap<NTuple<Location>, NTuple<Descriptor>>>();
167 this.mapFlatNodeToDeleteSet = new Hashtable<FlatNode, SharedLocMap>();
168 this.liveness = new Liveness();
169 this.liveInTempSetToEventLoop = new HashSet<TempDescriptor>();
172 public void definitelyWrittenCheck() {
173 if (!ssjava.getAnnotationRequireSet().isEmpty()) {
176 methodReadWriteSetAnalysis();
177 computeSharedCoverSet();
186 private void sharedLocAnalysis() {
188 // perform method READ/OVERWRITE analysis
189 LinkedList<MethodDescriptor> descriptorListToAnalyze = ssjava.getSortedDescriptors();
191 // current descriptors to visit in fixed-point interprocedural analysis,
193 // dependency in the call graph
194 methodDescriptorsToVisitStack.clear();
196 descriptorListToAnalyze.removeFirst();
198 Set<MethodDescriptor> methodDescriptorToVistSet = new HashSet<MethodDescriptor>();
199 methodDescriptorToVistSet.addAll(descriptorListToAnalyze);
201 while (!descriptorListToAnalyze.isEmpty()) {
202 MethodDescriptor md = descriptorListToAnalyze.removeFirst();
203 methodDescriptorsToVisitStack.add(md);
206 // analyze scheduled methods until there are no more to visit
207 while (!methodDescriptorsToVisitStack.isEmpty()) {
208 // start to analyze leaf node
209 MethodDescriptor md = methodDescriptorsToVisitStack.pop();
210 FlatMethod fm = state.getMethodFlat(md);
212 SharedLocMap sharedLocMap = new SharedLocMap();
213 SharedLocMap deleteSet = new SharedLocMap();
215 sharedLoc_analyzeMethod(fm, sharedLocMap, deleteSet);
216 SharedLocMap prevSharedLocMap = mapFlatMethodToSharedLocMap.get(fm);
217 SharedLocMap prevDeleteSet = mapFlatMethodToDeleteSet.get(fm);
219 if (!(deleteSet.equals(prevDeleteSet) && sharedLocMap.equals(prevSharedLocMap))) {
220 mapFlatMethodToSharedLocMap.put(fm, sharedLocMap);
221 mapFlatMethodToDeleteSet.put(fm, deleteSet);
223 // results for callee changed, so enqueue dependents caller for
226 Iterator<MethodDescriptor> depsItr = ssjava.getDependents(md).iterator();
227 while (depsItr.hasNext()) {
228 MethodDescriptor methodNext = depsItr.next();
229 if (!methodDescriptorsToVisitStack.contains(methodNext)
230 && methodDescriptorToVistSet.contains(methodNext)) {
231 methodDescriptorsToVisitStack.add(methodNext);
240 sharedLoc_analyzeEventLoop();
244 private void sharedLoc_analyzeEventLoop() {
245 if (state.SSJAVADEBUG) {
246 System.out.println("SSJAVA: Definite clearance for shared locations Analyzing: eventloop");
248 SharedLocMap sharedLocMap = new SharedLocMap();
249 SharedLocMap deleteSet = new SharedLocMap();
250 sharedLoc_analyzeBody(state.getMethodFlat(methodContainingSSJavaLoop),
251 ssjava.getSSJavaLoopEntrance(), sharedLocMap, deleteSet, true);
255 private void sharedLoc_analyzeMethod(FlatMethod fm, SharedLocMap sharedLocMap,
256 SharedLocMap deleteSet) {
257 if (state.SSJAVADEBUG) {
258 System.out.println("SSJAVA: Definite clearance for shared locations Analyzing: " + fm);
261 sharedLoc_analyzeBody(fm, fm, sharedLocMap, deleteSet, false);
265 private void sharedLoc_analyzeBody(FlatMethod fm, FlatNode startNode, SharedLocMap sharedLocMap,
266 SharedLocMap deleteSet, boolean isEventLoopBody) {
268 // intraprocedural analysis
269 Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
270 flatNodesToVisit.add(startNode);
272 while (!flatNodesToVisit.isEmpty()) {
273 FlatNode fn = flatNodesToVisit.iterator().next();
274 flatNodesToVisit.remove(fn);
276 SharedLocMap currSharedSet = new SharedLocMap();
277 SharedLocMap currDeleteSet = new SharedLocMap();
279 for (int i = 0; i < fn.numPrev(); i++) {
280 FlatNode prevFn = fn.getPrev(i);
281 SharedLocMap inSharedLoc = mapFlatNodeToSharedLocMapping.get(prevFn);
282 if (inSharedLoc != null) {
283 mergeSharedLocMap(currSharedSet, inSharedLoc);
286 SharedLocMap inDeleteLoc = mapFlatNodeToDeleteSet.get(prevFn);
287 if (inDeleteLoc != null) {
288 mergeDeleteSet(currDeleteSet, inDeleteLoc);
292 sharedLoc_nodeActions(fm, fn, currSharedSet, currDeleteSet, sharedLocMap, deleteSet,
295 SharedLocMap prevSharedSet = mapFlatNodeToSharedLocMapping.get(fn);
296 SharedLocMap prevDeleteSet = mapFlatNodeToDeleteSet.get(fn);
298 if (!(currSharedSet.equals(prevSharedSet) && currDeleteSet.equals(prevDeleteSet))) {
299 mapFlatNodeToSharedLocMapping.put(fn, currSharedSet);
300 mapFlatNodeToDeleteSet.put(fn, currDeleteSet);
301 for (int i = 0; i < fn.numNext(); i++) {
302 FlatNode nn = fn.getNext(i);
303 if ((!isEventLoopBody) || loopIncElements.contains(nn)) {
304 flatNodesToVisit.add(nn);
314 private void sharedLoc_nodeActions(FlatMethod fm, FlatNode fn, SharedLocMap curr,
315 SharedLocMap currDeleteSet, SharedLocMap sharedLocMap, SharedLocMap deleteSet,
316 boolean isEventLoopBody) {
318 MethodDescriptor md = fm.getMethod();
320 SharedLocMap killSet = new SharedLocMap();
321 SharedLocMap genSet = new SharedLocMap();
329 case FKind.FlatOpNode: {
331 if (isEventLoopBody) {
332 FlatOpNode fon = (FlatOpNode) fn;
334 if (fon.getOp().getOp() == Operation.ASSIGN) {
338 if (!lhs.getSymbol().startsWith("neverused") && !lhs.getSymbol().startsWith("leftop")
339 && !lhs.getSymbol().startsWith("rightop") && rhs.getType().isImmutable()) {
341 if (mapHeapPath.containsKey(rhs)) {
342 Location dstLoc = getLocation(lhs);
343 if (dstLoc != null && ssjava.isSharedLocation(dstLoc)) {
344 NTuple<Descriptor> lhsHeapPath = computePath(lhs);
345 NTuple<Location> lhsLocTuple = mapDescriptorToLocationPath.get(lhs);
347 Location srcLoc = getLocation(lhs);
349 // computing gen/kill set
350 computeKILLSetForWrite(curr, killSet, lhsLocTuple, lhsHeapPath);
352 if (!ssjava.isSameHeightWrite(fn)) {
353 computeGENSetForHigherWrite(curr, killSet, lhsLocTuple, lhsHeapPath);
354 updateDeleteSetForHigherWrite(currDeleteSet, lhsLocTuple, lhsHeapPath);
356 computeGENSetForSameHeightWrite(curr, killSet, lhsLocTuple, lhsHeapPath);
357 updateDeleteSetForSameHeightWrite(currDeleteSet, lhsLocTuple, lhsHeapPath);
374 case FKind.FlatSetFieldNode:
375 case FKind.FlatSetElementNode: {
378 if (fn.kind() == FKind.FlatSetFieldNode) {
379 FlatSetFieldNode fsfn = (FlatSetFieldNode) fn;
381 fld = fsfn.getField();
383 fieldLoc = (Location) fld.getType().getExtension();
388 if (!isEventLoopBody && fieldLoc.getDescriptor().equals(md)) {
389 // if the field belongs to the local lattice, no reason to calculate
394 NTuple<Location> fieldLocTuple = new NTuple<Location>();
395 if (fld.isStatic()) {
397 // in this case, fld has TOP location
398 Location topLocation = Location.createTopLocation(md);
399 fieldLocTuple.add(topLocation);
401 fieldLocTuple.addAll(deriveGlobalLocationTuple(md));
402 if (fn.kind() == FKind.FlatSetFieldNode) {
403 fieldLocTuple.add((Location) fld.getType().getExtension());
408 fieldLocTuple.addAll(deriveLocationTuple(md, lhs));
409 if (fn.kind() == FKind.FlatSetFieldNode) {
410 fieldLocTuple.add((Location) fld.getType().getExtension());
414 // shared loc extension
415 Location srcLoc = getLocation(rhs);
416 if (ssjava.isSharedLocation(fieldLoc)) {
417 // only care the case that loc(f) is shared location
420 // NTuple<Location> fieldLocTuple = new NTuple<Location>();
421 // fieldLocTuple.addAll(mapDescriptorToLocationPath.get(lhs));
422 // fieldLocTuple.add(fieldLoc);
424 NTuple<Descriptor> fldHeapPath = new NTuple<Descriptor>();
425 fldHeapPath.addAll(computePath(lhs));
426 if (fn.kind() == FKind.FlatSetFieldNode) {
427 fldHeapPath.add(fld);
430 // computing gen/kill set
431 computeKILLSetForWrite(curr, killSet, fieldLocTuple, fldHeapPath);
433 if (!ssjava.isSameHeightWrite(fn)) {
434 computeGENSetForHigherWrite(curr, genSet, fieldLocTuple, fldHeapPath);
435 updateDeleteSetForHigherWrite(currDeleteSet, fieldLocTuple, fldHeapPath);
437 computeGENSetForSameHeightWrite(curr, genSet, fieldLocTuple, fldHeapPath);
438 updateDeleteSetForSameHeightWrite(currDeleteSet, fieldLocTuple, fldHeapPath);
446 case FKind.FlatCall: {
447 FlatCall fc = (FlatCall) fn;
449 bindHeapPathCallerArgWithCaleeParamForSharedLoc(fm.getMethod(), fc);
451 // computing gen/kill set
452 generateKILLSetForFlatCall(curr, killSet);
453 generateGENSetForFlatCall(curr, genSet);
458 case FKind.FlatExit: {
459 // merge the current delete/shared loc mapping
460 mergeSharedLocMap(sharedLocMap, curr);
461 mergeDeleteSet(deleteSet, currDeleteSet);
468 computeNewMapping(curr, killSet, genSet);
472 private void generateGENSetForFlatCall(SharedLocMap curr, SharedLocMap genSet) {
474 Set<NTuple<Location>> locTupleSet = calleeIntersectBoundSharedSet.keySet();
475 for (Iterator iterator = locTupleSet.iterator(); iterator.hasNext();) {
476 NTuple<Location> locTupleKey = (NTuple<Location>) iterator.next();
477 genSet.addWrite(locTupleKey, curr.get(locTupleKey));
478 genSet.addWrite(locTupleKey, calleeIntersectBoundSharedSet.get(locTupleKey));
480 genSet.removeWriteAll(locTupleKey, calleeUnionBoundDeleteSet.get(locTupleKey));
485 private void generateKILLSetForFlatCall(SharedLocMap curr, SharedLocMap killSet) {
487 Set<NTuple<Location>> locTupleSet = calleeIntersectBoundSharedSet.keySet();
488 for (Iterator iterator = locTupleSet.iterator(); iterator.hasNext();) {
489 NTuple<Location> locTupleKey = (NTuple<Location>) iterator.next();
490 killSet.addWrite(locTupleKey, curr.get(locTupleKey));
495 private void mergeDeleteSet(SharedLocMap currDeleteSet, SharedLocMap inDeleteLoc) {
497 Set<NTuple<Location>> locTupleKeySet = inDeleteLoc.keySet();
499 for (Iterator iterator = locTupleKeySet.iterator(); iterator.hasNext();) {
500 NTuple<Location> locTupleKey = (NTuple<Location>) iterator.next();
502 Set<NTuple<Descriptor>> inSet = inDeleteLoc.get(locTupleKey);
503 currDeleteSet.addWrite(locTupleKey, inSet);
508 private void computeNewMapping(SharedLocMap curr, SharedLocMap killSet, SharedLocMap genSet) {
513 private void updateDeleteSetForHigherWrite(SharedLocMap currDeleteSet, NTuple<Location> locTuple,
514 NTuple<Descriptor> hp) {
515 currDeleteSet.removeWrite(locTuple, hp);
518 private void updateDeleteSetForSameHeightWrite(SharedLocMap currDeleteSet,
519 NTuple<Location> locTuple, NTuple<Descriptor> hp) {
520 currDeleteSet.addWrite(locTuple, hp);
523 private void computeGENSetForHigherWrite(SharedLocMap curr, SharedLocMap genSet,
524 NTuple<Location> locTuple, NTuple<Descriptor> hp) {
525 Set<NTuple<Descriptor>> currWriteSet = curr.get(locTuple);
527 if (currWriteSet != null) {
528 genSet.addWrite(locTuple, currWriteSet);
531 genSet.addWrite(locTuple, hp);
534 private void computeGENSetForSameHeightWrite(SharedLocMap curr, SharedLocMap genSet,
535 NTuple<Location> locTuple, NTuple<Descriptor> hp) {
536 Set<NTuple<Descriptor>> currWriteSet = curr.get(locTuple);
538 if (currWriteSet != null) {
539 genSet.addWrite(locTuple, currWriteSet);
541 genSet.removeWrite(locTuple, hp);
544 private void computeKILLSetForWrite(SharedLocMap curr, SharedLocMap killSet,
545 NTuple<Location> locTuple, NTuple<Descriptor> hp) {
547 Set<NTuple<Descriptor>> writeSet = curr.get(locTuple);
548 if (writeSet != null) {
549 killSet.addWrite(locTuple, writeSet);
554 private void mergeSharedLocMap(SharedLocMap currSharedSet, SharedLocMap in) {
556 Set<NTuple<Location>> locTupleKeySet = in.keySet();
557 for (Iterator iterator = locTupleKeySet.iterator(); iterator.hasNext();) {
558 NTuple<Location> locTupleKey = (NTuple<Location>) iterator.next();
560 Set<NTuple<Descriptor>> inSet = in.get(locTupleKey);
561 Set<NTuple<Descriptor>> currSet = currSharedSet.get(locTupleKey);
562 if (currSet == null) {
563 currSet = new HashSet<NTuple<Descriptor>>();
564 currSet.addAll(inSet);
565 currSharedSet.addWrite(locTupleKey, currSet);
567 currSet.retainAll(inSet);
572 private void computeSharedCoverSet() {
573 LinkedList<MethodDescriptor> descriptorListToAnalyze = ssjava.getSortedDescriptors();
575 // current descriptors to visit in fixed-point interprocedural analysis,
577 // dependency in the call graph
578 methodDescriptorsToVisitStack.clear();
580 descriptorListToAnalyze.removeFirst();
582 Set<MethodDescriptor> methodDescriptorToVistSet = new HashSet<MethodDescriptor>();
583 methodDescriptorToVistSet.addAll(descriptorListToAnalyze);
585 while (!descriptorListToAnalyze.isEmpty()) {
586 MethodDescriptor md = descriptorListToAnalyze.removeFirst();
587 methodDescriptorsToVisitStack.add(md);
590 // analyze scheduled methods until there are no more to visit
591 while (!methodDescriptorsToVisitStack.isEmpty()) {
592 MethodDescriptor md = methodDescriptorsToVisitStack.pop();
593 FlatMethod fm = state.getMethodFlat(md);
594 computeSharedCoverSet_analyzeMethod(fm, md.equals(methodContainingSSJavaLoop));
597 computeSharedCoverSetForEventLoop();
601 private void computeSharedCoverSetForEventLoop() {
602 computeSharedCoverSet_analyzeMethod(state.getMethodFlat(methodContainingSSJavaLoop), true);
605 private void computeSharedCoverSet_analyzeMethod(FlatMethod fm, boolean onlyVisitSSJavaLoop) {
607 // System.out.println("computeSharedCoverSet_analyzeMethod=" + fm);
608 MethodDescriptor md = fm.getMethod();
610 Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
612 Set<FlatNode> visited = new HashSet<FlatNode>();
614 if (onlyVisitSSJavaLoop) {
615 flatNodesToVisit.add(ssjava.getSSJavaLoopEntrance());
617 flatNodesToVisit.add(fm);
620 while (!flatNodesToVisit.isEmpty()) {
621 FlatNode fn = flatNodesToVisit.iterator().next();
622 flatNodesToVisit.remove(fn);
625 computeSharedCoverSet_nodeActions(md, fn, onlyVisitSSJavaLoop);
627 for (int i = 0; i < fn.numNext(); i++) {
628 FlatNode nn = fn.getNext(i);
630 if (!visited.contains(nn)) {
631 if (!onlyVisitSSJavaLoop || (onlyVisitSSJavaLoop && loopIncElements.contains(nn))) {
632 flatNodesToVisit.add(nn);
642 private void computeSharedCoverSet_nodeActions(MethodDescriptor md, FlatNode fn,
643 boolean isEventLoopBody) {
650 case FKind.FlatLiteralNode: {
651 FlatLiteralNode fln = (FlatLiteralNode) fn;
654 NTuple<Location> lhsLocTuple = new NTuple<Location>();
655 lhsLocTuple.add(Location.createTopLocation(md));
656 mapDescriptorToLocationPath.put(lhs, lhsLocTuple);
658 if (lhs.getType().isPrimitive() && !lhs.getSymbol().startsWith("neverused")
659 && !lhs.getSymbol().startsWith("srctmp")) {
660 // only need to care about composite location case here
661 if (lhs.getType().getExtension() instanceof SSJavaType) {
662 CompositeLocation compLoc = ((SSJavaType) lhs.getType().getExtension()).getCompLoc();
663 Location lastLocElement = compLoc.get(compLoc.getSize() - 1);
670 case FKind.FlatOpNode: {
671 FlatOpNode fon = (FlatOpNode) fn;
672 // for a normal assign node, need to propagate lhs's location path to
674 if (fon.getOp().getOp() == Operation.ASSIGN) {
678 if (!lhs.getSymbol().startsWith("neverused") && !lhs.getSymbol().startsWith("leftop")
679 && !lhs.getSymbol().startsWith("rightop")) {
681 if (mapHeapPath.containsKey(rhs)) {
682 NTuple<Location> rhsLocTuple = new NTuple<Location>();
683 NTuple<Location> lhsLocTuple = new NTuple<Location>();
684 if (mapDescriptorToLocationPath.containsKey(rhs)) {
685 mapDescriptorToLocationPath.put(lhs, deriveLocationTuple(md, rhs));
686 lhsLocTuple = mapDescriptorToLocationPath.get(lhs);
689 if (rhs.getType().getExtension() != null
690 && rhs.getType().getExtension() instanceof SSJavaType) {
692 if (((SSJavaType) rhs.getType().getExtension()).getCompLoc() != null) {
693 rhsLocTuple.addAll(((SSJavaType) rhs.getType().getExtension()).getCompLoc()
698 NTuple<Location> locTuple = deriveLocationTuple(md, rhs);
699 if (locTuple != null) {
700 rhsLocTuple.addAll(locTuple);
703 if (rhsLocTuple.size() > 0) {
704 mapDescriptorToLocationPath.put(rhs, rhsLocTuple);
708 if (lhs.getType().getExtension() != null
709 && lhs.getType().getExtension() instanceof SSJavaType) {
710 lhsLocTuple.addAll(((SSJavaType) lhs.getType().getExtension()).getCompLoc()
712 mapDescriptorToLocationPath.put(lhs, lhsLocTuple);
713 } else if (mapDescriptorToLocationPath.get(rhs) != null) {
714 // propagate rhs's location to lhs
715 lhsLocTuple.addAll(mapDescriptorToLocationPath.get(rhs));
716 mapDescriptorToLocationPath.put(lhs, lhsLocTuple);
720 if (isEventLoopBody && lhs.getType().isPrimitive()
721 && !lhs.getSymbol().startsWith("srctmp")) {
723 NTuple<Descriptor> lhsHeapPath = computePath(lhs);
725 if (lhsLocTuple != null) {
726 addMayWrittenSet(md, lhsLocTuple, lhsHeapPath);
740 case FKind.FlatSetFieldNode:
741 case FKind.FlatSetElementNode: {
745 if (fn.kind() == FKind.FlatSetFieldNode) {
746 FlatSetFieldNode fsfn = (FlatSetFieldNode) fn;
748 fld = fsfn.getField();
751 FlatSetElementNode fsen = (FlatSetElementNode) fn;
754 TypeDescriptor td = lhs.getType().dereference();
755 fld = getArrayField(td);
758 NTuple<Location> lhsLocTuple = new NTuple<Location>();
759 if (fld.isStatic()) {
761 // in this case, fld has TOP location
762 Location topLocation = Location.createTopLocation(md);
763 lhsLocTuple.add(topLocation);
765 lhsLocTuple.addAll(deriveGlobalLocationTuple(md));
768 lhsLocTuple.addAll(deriveLocationTuple(md, lhs));
771 mapDescriptorToLocationPath.put(lhs, lhsLocTuple);
773 NTuple<Location> fieldLocTuple = new NTuple<Location>();
774 fieldLocTuple.addAll(lhsLocTuple);
776 if (fn.kind() == FKind.FlatSetFieldNode) {
777 fieldLocTuple.add((Location) fld.getType().getExtension());
780 if (mapHeapPath.containsKey(lhs)) {
781 // fields reachable from the param can have heap path entry.
782 NTuple<Descriptor> lhsHeapPath = new NTuple<Descriptor>();
783 lhsHeapPath.addAll(mapHeapPath.get(lhs));
785 Location fieldLocation;
786 if (fn.kind() == FKind.FlatSetFieldNode) {
787 fieldLocation = getLocation(fld);
789 fieldLocation = getLocation(lhsHeapPath.get(getArrayBaseDescriptorIdx(lhsHeapPath)));
792 // Location fieldLocation = getLocation(lhs);
793 if (!isEventLoopBody && fieldLocation.getDescriptor().equals(md)) {
794 // if the field belongs to the local lattice, no reason to calculate
799 if (ssjava.isSharedLocation(fieldLocation)) {
801 NTuple<Descriptor> fieldHeapPath = new NTuple<Descriptor>();
802 fieldHeapPath.addAll(computePath(lhs));
803 if (fn.kind() == FKind.FlatSetFieldNode) {
804 fieldHeapPath.add(fld);
807 addMayWrittenSet(md, fieldLocTuple, fieldHeapPath);
815 case FKind.FlatElementNode:
816 case FKind.FlatFieldNode: {
820 if (fn.kind() == FKind.FlatFieldNode) {
821 FlatFieldNode ffn = (FlatFieldNode) fn;
824 fld = ffn.getField();
826 FlatElementNode fen = (FlatElementNode) fn;
829 TypeDescriptor td = rhs.getType().dereference();
830 fld = getArrayField(td);
833 NTuple<Location> locTuple = new NTuple<Location>();
835 if (fld.isStatic()) {
838 // in this case, fld has TOP location
839 Location topLocation = Location.createTopLocation(md);
840 locTuple.add(topLocation);
842 locTuple.addAll(deriveGlobalLocationTuple(md));
843 if (fn.kind() == FKind.FlatFieldNode) {
844 locTuple.add((Location) fld.getType().getExtension());
849 locTuple.addAll(deriveLocationTuple(md, rhs));
850 if (fn.kind() == FKind.FlatFieldNode) {
851 locTuple.add((Location) fld.getType().getExtension());
855 mapDescriptorToLocationPath.put(lhs, locTuple);
860 case FKind.FlatCall: {
862 FlatCall fc = (FlatCall) fn;
864 bindLocationPathCallerArgWithCalleeParam(md, fc);
869 case FKind.FlatNew: {
871 FlatNew fnew = (FlatNew) fn;
872 TempDescriptor dst = fnew.getDst();
873 NTuple<Location> locTuple = deriveLocationTuple(md, dst);
875 if (locTuple != null) {
876 NTuple<Location> dstLocTuple = new NTuple<Location>();
877 dstLocTuple.addAll(locTuple);
878 mapDescriptorToLocationPath.put(dst, dstLocTuple);
886 private void addMayWrittenSet(MethodDescriptor md, NTuple<Location> locTuple,
887 NTuple<Descriptor> heapPath) {
889 MultiSourceMap<NTuple<Location>, NTuple<Descriptor>> map = mapMethodToSharedLocCoverSet.get(md);
891 map = new MultiSourceMap<NTuple<Location>, NTuple<Descriptor>>();
892 mapMethodToSharedLocCoverSet.put(md, map);
895 Set<NTuple<Descriptor>> writeSet = map.get(locTuple);
896 if (writeSet == null) {
897 writeSet = new HashSet<NTuple<Descriptor>>();
898 map.put(locTuple, writeSet);
900 writeSet.add(heapPath);
904 private void bindLocationPathCallerArgWithCalleeParam(MethodDescriptor mdCaller, FlatCall fc) {
906 if (ssjava.isSSJavaUtil(fc.getMethod().getClassDesc())) {
908 // have write effects on the first argument
909 TempDescriptor arg = fc.getArg(0);
910 NTuple<Location> argLocationPath = deriveLocationTuple(mdCaller, arg);
911 NTuple<Descriptor> argHeapPath = computePath(arg);
912 addMayWrittenSet(mdCaller, argLocationPath, argHeapPath);
913 } else if (ssjava.needTobeAnnotated(fc.getMethod())) {
915 // if arg is not primitive type, we need to propagate maywritten set to
916 // the caller's location path
918 MethodDescriptor mdCallee = fc.getMethod();
919 Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
920 setPossibleCallees.addAll(callGraph.getMethods(mdCallee));
922 // create mapping from arg idx to its heap paths
923 Hashtable<Integer, NTuple<Descriptor>> mapArgIdx2CallerArgHeapPath =
924 new Hashtable<Integer, NTuple<Descriptor>>();
926 // create mapping from arg idx to its location paths
927 Hashtable<Integer, NTuple<Location>> mapArgIdx2CallerArgLocationPath =
928 new Hashtable<Integer, NTuple<Location>>();
930 if (fc.getThis() != null) {
932 if (mapHeapPath.containsKey(fc.getThis())) {
934 // setup heap path for 'this'
935 NTuple<Descriptor> thisHeapPath = new NTuple<Descriptor>();
936 thisHeapPath.addAll(mapHeapPath.get(fc.getThis()));
937 mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(0), thisHeapPath);
939 // setup location path for 'this'
940 NTuple<Location> thisLocationPath = deriveLocationTuple(mdCaller, fc.getThis());
941 mapArgIdx2CallerArgLocationPath.put(Integer.valueOf(0), thisLocationPath);
946 for (int i = 0; i < fc.numArgs(); i++) {
947 TempDescriptor arg = fc.getArg(i);
948 // create mapping arg to loc path
950 if (mapHeapPath.containsKey(arg)) {
952 NTuple<Descriptor> argHeapPath = mapHeapPath.get(arg);
953 mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(i + 1), argHeapPath);
955 NTuple<Location> argLocationPath = deriveLocationTuple(mdCaller, arg);
956 mapArgIdx2CallerArgLocationPath.put(Integer.valueOf(i + 1), argLocationPath);
961 for (Iterator iterator = setPossibleCallees.iterator(); iterator.hasNext();) {
962 MethodDescriptor callee = (MethodDescriptor) iterator.next();
963 FlatMethod calleeFlatMethod = state.getMethodFlat(callee);
965 // binding caller's args and callee's params
967 Hashtable<NTuple<Descriptor>, NTuple<Descriptor>> mapParamHeapPathToCallerArgHeapPath =
968 new Hashtable<NTuple<Descriptor>, NTuple<Descriptor>>();
970 Hashtable<Integer, TempDescriptor> mapParamIdx2ParamTempDesc =
971 new Hashtable<Integer, TempDescriptor>();
973 if (calleeFlatMethod.getMethod().isStatic()) {
974 // static method does not have implicit 'this' arg
978 for (int i = 0; i < calleeFlatMethod.numParameters(); i++) {
979 TempDescriptor param = calleeFlatMethod.getParameter(i);
980 mapParamIdx2ParamTempDesc.put(Integer.valueOf(i + offset), param);
982 NTuple<Descriptor> calleeHeapPath = computePath(param);
984 NTuple<Descriptor> argHeapPath =
985 mapArgIdx2CallerArgHeapPath.get(Integer.valueOf(i + offset));
987 if (argHeapPath != null) {
988 mapParamHeapPathToCallerArgHeapPath.put(calleeHeapPath, argHeapPath);
994 Set<Integer> keySet = mapArgIdx2CallerArgLocationPath.keySet();
995 for (Iterator iterator2 = keySet.iterator(); iterator2.hasNext();) {
996 Integer idx = (Integer) iterator2.next();
998 NTuple<Location> callerArgLocationPath = mapArgIdx2CallerArgLocationPath.get(idx);
1000 TempDescriptor calleeParam = mapParamIdx2ParamTempDesc.get(idx);
1001 NTuple<Location> calleeLocationPath = deriveLocationTuple(mdCallee, calleeParam);
1003 NTuple<Descriptor> callerArgHeapPath = mapArgIdx2CallerArgHeapPath.get(idx);
1004 NTuple<Descriptor> calleeHeapPath = computePath(calleeParam);
1006 if (!calleeParam.getType().isPrimitive()) {
1007 createNewMappingOfMayWrittenSet(mdCaller, callee, callerArgHeapPath,
1008 callerArgLocationPath, calleeHeapPath, calleeLocationPath,
1009 mapParamHeapPathToCallerArgHeapPath);
1019 private Hashtable<NTuple<Location>, Set<NTuple<Descriptor>>> getMappingByStartedWith(
1020 MultiSourceMap<NTuple<Location>, NTuple<Descriptor>> map, NTuple<Location> in) {
1022 Hashtable<NTuple<Location>, Set<NTuple<Descriptor>>> matchedMapping =
1023 new Hashtable<NTuple<Location>, Set<NTuple<Descriptor>>>();
1025 Set<NTuple<Location>> keySet = map.keySet();
1027 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
1028 NTuple<Location> key = (NTuple<Location>) iterator.next();
1029 if (key.startsWith(in)) {
1030 matchedMapping.put(key, map.get(key));
1034 return matchedMapping;
1038 private void createNewMappingOfMayWrittenSet(MethodDescriptor caller, MethodDescriptor callee,
1039 NTuple<Descriptor> callerArgHeapPath, NTuple<Location> callerArgLocPath,
1040 NTuple<Descriptor> calleeParamHeapPath, NTuple<Location> calleeParamLocPath,
1041 Hashtable<NTuple<Descriptor>, NTuple<Descriptor>> mapParamHeapPathToCallerArgHeapPath) {
1043 // propagate may-written-set associated with the key that is started with
1044 // calleepath to the caller
1045 // 1) makes a new key by combining caller path and callee path(except local
1046 // loc element of param)
1047 // 2) create new mapping of may-written-set of callee path to caller path
1049 // extract all may written effect accessed through callee param path
1050 MultiSourceMap<NTuple<Location>, NTuple<Descriptor>> calleeMapping =
1051 mapMethodToSharedLocCoverSet.get(callee);
1053 if (calleeMapping == null) {
1057 MultiSourceMap<NTuple<Location>, NTuple<Descriptor>> callerMapping =
1058 mapMethodToSharedLocCoverSet.get(caller);
1060 if (callerMapping == null) {
1061 callerMapping = new MultiSourceMap<NTuple<Location>, NTuple<Descriptor>>();
1062 mapMethodToSharedLocCoverSet.put(caller, callerMapping);
1065 Hashtable<NTuple<Location>, Set<NTuple<Descriptor>>> paramMapping =
1066 getMappingByStartedWith(calleeMapping, calleeParamLocPath);
1068 Set<NTuple<Location>> calleeKeySet = paramMapping.keySet();
1070 for (Iterator iterator = calleeKeySet.iterator(); iterator.hasNext();) {
1071 NTuple<Location> calleeKey = (NTuple<Location>) iterator.next();
1073 Set<NTuple<Descriptor>> calleeMayWriteSet = paramMapping.get(calleeKey);
1075 if (calleeMayWriteSet != null) {
1077 Set<NTuple<Descriptor>> boundMayWriteSet = new HashSet<NTuple<Descriptor>>();
1079 Set<NTuple<Descriptor>> boundSet =
1080 convertToCallerMayWriteSet(calleeParamHeapPath, calleeMayWriteSet, callerMapping,
1081 mapParamHeapPathToCallerArgHeapPath);
1083 boundMayWriteSet.addAll(boundSet);
1085 NTuple<Location> newKey = new NTuple<Location>();
1086 newKey.addAll(callerArgLocPath);
1087 // need to replace the local location with the caller's path so skip the
1088 // local location of the parameter
1089 for (int i = 1; i < calleeKey.size(); i++) {
1090 newKey.add(calleeKey.get(i));
1093 callerMapping.union(newKey, boundMayWriteSet);
1100 private Set<NTuple<Descriptor>> convertToCallerMayWriteSet(
1101 NTuple<Descriptor> calleeParamHeapPath, Set<NTuple<Descriptor>> calleeMayWriteSet,
1102 MultiSourceMap<NTuple<Location>, NTuple<Descriptor>> callerMapping,
1103 Hashtable<NTuple<Descriptor>, NTuple<Descriptor>> mapParamHeapPathToCallerArgHeapPath) {
1105 Set<NTuple<Descriptor>> boundSet = new HashSet<NTuple<Descriptor>>();
1107 // replace callee's param path with caller's arg path
1108 for (Iterator iterator = calleeMayWriteSet.iterator(); iterator.hasNext();) {
1109 NTuple<Descriptor> calleeWriteHeapPath = (NTuple<Descriptor>) iterator.next();
1111 NTuple<Descriptor> writeHeapPathParamHeapPath = calleeWriteHeapPath.subList(0, 1);
1113 NTuple<Descriptor> callerArgHeapPath =
1114 mapParamHeapPathToCallerArgHeapPath.get(writeHeapPathParamHeapPath);
1116 NTuple<Descriptor> boundHeapPath = new NTuple<Descriptor>();
1117 boundHeapPath.addAll(callerArgHeapPath);
1119 for (int i = 1; i < calleeWriteHeapPath.size(); i++) {
1120 boundHeapPath.add(calleeWriteHeapPath.get(i));
1123 boundSet.add(boundHeapPath);
1130 private Location getLocation(Descriptor d) {
1132 if (d instanceof FieldDescriptor) {
1133 TypeExtension te = ((FieldDescriptor) d).getType().getExtension();
1135 return (Location) te;
1138 assert d instanceof TempDescriptor;
1139 TempDescriptor td = (TempDescriptor) d;
1141 TypeExtension te = td.getType().getExtension();
1143 if (te instanceof SSJavaType) {
1144 SSJavaType ssType = (SSJavaType) te;
1145 if (ssType.getCompLoc() != null) {
1146 CompositeLocation comp = ssType.getCompLoc();
1147 return comp.get(comp.getSize() - 1);
1152 return (Location) te;
1157 return mapDescToLocation.get(d);
1160 private void eventLoopAnalysis() {
1161 // perform second stage analysis: intraprocedural analysis ensure that
1163 // variables are definitely written in-between the same read
1165 Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
1166 flatNodesToVisit.add(ssjava.getSSJavaLoopEntrance());
1168 while (!flatNodesToVisit.isEmpty()) {
1169 FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next();
1170 flatNodesToVisit.remove(fn);
1172 Hashtable<NTuple<Descriptor>, Set<WriteAge>> prev = mapFlatNodetoEventLoopMap.get(fn);
1174 Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr =
1175 new Hashtable<NTuple<Descriptor>, Set<WriteAge>>();
1176 for (int i = 0; i < fn.numPrev(); i++) {
1177 FlatNode nn = fn.getPrev(i);
1178 Hashtable<NTuple<Descriptor>, Set<WriteAge>> in = mapFlatNodetoEventLoopMap.get(nn);
1184 eventLoopAnalysis_nodeAction(fn, curr, ssjava.getSSJavaLoopEntrance());
1186 // if a new result, schedule forward nodes for analysis
1187 if (!curr.equals(prev)) {
1188 mapFlatNodetoEventLoopMap.put(fn, curr);
1190 for (int i = 0; i < fn.numNext(); i++) {
1191 FlatNode nn = fn.getNext(i);
1192 if (loopIncElements.contains(nn)) {
1193 flatNodesToVisit.add(nn);
1201 private void union(Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr,
1202 Hashtable<NTuple<Descriptor>, Set<WriteAge>> in) {
1204 Set<NTuple<Descriptor>> inKeySet = in.keySet();
1205 for (Iterator iterator = inKeySet.iterator(); iterator.hasNext();) {
1206 NTuple<Descriptor> inKey = (NTuple<Descriptor>) iterator.next();
1207 Set<WriteAge> inSet = in.get(inKey);
1209 Set<WriteAge> currSet = curr.get(inKey);
1211 if (currSet == null) {
1212 currSet = new HashSet<WriteAge>();
1213 curr.put(inKey, currSet);
1215 currSet.addAll(inSet);
1220 private void eventLoopAnalysis_nodeAction(FlatNode fn,
1221 Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr, FlatNode loopEntrance) {
1223 Hashtable<NTuple<Descriptor>, Set<WriteAge>> readWriteKillSet =
1224 new Hashtable<NTuple<Descriptor>, Set<WriteAge>>();
1225 Hashtable<NTuple<Descriptor>, Set<WriteAge>> readWriteGenSet =
1226 new Hashtable<NTuple<Descriptor>, Set<WriteAge>>();
1228 if (fn.equals(loopEntrance)) {
1229 // it reaches loop entrance: changes all flag to true
1230 Set<NTuple<Descriptor>> keySet = curr.keySet();
1231 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
1232 NTuple<Descriptor> key = (NTuple<Descriptor>) iterator.next();
1233 Set<WriteAge> writeAgeSet = curr.get(key);
1235 Set<WriteAge> incSet = new HashSet<WriteAge>();
1236 incSet.addAll(writeAgeSet);
1237 writeAgeSet.clear();
1239 for (Iterator iterator2 = incSet.iterator(); iterator2.hasNext();) {
1240 WriteAge writeAge = (WriteAge) iterator2.next();
1241 WriteAge newWriteAge = writeAge.copy();
1243 writeAgeSet.add(newWriteAge);
1251 FieldDescriptor fld;
1253 switch (fn.kind()) {
1255 case FKind.FlatOpNode: {
1256 FlatOpNode fon = (FlatOpNode) fn;
1257 lhs = fon.getDest();
1258 rhs = fon.getLeft();
1260 if (fon.getOp().getOp() == Operation.ASSIGN) {
1262 if (!lhs.getSymbol().startsWith("neverused") && !lhs.getSymbol().startsWith("leftop")
1263 && !lhs.getSymbol().startsWith("rightop")) {
1265 boolean hasWriteEffect = false;
1267 if (rhs.getType().getExtension() instanceof SSJavaType
1268 && lhs.getType().getExtension() instanceof SSJavaType) {
1270 CompositeLocation rhsCompLoc =
1271 ((SSJavaType) rhs.getType().getExtension()).getCompLoc();
1273 CompositeLocation lhsCompLoc =
1274 ((SSJavaType) lhs.getType().getExtension()).getCompLoc();
1276 if (lhsCompLoc != rhsCompLoc) {
1277 // have a write effect!
1278 hasWriteEffect = true;
1281 } else if (lhs.getType().isImmutable()) {
1282 hasWriteEffect = true;
1285 if (hasWriteEffect && mapHeapPath.containsKey(lhs)) {
1287 NTuple<Descriptor> lhsHeapPath = new NTuple<Descriptor>();
1288 lhsHeapPath.addAll(mapHeapPath.get(lhs));
1290 Location lhsLoc = getLocation(lhs);
1291 if (ssjava.isSharedLocation(lhsLoc)) {
1293 NTuple<Descriptor> varHeapPath = computePath(lhs);
1294 NTuple<Location> varLocTuple = mapDescriptorToLocationPath.get(lhs);
1296 Set<NTuple<Descriptor>> writtenSet =
1297 mapFlatNodeToSharedLocMapping.get(fn).get(varLocTuple);
1299 if (isCovered(varLocTuple, writtenSet)) {
1300 computeKILLSetForSharedWrite(curr, writtenSet, readWriteKillSet);
1301 computeGENSetForSharedAllCoverWrite(curr, writtenSet, readWriteGenSet);
1303 computeGENSetForSharedNonCoverWrite(curr, varHeapPath, readWriteGenSet);
1308 computeKILLSetForWrite(curr, lhsHeapPath, readWriteKillSet);
1309 computeGENSetForWrite(lhsHeapPath, readWriteGenSet);
1312 Set<WriteAge> writeAgeSet = curr.get(lhsHeapPath);
1313 checkWriteAgeSet(writeAgeSet, lhsHeapPath, fn);
1323 case FKind.FlatFieldNode:
1324 case FKind.FlatElementNode: {
1326 if (fn.kind() == FKind.FlatFieldNode) {
1327 FlatFieldNode ffn = (FlatFieldNode) fn;
1330 fld = ffn.getField();
1332 FlatElementNode fen = (FlatElementNode) fn;
1335 TypeDescriptor td = rhs.getType().dereference();
1336 fld = getArrayField(td);
1340 NTuple<Descriptor> srcHeapPath = mapHeapPath.get(rhs);
1341 NTuple<Descriptor> fldHeapPath;
1342 if (srcHeapPath != null) {
1343 fldHeapPath = new NTuple<Descriptor>(srcHeapPath.getList());
1345 // if srcHeapPath is null, it is static reference
1346 fldHeapPath = new NTuple<Descriptor>();
1347 fldHeapPath.add(rhs);
1349 fldHeapPath.add(fld);
1351 Set<WriteAge> writeAgeSet = curr.get(fldHeapPath);
1353 checkWriteAgeSet(writeAgeSet, fldHeapPath, fn);
1358 case FKind.FlatSetFieldNode:
1359 case FKind.FlatSetElementNode: {
1361 if (fn.kind() == FKind.FlatSetFieldNode) {
1362 FlatSetFieldNode fsfn = (FlatSetFieldNode) fn;
1363 lhs = fsfn.getDst();
1364 fld = fsfn.getField();
1366 FlatSetElementNode fsen = (FlatSetElementNode) fn;
1367 lhs = fsen.getDst();
1368 rhs = fsen.getSrc();
1369 TypeDescriptor td = lhs.getType().dereference();
1370 fld = getArrayField(td);
1374 NTuple<Descriptor> lhsHeapPath = mapHeapPath.get(lhs);
1375 if (lhsHeapPath != null) {
1377 NTuple<Descriptor> fldHeapPath = new NTuple<Descriptor>(lhsHeapPath.getList());
1378 if (fn.kind() == FKind.FlatSetFieldNode) {
1379 fldHeapPath.add(fld);
1382 // shared loc extension
1384 if (fn.kind() == FKind.FlatSetFieldNode) {
1385 fieldLoc = (Location) fld.getType().getExtension();
1387 NTuple<Location> locTuple = mapDescriptorToLocationPath.get(lhs);
1388 fieldLoc = locTuple.get(locTuple.size() - 1);
1391 if (ssjava.isSharedLocation(fieldLoc)) {
1393 NTuple<Location> fieldLocTuple = new NTuple<Location>();
1394 fieldLocTuple.addAll(mapDescriptorToLocationPath.get(lhs));
1395 if (fn.kind() == FKind.FlatSetFieldNode) {
1396 fieldLocTuple.add(fieldLoc);
1399 Set<NTuple<Descriptor>> writtenSet =
1400 mapFlatNodeToSharedLocMapping.get(fn).get(fieldLocTuple);
1402 if (isCovered(fieldLocTuple, writtenSet)) {
1403 computeKILLSetForSharedWrite(curr, writtenSet, readWriteKillSet);
1404 computeGENSetForSharedAllCoverWrite(curr, writtenSet, readWriteGenSet);
1406 computeGENSetForSharedNonCoverWrite(curr, fldHeapPath, readWriteGenSet);
1410 computeKILLSetForWrite(curr, fldHeapPath, readWriteKillSet);
1411 computeGENSetForWrite(fldHeapPath, readWriteGenSet);
1419 case FKind.FlatCall: {
1420 FlatCall fc = (FlatCall) fn;
1422 SharedLocMap sharedLocMap = mapFlatNodeToSharedLocMapping.get(fc);
1423 generateKILLSetForFlatCall(fc, curr, sharedLocMap, readWriteKillSet);
1424 generateGENSetForFlatCall(fc, sharedLocMap, readWriteGenSet);
1431 computeNewMapping(curr, readWriteKillSet, readWriteGenSet);
1432 if (fn instanceof FlatCall) {
1433 checkManyRead((FlatCall) fn, curr);
1440 private void computeGENSetForSharedNonCoverWrite(
1441 Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr, NTuple<Descriptor> heapPath,
1442 Hashtable<NTuple<Descriptor>, Set<WriteAge>> genSet) {
1444 Set<WriteAge> writeAgeSet = genSet.get(heapPath);
1445 if (writeAgeSet == null) {
1446 writeAgeSet = new HashSet<WriteAge>();
1447 genSet.put(heapPath, writeAgeSet);
1450 writeAgeSet.add(new WriteAge(1));
1454 private void computeGENSetForSharedAllCoverWrite(
1455 Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr, Set<NTuple<Descriptor>> writtenSet,
1456 Hashtable<NTuple<Descriptor>, Set<WriteAge>> genSet) {
1458 for (Iterator iterator = writtenSet.iterator(); iterator.hasNext();) {
1459 NTuple<Descriptor> writeHeapPath = (NTuple<Descriptor>) iterator.next();
1461 Set<WriteAge> writeAgeSet = new HashSet<WriteAge>();
1462 writeAgeSet.add(new WriteAge(0));
1464 genSet.put(writeHeapPath, writeAgeSet);
1469 private void computeKILLSetForSharedWrite(Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr,
1470 Set<NTuple<Descriptor>> writtenSet, Hashtable<NTuple<Descriptor>, Set<WriteAge>> killSet) {
1472 for (Iterator iterator = writtenSet.iterator(); iterator.hasNext();) {
1473 NTuple<Descriptor> writeHeapPath = (NTuple<Descriptor>) iterator.next();
1474 Set<WriteAge> writeSet = curr.get(writeHeapPath);
1475 if (writeSet != null) {
1476 killSet.put(writeHeapPath, writeSet);
1482 private boolean isCovered(NTuple<Location> locTuple, Set<NTuple<Descriptor>> inSet) {
1484 if (inSet == null) {
1488 Set<NTuple<Descriptor>> coverSet =
1489 mapMethodToSharedLocCoverSet.get(methodContainingSSJavaLoop).get(locTuple);
1491 return inSet.containsAll(coverSet);
1494 private void checkManyRead(FlatCall fc, Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr) {
1496 Set<NTuple<Descriptor>> boundReadSet = mapFlatNodeToBoundReadSet.get(fc);
1498 for (Iterator iterator = boundReadSet.iterator(); iterator.hasNext();) {
1499 NTuple<Descriptor> readHeapPath = (NTuple<Descriptor>) iterator.next();
1500 Set<WriteAge> writeAgeSet = curr.get(readHeapPath);
1501 checkWriteAgeSet(writeAgeSet, readHeapPath, fc);
1506 private void checkWriteAgeSet(Set<WriteAge> writeAgeSet, NTuple<Descriptor> path, FlatNode fn) {
1508 if (writeAgeSet != null) {
1509 for (Iterator iterator = writeAgeSet.iterator(); iterator.hasNext();) {
1510 WriteAge writeAge = (WriteAge) iterator.next();
1511 if (writeAge.getAge() > MAXAGE) {
1512 generateErrorMessage(path, fn);
1518 private void generateErrorMessage(NTuple<Descriptor> path, FlatNode fn) {
1520 Descriptor lastDesc = path.get(getArrayBaseDescriptorIdx(path));
1521 if (ssjava.isSharedLocation(getLocation(lastDesc))) {
1523 NTuple<Location> locPathTuple = getLocationTuple(path);
1524 Set<NTuple<Descriptor>> coverSet =
1525 mapMethodToSharedLocCoverSet.get(methodContainingSSJavaLoop).get(locPathTuple);
1526 throw new Error("Shared memory locations, which is reachable through references " + path
1527 + ", are not completely overwritten by the higher values at "
1528 + methodContainingSSJavaLoop.getClassDesc().getSourceFileName() + "::" + fn.getNumLine()
1529 + ".\nThe following memory locations belong to the same shared locations:" + coverSet);
1533 "Memory location, which is reachable through references "
1535 + ", who comes back to the same read statement without being overwritten at the out-most iteration at "
1536 + methodContainingSSJavaLoop.getClassDesc().getSourceFileName() + "::"
1542 private void generateGENSetForFlatCall(FlatCall fc, SharedLocMap sharedLocMap,
1543 Hashtable<NTuple<Descriptor>, Set<WriteAge>> GENSet) {
1545 Set<NTuple<Descriptor>> boundMayWriteSet = mapFlatNodeToBoundMayWriteSet.get(fc);
1547 for (Iterator iterator = boundMayWriteSet.iterator(); iterator.hasNext();) {
1548 NTuple<Descriptor> heapPath = (NTuple<Descriptor>) iterator.next();
1550 if (!isSharedLocation(heapPath)) {
1551 addWriteAgeToSet(heapPath, GENSet, new WriteAge(0));
1553 // if the current heap path is shared location
1555 NTuple<Location> locTuple = getLocationTuple(heapPath);
1557 Set<NTuple<Descriptor>> sharedWriteHeapPathSet = sharedLocMap.get(locTuple);
1559 if (isCovered(locTuple, sharedLocMap.get(locTuple))) {
1560 // if it is covered, add all of heap paths belong to the same shared
1561 // loc with write age 0
1563 for (Iterator iterator2 = sharedWriteHeapPathSet.iterator(); iterator2.hasNext();) {
1564 NTuple<Descriptor> sharedHeapPath = (NTuple<Descriptor>) iterator2.next();
1565 addWriteAgeToSet(sharedHeapPath, GENSet, new WriteAge(0));
1569 // if not covered, add write age 1 to the heap path that is
1570 // may-written but not covered
1571 addWriteAgeToSet(heapPath, GENSet, new WriteAge(1));
1580 private void addWriteAgeToSet(NTuple<Descriptor> heapPath,
1581 Hashtable<NTuple<Descriptor>, Set<WriteAge>> map, WriteAge age) {
1583 Set<WriteAge> currSet = map.get(heapPath);
1584 if (currSet == null) {
1585 currSet = new HashSet<WriteAge>();
1586 map.put(heapPath, currSet);
1592 private void generateKILLSetForFlatCall(FlatCall fc,
1593 Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr, SharedLocMap sharedLocMap,
1594 Hashtable<NTuple<Descriptor>, Set<WriteAge>> KILLSet) {
1596 Set<NTuple<Descriptor>> boundMustWriteSet = mapFlatNodeToBoundMustWriteSet.get(fc);
1598 for (Iterator iterator = boundMustWriteSet.iterator(); iterator.hasNext();) {
1599 NTuple<Descriptor> heapPath = (NTuple<Descriptor>) iterator.next();
1601 if (isSharedLocation(heapPath)) {
1602 NTuple<Location> locTuple = getLocationTuple(heapPath);
1604 if (isCovered(locTuple, sharedLocMap.get(locTuple)) && curr.containsKey(heapPath)) {
1605 // if it is shared loc and corresponding shared loc has been covered
1606 KILLSet.put(heapPath, curr.get(heapPath));
1610 for (Enumeration<NTuple<Descriptor>> e = curr.keys(); e.hasMoreElements();) {
1611 NTuple<Descriptor> key = e.nextElement();
1612 if (key.startsWith(heapPath)) {
1613 KILLSet.put(key, curr.get(key));
1623 private int getArrayBaseDescriptorIdx(NTuple<Descriptor> heapPath) {
1625 for (int i = heapPath.size() - 1; i >= 0; i--) {
1626 if (!heapPath.get(i).getSymbol().equals(arrayElementFieldName)) {
1635 private boolean isSharedLocation(NTuple<Descriptor> heapPath) {
1637 Descriptor d = heapPath.get(getArrayBaseDescriptorIdx(heapPath));
1639 return ssjava.isSharedLocation(getLocation(heapPath.get(getArrayBaseDescriptorIdx(heapPath))));
1643 private NTuple<Location> getLocationTuple(NTuple<Descriptor> heapPath) {
1645 NTuple<Location> locTuple = new NTuple<Location>();
1647 locTuple.addAll(mapDescriptorToLocationPath.get(heapPath.get(0)));
1649 for (int i = 1; i <= getArrayBaseDescriptorIdx(heapPath); i++) {
1650 locTuple.add(getLocation(heapPath.get(i)));
1656 private void computeNewMapping(Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr,
1657 Hashtable<NTuple<Descriptor>, Set<WriteAge>> KILLSet,
1658 Hashtable<NTuple<Descriptor>, Set<WriteAge>> GENSet) {
1660 for (Enumeration<NTuple<Descriptor>> e = KILLSet.keys(); e.hasMoreElements();) {
1661 NTuple<Descriptor> key = e.nextElement();
1663 Set<WriteAge> writeAgeSet = curr.get(key);
1664 if (writeAgeSet == null) {
1665 writeAgeSet = new HashSet<WriteAge>();
1666 curr.put(key, writeAgeSet);
1668 writeAgeSet.removeAll(KILLSet.get(key));
1671 for (Enumeration<NTuple<Descriptor>> e = GENSet.keys(); e.hasMoreElements();) {
1672 NTuple<Descriptor> key = e.nextElement();
1674 Set<WriteAge> currWriteAgeSet = curr.get(key);
1675 if (currWriteAgeSet == null) {
1676 currWriteAgeSet = new HashSet<WriteAge>();
1677 curr.put(key, currWriteAgeSet);
1679 currWriteAgeSet.addAll(GENSet.get(key));
1684 private void computeGENSetForWrite(NTuple<Descriptor> fldHeapPath,
1685 Hashtable<NTuple<Descriptor>, Set<WriteAge>> GENSet) {
1687 // generate write age 0 for the field being written to
1688 Set<WriteAge> writeAgeSet = new HashSet<WriteAge>();
1689 writeAgeSet.add(new WriteAge(0));
1690 GENSet.put(fldHeapPath, writeAgeSet);
1694 private void computeKILLSetForWrite(Hashtable<NTuple<Descriptor>, Set<WriteAge>> curr,
1695 NTuple<Descriptor> hp, Hashtable<NTuple<Descriptor>, Set<WriteAge>> KILLSet) {
1697 // removes all of heap path that starts with prefix 'hp'
1698 // since any reference overwrite along heap path gives overwriting side
1699 // effects on the value
1701 Set<NTuple<Descriptor>> keySet = curr.keySet();
1702 for (Iterator<NTuple<Descriptor>> iter = keySet.iterator(); iter.hasNext();) {
1703 NTuple<Descriptor> key = iter.next();
1704 if (key.startsWith(hp)) {
1705 KILLSet.put(key, curr.get(key));
1711 private void bindHeapPathCallerArgWithCalleeParam(FlatCall fc) {
1712 // compute all possible callee set
1713 // transform all READ/WRITE set from the any possible
1714 // callees to the caller
1715 calleeUnionBoundReadSet.clear();
1716 calleeIntersectBoundMustWriteSet.clear();
1717 calleeUnionBoundMayWriteSet.clear();
1719 if (ssjava.isSSJavaUtil(fc.getMethod().getClassDesc())) {
1720 // ssjava util case!
1721 // have write effects on the first argument
1722 TempDescriptor arg = fc.getArg(0);
1723 NTuple<Descriptor> argHeapPath = computePath(arg);
1724 calleeIntersectBoundMustWriteSet.add(argHeapPath);
1725 calleeUnionBoundMayWriteSet.add(argHeapPath);
1727 MethodDescriptor mdCallee = fc.getMethod();
1728 Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
1729 setPossibleCallees.addAll(callGraph.getMethods(mdCallee));
1731 // create mapping from arg idx to its heap paths
1732 Hashtable<Integer, NTuple<Descriptor>> mapArgIdx2CallerArgHeapPath =
1733 new Hashtable<Integer, NTuple<Descriptor>>();
1735 // arg idx is starting from 'this' arg
1736 if (fc.getThis() != null) {
1737 NTuple<Descriptor> thisHeapPath = mapHeapPath.get(fc.getThis());
1738 if (thisHeapPath != null) {
1739 // if 'this' does not have heap path, it is local reference
1740 mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(0), thisHeapPath);
1744 for (int i = 0; i < fc.numArgs(); i++) {
1745 TempDescriptor arg = fc.getArg(i);
1746 NTuple<Descriptor> argHeapPath = computePath(arg);
1747 mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(i + 1), argHeapPath);
1750 for (Iterator iterator = setPossibleCallees.iterator(); iterator.hasNext();) {
1751 MethodDescriptor callee = (MethodDescriptor) iterator.next();
1752 FlatMethod calleeFlatMethod = state.getMethodFlat(callee);
1754 // binding caller's args and callee's params
1756 Set<NTuple<Descriptor>> calleeReadSet = mapFlatMethodToReadSet.get(calleeFlatMethod);
1757 if (calleeReadSet == null) {
1758 calleeReadSet = new HashSet<NTuple<Descriptor>>();
1759 mapFlatMethodToReadSet.put(calleeFlatMethod, calleeReadSet);
1762 Set<NTuple<Descriptor>> calleeMustWriteSet =
1763 mapFlatMethodToMustWriteSet.get(calleeFlatMethod);
1765 if (calleeMustWriteSet == null) {
1766 calleeMustWriteSet = new HashSet<NTuple<Descriptor>>();
1767 mapFlatMethodToMustWriteSet.put(calleeFlatMethod, calleeMustWriteSet);
1770 Set<NTuple<Descriptor>> calleeMayWriteSet =
1771 mapFlatMethodToMayWriteSet.get(calleeFlatMethod);
1773 if (calleeMayWriteSet == null) {
1774 calleeMayWriteSet = new HashSet<NTuple<Descriptor>>();
1775 mapFlatMethodToMayWriteSet.put(calleeFlatMethod, calleeMayWriteSet);
1778 Hashtable<Integer, TempDescriptor> mapParamIdx2ParamTempDesc =
1779 new Hashtable<Integer, TempDescriptor>();
1781 if (calleeFlatMethod.getMethod().isStatic()) {
1782 // static method does not have implicit 'this' arg
1785 for (int i = 0; i < calleeFlatMethod.numParameters(); i++) {
1786 TempDescriptor param = calleeFlatMethod.getParameter(i);
1787 mapParamIdx2ParamTempDesc.put(Integer.valueOf(i + offset), param);
1790 Set<NTuple<Descriptor>> calleeBoundReadSet =
1791 bindSet(calleeReadSet, mapParamIdx2ParamTempDesc, mapArgIdx2CallerArgHeapPath);
1792 // union of the current read set and the current callee's
1794 calleeUnionBoundReadSet.addAll(calleeBoundReadSet);
1796 Set<NTuple<Descriptor>> calleeBoundMustWriteSet =
1797 bindSet(calleeMustWriteSet, mapParamIdx2ParamTempDesc, mapArgIdx2CallerArgHeapPath);
1798 // intersection of the current overwrite set and the current
1801 merge(calleeIntersectBoundMustWriteSet, calleeBoundMustWriteSet);
1803 Set<NTuple<Descriptor>> boundWriteSetFromCallee =
1804 bindSet(calleeMayWriteSet, mapParamIdx2ParamTempDesc, mapArgIdx2CallerArgHeapPath);
1805 calleeUnionBoundMayWriteSet.addAll(boundWriteSetFromCallee);
1812 private void bindHeapPathCallerArgWithCaleeParamForSharedLoc(MethodDescriptor mdCaller,
1815 calleeIntersectBoundSharedSet.clear();
1816 calleeUnionBoundDeleteSet.clear();
1818 if (ssjava.isSSJavaUtil(fc.getMethod().getClassDesc())) {
1819 // ssjava util case!
1820 // have write effects on the first argument
1821 TempDescriptor arg = fc.getArg(0);
1822 NTuple<Descriptor> argHeapPath = computePath(arg);
1824 // convert heap path to location path
1825 NTuple<Location> argLocTuple = new NTuple<Location>();
1826 argLocTuple.addAll(deriveLocationTuple(mdCaller, (TempDescriptor) argHeapPath.get(0)));
1827 for (int i = 1; i < argHeapPath.size(); i++) {
1828 argLocTuple.add(getLocation(argHeapPath.get(i)));
1831 calleeIntersectBoundSharedSet.addWrite(argLocTuple, argHeapPath);
1833 } else if (ssjava.needTobeAnnotated(fc.getMethod())) {
1835 // if arg is not primitive type, we need to propagate maywritten set to
1836 // the caller's location path
1838 MethodDescriptor mdCallee = fc.getMethod();
1839 Set<MethodDescriptor> setPossibleCallees = new HashSet<MethodDescriptor>();
1840 setPossibleCallees.addAll(callGraph.getMethods(mdCallee));
1842 // create mapping from arg idx to its heap paths
1843 Hashtable<Integer, NTuple<Descriptor>> mapArgIdx2CallerArgHeapPath =
1844 new Hashtable<Integer, NTuple<Descriptor>>();
1846 // arg idx is starting from 'this' arg
1847 if (fc.getThis() != null) {
1848 NTuple<Descriptor> thisHeapPath = mapHeapPath.get(fc.getThis());
1849 if (thisHeapPath == null) {
1850 // method is called without creating new flat node representing 'this'
1851 thisHeapPath = new NTuple<Descriptor>();
1852 thisHeapPath.add(fc.getThis());
1855 mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(0), thisHeapPath);
1858 for (int i = 0; i < fc.numArgs(); i++) {
1859 TempDescriptor arg = fc.getArg(i);
1860 NTuple<Descriptor> argHeapPath = computePath(arg);
1861 mapArgIdx2CallerArgHeapPath.put(Integer.valueOf(i + 1), argHeapPath);
1864 // create mapping from arg idx to its location paths
1865 Hashtable<Integer, NTuple<Location>> mapArgIdx2CallerAgLocationPath =
1866 new Hashtable<Integer, NTuple<Location>>();
1868 // arg idx is starting from 'this' arg
1869 if (fc.getThis() != null) {
1870 NTuple<Location> thisLocationPath = deriveLocationTuple(mdCaller, fc.getThis());
1871 if (thisLocationPath != null) {
1872 mapArgIdx2CallerAgLocationPath.put(Integer.valueOf(0), thisLocationPath);
1876 for (int i = 0; i < fc.numArgs(); i++) {
1877 TempDescriptor arg = fc.getArg(i);
1878 NTuple<Location> argLocationPath = deriveLocationTuple(mdCaller, arg);
1879 if (argLocationPath != null) {
1880 mapArgIdx2CallerAgLocationPath.put(Integer.valueOf(i + 1), argLocationPath);
1884 for (Iterator iterator = setPossibleCallees.iterator(); iterator.hasNext();) {
1885 MethodDescriptor callee = (MethodDescriptor) iterator.next();
1886 FlatMethod calleeFlatMethod = state.getMethodFlat(callee);
1888 // binding caller's args and callee's params
1890 Hashtable<Integer, TempDescriptor> mapParamIdx2ParamTempDesc =
1891 new Hashtable<Integer, TempDescriptor>();
1893 if (calleeFlatMethod.getMethod().isStatic()) {
1894 // static method does not have implicit 'this' arg
1897 for (int i = 0; i < calleeFlatMethod.numParameters(); i++) {
1898 TempDescriptor param = calleeFlatMethod.getParameter(i);
1899 mapParamIdx2ParamTempDesc.put(Integer.valueOf(i + offset), param);
1902 Set<Integer> keySet = mapArgIdx2CallerAgLocationPath.keySet();
1903 for (Iterator iterator2 = keySet.iterator(); iterator2.hasNext();) {
1904 Integer idx = (Integer) iterator2.next();
1905 NTuple<Location> callerArgLocationPath = mapArgIdx2CallerAgLocationPath.get(idx);
1906 NTuple<Descriptor> callerArgHeapPath = mapArgIdx2CallerArgHeapPath.get(idx);
1908 TempDescriptor calleeParam = mapParamIdx2ParamTempDesc.get(idx);
1909 NTuple<Location> calleeLocationPath = deriveLocationTuple(mdCallee, calleeParam);
1910 SharedLocMap calleeDeleteSet = mapFlatMethodToDeleteSet.get(calleeFlatMethod);
1911 SharedLocMap calleeSharedLocMap = mapFlatMethodToSharedLocMap.get(calleeFlatMethod);
1913 if (calleeDeleteSet != null) {
1914 createNewMappingOfDeleteSet(callerArgLocationPath, callerArgHeapPath,
1915 calleeLocationPath, calleeDeleteSet);
1918 if (calleeSharedLocMap != null) {
1919 createNewMappingOfSharedSet(callerArgLocationPath, callerArgHeapPath,
1920 calleeLocationPath, calleeSharedLocMap);
1930 private void createNewMappingOfDeleteSet(NTuple<Location> callerArgLocationPath,
1931 NTuple<Descriptor> callerArgHeapPath, NTuple<Location> calleeLocationPath,
1932 SharedLocMap calleeDeleteSet) {
1934 SharedLocMap calleeParamDeleteSet = calleeDeleteSet.getHeapPathStartedWith(calleeLocationPath);
1936 Set<NTuple<Location>> keySet = calleeParamDeleteSet.keySet();
1937 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
1938 NTuple<Location> calleeLocTupleKey = (NTuple<Location>) iterator.next();
1939 Set<NTuple<Descriptor>> heapPathSet = calleeParamDeleteSet.get(calleeLocTupleKey);
1940 for (Iterator iterator2 = heapPathSet.iterator(); iterator2.hasNext();) {
1941 NTuple<Descriptor> calleeHeapPath = (NTuple<Descriptor>) iterator2.next();
1942 calleeUnionBoundDeleteSet.addWrite(
1943 bindLocationPath(callerArgLocationPath, calleeLocTupleKey),
1944 bindHeapPath(callerArgHeapPath, calleeHeapPath));
1950 private void createNewMappingOfSharedSet(NTuple<Location> callerArgLocationPath,
1951 NTuple<Descriptor> callerArgHeapPath, NTuple<Location> calleeLocationPath,
1952 SharedLocMap calleeSharedLocMap) {
1954 SharedLocMap calleeParamSharedSet =
1955 calleeSharedLocMap.getHeapPathStartedWith(calleeLocationPath);
1957 Set<NTuple<Location>> keySet = calleeParamSharedSet.keySet();
1958 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
1959 NTuple<Location> calleeLocTupleKey = (NTuple<Location>) iterator.next();
1960 Set<NTuple<Descriptor>> heapPathSet = calleeParamSharedSet.get(calleeLocTupleKey);
1961 Set<NTuple<Descriptor>> boundHeapPathSet = new HashSet<NTuple<Descriptor>>();
1962 for (Iterator iterator2 = heapPathSet.iterator(); iterator2.hasNext();) {
1963 NTuple<Descriptor> calleeHeapPath = (NTuple<Descriptor>) iterator2.next();
1964 boundHeapPathSet.add(bindHeapPath(callerArgHeapPath, calleeHeapPath));
1966 calleeIntersectBoundSharedSet.intersect(
1967 bindLocationPath(callerArgLocationPath, calleeLocTupleKey), boundHeapPathSet);
1972 private NTuple<Location> bindLocationPath(NTuple<Location> start, NTuple<Location> end) {
1973 NTuple<Location> locPath = new NTuple<Location>();
1974 locPath.addAll(start);
1975 for (int i = 1; i < end.size(); i++) {
1976 locPath.add(end.get(i));
1981 private NTuple<Descriptor> bindHeapPath(NTuple<Descriptor> start, NTuple<Descriptor> end) {
1982 NTuple<Descriptor> heapPath = new NTuple<Descriptor>();
1983 heapPath.addAll(start);
1984 for (int i = 1; i < end.size(); i++) {
1985 heapPath.add(end.get(i));
1990 private void initialize() {
1991 // First, identify ssjava loop entrace
1993 // no need to analyze method having ssjava loop
1994 methodContainingSSJavaLoop = ssjava.getMethodContainingSSJavaLoop();
1996 FlatMethod fm = state.getMethodFlat(methodContainingSSJavaLoop);
1997 Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
1998 flatNodesToVisit.add(fm);
2000 LoopFinder loopFinder = new LoopFinder(fm);
2002 while (!flatNodesToVisit.isEmpty()) {
2003 FlatNode fn = flatNodesToVisit.iterator().next();
2004 flatNodesToVisit.remove(fn);
2006 String label = (String) state.fn2labelMap.get(fn);
2007 if (label != null) {
2009 if (label.equals(ssjava.SSJAVA)) {
2010 ssjava.setSSJavaLoopEntrance(fn);
2015 for (int i = 0; i < fn.numNext(); i++) {
2016 FlatNode nn = fn.getNext(i);
2017 flatNodesToVisit.add(nn);
2021 assert ssjava.getSSJavaLoopEntrance() != null;
2023 // assume that ssjava loop is top-level loop in method, not nested loop
2024 Set nestedLoop = loopFinder.nestedLoops();
2025 for (Iterator loopIter = nestedLoop.iterator(); loopIter.hasNext();) {
2026 LoopFinder lf = (LoopFinder) loopIter.next();
2027 if (lf.loopEntrances().iterator().next().equals(ssjava.getSSJavaLoopEntrance())) {
2032 assert ssjavaLoop != null;
2034 loopIncElements = (Set<FlatNode>) ssjavaLoop.loopIncElements();
2036 // perform topological sort over the set of methods accessed by the main
2038 // Set<MethodDescriptor> methodDescriptorsToAnalyze = new
2039 // HashSet<MethodDescriptor>();
2040 // methodDescriptorsToAnalyze.addAll(ssjava.getAnnotationRequireSet());
2041 // sortedDescriptors = topologicalSort(methodDescriptorsToAnalyze);
2043 liveInTempSetToEventLoop =
2044 liveness.getLiveInTemps(state.getMethodFlat(methodContainingSSJavaLoop),
2045 ssjava.getSSJavaLoopEntrance());
2048 private void methodReadWriteSetAnalysis() {
2049 // perform method READ/OVERWRITE analysis
2050 LinkedList<MethodDescriptor> descriptorListToAnalyze = ssjava.getSortedDescriptors();
2052 // current descriptors to visit in fixed-point interprocedural analysis,
2054 // dependency in the call graph
2055 methodDescriptorsToVisitStack.clear();
2057 descriptorListToAnalyze.removeFirst();
2059 Set<MethodDescriptor> methodDescriptorToVistSet = new HashSet<MethodDescriptor>();
2060 methodDescriptorToVistSet.addAll(descriptorListToAnalyze);
2062 while (!descriptorListToAnalyze.isEmpty()) {
2063 MethodDescriptor md = descriptorListToAnalyze.removeFirst();
2064 methodDescriptorsToVisitStack.add(md);
2067 // analyze scheduled methods until there are no more to visit
2068 while (!methodDescriptorsToVisitStack.isEmpty()) {
2069 // start to analyze leaf node
2070 MethodDescriptor md = methodDescriptorsToVisitStack.pop();
2071 FlatMethod fm = state.getMethodFlat(md);
2073 Set<NTuple<Descriptor>> readSet = new HashSet<NTuple<Descriptor>>();
2074 Set<NTuple<Descriptor>> mustWriteSet = new HashSet<NTuple<Descriptor>>();
2075 Set<NTuple<Descriptor>> mayWriteSet = new HashSet<NTuple<Descriptor>>();
2077 methodReadWriteSet_analyzeMethod(fm, readSet, mustWriteSet, mayWriteSet);
2079 Set<NTuple<Descriptor>> prevRead = mapFlatMethodToReadSet.get(fm);
2080 Set<NTuple<Descriptor>> prevMustWrite = mapFlatMethodToMustWriteSet.get(fm);
2081 Set<NTuple<Descriptor>> prevMayWrite = mapFlatMethodToMayWriteSet.get(fm);
2083 if (!(readSet.equals(prevRead) && mustWriteSet.equals(prevMustWrite) && mayWriteSet
2084 .equals(prevMayWrite))) {
2085 mapFlatMethodToReadSet.put(fm, readSet);
2086 mapFlatMethodToMustWriteSet.put(fm, mustWriteSet);
2087 mapFlatMethodToMayWriteSet.put(fm, mayWriteSet);
2089 // results for callee changed, so enqueue dependents caller for
2092 Iterator<MethodDescriptor> depsItr = ssjava.getDependents(md).iterator();
2093 while (depsItr.hasNext()) {
2094 MethodDescriptor methodNext = depsItr.next();
2095 if (!methodDescriptorsToVisitStack.contains(methodNext)
2096 && methodDescriptorToVistSet.contains(methodNext)) {
2097 methodDescriptorsToVisitStack.add(methodNext);
2106 methodReadWriteSetAnalysisToEventLoopBody();
2110 private void methodReadWriteSet_analyzeMethod(FlatMethod fm, Set<NTuple<Descriptor>> readSet,
2111 Set<NTuple<Descriptor>> mustWriteSet, Set<NTuple<Descriptor>> mayWriteSet) {
2112 if (state.SSJAVADEBUG) {
2113 System.out.println("SSJAVA: Definitely written Analyzing: " + fm);
2116 methodReadWriteSet_analyzeBody(fm, readSet, mustWriteSet, mayWriteSet, false);
2120 private void methodReadWriteSetAnalysisToEventLoopBody() {
2122 // perform method read/write analysis for Event Loop Body
2124 FlatMethod flatMethodContainingSSJavaLoop = state.getMethodFlat(methodContainingSSJavaLoop);
2126 if (state.SSJAVADEBUG) {
2127 System.out.println("SSJAVA: Definitely written Event Loop Analyzing: "
2128 + flatMethodContainingSSJavaLoop);
2131 Set<NTuple<Descriptor>> readSet = new HashSet<NTuple<Descriptor>>();
2132 Set<NTuple<Descriptor>> mustWriteSet = new HashSet<NTuple<Descriptor>>();
2133 Set<NTuple<Descriptor>> mayWriteSet = new HashSet<NTuple<Descriptor>>();
2135 mapFlatMethodToReadSet.put(flatMethodContainingSSJavaLoop, readSet);
2136 mapFlatMethodToMustWriteSet.put(flatMethodContainingSSJavaLoop, mustWriteSet);
2137 mapFlatMethodToMayWriteSet.put(flatMethodContainingSSJavaLoop, mayWriteSet);
2139 for (Iterator iterator = liveInTempSetToEventLoop.iterator(); iterator.hasNext();) {
2140 TempDescriptor liveIn = (TempDescriptor) iterator.next();
2141 NTuple<Descriptor> heapPath = new NTuple<Descriptor>();
2142 heapPath.add(liveIn);
2143 mapHeapPath.put(liveIn, heapPath);
2146 methodReadWriteSet_analyzeBody(ssjava.getSSJavaLoopEntrance(), readSet, mustWriteSet,
2151 private void methodReadWriteSet_analyzeBody(FlatNode startNode, Set<NTuple<Descriptor>> readSet,
2152 Set<NTuple<Descriptor>> mustWriteSet, Set<NTuple<Descriptor>> mayWriteSet,
2153 boolean isEventLoopBody) {
2155 // intraprocedural analysis
2156 Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
2157 flatNodesToVisit.add(startNode);
2159 while (!flatNodesToVisit.isEmpty()) {
2160 FlatNode fn = flatNodesToVisit.iterator().next();
2161 flatNodesToVisit.remove(fn);
2163 Set<NTuple<Descriptor>> currMustWriteSet = new HashSet<NTuple<Descriptor>>();
2165 for (int i = 0; i < fn.numPrev(); i++) {
2166 FlatNode prevFn = fn.getPrev(i);
2167 Set<NTuple<Descriptor>> in = mapFlatNodeToMustWriteSet.get(prevFn);
2169 merge(currMustWriteSet, in);
2173 methodReadWriteSet_nodeActions(fn, currMustWriteSet, readSet, mustWriteSet, mayWriteSet,
2176 Set<NTuple<Descriptor>> mustSetPrev = mapFlatNodeToMustWriteSet.get(fn);
2178 if (!currMustWriteSet.equals(mustSetPrev)) {
2179 mapFlatNodeToMustWriteSet.put(fn, currMustWriteSet);
2180 for (int i = 0; i < fn.numNext(); i++) {
2181 FlatNode nn = fn.getNext(i);
2182 if ((!isEventLoopBody) || loopIncElements.contains(nn)) {
2183 flatNodesToVisit.add(nn);
2193 private void methodReadWriteSet_nodeActions(FlatNode fn,
2194 Set<NTuple<Descriptor>> currMustWriteSet, Set<NTuple<Descriptor>> readSet,
2195 Set<NTuple<Descriptor>> mustWriteSet, Set<NTuple<Descriptor>> mayWriteSet,
2196 boolean isEventLoopBody) {
2200 FieldDescriptor fld;
2202 switch (fn.kind()) {
2203 case FKind.FlatMethod: {
2205 // set up initial heap paths for method parameters
2206 FlatMethod fm = (FlatMethod) fn;
2207 for (int i = 0; i < fm.numParameters(); i++) {
2208 TempDescriptor param = fm.getParameter(i);
2209 NTuple<Descriptor> heapPath = new NTuple<Descriptor>();
2210 heapPath.add(param);
2211 mapHeapPath.put(param, heapPath);
2216 case FKind.FlatOpNode: {
2217 FlatOpNode fon = (FlatOpNode) fn;
2218 // for a normal assign node, need to propagate lhs's heap path to
2221 if (fon.getOp().getOp() == Operation.ASSIGN) {
2222 rhs = fon.getLeft();
2223 lhs = fon.getDest();
2225 NTuple<Descriptor> rhsHeapPath = mapHeapPath.get(rhs);
2227 // if (lhs.getType().isPrimitive()) {
2228 // NTuple<Descriptor> lhsHeapPath = new NTuple<Descriptor>();
2229 // lhsHeapPath.add(lhs);
2230 // mapHeapPath.put(lhs, lhsHeapPath);
2233 if (rhsHeapPath != null && (!lhs.getType().isPrimitive())) {
2234 mapHeapPath.put(lhs, mapHeapPath.get(rhs));
2237 // if (isEventLoopBody) {
2238 // NTuple<Descriptor> lhsHeapPath = new NTuple<Descriptor>();
2239 // lhsHeapPath.add(rhs);
2240 // mapHeapPath.put(lhs, lhsHeapPath);
2246 // shared loc extension
2247 if (isEventLoopBody) {
2248 if (!lhs.getSymbol().startsWith("neverused") && rhs.getType().isImmutable()) {
2250 if (rhs.getType().getExtension() instanceof Location
2251 && lhs.getType().getExtension() instanceof CompositeLocation) {
2253 Location rhsLoc = (Location) rhs.getType().getExtension();
2255 CompositeLocation lhsCompLoc = (CompositeLocation) lhs.getType().getExtension();
2256 Location dstLoc = lhsCompLoc.get(lhsCompLoc.getSize() - 1);
2258 NTuple<Descriptor> heapPath = new NTuple<Descriptor>();
2259 for (int i = 0; i < rhsHeapPath.size() - 1; i++) {
2260 heapPath.add(rhsHeapPath.get(i));
2263 NTuple<Descriptor> writeHeapPath = new NTuple<Descriptor>();
2264 writeHeapPath.addAll(heapPath);
2265 writeHeapPath.add(lhs);
2275 case FKind.FlatElementNode:
2276 case FKind.FlatFieldNode: {
2280 if (fn.kind() == FKind.FlatFieldNode) {
2281 FlatFieldNode ffn = (FlatFieldNode) fn;
2284 fld = ffn.getField();
2286 FlatElementNode fen = (FlatElementNode) fn;
2289 TypeDescriptor td = rhs.getType().dereference();
2290 fld = getArrayField(td);
2293 if (fld.isFinal()) {
2294 // if field is final no need to check
2299 NTuple<Descriptor> srcHeapPath = mapHeapPath.get(rhs);
2300 if (srcHeapPath != null) {
2301 // if lhs srcHeapPath is null, it means that it is not reachable from
2302 // callee's parameters. so just ignore it
2304 NTuple<Descriptor> readingHeapPath = new NTuple<Descriptor>(srcHeapPath.getList());
2305 if (fn.kind() == FKind.FlatFieldNode) {
2306 readingHeapPath.add(fld);
2309 mapHeapPath.put(lhs, readingHeapPath);
2312 if (fld.getType().isImmutable()) {
2313 // if WT doesnot have hp(x.f), add hp(x.f) to READ
2314 if (!currMustWriteSet.contains(readingHeapPath)) {
2315 readSet.add(readingHeapPath);
2319 // no need to kill hp(x.f) from WT
2325 case FKind.FlatSetFieldNode:
2326 case FKind.FlatSetElementNode: {
2330 if (fn.kind() == FKind.FlatSetFieldNode) {
2331 FlatSetFieldNode fsfn = (FlatSetFieldNode) fn;
2332 lhs = fsfn.getDst();
2333 fld = fsfn.getField();
2334 rhs = fsfn.getSrc();
2336 FlatSetElementNode fsen = (FlatSetElementNode) fn;
2337 lhs = fsen.getDst();
2338 rhs = fsen.getSrc();
2339 TypeDescriptor td = lhs.getType().dereference();
2340 fld = getArrayField(td);
2344 NTuple<Descriptor> lhsHeapPath = mapHeapPath.get(lhs);
2346 if (lhsHeapPath != null) {
2347 // if lhs heap path is null, it means that it is not reachable from
2348 // callee's parameters. so just ignore it
2349 NTuple<Descriptor> fldHeapPath = new NTuple<Descriptor>(lhsHeapPath.getList());
2350 if (fn.kind() != FKind.FlatSetElementNode) {
2351 fldHeapPath.add(fld);
2353 // mapHeapPath.put(fld, fldHeapPath);
2356 // need to add hp(y) to WT
2357 if (fn.kind() != FKind.FlatSetElementNode) {
2358 currMustWriteSet.add(fldHeapPath);
2360 mayWriteSet.add(fldHeapPath);
2367 case FKind.FlatCall: {
2369 FlatCall fc = (FlatCall) fn;
2371 bindHeapPathCallerArgWithCalleeParam(fc);
2373 Set<NTuple<Descriptor>> boundReadSet = new HashSet<NTuple<Descriptor>>();
2374 boundReadSet.addAll(calleeUnionBoundReadSet);
2376 Set<NTuple<Descriptor>> boundMustWriteSet = new HashSet<NTuple<Descriptor>>();
2377 boundMustWriteSet.addAll(calleeIntersectBoundMustWriteSet);
2379 Set<NTuple<Descriptor>> boundMayWriteSet = new HashSet<NTuple<Descriptor>>();
2380 boundMayWriteSet.addAll(calleeUnionBoundMayWriteSet);
2382 mapFlatNodeToBoundReadSet.put(fn, boundReadSet);
2383 mapFlatNodeToBoundMustWriteSet.put(fn, boundMustWriteSet);
2384 mapFlatNodeToBoundMayWriteSet.put(fn, boundMayWriteSet);
2386 // add heap path, which is an element of READ_bound set and is not
2388 // element of WT set, to the caller's READ set
2389 for (Iterator iterator = calleeUnionBoundReadSet.iterator(); iterator.hasNext();) {
2390 NTuple<Descriptor> read = (NTuple<Descriptor>) iterator.next();
2391 if (!currMustWriteSet.contains(read)) {
2396 // add heap path, which is an element of OVERWRITE_bound set, to the
2398 for (Iterator iterator = calleeIntersectBoundMustWriteSet.iterator(); iterator.hasNext();) {
2399 NTuple<Descriptor> write = (NTuple<Descriptor>) iterator.next();
2400 currMustWriteSet.add(write);
2403 // add heap path, which is an element of WRITE_BOUND set, to the
2404 // caller's writeSet
2405 for (Iterator iterator = calleeUnionBoundMayWriteSet.iterator(); iterator.hasNext();) {
2406 NTuple<Descriptor> write = (NTuple<Descriptor>) iterator.next();
2407 mayWriteSet.add(write);
2413 case FKind.FlatExit: {
2414 // merge the current written set with OVERWRITE set
2415 merge(mustWriteSet, currMustWriteSet);
2423 static public FieldDescriptor getArrayField(TypeDescriptor td) {
2424 FieldDescriptor fd = mapTypeToArrayField.get(td);
2427 new FieldDescriptor(new Modifiers(Modifiers.PUBLIC), td, arrayElementFieldName, null,
2429 mapTypeToArrayField.put(td, fd);
2434 private void merge(Set<NTuple<Descriptor>> curr, Set<NTuple<Descriptor>> in) {
2435 if (curr.isEmpty()) {
2436 // set has a special initial value which covers all possible
2438 // For the first time of intersection, we can take all previous set
2441 // otherwise, current set is the intersection of the two sets
2447 // combine two heap path
2448 private NTuple<Descriptor> combine(NTuple<Descriptor> callerIn, NTuple<Descriptor> calleeIn) {
2449 NTuple<Descriptor> combined = new NTuple<Descriptor>();
2451 for (int i = 0; i < callerIn.size(); i++) {
2452 combined.add(callerIn.get(i));
2455 // the first element of callee's heap path represents parameter
2456 // so we skip the first one since it is already added from caller's heap
2458 for (int i = 1; i < calleeIn.size(); i++) {
2459 combined.add(calleeIn.get(i));
2465 private Set<NTuple<Descriptor>> bindSet(Set<NTuple<Descriptor>> calleeSet,
2466 Hashtable<Integer, TempDescriptor> mapParamIdx2ParamTempDesc,
2467 Hashtable<Integer, NTuple<Descriptor>> mapCallerArgIdx2HeapPath) {
2469 Set<NTuple<Descriptor>> boundedCalleeSet = new HashSet<NTuple<Descriptor>>();
2471 Set<Integer> keySet = mapCallerArgIdx2HeapPath.keySet();
2472 for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
2473 Integer idx = (Integer) iterator.next();
2475 NTuple<Descriptor> callerArgHeapPath = mapCallerArgIdx2HeapPath.get(idx);
2476 TempDescriptor calleeParam = mapParamIdx2ParamTempDesc.get(idx);
2477 for (Iterator iterator2 = calleeSet.iterator(); iterator2.hasNext();) {
2478 NTuple<Descriptor> element = (NTuple<Descriptor>) iterator2.next();
2479 if (element.startsWith(calleeParam)) {
2480 NTuple<Descriptor> boundElement = combine(callerArgHeapPath, element);
2481 boundedCalleeSet.add(boundElement);
2487 return boundedCalleeSet;
2491 private NTuple<Descriptor> computePath(Descriptor td) {
2492 // generate proper path fot input td
2493 // if td is local variable, it just generate one element tuple path
2494 if (mapHeapPath.containsKey(td)) {
2495 NTuple<Descriptor> rtrHeapPath = new NTuple<Descriptor>();
2496 rtrHeapPath.addAll(mapHeapPath.get(td));
2499 NTuple<Descriptor> rtrHeapPath = new NTuple<Descriptor>();
2500 rtrHeapPath.add(td);
2505 private NTuple<Location> deriveThisLocationTuple(MethodDescriptor md) {
2506 String thisLocIdentifier = ssjava.getMethodLattice(md).getThisLoc();
2507 Location thisLoc = new Location(md, thisLocIdentifier);
2508 NTuple<Location> locTuple = new NTuple<Location>();
2509 locTuple.add(thisLoc);
2513 private NTuple<Location> deriveGlobalLocationTuple(MethodDescriptor md) {
2514 String globalLocIdentifier = ssjava.getMethodLattice(md).getGlobalLoc();
2515 Location globalLoc = new Location(md, globalLocIdentifier);
2516 NTuple<Location> locTuple = new NTuple<Location>();
2517 locTuple.add(globalLoc);
2521 private NTuple<Location> deriveLocationTuple(MethodDescriptor md, TempDescriptor td) {
2523 assert td.getType() != null;
2525 if (mapDescriptorToLocationPath.containsKey(td)) {
2526 NTuple<Location> locPath = mapDescriptorToLocationPath.get(td);
2527 NTuple<Location> rtrPath = new NTuple<Location>();
2528 rtrPath.addAll(locPath);
2531 if (td.getSymbol().startsWith("this")) {
2532 NTuple<Location> thisPath = deriveThisLocationTuple(md);
2533 NTuple<Location> rtrPath = new NTuple<Location>();
2534 rtrPath.addAll(thisPath);
2538 if (td.getType().getExtension() != null) {
2539 SSJavaType ssJavaType = (SSJavaType) td.getType().getExtension();
2540 if (ssJavaType.getCompLoc() != null) {
2541 NTuple<Location> rtrPath = new NTuple<Location>();
2542 rtrPath.addAll(ssJavaType.getCompLoc().getTuple());