我对 JVM 的 Loading Constraints 理解正确吗?

2020-09-11 15:01:04 +08:00
 JasonLaw

Java Virtual Machine Specification - Chapter 5. Loading, Linking, and Initializing - 5.3. Creation and Loading - 5.3.4. Loading Constraints介绍了 Loading Constraints 。

假设有如下代码:

class Cat {
    public static void main(String[] args) {
        System.out.println(Mouse.ct);
    }
}
class Mouse {
    public static final CustomType ct = new CustomType();
}
class CustomType {}

Cat使用了Mouse.ct,所以它的常量池会包含指向CustomType的一个 symbolic reference 。Mouse定义了public static final CustomType ct,所以它的常量池也会包含指向CustomType的一个 symbolic reference 。

我理解的 Loading Constraints 是:如果 class loader L1 发起对Cat的加载,class loader L2发起对Mouse的加载。关于两者常量池中都包含的指向CustomType的 symbolic reference,最后要保证 L1 和 L2 所获得的 java.lang.Class instance 是同一个,而且 java.lang.Class instance 所关联的 method area 中的类型信息也是同一个。

请问我的理解正确吗?

1119 次点击
所在节点    Java
0 条回复

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/706171

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX