JVM Series II: GC Policy & Memory request, object aging

Source: Internet
Author: User

There are a number of algorithms for GC (garbage Collection) in the JVM, such as the tag purge collector, the compression collector, the generational collector, and more, see the types of hotspot VM GC

Now more commonly used is generational collection (generational collection, also used by Sun VMs, introduced after j2se1.2), which will divide the memory into several regions, placing objects of different life cycles in different regions: youngGeneration ,tenured generation and permanet generation. Most of the objec are assigned to young generation (life cycle is short), and most of the objects die here. When young generation is full, minor collection (YGC) is raised. Objects that survive after the minor collection are moved to the tenured generation ( longer life cycle ). Finally, thetenured generation major collection after full. Major collection (full GC) will trigger the recovery of the entire heap, including the recovery of young generation. Permanet generation region is relatively stable, mainly storing classloader information.

Young generation is comprised of Eden, 2 survivor regions. One of the survivor areas is always empty, which is the destination of the Eden area and another survivor area alive Objecy after the next copy collection. object is copied in the Survivo area until it is transferred to the tenured area.

We want to minimize the number of full GC (tenured generation is generally large, the collection time is long, and the frequent full GC will result in a severe impact on the performance of the application).

Heap Memory GC
The JVM (with the strategy of generational recycling) uses a higher frequency to YGC young generation (tenured generation) with fewer old objects (tenured Generation is full before it is fully GC. This makes it unnecessary to check all the objects in memory every time the GC is over.

Non-heap memory not GC

The GC does not clean up permgen space during the main program's run time, so if you have many classes in your application (especially the dynamically generated class, and of course PermGen space is not limited to classes), PermGen space errors are likely to occur.

Memory request, Object aging Process
One, the memory application process

    1. The JVM tries to initialize an area 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 (Minor collection), and if Eden space is still insufficient to fit into the new object, it attempts 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 retained in the Survivor area;
    5. When there is not enough space in the old area, the JVM will major collection in the old area;
    6. After a complete garbage collection, "Out of memory error" occurs if the survivor and old areas still cannot hold portions of objects copied from Eden, causing the JVM to be unable to create an area for the new object in the Eden area;

Second, the object of aging process

  1. The memory of the newly created object is allocated from Eden. The process of Minor collection is to copy Eden and the live object in survivor space into the free survivor space. After the object has undergone a certain number of minor collection in young generation, which can be configured by parameter, it is moved to old generation, called tenuring.
  2. GC Trigger conditions
    GC Type Trigger conditions What happens when the trigger is triggered Attention View mode
    YGC eden Less space

    Empty the memory occupied by all no ref objects in Eden+from survivor
    will eden+from all surviving objects in sur into to sur
    Some of the objects will be promoted to the old:
        to sur does not fit
        survive more than
    recalculate tenuring in turning threshold Threshold (Serial parallel GC triggers this)

    Resizes Eden and from (parallel GC triggers this)

    The whole process pauses whether the
    is multithreaded by the specific GC determines
    GC log
    FGC

    Old space is low
    Perm Lack of space
    Display of timed triggers called SYSTEM.GC, RMI, etc.
    A pessimistic strategy when YGC
    Dump Live Memory information (jmap–dump:live)

    Empty the object of no ref in the heap
    The class information loaded in the ClassLoader that has been unloaded in the PermGen

    If Collectgenofirst is configured, the YGC is triggered first (for serial GC)
    If SCAVENGEBEFOREFULLGC is configured, the YGC is triggered first (for serial GC)

    Entire Process suspension Application
    Whether multithreading is determined by a specific GC

    Whether to compress the specific GC to see the configuration
    Jstat–gcutil
    GC Log
    Permanent generation insufficient space will cause full GC, still not enough to cause PermGen space error.

Reference:

http://jiangyongyuan.javaeye.com/blog/356502

http://www.helloying.com/blog/archives/164

JVM Series II: GC Policy & Memory request, object aging

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.