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:
- ClassLoader is the top class of the ClassLoader in a Java program
- ExtClassLoader and ApppClassLoader are derived from the ClassLoader class
- Bootstrap ClassLoader is not included
2. Classification of class loading
- The JVM supports two types of class loaders, Bootstrap and User-defined classloaders.
- 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.
- 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).
- This class loading is implemented in C/C++ and is nested within the JVM.
- 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 - Does not inherit from java.lang. ClassLoader and has no parent loader
- Bootstrap ClassLoade loads extension classes and application class loaders and specifies them as parent class loaders.
- 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
- Java language, implemented by sun.misc.Launcher$ExtClassLoader.
- Derived from the ClassLoader class
The parent class loader is the initiator class loader
- 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)
- Java language, derived from the ClassLoader class from the Sun.misc. Launcher$AppClassLoader implementation
The AppClassloader is loaded by the boot class loader
- It is responsible for loading libraries in the path specified by the environment variable Classpath or the system property java.class.path.
- Class loading is the default class loader in a program, and it is generally used to load classes in Java applications
- Through this. GetsystemClassLoader () method can get the class loader
6. User-defined ClassLoader Custom ClassLoader
- If necessary, we can also customize class loaders to customize how classes are loaded.
- 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
- All classes are loaded into the runtime data area by the class loader
- Different classes require different class loaders to load
- For the purpose of
security
- 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