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?
- 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