Description
While working on GraalVM native image support for the Spring Framework, we have noticed that we could really benefit from having the GraalVM native image agent automatically set the value of the org.graalvm.nativeimage.imagecode
JVM system property to agent
(or something similar).
The reason we need this is that we have certain code paths that get executed while running with the agent that will never be executed within a native image. Without such a flag available while running with the agent, the agent will generate native image configuration (e.g., in reflect-config.json
) that is inappropriate for the actual runtime behavior within a native image.
For example, in Spring's SerializableTypeWrapper
we have a check that avoids proxy creation for Serializable
. Although this check works as expected within a native image, when we execute this code path while running with the agent, the check will evaluate to false
, and consequently Spring will create a dynamic proxy that implements java.io.Serializable
which is not supported within a native image.
As a workaround, we are running the agent with -Dorg.graalvm.nativeimage.imagecode=agent
:
And we have modified our GraalVmDetector
utility class as follows.
This allows Spring to choose the correct code path (while running with the agent) that will be the actual code path executed within a native image.
In summary, we would be very grateful if the GraalVM native image agent would automatically set the value of the org.graalvm.nativeimage.imagecode
JVM system property to agent
(or something similar), and we are confident that other framework and application developers will also benefit from a standardized solution to this.