title: Sun's JVM heap size limit on Ubuntu 64-bit
body: <p>I see some strange behavior on the maximum heap size I get on Sun's JVM, compared to JRockit.</p>
  
  <p>I'm running IDEA on 64-bit VMs on a 64-bit system (Ubuntu 11.04). The JVM versions I'm testing are: <code>Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)</code> (which I got with <code>apt-get install sun-java6-jdk</code>, and <code>Oracle JRockit(R) (build R28.1.3-11-141760-1.6.0_24-20110301-1432-linux-x86_64, compiled mode)</code> (which I downloaded from Oracle's site a couple of months ago).</p>
  
  <p>If I pass the parameters -Xms1g -Xmx3g, IDEA will report a maximum heap size of 1820M on Sun's JVM, and 3072M (as expected) on JRockit.</p>
  
  <p>If I pass -Xms2g -Xmx4g, IDEA will report 3640M on Sun's and 4096M on JRockit.</p>
  
  <p>What is happening? What are those mystic numbers 1820M and 3640M = 2*1820M? Isn't it possible to run Sun's JVM with the exact heap size I want?</p>
  
  <p>EDIT:</p>
  
  <p>An answer has been deleted, so just to bring my comments back: please note that I'm talking about the MAX size, not the current size. Consider that I've researched a lot before asking the question here, so there's no need to teach the meaning of Xms, Xmx or any of the other of the parameters that specify the size of regions of the memory (those can be found elsewhere).</p>
  
  <p>EDIT2:</p>
  
  <p>I wrote the following simple code to test this behavior:</p>
  
  <pre><code>public static void main(String[] args) throws Exception {
    while (true) {
      final Runtime r = Runtime.getRuntime();
      System.out.println("r.freeMemory() = " + r.freeMemory()/1024.0/1024);
      System.out.println("r.totalMemory() = " + r.totalMemory()/1024.0/1024);
      System.out.println("r.maxMemory() = " + r.maxMemory()/1024.0/1024);
      Thread.sleep(1000);
    }
  }
  </code></pre>
  
  <p>Then I ran it with -Xmx100m, -Xmx110m, -Xmx120m, etc... for many many different values, both on Sun's JVM and o JRockit. Sun's will always report a bizarre value for <code>maxMemory()</code> and would grow on big steps (like 30M) between runs. JRockit reported the exact value every time.</p>