Discuss about JVM garbage collection

Source: Internet
Author: User

 

In JDK 5.0, there are four types of garbage collectors. Generally, we do not select to configure a specific collector. The default type is serial collector. The other three types are throughput.
Collector, concurrentcollector, and train collector (the oldest compatible version ).

 

In most cases, you do not need to pay attention to specific Gc Types, unless this application needs to demonstrate unique features in the aspect of garbage collection. There was no parallel collection before JDK 1.3, so real-time garbage collection in multi-processor systems will not speed up. It is not until the parallel recycle (throughput and concurrent) is introduced in the future, that is, the recycle thread is run while the application is running.

 

To optimize the performance, the memory in the JVM heap divides Intervals Based on the age (AGE) of the management object (survival time). Different types of GC are triggered after each interval is filled with objects. First, the object will be allocated space in the young area during initialization, and according
"Mortality" principle, many objects will be recycled directly in the young region, instead of having the opportunity to relate to other areas. When the young area is full, minor recycle will be triggered. Minor recycle is targeted at some of the surviving objects in the allocated space for the first time, so the execution speed is very fast. After recycling, the surviving objects will be transferred to the tenured area. Full recovery is triggered when the tenured area is full, and full recovery is performed because all live
So the execution speed of objects is much slower.

 

 

The default heap space structure managed by various GC in JVM is as follows -- (except for throughput collector)

 

 

During initialization, a large part of physical memory is not allocated to GC computing, that is, the two virtual parts of the young and tenured areas we see, only when necessary will these spaces be added to GC. The young area on the way is composed of an Eden area and two very small primary vor areas. During objects initialization, they are both in the Eden area, and two very small primary vor areas (from and) the to Area in is always empty. It serves as the buffer zone for the surviving objects in the Eden and from areas during the next GC operation, the cached object is old enough, and the surviving objects will be moved to the tenured area symbolizing the old age. In the perm area on the Right of tenured, that is, the permanent generation, which is used to store class information and methods information and does not participate in GC, it also has a preset size and an adjustable virtual block.

 

Jvmgc has two main performance indicators: throughput and pauses. Throughput is the percentage of the total time except for the non-GC time, while pauses is the time at which the application stops when GC occurs.

 

This is the garbage collection mechanism of Sun JVM. It is worth noting that the stagnation caused by full GC has a great impact on performance and should be avoided as much as possible, however, Sun JVM has a feature that when an object with a large memory size needs to be allocated at a time, it is usually directly placed in the tenured area, which can easily trigger full GC. Relatively speaking, IBM's JVM does not distinguish between young and tenured. It directly stores objects in the managed memory according to the hash table structure, it is divided into grids of different sizes. When GC is triggered, the items that can be recycled are cleared, and the nearest lattice can be found in the next allocation object. By default, the system does not move the remaining objects to merge the lattice fragments, unless the ing parameter is set to trigger the merge, but the scanning time is sacrificed. Therefore, JVM garbage collection is not omnipotent. Although developers do not have to worry about code writing, there may be unavoidable performance problems in some cases.

 

All we can do is understand the jvm gc mechanism and configurable parameters, and adopt the most appropriate method for GC under specific applications and requirements.



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.