<> Introduce to you G1 garbage collector

G1 Collector companion JAVA9 to 2017-9-21 release ,G1 The collector runs on the server side with low latency and high throughput ,HotSpot Team expectation replacement CMS
collector . That is to obtain the maximum measurement when the pause time is met . There are two collection modes Young GC and Mixed GC.G1 The collector divides the heap memory into equal sizes Region
, Cenozoic era , The old generation has become a logical concept . Marking is used as a whole - Sorting algorithm , Local replication algorithm is adopted .

G1 yes jdk1.9 Default garbage collector for ,-XX:+UseG1GC open

<>G1 collector Region Type of

* Cenozoic era
* Old age
* not used
* Large object area

Cenozoic era , Old age Region It is no longer a continuous space . Of course, save the enlarged object Region Must be continuous .

<>G1 How to allocate large objects in the collector

* Object size <0.5 individual RegionSize Direct Cenozoic Eden Region area
* Object size >=0.5 individual RegionSize And the size of the object <1 individual RegionSize, Save to large object area Humongous Region
* Object size >=1 individual RegionSize Save to continuous large object area Humongous Region
<> How to specify Region Size of

use -XX:G1HeapRegionSize To specify Region Size of ,Region The size of the must be 2 Power of , maximum 32M.

<>G1 Operation process of garbage collector ?

<> Initial marking (stop the world)

compare GC Roots Directly referenced objects are also marked , Simultaneous marking GC Roots Where the object is located Region be called Root Region

<> Root partition scan

Scan the entire older generation Region of Rset, The tag contains the of the initial tag phase Root Region of Region

<> Concurrent marking

Scan steps for traversing the root partition are marked Region, Mark all reachable objects , Concurrent execution with application threads

<> Relabel (stop the world)

Because the concurrency flag is executed concurrently with the application thread , Therefore, it is inevitable that some objects will change ,G1 GC empty SATB buffer , Tracking live objects that are not accessed , And perform reference processing .

<> Select clear (stop the world)

Evaluate each Region Amount of garbage , Select the ones with the best recovery effect Region
collect ( Depending on -XX:MaxGCPauseMillis Set value , The default is 200ms). Within the specified pause time , Get maximum throughput .

<> What is? Rset

each Region During initialization , Will initialize one Rset(remembered set), each Region All contain one Rset,Rset The function of is to record which memory areas are (
Region) Heap current Region Reference to .Rset Is a space for time data structure . Yes Rset You can avoid scanning the entire heap .

<>G1 and CMS Differences between

* G1 Use mark - Sorting algorithm ,CMS Use mark - Clearing algorithm , therefore G1 It won't produce a lot of garbage debris .
* G1 of STW(stop the world) controlled , have access to -XX:MaxGCPauseMillis set default 200ms
* G1 of Young GC The model can work in the younger generation , And separate CMS Can only work in the elderly generation .
<>G1 Application scenarios

* Server multi-core CPU,JVM Large footprint applications ( At least greater than 4G).
* The application generates a lot of fragments during operation , Frequent compression is required .
* Want more control , Predictable pause time ; Prevent avalanche under high and low temperature .

Technology
©2019-2020 Toolsou All rights reserved,
Android Using wechat in H5 Payment result refresh during payment shock !!C++ Can make a sound ! Basic operation of single linked list C Language explanation Java Implement an epidemic number management system 2021 year 11 World programming language ranking linux upper mysql Invalid command _linux lower mysql The command is useless Java project : Campus dormitory management system (java+jsp+javaweb+mysql+ajax) Wechat applet development project directory linux ubuntu Which version ,Ubuntu Which version is the best ?python Code painting cherry blossoms - How to use Python Draw a beautiful cherry blossom