Java Virtual Machine series: (i) JVM memory area

Source: Internet
Author: User
1. Overview Java and C + + there is a dynamic memory allocation and garbage collection technology called the "high Wall", the wall outside people want to go in, the wall inside people but think out. 2. Run-time data region

The JVM, while executing a Java program, divides the memory it manages into several different data regions. The following figure:


2.1 Program counter (pcregister)First, it is thread-private. In addition, it is a smaller memory model that can be viewed as the line number indicator of the bytecode executed by the current thread.      In the virtual machine concept model, the bytecode interpreter works by changing the value of this counter to select the next byte code command to be executed, branching, looping, jumping, exception handling, thread recovery and other basic functions need to rely on this counter to complete. This area is the only area where Oom (out of memory) does not appear.
2.2 Java Virtual machine stack (VM stack)is also a thread-private, and its lifecycle is the same as that of a thread. Java Virtual Machine Stacks describes the memory model that is executed by the Java method: Each method creates a stack frame (the stack frame) to store information such as "local variable table", "Operand stack", "Dynamic Link", "Method exit", while executing.      Each method from the call until the completion of the process, corresponds to a stack frame in the virtual machine into the stack to the process of stack. The Local variables table holds the various basic data types, object application types, which are known at compile time.      The memory space required by the local variable table is allocated during compilation, and the method does not change during the run. Two kinds of abnormal condition: stackoverflowerror, OutOfMemoryError.
2.3 Local methods Stack (Native method Stack)The local method stack serves the native method that the virtual machine uses. Also throws two kinds of abnormalities: stackoverflowerror, OutOfMemoryError.
2.4 java Heap (Java heap)The Java heap is the largest chunk of memory managed by the JVM, a memory area shared by all threads, with the sole purpose of storing object instances, where almost all object instances allocate memory.      The Java heap is the main area of garbage collector management, also known as the GC heap. The Java heap can generally be divided into the following three parts: (Young generation, old age, permanent generation)

Young Youth District is divided into three districts: Eden area, two survivor (from and to) of the same size, of which only one of them is used in the Survivor interval, and the other is a copy object for garbage collection. When the young interval is full, the minor GC moves the surviving object to the idle survivor interval, and after several garbage collections, the object that survives the survivor will be moved to the tenured interval, according to the JVM's strategy.
The JVM provides the appropriate parameters to configure the memory size

Total Heap

-XMS: Specifies the initialization of memory after the JVM's initial startup

-XMX: Specifies the maximum memory for the JVM heap, and allocates the memory of the specified size of the-XMX parameter to the JVM after the JVM is started, but not necessarily all, and the JVM adjusts the memory that is actually used for the JVM based on the-XMS parameters

the difference between the-XMX-XMS is the size of three virtual spaces

Young Generation

-xx:newratio=8 means the ratio of tenured and young is 8:1, so EDEN+2*SURVIVOR=1/9

Heap Memory

-xx:survivorratio=32 means that the ratio of Eden to a survivor is 32:1, a survivor that accounts for 1/34 of young.

The-XMN parameter sets the size of the young generation

Perm Generation

-xx:permsize=16m-xx:maxpermsize=64m

Thread stack-xx:xss=128k
The 2.5 method areas (methods area) are also called permanent generation (PermGen).      The Java Virtual machine describes the method area as a logical part of the heap, but it has an alias: Non-heap, the purpose is to separate from the Heap.      Like heaps, is the memory area shared by each thread, storing class information loaded by the virtual machine, constants, static variables, just-in-time compiler (JIT)-compiled code. In contrast, garbage collection behavior is less likely in this region.
2.6 Runtime (Runtime Constant pool) It is part of the method area that holds the various literal and symbolic applications generated by the compiler. 2.7 Direct Memory is not part of a virtual Run-time data area, nor is it a memory area defined in the Java Virtual Machine specification.


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.