From ea38ec153acf5c70a9e7748d456db45450c5c2f9 Mon Sep 17 00:00:00 2001 From: Kelvin Nilsen Date: Wed, 14 Jan 2026 21:55:04 +0000 Subject: [PATCH] move some post_initialize() work into subclass ShenandoahGenerationalHeuristics --- .../heuristics/shenandoahAdaptiveHeuristics.cpp | 16 +++++----------- .../heuristics/shenandoahAdaptiveHeuristics.hpp | 12 ++++++------ .../shenandoahGenerationalHeuristics.cpp | 10 ++++++++++ .../shenandoahGenerationalHeuristics.hpp | 3 +++ 4 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/hotspot/share/gc/shenandoah/heuristics/shenandoahAdaptiveHeuristics.cpp b/src/hotspot/share/gc/shenandoah/heuristics/shenandoahAdaptiveHeuristics.cpp index f0531f3b0f9..1d680e8845f 100644 --- a/src/hotspot/share/gc/shenandoah/heuristics/shenandoahAdaptiveHeuristics.cpp +++ b/src/hotspot/share/gc/shenandoah/heuristics/shenandoahAdaptiveHeuristics.cpp @@ -129,17 +129,11 @@ void ShenandoahAdaptiveHeuristics::initialize() { void ShenandoahAdaptiveHeuristics::post_initialize() { ShenandoahHeuristics::post_initialize(); _free_set = ShenandoahHeap::heap()->free_set(); - if (_is_generational) { - _regulator_thread = ShenandoahGenerationalHeap::heap()->regulator_thread(); - size_t young_available = ShenandoahGenerationalHeap::heap()->young_generation()->max_capacity() - - (ShenandoahGenerationalHeap::heap()->young_generation()->used() + _free_set->reserved()); - recalculate_trigger_threshold(young_available); - } else { - _control_thread = ShenandoahHeap::heap()->control_thread(); - size_t global_available = ShenandoahHeap::heap()->global_generation()->max_capacity() - - (ShenandoahHeap::heap()->global_generation()->used() + _free_set->reserved()); - recalculate_trigger_threshold(global_available); - } + assert(!_is_generational, "ShenandoahGenerationalHeuristics overrides this method"); + _control_thread = ShenandoahHeap::heap()->control_thread(); + size_t global_available = (ShenandoahHeap::heap()->global_generation()->max_capacity() - + (ShenandoahHeap::heap()->global_generation()->used() + _free_set->reserved())); + recalculate_trigger_threshold(global_available); } double ShenandoahAdaptiveHeuristics::get_most_recent_wake_time() const { diff --git a/src/hotspot/share/gc/shenandoah/heuristics/shenandoahAdaptiveHeuristics.hpp b/src/hotspot/share/gc/shenandoah/heuristics/shenandoahAdaptiveHeuristics.hpp index 6e8b50afad7..dd0eaa9e794 100644 --- a/src/hotspot/share/gc/shenandoah/heuristics/shenandoahAdaptiveHeuristics.hpp +++ b/src/hotspot/share/gc/shenandoah/heuristics/shenandoahAdaptiveHeuristics.hpp @@ -190,12 +190,6 @@ public: void adjust_margin_of_error(double amount); void adjust_spike_threshold(double amount); - // _trigger_threshold, represented in words, is the amount of memory that we allow ourselves to allocate while concurrent - // GC is running. If anticipated consumption of mutator memory during GC (e.g. average alloc rate * average GC time) - // exceeds _trigger_threshold, we need to start GC now. Note that we intend NOT to allocate the headroom reserve, - // so this is not included in the _trigger_threshold. - void recalculate_trigger_threshold(size_t mutator_available); - // Returns number of words that can be allocated before we need to trigger next GC. inline size_t allocatable() const { size_t allocated_bytes = _free_set->get_bytes_allocated_since_gc_start(); @@ -267,6 +261,12 @@ protected: double _gc_time_b; // y-intercept double _gc_time_sd; // sd on deviance from prediction + // _trigger_threshold, represented in words, is the amount of memory that we allow ourselves to allocate while concurrent + // GC is running. If anticipated consumption of mutator memory during GC (e.g. average alloc rate * average GC time) + // exceeds _trigger_threshold, we need to start GC now. Note that we intend NOT to allocate the headroom reserve, + // so this is not included in the _trigger_threshold. + void recalculate_trigger_threshold(size_t mutator_available); + void add_gc_time(double timestamp_at_start, double duration); void add_degenerated_gc_time(double timestamp_at_start, double duration); double predict_gc_time(double timestamp_at_start); diff --git a/src/hotspot/share/gc/shenandoah/heuristics/shenandoahGenerationalHeuristics.cpp b/src/hotspot/share/gc/shenandoah/heuristics/shenandoahGenerationalHeuristics.cpp index b14d72f249b..b94634fd088 100644 --- a/src/hotspot/share/gc/shenandoah/heuristics/shenandoahGenerationalHeuristics.cpp +++ b/src/hotspot/share/gc/shenandoah/heuristics/shenandoahGenerationalHeuristics.cpp @@ -31,12 +31,22 @@ #include "gc/shenandoah/shenandoahHeapRegion.inline.hpp" #include "gc/shenandoah/shenandoahOldGeneration.hpp" #include "gc/shenandoah/shenandoahTrace.hpp" +#include "gc/shenandoah/shenandoahYoungGeneration.hpp" #include "logging/log.hpp" ShenandoahGenerationalHeuristics::ShenandoahGenerationalHeuristics(ShenandoahGeneration* generation) : ShenandoahAdaptiveHeuristics(generation), _generation(generation) { } +void ShenandoahGenerationalHeuristics::post_initialize() { + ShenandoahHeuristics::post_initialize(); + _free_set = ShenandoahHeap::heap()->free_set(); + _regulator_thread = ShenandoahGenerationalHeap::heap()->regulator_thread(); + size_t young_available = (ShenandoahGenerationalHeap::heap()->young_generation()->max_capacity() - + (ShenandoahGenerationalHeap::heap()->young_generation()->used() + _free_set->reserved())); + recalculate_trigger_threshold(young_available); +} + void ShenandoahGenerationalHeuristics::choose_collection_set(ShenandoahCollectionSet* collection_set) { assert(collection_set->is_empty(), "Must be empty"); diff --git a/src/hotspot/share/gc/shenandoah/heuristics/shenandoahGenerationalHeuristics.hpp b/src/hotspot/share/gc/shenandoah/heuristics/shenandoahGenerationalHeuristics.hpp index 31c016bb4b7..3382847767c 100644 --- a/src/hotspot/share/gc/shenandoah/heuristics/shenandoahGenerationalHeuristics.hpp +++ b/src/hotspot/share/gc/shenandoah/heuristics/shenandoahGenerationalHeuristics.hpp @@ -45,6 +45,9 @@ public: explicit ShenandoahGenerationalHeuristics(ShenandoahGeneration* generation); void choose_collection_set(ShenandoahCollectionSet* collection_set) override; + + virtual void post_initialize() override; + protected: ShenandoahGeneration* _generation;