java - 当没有指定显式参数时,进程是否会分配足够的堆?

标签 java performance memory-management jvm

我正在通过 Java 8 上的主类运行 Java 进程。我没有在任何地方指定最小 (Xms) 和最大 (Xmx) 堆大小。但是当我通过 visualVM 检查它时 4267704320(即 4.26 GB)这是给定进程的默认最大堆大小(也通过 Windows 命令确认 -XX:+PrintFlagsFinal -version 2>&1 |找到 MaxHeapSize。同样在 linux box 上也是如此)。

我的问题是如果我的进程(在 linux 机器上)需要更多 5 GB(我有 30 GB RAM),当我没有指定时我的进程是否会分配 5 GB 内存 任何显式堆大小(Xms 和 Xmx)参数。

最佳答案

鉴于您机器上的可用 RAM,如果您在服务器模式下运行 64 位 JVM,那么是的,堆大小将能够达到大约 7.5 GB。

Documentation (我突出了相关部分):

Client JVM Default Initial and Maximum Heap Sizes

The default maximum heap size is half of the physical memory up to a physical memory size of 192 megabytes (MB) and otherwise one fourth of the physical memory up to a physical memory size of 1 gigabyte (GB).

Server JVM Default Initial and Maximum Heap Sizes

The default initial and maximum heap sizes work similarly on the server JVM as it does on the client JVM, except that the default values can go higher. On 32-bit JVMs, the default maximum heap size can be up to 1 GB if there is 4 GB or more of physical memory. On 64-bit JVMs, the default maximum heap size can be up to 32 GB if there is 128 GB or more of physical memory. You can always set a higher or lower initial and maximum heap by specifying those values directly; see the next section.

同样,假设 64 位 JVM 在服务器模式下运行,根据文档,默认的最大堆大小将是总 RAM 的四分之一。因此,您的情况大约为 7.5 GB(30 GB 的 1/4)。

如果在服务器模式下运行 32 位 JVM,则上限为 1 GB。在客户端模式下,您的最大值为 256 MB。

关于java - 当没有指定显式参数时,进程是否会分配足够的堆?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39596729/

相关文章:

java - 将 DAO 注入(inject)构造函数是否被认为是不好的做法?如果是这样,为什么?

java - Joda DateTimeFormatter 知道上午还是下午

c++ - 确保 `std::vector` 不会移动其指针

ios - SKSprite 场景的内存问题

java - 如何让循环在我的 Java 程序中工作?

java - 设置背景颜色 Java JButton

algorithm - 给定食谱列表和拥有的成分列表,哪种算法最适合确定 "Which ingredient could I add to access the most recipes?"

python - 带有 if 语句的 while 循环比 while 循环更快

android - 如何在Android中使用谷歌地图获得速度?

c++ - C++ 类的内存布局是否会受到地址空间布局随机化的影响