<> one , Object creation process

1.loading: Load corresponding class class file .

2.linking: Verify file format (verification), Allocate memory for static variables of a class , And initialize to the default value (preparation), Convert symbolic references to direct references (resolution).
3.initializing: The initialization process assigns the correct initial value to the static variable of the class .
4. Allocate memory for objects .
5. Assign default values to member variables .
6. Call construction method : Default initial value of member variable , Other statements .

<> two , Object structure

1. Object header :Mark Word( Tag field ),Class Pointer( Type pointer ). among Class
Pointer It is used by the virtual machine to determine the instance of which class this object is through this pointer ,Mark
Word Used to store the runtime data of the object itself , as : Hash code ,GC Generational age , Lock status flag , thread id etc .
2. Instance data : Store the attribute data information of the class , Include attribute information of the parent class .
3. Fill data : Since the virtual machine requires that the starting address of the object must be 8 Integer multiple of bytes , Used to fill .
The array object will have an additional array length of four bytes .

<> three , Object size in memory

Object object = new Object();
Mark Word( Tag field ):8 byte .
Class Pointer( Type pointer ):4 byte .
altogether 8+4=12 byte , But not 8 Multiple of , Will fill in 16 byte .

<> four . Object allocation process

1.new An object , First judge whether the stack can be stored , If it can be allocated on the stack , The object is cleared when you leave the team .
2. If the stack cannot be stored , Large objects are stored directly in heap memory , until MajorGC Clear when .
3. Small objects stored in Eden Eden Park ,Minor GC If the object is not cleared , Transfer to survivor Two areas of , Meet the age transfer to the elderly generation .

Technology