gpt4 book ai didi

java - JVM字节码验证者的职责

转载 作者:IT老高 更新时间:2023-10-28 21:00:26 25 4
gpt4 key购买 nike

有人可以列出字节码 validator 必须执行以保证程序正确性的主要任务吗? JVM 规范中是否定义了一组标准的、最小的职责?我还想知道验证是否跨越其他阶段,例如加载和初始化。

最佳答案

这是在 JVM Specification: Chapter 4.10. Verification of class Files 中指定的.

页面的大部分内容描述了类型安全的各个方面。要检查程序是否是类型安全的,验证程序需要确定每个程序点的操作数堆栈中的操作数类型,并确保它们与相应指令所期望的类型相匹配。

它验证的其他内容包括但不限于以下内容:

  • Branches must be within the bounds of the code array for the method.

  • The targets of all control-flow instructions are each the start of an instruction. In the case of a wide instruction, the wide opcode is considered the start of the instruction, and the opcode giving the operation modified by that wide instruction is not considered to start an instruction. Branches into the middle of an instruction are disallowed.

  • No instruction can access or modify a local variable at an index greater than or equal to the number of local variables that its method indicates it allocates.

  • All references to the constant pool must be to an entry of the appropriate type. (For example, the instruction getfield must reference a field.)

  • The code does not end in the middle of an instruction.

  • Execution cannot fall off the end of the code.

  • For each exception handler, the starting and ending point of code protected by the handler must be at the beginning of an instruction or, in the case of the ending point, immediately past the end of the code. The starting point must be before the ending point. The exception handler code must start at a valid instruction, and it must not start at an opcode being modified by the wide instruction.

作为最后一步, validator 还执行数据流分析,以确保没有指令引用任何未初始化的局部变量。

关于java - JVM字节码验证者的职责,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10562876/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com