官术网_书友最值得收藏!

G1 memory

G1 divides the memory into regionsthat is, the Eden, Survivor, and Old generation regionsthis is typically about 2,048 in the count (or as close to this as possible). A region is the memory space used to store objects of different generations, without requiring them to be allocated contiguously. The size of each region depends on the memory size. All the Eden and Survivor regions are together referred to as the young generation, and all the Old regions are referred to as the old generation. The size of the regions is calculated as X to the power of 2, where X is between 1 MB and 64 MB. G1 also defines the Humongous memory regions for large objects, whose size is greater than 50% of the size of the Eden regions. Since these regions are not allocated contiguously, here's how your memory might look with G1 GC:

New objects are allocated in the Eden regions. During a young collection, a G1 GC moves the live objects from the Eden regions to the Survivor regions. Objects in the Survivor region are moved to the Old region if they have lived long enough (this is specified by using XX:MaxTenuringThreshold), or until they are collected.

A young collection collects, evacuates, and compacts objects to the Survivor regions from the Eden regions. A mixed collection, as the name suggests, will include a select set of Eden and Old regions. A mixed collection works by collecting objects quickly and frequently so that the Eden and Survivor regions are freed up as soon as they can be.

When an object is more than 50% of the size of a region, it is allocated to the Humongous regiona contiguous set of regions in the Old generation regions. A Humongous region is not allocated in the Eden regions in order to keep the cost of copying or evacuating it low.

When young and mixed collections can no longer reclaim enough memory, full GC occurs. This includes marking the live objects, preparing for compaction, adjusting pointers, and compacting the heap.

This section covers just an overview of how the memory is organized and reclaimed in G1 GC so that you can follow the contents of this section. For further details, you can refer to https://www.oracle.com/technetwork/tutorials/tutorials-1876574.html.

Let's work with a sample code that, apart from triggering young and mixed collections, also triggers full GC, eventually exiting the JVM due to an exhausted heap and an inability to allocate more objects.

主站蜘蛛池模板: 孟州市| 调兵山市| 祁阳县| 鄯善县| 车险| 肇源县| 泰州市| 舟曲县| 库尔勒市| 云安县| 黄浦区| 宜州市| 辽宁省| 台山市| 绥滨县| 麻江县| 阿瓦提县| 界首市| 赤水市| 滦南县| 常德市| 汽车| 来安县| 和平县| 金堂县| 叙永县| 临洮县| 大名县| 甘德县| 汉沽区| 伊金霍洛旗| 偏关县| 繁峙县| 通渭县| 酒泉市| 泽库县| 通江县| 剑川县| 仁化县| 永新县| 铜鼓县|