Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/g1/g1CollectedHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "gc/g1/g1CollectedHeap.inline.hpp"
#include "gc/g1/g1CollectionSet.hpp"
#include "gc/g1/g1CollectionSetCandidates.hpp"
#include "gc/g1/g1CollectorState.hpp"
#include "gc/g1/g1CollectorState.inline.hpp"
#include "gc/g1/g1ConcurrentMarkThread.inline.hpp"
#include "gc/g1/g1ConcurrentRefine.hpp"
#include "gc/g1/g1ConcurrentRefineThread.hpp"
Expand Down
1 change: 0 additions & 1 deletion src/hotspot/share/gc/g1/g1CollectedHeap.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "gc/g1/g1CollectedHeap.hpp"

#include "gc/g1/g1BarrierSet.hpp"
#include "gc/g1/g1CollectorState.hpp"
#include "gc/g1/g1ConcurrentMark.inline.hpp"
#include "gc/g1/g1EvacFailureRegions.hpp"
#include "gc/g1/g1EvacStats.inline.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/g1/g1CollectionSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
#include "gc/g1/g1CollectedHeap.inline.hpp"
#include "gc/g1/g1CollectionSet.inline.hpp"
#include "gc/g1/g1CollectionSetCandidates.inline.hpp"
#include "gc/g1/g1CollectorState.hpp"
#include "gc/g1/g1CollectorState.inline.hpp"
#include "gc/g1/g1HeapRegion.inline.hpp"
#include "gc/g1/g1HeapRegionRemSet.inline.hpp"
#include "gc/g1/g1HeapRegionSet.hpp"
Expand Down
36 changes: 13 additions & 23 deletions src/hotspot/share/gc/g1/g1CollectorState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,42 +22,32 @@
*
*/

#include "gc/g1/g1CollectedHeap.inline.hpp"
#include "gc/g1/g1CollectorState.hpp"
#include "gc/g1/g1ConcurrentMarkThread.inline.hpp"
#include "gc/g1/g1CollectorState.inline.hpp"
#include "runtime/safepoint.hpp"
#include "utilities/debug.hpp"

G1CollectorState::Pause G1CollectorState::gc_pause_type(bool concurrent_operation_is_full_mark) const {
assert(SafepointSynchronize::is_at_safepoint(), "must be");
switch (_phase) {
case Phase::YoungNormal: return Pause::Normal;
case Phase::YoungPrepareMixed: return Pause::PrepareMixed;
case Phase::YoungConcurrentStart:
return concurrent_operation_is_full_mark ? Pause::ConcurrentStartFull :
Pause::ConcurrentStartUndo;
case Phase::YoungPrepareMixed: return Pause::PrepareMixed;
case Phase::Mixed: return Pause::Mixed;
case Phase::FullGC: return Pause::Full;
default: ShouldNotReachHere();
}
}

