探索JVM的堆記憶體分佈:官方圖片展示

快乐的总统95發表於2024-10-05

序章

擷取Java官方的 堆記憶體分佈相關圖片 到本文。

Java Platform, Standard Edition

HotSpot Virtual Machine Garbage Collection Tuning Guide

Java 21

https://docs.oracle.com/en/java/javase/21/gctuning/preface.html

探索JVM的堆記憶體分佈:官方圖片展示

下載為 pdf,搜尋 Figure,擷取其中的 堆記憶體分佈相關的圖片 到本文。

原來,堆記憶體 是由 垃圾回收器 分配的,不同的 垃圾回收器 有不同的分配規則。

Figure 3-2 Default Arrangement of Generations in the Serial Collector

探索JVM的堆記憶體分佈:官方圖片展示

原文:

At startup, the Java HotSpot VM reserves the entire Java heap in the address space, but
doesn't allocate any physical memory for it unless needed.

The entire address space covering the Java heap is logically divided into young and old generations. The complete address space
reserved for object memory can be divided into the young and old generations.

bing.com 翻譯:

啟動時,Java HotSpot VM 會在地址空間中保留整個 Java 堆,但除非需要,否則不會為其分配任何實體記憶體。

覆蓋 Java 堆的整個地址空間在邏輯上分為新代和老代。為物件記憶體保留的完整地址空間可分為新代和老代。

The young generation consists of eden and two survivor spaces. Most objects are initially allocated in eden.
One survivor space is empty at any time, and serves as the destination of live objects in eden and the other survivor space during garbage collection;
after garbage collection, eden and the source survivor space are empty.
In the next garbage collection, the purpose of the two survivor spaces are exchanged.
The one space recently filled is a source of live objects that are copied into the other survivor space.
Objects are copied between survivor spaces in this way until they've been copied a certain number of times or there isn't enough
space left there.
These objects are copied into the old region.
This process is also called aging.

bing.com 翻譯:

年輕一代由 eden 和兩個倖存者空間組成。大多數物件最初是在 eden 中分配的。
一個倖存者空間在任何時候都是空的,並作為 eden 中活動物件的目的地,在垃圾回收期間充當另一個倖存者空間的目的地;
垃圾回收後,Eden 和 Source Survivor Space 為空。
在下一次垃圾回收中,將交換兩個倖存者空間的用途。
最近填充的一個空間是被複制到另一個倖存空間的活動物件的源。
以這種方式在倖存者空間之間複製物件,直到它們被複制一定次數或沒有足夠的時間
那裡留有空間。
這些物件將複製到舊區域中。
這個過程也稱為老化。

Figure 4-1 Heap Options

探索JVM的堆記憶體分佈:官方圖片展示

堆引數。

Figure 6-1 Arrangement of Generations in the Parallel Collector

探索JVM的堆記憶體分佈:官方圖片展示

Figure 7-1 G1 Garbage Collector Heap Layout

探索JVM的堆記憶體分佈:官方圖片展示

原文:

The young generation contains eden regions (red) and survivor regions (red with "S").
These regions provide the same function as the respective contiguous spaces in other collectors,
with the difference that in G1 these regions are typically laid out in a noncontiguous pattern in memory.
Old regions (light blue) make up the old generation. Old generation regions may be humongous (light blue with "H") for objects that span multiple regions.

bing.com 翻譯:

新生代包含 eden 區域(紅色)和倖存區域(紅色,帶“S”)。
這些區域提供與其他收集器中相應的連續空間相同的功能。
不同的是,在 G1 中,這些區域通常在記憶體中以非連續模式佈局。
舊區域(淺藍色)構成了老一代。對於跨多個區域的物件,老一代區域可能很大(帶“H”的淺藍色)。

An application always allocates into a young generation, that is, eden regions, with the exception of humongous objects that are directly allocated as belonging to the old generation.

bing.com 翻譯:

應用程式始終分配給新生代,即 eden 區域,但直接分配為屬於老一代的巨大物件除外。

Figure 7-2 Garbage Collection Cycle Overview

探索JVM的堆記憶體分佈:官方圖片展示

圖片下方有 各個階段的介紹,可取原文檢視。

小結

官文中 的圖片 展示了 Serial、Parallel、G1 三種 垃圾回收器 的 堆記憶體分佈。

當然,官文還有更多豐富的內容,請自行學習。

Java 8

連結:

https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/

沒找到 pdf 下載入口。

Figure 3-2 Default Arrangement of Generations, Except for Parallel Collector and G1

探索JVM的堆記憶體分佈:官方圖片展示

圖片描述(Description of):

探索JVM的堆記憶體分佈:官方圖片展示

Figure 4-1 Heap Parameters

探索JVM的堆記憶體分佈:官方圖片展示

Description of:

探索JVM的堆記憶體分佈:官方圖片展示

Figure 6-1 Arrangement of Generations in the Parallel Collector

探索JVM的堆記憶體分佈:官方圖片展示

Description of:

探索JVM的堆記憶體分佈:官方圖片展示

Figure 9-1 Heap Division by G1

探索JVM的堆記憶體分佈:官方圖片展示

Description of:

The figure consists of a 10-by-10 grid. Most of the grid's cells are gray.

Nineteen cells are colored dark blue.

These dark blue cells are randomly distributed in the upper six rows of the grid.

Two of these dark blue cells contain a red box.

A cell two cells wide and one cell high (which appears in the first row) and a cell three cells wide and one cell high (which appears in the sixth row) are colored dark blue and labeled "H."

Eight cells are colored light blue and contain a red box.

Two of these cells are labeled "S."

These light blue cells with a red box are distributed randomly, most of them located in the upper half of the grid.

bing.com 翻譯:

該圖由一個 10 x 10 的網格組成。網格的大多數單元格都是灰色的。

19 個細胞為深藍色。

這些深藍色單元格隨機分佈在網格的上六行中。

其中兩個深藍色單元格包含一個紅色框。

一個單元格寬 2 個單元格,高 1 個單元格(顯示在第一行中)和一個單元格寬 3 個單元格,高 1 個單元格(顯示在第六行中)為深藍色,並標記為“H”。

八個單元格為淺藍色,幷包含一個紅色框。

其中兩個單元格標記為 “S”。

這些帶有紅色框的淺藍色單元格是隨機分佈的,其中大多數位於網格的上半部分。

---END---

本文連結:

https://www.cnblogs.com/luo630/p/18446638

ben釋出於部落格園

ben釋出於部落格園

相關文章