JVM Learning notes-garbage collector

Source: Internet
Author: User

TITLE:JVM Study notes-garbage collector
DATE:2018/9/4 17:09:31
Description: Recently started the study of the JVM, here to share their own learning process notes, hoping to help some small partners, but also a comb of their own learning.

Garbage collector

There is a lot of garbage collector content, but the algorithm principle is based on garbage collection algorithm, so here is only a brief introduction of the characteristics of each collector.

  • Collector groups in the Hopspot
    The connection between the two virtual machines means that they can be used with each other, and vice versa.

  • Serial collector
    • Using the mark-and-Organize algorithm
    • The single-threaded collector, where a single thread refers to the serial when performing a collection of threads, the other threads must be paused, causing a large number of GC pauses to occur.
    • The advantages are simple and efficient, excellent performance in the client mode virtual machine.

  • Serial Old Collector
    • Serial version of the old age, the characteristics of basic and serial consistent.
    • It can be used in conjunction with parallel before JDK1.5, or as a fallback scheme for CMS.

  • Parnew Collector
    • Parnew is a multithreaded version that is improved for serial.
    • In many virtual machines, parnew is the preferred collector for the new generation, because it can be used in conjunction with the CMS except serial.

  • Parallel Scavenge Collector
    • is a new generation of collectors, using multi-threaded + replication algorithms.
    • The main focus is on the throughput of the Collector 吞吐量=运行用户代码时间/(运行用户代码时间+垃圾收集时间) , which provides two parameters for precise control of throughput:
      • -xx:maxgcpausemillis, maximum GC pause time. The allowable value is a number of milliseconds greater than 0, and the collector ensures that the collection time does not exceed that value. Note that a shorter pause time is required to sacrifice throughput and space, and a smaller pause time may lead to more frequent GC.
      • -XX:GCTIMERATIO,GC time as a percentage of total time. is an integer between 0-100 and equal to the reciprocal of the throughput.

  • Parallel Old Collector
    • Parallel the old version of scavenge, using multi-threaded + tag finishing algorithms.
    • Due to the poor performance of serial old on the service side, the collector is used in conjunction with the parallel scavenge.

  • The
  • CMS collector (Concurrent Mark Sweep)
    • is based on the tag-purge algorithm, a collector that targets the shortest GC pause time. Its operation is divided into 4 steps: The
      • initial tag
        marks the object to which GC roots can be associated. The
      • concurrency token
        is a trace of the object initiated by GC roots, verifying that it is available.
      • to re-flag the tag record of a part of an object that has changed during the concurrency token.
      • to clear the space for the
        Purge tag object.
    where only the initial tag and the two procedure need to be paused, but these two processes are simply tokens, fast, and the longest cleanup process can be processed in parallel with the user thread under the CMS. Although the
    • CMS is powerful, it still has the following 3 drawbacks:
      • Although the CMS does not cause the GC to stall, the concurrency cost is CPU-intensive, which can cause the user program to become slower, and the problem becomes more apparent in CPUs with lower cores.
      • Since the cleanup of the CMS does not suspend the user thread, which may result in "floating garbage", it is necessary to set aside a portion of the memory space corresponding to "floating garbage", so the CMS has a percentage of memory that triggers recycling, which defaults to 92% in JDK1.6. If the reserved memory is still unable to meet the program's requirements, the CMS initiates a fallback scheme (typically serial old) to re-collect.
      • because the CMS uses the tag-purge algorithm, there is a large amount of memory fragmentation that can cause large objects to find no space to store and trigger a full GC for memory grooming in advance.
  • G1 collectors appear after JDK1.7, G1 has the following four features:
    • parallel and concurrent, can take advantage of multi-threading, multi-CPU, so that the GC and the user thread parallel. The
    • G1 can manage the entire GC heap on its own, with generational features that can be handled in different ways depending on the region. The
    • divides the Java heap into multiple independent regions of equal size (region), which is based on the replication algorithm, and is based on the implementation of the tag-collation algorithm, combining the advantages of the two algorithms. The
    • establishes a predictable pause model, which can be set to the desired GC time through -xx:maxgcpausemillis , and G1 will try to complete the GC at that time.

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.