src/hotspot/share/gc/g1/g1CollectorState.hpp
changeset 49643 a3453bbd5418
parent 49632 64f9ebc85e67
child 49664 9a04cc89dde0
equal deleted inserted replaced
49642:7bad9c9efdf3 49643:a3453bbd5418
    26 #define SHARE_VM_GC_G1_G1COLLECTORSTATE_HPP
    26 #define SHARE_VM_GC_G1_G1COLLECTORSTATE_HPP
    27 
    27 
    28 #include "gc/g1/g1YCTypes.hpp"
    28 #include "gc/g1/g1YCTypes.hpp"
    29 #include "utilities/globalDefinitions.hpp"
    29 #include "utilities/globalDefinitions.hpp"
    30 
    30 
    31 // Various state variables that indicate
    31 // State of the G1 collection.
    32 // the phase of the G1 collection.
       
    33 class G1CollectorState {
    32 class G1CollectorState {
    34   // Indicates whether we are in "full young" or "mixed" GC mode.
    33   // Indicates whether we are in the phase where we do partial gcs that only contain
    35   bool _gcs_are_young;
    34   // the young generation. Not set while _in_full_gc is set.
    36   // Was the last GC "young"?
    35   bool _in_young_only_phase;
    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 
    36 
    42   // If initiate_conc_mark_if_possible() is set at the beginning of a
    37   // Indicates whether we are in the last young gc before the mixed gc phase. This GC
       
    38   // is required to keep pause time requirements.
       
    39   bool _in_young_gc_before_mixed;
       
    40 
       
    41   // 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
    42   // pause, it is a suggestion that the pause should start a marking
    44   // cycle by doing the initial-mark work. However, it is possible
    43   // cycle by doing the initial-mark work. However, it is possible
    45   // that the concurrent marking thread is still finishing up the
    44   // that the concurrent marking thread is still finishing up the
    46   // previous marking cycle (e.g., clearing the next marking
    45   // previous marking cycle (e.g., clearing the next marking
    47   // bitmap). If that is the case we cannot start a new cycle and
    46   // 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
    47   // 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
    48   // what it is doing. In this case we will postpone the marking cycle
    50   // initiation decision for the next pause. When we eventually decide
    49   // initiation decision for the next pause. When we eventually decide
    51   // to start a cycle, we will set _during_initial_mark_pause which
    50   // to start a cycle, we will set _in_initial_mark_gc which
    52   // will stay true until the end of the initial-mark pause and it's
    51   // will stay true until the end of the initial-mark pause doing the
    53   // the condition that indicates that a pause is doing the
       
    54   // initial-mark work.
    52   // initial-mark work.
    55   volatile bool _during_initial_mark_pause;
    53   volatile bool _in_initial_mark_gc;
    56 
    54 
    57   // At the end of a pause we check the heap occupancy and we decide
    55   // 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
    56   // 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
    57   // we decide that we want to do that, set this parameter. This parameter will
    60   // true. So, this parameter will stay true between the end of a
    58   // stay set until the beginning of a subsequent pause (not necessarily
    61   // pause and the beginning of a subsequent pause (not necessarily
    59   // the next one) when we decide that we will indeed start a marking cycle and
    62   // the next one, see the comments on the next field) when we decide
    60   // do the initial-mark work.
    63   // that we will indeed start a marking cycle and do the initial-mark
       
    64   // work.
       
    65   volatile bool _initiate_conc_mark_if_possible;
    61   volatile bool _initiate_conc_mark_if_possible;
    66 
    62 
    67   // NOTE: if some of these are synonyms for others,
    63   // Marking or rebuilding remembered set work is in progress. Set from the end
    68   // the redundant fields should be eliminated. XXX
    64   // of the initial mark pause to the end of the Cleanup pause.
    69   bool _during_marking;
    65   bool _mark_or_rebuild_in_progress;
    70   bool _mark_in_progress;
       
    71   bool _in_marking_window;
       
    72   bool _in_marking_window_im;
       
    73 
    66 
    74   bool _full_collection;
    67   // Set during a full gc pause.
       
    68   bool _in_full_gc;
    75 
    69 
    76   public:
    70 public:
    77     G1CollectorState() :
    71   G1CollectorState() :
    78       _gcs_are_young(true),
    72     _in_young_only_phase(true),
    79       _last_gc_was_young(false),
    73     _in_young_gc_before_mixed(false),
    80       _last_young_gc(false),
       
    81 
    74 
    82       _during_initial_mark_pause(false),
    75     _in_initial_mark_gc(false),
    83       _initiate_conc_mark_if_possible(false),
    76     _initiate_conc_mark_if_possible(false),
    84 
    77 
    85       _during_marking(false),
    78     _mark_or_rebuild_in_progress(false),
    86       _mark_in_progress(false),
    79     _in_full_gc(false) { }
    87       _in_marking_window(false),
       
    88       _in_marking_window_im(false),
       
    89       _full_collection(false) {}
       
    90 
    80 
    91   // Setters
    81   // Phase setters
    92   void set_gcs_are_young(bool v) { _gcs_are_young = v; }
    82   void set_in_young_only_phase(bool v) { _in_young_only_phase = v; }
    93   void set_last_gc_was_young(bool v) { _last_gc_was_young = v; }
    83 
    94   void set_last_young_gc(bool v) { _last_young_gc = v; }
    84   // Pause setters
    95   void set_during_initial_mark_pause(bool v) { _during_initial_mark_pause = v; }
    85   void set_in_young_gc_before_mixed(bool v) { _in_young_gc_before_mixed = v; }
       
    86   void set_in_initial_mark_gc(bool v) { _in_initial_mark_gc = v; }
       
    87   void set_in_full_gc(bool v) { _in_full_gc = v; }
       
    88 
    96   void set_initiate_conc_mark_if_possible(bool v) { _initiate_conc_mark_if_possible = v; }
    89   void set_initiate_conc_mark_if_possible(bool v) { _initiate_conc_mark_if_possible = v; }
    97   void set_during_marking(bool v) { _during_marking = v; }
       
    98   void set_mark_in_progress(bool v) { _mark_in_progress = v; }
       
    99   void set_in_marking_window(bool v) { _in_marking_window = v; }
       
   100   void set_in_marking_window_im(bool v) { _in_marking_window_im = v; }
       
   101   void set_full_collection(bool v) { _full_collection = v; }
       
   102 
    90 
   103   // Getters
    91   void set_mark_or_rebuild_in_progress(bool v) { _mark_or_rebuild_in_progress = v; }
   104   bool gcs_are_young() const { return _gcs_are_young; }
    92 
   105   bool last_gc_was_young() const { return _last_gc_was_young; }
    93   // Phase getters
   106   bool last_young_gc() const { return _last_young_gc; }
    94   bool in_young_only_phase() const { return _in_young_only_phase && !_in_full_gc; }
   107   bool during_initial_mark_pause() const { return _during_initial_mark_pause; }
    95   bool in_mixed_phase() const { return !in_young_only_phase() && !_in_full_gc; }
       
    96 
       
    97   // Specific pauses
       
    98   bool in_young_gc_before_mixed() const { return _in_young_gc_before_mixed; }
       
    99   bool in_full_gc() const { return _in_full_gc; }
       
   100   bool in_initial_mark_gc() const { return _in_initial_mark_gc; }
       
   101 
   108   bool initiate_conc_mark_if_possible() const { return _initiate_conc_mark_if_possible; }
   102   bool initiate_conc_mark_if_possible() const { return _initiate_conc_mark_if_possible; }
   109   bool during_marking() const { return _during_marking; }
       
   110   bool mark_in_progress() const { return _mark_in_progress; }
       
   111   bool in_marking_window() const { return _in_marking_window; }
       
   112   bool in_marking_window_im() const { return _in_marking_window_im; }
       
   113   bool full_collection() const { return _full_collection; }
       
   114 
   103 
   115   // Composite booleans (clients worry about flickering)
   104   bool mark_or_rebuild_in_progress() const { return _mark_or_rebuild_in_progress; }
   116   bool during_concurrent_mark() const {
       
   117     return (_in_marking_window && !_in_marking_window_im);
       
   118   }
       
   119 
   105 
   120   G1YCType yc_type() const {
   106   G1YCType yc_type() const {
   121     if (during_initial_mark_pause()) {
   107     if (in_initial_mark_gc()) {
   122       return InitialMark;
   108       return InitialMark;
   123     } else if (mark_in_progress()) {
   109     } else if (mark_or_rebuild_in_progress()) {
   124       return DuringMark;
   110       return DuringMarkOrRebuild;
   125     } else if (gcs_are_young()) {
   111     } else if (in_young_only_phase()) {
   126       return Normal;
   112       return Normal;
   127     } else {
   113     } else {
   128       return Mixed;
   114       return Mixed;
   129     }
   115     }
   130   }
   116   }