Javaagent – a complex but powerful instrumentation

If you go back again to metrics, you can find existing javaagents even if they are less numerous, since writing an agent is a bit more complicated.

A javaagent is a particular kind of the main method provided by the JVM that enables you to register ClassFileTransformer, which is a way to modify the classes' bytecode before they get loaded. In other words, you will write some code and compile it, but the JVM will never execute it. Instead, it will execute a rewritten version of the code.

We will not detail how to do it here. In fact, it is more complicated than writing an interceptor (you need to take care of the classloaders, write low-level bytecode with the ASM library or an equivalent, ...

Get Java EE 8 High Performance now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.