Deep understanding of Java Virtual machines: Hotspot Virtual machine objects uncover __java

Source: Internet
Author: User
what is hotspot?

By mentioning the hotspot VM, all Java programmers know that it is the virtual machine in the Sun JDK and OPENJDK and the most widely used Java virtual machine. But not all of us know that the virtual machine, which now looks "pure", was not originally developed by Sun, but was designed by a small company called "Longview Technologies", even though the virtual machine was not originally developed for the Java language. It comes from the Strongtalk VM, and quite a lot of this virtual machine comes from a virtual machine designed to support the self language's goal of achieving more than 50% of the execution efficiency of C language.

Sun has noted that the virtual machine has many good ideas and practical results in JIT compilation, and acquired the Longview Technologies Company in 1997 to obtain the hotspot VM.

The HotSpot VM inherits the benefits of Sun's previous two commercial virtual machines (such as the exact memory management mentioned earlier), there are also many of its own new technical advantages, such as its name HotSpot refers to its hot Code detection technology (in fact, two VMs are essentially the same period of independent products, Hotspot is a bit earlier, hotspot is the exact GC at the beginning, and exact VM has almost the same hot spot detection as hotspot. In order to exact VM and HotSpot VM which is Sun's main support VM product, there has been an argument within Sun company that HotSpot defeat exact is not a technical victory), HotSpot The Hotspot code detection capability of a VM can find the most compiled code by executing the counter, and then notifies the JIT compiler to compile it in a method-by-unit way. If a method is called frequently, or the number of effective loops in the method is large, the standard compilation and OSR (stack substitution) compilation actions are triggered respectively. Work properly with the interpreter through the compiler, you can balance the optimized program response time against the best execution performance, and you don't have to wait for local code output to execute the program, and the time pressure for Just-in-time compilation is also relatively low, which helps to introduce more code optimization techniques to output more-quality local code.

At the JavaOne conference in 2006, Sun announced that it would eventually open up Java and, in the ensuing year, release the source code under the GPL with various parts of the JDK (including, of course, the hotspot VM).
And based on this, the OPENJDK is established. In this way, the HotSpot VM becomes a common virtual machine for the Sun JDK and openjdk two implementations of extremely close JDK projects.

In 2008 and 2009, Oracle companies acquired both Bea and Sun, so Oracle has two outstanding Java Virtual machines: JRockit VM and hotspot VM.

Oracle announces that the two virtual machines will be integrated to complement each other in the near future (approximately when JDK 8 is released).
The integrated approach is largely based on hotspot, porting JRockit's outstanding features, such as using JRockit's garbage collector and Missioncontrol service, using the hotspot JIT compiler and mixed run-time systems. one, object creation

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, then the corresponding class loading process must be done first.

After the check is passed, the virtual machine allocates memory for the newborn object in the heap, and the memory required by the object can be fully determined when the class is loaded. If the memory in the heap is absolutely regular, memory will be divided into idle and used on both sides, with a pointer in the center as a point of demarcation indicator, allocating memory is just to the free space over the side of the object to move over a distance of equal size, become "pointer collision (Bump the pointer)" 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 divide the objects into instances, and updates the records on the list, which is called the free list. Choose which allocation method is determined by whether the Java heap is structured, and whether the Java heap is structured and determined by whether the garbage collector used has a compression collation function.

The virtual machine needs to initialize the allocated memory space to 0 values, and if the Tlab (local thread allocation buffer) is used, the process can also be advanced to Tlab allocation.

The virtual confidential makes the necessary settings for the object. The necessary information will be stored in the object header.

After the new instruction is executed, the method is followed to initialize the object according to the programmer's will. second, the memory layout of the object

In the hotspot virtual machine, the layout of objects stored in memory is divided into Object headers (header), instance data (Instance), and alignment padding (Padding).

The object header contains two pieces of information: The first part is used to store run-time data for the object itself. This portion of the data is 32bit and 64bit in length in 32-bit and 64-bit virtual machines (without the compression pointer turned on), called "Mark Word"; The second part is a type pointer, a pointer to its class metadata that the virtual machine uses to determine which class the object is an instance of. If the object is a Java array, there must also be a piece of data in the object header to record the length of the array.
Instance data stores the actual valid information for the object, which is the various types of field content defined in the program code.
Alignment padding does not necessarily exist, nor does it have a special meaning, it only acts as a placeholder.

third, the object's access location

The way in which objects are accessed depends on the implementation of the virtual machine, and there are two ways in which the current mainstream access is using a handle and a direct pointer.

Using handle access, a chunk of memory is drawn in the heap as a handle pool, where the object's handle address is stored in the reference, and the handle contains the specific address information of the object instance data and the type data.

With direct pointer access, the layout of the heap object must consider how to place information about the access type data, while the reference store is directly the object address.

The advantage of using a handle is that the object moves only to change the instance data pointer in the handle, and the reference itself does not need to be modified.
The most benefit of using direct pointer access is faster.

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.