- Java 11 and 12:New Features
- Mala Gupta
- 420字
- 2021-07-02 12:27:06
G1 memory
G1 divides the memory into regions—that is, the Eden, Survivor, and Old generation regions—this 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 region—a 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.
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.
- C++程序設(shè)計教程
- Google Apps Script for Beginners
- 密碼學原理與Java實現(xiàn)
- 軟件架構(gòu)設(shè)計:大型網(wǎng)站技術(shù)架構(gòu)與業(yè)務架構(gòu)融合之道
- Hands-On JavaScript High Performance
- Mastering Swift 2
- 零基礎(chǔ)學Java(第4版)
- Apex Design Patterns
- Java圖像處理:基于OpenCV與JVM
- Android應用開發(fā)深入學習實錄
- 計算機應用基礎(chǔ)(第二版)
- 基于MATLAB的控制系統(tǒng)仿真及應用
- Clojure for Finance
- 城市信息模型平臺頂層設(shè)計與實踐
- 前端程序員面試算法寶典