java virtual machine - data area

Original link: https://blog.csdn.net/qq_39089301/article/details/87278249

1. Rough

Has often been divided into the java memory heap (Heap) and stack memory (Stack), this distribution is rough.

Java memory area is actually divided than this complex

This division can only show that the prevalence of most programmers are most concerned about, the relationship with the object of memory allocated memory area is most closely these two.

2. meticulous division

2.1 Program Counter

Program Counter (Program Counter Register) is a small memory space,

Thread can be seen as the current byte code executed by the line number indicator.

In the conceptual model of a virtual machine's (only a conceptual model, a variety of virtual machine through some possible to achieve a more efficient manner),

Bytecode interpreter by changing the value of the counter is bytecode instructions to select a next to be executed, scores, loop

Jump, exception handling, thread resume and other basic functions need to rely on this counter is complete.

A more detailed in-depth reading books jvm virtual machine.

2.2Java virtual machine stack

Like the thread counter, Java Virtual Machine stack (Java Virtual Machine Stacks) is a thread private,

A thread is the same as the life cycle of the memory model Java virtual machine stack execution method described:

In each method are performed simultaneously to create a stack frame information for storing local variable table, the operand stack, dynamic link, the method exports.

Each method invocation from execution until the completion of the project, it corresponds to a stack frame to push the stack works in a virtual machine stack.

This contains the local variable table. 8 which is stored a large basic data types, and returnAddress object reference type (byte code point address).

In the Java virtual machine specification, this area provides two kinds of exceptions: If the stack is greater than the depth of the thread requested stack depth allowed by the virtual machine, the abnormal StackOverflowError ran;

If the virtual machine can dynamically expand the stack (most current Java virtual machine can dynamically expanding, but the Java Virtual Machine specification also allows the virtual machine fixed length),

If the extension can not apply enough memory, it will throw an OutOfMemoryError.

2.3 native method stacks

Native method stacks (Native Method Stack) is similar to the role played by the virtual machine stack, the difference is: java virtual machine stack for the Java virtual machine to perform method (bytecode) services,

The native method stacks, the virtual machine to use a method of Native service. Anomalies with the virtual machine stack.

2.4Java heap

For most applications, Java heap (Java Heap) is the largest piece of memory in the Java virtual machine management.

Java heap is shared by all threads in a memory area,

Created when the virtual machine starts. The sole purpose of this memory area is stored object instance,

Almost all object instances are here to allocate memory. With JIT compiler development,

During compilation, if the JIT escape through the analysis found that some object does not escape the method,

Then it is possible heap memory allocation can be optimized to stack memory allocation. But this is not absolute.

(The time will be to write the object Examples of other dispensing position)

2.5 Method zone

For the habit in HopSpot virtual machine developers, for developers to deploy programs,

Many people are willing to method area called "permanent generation", in essence, both the two are not equivalent,

Simply because HotSpot virtual machine's design team to GC generational collection area extends to methods, or permanent generations to implement the method area only.

Guess you like

Origin blog.csdn.net/zhupanlinch/article/details/102735598