-
Notifications
You must be signed in to change notification settings - Fork 38.4k
Replace build-time initialization by constant field evaluation at build-time #28624
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
Comments
Perhaps the |
@philwebb Could you please confirm that this build time initialization of classes is just required for class level |
@sdeleuze correct, that's just for class-level use. |
Leverage a subset of @philwebb https://github.com/philwebb/scratch-graal-conditions/tree/annotations to set the value of some boolean static field at build time for native images without leveraging class build-time initialization in order to avoid related compatibility issues. See spring-projectsgh-28624
Good news, I have been able to leverage the updated As soon as GraalVM team provides a builtin solution via the working group @bclozel and I have joined, it would replace this GraalVM feature. That's why I have preferred not introducing a new annotation like |
https://github.com/sdeleuze/build-time-constant-fields allows to test it works as expected. Not sure yet if/how we should integrate that in the CI, but probably good enough for this milestone to have such side repository to test the behavior. Logs printed during the native build allow to identify which fields are set to a constant value at build time. |
Leverage a subset of @philwebb https://github.com/philwebb/scratch-graal-conditions/tree/annotations to set the value of some boolean static field at build time for native images without leveraging class build-time initialization in order to avoid related compatibility issues. Closes spring-projectsgh-28624
As spring-projectsgh-28624 supports only static boolean fields, we still need a few classes to be initialized at build time. Such explicit configuration should be in theory avoidable, so we will work with the GraalVM team to see if this can be fixed, see for example oracle/graal#4673 for HttpStatus. See spring-projectsgh-28624
After this commit, KotlinDetector#kotlinPresent is computed at build time. See spring-projectsgh-28624
This is needed as GraalVM 22.2 enabled the module system when building native-images and all plugins have to participate in it. See spring-projectsgh-28624 Closes spring-projectsgh-28732
This commit makes ConstantFieldFeature compatible with GraalVM 22.2 while retaining GraalVM 22.1 compatibility. See spring-projectsgh-28624
This pattern is used in Spring Boot. See spring-projectsgh-28624
In order to compile to native images and to provide a reasonable footprint, we are currently forced to initialize classes containing
ClassUtils#isPresent
checks at build time. A meaningful concrete example of that requirement is provided by Spring MVC support that does not compile unless a few classes are initialized at build time, see 2b76a12.The drawback is that this build time init of
WebMvcConfigurationSupport
andRestTemplate
forces to initialize transitively all classes used in static fields/blocks at build time as well :ClassUtils
,SpringProperties
,ConcurrentReferenceHashMap
. Worse : for other classes with similar pattern, if they contain a static loggers, this will force to initialize Logback at build time which is a dead end in term of compatibility as shown multiple times in Spring Native.We are working on a middle-long term solution with GraalVM to replace build time init by another mechanism, less viral, with less compatibility issues. But for time being, we need to find a solution to this issue.
A pragmatic solution would be isolate classpath checks in a per module (
spring-core
,spring-web
) class that would be itself init at build time but with no other purpose, removing the risk of viral expension of the classes init at build time. If we take theWebMvcConfigurationSupport
use case, we would have something like:Bonus point, I think I like the fact that we provide reusable methods for classpath checks without arbitrary
String
parameter.Implementation would potentially even not use
ClassUtils
to limit the classes init at build time (not sure what is would use instead, to be discussed, not a blocking point).Any thoughts @jhoeller @snicoll @bclozel?
The text was updated successfully, but these errors were encountered: