Deep understanding of Java Virtual Machine--hotspot virtual machine objects __JVM

Source: Internet
Author: User
Tags garbage collection
1. Creation of Objects 1.1 class Load Check

When a virtual opportunity comes to a new command, it first checks whether the parameter of the instruction can navigate to a class's symbolic reference in a constant pool, and checks whether the class represented by the symbolic reference has been loaded, parsed, and initialized. If not, the corresponding class loading process is performed first. 1.2 Allocating memory

Divides a certain size of memory from the Java heap into a newborn object.

Whether the garbage collector has the compression collation function determines whether the Java heap is structured. and whether the Java heap is structured determines how the memory is allocated. "Pointer collision": If the memory in the Java heap is absolutely regular, all the used memory aside, the free memory on the other side, with a pointer in the center as the indicator of the demarcation point, the allocated memory is just the pointer to the free space to move a paragraph and the object size of the same distance. Free list: If the memory in the Java heap is not regular, the virtual machine maintains a list of which memory blocks are available, finds a large enough space in the list to partition the object instance, and updates the records on the list.

Concurrent thread security synchronizes the actions of allocating memory space. The atomic nature of the update operation is ensured by using the CAS with failed retries. The memory allocation action is divided into different spaces according to the thread. Each thread allocates a small chunk of memory in the Java heap, called the local thread allocation buffer (TLAB). Which thread allocates memory, is allocated on which thread's Tlab. Synchronous locking is required only when Tlab is used up and a new tlab is allocated. 1.3 Initialization

The virtual machine initializes the allocated memory space to a value of 0 (excluding the object header). 2. The memory layout of the object

In a hotspot virtual machine, the layout in which objects are stored in memory is divided into 3 areas: Object Headers (header), instance data (Instance), and alignment padding (Padding). 2.1 Object Headers

The object header contains two pieces of information: The Run-time data that stores the object itself, such as hash code, GC generational age, lock status flag, thread-held lock, biased thread ID, biased timestamp, and so on. A type pointer, a pointer to its class metadata that the virtual machine uses to determine which class the object is an instance of. 3. Access location of the object

Java programs need to use the reference data on the stack to manipulate specific objects on the heap. 3.1 using handle access

The Java heap divides a piece of memory to serve as a handle pool, where the object's handle address is stored in the reference, and the handle contains specific information about the instance data and the type data.

Reference-> Handle Pool-> instance pool (object instance data) + Method area (object type data)

Advantage: The stable handle address is stored in the reference, and when the object is moved (which is very common when the object is moved by garbage collection), only the instance data pointer in the handle is changed, and the reference itself does not need to be modified. 3.2 Using direct pointer access

Place information about the access type data in the Java heap object. And the reference is stored directly is the object address.

Reference-> object instance data-> method Area (object type data)

Advantages: Fast, saving the time cost of pointer positioning.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.