1 /*
   2  * Copyright (c) 2015, 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_VM_GC_G1_G1COLLECTORSTATE_HPP
  26 #define SHARE_VM_GC_G1_G1COLLECTORSTATE_HPP
  27 
  28 #include "utilities/globalDefinitions.hpp"
  29 #include "gc/g1/g1YCTypes.hpp"
  30 
  31 // Various state variables that indicate
  32 // the phase of the G1 collection.
  33 class G1CollectorState VALUE_OBJ_CLASS_SPEC {
  34   // Indicates whether we are in "full young" or "mixed" GC mode.
  35   bool _gcs_are_young;
  36   // Was the last GC "young"?
  37   bool _last_gc_was_young;
  38   // Is this the "last young GC" before we start doing mixed GCs?
  39   // Set after a concurrent mark has completed.
  40   bool _last_young_gc;
  41 
  42   // If initiate_conc_mark_if_possible() is set at the beginning of a
  43   // pause, it is a suggestion that the pause should start a marking
  44   // cycle by doing the initial-mark work. However, it is possible
  45   // that the concurrent marking thread is still finishing up the
  46   // previous marking cycle (e.g., clearing the next marking
  47   // bitmap). If that is the case we cannot start a new cycle and
  48   // we'll have to wait for the concurrent marking thread to finish
  49   // what it is doing. In this case we will postpone the marking cycle
  50   // initiation decision for the next pause. When we eventually decide
  51   // to start a cycle, we will set _during_initial_mark_pause which
  52   // will stay true until the end of the initial-mark pause and it's
  53   // the condition that indicates that a pause is doing the
  54   // initial-mark work.
  55   volatile bool _during_initial_mark_pause;
  56 
  57   // At the end of a pause we check the heap occupancy and we decide
  58   // whether we will start a marking cycle during the next pause. If
  59   // we decide that we want to do that, we will set this parameter to
  60   // true. So, this parameter will stay true between the end of a
  61   // pause and the beginning of a subsequent pause (not necessarily
  62   // the next one, see the comments on the next field) when we decide
  63   // that we will indeed start a marking cycle and do the initial-mark
  64   // work.
  65   volatile bool _initiate_conc_mark_if_possible;
  66 
  67   // NOTE: if some of these are synonyms for others,
  68   // the redundant fields should be eliminated. XXX
  69   bool _during_marking;
  70   bool _mark_in_progress;
  71   bool _in_marking_window;
  72   bool _in_marking_window_im;
  73 
  74   bool _concurrent_cycle_started;
  75   bool _full_collection;
  76 
  77   public:
  78     G1CollectorState() :
  79       _gcs_are_young(true),
  80       _last_gc_was_young(false),
  81       _last_young_gc(false),
  82 
  83       _during_initial_mark_pause(false),
  84       _initiate_conc_mark_if_possible(false),
  85 
  86       _during_marking(false),
  87       _mark_in_progress(false),
  88       _in_marking_window(false),
  89       _in_marking_window_im(false),
  90       _concurrent_cycle_started(false),
  91       _full_collection(false) {}
  92 
  93   // Setters
  94   void set_gcs_are_young(bool v) { _gcs_are_young = v; }
  95   void set_last_gc_was_young(bool v) { _last_gc_was_young = v; }
  96   void set_last_young_gc(bool v) { _last_young_gc = v; }
  97   void set_during_initial_mark_pause(bool v) { _during_initial_mark_pause = v; }
  98   void set_initiate_conc_mark_if_possible(bool v) { _initiate_conc_mark_if_possible = v; }
  99   void set_during_marking(bool v) { _during_marking = v; }
 100   void set_mark_in_progress(bool v) { _mark_in_progress = v; }
 101   void set_in_marking_window(bool v) { _in_marking_window = v; }
 102   void set_in_marking_window_im(bool v) { _in_marking_window_im = v; }
 103   void set_concurrent_cycle_started(bool v) { _concurrent_cycle_started = v; }
 104   void set_full_collection(bool v) { _full_collection = v; }
 105 
 106   // Getters
 107   bool gcs_are_young() const { return _gcs_are_young; }
 108   bool last_gc_was_young() const { return _last_gc_was_young; }
 109   bool last_young_gc() const { return _last_young_gc; }
 110   bool during_initial_mark_pause() const { return _during_initial_mark_pause; }
 111   bool initiate_conc_mark_if_possible() const { return _initiate_conc_mark_if_possible; }
 112   bool during_marking() const { return _during_marking; }
 113   bool mark_in_progress() const { return _mark_in_progress; }
 114   bool in_marking_window() const { return _in_marking_window; }
 115   bool in_marking_window_im() const { return _in_marking_window_im; }
 116   bool concurrent_cycle_started() const { return _concurrent_cycle_started; }
 117   bool full_collection() const { return _full_collection; }
 118 
 119   // Composite booleans (clients worry about flickering)
 120   bool during_concurrent_mark() const {
 121     return (_in_marking_window && !_in_marking_window_im);
 122   }
 123 
 124   G1YCType yc_type() const {
 125     if (during_initial_mark_pause()) {
 126       return InitialMark;
 127     } else if (mark_in_progress()) {
 128       return DuringMark;
 129     } else if (gcs_are_young()) {
 130       return Normal;
 131     } else {
 132       return Mixed;
 133     }
 134   }
 135 };
 136 
 137 #endif // SHARE_VM_GC_G1_G1COLLECTORSTATE_HPP