"JVM G1 source code analysis and tuning" study notes

GC algorithm associated with the JVM garbage collector

GC related algorithms

  • Generational management
  • Replication algorithm
  • Clear labeling
  • Compression mark

JVM garbage collectors

P242 Table 11-1 payback compare different types of garbage

  • Serial collector Serial. Serial GC for the new generation, with a copy algorithm; Serial Old GC's role on the old, using a mark - compression algorithm. STW
  • Parallel collector Parallel. Parallel new role in the new generation, using the copy algorithm; Parallel old role of the old era, with the mark - compression algorithm. STW. Concurrent collector is to collect accurate, no floating garbage.
  • Concurrent collector Concurrent-Mark-Sweep. Old's garbage collector. Use the mark - sweep algorithm. Into initial labels (Initial-Mark, STW), concurrent mark (Concurrent-Mark), re-mark (Remark, STW), clear concurrent (Concurrent-Sweep). CMS because of the need to store a reference intergenerational relations, so there consume additional storage space. CMS is not accurate collection, will produce a floating garbage.
  • Priority garbage collector G1. Collected in accordance partition, the partition will always recover the new generation, the old generation is to choose the best partition portion after recovery effect concurrent mark. G1 is divided into three recovery mode: 新生代回收Young, 混合回收(Mixed, both to collect the new generation also collected some of the old year), FUll GC. 新生代回收STW only need before you begin. 混合回收It is divided into two phases: the concurrent garbage collection and marking phase stage. Concurrent marking phase was divided into four steps: an initial sub-phase marker (initital-mark), concurrent mark sub-phase (concurrent-mark), then mark sub-phase (remark, STW), cleaning sub-stages (cleanup, STW). Due to partition design, G1 references take up extra storage space consumed by a larger relationship. G1 is not accurate collection, will produce a floating garbage.

The basic concept of G1

Partition

G1 is divided into a small region of memory used. These regions called Heap Region. There are extended YHR(the new generation partition), OHR(old generation partitions) HHR(partition large objects) and the like
in order to achieve a balanced distribution efficiency and cleaning efficiency, the size of the upper and lower limit values of HR, i.e., 1MB-32MB. Combined with whole heap space is divided into 2048 HR, then the maximum stack typically G1 management is 32MB * 2048 = 64G.

The size of the new generation

Parameter set such that G1 can infer the maximum and minimum

Parameters involved are:

  • MaxNewSize new generation of maximum, minimum NewSize, Xmn (equivalent to MaxNewSize and NewSize, and MaxNewSize = NewSize)
  • NewRatio, if the item parameter is set, this parameter is ignored
  • If only set NewRatio, the new generation is the same as the maximum and minimum: the entire heap / (newRatio + 1)
  • If no minimum and maximum values, or only one of which is provided, according to the parameters will then G1 G1MaxNewSizePercent (default 60) and G1NewSizePercent (default 5) ratio of the total stack space is calculated.

If the maximum value and the minimum value G1 inferred new generation equal, then the new generation do not change dynamically, do not change dynamically cause may not meet the desired dwell time subsequent new generation of the GC , so there is no article mentioned G1 Xmn recommended setting parameters.

Related code share / vm / gc_implementation / g1 / g1collectorPolicy.cpp

G1 heuristics to infer the size of the new generation

G1 has a thread dedicated to the sampling process to predict the length of the new generation of the list should be much, and dynamically adjusts.

When and how much extended memory once the expansion?
Parameters -XX: GCTimeRatio represents the ratio of the time-consuming application with the GC, G1 9 default. That is time-consuming and time-consuming application GC when the proportion exceeds 10%, the dynamic expansion. Expanded size parameter is G1ExpandByPercentOfAvailable, while at least greater than 1MB, up to not exceed the current times the size of the already allocated.
Code size_t G1CollectorPolicy :: expansion_amount () ....
The book in Chapter V speaks refine this thread point more in detail

G1 pause prediction model

I'm more partial math quickly jump over
prediction logic G1 is based on the average attenuation (Decaying Average) and attenuation standard deviation.

Card table and bitmap

Card table (CardTable) is one of the common concept of CMS. I understand the composition range described object reference depository relationships or data structures stored. The book also speaks of a more simple, the details can be found in "garbage collection algorithms Handbook: The Art of automatic memory management."

Object header

Speak JVM memory model will speak object header. See, I can write the JVM object model and the corresponding terms and concepts

Stack frame, thread, etc.

Stack frame can be found in letters written by Avion "Secret Java Virtual Machine" Chapter VII of the Java stack frames, write in more detail. The book only in passing, looked with nothing did not see the difference.

Object allocation of G1

  • Fast and slow distribution distribution
  • Quick distribution achieved by TLAB (Thread Local Allocation Buffer). TLAB own allocation is CAS operations. Internal TLAB to object allocation is no lock, because only the thread with its own thing.
  • TLAB mechanism or generate wastes memory object is not assigned in a two TLAB region, the tail region endmost TLAB may remain empty. TLABRefillWasteFraction by the parameter adjustment, the ratio of representation allows wasteful. The default value is 64, it means that wasted space can be 1/64.
  • TLAB size can be automatically adjusted, but will not exceed half of HR. ,
  • You can use the parameters -XX: -ResizeTLAB disabled ResizeTLAB, and use the parameters -XX: TLABSize specify a size. -XX: + PrintTLAB can track TLAB work.
  • TLAB is generally not recommended to modify the parameters, it is recommended to use the default values

