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 会阻止尾调用优化吗?
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01