Java Reference
In-Depth Information
The data area is used to store the values for all instance variables of the object. The header area layout is fixed for a
particular JVM implementation whereas the data area layout is dependent on the object type. The Java Hotspot virtual
machine uses two machine-words (in 32-bit architecture one word is 4 bytes) for the object header. If the object is
an array, it uses three machine-words for its header. One extra word in the header is used to store the array length.
However, most JVMs use three-machine words for an object header. Figure 11-1 depicts the object layout for the Java
Hotspot VM and the IBM VM.
Object header
classptr
size + flags
classptr
hash + age + lock
mptr
hash + age + lock
arraylengt h
locknflags
Object Data
Array Elements
Object Data
Java array object layout in Sun
Hotspot VM
Java object layout in Sun Hotspot VM
Java object layout in IBM VM
Figure 11-1. The layout of an object in the Java Hotspot VM and the IBM VM
The Java Hotspot VM uses a variable length object header to save memory on the heap. Since most Java objects
are small, one machine-word savings per object for non-array objects is a significant heap space savings. The Java
Hotspot VM's object header contains the following information:
classptr : This is the first machine-word in the object layout. It contains a pointer to the
class information of the object. The class information includes the object's method table, the
object's size, and a pointer to a Class structure, which contains information about the class of
the object, etc.
hash + age + lock : This is the second machine-word in the object header. It contains the
object's hash code, age information, and lock fields. Age information is used in the process of
reclaiming the object's memory by the generational garbage collector. The generation garbage
collector is a special type of garbage collector that uses the object's age in its algorithm to
reclaim an object's memory.
arraylength : This is the third machine-word in the object header. It is included only if
the object is an array. It contains the length of the array. In this case, the object's data area
contains the array elements.
 
Search WWH ::




Custom Search