xtdb / xtdb

An immutable database for application development and time-travel data compliance, with SQL and XTQL. Developed by @juxt
https://xtdb.com
Mozilla Public License 2.0
2.5k stars 162 forks source link

Graal Native Image Support #158

Open hraberg opened 5 years ago

hraberg commented 5 years ago

We want crux.main.graal to delegate to crux.bootstrap.cli like the normal crux.main namespace. This is currently blocked by this issue which stops Kafka clients from being used inside a native image: https://github.com/oracle/graal/issues/532

We should track this issue and check new releases of Graal and see if we can move crux.main.graal to do the right thing.

hraberg commented 5 years ago

Related to #155.

hraberg commented 5 years ago

For reference, if someone else decided to look at this, there's a script to build the native image here: dev/build-graal-native-image.sh

hraberg commented 5 years ago

For reference: https://github.com/oracle/graal/blob/master/substratevm/LIMITATIONS.md

hraberg commented 5 years ago

Also, we currently use Clojure 1.9 in the Graal profile. This due to this Clojure bug: https://dev.clojure.org/jira/browse/CLJ-1472

This bug is in 1.9 as well, but that version of spec doesn't use the locking macro, which is where the bug arises. When this ticket is fixed we can move the Graal profile to 1.10. The real fix will be in Clojure, but a potential fix might turn up in spec which circumvents it.

A potential alternative is to downgrade spec to the version in 1.9, but there might be other issues with that.

hraberg commented 5 years ago

Also worth noting that Graal itself is currently a 1.8 based JVM.

hraberg commented 5 years ago

As JNR doesn't work in the native image, we could consider cutting out JNI (and JNR) entirely and use theorg.graalvm.nativeimage.c which is only available inside the native image to call C directly from Java.

This blog post and repository is the best example: https://cornerwings.github.io/2018/07/graal-native-methods/ https://github.com/cornerwings/graal-native-interaction

It's somewhat documented by this test: https://github.com/oracle/graal/blob/master/substratevm/src/com.oracle.svm.tutorial/src/com/oracle/svm/tutorial/CInterfaceTutorial.java

The JavaDocs are here: http://www.graalvm.org/sdk/javadoc/

The graal profile would need this dependency (or later): [org.graalvm.sdk/graal-sdk "1.0.0-rc12"]

refset commented 5 years ago

Graal has moved on slightly since it's latest big release so our use of it will have to be updated.

gklijs commented 5 years ago

With quarkus it's possible to have a navive compiled kafka client, I'm not sure how easy this can be integrated with Clojure https://quarkus.io/guides/kafka-guide