当前位置:网站首页>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
边栏推荐
- Introduction to neural network (Part 2)
- I was pressed for the draft, so let's talk about how long links can be as efficient as short links in the development of mobile terminals
- Directory of tornado
- Take you to master the formatter of visual studio code
- In the era of low code development, is it still needed?
- MySQL中的文本處理函數整理,收藏速查
- [Chongqing Guangdong education] National Open University spring 2019 770 real estate appraisal reference questions
- Blue Bridge Cup Quick sort (code completion)
- Would you like to go? Go! Don't hesitate if you like it
- 线性代数1.1
猜你喜欢
Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
Advanced MySQL: Basics (5-8 Lectures)
Tri des fonctions de traitement de texte dans MySQL, recherche rapide préférée
Technical experts from large factories: common thinking models in architecture design
MySQL中的文本處理函數整理,收藏速查
Zhanrui tankbang | jointly build, cooperate and win-win zhanrui core ecology
Comparison between applet framework and platform compilation
[network security] what is emergency response? What indicators should you pay attention to in emergency response?
如何用MOS管来实现电源防反接电路
With excellent strength, wangchain technology, together with IBM and Huawei, has entered the annual contribution list of "super ledger"!
随机推荐
Boast about Devops
OKR vs. KPI 一次搞清楚这两大概念!
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)
Introduction to rce in attack and defense world
Rhcsa the next day
With excellent strength, wangchain technology, together with IBM and Huawei, has entered the annual contribution list of "super ledger"!
深入浅出:了解时序数据库 InfluxDB
Zhanrui tankbang | jointly build, cooperate and win-win zhanrui core ecology
Introduction to deep learning Ann neural network parameter optimization problem (SGD, momentum, adagrad, rmsprop, Adam)
Electronic Association C language level 1 35, bank interest
Zephyr 學習筆記2,Scheduling
win10微软拼音输入法输入文字时候下方不出现中文提示
Project 1 household accounting software (goal + demand description + code explanation + basic fund and revenue and expenditure details record + realization of keyboard access)
Easy to understand: understand the time series database incluxdb
SQL注入测试工具之Sqli-labs下载安装重置数据库报错解决办法之一(#0{main}thrown in D:\Software\phpstudy_pro\WWW\sqli-labs-……)
【Kubernetes系列】Kubernetes 上安装 KubeSphere
Experience installing VMware esxi 6.7 under VMware Workstation 16
Guoguo took you to write a linked list, and the primary school students said it was good after reading it
【森城市】GIS数据漫谈(一)
果果带你写链表,小学生看了都说好