Remember the analysis of Java objects in memory

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.