Skip to content

Commit

Permalink
8275051: Shenandoah: Correct ordering of requested gc cause and gc re…
Browse files Browse the repository at this point in the history
…quest flag

Reviewed-by: shade
  • Loading branch information
zhengyu123 committed Oct 12, 2021
1 parent b460d6d commit 1ab6414
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/hotspot/share/gc/shenandoah/shenandoahControlThread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ void ShenandoahControlThread::run_service() {
while (!in_graceful_shutdown() && !should_terminate()) {
// Figure out if we have pending requests.
bool alloc_failure_pending = _alloc_failure_gc.is_set();
bool explicit_gc_requested = _gc_requested.is_set() && is_explicit_gc(_requested_gc_cause);
bool implicit_gc_requested = _gc_requested.is_set() && !is_explicit_gc(_requested_gc_cause);
bool is_gc_requested = _gc_requested.is_set();
GCCause::Cause requested_gc_cause = _requested_gc_cause;
bool explicit_gc_requested = is_gc_requested && is_explicit_gc(requested_gc_cause);
bool implicit_gc_requested = is_gc_requested && !is_explicit_gc(requested_gc_cause);

// This control loop iteration have seen this much allocations.
size_t allocs_seen = Atomic::xchg(&_allocs_seen, (size_t)0, memory_order_relaxed);
Expand Down Expand Up @@ -132,7 +134,7 @@ void ShenandoahControlThread::run_service() {
}

} else if (explicit_gc_requested) {
cause = _requested_gc_cause;
cause = requested_gc_cause;
log_info(gc)("Trigger: Explicit GC request (%s)", GCCause::to_string(cause));

heuristics->record_requested_gc();
Expand All @@ -147,7 +149,7 @@ void ShenandoahControlThread::run_service() {
mode = stw_full;
}
} else if (implicit_gc_requested) {
cause = _requested_gc_cause;
cause = requested_gc_cause;
log_info(gc)("Trigger: Implicit GC request (%s)", GCCause::to_string(cause));

heuristics->record_requested_gc();
Expand Down Expand Up @@ -505,8 +507,11 @@ void ShenandoahControlThread::handle_requested_gc(GCCause::Cause cause) {
size_t current_gc_id = get_gc_id();
size_t required_gc_id = current_gc_id + 1;
while (current_gc_id < required_gc_id) {
_gc_requested.set();
// Although setting gc request is under _gc_waiters_lock, but read side (run_service())
// does not take the lock. We need to enforce following order, so that read side sees
// latest requested gc cause when the flag is set.
_requested_gc_cause = cause;
_gc_requested.set();

if (cause != GCCause::_wb_breakpoint) {
ml.wait();
Expand Down

1 comment on commit 1ab6414

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.