1 /*
  2  * Copyright (c) 2021, Red Hat, Inc. All rights reserved.
  3  * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
  4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  5  *
  6  * This code is free software; you can redistribute it and/or modify it
  7  * under the terms of the GNU General Public License version 2 only, as
  8  * published by the Free Software Foundation.
  9  *
 10  * This code is distributed in the hope that it will be useful, but WITHOUT
 11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 13  * version 2 for more details (a copy is included in the LICENSE file that
 14  * accompanied this code).
 15  *
 16  * You should have received a copy of the GNU General Public License version
 17  * 2 along with this work; if not, write to the Free Software Foundation,
 18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 19  *
 20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 21  * or visit www.oracle.com if you need additional information or have any
 22  * questions.
 23  *
 24  */
 25 
 26 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHCONCURRENTGC_HPP
 27 #define SHARE_GC_SHENANDOAH_SHENANDOAHCONCURRENTGC_HPP
 28 
 29 #include "gc/shared/gcCause.hpp"
 30 #include "gc/shenandoah/shenandoahConcurrentMark.hpp"
 31 #include "gc/shenandoah/shenandoahGC.hpp"
 32 #include "gc/shenandoah/shenandoahHeap.hpp"
 33 
 34 class ShenandoahGeneration;
 35 
 36 class VM_ShenandoahInitMark;
 37 class VM_ShenandoahFinalMarkStartEvac;
 38 class VM_ShenandoahInitUpdateRefs;
 39 class VM_ShenandoahFinalUpdateRefs;
 40 
 41 class ShenandoahConcurrentGC : public ShenandoahGC {
 42   friend class VM_ShenandoahInitMark;
 43   friend class VM_ShenandoahFinalMarkStartEvac;
 44   friend class VM_ShenandoahInitUpdateRefs;
 45   friend class VM_ShenandoahFinalUpdateRefs;
 46   friend class VM_ShenandoahFinalRoots;
 47 
 48 protected:
 49   ShenandoahConcurrentMark    _mark;
 50 
 51 private:
 52   ShenandoahDegenPoint        _degen_point;
 53   bool                        _abbreviated;
 54   const bool                  _do_old_gc_bootstrap;
 55 
 56 protected:
 57   ShenandoahGeneration* const _generation;
 58 
 59 public:
 60   ShenandoahConcurrentGC(ShenandoahGeneration* generation, bool do_old_gc_bootstrap);
 61   bool collect(GCCause::Cause cause);
 62   ShenandoahDegenPoint degen_point() const;
 63   bool abbreviated() const { return _abbreviated; }
 64 
 65 private:
 66   // Entry points to STW GC operations, these cause a related safepoint, that then
 67   // call the entry method below
 68   void vmop_entry_init_mark();
 69 
 70 protected:
 71   void vmop_entry_final_mark();
 72   void vmop_entry_final_roots();
 73 
 74 private:
 75   void vmop_entry_init_updaterefs();
 76   void vmop_entry_final_updaterefs();
 77 
 78   // Entry methods to normally STW GC operations. These set up logging, monitoring
 79   // and workers for net VM operation
 80   void entry_init_mark();
 81   void entry_final_mark();
 82   void entry_init_updaterefs();
 83   void entry_final_updaterefs();
 84   void entry_final_roots();
 85 
 86   // Entry methods to normally concurrent GC operations. These set up logging, monitoring
 87   // for concurrent operation.
 88   void entry_reset();
 89   void entry_mark_roots();
 90   void entry_scan_remembered_set();
 91 
 92 protected:
 93   void entry_mark();
 94   void entry_thread_roots();
 95   void entry_weak_refs();
 96   void entry_weak_roots();
 97   void entry_class_unloading();
 98   void entry_strong_roots();
 99   void entry_cleanup_early();
100 
101 private:
102   void entry_evacuate();
103   void entry_update_thread_roots();
104   void entry_updaterefs();
105   void entry_cleanup_complete();
106 
107   // Actual work for the phases
108   void op_reset();
109   void op_init_mark();
110   void op_mark_roots();
111   void op_mark();
112   void op_thread_roots();
113   void op_weak_refs();
114   void op_weak_roots();
115   void op_class_unloading();
116   void op_strong_roots();
117   void op_cleanup_early();
118   void op_evacuate();
119   void op_init_updaterefs();
120   void op_updaterefs();
121   void op_update_thread_roots();
122   void op_final_updaterefs();
123   void op_final_roots();
124   void op_cleanup_complete();
125 
126 protected:
127   virtual void op_final_mark();
128 
129 private:
130   void start_mark();
131 
132   // Messages for GC trace events, they have to be immortal for
133   // passing around the logging/tracing systems
134   const char* init_mark_event_message() const;
135   const char* final_mark_event_message() const;
136   const char* conc_mark_event_message() const;
137 
138 protected:
139   // Check GC cancellation and abort concurrent GC
140   bool check_cancellation_and_abort(ShenandoahDegenPoint point);
141 };
142 
143 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHCONCURRENTGC_HPP