Skip to content

Commit

Permalink
Have regulator thread wait until expected condition is met
Browse files Browse the repository at this point in the history
  • Loading branch information
earthling-amzn committed Sep 29, 2023
1 parent a23e366 commit cc29c78
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 7 deletions.
9 changes: 7 additions & 2 deletions src/hotspot/share/gc/shenandoah/shenandoahControlThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -906,20 +906,25 @@ bool ShenandoahControlThread::request_concurrent_gc(ShenandoahGenerationType gen
_requested_generation = generation;
notify_control_thread();
MonitorLocker ml(&_regulator_lock, Mutex::_no_safepoint_check_flag);
ml.wait();
while (_mode == none) {
ml.wait();
}
return true;
}

if (preempt_old_marking(generation)) {
log_info(gc)("Preempting old generation mark to allow %s GC", shenandoah_generation_name(generation));
assert(_mode == servicing_old, "Cannot preempt old if old cycle isn't running.");
_requested_gc_cause = GCCause::_shenandoah_concurrent_gc;
_requested_generation = generation;
_preemption_requested.set();
ShenandoahHeap::heap()->cancel_gc(GCCause::_shenandoah_concurrent_gc);
notify_control_thread();

MonitorLocker ml(&_regulator_lock, Mutex::_no_safepoint_check_flag);
ml.wait();
while (_mode == servicing_old) {
ml.wait();
}
return true;
}

Expand Down
32 changes: 27 additions & 5 deletions src/hotspot/share/gc/shenandoah/shenandoahRegulatorThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void ShenandoahRegulatorThread::regulate_concurrent_cycles() {
ShenandoahControlThread::GCMode mode = _control_thread->gc_mode();
if (mode == ShenandoahControlThread::none) {
if (should_unload_classes()) {
if (_control_thread->request_concurrent_gc(ShenandoahControlThread::select_global_generation())) {
if (request_concurrent_gc(ShenandoahControlThread::select_global_generation())) {
log_info(gc)("Heuristics request for global (unload classes) accepted.");
}
} else {
Expand Down Expand Up @@ -137,19 +137,41 @@ void ShenandoahRegulatorThread::regulator_sleep() {
}

os::naked_short_sleep(_sleep);
if (LogTarget(Info, gc, thread)::is_enabled()) {
double elapsed = os::elapsedTime() - current;
double hiccup = elapsed - double(_sleep);
if (hiccup > 0.0) {
log_info(gc, thread)("Regulator hiccup time: %.3fs", hiccup);
}
}
}

bool ShenandoahRegulatorThread::start_old_cycle() {
return !ShenandoahHeap::heap()->doing_mixed_evacuations() && !ShenandoahHeap::heap()->collection_set()->has_old_regions() &&
_old_heuristics->should_start_gc() && _control_thread->request_concurrent_gc(OLD);
// TODO: These first two checks might be vestigial
return !ShenandoahHeap::heap()->doing_mixed_evacuations()
&& !ShenandoahHeap::heap()->collection_set()->has_old_regions()
&& _old_heuristics->should_start_gc()
&& request_concurrent_gc(OLD);
}

bool ShenandoahRegulatorThread::request_concurrent_gc(ShenandoahGenerationType generation) {
double now = os::elapsedTime();
bool accepted = _control_thread->request_concurrent_gc(generation);
if (LogTarget(Info, gc, thread)::is_enabled() && accepted) {
double wait_time = os::elapsedTime() - now;
if (wait_time > 0) {
log_info(gc, thread)("Regulator waited %.3fs for control thread to acknowledge request.", wait_time);
}
}
return accepted;
}

bool ShenandoahRegulatorThread::start_young_cycle() {
return _young_heuristics->should_start_gc() && _control_thread->request_concurrent_gc(YOUNG);
return _young_heuristics->should_start_gc() && request_concurrent_gc(YOUNG);
}

bool ShenandoahRegulatorThread::start_global_cycle() {
return _global_heuristics->should_start_gc() && _control_thread->request_concurrent_gc(ShenandoahControlThread::select_global_generation());
return _global_heuristics->should_start_gc() && request_concurrent_gc(ShenandoahControlThread::select_global_generation());
}

void ShenandoahRegulatorThread::stop_service() {
Expand Down
2 changes: 2 additions & 0 deletions src/hotspot/share/gc/shenandoah/shenandoahRegulatorThread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ class ShenandoahRegulatorThread: public ConcurrentGCThread {
double _last_sleep_adjust_time;

void regulator_sleep();

bool request_concurrent_gc(ShenandoahGenerationType generation);
};


Expand Down

0 comments on commit cc29c78

Please sign in to comment.