当前位置:网站首页>Virtual machine class loading mechanism
Virtual machine class loading mechanism
2022-06-25 17:44:00 【[email protected]】
List of articles
1. Class load time

Class must be initialized 5 In this case :
- encounter new、getstatic、putstatic、invokestatic this 4 Bytecode instructions , If the class is not initialized , You need to trigger its initialization
- Use java.lang.reflect When a package's method makes a reflection call to a class , If the class is not initialized , You need to trigger its initialization
- When initializing a class , Its parent class has not been initialized , You need to trigger the initialization of its parent class first
- When the virtual machine starts , The user needs to specify a main class to execute ( contain main Class of method ), Virtual opportunity initializes the main class first
- When using JDK1.7 Dynamic language support for , If one java.lang.invoke.MethodHandle The final parsing result of the example REF_getStatic,REF_putStatic,REF_invokeStatic Method handle for , And the class corresponding to this method handle has not been initialized , You need to trigger its initialization first
Be careful :
- For static fields , Only classes that directly define this field will be initialized , Reference the static fields defined in the parent class through its subclasses , Only the initialization of the parent class will be triggered , Does not trigger subclass initialization
- Define reference classes through arrays , Initialization of this class will not be triggered
- Constants are stored in the constant pool of the unused class during compilation , In essence, there is no direct reference to the class defining constant , So it doesn't trigger the initialization of the class that defines the constant
- When a class is initialized, its parent class must have been initialized , But when an interface is initialized , It is not required that all its parent classes have been initialized , It is initialized only when the parent interface is actually used
2. The process of class loading
2.1 load
- load yes Class loading A stage in the process
During the loading phase, the virtual machine needs to complete 3 thing :
- Get the binary byte stream that defines this class through the fully qualified class name of a class
- Convert the static storage structure represented by the byte stream into the runtime data structure of the method area
- Generate a representation of this class in memory java.lang.Class object , As the access to all kinds of data of this class in method area
2.2 verification
- Verification is the first step in the connection phase , The purpose is to make sure that Class The information contained in the byte stream of the file meets the requirements of the current virtual machine
- File format validation
- Metadata validation
- Bytecode verification
- Compliance with reference validation
2.3 Get ready
- The preparation stage is officially for Class variables The stage of allocating memory and setting the initial value of class variables , The memory used by these variables will be allocated in the method area
2.4 analysis
- The parsing phase is the process in which the virtual machine replaces the symbolic reference in the constant pool with a direct reference
2.5 initialization
- The class initialization phase is the last step in the class loading phase
3. Class and class loader
- Even if two classes come from the same Class file , Loaded by the same virtual machine , As long as the classloaders that load them are different , Then the two classes must not be equal ( Representative class of equality Class Object's equals Method 、isInstance Method , It also includes the use of instanceOf Keyword is used to judge the relationship of the object )
4. Parent delegation model
- from Java From a virtual machine perspective, there are only two different class loaders : Start class loader and Other class loaders
To subdivide :
- Start class loader
- Extended class loader
- Application class loader

- The two parent delegation model requires in addition to the top-level bootloader , The rest of the class loaders should have their own parent class loaders
The working process of the parent delegation model :
If a class loader receives a class load request , It doesn't try to load the class itself first , Instead, delegate the request to the parent loader to complete , This is true of class loaders at every level , Therefore, all load requests should eventually be sent to the top-level startup class loader , Only when the parent loader reports that it is unable to complete the request , Sub loader will try to load by itself
benefits :
Java Class has a hierarchical relationship with priority along with its classloader , such as Object class , No matter which class the loader is , Finally, it is delegated to the top boot class loader to load , therefore Object Class is a class in the various classloader environments of a program ; contrary , If you don't use the parental delegation model , The user writes his own class loader to load Object class , There will be many different Object class
版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202190532337798.html
边栏推荐
- RuntimeError: Trying to backward through the graph a second time (or directly access saved variable
- 【UVM实战 ===> Episode_1 】~ MCDF设计更新、AMBA标准接口、UVM验证环境更新
- Mobx学习之路----强大的“状态管理工具”
- ACY100油烟浓度在线监控仪针对饮食业厨房油烟排放
- Vscode automatically generates ifndef define ENDIF of header file
- 大学生暑假换机热,ROG 明星产品幻 16 翻转版 / 幻 13 / 幻 X 预约
- 【Matlab】数值微积分与方程求解
- mvdr波束 matlab,mvdr波束形成matlab[通俗易懂]
- C语言中%含义
- 相同wifi下,笔记本连接台式机上的虚拟机
猜你喜欢
![[UVM practice== > episode_1] ~ MCDF design update, AMBA standard interface, UVM verification environment update](/img/22/0c13e98e634a99d1680dd4bb12eaef.png)
[UVM practice== > episode_1] ~ MCDF design update, AMBA standard interface, UVM verification environment update

Three traversal methods of binary tree (recursive + non recursive) complete code

什么是算子?

【 NLP 】 in this year's English college entrance examination, CMU delivered 134 high scores with reconstruction pre training, significantly surpassing gpt3

Encryption trend: Fashion advances to the meta universe

DDD concept is complex and difficult to understand. How to design code implementation model in practice?

Acy100 oil fume concentration online monitor for kitchen oil fume emission in catering industry

About Equilibrium - Simplified bottleneck model

HMS Core机器学习服务实现同声传译,支持中英文互译和多种音色语音播报

Langage d'assemblage (5) Registre (accès à la mémoire)
随机推荐
Huawei cloud gaussdb (for redis) unveiling issue 19: gaussdb (for redis) comprehensive comparison with CODIS
什么是公链开发?公链开发项目有哪些?
Jerry's system clock setting is reset or invalid [chapter]
Garbage collector and memory allocation strategy
HMS Core机器学习服务实现同声传译,支持中英文互译和多种音色语音播报
Accumulation of some common knowledge points
使用DiskGenius拓展系統盤C盤的容量
[efficiency] another note artifact is open source!
相同wifi下,笔记本连接台式机上的虚拟机
Vscode automatically generates ifndef define ENDIF of header file
十大龙头券商 办理开户安全吗
20 provinces and cities announce the road map of the meta universe
Expressing integers by the sum of consecutive natural numbers
深入理解ELF文件
TLV decoding
win10安装cuda的操作步骤(不断完美中)
【Matlab】数值微积分与方程求解
golang list to string
bert之我的小总结
IDEA全局搜索汉字[通俗易懂]