--- old/src/hotspot/share/gc/g1/g1Policy.cpp 2019-11-20 14:56:37.077025344 +0100 +++ new/src/hotspot/share/gc/g1/g1Policy.cpp 2019-11-20 14:56:36.734014727 +0100 @@ -722,7 +722,11 @@ p->sum_thread_work_items(G1GCPhaseTimes::OptMergeRS, G1GCPhaseTimes::MergeRSDirtyCards) + total_log_buffer_cards; - if (total_cards_merged > 10) { + // The threshold for the number of cards in a given sampling which we consider + // large enough so that the impact from setup and other costs is negligible. + size_t const CardsNumSamplingThreshold = 10; + + if (total_cards_merged > CardsNumSamplingThreshold) { double avg_time_merge_cards = average_time_ms(G1GCPhaseTimes::MergeER) + average_time_ms(G1GCPhaseTimes::MergeRS) + average_time_ms(G1GCPhaseTimes::MergeHCC) + @@ -735,7 +739,7 @@ size_t const total_cards_scanned = p->sum_thread_work_items(G1GCPhaseTimes::ScanHR, G1GCPhaseTimes::ScanHRScannedCards) + p->sum_thread_work_items(G1GCPhaseTimes::OptScanHR, G1GCPhaseTimes::ScanHRScannedCards); - if (total_cards_scanned > 10) { + if (total_cards_scanned > CardsNumSamplingThreshold) { double avg_time_dirty_card_scan = average_time_ms(G1GCPhaseTimes::ScanHR) + average_time_ms(G1GCPhaseTimes::OptScanHR);