Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the structure of the Java object in memory

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

Most people do not understand the knowledge points of this article, "what is the structure of Java objects in memory?" so the editor summarizes the following contents, detailed contents, clear steps, and has a certain reference value. I hope you can get something after reading this article. Let's take a look at this "what is the structure of Java objects in memory".

1. Object head, which is divided into MarkWord and KlassPoint.

MarkWord (tag field): the HashCode of the object is stored by default, instead of age and lock tag location information. It reuses its own storage space based on the state of the object, that is, the data stored in the MarkWord changes as the location of the lock tag changes.

KlassPoint (type pointer): a pointer to the metadata of its class through which the virtual machine determines which class the object belongs to.

2. Instance data. This part mainly stores data information and parent class information.

3. Align the fill. Because the virtual machine requires the starting address of the object to be an integer multiple of 8 bytes, the padding data does not necessarily exist, just for byte alignment.

An empty object occupies 8 bytes because of alignment padding, less than 8 bytes alignment padding will help us to complete it automatically.

Example

Public class TestStudent {public static void main (String [] args) {int n = 10; / / Stack int m = 10; / / Stack Student stu = new Student (); / / attribute assignment stu.name= "Zhang San"; System.out.println (stu.name); / / null Zhang San System.out.println (stu.age); / / 0 / / call String name= "ls"; / / Local variable (constant pool) String aaaa= "ls"; String pwd = "123" Stu.login (name,pwd); System.out.println ("name:" + name); / / lsSystem.out.println ("execute");}} class Student {/ / attribute String name;int age;// user login / / String userName;// String pwd;public void login (String userName,String pwd) {System.out.println (userName+ "= =" + pwd); / / ls 123} public void show () {System.out.println ("name:" + name + ", age:" + age ") }} the above is the content of this article on "what is the structure of Java objects in memory". I believe we all have a certain understanding. I hope the content shared by the editor will be helpful to you. If you want to know more about the relevant knowledge, please follow the industry information channel.

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.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report