src/share/vm/gc_implementation/g1/collectionSetChooser.hpp

Mon, 19 Aug 2019 10:11:31 +0200

author
neugens
date
Mon, 19 Aug 2019 10:11:31 +0200
changeset 9861
a248d0be1309
parent 9327
f96fcd9e1e1b
child 9448
73d689add964
permissions
-rw-r--r--

8229401: Fix JFR code cache test failures
8223689: Add JFR Thread Sampling Support
8223690: Add JFR BiasedLock Event Support
8223691: Add JFR G1 Region Type Change Event Support
8223692: Add JFR G1 Heap Summary Event Support
Summary: Backport JFR from JDK11, additional fixes
Reviewed-by: neugens, apetushkov
Contributed-by: denghui.ddh@alibaba-inc.com

ysr@777 1 /*
mikael@6198 2 * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
ysr@777 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ysr@777 4 *
ysr@777 5 * This code is free software; you can redistribute it and/or modify it
ysr@777 6 * under the terms of the GNU General Public License version 2 only, as
ysr@777 7 * published by the Free Software Foundation.
ysr@777 8 *
ysr@777 9 * This code is distributed in the hope that it will be useful, but WITHOUT
ysr@777 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ysr@777 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ysr@777 12 * version 2 for more details (a copy is included in the LICENSE file that
ysr@777 13 * accompanied this code).
ysr@777 14 *
ysr@777 15 * You should have received a copy of the GNU General Public License version
ysr@777 16 * 2 along with this work; if not, write to the Free Software Foundation,
ysr@777 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ysr@777 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
ysr@777 22 *
ysr@777 23 */
ysr@777 24
stefank@2314 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP
stefank@2314 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP
stefank@2314 27
stefank@2314 28 #include "gc_implementation/g1/heapRegion.hpp"
stefank@2314 29 #include "utilities/growableArray.hpp"
stefank@2314 30
zgu@3900 31 class CollectionSetChooser: public CHeapObj<mtGC> {
ysr@777 32
tonyp@3714 33 GrowableArray<HeapRegion*> _regions;
tonyp@3714 34
tonyp@3714 35 // Unfortunately, GrowableArray uses ints for length and indexes. To
tonyp@3714 36 // avoid excessive casting in the rest of the class the following
tonyp@3714 37 // wrapper methods are provided that use uints.
tonyp@3714 38
tonyp@3714 39 uint regions_length() { return (uint) _regions.length(); }
tonyp@3714 40 HeapRegion* regions_at(uint i) { return _regions.at((int) i); }
tonyp@3714 41 void regions_at_put(uint i, HeapRegion* hr) {
tonyp@3714 42 _regions.at_put((int) i, hr);
tonyp@3714 43 }
tonyp@3714 44 void regions_at_put_grow(uint i, HeapRegion* hr) {
tonyp@3714 45 _regions.at_put_grow((int) i, hr);
tonyp@3714 46 }
tonyp@3714 47 void regions_trunc_to(uint i) { _regions.trunc_to((uint) i); }
tonyp@3539 48
tonyp@3539 49 // The index of the next candidate old region to be considered for
tonyp@3539 50 // addition to the CSet.
tonyp@3714 51 uint _curr_index;
tonyp@3539 52
tonyp@3539 53 // The number of candidate old regions added to the CSet chooser.
johnc@4681 54 // Note: this is not updated when removing a region using
johnc@4681 55 // remove_and_move_to_next() below.
tonyp@3714 56 uint _length;
tonyp@3539 57
tonyp@3714 58 // Keeps track of the start of the next array chunk to be claimed by
tonyp@3714 59 // parallel GC workers.
tonyp@3714 60 uint _first_par_unreserved_idx;
ysr@777 61
tonyp@3539 62 // If a region has more live bytes than this threshold, it will not
tonyp@3539 63 // be added to the CSet chooser and will not be a candidate for
tonyp@3539 64 // collection.
tonyp@3714 65 size_t _region_live_threshold_bytes;
ysr@777 66
tonyp@3539 67 // The sum of reclaimable bytes over all the regions in the CSet chooser.
tonyp@3714 68 size_t _remaining_reclaimable_bytes;
ysr@777 69
ysr@777 70 public:
ysr@777 71
tonyp@3539 72 // Return the current candidate region to be considered for
tonyp@3539 73 // collection without removing it from the CSet chooser.
tonyp@3539 74 HeapRegion* peek() {
tonyp@3539 75 HeapRegion* res = NULL;
tonyp@3539 76 if (_curr_index < _length) {
tonyp@3714 77 res = regions_at(_curr_index);
tonyp@3539 78 assert(res != NULL,
tonyp@3714 79 err_msg("Unexpected NULL hr in _regions at index %u",
tonyp@3539 80 _curr_index));
tonyp@3539 81 }
tonyp@3539 82 return res;
tonyp@3539 83 }
tonyp@3539 84
tonyp@3539 85 // Remove the given region from the CSet chooser and move to the
tonyp@3539 86 // next one. The given region should be the current candidate region
tonyp@3539 87 // in the CSet chooser.
tonyp@3539 88 void remove_and_move_to_next(HeapRegion* hr) {
tonyp@3539 89 assert(hr != NULL, "pre-condition");
tonyp@3539 90 assert(_curr_index < _length, "pre-condition");
tonyp@3714 91 assert(regions_at(_curr_index) == hr, "pre-condition");
tonyp@3714 92 regions_at_put(_curr_index, NULL);
tonyp@3714 93 assert(hr->reclaimable_bytes() <= _remaining_reclaimable_bytes,
tonyp@3539 94 err_msg("remaining reclaimable bytes inconsistent "
kevinw@9327 95 "from region: " SIZE_FORMAT " remaining: " SIZE_FORMAT,
tonyp@3714 96 hr->reclaimable_bytes(), _remaining_reclaimable_bytes));
tonyp@3714 97 _remaining_reclaimable_bytes -= hr->reclaimable_bytes();
tonyp@3539 98 _curr_index += 1;
tonyp@3539 99 }
ysr@777 100
ysr@777 101 CollectionSetChooser();
ysr@777 102
tonyp@3714 103 void sort_regions();
tonyp@3539 104
tonyp@3539 105 // Determine whether to add the given region to the CSet chooser or
tonyp@3539 106 // not. Currently, we skip humongous regions (we never add them to
tonyp@3539 107 // the CSet, we only reclaim them during cleanup) and regions whose
tonyp@3539 108 // live bytes are over the threshold.
tonyp@3714 109 bool should_add(HeapRegion* hr) {
tonyp@3539 110 assert(hr->is_marked(), "pre-condition");
tonyp@3539 111 assert(!hr->is_young(), "should never consider young regions");
tonyp@3539 112 return !hr->isHumongous() &&
tonyp@3714 113 hr->live_bytes() < _region_live_threshold_bytes;
tonyp@3539 114 }
tonyp@3539 115
johnc@4681 116 // Returns the number candidate old regions added
johnc@4681 117 uint length() { return _length; }
tonyp@3539 118
tonyp@3539 119 // Serial version.
tonyp@3714 120 void add_region(HeapRegion *hr);
ysr@777 121
tonyp@3714 122 // Must be called before calls to claim_array_chunk().
tonyp@3714 123 // n_regions is the number of regions, chunk_size the chunk size.
tonyp@3714 124 void prepare_for_par_region_addition(uint n_regions, uint chunk_size);
tonyp@3714 125 // Returns the first index in a contiguous chunk of chunk_size indexes
ysr@777 126 // that the calling thread has reserved. These must be set by the
tonyp@3714 127 // calling thread using set_region() (to NULL if necessary).
tonyp@3714 128 uint claim_array_chunk(uint chunk_size);
ysr@777 129 // Set the marked array entry at index to hr. Careful to claim the index
ysr@777 130 // first if in parallel.
tonyp@3714 131 void set_region(uint index, HeapRegion* hr);
tonyp@3539 132 // Atomically increment the number of added regions by region_num
tonyp@3539 133 // and the amount of reclaimable bytes by reclaimable_bytes.
tonyp@3714 134 void update_totals(uint region_num, size_t reclaimable_bytes);
ysr@777 135
tonyp@3714 136 void clear();
ysr@777 137
tonyp@3539 138 // Return the number of candidate regions that remain to be collected.
tonyp@3714 139 uint remaining_regions() { return _length - _curr_index; }
ysr@777 140
tonyp@3539 141 // Determine whether the CSet chooser has more candidate regions or not.
tonyp@3714 142 bool is_empty() { return remaining_regions() == 0; }
tonyp@3539 143
tonyp@3539 144 // Return the reclaimable bytes that remain to be collected on
tonyp@3539 145 // all the candidate regions in the CSet chooser.
tonyp@3714 146 size_t remaining_reclaimable_bytes() { return _remaining_reclaimable_bytes; }
ysr@777 147
tonyp@3714 148 // Returns true if the used portion of "_regions" is properly
ysr@777 149 // sorted, otherwise asserts false.
tonyp@3714 150 void verify() PRODUCT_RETURN;
ysr@777 151 };
stefank@2314 152
tonyp@3957 153 class CSetChooserParUpdater : public StackObj {
tonyp@3957 154 private:
tonyp@3957 155 CollectionSetChooser* _chooser;
tonyp@3957 156 bool _parallel;
tonyp@3957 157 uint _chunk_size;
tonyp@3957 158 uint _cur_chunk_idx;
tonyp@3957 159 uint _cur_chunk_end;
tonyp@3957 160 uint _regions_added;
tonyp@3957 161 size_t _reclaimable_bytes_added;
tonyp@3957 162
tonyp@3957 163 public:
tonyp@3957 164 CSetChooserParUpdater(CollectionSetChooser* chooser,
tonyp@3957 165 bool parallel, uint chunk_size) :
tonyp@3957 166 _chooser(chooser), _parallel(parallel), _chunk_size(chunk_size),
tonyp@3957 167 _cur_chunk_idx(0), _cur_chunk_end(0),
tonyp@3957 168 _regions_added(0), _reclaimable_bytes_added(0) { }
tonyp@3957 169
tonyp@3957 170 ~CSetChooserParUpdater() {
tonyp@3957 171 if (_parallel && _regions_added > 0) {
tonyp@3957 172 _chooser->update_totals(_regions_added, _reclaimable_bytes_added);
tonyp@3957 173 }
tonyp@3957 174 }
tonyp@3957 175
tonyp@3957 176 void add_region(HeapRegion* hr) {
tonyp@3957 177 if (_parallel) {
tonyp@3957 178 if (_cur_chunk_idx == _cur_chunk_end) {
tonyp@3957 179 _cur_chunk_idx = _chooser->claim_array_chunk(_chunk_size);
tonyp@3957 180 _cur_chunk_end = _cur_chunk_idx + _chunk_size;
tonyp@3957 181 }
tonyp@3957 182 assert(_cur_chunk_idx < _cur_chunk_end, "invariant");
tonyp@3957 183 _chooser->set_region(_cur_chunk_idx, hr);
tonyp@3957 184 _cur_chunk_idx += 1;
tonyp@3957 185 } else {
tonyp@3957 186 _chooser->add_region(hr);
tonyp@3957 187 }
tonyp@3957 188 _regions_added += 1;
tonyp@3957 189 _reclaimable_bytes_added += hr->reclaimable_bytes();
tonyp@3957 190 }
tonyp@3957 191
tonyp@3957 192 bool should_add(HeapRegion* hr) { return _chooser->should_add(hr); }
tonyp@3957 193 };
tonyp@3957 194
stefank@2314 195 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_COLLECTIONSETCHOOSER_HPP
tonyp@3957 196

mercurial