Java Basics-What is the usual GC policy, when YGC is triggered and when is the FGC triggered?

Source: Internet
Author: User

I. Memory recovery strategies and common concepts

Common memory recycling strategies can be understood from several dimensions:

1 Serial & Parallel
Serial: Single thread to perform memory reclamation work. Very simple, no need to worry about synchronization and other issues, but time-consuming, not suitable for multi-CPU.
Parallel: Multi-threaded concurrency for recycling. Suitable for multi-CPU, high efficiency.
2 Concurrency & Stop the World
The application thread in Stop the WORLD:JVM hangs and only the garbage collection thread is working on the garbage cleanup. Simple, no need to consider issues such as recycling is not clean.
Concurrency: Applications are running while garbage collection is in use. Guarantee the response time of the application. There will be two recycling cases where recycling is not clean.
3 Compression & Non-compression &copy
Compression: After a garbage collection, the surviving objects are slid into a continuous space by sliding, clearing the debris and ensuring that the remaining space is continuous.
Non-compression: preserves fragmentation and does not compress.

Copy: Move the surviving object to a new space, and the old space is all released. (Larger memory is required.) )

A garbage collection algorithm, which can be considered and designed from the above several dimensions, eventually produces a garbage collector with different features for different scenarios.

Second, the YGC&FGC of the JVM

YGC: GC for the Cenozoic heap. The frequency is higher because most of the objects have a short life expectancy and are recycled in the Cenozoic. Performance is less expensive.

FGC: A full heap range of GC. FGC is triggered when the default heap space is used to reach 80% (adjustable). Taking our production environment as an example, it is generally less likely to trigger FGC, sometimes 10 days or about a week.

Third, when will trigger YGC, when to trigger FGC?

YGC's timing:

Lack of EDN Space

FGC's timing:

1.old lack of space;

2.perm lack of space;

3. Display call System.GC (), including RMI and other timing triggers;

Pessimistic strategy at 4.YGC;

5.dump Live Memory Information (jmap–dump:live).

The timing of the triggering of YGC is quite obvious, that is, Eden Space is not enough, this time will certainly trigger YGC

For FGC trigger timing, old space shortage, and perm space, call System.GC () These are more obvious, that is, in this case, the general will trigger GC.

The most complex is the so-called pessimistic strategy, which triggers the mechanism is to first calculate the average size of the promotion before, that is, from the Cenozoic, through the YGC into the average size of the Cenozoic, and then if the old generation of the remaining space is less than the promotion size, then will trigger a FULLGC. The SDK considers the strategy is, from the average and long-term situation, the next promotion space is very large, rather than wait until then in FULLGC pessimistic think next time will certainly trigger FULLGC, directly first to execute a FULLGC. And from the actual use of the process, but also achieved a relatively stable effect.

Java Basics-What is the usual GC policy, when YGC is triggered and when is the FGC triggered?

Related Article

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.