JVM Learning note-java Memory management (i)

Source: Internet
Author: User

                            Run-time Data area

Java Programmer Bar The right to memory control is given to the virtual machine to complete, in the event of memory overflow or leakage, if you do not understand how the virtual machine uses memory, then troubleshooting will be very difficult.

When executing Java programs, the JVM divides the managed memory into several different data areas, roughly divided into two categories, thread isolation, and non-thread isolation. Specific segments visible

(1) Program counter

is a small memory space that can be seen as the line number indicator of the bytecode executed by the current thread. The multithreading of Java is implemented by rotating threads, and each thread needs a separate program counter for the thread to switch back to the correct execution location.

The only area without any outofmemoryerror.

(2) Java Virtual Machine stack

Thread Private

The virtual machine stack describes the memory model that the Java method executes: Each method creates a stack frame at execution time, which stores information such as local variable tables, operand stacks, dynamic links, method exits, and so on. Each method from the call to the completion of the process, is a stack frame from the stack to the stack process.

The local variable table holds the basic data type that the compiler has known, the object reference. The memory space of the local variable table is allocated at compile time and does not change at run time.

The error that will occur: 1. StackOverflow, which indicates that the request stack is deep across the bounds. 2.OutOfMemoryError, which indicates that the extension cannot request enough memory.

(3) Local method stack

and the virtual machine stack is the difference: the virtual machine stack for the virtual machine execution Java method Service, the local method stack for the use of the native method service.

(4) Java heap

Should be the largest chunk of memory that the JVM manages, thread sharing. Almost all object instances allocate memory on the heap.

Java heap is the main area of garbage collector management, Java heap can be divided into the new generation and the old age, and then more detailed can be divided into Eden,from survior,to survior

In order to achieve thread safety, the Java heap can be divided into multiple thread-private allocation buffers (Tlab), the memory allocation action by thread in different space (Tlab), which thread needs to allocate memory, on which tlab on which to allocate

(5) Method area

Thread sharing

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

An important part of the method area: Run a constant-rate pool. The class file has a constant pool in addition to the description of the classes, fields, methods, interfaces, and so on. A constant pool is used to hold various literal and symbolic references generated during the compilation period. This section is stored in the run-time pool of the class load backward into the method area. The runtime pool is dynamic with respect to the class file constant pool, and the runtime can also put new constants into the pool.

JVM Learning note-java Memory management (i)

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.