当前位置:网站首页>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 .
边栏推荐
- 原生js打造日程表-支持鼠标滚轮滚动选择月份-可以移植到任何框架中
- What is the essential difference between Bi development and report development?
- Solution and summary of Nacos startup failure
- Flutter 实战-快速实现音视频通话应用
- The key to the success of digital transformation enterprises is to create value with data
- 集合对象值改变NULL值对象
- 奔赴山海之前,毕业季一定要做的那些事情
- ddr4测试-2
- 直播HLS协议
- Compile ffmpeg source code with msys+vs2019 under win10
猜你喜欢

118. Yanghui triangle

After studying 11 kinds of real-time chat software, I found that they all have these functions

Les canaux de culture intensive s'efforcent de développer Fu Xin et Wei Shi jiajie pour organiser une conférence de formation sur les nouveaux produits

Task: denial of service DOS

GC垃圾回收

ddr4测试-2

uni-app商品分类

Actual combat of flutter - fast implementation of audio and video call application

Facebook聊单,SaleSmartly有妙招!

Basic use of MySQL
随机推荐
数字化转型企业成功的关键,用数据创造价值
H264 encoding profile & level control
Basic use of MySQL
任务:拒绝服务DoS
Ffmpeg avframe to cv:: mat
产品模块化设计的前世今生
Task: denial of service DOS
Uni app wechat applet one click login to obtain permission function
狼人杀攻略:你当我好骗吗,我们相信谁!
【英语语法】Unit1 冠词、名词、代词和数词
为什么一定要从DevOps走向BizDevOps?
微信公众号开发相关流程及功能介绍
703. The k-th element in the data flow
使用 Kibana Timelion 进行时间序列分析
Shell advanced
新版国标GB28181视频平台EasyGBS如何配置WebRTC视频流格式播放?
JS 之 常用内置类的使用
Facebook聊单,SaleSmartly有妙招!
Ffmpeg error code
Salesmartly has some tricks for Facebook chat!