Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding max JVM heap size - 32bit vs 64bit

I've read the max heap size on 32bit Windows is ~1.5GB which is due to the fact that the JVM requires contiguous memory. Can someone explain the concept of "contiguous memory" and why you only have max 1.5GB on Windows?

Secondly, what then is the max heap size on 64 bit Windows and why is this different than what's available on 32 bit?

like image 254
Marcus Leon Avatar asked Mar 16 '10 19:03

Marcus Leon


People also ask

What is the maximum heap size of 32-bit and 64-bit JVM?

Max Heap Size. 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. In practice, due to various constraints, the limit can be much lower and varies given the operating system.

What is the max heap size for 32-bit JVM?

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.

What is the difference between 32-bit and 64-bit JVM?

In 32-bit JVM we can have less memory for heap size than in 64-bit JVM. In 64-bit JVM we can specify more memory for heap size than in 32-bit JVM. The limit for maximum memory in 32-bit is useful for 4G connectivity. It is particularly useful for java applications with large heaps.

What is the difference between 32-bit Java and 64-bit Java?

That's all about the difference between 32-bit and 64-bit JVM in Java. As you have seen, the key difference comes in how much memory you can allocate, while 32-bit JVM can just have 4G which is very less for modern, memory-intensive Java application, 64-bit JVM virtually gives you unlimited memory.


1 Answers

The 32-bit/64-bit part is unrelated to Java

It turns out that memory locations in a 32-bit system are referenced by 32-bit unsigned integers. This allows up to 2^32 possible memory locations. Since each location stores 1 byte you get 2^32 bytes or 4 GB if you prefer.

On a 64 bit system there are 2^64 locations, or 16 exabytes.

Now, in Windows, the contiguous part becomes a big issue, but that is just how Windows does things. The idea is that you need to have an entire "uninterrupted" range for your heap. Sadly, Windows allocates some memory somewhere in the middle. This basically leaves you with about half the left side or half the right side, about 1.5-2GB chunks, to allocate your heap.

Check out this question for more details on 32 vs 64 bit.

Edit: Thanks mrjoltcola for the exa prefix!

like image 76
Pace Avatar answered Oct 15 '22 00:10

Pace