clean up interface for creating a DemandRefinementPointsTo class, and make the internal ThisFilteringHeapModel package visible

git-svn-id: https://wala.svn.sourceforge.net/svnroot/wala/trunk@3827 f5eafffb-2e1d-0410-98e4-8ec43c5233c4
This commit is contained in:
msridhar1 2010-04-30 17:13:14 +00:00
parent f01fae7482
commit f76602dbfb
6 changed files with 46 additions and 31 deletions

View File

@ -48,7 +48,6 @@ import com.ibm.wala.classLoader.IClass;
import com.ibm.wala.classLoader.NewSiteReference;
import com.ibm.wala.core.tests.callGraph.CallGraphTestUtil;
import com.ibm.wala.demandpa.alg.DemandRefinementPointsTo;
import com.ibm.wala.demandpa.alg.ThisFilteringHeapModel;
import com.ibm.wala.demandpa.alg.statemachine.DummyStateMachine;
import com.ibm.wala.demandpa.alg.statemachine.StateMachineFactory;
import com.ibm.wala.demandpa.flowgraph.IFlowLabel;
@ -283,8 +282,7 @@ public abstract class AbstractPtrTest {
// MemoryAccessMap mam = new SimpleMemoryAccessMap(cg, cgBuilder.getPointerAnalysis().getHeapModel(), false);
MemoryAccessMap mam = new PABasedMemoryAccessMap(cg, cgBuilder.getPointerAnalysis());
SSAPropagationCallGraphBuilder builder = Util.makeVanillaZeroOneCFABuilder(options, analysisCache, cha, scope);
DemandRefinementPointsTo fullDemandPointsTo = new DemandRefinementPointsTo(cg, new ThisFilteringHeapModel(builder, cha), mam,
cha, options, getStateMachineFactory());
DemandRefinementPointsTo fullDemandPointsTo = DemandRefinementPointsTo.makeWithDefaultFlowGraph(cg, builder, mam, cha, options, getStateMachineFactory());
return fullDemandPointsTo;
}

View File

