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

Support GraalVM JDK 21+ --strict-image-heap flag #10001

Merged
merged 2 commits into from
Oct 23, 2023

Conversation

graemerocher
Copy link
Contributor

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.

@graemerocher graemerocher added the type: improvement A minor improvement to an existing feature label Oct 20, 2023
@graemerocher
Copy link
Contributor Author

/cc @fniephaus

@fniephaus
Copy link

Maybe add --strict-image-heap to the argument list used for testing so that we see it's working? The latest patch release of GraalVM should give you a meaningful error if that is not the case.

@graemerocher
Copy link
Contributor Author

the dev builds will do that will they not?

@sonarcloud
Copy link

sonarcloud bot commented Oct 20, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

Copy link
Contributor

@sdelamo sdelamo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you target 4.2.x as base?

@graemerocher
Copy link
Contributor Author

IMO It makes sense it goes into 4.1.x as well because it is backwards compatible with old GraalVM

@graemerocher graemerocher merged commit 76efcd3 into 4.1.x Oct 23, 2023
10 checks passed
@graemerocher graemerocher deleted the graal-strict-image-heap branch October 23, 2023 09:56
@fniephaus
Copy link

the dev builds will do that will they not?

Yes, that is correct and probably the best solution. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: improvement A minor improvement to an existing feature
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants