In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "the loading process of JVM class and the case sharing of parent delegation model". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn "the loading process of the JVM class and the case sharing of the parent delegation model".
Class loading process
The class loading process loads the class description data from the .class file into memory for JVM, parses and initializes the data, and finally forms the Java type that is directly used by JVM. Contains:
Load: gets the binary byte stream of this class and converts the static storage structure represented by the byte stream into the run-time data structure of the method area And generate the java.lang.Object object representing the class in memory as the access entry of the method area to verify: ensure that the information symbols contained in the byte stream of the Class file are currently required by the virtual machine (file format verification, metadata verification, bytecode verification, Ready to allocate memory for class variables and set the initial value resolution of class variables: replace symbolic references in the constant pool with direct reference initialization: execute the class constructor () method
Class loader
The loading operation in the process of class loading is completed by class loading. Class loaders are divided into:
Launch classloader / Bootstrap ClassLoader: responsible for loading all classes in the JAVA_HOME/lib directory, or classes in the path specified by the option-Xbootcalsspath; extended classloader / ExtClasLoader: responsible for loading all types in the JAVA_HOME/lib/ext directory, or all types in the path specified by the parameter-Xbootclasspath Application classloader / AppClassLoader: responsible for loading all types of custom loaders under the user classpath ClassPath: all classloaders that inherit the abstract class java.lang.ClassLoader
Parental delegation model
Parent delegation process: when a class loader receives a class load task, it immediately delegates the task to its parent class loader to execute until it is delegated to the top-level startup class loader. If the parent class loader cannot load the class delegated to it, the class loading task is returned to its next level loader for execution.
The biggest advantage of the parent delegation model is that it gives the Java class a hierarchical relationship with its classloader with priority. For example, if we want to load the top-level Java class, the java.lang.Object class, no matter which class loader we use to load the Object class, the load request will eventually be delegated to the startup class loader (Bootstrap ClassLoader), which ensures that all the Object classes loaded by the loader are the same class. If there is no parent delegation model, two different Object classes, Wupx::Object and Huyx::Object, will appear.
Case study of parental delegation model
The loadClass () method of java.lang.ClassLoader
Protected Class loadClass (String name, boolean resolve) throws ClassNotFoundException {synchronized (getClassLoadingLock (name)) {/ / First, check if the class has already been loaded Class c = findLoadedClass (name); if (c = = null) {long t0 = System.nanoTime () Try {if (parent! = null) {c = parent.loadClass (name, false);} else {c = findBootstrapClassOrNull (name) } catch (ClassNotFoundException e) {/ / ClassNotFoundException thrown if class not found / / from the non-null parent class loader} if (c = = null) {/ / If still not found, then invoke findClass in order / / to find the class. Long T1 = System.nanoTime (); c = findClass (name); / / this is the defining class loader; record the stats sun.misc.PerfCounter.getParentDelegationTime (). AddTime (T1-T0); sun.misc.PerfCounter.getFindClassTime (). AddElapsedTimeFrom (T1); sun.misc.PerfCounter.getFindClasses (). Increment () }} if (resolve) {resolveClass (c);} return c;}}
At this point, I believe you have a deeper understanding of "the loading process of the JVM class and the case sharing of the parent delegation model". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.