TLAB quickly assign code HeapWord * CollectedHeap :: allocate_from_tlab ...

Refine the G1 thread

Talk about Rset

Rset

Rset is used to do?

  • Rset is an abstract concept, a reference relationship is recorded between the different generations of inter purpose is to accelerate the GC.
  • In layman's terms, the recording can be set from Rset pointer points to non-collecting portion collecting portion. For this recording described demand, there are two ways, one is 我引用了谁called Point Out; one 谁引用了我, called Point In. G1 latter.
  • G1 required references between the recording intergenerational comprising: partitioning the old generation to the new generation of a reference relationship between the partition (YGC, the reference relationship is part of the GC Roots of the old generation can not be invoked to recover lost thing .. .); when referring to the relationship between the old generation to the old generation partitions partition (mixed with GC)
  • Rset relationship with card tables refer to Figure 4-1 P68
  • G1 introduces a PRT, TODO: do not look too understand
  • DCQ and Refinemnet zone of four-color area did not look too understand

Rset write barrier

Why it comes to writing barrier, because Refine thread is concerned with the relationship between the change application, but he is how to identify the relationship between a reference change it? That is, by writing to complete the barrier. Here to talk write barrier related points:

  • Write barrier word I do not know why so named, difficult to understand intuitively.
  • I understand it is, write blocker treatment before and after the operation. For example, I putfield assignment of field, before the assignment I have to tell this object is DCQ I quoted, which is to write barrier action.
  • Saying the book: 写屏障refers to the change in value of a particular time in memory, a number of additional actions to perform.
  • CMS is not washed by scraping write barrier referenced records, G1 too.
  • Write barrier will be optimized, not all of the references to the relationship between changes will be recorded.
    • Record the new generation to the new generation without a reference, or a reference to the new generation to the old generation, when the write barrier filter
    • Filter out internal reference the same partition, filter processing in Rset
    • Filter out null reference, filter processing in Rset

Refine thread

  • Refine thread is a group, is a thread pool, not one.
  • I understand he is a thread for sampling, the main role of the new generation of set number of partitions. The remaining threads for managing Rset, Rset not update synchronization is complete, depending Refine threads asynchronously, asynchronous, but also by DCQ dirty card queue queue staging transition.
  • JVM Refine involve more complex, not a careful study
  • Parameters: by -XX: + G1TraceConcRefinement observe Refine thread work. By -XX: + G1SummarizeRSetStats observe Rset update.

New Generation Recycling

As already talked about, G1 GC in three: 新生代回收Young, 混合回收(Mixed, both to collect the new generation also collected some of the old year),FUll GC

step:

  1. Select CSet
  2. Root treatment
  3. Rset processing
  4. copy
  5. Redirty reconstruction Rset
  6. Free up space

Related Blog

You can use -XX: G1LogLevel = finest open more detailed log
keyword GC pause (G1 Evacuation Pause) ( young), 0.0182341 secs ...

Tuning parameters

Mixed Recycling

混合回收It is divided into two stages:

  • Concurrent mark phase
  • Garbage collection phase (recovery consistent with the new generation)

Concurrent marking phase was divided into four steps:

  1. The initial mark sub-phase (initital-mark)
  2. Concurrent mark sub-phase (concurrent-mark)
  3. Then mark sub-phase (remark, STW)
  4. Cleanup sub-phase (cleanup, STW

Concurrent mark of difficulty:
objects in the process of being labeled reference relationship has changed.
By three-color labeling algorithm combined with STAB write barrier is completed.
Write barrier code oop_store in, oop.inline.hpp

Related Blog

PAUSE key GC (G1 Evacuation Pause) (Mixed), 0.0106341 secs ...
GC PAUSE (G1 Evacuation Pause) (Young) (Initial-Mark), .... // initial mark borrowed YGC
[Concurrent GC-Mark -start] ...
[Concurrent the GC-Mark-End] ...
[the remark the GC ...] ...
[the GC Cleanup ...] ...

Tuning parameters

Full GC

JDK10 before FGC is serial, JDK10 support parallel after.
Code G1CollectedHeap :: do_collection
recovery algorithm using clear marks, serial steps:

  1. Mark live objects
  2. Calculate the new object address
  3. All objects are updated to the new address
  4. Moving objects to complete the compression

Related Blog

[Full GC (Allocation Failure) ..... 0.2036229 secs]....

G1 Tuning

It is mainly related indicators: a maximum throughput, end stop period of time as possible, the lowest possible frequency and high GC heap space utilization efficiency.
The main tuning parameters see Table 11-2 P244, mainly related to the stack, the parameter RSet, numerals and GC four aspects.

Guess you like

Origin www.cnblogs.com/simoncook/p/11831289.html