了解JVM堆打印输出中的元空间行 [英] Understanding metaspace line in JVM heap printout

查看:133
本文介绍了了解JVM堆打印输出中的元空间行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java 8堆打印输出中,您可能会看到如下所示的行:


Metaspace used 2425K,容量 4498K,承诺 4864K,保留 1056768K




Metaspace由一个或多个虚拟空间组成。虚拟空间是从OS获得的连续地址空间的区域。它们按需分配。分配时,虚拟空间从操作系统中保留内存,但尚未提交。元空间保留内存是所有虚拟空间的总大小。



虚拟空间内的分配单元是Metachunk(或简称为Chunk)。从虚拟空间分配新块时,相应的内存已提交。元数据空间已提交内存是所有数据块的总大小。



块的大小可能不同。当ClassLoader被垃圾收集时,属于它的所有Metachunk都被释放。全局免费列表中保留了免费块。元空间容量是所有分配(即非免费)块的总大小。



新块分配


  1. 在免费列表中查找现有的免费块。

  2. 如果没有合适的免费块,从当前虚拟空间分配一个新的。

  3. 如果当前的虚拟空间已用完,请保留一个新的虚拟空间。

类元数据在一个块中分配。块可能不包含来自多个ClassLoader的数据,但是一个ClassLoader可能有多个块。 Metaspace used 是所有块中所有类元数据的总大小。


In a Java 8 heap printout, you may see a line that looks like:

Metaspace used 2425K, capacity 4498K, committed 4864K, reserved 1056768K

https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/considerations.html tries to explain the line:

In the line beginning with Metaspace, the used value is the amount of space used for loaded classes. The capacity value is the space available for metadata in currently allocated chunks. The committed value is the amount of space available for chunks. The reserved value is the amount of space reserved (but not necessarily committed) for metadata.

Again, from the above link:

Space is requested from the OS and then divided into chunks. A class loader allocates space for metadata from its chunks (a chunk is bound to a specific class loader).

I want to know what each field means (used, capacity, committed, reserved), but I am struggling to understand the above definitions.

My understanding is that metaspace is carved out of the JVM process's virtual address space. The JVM reserves an initial size on startup based on -XX:MetaspaceSize, which has an undocumented, platform-specific default. I assume that reserved refers to the total size of the metaspace. The space is divided into chunks. I am not sure if each chunk has the same size. Each chunk contains class metadata associated with a single class loader.

Capacity and committed sounds like free space to me (based on the definitions from the link). Since metadata is stored within chunks, then I would assume that used + capacity would equal committed, but it doesn't. Maybe committed means reserved space that is used, but then what would used mean? Used space used by metadata? Then, what other ways are there to use the space?

I hope you see my confusion. I would appreciate clarification on the definitions.

解决方案

Metaspace consists of one or more Virtual Spaces. Virtual Spaces are areas of contiguous address space obtained from the OS. They are allocated on demand. When allocated, Virtual Space reserves memory from the OS, but not yet commits it. Metaspace reserved memory is the total size of all Virtual Spaces.

Allocation unit inside Virtual Space is Metachunk (or simply Chunk). When a new chunk is allocated from a Virtual Space, the corresponding memory is committed. Metaspace committed memory is the total size of all chunks.

Chunks may differ in size. When a ClassLoader gets garbage collected, all Metachunks belonging to it are freed. Free chunks are maintained in the global free list. Metaspace capacity is the total size of all allocated (i.e. not free) chunks.

New chunk allocation

  1. Look for an existing free chunk in the free list.
  2. If there is no suitable free chunk, allocate a new one from the current Virtual Space.
  3. If the current Virtual Space is exhausted, reserve a new Virtual Space.

Class metadata is allocated within a chunk. Chunk may not contain data from multiple ClassLoaders, but one ClassLoader may have several chunks. Metaspace used is the total size of all class metadata from all chunks.

这篇关于了解JVM堆打印输出中的元空间行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