move some post_initialize() work into subclass ShenandoahGenerationalHeuristics

This commit is contained in:
Kelvin Nilsen 2026-01-14 21:55:04 +00:00
parent e772e4b84d
commit ea38ec153a
4 changed files with 24 additions and 17 deletions

View File

@ -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 {

View File

@ -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);

View File

@ -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");

View File

@ -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;