在尝试优化 C 和 LISP 时,查看编译器输出的汇编代码会有很大帮助。
Clojure 可能会编译为同样有用的 JVM 字节码。
我如何看到它?
最佳答案
Clojure 在运行时动态地将所有 Clojure 代码编译为字节码。我不确定你如何看到这个动态编译的字节码。但是,您可以自己对 Clojure 代码进行提前 (AOT) 编译,这将生成 .class 文件。然后你可以使用javap
来查看字节码。
使用 Clojure/core 中的 compile
函数来编译你的命名空间:
compile function
Usage: (compile lib)
Compiles the namespace named by the symbol lib into a set of classfiles. The source for the lib must be in a proper classpath-relative directory. The output files will go into the directory specified by compile-path, and that directory too must be in the classpath.
然后使用javap
:
javap -l -c -s -private MyClass
关于clojure - 如何检查 clojure 函数的 JVM 字节码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3819809/