Java Virtual Machine Value object access and how to use the object reference (2)

Source: Internet
Author: User

Object access is ubiquitous in the Java language and is the most common program behavior, but even the simplest accesses involve the association between the three most important memory areas of the Java stack, the Java heap, and the method area , as in the following code:

ObjectnewObject();

We know that in the Java stack is a reference to the object, in the Java heap is the specific new object entity, depending on the specific type and the virtual machine implementation of the object memory layout (objects), the length of this block of memory is not fixed.
Also, in the Java heap, you must include address information that can find data for this object type, such as Object types, parent classes, implemented interfaces, methods, and so on, which are stored in the method area.

Since the Java stack is a reference to the object, then how we use the object there are two main ways to access it: using a handle and a direct pointer .

(1) using a handle:

If you use handle access, a block of memory will be partitioned into the Java heap as a handle pool, where the handle address of the object is stored, and the handle contains the specific address information of the object instance data and the type data, reference.

(2) Direct pointer

If you use direct pointer access, the layout of the Java heap object must consider how to place information about the access type data, the object address is stored directly in the reference,

There are advantages to the way these two objects are accessed, and the greatest benefit of using handle access is that reference stores a stable handle address that changes only the instance data pointer in the handle when the object is moved (which is a very common behavior when the object is garbage collected), and reference itself does not need to be modified.

The biggest benefit of using direct pointer access is faster speed , which saves time spent on pointer positioning, because object access is very frequent in Java, so this overhead is a significant execution cost.

Java Virtual Machine Value object access and how to use the object reference (2)

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.