What's the maximum amount of heap space that one can allocate for java on a 64-bit platform? Is it unlimited?
-
Why do you think it's unlimited? – Jack Leow Jan 19 '10 at 13:40
5 Answers
Theoretically 264, but there might be limitations (obviously)
According to this FAQ it's only limited by memory and swap space on the local system:
On 64-bit VMs, you have 64 bits of addressability to work with resulting in a maximum Java heap size limited only by the amount of physical memory and swap space your system provides.See also Why can't I get a larger heap with the 32-bit JVM?
Also keep in mind you need to set the max heap via command line. Without an -Xmx command. without it Java uses 64mb + 30% = 83.2mb as a default max heap on 64 bit machines according the same FAQ.
java -Xmx1000g myClass
works fine on my machine. But it dosn't seem to yet support the 't' modifier so you can't specify max memory in terabytes yet :)

- 4,570
- 1
- 21
- 19
-
1000g worked for you? I thought `java` would validate if there's enough memory before taking in that option. – asgs Oct 02 '16 at 09:40
If you could make every atom in the universe into a byte of RAM, you could allocate it in a 64 bit address space.
Actually, that's a slight exaggeration.
There are 10^80 atoms in the universe (according to WolframAlpha), and 2^64 bytes of address space in a 64 bit system, so you'd only be able to address 1 out of every 5x10^60 atoms. But if you have 18 qintillion bytes of RAM, you'd probably need a couple of quantum black holes to power it with.

- 179,021
- 58
- 319
- 408
-
@Stephen, I edited the answer before you posted your comment. WolframAlpha rules! – Paul Tomblin Jan 19 '10 at 13:34
-
2
-
1Just when i thought Java started to get boring, i run into old posts like these. Faith in OOPs, restored. – Makarand Oct 05 '17 at 09:41
This probably depends on the system your VM is running in. If you are running a AMD x64 architecture the address space of currently shipped processors uses 48 Bits, not 64. This results in a theoretical maximum of roughly 256 TB. (See http://en.wikipedia.org/wiki/X86-64)
I am not a specialist in VMs, but any modern OS typically will give as much memory as there is physical RAM plus available virtual memory. Probably thats what the VM will pass to your application depending on its configuration.

- 12,032
- 10
- 54
- 92
-
3The relevant AMD manual states that the virtual address space is in fact 64 bits (Chapter 2.2.1, AMD64 Architecture Programmer’s Manual, v3.14, September 2007) – MSalters Jan 19 '10 at 14:47
With recent VMs from Sun, the practical heap limit size is usually 512 times the available physical and/or virtual memory. Even if the theoretical limit is much higher, the VM will allocate 1 byte for maangement purposes for each 512 bytes of heap memory on startup, so 1TB of heap will immediately require 2GB for the memory management.

- 33,923
- 7
- 70
- 94
-
-
1You won't find a reference for that anyhwere. It's simply the way the VM is implemented, or at least was implemented in current versions two years ago. – jarnbjo Nov 17 '11 at 15:21
In theory its between 2^63
and 2^64
bytes.
In practice it is limited by the amount of physical memory and swap space available on your machine. And the physical memory is in turn limited by your chipset (i.e. the number of address pins on the physical memory address bus) and motherboard (i.e. the number and size of the DIMM sockets).

- 698,415
- 94
- 811
- 1,216
-
2For AMD64, the current specs foresee 40-52 address pins. Also, they support NUMA architectures where each processor has a chunk of memory which other processors can only access indirectly. – MSalters Jan 19 '10 at 14:49