The memory addressability provided by the architecture depends on the bit size of the processor — for example, 32 or 64 bits, or 31 bits in the case of the mainframe. The number of bits the process can handle determines the range of memory that the processor is capable of addressing: 32 bits provides an addressable range of 2^32, which is 4,294,967,296 bits, or 4GB. The addressable range for a 64-bit processor is significantly larger: 2^64 is 18,446,744,073,709,551,616, or 16 exabytes.
Some of the addressable range provided by the processor architecture is used by the OS itself for its kernel and (for JVMs written in C or C++) for the C runtime. The amount of memory used by the OS and C runtime depends on the OS being used, but it is usually significant: the default usage by Windows is 2GB. The remaining addressable space — termed the user space — is the memory available to the actual process that's running.
For Java applications, then, the user space is the memory used by the Java process, effectively consisting of two pools: the Java heap(s) and the native (non-Java) heap. The size of the Java heap is controlled by the JVM's Java heap settings: -Xms and -Xmx The native heap is the user space left over after the Java heap has been allocated at the maximum size setting.
Example memory layout for a 32-bit Java process:
The amount of object metadata varies by JVM version and vendor, but it typically consists of:
java.lang.Integer
object, for example, this is a pointer to the java.lang.Integer
class.The object metadata is then followed by the object data itself, consisting of the fields stored in the object instance. In the case of a java.lang.Integer
object, this is a single int
.
Example layout of a java.lang.Integer object for a 32-bit Java process: 128 bits of data are used to store the 32 bits of data in the int value, because the object metadata uses the rest of those 128 bits.
The primary difference is that the array object has an additional piece of metadata that denotes the array's size. An array object's metadata, then, consists of:
int
fields, this is a pointer to the int[]
class.