从 Java SE 6 开始,Sun JVM 的默认最大堆大小是多少?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2915276/
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-13 14:27:33  来源:igfitidea点击:

What is the default maximum heap size for Sun's JVM from Java SE 6?

javajvmmemory-management

提问by dfrankow

What is the default maximum heap size for Sun's JVM from Java SE 6 (i.e. equivalent to setting -Xmx)?

从 Java SE 6 开始,Sun JVM 的默认最大堆大小是多少(即相当于设置 -Xmx)?

Looks like for Java SE 5 with a server-class machine, it's

看起来对于带有服务器级机器的 Java SE 5,它是

Smaller of 1/4th of the physical memory or 1GB.

物理内存的 1/4 或 1GB,以较小者为准。

Bonus question: Looks like for IBM's JVM you can ask it

额外问题:对于 IBM 的 JVM,您可以问它

java -verbose:sizes -version

Can you similarly ask Sun's JVM?

你能类似地问Sun的JVM吗?

Edit:

编辑

I used Runtime.getRuntime().maxMemory to confirm min(physical memory/4, 1G), referenced in Sun documentation.

我使用 Runtime.getRuntime().maxMemory 来确认最小(物理内存/4,1G),在Sun 文档中引用。

采纳答案by qmc

java 1.6.0_21 or later, or so...

java 1.6.0_21 或更高版本,或...

$ java -XX:+PrintFlagsFinal -version 2>&1 | grep MaxHeapSize
uintx MaxHeapSize                         := 12660904960      {product}

It looks like the min(1G) has been removed.

看起来 min(1G) 已被删除。

Or on Windows using findstr

或者在 Windows 上使用 findstr

C:\>java -XX:+PrintFlagsFinal -version 2>&1 | findstr MaxHeapSize

回答by Inv3r53

one way is if you have a jdk installed , in bin folder there is a utility called jconsole(even visualvm can be used). Launch it and connect to the relevant java process and you can see what are the heap size settings set and many other details

一种方法是,如果您安装了 jdk,则在 bin 文件夹中有一个名为 jconsole 的实用程序(甚至可以使用 visualvm)。启动它并连接到相关的java进程,您可以看到堆大小设置设置和许多其他详细信息

When running headless or cli only, jConsole can be used over lan, if you specify a port to connect on when starting the service in question.

当仅运行 headless 或 cli 时,如果您在启动相关服务时指定要连接的端口,则可以通过 lan 使用 jConsole。

回答by dfrankow

One can ask with some Java code:

可以用一些 Java 代码提问:

long maxBytes = Runtime.getRuntime().maxMemory();
System.out.println("Max memory: " + maxBytes / 1024 / 1024 + "M");

See javadoc.

请参阅javadoc

回答by chrisinmtown

To answer this question it's critical whether the Java VM is in CLIENT or SERVER mode. You can specify "-client" or "-server" options. Otherwise java uses internal rules; basically win32 is always client and Linux is always server, but see the table here:

要回答这个问题,Java VM 是处于 CLIENT 模式还是 SERVER 模式至关重要。您可以指定“-client”或“-server”选项。否则java使用内部规则;基本上,win32 始终是客户端,Linux 始终是服务器,但请参阅此处的表格:

http://docs.oracle.com/javase/6/docs/technotes/guides/vm/server-class.html

http://docs.oracle.com/javase/6/docs/technotes/guides/vm/server-class.html

Sun/Oracle jre6u18 doc says re client: the VM gets 1/2 of physical memory if machine has <= 192MB; 1/4 of memory if machine has <= 1Gb; max 256Mb. In my test on a 32bit WindowsXP system with 2Gb phys mem, Java allocated 256Mb, which agrees with the doc.

Sun/Oracle jre6u18 doc 说客户端:如果机器具有 <= 192MB,VM 将获得 1/2 的物理内存;如果机器 <= 1Gb,则为 1/4 内存;最大 256Mb。在我对具有 2Gb phys mem 的 32 位 WindowsXP 系统进行的测试中,Java 分配了 256Mb,这与文档一致。

Sun/Oracle jre6u18 doc says re server: same as client, then adds confusing language: for 32bit JVM the default max is 1Gb, and for 64 bit JVM the default is 32Gb. In my test on a 64bit linux machine with 8Gb physical, Java allocates 2Gb, which is 1/4 of physical; on a 64bit linux machine with 128Gb physical Java allocates 32Gb, again 1/4 of physical.

Sun/Oracle jre6u18 文档说服务器:与客户端相同,然后添加了令人困惑的语言:对于 32 位 JVM,默认最大值为 1Gb,对于 64 位 JVM,默认最大值为 32Gb。我在一台 64 位 linux 机器上测试,物理内存为 8Gb,Java 分配了 2Gb,这是物理内存的 1/4;在具有 128Gb 物理 Java 的 64 位 linux 机器上分配 32Gb,同样是物理的 1/4。

Thanks to this SO post for guiding me:

感谢这篇SO帖子指导我:

Definition of server-class machine changed recently?

最近服务器级机器的定义有变化吗?

回答by user1754962

With JDK, You can also use jinfo to connect to the JVM for the <PROCESS_ID>in question and get the value for MaxHeapSize:

使用 JDK,您还可以使用 jinfo 连接到有<PROCESS_ID>问题的 JVM并获取 MaxHeapSize 的值:

jinfo -flag MaxHeapSize <PROCESS_ID>

回答by Jabir

As of JDK6U18 following are configurations for the Heap Size.

从 JDK6U18 开始,以下是堆大小的配置。

In the Client JVM, the default Java heap configuration has been modified to improve the performance of today's rich client applications. Initial and maximum heap sizes are larger and settings related to generational garbage collection are better tuned.

The default maximum heap size is half of the physical memory up to a physical memory size of 192 megabytes and otherwise one fourth of the physical memory up to a physical memory size of 1 gigabyte. For example, if your machine has 128 megabytes of physical memory, then the maximum heap size is 64 megabytes, and greater than or equal to 1 gigabyte of physical memory results in a maximum heap size of 256 megabytes. The maximum heap size is not actually used by the JVM unless your program creates enough objects to require it. A much smaller amount, termed the initial heap size, is allocated during JVM initialization. This amount is at least 8 megabytes and otherwise 1/64 of physical memory up to a physical memory size of 1 gigabyte.

在客户端 JVM 中,修改了默认的 Java 堆配置以提高当今富客户端应用程序的性能。初始和最大堆大小更大,并且与分代垃圾收集相关的设置得到更好的调整。

默认的最大堆大小是物理内存的一半,最大为 192 兆字节的物理内存大小,否则为物理内存的四分之一,最大为 1 GB 的物理内存大小。例如,如果您的机器有 128 兆字节的物理内存,则最大堆大小为 64 兆字节,大于或等于 1 GB 的物理内存导致最大堆大小为 256 兆字节。JVM 不会实际使用最大堆大小,除非您的程序创建了足够多的对象来要求它。在 JVM 初始化期间分配的数量要小得多,称为初始堆大小。该数量至少为 8 兆字节,否则为物理内存的 1/64,最大为 1 GB 的物理内存大小。

Source : http://www.oracle.com/technetwork/java/javase/6u18-142093.html

来源:http: //www.oracle.com/technetwork/java/javase/6u18-142093.html