Skip to content

Commit

Permalink
8345374: Ubsan: runtime error: division by zero
Browse files Browse the repository at this point in the history
Reviewed-by: jwaters, ayang, amitkumar
  • Loading branch information
Kim Barrett committed Jan 2, 2025
1 parent d3abf01 commit a87bc7e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/hotspot/share/gc/g1/g1HeapSizingPolicy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,14 @@ size_t G1HeapSizingPolicy::young_collection_expansion_amount() {
}

static size_t target_heap_capacity(size_t used_bytes, uintx free_ratio) {
assert(free_ratio <= 100, "precondition");
if (free_ratio == 100) {
// If 100 then below calculations will divide by zero and return min of
// resulting infinity and MaxHeapSize. Avoid issues of UB vs is_iec559
// and ubsan warnings, and just immediately return MaxHeapSize.
return MaxHeapSize;
}

const double desired_free_percentage = (double) free_ratio / 100.0;
const double desired_used_percentage = 1.0 - desired_free_percentage;

Expand Down

0 comments on commit a87bc7e

Please sign in to comment.