Javaagent attach issue for Java9+

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Javaagent attach issue for Java9+

Jean-Louis MONTEIRO
Hi,

This is a follow up of https://issues.apache.org/jira/browse/TOMEE-2619
When running on Java9+, the JVM does not allow anymore to attach an
instrumentation to the current JVM (self), unless you add the
flag -Djdk.attach.allowAttachSelf which is off by default.

So currently our javaagent required for OpenJPA for instance fail

> Caused by: java.io.IOException: Can not attach to current VM
>  at jdk.attach/sun.tools.attach.HotSpotVirtualMachine.<init>(HotSpotVirtualMachine.java:75)
>  at jdk.attach/sun.tools.attach.VirtualMachineImpl.<init>(VirtualMachineImpl.java:56)
>  at jdk.attach/sun.tools.attach.AttachProviderImpl.attachVirtualMachine(AttachProviderImpl.java:58)
>  at jdk.attach/com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:207)
>  ... 43 more
> INFO - JAVA AGENT NOT INSTALLED. The JPA Persistence Provider requested installation of a ClassFileTransformer which requires a JavaAgent.  See http://tomee.apache.org/javaagent.html
>
>
I looked at different options.
Of course short term, I'll go with adding the flag so we can focus on Java
11 support.
Long term, I'm wondering if we should have some trick like bytebuddy which
does a very good job. See discussion
https://github.com/raphw/byte-buddy/issues/295

and the agent attach code
https://github.com/raphw/byte-buddy/blob/master/byte-buddy-agent/src/main/java/net/bytebuddy/agent/ByteBuddyAgent.java#L659

What do you guys think?
Anyone willing to contribute that to TomEE?

ByteBuddy is ASL v2, so we can of course reuse some of its code.

--
Jean-Louis Monteiro
http://twitter.com/jlouismonteiro
http://www.tomitribe.com
   --
    Jean-Louis Monteiro
    http://twitter.com/jlouismonteiro
    http://www.tomitribe.com
Reply | Threaded
Open this post in threaded view
|

Re: Javaagent attach issue for Java9+

jgallimore
Adding the flag seems reasonable. Does the Bytebuddy-style workaround still
work for earlier Java versions?

Jon

On Thu, Aug 15, 2019 at 12:32 PM Jean-Louis Monteiro <
[hidden email]> wrote:

> Hi,
>
> This is a follow up of https://issues.apache.org/jira/browse/TOMEE-2619
> When running on Java9+, the JVM does not allow anymore to attach an
> instrumentation to the current JVM (self), unless you add the
> flag -Djdk.attach.allowAttachSelf which is off by default.
>
> So currently our javaagent required for OpenJPA for instance fail
>
> > Caused by: java.io.IOException: Can not attach to current VM
> >  at
> jdk.attach/sun.tools.attach.HotSpotVirtualMachine.<init>(HotSpotVirtualMachine.java:75)
> >  at
> jdk.attach/sun.tools.attach.VirtualMachineImpl.<init>(VirtualMachineImpl.java:56)
> >  at
> jdk.attach/sun.tools.attach.AttachProviderImpl.attachVirtualMachine(AttachProviderImpl.java:58)
> >  at
> jdk.attach/com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:207)
> >  ... 43 more
> > INFO - JAVA AGENT NOT INSTALLED. The JPA Persistence Provider requested
> installation of a ClassFileTransformer which requires a JavaAgent.  See
> http://tomee.apache.org/javaagent.html
> >
> >
> I looked at different options.
> Of course short term, I'll go with adding the flag so we can focus on Java
> 11 support.
> Long term, I'm wondering if we should have some trick like bytebuddy which
> does a very good job. See discussion
> https://github.com/raphw/byte-buddy/issues/295
>
> and the agent attach code
>
> https://github.com/raphw/byte-buddy/blob/master/byte-buddy-agent/src/main/java/net/bytebuddy/agent/ByteBuddyAgent.java#L659
>
> What do you guys think?
> Anyone willing to contribute that to TomEE?
>
> ByteBuddy is ASL v2, so we can of course reuse some of its code.
>
> --
> Jean-Louis Monteiro
> http://twitter.com/jlouismonteiro
> http://www.tomitribe.com
>
Reply | Threaded
Open this post in threaded view
|

Re: Javaagent attach issue for Java9+

Jean-Louis MONTEIRO
Yes it does work. If Java is 9+ then it uses a forked process to attach the
agent. If before then usual attach should work.

Le ven. 16 août 2019 à 14:46, Jonathan Gallimore <
[hidden email]> a écrit :

> Adding the flag seems reasonable. Does the Bytebuddy-style workaround still
> work for earlier Java versions?
>
> Jon
>
> On Thu, Aug 15, 2019 at 12:32 PM Jean-Louis Monteiro <
> [hidden email]> wrote:
>
> > Hi,
> >
> > This is a follow up of https://issues.apache.org/jira/browse/TOMEE-2619
> > When running on Java9+, the JVM does not allow anymore to attach an
> > instrumentation to the current JVM (self), unless you add the
> > flag -Djdk.attach.allowAttachSelf which is off by default.
> >
> > So currently our javaagent required for OpenJPA for instance fail
> >
> > > Caused by: java.io.IOException: Can not attach to current VM
> > >  at
> >
> jdk.attach/sun.tools.attach.HotSpotVirtualMachine.<init>(HotSpotVirtualMachine.java:75)
> > >  at
> >
> jdk.attach/sun.tools.attach.VirtualMachineImpl.<init>(VirtualMachineImpl.java:56)
> > >  at
> >
> jdk.attach/sun.tools.attach.AttachProviderImpl.attachVirtualMachine(AttachProviderImpl.java:58)
> > >  at
> >
> jdk.attach/com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:207)
> > >  ... 43 more
> > > INFO - JAVA AGENT NOT INSTALLED. The JPA Persistence Provider requested
> > installation of a ClassFileTransformer which requires a JavaAgent.  See
> > http://tomee.apache.org/javaagent.html
> > >
> > >
> > I looked at different options.
> > Of course short term, I'll go with adding the flag so we can focus on
> Java
> > 11 support.
> > Long term, I'm wondering if we should have some trick like bytebuddy
> which
> > does a very good job. See discussion
> > https://github.com/raphw/byte-buddy/issues/295
> >
> > and the agent attach code
> >
> >
> https://github.com/raphw/byte-buddy/blob/master/byte-buddy-agent/src/main/java/net/bytebuddy/agent/ByteBuddyAgent.java#L659
> >
> > What do you guys think?
> > Anyone willing to contribute that to TomEE?
> >
> > ByteBuddy is ASL v2, so we can of course reuse some of its code.
> >
> > --
> > Jean-Louis Monteiro
> > http://twitter.com/jlouismonteiro
> > http://www.tomitribe.com
> >
>
   --
    Jean-Louis Monteiro
    http://twitter.com/jlouismonteiro
    http://www.tomitribe.com