1 /*
  2  * Copyright (c) 2021, Red Hat, Inc. 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_SHENANDOAH_SHENANDOAHCONCURRENTGC_HPP
 26 #define SHARE_GC_SHENANDOAH_SHENANDOAHCONCURRENTGC_HPP
 27 
 28 #include "gc/shared/gcCause.hpp"
 29 #include "gc/shenandoah/shenandoahConcurrentMark.hpp"
 30 #include "gc/shenandoah/shenandoahGC.hpp"
 31 #include "gc/shenandoah/shenandoahHeap.hpp"
 32 
 33 class ShenandoahGeneration;
 34 
 35 class VM_ShenandoahInitMark;
 36 class VM_ShenandoahFinalMarkStartEvac;
 37 class VM_ShenandoahInitUpdateRefs;
 38 class VM_ShenandoahFinalUpdateRefs;
 39 
 40 class ShenandoahConcurrentGC : public ShenandoahGC {
 41   friend class VM_ShenandoahInitMark;
 42   friend class VM_ShenandoahFinalMarkStartEvac;
 43   friend class VM_ShenandoahInitUpdateRefs;
 44   friend class VM_ShenandoahFinalUpdateRefs;
 45   friend class VM_ShenandoahFinalRoots;
 46 
 47 protected:
 48   ShenandoahConcurrentMark    _mark;
 49 
 50 private:
 51   ShenandoahDegenPoint        _degen_point;
 52   bool                        _mixed_evac; // true iff most recent evacuation includes old-gen HeapRegions
 53   const bool                  _do_old_gc_bootstrap;
 54 
 55 protected:
 56   ShenandoahGeneration* const _generation;
 57 
 58 public:
 59   ShenandoahConcurrentGC(ShenandoahGeneration* generation, bool do_old_gc_bootstrap);
 60   bool collect(GCCause::Cause cause);
 61   ShenandoahDegenPoint degen_point() const;
 62 
 63 private:
 64   // Entry points to STW GC operations, these cause a related safepoint, that then
 65   // call the entry method below
 66   void vmop_entry_init_mark();
 67 
 68 protected:
 69   void vmop_entry_final_mark();
 70   void vmop_entry_final_roots();
 71 
 72 private:
 73   void vmop_entry_init_updaterefs();
 74   void vmop_entry_final_updaterefs();
 75 
 76   // Entry methods to normally STW GC operations. These set up logging, monitoring
 77   // and workers for net VM operation
 78   void entry_init_mark();
 79   void entry_final_mark();
 80   void entry_init_updaterefs();
 81   void entry_final_updaterefs();
 82   void entry_final_roots();
 83 
 84   // Entry methods to normally concurrent GC operations. These set up logging, monitoring
 85   // for concurrent operation.
 86   void entry_reset();
 87   void entry_mark_roots();
 88 
 89 protected:
 90   void entry_mark();
 91   void entry_thread_roots();
 92   void entry_weak_refs();
 93   void entry_weak_roots();
 94   void entry_class_unloading();
 95   void entry_strong_roots();
 96   void entry_cleanup_early();
 97   virtual void op_final_mark();
 98 
 99 private:
100   void entry_evacuate();
101   void entry_update_thread_roots();
102   void entry_updaterefs();
103   void entry_cleanup_complete();
104   void entry_global_coalesce_and_fill();
105 
106   // Actual work for the phases
107   void op_reset();
108   void op_init_mark();
109   void op_mark_roots();
110   void op_mark();
111   void op_thread_roots();
112   void op_weak_refs();
113   void op_weak_roots();
114   void op_class_unloading();
115   void op_strong_roots();
116   void op_cleanup_early();
117   void op_evacuate();
118   void op_init_updaterefs();
119   void op_updaterefs();
120   void op_update_thread_roots();
121   void op_final_updaterefs();
122   void op_final_roots();
123   void op_cleanup_complete();
124   void op_global_coalesce_and_fill();
125 
126   // Messages for GC trace events, they have to be immortal for
127   // passing around the logging/tracing systems
128   void init_mark_event_message(char* buf, size_t len) const;
129   void final_mark_event_message(char* buf, size_t len) const;
130   void conc_mark_event_message(char* buf, size_t len) const;
131 
132 protected:
133   // Check GC cancellation and abort concurrent GC
134   bool check_cancellation_and_abort(ShenandoahDegenPoint point);
135 };
136 
137 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHCONCURRENTGC_HPP