RFR: 6895: Agent Instrumentation fails to emit events when the instrumented class has a different/custom ClassLoader

Joshua Matsuoka jmatsuoka at openjdk.java.net
Tue Oct 27 14:28:26 UTC 2020


Hi,

This PR addresses JMC-6895, which made it so that the agent instrumentation would silently fail and not emit events when a class being instrumented was loaded by a custom classloader and its' methods were reflectively invoked.

The following is the sequence of events that caused this bug:

- When the class was initially loaded by the AppClassLoader the agent instruments it as we'd expect
- When the class was later loaded by the custom classloader, that classloader's loadClass call chain would lead to the agent being called to transform again
-- Since the transform had already been done once it was marked as complete and would not do anything
-- When the code for the class was later run, it would not emit the events due to a ClassNotFoundException on the injected event classes as they were not visible to the custom classloader

This patch resolves this and makes sure instrumentation is done with the custom classloader and that the event classes are visible to it. I've also included an integration test replicating the behavior that caused the bug.

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

Commit messages:
 - Merge remote-tracking branch 'upstream/master'
 - 6895: Agent Instrumentation fails to emit events when the instrumented class has a different/custom classloader

Changes: https://git.openjdk.java.net/jmc/pull/142/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jmc&pr=142&range=00
  Issue: https://bugs.openjdk.java.net/browse/JMC-6895
  Stats: 236 lines in 5 files changed: 223 ins; 9 del; 4 mod
  Patch: https://git.openjdk.java.net/jmc/pull/142.diff
  Fetch: git fetch https://git.openjdk.java.net/jmc pull/142/head:pull/142

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


More information about the jmc-dev mailing list