当前位置:网站首页>Heap concept in JVM
Heap concept in JVM
2022-07-04 07:37:00 【xmh-sxh-1314】
One . Overview of heap
One JVM Instance has only one heap memory , So is heap Java The core area of memory management , Pile on JVM Create at startup , Its size is also created , yes JVM The largest memory space in the , All threads share Java Pile up , Physically discontinuous, logically continuous memory space , Almost all instances allocate memory here , At the end of the method , Objects in the heap are not deleted immediately , Only deleted during garbage collection , The pile is GC( Garbage collector ) Key areas for implementing garbage collection .
Two . Heap space subdivision
Java7 As before, heap space is logically divided into three parts : New Area + Retirement area + Forever
Java8 And later, the heap memory is logically divided into : New Area + Retirement area + Meta space
The new generation :
1. The new generation uses replication algorithm
2. The new generation is gc The key object of , Officially tested 70% The life cycle of objects will end in the new generation
3. The new generation is divided into eden、survivor1、survivor2, Object creation is first placed in eden in , After a certain period of time, it will be placed in the survivor area
4. The memory ratio is assumed by default :8:1:1
5. Cenozoic collector :Minor GC/Young GC
eden( New Area )
When the object is initially loaded, it will enter the new area
survivor( Survival zone )
The survival zone is further divided into from and to — Who is empty, who is to , There will always be an empty area .
The surviving area will not actively recycle garbage , It's just eden Only when recycling gc
When the threshold in the surviving area reaches 15 after ( Default 15 Modifiable ) Will automatically enter the elderly generation
When the new area (eden) When there is insufficient memory , Will be carried out in YGC, Then the object without pointer will be recycled , And the object to which the pointer is directed is put survivor1 perhaps survivor2 In the region ,eden Empty , Put the data into a survivor in .— When the second time gc It will be eden Put the data into another empty survivor in , And will present survivor Valid data in , Put the empty survivor in , One analogy .
Old age
1. Larger object data will be put into the elderly
2. The data of the s are relatively persistent and infrequent gc
3.(MajorGC / Old GC) It's going on majorgc At least once minorGc , and majorgc Is more efficient than minorGc slow 10 Times
4. Old age collector :MajorGC / Old GC Distinguish between and Full GC
When an object enters memory Will enter eden, If the full (YGC Recycle what is not referenced , If there are still references ) Will be put into the s1 perhaps s0 This involves to from Which is empty is to,( The next time eden When it is full again, there will be data 【 give an example s1】 in Data into s0, And iterative version ) And so on , When the number of iterations of an object reaches the default 15 thereafter ,( Of course, there will be special optimization : As if survivor The total memory of the same age in the region is greater than survivor Half of the memory , Objects older than or equal to the average age will be placed in the elderly generation in advance ) It will be put into the old generation About YGC The entire (YoungGC) It can also be for (Minor GC) s1,0 There will be no separate gc Recycling will only passively rely on eden Of gc When eden Conduct gc It will be recycled automatically s1,s0
yangGC Only in eden When the area is full , Not in survivor When the area is full ,eden District GC I will also put survivor Area for GC, When survivor in age=15 The data will be put into the elderly area .
Why three generations
Four memory allocation strategies ( Or object promotion rules )
If the object is EDEN Was born and passed through once MinnorGC Still alive after , And can be Survivor If it can be accommodated , Will be placed in the survivor area , And set the target age to 1, Every time I get through MinnorGC,age Add one year , When age Add to 15 when , Will be put into the old generation
5、 ... and .TLAB
Vi. escape analysis
What is escape ?
That is, if you create an object in a method , also return Outgoing , Or assign values to external variables , Then we run away .
-XX:+DoEscapeAnalysis (JDK1.8 Then it turns on by default )
-XX:+DoEscapeAnalysis( close )
Escape analysis includes the following
On the stack
That is, allocate objects directly to the stack , Die with the death of stack , Less gc( There is no... In the stack gc), Improved performance 、 Speed .
Synchronous ellipsis
Because it is unique to each stack , A stack is also a thread, so there is no synchronization safety problem .
Separate objects or scalar substitution
expand : A class represents a : The amount of polymerization , Scalars are the smallest data that cannot be analyzed , Aggregate quantity can be analyzed as scalar quantity , That is, analyze attributes
That is, when loading a pojo Class time , Instead of creating objects , Scalar substitution is analyzed into small attributes , Reduced memory , Improved performance .
But based on hotSpot The technology of virtual machine is not mature , Because we still need to judge whether Belong to escape , If there is no escape , It may waste judgment time and other problems .
But in the end, scalar substitution refers to hotSpot In the virtual machine
边栏推荐
- Basic DOS commands
- flask-sqlalchemy 循环引用
- Splicing plain text into JSON strings - easy language method
- Mysql database - function constraint multi table query transaction
- [Chongqing Guangdong education] National Open University spring 2019 770 real estate appraisal reference questions
- Types of references in BibTex
- Blue Bridge Cup Quick sort (code completion)
- The IP bound to the socket is inaddr_ The meaning of any htonl (inaddr_any) (0.0.0.0 all addresses, uncertain addresses, arbitrary addresses)
- 2022-021ARTS:下半年開始
- L1-022 odd even split (10 points)
猜你喜欢

System architecture design of circle of friends

Introduction to sap commerce cloud B2B organization function

Tri des fonctions de traitement de texte dans MySQL, recherche rapide préférée
![[Mori city] random talk on GIS data (I)](/img/e4/2a2ceb10a2c0285cdd0c922f827930.png)
[Mori city] random talk on GIS data (I)

Two years ago, the United States was reluctant to sell chips, but now there are mountains of chips begging China for help

It's healthy to drink medicinal wine like this. Are you drinking it right

神经网络入门(下)

Rhcsa day 3

Introduction to rce in attack and defense world
![[Android reverse] function interception (use cache_flush system function to refresh CPU cache | refresh CPU cache disadvantages | recommended time for function interception)](/img/5c/afb0d43665a8b46579dc604d983790.jpg)
[Android reverse] function interception (use cache_flush system function to refresh CPU cache | refresh CPU cache disadvantages | recommended time for function interception)
随机推荐
人生规划(Flag)
输入年份、月份,确定天数
Introduction to deep learning Ann neural network parameter optimization problem (SGD, momentum, adagrad, rmsprop, Adam)
Solution of running crash caused by node error
Go learning notes - constants
Project 1 household accounting software (goal + demand description + code explanation + basic fund and revenue and expenditure details record + realization of keyboard access)
[kubernetes series] kubesphere is installed on kubernetes
The IP bound to the socket is inaddr_ The meaning of any htonl (inaddr_any) (0.0.0.0 all addresses, uncertain addresses, arbitrary addresses)
2022-021ARTS:下半年开始
What are the work contents of operation and maintenance engineers? Can you list it in detail?
Oceanbase is the leader in the magic quadrant of China's database in 2021
【FreeRTOS】FreeRTOS学习笔记(7)— 手写FreeRTOS双向链表/源码分析
Label management of kubernetes cluster
Introduction to rce in attack and defense world
电子协会 C语言 1级 34 、分段函数
Blog stop statement
提升复杂场景三维重建精度 | 基于PaddleSeg分割无人机遥感影像
Practice (9-12 Lectures)
Two years ago, the United States was reluctant to sell chips, but now there are mountains of chips begging China for help
JVM -- class loading process and runtime data area