当前位置:网站首页>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 .
边栏推荐
猜你喜欢

Introduction to relevant processes and functions of wechat official account development

JS 之 常用内置类的使用

Basic use of MySQL

SQL 入门计划-1-选择

Optimization of video streaming with repeated requests in the case of unstable easygbs network

Oracle物理体系结构

A brief understanding of white box encryption technology
![[go ~ 0 to 1] day 5 July 1 type alias, custom type, interface, package and initialization function](/img/1e/bed6a761f07c052e43b1e3b1701760.png)
[go ~ 0 to 1] day 5 July 1 type alias, custom type, interface, package and initialization function

任务:拒绝服务DoS

Instagram 为何从内容共享平台变成营销工具?独立站卖家如何利用该工具?
随机推荐
MySQL signale une erreur can 't create table' demo01. TB Étudiant '(errno: 150)
How to configure webrtc video streaming format for easygbs, a new version of national standard gb28181 video platform?
Introduction to relevant processes and functions of wechat official account development
Flutter 实战-快速实现音视频通话应用
js三元表达式复杂条件判断
CMU AI PhD first year summary
新增订单如何防止重复提交
JS 之 常用内置类的使用
微信公众号开发相关流程及功能介绍
一文读懂C语言中的结构体
Thesis reading [distinctive late semantic graph for video capturing]
精耕渠道共謀發展 福昕攜手偉仕佳傑開展新產品培訓大會
EasyGBS网络不稳定情况下重复请求视频拉流问题的优化
Define dichotomy lookup
ES6中的代理proxy
求各种极限的方法
正则表达式=Regex=regular expression
Compile ffmpeg source code with msys+vs2019 under win10
After studying 11 kinds of real-time chat software, I found that they all have these functions
GC垃圾回收