In Java objects for us to be familiar with, but also simple to use, when you want to new one, so ah we programmers do not lack objects! So do we really know who we’re talking to? What are its components? In the HotSpot VIRTUAL machine, which is our common virtual machine. Object composition is divided into three areas: object header, instance data, and alignment fill.

Object head

The object header is divided into two parts: the object’s own runtime data, and the type pointer

Object’s own runtime data, such as: HashCode, lock status flags, locks held by threads, bias thread ID, bias timestamp, GC generation age, etc. On a 32-bit OR 64-bit VM (if the compression pointer is not enabled), the data length is 32 and 64 bits, respectively. This part is called the “Mark Word”.

In addition, Mark Word is designed to store more information in a small space without fixed data structure. It stores different data according to different states. For example, in the 32-bit case, the stored contents change as follows

A type pointer, which is a pointer to the object’s class metadata, is used to know which class instance the object is, but not all virtual machine implementations use this to find class metadata.

Like HotSpot virtual machine, we all know that when an object is new, it stores a reference to the object, which stores the address of the object instance. Some virtual machine implementations store a reference to the address of an object handle, which contains the address of the object instance and the address of the object type.

In other words, a VM of this type has a handle pool, which stores the instance data address and class data address of an object. Therefore, the VM of this type can directly find the instance of the class to which the object belongs by using the class data address in the handle pool.

The instance data

Instance data is the area of data that an object actually stores, the contents of various types of fields.

Alignment filling

This section serves no other purpose than as a placeholder, mainly because the memory management of the HotSpot VIRTUAL machine requires that the object size be a multiples of 8 bytes, and the object header is exactly that, but the instance data is not necessarily that, so it needs to be aligned to fill completion.


If there are mistakes welcome to correct!

Personal public account: Yes training level guide