JVM是否会阻止尾调用优化? [英] Does the JVM prevent tail call optimizations?
问题描述
我在这个问题上看到了这句话:构建网络服务的优秀功能语言是什么?
I saw this quote on the question: What is a good functional language on which to build a web service?
除了自递归函数外,Scala特别不支持尾调用消除,这限制了你可以做的组合种类(这是一个JVM的基本限制。
Scala in particular doesn't support tail-call elimination except in self-recursive functions, which limits the kinds of composition you can do (this is a fundamental limitation of the JVM).
这是真的吗?如果是这样,那么创建这个基本限制的JVM是什么呢?
Is this true? If so, what is it about the JVM that creates this fundamental limitation?
推荐答案
这篇文章:递归或迭代?可能有所帮助。
This post: Recursion or Iteration? might help.
简而言之,尾调用由于安全模型以及始终需要堆栈跟踪的需要,在JVM中很难进行优化。理论上可以支持这些要求,但可能需要一个新的字节码(参见 John Rose的非正式提案) )。
In short, tail call optimization is hard to do in the JVM because of the security model and the need to always have a stack trace available. These requirements could in theory be supported, but it would probably require a new bytecode (see John Rose's informal proposal).
Sun bug#4726340 ,其中评估(从2002年开始)结束:
There is also more discussion in Sun bug #4726340, where the evaluation (from 2002) ends:
I相信这可以做到,但这不是一个小任务。
I believe this could be done nonetheless, but it is not a small task.
目前,在中有一些工作正在进行href =http://openjdk.java.net/projects/mlvm/subprojects.html =nofollow noreferrer>达芬奇机器项目。尾调用子项目的状态列为proto 80%;它不太可能进入Java 7,但我认为它在Java 8上有很好的机会。
Currently, there is some work going on in the Da Vinci Machine project. The tail call subproject's status is listed as "proto 80%"; it is unlikely to make it into Java 7, but I think it has a very good chance at Java 8.
这篇关于JVM是否会阻止尾调用优化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!