我对 JVM 的 Loading Constraints 理解正确吗?
資深大佬 : JasonLaw 7
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 中的类型信息也是同一个。
请问我的理解正确吗?
大佬有話說 (0)