JVM Memory Partitioning Summary

Source: Internet
Author: User

Overview

Before you say JVM Memory Partitioning, let's start with the Java program's specific execution process:

Java source files are compiled by the Java compiler and become class bytecode files.

After the JVM's classloader loaded class file is complete, it is handed to execution engine execution.

All data and information used during execution of the engine execution is stored in the runtime data area .

The Runtime data area is what we often call JVM memory.

Runtime Data area

What does the Runtime data area include?

TheJava Virtual machine specification specifies that the runtime data area consists mainly of the local method stack (nativemethods Stack), thejava Stack ( VM Stack), program counter (Programs counter Register), Heap (heap), method area ( Methodarea).

Although the Java Virtual machine specification specifies which parts of a virtual machine should be included, there are no specific implementation requirements, so different virtual opportunities have different implementations.

What data is stored in the Runtime data area ?

1, program counter

Program counter: Saves the memory address of the next execution command.

After the command address is obtained, the program counter automatically points to the memory address of the next instruction. Depending on the implementation of the virtual machine, it will only be the concept and the role of the program counter.

In the JVM , multithreading takes the CPU execution in turn , so each thread has its own program counter. And they don't interfere with each other.

In the JVM specification, if the current program is executing the native method, the value in the program counter should be the address of the next instruction, if it is a non- native method, The value in the program counter should be undefined.

Because the space that is stored in the program counter does not change with the execution of the program, there is no memory overflow in the program counters.

2,JavaStack

The Java stack is also called the virtual machine stack, which is what we often call the stack, and the Java stack is the memory model that the Java method executes.

Java stack is stored in a stack of frames, each stack frame includes: local variable table, operand stack, run a constant pool of reference, method return address, additional information.

When a thread invokes a method, it creates a stack frame and presses the stack. The stack is executed after the method has finished executing. The method that the thread is currently executing must be at the top of the stack. Here you should understand why, when recursion, a non-attention will be stack overflow. This part of the stack is opaque to programmers and is implemented automatically by the system.

What are all the parts in the stack frame?

Local variable table

Local Variables table: a local variable in a stored method, a local variable that has a basic data type and a reference data type,

For variables of basic data types, values are stored (each base data type has a fixed memory footprint), and variables that reference data types store references to Objects . The size of the local variable table can be determined at compiler time, so the size of the local variable table will not change during program execution.

Operand stack: The process of executing a thread is actually the process of executing a statement, which is ultimately the process of computing. However, all of the calculations in the program are performed on the operand stack. It can be understood that it is used to do calculations.

Run a reference to a constant pool: The constants in the class may be used during method execution, and a reference must be directed to the run-time.

Method return Address: When the method executes, the return address of the method must be saved in the stack frame to return to where it was previously called.

Additional information: TheJava Virtual machine specification allows specific implementations of some virtual machines to add information that is not described in the specification to a stack frame, such as debugging-related information, which is entirely dependent on the virtual machine's specific implementation.

3, the local method stack

The principle and function of the local method stack and the Java stack are very similar. The difference is that the value of the Java stack is performed for the Java method execution Service. The local method stack is performed as a service to the native method. the specific implementation of the local development and the data interface are not mandated by the JVM specification, and the virtual machine can be implemented freely. For example , the implementation of the hotsopt virtual machine is to combine the local method stack with the Java stack.

4, Heap

The heap in Java is used to store the objects themselves and arrays (pointers to arrays in the Java stack).

This part of the heap is the main area of Java garbage collection.

The heap is shared by all threads, and there is only one heap in the JVM .

5, method area

It is shared by all threads as a heap.

The method area mainly stores information about each class (such as the name of the class, method information, field information), static variables, constants, code after the compiler, and so on.

Constant pools In addition to the constant values that contain the various basic types defined in the code (such as int,long , and so on) and object types (such as strings and arrays) , it also contains some symbolic references ( running a constant pool )that appear as text, such as:

The fully qualified name of the class and interface;

The name and descriptor of the field;

Methods and names and descriptors.

Add:

In class files, in addition to descriptions of the fields, methods, interfaces, and so on, a constant pool is used to store the literal and symbolic references generated during compilation.



JVM Memory Partitioning Summary

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.