If you want to use 32-bit references, your heap is limited to 32 GB.

However, if you are willing to use 64-bit references, the size is likely to be limited by your OS, just as it is with 32-bit JVM. e.g. on Windows 32-bit this is 1.2 to 1.5 GB.

Note: you will want your JVM heap to fit into main memory, ideally inside one NUMA region. That's about 1 TB on the bigger machines. If your JVM spans NUMA regions the memory access and the GC in particular will take much longer. If your JVM heap start swapping it might take hours to GC, or even make your machine unusable as it thrashes the swap drive.

Note: You can access large direct memory and memory mapped sizes even if you use 32-bit references in your heap. i.e. use well above 32 GB.

Compressed oops in the Hotspot JVM

Compressed oops represent managed pointers (in many but not all places in the JVM) as 32-bit values which must be scaled by a factor of 8 and added to a 64-bit base address to find the object they refer to. This allows applications to address up to four billion objects (not bytes), or a heap size of up to about 32Gb. At the same time, data structure compactness is competitive with ILP32 mode.

Answer from Peter Lawrey on Stack Overflow
🌐
IBM
ibm.com › support › pages › recommended-maximum-heap-sizes-32-and-64-bit-websphere-java-instances
Recommended Maximum Heap Sizes on 32 and 64 bit WebSphere Java instances
*Remember that the WAS Java process ... stacks in general, the recommended Maximum Heap range for WebSphere Application Server, would be between (4096M - 8192M) or (4G - 8G)....
Discussions

What is max heap size I can allocate for Java 64-bit - Oracle Forums
Hi folks, We have the server running 64-bit Linux and Java. What is the highest number of heap size I can set? Let's say the server has 256 G of RAM. Can I allocate 128 GB to Java heap or ever more? ... More on forums.oracle.com
🌐 forums.oracle.com
April 23, 2013
java - JVM heap size not getting more than 1.6 GB for 64 bit JVM - Stack Overflow
Are you really sure that you are using a 64 bit JVM? 1600M sounds pretty much like a typical limit of a 32 bit JVM. You can use the -showversion option to let the JVM print the relevant information without terminating. ... Save this answer. ... Show activity on this post. ... The default initial and maximum heap sizes ... More on stackoverflow.com
🌐 stackoverflow.com
Maximum Java heap size of a 32-bit JVM on a 64-bit OS - Stack Overflow
The maximum theoretical heap limit for the 32-bit JVM is 4G. Due to various additional constraints such as available swap, kernel address space usage, memory fragmentation, and VM overhead, in practice the limit can be much lower. On most modern 32-bit Windows systems the maximum heap size will range from 1.4G to 1.6G. On 32-bit Solaris kernels the address space is limited to 2G. On 64... More on stackoverflow.com
🌐 stackoverflow.com
What is the default maximum heap size for Sun's JVM from Java SE 6? - Stack Overflow
What is the default maximum heap size for Sun's JVM from Java SE 6 (i.e. equivalent to setting -Xmx)? Looks like for Java SE 5 with a server-class machine, it's Smaller of 1/4th of the physical ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Blogger
javarevisited.blogspot.com › 2013 › 04 › what-is-maximum-heap-size-for-32-bit-64-JVM-Java-memory.html
What is the maximum Heap Size of 32 bit or 64-bit JVM in Windows and Linux?
Maximum heap size for 32 bit or 64 bit JVM looks easy to determine by looking at addressable memory space like 2^32 (4GB) for 32 bit JVM and 2^64 for 64 bit JVM. The confusion starts here because you can not really set 4GB as the maximum heap ...
🌐
Baeldung
baeldung.com › home › java › jvm › could not reserve enough space for object heap
Could Not Reserve Enough Space for Object Heap | Baeldung
January 8, 2024 - The maximum theoretical heap limit for the 32-bit and 64-bit JVM is easy to determine by looking at the available memory space, 2^32 (4 GB) for 32-bit JVM and 2^64 (16 Exabytes) for 64-bit JVM.
🌐
GeeksforGeeks
geeksforgeeks.org › java › how-is-the-default-max-java-heap-size-determined
How is the default max Java Heap size determined? - GeeksforGeeks
July 23, 2025 - If a machine has 128 megabytes ... size is 64 megabytes, and greater than or equal to 1 gigabyte of physical memory results in a maximum heap size of 256 megabytes. The maximum heap size is not actually used by the JVM unless your program creates ...
🌐
IBM
ibm.com › support › pages › largest-possible-maximum-heap-size-websphere-java-64-bit-linux-x86-64
Largest Possible Maximum Heap Size for WebSphere Java 64 Bit on Linux x86-64
Maximum Heap in practice on WAS Linux x86-64 would be approximately -Xmx76t for Java heap because the rest, or 52 TB, is used by Native heap. *There is no Java heap size restriction from JVM, which potentially means there could be a setting as large as a 64-bit platform can address.
🌐
Oracle
forums.oracle.com › ords › apexds › post › what-is-max-heap-size-i-can-allocate-for-java-64-bit-9150
What is max heap size I can allocate for Java 64-bit - Oracle Forums
April 23, 2013 - Hi folks, We have the server running 64-bit Linux and Java. What is the highest number of heap size I can set? Let's say the server has 256 G of RAM. Can I allocate 128 GB to Java heap or ever more? ...
🌐
SetGetWeb
setgetweb.com › p › commerce7 › com.ibm.commerce.admin.doc › refs › rpmtuningjvmsettings.htm
JVM performance tuning - setgetweb.com
The tuning and deployment process for the 64-bit JVM can be simplified by not having to tune the disk offload performance. Significant operational savings can be realized for some customers. The ability to increase the maximum heap size beyond 1.5 Gb is beneficial when the store is experiencing ...
Find elsewhere
🌐
Blogger
javarevisited.blogspot.com › 2013 › 04 › what-is-maximum-heap-size-for-32-bit-64-JVM-Java-memory.html
Javarevisited: What is the maximum Heap Size of 32 bit or 64-bit JVM in Windows and Linux?
Theoretical maximum memory for x64 machines is 2^64 bit but again it depends on how much your operating systems allow. I read somewhere that Windows allowed a maximum of 32GB for 64 bit JVM.
🌐
Stack Overflow
stackoverflow.com › questions › 41763128 › jvm-heap-size-not-getting-more-than-1-6-gb-for-64-bit-jvm
java - JVM heap size not getting more than 1.6 GB for 64 bit JVM - Stack Overflow
On 32-bit JVMs, the default maximum heap size can be up to 1 GB if there is 4 GB or more of physical memory. On 64-bit JVMs, the default maximum heap size can be up to 32 GB if there is 128 GB or more of physical memory.
🌐
Java67
java67.com › 2016 › 02 › how-to-increase-heap-size-of-java-program-eclipse-command-line.html
How to Increase Heap Size of Java Program running in Eclipse [Example] | Java67
Practically, you will get around 1.5GB in 32-bit Windows, 2.5GB on 32 bit Linux and slightly more on 32-bit Solaris system. To use a larger heap size, you need to use a 64-bit JVM, where you can theoretically set quite a large heap space.
Top answer
1 of 16
96

