当前位置:网站首页>jvm类加载过程简介说明
jvm类加载过程简介说明
2022-07-24 03:36:00 【qq_25073223】
转自:
下文笔者将简介JVM 将class文件加载到内存的整个过程简介说明,如下所示:
类加载的过程主要分为三个部分: 加载,链接,初始化 而链接又可以细分为三个小部分: 验证,准备,解析
加载
加载:将class字节码文件从各个来源通过类加载器装载入内存中 将class文件字节码内容加载到内存中 并将这些静态数据转换成方法区中的运行时数据结构 在堆中生成一个代表这个类的java.lang.Class对象 作为方法区类数据的访问入口
链接
将java类的二进制代码合并到jvm的运行状态之中的过程
验证
确保加载的类信息符合jvm规范,没有安全方面的问题。 对于文件格式的验证,比如常量中是否有不被支持的常量?文件中是否有不规范的或者附加的其他信息? 对于元数据的验证,比如该类是否继承了被final修饰的类?类中的字段,方法是否与父类冲突?是否出现了不合理的重载? 对于字节码的验证,保证程序语义的合理性,比如要保证类型转换的合理性。 对于符号引用的验证,比如校验符号引用中通过全限定名是否能够找到对应的类?校验符号引用中的访问性(private,public等)是否可被当前类访问?
准备
正式为类变量(static变量)分配内存并设置类变量初始值的阶段,这些内存都将在方法区中进行分配 特别需要注意,初值,不是代码中具体写的初始化的值,而是Java虚拟机根据不同变量类型的默认初始值 比如8种基本类型的初值,默认为0;引用类型的初值则为null;常量的初值即为代码中设置的值,final static tmp = 456, 那么该阶段tmp的初值就是456
解析
虚拟机常量池内的符号引用替换为直接引用的过程 (如String s ="java265",转化为 s的地址指向"java265"的地址)
初始化
此阶段主要是对类变量初始化,执行类构造器的过程 (只对static修饰的变量或语句进行初始化) 当初始化一个类的时候,其父类尚未初始化,则优先初始化其父类 当同时包含多个静态变量和静态代码块,则按照自上而下的顺序依次执行 当访问一个java类的静态域时,只有真正声明这个静态变量的类才会被初始化
边栏推荐
- Exttestngireporterlistener all codes
- The local picture cannot be displayed after the uniapp H5 is packaged
- 08 reptile project
- 水题: 接雨水
- Bet on the whole scene, what is the odds of glory?
- You must know the ten vulnerabilities of invalid access control
- Outlook client outlook.com mailbox setting method
- Developers share mindspire Lite experience, one click image segmentation
- How will you answer the "Hello world" challenge written in C language?
- QT custom class uses custom parametric signals and slots
猜你喜欢

Developers share mindspire Lite experience, one click image segmentation

正則錶達式 \b \B 深入淺出理解單詞邊界的匹配

CVE-2022-29464 WSO2文件上传漏洞

4.合宙Air32F103_LCD

SolidWorks CAM data cannot be recovered because a processed part has been detected.

RTOS internal skill cultivation (10) | in depth analysis of RTOS kernel context switching mechanism

C語言經典練習題(2)——“冒泡排序(Bubble Sort)“

Emqx v4.4.5 Publishing: new exclusive subscriptions and mqtt 5.0 publishing attribute support

Hcip day 9 notes (OSPF routing feedback, routing policy, and Configuration Guide)

Bingbing learning notes: basic operation of vim tool
随机推荐
Qt自定义类使用自定义含参信号与槽
SkyWalking分布式系统应用程序性能监控工具-上
Jump statement in day011 loop structure
Skywalking distributed system application performance monitoring tool - upper
Leetcode Hot 100 (topic 8) (232/88/451/offer10/offer22/344/)
How to write selenium's testng.xml
错误代码0x80004005
Appendtofile append failed
[wepy2.0] installation
21st day of written test mandatory training
Introduction to pytorch ecology
JS 数组 isAarray() typeof
What are Caicai and qiniu doing? Is it safe to open an account?
Tetris, 1
JS array isaarray() typeof
Gpushare.com | 如何使用TensorBoardX可视化工具?
How to implement desktop lyrics in pyqt
Data Lake: introduction to Apache Hudi
Idea failed to load resource: the server responded with a status of 404 (not found)
Read and understand the advantages of the LAAS scheme of elephant swap