"Java JVM" Java Virtual machine memory allocation several principles __java

Source: Internet
Author: User

1. In most cases, the object is allocated in the New Generation Eden region. When the Eden area does not have enough space to allocate, the virtual machine initiates a minor GC

2, large objects directly into the old age. A large object is a Java object that requires a large amount of contiguous memory space, and the most typical large object is that long string and array.

3, long-term survival of the object will enter the old age.
Virtual machines Use the idea of generational collection to manage memory, so memory recycling must be able to identify which objects should be placed in the new generation and which objects should be placed in the old age. To do this, the virtual machine defines an object age counter for that object. If the object survives in Eden and is still alive after the first minor GC, and can carry survivor, it will be moved into survivor space and the object age is set to 1. Objects in the Survivor area every time the minor GC, age increases 1 years old, when his age increases to a certain extent (the default is 15 years old), will be promoted to the old age. The age threshold for an object to be promoted in the old era can be set by-xx:maxtenuringthreshold parameters.

4, dynamic object age determination. In order to better adapt to the memory of different programs, the virtual machine is not always required to reach the age of the object must be reached maxtenuringthreshold to the old age, if the same age in the survivor space of all objects of the total amount of rain survivor space Half, Objects older than or equal to that age can go directly into the old age.

5, Space distribution guarantee.
Before the minor GC occurs, the virtual opportunity checks to see if the maximum available contiguous space in the old age is greater than the total space of all the new generation objects, and if that condition is true, then the minor GC can ensure that it is safe. If not, the virtual opportunity to see if the Handlepromotionfailure setting value allows the guarantee to fail. If allowed, it will continue to check that the maximum available contiguous space in the old age is greater than the average size of the objects promoted to the old age, and if greater than, will attempt a minor GC, although this minor GC is risky If less than or Handlepromotionfailuer settings are not allowed to take risks, then the full GC should be changed instead.

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.