A picture to understand the flow chart of creating an object in the JVM

Insert picture description here
1. The bytecode file is loaded into the distribution area; it is
divided into a static area and a
non-static area
2. Then the method runs into the stack memory, the local variables in the running method are also in the corresponding stack, and
the objects created after the method runs enter the heap , Member variables also enter the heap;
each object in the heap has an address value, and the member variables have default values ​​(string is null, the value is 0), and
there is an address reference to the method in the method area in the heap. Get the corresponding method through the address reference to the method area
3. The local variables in the stack find the corresponding member variable from the address value to the heap and assign it to him, and then get the reference address of the member method in the heap to get the corresponding method and assign it to the method area , Finally push the stack to run, first in, last out, and finally pop the stack. Free up space

Guess you like

Origin blog.csdn.net/weixin_47785112/article/details/109223902