[Wala-wala] Forward slicing static methods

77 views
Skip to first unread message

Pinzger, Martin

unread,
Sep 27, 2017, 4:11:23 AM9/27/17
to wala...@lists.sourceforge.net
Dear All,
I am using WALA 1.4.3, Java 1.8 to compute forward slices and found that static methods are excluded from the slices. I am using the following simplified source code:

AnalysisScope scope = AnalysisScopeReader.makeJavaBinaryAnalysisScope("out/test/classes/dummy", null);
DefaultExclusion.addDefaultExclusions(scope);
ClassHierarchy cha = ClassHierarchyFactory.make(scope);

Iterable<Entrypoint> entrypoints = getEntrypoint(cha); // add all methods of the dummy package
AnalysisOptions options = new AnalysisOptions(scope, entrypoints);
com.ibm.wala.ipa.callgraph.CallGraphBuilder cgb = Util.makeZeroOneContainerCFABuilder(options, new AnalysisCacheImpl(), cha, scope, null, null);
CallGraph cg = cgb.makeCallGraph(options, null);
PointerAnalysis pa = cgb.getPointerAnalysis();

Iterable<CGNode> entryPoint = findMethod(cg, "v", "()J");
Iterable<Statement> callsTo = findCallTo(entryPoint, "m");
Collection sliceForward;
for(Statement call : callsTo){
sliceForward = Slicer.computeForwardSlice(call, cg, pa, Slicer.DataDependenceOptions.FULL, Slicer.ControlDependenceOptions.FULL);
dumpSlice(sliceForward);
}

## The slices are computed on the following input

package dummy;
public class Testing {

public long v() throws InterruptedException {
long y = System.currentTimeMillis();
long tmp = y + 10;
long myI = m(y); // starting point for the forward slice
if (tmp > 10) {
myI += 5;
} else {
myI += 10;
}
return myI;
}

public static long m(long y) {
long lt = 10;
if (y >10) {
return lt + y;
}
return y;
}
}

## Observations and questions:
# If m() is declared static only the following output is generated:
NORMAL v:18 = invokestatic < Application, Ldummy/Testing, m(J)J > 11 @41 exception:17 Node: < Application, Ldummy/Testing, v()J > Context: Everywhere

# If I switch m() to a member method I obtain the full slice:
NORMAL v:18 = invokevirtual < Application, Ldummy/Testing, m(J)J > 1,11 @42 exception:17 Node: < Application, Ldummy/Testing, v()J > Context: Everywhere
NORMAL v:23 = binaryop(add) 18 , 22 Node: < Application, Ldummy/Testing, v()J > Context: Everywhere
NORMAL v:21 = binaryop(add) 18 , 12 Node: < Application, Ldummy/Testing, v()J > Context: Everywhere
NORMAL v:return 24 Node: < Application, Ldummy/Testing, v()J > Context: Everywhere
NORMAL m:5 = compare 2,4 opcode=cmp Node: < Application, Ldummy/Testing, m(J)J > Context: Everywhere
NORMAL m:conditional branch(le, to iindex=11) 5,6 Node: < Application, Ldummy/Testing, m(J)J > Context: Everywhere
NORMAL m:7 = binaryop(add) 4 , 2 Node: < Application, Ldummy/Testing, m(J)J > Context: Everywhere
NORMAL m:return 7 Node: < Application, Ldummy/Testing, m(J)J > Context: Everywhere


Why is the slice of the static m() not included? Did I miss something?

Thank you in advance for your support.

Best,
Martin

Martin Pinzger
Software Engineering Research Group
University of Klagenfurt



signature.asc

Manu Sridharan

unread,
Oct 15, 2017, 12:38:37 AM10/15/17
to wala...@lists.sourceforge.net
Hi Martin,

What kind of Statements does findCallTo return?  If you want to track statements that are data dependent on the result of the call, I think it should be returning NormalReturnCaller statements.  If it's just a NormalStatement wrapping the invoke I don't think it will work.  Does that fix the problem?  If I'm right, the reason you're seeing a different result with an invoke is actually due to unexpected control dependence; everything after the invocation is control-dependent on the invocation not throwing an NPE.

Let me know if this fixes the problem.  If it does, we should document it better (I ran into a similar problem a couple months back).

--Manu

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot_______________________________________________
Wala-wala mailing list
Wala...@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/wala-wala

Pinzger, Martin

unread,
Oct 16, 2017, 11:29:19 AM10/16/17
to WALA discussion and Q&A
Dear Manu,
thank you for your help. You are right, the findCallTo returns only a NormalStatement instead of a NormalReturnCaller. I updated this method and now it works. I will keep you posted should I run into more problems with slicing static methods.

Thanks a lot!

Best,
Martin

Martin Pinzger
Software Engineering Research Group
University of Klagenfurt



signature.asc
Reply all
Reply to author
Forward
0 new messages