Does the JVM prevent tail call optimizations?(JVM 会阻止尾调用优化吗?)
问题描述
我在这个问题上看到了这句话:构建 Web 服务的好的函数式语言是什么?
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 believe this could be done nonetheless, but it is not a small task.
目前,达芬奇机器正在进行一些工作项目.尾调用子项目的状态列为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 会阻止尾调用优化吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:JVM 会阻止尾调用优化吗?
基础教程推荐
- 如何使用 Java 创建 X509 证书? 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 降序排序:Java Map 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01