Skip to content

Commit a87bc7e

Browse files
author
Kim Barrett
committed
8345374: Ubsan: runtime error: division by zero
Reviewed-by: jwaters, ayang, amitkumar
1 parent d3abf01 commit a87bc7e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,14 @@ size_t G1HeapSizingPolicy::young_collection_expansion_amount() {
198198
}
199199

200200
static size_t target_heap_capacity(size_t used_bytes, uintx free_ratio) {
201+
assert(free_ratio <= 100, "precondition");
202+
if (free_ratio == 100) {
203+
// If 100 then below calculations will divide by zero and return min of
204+
// resulting infinity and MaxHeapSize. Avoid issues of UB vs is_iec559
205+
// and ubsan warnings, and just immediately return MaxHeapSize.
206+
return MaxHeapSize;
207+
}
208+
201209
const double desired_free_percentage = (double) free_ratio / 100.0;
202210
const double desired_used_percentage = 1.0 - desired_free_percentage;
203211

0 commit comments

Comments
 (0)