JVM Tuning Summary (v)-generational garbage collection detailed 1

Source: Internet
Author: User
Tags garbage collection

Why do we have to divide

The generational garbage collection strategy is based on the fact that the lifecycle of different objects is not the same. As a result, objects of different lifecycles can be collected in different ways to improve recovery efficiency.

In the process of running a Java program, a large number of objects are generated, some of which are related to business information, such as session objects, threads, and socket connections in HTTP requests, which are directly tied to the business and therefore have a long lifecycle. But there are some objects, mainly in the process of running the program generated temporary variables, these objects life cycle will be relatively short, such as: string objects, because of its invariant class characteristics, the system will produce a large number of these objects, some objects can be recycled even once.

Just imagine that, without making a distinction between object survival time, each garbage collection is a collection of the entire heap space, spending time relative to the president, and because each recovery needs to traverse all the surviving objects, but in fact, for long-lived objects, this traversal is ineffective, because it may be traversed many times , but they still exist. Therefore, the separation of garbage collection by the use of the idea of division, the Division of Generations, the different life cycle of the objects in different generations, different generations to use the most suitable for its garbage collection method for recycling.

How to divide the generation

As shown in the figure:

The virtual machines are divided into three generations: young Generation, Old Generation, and persistent generation (permanent Generation). The persistence generation mainly holds the class information of the Java class, which is not related to the Java objects collected by garbage collection. The division of the younger generation and the older generation has a greater impact on garbage collection.

Young generation:

All newly generated objects are first placed in the younger generation. The goal of the younger generation is to collect as quickly as possible those objects with short life cycles. The young generation is divided into three districts. An Eden area, two survivor districts (in general). Most objects are generated in the Eden area. When the Eden is full, the surviving objects will be copied to the Survivor area (one of two), and when the survivor is full, the surviving objects of the area will be copied to another survivor area, and when the survivor is full, Objects copied from the first survivor area and still alive at this time will be replicated in the old age area (tenured). Note that the two areas of survivor are symmetrical and have no precedence, so there may be simultaneous objects in the same zone that are replicated from Eden, and those that were copied from the previous survivor, and those that were copied to the old age only came from the first survivor. Moreover, one of the survivor areas is always empty. At the same time, the Survivor area can be configured as multiple (more than two) depending on the program, which can increase the presence of objects in the younger generation and reduce the likelihood of being placed in the older generation.

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.