当前位置:网站首页>[JVM] detailed description of the process of creating objects
[JVM] detailed description of the process of creating objects
2022-07-02 02:49:00 【A Xiaobing】
Preface
Development process , We must often create an object , Don't say you don't know , To create an object, you should first think of new, and you? new It's cool , But you know you are so new once , How did you create this object ? Do you know the principle ? It doesn't matter if I don't know , Next, let's explain it in combination with the figure
Detailed steps
1、JVM Received our new Instructions
First, I will check the quilt new Whether this parameter of can locate the symbolic reference of this class in the constant pool , And also check whether the class referenced by this symbol has been loaded 、 analysis 、 initialization
2、 Check whether the current class has been initialized
If this class has been initialized , Then proceed to the following serial number 3 Steps for , Otherwise, you need to load the class first
3、 Allocate memory
After the class load verification passes , Then the memory allocation of new objects will be carried out
4、 Confirm the memory size
The memory size required for object generation can be determined when the class is loaded , Allocating space for an object is equivalent to transferring a certain amount of memory from Java Divide it up in the heap
5、 Allocated memory size
There are two main situations
(1)JVM The memory is regular , All memory used is put aside , The free memory is on the other side , Put a pointer in the middle as an indicator of the dividing point , In this case , It is easier to allocate memory , At that time, you just need to put the pointer 2 Point to the free memory and move a distance equal to the size of the object , This is what is often said “ Pointer collision ”
(2)JVM Memory of is irregular , It is equivalent to that the used memory and unused memory are staggered with each other , In this case, there is no way to achieve pointer collision , So what should we do ? Only one table needs to be maintained , To record the information available in memory , When allocating, find enough space in the list to allocate to the object instance and update the memory state in the record table
6、 initialization
After the above memory space is allocated ,JVM You need to initialize the memory space to 0, There are also steps in the picture TLAB, If you use TLAB, You can go to TLAB The initialization can be carried out during allocation
7、 Basic information settings
JVM Make the necessary Settings for the object , For example, hash code 、 Memory address and other information
8、 Generate executable objects
Here we need to execute init Method , Initialize the object according to the initialization operation set in the program , At this time, an object is really initialized , Created a virtual machine executable java type
边栏推荐
- [learn C and fly] 2day Chapter 8 pointer (practice 8.1 password unlocking)
- MVVM and MVC
- [opencv] - comprehensive examples of five image filters
- 2022 safety officer-c certificate examination questions and mock examination
- After marriage
- LFM信号加噪、时频分析、滤波
- Multi threaded query, double efficiency
- Après le mariage
- How to batch add background and transition effects to videos?
- What is the function of the headphone driver
猜你喜欢

Special symbols in SAP ui5 data binding syntax, and detailed explanation of absolute binding and relative binding concepts

Pychart creates new projects & loads faster & fonts larger & changes appearance

Batch detect whether there is CDN in URL - high accuracy

Which kind of sports headphones is easier to use? The most recommended sports headphones

使用 useDeferredValue 进行异步渲染

Connected block template and variants (4 questions in total)

Golang configure export goprivate to pull private library code

AcWing 245. Can you answer these questions (line segment tree)

Coordinatorlayout + tablayout + viewpager2 (there is another recyclerview nested inside), and the sliding conflict of recyclerview is solved

LFM信号加噪、时频分析、滤波
随机推荐
Redis cluster
how to come in an investnent bank team
Rotating frame target detection mmrotate v0.3.1 learning model
Is bone conduction earphone better than traditional earphones? The sound production principle of bone conduction earphones is popular science
Vsocde has cli every time it is opened js
Which kind of sports headphones is easier to use? The most recommended sports headphones
Multi threaded query, double efficiency
2022-2028 global aluminum beverage can coating industry research and trend analysis report
Infix expression to suffix expression (computer) code
tarjan2
旋转框目标检测mmrotate v0.3.1 学习模型
[learn C and fly] 4day Chapter 2 program in C language (exercise 2.5 generate power table and factorial table
Decipher the AI black technology behind sports: figure skating action recognition, multi-mode video classification and wonderful clip editing
Query word weight, search word weight calculation
2022-2028 global nano abrasive industry research and trend analysis report
使用开源项目【Banner】实现轮播图效果(带小圆点)
What is the difference between an intermediate human resource manager and an intermediate economist (human resources direction)?
附加:信息脱敏;
What are the characteristics of common web proxy IP
[learn C and fly] 1day Chapter 2 (exercise 2.2 find the temperature of Fahrenheit corresponding to 100 ° f)
