JVM验证-什么时候执行? [英] JVM verifierification -when is it performed?

查看:96
本文介绍了JVM验证-什么时候执行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在什么情况下JVM中的验证程序会准确地启动并检查类.我知道这样的一个实例是当您加载类时,但是有时会加载类,然后再进行验证.这就是为什么我想确切地知道什么时候发生.

I would like to know in what situations exactly would the verifier in JVM kick in and check the class. I know one such instance is when you load the class, but sometimes class is loaded and later on verified. That's why I want to know precisely when that happens.

推荐答案

规范(§4.10)指出以下内容:

The spec (§4.10) says the following:

Java虚拟机实现会验证每个类文件 满足链接时的必要约束(第5.4节).

A Java virtual machine implementation verifies that each class file satisfies the necessary constraints at linking time (§5.4).

§5.4定义了链接时间"的确切含义:

§5.4 defines what exactly "linking time" means:

链接类或接口涉及验证和准备 类或接口,其直接超类,其直接超接口, 及其元素类型(如果是数组类型)(如有必要). 类或接口中符号引用的解析是 链接的可选部分.

Linking a class or interface involves verifying and preparing that class or interface, its direct superclass, its direct superinterfaces, and its element type (if it is an array type), if necessary. Resolution of symbolic references in the class or interface is an optional part of linking.

此规范允许实现何时执行的灵活性 进行链接活动(并且由于递归而导致加载), 前提是要保留以下所有属性:

This specification allows an implementation flexibility as to when linking activities (and, because of recursion, loading) take place, provided that all of the following properties are maintained:

A class or interface is completely loaded before it is linked.

A class or interface is completely verified and prepared before it is initialized.

Errors detected during linkage are thrown at a point in the program where some action is taken by the program that might, directly

或间接要求链接到所涉及的类或接口 错误.

or indirectly, require linkage to the class or interface involved in the error.

例如,Java虚拟机实现可以选择执行以下操作: 分别解析类或接口中的每个符号引用 使用时(懒惰"或最新"分辨率),或全部解决 在验证班级时立即(急切"或静态" 解析度).这意味着解决过程可能会继续, 在类或接口初始化之后的某些实现. 无论采用哪种策略,解决过程中都会检测到任何错误 必须扔到程序中的某个位置(直接或间接) 使用对类或接口的符号引用.

For example, a Java virtual machine implementation may choose to resolve each symbolic reference in a class or interface individually when it is used ("lazy" or "late" resolution), or to resolve them all at once when the class is being verified ("eager" or "static" resolution). This means that the resolution process may continue, in some implementations, after a class or interface has been initialized. Whichever strategy is followed, any error detected during resolution must be thrown at a point in the program that (directly or indirectly) uses a symbolic reference to the class or interface.

请注意,事实上,至少Hotspot正在按照所述进行延迟初始化(如果JRockit和co否则,我会感到非常惊讶).

Note as a matter of fact at least Hotspot is doing lazy initialization as described (and I'd be extremely surprised if JRockit and co did otherwise).

来源:

http://docs. oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.10

http://docs. oracle.com/javase/specs/jvms/se7/html/jvms-5.html#jvms-5.4

这篇关于JVM验证-什么时候执行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