Recover Code Lines from Probes

33 views
Skip to first unread message

Tom G

unread,
Jul 10, 2022, 5:53:33 AM7/10/22
to JaCoCo and EclEmma Users
Hi,
if I have a probe boolean array and the name of the class. Is there some simple manual way to map a hit probe to the corresponding source line?

Regards,
Tom

Marc Hoffmann

unread,
Jul 10, 2022, 5:57:42 AM7/10/22
to JaCoCo and EclEmma Users
Hi Tom,

as “simple” as it is described here: https://www.jacoco.org/jacoco/trunk/doc/flow.html

In short: You need the underlying class files to interpret the probes. This is exactly what the JaCoCo analyzer does.

Regards,
-marc

--
You received this message because you are subscribed to the Google Groups "JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jacoco+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jacoco/bf8afb15-7adf-41f5-a854-5c92346c7d43n%40googlegroups.com.

Tom G

unread,
Jul 10, 2022, 6:27:50 AM7/10/22
to JaCoCo and EclEmma Users
Thanks for the quick response :)
Is it possible to recover it without relying on the class files?
E.g. if I only have the source code, theoretically, I know where the branches are (statically analyzing and identifying IFs, Switches, Exceptions, ...), then I also thereotically should know where the probes have been inserted right?

Marc Hoffmann

unread,
Jul 10, 2022, 9:16:53 AM7/10/22
to jac...@googlegroups.com
Is it possible to recover it without relying on the class files?

No, JaCoCo is based on class files.

E.g. if I only have the source code, theoretically, I know where the branches are (statically analyzing and identifying IFs, Switches, Exceptions, ...), then I also thereotically should know where the probes have been inserted right?

You can compile these class files given that you use the exact same build chain. Please see https://www.jacoco.org/jacoco/trunk/doc/classids.html

JaCoCo tracks execution with so called probes. Probes are additional byte code instructions inserted in the original class file which will note when they are executed and report this to the JaCoCo runtime. This process is called instrumentation. To keep the runtime overhead minimal, only a few probes are inserted at "strategic" places. These probe positions are determined by analyzing the control flow of all methods of a class. As a result every instrumented class produces a list of n boolean flags indicating whether the probe has been executed or not. A JaCoCo *.exec file simply stores a boolean array per class id.

At analysis time, for example for report generation, the *.exec file is used to get information about probe execution status. But as probes are stored in a plain boolean array there is no information like corresponding methods or lines. To retrieve this information we need the original class files and perform the exact same control flow analysis than at instrumentation time. Because this is a deterministic process we get the same probe positions. With this information we can now interfere the execution status of every single instruction and branch of a method. Using the debug information embedded in the class files we can also calculate line coverage.

If we would use just slightly different classes at analysis time than at runtime — e.g. different method ordering or additional branches — we would end-up with different probes. For example the probe at index i would be in method a() and not in method b(). Obviously this will create random coverage results. 



Reply all
Reply to author
Forward
0 new messages