Data area structure of Java Virtual runtime

Source: Internet
Author: User
Tags java se

This section of this article refers to the Java Virtual Machine specification (Java SE 7 version) of the Chinese translation and Zhou Zhiming of "in-depth understanding of Java Virtual Machine", plus personal understanding. The original book on the Java Virtual Runtime data area description only 6 pages, while referring to other network data, personal ability limit, do not rule out the existence of cognitive errors.

The JVM divides the memory used during the program run into several run-time data areas, some of which are created as the virtual machine starts and destroyed as the virtual machine exits. Others correspond to thread one by one, which is created as the thread starts and is destroyed as the thread ends. The data area is divided as indicated:

Java Heap (Java heaps)

In the JVM, the Java heap is a region of run-time memory that can be shared by individual threads, and is the area for allocating memory for all class instances and arrays of objects. The Java heap is created when the virtual machine is started and stores various objects managed by the garbage collector (GC) that cannot be explicitly destroyed.

OutOfMemoryError errors may occur in the Java heap .

Method Area

A method area is used to store the structure information of a class that has been loaded by a virtual machine, such as bytecode that runs a constant pool, field and method data, constructors, and normal methods, as well as some special methods used in class, instance, and interface initialization.

The method area is logically part of the Java heap, but the JVM specification is very lenient to the method area, and you can choose not to implement garbage collection. Because of the very harsh conditions of type unloading, the garbage collection effect of the method area is not ideal.

OutOfMemoryError error may occur in the method area .

run a constant pool (runtime Constant)

The bytecode of each class or interface goes beyond the descriptive information of a class version, field, method, interface, and contains a constant pool table (Constant_pool table) that holds the various literal and symbolic references generated during the compilation period, which is the run-time representation of the constant pool table. Each running constant pool is allocated in the JVM's method area, and the corresponding run-time pool is created after the class and interface are loaded into the virtual machine.

the JVM may throw outofmemoryerror errors when creating a run-time-constant pool .



PC Counter (program Counter Register)

The JVM thread is private, saving the address of the bytecode instruction that the current thread is executing, and if the native method is being executed, the value is undefined and there is no memory error in this memory area.

java VM Stack (Java Virtual machine stack)

In the first edition, also known as the Java stack, each JVM thread has its own private Java Virtual machine stack, which is created at the same time as the thread to store the stack frame.

Stackoverflowerror and OutOfMemoryError errors may occur in the Java Virtual machine stack.

Local methods Stack (Native method Stacks)

The JVM thread is private, similar to the Java Virtual machine stack, where the Java virtual machine stack executes Java method services for the virtual machine, while the local method stack executes the native method service for the virtual machine. The JVM specification does not specify how the region is implemented, and the Sun hotspot virtual machine directly synthesizes the local method stack and the Java Virtual machine stack. As with the Java Virtual Machine stack, the local method stack can also throw stackoverflowerror and outofmemoryerror errors.

stack frames (stack frame)


A stack frame is a data structure used to store the results of a part of a process, and each method call corresponds to a stack frame that is created with the method invocation and destroyed as the method ends. The spatial allocation of stack frames in the Java Virtual machine stack, each stack frame includes its own local variable table, operand stack, and dynamic link (a reference to the run-time pool of the class to which the current method belongs).



Data area structure of Java Virtual runtime

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.