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: phh
Backport-of: 1ab64143c06e33e23172dd77c39e434443347364
  • Loading branch information
zhengyu123 committed Oct 20, 2021
1 parent 4b6e487 commit 1297c26
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/hotspot/share/gc/shenandoah/shenandoahControlThread.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2013, 2020, Red Hat, Inc. All rights reserved.
* Copyright (c) 2013, 2021, Red Hat, Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
Expand Down Expand Up @@ -89,8 +90,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<size_t>(0, &_allocs_seen, memory_order_relaxed);
Expand Down Expand Up @@ -124,7 +127,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 @@ -140,7 +143,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 @@ -536,8 +539,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();
ml.wait();
current_gc_id = get_gc_id();
}
Expand Down

1 comment on commit 1297c26

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