1 /*
2 * Copyright (c) 2001, 2026, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_GC_G1_G1CONCURRENTMARKTHREAD_INLINE_HPP
26 #define SHARE_GC_G1_G1CONCURRENTMARKTHREAD_INLINE_HPP
27
28 #include "gc/g1/g1ConcurrentMarkThread.hpp"
29
30 #include "gc/g1/g1ConcurrentMark.hpp"
31 #include "runtime/os.hpp"
32
33 // Total virtual time so far.
34 inline double G1ConcurrentMarkThread::total_mark_cpu_time_s() {
35 return static_cast<double>(os::thread_cpu_time(this)) / NANOSECS_PER_SEC + worker_threads_cpu_time_s();
36 }
37
38 // Marking virtual time so far
39 inline double G1ConcurrentMarkThread::worker_threads_cpu_time_s() {
40 return _cm->worker_threads_cpu_time_s();
41 }
42
43 inline bool G1ConcurrentMarkThread::is_in_full_concurrent_cycle() const {
44 ServiceState st = state();
45 return (st == FullCycleMarking || st == FullCycleRebuildOrScrub || st == FullCycleResetForNextCycle);
46 }
47
48 inline void G1ConcurrentMarkThread::set_idle() {
49 // Concurrent cycle may be aborted any time.
50 assert(!is_idle(), "must not be idle");
51 _state.store_relaxed(Idle);
52 }
53
54 inline void G1ConcurrentMarkThread::start_full_cycle() {
55 assert(SafepointSynchronize::is_at_safepoint(), "must be");
56 assert(is_idle(), "cycle in progress");
57 _state.store_relaxed(FullCycleMarking);
58 }
59
60 inline void G1ConcurrentMarkThread::start_undo_cycle() {
61 assert(SafepointSynchronize::is_at_safepoint(), "must be");
62 assert(is_idle(), "cycle in progress");
63 _state.store_relaxed(UndoCycleResetForNextCycle);
64 }
65
66 inline void G1ConcurrentMarkThread::set_full_cycle_rebuild_and_scrub() {
67 assert(SafepointSynchronize::is_at_safepoint(), "must be");
68 assert(state() == FullCycleMarking, "must be");
69 _state.store_relaxed(FullCycleRebuildOrScrub);
70 }
71
72 inline void G1ConcurrentMarkThread::set_full_cycle_reset_for_next_cycle() {
73 assert(SafepointSynchronize::is_at_safepoint(), "must be");
74 assert(state() == FullCycleRebuildOrScrub, "must be");
75 _state.store_relaxed(FullCycleResetForNextCycle);
76 }
77
78 inline bool G1ConcurrentMarkThread::is_in_marking() const {
79 return state() == FullCycleMarking;
80 }
81
82 inline bool G1ConcurrentMarkThread::is_in_marking_or_rebuild() const {
83 ServiceState st = state();
84 return st == FullCycleMarking || st == FullCycleRebuildOrScrub;
85 }
86
87 inline bool G1ConcurrentMarkThread::is_in_reset_for_next_cycle() const {
88 ServiceState st = state();
89 return st == FullCycleResetForNextCycle || st == UndoCycleResetForNextCycle;
90 }
91
92 inline bool G1ConcurrentMarkThread::is_idle() const {
93 return state() == Idle;
94 }
95
96 inline bool G1ConcurrentMarkThread::is_in_progress() const {
97 return !is_idle();
98 }
99
100 inline bool G1ConcurrentMarkThread::is_in_undo_cycle() const {
101 return state() == UndoCycleResetForNextCycle;
102 }
103
104 #endif // SHARE_GC_G1_G1CONCURRENTMARKTHREAD_INLINE_HPP