V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
JasonLaw
V2EX  ›  Java

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

  •  
  •   JasonLaw · Sep 11, 2020 · 1515 views
    This topic created in 2066 days ago, the information mentioned may be changed or developed.

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

    请问我的理解正确吗?

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2517 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 00:28 · PVG 08:28 · LAX 17:28 · JFK 20:28
    ♥ Do have faith in what you're doing.