Support GraalVM JDK 21+ --strict-image-heap flag #10001
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In the next version of GraalVM
--strict-image-heap
will be the default which means that any objects stored in the image heap that are not primitive needs to be initialised at build time.Currently the only objects Micronaut initialises are build time is the annotation metadata. These can potentially have instantiated conditions (types that implement
io.micronaut.context.condition.Condition
) inside the annotation metadata. This is because@Requires(condition=..)
member is annotated with@InstantiatedMember
so that these instances are instantiated and stored in the metadata.This change alters our GraalVM feature so that these condition objects are marked for initialisation at build time and fixes GraalVM compilation when
--strict-image-heap
is specified. We already had restrictions in place that conditions cannot have constructor arguments. So another restriction that they can't have weird static initialisers that do IO/start threads etc. is not going to be an issue.A cursory search through existing conditions shows they none of them have any static initialisers so IMO this is a safe change to make in preparation for the next release of GraalVM.