Detailed garbage collector

Here Insert Picture Description

Introduction

Here Insert Picture Description
Effect is shown in FIG seven different generational collectors, if there is the connection between the two collectors, suggests that they may be used with. When JDK8 the Serial + CMS, ParNew + Serial Old combination of these two statements is abandoned, and completely abolished support for these combinations in JDK9

First clear a concept

Parallel (Parallel) : refers to the number of threads in parallel garbage collection, but this time the user thread is still in a wait state
concurrent (Concurrent ): refers to the user threads and threads execute simultaneously garbage collection

Serial Collector

The new generation, mark - replication algorithm, single-threaded. When garbage collection, threads must suspend all other work until it is collected by the end of
Here Insert Picture Description

ParNew collector

It is a multi-threaded parallel version Serial collector on ParNew nature
Here Insert Picture Description

Parallel Scavenge collector

The new generation, mark replication algorithm, multi-threaded, focuses on the throughput
throughput = user code running time / (run time + user code to run garbage collection time)

Serial Old collectors

Years old, Mark - sorting algorithm, single-threaded, old collector's edition Serial

Use the following two

  1. In JDK5 and earlier in the Parallel Scavenge collector with the use of
  2. , Used as a back-up plan when failure occurs when the CMS collector Concurrent Mode Failure concurrent collection happen

Parallel Old collectors

Years old, Mark - sorting algorithms, multi-threaded, the old version's Parallel Scavenge collector

Focus on throughput or processor resources are more scarce occasion, it can give priority to add Parallel Old Parallel Scavenge collector this combination
Here Insert Picture Description

CMS collector

Years old, mark - sweep algorithm, multi-threaded, the main concern delay

The operation process is divided into four steps

  1. The initial mark (CMS initial mark)
  2. Concurrent mark (CMS concurrent mark)
  3. Relabeled (CMS remark)
  4. Concurrent Clear (CMS concurrent sweep)
    Here Insert Picture Description
  5. The initial mark: mark what objects can be linked directly to the GC Roots, very fast
  6. Concurrent mark: direct associated objects GC Roots from the beginning of the entire object graph traversal, this process takes a long time but do not need to stop user threads can run concurrently with the garbage collection
  7. Relabeled: To amend during concurrent mark, due to the continued operation of the user program which led to marked record that part of the object changes from label
  8. Concurrent clear: clean up the deleted objects marking phase judgment have died, because no moving live objects, so you can also look at this stage concurrent user threads

Garbage First collector (G1)

to sum up

collector Collect objects and algorithms Collector type Explanation Applicable scene
Serial The new generation, replication algorithm Single-threaded Simple and efficient; not suitable memory situation
ParNew The new generation, replication algorithm Parallel multi-threaded Collector ParNew garbage collector is multi-threaded version of the Serial collector With CMS garbage collector's choice
Parallel Scavenge collector certain priority The new generation, replication algorithm Parallel multi-threaded Collector Similarly ParNew, more attention throughput, throughput reaches a controlled GC itself is the default mode on Server-level multi-CPU machines, the main task for background operation does not require much interaction
collector Collect objects and algorithms Collector type Explanation Applicable scene
Serial Old Years old, mark Collation Algorithm Single-threaded Under Client mode virtual machine
Parallel Old Years old, mark Collation Algorithm Parallel multi-threaded Collector Paraller Scavenge collector years old version, in order to configure the characteristics of the throughput Parallel Svavenge corresponding compositions developed for In focusing on the use of CPU resources and throughput sensitive applications
CMS Years old, mark sweep algorithm Parallel and concurrent collector User thread to stop garbage collection time shortened as much as possible; the disadvantage is that memory fragmentation 1, 2 requires more CPU resources, 3 floating garbage problem that requires more heap space. The corresponding emphasis on service speed, dwell time system and user experience of Internet sites or B / S system. Internet backend cms is currently the mainstream garbage collector
G1 Across the old and the new generation's; tags to organize decentralized + Parallel and concurrent collector JDK1.7 was formally introduced, using the partition recovery of thinking, memory recovery complete standstill of low basic premise without sacrificing throughput; predictable pause is its greatest strength

Welcome attention

Here Insert Picture Description

Reference blog

Published 385 original articles · won praise 1471 · Views 900,000 +

Guess you like

Origin blog.csdn.net/zzti_erlie/article/details/104585411