From: yeom Date: Thu, 24 Jun 2010 16:52:25 +0000 (+0000) Subject: changes. X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=e40a1fb73a2f722abe9a3644115d9bcf5a33a88e;p=IRC.git changes. --- diff --git a/Robust/src/Analysis/Disjoint/EffectSet.java b/Robust/src/Analysis/Disjoint/EffectSet.java new file mode 100644 index 00000000..cbddc2a3 --- /dev/null +++ b/Robust/src/Analysis/Disjoint/EffectSet.java @@ -0,0 +1,34 @@ +package Analysis.Disjoint; + +import java.util.HashSet; +import java.util.Hashtable; + +import IR.Flat.TempDescriptor; + +public class EffectSet { + + private Hashtable> methodEffectSet; + private Hashtable> rblockEffectSet; + + public EffectSet() { + methodEffectSet = new Hashtable>(); + } + + public void addMethodEffect(Integer paramIdx, Effect e) { + HashSet effectSet = methodEffectSet.get(paramIdx); + if (effectSet == null) { + effectSet = new HashSet(); + } + effectSet.add(e); + methodEffectSet.put(paramIdx, effectSet); + } + + public String toString() { + if (methodEffectSet != null) { + return methodEffectSet.toString(); + } else { + return rblockEffectSet.toString(); + } + } + +} diff --git a/Robust/src/Analysis/Disjoint/EffectsAnalysis.java b/Robust/src/Analysis/Disjoint/EffectsAnalysis.java index eaef2a76..043d6dde 100644 --- a/Robust/src/Analysis/Disjoint/EffectsAnalysis.java +++ b/Robust/src/Analysis/Disjoint/EffectsAnalysis.java @@ -1,17 +1,11 @@ package Analysis.Disjoint; -import java.io.BufferedWriter; -import java.io.FileWriter; -import java.io.IOException; import java.util.Hashtable; import java.util.Iterator; -import java.util.Set; import IR.FieldDescriptor; -import IR.MethodDescriptor; -import IR.TypeDescriptor; import IR.Flat.FlatCall; -import IR.Flat.FlatSetElementNode; +import IR.Flat.FlatMethod; import IR.Flat.TempDescriptor; ///////////////////////////////////////////// @@ -32,136 +26,157 @@ import IR.Flat.TempDescriptor; public class EffectsAnalysis { - //private Hashtable mapMethodContextToMethodEffects; - // boolean methodeffects = false; + private Hashtable mapFlatmethodToEffectset; - public EffectsAnalysis( boolean methodeffects ) { - //this.methodeffects = methodeffects; - //mapMethodContextToMethodEffects = new Hashtable(); + // private Hashtable + // mapMethodContextToMethodEffects; + // boolean methodeffects = false; + + public EffectsAnalysis(boolean methodeffects) { + mapFlatmethodToEffectset = new Hashtable(); + } + + public void analyzeFlatFieldNode(FlatMethod fmContaining, ReachGraph rg, TempDescriptor rhs, FieldDescriptor fld) { + + VariableNode vn = rg.td2vn.get(rhs); + + EffectSet effectSet = mapFlatmethodToEffectset.get(fmContaining); + if (effectSet == null) { + effectSet = new EffectSet(); + } + + for (Iterator iterator = vn.iteratorToReferencees(); iterator.hasNext();) { + RefEdge edge = iterator.next(); + TaintSet taintSet = edge.getTaints(); + AllocSite affectedAlloc = edge.getDst().getAllocSite(); + for (Iterator taintSetIter = taintSet.iterator(); taintSetIter.hasNext();) { + Taint taint = taintSetIter.next(); + +// Effect effect = new Effect(taint.getParamIndex(), taint.getAllocSite(), affectedAlloc, Effect.read, fld); +// effectSet.addMethodEffect(taint.getParamIndex(), effect); + + } + } + + mapFlatmethodToEffectset.put(fmContaining, effectSet); + + } + + public void analyzeFlatSetFieldNode(FlatMethod fmContaining, ReachGraph rg, TempDescriptor lhs, FieldDescriptor fld) { + + VariableNode vn = rg.td2vn.get(lhs); + + EffectSet effectSet = mapFlatmethodToEffectset.get(fmContaining); + if (effectSet == null) { + effectSet = new EffectSet(); + } + + for (Iterator iterator = vn.iteratorToReferencees(); iterator.hasNext();) { + RefEdge edge = iterator.next(); + TaintSet taintSet = edge.getTaints(); + AllocSite affectedAlloc = edge.getDst().getAllocSite(); + for (Iterator taintSetIter = taintSet.iterator(); taintSetIter.hasNext();) { + Taint taint = taintSetIter.next(); + +// Effect effect = new Effect(taint.getParamIndex(), taint.getAllocSite(), affectedAlloc, Effect.write, fld); +// effectSet.addMethodEffect(taint.getParamIndex(), effect); + + } + } + + mapFlatmethodToEffectset.put(fmContaining, effectSet); + + } + + public EffectSet getEffectSet(FlatMethod fm) { + return mapFlatmethodToEffectset.get(fm); } /* - public MethodEffects getMethodEffectsByMethodContext(MethodContext mc){ - return mapMethodContextToMethodEffects.get(mc); - } - - public void createNewMapping(MethodContext mcNew) { - if(!methodeffects) return; - if (!mapMethodContextToMethodEffects.containsKey(mcNew)) { - MethodEffects meNew = new MethodEffects(); - mapMethodContextToMethodEffects.put(mcNew, meNew); - } - } - */ + * public MethodEffects getMethodEffectsByMethodContext(MethodContext mc){ + * return mapMethodContextToMethodEffects.get(mc); } + * + * public void createNewMapping(MethodContext mcNew) { if(!methodeffects) + * return; if (!mapMethodContextToMethodEffects.containsKey(mcNew)) { + * MethodEffects meNew = new MethodEffects(); + * mapMethodContextToMethodEffects.put(mcNew, meNew); } } + */ /* - public void analyzeFlatCall(OwnershipGraph calleeOG, - MethodContext calleeMC, MethodContext callerMC, FlatCall fc) { - if(!methodeffects) return; - MethodEffects me = mapMethodContextToMethodEffects.get(callerMC); - MethodEffects meFlatCall = mapMethodContextToMethodEffects - .get(calleeMC); - me.analyzeFlatCall(calleeOG, fc, callerMC, meFlatCall); - mapMethodContextToMethodEffects.put(callerMC, me); - } - */ + * public void analyzeFlatCall(OwnershipGraph calleeOG, MethodContext + * calleeMC, MethodContext callerMC, FlatCall fc) { if(!methodeffects) return; + * MethodEffects me = mapMethodContextToMethodEffects.get(callerMC); + * MethodEffects meFlatCall = mapMethodContextToMethodEffects .get(calleeMC); + * me.analyzeFlatCall(calleeOG, fc, callerMC, meFlatCall); + * mapMethodContextToMethodEffects.put(callerMC, me); } + */ /* - public void analyzeFlatFieldNode(MethodContext mc, OwnershipGraph og, - TempDescriptor srcDesc, FieldDescriptor fieldDesc) { - if(!methodeffects) return; - MethodEffects me = mapMethodContextToMethodEffects.get(mc); - me.analyzeFlatFieldNode(og, srcDesc, fieldDesc); - mapMethodContextToMethodEffects.put(mc, me); - } - - public void analyzeFlatSetFieldNode(MethodContext mc, OwnershipGraph og, - TempDescriptor dstDesc, FieldDescriptor fieldDesc) { - if(!methodeffects) return; - MethodEffects me = mapMethodContextToMethodEffects.get(mc); - me.analyzeFlatSetFieldNode(og, dstDesc, fieldDesc); - mapMethodContextToMethodEffects.put(mc, me); - } - - public void analyzeFlatSetElementNode(MethodContext mc, OwnershipGraph og, - TempDescriptor dstDesc, FieldDescriptor fieldDesc) { - if(!methodeffects) return; - MethodEffects me = mapMethodContextToMethodEffects.get(mc); - me.analyzeFlatSetElementNode(og, dstDesc, fieldDesc); - mapMethodContextToMethodEffects.put(mc, me); - } - - public void analyzeFlatElementNode(MethodContext mc, OwnershipGraph og, - TempDescriptor dstDesc, FieldDescriptor fieldDesc) { - if(!methodeffects) return; - MethodEffects me = mapMethodContextToMethodEffects.get(mc); - me.analyzeFlatElementNode(og, dstDesc, fieldDesc); - mapMethodContextToMethodEffects.put(mc, me); - } - - - public void writeMethodEffectsResult() throws IOException { - - try { - BufferedWriter bw = new BufferedWriter(new FileWriter( - "MethodEffects_report.txt")); - - Set mcSet = mapMethodContextToMethodEffects.keySet(); - Iterator mcIter = mcSet.iterator(); - while (mcIter.hasNext()) { - MethodContext mc = mcIter.next(); - MethodDescriptor md = (MethodDescriptor) mc.getDescriptor(); - - int startIdx = 0; - if (!md.isStatic()) { - startIdx = 1; - } - - MethodEffects me = mapMethodContextToMethodEffects.get(mc); - EffectsSet effectsSet = me.getEffects(); - - bw.write("Method " + mc + " :\n"); - for (int i = startIdx; i < md.numParameters() + startIdx; i++) { - - String paramName = md.getParamName(i - startIdx); - - Set effectSet = effectsSet.getReadingSet(i); - String keyStr = "{"; - if (effectSet != null) { - Iterator 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 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); - } - - } - */ + * public void analyzeFlatFieldNode(MethodContext mc, OwnershipGraph og, + * TempDescriptor srcDesc, FieldDescriptor fieldDesc) { if(!methodeffects) + * return; MethodEffects me = mapMethodContextToMethodEffects.get(mc); + * me.analyzeFlatFieldNode(og, srcDesc, fieldDesc); + * mapMethodContextToMethodEffects.put(mc, me); } + * + * public void analyzeFlatSetFieldNode(MethodContext mc, OwnershipGraph og, + * TempDescriptor dstDesc, FieldDescriptor fieldDesc) { if(!methodeffects) + * return; MethodEffects me = mapMethodContextToMethodEffects.get(mc); + * me.analyzeFlatSetFieldNode(og, dstDesc, fieldDesc); + * mapMethodContextToMethodEffects.put(mc, me); } + * + * public void analyzeFlatSetElementNode(MethodContext mc, OwnershipGraph og, + * TempDescriptor dstDesc, FieldDescriptor fieldDesc) { if(!methodeffects) + * return; MethodEffects me = mapMethodContextToMethodEffects.get(mc); + * me.analyzeFlatSetElementNode(og, dstDesc, fieldDesc); + * mapMethodContextToMethodEffects.put(mc, me); } + * + * public void analyzeFlatElementNode(MethodContext mc, OwnershipGraph og, + * TempDescriptor dstDesc, FieldDescriptor fieldDesc) { if(!methodeffects) + * return; MethodEffects me = mapMethodContextToMethodEffects.get(mc); + * me.analyzeFlatElementNode(og, dstDesc, fieldDesc); + * mapMethodContextToMethodEffects.put(mc, me); } + * + * + * public void writeMethodEffectsResult() throws IOException { + * + * try { BufferedWriter bw = new BufferedWriter(new FileWriter( + * "MethodEffects_report.txt")); + * + * Set mcSet = mapMethodContextToMethodEffects.keySet(); + * Iterator mcIter = mcSet.iterator(); while (mcIter.hasNext()) + * { MethodContext mc = mcIter.next(); MethodDescriptor md = + * (MethodDescriptor) mc.getDescriptor(); + * + * int startIdx = 0; if (!md.isStatic()) { startIdx = 1; } + * + * MethodEffects me = mapMethodContextToMethodEffects.get(mc); EffectsSet + * effectsSet = me.getEffects(); + * + * bw.write("Method " + mc + " :\n"); for (int i = startIdx; i < + * md.numParameters() + startIdx; i++) { + * + * String paramName = md.getParamName(i - startIdx); + * + * Set effectSet = effectsSet.getReadingSet(i); String keyStr = + * "{"; if (effectSet != null) { Iterator 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 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); } + * + * } + */ }