Java 类加载器:定义加载器和启动加载器的区别?

Java classloader: difference between defining loader & initiating loader?

来自JVMS

A class loader L may create C by defining it directly or by delegating to another class loader. If L creates C directly, we say that L defines C or, equivalently, that L is the defining loader of C.

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.

我对这些有点困惑。

假设我们有两个 class 加载器:L 和 Lp,Lp 是 L 的父级。

如果C在L中定义并且被L成功创建,那么L既是C的定义加载器又是初始化加载器,是对吗?

如果C在L中定义但由Lp创建,我猜Lpinitiating loader 的 C?
但是 C 的 定义加载程序 是什么?因为 C 是在 L 中定义的,但不是由它直接创建的?这是个问题。

感谢所有回复。

Class加载器通常遵循委托机制。

假设委托层次结构是 L->Lp->Lq 并且 class 定义在 Lp
在这种情况下,
L 会将 class 加载委托给 Lp,
Lp 将委托给 Lq
Lq 不会加载 class 并且调用 return 返回 Lp
Lp 将加载 class,因为它是在 Lp 中定义的,调用 return 返回到 L

这里 LpL 是初始 class 加载程序,Lp 是定义 class 加载程序。

类似地,如果委托层次结构是 L->Lp 并且 class 在 L 中定义,
L 成为定义和启动 class 加载程序。
Lp 不是启动 class 加载器。

简单地说,如果 class 加载器能够 return 对委托链中 Class 实例的引用,它是一个启动 class装载机。