-
Notifications
You must be signed in to change notification settings - Fork 169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for graal native-image #115
Comments
I have not tried it with graal native images, I don't understand what the error in the linked issue means. Any help with deciphering it will be of great help. |
Thanks for the comment, @luben! I am waiting for advice on the native-image Slack channel, will keep this updated if I find anything that works. |
One thing you can try is extract the libzstd-jni for your architecutre from the jar and put it on your LD_LIBRARY_PATH, e.g. in /usr/local/lib - the java loader always try to fall-back to locally installed library. (your paths on mac can be different) |
Would be great if zstd-jni/src/main/java/com/github/luben/zstd/ZstdOutputStream.java Lines 15 to 17 in a4926bb
|
Hello @danielkec, would such a change allow for a workaround? I've since updated to version |
It's may be easy to replace the static |
I did that lazy loading when ZstdOutputStream is constructed and it seems to be working well, but my use case is limited to Kafka client needs. https://github.com/oracle/helidon/pull/2555/files#diff-e753f841f896d9d0153523f5980d3bac292135793c9eacfab8fe2a082c41665bR76-R92 |
Then I will make it lazy for all the non-static classes. This should cover most of the use-cases, though the |
@luben That would be super cool 👍 |
Discussed in #115 - it may help supporting Graal.
@danielkec , I have just released v1.4.7-1 and it moves the loading of the native library from the static sections to the constructors. Though it does not cover the |
Hmm, this breaks apache commons/compress. I will revert and release v1.4.7-2 and will explore independently. |
Hi, @luben is there a new update for this issue? Thank you. |
So the lazy loading didn't work. Another option that I can thing of is to let you load manually the native library and tell Edit: added it - a3b5c4c , can you test and see if it lets you workaround the loading issue? |
Warning: Could not resolve class com.github.luben.zstd.ZstdCompressCtx for reflection configuration. Reason: java.lang.ClassNotFoundException: com.github.luben.zstd.ZstdCompressCtx.
Warning: Could not resolve class com.github.luben.zstd.Zstd for reflection configuration. Reason: java.lang.ClassNotFoundException: com.github.luben.zstd.Zstd. |
I don't have any experience with GraalVM. I don't mind maintaining our own reachability data in the zstd-jni package, but I will need some help with the initial setup/version. |
|
|
BTW, the gradle build is just for the Android If I understand correctly, the metadata is needed if somebody uses runtime reflection. In the zstd-jni we don't use any reflection, so may be you are right that netty (if it reflects over zstd-jni classes) should declare its reflection targets. |
|
For runtime initialised, simply including the binary for the platform it's running on and declaring in If you're curious what that'd look like: [
{
"name": "com.github.luben.zstd.ZstdOutputStreamNoFinalizer",
"fields": [
{
"name": "dstPos"
},
{
"name": "srcPos"
}
]
},
{
"name": "com.github.luben.zstd.ZstdInputStreamNoFinalizer",
"fields": [
{
"name": "dstPos"
},
{
"name": "srcPos"
}
]
}
] Although, for build-time initialized, I've been working on reimplementing the JNI methods in Java for native-image use that only requires the system binary. Would there be any interest in upstreaming it and hooking it up with testing? |
@KJP12 I can proactively submit some necessary GraalVM metadata to https://github.com/oracle/graalvm-reachability-metadata , for Gradle there is an Agent integration of Native Build Tools to handle unit tests. I've never used sbt, could you provide a unit test for this part of the metadata? Or do you intend to submit a PR? |
I was thinking of maybe pushing the metadata here with a bit extra for not retaining the fields if the classes aren't reachable, since it'd probably be a decent place for that? Tho the central reachability repository should be fine too. I'm not really experienced with getting testing done with native image, so I am not sure if I can PR that in immediately. |
Hi, Sorry for the long delays on my side. I am open to PRs to add the metadata here. Having it in the https://github.com/oracle/graalvm-reachability-metadata will also work, please tag me if you send a PR there. Regarding bindings directly to libzstd - I think this will be a fine approach but we have to drop support for old JVMs as far as I can tell. If we do that we may refactor and cleanup the whole library as it has accumulated a lot of cruft due to mistakes, changes in libzstd, and the goal to keep backward compatibility. |
Same here! I'm willing to test whatever approaches might work. In the original reported issue I am using zstd through commons-compress, which adds an additional layer to consider. |
The method for Graal native-image using its C API wouldn't require any level of rewriting, beyond translating the JNI code to Java, or dropping support, just substitutions and calling APIs from there, which would not be active outside of native-image. If you feel it'd be best to rewrite it so that mistakes can be ironed out first, I could maintain it independently in the meantime. Panama is a different thing that would require more intervention tho, and given that there is no LTS JDK with it included, that would have to hold off for a bit longer. |
@KJP12 , thanks for clarifying, yes, I was thinking about Panama. I am open to get make it work seamlessly on Graal native. There are some mistakes, e.g. ZstdOutputStream vs ZstdOutputStreamNoFinalizer, but there is nothing major. I think the risk of rewrite from scratch would be greater than continue with the current structure. So if we can keep the backward compatibility, we don't need to rewrite. |
sdk use java 22.3.r17-grl
cd ./zstd-jni/
sdk install scala 2.13.10
./gradlew -Pagent clean test
./gradlew metadataCopy --task test --dir src/main/resources/META-INF/native-image/com.github.luben/zstd-jni/1.5.2-5 |
@linghengqian
|
[
{
"name": "com.github.luben.zstd.ZstdOutputStreamNoFinalizer",
"fields": [
{
"name": "dstPos"
},
{
"name": "srcPos"
}
]
},
{
"name": "com.github.luben.zstd.ZstdInputStreamNoFinalizer",
"fields": [
{
"name": "dstPos"
},
{
"name": "srcPos"
}
]
}
]
|
Sorry for the delay. I think it would be easier to write a few simple happy-path unit tests in Java and try to validate the GraalVM metadata with them. I am not sure what is the support for GraalVM in Scala. |
@luben I'm just curious, besides https://github.com/luben/ZstdAndroidExample , does |
There are javadocs: https://www.javadoc.io/doc/com.github.luben/zstd-jni/latest/com/github/luben/zstd/package-summary.html And if it's about writing tests, I think it would be easy to rewrite some of the Scala tests in Java |
|
Thanks a lot for your work! I put some comments on the PR - mostly how we can make the refection configs more generic so they could apply to other versions/OS-es |
|
@linghengqian, thanks a lot for your work! Let hope oracle/graalvm-reachability-metadata#121 is merged soon. |
|
it just got merged: oracle/graalvm-reachability-metadata#121 |
Closing as it is solved by oracle/graalvm-reachability-metadata#121 |
Thank you, @luben! I'll try to follow the advice above to solve my initial issue. |
Hello,
I am tracking a runtime error with zstd-jni when attempting to build a GraalVM native-image that includes
com.github.luben:zstd-jni:jar:1.4.4-7:runtime
as a dependency.heuermh/dishevelled-bio#24
I am still rather new to native-image, and may be missing some configuration or other obvious fix
https://github.com/oracle/graal/blob/master/substratevm/JNI.md
The text was updated successfully, but these errors were encountered: