Skip to content

Commit 8063aa2

Browse files
author
Kim Barrett
committed
8306695: Divide by zero in G1Policy::logged_cards_processing_time
Reviewed-by: iwalulya, tschatzl
1 parent 2471919 commit 8063aa2

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/hotspot/share/gc/g1/g1Policy.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2001, 2022, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2001, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -722,8 +722,15 @@ double G1Policy::logged_cards_processing_time() const {
722722
size_t logged_dirty_cards = phase_times()->sum_thread_work_items(G1GCPhaseTimes::MergeLB, G1GCPhaseTimes::MergeLBDirtyCards);
723723
size_t scan_heap_roots_cards = phase_times()->sum_thread_work_items(G1GCPhaseTimes::ScanHR, G1GCPhaseTimes::ScanHRScannedCards) +
724724
phase_times()->sum_thread_work_items(G1GCPhaseTimes::OptScanHR, G1GCPhaseTimes::ScanHRScannedCards);
725-
// This may happen if there are duplicate cards in different log buffers.
726-
if (logged_dirty_cards > scan_heap_roots_cards) {
725+
// Approximate the time spent processing cards from log buffers by scaling
726+
// the total processing time by the ratio of logged cards to total cards
727+
// processed. There might be duplicate cards in different log buffers,
728+
// leading to an overestimate. That effect should be relatively small
729+
// unless there are few cards to process, because cards in buffers are
730+
// dirtied to limit duplication. Also need to avoid scaling when both
731+
// counts are zero, which happens especially during early GCs. So ascribe
732+
// all of the time to the logged cards unless there are more total cards.
733+
if (logged_dirty_cards >= scan_heap_roots_cards) {
727734
return all_cards_processing_time + average_time_ms(G1GCPhaseTimes::MergeLB);
728735
}
729736
return (all_cards_processing_time * logged_dirty_cards / scan_heap_roots_cards) + average_time_ms(G1GCPhaseTimes::MergeLB);

0 commit comments

Comments
 (0)