Class AllocationInstrumenterBootstrap
In order to rewrite classes that are loaded by the bootstrap class loader to point to agent-provided instrumentation, the agent needs to be loaded by the bootstrap class loader.
There are three ways of doing this. The first requires that we add "Boot-Class-Path: <JAR file name>" to the agent's manifest. That only works when we know the exact name of the output JAR. That's not the case in various environments. For example, Maven-released JARs often bake a version number into their JAR names. The second is to add the JAR to the bootclasspath on the command line, but that's awful, as well as unsupported in Java 9.
The third is to use Instrumentation#appendToBootstrapClassLoaderSearch, which works as advertised. We can dynamically determine the name of the JAR containing this class (i.e., the agent), and then add that JAR to the bootstrap class path. The problem with this approach is that the agent's premain class is loaded prior to our ability to call that function, so it can't do the things we need the agent to be in the bootstrap class path to do. One workaround for this is to create a class that does nothing but call appendToBootstrapClassLoaderSearch on the agent's JAR file, and then calls into the real premain function (like the one below). Rather than replicating this class for every agent we might write, we use generated code.
This file is pre-processed to include the correct name of the class being used as a premain before being compiled and integrated into the agent.
-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
AllocationInstrumenterBootstrap
public AllocationInstrumenterBootstrap()
-
-
Method Details
-
premain
-