Java objects account for memory size calculation and common types of occupancy
The alignment of the hotspot is a 8-byte alignment----calculation formula: (object header + instance data + padding)% 8 equals 0 and 0 <= padding < 8
Common objects in a Hotspot machine
32-bit object header accounted for 8 bytes reference type 4 bytes
64-bit object header accounted for 16 bytes reference type 8 bytes
In 64-bit
Empty Object Array Object Header 24 increase one length increase one reference type length 64 bits is 8
Empty base data Type Array Object Header 24 increase one length increase the length of a base data type itself
After 64-bit compression
Normal Object Object Header 12 byte reference type 4 bytes
Object header 16 After array object compression
Add a length to increase the length of a base data type itself
----Because of the cross-platform nature of Java, the basic type of data on 32-bit and 64-bit memory size is the same
1Bytes = 8bit The number of data bits the CPU can process at a time----32-bit and 64-bit----4-byte and 8-byte
Memory layout for object headers
The running data of the object itself occupies one CPU pointer to the object instance.
The array is special because you want to save the length of the data to the head, so you have to account for the CPU again.
It can be seen that the object header of a normal object has two parts and the array object has three parts
Can deduce the
The object header of a 32-bit normal object is a 8 array of object headers that are 12
The object header of a 64-bit normal object is a 16 array of object headers that are 24
Remember the analysis of Java objects in memory