graalvm

Discuss GraalVM related topics. Use clojure 1.10.2 or newer for all new projects. Contribute to https://github.com/clj-easy/graal-docs and https://github.com/BrunoBonacci/graalvm-clojure. GraalVM slack: https://www.graalvm.org/slack-invitation/.
Kamuela 2020-07-04T11:28:03.039Z

Trying to compile a helloworld with https://github.com/taylorwood/lein-native-image and get

Error: Could not find or load main class graal_thing.core
Caused by: java.lang.ClassNotFoundException: graal_thing.core
after what appears to be a successful lein native-image

borkdude 2020-07-04T11:29:54.039500Z

@kamuela Have you used :gen-class in your main namespace?

Kamuela 2020-07-04T11:30:43.039700Z

@borkdude

borkdude 2020-07-04T11:31:13.040200Z

have you specified the main ns in project.clj?

Kamuela 2020-07-04T11:32:08.040800Z

Hmm, I created this with lein new app but

(defproject graal-thing "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "<http://example.com/FIXME>"
  :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
            :url "<https://www.eclipse.org/legal/epl-2.0/>"}
  :dependencies [[org.clojure/clojure "1.10.2-alpha1"]]
  :main ^:skip-aot graal-thing.core
  :target-path "target/%s"
  :profiles {:uberjar {:aot :all}}
  :plugins [[io.taylorwood/lein-native-image "0.3.1"]])

Kamuela 2020-07-04T11:32:52.041Z

I think that line does what you've asked

Kamuela 2020-07-04T11:33:25.041300Z

And for further reference

➜  graal-thing lein run
OpenJDK 64-Bit Server VM warning: forcing TieredStopAtLevel to full optimization because JVMCI is enabled
OpenJDK 64-Bit Server VM warning: forcing TieredStopAtLevel to full optimization because JVMCI is enabled
PING!
PONG!

Kamuela 2020-07-04T11:35:44.041700Z

I do just realize there are some warnings when I run lein native-image

Kamuela 2020-07-04T11:36:38.041900Z

➜  graal-thing lein native-image                                                                
OpenJDK 64-Bit Server VM warning: forcing TieredStopAtLevel to full optimization because JVMCI is enabled
OpenJDK 64-Bit Server VM warning: forcing TieredStopAtLevel to full optimization because JVMCI is enabled
Compiling graal-thing.core
Build on Server(pid: 58122, port: 50139)
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122]    classlist:     878.30 ms,  2.62 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122]        (cap):   1,905.34 ms,  2.62 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122]        setup:   2,186.43 ms,  2.62 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122]     (clinit):     170.72 ms,  2.65 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122]     analysis:  10,394.34 ms,  2.65 GB
Warning: Aborting stand-alone image build due to unsupported features
Warning: Use -H:+ReportExceptionStackTraces to print stacktrace of underlying exception
Build on Server(pid: 58122, port: 50139)
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122]    classlist:      80.53 ms,  2.73 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122]        (cap):   1,526.57 ms,  2.73 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122]        setup:   1,768.75 ms,  2.73 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122]     (clinit):     120.93 ms,  2.73 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122]   (typeflow):   2,626.58 ms,  2.73 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122]    (objects):   3,042.60 ms,  2.73 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122]   (features):      70.71 ms,  2.73 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122]     analysis:   5,958.54 ms,  2.73 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122]     universe:     179.95 ms,  2.73 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122]      (parse):     229.34 ms,  2.73 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122]     (inline):     432.89 ms,  2.64 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122]    (compile):   1,737.58 ms,  2.66 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122]      compile:   2,715.36 ms,  2.66 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122]        image:     633.62 ms,  2.66 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122]        write:     201.14 ms,  2.66 GB
[/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT:58122]      [total]:  11,592.85 ms,  2.66 GB
Warning: Image '/Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT' is a fallback image that requires a JDK for execution (use --no-fallback to suppress fallback image generation and to print more detailed information why a fallback image was necessary).
Created native image /Users/kamuela/Code/graal-thing/target/default+uberjar/graal-thing-0.1.0-SNAPSHOT

borkdude 2020-07-04T11:49:29.042300Z

@kamuela Start with hello world https://github.com/lread/clj-graal-docs

Kamuela 2020-07-04T11:56:03.042900Z

Ok, I'm now using this

$NATIVE_IMAGE \
    -jar target/hello-world-0.1.0-SNAPSHOT-standalone.jar \
    -H:Name=hello-world \
    -H:+ReportExceptionStackTraces \
    --initialize-at-build-time  \
    --verbose \
    --no-fallback \
    --no-server \
    "-J-Xmx3g"
directly

Kamuela 2020-07-04T11:56:56.043200Z

➜  graal-thing ./graal-thing 
PING!
PONG!
Like a charm!

Kamuela 2020-07-04T11:57:25.043700Z

I guess there's something I'm missing when trying to use @taylor's lein plugin

lispyclouds 2020-07-04T12:00:24.045500Z

@kamuela you can try adding this to your project.clj with the plugin

:native-image {:name "hello-world"
                 :opts ["--initialize-at-build-time"
                        "--verbose"
                        "--no-fallback"
                        "--no-server"
                        "--report-unsupported-elements-at-runtime"]}
should work too

1👍
Kamuela 2020-07-04T12:00:54.045900Z

--no-fallback I understand, what does --no-server do?

Kamuela 2020-07-04T12:01:10.046500Z

Or "-J-Xmx3g" for that matter

borkdude 2020-07-04T12:01:22.046900Z

I've tried plugins before, but I've had several problems that made me just use the vanilla thing via a script. Not worth the debugging time.

1☝️
borkdude 2020-07-04T12:02:08.047700Z

@kamuela You can read what this means by running native-image --help or similar

lispyclouds 2020-07-04T12:02:53.048400Z

i would echo @borkdude too and recommend to build the jar separately and compile afterwards

borkdude 2020-07-04T12:03:33.048900Z

yeah or even just (compile 'foo.bar) and then add classes to your GraalVM native classpath

borkdude 2020-07-04T12:03:51.049300Z

this is also documented in the hello world of clj-graal-docs, both approaches are

Kamuela 2020-07-04T12:07:00.049800Z

At the top of every namespace means

(ns graal-thing.core
  (:gen-class))

(set! *warn-on-reflection* true)
?

borkdude 2020-07-04T12:07:07.050Z

yes

Kamuela 2020-07-04T12:07:26.050300Z

Is that to do with the really long compile times?

borkdude 2020-07-04T12:08:49.050800Z

you also want to enable direct linking. but all kinds of things can spike compile times, hard to say without context

borkdude 2020-07-04T12:08:56.051Z

afk

Kamuela 2020-07-04T13:11:43.051100Z

This worked, too. Thank you