You can ask the Java Runtime:

public class MaxMemory {
    public static void main(String[] args) {
        Runtime rt = Runtime.getRuntime();
        long totalMem = rt.totalMemory();
        long maxMem = rt.maxMemory();
        long freeMem = rt.freeMemory();
        double megs = 1048576.0;

        System.out.println ("Total Memory: " + totalMem + " (" + (totalMem/megs) + " MiB)");
        System.out.println ("Max Memory:   " + maxMem + " (" + (maxMem/megs) + " MiB)");
        System.out.println ("Free Memory:  " + freeMem + " (" + (freeMem/megs) + " MiB)");
    }
}

This will report the "Max Memory" based upon default heap allocation. So you still would need to play with -Xmx (on HotSpot). I found that running on Windows 7 Enterprise 64-bit, my 32-bit HotSpot JVM can allocate up to 1577MiB:

[C:scratch]> java -Xmx1600M MaxMemory
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.
[C:scratch]> java -Xmx1590M MaxMemory
Total Memory: 2031616 (1.9375 MiB)
Max Memory:   1654456320 (1577.8125 MiB)
Free Memory:  1840872 (1.75559234619 MiB)
[C:scratch]>

Whereas with a 64-bit JVM on the same OS, of course it's much higher (about 3TiB)

[C:scratch]> java -Xmx3560G MaxMemory
Error occurred during initialization of VM
Could not reserve enough space for object heap
[C:scratch]> java -Xmx3550G MaxMemory
Total Memory: 94240768 (89.875 MiB)
Max Memory:   3388252028928 (3184151.84297 MiB)
Free Memory:  93747752 (89.4048233032 MiB)
[C:scratch]>

As others have already mentioned, it depends on the OS.

  • For 32-bit Windows: it'll be <2GB (Windows internals book says 2GB for user processes)
  • For 32-bit BSD / Linux: <3GB (from the Devil Book)
  • For 32-bit MacOS X: <4GB (from Mac OS X internals book)
  • Not sure about 32-bit Solaris, but the code above has been tested in this answer.

