java - JVM 规范中 JSR/RET 的状态

标签 java jvm opcode finally jvm-bytecode

JVM 规范的某些部分建议操作 JSR (Jump SubRoutine) , JSR_W (Jump SubRoutine Wide)RET (RETurn from subroutine)最多只能使用类文件版本 50.0 (JDK 1.6):

3.13 Compiling Finally

(This section assumes a compiler generates class files with version number 50.0 or below, so that the jsr instruction may be used. See also §4.10.2.5.)

之后:

4.10.2.5. Exceptions and finally

To implement the try-finally construct, a compiler for the Java programming language that generates class files with version number 50.0 or below may use the exception-handling facilities together with two special instructions: jsr ("jump to subroutine") and ret ("return from subroutine").

另一方面,操作码描述本身并未提及弃用这些功能。引用的文本只说明了 50.0 之前的版本,但没有明确说明之后的情况。

This comment (对于询问此弃用或删除背后的动机的问题)表示类似程度的混淆,所以显然我不是唯一一个在寻找这个的人。

最佳答案

在向我的问题添加链接时,我注意到 §4.10.1.9: Type Checking Instructions 中没有相关操作码。所以这表明新的基于 strackframe 的类型验证方案无法处理它们,§4.10: Verification of class Files 写道:

Verification by type checking must be used to verify class files whose version number is greater than or equal to 50.0.

或在 §4.10.1: Verification by Type Checking 中更详细地说明:

A class file whose version number is 50.0 or above (§4.1) must be verified using the type checking rules given in this section.

If, and only if, a class file's version number equals 50.0, then if the type checking fails, a Java Virtual Machine implementation may choose to attempt to perform verification by type inference (§4.10.2).

所以我想说 50.0 版本的类可能仍然包含jsrret,但存在 JVM 实现无法实现的风险' t 验证所述类,因此将无法加载它。

但后来我在 §4.9.1: Static Constraints 中发现了一个更明确的规则:

Only instances of the instructions documented in §6.5 may appear in the code array. Instances of instructions using the reserved opcodes (§6.2) or any opcodes not documented in this specification must not appear in the code array.

If the class file version number is 51.0 or above, then neither the jsr opcode or the jsr_w opcode may appear in the code array.

第一段与这个问题无关,因为说明在 §6.5 中列出,并且根据 §6.2 没有保留。但第二段明确将它们标记为在 51.0 及更高版本中禁止使用。另一方面,ret 操作码在没有 jsrjsr_w 的情况下是无用的,因为只有这两条指令可以创建类型为 returnAddress 的堆栈元素(并通过一些 astore 该类型的局部变量)由 ret 使用。


我仍然认为应该在 §6.5 中包含一些与此相关的通知。不幸的是,如果选择类型:错误,类别:Java 平台标准版,子类别:规范<,Java bug report webpage 会隐藏继续按钮/em>。它指出

This subcategory is for reporting technical errors and ambiguities in the text of the Java Language Specification and the JVM Specification. It is not the venue to propose new features in the Java language or JVM. Ongoing feature development is carried out in OpenJDK; corresponding enhancements to the Java Language Specification and the JVM Specification are managed through the Java Community Process.

但是通过 JCP 只是为了在这三个操作码的描述中添加一些澄清说明感觉就像是大材小用。所以我希望这篇文章能帮助那些无法在规范本身中找到答案的人。

关于java - JVM 规范中 JSR/RET 的状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37013761/

相关文章:

java - 如何在 Linux 上调试 native Java 崩溃?

java - 为什么 JSR/RET 不推荐使用 Java 字节码?

C# IL 代码修改 - 保持堆栈完整

java - 上传文件excel并用java中的JAX-RS 2.0读取

Java-Stream,带有重复键的 toMap

java - Java 字节码是什么样的?

python - 虚拟机如何渲染GUI?

assembly - 对模拟器进行编程 : How does the emulator understand opcodes from addresses?

java - 为什么我的基本身份验证适用于 POST 而不是 GET 请求?

java - Thymeleaf 表单提交结果出现 404?