From: yeom Date: Mon, 11 Jul 2011 23:27:23 +0000 (+0000) Subject: refactoring X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=09309478816128d9020a6399d7a0e5a5de816216;p=IRC.git refactoring --- diff --git a/Robust/src/Analysis/SSJava/ClearingSummary.java b/Robust/src/Analysis/SSJava/ClearingSummary.java new file mode 100644 index 00000000..fd5a3de8 --- /dev/null +++ b/Robust/src/Analysis/SSJava/ClearingSummary.java @@ -0,0 +1,59 @@ +package Analysis.SSJava; + +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Set; + +import IR.Descriptor; + +public class ClearingSummary { + + Hashtable, SharedStatus> summary; + + public ClearingSummary() { + summary = new Hashtable, SharedStatus>(); + } + + public Iterator> heapPathIterator() { + return summary.keySet().iterator(); + } + + public SharedStatus get(NTuple hp) { + return summary.get(hp); + } + + public Set> keySet() { + return summary.keySet(); + } + + public void put(NTuple key, SharedStatus value) { + summary.put(key, value); + } + + public String toString() { + return summary.toString(); + } + + public int hashCode() { + return summary.hashCode(); + } + + public Hashtable, SharedStatus> getSummary() { + return summary; + } + + public boolean equals(Object o) { + + if (!(o instanceof ClearingSummary)) { + return false; + } + + ClearingSummary in = (ClearingSummary) o; + + if (getSummary().equals(in.getSummary())) { + return true; + } + + return false; + } +} diff --git a/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java b/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java index 750f97a2..93145be8 100644 --- a/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java +++ b/Robust/src/Analysis/SSJava/DefinitelyWrittenCheck.java @@ -63,14 +63,14 @@ public class DefinitelyWrittenCheck { // 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, SharedLocState>> mapMethodDescriptorToCompleteClearingSummary; + private Hashtable mapMethodDescriptorToCompleteClearingSummary; // maps a method descriptor to the merged incoming caller's current // overwritten status - private Hashtable, SharedLocState>> mapMethodDescriptorToInitialClearingSummary; + private Hashtable mapMethodDescriptorToInitialClearingSummary; // maps a flat node to current partial results - private Hashtable, SharedLocState>> mapFlatNodeToClearingSummary; + private Hashtable mapFlatNodeToClearingSummary; // maps shared location to the set of descriptors which belong to the shared // location @@ -82,7 +82,7 @@ public class DefinitelyWrittenCheck { // when analyzing flatcall, need to re-schedule set of callee private Set calleesToEnqueue; - private Set, SharedLocState>> possibleCalleeCompleteSummarySetToCaller; + private Set possibleCalleeCompleteSummarySetToCaller; private LinkedList sortedDescriptors; @@ -110,14 +110,13 @@ public class DefinitelyWrittenCheck { this.calleeIntersectBoundOverWriteSet = new HashSet>(); this.mapMethodDescriptorToCompleteClearingSummary = - new Hashtable, SharedLocState>>(); + new Hashtable(); this.mapMethodDescriptorToInitialClearingSummary = - new Hashtable, SharedLocState>>(); + new Hashtable(); this.mapSharedLocation2DescriptorSet = new Hashtable>(); this.methodDescriptorsToVisitStack = new Stack(); this.calleesToEnqueue = new HashSet(); - this.possibleCalleeCompleteSummarySetToCaller = - new HashSet, SharedLocState>>(); + this.possibleCalleeCompleteSummarySetToCaller = new HashSet(); this.LOCAL = new TempDescriptor("LOCAL"); } @@ -134,7 +133,7 @@ public class DefinitelyWrittenCheck { // mapping of method containing ssjava loop has the final result of // shared location analysis - Hashtable, SharedLocState> result = + ClearingSummary result = mapMethodDescriptorToCompleteClearingSummary.get(sortedDescriptors.peekFirst()); System.out.println("checkSharedLocationResult=" + result); @@ -142,7 +141,7 @@ public class DefinitelyWrittenCheck { Set> hpKeySet = result.keySet(); for (Iterator iterator = hpKeySet.iterator(); iterator.hasNext();) { NTuple hpKey = (NTuple) iterator.next(); - SharedLocState state = result.get(hpKey); + SharedStatus state = result.get(hpKey); Set locKeySet = state.getLocationSet(); for (Iterator iterator2 = locKeySet.iterator(); iterator2.hasNext();) { Location locKey = (Location) iterator2.next(); @@ -170,11 +169,10 @@ public class DefinitelyWrittenCheck { while (!methodDescriptorsToVisitStack.isEmpty()) { MethodDescriptor md = methodDescriptorsToVisitStack.pop(); - Hashtable, SharedLocState> completeSummary = + ClearingSummary completeSummary = sharedLocation_analyzeMethod(md, (md.equals(methodContainingSSJavaLoop))); - Hashtable, SharedLocState> prevCompleteSummary = - mapMethodDescriptorToCompleteClearingSummary.get(md); + ClearingSummary prevCompleteSummary = mapMethodDescriptorToCompleteClearingSummary.get(md); if (!completeSummary.equals(prevCompleteSummary)) { @@ -207,8 +205,8 @@ public class DefinitelyWrittenCheck { } - private Hashtable, 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 + " " @@ -221,8 +219,7 @@ public class DefinitelyWrittenCheck { Set flatNodesToVisit = new HashSet(); // start a new mapping of partial results for each flat node - mapFlatNodeToClearingSummary = - new Hashtable, SharedLocState>>(); + mapFlatNodeToClearingSummary = new Hashtable(); if (onlyVisitSSJavaLoop) { flatNodesToVisit.add(ssjavaLoopEntrance); @@ -236,14 +233,12 @@ public class DefinitelyWrittenCheck { FlatNode fn = flatNodesToVisit.iterator().next(); flatNodesToVisit.remove(fn); - Hashtable, SharedLocState> curr = - new Hashtable, SharedLocState>(); + ClearingSummary curr = new ClearingSummary(); - Set, SharedLocState>> prevSet = - new HashSet, SharedLocState>>(); + Set prevSet = new HashSet(); for (int i = 0; i < fn.numPrev(); i++) { FlatNode prevFn = fn.getPrev(i); - Hashtable, SharedLocState> in = mapFlatNodeToClearingSummary.get(prevFn); + ClearingSummary in = mapFlatNodeToClearingSummary.get(prevFn); if (in != null) { prevSet.add(in); } @@ -251,8 +246,7 @@ public class DefinitelyWrittenCheck { mergeSharedLocationAnaylsis(curr, prevSet); sharedLocation_nodeActions(md, fn, curr, returnNodeSet, onlyVisitSSJavaLoop); - Hashtable, SharedLocState> clearingPrev = - mapFlatNodeToClearingSummary.get(fn); + ClearingSummary clearingPrev = mapFlatNodeToClearingSummary.get(fn); if (!curr.equals(clearingPrev)) { mapFlatNodeToClearingSummary.put(fn, curr); @@ -269,17 +263,15 @@ public class DefinitelyWrittenCheck { } - Hashtable, SharedLocState> completeSummary = - new Hashtable, SharedLocState>(); + ClearingSummary completeSummary = new ClearingSummary(); + Set summarySet = new HashSet(); - Set, SharedLocState>> summarySet = - new HashSet, 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, SharedLocState> frnSummary = + ClearingSummary frnSummary = mapFlatNodeToClearingSummary.get(ssjavaLoopEntrance.getPrev(i)); if (frnSummary != null) { summarySet.add(frnSummary); @@ -290,8 +282,7 @@ public class DefinitelyWrittenCheck { if (!returnNodeSet.isEmpty()) { for (Iterator iterator = returnNodeSet.iterator(); iterator.hasNext();) { FlatNode frn = (FlatNode) iterator.next(); - Hashtable, SharedLocState> frnSummary = - mapFlatNodeToClearingSummary.get(frn); + ClearingSummary frnSummary = mapFlatNodeToClearingSummary.get(frn); summarySet.add(frnSummary); } } @@ -301,8 +292,7 @@ public class DefinitelyWrittenCheck { } private void sharedLocation_nodeActions(MethodDescriptor caller, FlatNode fn, - Hashtable, SharedLocState> curr, Set returnNodeSet, - boolean isSSJavaLoop) { + ClearingSummary curr, Set returnNodeSet, boolean isSSJavaLoop) { TempDescriptor lhs; TempDescriptor rhs; @@ -312,11 +302,10 @@ public class DefinitelyWrittenCheck { case FKind.FlatMethod: { FlatMethod fm = (FlatMethod) fn; - Hashtable, SharedLocState> summaryFromCaller = + ClearingSummary summaryFromCaller = mapMethodDescriptorToInitialClearingSummary.get(fm.getMethod()); - Set, SharedLocState>> inSet = - new HashSet, SharedLocState>>(); + Set inSet = new HashSet(); inSet.add(summaryFromCaller); mergeSharedLocationAnaylsis(curr, inSet); @@ -405,10 +394,10 @@ public class DefinitelyWrittenCheck { // updates possible callee's initial summary using caller's current // writing status - Hashtable, SharedLocState> prevCalleeInitSummary = + ClearingSummary prevCalleeInitSummary = mapMethodDescriptorToInitialClearingSummary.get(mdPossibleCallee); - Hashtable, SharedLocState> calleeInitSummary = + ClearingSummary calleeInitSummary = bindHeapPathOfCalleeCallerEffects(fc, calleeFlatMethod, curr); // if changes, update the init summary @@ -438,11 +427,10 @@ public class DefinitelyWrittenCheck { } - private Hashtable, SharedLocState> bindHeapPathOfCalleeCallerEffects( - FlatCall fc, FlatMethod calleeFlatMethod, Hashtable, SharedLocState> curr) { + private ClearingSummary bindHeapPathOfCalleeCallerEffects(FlatCall fc, + FlatMethod calleeFlatMethod, ClearingSummary curr) { - Hashtable, SharedLocState> boundSet = - new Hashtable, SharedLocState>(); + ClearingSummary boundSet = new ClearingSummary(); // create mapping from arg idx to its heap paths Hashtable> mapArgIdx2CallerArgHeapPath = @@ -493,12 +481,11 @@ public class DefinitelyWrittenCheck { } // contribute callee's complete summary into the caller's current summary - Hashtable, SharedLocState> calleeCompleteSummary = + ClearingSummary calleeCompleteSummary = mapMethodDescriptorToCompleteClearingSummary.get(calleeFlatMethod.getMethod()); if (calleeCompleteSummary != null) { - Hashtable, SharedLocState> boundCalleeEfffects = - new Hashtable, SharedLocState>(); + ClearingSummary boundCalleeEfffects = new ClearingSummary(); for (int i = 0; i < calleeFlatMethod.numParameters(); i++) { NTuple argHeapPath = mapArgIdx2CallerArgHeapPath.get(Integer.valueOf(i)); TempDescriptor calleeParamHeapPath = mapParamIdx2ParamTempDesc.get(Integer.valueOf(i)); @@ -709,11 +696,10 @@ public class DefinitelyWrittenCheck { } - private void writeLocation(Hashtable, SharedLocState> curr, - NTuple hp, Descriptor d) { + private void writeLocation(ClearingSummary curr, NTuple 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 @@ -727,21 +713,19 @@ public class DefinitelyWrittenCheck { } } - private void readLocation(Hashtable, SharedLocState> curr, - NTuple hp, Descriptor d) { + private void readLocation(ClearingSummary curr, NTuple 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, SharedLocState> curr, - NTuple hp) { - SharedLocState state = curr.get(hp); + private SharedStatus getState(ClearingSummary curr, NTuple hp) { + SharedStatus state = curr.get(hp); if (state == null) { - state = new SharedLocState(); + state = new SharedStatus(); curr.put(hp, state); } return state; @@ -1355,8 +1339,7 @@ public class DefinitelyWrittenCheck { } - private void mergeSharedLocationAnaylsis(Hashtable, SharedLocState> curr, - Set, SharedLocState>> inSet) { + private void mergeSharedLocationAnaylsis(ClearingSummary curr, Set inSet) { if (inSet.size() == 0) { return; @@ -1367,18 +1350,17 @@ public class DefinitelyWrittenCheck { for (Iterator inIterator = inSet.iterator(); inIterator.hasNext();) { - Hashtable, SharedLocState> inTable = - (Hashtable, SharedLocState>) inIterator.next(); + ClearingSummary inTable = (ClearingSummary) inIterator.next(); Set> keySet = inTable.keySet(); for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { NTuple hpKey = (NTuple) 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); @@ -1407,7 +1389,7 @@ public class DefinitelyWrittenCheck { Set> hpKeySet = curr.keySet(); for (Iterator iterator = hpKeySet.iterator(); iterator.hasNext();) { NTuple hpKey = (NTuple) iterator.next(); - SharedLocState currState = curr.get(hpKey); + SharedStatus currState = curr.get(hpKey); Set locKeySet = currState.getMap().keySet(); for (Iterator iterator2 = locKeySet.iterator(); iterator2.hasNext();) { Location locKey = (Location) iterator2.next(); diff --git a/Robust/src/Analysis/SSJava/SharedLocState.java b/Robust/src/Analysis/SSJava/SharedLocState.java deleted file mode 100644 index bd197610..00000000 --- a/Robust/src/Analysis/SSJava/SharedLocState.java +++ /dev/null @@ -1,111 +0,0 @@ -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, Boolean>> mapLocation2Status; - - public SharedLocState() { - mapLocation2Status = new Hashtable, Boolean>>(); - } - - private Pair, Boolean> getStatus(Location loc) { - Pair, Boolean> pair = mapLocation2Status.get(loc); - if (pair == null) { - pair = new Pair, Boolean>(new HashSet(), 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 getLocationSet() { - return mapLocation2Status.keySet(); - } - - public void merge(SharedLocState inState) { - Set keySet = inState.getLocationSet(); - for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { - Location inLoc = (Location) iterator.next(); - - Pair, Boolean> inPair = inState.getStatus(inLoc); - Pair, Boolean> currPair = mapLocation2Status.get(inLoc); - - if (currPair == null) { - currPair = - new Pair, Boolean>(new HashSet(), new Boolean(false)); - mapLocation2Status.put(inLoc, currPair); - } - mergeSet(currPair.getFirst(), inPair.getFirst()); - } - } - - public void mergeSet(Set curr, Set 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, 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 getVarSet(Location loc) { - return mapLocation2Status.get(loc).getFirst(); - } - - public void updateFlag(Location loc, boolean b) { - Pair, Boolean> pair = mapLocation2Status.get(loc); - if (pair.getSecond() != b) { - mapLocation2Status.put(loc, - new Pair, 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, Boolean>>) mapLocation2Status.clone(); - return newState; - } -} diff --git a/Robust/src/Analysis/SSJava/SharedStatus.java b/Robust/src/Analysis/SSJava/SharedStatus.java new file mode 100644 index 00000000..8c6f9f51 --- /dev/null +++ b/Robust/src/Analysis/SSJava/SharedStatus.java @@ -0,0 +1,111 @@ +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, Boolean>> mapLocation2Status; + + public SharedStatus() { + mapLocation2Status = new Hashtable, Boolean>>(); + } + + private Pair, Boolean> getStatus(Location loc) { + Pair, Boolean> pair = mapLocation2Status.get(loc); + if (pair == null) { + pair = new Pair, Boolean>(new HashSet(), 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 getLocationSet() { + return mapLocation2Status.keySet(); + } + + public void merge(SharedStatus inState) { + Set keySet = inState.getLocationSet(); + for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { + Location inLoc = (Location) iterator.next(); + + Pair, Boolean> inPair = inState.getStatus(inLoc); + Pair, Boolean> currPair = mapLocation2Status.get(inLoc); + + if (currPair == null) { + currPair = + new Pair, Boolean>(new HashSet(), new Boolean(false)); + mapLocation2Status.put(inLoc, currPair); + } + mergeSet(currPair.getFirst(), inPair.getFirst()); + } + } + + public void mergeSet(Set curr, Set 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, 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 getVarSet(Location loc) { + return mapLocation2Status.get(loc).getFirst(); + } + + public void updateFlag(Location loc, boolean b) { + Pair, Boolean> pair = mapLocation2Status.get(loc); + if (pair.getSecond() != b) { + mapLocation2Status.put(loc, + new Pair, 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, Boolean>>) mapLocation2Status.clone(); + return newState; + } +}