First, create an object
1, when the virtual opportunity to a new directive, first to check whether the parameters of this command to locate a symbol referenced in the class constant pool, and checks whether the class represented by this symbolic reference has been loaded, parsed and initialized. If not, then you must perform the appropriate class loading process.
2, the virtual machine will allocate an object of newborn
- Pointer collision: the Java heap memory is absolutely regular , all memory is used aside, free memory on the other side, the middle stood a pointer as an indicator cut-off point, and that the allocated memory is just the moving the pointer size equal to the period of the object distance in the free space there
- Free list: Java heap memory is not regular, free memory and used memory intertwined, the virtual machine must maintain a list of which memory blocks are available on the record, find a list from the time allocated plenty of space allocated to the object instance, and update records on the list.
3, the virtual machine needs to allocate memory space is initialized to a value of zero (not including the object header)
4, the virtual machine is subject to the necessary settings, for example, which this object is an instance of the class, how to find information such as metadata, hash code of the object, GC target sub-generation information age. This information is stored in the object object head (Object Header) in
5, the implementation of <init> method, in accordance with the wishes of the programmer to initialize the object, so that a real object is considered completely available emerge.
Second, the object memory layout
- Mark Word: storage of runtime data object itself, such as the hash code (HashCode), GC generational age, the lock status flags, thread holds the lock, missed the thread ID, timestamp bias .
This part of the length of data in 32-bit and 64-bit virtual machine (not open compressed pointer), respectively, and for the 32bit 64bit, officially called "Mark Word".
- Type pointers: a pointer to its class object is metadata, the virtual machine is determined by the pointer which this object is an instance of the class
Third, access the location of the object
java program required to operate the particular object on the heap by the reference data on the stack.
Handle visit:
Direct pointers: