Some fun with GraalVM

I am getting GraalVM to run with CLI-matic to create small command line tools. It works - kind of. I am trying to run this: https://github.com/l3nz/cli-matic/blob/master/examples/toycalc.clj

I am getting a weird error:

Error: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Unsupported type java.net.JarURLConnection is reachable
To diagnose the issue, you can add the option -H:+ReportUnsupportedElementsAtRuntime. The unsupported element is then reported at run time when it is accessed the first time.
Trace:
        at parsing java.net.URLClassLoader.getResourceAsStream(URLClassLoader.java:239)
Call path from entry point to java.net.URLClassLoader.getResourceAsStream(String):
        at java.net.URLClassLoader.getResourceAsStream(URLClassLoader.java:232)
        at clojure.lang.RT.resourceAsStream(RT.java:2183)
        at clojure.lang.RT.compile(RT.java:410)
        at clojure.lang.RT.load(RT.java:458)
        at clojure.lang.RT.load(RT.java:426)
        at clojure.core$load$fn__6546.invoke(core.clj:6046)
        at clojure.lang.AFn.run(AFn.java:22)
        at java.lang.Thread.run(Thread.java:748)
        at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:238)
        at com.oracle.svm.core.code.CEntryPointCallStubs.com_002eoracle_002esvm_002ecore_002eposix_002ethread_002ePosixJavaThreads_002epthreadStartRoutine_0028com_002eoracle_002esvm_002ecore_002eposix_002ethread_002ePosixJavaThreads_0024ThreadStartData_0029(generated:0)

Not sure why it’s complaining about a java.net.JarURLConnection class…

But if work around the issue by adding a -H:+ReportUnsupportedElementsAtRuntime it just grinds on and on and at the end spits out a 25M executable that is compressed to ~7M.

-rwxr-xr-x  1 root root  25873378 Jul 19 22:12 testaot-0.2-standalone
-rwxr-xr-x  1 root root   7028008 Jul 19 22:12 testaot-0.2-standalone.gz

Now for the good news - this is a JVM execution:

# time ./graalvm-ce-1.0.0-rc4/bin/java -jar testaot-0.2-standalone.jar -?
NAME:
 toycalc - A command-line toy calculator

USAGE:
 toycalc [global-options] command [command options] [arguments...]

real    0m1.563s
user    0m2.755s
sys     0m0.156s

And this is compiled:

# time ./testaot-0.2-standalone -?
NAME:
 toycalc - A command-line toy calculator

USAGE:
 toycalc [global-options] command [command options] [arguments...]

real    0m0.005s
user    0m0.003s
sys     0m0.002s

Not half bad, is it? :smile:

5 Likes

BTW, I created a blog entry about it: https://www.astrecipes.net/blog/2018/07/20/cmd-line-apps-with-clojure-and-graalvm/

1 Like

Not half bad indeed. Thanks for sharing!

Typo spotted

, at the moment we have to tell Graal not to abort at compile time but to defer such exceptions to compile time

I think you want to defer them to runtime.

By the way, what really happened when this warning shows up? Does it mean it can agressively compile your code and falls back to dynamic class loading anyway in the final executable?

Thanks - will fix it. I’m an awful bad typist.

The idea is that it will crash and burn at runtime - so it’s bad, but at the moment I am aware of no better option. As it is in RT, I guess that there is nothing that can be done about it.

Ok so the compiler time warning is just about the possibility of a problem, not a signal that the app will crash no matter what. I get it, thanks.

Yes - but at that point you don’t know if it may crash and burn or not.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.