1. Overview
1.概述
In this short article, we’re going to see the difference between various memory size metrics in the JVM.
在这篇短文中,我们将看到JVM中各种内存大小指标的区别。
First, we’ll talk about how adaptive sizing works, and then we’ll evaluate the difference between max, used, and committed sizes.
首先,我们将讨论自适应大小的工作原理,然后我们将评估最大、已用和已承诺大小之间的区别。
2. Max Size and Adaptive Sizing
2.最大尺寸和自适应尺寸
Two values control the size of the JVM heap: one initial value specified via the -Xms flag and another maximum value controlled by the -Xmx tuning flag.
有两个值控制JVM堆的大小。一个初始值通过-Xms标志指定,另一个最大值由-Xmx调整标志控制。
If we don’t specify these flags, then the JVM will choose default values for them. These default values depend on the underlying OS, amount of available RAM, and, of course, the JVM implementation itself:
如果我们不指定这些标志,那么JVM将为它们选择默认值。这些默认值取决于底层操作系统、可用的RAM数量,当然还有JVM实现本身:
Regardless of the actual size and default values, the heap size starts with an initial size. As we allocate more objects, the heap size may grow to accommodate for that. The heap size, however, can’t go beyond the maximum heap size.
无论实际大小和默认值如何,堆的大小都是从初始大小开始的。随着我们分配更多的对象,堆的大小可能会增长以适应这种情况。然而,堆的大小不能超过最大堆的大小。
Put simply, the max heap size is the size specified via the -Xmx flag. Also, when we don’t explicitly specify the -Xmx, the JVM calculates a default max size.
简单地说,最大堆大小是通过-Xmx标志指定的大小。另外,当我们没有明确指定-Xmx时,JVM会计算出一个默认的最大尺寸。
3. Used Size
3.使用的尺寸
Now, let’s suppose we allocated a few objects since the program started. The heap size may grow a bit to accommodate for new objects:
现在,我们假设在程序开始后我们分配了一些对象。堆的大小可能会增长一些,以适应新的对象。
The used space is the amount of memory that is currently occupied by Java objects. It’s always less than or equal to the max size.
已用空间是指目前被Java对象占用的内存量。它总是小于或等于最大尺寸。
4. Committed Size
4.承诺的规模
The committed size is the amount of memory guaranteed to be available for use by the Java virtual machine. The committed memory size is always greater than or equal to the used size.
提交的大小是保证可供Java虚拟机使用的内存量。提交的内存大小总是大于或等于使用的大小。
5. Conclusion
5.总结
In this short article, we saw the difference between max, used, and committed heap size.
在这篇短文中,我们看到了最大、已用和已提交的堆大小之间的区别。