graalvm

Rick Suijkerbuijk 2022-09-19T08:09:44.906449Z

Hi everyone, We're currently trying to build a native image out of our clojure application but we're running into some bumps. If we build with native-image [ARGS] --initalize-at-build-time it works like a charm but we get the warning that --initalize-at-build-time will be deprecated in the future, so obviously we are trying to avoid using the global flag. However this raises a problem. We use clj-easy to manage the packages for build time initialization registry but that library wont register single segment packages which leaves us with the following problem:

[clj-easy/graal-build-time] WARN: Single segment package found for class: primitive_math__init.class. This class has no package and it will not be added to the result packages.
And causes the build to fail:
2 fatal errors detected:
Fatal error: org.graalvm.compiler.debug.GraalError: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: No instances of primitive_math$_LT__LT_ are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use --trace-object-instantiation=primitive_math$_LT__LT_.

Fatal error: org.graalvm.compiler.debug.GraalError: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: No instances of primitive_math$ns_wrapper$fn__6326 are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use --trace-object-instantiation=primitive_math$ns_wrapper$fn__6326.
Does anybody have an idea how to include primitive_math manually to --initalize-at-build-time ? We tried --initalize-at-build-time=primitive_math and some variations to it but with no success. Thanks in advance!

borkdude 2022-09-19T08:14:06.669619Z

@rick.suijkerbuijk Yes, use primitive-math from here: https://github.com/clj-commons/primitive-math/tree/master/src/clj_commons It now has a multi-segment namespace

Rick Suijkerbuijk 2022-09-19T08:14:57.494589Z

Forgot to mention, we do not use primitive-math ourselves but our lancaster library uses it which causes a cascading effect

borkdude 2022-09-19T08:15:18.641759Z

then upgrade primitive math in lancaster

Bart Kleijngeld 2022-09-19T08:20:13.067549Z

@borkdude Lancaster depends on the latest 1.0.0 version already

Bart Kleijngeld 2022-09-19T08:22:46.763019Z

(Also: if the version was the problem, I wouldn't understand why the global --initalize-at-build-time does work)

Bart Kleijngeld 2022-09-19T08:25:38.689499Z

(Oh, you mean upgrade to the version of the master branch perhaps?)

borkdude 2022-09-19T08:25:46.429689Z

If the Lancaster library still requires the single segment namespace that won't help. You need to avoid loading that

Rick Suijkerbuijk 2022-09-19T08:39:24.913249Z

but then the question how come the global --initalize-at-build-time manages to catch this and if you try to feed it by hand it wont register?

borkdude 2022-09-19T08:41:55.357279Z

Because you need to give it either class names or regexes and those assume a package name. Single segment namespaces compile to classes without packages

Rick Suijkerbuijk 2022-09-19T08:44:07.768549Z

so in other words there's nothing really to point to - manually, and the global flag just catches everything it comes across?

borkdude 2022-09-19T08:44:19.840349Z

One namespace compiles to many classes with unpredictable suffixes

borkdude 2022-09-19T08:44:30.518139Z

Yes

👍 1
Bart Kleijngeld 2022-09-19T08:45:45.621059Z

Ahh, right. So if we upgrade to the master version of primitive-math which has a multi-segment namespace, we can point to it manually?

borkdude 2022-09-19T08:56:01.690489Z

you don't need master, 1.0.0 has those multi-segment namespaces and if you use those rather than the single-segment one, you don't need to do anything manually

Bart Kleijngeld 2022-09-19T08:57:46.151469Z

Weird, since 1.0.0 is the version being used.

Bart Kleijngeld 2022-09-19T08:58:15.955159Z

[clj-easy/graal-build-time] WARN: Single segment package found for class: primitive_math__init.class. This class has no package and it will not be added to the result packages.
But the plugin still complains about the single segment package.

Bart Kleijngeld 2022-09-19T09:00:34.112989Z

I think my level of understanding of the basics is insufficient. Lancaster does use 1.0.0 (the one you claim is multi-segment). Or is the single namespace segment still accessible in that version (and are you then saying that perhaps Lancaster still uses that)?

borkdude 2022-09-19T09:01:59.284399Z

Yes it is. For backwards compatibility. You need to move manually to the multi-segment namespace, there is no magic here

Bart Kleijngeld 2022-09-19T09:02:34.989299Z

Alright, I finally understand why we seemed to be talking past one another. Thanks for clarifying

👍 1
igrishaev 2022-09-19T09:23:20.504019Z

Hi, can anyone give me a hint on charset for native image? When I run a binary file compiled, the default charset is US-ASCII, and all the non-english symbols sent to stdout/stderr appear as question marks. Is it possible to change the charset with an argument?

igrishaev 2022-09-19T09:27:51.445439Z

I’m using a binary file compiled from Clojure in a cloud service where interaction goes through stdout (response) and stderr (logs). At the moment, I can only use english characters which is a bit inconvenient sometimes.

borkdude 2022-09-19T09:35:48.386199Z

@igrishaev Have you tried -H:+AddAllCharsets ? https://www.graalvm.org/uploads/quick-references/native-image-quick-reference-v2_A4.pdf

igrishaev 2022-09-19T09:36:29.089789Z

Not yet, let me try…

igrishaev 2022-09-19T09:40:35.713929Z

I have global :jvm-opts ["-Dfile.encoding=UTF-8"] in my project.clj file, and -H:+AddAllCharsets in the args. Still, printing something like “Иван” gives ???? in the console

borkdude 2022-09-19T09:41:26.256389Z

Maybe you also have to provide that jvm option to native image during compilation

igrishaev 2022-09-19T09:41:26.711809Z

and (Charset/defaultCharset) returns US-ASCII

igrishaev 2022-09-19T09:44:58.191019Z

wow, -J-Dfile.encoding=UTF-8 had worked! Thanks!

👍 1