当前位置:网站首页>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
边栏推荐
- This article is enough for learning advanced mysql
- 手写简易版flexible.js以及源码分析
- Zabbix agent主动模式的实现
- The crackdown on Huawei prompted made in China to join forces to fight back, and another enterprise announced to invest 100 billion in R & D
- Activiti常見操作數據錶關系
- 如何用MOS管来实现电源防反接电路
- win10微软拼音输入法输入文字时候下方不出现中文提示
- Boosting the Performance of Video Compression Artifact Reduction with Reference Frame Proposals and
- Guoguo took you to write a linked list, and the primary school students said it was good after reading it
- Electronic Association C language level 1 34, piecewise function
猜你喜欢
Redis - detailed explanation of cache avalanche, cache penetration and cache breakdown
大厂技术专家:架构设计中常用的思维模型
Project 1 household accounting software (goal + demand description + code explanation + basic fund and revenue and expenditure details record + realization of keyboard access)
[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
Experience installing VMware esxi 6.7 under VMware Workstation 16
Xcode 14之大变化详细介绍
Used on windows Bat file startup project
[kubernetes series] kubesphere is installed on kubernetes
Chain ide -- the infrastructure of the metauniverse
随机推荐
L1-028 judging prime number (10 points)
PCIE知识点-010:PCIE 热插拔资料从哪获取
Docker install MySQL
L1-024 the day after tomorrow (5 points)
2022-021rts: from the second half of the year
The frost peel off the purple dragon scale, and the xiariba people will talk about database SQL optimization and the principle of indexing (primary / secondary / clustered / non clustered)
线性代数1.1
神经网络入门(下)
节点基础~节点操作
Amd RX 7000 Series graphics card product line exposure: two generations of core and process mix and match
Take you to master the formatter of visual studio code
[Android reverse] function interception (use cache_flush system function to refresh CPU cache | refresh CPU cache disadvantages | recommended time for function interception)
win10微软拼音输入法输入文字时候下方不出现中文提示
Adaptive spatiotemporal fusion of multi-target networks for compressed video perception enhancement
Zephyr Learning note 2, Scheduling
Tri des fonctions de traitement de texte dans MySQL, recherche rapide préférée
With excellent strength, wangchain technology, together with IBM and Huawei, has entered the annual contribution list of "super ledger"!
L1-027 rental (20 points)
Rapidjson reading and writing JSON files
谷歌官方回应:我们没有放弃TensorFlow,未来与JAX并肩发展