How to Implement object access in JVM (detailed description)

Source: Internet
Author: User

How to Implement object access in JVM (detailed description)

The previous article introduced the JVM runtime data zone.


Next, let's discuss how objects in JVM are allocated and accessed? This process will involve three important memory areas, namely the Virtual Machine stack, heap, and method zone, mentioned in the previous article.


For example, the following code is as follows:

ClassA object = new ClassA ();

If the code appears in a method, the "ClassA object" part will be reflected in the local variable table of the Java Virtual Machine stack, it stores reference data in the VM stack. The "new ClassA ()" part will be reflected in the Java heap memory to form a structured memory that stores the data values of all instances of the ClassA type. The length of this memory is not fixed, it varies according to the specific type and the Object Memory layout implemented by virtual machines. In addition, the Java heap must contain the address information that can be used to find data of this object type (such as object type, parent class, implemented interface, and method, these types of data are stored in the method area.

In the Java Virtual Machine specification, there are no rules on how to access specific objects through reference type reference. Currently, there are two mainstream implementation methods:

1. access through a handle. A memory block will be allocated in the Java heap as the handle pool. The reference stores the handle address of the object,

The handle contains the specific address information of the object instance and type data, as shown in:



2. for direct pointer access, you must consider how to place information about type data in the access method area in the layout of Java heap objects,

The address of the object instance is directly stored in reference, as shown in



Summary:

In both cases, the object access method has its own advantages. The biggest advantage of using the handle access method is that the reference stores a stable handle address.

The biggest advantage of using direct pointers is faster.

  • Previous detailed description of memory regions of Java Virtual Machine
Top
1
Step on

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.