@ -41,7 +41,6 @@ import com.ibm.wala.core.tests.callGraph.CallGraphTestUtil;
import com.ibm.wala.core.tests.demandpa.TestInfo;
import com.ibm.wala.demandpa.alg.DemandRefinementPointsTo;
import com.ibm.wala.demandpa.alg.IDemandPointerAnalysis;
import com.ibm.wala.demandpa.alg.ThisFilteringHeapModel;
import com.ibm.wala.demandpa.alg.statemachine.DummyStateMachine;
import com.ibm.wala.demandpa.flowgraph.IFlowLabel;
import com.ibm.wala.demandpa.util.CallGraphMapUtil;
@ -219,8 +218,7 @@ public class CompareToZeroOneCFADriver {
CallGraph cg, MemoryAccessMap fam) {
SSAPropagationCallGraphBuilder builder = Util.makeVanillaZeroOneCFABuilder(options, new AnalysisCache(), cha, scope);
// return new TestNewGraphPointsTo(cg, builder, fam, cha, warnings);
DemandRefinementPointsTo fullDemandPointsTo = new DemandRefinementPointsTo(cg, new ThisFilteringHeapModel(builder,cha), fam, cha, options,
new DummyStateMachine.Factory<IFlowLabel>());
DemandRefinementPointsTo fullDemandPointsTo = DemandRefinementPointsTo.makeWithDefaultFlowGraph(cg, builder, fam, cha, options, new DummyStateMachine.Factory<IFlowLabel>());
// fullDemandPointsTo.setOnTheFly(true);
// fullDemandPointsTo.setRefineFields(true);
return fullDemandPointsTo;

View File

@ -42,7 +42,6 @@ import com.ibm.wala.core.tests.callGraph.CallGraphTestUtil;
import com.ibm.wala.core.tests.util.TestConstants;
import com.ibm.wala.demandpa.alg.ContextSensitiveStateMachine;
import com.ibm.wala.demandpa.alg.DemandRefinementPointsTo;
import com.ibm.wala.demandpa.alg.ThisFilteringHeapModel;
import com.ibm.wala.demandpa.alg.DemandRefinementPointsTo.PointsToResult;
import com.ibm.wala.demandpa.alg.refinepolicy.FieldRefinePolicy;
import com.ibm.wala.demandpa.alg.refinepolicy.ManualFieldPolicy;
@ -147,8 +146,7 @@ public class DemandCastChecker {
System.err.println("done");
System.err.println(CallGraphStats.getStats(cg));
MemoryAccessMap fam = new SimpleMemoryAccessMap(cg, cgAndPA.snd.getHeapModel(), false);
DemandRefinementPointsTo fullDemandPointsTo = new DemandRefinementPointsTo(cg, new ThisFilteringHeapModel(heapModel, cha), fam,
cha, options, makeStateMachineFactory());
DemandRefinementPointsTo fullDemandPointsTo = DemandRefinementPointsTo.makeWithDefaultFlowGraph(cg, heapModel, fam, cha, options, makeStateMachineFactory());
fullDemandPointsTo.setRefinementPolicyFactory(chooseRefinePolicyFactory(cha));
return fullDemandPointsTo;
}

View File

@ -40,7 +40,6 @@ import com.ibm.wala.core.tests.demandpa.TestInfo;
import com.ibm.wala.demandpa.alg.DemandRefinementPointsTo;
import com.ibm.wala.demandpa.alg.IDemandPointerAnalysis;
import com.ibm.wala.demandpa.alg.SimpleDemandPointsTo;
import com.ibm.wala.demandpa.alg.ThisFilteringHeapModel;
import com.ibm.wala.demandpa.alg.refinepolicy.AlwaysRefineCGPolicy;
import com.ibm.wala.demandpa.alg.refinepolicy.AlwaysRefineFieldsPolicy;
import com.ibm.wala.demandpa.alg.refinepolicy.SinglePassRefinementPolicy;
@ -155,8 +154,7 @@ public class TestAgainstSimpleDriver {
CallGraph cg, MemoryAccessMap fam) {
SSAPropagationCallGraphBuilder builder = Util.makeVanillaZeroOneCFABuilder(options, new AnalysisCache(), cha, scope);
// return new TestNewGraphPointsTo(cg, builder, fam, cha, warnings);
DemandRefinementPointsTo fullDemandPointsTo = new DemandRefinementPointsTo(cg, new ThisFilteringHeapModel(builder,cha), fam, cha, options,
new DummyStateMachine.Factory<IFlowLabel>());
DemandRefinementPointsTo fullDemandPointsTo = DemandRefinementPointsTo.makeWithDefaultFlowGraph(cg, builder, fam, cha, options, new DummyStateMachine.Factory<IFlowLabel>());
// fullDemandPointsTo.setCGRefinePolicy(new AlwaysRefineCGPolicy());
// fullDemandPointsTo.setFieldRefinePolicy(new AlwaysRefineFieldsPolicy());
fullDemandPointsTo.setRefinementPolicyFactory(new SinglePassRefinementPolicy.Factory(new AlwaysRefineFieldsPolicy(),

View File

@ -168,12 +168,7 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
return refinementPolicy;
}
public DemandRefinementPointsTo(CallGraph cg, ThisFilteringHeapModel model, MemoryAccessMap mam, IClassHierarchy cha,
AnalysisOptions options, StateMachineFactory<IFlowLabel> stateMachineFactory) {
this(cg, model, mam, cha, options, stateMachineFactory, new DemandPointerFlowGraph(cg, model, mam, cha));
}
public DemandRefinementPointsTo(CallGraph cg, ThisFilteringHeapModel model, MemoryAccessMap fam, IClassHierarchy cha,
private DemandRefinementPointsTo(CallGraph cg, ThisFilteringHeapModel model, MemoryAccessMap fam, IClassHierarchy cha,
AnalysisOptions options, StateMachineFactory<IFlowLabel> stateMachineFactory, IFlowGraph flowGraph) {
super(cg, model, fam, cha, options);
this.stateMachineFactory = stateMachineFactory;
@ -298,6 +293,34 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
return finalP2Set;
}
/**
* create a demand points-to analysis runner using a {@link DemandPointerFlowGraph} as the underlying flow graph.
*
* @see #make(CallGraph, HeapModel, MemoryAccessMap, IClassHierarchy, AnalysisOptions, StateMachineFactory, IFlowGraph)
*/
public static DemandRefinementPointsTo makeWithDefaultFlowGraph(CallGraph cg, HeapModel model, MemoryAccessMap mam,
IClassHierarchy cha, AnalysisOptions options, StateMachineFactory<IFlowLabel> stateMachineFactory) {
return make(cg, new ThisFilteringHeapModel(model, cha), mam, cha, options, stateMachineFactory, new DemandPointerFlowGraph(cg,
model, mam, cha));
}
/**
* create a demand points-to analysis runner
*
* @param cg the underlying call graph for the analysis
* @param model the heap model to be used for the analysis
* @param mam indicates what code reads or writes each field
* @param cha
* @param options
* @param stateMachineFactory factory for state machines to track additional properties like calling context
* @param flowGraph the underlying labelled graph data structure indicating data flow in each method
*/
public static DemandRefinementPointsTo make(CallGraph cg, HeapModel model, MemoryAccessMap mam, IClassHierarchy cha,
AnalysisOptions options, StateMachineFactory<IFlowLabel> stateMachineFactory, IFlowGraph flowGraph) {
return new DemandRefinementPointsTo(cg, new ThisFilteringHeapModel(model, cha), mam, cha, options, stateMachineFactory,
flowGraph);
}
private Pair<PointsToResult, Collection<InstanceKeyAndState>> outerRefinementLoop(PointerKeyAndState queried,
Predicate<InstanceKey> ikeyPred) {
Collection<InstanceKeyAndState> lastP2Set = null;
@ -588,7 +611,7 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
} else {
// new set size is >= lastP2Set, so don't update
// TODO what is wrong with this assertion?!? --MS
//assert removeStates(curFlowsToSet).containsAll(removeStates(lastFlowsToSet));
// assert removeStates(curFlowsToSet).containsAll(removeStates(lastFlowsToSet));
}
// TODO add predicate support
if (curFlowsToSet.isEmpty() /* || passesPred(curFlowsToSet, ikeyPred) */) {
@ -905,20 +928,20 @@ public class DemandRefinementPointsTo extends AbstractDemandPointsTo {
});
vals = tmp;
} else if (typeFilter instanceof MultipleClassesFilter) {
final MutableIntSet tmp = intSetFactory.make();
vals.foreach(new IntSetAction() {
final MutableIntSet tmp = intSetFactory.make();
vals.foreach(new IntSetAction() {
public void act(int x) {
InstanceKeyAndState ikAndState = ikAndStates.getMappedObject(x);
for (IClass t : ((MultipleClassesFilter)typeFilter).getConcreteTypes()) {
if (cha.isAssignableFrom(t, ikAndState.getInstanceKey().getConcreteType())) {
tmp.add(x);
}
public void act(int x) {
InstanceKeyAndState ikAndState = ikAndStates.getMappedObject(x);
for (IClass t : ((MultipleClassesFilter) typeFilter).getConcreteTypes()) {
if (cha.isAssignableFrom(t, ikAndState.getInstanceKey().getConcreteType())) {
tmp.add(x);
}
}
}
});
vals = tmp;
});
vals = tmp;
} else if (typeFilter instanceof SingleInstanceFilter) {
final InstanceKey theOnlyInstanceKey = ((SingleInstanceFilter) typeFilter).getInstance();
final MutableIntSet tmp = intSetFactory.make();

View File

@ -22,11 +22,11 @@ import com.ibm.wala.util.debug.Assertions;
* a {@link HeapModel} that delegates to another except for pointer keys representing <code>this</code> parameters of methods, for
* which it returns a {@link FilteredPointerKey} for the type of the parameter
*
* @see #getPointerKeyForLocal(CGNode, int)
* @see {@link DemandRefinementPointsTo}
* @author manu
*
*/
public class ThisFilteringHeapModel implements HeapModel {
class ThisFilteringHeapModel implements HeapModel {
private final HeapModel delegate;