From: yeom Date: Wed, 7 Oct 2009 00:16:17 +0000 (+0000) Subject: changes to maintain strong update effects. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=73d400c748a2a35a863e53e95113fe7343a98120;p=IRC.git changes to maintain strong update effects. --- diff --git a/Robust/src/Analysis/MLP/MLPAnalysis.java b/Robust/src/Analysis/MLP/MLPAnalysis.java index 2f7afe22..be46e945 100644 --- a/Robust/src/Analysis/MLP/MLPAnalysis.java +++ b/Robust/src/Analysis/MLP/MLPAnalysis.java @@ -919,6 +919,33 @@ public class MLPAnalysis { parentWriteTable.put(td, parentEffectsSet); } + + Hashtable> strongUpdateTable = set + .getStrongUpdateTable(); + Hashtable> parentstrongUpdateTable = parent + .getSeseEffectsSet().getStrongUpdateTable(); + keys = strongUpdateTable.keySet(); + keyIter = keys.iterator(); + while (keyIter.hasNext()) { + TempDescriptor td = (TempDescriptor) keyIter.next(); + HashSet effectsSet = strongUpdateTable.get(td); + HashSet parentEffectsSet = parentstrongUpdateTable + .get(td); + if (parentEffectsSet == null) { + parentEffectsSet = new HashSet(); + } + + for (Iterator iterator = effectsSet.iterator(); iterator + .hasNext();) { + SESEEffectsKey seseKey = (SESEEffectsKey) iterator + .next(); + parentEffectsSet.add(new SESEEffectsKey(seseKey + .getFieldDescriptor(), seseKey + .getTypeDescriptor(), seseKey.getHRNId())); + } + + parentstrongUpdateTable.put(td, parentEffectsSet); + } } @@ -970,8 +997,29 @@ public class MLPAnalysis { while (edgeIter.hasNext()) { ReferenceEdge edge = edgeIter.next(); - if(edge.getTaintIdentifier()>0){ + if(edge.getTaintIdentifier()>0){ HeapRegionNode accessHRN = edge.getDst(); + /// follow the chain of reference to identify possible accesses + Iterator referIter=accessHRN.iteratorToReferencers(); + while (referIter.hasNext()) { + ReferenceEdge referEdge = (ReferenceEdge) referIter.next(); + + if (referEdge.getTaintIdentifier() > 0) { + HashSet referSet = new HashSet(); + followReference(accessHRN, referSet, new HashSet(), + currentSESE); + + Iterator referSetIter=referSet.iterator(); + while (referSetIter.hasNext()) { + TempDescriptor tempDescriptor = (TempDescriptor) referSetIter + .next(); + currentSESE.readEffects(tempDescriptor, field + .getSymbol(), src.getType(), accessHRN + .getID()); + } + } + } + /// affectedTDSet = getReferenceNodeSet(accessHRN); affectedIter = affectedTDSet.iterator(); while (affectedIter.hasNext()) { @@ -1007,6 +1055,27 @@ public class MLPAnalysis { LabelNode dstLN = og.td2ln.get(dst); if (dstLN != null) { + // check possible strong updates + boolean strongUpdate = false; + + if( !field.getType().isImmutable() || field.getType().isArray() ) { + Iterator itrXhrn = dstLN.iteratorToReferencees(); + while( itrXhrn.hasNext() ) { + ReferenceEdge edgeX = itrXhrn.next(); + HeapRegionNode hrnX = edgeX.getDst(); + + // we can do a strong update here if one of two cases holds + if( field != null && + field != OwnershipAnalysis.getArrayField( field.getType() ) && + ( (hrnX.getNumReferencers() == 1) || // case 1 + (hrnX.isSingleObject() && dstLN.getNumReferencees() == 1) // case 2 + ) + ) { + strongUpdate = true; + } + } + } + HashSet affectedTDSet = getAccessedTaintNodeSet(dstLN); Iterator affectedIter = affectedTDSet @@ -1025,7 +1094,7 @@ public class MLPAnalysis { if (field.getType().isImmutable()) { currentSESE.writeEffects(affectedTD, field .getSymbol(), dst.getType(), hrn - .getID()); + .getID(),strongUpdate); } else { Iterator referencers = hrn @@ -1038,7 +1107,7 @@ public class MLPAnalysis { currentSESE.writeEffects(affectedTD, field.getSymbol(), dst .getType(), - referenceEdge.getDst().getID()); + referenceEdge.getDst().getID(),strongUpdate); } } } @@ -1054,6 +1123,28 @@ public class MLPAnalysis { ReferenceEdge edge = edgeIter.next(); if (edge.getTaintIdentifier() > 0) { HeapRegionNode accessHRN = edge.getDst(); + /// follow the chain of reference to identify possible accesses + Iterator referIter=accessHRN.iteratorToReferencers(); + while (referIter.hasNext()) { + ReferenceEdge referEdge = (ReferenceEdge) referIter.next(); + + if (referEdge.getTaintIdentifier() > 0) { + HashSet referSet = new HashSet(); + followReference(accessHRN, referSet, new HashSet(), + currentSESE); + Iterator referSetIter=referSet.iterator(); + while (referSetIter.hasNext()) { + TempDescriptor tempDescriptor = (TempDescriptor) referSetIter + .next(); + currentSESE.writeEffects(tempDescriptor, field + .getSymbol(), dst.getType(), accessHRN + .getID(),strongUpdate); + } + + } + + } + /// affectedTDSet = getReferenceNodeSet(accessHRN); affectedIter = affectedTDSet.iterator(); while (affectedIter.hasNext()) { @@ -1068,7 +1159,7 @@ public class MLPAnalysis { HeapRegionNode hrn = hrnIter.next(); currentSESE.writeEffects(affectedTD, field .getSymbol(), dst.getType(), hrn - .getID()); + .getID(),strongUpdate); } @@ -1112,6 +1203,9 @@ public class MLPAnalysis { i + base); Set writeSet = me.getEffects().getWritingSet( i + base); + + Set strongUpdateSet = me.getEffects().getStrongUpdateSet( + i + base); LabelNode argLN = og.td2ln.get(arg); if (argLN != null) { @@ -1161,11 +1255,35 @@ public class MLPAnalysis { currentSESE.writeEffects(affectedTD, key.getFieldDescriptor(), key .getTypeDescriptor(), - hrnID); + hrnID,false); + } + + } + } + + if (strongUpdateSet != null) { + Iterator strongUpdateIter = strongUpdateSet + .iterator(); + while (strongUpdateIter.hasNext()) { + EffectsKey key = strongUpdateIter.next(); + + Set hrnSet = getCallerHRNId( + new Integer(i + base), calleeOG, + key.getHRNId(), decomp); + Iterator hrnIter = hrnSet + .iterator(); + while (hrnIter.hasNext()) { + Integer hrnID = (Integer) hrnIter + .next(); + currentSESE.writeEffects(affectedTD, + key.getFieldDescriptor(), key + .getTypeDescriptor(), + hrnID,true); } } } + } @@ -1181,6 +1299,29 @@ public class MLPAnalysis { } } + private void followReference(HeapRegionNode hrn,HashSet tdSet, HashSet visited, FlatSESEEnterNode currentSESE){ + + Iterator referIter=hrn.iteratorToReferencers(); + // check whether hrn is referenced by TD + while (referIter.hasNext()) { + ReferenceEdge referEdge = (ReferenceEdge) referIter.next(); + if(referEdge.getSrc() instanceof LabelNode){ + LabelNode ln=(LabelNode)referEdge.getSrc(); + if(currentSESE.getInVarSet().contains(ln.getTempDescriptor())){ + tdSet.add(ln.getTempDescriptor()); + } + }else if(referEdge.getSrc() instanceof HeapRegionNode){ + HeapRegionNode nextHRN=(HeapRegionNode)referEdge.getSrc(); + if(!visited.contains(nextHRN)){ + visited.add(nextHRN); + followReference(nextHRN,tdSet,visited,currentSESE); + } + + } + } + + } + private Set getCallerHRNId(Integer paramIdx, OwnershipGraph calleeOG, Integer calleeHRNId, ParameterDecomposition paramDecom) { diff --git a/Robust/src/Analysis/MLP/SESEEffectsSet.java b/Robust/src/Analysis/MLP/SESEEffectsSet.java index 395bcefd..be6500af 100644 --- a/Robust/src/Analysis/MLP/SESEEffectsSet.java +++ b/Robust/src/Analysis/MLP/SESEEffectsSet.java @@ -11,10 +11,12 @@ import IR.Flat.TempDescriptor; public class SESEEffectsSet { private Hashtable> readTable; private Hashtable> writeTable; + private Hashtable> strongUpdateTable; public SESEEffectsSet() { readTable = new Hashtable>(); writeTable = new Hashtable>(); + strongUpdateTable = new Hashtable>(); } public void addReadingVar(TempDescriptor td, SESEEffectsKey access) { @@ -62,6 +64,10 @@ public class SESEEffectsSet { public Hashtable> getWriteTable() { return writeTable; } + + public Hashtable> getStrongUpdateTable() { + return strongUpdateTable; + } public void addWritingVar(TempDescriptor td, SESEEffectsKey access) { HashSet aSet = writeTable.get(td); @@ -71,6 +77,15 @@ public class SESEEffectsSet { aSet.add(access); writeTable.put(td, aSet); } + + public void addStrongUpdateVar(TempDescriptor td, SESEEffectsKey access) { + HashSet aSet = strongUpdateTable.get(td); + if (aSet == null) { + aSet = new HashSet(); + } + aSet.add(access); + strongUpdateTable.put(td, aSet); + } public Set getReadingSet(TempDescriptor td) { return readTable.get(td); @@ -118,6 +133,23 @@ public class SESEEffectsSet { writer.write("Live-in Var " + td + " Write=" + keyStr+"\n"); } + keySet = strongUpdateTable.keySet(); + iter = keySet.iterator(); + while (iter.hasNext()) { + TempDescriptor td = iter.next(); + Set effectSet = strongUpdateTable.get(td); + String keyStr = "{"; + if (effectSet != null) { + Iterator effectIter = effectSet.iterator(); + while (effectIter.hasNext()) { + SESEEffectsKey key = effectIter.next(); + keyStr += " " + key; + } + } + keyStr+=" }"; + writer.write("Live-in Var " + td + " StrongUpdate=" + keyStr+"\n"); + } + return writer.toString(); } @@ -134,7 +166,8 @@ public class SESEEffectsSet { SESEEffectsSet in = (SESEEffectsSet) o; if (getReadTable().equals(in.getReadTable()) - && getWriteTable().equals(in.getWriteTable())) { + && getWriteTable().equals(in.getWriteTable()) + && getStrongUpdateTable().equals(in.getStrongUpdateTable())) { return true; } else { return false; @@ -145,7 +178,7 @@ public class SESEEffectsSet { public int hashCode() { int hash = 1; - hash += getReadTable().hashCode() + getWriteTable().hashCode() * 31; + hash += getReadTable().hashCode() + getWriteTable().hashCode() * 31 +getStrongUpdateTable().hashCode(); return hash; } diff --git a/Robust/src/Analysis/OwnershipAnalysis/EffectsSet.java b/Robust/src/Analysis/OwnershipAnalysis/EffectsSet.java index a53cb26c..63d6f238 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/EffectsSet.java +++ b/Robust/src/Analysis/OwnershipAnalysis/EffectsSet.java @@ -9,10 +9,12 @@ public class EffectsSet { private Hashtable> readTable; private Hashtable> writeTable; + private Hashtable> strongUpdateTable; public EffectsSet() { readTable = new Hashtable>(); writeTable = new Hashtable>(); + strongUpdateTable = new Hashtable>(); } public void addReadingVar(Integer idx, EffectsKey access) { @@ -50,6 +52,20 @@ public class EffectsSet { } } + + public void addStrongUpdateEffectsSet(Integer idx, HashSet newSet) { + + if (newSet != null) { + HashSet aSet = strongUpdateTable.get(idx); + if (aSet == null) { + aSet = new HashSet(); + } + aSet.addAll(newSet); + strongUpdateTable.put(idx, aSet); + } + + } + public Hashtable> getReadTable() { return readTable; @@ -58,6 +74,10 @@ public class EffectsSet { public Hashtable> getWriteTable() { return writeTable; } + + public Hashtable> getStrongUpdateTable() { + return strongUpdateTable; + } public void addWritingVar(Integer idx, EffectsKey access) { HashSet aSet = writeTable.get(idx); @@ -65,7 +85,16 @@ public class EffectsSet { aSet = new HashSet(); } aSet.add(access); - writeTable.put(idx, aSet); + writeTable.put(idx, aSet); + } + + public void addStrongUpdateVar(Integer idx, EffectsKey access) { + HashSet aSet = strongUpdateTable.get(idx); + if (aSet == null) { + aSet = new HashSet(); + } + aSet.add(access); + strongUpdateTable.put(idx, aSet); } public Set getReadingSet(Integer idx) { @@ -75,6 +104,10 @@ public class EffectsSet { public Set getWritingSet(Integer idx) { return writeTable.get(idx); } + + public Set getStrongUpdateSet(Integer idx) { + return strongUpdateTable.get(idx); + } public void printSet() { System.out.println("writeTable=>" + writeTable.hashCode()); @@ -130,7 +163,8 @@ public class EffectsSet { EffectsSet in = (EffectsSet) o; if (getReadTable().equals(in.getReadTable()) - && getWriteTable().equals(in.getWriteTable())) { + && getWriteTable().equals(in.getWriteTable()) + && getStrongUpdateTable().equals(in.getStrongUpdateTable())) { return true; } else { return false; @@ -141,7 +175,7 @@ public class EffectsSet { public int hashCode() { int hash = 1; - hash += getReadTable().hashCode() + getWriteTable().hashCode() * 31; + hash += getReadTable().hashCode() + getWriteTable().hashCode() * 31 + getStrongUpdateTable().hashCode(); return hash; } diff --git a/Robust/src/Analysis/OwnershipAnalysis/MethodEffects.java b/Robust/src/Analysis/OwnershipAnalysis/MethodEffects.java index 624443a4..cacb40af 100644 --- a/Robust/src/Analysis/OwnershipAnalysis/MethodEffects.java +++ b/Robust/src/Analysis/OwnershipAnalysis/MethodEffects.java @@ -71,6 +71,26 @@ public class MethodEffects { LabelNode ln = getLabelNodeFromTemp(og, dstDesc); if (ln != null) { + /// check possible strong updates + boolean strongUpdate = false; + if( !fieldDesc.getType().isImmutable() || fieldDesc.getType().isArray() ) { + Iterator itrXhrn = ln.iteratorToReferencees(); + while( itrXhrn.hasNext() ) { + ReferenceEdge edgeX = itrXhrn.next(); + HeapRegionNode hrnX = edgeX.getDst(); + + if( fieldDesc != null && + fieldDesc != OwnershipAnalysis.getArrayField( fieldDesc.getType() ) && + ( (hrnX.getNumReferencers() == 1) || // case 1 + (hrnX.isSingleObject() && ln.getNumReferencees() == 1) // case 2 + ) + ) { + strongUpdate = true; + } + } + } + //// + Iterator heapRegionsItr = ln.iteratorToReferencees(); while (heapRegionsItr.hasNext()) { @@ -88,6 +108,10 @@ public class MethodEffects { Integer paramID = paramIter.next(); effectsSet.addWritingVar(paramID, new EffectsKey( fieldDesc.getSymbol(), dstDesc.getType(),hrn.getID())); + if(strongUpdate){ + effectsSet.addStrongUpdateVar(paramID, new EffectsKey( + fieldDesc.getSymbol(), dstDesc.getType(),hrn.getID())); + } } } @@ -103,6 +127,10 @@ public class MethodEffects { Integer paramID = paramIter.next(); effectsSet.addWritingVar(paramID, new EffectsKey( fieldDesc.getSymbol(), dstDesc.getType(),hrn.getID())); + if(strongUpdate){ + effectsSet.addStrongUpdateVar(paramID, new EffectsKey( + fieldDesc.getSymbol(), dstDesc.getType(),hrn.getID())); + } } } @@ -193,6 +221,15 @@ public class MethodEffects { .getWriteTable().get(calleeParamIdx); effectsSet.addWritingEffectsSet(paramIdx, newSet); } + + // handle strong update effects + paramIter = paramIDs.iterator(); + while (paramIter.hasNext()) { + Integer paramIdx = paramIter.next(); + HashSet newSet = callee.getEffects() + .getStrongUpdateTable().get(calleeParamIdx); + effectsSet.addStrongUpdateEffectsSet(paramIdx, newSet); + } } diff --git a/Robust/src/IR/Flat/FlatSESEEnterNode.java b/Robust/src/IR/Flat/FlatSESEEnterNode.java index b8100d19..b2de4d12 100644 --- a/Robust/src/IR/Flat/FlatSESEEnterNode.java +++ b/Robust/src/IR/Flat/FlatSESEEnterNode.java @@ -337,8 +337,11 @@ public class FlatSESEEnterNode extends FlatNode { return 31*id; } - public void writeEffects(TempDescriptor td, String fd, TypeDescriptor type, Integer hrnId){ + public void writeEffects(TempDescriptor td, String fd, TypeDescriptor type, Integer hrnId, boolean strongUpdate){ seseEffectsSet.addWritingVar(td, new SESEEffectsKey(fd, type, hrnId)); + if(strongUpdate){ + seseEffectsSet.addStrongUpdateVar(td, new SESEEffectsKey(fd, type, hrnId)); + } } public void readEffects(TempDescriptor td, String fd, TypeDescriptor type, Integer hrnId ){