Java 增加内存密集型应用程序的 JVM 最大堆大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3030263/
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
Increasing the JVM maximum heap size for memory intensive applications
提问by Alceu Costa
I need to run a Java memory intensive application that uses more than 2GB, but I am having problems to increase the heap maximum size. So far, I have tried the following approaches:
我需要运行一个使用超过 2GB 的 Java 内存密集型应用程序,但是我在增加堆最大大小时遇到了问题。到目前为止,我尝试了以下方法:
Setting the -Xmx parameter, e.g. -Xmx3000m. This approaches fails at the creation of the JVM. From what I've googled, it looks like that -Xmx must be less than 2GB.
Using the -XX:+AggressiveHeap option. When I try this approach I get an 'Not enough memory' error that tells that the heap size is 1273.4 MB, even though my computer has 8GB of memory.
设置-Xmx 参数,例如-Xmx3000m。这种方法在创建 JVM 时失败。从我用谷歌搜索的内容来看,-Xmx 必须小于 2GB。
使用-XX:+AggressiveHeap 选项。当我尝试这种方法时,我收到“内存不足”错误,指出堆大小为 1273.4 MB,即使我的计算机有 8GB 内存。
Is there another approach that I can try to increase the maximum heap size of the JVM? Here's a summary of the computer specs:
是否有另一种方法可以尝试增加 JVM 的最大堆大小?以下是计算机规格的摘要:
- OS: Windows 7 (64 bit)
- Processor: Intel Core i7 (2.66 GHz)
- Memory: 8 GB
- java -version:
- 操作系统:Windows 7(64 位)
- 处理器:英特尔酷睿 i7 (2.66 GHz)
- 内存:8 GB
- java - 版本:
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)
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)
回答by G__
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.
我相信 2GB 的限制是针对 32 位 Java 的。我认为 v1.6 总是 64 位,但尝试强制 64 位模式只是为了查看:添加 -d64 选项。
回答by mohitsoni
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.
在 32 位模式下使用 JVM 时,可以分配的最大堆大小为 1280 MB。所以,如果你想超越它,你需要在 64 模式下调用 JVM。
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
- -d64:将启用 64 位 JVM
- -Xms512m:将初始堆大小设置为 512 MB
- -Xmx4g:将最大堆大小设置为 4 GB
You can tune in -Xms and -Xmx as per you requirements (YMMV)
您可以根据需要调整 -Xms 和 -Xmx (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
关于 JVM 性能调整的非常好的资源,可能需要查看:http: //java.sun.com/javase/technologies/hotspot/gc/gc_tuning_6.html
回答by Jean B
32-bit Java is limited to approximately 1.4 to 1.6 GB.
32 位 Java 被限制为大约 1.4 到 1.6 GB。
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.
32 位 JVM 的最大理论堆限制为 4G。由于可用交换、内核地址空间使用、内存碎片和 VM 开销等各种附加限制,实际上限制可能要低得多。在大多数现代 32 位 Windows 系统上,最大堆大小范围为 1.4G 到 1.6G。在 32 位 Solaris 内核上,地址空间限制为 2G。在运行 32 位 VM 的 64 位操作系统上,最大堆大小可以更高,在许多 Solaris 系统上接近 4G。
回答by tutorialbyexample
Below conf works for me:
以下 conf 对我有用:
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 ##代码##`/ApacheJMeter.jar "$@"