bool G1CollectorState::is_in_concurrent_cycle() const {
G1ConcurrentMark* cm = G1CollectedHeap::heap()->concurrent_mark();
return cm->is_in_concurrent_cycle();
const char* G1CollectorState::to_string(Pause type) {
static const char* pause_strings[] = { "Normal",
"Concurrent Start", // Do not distinguish between the different
"Concurrent Start", // Concurrent Start pauses.
"Prepare Mixed",
"Cleanup",
"Remark",
"Mixed",
"Full" };
return pause_strings[static_cast<uint>(type)];
}

bool G1CollectorState::is_in_marking() const {
G1ConcurrentMark* cm = G1CollectedHeap::heap()->concurrent_mark();
return cm->is_in_marking();
}

bool G1CollectorState::is_in_mark_or_rebuild() const {
G1ConcurrentMark* cm = G1CollectedHeap::heap()->concurrent_mark();
return is_in_marking() || cm->is_in_rebuild_or_scrub();
}

bool G1CollectorState::is_in_reset_for_next_cycle() const {
G1ConcurrentMark* cm = G1CollectedHeap::heap()->concurrent_mark();
return cm->is_in_reset_for_next_cycle();
}

80 changes: 23 additions & 57 deletions src/hotspot/share/gc/g1/g1CollectorState.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,26 +67,25 @@ class G1CollectorState {
_initiate_conc_mark_if_possible(false) { }

// Phase setters
void set_in_normal_young_gc() { _phase = Phase::YoungNormal; }
void set_in_space_reclamation_phase() { _phase = Phase::Mixed; }
void set_in_full_gc() { _phase = Phase::FullGC; }
inline void set_in_normal_young_gc();
inline void set_in_space_reclamation_phase();
inline void set_in_full_gc();

// Pause setters
void set_in_concurrent_start_gc() { _phase = Phase::YoungConcurrentStart; _initiate_conc_mark_if_possible = false; }
void set_in_prepare_mixed_gc() { _phase = Phase::YoungPrepareMixed; }
inline void set_in_concurrent_start_gc();
inline void set_in_prepare_mixed_gc();

void set_initiate_conc_mark_if_possible(bool v) { _initiate_conc_mark_if_possible = v; }
inline void set_initiate_conc_mark_if_possible(bool v);

// Phase getters
bool is_in_young_only_phase() const { return _phase == Phase::YoungNormal || _phase == Phase::YoungConcurrentStart || _phase == Phase::YoungPrepareMixed; }
bool is_in_mixed_phase() const { return _phase == Phase::Mixed; }
inline bool is_in_young_only_phase() const;
inline bool is_in_mixed_phase() const;

// Specific pauses
bool is_in_concurrent_start_gc() const { return _phase == Phase::YoungConcurrentStart; }
bool is_in_prepare_mixed_gc() const { return _phase == Phase::YoungPrepareMixed; }
bool is_in_full_gc() const { return _phase == Phase::FullGC; }
inline bool is_in_concurrent_start_gc() const;
inline bool is_in_prepare_mixed_gc() const;
inline bool is_in_full_gc() const;

bool initiate_conc_mark_if_possible() const { return _initiate_conc_mark_if_possible; }
inline bool initiate_conc_mark_if_possible() const;

bool is_in_concurrent_cycle() const;
bool is_in_marking() const;
Expand All @@ -107,50 +106,17 @@ class G1CollectorState {
// Calculate GC Pause Type from internal state.
Pause gc_pause_type(bool concurrent_operation_is_full_mark) const;

static const char* to_string(Pause type) {
static const char* pause_strings[] = { "Normal",
"Concurrent Start", // Do not distinguish between the different
"Concurrent Start", // Concurrent Start pauses.
"Prepare Mixed",
"Cleanup",
"Remark",
"Mixed",
"Full" };
return pause_strings[static_cast<uint>(type)];
}

static void assert_is_young_pause(Pause type) {
assert(type != Pause::Full, "must be");
assert(type != Pause::Remark, "must be");
assert(type != Pause::Cleanup, "must be");
}

static bool is_young_only_pause(Pause type) {
assert_is_young_pause(type);
return type == Pause::ConcurrentStartUndo ||
type == Pause::ConcurrentStartFull ||
type == Pause::PrepareMixed ||
type == Pause::Normal;
}

static bool is_mixed_pause(Pause type) {
assert_is_young_pause(type);
return type == Pause::Mixed;
}

static bool is_prepare_mixed_pause(Pause type) {
assert_is_young_pause(type);
return type == Pause::PrepareMixed;
}

static bool is_concurrent_start_pause(Pause type) {
assert_is_young_pause(type);
return type == Pause::ConcurrentStartFull || type == Pause::ConcurrentStartUndo;
}

static bool is_concurrent_cycle_pause(Pause type) {
return type == Pause::Cleanup || type == Pause::Remark;
}
static const char* to_string(Pause type);

// Pause kind queries
inline static void assert_is_young_pause(Pause type);

inline static bool is_young_only_pause(Pause type);
inline static bool is_concurrent_start_pause(Pause type);
inline static bool is_prepare_mixed_pause(Pause type);
inline static bool is_mixed_pause(Pause type);

inline static bool is_concurrent_cycle_pause(Pause type);
};

ENUMERATOR_RANGE(G1CollectorState::Pause, G1CollectorState::Pause::Normal, G1CollectorState::Pause::Full)
Expand Down
128 changes: 128 additions & 0 deletions src/hotspot/share/gc/g1/g1CollectorState.inline.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Copyright (c) 2026, Oracle and/or its affiliates. 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
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/

#ifndef SHARE_GC_G1_G1COLLECTORSTATE_INLINE_HPP
#define SHARE_GC_G1_G1COLLECTORSTATE_INLINE_HPP

#include "gc/g1/g1CollectorState.hpp"

#include "gc/g1/g1CollectedHeap.hpp"
#include "gc/g1/g1ConcurrentMark.inline.hpp"

inline void G1CollectorState::set_in_normal_young_gc() {
_phase = Phase::YoungNormal;
}
inline void G1CollectorState::set_in_space_reclamation_phase() {
_phase = Phase::Mixed;
}
inline void G1CollectorState::set_in_full_gc() {
_phase = Phase::FullGC;
}

inline void G1CollectorState::set_in_concurrent_start_gc() {
_phase = Phase::YoungConcurrentStart;
_initiate_conc_mark_if_possible = false;
}
inline void G1CollectorState::set_in_prepare_mixed_gc() {
_phase = Phase::YoungPrepareMixed;
}

inline void G1CollectorState::set_initiate_conc_mark_if_possible(bool v) {
_initiate_conc_mark_if_possible = v;
}

inline bool G1CollectorState::is_in_young_only_phase() const {
return _phase == Phase::YoungNormal ||
_phase == Phase::YoungConcurrentStart ||
_phase == Phase::YoungPrepareMixed;
}
inline bool G1CollectorState::is_in_mixed_phase() const {
return _phase == Phase::Mixed;
}

inline bool G1CollectorState::is_in_prepare_mixed_gc() const {
return _phase == Phase::YoungPrepareMixed;
}
inline bool G1CollectorState::is_in_full_gc() const {
return _phase == Phase::FullGC;
}
inline bool G1CollectorState::is_in_concurrent_start_gc() const {
return _phase == Phase::YoungConcurrentStart;
}

inline bool G1CollectorState::initiate_conc_mark_if_possible() const {
return _initiate_conc_mark_if_possible;
}

inline bool G1CollectorState::is_in_concurrent_cycle() const {
G1ConcurrentMark* cm = G1CollectedHeap::heap()->concurrent_mark();
return cm->is_in_concurrent_cycle();
}
inline bool G1CollectorState::is_in_marking() const {
G1ConcurrentMark* cm = G1CollectedHeap::heap()->concurrent_mark();
return cm->is_in_marking();
}
inline bool G1CollectorState::is_in_mark_or_rebuild() const {
G1ConcurrentMark* cm = G1CollectedHeap::heap()->concurrent_mark();
return is_in_marking() || cm->is_in_rebuild_or_scrub();
}
inline bool G1CollectorState::is_in_reset_for_next_cycle() const {
G1ConcurrentMark* cm = G1CollectedHeap::heap()->concurrent_mark();
return cm->is_in_reset_for_next_cycle();
}

inline void G1CollectorState::assert_is_young_pause(Pause type) {
assert(type != Pause::Full, "must be");
assert(type != Pause::Remark, "must be");
assert(type != Pause::Cleanup, "must be");
Comment on lines +96 to +98
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think positive assertion here is easier to read.

}

inline bool G1CollectorState::is_young_only_pause(Pause type) {
assert_is_young_pause(type);
return type == Pause::ConcurrentStartUndo ||
type == Pause::ConcurrentStartFull ||
type == Pause::PrepareMixed ||
type == Pause::Normal;
}

inline bool G1CollectorState::is_mixed_pause(Pause type) {
assert_is_young_pause(type);
return type == Pause::Mixed;
}

inline bool G1CollectorState::is_prepare_mixed_pause(Pause type) {
assert_is_young_pause(type);
return type == Pause::PrepareMixed;
}

inline bool G1CollectorState::is_concurrent_start_pause(Pause type) {
assert_is_young_pause(type);
return type == Pause::ConcurrentStartFull || type == Pause::ConcurrentStartUndo;
}

inline bool G1CollectorState::is_concurrent_cycle_pause(Pause type) {
return type == Pause::Cleanup || type == Pause::Remark;
}

#endif // SHARE_GC_G1_G1COLLECTORSTATE_INLINE_HPP
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/g1/g1ConcurrentMark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include "gc/g1/g1CardSetMemory.hpp"
#include "gc/g1/g1CardTableClaimTable.inline.hpp"
#include "gc/g1/g1CollectedHeap.inline.hpp"
#include "gc/g1/g1CollectorState.hpp"
#include "gc/g1/g1CollectorState.inline.hpp"
#include "gc/g1/g1ConcurrentMark.inline.hpp"
#include "gc/g1/g1ConcurrentMarkRemarkTasks.hpp"
#include "gc/g1/g1ConcurrentMarkThread.inline.hpp"
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/share/gc/g1/g1FullGCCompactTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
*/

#include "gc/g1/g1CollectedHeap.hpp"
#include "gc/g1/g1CollectedHeap.inline.hpp"
#include "gc/g1/g1ConcurrentMarkBitMap.inline.hpp"
#include "gc/g1/g1FullCollector.inline.hpp"
#include "gc/g1/g1FullGCCompactionPoint.hpp"
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/gc/g1/g1HeapVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include "code/nmethod.hpp"
#include "gc/g1/g1Allocator.inline.hpp"
#include "gc/g1/g1CollectedHeap.inline.hpp"
#include "gc/g1/g1CollectorState.inline.hpp"
#include "gc/g1/g1ConcurrentMarkThread.hpp"
#include "gc/g1/g1HeapRegion.inline.hpp"
#include "gc/g1/g1HeapRegionRemSet.hpp"
Expand Down
1 change: 1 addition & 0 deletions src/hotspot/share/gc/g1/g1PeriodicGCTask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

#include "gc/g1/g1CollectedHeap.inline.hpp"
#include "gc/g1/g1CollectorState.inline.hpp"
#include "gc/g1/g1ConcurrentMark.inline.hpp"
#include "gc/g1/g1ConcurrentMarkThread.inline.hpp"
#include "gc/g1/g1GCCounters.hpp"
Expand Down
12 changes: 12 additions & 0 deletions src/hotspot/share/gc/g1/g1Policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "gc/g1/g1CollectedHeap.inline.hpp"
#include "gc/g1/g1CollectionSet.hpp"
#include "gc/g1/g1CollectionSetCandidates.inline.hpp"
#include "gc/g1/g1CollectorState.inline.hpp"
#include "gc/g1/g1ConcurrentMark.hpp"
#include "gc/g1/g1ConcurrentMarkThread.inline.hpp"
#include "gc/g1/g1ConcurrentRefine.hpp"
Expand Down Expand Up @@ -1133,6 +1134,17 @@ double G1Policy::predict_eden_copy_time_ms(uint count, size_t* bytes_to_copy) co
return _analytics->predict_object_copy_time_ms(expected_bytes, collector_state()->is_in_young_only_phase());
}

bool G1Policy::should_update_surv_rate_group_predictors() {
return collector_state()->is_in_young_only_phase() && !collector_state()->is_in_mark_or_rebuild();
}

void G1Policy::cset_regions_freed() {
bool update = should_update_surv_rate_group_predictors();

_eden_surv_rate_group->all_surviving_words_recorded(predictor(), update);
_survivor_surv_rate_group->all_surviving_words_recorded(predictor(), update);
}

double G1Policy::predict_region_copy_time_ms(G1HeapRegion* hr, bool for_young_only_phase) const {
size_t const bytes_to_copy = predict_bytes_to_copy(hr);
return _analytics->predict_object_copy_time_ms(bytes_to_copy, for_young_only_phase);
Expand Down
11 changes: 2 additions & 9 deletions src/hotspot/share/gc/g1/g1Policy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ class G1Policy: public CHeapObj<mtGC> {

G1ConcurrentStartToMixedTimeTracker _concurrent_start_to_mixed;

bool should_update_surv_rate_group_predictors() {
return collector_state()->is_in_young_only_phase() && !collector_state()->is_in_mark_or_rebuild();
}
bool should_update_surv_rate_group_predictors();

double pending_cards_processing_time() const;
public:
Expand Down Expand Up @@ -160,12 +158,7 @@ class G1Policy: public CHeapObj<mtGC> {
// bytes_to_copy is non-null.
double predict_eden_copy_time_ms(uint count, size_t* bytes_to_copy = nullptr) const;

void cset_regions_freed() {
bool update = should_update_surv_rate_group_predictors();

_eden_surv_rate_group->all_surviving_words_recorded(predictor(), update);
_survivor_surv_rate_group->all_surviving_words_recorded(predictor(), update);
}
void cset_regions_freed();

G1MMUTracker* mmu_tracker() {
return _mmu_tracker;
Expand Down
Loading