1. Creation of objects
The first virtual opportunity to a new instruction is to check whether the parameter of the directive can be positioned in the constant pool for the symbolic reference of a class, and to check whether the class represented by the symbol reference has been loaded, parsed, and initialized. If not, you must first perform the appropriate class loading process.
After the class load check passes, the virtual machine then allocates memory for the new object. The size of the memory required by an object is fully determined after the class is loaded, and the task of allocating space to an object is equivalent to dividing a size of memory from the Java heap.
Here are two ways to allocate: pointer collision: Assuming that the Java heap memory is structured, all used memory aside, free memory on the other side, and a pointer in the middle of the indicator as the demarcation point, then allocating memory size is just the pointer to the idle side to move a paragraph and object size to wait for the distance.
Idle list: If the Java heap memory is not structured, you must maintain a list of which memory blocks are available, and at the time of allocation, find a large enough space in the list to be partitioned to the object instance and update the records on the list.
In addition to how to divide the available space, there is another issue to consider, object creation is very frequent behavior, in the concurrency of the thread there is a security problem,
Two solutions: 1. Synchronizing actions for allocating memory space
2. The actions of the memory allocation are divided in different spaces by thread, that is, each thread allocates a small chunk of memory in the Java heap, called the local thread allocation buffer (thread local Allocation buffer,tlab) which thread allocates memory, On which thread the Tlab is allocated, only the Tlab runs out and assigns a new Tlab, which requires a synchronous lock.
Next, the virtual machines are required to set the object. For example, this object is the instance of which class, how to find the metadata information of the class, the object's Harlem code, the object's GC generational age, and so on.
The next step is some init initialization.
Object analysis based on hotspot and Java heap as an example