[Soot-list] My Forward Analysis crashes when there is a loop in function

Ahmad Golzar golzara at cs.man.ac.uk
Wed Jul 30 20:38:28 EDT 2008


Hi,

I have implemented "Reaching Definitions" analysis using the data-flow
analysis framework in Soot. It works fine with functions that do not have
any loops in them, but crashes with any function that contains a loop. Here
is the code of the class. Have I done anything wrong? 

 

public class ReachingDefinitionsAnalysis extends ForwardFlowAnalysis

{

                private FlowSet emptySet;

                

                public ReachingDefinitionsAnalysis(DirectedGraph<Unit> g) {

                                super(g);                             

                                emptySet = new ArraySparseSet();

                                doAnalysis();

                }

                

                @Override

                protected void merge(Object in1, Object in2, Object out) {

                                FlowSet inSet1 = (FlowSet)in1,

                                                                inSet2 =
(FlowSet)in2,

                                                                outSet =
(FlowSet)out;

                                inSet1.union(inSet2, outSet);

                }

 

                @Override

                protected void copy(Object source, Object dest) {

                                FlowSet srcSet = (FlowSet)source,

                                                                destSet =
(FlowSet)dest;

                                srcSet.copy(destSet);

                }

                

                @Override

                protected Object newInitialFlow() {

                                return emptySet.clone();

                }

 

                @Override

                protected Object entryInitialFlow() {

                                return emptySet.clone();

                }

                

                @Override

                protected void flowThrough(Object in, Object node, Object
out) {

                                FlowSet inSet = (FlowSet)in,

                                                                outSet =
(FlowSet)out;

                                Unit u = (Unit)node;

                                kill(inSet, u, outSet);

                                gen(outSet, u);

                }

                

                private void kill(FlowSet inSet, Unit u, FlowSet outSet) {

                                FlowSet kills = (FlowSet)emptySet.clone();

                                Iterator<ValueBox> defIt =
u.getDefBoxes().iterator();

                                while (defIt.hasNext()) {

                                                ValueBox defBox =
defIt.next();

 

                                                if (defBox.getValue()
instanceof Local) {

 
Iterator<DependencyItem> inSetIt = inSet.iterator();

                                                                while
(inSetIt.hasNext()) {

 
DependencyItem e = inSetIt.next();

 
Local local = e.getLocal();

 
if (local.equivTo(defBox.getValue()))

 
kills.add(e);

                                                                }

                                                }

                                }

                                inSet.difference(kills, outSet);

                }

                

                private void gen(FlowSet outSet, Unit u) {

                                Iterator<ValueBox> useIt =
u.getDefBoxes().iterator();

                                

                                while (useIt.hasNext()) {

                                                ValueBox useBox =
useIt.next();

                                                if(useBox.getValue()
instanceof Local)

 
outSet.add(new DependencyItem(u, (Local)useBox.getValue()));

                                }

                }              

}

 

public class DependencyItem

{

                private Local local;

                private Unit unit;

                DependencyItem(Unit u, Local l)

                {

                                this.unit = u;

                                this.local = l;

                }

                

                public Local getLocal(){

                                return this.local;

                }

                

                public Unit getUnit()

                {

                                return this.unit;

                }

}

 

Thanks,

Ahmad

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.CS.McGill.CA/pipermail/soot-list/attachments/20080731/a6e70ef3/attachment-0001.htm


More information about the Soot-list mailing list