clj-easy / graal-docs

Scripts and tips to get Clojure latest working with GraalVM latest
Eclipse Public License 1.0
390 stars 20 forks source link

More notes on class initialization #53

Closed borkdude closed 3 years ago

borkdude commented 3 years ago

https://github.com/lread/clj-graal-docs#class-initialization

See https://github.com/oracle/graal/discussions/3476

From Graal 22 on, the global --initialize-at-build-time option will be deprecated.

It is possible to get a list of Clojure-produced packages with something like:

(require 'babashka.main)
(->> (map ns-name (all-ns)) (remove #(str/starts-with? % "clojure")) (map #(str/split (str %) #"\.")) (keep butlast) (map #(str/join "." %)) distinct (map munge) (cons "clojure"))

and then make a comma separated list out of that:

"--initialize-at-build-time=clojure,sci.impl,selmer,babashka.nrepl,babashka.impl.clojure.java,babashka.impl,rewrite_clj.node,bencode,rewrite_clj.parser,babashka.impl.clojure,org.httpkit,rewrite_clj.custom_zipper,rewrite_clj.zip,borkdude.graal,babashka.nrepl.impl,babashka.pods,cognitect,babashka,edamame.impl,cheshire,rewrite_clj,hiccup,sci,borkdude,flatland.ordered,babashka.pods.impl,clj_yaml,babashka.impl.clojure.core,datascript,hf.depstar,babashka.impl.tools,sci.addons,babashka.impl.clojure.test"

This has an additional benefit that not all Java classes are initialized at build time, reducing the chance on any incorrect behavior.

borkdude commented 3 years ago

I'm planning to make a library out of this. Perhaps we can use the Graal annotations processor to accomplish this goal, so then users would only have to include a library on their classpath.

borkdude commented 3 years ago

Relevant APIs:

borkdude commented 3 years ago

@ericdallo Made a repo here where we can implement this:

https://github.com/clj-easy/graal-build-time

borkdude commented 3 years ago

I guess we can start recommending https://github.com/clj-easy/graal-build-time over the global --initialize-at-build-time option now.

lread commented 3 years ago

Note to self: warning output from GraalVM 21.2.0

--initialize-at-build-time without arguments has been deprecated and will be removed in GraalVM 22.0.