RFR: 6246: Making the agent stop using Unsafe

Kangcheng Xu kxu at openjdk.java.net
Fri Jan 17 19:35:22 UTC 2020

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.


 - 3c26203d: remove unsafe related helpers functions
 - bf895935: make agent stop using Unsafe

Changes: https://git.openjdk.java.net/jmc/pull/35/files
 Webrev: https://webrevs.openjdk.java.net/jmc/35/webrev.00
  Issue: https://bugs.openjdk.java.net/browse/JMC-6246
  Stats: 102 lines in 5 files changed: 36 ins; 58 del; 8 mod
  Patch: https://git.openjdk.java.net/jmc/pull/35.diff
  Fetch: git fetch https://git.openjdk.java.net/jmc pull/35/head:pull/35

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

More information about the jmc-dev mailing list