Virtual machine class loading mechanism (preparation)

ready

The preparation phase is to formally allocate memory space for class variables. And the stage of setting the initial value of class variables, the memory used by these variables will be allocated in the method area. There are two confusing concepts in this stage. It should be emphasized that first of all, the memory allocation performed at this time only contains the class Variables modified by static. Instead of including instance variables, the instance variables will be allocated to the armor stack along with the object when the object is instantiated. Secondly, the initialization mentioned here usually refers to the zero value of the data type.
As mentioned above, under normal circumstances the initial value is zero, so there will be some special cases, if there is a constant value attribute in the attribute table of the class field. Then in the preparation phase, the variable value will be initialized to the value specified by the constant value attribute. For example, modified by final.

Guess you like

Origin blog.csdn.net/weixin_39472101/article/details/110704367