Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AOT for GraalVM 22 #283

Merged
merged 1 commit into from
Apr 2, 2024
Merged

Fix AOT for GraalVM 22 #283

merged 1 commit into from
Apr 2, 2024

Conversation

melix
Copy link
Collaborator

@melix melix commented Mar 29, 2024

This commit updates how Micronaut AOT generates code for GraalVM 22. In 22, the new default is to forbid build time initialization of classes. Each class which is initialized at build time has to be explicitly declared as such. This commit makes it so that classes we generate and know are initialized at build time are added to the --initialize-at-build-time option.

While this fixes a lot of cases, we cannot, unfortunately, kwow upfront all the dependencies of the types we initialize at build time, which may also need build time initialization. This means that in some cases, users will have to explicitly add some types to the list (e.g via a buildArg in the native binaries Gradle extension).

Ideally, we should move AOT off build time initialization. However, this is not currently doable, since precisely Micronaut Core and optimization registration is designed to use static fields. An option would be to use service loading instead, but it's a breaking change, and that would remove the ability to have a service loading optimization. While removing the service loading optimization may not be an issue for native, it is, however, a problem for JIT optimizations.

There's therefore no good solution that I'm aware of to this problem.

Note: this problem was unnoticed because we don't have tests which try to build a native image with AOT optimizations on latest GraalVM. It would be good to have such tests somewhere. /cc @fniephaus

This commit updates how Micronaut AOT generates code for GraalVM 22.
In 22, the new default is to forbid build time initialization of
classes. Each class which is initialized at build time has to be
explicitly declared as such. This commit makes it so that classes
we generate and know are initialized at build time are added to
the `--initialize-at-build-time` option.

While this fixes a lot of cases, we cannot, unfortunately, kwow
upfront all the dependencies of the types we initialize at build
time, which may _also_ need build time initialization. This means
that in some cases, users will have to explicitly add some types
to the list (e.g via a `buildArg` in the native binaries Gradle
extension).

Ideally, we should move AOT off build time initialization.
However, this is not currently doable, since precisely Micronaut
Core and optimization registration is designed to use static
fields. An option would be to use service loading instead, but
it's a breaking change, and that would remove the ability to
have a service loading optimization. While removing the service
loading optimization may not be an issue for native, it is,
however, a problem for JIT optimizations.

There's therefore no good solution that I'm aware of to this
problem.
@melix melix added the type: bug Something isn't working label Mar 29, 2024
@melix melix requested review from graemerocher and sdelamo March 29, 2024 17:18
@melix melix self-assigned this Mar 29, 2024
Copy link

@melix melix merged commit 7856eef into master Apr 2, 2024
11 checks passed
@melix melix deleted the cc/fix-graalvm-22 branch April 2, 2024 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants