java 如何减少JVM虚拟内存使用量?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12025525/
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
How to reduce JVM virtual memory usage?
提问by
I have a Java program to run on Solaris 10 X86 with 2GB physical memory and 2GB swap.
我有一个 Java 程序可以在具有 2GB 物理内存和 2GB 交换空间的 Solaris 10 X86 上运行。
The program runs fine in Linux 64-bit, it consumes only about 450MB memory.
该程序在 64 位 Linux 上运行良好,仅消耗大约 450MB 内存。
However when it runs in Solaris, it always reports OutOfMemoryError, and I noticed that right before the error happens, it was trying to use > 4GB of virtual memory, which is definitely not possible on 32-bit system.
但是当它在 Solaris 中运行时,它总是报告 OutOfMemoryError,我注意到就在错误发生之前,它试图使用 > 4GB 的虚拟内存,这在 32 位系统上绝对不可能。
So why does JVM tries to use that much virtual memory? Is there a way to tell JVM not to use that much virtual memory?
那么为什么 JVM 会尝试使用那么多虚拟内存呢?有没有办法告诉 JVM 不要使用那么多虚拟内存?
Thank you.
谢谢你。
Edit:
编辑:
Thanks for everyone's opinions! Here is the complete error message:
谢谢大家的意见!这是完整的错误消息:
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (malloc) failed to allocate 32756 bytes for ChunkPool::allocate
# Possible reasons:
# The system is out of physical RAM or swap space
# In 32 bit mode, the process size limit was hit
# Possible solutions:
# Reduce memory load on the system
# Increase physical memory or swap space
# Check if swap backing store is full
# Use 64 bit Java on a 64 bit OS
# Decrease Java heap size (-Xmx/-Xms)
# Decrease number of Java threads
# Decrease Java thread stack sizes (-Xss)
# Set larger code cache with -XX:ReservedCodeCacheSize=
# This output file may be truncated or incomplete.
#
# Out of Memory Error (allocation.cpp:211), pid=1052, tid=16
#
# JRE version: 6.0_26-b03
# Java VM: Java HotSpot(TM) Server VM (20.1-b02 mixed mode solaris-x86 )
--------------- T H R E A D ---------------
Current thread (0x081a3400): JavaThread "C2 CompilerThread1" daemon
采纳答案by Integrating Stuff
You might be passing parameters to the JVM that make it use this much memory.
您可能正在将参数传递给 JVM,使其使用这么多内存。
Depending on the exact error - is it a heap space problem or a permgen space problem? - passing parameters to the jvm such as -Xms512m and -Xmx512m, or -XX:PermSize=128m and -XX:MaxPermSize=128m, might solve the problem on your system.
取决于确切的错误 - 是堆空间问题还是永久空间问题?- 将参数传递给 jvm,例如 -Xms512m 和 -Xmx512m,或 -XX:PermSize=128m 和 -XX:MaxPermSize=128m,可能会解决您系统上的问题。
回答by Fabian Barney
Try setting jvm param -Xmx1g
to limit the usage of 1 gigabyte at most.
尝试设置 jvm 参数-Xmx1g
以限制最多 1 GB 的使用。