<> heap

<> summary

* 1) One JVM Instance has only one heap memory , So is the heap Java Core area of memory management
* 2)Java The heap area is JVM Created at startup , The size of the space is determined , yes JVM Maximum memory space managed ( Heap memory size is adjustable )
* 3)《Java Virtual machine specification 》 regulations , The heap can be in a physically discontinuous memory space , But logically it should be considered continuous
* 4) All thread sharing Java heap , You can also partition the thread's private buffer here (Thread Local Allocation Buffer,TLAB)
* 5) Arrays and objects may never be stored on the heap , Because the reference is saved in the stack frame , This reference points to the position of the object or array in the heap
* 6) At the end of the method , Objects in the heap will not be removed immediately , It's only removed when garbage is collected
* 7) heap , yes GC Key areas for garbage collection
<> Architecture diagram

<> Heap memory breakdown

Java7 The heap memory is logically divided into

* Cenozoic era
* Old age
* Permanent generation
Java8 After that, heap memory is logically divided into

* Cenozoic era
* Old age
* Metaspace
be careful : Although the heap memory is logically divided into new generations , Old age and meta space , But the physical heap only includes the Cenozoic , Old age , The realization of Metaspace as method area

<> Heap space size

Java Heap area for storage Java Object instance , So the size of the heap is JVM Defined at startup , Through “-Xms” and “-Xmx” To set up

* “-Xms” Starting memory of heap area represented by domain , Equivalent to -XX:InitialHeapSize
* ”Xmx“ The maximum memory used to represent the heap area , Equivalent to -XX:MaxHeapSize
Once the memory size in the heap exceeds ”-Xmx“ When the specified maximum memory , Will throw OutOfMemoryError abnormal

Usually, the -Xms and -Xmx The two parameters are configured with the same value , The purpose is to be able to Java After the garbage collection mechanism cleans up the heap area, it does not need to re separate and calculate the size of the heap area , To improve performance

By default , Initialize memory size : Physical computer memory / 64; Maximum memory size : Physical computer memory size / 4

<> New and old generation

store in JVM In Java Objects can be divided into two categories :

* One is transient objects with short life cycle , Such objects are created and die very quickly
* Another kind of object has a very long life cycle , In some extreme cases, it can also JVM Consistent life cycle of
Java The heap area can be subdivided into : Cenozoic era (YoungGen) And the elderly (OldGen)
The Cenozoic can be divided into Eden area ( Eden Park ),Survivor0 area ( survivor 0 area ) and Survivo1 area ( survivor 1 area )

The following parameters are not normally adjusted , Use the default :

Allocation of the proportion of the new generation and the old generation in the heap structure :

* default -XX:NewRatio=2, Indicates Cenozoic occupation 1, Elderly generation 2, That is to say, the Cenozoic took up the whole pile 1/3
Configure the Eden And two outside Survivor Space share :

* The default scale is 8:1:1 Available through -XX:SurvivoRatio Parameter adjustment
Almost all Java The objects are all in Eden Tegument new Come out

Most of them Java Objects were destroyed in the new generation , Namely ” transient “

Available through -Xmn Set the maximum memory size of the new generation , If this parameter is used ,-XX:NewRatio The parameters are invalid , Generally, the default value can be used

<> Object allocation process

<> summary

Allocating memory for new objects is a very rigorous and complex task , So it's complicated , Here's an overview

* 1)new The objects come out first Eden area , There is a size limit in this area
* 2) When Eden When the area space is full , The program also needs to create objects , The user thread is blocked ,JVM The garbage collector will Eden Garbage collection in the area (Minor
GC), take Eden Objects in the zone that are no longer referenced by other objects are destroyed , Load new objects and put them in Eden area
* 3) Then the Eden Move remaining objects in area to Survivor0 area
* 4) If garbage collection is triggered again , Yes Eden District and from area ( because Survivor0 and 1 Zone can only have one zone to store data , So we call it from
area , Those who do not store data are called to area ) Garbage collection , Then the Eden and from The ones that survived in the zone to area
* 5) Continue to trigger garbage collection , The surviving objects are constantly changing from Move to to area , Continue the whole process
* 6) Object in from and to After the continuous movement of the area , When the number reaches 15 Second hour , It's going to move from the new generation to the old one , This number can be passed
-XX:MaxTenuringThreshold To set up
<> summary

* About garbage collection : Frequent recycling in the new generation , Rarely recycled in the elderly , Almost no permanent generation / Metaspace recycling
<> Better understanding through the figure below

<>

Technology
©2019-2020 Toolsou All rights reserved,
First knowledge python Skills summary GDOI2019 travels c Linguistic 5 Three common sorting methods Python Basic knowledge and notes " Cephalosporin wine Say go and go "? DANGER ! Don't drink alcohol when taking these drugs Thorough explanation from Zhongtai vue The component page height is adaptive according to the screen size Classical algorithm - recursion ( The case of raw rabbit ) Big data tells you , How tired are Chinese women about keras use fit_generator Encountered in StopIteration