graalvm

Discuss GraalVM related topics. Use clojure 1.10.2 or newer for all new projects. Contribute to https://github.com/clj-easy/graal-docs and https://github.com/BrunoBonacci/graalvm-clojure. GraalVM slack: https://www.graalvm.org/slack-invitation/.
borkdude 2020-03-09T12:18:49.271900Z

pgmig was updated from clojure 1.8.0 (!) to clojure 1.10.2-alpha1: https://github.com/leafclick/pgmig/commit/68864abe8e94910402e6a01d7de88f5d0cdfc504

alexmiller 2020-03-09T12:59:17.272100Z

1.10.2-alpha1

borkdude 2020-03-09T12:59:38.272400Z

yes

katox 2020-03-09T13:13:04.273300Z

@mkvlr I have a frontend rest service running in native image:

[tiketguard:26315]    classlist:  10,791.61 ms
[tiketguard:26315]        (cap):   1,308.11 ms
[tiketguard:26315]        setup:   3,329.41 ms
[tiketguard:26315]   (typeflow): 323,689.19 ms
[tiketguard:26315]    (objects):  78,563.42 ms
[tiketguard:26315]   (features):  10,511.45 ms
[tiketguard:26315]     analysis: 419,706.99 ms
[tiketguard:26315]     (clinit):   1,737.86 ms
[tiketguard:26315]     universe:   6,046.41 ms
[tiketguard:26315]      (parse):  11,295.08 ms
[tiketguard:26315]     (inline):  13,751.14 ms
[tiketguard:26315]    (compile):  65,125.46 ms
[tiketguard:26315]      compile:  95,394.01 ms
[tiketguard:26315]        image:  14,677.93 ms
[tiketguard:26315]        write:   1,736.10 ms
[tiketguard:26315]      [total]: 552,193.88 ms

katox 2020-03-09T13:13:43.273700Z

it seems to work normally with 1.10.2-alpha1 as well

katox 2020-03-09T13:15:45.274100Z

hmm, no premature statement

katox 2020-03-09T13:16:10.274300Z

it compiles though 🙂

katox 2020-03-09T13:17:01.274900Z

I think it culprint is some of the deps having spec in its deps (and not in the latest version)

borkdude 2020-03-09T13:17:28.275300Z

shouldn't 1.10.2-alpha1 pull in the latest spec, or does it get overriden somehow?

borkdude 2020-03-09T13:17:44.275800Z

clj -Spath or lein classpath should tell you the answer

borkdude 2020-03-09T13:19:13.276500Z

could also be that one dep of yours is AOT-ed with clojure 1.10.1 or so

katox 2020-03-09T13:20:20.276800Z

spec.alpha-0.2.187.jar

borkdude 2020-03-09T13:21:31.277500Z

what error are you seeing?

katox 2020-03-09T13:21:46.277700Z

I'll have to investigate. But the message is what I see when "wrong" spec is in com.oracle.svm.core.jdk.UnsupportedFeatureError: Invoke with MethodHandle argument could not be reduced to at most a single call: java.lang.invoke.Invokers$Holder.invoke_MT(Object, Object, Object, Object)

borkdude 2020-03-09T13:21:56.278Z

@katox that's a JDK11 related thing.

katox 2020-03-09T13:22:10.278600Z

there are deps that don't include stuff when using clj 1.8

borkdude 2020-03-09T13:22:14.278700Z

try jdk8

borkdude 2020-03-09T13:22:27.279Z

graalvm-xxx-java8

katox 2020-03-09T13:22:44.279400Z

yet pgmig works with it

borkdude 2020-03-09T13:23:07.279700Z

yeah, it depends whether your program will hit that piece of code I think

katox 2020-03-09T13:23:40.280500Z

It seems so. Bunch of code is spec related and thus not included when using clj 1.8.

katox 2020-03-09T13:25:19.282500Z

That'd make sense. I tried to avoid reflection calls in pgmig but that's not feasible in the larger app. I'll try to play again with it soon

borkdude 2020-03-09T13:25:47.282900Z

the patch works well

katox 2020-03-09T13:26:05.283300Z

for now I'll try again with graal on java8

katox 2020-03-09T13:51:14.285Z

@borkdude good tip, the reflector error is gone on java8 graal. There are still problems in the final binary but the build is on track now.

borkdude 2020-03-09T15:26:26.285600Z

I think I found a better fix for the clojure.lang.Reflector issue with java11! https://github.com/oracle/graal/issues/2214#issuecomment-596598421 No need anymore to patch Clojure itself by overriding the class.

katox 2020-03-09T15:30:57.286600Z

I updated some more deps and now the full app works with java8 graal!

