// maps a method descriptor to its current summary during the analysis
// then analysis reaches fixed-point, this mapping will have the final summary
// for each method descriptor
- private Hashtable<MethodDescriptor, Hashtable<NTuple<Descriptor>, SharedLocState>> mapMethodDescriptorToCompleteClearingSummary;
+ private Hashtable<MethodDescriptor, ClearingSummary> mapMethodDescriptorToCompleteClearingSummary;
// maps a method descriptor to the merged incoming caller's current
// overwritten status
- private Hashtable<MethodDescriptor, Hashtable<NTuple<Descriptor>, SharedLocState>> mapMethodDescriptorToInitialClearingSummary;
+ private Hashtable<MethodDescriptor, ClearingSummary> mapMethodDescriptorToInitialClearingSummary;
// maps a flat node to current partial results
- private Hashtable<FlatNode, Hashtable<NTuple<Descriptor>, SharedLocState>> mapFlatNodeToClearingSummary;
+ private Hashtable<FlatNode, ClearingSummary> mapFlatNodeToClearingSummary;
// maps shared location to the set of descriptors which belong to the shared
// location
// when analyzing flatcall, need to re-schedule set of callee
private Set<MethodDescriptor> calleesToEnqueue;
- private Set<Hashtable<NTuple<Descriptor>, SharedLocState>> possibleCalleeCompleteSummarySetToCaller;
+ private Set<ClearingSummary> possibleCalleeCompleteSummarySetToCaller;
private LinkedList<MethodDescriptor> sortedDescriptors;
this.calleeIntersectBoundOverWriteSet = new HashSet<NTuple<Descriptor>>();
this.mapMethodDescriptorToCompleteClearingSummary =
- new Hashtable<MethodDescriptor, Hashtable<NTuple<Descriptor>, SharedLocState>>();
+ new Hashtable<MethodDescriptor, ClearingSummary>();
this.mapMethodDescriptorToInitialClearingSummary =
- new Hashtable<MethodDescriptor, Hashtable<NTuple<Descriptor>, SharedLocState>>();
+ new Hashtable<MethodDescriptor, ClearingSummary>();
this.mapSharedLocation2DescriptorSet = new Hashtable<Location, Set<Descriptor>>();
this.methodDescriptorsToVisitStack = new Stack<MethodDescriptor>();
this.calleesToEnqueue = new HashSet<MethodDescriptor>();
- this.possibleCalleeCompleteSummarySetToCaller =
- new HashSet<Hashtable<NTuple<Descriptor>, SharedLocState>>();
+ this.possibleCalleeCompleteSummarySetToCaller = new HashSet<ClearingSummary>();
this.LOCAL = new TempDescriptor("LOCAL");
}
// mapping of method containing ssjava loop has the final result of
// shared location analysis
- Hashtable<NTuple<Descriptor>, SharedLocState> result =
+ ClearingSummary result =
mapMethodDescriptorToCompleteClearingSummary.get(sortedDescriptors.peekFirst());
System.out.println("checkSharedLocationResult=" + result);
Set<NTuple<Descriptor>> hpKeySet = result.keySet();
for (Iterator iterator = hpKeySet.iterator(); iterator.hasNext();) {
NTuple<Descriptor> hpKey = (NTuple<Descriptor>) iterator.next();
- SharedLocState state = result.get(hpKey);
+ SharedStatus state = result.get(hpKey);
Set<Location> locKeySet = state.getLocationSet();
for (Iterator iterator2 = locKeySet.iterator(); iterator2.hasNext();) {
Location locKey = (Location) iterator2.next();
while (!methodDescriptorsToVisitStack.isEmpty()) {
MethodDescriptor md = methodDescriptorsToVisitStack.pop();
- Hashtable<NTuple<Descriptor>, SharedLocState> completeSummary =
+ ClearingSummary completeSummary =
sharedLocation_analyzeMethod(md, (md.equals(methodContainingSSJavaLoop)));
- Hashtable<NTuple<Descriptor>, SharedLocState> prevCompleteSummary =
- mapMethodDescriptorToCompleteClearingSummary.get(md);
+ ClearingSummary prevCompleteSummary = mapMethodDescriptorToCompleteClearingSummary.get(md);
if (!completeSummary.equals(prevCompleteSummary)) {
}
- private Hashtable<NTuple<Descriptor>, SharedLocState> sharedLocation_analyzeMethod(
- MethodDescriptor md, boolean onlyVisitSSJavaLoop) {
+ private ClearingSummary sharedLocation_analyzeMethod(MethodDescriptor md,
+ boolean onlyVisitSSJavaLoop) {
if (state.SSJAVADEBUG) {
System.out.println("Definitely written for shared locations Analyzing: " + md + " "
Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
// start a new mapping of partial results for each flat node
- mapFlatNodeToClearingSummary =
- new Hashtable<FlatNode, Hashtable<NTuple<Descriptor>, SharedLocState>>();
+ mapFlatNodeToClearingSummary = new Hashtable<FlatNode, ClearingSummary>();
if (onlyVisitSSJavaLoop) {
flatNodesToVisit.add(ssjavaLoopEntrance);
FlatNode fn = flatNodesToVisit.iterator().next();
flatNodesToVisit.remove(fn);
- Hashtable<NTuple<Descriptor>, SharedLocState> curr =
- new Hashtable<NTuple<Descriptor>, SharedLocState>();
+ ClearingSummary curr = new ClearingSummary();
- Set<Hashtable<NTuple<Descriptor>, SharedLocState>> prevSet =
- new HashSet<Hashtable<NTuple<Descriptor>, SharedLocState>>();
+ Set<ClearingSummary> prevSet = new HashSet<ClearingSummary>();
for (int i = 0; i < fn.numPrev(); i++) {
FlatNode prevFn = fn.getPrev(i);
- Hashtable<NTuple<Descriptor>, SharedLocState> in = mapFlatNodeToClearingSummary.get(prevFn);
+ ClearingSummary in = mapFlatNodeToClearingSummary.get(prevFn);
if (in != null) {
prevSet.add(in);
}
mergeSharedLocationAnaylsis(curr, prevSet);
sharedLocation_nodeActions(md, fn, curr, returnNodeSet, onlyVisitSSJavaLoop);
- Hashtable<NTuple<Descriptor>, SharedLocState> clearingPrev =
- mapFlatNodeToClearingSummary.get(fn);
+ ClearingSummary clearingPrev = mapFlatNodeToClearingSummary.get(fn);
if (!curr.equals(clearingPrev)) {
mapFlatNodeToClearingSummary.put(fn, curr);
}
- Hashtable<NTuple<Descriptor>, SharedLocState> completeSummary =
- new Hashtable<NTuple<Descriptor>, SharedLocState>();
+ ClearingSummary completeSummary = new ClearingSummary();
+ Set<ClearingSummary> summarySet = new HashSet<ClearingSummary>();
- Set<Hashtable<NTuple<Descriptor>, SharedLocState>> summarySet =
- new HashSet<Hashtable<NTuple<Descriptor>, SharedLocState>>();
if (onlyVisitSSJavaLoop) {
// when analyzing ssjava loop,
// complete summary is merging of all previous nodes of ssjava loop
// entrance
for (int i = 0; i < ssjavaLoopEntrance.numPrev(); i++) {
- Hashtable<NTuple<Descriptor>, SharedLocState> frnSummary =
+ ClearingSummary frnSummary =
mapFlatNodeToClearingSummary.get(ssjavaLoopEntrance.getPrev(i));
if (frnSummary != null) {
summarySet.add(frnSummary);
if (!returnNodeSet.isEmpty()) {
for (Iterator iterator = returnNodeSet.iterator(); iterator.hasNext();) {
FlatNode frn = (FlatNode) iterator.next();
- Hashtable<NTuple<Descriptor>, SharedLocState> frnSummary =
- mapFlatNodeToClearingSummary.get(frn);
+ ClearingSummary frnSummary = mapFlatNodeToClearingSummary.get(frn);
summarySet.add(frnSummary);
}
}
}
private void sharedLocation_nodeActions(MethodDescriptor caller, FlatNode fn,
- Hashtable<NTuple<Descriptor>, SharedLocState> curr, Set<FlatNode> returnNodeSet,
- boolean isSSJavaLoop) {
+ ClearingSummary curr, Set<FlatNode> returnNodeSet, boolean isSSJavaLoop) {
TempDescriptor lhs;
TempDescriptor rhs;
case FKind.FlatMethod: {
FlatMethod fm = (FlatMethod) fn;
- Hashtable<NTuple<Descriptor>, SharedLocState> summaryFromCaller =
+ ClearingSummary summaryFromCaller =
mapMethodDescriptorToInitialClearingSummary.get(fm.getMethod());
- Set<Hashtable<NTuple<Descriptor>, SharedLocState>> inSet =
- new HashSet<Hashtable<NTuple<Descriptor>, SharedLocState>>();
+ Set<ClearingSummary> inSet = new HashSet<ClearingSummary>();
inSet.add(summaryFromCaller);
mergeSharedLocationAnaylsis(curr, inSet);
// updates possible callee's initial summary using caller's current
// writing status
- Hashtable<NTuple<Descriptor>, SharedLocState> prevCalleeInitSummary =
+ ClearingSummary prevCalleeInitSummary =
mapMethodDescriptorToInitialClearingSummary.get(mdPossibleCallee);
- Hashtable<NTuple<Descriptor>, SharedLocState> calleeInitSummary =
+ ClearingSummary calleeInitSummary =
bindHeapPathOfCalleeCallerEffects(fc, calleeFlatMethod, curr);
// if changes, update the init summary
}
- private Hashtable<NTuple<Descriptor>, SharedLocState> bindHeapPathOfCalleeCallerEffects(
- FlatCall fc, FlatMethod calleeFlatMethod, Hashtable<NTuple<Descriptor>, SharedLocState> curr) {
+ private ClearingSummary bindHeapPathOfCalleeCallerEffects(FlatCall fc,
+ FlatMethod calleeFlatMethod, ClearingSummary curr) {
- Hashtable<NTuple<Descriptor>, SharedLocState> boundSet =
- new Hashtable<NTuple<Descriptor>, SharedLocState>();
+ ClearingSummary boundSet = new ClearingSummary();
// create mapping from arg idx to its heap paths
Hashtable<Integer, NTuple<Descriptor>> mapArgIdx2CallerArgHeapPath =
}
// contribute callee's complete summary into the caller's current summary
- Hashtable<NTuple<Descriptor>, SharedLocState> calleeCompleteSummary =
+ ClearingSummary calleeCompleteSummary =
mapMethodDescriptorToCompleteClearingSummary.get(calleeFlatMethod.getMethod());
if (calleeCompleteSummary != null) {
- Hashtable<NTuple<Descriptor>, SharedLocState> boundCalleeEfffects =
- new Hashtable<NTuple<Descriptor>, SharedLocState>();
+ ClearingSummary boundCalleeEfffects = new ClearingSummary();
for (int i = 0; i < calleeFlatMethod.numParameters(); i++) {
NTuple<Descriptor> argHeapPath = mapArgIdx2CallerArgHeapPath.get(Integer.valueOf(i));
TempDescriptor calleeParamHeapPath = mapParamIdx2ParamTempDesc.get(Integer.valueOf(i));
}
- private void writeLocation(Hashtable<NTuple<Descriptor>, SharedLocState> curr,
- NTuple<Descriptor> hp, Descriptor d) {
+ private void writeLocation(ClearingSummary curr, NTuple<Descriptor> hp, Descriptor d) {
Location loc = getLocation(d);
if (loc != null && hasReadingEffectOnSharedLocation(hp, loc, d)) {
- SharedLocState state = getState(curr, hp);
+ SharedStatus state = getState(curr, hp);
state.addVar(loc, d);
// if the set v contains all of variables belonging to the shared
}
}
- private void readLocation(Hashtable<NTuple<Descriptor>, SharedLocState> curr,
- NTuple<Descriptor> hp, Descriptor d) {
+ private void readLocation(ClearingSummary curr, NTuple<Descriptor> hp, Descriptor d) {
// remove reading var x from written set
Location loc = getLocation(d);
if (loc != null && hasReadingEffectOnSharedLocation(hp, loc, d)) {
- SharedLocState state = getState(curr, hp);
+ SharedStatus state = getState(curr, hp);
state.removeVar(loc, d);
}
}
- private SharedLocState getState(Hashtable<NTuple<Descriptor>, SharedLocState> curr,
- NTuple<Descriptor> hp) {
- SharedLocState state = curr.get(hp);
+ private SharedStatus getState(ClearingSummary curr, NTuple<Descriptor> hp) {
+ SharedStatus state = curr.get(hp);
if (state == null) {
- state = new SharedLocState();
+ state = new SharedStatus();
curr.put(hp, state);
}
return state;
}
- private void mergeSharedLocationAnaylsis(Hashtable<NTuple<Descriptor>, SharedLocState> curr,
- Set<Hashtable<NTuple<Descriptor>, SharedLocState>> inSet) {
+ private void mergeSharedLocationAnaylsis(ClearingSummary curr, Set<ClearingSummary> inSet) {
if (inSet.size() == 0) {
return;
for (Iterator inIterator = inSet.iterator(); inIterator.hasNext();) {
- Hashtable<NTuple<Descriptor>, SharedLocState> inTable =
- (Hashtable<NTuple<Descriptor>, SharedLocState>) inIterator.next();
+ ClearingSummary inTable = (ClearingSummary) inIterator.next();
Set<NTuple<Descriptor>> keySet = inTable.keySet();
for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
NTuple<Descriptor> hpKey = (NTuple<Descriptor>) iterator.next();
- SharedLocState inState = inTable.get(hpKey);
+ SharedStatus inState = inTable.get(hpKey);
- SharedLocState currState = curr.get(hpKey);
+ SharedStatus currState = curr.get(hpKey);
if (currState == null) {
- currState = new SharedLocState();
+ currState = new SharedStatus();
curr.put(hpKey, currState);
}
currState.merge(inState);
Set<NTuple<Descriptor>> hpKeySet = curr.keySet();
for (Iterator iterator = hpKeySet.iterator(); iterator.hasNext();) {
NTuple<Descriptor> hpKey = (NTuple<Descriptor>) iterator.next();
- SharedLocState currState = curr.get(hpKey);
+ SharedStatus currState = curr.get(hpKey);
Set<Location> locKeySet = currState.getMap().keySet();
for (Iterator iterator2 = locKeySet.iterator(); iterator2.hasNext();) {
Location locKey = (Location) iterator2.next();
+++ /dev/null
-package Analysis.SSJava;
-
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.Set;
-
-import IR.Descriptor;
-import Util.Pair;
-
-public class SharedLocState {
-
- // maps location to its current writing var set and flag
- Hashtable<Location, Pair<Set<Descriptor>, Boolean>> mapLocation2Status;
-
- public SharedLocState() {
- mapLocation2Status = new Hashtable<Location, Pair<Set<Descriptor>, Boolean>>();
- }
-
- private Pair<Set<Descriptor>, Boolean> getStatus(Location loc) {
- Pair<Set<Descriptor>, Boolean> pair = mapLocation2Status.get(loc);
- if (pair == null) {
- pair = new Pair<Set<Descriptor>, Boolean>(new HashSet<Descriptor>(), new Boolean(false));
- mapLocation2Status.put(loc, pair);
- }
- return pair;
- }
-
- public void addVar(Location loc, Descriptor d) {
- getStatus(loc).getFirst().add(d);
- }
-
- public void removeVar(Location loc, Descriptor d) {
- getStatus(loc).getFirst().remove(d);
- }
-
- public String toString() {
- return mapLocation2Status.toString();
- }
-
- public Set<Location> getLocationSet() {
- return mapLocation2Status.keySet();
- }
-
- public void merge(SharedLocState inState) {
- Set<Location> keySet = inState.getLocationSet();
- for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
- Location inLoc = (Location) iterator.next();
-
- Pair<Set<Descriptor>, Boolean> inPair = inState.getStatus(inLoc);
- Pair<Set<Descriptor>, Boolean> currPair = mapLocation2Status.get(inLoc);
-
- if (currPair == null) {
- currPair =
- new Pair<Set<Descriptor>, Boolean>(new HashSet<Descriptor>(), new Boolean(false));
- mapLocation2Status.put(inLoc, currPair);
- }
- mergeSet(currPair.getFirst(), inPair.getFirst());
- }
- }
-
- public void mergeSet(Set<Descriptor> curr, Set<Descriptor> in) {
- if (curr.isEmpty()) {
- // Varset has a special initial value which covers all possible
- // elements
- // For the first time of intersection, we can take all previous set
- curr.addAll(in);
- } else {
- curr.retainAll(in);
- }
- }
-
- public int hashCode() {
- return mapLocation2Status.hashCode();
- }
-
- public Hashtable<Location, Pair<Set<Descriptor>, Boolean>> getMap() {
- return mapLocation2Status;
- }
-
- public boolean equals(Object o) {
- if (!(o instanceof SharedLocState)) {
- return false;
- }
- SharedLocState in = (SharedLocState) o;
- return in.getMap().equals(mapLocation2Status);
- }
-
- public Set<Descriptor> getVarSet(Location loc) {
- return mapLocation2Status.get(loc).getFirst();
- }
-
- public void updateFlag(Location loc, boolean b) {
- Pair<Set<Descriptor>, Boolean> pair = mapLocation2Status.get(loc);
- if (pair.getSecond() != b) {
- mapLocation2Status.put(loc,
- new Pair<Set<Descriptor>, Boolean>(pair.getFirst(), Boolean.valueOf(b)));
- }
- }
-
- public boolean getFlag(Location loc) {
- return mapLocation2Status.get(loc).getSecond().booleanValue();
- }
-
- public SharedLocState clone() {
- SharedLocState newState = new SharedLocState();
- newState.mapLocation2Status =
- (Hashtable<Location, Pair<Set<Descriptor>, Boolean>>) mapLocation2Status.clone();
- return newState;
- }
-}
--- /dev/null
+package Analysis.SSJava;
+
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Set;
+
+import IR.Descriptor;
+import Util.Pair;
+
+public class SharedStatus {
+
+ // maps location to its current writing var set and flag
+ Hashtable<Location, Pair<Set<Descriptor>, Boolean>> mapLocation2Status;
+
+ public SharedStatus() {
+ mapLocation2Status = new Hashtable<Location, Pair<Set<Descriptor>, Boolean>>();
+ }
+
+ private Pair<Set<Descriptor>, Boolean> getStatus(Location loc) {
+ Pair<Set<Descriptor>, Boolean> pair = mapLocation2Status.get(loc);
+ if (pair == null) {
+ pair = new Pair<Set<Descriptor>, Boolean>(new HashSet<Descriptor>(), new Boolean(false));
+ mapLocation2Status.put(loc, pair);
+ }
+ return pair;
+ }
+
+ public void addVar(Location loc, Descriptor d) {
+ getStatus(loc).getFirst().add(d);
+ }
+
+ public void removeVar(Location loc, Descriptor d) {
+ getStatus(loc).getFirst().remove(d);
+ }
+
+ public String toString() {
+ return mapLocation2Status.toString();
+ }
+
+ public Set<Location> getLocationSet() {
+ return mapLocation2Status.keySet();
+ }
+
+ public void merge(SharedStatus inState) {
+ Set<Location> keySet = inState.getLocationSet();
+ for (Iterator iterator = keySet.iterator(); iterator.hasNext();) {
+ Location inLoc = (Location) iterator.next();
+
+ Pair<Set<Descriptor>, Boolean> inPair = inState.getStatus(inLoc);
+ Pair<Set<Descriptor>, Boolean> currPair = mapLocation2Status.get(inLoc);
+
+ if (currPair == null) {
+ currPair =
+ new Pair<Set<Descriptor>, Boolean>(new HashSet<Descriptor>(), new Boolean(false));
+ mapLocation2Status.put(inLoc, currPair);
+ }
+ mergeSet(currPair.getFirst(), inPair.getFirst());
+ }
+ }
+
+ public void mergeSet(Set<Descriptor> curr, Set<Descriptor> in) {
+ if (curr.isEmpty()) {
+ // Varset has a special initial value which covers all possible
+ // elements
+ // For the first time of intersection, we can take all previous set
+ curr.addAll(in);
+ } else {
+ curr.retainAll(in);
+ }
+ }
+
+ public int hashCode() {
+ return mapLocation2Status.hashCode();
+ }
+
+ public Hashtable<Location, Pair<Set<Descriptor>, Boolean>> getMap() {
+ return mapLocation2Status;
+ }
+
+ public boolean equals(Object o) {
+ if (!(o instanceof SharedStatus)) {
+ return false;
+ }
+ SharedStatus in = (SharedStatus) o;
+ return in.getMap().equals(mapLocation2Status);
+ }
+
+ public Set<Descriptor> getVarSet(Location loc) {
+ return mapLocation2Status.get(loc).getFirst();
+ }
+
+ public void updateFlag(Location loc, boolean b) {
+ Pair<Set<Descriptor>, Boolean> pair = mapLocation2Status.get(loc);
+ if (pair.getSecond() != b) {
+ mapLocation2Status.put(loc,
+ new Pair<Set<Descriptor>, Boolean>(pair.getFirst(), Boolean.valueOf(b)));
+ }
+ }
+
+ public boolean getFlag(Location loc) {
+ return mapLocation2Status.get(loc).getSecond().booleanValue();
+ }
+
+ public SharedStatus clone() {
+ SharedStatus newState = new SharedStatus();
+ newState.mapLocation2Status =
+ (Hashtable<Location, Pair<Set<Descriptor>, Boolean>>) mapLocation2Status.clone();
+ return newState;
+ }
+}