Understanding max JVM heap size - 32bit vs 64bit
Asked Answered
F

3

33

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?

Funchal answered 16/3, 2010 at 19:40 Comment(2)
The limit for any 32-bit jvm on a 32-bit OS ranges from about 1.2 GB (some versions of Windows) to 2.0 GB (Solaris). 32-bit jvm on 64-bit Solaris can get 4 GB. I think the maximum 64-bit jvm on 64-bit Windows is 32GB.Reduction
I would have expected a 32bit JVM on a 64bit Win7 to be able to get 4GB as well - but that isn't the case - it's those 1.5GB again... (JDK5)Levesque
M
37

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!

Mot answered 16/3, 2010 at 19:43 Comment(2)
exa comes after peta ;) I's somewhat implied already, but I think it's worth pointing out that, since the address space is so large, it's easier to find a larger contiguous block of available address space--which is why you can specify a much larger heap size on a 64-bit OS.Balanced
Its also worth noting that for memory, an Exabyte is 1024^6 bytes and an Exabyte of storage is 1000^6 bytes. So 2^64 is 16 Exabytes of memory and 18.4 Exabytes of storage. ;)Polacre
R
6

Contiguous simply means "without gaps", one long single segment. The amount is limited by how large a segment the OS can map for your process. Whether Java requires a contiguous heap or not is an implementation issue specific to JVM and may not exist for other VMs.

Radiotelegraphy answered 16/3, 2010 at 19:46 Comment(0)
B
4

Contiguous memory is not the problem limiting windows to use only 1.2 GB of heap. Even though min/max heap defined, JVM would occupy max heap from system memory while starting. It will then reference only min heap within the occupied system memory until it had to expand. Contiguous memory of max heap is required to start JVM in most of the implimentation to improve performace.

As Marcus explained above the limit of 32 bit hardware is 4GB for a single process(thread). Every operating system address this 4GB diffrenetly. 4GB is majorly split as kernel space and user space. In 32 bit windows the max user space is close to 1.5 GB. There is option to boot windows with /3GB switch to have more userspace.

Breunig answered 30/7, 2010 at 18:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.