Home > Java > javaTutorial > Detailed introduction to object access in Java virtual machine (picture)

Detailed introduction to object access in Java virtual machine (picture)

黄舟
Release: 2017-03-25 10:36:20
Original
1387 people have browsed it

This article mainly introduces the relevant information about the detailed explanation of object access in the java virtual machine. Friends in need can refer to the following

Detailed explanation of object access in the java virtual machine

Object access will involve three memory areas: Java stack, Java heap, and method area.

Such as the following code:

Object objectRef = new Object();
Copy after login

Assuming this code appears in the method body, the "Object objectRef" part will be reflected in the local variables of the Java stack, as A reference type data appears. The "new Object()" part will be reflected in the Java heap, forming a structured memory that stores all instance data values ​​of the Object class type, based on the specific type and the object memory layout implemented by the virtual machine. Differently, the length of this memory is not fixed. In addition, the java heap must also include address information that can find this object type data (such as object type, parent class, implemented interface, methods, etc.). These data types are stored in the method area.

The reference type in the Java virtual machine specification only stipulates a reference address pointing to the object, and does not define the method through which this reference should be located to access the object location in the Java heap. Therefore Different virtual machine implementations may have different access methods. There are two mainstream methods: using handles and direct pointers.

#: Java pile will be divided into a piece of memory as the handle pool. Reference is stored in the handle address of the object, and the handle contains the object instance data and type data's respective specific address information.

Detailed introduction to object access in Java virtual machine (picture)

Pointer access method: The reference variable directly stores the address of the object, and part of the java heap object stores the object instance data, and the other part stores Object type data.

These two methods of accessing objects have their own advantages. The biggest advantage of using the handle access method is that the stable handle address is stored in the reference and only needs to be changed when the object is moved. The instance data pointer in the handle, and the reference does not need to be changed. The biggest advantage of using the pointer access method is that it is fast. It saves the time overhead of pointer positioning. As far as the virtual machine is concerned, it uses the second method (direct pointer access).

The above is the detailed content of Detailed introduction to object access in Java virtual machine (picture). For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template