borkdude 2020-03-09T15:31:34.287100Z

I'll make some proper docs around this java11 fix later

katox 2020-03-09T15:32:30.288300Z

@borkdude is the above a configuration class that can be included in the project along with json configuration? Because I tried the java configuration code before and ran into more troubles.

borkdude 2020-03-09T15:35:32.288800Z

@katox This is the fix in action: https://github.com/borkdude/sci/commit/4c8190c0e95860ece8e8b195b05d31ad0866d763 you need to compile this with svm.jar on the classpath. The commit shows that.

😮 1
lread 2020-03-09T15:38:44.289700Z

Oh that’s interesting @borkdude, so with Java substitutions, we can monkey patch Clojure!

borkdude 2020-03-09T15:39:02.290Z

yes, at least the Java bits

borkdude 2020-03-09T15:39:27.290400Z

so if Clojure is going to have more Java-version specific bits, we can maybe work around it this way

lread 2020-03-09T15:40:14.291Z

yeah… neat! Another tool in the chest!

katox 2020-03-09T15:44:31.292Z

I think oracle provided some maven svm artifact. You could put it as a native image profile dependence.

borkdude 2020-03-09T15:46:20.292400Z

ah nice. I'll use that then

Crispin 2020-03-09T15:46:58.292800Z

Very impressive @borkdude.

borkdude 2020-03-09T15:47:03.293100Z

it is GPL licenced. is this what the classpath exception is for, i.e. when I compile my binary with this, I can still distribute it?

Crispin 2020-03-09T15:47:59.293200Z

So am I reading this right. This works both graal java 8 and java 11. And keeps full functionality in both.

borkdude 2020-03-09T15:48:06.293400Z

yep

borkdude 2020-03-09T15:48:27.293600Z

I think I could even make a library out of this

borkdude 2020-03-09T15:48:52.293800Z

I'll try this later this week

Crispin 2020-03-09T15:48:55.294Z

You have been busy! How did you learn about @TargetElement? Just reading source code?

borkdude 2020-03-09T15:49:27.294200Z

it came up in another issue. See https://github.com/oracle/graal/issues/2136 towards the end.

borkdude 2020-03-09T15:51:20.294900Z

This is from the native-image chat:

Michiel Borkent  [4:22 PM]
Is the svm.jar available as a maven library so I can put it on my classpath via a package manager?


Michiel Borkent  [4:38 PM]
it seems it is, but not updated for newer versions? <https://mvnrepository.com/artifact/com.oracle.substratevm/svm> (edited) 

David Lloyd  [4:49 PM]
the group ID changed to org.graalvm.nativeimage
[4:49 PM]
<https://search.maven.org/search?q=svm>
<http://search.maven.org|search.maven.org>
The Central Repository Search Engine
The Search Engine for The Central Repository

Michiel Borkent  [4:50 PM]
oh thank you!

Peter Niederwieser  [4:50 PM]
afaik the jar can't currently be used with openjdk.

Crispin 2020-03-09T15:55:43.295200Z

Ah yeah, I see. Very nice. This is so much better.

katox 2020-03-09T15:56:28.296100Z

But you don't use it with openjdk. You use graal and the graal's native image to create and link the binary. And the binary on linux is linked to some gnu libc stuff.

Crispin 2020-03-09T16:01:23.296900Z

glibc (just that lib) is also LGPL not GPL.

Crispin 2020-03-09T16:01:59.297600Z

the gnu library that normally causes linking license problems is libreadline (its GPL)

katox 2020-03-09T16:05:05.298400Z

You're right. Still there is no openjdk involved unless you use that on CI server.

borkdude 2020-03-09T16:06:30.299500Z

I'll process this fix into proper docs and maybe a lib later this week(end)

katox 2020-03-09T17:12:42.300700Z

Just FYI native-image compilation times for the FE service app - various -J-Xmx settings

16G
[tiketguard:21475]      [total]: 280,823.65 ms
10G
[tiketguard:30357]      [total]: 874,997.50 ms
8G
java.lang.OutOfMemoryError

katox 2020-03-09T17:14:30.301700Z

for reference the uberjar size is about 40megs (got a heavy cut to actually compile and run as a native-image)

borkdude 2020-03-09T19:16:37.302Z

Here's the library: https://github.com/borkdude/clj-reflector-graal-java11-fix

borkdude 2020-03-09T19:18:41.302600Z

Feedback welcome. If it also works for you, I'll drop the alpha label

borkdude 2020-03-09T19:39:07.303Z

It worked for sci.

jumar 2020-03-09T21:00:06.304100Z

Interesting speedup going from 10 to 16 G