Fork me on GitHub
#graalvm
<
2021-07-13
>
Adam Helins10:07:52

Has anyone been able to use Hawk in a native image? I'm having a hard time going through all the reflection. Alternatively, is there another file watcher that plays nicely with native image AND allow to watch individual files?

borkdude10:07:29

@adam678 Babashka supports file watchers as pods

borkdude10:07:08

There are two of them: fswatcher (in golang) and filewatcher (in Rust)

borkdude10:07:25

Perhaps not exactly what you're looking for ;)

borkdude10:07:54

If you're looking to solve reflection issues you could take a look at https://github.com/borkdude/refl

Adam Helins11:07:42

Is it really a problem to have many false positive? Perf-wise?

borkdude11:07:05

Probably not, it will just bloat your binary a lot.

borkdude11:07:31

I don't like bloated binaries

Karol Wójcik11:07:28

Sometimes false positives will trigger warnings on GraalVM

borkdude11:07:04

if it's a reference to a class that can't be found yes. this can happen with the gensym-ed function symbols

Karol Wójcik11:07:29

Like aws-api generates tons of false spec, eval$fn positives.

Adam Helins12:07:52

@borkdude "But excluding all calls from `clojure.lang.RT` may be too coarse for some programs" Would you have an example? I am trying to better understand what is at stake and how to ensure that reflection is configured appropriately (as opposed to running the binary and seeing it fail at some point)

borkdude12:07:33

@adam678 Yes, e.g. when RT makes an array reflectively

👍 2
Adam Helins12:07:00

Has anyone ever encountered the following error stemming from the reflection config file when creating an image?

[build/native/app/run:27454]    classlist:   5,146.55 ms,  0.96 GB
[build/native/app/run:27454]        (cap):     962.60 ms,  0.96 GB
[build/native/app/run:27454]        setup:   1,949.40 ms,  0.96 GB
Error: Error parsing reflection configuration in /home/adam/projects/foo/clj/tool/foo/reflect-config.json:
Method java.lang.reflect.Method.canAccess(Object) not found. To allow unresolvable reflection configuration, use option -H:+AllowIncompleteClasspath
Verify that the configuration matches the schema described in the -H:PrintFlags=+ output for option ReflectionConfigurationFiles.
com.oracle.svm.core.util.UserError$UserException: Error parsing reflection configuration in /home/adam/projects/convex/clj/tool/foo/reflect-config.json:
Method java.lang.reflect.Method.canAccess(Object) not found. To allow unresolvable reflection configuration, use option -H:+AllowIncompleteClasspath
Adding -H:+AllowIncompleteClasspath seems to work (my binary seems to behave well) but it sounds scary and it still produces a warning when creating the image:
[build/native/app/run:27699]    classlist:   7,491.46 ms,  0.96 GB
[build/native/app/run:27699]        (cap):     818.44 ms,  0.96 GB
WARNING: Method java.lang.reflect.Method.canAccess(Object) not found.
[build/native/app/run:27699]        setup:   5,448.74 ms,  0.96 GB
...

borkdude12:07:28

@adam678 I don't recommend using that option. You have to fix your reflection config manually. See borkdude/refl. This is a bug in the native-image agent I think

borkdude12:07:32

You will need that method to allow Clojure itself to do reflection at runtime

borkdude12:07:59

it's a good default to always just add it

borkdude12:07:09

also see clj-graal-docs where we documented this

Karol Wójcik12:07:42

Also you seems to have a broken reflection config:

Error: Error parsing reflection configuration in /home/adam/projects/foo/clj/tool/foo/reflect-config.json

Adam Helins13:07:12

Thanks, it seems to work, and googling wasn't helping

Adam Helins13:07:43

In my case at least, agent was also adding an isVarArgs method to java.lang.reflect.Method, I simply removed it and kept canAccess