【问题标题】:What is max heap size I can allocate for JVM on Win32 machine?我可以为 Win32 机器上的 JVM 分配的最大堆大小是多少?
【发布时间】:2011-01-07 17:11:22
【问题描述】:

我在 Windows XP 上运行 BEA JRockit JDK 5.0 Update 6。我想知道当我的机器上有 4GB 的主内存时我可以分配的最大堆是多少。

【问题讨论】:

    标签: jvm heap-memory windows-xp jrockit


    【解决方案1】:

    SO link得到答案

    【讨论】:

      【解决方案2】:

      我没有 JRockit,但我应该尝试一些 -Xmx 选项的值。 在我的 JVM 上,限制为 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.
      

      我用这样的程序对其进行了测试,所以你可以看到你的应用程序可以从 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 ");
                  }
              }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-06-29
        • 2011-03-29
        • 1970-01-01
        • 2011-02-24
        • 1970-01-01
        • 2021-02-11
        • 1970-01-01
        • 2010-11-03
        相关资源
        最近更新 更多