Max memory for 64bit Java
What's the maximum amount of heap space that one can al开发者_如何学运维locate for java on a 64-bit platform? Is it unlimited?
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 :)
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.
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.
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.
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).
精彩评论