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

关于“Inside the Java Virtual Machine - Chapter 8 - The Linking Model - Class Loaders and the Parent-Delegation Model”的疑问

  •  
  •   JasonLaw · 2020-09-08 10:02:18 +08:00 · 1005 次点击
    这是一个创建于 1541 天前的主题,其中的信息可能已经有所发展或是发生改变。

    Inside the Java Virtual Machine - Chapter 8 - The Linking Model - Class Loaders and the Parent-Delegation Model中,有如下这么一段:

    In Java terminology, a class loader that is asked to load a type, but returns a type loaded by some other class loader, is called an initiating class loader of that type. The class loader that actually defines the type is called the defining class loader for the type. In the previous example, therefore, the defining class loader for java.io.FileReader is the bootstrap class loader. Class Cindy is an initiating class loader, but so are Mom, Grandma, and even the bootstrap class loader. Any class loader that is asked to load a type and is able to return a reference to the Class instance representing the type is an initiating loader of that type.

    "a class loader that is asked to load a type, but returns a type loaded by some other class loader, is called an initiating class loader of that type"和"Any class loader that is asked to load a type and is able to return a reference to the Class instance representing the type is an initiating loader of that type"是不是有点矛盾?

    假设 parent-delegation chain 是"L -> Lp -> bootstrap",应用请求 class loader L 加载 java.io.FileReader,L 会 delegate 给 Lp,Lp 会 delegate 给 bootstrap,bootstrap 会成功加载并返回 Class instance 给 Lp,然后 Lp 返回 Class instance 给 L 。

    按照上面的例子,我理解的话,“a class loader that is asked to load a type, but returns a type loaded by some other class loader, is called an initiating class loader of that type”意味着“L 和 Lp 是 initiating class loader,而 bootstrap 不是,因为 type 就是被 bootstrap 加载的,不满足 returns a type loaded by some other class loader”。而“Any class loader that is asked to load a type and is able to return a reference to the Class instance representing the type is an initiating loader of that type”则意味着“L 、Lp 和 bootstrap 都是 initiating class loader”。这是书本的错误吗?

    Chapter 5. Loading, Linking, and Initializing - 5.3. Creation and Loading也说了“When one class loader delegates to another class loader, the loader that initiates the loading is not necessarily the same loader that completes the loading and defines the class. If L creates C, either by defining it directly or by delegation, we say that L initiates loading of C or, equivalently, that L is an initiating loader of C.”。

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5314 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 05:45 · PVG 13:45 · LAX 21:45 · JFK 00:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.