V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
JasonLaw
V2EX  ›  Java

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

  •  
  •   JasonLaw · 2020-09-11 15:01:04 +08:00 · 1077 次点击
    这是一个创建于 1334 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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 中的类型信息也是同一个。

    请问我的理解正确吗?

    第 1 条附言  ·  2020-09-14 17:32:02 +08:00
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1436 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 23:45 · PVG 07:45 · LAX 16:45 · JFK 19:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.