From 09309478816128d9020a6399d7a0e5a5de816216 Mon Sep 17 00:00:00 2001 From: yeom Date: Mon, 11 Jul 2011 23:27:23 +0000 Subject: [PATCH] refactoring --- .../src/Analysis/SSJava/ClearingSummary.java | 59 ++++++++++ .../SSJava/DefinitelyWrittenCheck.java | 108 ++++++++---------- ...{SharedLocState.java => SharedStatus.java} | 14 +-- 3 files changed, 111 insertions(+), 70 deletions(-) create mode 100644 Robust/src/Analysis/SSJava/ClearingSummary.java rename Robust/src/Analysis/SSJava/{SharedLocState.java => SharedStatus.java} (91%) 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/SharedStatus.java similarity index 91% rename from Robust/src/Analysis/SSJava/SharedLocState.java rename to Robust/src/Analysis/SSJava/SharedStatus.java index bd197610..8c6f9f51 100644 --- a/Robust/src/Analysis/SSJava/SharedLocState.java +++ b/Robust/src/Analysis/SSJava/SharedStatus.java @@ -8,12 +8,12 @@ import java.util.Set; import IR.Descriptor; import Util.Pair; -public class SharedLocState { +public class SharedStatus { // maps location to its current writing var set and flag Hashtable, Boolean>> mapLocation2Status; - public SharedLocState() { + public SharedStatus() { mapLocation2Status = new Hashtable, Boolean>>(); } @@ -42,7 +42,7 @@ public class SharedLocState { return mapLocation2Status.keySet(); } - public void merge(SharedLocState inState) { + public void merge(SharedStatus inState) { Set keySet = inState.getLocationSet(); for (Iterator iterator = keySet.iterator(); iterator.hasNext();) { Location inLoc = (Location) iterator.next(); @@ -79,10 +79,10 @@ public class SharedLocState { } public boolean equals(Object o) { - if (!(o instanceof SharedLocState)) { + if (!(o instanceof SharedStatus)) { return false; } - SharedLocState in = (SharedLocState) o; + SharedStatus in = (SharedStatus) o; return in.getMap().equals(mapLocation2Status); } @@ -102,8 +102,8 @@ public class SharedLocState { return mapLocation2Status.get(loc).getSecond().booleanValue(); } - public SharedLocState clone() { - SharedLocState newState = new SharedLocState(); + public SharedStatus clone() { + SharedStatus newState = new SharedStatus(); newState.mapLocation2Status = (Hashtable, Boolean>>) mapLocation2Status.clone(); return newState; -- 2.34.1