In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Today, I will talk to you about how to analyze the composition of Java objects, which may not be well understood by many people. In order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.
In java, objects are familiar to us and easy to use. When do you want to new one, so we programmers have no shortage of objects!
Do we really know someone? Which parts does it consist of?
In the HotSpot virtual machine, which is our common virtual machine. The object composition is divided into three areas: object header, instance data, and alignment padding.
Object head
The object header is divided into two parts: the run-time data of the object itself, and the type pointer.
Object's own runtime data, such as: HashCode, lock status flag, lock held by thread, bias thread ID, bias timestamp, GC generation age, and so on. This part of the data length is 32bit and 64bit in 32-bit and 64-bit virtual machines (if the compression pointer is not enabled), respectively. This section is called "Mark Word".
And Mark Word is designed to have no fixed data structure to store more information in a very small space, it will store different data according to different states. For example, in the case of 32-bit, the change in storage content is as follows
The type pointer, that is, the pointer to the class metadata of this object, is used to know which class instance the object is, but not all virtual machine implementations use this to find the class metadata.
Like the HotSpot virtual machine, we all know that usually new an object stores the reference of the object, this reference stores the address of the object instance, and the implementation of some virtual machines is that this reference stores the handle address of an object, and the handle address contains the object instance address and the object type address.
That is, this kind of virtual machine has a handle pool, and the instance data address and class data address of the object are stored inside the handle pool, so this kind of virtual machine can directly find the instance of which class the object belongs to through the class data address in the handle pool.
If the object is an array, you need another place to record the length of the data.
Instance data
Instance data is the data area that the object really stores, various types of field content.
Align fill
This part of the content has no other meaning, but plays the role of a placeholder, mainly because the memory management of the HotSpot virtual machine requires that the size of the object must be an integer multiple of 8 bytes, and the object header is exactly an integer multiple of 8 bytes, but the instance data is not necessarily, so it needs to be filled with alignment.
After reading the above, do you have any further understanding of how to analyze the composition of Java objects? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.