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