探索JVM的堆内存分布:官方图片展示

 

序章

截取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

下载为 pdf,搜索 Figure,截取其中的 堆内存分布相关的图片 到本文。

 

原来,堆内存 是由 垃圾回收器 分配的,不同的 垃圾回收器 有不同的分配规则。

 

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

原文:

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

堆参数。

 

Figure 6-1 Arrangement of Generations in the Parallel Collector

 

Figure 7-1 G1 Garbage Collector Heap Layout

原文:

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

图片下方有 各个阶段的介绍,可取原文查看。

 

小结

官文中 的图片 展示了 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

图片描述(Description of):

 

Figure 4-1 Heap Parameters

Description of:

Figure 6-1 Arrangement of Generations in the Parallel Collector

Description of:

 

Figure 9-1 Heap Division by G1

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发布于博客园

 

posted @ 2024-10-05 07:07  快乐的欧阳天美1114  阅读(13)  评论(2编辑  收藏  举报