当前位置:网站首页>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类的静态域时,只有真正声明这个静态变量的类才会被初始化
边栏推荐
- Ue5 split screen (small map) solution
- Simulink code generation: variable subsystem and its code
- Write code, and multiple characters move from both ends to converge in the middle
- IO stream sorting
- Introduction to pytorch ecology
- C language classic exercises (2) - "bubble sort"“
- uniapp H5打包后本地图片无法显示问题
- Embedded system transplantation [5] - Cross compilation tool chain
- Tetris, 1
- C語言經典練習題(2)——“冒泡排序(Bubble Sort)“
猜你喜欢

SolidWorks cannot reference references

Idea failed to load resource: the server responded with a status of 404 (not found)

Talk about the application of FIFO

Programmers may still be programmers, and coders may only be coders

Developers share mindspire Lite experience, one click image segmentation

Genesis public chain: Tamp the foundation of Web 3.0 development

Convert the pseudo array returned by childNodes into a true array
![[JS reverse hundred examples] a public resource trading network, reverse analysis of announcement URL parameters](/img/0b/3645a0a8ec677f96427b35bd371e7e.png)
[JS reverse hundred examples] a public resource trading network, reverse analysis of announcement URL parameters

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

Shengsi YiDianTong | deep learning analysis of classical convolutional neural network
随机推荐
New definition of mobile communication: R & scmx500 will improve the IP data throughput of 5g devices
Istio architecture extension mechanism
Batch visual target detection callout box -- Yolo format dataset
What is IMU?
STL multimap
4. Hezhou air32f103_ LCD
Do the right thing, do it right
Simulink代码生成: 可变子系统及其代码
How to implement desktop lyrics in pyqt
08 reptile project
Secondary development of ArcGIS JS API -- loading national sky map
buu web
JS 數組 isAarray() typeof
C語言經典練習題(2)——“冒泡排序(Bubble Sort)“
Leetcode-382. random nodes of linked list
Embedded system transplantation [5] - Cross compilation tool chain
Binary tree traversal (day 74)
MySQL学习——MySQL软件的安装及环境配置(Windows)详细!
Regular expression \b \b understand word boundary matching in simple terms
JIRA automation experience sharing for 2 years