Fork me on GitHub
#graalvm
<
2022-01-14
>
Daniils Petrovs17:01:59

Hey guys 👋 I am using graal-build-time and a tiny compile script to try and build a native image from an uberjar, but native-image always breaks saying certain classes where initialized at build time, even though I went through them and passed them to the --initialize-at-run-time option.

borkdude18:01:17

@U013SKZJM39 Just add com.fasterxml to the list

borkdude18:01:45

We also have a solution for this here: https://github.com/clj-easy/graal-config if you are using cheshire, supposedly

Daniils Petrovs19:01:04

Hmm not cheshire in particular, but maybe one of the other deps depends on it

borkdude19:01:25

easy to find out with clojure -Stree or lein deps :tree

👍 1
Daniils Petrovs19:01:30

I’m using etaoin and some CLI option parsing, so it’s likely a transitive dep somewhere

borkdude19:01:47

oh etaoin... I have that graalified already

Daniils Petrovs19:01:48

Thanks, I’ll take a look later 🙇

borkdude19:01:59

but I had to do some workarounds for that

Daniils Petrovs20:01:20

Oh for Babashka? :thinking_face: yeah that would be very useful

borkdude20:01:28

Yes:

(require '[babashka.pods :as pods])
(pods/load-pod 'org.babashka/etaoin "0.1.0")
;; or for loading local binary: (pods/load-pod "./pod-babashka-etaoin")
(require '[pod.babashka.etaoin :as eta])
(def driver (eta/firefox))
(eta/go driver "")
(eta/quit driver)

Daniils Petrovs22:01:11

so I looked at graal-config examples and merged the options and reflection configs, and I got much further now :thumbsup:

Daniils Petrovs22:01:38

now I’m just stuck on this error and can’t wrap my head around it:

Error: Classes that should be initialized at run time got initialized during image building:
 java.security.Security the class was requested to be initialized at run time (from the command line). To see why java.security.Security got initialized use --trace-class-initialization=java.security.Security
java.security.SecureRandom the class was requested to be initialized at run time (from the command line). To see why java.security.SecureRandom got initialized use --trace-class-initialization=java.security.SecureRandom
java.security.MessageDigest the class was requested to be initialized at run time (from the command line). To see why java.security.MessageDigest got initialized use --trace-class-initialization=java.security.MessageDigest

Daniils Petrovs22:01:41

My config so far

borkdude22:01:03

I have a separate project here on which I based the pod: https://github.com/borkdude/etaoin-graal where I changed some stuff. Maybe it's useful going into that.

👍 1
Daniils Petrovs22:01:46

hm I was debugging a bit more and hit this one:

Error: Incompatible change of initialization policy for com.sun.jndi.dns.DnsClient: trying to change RUN_TIME from the command line to RERUN Contains Random references, therefore can't be included in the image heap.
com.oracle.svm.core.util.UserError$UserException: Incompatible change of initialization policy for com.sun.jndi.dns.DnsClient: trying to change RUN_TIME from the command line to RERUN Contains Random references, therefore can't be included in the image heap.
basically the root of the problem is java.security.SecureRandom

borkdude22:01:28

The problem is that some secure-random thing is initialized at the top level

borkdude22:01:37

perhaps you are doing (def http-client ...)

borkdude22:01:44

which you should wrap in a delay

Daniils Petrovs22:01:07

nope, no bare HTTP calls, just using etaoin APIs

borkdude22:01:18

but maybe etaoin itself is doing that

Daniils Petrovs22:01:23

(defn setup-driver
  ([] (setup-driver true))
  ([headless?]
   (let [driver (api/chrome {:headless headless?})]
     (api/set-window-size driver 1200 800)
     driver)))

borkdude22:01:38

this is why I ultimately forked it and made it graal-friendly

👍 1
Daniils Petrovs22:01:38

Hmm could be, should I try your fork then?

borkdude22:01:53

sure. I also published it to clojars

borkdude22:01:03

see its project.clj

👏 1
Daniils Petrovs22:01:53

Ok I tried the fork, still getting this:

Error: Classes that should be initialized at run time got initialized during image building:
 sun.security.jca.JCAUtil the class was requested to be initialized at run time (from the command line). sun.security.jca.JCAUtil has been initialized without the native-image initialization instrumentation and the stack trace can't be tracked. Try avoiding to initialize the class that caused initialization of sun.security.jca.JCAUtil
java.security.SecureRandom the class was requested to be initialized at run time (from the command line). com.sun.jndi.dns.DnsClient caused initialization of this class with the following trace:
	at java.security.SecureRandom.<clinit>(SecureRandom.java:152)
	at sun.security.jca.JCAUtil$CachedSecureRandomHolder.<clinit>(JCAUtil.java:59)
	at sun.security.jca.JCAUtil.getSecureRandom(JCAUtil.java:69)
	at com.sun.jndi.dns.DnsClient.<clinit>(DnsClient.java:84)

borkdude22:01:19

This might be coming from your app code then

borkdude22:01:31

If I can't see it, I can't really comment on it

Daniils Petrovs17:01:22

My script:

"native-image" \
    -jar target/uberjar/atoss-cli-standalone.jar \
    -H:Name=atoss-native \
    -H:+ReportExceptionStackTraces \
	--initialize-at-run-time=org.apache.commons.logging.LogFactory,org.apache.http.conn.ssl.AbstractVerifier,org.apache.http.Consts,org.apache.http.conn.ssl.BrowserCompatHostnameVerifier,org.apache.http.nio.conn.ssl.SSLIOSessionStrategy,org.apache.http.conn.ssl.AllowAllHostnameVerifier,com.fasterxml.jackson.dataformat.cbor.CBORFactory,com.fasterxml.jackson.dataformat.smile.SmileFactory,com.fasterxml.jackson.core.JsonFactory,org.apache.http.conn.ssl.StrictHostnameVerifier,org.apache.http.conn.ssl.SSLConnectionSocketFactory \
    --no-fallback \
    --no-server \
    "-J-Xmx3g"

Daniils Petrovs17:01:08

What native-image logged

Daniils Petrovs17:01:01

Don’t think it’s related to Graal’s version, but just in case its [email protected]

emccue23:01:40

Encountering build errors that I think are related to incomplete trace info, but i can’t really tell. https://github.com/bowbahdoe/jproject/runs/4823295129?check_suite_focus=true

borkdude23:01:38

sleep time here, back tomorrow

👍 1
emccue17:01:48

I got the compile working and an exe that will run by copying the flags from the tools-deps-native project and using clj-easy, but for whatever reason it won’t see a deps.edn in the directory i run it in

borkdude17:01:27

This is likely because you are using a def somewhere which reads things at compile time rather than at run time.

emccue17:01:50

afaict nothing in my code does that. the only defs i have are for help messages.

borkdude18:01:39

Are you using the same version of tools.deps.alpha as tools-deps-native is?

emccue04:01:25

Nope. I was on 0.12.1109 and tools-deps-native is on 0.12.1067

emccue04:01:56

i was able to resolve the issue by manually slurping the project deps.edn

emccue04:01:55

but im gonna have to shelve this while i learn stuff since seeing this https://github.com/sormuras/bach makes me realize i dont understand modules nearly enough yet