Problems using Clojure with J9 JVM
The trouble is an Exception or Error, of one kind or another, usually originating in clojure.core; frequently it is a NullPointerException in reduce1 that is also thrown by Leiningen on the J9 JVM.
The problem is erratic. But something reliably goes wrong if J9 "always compiles" (-Xcomp) and it seems to work fine when J9 "always interprets" (-Xint).
On the first run of clojure it threw NullPointerException. More about this below.
Trying various JVM options, I found that the -Xint JVM option allowed clojure to download various things and display the REPL prompt. According to java -X this option means "interpreted mode execution only". After the first successful run, subsequent runs of clojure usually succeeded in producing the REPL prompt. However, the -Xcomp JVM option makes the error happen every time. It means "forces compilation of methods on first invocation".
The NullPointerException stack trace was:
On a subsequent run, I got a different error:
Syntax error macroexpanding clojure.core/defn- at (clojure/tools/cli.cljc:124:1). null Full report at: /tmp/clojure-12652663517358293277.edn
On yet another run, I got yet a different error message:
The trouble happens in Windows and Linux, and both the "11" and "15" versions of the J9 JVM, and numerous (all?) Clojure versions including 1.10.1, 1.10.2, 1.7, and 1.5.1.
The issue was traced to a bad change in j9 and they reverted it (see https://github.com/eclipse/openj9/issues/12191#issuecomment-799695842).
From the resolution:
"The fix delivered #12221 backports this to the 0.26 release which will be generated for Java 8, 11, and 16. We use the same JIT compiler for all of those JVM levels so the fix will be there in 0.26 releases.
This release is scheduled for April 23, 2021:
I think for working with this, getting clj and leiningen out of the way is helpful.
The strange NPEs makes me wonder if it's related to locals-clearing bytecode. Could experiment with trying a build of Clojure with locals clearing off (or slim build) to see if the errors still occur.