Open
Description
This ticket summarizes the current status and next steps for Java agent support in Native Image.
Current status
At build time, bytecode transformation can be done by passing a Java agent to Native Image with -J-javaagent:agent.jar. Things to note:
- The agent is running and transforming all classes at build time.
- The premain of the agent is only executed at build time.
- The agent is currently marked as link-at-build-time so all of the classes need to be present in the agent jar.
- The agent should not touch the classes that are used by native-image itself, as this might interfere with the build or result in unpredictable behavior at run time. Instrumenting JDK classes should work to a large degree but there are a few pitfalls:
- Too complex instrumentation (e.g., introducing Java heap allocation or synchronization) may break the image build or execution at run-time (Native Image assumes for some JDK methods that they only contain trivial code).
- Native Image substitutes some JDK code with a custom implementation. Instrumenting such JDK code is not possible as the substitution takes precedence (i.e., it will look as if the JDK code was not instrumented).
Goals
- Simplify and improve agent support at build time:
- Explore removing the limitation of linking at build time
- Explore executing premain at runtime
- Explore limiting the scope of Native Image classes that the agent can transform
Non-goals
- Allowing agents to transform classes at runtime
Metadata
Metadata
Labels
Type
Projects
Status
In Progress