Inject Jacocoagent.jar into an already running jvm

46 views
Skip to first unread message

Jun Fu

unread,
Nov 23, 2022, 6:24:06 AM11/23/22
to JaCoCo and EclEmma Users
Hi guys,
Is it possible to dynamically inject Jacocoagent.jar into an already running jvm without restarting?such as injecting through agentmain?

Marc Hoffmann

unread,
Nov 23, 2022, 8:47:07 AM11/23/22
to JaCoCo and EclEmma Users
Hi,

this is not supported and there are no plans to do so. Depending on the instrumentation strategy the schema of the class files needs to be changed, which is not supported by the JVM,

Out of curiosity, what is your use case for this?

Regards,
-marc 

On 23. Nov 2022, at 12:24, Jun Fu <fuju...@gmail.com> wrote:

Hi guys,
Is it possible to dynamically inject Jacocoagent.jar into an already running jvm without restarting?such as injecting through agentmain?

--
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/a6399ba7-2a85-4eaa-aebc-79b0a8c50437n%40googlegroups.com.

Jun Fu

unread,
Nov 23, 2022, 9:41:40 PM11/23/22
to JaCoCo and EclEmma Users
Hi,

My case is,  I use a linux virtual machine with a docker installed. My springboot project is deployed in the docker and is running. I want to run local interface tests and get code coverage data of the springboot project.
As far as I know, I can use  '-javaagent:[yourpath/]jacocoagent.jar=[option1]=[value1],[option2]=[value2]'  to inject jacocoagent.jar into this docker,  but I need to modify the startup script of the docker container and
restart. Because this docker container will reset all additional actions every time it is updated and this springboot project interface will be called,so in order to reduce impact,I want to attach a running jvm without
restarting.

I'm not sure I have described the case clearly?

I learned that the agent.jar can be dynamically attached to a running java process through javaagent (agentmain),  that is,  the dynamic instrument after the JVM starts. When the class has been loaded,  it could  use
Instrumentation#retransformClasses to retransform the corresponding class. But it seems that jacoco does not support this now, so I don't know how to implement it.

Thanks.

Marc Hoffmann

unread,
Nov 29, 2022, 1:22:08 PM11/29/22
to JaCoCo and EclEmma Users
Hi,

it’s not only about the VM parameter, you also need the jacocoagent.jar file available in the docker container. This also holds true if you want to attach dynamically (which comes with other challenges when the JVM is running in a docker container).

The most robust solution will probably be if you create a docker image which includes the JaCoCo agent and has an option in its start script to enable the agent.

Cheers,
-marc

Jun Fu

unread,
Dec 2, 2022, 9:51:09 AM12/2/22
to JaCoCo and EclEmma Users
Hi,

yeah, we plan to still use the method of adding the ‘-javaagent‘ parameter to the docker container.

Thanks for your help!

Reply all
Reply to author
Forward
0 new messages