Max memory for 64bit Java
Asked Answered
P

5

20

What's the maximum amount of heap space that one can allocate for java on a 64-bit platform? Is it unlimited?

Psephology answered 19/1, 2010 at 13:18 Comment(1)
Why do you think it's unlimited?Michelmichelangelo
C
18

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 :)

Compliance answered 19/1, 2010 at 14:37 Comment(1)
1000g worked for you? I thought java would validate if there's enough memory before taking in that option.Levite
H
14

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.

Hartwell answered 19/1, 2010 at 13:24 Comment(3)
@Stephen, I edited the answer before you posted your comment. WolframAlpha rules!Hartwell
Wouldn't want to wait for a full collect on that!Smalley
Just when i thought Java started to get boring, i run into old posts like these. Faith in OOPs, restored.Iaria
K
3

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.

Kauslick answered 19/1, 2010 at 13:41 Comment(1)
The 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)Leniency
P
2

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.

Prostomium answered 19/1, 2010 at 13:52 Comment(2)
Can you please cite a reference?Woolly
You 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.Prostomium
F
0

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).

Flagella answered 19/1, 2010 at 13:24 Comment(1)
For 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.Leniency

© 2022 - 2024 — McMap. All rights reserved.