I am just revisiting the JVM concepts and was try to do a delegation check. Consider the below code
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;
}
}
Output
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
I am expecting the BootstrapClassLoader as well from what I've read online, not sure of this.
I am using adopt-openjdk-with-openj9-jvm
and JDK version is jdk8u212-b03
Bootstrap class loader has no corresponding java.lang.ClassLoader
object; its implementation is inside JVM. Otherwise who will load java.lang.ClassLoader
class?
As the specification of ClassLoader.getParent
says,
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 is exactly such implementation.