JVM Tuning Summary (iii)-Basic garbage collection algorithm

Source: Internet
Author: User

The garbage collection algorithm can be divided from different angles:

According to the basic recycling strategy

Reference count (Reference counting):

Compare the old recycling algorithms. The principle is that this object has a reference, that is to add a count, delete a reference and reduce a count. When garbage collection, only objects with a collection count of 0 are used. The most deadly of this algorithm is the inability to handle circular references.

Mark-Clear (Mark-sweep):

This algorithm executes in two stages. The first stage marks all referenced objects starting from the reference root node, the second stage traverses the entire heap, and the unmarked objects are purged. This algorithm needs to pause the entire application while generating memory fragmentation.

Replication (Copying):

This algorithm delimits the memory space as two equal areas, using only one of the regions at a time. During garbage collection, iterate through the current usage area and copy the objects in use to another area. The sub-algorithm processes only the objects that are in use at a time, so the copy cost is small, and replication can be done in the past, and there is no "fragmentation" problem. Of course, the disadvantage of this algorithm is also very obvious, is to need twice times the memory space.

Labeling-Finishing (mark-compact):

This algorithm combines the advantages of the "mark-clear" and "copy" two algorithms. It is also divided into two stages, the first phase marks all referenced objects starting from the root node, the second stage traverses the entire heap, clears the unlabeled objects and "compresses" the surviving objects into one of the heaps, and discharges them sequentially. This algorithm avoids the "mark-erase" fragmentation problem and avoids the space problem of the "copy" algorithm.

Divided by the way the partition treats

Incremental Collection (Incremental collecting): real-time garbage collection algorithm, i.e., garbage collection while the application is in progress. Do not know what reason the collector in JDK5.0 does not use this algorithm.

Generational Collection (generational collecting): a garbage collection algorithm based on the analysis of the object life cycle. Divide the objects into young, old, and persistent generations, using different algorithms (one of these methods) for different life cycle objects. The current garbage collector (starting with j2se1.2) uses this algorithm.

Divide by System thread

Serial Collection: Serial collection uses single-threaded processing for all garbage collection work because it is easy and efficient to implement without multithreading. However, its limitations are also obvious, that is, the advantage of not using multiple processors, so this collection is suitable for single-processor machines. Of course, this collector can also be used on multiprocessor machines with a small amount of data (around 100M).

Parallel Collection: Parallel collection uses multithreading to handle garbage collection, which is fast and efficient. And the higher the number of CPUs in theory, the more the advantages of parallel collectors can be demonstrated.

Concurrent Collection: with respect to serial collection and parallel collection, the previous two garbage collection tasks require a halt to the entire running environment, and only the garbage collector is running, so the system will have a noticeable pause during garbage collection, and the pause time will be longer because the heap is larger.

JVM Tuning Summary (iii)-Basic garbage collection algorithm

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.