AdoptOpenJDK / jitwatch

Log analyser / visualiser for Java HotSpot JIT compiler. Inspect inlining decisions, hot methods, bytecode, and assembly. View results in the JavaFX user interface.
Other
3.06k stars 437 forks source link

Issues when profiled classes are injected into java.lang #313

Closed nahsra closed 2 years ago

nahsra commented 4 years ago

I am profiling a Java agent which injects classes into java.lang. When I hit "Start" the process never finishes, and I see this in the log:

Exception in thread "Thread-8" java.lang.SecurityException: Prohibited package name: java.lang at java.lang.ClassLoader.preDefineClass(ClassLoader.java:662) at java.lang.ClassLoader.defineClass(ClassLoader.java:761) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) at java.net.URLClassLoader.access$100(URLClassLoader.java:73) at java.net.URLClassLoader$1.run(URLClassLoader.java:368) at java.net.URLClassLoader$1.run(URLClassLoader.java:362) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:361) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:763) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) at java.net.URLClassLoader.access$100(URLClassLoader.java:73) at java.net.URLClassLoader$1.run(URLClassLoader.java:368) at java.net.URLClassLoader$1.run(URLClassLoader.java:362) at java.security.AccessController.doPrivileged(Native Method)

I am guessing that it is the fact that I have injected some classes to java.lang, and added them to the config, which is causing this problem as someone is attempting to forcefully load those classes into the JVM.

Unfortunately these are incredibly hot calls (we instrument java.lang.String and other very hot paths) and so understanding their JIT impact in particular is very important to us.

I am running on commit adbea1d as I had issues with newer code on my Mac OSX / 1.8.0_161.

nahsra commented 4 years ago

It's worth noting this only happens when I add those classes to the Config -- but if I take them out of the config, I think I lose some analysis ability (I'm not an expert yet, but I freaking love this tool.)

chriswhocodes commented 4 years ago

Hi @nahsra, I think this is down to the way I use a classloader to load classes in order to discover their declared methods so I can visualise what was and wasn't JIT compiled in a class.

Looking back this wasn't such a great idea and in the post-JPMS world it's going to cause more problems with security / access permissions.

I have another project, not on GitHub yet, which is a fast classfile analyser which does not rely on classloading and reflection for discovery.

I'll see how much work it will be to finish that off and integrate it with JITWatch.

As long as the classes you are injecting exist as class files on disk then this should help with the problem you're encountering.

Cheers,

Chris

chriswhocodes commented 2 years ago

Hi, I'm closing all the issues except for the ones I'm actively working on.