"Using Pre-Instrumented Classes With the Java Agent": where it works &not works ??

699 views
Skip to first unread message

yajvane

unread,
Oct 17, 2016, 3:55:00 AM10/17/16
to JaCoCo and EclEmma Users
Hi,

As per the documentation available at http://www.eclemma.org/jacoco/trunk/doc/offline.html on "Using Pre-Instrumented Classes With the Java Agent' :

"It is possible to also use offline-instrumented classes with the JaCoCo Java agent. In this case the configuration is taken from the agent options. The agent must be configured in a way that pre-instrumented classes are excluded, e.g. with "excludes=*". Otherwise it will result in error messages on the console if the agent instruments such classes again."

I tried with couple of maven projects and able to see that this (pre-instrumented classes with jacoco-maven-plugin:prepare-agent test) is working fine. But, in some projects this is NOT working and throwing an exception "Caused by: java.lang.ClassNotFoundException: org.jacoco.agent.rt.internal_6da5971.Offline" (I was following on this exception on separate thread). 

Please help me in understanding this ! In what scenarios it works and not works !!! Would request to please elaborate on the phrase "It is possible..." 

I understand that offline instrumentation + placing jacocoagent.jar in class-path is the right way, but some how ., with whatever the possible maven (pom.xml) configuration ., that's always throwing exception. That's why trying to understand the things at more deeper level !!!

Thank you !!!

-Regards,
Kesav.

Marc R. Hoffmann

unread,
Oct 17, 2016, 7:44:28 AM10/17/16
to jac...@googlegroups.com
Hi,

the JaCoCo runtime needs to be accessible to by the executed classes. One option is to put it on the application classpath, another option is to configure the the JaCoC agent (all Java agents are added to classpath).

Typical pitfalls with offline instrumentations to check for:

1) The JaCoCo runtime must be the exact same version than the JaCoCo instrumentation tool.
2) The JaCoCo runtime classes must be visible to the classes under test from a classloading perspective. This is typically only the case for simple "main" applications. As soon as you run in containers (J2EE, OSGi etc.) the application classpath might not be visible to deployed components.

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/f85f8ef7-dbf6-4950-95d2-6d382e0995c6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

yajvane

unread,
Oct 19, 2016, 12:24:24 PM10/19/16
to JaCoCo and EclEmma Users
Hi Marc,

1] Able to add jacocoagent.jar (which was packed inside org.jacoco.agent-0.7.7.201606060606.jar) to class path & things went fine for a single project. "jacoco.exec" was getting generated. But, when I ran for a multi-module maven project., jacoco.exec was NOT getting generated for all modules. Only one of the module have the report got generated ( though configured jacoco-agent.properties with destfile and added that as part of class path !!!) . Any idea why jacocoagent.jar in classpath not able to generate jacoco.exec for all modules ??  

2] As jacoco.exec not getting generated for all modules while using jacocoagent.jar in classpath,  tried both classpath option as well as java agent option at same time. In this case, I am able to see all jacoco.exec's got generated. Any harm using both classpath/javaagent option at same time ??

-Best Regards,
Kesav.

Marc Hoffmann

unread,
Oct 19, 2016, 1:49:01 PM10/19/16
to jac...@googlegroups.com
Hi,

there is a difference between how jacocoagent.jar is used:

- Java agent: jacoco.exec is generated in any case, even if no
instrumented class is executed
- Classpath: jacoco.exec is only generated when a isntrumented class has
been executed.

Maybe this makes the difference in your case?

As I wrote before: If jacoco is configured as a Java agent it already
ends up on the classpath. No need to add it again.

Regards,
-marc

