Java Virtual machine Learning-Object access

Source: Internet
Author: User

Object access involves the three memory regions of the Java stack, the Java heap, and the method area.

As the following code:

[Java]View Plaincopyprint?
    1. Object objectref = new Object ();

Assuming that this code appears in the method body, the "Object objectref" section will be reflected in the Java stack's local variables, as a reference type data appears. The "new Object ()" section will be reflected in the Java heap, forming a piece of structured memory that stores all instance data values of type object, and the length of the memory is not fixed depending on the type and the object memory layout implemented by the virtual machine. 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.

The reference type only specifies a reference address to the object in the Java Virtual Machine specification, and does not define the way that the reference should be positioned to access the object's location in the Java heap, so different virtual machine implementations may have different access methods. There are two main ways of doing this: using handles and direct pointers.

Handle Access : A chunk of memory is partitioned into the Java heap as a handle pool, where the handle address of the object is stored in the reference, and the handle contains the specific address information for the object instance data and the type data.

pointer Access : The address of the object is stored directly in the reference variable, while the Java heap object is stored as part of the object instance data, and the other part stores the object type data.

There are advantages to the two ways of accessing objects, and the greatest advantage of using handle access is that reference stores a stable handle address, which only needs to change the instance data pointer in the handle when the object is moved, and reference does not need to be changed. The greatest benefit of using pointer access is the speed, which saves the time overhead of a pointer location, which in the case of a virtual machine uses the second method (direct pointer access).

Java Virtual machine Learning-Object access

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.