Java 8 中的默认 Xmxsize(最大堆大小)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28272923/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 05:54:04  来源:igfitidea点击:

Default Xmxsize in Java 8 (max heap size)

javamemory

提问by Vitaly

In the oracle documentationI found:

oracle文档中我发现:

-Xmxsize Specifies the maximum size (in bytes) of the memory allocation pool in bytes ... The default value is chosen at runtime based on system configuration.

-Xmxsize 以字节为单位指定内存分配池的最大大小(以字节为单位)...默认值是在运行时根据系统配置选择的。

What does system configurationmean?

这是什么系统配置是什么意思?

采纳答案by icza

It varies on implementation and version, but usually it depends on the VM used (e.g. client or server, see -clientand -serverparameters) and on your system memory.

它因实现和版本而异,但通常取决于所使用的 VM(例如客户端或服务器、查看-client-server参数)以及您的系统内存。

Often for clientthe default value is 1/4th of your physical memory or 1GB (whichever is smaller).

通常client默认值是物理内存的 1/4 或 1GB(以较小者为准)。

Also Java configuration options (command line parameters) can be "outsourced" to environment variables including the -Xmx, which can change the default (meaning specify a new default). Specifically the JAVA_TOOL_OPTIONSenvironment variable is checked by all Java tools and used if exists (more details hereand here).

此外,Java 配置选项(命令行参数)可以“外包”给环境变量,包括-Xmx,这可以更改默认值(意味着指定新的默认值)。具体来说JAVA_TOOL_OPTIONS,所有 Java 工具都会检查环境变量并在存在时使用(更多详细信息在这里这里)。

You can run the following command to see default values:

您可以运行以下命令来查看默认值:

java -XX:+PrintFlagsFinal -version

It gives you a loooong list, -Xmxis in MaxHeapSize, -Xmsis in InitialHeapSize. Filter your output (e.g. |grepon linux) or save it in a file so you can search in it.

它为您提供了一个 loooong 列表,-XmxMaxHeapSize-XmsInitialHeapSize。过滤您的输出(例如|grep在 linux 上)或将其保存在一个文件中,以便您可以在其中进行搜索。

回答by brianNotBob

Surprisingly this question doesn't have a definitive documented answer. Perhaps another data point would provide value to others looking for an answer. On my systems running CentOS (6.8,7.3) and Java 8 (build 1.8.0_60-b27, 64-Bit Server):

令人惊讶的是,这个问题没有明确的记录答案。也许另一个数据点会为其他寻求答案的人提供价值。在我运行 CentOS (6.8,7.3) 和 Java 8 (build 1.8.0_60-b27, 64-Bit Server) 的系统上:

default memory is 1/4 of physical memory, not limited by 1GB.

默认内存为物理内存的1/4,不受1GB限制。

Also, -XX:+PrintFlagsFinalprints to STDERR so command to determine current default memory presented by others above should be tweaked to the following:

此外,-XX:+PrintFlagsFinal打印到 STDERR 以便确定上面其他人提供的当前默认内存的命令应调整为以下内容:

java -XX:+PrintFlagsFinal 2>&1 | grep MaxHeapSize

The following is returned on system with 64GB of physical RAM:

在具有 64GB 物理 RAM 的系统上返回以下内容:

uintx MaxHeapSize                                  := 16873684992      {product}

回答by Sarat Chandra

Like you have mentioned, The default -Xmxsize(Maximum HeapSize) depends on your system configuration.

就像您提到的,默认值-Xmxsize(最大堆大小)取决于您的系统配置。

Java8 clienttakes Larger of 1/64th of your physical memory for your Xmssize(Minimum HeapSize) and Smaller of 1/4th of your physical memory for your -Xmxsize(Maximum HeapSize).

Java8clientXmssize(最小堆大小)占用物理内存的1/64中的较大者,为-Xmxsize(最大堆大小)占用物理内存的 1/4 中的较小者。

Which means if you have a physical memory of 8GB RAM, you will have Xmssizeas Larger of 8*(1/6) and Smaller of -Xmxsizeas 8*(1/4).

这意味着如果您有 8GB RAM 的物理内存,您将拥有Xmssize8*(1/6) 中的较大值和-Xmxsize8*(1/4) 中的较小值。

You can Check your default HeapSize with

您可以检查您的默认 HeapSize

In Windows:

Windows 中

java -XX:+PrintFlagsFinal -version | findstr /i "HeapSize PermSize ThreadStackSize"

In Linux:

Linux 中

java -XX:+PrintFlagsFinal -version | grep -iE 'HeapSize|PermSize|ThreadStackSize'

These default values can also be overrided to your desired amount.

这些默认值也可以覆盖为您想要的数量。

回答by Binita Bharati

On my Ubuntu VM, with 1048 MB total RAM, java -XX:+PrintFlagsFinal -version | grep HeapSizeprinted : uintx MaxHeapSize := 266338304, which is approx 266MB and is 1/4th of my total RAM.

在我的 Ubuntu VM 上,总 RAM 为 1048 MB,java -XX:+PrintFlagsFinal -version | grep HeapSize打印 : uintx MaxHeapSize := 266338304,大约为 266MB,是我总 RAM 的 1/4。

回答by Vyshnav Ramesh Thrissur

As of 8, May, 2019:

截至2019 年 5 月 8 日:

JVM heap size depends on system configuration, meaning:

JVM 堆大小取决于系统配置,意思是:

a) client jvm vs server jvm

a) 客户端 jvm 与服务器 jvm

b) 32bit vs 64bit.

b) 32 位与 64 位

Links:

链接:

1) updation from J2SE5.0: https://docs.oracle.com/javase/6/docs/technotes/guides/vm/gc-ergonomics.html
2) brief answer: https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/ergonomics.html
3) detailed answer: https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/parallel.html#default_heap_size
4) client vs server: https://www.javacodegeeks.com/2011/07/jvm-options-client-vs-server.html

1) 从 J2SE5.0 更新:https://docs.oracle.com/javase/6/docs/technotes/guides/vm/gc-ergonomics.html
2) 简要回答:https: //docs.oracle.com/ javase/8/docs/technotes/guides/vm/gctuning/ergonomics.html
3) 详细解答:https: //docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/parallel.html# default_heap_size
4) 客户端与服务器:https: //www.javacodegeeks.com/2011/07/jvm-options-client-vs-server.html

Summary:(Its tough to understand from the above links. So summarizing them here)

总结:(从上面的链接很难理解。所以在这里总结一下)

1) Default maximum heap size for Client jvm is 256mb (there is an exception, read from links above).

1) 客户端 jvm 的默认最大堆大小为 256mb(有一个例外,从上面的链接中读取)。

2) Default maximum heap size for Server jvm of 32bit is 1gb and of 64 bit is 32gb (again there are exceptions here too. Kindly read that from the links).

2) 32 位服务器 jvm 的默认最大堆大小是 1gb,64 位是 32gb(这里也有例外。请从链接中阅读)。

So default maximum jvm heap size is: 256mbor 1gbor 32gbdepending on VM, above.

所以默认的最大 jvm 堆大小是:256mb1gb32gb,具体取决于上面的 VM。