Object analysis based on hotspot and Java heap as an example

Source: Internet
Author: User

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

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.