BootstrapClassLoader 未在委托模型中加载
BootstrapClassLoader not loading in the Delegation Model
我只是重新审视 JVM 概念并尝试进行委托检查。考虑下面的代码
public class SrkDelegationDemo {
public static void main(String[] args) {
ClassLoader cl = ClassLoader.getSystemClassLoader();
while (true) {
System.out.println("ClassLoader is " + cl);
ClassLoader parent = cl.getParent();
if (parent == null) {
System.out.println("Last Classloader which has no parent = " + cl);
// This line should print Bootstrap
break;
}
cl = parent;
}
}
输出
ClassLoader is sun.misc.Launcher$AppClassLoader@ab770638
ClassLoader is sun.misc.Launcher$ExtClassLoader@75c10082
Last Classloader which has no parent = sun.misc.Launcher$ExtClassLoader@75c10082
根据我在网上阅读的内容,我也期待 BootstrapClassLoader,但不确定。
我正在使用 adopt-openjdk-with-openj9-jvm
和 JDK 版本是 jdk8u212-b03
Bootstrap class加载器没有对应的java.lang.ClassLoader
对象;它的实现在 JVM 内部。不然谁来加载java.lang.ClassLoader
class?
正如 ClassLoader.getParent
的规范所说,
Some implementations may use null to represent the bootstrap class
loader. This method will return null in such implementations if this
class loader's parent is the bootstrap class loader.
OpenJDK 正是这样的实现。
我只是重新审视 JVM 概念并尝试进行委托检查。考虑下面的代码
public class SrkDelegationDemo {
public static void main(String[] args) {
ClassLoader cl = ClassLoader.getSystemClassLoader();
while (true) {
System.out.println("ClassLoader is " + cl);
ClassLoader parent = cl.getParent();
if (parent == null) {
System.out.println("Last Classloader which has no parent = " + cl);
// This line should print Bootstrap
break;
}
cl = parent;
}
}
输出
ClassLoader is sun.misc.Launcher$AppClassLoader@ab770638
ClassLoader is sun.misc.Launcher$ExtClassLoader@75c10082
Last Classloader which has no parent = sun.misc.Launcher$ExtClassLoader@75c10082
根据我在网上阅读的内容,我也期待 BootstrapClassLoader,但不确定。
我正在使用 adopt-openjdk-with-openj9-jvm
和 JDK 版本是 jdk8u212-b03
Bootstrap class加载器没有对应的java.lang.ClassLoader
对象;它的实现在 JVM 内部。不然谁来加载java.lang.ClassLoader
class?
正如 ClassLoader.getParent
的规范所说,
Some implementations may use null to represent the bootstrap class loader. This method will return null in such implementations if this class loader's parent is the bootstrap class loader.
OpenJDK 正是这样的实现。