Introduction of class loader and class loading process

Java's 3 loaders

  1. Boot class loader BootStrapClassLoader

  2. Extended class loader ExtensionClassLoader

  3. Application class loader ApplicationClassLoader

    The three types of loaders can be simply understood as:

    BootStrapClassLoaderWhat is loaded is the class library of JVM core classes is
    ExtensionClassLoaderloaded is the class library of extended classes
    ApplicationClassLoaderLoads the java class library written by ourselves

Which libraries are loaded by the class loader

jdk1.8 in BootStrapClassLoaderload D:\Program Files\Java\jdk1.8.0_201\jre\libunder

  • resources.jar
  • rt.jar
  • sunrsasign.jar
  • jsse.jar
  • jce.jar
  • charsets.jar
  • jfr.jar
    and D:/Program Files/Java/jdk1.8.0_201/jre/classesfolders under the class file

ExtensionClassLoaderLoad java extension class library
D:\Program Files\Java\jdk1.8.0_201\jre\lib\ext
for example

  • access-bridge-64.jar
  • cldrdata.jar
  • dnsns.jar
  • jaccess.jar
  • jfxrt.jar
  • localedata.jar
  • nashorn.jar
  • sunec.jar
  • sunjce_provider.jar
  • sunmscapi.jar
  • sunpkcs11.jar
  • zipfs.jar


ApplicationClassLoaderLoad application class

The process of java application startup:

  1. First, the .javafile is compiled into a .classfile by javac .
  2. When we start java程序, the .classfile is loaded into memory through the class loading subsystem, which is divided into three loaders ( BootStrapClassLoader、ExtensionClassLoader、ApplicationClassLoader).
    First, you need to load the java-based class library (described above), that is, BootStrapClassLoaderload the java class library, when the boot class loader is loaded, then ExtensionClassLoaderload the extended class library, and then ApplicationClassLoaderload the class where the main method is located into the memory .
    In the process of running the program will be used in other types of documents, loaded in addition to the main method that category, there is a parent delegation mechanism classes and sandbox mechanism , it can be simply understood as the first inquiry BootStrapClassLoaderthere will be classes loaded into memory, if not Then ask if ExtensionClassLoaderthis class has been loaded into memory. If it has not been loaded before, it will be used ApplicationClassLoaderfor loading. BootStrapClassLoader、ExtensionClassLoaderThe class path they load is fixed, so the classes they load are also relatively fixed (unless they put their classes under the class library path).
  3. The class loading subsystem is further divided into: loading, linking, and initialization .
    The class loaded into the memory will be loaded, verified, prepared, parsed, initialized ( 主要是 静态成员变量、静态代码块 的初始化), and loaded into the memory after the initialization is complete
After completing the above actions, even if the application is started, the rest is the life cycle of the application

Guess you like

Origin blog.csdn.net/qq_41813208/article/details/108577391