当前位置:网站首页>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
边栏推荐
- In the era of low code development, is it still needed?
- Comparison between applet framework and platform compilation
- [FreeRTOS] FreeRTOS learning notes (7) - handwritten FreeRTOS two-way linked list / source code analysis
- [MySQL transaction]
- 【Kubernetes系列】Kubernetes 上安装 KubeSphere
- [Android reverse] function interception (use cache_flush system function to refresh CPU cache | refresh CPU cache disadvantages | recommended time for function interception)
- User login function: simple but difficult
- 两年前美国芯片扭捏着不卖芯片,如今芯片堆积如山祈求中国帮忙
- [thread pool]
- Directory of tornado
猜你喜欢
NLP literature reading summary
Blog stop statement
深入浅出:了解时序数据库 InfluxDB
【Kubernetes系列】Kubernetes 上安装 KubeSphere
Chain ide -- the infrastructure of the metauniverse
Guoguo took you to write a linked list, and the primary school students said it was good after reading it
Unity opens the explorer from the inspector interface, selects and records the file path
大厂技术专家:架构设计中常用的思维模型
window上用.bat文件启动项目
Handwritten easy version flexible JS and source code analysis
随机推荐
[Flink] temporal semantics and watermark
Adaptive spatiotemporal fusion of multi-target networks for compressed video perception enhancement
Xcode 14之大变化详细介绍
Text processing function sorting in mysql, quick search of collection
L1-024 the day after tomorrow (5 points)
MySQL storage engine
Detailed introduction to the big changes of Xcode 14
Zephyr 學習筆記2,Scheduling
[C language] open the door of C
MySQL中的文本处理函数整理,收藏速查
[thread pool]
How to send mail with Jianmu Ci
人生规划(Flag)
With excellent strength, wangchain technology, together with IBM and Huawei, has entered the annual contribution list of "super ledger"!
Zephyr study notes 2, scheduling
论文学习——基于极值点特征的时间序列相似性查询方法
节点基础~节点操作
Implementation of ZABBIX agent active mode
rapidjson读写json文件
Introduction to neural network (Part 2)