选择加入 JVM 中基于每种语言的尾部调用支持?
虽然尾部调用优化看起来不会被添加为常见的优化技术,特别是在 Sun 被收购之后,但从技术上来说,让在 VM 上运行的语言自行决定编译器是否发出 是不可能的吗?字节码中的tailcall
指令?
例如Java、Groovy 可以决定不使用该指令,而 Scala 或 Clojure 等更多函数式语言可以发出该指令,而 HotSpot VM 只会优化那些标有 tailcall
的指令?
While it doesn't look like that tail call optimization will ever be added as a common optimization technique, especially after Sun was bought, wouldn't it be technically possible to let languages running on the VM decide themselves if their compiler emits tailcall
instructions in the byte code?
E. g. Java, Groovy can decide not to use the instruction, while more functional languages like Scala or Clojure can emit it and the HotSpot VM will only optimize the ones marked with tailcall
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这在技术上是可行的——事实上,Arnold Schwaighofer 为 OpenJDK 提供了一个实验性补丁,其中就是这样做的,尽管应用补丁和构建并不容易,因为它目前没有保持最新状态。
显式尾部调用指令比 JVM 对尾部位置的函数调用进行透明优化具有优势,因为 JVM 可以验证您指定为尾部调用的内容是否确实如此,请参阅此 John Rose 的尾调用博客文章,解释了一些可以完成的验证。
我认为 JVM 的未来不是 Java,我希望有时间和才华的人推动 JVM 的尾部调用向前发展。
Yes, this is technically possible -- in fact there an experimental patch by Arnold Schwaighofer for OpenJDK which does just that, although it isn't easy to apply the patch and build, as it isn't kept up to date at present.
An explicit tail call instruction has advantages over transparent optimisation of function calls in tail position by the JVM, as the JVM can verify that what you have specified as a tail call really is see this tail call blog post by John Rose for an explanation of some of the verification which can by done.
I think the future of the JVM is not Java, and I hope that someone with the time and talent pushes tail calls for the JVM forward.