Java garbage Collection Garbage Collection (second, garbage collector

Source: Internet
Author: User

Garbage collector

  • Garbage collector for hotspot virtual machines
    • There is no provision in the Java Virtual Machine specification for how the garbage collector can be implemented, so different versions of the virtual machine provide a large difference in the garbage collector, and will provide the parameters for the user to apply the characteristics and requirements of the collection of the various eras used. The hotspot virtual machine after Java 1.7 contains the following collectors:
    • Cenozoic Collector: Serial, Parnew,parallel scavenge
    • Old age Collector: Cms,serial Old,parallel
    • Standalone heap collector: G1
  • Serial collector
    • The serial collector is the most basic development in the history of the collector. Before jdk1.3 is the only option for virtual machine generation collection. This collector is a single-threaded collector, but its single-threaded meaning does not only mean that it uses a single CPU or a collection thread to do garbage collection, but more importantly, it must suspend all other threads when it is garbage collected, and it collects the end. "Stop the World" is a feature of this collector. This work is actually by the virtual machine in the background auto-completion of the user is not visible in the case of the user's normal working thread all stop to many applications difficult to accept. But the virtual machine development team to eliminate or work threads because of memory recovery caused by the pause has been working hard, from serial to parallel collectors to the CMS to G1, a more and more excellent collectors appear, the user thread pause time is constantly shortened, but still no way to eliminate.
    • Serial advantages: Simple and efficient, single CPU environment serial collector because there is no thread interaction overhead, concentrate on garbage collection nature can get the highest single-thread collection efficiency, in the application scenario is allocated to the virtual machine memory is not very large, collect dozens of hundred trillion new generation, The pause time can be controlled to dozens of milliseconds for up to 100 milliseconds as long as it does not occur frequently this pause is acceptable. So serial is a good choice for virtual machines in client mode.
  • Parnew Collector
    • The Parnew collector is actually a multi-threaded version of the serial collector, in addition to using multithreading for garbage collection, the rest includes all the controllable parameters of the serial collector, the collection algorithm, the Stop the World Object allocation rule, and the recycling strategy is the same as serial. As follows:
    • Currently only the Parnew collector can work with the CMS collector, becoming the preferred generation collector for virtual machines in server mode.
  • Parallel Scavenge Collector
    • The new generation collector, which is also using the copy algorithm parallel scavenge collector is characterized by its focus and other collectors different from the collectors such as the focus of the collector is as much as possible to shorten the garbage collection when the user thread pause time, and parallel The target of the scavenge collector is to achieve a controllable throughput (throughput). Throughput: Is the ratio of the CPU time spent running user code to the total CPU elapsed time, throughput = Run user code time/(run user code time + garbage collection time), virtual machine runs for 100 minutes, garbage collection takes 1 minutes, throughput is 99%.
      • The Parallel scavenge collector has a total of two parameters for precise control of throughput: Maximum garbage collection pause time-xx:maxgcpausemills, directly set throughput size-xx:gctimeratio
      • MAXGCPAUSEMILLS:GC pause time Reduction is the sacrifice of throughput and the new generation of space exchange, the system to the new generation of small points, collect 200M is certainly faster than 500M, which also led to the garbage collector more frequent the original 10s once, each 100ms, now is 5s once each 70ms. The pause time has come down and the throughput has come down.
      • gctimeratio:0-100 Integer, garbage collection time accounted for the total time, is the inverse of the throughput, such as the default is 99 is 1% (1/(99+1)) garbage collection time;
      • -xx:+useadaptivesizepolicy: Do not need to manually set the Eden Survivor scale after opening, the old age object size of the detail parameters, the sequel and will dynamically adjust these parameters to provide the most suitable for the pause time or maximum throughput. Adaptive regulation is also an important difference from the Parnew collector.
  • Serial old
    • The older version of serial, the single-threaded collector uses the tag-grooming algorithm, primarily in client mode under virtual machines
    • Pre-JDK1.5 with parallel scavenge collector, CMS backup plan
  • Parallel old
    • Parallel the old version of the scavenge collector, using multi-threaded and tag grooming algorithms.
    • The new generation if the parallel scavenge collector is selected, the old age can only use serial, with the advent of parallel, in the focus on throughput and CPU-sensitive resource situations can be prioritized parallel scavenge and parallel Old combination.
  • CMS (Concurrent Mark Sweep)
    •   

  • G1 (Garbage first)
    • The G1 collector is a garbage collector for service-side applications
      • Parallel and Concurrency: G1 can take advantage of the hardware benefits of multi-CPU multicore environments, using multiple CPUs to reduce stop-the-world time
      • Generational collection: The G1 collector collects two new generations of old age and can independently manage the entire GC heap without the need for additional collector mates
      • Space consolidation: G1 uses the "mark-and-organize" algorithm to implement the collector, meaning that the G1 does not generate memory space fragmentation during operation and provides regular, usable memory after collection
      • Predictable pauses: Create a predictable pause-time model that allows the user to explicitly specify a time fragment of M milliseconds to consume on the garbage collector for no more than n milliseconds

Java garbage Collection Garbage Collection (second, garbage collector

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.