简体   繁体   English

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

[英]Default Xmxsize in Java 8 (max heap size)

In the oracle documentation I 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 configuration mean?系统配置是什么意思?

It varies on implementation and version, but usually it depends on the VM used (eg client or server, see -client and -server parameters) and on your system memory.它因实现和版本而异,但通常取决于所使用的 VM(例如客户端或服务器,请参阅-client-server参数)以及您的系统内存。

Often for client the 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).此外,Java 配置选项(命令行参数)可以“外包”给环境变量,包括-Xmx ,它可以更改默认值(意味着指定新的默认值)。 Specifically the JAVA_TOOL_OPTIONS environment variable is checked by all Java tools and used if exists (more details here and here ).特别是JAVA_TOOL_OPTIONS环境变量由所有 Java 工具检查并在存在时使用(更多详细信息在这里这里)。

You can run the following command to see default values:您可以运行以下命令来查看默认值:

java -XX:+PrintFlagsFinal -version

It gives you a loooong list, -Xmx is in MaxHeapSize , -Xms is in InitialHeapSize .它为您提供了一个 loooong 列表, -XmxMaxHeapSize-XmsInitialHeapSize Filter your output (eg |grep on linux) or save it in a file so you can search in it.过滤您的输出(例如Linux 上的|grep )或将其保存在一个文件中,以便您可以在其中进行搜索。

Like you have mentioned, The default -Xmxsize (Maximum HeapSize) depends on your system configuration.就像您提到的,默认的-Xmxsize (最大堆大小)取决于您的系统配置。

Java8 client takes 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). Java8 clientXmssize (最小堆大小) Xmssize物理内存的Xmssize较大者,为-Xmxsize (最大堆大小) -Xmxsize物理内存的-Xmxsize较小者。

Which means if you have a physical memory of 8GB RAM, you will have Xmssize as Larger of 8*(1/64) and Smaller of -Xmxsize as 8*(1/4).这意味着如果您的物理内存为 8GB RAM,则Xmssize 8*(1/64) 中的较大者, -Xmxsize较小者为 8*(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.这些默认值也可以覆盖为您想要的数量。

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:+PrintFlagsFinal prints 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}

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 1) 从 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 2)简答: 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 3)详细解答: 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 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: 256mb or 1gb or 32gb depending on VM, above.所以默认的最大 jvm 堆大小是: 256mb1gb32gb,具体取决于上面的 VM。

On my Ubuntu VM, with 1048 MB total RAM, java -XX:+PrintFlagsFinal -version | grep HeapSize在我的 Ubuntu VM 上,总内存为 1048 MB, java -XX:+PrintFlagsFinal -version | grep HeapSize java -XX:+PrintFlagsFinal -version | grep HeapSize printed : uintx MaxHeapSize := 266338304 , which is approx 266MB and is 1/4th of my total RAM. java -XX:+PrintFlagsFinal -version | grep HeapSize打印: uintx MaxHeapSize := 266338304 ,大约 266MB,是我总 RAM 的 1/4。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM