gpt4 book ai didi

java - Windows 上每个 Java 进程的最大内存量?

转载 作者:IT老高 更新时间:2023-10-28 20:26:06 26 4
gpt4 key购买 nike

在 32 位 Windows 上,您可以使用 -Xmx 为 Java 进程分配的最大堆大小是多少?

我问是因为我想使用 OpenMap 中的 ETOPO1 数据原始二进制浮点文件大约 910 MB。

最佳答案

没有什么比经验实验更能回答您的问题了。我编写了一个 Java 程序并在指定 XMX 标志时运行它(也使用 XMS=XMX 强制 JVM 预分配所有内存)。为了进一步防止 JVM 优化,我主动分配了 X 个 10MB 对象。我在使用 Sun 和 IBM JVM 的不同 32 位操作系统上对多个增加 XMX 值并增加分配的 MB 数量的 JVM 进行了一些测试,以下是结果摘要:

操作系统:Windows XP SP2,JVM:Sun 1.6.0_02,最大堆大小:1470 MB
操作系统:Windows XP SP2,JVM:IBM 1.5,最大堆大小:1810 MB
操作系统:Windows Server 2003 SE,JVM:IBM 1.5,最大堆大小:1850 MB
操作系统:Linux 2.6,JVM:IBM 1.5,最大堆大小:2750 MB

以下是详细的运行尝试以及分配类帮助程序源代码:

WinXP SP2、SUN JVM:

C:>java -versionjava version "1.6.0_02"Java(TM) SE Runtime Environment (build 1.6.0_02-b06)Java HotSpot(TM) Client VM (build 1.6.0_02-b06, mixed mode)

java -Xms1470m -Xmx1470m Class1 142...about to create object 141object 141 created

C:>java -Xms1480m -Xmx1480m Class1 145Error occurred during initialization of VMCould not reserve enough space for object heapCould not create the Java virtual machine.

WinXP SP2, IBM JVM
 C:>c:\ibm\jdk\bin\java.exe -versionjava version "1.5.0"Java(TM) 2 Runtime Environment, Standard Edition (build pwi32devifx-20070323 (ifix 117674: SR4 + 116644 + 114941 + 116110 + 114881))IBM J9 VM (build 2.3, J2RE 1.5.0 IBM J9 2.3 Windows XP x86-32 j9vmwi3223ifx-20070323 (JIT enabled)J9VM - 20070322_12058_lHdSMRJIT  - 20070109_1805ifx3_r8GC   - WASIFIX_2007)JCL  - 20070131

c:\ibm\jdk\bin\java.exe -Xms1810m -Xmx1810m Class1 178...about to create object 177object 177 created

C:>c:\ibm\jdk\bin\java.exe -Xms1820m -Xmx1820m Class1 179JVMJ9VM015W Initialization error for library j9gc23(2): Failed to instantiate heap. 1820M requestedCould not create the Java virtual machine.

Win2003 SE, IBM JVM
C:>"C:\IBM\java" -Xms1850m -Xmx1850m Class1sleeping for 5 seconds.Done.

C:>"C:\IBM\java" -Xms1880m -Xmx1880m Class1JVMJ9VM015W Initialization error for library j9gc23(2): Failed to instantiate heap. 1880M requestedCould not create the Java virtual machine.

Linux 2.6, IBM JVM
[root@myMachine ~]# /opt/ibm/java2-i386-50/bin/java -versionjava version "1.5.0"Java(TM) 2 Runtime Environment, Standard Edition (build pxi32dev-20060511 (SR2))IBM J9 VM (build 2.3, J2RE 1.5.0 IBM J9 2.3 Linux x86-32 j9vmxi3223-20060504 (JIT enabled)J9VM - 20060501_06428_lHdSMRJIT  - 20060428_1800_r8GC   - 20060501_AA)JCL  - 20060511a

/opt/ibm/java2-i386-50/bin/java -Xms2750m -Xmx2750m Class1 270

[root@myMachine ~]# /opt/ibm/java2-i386-50/bin/java -Xms2800m -Xmx2800m Class1 270JVMJ9VM015W Initialization error for library j9gc23(2): Failed to instantiate heap. 2800M requestedCould not create the Java virtual machine.

Here's the code:


import java.util.StringTokenizer;


public class Class1 {

public Class1() {}

private class BigObject {
byte _myArr[];
public BigObject() {
_myArr = new byte[10000000];
}
}
public static void main(String[] args) {
(new Class1()).perform(Integer.parseInt(args[0]));
}
public void perform(int numOfObjects) {
System.out.println("creating 10 MB arrays.");
BigObject arr[] = new BigObject[numOfObjects];
for (int i=0;i <numOfObjects; i++) {
System.out.println("about to create object "+i);
arr[i] = new BigObject();
System.out.println("object "+i+" created");
}
System.out.println("sleeping for 5 seconds.");
try {
Thread.sleep(5000);
}catch (Exception e) {e.printStackTrace();}
System.out.println("Done.");
}

}

关于java - Windows 上每个 Java 进程的最大内存量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/987219/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com