Deep understanding of Java Virtual Machine Two, memory management mechanism

Source: Internet
Author: User

Automatic memory management for Java virtual machines.

A Java Virtual machine divides the memory it manages into several different regions as it executes a Java program.

1 Program Counters

Each thread has a separate counter that indicates the location of the bytecode that needs to be executed.

2 Virtual Machine Stack

A virtual machine stack is a memory model used to describe the execution of Java methods, and each method is executed to create a stack frame for storing local variable tables, operations stacks, dynamic links, method exits, and so on.

Each method is called until the completion of the process, corresponding to a stack frame from the virtual machine stack from the stack to the stack.

The virtual machine stack thread is private, and the declaration cycle is the same as the thread.

The memory space required for a local variable table is allocated during compilation, and when entering a method, the method needs to allocate how much local variable space is fully determined in the frame,

The size of the local variable table does not change while the method is running

Stackoverflowerror exception is thrown when a thread requests a stack depth that is greater than the allowed depth of the virtual machine

OutOfMemoryError exception is thrown when the virtual machine stack automatically expands when it cannot request enough memory

3 Local Method Stack

Similar to virtual machine stacks, but acts on local methods

4 Java Heap

The purpose is to store object instances, which are created when the virtual machine is started and shared by all threads.

According to the generational collection algorithm, it is divided into Cenozoic and old age.

The Java heap can be in a physically discontinuous memory space.

5 Method Area

shared by all threads. Used to store data such as class information, constants, static constants, and instant compiler-compiled code that have been loaded by the virtual machine.

The garbage collection behavior is less frequent in this area, and the memory recovery target for this area is primarily for constant pools and for unloading types.

6 running a constant-rate pool

Part of the method area, class file in addition to the class version, fields, methods, interfaces and other descriptive information, there is a constant pool.

Used to hold various literal and symbolic references generated by the compilation period, which will be stored in the run-time pool of the method area after the class is loaded.

7 Direct Memory

The direct memory of this machine is not limited by the Java heap size.

In-depth understanding of Java Virtual Machine Two, memory management mechanism

Related Article

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.