8308766: TLAB initialization may cause div by zero

Reviewed-by: shade, ayang
This commit is contained in:
Thomas Schatzl
2023-06-01 06:57:45 +00:00
parent 6c7225f819
commit 96ed1392d1

View File

@@ -213,9 +213,11 @@ void ThreadLocalAllocBuffer::initialize() {
set_desired_size(initial_desired_size());
size_t capacity = Universe::heap()->tlab_capacity(thread()) / HeapWordSize;
// Keep alloc_frac as float and not double to avoid the double to float conversion
float alloc_frac = desired_size() * target_refills() / (float) capacity;
_allocation_fraction.sample(alloc_frac);
if (capacity > 0) {
// Keep alloc_frac as float and not double to avoid the double to float conversion
float alloc_frac = desired_size() * target_refills() / (float)capacity;
_allocation_fraction.sample(alloc_frac);
}
set_refill_waste_limit(initial_refill_waste_limit());