Dynamic attach fails on tomcat (v9)

anton hägerstrand anton.hagerstrand at gmail.com
Sun Sep 20 20:46:20 UTC 2020


Hi! First and foremost, thanks for jol. It's an awesome tool.

I recently migrated an app to tomcat, jol seems to fail to do dynamic
attach. The error message/warning I get is "Dynamic Attach failed. You may
add this JAR as -javaagent manually, or supply
-Djdk.attach.allowAttachSelf", even though I have supplied
-Djdk.attach.allowAttachSelf.

I tried replicating the behavior a bit by creating my own version of the
InstrumentationSupport class in jol, just to do a simple print-out of the
actual errors that makes jol throw the dynamic attached failed exception.
These are the relevant parts of the stacktrace from my modified class, I
added a set of debug prints to the top but except for that it is the same
as the original.

java.lang.IllegalAccessException: class
org.openjdk.jol.vm.InstrumentationSupportTest cannot access a member of
class org.openjdk.jol.vm.InstrumentationSupportTest$Installer with
modifiers "public static volatile"
at
java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:361)
at
java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:591)
at java.base/java.lang.reflect.Field.checkAccess(Field.java:1075)
at java.base/java.lang.reflect.Field.get(Field.java:416)
at
org.openjdk.jol.vm.InstrumentationSupportTest.tryDynamicAttach(InstrumentationSupportTest.java:80)
at
org.openjdk.jol.vm.InstrumentationSupportTest.instance(InstrumentationSupportTest.java:43)
at
org.openjdk.jol.vm.InstrumentationSupportTest.tryInstance(InstrumentationSupportTest.java:31)

It seems to me like the issue is might be that jol is using the system
classloader to access the Installer subclass, since I package jol as a part
of my war-file, which would be using a different classloader?

If that is the case, which classloader should be used? I don't have any
particular knowledge about dynamic attach, does it require the system
classloader?

 I my explanation makes sense. I run tomcat version 9 and java 11, with jol
0.13.

Thanks
Anton


More information about the jol-dev mailing list