Yes, eval will generate classes in a dynamic classloader, load them, then
call methods on the newly formed class/object except for
too-simple-to-be-interesting cases.

On Mon, Nov 26, 2018 at 11:43 AM Khalid Jebbari <khalid.jebb...@gmail.com>
wrote:

> Hi,
>
> I was doing a small experiment with Clojure and GraalVM and ended with
> this minimal reproduction case of an incompatibility between Clojure's
> `eval` and GraalVM's native-image tool (the program that compiles a JVM
> program to a native executable, based on the GraalVM's SubstrateVM
> compiler).
>
> Here's the Clojure program:
>
> (ns test-cli.main
>   (:gen-class))
>
> (set! *warn-on-reflection* true)
>
> (defn -main
>   "I don't do a whole lot ... yet."
>   [& args]
>   (println (+ 1 1)) ;; trick to force loading clojure.lang.Numbers, not
> working
>   (eval (read-string "(+ 1 1)")))
>
> Using Clojure 1.9.0 and GraalVM version 1.0.0-rc9.
>
> When I compile it with the
> option "--report-unsupported-elements-at-runtime" (which gives a more
> precised error message), here's the output when I try executing the
> resulting executable:
>
> Exception in thread "main" java.lang.ClassNotFoundException:
> clojure.lang.Numbers, compiling:(NO_SOURCE_PATH:0:0)
>         at java.lang.Throwable.<init>(Throwable.java:287)
>         at java.lang.Exception.<init>(Exception.java:84)
>         at java.lang.RuntimeException.<init>(RuntimeException.java:80)
>         at
> clojure.lang.Compiler$CompilerException.<init>(Compiler.java:6804)
>         at clojure.lang.Compiler.analyzeSeq(Compiler.java:7010)
>         at clojure.lang.Compiler.analyze(Compiler.java:6773)
>         at clojure.lang.Compiler.analyze(Compiler.java:6729)
>         at clojure.lang.Compiler.analyzeSeq(Compiler.java:6998)
>         at clojure.lang.Compiler.analyze(Compiler.java:6773)
>         at clojure.lang.Compiler.analyze(Compiler.java:6729)
>         at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:6100)
>         at clojure.lang.Compiler$FnMethod.parse(Compiler.java:5460)
>         at clojure.lang.Compiler$FnExpr.parse(Compiler.java:4022)
>         at clojure.lang.Compiler.analyzeSeq(Compiler.java:7001)
>         at clojure.lang.Compiler.analyze(Compiler.java:6773)
>         at clojure.lang.Compiler.eval(Compiler.java:7059)
>         at clojure.lang.Compiler.eval(Compiler.java:7025)
>         at clojure.core$eval.invokeStatic(core.clj:3206)
>         at test_cli.main$_main.invokeStatic(main.clj:7)
>         at test_cli.main$_main.doInvoke(main.clj:7)
>         at clojure.lang.RestFn.invoke(RestFn.java:397)
>         at clojure.lang.AFn.applyToHelper(AFn.java:152)
>         at clojure.lang.RestFn.applyTo(RestFn.java:132)
>         at test_cli.main.main(Unknown Source)
>         at
> com.oracle.svm.core.JavaMainWrapper.run(JavaMainWrapper.java:164)
> Caused by: java.lang.ClassNotFoundException: clojure.lang.Numbers
>         at java.lang.Throwable.<init>(Throwable.java:287)
>         at java.lang.Exception.<init>(Exception.java:84)
>         at
> java.lang.ReflectiveOperationException.<init>(ReflectiveOperationException.java:75)
>         at
> java.lang.ClassNotFoundException.<init>(ClassNotFoundException.java:82)
>         at
> com.oracle.svm.core.hub.ClassForNameSupport.forName(ClassForNameSupport.java:51)
>         at com.oracle.svm.core.hub.DynamicHub.forName(DynamicHub.java:1036)
>         at clojure.lang.RT.classForName(RT.java:2204)
>         at clojure.lang.RT.classForNameNonLoading(RT.java:2217)
>         at clojure.lang.Compiler$HostExpr.maybeClass(Compiler.java:1041)
>         at clojure.lang.Compiler$HostExpr$Parser.parse(Compiler.java:982)
>         at clojure.lang.Compiler.analyzeSeq(Compiler.java:7003)
>         ... 20 more
>
> I'm no expert in Java/JVM and would like to understand the problem.
> According to the SubstrateVM documentation (
> https://github.com/oracle/graal/blob/master/substratevm/LIMITATIONS.md)
> it can't compile Dynamic Class Loading/Unloading. Is Clojure's `eval` doing
> such dynamic loading? Or doing something else not supported by SubstrateVM
> as said in the documentation?
>
> Thanks *a lot* in advance for you answers.
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to