mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2026-01-08 17:41:41 +01:00
8223762: Shenandoah: overflows in calculations involving heap capacity
Reviewed-by: rkennke
This commit is contained in:
@@ -73,9 +73,9 @@ void ShenandoahAdaptiveHeuristics::choose_collection_set_from_regiondata(Shenand
|
||||
// ShenandoahGarbageThreshold is the soft threshold which would be ignored until min_garbage is hit.
|
||||
|
||||
size_t capacity = ShenandoahHeap::heap()->max_capacity();
|
||||
size_t free_target = ShenandoahMinFreeThreshold * capacity / 100;
|
||||
size_t free_target = capacity / 100 * ShenandoahMinFreeThreshold;
|
||||
size_t min_garbage = free_target > actual_free ? (free_target - actual_free) : 0;
|
||||
size_t max_cset = (size_t)(1.0 * ShenandoahEvacReserve * capacity / 100 / ShenandoahEvacWaste);
|
||||
size_t max_cset = (size_t)((1.0 * capacity / 100 * ShenandoahEvacReserve) / ShenandoahEvacWaste);
|
||||
|
||||
log_info(gc, ergo)("Adaptive CSet Selection. Target Free: " SIZE_FORMAT "M, Actual Free: "
|
||||
SIZE_FORMAT "M, Max CSet: " SIZE_FORMAT "M, Min Garbage: " SIZE_FORMAT "M",
|
||||
@@ -128,7 +128,7 @@ bool ShenandoahAdaptiveHeuristics::should_start_normal_gc() const {
|
||||
|
||||
// Check if we are falling below the worst limit, time to trigger the GC, regardless of
|
||||
// anything else.
|
||||
size_t min_threshold = ShenandoahMinFreeThreshold * heap->max_capacity() / 100;
|
||||
size_t min_threshold = capacity / 100 * ShenandoahMinFreeThreshold;
|
||||
if (available < min_threshold) {
|
||||
log_info(gc)("Trigger: Free (" SIZE_FORMAT "M) is below minimum threshold (" SIZE_FORMAT "M)",
|
||||
available / M, min_threshold / M);
|
||||
@@ -138,7 +138,7 @@ bool ShenandoahAdaptiveHeuristics::should_start_normal_gc() const {
|
||||
// Check if are need to learn a bit about the application
|
||||
const size_t max_learn = ShenandoahLearningSteps;
|
||||
if (_gc_times_learned < max_learn) {
|
||||
size_t init_threshold = ShenandoahInitFreeThreshold * heap->max_capacity() / 100;
|
||||
size_t init_threshold = capacity / 100 * ShenandoahInitFreeThreshold;
|
||||
if (available < init_threshold) {
|
||||
log_info(gc)("Trigger: Learning " SIZE_FORMAT " of " SIZE_FORMAT ". Free (" SIZE_FORMAT "M) is below initial threshold (" SIZE_FORMAT "M)",
|
||||
_gc_times_learned + 1, max_learn, available / M, init_threshold / M);
|
||||
@@ -152,8 +152,8 @@ bool ShenandoahAdaptiveHeuristics::should_start_normal_gc() const {
|
||||
|
||||
size_t allocation_headroom = available;
|
||||
|
||||
size_t spike_headroom = ShenandoahAllocSpikeFactor * capacity / 100;
|
||||
size_t penalties = _gc_time_penalties * capacity / 100;
|
||||
size_t spike_headroom = capacity / 100 * ShenandoahAllocSpikeFactor;
|
||||
size_t penalties = capacity / 100 * _gc_time_penalties;
|
||||
|
||||
allocation_headroom -= MIN2(allocation_headroom, spike_headroom);
|
||||
allocation_headroom -= MIN2(allocation_headroom, penalties);
|
||||
|
||||
@@ -52,9 +52,11 @@ ShenandoahCompactHeuristics::ShenandoahCompactHeuristics() : ShenandoahHeuristic
|
||||
bool ShenandoahCompactHeuristics::should_start_normal_gc() const {
|
||||
ShenandoahHeap* heap = ShenandoahHeap::heap();
|
||||
|
||||
size_t capacity = heap->max_capacity();
|
||||
size_t available = heap->free_set()->available();
|
||||
size_t threshold_bytes_allocated = heap->max_capacity() * ShenandoahAllocationThreshold / 100;
|
||||
size_t min_threshold = ShenandoahMinFreeThreshold * heap->max_capacity() / 100;
|
||||
|
||||
size_t threshold_bytes_allocated = capacity / 100 * ShenandoahAllocationThreshold;
|
||||
size_t min_threshold = capacity / 100 * ShenandoahMinFreeThreshold;
|
||||
|
||||
if (available < min_threshold) {
|
||||
log_info(gc)("Trigger: Free (" SIZE_FORMAT "M) is below minimum threshold (" SIZE_FORMAT "M)",
|
||||
|
||||
@@ -82,7 +82,7 @@ void ShenandoahPassiveHeuristics::choose_collection_set_from_regiondata(Shenando
|
||||
// Do not select too large CSet that would overflow the available free space.
|
||||
// Take at least the entire evacuation reserve, and be free to overflow to free space.
|
||||
size_t capacity = ShenandoahHeap::heap()->max_capacity();
|
||||
size_t available = MAX2(ShenandoahEvacReserve * capacity / 100, actual_free);
|
||||
size_t available = MAX2(capacity / 100 * ShenandoahEvacReserve, actual_free);
|
||||
size_t max_cset = (size_t)(available / ShenandoahEvacWaste);
|
||||
|
||||
log_info(gc, ergo)("CSet Selection. Actual Free: " SIZE_FORMAT "M, Max CSet: " SIZE_FORMAT "M",
|
||||
|
||||
@@ -54,7 +54,7 @@ bool ShenandoahStaticHeuristics::should_start_normal_gc() const {
|
||||
|
||||
size_t capacity = heap->max_capacity();
|
||||
size_t available = heap->free_set()->available();
|
||||
size_t threshold_available = (capacity * ShenandoahFreeThreshold) / 100;
|
||||
size_t threshold_available = capacity / 100 * ShenandoahFreeThreshold;
|
||||
|
||||
if (available < threshold_available) {
|
||||
log_info(gc)("Trigger: Free (" SIZE_FORMAT "M) is below free threshold (" SIZE_FORMAT "M)",
|
||||
|
||||
@@ -119,9 +119,9 @@ void ShenandoahTraversalHeuristics::choose_collection_set(ShenandoahCollectionSe
|
||||
|
||||
size_t capacity = heap->max_capacity();
|
||||
size_t actual_free = heap->free_set()->available();
|
||||
size_t free_target = ShenandoahMinFreeThreshold * capacity / 100;
|
||||
size_t free_target = capacity / 100 * ShenandoahMinFreeThreshold;
|
||||
size_t min_garbage = free_target > actual_free ? (free_target - actual_free) : 0;
|
||||
size_t max_cset = (size_t)(1.0 * ShenandoahEvacReserve * capacity / 100 / ShenandoahEvacWaste);
|
||||
size_t max_cset = (size_t)((1.0 * capacity / 100 * ShenandoahEvacReserve) / ShenandoahEvacWaste);
|
||||
|
||||
log_info(gc, ergo)("Adaptive CSet Selection. Target Free: " SIZE_FORMAT "M, Actual Free: "
|
||||
SIZE_FORMAT "M, Max CSet: " SIZE_FORMAT "M, Min Garbage: " SIZE_FORMAT "M",
|
||||
@@ -211,7 +211,7 @@ bool ShenandoahTraversalHeuristics::should_start_traversal_gc() {
|
||||
|
||||
// Check if we are falling below the worst limit, time to trigger the GC, regardless of
|
||||
// anything else.
|
||||
size_t min_threshold = ShenandoahMinFreeThreshold * heap->max_capacity() / 100;
|
||||
size_t min_threshold = capacity / 100 * ShenandoahMinFreeThreshold;
|
||||
if (available < min_threshold) {
|
||||
log_info(gc)("Trigger: Free (" SIZE_FORMAT "M) is below minimum threshold (" SIZE_FORMAT "M)",
|
||||
available / M, min_threshold / M);
|
||||
@@ -221,7 +221,7 @@ bool ShenandoahTraversalHeuristics::should_start_traversal_gc() {
|
||||
// Check if are need to learn a bit about the application
|
||||
const size_t max_learn = ShenandoahLearningSteps;
|
||||
if (_gc_times_learned < max_learn) {
|
||||
size_t init_threshold = ShenandoahInitFreeThreshold * heap->max_capacity() / 100;
|
||||
size_t init_threshold = capacity / 100 * ShenandoahInitFreeThreshold;
|
||||
if (available < init_threshold) {
|
||||
log_info(gc)("Trigger: Learning " SIZE_FORMAT " of " SIZE_FORMAT ". Free (" SIZE_FORMAT "M) is below initial threshold (" SIZE_FORMAT "M)",
|
||||
_gc_times_learned + 1, max_learn, available / M, init_threshold / M);
|
||||
@@ -235,8 +235,8 @@ bool ShenandoahTraversalHeuristics::should_start_traversal_gc() {
|
||||
|
||||
size_t allocation_headroom = available;
|
||||
|
||||
size_t spike_headroom = ShenandoahAllocSpikeFactor * capacity / 100;
|
||||
size_t penalties = _gc_time_penalties * capacity / 100;
|
||||
size_t spike_headroom = capacity / 100 * ShenandoahAllocSpikeFactor;
|
||||
size_t penalties = capacity / 100 * _gc_time_penalties;
|
||||
|
||||
allocation_headroom -= MIN2(allocation_headroom, spike_headroom);
|
||||
allocation_headroom -= MIN2(allocation_headroom, penalties);
|
||||
|
||||
@@ -430,7 +430,7 @@ void ShenandoahFreeSet::rebuild() {
|
||||
}
|
||||
|
||||
// Evac reserve: reserve trailing space for evacuations
|
||||
size_t to_reserve = ShenandoahEvacReserve * _heap->max_capacity() / 100;
|
||||
size_t to_reserve = _heap->max_capacity() / 100 * ShenandoahEvacReserve;
|
||||
size_t reserved = 0;
|
||||
|
||||
for (size_t idx = _heap->num_regions() - 1; idx > 0; idx--) {
|
||||
|
||||
@@ -153,7 +153,7 @@ void ShenandoahPacer::setup_for_traversal() {
|
||||
void ShenandoahPacer::setup_for_idle() {
|
||||
assert(ShenandoahPacing, "Only be here when pacing is enabled");
|
||||
|
||||
size_t initial = _heap->max_capacity() * ShenandoahPacingIdleSlack / 100;
|
||||
size_t initial = _heap->max_capacity() / 100 * ShenandoahPacingIdleSlack;
|
||||
double tax = 1;
|
||||
|
||||
restart_with(initial, tax);
|
||||
|
||||
Reference in New Issue
Block a user