|
From: Marcel B. <br...@st...> - 2008-10-24 16:59:05
|
Hi,
> I'd suggest you associate the protocol (method sequence) with the
> abstract object determined by pointer analysis, which is called an
> InstanceKey in WALA. That is, first perform a pointer analysis, and
> when you see a method call, update the state for the InstanceKeys
> which correspond to the receiver of the call
Thanks for the guidance. So far I can collect most of the information I
want to, but have a difficulty with uninitialized fields. For the same
sample as before no InstanceKey is returned by the PA.getPointsTo(PK)
for local variables that should point to an (uninitialized) field. Can
someone help out and give me a hint how I can get rid of these empty
PointsTo-sets for uninitialized fields (see code below)?
By the way another question:
I use a ContextSelector to limit the scope of the analysis by returning
an IllegalArgumentExceptionContext. Is this the intended way to limit
such an analysis?
Thanks and regards,
Marcel
== Current Code ==
private void findUsages(final IMethod method,
AnalysisScope scope) throws Exception {
Entrypoint e = new DefaultEntrypoint(method,
cha);
AnalysisCache cache = new AnalysisCache();
AnalysisOptions opts = new AnalysisOptions(
scope, Collections.singleton(e));
ContextSelector selector = new ContextSelector() {
@Override
public Context getCalleeTarget(
CGNode caller, CallSiteReference site,
IMethod callee, InstanceKey receiver) {
// limit the analysis to the given method only. All calls that
// go to another method should be blocked since we are searching
// for object protocols on a single method level only (yet).
if (callee == method) {
return Everywhere.EVERYWHERE;
}
// XXX is this valid to limit the pointer analysis this way is
// there another (standard) way we should use instead?
return new IllegalArgumentExceptionContext();
}
};
SSAPropagationCallGraphBuilder builder = Util
.makeVanillaZeroOneCFABuilder(
opts,
cache,
cha,
scope,
selector,
new DefaultSSAInterpreter(opts, cache));
CallGraph cg = builder.makeCallGraph(opts);
final PointerAnalysis pa = builder
.getPointerAnalysis();
final CGNode next = cg.getEntrypointNodes()
.iterator().next();
// == Data Collection ==
//
// collect all method calls invoked on per instance key level
final MultiSetMap<InstanceKey, SSAInvokeInstruction> protocols =
new MultiSetMap<InstanceKey, SSAInvokeInstruction>();
next.getIR().visitNormalInstructions(
new Visitor() {
@Override
public void visitInvoke(
SSAInvokeInstruction instruction) {
int receiver = instruction
.getReceiver();
PointerKey key = pa.getHeapModel()
.getPointerKeyForLocal(next,
receiver);
//
// XXX why does this return an empty set for (uninitialized
// fields?)
for (InstanceKey ik : pa
.getPointsToSet(key)) {
protocols.add(ik, instruction);
}
}
});
[...]
> === Sample ===
>
> public class Sample
> {
> private static Logger log;
>
> void log()
> {
> log.info(null);
> log.debug("");
> }
> }
|