title: Cannot run a 64-bit JVM in 64-bit Windows 7 with a large heap size
body: <p>This is 64-bit <code>Windows 7 Enterprise</code> and 64-bit Java 7:</p>
  
  <pre><code>java version "1.7.0_04"
  Java(TM) SE Runtime Environment (build 1.7.0_04-b20)
  Java HotSpot(TM) 64-Bit Server VM (build 23.0-b21, mixed mode)
  </code></pre>
  
  <p>This happens using a shell of both <code>C:\Windows\SystemWOW64\cmd.exe</code> (which I incorrectly thought was the 64-bit version) <strong>and</strong> with <code>C:\Windows\System32\cmd.exe</code> (which I have just found out, courtesy of Pulsar, is a 64-bit application despite the path name).</p>
  
  <p>The program itself is trivial:</p>
  
  <pre><code>public class Trivial
  {
      public static void main(String[] args) {
          System.out.println("total = " + toMB(Runtime.getRuntime().totalMemory()));
          System.out.println("max   = " + toMB(Runtime.getRuntime().maxMemory()));
      }
  
      private static long toMB(long bytes) {
          return bytes / (1024L * 1024L);
      }
  }
  </code></pre>
  
  <p>I was just fooling around with different <code>-Xmx</code> and <code>-Xms</code> arguments to see what would happen.  I would have though that with 64-bit Java on 64-bit Windows I could use pretty much whatever size max and initial heap I wanted, but that's not what's happening.</p>
  
  <p><code>java -Xmx16G -Xms2G Trivial</code> (for example) works fine.  However, <code>java -Xmx16G -Xms4G Trivial</code> gives me:</p>
  
  <pre><code>Error occurred during initialization of VM
  Could not reserve enough space for object heap
  </code></pre>
  
  <p>Weirder (to me), <code>java -Xmx16G -Xms3G Trivial</code> gives a different error:</p>
  
  <pre><code>Error occurred during initialization of VM
  Unable to allocate tables for parallel garbage collection for the requested heap size.
  Error: Could not create the Java Virtual Machine.
  Error: A fatal exception has occurred. Program will exit.
  </code></pre>
  
  <p>Attempting to split the difference between <code>2G</code> and <code>3G</code> to see if there was a specific size where this happened I tried <code>java -Xmx16G -Xms2900M Trivial</code> and it worked.  Then I tried <code>-Xms2960M</code> and it worked.  With <code>-Xms2970m</code> the JVM crashed:</p>
  
  <pre><code>#
  # There is insufficient memory for the Java Runtime Environment to continue.
  # Native memory allocation (malloc) failed to allocate 1048576 bytes for E in C:\jdk7u2_64p\jdk7u4\hotspot\src\share\vm\utilities/taskqueue.hpp
  # An error report file with more information is saved as:
  # C:\Users\QuantumMechanic\Temp\hs_err_pid10780.log
  </code></pre>
  
  <p>That continued until <code>-Xms2995M</code> when it switched back to the "unable to allocate tables for parallel garbage collection" message and stuck with that as <code>-Xms</code> was increased further.</p>
  
  <p>What could be going on?  Does launching something from <code>cmd.exe</code> (even a 64-bit one) impose some process size limits?  Is Windows (or the JVM) requiring a single huge memory block?  (But then why the different messages)?  Something else?</p>