@borkdude is it easy to start a (socket) repl for sci running on clojure+graalvm? I looked around a bit in the docs for sci, but couldn't find an answer
could one use clojure.core.server/start-server
with sci somehow? 🙂
@saikyun The most complete example I have of this is babashka, which ships with both socket repl and nREPL
babashka.nrepl is the easiest to integrate since that's been split out into a library: https://github.com/babashka/babashka.nrepl
ah, cool, thanks for the info 🙂
if you need a socket REPL we could make a similar project which splits out the socket repl from babashka for use in other sci GraalVM projects
hehe, my favourite repl client is based on socket repl. but in this case, I'm mostly looking for speeding up my iteration cycle when trying out things in graalvm.
so for now, trying the nrepl version is more than good enough for me 🙂
the best iteration cycle is probably: develop on the JVM as long as possible and only compile to native as a last step
agree. in this case though, it's native image specific behaviour I'm trying to inspect
ah right
specifically, I'm trying to figure out the differences and similarities between polyglot with llvm context, and graalvm.c
@borkdude I got babashka.nrepl working in a jvm repl, but when trying to run it with native image I get this:
[thread:42] scope: ForkJoinPool-2-worker-21
[thread:42] scope: ForkJoinPool-2-worker-21.ClosedWorldAnalysis
Context: StructuredGraph:8140{AnalysisMethod<sci.impl.Reflector.canAccess -> HotSpotMethod<Reflector.canAccess(Method, Object)>>}
Context: AnalysisMethod<sci.impl.Reflector.canAccess -> HotSpotMethod<Reflector.canAccess(Method, Object)>>
[thread:42] scope: ForkJoinPool-2-worker-21.ClosedWorldAnalysis.AnalysisGraphBuilderPhase.IntrinsifyMethodHandles
Context: StructuredGraph:8180{HotSpotMethod<Invokers$Holder.invoke_MT(Object, Object, Object, Object)>}
Exception raised in scope ForkJoinPool-2-worker-21.ClosedWorldAnalysis.AnalysisGraphBuilderPhase.IntrinsifyMethodHandles: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: Invoke with MethodHandle argument could not be reduced to at most a single call or single field access. The method handle must be a compile time constant, e.g., be loaded from a `static final` field. Method that contains the method handle invocation: java.lang.invoke.Invokers$Holder.invoke_MT(Object, Object, Object, Object)
any ideas? 🙂
I use this example: https://github.com/babashka/babashka.nrepl#starting-a-server
yes, this is because you're probably using graalvm jdk11?
indeed
ah, thanks
Also you'll need https://github.com/borkdude/clj-reflector-graal-java11-fix
probably
I'll try it! 🙂
ah, of course I'm on a unsupported version of graalvm ^^;
20.2.0-dev
maybe I should try a non-dev version
is there a reason you're using the dev version?
you can still use your dev version, but you'll need this to compile yourself: https://github.com/borkdude/clj-reflector-graal-java11-fix/blob/master/src-java/borkdude/Clojure_lang_Reflector_Substitutions.java
I'm actually not sure anymore. I ended up here when trying various examples
aha, I could just import the source?
it depends on svm.jar in the graalvm distribution so you'll also need to add that to your classpath when compiling it
dev versions don't have a published version of svm.jar on maven
okay, I see. I found svm.jar in my graalvm distribution, so I'll give it a shot 🙂
hah, now it works. thanks a lot! this will be very helpful 🙂
I feel a bit of discomfort when I think about the research and work you've had to do to get it all running this well. thanks a lot for that!
I've already peeked a lot at babashka to get started with ni + clojure, so that's been very helpful as well 🙂
hm, for some reason I'm having trouble calling static methods on classes. I've added the class to reflection.json
and added this flag to ni call: "-H:ReflectionConfigurationFiles=reflection.json"
. I can eval the class name, but all methods on it seem gone (despite being able to call them in the source code precisely before the call to start-server!
)
nvm, now it works
not sure what I did wrong first though 😛 oh well
now I just get segfaults when trying to call (c) native functions, haha. I guess that's progress
is there a way inside the clojure source to know if one is in native-image or not? trying to find if one could set compile flags in leiningen somehow, but so far coming up short
@saikyun Yes, check (System/getProperties)
, there are some graalvm specific things in there
thanks 🙂