"007" "jvm--memory allocation and recovery policy"

Source: Internet
Author: User

memory allocation and recall policy

The JVM's own active memory management has to proactively address two of issues: objects allocate memory and reclaim memory allocated to objects. The first few pieces of recycled memory have been told. Now say memory allocation. An object's memory allocations are generally allocated in heap memory, or they can be JIT-compiled and then split into scalar types to be indirectly allocated on the stack. The object is primarily allocated on the new generation of Eden, assuming that the local thread allocation cache is started and will be allocated on a thread-first basis in Tlab (local thread allocation cache).

In a few cases it may also be assigned directly in the old age, the assigned rule is not fixed, and the combination of which garbage collector is used, and the memory-dependent parameter setting in the virtual machine.

object Precedence in Eden area assignment

in most cases, the object is in the Cenozoic Eden allocated in the area. when the Eden area does not have enough space to allocate, the virtual machine will initiate a Minor GC.

    • New Generation GC (MINORGC): New generation of garbage collection action, Java objects are mostly short life, so minorgc very frequent, faster.

    • The old age GC (MAJORGC or FULLGC): garbage collection movements in the old age, MAJORGC, often accompanied at least once MINORGC (not absolute. In the collection strategy of the Parallelscavenge collector there is a policy selection process that is directly MAJORGC. The speed of MAJORGC is more than 10 times times slower than MINORGC.


large objects go straight into the old age

Large objects are Java objects that require a large amount of contiguous memory space. The most typical large object is that very long string and large array.

-xx:pretenuresizethreshold can set the value of a large object directly in the old age distribution. Avoid garbage collection when a large amount of memory is copied between the Eden area and the two survivor zones.

long-lived objects will enter the old age.

The virtual machine collects methods to manage memory, and when memory is reclaimed it must be able to identify which objects should be placed in the new generation and which should be in the old age.

The virtual machine defines an object age counter for each object. Assuming that the object is still in place after Eden was born and after the first MINORGC, and can be accommodated by survivor, it will be moved to survivor space and set the object age to 1.

Object in the Survivor area each time minor GC, age is added 1 years old. when the age is added to a certain degree (default feeling 15 years old) elbow. will be promoted to the old age. The age threshold at which the object is promoted to the old age can be set by the number of-xx:maxtenuringtbreshold.

Dynamic Object Age Determination

In order to better adapt to the memory situation of different programs, the virtual machine does not always require the age of the object must reach Maxtenuringthreshold talent promotion to the old age, assuming that the same age in Survivor space total object size of the sum of more than half of survivor space, Objects older than or equal to that age are able to enter the old age without waiting for the ages required in the maxtenuringthreshold.

Space Allocation Guarantee

In the case of MINORGC elbow, the average size of each promotion to the old age is greater than the remaining space size of the old age before the virtual opportunity test. If the assumption is greater, the FULLGC is changed directly.

Assumed to be less than. To see if the Handlepromotionfailure setting agrees to the warranty failure: Assuming consent, it will only be MINORGC: assuming disagree, it will be replaced once FULLGC

Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.

"007" "jvm--memory allocation and recovery policy"

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.