JVM memory model and memory allocation process

Source: Internet
Author: User
Tags xms

First, the JVM memory model

The JVM primarily manages two types of memory: heap and non-heap (permanent zone).

1. Heap is a runtime data region where all class instances and arrays of memory are allocated. The heap distinguishes between two chunks, one young Generation and the other old Generation:
1) in young generation, there is a space called Eden spaces, mainly for the newborn objects, and two survivor Spaces (From,to), they are always the same size, they are used to store each garbage collection survived after the object.
2) in the old generation, the memory objects that have long life cycles in the application are primarily stored.

2, Permanent District:
Permanent Generation, the main storage is the Java class information, including parsing methods, properties, fields and so on. The permanent band basically does not participate in garbage collection. Permanent generation is not a part of the heap.

.

Second, memory size

1. Heap memory allocation
The initial memory allocated by the JVM is specified by-XMS, which defaults to 1/64 of the physical memory;
The maximum allocated memory for the JVM is specified by-XMX, which defaults to 1/4 of the physical memory.

When the default free heap memory is less than 40%, the JVM increases the heap until the maximum limit of-xmx, which can be specified by-xx:minheapfreeratio.
When the default free heap memory is greater than 70%, the JVM reduces the heap until the minimum limit of-XMS, which can be specified by-xx:maxheapfreeratio.

2. Permanent area memory allocation
The JVM uses-xx:permsize to set the non-heap memory initial value, which defaults to 1/64 of the physical memory;
The maximum amount of non-heap memory is set by Xx:maxpermsize, which defaults to 1/4 of physical memory.

third, JVM memory allocation process

1. The JVM tries to initialize a chunk of memory in Eden for the relevant Java object.
2. When the Eden space is sufficient, the memory request ends; otherwise to the next step.
3. The JVM attempts to release all inactive objects in Eden (this is a 1 or more advanced garbage collection). If Eden space is still insufficient to fit into the new object after release, an attempt is made to put some of the active objects in Eden into the survivor area.
4. The survivor area is used as an intermediate swap area for Eden and old, and when the old area is sufficiently large, the objects in the Survivor area will be moved to the old area, otherwise they will be kept in the survivor area.
5, when the old area is not enough space, the JVM will be in the old area of full garbage collection (level 0).
6. After a complete garbage collection, if the survivor and old areas still cannot store some of the objects copied from Eden, causing the JVM to fail to create memory areas for new objects in the Eden area, an "out of memories" error occurs.

Reference:

Java memory model and GC principle

Java memory model and GC principle and Diagram JVM Application object in memory and garbage collection process

JVM memory model and memory allocation process

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.