For a 64-bit host OS, if the JVM is 32-bit, it'll still depend, most likely like above as demonstrated.

-- UPDATE 20110905: I just wanted to point out some other observations / details:

  • The hardware that I ran this on was 64-bit with 6GB of actual RAM installed. The operating system was Windows 7 Enterprise, 64-bit
  • The actual amount of Runtime.MaxMemory that can be allocated also depends on the operating system's working set. I once ran this while I also had VirtualBox running and found I could not successfully start the HotSpot JVM with -Xmx1590M and had to go smaller. This also implies that you may get more than 1590M depending upon your working set size at the time (though I still maintain it'll be under 2GiB for 32-bit because of Windows' design)
2 of 16
78

32-bit JVMs which expect to have a single large chunk of memory and use raw pointers cannot use more than 4 Gb (since that is the 32 bit limit which also applies to pointers). This includes Sun and - I'm pretty sure - also IBM implementations. I do not know if e.g. JRockit or others have a large memory option with their 32-bit implementations.

If you expect to be hitting this limit you should strongly consider starting a parallel track validating a 64-bit JVM for your production environment so you have that ready for when the 32-bit environment breaks down. Otherwise you will have to do that work under pressure, which is never nice.


Edit 2014-05-15: Oracle FAQ:

The maximum theoretical heap limit for the 32-bit JVM is 4G. Due to various additional constraints such as available swap, kernel address space usage, memory fragmentation, and VM overhead, in practice the limit can be much lower. On most modern 32-bit Windows systems the maximum heap size will range from 1.4G to 1.6G. On 32-bit Solaris kernels the address space is limited to 2G. On 64-bit operating systems running the 32-bit VM, the max heap size can be higher, approaching 4G on many Solaris systems.

(http://www.oracle.com/technetwork/java/hotspotfaq-138619.html#gc_heap_32bit)

🌐
javaspring
javaspring.net › blog › maximum-java-heap-size-of-a-32-bit-jvm-on-a-64-bit-os
Maximum Java Heap Size for 32-bit JVM on 64-bit OS: Theoretical vs Practical Limits Explained — javaspring.net
In contrast, a 64-bit JVM uses the 64-bit instruction set, enabling much larger heap sizes (often tens or hundreds of GB). The theoretical maximum heap size for a 32-bit JVM is 4GB—the total addressable memory.
🌐
Blogger
javarevisited.blogspot.com › 2011 › 05 › java-heap-space-memory-size-jvm.html
10 points about Java Heap Space or Java Heap Memory
The default size of Heap space ... throughput garbage collector in Java 1.5 default maximum heap size of JVM would be Physical Memory/4 and the default initial heap size would be Physical Memory/16....
Top answer
1 of 10
669

On Windows, you can use the following command to find out the defaults on the system where your applications runs.

java -XX:+PrintFlagsFinal -version | findstr HeapSize

Look for the options MaxHeapSize (for -Xmx) and InitialHeapSize for -Xms.

On a Unix/Linux system, you can do

java -XX:+PrintFlagsFinal -version | grep HeapSize

I believe the resulting output is in bytes.

2 of 10
130

For Java SE 5: According to Garbage Collector Ergonomics [Oracle]:

initial heap size:

Larger of 1/64th of the machine's physical memory on the machine or some reasonable minimum. Before J2SE 5.0, the default initial heap size was a reasonable minimum, which varies by platform. You can override this default using the -Xms command-line option.

maximum heap size:

Smaller of 1/4th of the physical memory or 1GB. Before J2SE 5.0, the default maximum heap size was 64MB. You can override this default using the -Xmx command-line option.

UPDATE:

As pointed out by Tom Anderson in his comment, the above is for server-class machines. From Ergonomics in the 5.0 JavaTM Virtual Machine:

In the J2SE platform version 5.0 a class of machine referred to as a server-class machine has been defined as a machine with

  • 2 or more physical processors
  • 2 or more Gbytes of physical memory

with the exception of 32 bit platforms running a version of the Windows operating system. On all other platforms the default values are the same as the default values for version 1.4.2.

In the J2SE platform version 1.4.2 by default the following selections were made

  • initial heap size of 4 Mbyte
  • maximum heap size of 64 Mbyte
🌐
Medium
medium.com › tier1app-com › does-32-bit-or-64-bit-jvm-matter-anymore-8d14b1b538d4
Does 32-bit or 64-bit JVM matter anymore? | by Ram Lakshmanan | Tier1app.com | Medium
June 10, 2019 - Below table summarizes maximum heap size (i.e. -Xmx) that you can set on 32-bit JVM: Whereas if you are running your application on a 64-bit JVM, maximum addressable memory space is 2⁶⁴ ...