src/hotspot/share/gc/g1/g1CollectionSet.hpp
author sjohanss
Fri, 07 Dec 2018 13:54:45 +0100
changeset 52897 495c05ee2a9a
parent 49806 2d62570a615c
child 53244 9807daeb47c4
permissions -rw-r--r--
8213890: Implementation of JEP 344: Abortable Mixed Collections for G1 Reviewed-by: tschatzl, kbarrett Contributed-by: erik.helin@oracle.com, stefan.johansson@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
37039
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
     1
/*
49392
2956d0ece7a9 8199282: Remove ValueObj class for allocation subclassing for gc code
coleenp
parents: 47216
diff changeset
     2
 * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
37039
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
     4
 *
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
     7
 * published by the Free Software Foundation.
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
     8
 *
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    13
 * accompanied this code).
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    14
 *
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    18
 *
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    21
 * questions.
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    22
 *
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    23
 */
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    24
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    25
#ifndef SHARE_VM_GC_G1_G1COLLECTIONSET_HPP
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    26
#define SHARE_VM_GC_G1_G1COLLECTIONSET_HPP
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    27
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    28
#include "gc/g1/collectionSetChooser.hpp"
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    29
#include "utilities/debug.hpp"
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    30
#include "utilities/globalDefinitions.hpp"
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    31
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    32
class G1CollectedHeap;
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    33
class G1CollectorState;
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    34
class G1GCPhaseTimes;
52897
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
    35
class G1ParScanThreadStateSet;
37985
539c597ee0fa 8154154: Separate G1 specific policy code from the CollectorPolicy class hierarchy
mgerdin
parents: 37262
diff changeset
    36
class G1Policy;
38183
cb68e4923223 8150721: Don't explicitly manage G1 young regions in YoungList
mgerdin
parents: 38109
diff changeset
    37
class G1SurvivorRegions;
37039
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    38
class HeapRegion;
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    39
49392
2956d0ece7a9 8199282: Remove ValueObj class for allocation subclassing for gc code
coleenp
parents: 47216
diff changeset
    40
