本文介绍了Windows XP 上的 Java 最大内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我总是能够为在 32 位 Windows XP(Java 1.4、1.5 和 1.6)上运行的 Java SE 分配 1400 MB.

I've always been able to allocate 1400 megabytes for Java SE running on 32-bit Windows XP (Java 1.4, 1.5 and 1.6).

java -Xmx1400m ...

今天我在使用 Java 1.5_16 和 1.6.0_07 的新 Windows XP 机器上尝试了相同的选项,但出现错误:

Today I tried the same option on a new Windows XP machine using Java 1.5_16 and 1.6.0_07 and got the error:

Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.

通过反复试验,我在这台机器上最多可以分配 1200 兆字节.

Through trial and error it seems 1200 megabytes is the most I can allocate on this machine.

为什么一台机器允许 1400 而另一台只允许 1200 的任何想法?

Any ideas why one machine would allow 1400 and another only 1200?

该机器有 4GB 的 RAM,其中 Windows 可以识别大约 3.5GB.

The machine has 4GB of RAM with about 3.5GB that Windows can recognize.

推荐答案

请记住,Windows 具有虚拟内存管理,而 JVM 只需要在其地址空间中连续的内存.因此,系统上运行的其他程序不一定会影响您的堆大小.会妨碍您的是加载到您的地址空间中的 DLL.不幸的是,Windows 中的优化最大限度地减少了链接期间 DLL 的重定位,这使得您更有可能拥有碎片化的地址空间.除了通常的东西之外,可能会切入您的地址空间的东西包括安全软件、CBT 软件、间谍软件和其他形式的恶意软件.造成差异的可能原因是不同的安全补丁、C 运行时版本等.设备驱动程序和其他内核位都有自己的地址空间(4GB 32 位空间中的另外 2GB).

Keep in mind that Windows has virtual memory management and the JVM only needs memory that is contiguous in its address space. So, other programs running on the system shouldn't necessarily impact your heap size. What will get in your way are DLL's that get loaded in to your address space. Unfortunately optimizations in Windows that minimize the relocation of DLL's during linking make it more likely you'll have a fragmented address space. Things that are likely to cut in to your address space aside from the usual stuff include security software, CBT software, spyware and other forms of malware. Likely causes of the variances are different security patches, C runtime versions, etc. Device drivers and other kernel bits have their own address space (the other 2GB of the 4GB 32-bit space).

可以尝试在 JVM 进程中检查 DLL 绑定,并尝试将 DLL 重新定位到更紧凑的地址空间.不好玩,但如果你绝望了......

You could try going through your DLL bindings in your JVM process and look at trying to rebase your DLL's in to a more compact address space. Not fun, but if you are desperate...

或者,您可以切换到 64 位 Windows 和 64 位 JVM.尽管其他人建议这样做,虽然它会占用更多 RAM,但您将拥有更多连续的虚拟地址空间,连续分配 2GB 将是微不足道的.

Alternatively, you can just switch to 64-bit Windows and a 64-bit JVM. Despite what others have suggested, while it will chew up more RAM, you will have much more contiguous virtual address space, and allocating 2GB contiguously would be trivial.

这篇关于Windows XP 上的 Java 最大内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 18:51