当前位置:网站首页>Object creation
Object creation
2022-07-01 19:41:00 【Chenyu】
5、 Object creation
5.1、 Object storage
After the object is created, it will be stored in the heap , And generate a memory address .

stay JVM Objects in are mainly stored in the heap in three parts :
- Object head : Including the layout of heap objects 、 type 、GC The state of 、 Basic information such as synchronization status and identification hash
- Mark Word: Object's own runtime data ( Hash code 、GC Generational age 、 Thread lock information, etc ). stay 32 position JVM The middle length is 32bit, stay 64 Bit JVM Medium is 64bit.
- Type a pointer :JVM Determine the instance of which class the object is created by the type pointer
- The length of the array ( Array objects )
- The instance data : Store the attribute value of the object
- Alignment filling : Align bytes , Populated data , Not necessary . Is to make the fields appear only in the same CPU In the cache line of
5.2、 Object creation process
Programmers write a class
.java The file is compiled as .class file : First, through Javac Compiler will .java To JVM Loadable .class Bytecode file
① Lexical parser : Separate words by spaces 、 The operator 、 Control symbols and other information , formation token information flow , Pass to the grammar parser .
② Syntax parser : hold token Information flows according to Java Grammar rules assemble idiom tree .
③ semantic analyzer : Check whether the keywords are used properly 、 Whether the type matches 、 Whether the scope is correct, etc .
④ Generated bytecode : Convert the information of the previous steps into bytecode .Class loading check : The virtual machine encountered keywords new, First, check whether the parameter corresponding to this instruction can locate the symbolic reference of this class in the constant pool , And check whether the class represented by this symbolic reference is loaded 、 Parsed and initialized . If not, execute class loading .
Class loading : Place the bytecode file in Java In the virtual machine , Load through class loader . There are three modes of execution , Explain to perform 、JIT Compile implementation 、JIT Compiler and interpreter mixed execution ( Main stream JVM Default execution mode ). The advantage of mixed mode is that the interpreter interprets the execution at startup , Save compilation time .
Make sure that after the class is loaded , The virtual machine allocates memory space for objects , The distribution method is Pointer collision 、 Free list Two kinds of .
- Pointer collision : The memory of the heap is regular , The used memory is divided to one side , The free one is on the other side , Use a pointer in the middle as the demarcation indicator , When allocating, move the point to the idle direction by a corresponding distance
- Free list : Memory is not regular , Fragmented , The virtual machine needs to maintain a list to record which memory is available , Find enough space to allocate , And update the list record .
Creating objects requires thread safety , There are usually two ways
- CAS+ Failure to retry : An implementation of optimistic locking , Suppose there is no conflict to create , Retry in case of conflict .
- TLAB: For each thread in Eden To allocate a piece of memory , When allocating memory, first in TLAB Distribute , Object greater than TLAB When the remaining memory or memory is exhausted , Then use CAS.
Initialize zero value : The virtual machine initializes the allocated memory space to zero , Ensure that the object instance field is Java Can be used without assigning initial value .
Set object header : Object is an instance of which class 、 Find different metadata 、 Hash 、GC Age etc.
perform init Method : Initialize an initial object according to the program design
Through the instant compiler JT Compile bytecode files into local machine code .
Java Programs are initially interpreted and executed through interpreters , When the virtual machine finds that a method or block of code is running very frequently , It will be regarded as ” Hot code ”, There are two ways to detect hotspot code, which are based on sampling and counter , In order to improve the execution efficiency of hotspot code , The virtual machine compiles them into local machine code , Optimize the code as much as possible , The back-end compiler that does this at run time is called just in time compiler .
You can also use static precompiler AOT Compile the program directly into binary code related to the target machine instruction set .
边栏推荐
- Mysql查询结果去除换行
- AAAI2020: Real-time Scene Text Detection with Differentiable Binarization
- GB28181的NAT穿透
- SIP protocol of gb28181
- axure不显示元件库
- Collation of open source protocols of open source frameworks commonly used in Web Development
- Define dichotomy lookup
- 商业智能BI开发和报表开发有什么本质区别?
- Bao, what if the O & M 100+ server is a headache? Use Xingyun housekeeper!
- Uni app product classification
猜你喜欢

HLS4ML进入方法

EasyGBS网络不稳定情况下重复请求视频拉流问题的优化

Introduction to relevant processes and functions of wechat official account development

Uni app wechat applet one click login to obtain permission function

自定义插入页面标签以及实现类似通讯录的首字母搜索

数字化转型企业成功的关键,用数据创造价值

GC垃圾回收

Test self-study people must see: how to find test items in software testing?

奔赴山海之前,毕业季一定要做的那些事情
![Thesis reading [distinctive late semantic graph for video capturing]](/img/d4/4f84a73a9127fa87bb0a74c4655d15.png)
Thesis reading [distinctive late semantic graph for video capturing]
随机推荐
类加载机制
Download (export) PDF template file (such as approval form), and report error: invalid nested tag * * * found, expected closing tag***
How to correctly use vertx to operate redis (3.9.4 with source code analysis)
Basic use of MySQL
Axure does not display catalogs
宝,运维100+服务器很头疼怎么办?用行云管家!
【sql优化】with as 和 临时表的区别
AAAI2020: Real-time Scene Text Detection with Differentiable Binarization
Collation of open source protocols of open source frameworks commonly used in Web Development
703. 数据流中的第 K 大元素
How to configure webrtc video streaming format for easygbs, a new version of national standard gb28181 video platform?
ffmpeg常用命令(二)
博途V16 获取系统时间转换成字符串
研究了11种实时聊天软件,我发现都具备这些功能…
703. The k-th element in the data flow
Uni app product classification
Why must we move from Devops to bizdevops?
What must be done in graduation season before going to Shanhai
大厂音视频职位面试题目--今日头条
Methods of finding various limits