当前位置:网站首页>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
边栏推荐
- L1-025 positive integer a+b (15 points)
- 2022-021ARTS:下半年开始
- MYCAT middleware installation and use
- How to buy financial products in 2022?
- Transition technology from IPv4 to IPv6
- User login function: simple but difficult
- Zabbix agent主动模式的实现
- Handwritten easy version flexible JS and source code analysis
- Easy to understand: understand the time series database incluxdb
- Is l1-029 too fat (5 points)
猜你喜欢
win10微软拼音输入法输入文字时候下方不出现中文提示
Transition technology from IPv4 to IPv6
Flask 常用组件
Guoguo took you to write a linked list, and the primary school students said it was good after reading it
The cloud native programming challenge ended, and Alibaba cloud launched the first white paper on application liveliness technology in the field of cloud native
Adaptive spatiotemporal fusion of multi-target networks for compressed video perception enhancement
Rhcsa the next day
Computer connects raspberry pie remotely through putty
Zephyr Learning note 2, Scheduling
This monitoring system can monitor the turnover intention and fishing all, and the product page has 404 after the dispute appears
随机推荐
大厂技术专家:架构设计中常用的思维模型
jdbc连接es查询的时候,有遇到下面这种情况的大神嘛?
Rhcsa day 3
Node foundation ~ node operation
21个战略性目标实例,推动你的公司快速发展
Preliminary study on temporal database incluxdb 2.2
电子协会 C语言 1级 34 、分段函数
Blue Bridge Cup Quick sort (code completion)
window上用.bat文件启动项目
Zephyr 學習筆記2,Scheduling
University stage summary
[network security] what is emergency response? What indicators should you pay attention to in emergency response?
flask-sqlalchemy 循环引用
In the era of low code development, is it still needed?
Pangu open source: multi support and promotion, the wave of chip industry
rapidjson读写json文件
Activiti常见操作数据表关系
Literature collation and thesis reading methods
两年前美国芯片扭捏着不卖芯片,如今芯片堆积如山祈求中国帮忙
Basic DOS commands