Skip to content

[GR-55707] Java Agents Support in Native Image #8177

Open
@alina-yur

Description

@alina-yur

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

Non-goals

  • Allowing agents to transform classes at runtime

Metadata

Metadata

Type

No type

Projects

Status

In Progress

Relationships

None yet

Development

No branches or pull requests

Issue actions