RFR: 6246: Making the agent stop using Unsafe

Kangcheng Xu kxu at openjdk.java.net
Fri Jan 17 20:11:04 UTC 2020


On Fri, 17 Jan 2020 20:03:42 GMT, Marcus Hirt <hirt at openjdk.org> wrote:

>> This patch addresses [JMC-6246](https://bugs.openjdk.java.net/browse/JMC-6246).
>> 
>> The usage of `Unsafe.defineClass()` is replaced with:
>> - for pre-Java 9, reflective access on `ClassLoader.getSystemClassLoader().defineClass()`
>> - for Java 9 and later, `MethodHandles.Lookup.defineClass()`
>> 
>> Please note that `LookUp.defineClass()` can only define classes within the same package of the lookup. Therefore generated events classes will be in the dedicated package `org.openjdk.jmc.agent.generated_events`, instead of being in the same package of the instrumented class.
> 
> Doesn't this affect in which class loader the event classes are defined, and especially their unload behaviour?

In the case of reflective access, it's called directly on the system class loader. For `Lookup.defineClass`, the event class is defined on the class loader of the lookup, which in this case is the system class loader that loads `org.openjdk.jmc.agent.generated_events.Dummy`.

In both cases, events are defined with the system class loader, just like `Unsafe.defineClass`.

-------------

PR: https://git.openjdk.java.net/jmc/pull/35


More information about the jmc-dev mailing list