Java Virtual Machine Specification read notes-run-time data area

Source: Internet
Author: User
Tags instance method

Java Virtual Machine Runtime data area includes the PC Register, Java VM Stack, Java heap, method area, local method stack, run a constant pool six parts.

1. PC Register

PC registers (also called program counters, programs Counter register), each Java Virtual machine thread has its own PC register. PC Register Error The byte-code instruction address of the current executing method, and if the current method is native, the value of the PC register is undefined.

2. Java Virtual machine stack

Java Virtual machine stack, each Java Virtual machine thread has its own private Java Virtual machine stack, which is used to store stack frames.

2.1 Stack Frame

Stack frame (Frames) a data structure used to store local variables and partial process results, and also to handle dynamic link (linking), method return value, Exception dispatch (Dispatch Exception).
The stack frame is created with the invocation of the method, which is destroyed with the method's end (the method completes gracefully and throws the exception that is not caught within the method).

Each stack frame has its own local variable table (local Variables), an operand stack (Operand stack), and a reference to the run constant pool of the class to which the current method belongs.

A thread only the stack frame of the currently executing method is active. This stack frame is the current stack frame, the corresponding method of the stack frame is the current method, the class that defines the method is the current class.

After the current stack frame is executed properly, the caller's state will also need to be restored, including the caller's local variable table, the operand stack, and the program counter that is correctly incremented to indicate that the method invocation instruction was executed.

2.1.1 Local variable table

The length of the local variable table (local Variables) is determined by the compilation period and stored in the binary representation of the class or interface-saved by the Code property of the method and provided to the stack frame for use.

A local variable can hold data of type Boolean, Byte, char, short, float, reference, and returnaddress; two local variables can hold data of type long and double.

The local variable table is accessed by index, and the index value starts at 0. A long or double occupies two contiguous local variables and is called with a smaller index value. When an instance method is called, the first local variable (index value 0) is used to store the object reference (that is, this) of the called method.

2.1.2 Operand stacks

The operand stack (Operand stack) is a last-in, first-out (last-in-first-out) stack. The length of the operand is determined by the compile time, also stored in the binary representation of the class or interface, and is saved and provided to the stack frame using the Code property of the method.

The stack frame to which the operand stack belongs is empty when it was just created. The members of each operand stack (Entry) can hold values for any data type defined by a Java virtual machine, and long and double are also stored in a member, which is an operational unit, but not a storage unit. A long or double type of data consumes two units of stack depth, and other data types occupy one.

In the operand stack, an operation is often nested by multiple sub-operations, and the result of a sub-operation can be used by other peripheral operations.

2.1.3 A reference to run a constant-rate pool

Each stack frame contains a reference to a carton running a constant pool, which is used to support the code implementation of the current method to dynamically link (dynamic linking). In a class file, a method that calls other methods or accesses its member variables is represented by a symbolic reference (symbolic Reference), and the purpose of dynamic linking is to convert the method represented by these symbolic references into a direct reference to the actual method.

3. Java Heap

The Java Heap (heap) is thread-shared and follows the life cycle of a Java virtual machine. All class instances and array objects are stored in the heap.

4. Method area

The method area is thread-shared and follows the life cycle of the Java Virtual machine. Used to store the structure information for each class, such as the byte-code contents of the run-time pool, field and method data, constructors and normal methods, and some special methods used in classes, instances, interfaces initialization (class or interface initialization method <clinit>, instance initialization method <init >)

The method area is a logical part of the heap, but the virtual machine can do no garbage collection (GC) for this zone.

5. Run a constant-rate pool

Runtime Constant Pool is a Chang (Constant_pool) [1] For each class or interface , and a constant pool holds numeric literals, symbolic references to methods or fields, and so on.

Each running constant pool is allocated in the method area of the Java Virtual machine, and the corresponding run-time pool is created after the class or interface is loaded into the virtual machine.

6. Local Method Stack

The local methods stack (Native method stack) is used to support the execution of the Native method. Similar to the Java Virtual machine stack is the life cycle of the thread.

    1. Constant pool for detailed collation?

Java Virtual Machine Specification read notes-run-time data area

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.