- Check whether the object is loaded, linked, initialized: whether symbolic references to the class are located in the constant pool, and check whether they are loaded, parsed, initialized,
- Allocate memory for objects: first calculate how much space an object occupies, and then allocate a chunk of memory in the heap for a new object
- Dealing with concurrency security: Object creation is a frequent process that requires concurrency issues to be addressed.
- The CAS fails to retry and the region is locked. Ensure that pointer updates are atomic
- (TLAB,Thread Local Allocation Buffer) : Allocates memory to different Spaces based on threads
- Initialize the allocated space: for example int=0, Boolean =0
- Set the object header of an object: Store the object’s owning class (metadata information of the class), HashCode of the object, GC information of the object, lock information and other data in the object’s object header
- Execute init method to initialize (assign initial value)
Object memory layout
Internal structure: object header, instance data, alignment padding (multiples of 8)
Instance data objects actually store valid information, including rules for various types of fields (both inherited and owned) defined in program code:
- Fields of the same width are always assigned together
- Variables defined in a parent class appear before subclasses
- If the CompactFields argument is true(the default is true), the narrow variable of the subclass may be inserted into the gap of the parent class variable