graalvm 2020-09-08

i am trying to make https://github.com/ashwinbhaskar/aerospike-migration command line application graalvm compatible. I am able to generate the native image with if I give --report-unsupported-elements-at-runtime parameter. But when I try to run the native image, I get this error

Caused by: java.io.FileNotFoundException: Could not locate clojure/core__init.class, clojure/core.clj or clojure/core.cljc on classpath.
	at clojure.lang.RT.load(RT.java:466)
	at clojure.lang.RT.load(RT.java:428)
	at clojure.lang.RT.doInit(RT.java:471)
	at clojure.lang.RT.<clinit>(RT.java:338)
	at com.oracle.svm.core.classinitialization.ClassInitializationInfo.invokeClassInitializer(ClassInitializationInfo.java:351)
	at com.oracle.svm.core.classinitialization.ClassInitializationInfo.initialize(ClassInitializationInfo.java:271)
Has anyone faced such an error?

looking at the project.clj, it doesn’t look like you’re AOTing your uberjar

doesn’t the presence of :gen-class generate the main class ahead of time?

@smith.adriane did you mean adding :aot :all to project.clj? I tried this. Still get the same error

@ashwinbhskr Check the contents of you uberjar

with jar -tf the-uberjar.jar

@borkdude I did that. I am able to see clojure/core__init.class in output

What is your native-image invocation?

I think it would be easier if you made a repro repo on Github

@borkdude sure, pushed all my changes to the repo. To reproduce. 1. Clone the repo and run make create-jar 2. A jar with name aerospike-migration.jar will be created. 3. Copy the jar to the Graalvm bin directory. 4. Run ./native-image --report-unsupported-elements-at-runtime -jar aerospike-migration.jar -H:Name=aerospike-migration --no-fallback -H:+ReportExceptionStackTraces 5. A native image with the name aerospike-migration will be generated. 6. Just run ./aerospike-migration --help You should see the error that I am getting

@borkdude using --initialize-at-build-time gives this exception while generating the native iamge

Call path from entry point to clojure.core.server$io_prepl$fn__8940.invoke(Object):
	at clojure.core.server$io_prepl$fn__8940.invoke(server.clj:284)
	at clojure.tools.logging.proxy$java.io.ByteArrayOutputStream$ff19274a.flush(Unknown Source)
	at java.io.PrintStream.flush(PrintStream.java:338)
	at com.oracle.svm.jni.functions.JNIFunctions.ExceptionDescribe(JNIFunctions.java:772)
	at com.oracle.svm.core.code.IsolateEnterStub.JNIFunctions_ExceptionDescribe_b5412f7570bccae90b000bc37855f00408b2ad73(generated:0)
Original exception that caused the problem: org.graalvm.compiler.core.common.PermanentBailoutException: Frame states being merged are incompatible: unbalanced monitors - locked objects do not match
 This frame state: [locals: [1,2,41,_,_,_,_] stack: [44] locks: [] rethrowException]
Other frame state: [locals: [1,2,41,_,_,_,_] stack: [74] locks: [51 / 42] rethrowException]
Parser context: clojure.core.server$io_prepl$fn__8940.invoke(server.clj:287) [bci: 84, intrinsic: false]

Use clojure 1.10.2-alpha1, also see the linked repo

okay, will do

@borkdude Tried out as given in the linked repo and shifting to clojure 1.10.2-alpha1. Now it gives the error:

Caused by: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Class initialization of org.postgresql.sspi.SSPIClient failed. Use the option --initialize-at-run-time=org.postgresql.sspi.SSPIClient to explicitly request delayed initialization of this class.
Detailed message:

Is the postgresql jdbc driver not graal compatible?

It is, but you need an additional setting.

Yes, using the additional setting made it work. But it complained that there no method that takes 1 argument for class CompletableFuture

Adding type hint solved the problem. Now I am able to execute the native image fine. Thanks a lot @borkdude!