On 2016-10-19 18:24, yajvane wrote:
> Hi Marc,
>
> 1] Able to add jacocoagent.jar (which was packed inside
> org.jacoco.agent-0.7.7.201606060606.jar) to class path & things went
> fine for a single project. "jacoco.exec" was getting generated. But,
> when I ran for a multi-module maven project., jacoco.exec was NOT
> getting generated for all modules. Only one of the module have the
> report got generated ( though configured jacoco-agent.properties with
> destfile and added that as part of class path !!!) . Any idea why
> jacocoagent.jar in classpath not able to generate jacoco.exec for all
> modules ??
>
> 2] As jacoco.exec not getting generated for all modules while using
> jacocoagent.jar in classpath, TRIED BOTH CLASSPATH OPTION AS WELL AS
> JAVA AGENT OPTION AT SAME TIME. In this case, I am able to see all
> jacoco.exec's got generated. Any harm using both classpath/javaagent
> option at same time ??
>
> -Best Regards,
>
> Kesav.
> On Monday, October 17, 2016 at 5:14:28 PM UTC+5:30, Marc R. Hoffmann
> wrote:
>
>> Hi,
>>
>> the JaCoCo runtime needs to be accessible to by the executed
>> classes. One option is to put it on the application classpath,
>> another option is to configure the the JaCoC agent (all Java agents
>> are added to classpath).
>>
>> Typical pitfalls with offline instrumentations to check for:
>>
>> 1) The JaCoCo runtime must be the exact same version than the JaCoCo
>> instrumentation tool.
>> 2) The JaCoCo runtime classes must be visible to the classes under
>> test from a classloading perspective. This is typically only the
>> case for simple "main" applications. As soon as you run in
>> containers (J2EE, OSGi etc.) the application classpath might not be
>> visible to deployed components.
>>
>> Regards,
>> -marc
>>
>> On 17.10.16 09:55, yajvane wrote:
>>
>>> Hi,
>>>
>>> As per the documentation available at
>>> http://www.eclemma.org/jacoco/trunk/doc/offline.html [1] on "Using
>>> Pre-Instrumented Classes With the Java Agent' :
>>>
>>> "IT IS POSSIBLE to also use offline-instrumented classes with the
>>> JaCoCo Java agent. In this case the configuration is taken from
>>> the agent options. The agent must be configured in a way that
>>> pre-instrumented classes are excluded, e.g. with "excludes=*".
>>> Otherwise it will result in error messages on the console if the
>>> agent instruments such classes again."
>>>
>>> I tried with couple of maven projects and able to see that this
>>> (pre-instrumented classes with jacoco-maven-plugin:prepare-agent
>>> test) is working fine. But, in some projects this is NOT working
>>> and throwing an exception "Caused by:
>>> java.lang.ClassNotFoundException:
>>> org.jacoco.agent.rt.internal_6da5971.Offline" (I was following on
>>> this exception on separate thread).
>>>
>>> Please help me in understanding this ! In what scenarios it works
>>> and not works !!! Would request to please elaborate on the phrase
>>> "IT IS POSSIBLE..."
>>>
>>> I understand that offline instrumentation + placing
>>> jacocoagent.jar in class-path is the right way, but some how .,
>>> with whatever the possible maven (pom.xml) configuration ., that's
>>> always throwing exception. That's why trying to understand the
>>> things at more deeper level !!!
>>>
>>> Thank you !!!
>>>
>>> -Regards,
>>> Kesav. --
>>> 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/f85f8ef7-dbf6-4950-95d2-6d382e0995c6%40googlegroups.com
>>> [2].
>>> For more options, visit https://groups.google.com/d/optout [3].
>
> --
> 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/0185e389-36dd-49f3-bfe6-f3bb247df4d7%40googlegroups.com
> [4].
> For more options, visit https://groups.google.com/d/optout.
>
>
> Links:
> ------
> [1] http://www.eclemma.org/jacoco/trunk/doc/offline.html
> [2]
> https://groups.google.com/d/msgid/jacoco/f85f8ef7-dbf6-4950-95d2-6d382e0995c6%40googlegroups.com?utm_medium=email&utm_source=footer
> [3] https://groups.google.com/d/optout
> [4]
> https://groups.google.com/d/msgid/jacoco/0185e389-36dd-49f3-bfe6-f3bb247df4d7%40googlegroups.com?utm_medium=email&utm_source=footer

yajvane

unread,
Oct 20, 2016, 8:13:10 AM10/20/16
to JaCoCo and EclEmma Users
Hi Marc,

When I ran for a specific maven project independently , things work fine. Only when I trigger from parent pom., agent is NOT writing to file (only one project have the jacoco.exec got generated).
Finally after "mvn test" got completed., I see this exception on console.

java.nio.channels.OverlappingFileLockException
        at sun.nio.ch.SharedFileLockTable.checkList(FileLockTable.java:255)
        at sun.nio.ch.SharedFileLockTable.add(FileLockTable.java:152)
        at sun.nio.ch.FileChannelImpl.lock(FileChannelImpl.java:1030)
        at java.nio.channels.FileChannel.lock(FileChannel.java:1053)
        at org.jacoco.agent.rt.internal_6da5971.output.FileOutput.openFile(FileOutput.java:69)
        at org.jacoco.agent.rt.internal_6da5971.output.FileOutput.writeExecutionData(FileOutput.java:53)
        at org.jacoco.agent.rt.internal_6da5971.Agent.shutdown(Agent.java:137)
        at org.jacoco.agent.rt.internal_6da5971.Agent$1.run(Agent.java:54)

It looks this is related to writeExecutionData exception. May be jacoco.exec's are NOT getting generated because of this exception !!!  Do you think this is the reason ? In what cases this exception occur ??

-Regards,
Kesav.

Marc Hoffmann

unread,
Oct 21, 2016, 7:03:54 AM10/21/16
to jac...@googlegroups.com
Hi,

this typically happens if two JaCoCo runtimes are configured for the
same JVM.

Your maven build log should print the command line used to invoke java.
Please check that there is only one agent configured and that there is
no additional jacocoagent.jar on the classpath.

Regards,
-marc
>>>>> http://www.eclemma.org/jacoco/trunk/doc/offline.html [1] [1] on
>>> For more options, visit https://groups.google.com/d/optout [3].
>>>
>>>
>>> Links:
>>> ------
>>> [1] http://www.eclemma.org/jacoco/trunk/doc/offline.html [1]
>>> [2]
>>>
>>
> https://groups.google.com/d/msgid/jacoco/f85f8ef7-dbf6-4950-95d2-6d382e0995c6%40googlegroups.com?utm_medium=email&utm_source=footer
>> [5]
>>> [3] https://groups.google.com/d/optout [3]
>>> [4]
>>>
>>
> https://groups.google.com/d/msgid/jacoco/0185e389-36dd-49f3-bfe6-f3bb247df4d7%40googlegroups.com?utm_medium=email&utm_source=footer
>> [6]
>
> --
> 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/bed9bdc3-dce7-4ea7-8320-04aa822810ab%40googlegroups.com
> [7].
> [5]
> https://groups.google.com/d/msgid/jacoco/f85f8ef7-dbf6-4950-95d2-6d382e0995c6%40googlegroups.com?utm_medium=email&utm_source=footer
> [6]
> https://groups.google.com/d/msgid/jacoco/0185e389-36dd-49f3-bfe6-f3bb247df4d7%40googlegroups.com?utm_medium=email&utm_source=footer
> [7]
> https://groups.google.com/d/msgid/jacoco/bed9bdc3-dce7-4ea7-8320-04aa822810ab%40googlegroups.com?utm_medium=email&utm_source=footer
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages