JVM learning-architecture Memory Model

Source: Internet
Author: User
Tags xms
  • I. Diagram of the Java Technical System Module
  • Ii. JVM memory Zone Model

1. Method Area

It is also called "permanent generation" and "non-heap". It is used to store class information, constants, static variables, and memory areas shared by various threads. The default value is 16 MB and the maximum value is 64 MB. You can use the-XX: permsize and-XX: maxpermsize parameters to limit the size of the method area.

Runtime constant pool: it is a part of the method area. Besides class version, field, method, interface, and other description information, the class file also has a constant pool, it is used to store various symbol references generated by the compiler. This part of content will be loaded into the runtime pool of the method area after the class is loaded.

2. Virtual Machine Stack

Describes the Memory Model of Java method execution: A "stack frame" is created when each method is executed to store the local variable table (including parameters) operation stack, method exit, and other information. Each method is called to the execution process, corresponding to a stack frame in the VM Stack from the inbound stack to the outbound stack process. The Declaration cycle is the same as that of the thread, and is private to the thread.

The local variable table stores various basic data types (Boolean, byte, Char, short, Int, float, long, and double) and object references (reference pointer, data of the 64-bit long and double types occupies the space of two local variables, and the remaining data types only occupy one. The memory space required by the local variable table is allocated during compilation. when you enter a method, the size of the local variable allocated in the stack frame is completely determined, during running, the stack frame does not change the size and space of the local variable table.

3. Local method Stack

Similar to the Virtual Machine stack, the difference is that the virtual machine stack is a Java method service executed by the virtual machine, while the local method stack is a native method service.

4. Heap

It is also called Java heap and GC heap, which are the largest memory area managed by the Java Virtual Machine and the memory area shared by various threads. They are created at JVM startup. The memory area stores object instances and arrays (all new objects ). The size is set using the-XMS (minimum value) and-xmx (maximum value) parameters.-XMS is the minimum memory applied during JVM startup, the default value is 1/64 of the operating system physical memory but less than 1 GB.-xmx is the maximum memory that can be applied by JVM. The default value is 1/4 of the physical memory but less than 1 GB, by default, when the free heap memory is less than 40%, the JVM will increase the heap to the size specified by-xmx. You can use-XX: minheapfreeration = to specify this ratio column. When the free heap memory is greater than 70%, the JVM will reduce the heap size to the size specified by-XMS. You can use XX: maxheapfreeration = to specify this ratio column. For running systems, to avoid frequent heap size adjustment during running, generally, the value of-XMS is set to the same as that of-xmx.

Because the collectors currently use the generational collection algorithm, the heap is divided into the new generation and the old generation. The new generation mainly stores newly created objects and objects that have not yet entered the old age. Objects stored in the old age after several new generations of GC (minor GC) remain alive.

New generation:

The newly created objects of the program are memory allocated from the new generation. The new generation is composed of Eden space and two identical vor spaces (S0 and S1 or from and, you can use the-xmn parameter to specify the size of the new generation, or you can adjust the size of the Eden space and elastic vor space through-XX: elastic vorration.

Old:

It is used to store any surviving objects after multiple new generation of GC, such as cache objects. Newly created objects may also directly enter the old age. There are two main situations: ①. for large objects, you can set the startup parameter-XX: pretenuresizethreshold = 1024 (in bytes, it is assumed that 0) to indicate that when the number of objects exceeds the upper limit, they are not allocated in the new generation, but are directly allocated in the old generation. ②. A large array object, cut from the array without referencing external objects.

The memory size occupied by the old age is the value corresponding to-xmx minus the value corresponding to-xmn.

5. Program counters

It is used to indicate the row number of the bytecode executed by the current thread. In the virtual machine model, when the bytecode interpreter is working, it selects the next bytecode instruction to be executed by changing the counter value, basic functions, such as branch, loop, exception handling, and thread recovery, must depend on counters.

  • Iii. Direct Memory

Direct Memory is not a part of the virtual machine memory, nor is it the memory area defined in the Java Virtual Machine specification. NIO added in jdk1.4 introduces the channel and buffer I/O method. It can call the native method to directly allocate off-heap memory, which is the local memory, does not affect the heap memory size.

Original article link: http://blog.csdn.net/java2000_wl/article/details/8009362 reprint please indicate the source!

JVM learning-architecture Memory Model

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.