增加内存密集型应用程序的 JVM 最大堆大小

我需要运行一个使用超过2GB 的 Java 内存密集型应用程序,但是我在增加堆的最大大小方面遇到了问题。到目前为止,我已经尝试了以下方法:

  • 设置-Xmx 参数,例如-Xmx3000m。这种方法在创建 JVM 时失败了。从我谷歌的内容来看,它看起来-Xmx 必须小于2GB。

  • 使用 - XX: + 咄咄逼人堆选项。当我尝试这种方法时,我得到一个“内存不足”错误,告诉堆大小是1273.4 MB,即使我的计算机有8 GB 的内存。

还有其他方法可以尝试增加 JVM 的最大堆大小吗?下面是计算机规格的摘要:

  • 操作系统: Windows 7(64位)
  • 处理器: Intel Core i7(2.66 GHz)
  • 内存: 8GB
  • Java-version:
java version "1.6.0_18"
Java(TM) SE Runtime Environment (build 1.6.0_18-b07)
Java HotSpot(TM) Client VM (build 16.0-b13, mixed mode, sharing)
403954 次浏览

Get yourself a 64-bit JVM from Oracle.

I believe the 2GB limit is for 32-bit Java. I thought v1.6 was always 64 bit, but try forcing 64 bit mode just to see: add the -d64 option.

When you are using JVM in 32-bit mode, the maximum heap size that can be allocated is 1280 MB. So, if you want to go beyond that, you need to invoke JVM in 64-mode.

You can use following:

$ java -d64 -Xms512m -Xmx4g HelloWorld

where,

  • -d64: Will enable 64-bit JVM
  • -Xms512m: Will set initial heap size as 512 MB
  • -Xmx4g: Will set maximum heap size as 4 GB

You can tune in -Xms and -Xmx as per you requirements (YMMV)

A very good resource on JVM performance tuning, which might want to look into: http://java.sun.com/javase/technologies/hotspot/gc/gc_tuning_6.html

32-bit Java is limited to approximately 1.4 to 1.6 GB.

Oracle 32 bit heap FAQ

Quote

The maximum theoretical heap limit for the 32-bit JVM is 4G. Due to various additional constraints such as available swap, kernel address space usage, memory fragmentation, and VM overhead, in practice the limit can be much lower. On most modern 32-bit Windows systems the maximum heap size will range from 1.4G to 1.6G. On 32-bit Solaris kernels the address space is limited to 2G. On 64-bit operating systems running the 32-bit VM, the max heap size can be higher, approaching 4G on many Solaris systems.

Below conf works for me:

JAVA_HOME=/JDK1.7.51-64/jdk1.7.0_51/
PATH=/JDK1.7.51-64/jdk1.7.0_51/bin:$PATH
export PATH
export JAVA_HOME


JVM_ARGS="-d64 -Xms1024m -Xmx15360m -server"


/JDK1.7.51-64/jdk1.7.0_51/bin/java $JVM_ARGS -jar `dirname $0`/ApacheJMeter.jar "$@"

In my case,

-Xms1024M -Xmx1024M is work

-Xms1024M -Xmx2048M result: Could not reserve enough space for object heap

after use JVM 64 bit, it allows using 2GB RAM, because I am using win server 2012

please see the available max heap size for JVM 32 bit on several OSs Xmx for JVM 32bit

https://www.codementor.io/@suryab/does-32-bit-or-64-bit-jvm-matter-anymore-w0sa2rk6z

For memory intensive applications, GraalVm can serve as a better alternative. Providing 32 GB as max heap size and other benefits. Hotspot vs Graal