Why can't I allocate 2GB of heap to the JVM on Windows?
It is a known fact that 32bit architectures limit the amount of memory any single process can allocate to 4GB. So why does the JVM limit the maximum heap size (-Xmx) to under 2GB?
When you try to run your JVM with a -Xmx2gb flag, you'll get the following error:
Error occurred during initialization of VM
Could not reserve enough space for object heap
This is a limitation of the Windows 32bit OS. 32bit processes can only use a max of 4GB memory address space. Windows further splits that into half by allocating 2GB to the kernel and 2GB to the application.
The reason you can not hit the 2GB limit within the VM is because there is memory overhead that the VM and OS use for the process (remember MaxPermSize?), hence you end up with a bit less than the actual 2GB limit.
The solution would be to move to a 64bit machine and OS.
3:10:05 PM
This has to be one of the most useful outlines of GC tuning information I have ever seen. Thanks to Pete Freitag for creating this from the original document. The original was nowhere as easy to read.
1:57:49 PM