JVM memory model and allocation parameters

Source: Internet
Author: User
Tags xms

JVM Memory model

    1. Program Counter : is a small amount of memory space. When the number of threads exceeds the number of CPUs, thread-by-time polling robs CPU resources. Each thread must use a separate program counter that records the next instruction to be run.
    2. Java Virtual machine stack (line stacks): Also thread-private memory space, which he and Java threads create at the same time, he saves local variables of the method, partial results, and participates in method invocation and return. if the thread is in the process of calculation, the requested stack depth is greater than the maximum available stack depth, the stackoverflowerror is thrown, if the Java stack can be dynamically extended, and in the process of expansion, the operating system does not have enough memory space to support the expansion of the stack, OutOfMemoryError is thrown;--parameter settings see Set line stacks
    3. Local method Stack : A call to manage a local method that is implemented using C.
    4. java heap : Heap space is divided into the new generation and the old age. The new generation is used to store the newly created objects, which are used to store older objects (objects that have a longer period of time and have more garbage collection times). The Cenozoic can be subdivided into eden,s0 and s1,eden when most of the objects are just established, usually placed here. S0 and S1 are survivor spaces, which means that the objects stored in them have experienced at least one garbage collection and survived. If the target of the surviving area has not been recycled until the specified age, there is an opportunity to enter the old age.
    5. method Area : Similar to heap space, it is also shared by all the threads of the JVM, and it mainly stores metadata such as type information, Chang, Domain information, method information, and so on.

Set maximum, minimum heap memory

    1. Specify the maximum heap memory with-XMX, the maximum heap memory refers to the maximum size of the new generation and the old age, which is the heap of Java applications.
    2. Use-XMS to specify the minimum heap memory, which is the size of the operating system memory occupied by the JVM when it starts.
    3. When the memory size specified by-XMS does not satisfy the application, the JVM will request more memory to the operating system until the-XMX specified memory size is reached. If the value of the-XMS is small, then the JVM will frequently perform GC operations to release the failed memory space in order to ensure that the system runs as much as possible within the specified memory range, thereby increasing the number of minor GC and full GC, which can have an impact on system performance. Therefore, when you set the-XMS value to-XMX, you can reduce the number of GC times and time-consuming at the beginning of the system Operation .

Set the thread stack

    1. Line stacks is a piece of private space of thread, can use-XSS to set the size of line stacks, the size of stack directly determines the depth of function call.
    2. Local variables are allocated in the thread, and the function calls need to open up space in the stack.
    3. If the space allocation of the stack is too small, then the thread may not have enough space to allocate local variables or not enough function call depth to cause the program to exit abnormally, and if the stack space is too large, the memory cost of opening the thread will rise and the total number of threads that the system can support will decrease.
    4. Java heap and line stacks are all like operating system request memory space, if the heap space is too large, it will cause the operating system can be used to reduce the memory of the line stacks, when the system cannot create a new thread due to insufficient memory, it throws an Oom exception (note that this oom is not a heap memory shortage). Therefore, if the system does require a large number of threads to execute concurrently, setting a smaller heap and a smaller stack can help increase the maximum number of threads the system can tolerate .

Set up Cenozoic

    1. Using-XMN to specify the size of the Cenozoic, the Cenozoic size is generally set to 1/4 to 1/3 of the entire heap space. Setting a larger or smaller Cenozoic has a significant impact on the performance of the system in GC behavior.
    2. Using-xx:newsize to set the initial size of the Cenozoic,-xx:maxnewsize sets the maximum value for the Cenozoic. Usually only the-XMN is set up to meet the needs.

Set Persistent generations

    1. The Persistence generation (the method area) is not part of the heap, use-xx:maxpermsize to set the persistent maximum value, and-xx:permsize to set the persistent minimum value.
    2. The size of a durable generation directly determines how many class definitions and constants the system can support.
    3. The general MaxPermSize is set to 64M or 128M.

Get heap Snapshot (heap dump)

Use the-xx:+heapdumponoutofmemoryerror parameter to export the current heap snapshot of the application when the program occurs with Oom. The parameter-xx:heapdumppath allows you to specify where the heap snapshot will be saved.

JVM memory model and allocation parameters

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.