guava
guava copied to clipboard
native-image support with Graal and native-image.properties
Consumers of Guava in a native-image built .jar would benefit from netty's approach with native-image.properties and org.graalvm.nativeimage.imagecode (see https://github.com/netty/netty/issues/8192 and https://github.com/netty/netty/pulls?q=is%3Apr+svm for what this entails).
The core issue is some parts of Guava use JDK features that are not compatible with GraalVM's native-image feature.
Some objectives:
- [ ]
native-image.propertiesfile is included in theMETA-INF/jarartifacts of Guava to be used bynative-image -jar user-shadow-jar.jarbuild pipeline. - [ ] Reflection, proxy and JNI configuration files included in the
META-INFand referenced by thenative-image.properties. - [ ] All of Guava can be initialized at build time using the
native-imageargument--initialize-at-build-time=com.google.
The biggest obstacle is some classes use native heap features which are not allowed for static initialization at build time. netty uses feature detection for this issue.
FAQ
Why is native-image valuable really?
Serverless applications and building Java applications for containers and mobile devices.
What are current workarounds?
- Static initialize only the specific Guava classes you need, and stop using the ones that are inherently incompatible. Usually the incompatibilities come from a transitive dependency on
Objectswhich has an emptystaticinitializer anyway. Repeatedly runnative-imageand add the classes it reports you need. - Avoid anything that does native heap allocation like the cache classes.
How can I make this about Google Cloud support for Java?
native-image support in Guava would make it easier to use a common Google Java library for serverless / cloud functions.
What is the reason why this issue is blocked?