[JVM-related] Java new garbage collector (Garbage First, G1)

Recalling the traditional garbage collector

  • HotSpot garbage collector to achieve
    • Serial Collector (collector-string)

      Usage scenarios, most servers are single-core CPU.
      Applicable collecting scene: 1 to collect the new generation (Young Generation Collection) 2 years old collection (Old Generation Collection).

    • Parallel Conllector (parallel collector)

      Throughput is also called collector (throughput collector) is applied to a multi-core system.
      Applicable collection scenario: 1. New Generation collection parallel processing. 2. old's collection and Serial Collectorthe same.

    • Parallel Compacting Collector (parallel compacting collector)

      Parallel Compacting Collector WAS Introduced of The in the J2SE 5.0 Update of The -difference BETWEEN 6. The Parallel Collector The IT and IT IS that uses Old Generation A new new algorithm for Garbage Collection .
      Note :. Eventually, The Parallel Parallel Compacting Collector Collector Will Replace The
      above text italic text tells us that this collector and on a parallel collectors only difference is the use of new algorithms in the old era.
      Applicable scene collection: 1 to collect the new generation (Young Generation Collector) and Parallel Collector same; 2 years old collection (Old Generation Collector)..

  • Concurrent Mark-Sweep (CMS) Collector (concurrent mark cleared)

    Young generation collections usually does not cause long pause, however, old generation collections is caused long pause, though it does not appear long, especially when the recovery is involved in large heaps. To address this, HotSpot JVM introduced called concurrent mark-sweep(CMS) collector, also commonly referred to 低延时收集器low-latency collector.
    Applicable scene: only applies to the old era, the new generation of treatment and Parallel Collector same.

    G1 goal

    G1 is planned as the long term replacement for the Concurrent Mark-Sweep Collector. Plans to G1 as an alternative to long-term CMS collector.
    It is in order to balance an optimal relationship between latency and throughput.

    The principle G1

    The basic properties
    And the same point of the CMS
  • CMS Replacement (CMS substitute)
  • Server 'Style' Garbage Collector (server garbage collector - memory, auditing difference)
  • Parallel Parallel
  • Concurrent Concurrent
  • Generational generational

    The main difference between the CMS and
  • Good Good Throughput Throughput
  • Compacting compression
  • Improved ease-of-use to enhance the usability (JVM more parameters are available)
  • Predictable (though not hard real-time) can be estimated, non-absolute real time.

    basic concept
  • Stack layout G1
    G1 is divided into fixed-size stack of Region / area (area size only 1,2,4,8,16 and 32M), the old and new generation of G1's are set without a continuous area, each area independent memory allocation and recovery region is the basic unit of memory management, node at a certain time, may be idle, when the memory is requested, the memory manager idle region assigned to a generational, and then return the application assigned to the space.

    In most cases, GC will be operating at the same time in one area.

  • Region Distribution

    Large Object (Humongous Objects)
    in the figure, i.e., the gray block across regions represent large objects, the object is the size of the large space that >=1/2 target a large area of space objects are sometimes processed in a special way of the following:
    • Each large object allocation area in the old years of continuous area. Object allocation starts at the first member in a continuous area, if the last area in the contiguous area there is free space, then the space will be allocated to lose the opportunity, until the large object whose association is fully recovered
    • Large objects typically recovered only Marking the end of a pause in Cleanup, or when Full GC.
    • Allocate large objects may cause garbage collection pauses occur prematurely (mainly because of wasted space.)
    • Large objects will move never happened, not even in the case of Full GC

UTOOLS1564983870502.png

  • Recovery period
    • Young-only

      Young-only stage of garbage collection when the object is gradually filling the old era to the current available memory. About to be promoted to the new generation of objects to enhance years old.
      This phase began in the Young-only collection action, that is, in the figure below blue ball, the ball is to collect every little action once, the object is to elevate years old. Young-only and Space-reclamation transition actually began to 老年代空间 *占用*reach a certain threshold, that Heap initialization occupancy threshold. At this time, G1 dispatches Initial Mark's Young-only collection (the big blue ball), instead of the usual Young-only (blue balls) collected.

      • Initial Mark
        such collections to mark the beginning of the process, with a conventional Young-only collection, decided that all concurrent mark up the region's survival in the old object is to be left to the Space-reclamation stage. When the labeling process did not end, the conventional Young-only collection that may have occurred, until the labeling is complete, will be accompanied by two special Stop-The-Worldpause, Remarkand CleanUp.
      • Remark standstill
        because Initial Markthe labeling process, because it is the concurrent execution, there may occur Young-onlycollect, causing the marker data error, it is necessary to re-mark once the process is executed serially cause Stop-The-World.

        Between the Remark and Cleanup, G1 will concurrently calculate a target viability of the final report, it will stop the data structure inside Cleanup stage update

      • Cleanup pause
        The pause is also the full recovery of the free area, and decide Space-reclamationwhether to stage the need to continue to track, if it continues to follow the case, complete Young-only stage only do Young-onlythe collection action.
    • Space-reclamation

      Space-reclamation (space reclamation / reuse) phase is recycled old's space, at the same time deal with the new generation.
      This phase consists of collection action more mixed composition, includes not only the new generation of the region, but also exclude years old live objects area, when the G1 still unable to find space to satisfy the request free, G1 will terminate this stage. If the application memory consumed, G1 will perform Stop-The-Worlda full stack of compression (Full GC).
      As shown below:

      two kinds iterative process is collected.

      G1 instruction details

      The initial footprint

      Initiating Heap Occupancy Percent (IHOP): Initial Mark the collection threshold is triggered, defined as the percentage of occupied Heap's old space.

      JVM setting parameters: -XX: InitiatingHeapOccupancyPercent
      default, in accordance with the memory allocation time, and the old tag in the tag's cycle, Gl garbage collector will automatically choose an ideal value of IHOP.
      Failure JVM parameters: -XX: -G1UseAdaptiveIHOP
      modification area space
      -XX: G1HeapRegionSize
      UTOOLS1565004969320.png

      G1 Vs. traditional garbage collector

  • G1 does not distinguish between new / old generation, only to distinguish Region
  • G1 collected in two stages Young-onlyandSpace-reclamation

Guess you like

Origin www.cnblogs.com/zhangpan1244/p/11305266.html