class G1CollectionSet {
49806
2d62570a615c 8200426: Make G1 code use _g1h members
tschatzl
parents: 49392
diff changeset
    41
  G1CollectedHeap* _g1h;
37985
539c597ee0fa 8154154: Separate G1 specific policy code from the CollectorPolicy class hierarchy
mgerdin
parents: 37262
diff changeset
    42
  G1Policy* _policy;
37039
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    43
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    44
  CollectionSetChooser* _cset_chooser;
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    45
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    46
  uint _eden_region_length;
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    47
  uint _survivor_region_length;
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    48
  uint _old_region_length;
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    49
39698
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
    50
  // The actual collection set as a set of region indices.
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
    51
  // All entries in _collection_set_regions below _collection_set_cur_length are
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
    52
  // assumed to be valid entries.
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
    53
  // We assume that at any time there is at most only one writer and (one or more)
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
    54
  // concurrent readers. This means we are good with using storestore and loadload
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
    55
  // barriers on the writer and reader respectively only.
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
    56
  uint* _collection_set_regions;
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
    57
  volatile size_t _collection_set_cur_length;
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
    58
  size_t _collection_set_max_length;
37039
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    59
52897
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
    60
  // When doing mixed collections we can add old regions to the collection, which
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
    61
  // can be collected if there is enough time. We call these optional regions and
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
    62
  // the pointer to these regions are stored in the array below.
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
    63
  HeapRegion** _optional_regions;
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
    64
  uint _optional_region_length;
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
    65
  uint _optional_region_max_length;
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
    66
37039
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    67
  // The number of bytes in the collection set before the pause. Set from
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    68
  // the incrementally built collection set at the start of an evacuation
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    69
  // pause, and incremented in finalize_old_part() when adding old regions
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    70
  // (if any) to the collection set.
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    71
  size_t _bytes_used_before;
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    72
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    73
  size_t _recorded_rs_lengths;
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    74
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    75
  // The associated information that is maintained while the incremental
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    76
  // collection set is being built with young regions. Used to populate
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    77
  // the recorded info for the evacuation pause.
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    78
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    79
  enum CSetBuildType {
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    80
    Active,             // We are actively building the collection set
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    81
    Inactive            // We are not actively building the collection set
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    82
  };
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    83
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    84
  CSetBuildType _inc_build_state;
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    85
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    86
  // The number of bytes in the incrementally built collection set.
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    87
  // Used to set _collection_set_bytes_used_before at the start of
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    88
  // an evacuation pause.
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    89
  size_t _inc_bytes_used_before;
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    90
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    91
  // The RSet lengths recorded for regions in the CSet. It is updated
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    92
  // by the thread that adds a new region to the CSet. We assume that
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    93
  // only one thread can be allocating a new CSet region (currently,
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    94
  // it does so after taking the Heap_lock) hence no need to
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    95
  // synchronize updates to this field.
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    96
  size_t _inc_recorded_rs_lengths;
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    97
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    98
  // A concurrent refinement thread periodically samples the young
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
    99
  // region RSets and needs to update _inc_recorded_rs_lengths as
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   100
  // the RSets grow. Instead of having to synchronize updates to that
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   101
  // field we accumulate them in this field and add it to
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   102
  // _inc_recorded_rs_lengths_diffs at the start of a GC.
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   103
  ssize_t _inc_recorded_rs_lengths_diffs;
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   104
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   105
  // The predicted elapsed time it will take to collect the regions in
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   106
  // the CSet. This is updated by the thread that adds a new region to
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   107
  // the CSet. See the comment for _inc_recorded_rs_lengths about
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   108
  // MT-safety assumptions.
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   109
  double _inc_predicted_elapsed_time_ms;
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   110
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   111
  // See the comment for _inc_recorded_rs_lengths_diffs.
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   112
  double _inc_predicted_elapsed_time_ms_diffs;
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   113
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   114
  G1CollectorState* collector_state();
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   115
  G1GCPhaseTimes* phase_times();
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   116
52897
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   117
  void verify_young_cset_indices() const NOT_DEBUG_RETURN;
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   118
  void add_as_optional(HeapRegion* hr);
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   119
  void add_as_old(HeapRegion* hr);
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   120
  bool optional_is_full();
37039
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   121
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   122
public:
37985
539c597ee0fa 8154154: Separate G1 specific policy code from the CollectorPolicy class hierarchy
mgerdin
parents: 37262
diff changeset
   123
  G1CollectionSet(G1CollectedHeap* g1h, G1Policy* policy);
37039
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   124
  ~G1CollectionSet();
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   125
39698
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   126
  // Initializes the collection set giving the maximum possible length of the collection set.
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   127
  void initialize(uint max_region_length);
52897
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   128
  void initialize_optional(uint max_length);
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   129
  void free_optional_regions();
39698
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   130
37039
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   131
  CollectionSetChooser* cset_chooser();
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   132
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   133
  void init_region_lengths(uint eden_cset_region_length,
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   134
                           uint survivor_cset_region_length);
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   135
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   136
  void set_recorded_rs_lengths(size_t rs_lengths);
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   137
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   138
  uint region_length() const       { return young_region_length() +
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   139
                                            old_region_length(); }
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   140
  uint young_region_length() const { return eden_region_length() +
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   141
                                            survivor_region_length(); }
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   142
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   143
  uint eden_region_length() const     { return _eden_region_length;     }
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   144
  uint survivor_region_length() const { return _survivor_region_length; }
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   145
  uint old_region_length() const      { return _old_region_length;      }
52897
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   146
  uint optional_region_length() const { return _optional_region_length; }
37039
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   147
39698
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   148
  // Incremental collection set support
37039
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   149
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   150
  // Initialize incremental collection set info.
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   151
  void start_incremental_building();
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   152
39698
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   153
  // Perform any final calculations on the incremental collection set fields
37039
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   154
  // before we can use them.
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   155
  void finalize_incremental_building();
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   156
39698
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   157
  // Reset the contents of the collection set.
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   158
  void clear();
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   159
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   160
  // Iterate over the collection set, applying the given HeapRegionClosure on all of them.
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   161
  // If may_be_aborted is true, iteration may be aborted using the return value of the
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   162
  // called closure method.
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   163
  void iterate(HeapRegionClosure* cl) const;
37039
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   164
39698
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   165
  // Iterate over the collection set, applying the given HeapRegionClosure on all of them,
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   166
  // trying to optimally spread out starting position of total_workers workers given the
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   167
  // caller's worker_id.
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   168
  void iterate_from(HeapRegionClosure* cl, uint worker_id, uint total_workers) const;
37039
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   169
39698
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   170
  // Stop adding regions to the incremental collection set.
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   171
  void stop_incremental_building() { _inc_build_state = Inactive; }
37039
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   172
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   173
  size_t recorded_rs_lengths() { return _recorded_rs_lengths; }
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   174
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   175
  size_t bytes_used_before() const {
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   176
    return _bytes_used_before;
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   177
  }
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   178
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   179
  void reset_bytes_used_before() {
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   180
    _bytes_used_before = 0;
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   181
  }
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   182
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   183
  // Choose a new collection set.  Marks the chosen regions as being
39698
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   184
  // "in_collection_set".
38183
cb68e4923223 8150721: Don't explicitly manage G1 young regions in YoungList
mgerdin
parents: 38109
diff changeset
   185
  double finalize_young_part(double target_pause_time_ms, G1SurvivorRegions* survivors);
37039
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   186
  void finalize_old_part(double time_remaining_ms);
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   187
39698
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   188
  // Add old region "hr" to the collection set.
37039
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   189
  void add_old_region(HeapRegion* hr);
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   190
52897
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   191
  // Add old region "hr" to optional collection set.
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   192
  void add_optional_region(HeapRegion* hr);
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   193
37039
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   194
  // Update information about hr in the aggregated information for
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   195
  // the incrementally built collection set.
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   196
  void update_young_region_prediction(HeapRegion* hr, size_t new_rs_length);
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   197
39698
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   198
  // Add eden region to the collection set.
37039
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   199
  void add_eden_region(HeapRegion* hr);
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   200
39698
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   201
  // Add survivor region to the collection set.
37039
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   202
  void add_survivor_regions(HeapRegion* hr);
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   203
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   204
#ifndef PRODUCT
39698
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   205
  bool verify_young_ages();
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   206
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   207
  void print(outputStream* st);
37039
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   208
#endif // !PRODUCT
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   209
52897
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   210
  double predict_region_elapsed_time_ms(HeapRegion* hr);
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   211
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   212
  void clear_optional_region(const HeapRegion* hr);
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   213
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   214
  HeapRegion* optional_region_at(uint i) const {
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   215
    assert(_optional_regions != NULL, "Not yet initialized");
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   216
    assert(i < _optional_region_length, "index %u out of bounds (%u)", i, _optional_region_length);
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   217
    return _optional_regions[i];
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   218
  }
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   219
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   220
  HeapRegion* remove_last_optional_region() {
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   221
    assert(_optional_regions != NULL, "Not yet initialized");
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   222
    assert(_optional_region_length != 0, "No region to remove");
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   223
    _optional_region_length--;
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   224
    HeapRegion* removed = _optional_regions[_optional_region_length];
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   225
    _optional_regions[_optional_region_length] = NULL;
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   226
    return removed;
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   227
  }
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   228
37039
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   229
private:
39698
4016de4e596b 8159978: Use an array to store the collection set regions instead of linking through regions
tschatzl
parents: 38183
diff changeset
   230
  // Update the incremental collection set information when adding a region.
37039
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   231
  void add_young_region_common(HeapRegion* hr);
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   232
};
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   233
52897
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   234
// Helper class to manage the optional regions in a Mixed collection.
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   235
class G1OptionalCSet : public StackObj {
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   236
private:
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   237
  G1CollectionSet* _cset;
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   238
  G1ParScanThreadStateSet* _pset;
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   239
  uint _current_index;
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   240
  uint _current_limit;
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   241
  bool _prepare_failed;
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   242
  bool _evacuation_failed;
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   243
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   244
  void prepare_to_evacuate_optional_region(HeapRegion* hr);
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   245
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   246
public:
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   247
  static const uint InvalidCSetIndex = UINT_MAX;
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   248
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   249
  G1OptionalCSet(G1CollectionSet* cset, G1ParScanThreadStateSet* pset) :
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   250
    _cset(cset),
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   251
    _pset(pset),
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   252
    _current_index(0),
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   253
    _current_limit(0),
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   254
    _prepare_failed(false),
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   255
    _evacuation_failed(false) { }
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   256
  // The destructor returns regions to the cset-chooser and
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   257
  // frees the optional structure in the cset.
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   258
  ~G1OptionalCSet();
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   259
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   260
  uint current_index() { return _current_index; }
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   261
  uint current_limit() { return _current_limit; }
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   262
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   263
  uint size();
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   264
  bool is_empty();
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   265
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   266
  HeapRegion* region_at(uint index);
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   267
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   268
  // Prepare a set of regions for optional evacuation.
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   269
  void prepare_evacuation(double time_left_ms);
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   270
  bool prepare_failed();
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   271
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   272
  // Complete the evacuation of the previously prepared
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   273
  // regions by updating their state and check for failures.
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   274
  void complete_evacuation();
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   275
  bool evacuation_failed();
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   276
};
495c05ee2a9a 8213890: Implementation of JEP 344: Abortable Mixed Collections for G1
sjohanss
parents: 49806
diff changeset
   277
37039
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   278
#endif // SHARE_VM_GC_G1_G1COLLECTIONSET_HPP
79f62b89a7a6 8151178: Move the collection set out of the G1 collector policy
mgerdin
parents:
diff changeset
   279