A: 019 – the JVM – class loading process at https://yuhongliang.blog.csdn.net/article/details/111499604

1. Package Sun.misc.Launcher is a portal application for the Java VIRTUAL machine

Let’s take a look at the code level integration of ClassLoader:



Here are three points:

  1. ClassLoader is the top class of the ClassLoader in a Java program
  2. ExtClassLoader and ApppClassLoader are derived from the ClassLoader class
  3. Bootstrap ClassLoader is not included

2. Classification of class loading

  1. The JVM supports two types of class loaders, Bootstrap and User-defined classloaders.
  2. Conceptually, custom classloaders are typically a class of class loaders defined by the developer in a program, but the Java Virtual Machine specification does not define them this way. Instead, it classifies all classloaders derived from the abstract ClassLoader as custom classloaders.
  3. Regardless of the class loader type, we have only three of the most common loaders in our programs.

    The relationship between the four,Not a descender, not a descender from a subclass to a superclass.

3. The built-in loader of the VM starts the class loader (Bootstrap ClassLoade).

  1. This class loading is implemented in C/C++ and is nested within the JVM.
  2. It is used to load Java’s core libraries (java-home /jre/lib/)rt.jar, cesources.jar, or sun.boot.class.path) to provide classes that the JVM itself needs
  3. Does not inherit from java.lang. ClassLoader and has no parent loader
  4. Bootstrap ClassLoade loads extension classes and application class loaders and specifies them as parent class loaders.
  5. For security reasons, Bootstrap starts the class loader to load only classes whose package names start with Java, javax.sun, and so on

4. Extension ClassLoader

  1. Java language, implemented by sun.misc.Launcher$ExtClassLoader.
  2. Derived from the ClassLoader class
  3. The parent class loader is the initiator class loader
  4. Load the class libraries from the directory specified by the java.ext.dirs system property, or from the IRE /lib/ext subdirectory (extension directory) of the JDK installation directory.If user-created jars are placed in this directory, they will also be automatically loaded by the extended class loader.

5. Application class loader (System class loader, AppClassloader)

  1. Java language, derived from the ClassLoader class from the Sun.misc. Launcher$AppClassLoader implementation
  2. The AppClassloader is loaded by the boot class loader
  3. It is responsible for loading libraries in the path specified by the environment variable Classpath or the system property java.class.path.
  4. Class loading is the default class loader in a program, and it is generally used to load classes in Java applications
  5. Through this. GetsystemClassLoader () method can get the class loader

6. User-defined ClassLoader Custom ClassLoader

  1. If necessary, we can also customize class loaders to customize how classes are loaded.
  2. Why custom class loaders?
  • Isolation load class
  • Modify the way classes are loaded
  • Extended load source
  • Preventing source code leakage

Example 7.



8. To summarize

  1. All classes are loaded into the runtime data area by the class loader
  2. Different classes require different class loaders to load
  3. For the purpose ofsecurity
  4. Safety is preserved core classes are not user malicious pollution next article: https://yuhongliang.blog.csdn.net/article/details/111565510 021 – JVM – parents delegate mechanism