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_G1VMOPERATIONS_HPP
26 #define SHARE_GC_G1_G1VMOPERATIONS_HPP
27
28 #include "gc/shared/gcId.hpp"
29 #include "gc/shared/gcVMOperations.hpp"
30
31 // VM_operations for the G1 collector.
32
33 class VM_G1CollectFull : public VM_GC_Collect_Operation {
34 protected:
35 bool skip_operation() const override;
36
37 public:
38 VM_G1CollectFull(uint gc_count_before,
39 uint full_gc_count_before,
40 GCCause::Cause cause) :
41 VM_GC_Collect_Operation(gc_count_before, cause, full_gc_count_before, true) { }
42 VMOp_Type type() const override { return VMOp_G1CollectFull; }
43 void doit() override;
44 };
45
46 class VM_G1TryInitiateConcMark : public VM_GC_Collect_Operation {
47 size_t _word_size;
48 bool _transient_failure;
49 bool _mark_in_progress;
50 bool _cycle_already_in_progress;
51 bool _whitebox_attached;
52 // The concurrent start pause may be cancelled for some reasons. Keep track of
53 // this.
54 bool _gc_succeeded;
55
56 public:
57 VM_G1TryInitiateConcMark(size_t word_size,
58 uint gc_count_before,
59 GCCause::Cause gc_cause);
60 virtual VMOp_Type type() const { return VMOp_G1TryInitiateConcMark; }
61 virtual bool doit_prologue();
62 virtual void doit();
63 bool transient_failure() const { return _transient_failure; }
64 bool mark_in_progress() const { return _mark_in_progress; }
65 bool cycle_already_in_progress() const { return _cycle_already_in_progress; }
66 bool whitebox_attached() const { return _whitebox_attached; }
67 bool gc_succeeded() const { return _gc_succeeded && VM_GC_Operation::gc_succeeded(); }
68 };
69
70 class VM_G1CollectForAllocation : public VM_CollectForAllocation {
71
72 public:
73 VM_G1CollectForAllocation(size_t word_size,
74 uint gc_count_before,
75 GCCause::Cause gc_cause);
76 virtual VMOp_Type type() const { return VMOp_G1CollectForAllocation; }
77 virtual void doit();
78 };
79
80 // Concurrent G1 stop-the-world operations such as remark and cleanup.
81 class VM_G1PauseConcurrent : public VM_Operation {
82 uint _gc_id;
83 bool _is_shutting_down;
84 const char* _message;
85
86 protected:
87 VM_G1PauseConcurrent(const char* message) :
88 _gc_id(GCId::current()), _is_shutting_down(false), _message(message) { }
89 virtual void work() = 0;
90
91 // Does this concurrent pause affect the memory pools? If so, update the collectionUsage()
92 // MemoryMXBean for the old gen memory pool (which is the only pool registered for concurrent
93 // pauses).
94 virtual bool affects_memory_pools() const = 0;
95 public:
96 bool doit_prologue() override;
97 void doit_epilogue() override;
98 void doit() override;
99 bool is_gc_operation() const override { return true; }
100 };
101
102 class VM_G1PauseRemark : public VM_G1PauseConcurrent {
103 bool affects_memory_pools() const override { return true; }
104
105 public:
106 VM_G1PauseRemark() : VM_G1PauseConcurrent("Pause Remark") { }
107 VMOp_Type type() const override { return VMOp_G1PauseRemark; }
108 void work() override;
109 };
110
111 class VM_G1PauseCleanup : public VM_G1PauseConcurrent {
112 bool affects_memory_pools() const override { return false; }
113
114 public:
115 VM_G1PauseCleanup() : VM_G1PauseConcurrent("Pause Cleanup") { }
116 VMOp_Type type() const override { return VMOp_G1PauseCleanup; }
117 void work() override;
118 };
119
120 class VM_G1StopMarking : public VM_Operation {
121 public:
122 VM_G1StopMarking() : VM_Operation() { }
123 VMOp_Type type() const override { return VMOp_G1StopMarking; }
124
125 bool doit_prologue() override;
126 void doit() override;
127
128 bool is_gc_operation() const override { return true; }
129 };
130
131 #endif // SHARE_GC_G1_G1VMOPERATIONS_HPP