JVM: Hotspot virtual machine object

In HotSpot virtual machine, objects in the layout may be stored in the memory divided into three regions: object header (Header), instance data (Instance data) and alignment padding . (Padding) object header comprises two parts information, the first portion of memory own runtime data, such as a hash value, the GC generational age lock state flag thread holds the lock, the lock biased ID, timestamp bias, this part of the length of data in the virtual machines 32 and 64 of the (unopened compression pointers) were 32bit and 64bit, Word official called Mark .

Memory contents Flag status
The hash code of the object, the object generational Age 01 Unlocked
Pointers to lock records 00 Lightweight lock
Heavyweight locks pointer pointing 10 Expansion (heavyweight lock)
Empty, no need to record 11 GC mark
Tend ID, timestamp bias, the object generational Age 01 Be biased

Find object metadata information does not have to go through the object itself. If the object is an array, the data object is a recording head must have a length of the array, but it can not determine the size of the array from the metadata.

Examples of the data portion is valid information object is actually stored, but also various types of field contents is defined in the program. Whether it is the parent class inherited or defined in a subclass. This section will affect the virtual machine allocation policy parameters and fields influence in the order defined in Java source code.

Alignment padding is not necessarily exist, there is no special meaning, merely a placeholder effect. The size of the object must be an integer multiple of 8 bytes, sample data does not satisfy a multiple of 8 bytes will be filled with complement.

Access to an object positioned
to create an object is to use objects, Java programs need to operate a specific object on the heap by reference data on the stack. reference type is a reference to an object, and does not specify what kind of positioning is a specific location for accessing the heap object,
to achieve these depend on the virtual machine. There are mainstream access method handles and direct pointer two kinds.

  1. If a handle words, Java heap memory to be divided as a pool handle, Reference handler address is stored in the object, and the handle contains object instance data and object type data of specific address information.
  2. If a direct pointer (small cost, relatively fast), then the Java heap object must consider placing access object data type information, and is stored in the reference object address .

Guess you like

Origin www.cnblogs.com/magic-sea/p/11614370.html