methodeffects object maintains analysis result for each method context.
+++ /dev/null
-package Analysis.MLP;
-
-import IR.TypeDescriptor;
-
-public class AccKey {
-
- private String fd;
- private TypeDescriptor td;
-
- // private Integer hrnID;
-
- public AccKey(String fd, TypeDescriptor td) {
- this.fd = fd;
- this.td = td;
- }
-
- public String getFieldDescriptor() {
- return fd;
- }
-
- public TypeDescriptor getTypeDescriptor() {
- return td;
- }
-
- public String toString() {
- return "(" + td + ")" + fd ;
- }
-
- public int hashCode() {
-
- int hash = 1;
-
- if (fd != null) {
- hash = hash * 31 + fd.hashCode();
- }
-
- if (td != null) {
- hash += td.getSymbol().hashCode();
- }
-
- return hash;
-
- }
-
- public boolean equals(Object o) {
-
- if (o == null) {
- return false;
- }
-
- if (!(o instanceof AccKey)) {
- return false;
- }
-
- AccKey in = (AccKey) o;
-
- if (fd.equals(in.getFieldDescriptor()) && td.getSymbol().equals(in.getTypeDescriptor().getSymbol())) {
- return true;
- } else {
- return false;
- }
-
- }
-}
+++ /dev/null
-package Analysis.MLP;
-
-import java.util.HashSet;
-import java.util.Hashtable;
-import java.util.Iterator;
-
-import IR.Flat.TempDescriptor;
-
-public class AccSet {
-
- private Hashtable<TempDescriptor, HashSet<AccKey>> readTable;
- private Hashtable<TempDescriptor, HashSet<AccKey>> writeTable;
-
- public AccSet() {
-
- readTable = new Hashtable<TempDescriptor, HashSet<AccKey>>();
- writeTable = new Hashtable<TempDescriptor, HashSet<AccKey>>();
-
- }
-
- public void addReadingVar(TempDescriptor td, AccKey access) {
- HashSet<AccKey> aSet = readTable.get(td);
- if (aSet == null) {
- aSet = new HashSet<AccKey>();
- }
-
- aSet.add(access);
- readTable.put(td, aSet);
- }
-
- public void addWritingVar(TempDescriptor td, AccKey access) {
-
- HashSet<AccKey> aSet = writeTable.get(td);
- if (aSet == null) {
- aSet = new HashSet<AccKey>();
- }
-
- aSet.add(access);
- writeTable.put(td, aSet);
-
- }
-
- public boolean containsParam(TempDescriptor td) {
-
- Iterator<TempDescriptor> iter = readTable.keySet().iterator();
-
- while (iter.hasNext()) {
-
- TempDescriptor key = iter.next();
- if (key.equals(td)) {
- return true;
- }
-
- }
-
- return false;
-
- }
-
- public void addParam(TempDescriptor paramTD) {
-
- if (!readTable.containsKey(paramTD)) {
- HashSet<AccKey> readSet = new HashSet<AccKey>();
- readTable.put(paramTD, readSet);
- }
-
- if (!writeTable.containsKey(paramTD)) {
- HashSet<AccKey> writeSet = new HashSet<AccKey>();
- writeTable.put(paramTD, writeSet);
- }
-
- }
-
- public void addAll(AccSet newAccSet) {
-
- Hashtable<TempDescriptor, HashSet<AccKey>> newReadTable = newAccSet
- .getReadTable();
- Hashtable<TempDescriptor, HashSet<AccKey>> newWriteTable = newAccSet
- .getWriteTable();
-
- Iterator<TempDescriptor> iter = newReadTable.keySet().iterator();
- while (iter.hasNext()) { // for each variables
- TempDescriptor td = iter.next();
-
- HashSet<AccKey> currentSet;
- if (!readTable.containsKey(td)) {
- currentSet = new HashSet<AccKey>();
- } else {
- currentSet = readTable.get(td);
- }
-
- HashSet<AccKey> newSet = newReadTable.get(td);
- currentSet.addAll(newSet);
- readTable.put(td, currentSet);
- }
-
- iter = newWriteTable.keySet().iterator();
- while (iter.hasNext()) { // for each variables
- TempDescriptor td = iter.next();
-
- HashSet<AccKey> currentSet;
- if (!writeTable.containsKey(td)) {
- currentSet = new HashSet<AccKey>();
- } else {
- currentSet = writeTable.get(td);
- }
-
- HashSet<AccKey> newSet = newWriteTable.get(td);
- currentSet.addAll(newSet);
- writeTable.put(td, currentSet);
- }
-
- }
-
- public Hashtable<TempDescriptor, HashSet<AccKey>> getReadTable() {
- return readTable;
- }
-
- public Hashtable<TempDescriptor, HashSet<AccKey>> getWriteTable() {
- return writeTable;
- }
-
- public boolean equals(Object o) {
- if (o == null) {
- return false;
- }
-
- if (!(o instanceof AccSet)) {
- return false;
- }
-
- AccSet in = (AccSet) o;
-
- if (getReadTable().equals(in.getReadTable())
- && getWriteTable().equals(in.getWriteTable())) {
- return true;
- } else {
- return false;
- }
-
- }
-
- public void printSet() {
-
- String readStr = "";
- String writeStr = "";
-
- readStr = "#Reading#\r\n";
- Iterator<TempDescriptor> iter = getReadTable().keySet().iterator();
- while (iter.hasNext()) { // for each variables
-
- TempDescriptor td = iter.next();
- HashSet<AccKey> aSet = readTable.get(td);
-
- readStr += td.getSymbol() + ":" + "{";
-
- Iterator<AccKey> setIter = aSet.iterator();
- while (setIter.hasNext()) {
- AccKey element = setIter.next();
- readStr += " " + element;
- }
- readStr += "}\r\n";
- }
-
- writeStr = "#Writing#\r\n";
- iter = getWriteTable().keySet().iterator();
- while (iter.hasNext()) { // for each variables
-
- TempDescriptor td = iter.next();
- HashSet<AccKey> aSet = writeTable.get(td);
-
- writeStr += td.getSymbol() + ":" + "{";
-
- Iterator<AccKey> setIter = aSet.iterator();
- while (setIter.hasNext()) {
- AccKey element = setIter.next();
- writeStr += " " + element;
- }
- writeStr += "}\r\n";
- }
-
- System.out.println(readStr);
- System.out.println(writeStr);
-
- }
-
- public String toString() {
-
- String str = "\n";
-
- Iterator<TempDescriptor> iter = getReadTable().keySet().iterator();
- while (iter.hasNext()) { // for each variables
-
- TempDescriptor td = iter.next();
-
- str += "\tParameter " + td.getSymbol() + " reading={";
-
- HashSet<AccKey> aSet = readTable.get(td);
- Iterator<AccKey> setIter = aSet.iterator();
- boolean first = true;
- while (setIter.hasNext()) {
- AccKey element = setIter.next();
- if (first) {
- str += " " + element;
- first = false;
- } else {
- str += " , " + element;
- }
-
- }
- str += " }\n";
-
- str += "\tParameter " + td.getSymbol() + " writing={";
-
- aSet = writeTable.get(td);
- setIter = aSet.iterator();
- first = true;
- while (setIter.hasNext()) {
- AccKey element = setIter.next();
- if (first) {
- str += " " + element;
- first = false;
- } else {
- str += " , " + element;
- }
-
- }
- str += " }\n";
-
- }
-
- return str;
- }
-
-}
private Hashtable< FlatNode, VarSrcTokTable > variableResults;
private Hashtable< FlatNode, Set<TempDescriptor> > notAvailableResults;
private Hashtable< FlatNode, CodePlan > codePlans;
-
- private Hashtable<FlatNode, AccSet> effectsResults;
private Hashtable< FlatEdge, FlatWriteDynamicVarNode > wdvNodesToSpliceIn;
notAvailableResults = new Hashtable< FlatNode, Set<TempDescriptor> >();
codePlans = new Hashtable< FlatNode, CodePlan >();
wdvNodesToSpliceIn = new Hashtable< FlatEdge, FlatWriteDynamicVarNode >();
-
- effectsResults = new Hashtable<FlatNode, AccSet>();
FlatMethod fmMain = state.getMethodFlat( typeUtil.getMain() );
// point, in a forward fixed-point pass
notAvailableForward( fm );
}
-
- // new pass for method effects analysis
- methItr = ownAnalysis.descriptorsToAnalyze.iterator();
- while (methItr.hasNext()) {
- Descriptor d = methItr.next();
- FlatMethod fm = state.getMethodFlat(d);
- effectsForward(fm);
- }
+
// 7th pass
methItr = ownAnalysis.descriptorsToAnalyze.iterator();
}
}
- private void effectsForward(FlatMethod fm) {
- Set<FlatNode> flatNodesToVisit = new HashSet<FlatNode>();
- flatNodesToVisit.add(fm);
-
- while (!flatNodesToVisit.isEmpty()) {
- FlatNode fn = (FlatNode) flatNodesToVisit.iterator().next();
- flatNodesToVisit.remove(fn);
-
- AccSet prev = effectsResults.get(fn);
- AccSet curr = new AccSet();
-
- // merge phase
- for (int i = 0; i < fn.numPrev(); i++) {
- FlatNode nn = fn.getPrev(i);
- AccSet accSet = effectsResults.get(nn);
- if (accSet != null) {
- curr.addAll(accSet);
- }
- }
-
- effects_nodeActions(fn, curr);
-
- // if a new result, schedule forward nodes for analysis
- if (!curr.equals(prev)) {
- effectsResults.put(fn, curr);
- for (int i = 0; i < fn.numNext(); i++) {
- FlatNode nn = fn.getNext(i);
- flatNodesToVisit.add(nn);
- }
- }
- }
-
- }
-
-
-
-
- private void effects_nodeActions(FlatNode fn, AccSet curr) {
-
- OwnershipGraph fnOG = ownAnalysis
- .getMappingFlatNodeToOwnershipGraph(fn);
-
- switch (fn.kind()) {
-
- case FKind.FlatMethod: {
-
- FlatMethod fm = (FlatMethod) fn;
- int numParam = fm.numParameters();
-
- for (int i = 0; i < numParam; i++) {
- TempDescriptor paramTD = fm.getParameter(i);
-
- curr.addParam(paramTD);
- }
-
- // for debug
- // OwnershipGraph fnOG =
- // ownAnalysis.getMappingFlatNodeToOwnershipGraph(fn);
- // try {
- // fnOG.writeGraph(fn + "FOOGRAPH", true, true, true, true, false);
- // } catch (IOException e) {
- // System.out.println("Error writing debug capture.");
- // System.exit(0);
- // }
-
- }
- break;
-
- case FKind.FlatSetFieldNode: {
-
- FlatSetFieldNode fsfn = (FlatSetFieldNode) fn;
-
- TempDescriptor dstDesc = fsfn.getDst();
- FieldDescriptor fieldDesc = fsfn.getField();
- TempDescriptor srcDesc = fsfn.getSrc();
-
- LabelNode ln = fnOG.td2ln.get(dstDesc);
- if (ln != null) {
- Iterator<ReferenceEdge> heapRegionsItr = ln
- .iteratorToReferencees();
-
- String tempStr = "";
- while (heapRegionsItr.hasNext()) {
- HeapRegionNode hrn2 = heapRegionsItr.next().getDst();
-
- Set<Integer> paramSet = fnOG.idSecondary2paramIndexSet
- .get(hrn2.getID());
-
- String param = null;
- if (paramSet != null) {
- Iterator<Integer> paramIter = paramSet.iterator();
- param = "";
- while (paramIter.hasNext()) {
- param += paramIter.next() + " ";
- }
- }
- tempStr += " " + hrn2 + "(" + param + ")";
- }
-
- heapRegionsItr = ln.iteratorToReferencees();
- while (heapRegionsItr.hasNext()) {
- ReferenceEdge edge = heapRegionsItr.next();
- HeapRegionNode hrn = edge.getDst();
-
- if (hrn.isParameter()) {
- // currently, handle this case. otherwise, ignore it.
- Iterator<ReferenceEdge> iter = hrn
- .iteratorToReferencers();
- while (iter.hasNext()) {
- ReferenceEdge re = iter.next();
- if (re.getSrc() instanceof LabelNode) {
- LabelNode labelNode = (LabelNode) re.getSrc();
-
- if (curr.containsParam(labelNode
- .getTempDescriptor())) {
-
- curr.addWritingVar(labelNode
- .getTempDescriptor(), new AccKey(
- fieldDesc.getSymbol(), dstDesc
- .getType()));
-
- }
-
- }
- }
-
- // check weather this heap region is parameter
- // reachable...
-
- Set<Integer> paramSet = fnOG.idSecondary2paramIndexSet
- .get(hrn.getID());
- if (paramSet != null) {
- Iterator<Integer> paramIter = paramSet.iterator();
-
- while (paramIter.hasNext()) {
- Integer paramID = paramIter.next();
-
- Integer primaryID = fnOG.paramIndex2idPrimary
- .get(paramID);
- HeapRegionNode paramHRN = fnOG.id2hrn
- .get(primaryID);
-
- HashSet<LabelNode> LNSet = getParameterLabelNodeSet(
- fnOG, curr, paramHRN);
-
- Iterator<LabelNode> LNSetIter = LNSet
- .iterator();
- while (LNSetIter.hasNext()) {
- LabelNode labelNode = LNSetIter.next();
-
- curr.addWritingVar(labelNode
- .getTempDescriptor(), new AccKey(
- fieldDesc.getSymbol(), dstDesc
- .getType()));
- }
-
- }
- }
-
- }
-
- }
- }
-
- }
- break;
-
- case FKind.FlatFieldNode: {
-
- FlatFieldNode ffn = (FlatFieldNode) fn;
-
- TempDescriptor srcDesc = ffn.getSrc();
- FieldDescriptor fieldDesc = ffn.getField();
-
- LabelNode ln = fnOG.td2ln.get(srcDesc);
- if (ln != null) {
-
- Iterator<ReferenceEdge> heapRegionsItr = ln
- .iteratorToReferencees();
- String tempStr = "";
- while (heapRegionsItr.hasNext()) {
-
- HeapRegionNode hrn = heapRegionsItr.next().getDst();
-
- Set<Integer> paramSet = fnOG.idSecondary2paramIndexSet
- .get(hrn.getID());
-
- String param = null;
- if (paramSet != null) {
- Iterator<Integer> paramIter = paramSet.iterator();
- param = "";
- while (paramIter.hasNext()) {
- param += paramIter.next() + " ";
- }
- }
- tempStr += " " + hrn + "(" + param + ")";
- }
-
- heapRegionsItr = ln.iteratorToReferencees();
- while (heapRegionsItr.hasNext()) {
- ReferenceEdge edge = heapRegionsItr.next();
- HeapRegionNode hrn = edge.getDst();
-
- if (hrn.isParameter()) {
- Iterator<ReferenceEdge> iter = hrn
- .iteratorToReferencers();
-
- while (iter.hasNext()) {
- ReferenceEdge re = iter.next();
- if (re.getSrc() instanceof LabelNode) {
-
- LabelNode labelNode = (LabelNode) re.getSrc();
-
- if (curr.containsParam(labelNode
- .getTempDescriptor())) {
- curr.addReadingVar(labelNode
- .getTempDescriptor(), new AccKey(
- fieldDesc.getSymbol(), srcDesc
- .getType()));
- }
- }
- }
-
- //
- // check weather this heap region is parameter
- // reachable...
- //
-
- Set<Integer> paramSet = fnOG.idSecondary2paramIndexSet
- .get(hrn.getID());
- if (paramSet != null) {
- Iterator<Integer> paramIter = paramSet.iterator();
-
- while (paramIter.hasNext()) {
- Integer paramID = paramIter.next();
-
- Integer primaryID = fnOG.paramIndex2idPrimary
- .get(paramID);
- HeapRegionNode paramHRN = fnOG.id2hrn
- .get(primaryID);
-
- HashSet<LabelNode> LNSet = getParameterLabelNodeSet(
- fnOG, curr, paramHRN);
-
- Iterator<LabelNode> LNSetIter = LNSet
- .iterator();
- while (LNSetIter.hasNext()) {
- LabelNode labelNode = LNSetIter.next();
-
- curr.addReadingVar(labelNode
- .getTempDescriptor(), new AccKey(
- fieldDesc.getSymbol(), srcDesc
- .getType()));
- }
- }
- }
- }
- }
-
- }
-
- }
- break;
-
- }
-
- }
-
- // returns the set of parameter label node which are associated with the
- // specific heap region node.
- private HashSet<LabelNode> getParameterLabelNodeSet(OwnershipGraph og,
- AccSet curr, HeapRegionNode hrn) {
-
- HashSet<LabelNode> set = new HashSet<LabelNode>();
- Iterator<ReferenceEdge> iter = hrn.iteratorToReferencers();
- while (iter.hasNext()) {
- ReferenceEdge re = iter.next();
- if (re.getSrc() instanceof LabelNode) {
- LabelNode labelNode = (LabelNode) re.getSrc();
- if (curr.containsParam(labelNode.getTempDescriptor())) {
- set.add(labelNode);
- }
- }
- }
- return set;
- }
private void notAvailableForward( FlatMethod fm ) {
--- /dev/null
+package Analysis.OwnershipAnalysis;
+
+import Analysis.MLP.AccKey;
+import IR.TypeDescriptor;
+
+public class EffectsKey {
+
+ private String fd;
+ private TypeDescriptor td;
+
+ public EffectsKey(String fd, TypeDescriptor td) {
+ this.fd = fd;
+ this.td = td;
+ }
+
+ public String getFieldDescriptor() {
+ return fd;
+ }
+
+ public TypeDescriptor getTypeDescriptor() {
+ return td;
+ }
+
+ public String toString() {
+ return "(" + td + ")" + fd;
+ }
+
+ public int hashCode() {
+
+ int hash = 1;
+
+ if (fd != null) {
+ hash = hash * 31 + fd.hashCode();
+ }
+
+ if (td != null) {
+ hash += td.getSymbol().hashCode();
+ }
+
+ return hash;
+
+ }
+
+ public boolean equals(Object o) {
+
+ if (o == null) {
+ return false;
+ }
+
+ if (!(o instanceof EffectsKey)) {
+ return false;
+ }
+
+ EffectsKey in = (EffectsKey) o;
+
+ if (fd.equals(in.getFieldDescriptor())
+ && td.getSymbol().equals(in.getTypeDescriptor().getSymbol())) {
+ return true;
+ } else {
+ return false;
+ }
+
+ }
+}
--- /dev/null
+package Analysis.OwnershipAnalysis;
+
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Set;
+
+import Analysis.MLP.AccKey;
+import Analysis.MLP.AccSet;
+import IR.Flat.TempDescriptor;
+
+public class EffectsSet {
+
+ private Hashtable<Integer, HashSet<EffectsKey>> readTable;
+ private Hashtable<Integer, HashSet<EffectsKey>> writeTable;
+
+ public EffectsSet() {
+ readTable = new Hashtable<Integer, HashSet<EffectsKey>>();
+ writeTable = new Hashtable<Integer, HashSet<EffectsKey>>();
+ }
+
+ public void addReadingVar(Integer idx, EffectsKey access) {
+ HashSet<EffectsKey> aSet = readTable.get(idx);
+ if (aSet == null) {
+ aSet = new HashSet<EffectsKey>();
+ }
+
+ aSet.add(access);
+ readTable.put(idx, aSet);
+ }
+
+ public void addReadingEffectsSet(Integer idx, HashSet<EffectsKey> newSet) {
+
+ if (newSet != null) {
+ HashSet<EffectsKey> aSet = readTable.get(idx);
+ if (aSet == null) {
+ aSet = new HashSet<EffectsKey>();
+ }
+ aSet.addAll(newSet);
+ readTable.put(idx, aSet);
+ }
+
+ }
+
+ public void addWritingEffectsSet(Integer idx, HashSet<EffectsKey> newSet) {
+
+ if (newSet != null) {
+ HashSet<EffectsKey> aSet = writeTable.get(idx);
+ if (aSet == null) {
+ aSet = new HashSet<EffectsKey>();
+ }
+ aSet.addAll(newSet);
+ writeTable.put(idx, aSet);
+ }
+
+ }
+
+ public Hashtable<Integer, HashSet<EffectsKey>> getReadTable() {
+ return readTable;
+ }
+
+ public Hashtable<Integer, HashSet<EffectsKey>> getWriteTable() {
+ return writeTable;
+ }
+
+ public void addWritingVar(Integer idx, EffectsKey access) {
+ HashSet<EffectsKey> aSet = writeTable.get(idx);
+ if (aSet == null) {
+ aSet = new HashSet<EffectsKey>();
+ }
+ aSet.add(access);
+ writeTable.put(idx, aSet);
+ }
+
+ public Set<EffectsKey> getReadingSet(Integer idx) {
+ return readTable.get(idx);
+ }
+
+ public Set<EffectsKey> getWritingSet(Integer idx) {
+ return writeTable.get(idx);
+ }
+
+ public void printSet() {
+ System.out.println("writeTable=>" + writeTable.hashCode());
+
+ Set<Integer> keySet = readTable.keySet();
+ Iterator<Integer> iter = keySet.iterator();
+ while (iter.hasNext()) {
+ Integer idx = iter.next();
+ Set<EffectsKey> effectSet = readTable.get(idx);
+ String keyStr = "{";
+ if (effectSet != null) {
+ Iterator<EffectsKey> effectIter = effectSet.iterator();
+ while (effectIter.hasNext()) {
+ EffectsKey key = effectIter.next();
+ keyStr += " " + key;
+ }
+ } else {
+ keyStr = "null";
+ }
+ System.out.println("param" + idx + " R=" + keyStr);
+ }
+
+ keySet = writeTable.keySet();
+ System.out.println("# R keyset=" + keySet.size());
+ iter = keySet.iterator();
+ while (iter.hasNext()) {
+ Integer idx = iter.next();
+ Set<EffectsKey> effectSet = writeTable.get(idx);
+ String keyStr = "{";
+ if (effectSet != null) {
+ Iterator<EffectsKey> effectIter = effectSet.iterator();
+ while (effectIter.hasNext()) {
+ EffectsKey key = effectIter.next();
+ keyStr += " " + key;
+ }
+ } else {
+ keyStr = "null";
+ }
+ System.out.println("param" + idx + " W=" + keyStr);
+ }
+
+ }
+
+ public boolean equals(Object o) {
+ if (o == null) {
+ return false;
+ }
+
+ if (!(o instanceof EffectsSet)) {
+ return false;
+ }
+
+ EffectsSet in = (EffectsSet) o;
+
+ if (getReadTable().equals(in.getReadTable())
+ && getWriteTable().equals(in.getWriteTable())) {
+ return true;
+ } else {
+ return false;
+ }
+
+ }
+
+ public int hashCode() {
+ int hash = 1;
+
+ hash += getReadTable().hashCode() + getWriteTable().hashCode() * 31;
+
+ return hash;
+ }
+
+}
--- /dev/null
+package Analysis.OwnershipAnalysis;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import IR.FieldDescriptor;
+import IR.Flat.FlatCall;
+import IR.Flat.TempDescriptor;
+
+public class MethodEffects {
+
+ private EffectsSet effectsSet;
+
+ public MethodEffects() {
+ effectsSet = new EffectsSet();
+ }
+
+ public EffectsSet getEffects() {
+ return effectsSet;
+ }
+
+ public void analyzeFlatFieldNode(OwnershipGraph og, TempDescriptor srcDesc,
+ FieldDescriptor fieldDesc) {
+
+ LabelNode ln = getLabelNodeFromTemp(og, srcDesc);
+ if (ln != null) {
+ Iterator<ReferenceEdge> heapRegionsItr = ln.iteratorToReferencees();
+
+ while (heapRegionsItr.hasNext()) {
+ ReferenceEdge edge = heapRegionsItr.next();
+ HeapRegionNode hrn = edge.getDst();
+
+ if (hrn.isParameter()) {
+ Set<Integer> paramSet = og.idPrimary2paramIndexSet.get(hrn
+ .getID());
+
+ if (paramSet != null) {
+ Iterator<Integer> paramIter = paramSet.iterator();
+ while (paramIter.hasNext()) {
+ Integer paramID = paramIter.next();
+ effectsSet.addReadingVar(paramID, new EffectsKey(
+ fieldDesc.getSymbol(), srcDesc.getType()));
+
+ }
+ }
+
+ // check weather this heap region is parameter
+ // reachable...
+
+ paramSet = og.idSecondary2paramIndexSet.get(hrn.getID());
+ if (paramSet != null) {
+ Iterator<Integer> paramIter = paramSet.iterator();
+
+ while (paramIter.hasNext()) {
+ Integer paramID = paramIter.next();
+ effectsSet.addReadingVar(paramID, new EffectsKey(
+ fieldDesc.getSymbol(), srcDesc.getType()));
+
+ }
+ }
+
+ }
+ }
+ }
+
+ }
+
+ public void analyzeFlatSetFieldNode(OwnershipGraph og,
+ TempDescriptor dstDesc, FieldDescriptor fieldDesc) {
+
+ LabelNode ln = getLabelNodeFromTemp(og, dstDesc);
+ if (ln != null) {
+ Iterator<ReferenceEdge> heapRegionsItr = ln.iteratorToReferencees();
+
+ while (heapRegionsItr.hasNext()) {
+ ReferenceEdge edge = heapRegionsItr.next();
+ HeapRegionNode hrn = edge.getDst();
+
+ if (hrn.isParameter()) {
+
+ Set<Integer> paramSet = og.idPrimary2paramIndexSet.get(hrn
+ .getID());
+
+ if (paramSet != null) {
+ Iterator<Integer> paramIter = paramSet.iterator();
+ while (paramIter.hasNext()) {
+ Integer paramID = paramIter.next();
+ effectsSet.addWritingVar(paramID, new EffectsKey(
+ fieldDesc.getSymbol(), dstDesc.getType()));
+
+ }
+ }
+
+ // check weather this heap region is parameter
+ // reachable...
+
+ paramSet = og.idSecondary2paramIndexSet.get(hrn.getID());
+ if (paramSet != null) {
+ Iterator<Integer> paramIter = paramSet.iterator();
+
+ while (paramIter.hasNext()) {
+ Integer paramID = paramIter.next();
+ effectsSet.addWritingVar(paramID, new EffectsKey(
+ fieldDesc.getSymbol(), dstDesc.getType()));
+
+ }
+ }
+
+ }
+ }
+ }
+
+ }
+
+ private Set<Integer> getReachableParamIndexSet(OwnershipGraph og,
+ TempDescriptor paramDesc) {
+
+ HashSet<Integer> resultSet = new HashSet<Integer>();
+
+ LabelNode ln = getLabelNodeFromTemp(og, paramDesc);
+ if (ln != null) {
+
+ Iterator<ReferenceEdge> heapRegionsItr = ln.iteratorToReferencees();
+
+ while (heapRegionsItr.hasNext()) {
+ ReferenceEdge edge = heapRegionsItr.next();
+ HeapRegionNode hrn = edge.getDst();
+
+ if (hrn.isParameter()) {
+
+ Set<Integer> paramSet = og.idPrimary2paramIndexSet.get(hrn
+ .getID());
+
+ if (paramSet != null) {
+ Iterator<Integer> paramIter = paramSet.iterator();
+ while (paramIter.hasNext()) {
+ Integer paramID = paramIter.next();
+
+ resultSet.add(paramID);
+
+ }
+ }
+
+ // check weather this heap region is parameter
+ // reachable...
+
+ paramSet = og.idSecondary2paramIndexSet.get(hrn.getID());
+ if (paramSet != null) {
+ Iterator<Integer> paramIter = paramSet.iterator();
+
+ while (paramIter.hasNext()) {
+ Integer paramID = paramIter.next();
+
+ resultSet.add(paramID);
+
+ }
+ }
+
+ }
+ }
+
+ }
+
+ return resultSet;
+
+ }
+
+ public void analyzeFlatCall(OwnershipGraph og, FlatCall fc,
+ MethodContext mc, MethodEffects callee) {
+
+ TempDescriptor[] tdArray = fc.readsTemps();
+
+ for (int callerIdx = 0; callerIdx < tdArray.length; callerIdx++) {
+ TempDescriptor paramDesc = tdArray[callerIdx];
+
+ Set<Integer> paramIDs = getReachableParamIndexSet(og, paramDesc);
+
+ // handle read effects
+ Iterator<Integer> paramIter = paramIDs.iterator();
+ while (paramIter.hasNext()) {
+ Integer paramIdx = paramIter.next();
+ HashSet<EffectsKey> newSet = callee.getEffects().getReadTable()
+ .get(paramIdx);
+ effectsSet.addReadingEffectsSet(callerIdx, newSet);
+ }
+
+ // handle write effects
+ paramIter = paramIDs.iterator();
+ while (paramIter.hasNext()) {
+ Integer paramIdx = paramIter.next();
+ HashSet<EffectsKey> newSet = callee.getEffects()
+ .getWriteTable().get(paramIdx);
+ effectsSet.addWritingEffectsSet(callerIdx, newSet);
+ }
+
+ }
+
+ }
+
+ protected LabelNode getLabelNodeFromTemp(OwnershipGraph og,
+ TempDescriptor td) {
+ assert td != null;
+
+ if (!og.td2ln.containsKey(td)) {
+ og.td2ln.put(td, new LabelNode(td));
+ }
+
+ return og.td2ln.get(td);
+ }
+
+ public boolean equals(Object o) {
+ if (o == null) {
+ return false;
+ }
+
+ if (!(o instanceof MethodEffects)) {
+ return false;
+ }
+
+ MethodEffects in = (MethodEffects) o;
+
+ if (getEffects().equals(in.getEffects())) {
+ return true;
+ } else {
+ return false;
+ }
+
+ }
+
+ public int hashCode() {
+ int hash = 1;
+
+ hash += getEffects().hashCode() * 37;
+
+ return hash;
+ }
+
+}
private boolean writeAllDOTs;
//map each FlatNode to its own internal ownership graph
- private Hashtable<FlatNode, OwnershipGraph> mappingFlatNodeToOwnershipGraph;
+ private Hashtable<MethodContext, MethodEffects> mapMethodContextToMethodEffects;
mapHrnIdToAllocationSite =
new Hashtable<Integer, AllocationSite>();
- mappingFlatNodeToOwnershipGraph = new Hashtable<FlatNode, OwnershipGraph>();
+ mapMethodContextToMethodEffects = new Hashtable<MethodContext, MethodEffects>();
if( writeAllDOTs ) {
//System.out.println("Previsiting " + mc);
+ if(!mapMethodContextToMethodEffects.containsKey(mc)){
+ MethodEffects me=new MethodEffects();
+ mapMethodContextToMethodEffects.put(mc, me);
+ }
+
og = analyzeFlatNode(mc, fm, null, og);
setGraphForMethodContext(mc, og);
}
writeFinalContextGraphs();
}
+ writeMethodEffectsResult();
+
if( aliasFile != null ) {
if( state.TASK ) {
writeAllAliases(aliasFile, treport);
FlatNode fn,
HashSet<FlatReturnNode> setRetNodes,
OwnershipGraph og) throws java.io.IOException {
+
+ MethodEffects me=mapMethodContextToMethodEffects.get(mc);
TempDescriptor lhs;
TempDescriptor rhs;
if( !fld.getType().isImmutable() || fld.getType().isArray() ) {
og.assignTempXEqualToTempYFieldF(lhs, rhs, fld);
}
+
+ me.analyzeFlatFieldNode(og, rhs, fld);
+
break;
case FKind.FlatSetFieldNode:
if( !fld.getType().isImmutable() || fld.getType().isArray() ) {
og.assignTempXFieldFEqualToTempY(lhs, fld, rhs);
}
+
+ me.analyzeFlatSetFieldNode(og, lhs, fld);
+
break;
case FKind.FlatElementNode:
} else {
ogMergeOfAllPossibleCalleeResults.resolveMethodCall(fc, md.isStatic(), flatm, onlyPossibleCallee, mc, null);
}
+
+ if(!mapMethodContextToMethodEffects.containsKey(mcNew)){
+ MethodEffects meNew=new MethodEffects();
+ mapMethodContextToMethodEffects.put(mcNew, meNew);
+ }
+
+ MethodEffects meFlatCall=mapMethodContextToMethodEffects.get(mcNew);
+ me.analyzeFlatCall(ogMergeOfAllPossibleCalleeResults,fc,mc,meFlatCall);
+
} else {
// if the method descriptor is virtual, then there could be a
Set contexts = mapDescriptorToAllMethodContexts.get( md );
assert contexts != null;
contexts.add( mcNew );
-
+
+
+ if(!mapMethodContextToMethodEffects.containsKey(mcNew)){
+ MethodEffects meNew=new MethodEffects();
+ mapMethodContextToMethodEffects.put(mcNew, meNew);
+ }
+
+
addDependent( mc, mcNew );
OwnershipGraph ogPotentialCallee = mapMethodContextToCompleteOwnershipGraph.get( mcNew );
ogCopy.resolveMethodCall(fc, possibleMd.isStatic(), pflatm, ogPotentialCallee, mc, null);
}
+ MethodEffects meFlatCall=mapMethodContextToMethodEffects.get(mcNew);
+ meFlatCall.analyzeFlatCall(ogMergeOfAllPossibleCalleeResults,fc,mcNew,meFlatCall);
+
ogMergeOfAllPossibleCalleeResults.merge(ogCopy);
}
}
break;
}
- mappingFlatNodeToOwnershipGraph.put(fn, og);
-
+ setMethodEffectsForMethodContext(mc, me);
+
return og;
}
return fdElement;
}
+
+ private void setMethodEffectsForMethodContext(MethodContext mc, MethodEffects me){
+ mapMethodContextToMethodEffects.put(mc,me);
+ }
private void setGraphForMethodContext(MethodContext mc, OwnershipGraph og) {
}
}
+ public void writeMethodEffectsResult() throws IOException {
+
+ try {
+ BufferedWriter bw = new BufferedWriter(new FileWriter(
+ "MethodEffects_resport.txt"));
+
+ Set<MethodContext> mcSet = mapMethodContextToMethodEffects.keySet();
+ Iterator<MethodContext> mcIter = mcSet.iterator();
+ while (mcIter.hasNext()) {
+ MethodContext mc = mcIter.next();
+ MethodDescriptor md = (MethodDescriptor) mc.getDescriptor();
+
+ MethodEffects me = mapMethodContextToMethodEffects.get(mc);
+ EffectsSet effectsSet = me.getEffects();
+
+ bw.write("Method " + mc +"::"+mc.hashCode() + " :\n");
+ for (int i = 0; i < md.numParameters(); i++) {
+
+ String paramName = md.getParamName(i);
+
+ Set<EffectsKey> effectSet = effectsSet
+ .getReadingSet(i);
+ String keyStr = "{";
+ if (effectSet != null) {
+ Iterator<EffectsKey> effectIter = effectSet.iterator();
+ while (effectIter.hasNext()) {
+ EffectsKey key = effectIter.next();
+ keyStr += " " + key;
+ }
+ }
+ keyStr += "}";
+ bw.write(" Paramter " + paramName + " ReadingSet="
+ + keyStr + "\n");
+
+ effectSet = effectsSet.getWritingSet(new Integer(i));
+ keyStr = "{";
+ if (effectSet != null) {
+ Iterator<EffectsKey> effectIter = effectSet.iterator();
+ while (effectIter.hasNext()) {
+ EffectsKey key = effectIter.next();
+ keyStr += " " + key;
+ }
+ }
+
+ keyStr += "}";
+ bw.write(" Paramter " + paramName + " WritingngSet="
+ + keyStr + "\n");
+
+ }
+ bw.write("\n");
+
+ }
+
+ bw.close();
+ } catch (IOException e) {
+ System.err.println(e);
+ }
+
+ // Set entrySet = mapMethodContextToMethodEffects.entrySet();
+ // Iterator itr = entrySet.iterator();
+ // while( itr.hasNext() ) {
+ // Map.Entry me = (Map.Entry) itr.next();
+ // MethodContext mc = (MethodContext) me.getKey();
+ // MethodEffects og = (MethodEffects) me.getValue();
+ //
+ // try {
+ // og.writeGraph(mc, true, true, true, false, false);
+ // } catch( IOException e ) {}
+ // }
+ }
+
+
// return just the allocation site associated with one FlatNew node
private AllocationSite getAllocationSiteFromFlatNewPRIVATE(FlatNew fn) {
return s;
}
- public OwnershipGraph getMappingFlatNodeToOwnershipGraph(FlatNode fn) {
- return mappingFlatNodeToOwnershipGraph.get(fn);
- }