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   const char*  _message;
 84 
 85 protected:
 86   VM_G1PauseConcurrent(const char* message) :
 87     _gc_id(GCId::current()), _message(message) { }
 88   virtual void work() = 0;
 89 
 90   // Does this concurrent pause affect the memory pools? If so, update the collectionUsage()
 91   // MemoryMXBean for the old gen memory pool (which is the only pool registered for concurrent
 92   // pauses).
 93   virtual bool affects_memory_pools() const = 0;
 94 public:
 95   bool doit_prologue() override;
 96   void doit_epilogue() override;
 97   void doit() override;
 98   bool is_gc_operation() const override { return true; }
 99 };
100 
101 class VM_G1PauseRemark : public VM_G1PauseConcurrent {
102   bool affects_memory_pools() const override { return true; }
103 
104 public:
105   VM_G1PauseRemark() : VM_G1PauseConcurrent("Pause Remark") { }
106   VMOp_Type type() const override { return VMOp_G1PauseRemark; }
107   void work() override;
108 };
109 
110 class VM_G1PauseCleanup : public VM_G1PauseConcurrent {
111   bool affects_memory_pools() const override { return false; }
112 
113 public:
114   VM_G1PauseCleanup() : VM_G1PauseConcurrent("Pause Cleanup") { }
115   VMOp_Type type() const override { return VMOp_G1PauseCleanup; }
116   void work() override;
117 };
118 
119 #endif // SHARE_GC_G1_G1VMOPERATIONS_HPP