Repository navigation
Call the C API v2 with the Foreign Function and Memory API on Java 25+ - #1029
Conversation
The build uses two JDKs now. JAVA_JNI (JDK 8+) compiles the driver, the JNI bindings and the tests, it is the JDK of JAVA_JNI_HOME, otherwise the JDK that CMake detects. JAVA_FFM (JDK 22+) compiles the FFM bindings, it is the JDK of JAVA_FFM_HOME, otherwise JAVA_JNI. The configuration fails when JAVA_FFM is older than JDK 22, so the jars without the FFM bindings are not built anymore. The JAVA22 names of the CMake files and of gen_ffm_native.py are renamed to JAVA_FFM, the names of the JDK 8+ part are renamed to JAVA_JNI. The FFM classes are compiled for the release of JAVA_FFM and are packed as META-INF/versions/<release>. Before this change javac used the release of the build JDK and jar always used 22, so the build failed with a JDK newer than 22. The FFM job of the CI checks the classes of JDK 25.
duckdb_jdbc_nolib_mr.jar is removed, duckdb_jdbc_nolib.jar and duckdb_jdbc.jar both have the FFM bindings now, as the classes of META-INF/versions/<version of JAVA_FFM>. The jar that has the JNI bindings only is an intermediate file of the build (java_jni/duckdb_jdbc_jni.jar), the tests and the FFM bindings are compiled against it. On a JDK that uses the FFM bindings the JNI ones can be selected with -Djdk.util.jar.enableMultiRelease=false. JAVA_FFM must be JDK 25 or later and must not be older than JAVA_JNI. javac is called without --release, so the class files have the version of the JDK that compiles them: a driver that is built with JDK 27 runs on JDK 27 and later only. Release builds use JDK 8 and JDK 25, CMake warns when JAVA_JNI is newer than 8 or JAVA_FFM is newer than 25. JAVA_FFM_HOME is kept in the CMake cache, so it is not required when a build directory is configured again.
The export lists were in conflict: the lists of main are taken and all the functions of the C API v2 are exported again with update_exports.py. The FFM bindings follow the changes of the JNI bindings of main. The new entry points are implemented: the value cast, the qualified names, the table and the column descriptions, the object cache, the encoding and the decoding of BIGNUM and the result sources of the Arrow export. The DECIMAL values that are wider than 38 digits and the BIGNUM values are read from their BIGNUM storage. The scan callbacks of the table functions are set on a data source, the C API has no such callbacks on a table function anymore. The Arrow export scans the chunks of the result with the __jdbc_arrow_result_scan function and does not copy them. DuckDBBindings and Capi of src/main/java22 are generated again, gen_ffm_native.py finds the method references of the Capi functions too.
The setup-jdk-corretto composite action downloads Amazon Corretto from its permanent URL with curl (HTTPS only, the certificates are verified), checks the SHA-256 checksum of the download against the checksum file of Corretto, sets the environment variable that is specified in its arguments (JAVA_HOME by default) to the home directory of the JDK and prints the version of the JDK. It does not change PATH. The jobs of Java.yml use this action instead of setup-java and of the JDK packages of the Docker images. All the builds use JDK 8 as JAVA_JNI_HOME and JDK 25 as JAVA_FFM_HOME, in the Docker builds the JDKs are mounted into the container (the JDKs for Alpine Linux in the musl builds). The tests run on JDK 8, the tests on the Linux hosts run on JDK 27 (JAVA_LATEST_HOME), the FFM tests on JDK 25, Spark on JDK 17 and Jepsen on JDK 21. The steps that run Java set PATH to the JDK that they use and print 'which java' and 'java -version'.
|
Just in case someone would like to try the FFM mode, snapshot binaries with this change included: <dependency>
<groupId>org.duckdb</groupId>
<artifactId>duckdb_jdbc</artifactId>
<version>2.1.0-dev-dc4c062</version>
</dependency><repository>
<id>duckdb</id>
<url>https://duckdb-staging.duckdb.org/duckdb/duckdb-java/maven/</url>
</repository>FFM support classes are packages in the same JAR files ( When the JAR is run on JDK 8 to 24 - then FFM classes are not loaded and the JNI mode is used with the same logic as before. It is also possible to use JNI mode on JDK 25+ by passing |
This is a continuation of the PR #1018