jdbi: Native image (GraalVM) compilation error
Trying to compile my project with jdbi usage into native image faced with following error:
Error: Unsupported features in methods
Detailed message:
Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Invoke with MethodHandle argument could not be reduced to at most a single call or single field access. The method handle must be a compile time constant, .g., be loaded from a `static final` field. Method that contains the method handle invocation: java.lang.invoke.MethodHandle.invokeBasic()
To enable method handles that do not require LambdaForm interpretation (e.g. because of a call to MethodHandle.bindTo()) or to diagnose the issue, you can add the option --report-unsupported-elements-at-runtime. The error is then reported at run time when the invoke is executed and the method handle has to be interpreted.
Trace:
at parsing java.lang.invoke.Invokers$Holder.invokeExact_MT(Invokers$Holder)
Call path from entry point to java.lang.invoke.Invokers$Holder.invokeExact_MT(Object, Object):
at java.lang.invoke.Invokers$Holder.invokeExact_MT(Invokers$Holder)
at org.jdbi.v3.core.config.ConfigRegistry.lambda$null$3(ConfigRegistry.java:100)
at org.jdbi.v3.core.config.ConfigRegistry$$Lambda$1041/0x00000007c2550440.apply(Unknown Source)
at org.jdbi.v3.core.internal.exceptions.Unchecked.lambda$function$4(Unchecked.java:76)
at org.jdbi.v3.core.internal.exceptions.Unchecked$$Lambda$1042/0x00000007c2550840.apply(Unknown Source)
at sun.security.ec.XECParameters$1.get(XECParameters.java:183)
at com.oracle.svm.core.jdk.SystemPropertiesSupport.initializeLazyValue(SystemPropertiesSupport.java:190)
at com.oracle.svm.core.jdk.SystemPropertiesSupport.getProperty(SystemPropertiesSupport.java:143)
at com.oracle.svm.core.jdk.Target_java_lang_System.getProperty(JavaLangSubstitutions.java:330)
at com.oracle.svm.jni.JNIJavaCallWrappers.jniInvoke_VARARGS:Ljava_lang_System_2_0002egetProperty_00028Ljava_lang_String_2_00029Ljava_lang_String_2(generated:0)
It will be very nice to have the ability to compile projects with jdbi usage into native images.
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 1
- Comments: 17 (8 by maintainers)
https://stackoverflow.com/questions/73022125/lambda-expression-classes-in-graalvm-reflection-configuration
Is there any progress on this specific issue?
I’ve been hacking a little bit on getting my jdbi/sqlite/kotlin setup to build and run using graalvm native-image and so far I have something that compiles and is able to make queries at runtime using version 3.28.0 of
jdbi3-kotlin,jdbi3-kotlin-sqlobject,jdbi3-sqlitecombined withorg.xerial:sqlite-jdbc:3.36.0.3.It mostly works by
org.jdbi.v3.core.,org.jdbi.v3.sqlobject,com.github.benmanes.cacheclasses toreflect-config.jsonproxy-config.jsonThis way it compiles and at runtime Jdbi can connect and make queries.
I’ve noticed the xerial-sqlite jar includes a
META-INF/native-image/folder that has the necessary native-image properties for the library. Is this something Jdbi wants to do as well?https://www.graalvm.org/22.0/reference-manual/native-image/BuildConfiguration/
After giving this a try again, now that Quarkus uses GraalVM 21 and therefore we have support for MethodHandles , I’m able to compile my application to a native executable. But still it doesn’t work.
It’s required to register all the classes used for reflection, i.e. all the classes that implement JdbiConfig but there are a lot more. I started a quarkus extension https://github.com/famartinrh/jdbi-quarkus-extension that should address all this kind of things, it’s not finished yet, and I may need help from someone who knows better the internals of jdbi and maybe a quarkus expert.
Just for now this describes the current status of the extension.