quarkus
quarkus copied to clipboard
Use conditional configuration for JNI, reflection, resources and proxies
Description
Upcoming GraalVM 21.3 version brings in conditional configuration for JNI, reflection, resources and proxy configuration. The only supported condition is that certain type is reachable. This configuration can also be applied programmatically.
Caffeine, Kubernetes Client and Postgresql JDK library are already taking advantage of something akin to this in their respective extensions. They're tapping directly into the reachability handler that powers conditional configuration.
All uses of JNI, reflection, resources and proxy configuration should move over to conditional configuration, to reduce the amount of configuration applied during image build time.
Caffeine, Kubernetes Client and Postgresql JDK library should also move over to this. As an example, here's the modifications done to the Caffeine extension to take advantage of conditional configuration: https://github.com/galderz/quarkus/commit/5f596024792e4a7a739ea77fc2b544d1acd9c1e2
Implementation ideas
No response
/cc @geoand, @iocanel
cc @zakkak
Please note that the corresponding API is new in 21.3 meaning that https://github.com/galderz/quarkus/commit/5f596024792e4a7a739ea77fc2b544d1acd9c1e2 breaks compatibility with 21.2 and 20.3. As a result, IMO we should first wait for Quarkus to move to 21.3 (expected in late October/early November) and drop support for 20.3 (expected in late October) before applying such changes (to avoid complicating things with version checks and reflection)
@galderz , /me eyeballing what we've got there these days:
30 @Override
31 public void beforeAnalysis(BeforeAnalysisAccess access) {
32 Class<?> caffeineCoreClazz = access.findClassByName("com.github.benmanes.caffeine.cache.Caffeine");
33 access.registerReachabilityHandler(this::ensureCaffeineSupportEnabled, caffeineCoreClazz);
34 }
35
36 private void ensureCaffeineSupportEnabled(DuringAnalysisAccess duringAnalysisAccess) {
37 final boolean needsEnablingYet = triggered.compareAndSet(false, true);
38 if (needsEnablingYet) {
39 if (log) {
40 System.out.println(
41 "Quarkus's automatic feature for GraalVM native images: enabling support for core Caffeine caches");
42 }
43 registerCaffeineReflections(duringAnalysisAccess);
44 }
45 }
I guess this is still pertinent?
Yes it is.
Closing this issue as there's no specific work to be done related to this.