开发者

What is max heap size I can allocate for JVM on Win32 machine?

开发者 https://www.devze.com 2022-12-18 04:11 出处:网络
I have BEA JRockit JDK 5.0 Update 6 running on Win开发者_StackOverflowdows XP. I wish to know what is the max heap I can allocate when I have primary memory of 4GB on my machine.I don\'t have JRockit

I have BEA JRockit JDK 5.0 Update 6 running on Win开发者_StackOverflowdows XP. I wish to know what is the max heap I can allocate when I have primary memory of 4GB on my machine.


I don't have JRockit but I should try some values of -Xmx option. On my JVM the limit is 1610 MB:

c:\tmp>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)

c:\tmp>java -Xmx1610m mem_test
1552 MB Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
    at mem_test.main(mem_test.java:15)

c:\tmp>java -Xmx1611m mem_test
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.

I tested it with such program, so you can see how many memory you application can allocate from heap available to JVM:

import java.util.ArrayList;
import java.io.*;

class mem_test
{
    public static void main(String[] args) 
        {
        ArrayList<byte[]> big_list = new ArrayList<byte[]>();
        int max = 0;
        int i = 0;
        while (true)
            {
            ++i;
            big_list.add(new byte[1024 * 1024]);
            max = i;
            if (i % 16 == 0)
                System.out.print("\r" + i + " MB ");
            }
        }
}


Got the answer in this SO link

0

精彩评论

暂无评论...
验证码 换一张
取 消