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

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 7195
c02ec279b062
parent 6876
710a3c8b516e
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation.
aoqi@0 8 *
aoqi@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 12 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 13 * accompanied this code).
aoqi@0 14 *
aoqi@0 15 * You should have received a copy of the GNU General Public License version
aoqi@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 18 *
aoqi@0 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 20 * or visit www.oracle.com if you need additional information or have any
aoqi@0 21 * questions.
aoqi@0 22 *
aoqi@0 23 */
aoqi@0 24
aoqi@0 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_HPP
aoqi@0 26 #define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_HPP
aoqi@0 27
aoqi@0 28 #include "gc_implementation/g1/heapRegion.hpp"
aoqi@0 29
aoqi@0 30 // Large buffer for some cases where the output might be larger than normal.
aoqi@0 31 #define HRS_ERR_MSG_BUFSZ 512
aoqi@0 32 typedef FormatBuffer<HRS_ERR_MSG_BUFSZ> hrs_err_msg;
aoqi@0 33
aoqi@0 34 // Set verification will be forced either if someone defines
aoqi@0 35 // HEAP_REGION_SET_FORCE_VERIFY to be 1, or in builds in which
aoqi@0 36 // asserts are compiled in.
aoqi@0 37 #ifndef HEAP_REGION_SET_FORCE_VERIFY
aoqi@0 38 #define HEAP_REGION_SET_FORCE_VERIFY defined(ASSERT)
aoqi@0 39 #endif // HEAP_REGION_SET_FORCE_VERIFY
aoqi@0 40
aoqi@0 41 class hrs_ext_msg;
aoqi@0 42
aoqi@0 43 class HRSMtSafeChecker : public CHeapObj<mtGC> {
aoqi@0 44 public:
aoqi@0 45 virtual void check() = 0;
aoqi@0 46 };
aoqi@0 47
aoqi@0 48 class MasterFreeRegionListMtSafeChecker : public HRSMtSafeChecker { public: void check(); };
aoqi@0 49 class SecondaryFreeRegionListMtSafeChecker : public HRSMtSafeChecker { public: void check(); };
aoqi@0 50 class HumongousRegionSetMtSafeChecker : public HRSMtSafeChecker { public: void check(); };
aoqi@0 51 class OldRegionSetMtSafeChecker : public HRSMtSafeChecker { public: void check(); };
aoqi@0 52
aoqi@0 53 class HeapRegionSetCount VALUE_OBJ_CLASS_SPEC {
aoqi@0 54 friend class VMStructs;
aoqi@0 55 uint _length;
aoqi@0 56 size_t _capacity;
aoqi@0 57
aoqi@0 58 public:
aoqi@0 59 HeapRegionSetCount() : _length(0), _capacity(0) { }
aoqi@0 60
aoqi@0 61 const uint length() const { return _length; }
aoqi@0 62 const size_t capacity() const { return _capacity; }
aoqi@0 63
aoqi@0 64 void increment(uint length_to_add, size_t capacity_to_add) {
aoqi@0 65 _length += length_to_add;
aoqi@0 66 _capacity += capacity_to_add;
aoqi@0 67 }
aoqi@0 68
aoqi@0 69 void decrement(const uint length_to_remove, const size_t capacity_to_remove) {
aoqi@0 70 _length -= length_to_remove;
aoqi@0 71 _capacity -= capacity_to_remove;
aoqi@0 72 }
aoqi@0 73 };
aoqi@0 74
aoqi@0 75 // Base class for all the classes that represent heap region sets. It
aoqi@0 76 // contains the basic attributes that each set needs to maintain
aoqi@0 77 // (e.g., length, region num, used bytes sum) plus any shared
aoqi@0 78 // functionality (e.g., verification).
aoqi@0 79
aoqi@0 80 class HeapRegionSetBase VALUE_OBJ_CLASS_SPEC {
aoqi@0 81 friend class VMStructs;
aoqi@0 82 private:
aoqi@0 83 bool _is_humongous;
brutisso@7195 84 bool _is_free;
aoqi@0 85 HRSMtSafeChecker* _mt_safety_checker;
aoqi@0 86
aoqi@0 87 protected:
aoqi@0 88 // The number of regions added to the set. If the set contains
aoqi@0 89 // only humongous regions, this reflects only 'starts humongous'
aoqi@0 90 // regions and does not include 'continues humongous' ones.
aoqi@0 91 HeapRegionSetCount _count;
aoqi@0 92
aoqi@0 93 const char* _name;
aoqi@0 94
aoqi@0 95 bool _verify_in_progress;
aoqi@0 96
aoqi@0 97 // verify_region() is used to ensure that the contents of a region
aoqi@0 98 // added to / removed from a set are consistent.
aoqi@0 99 void verify_region(HeapRegion* hr) PRODUCT_RETURN;
aoqi@0 100
aoqi@0 101 // Indicates whether all regions in the set should be humongous or
aoqi@0 102 // not. Only used during verification.
aoqi@0 103 bool regions_humongous() { return _is_humongous; }
aoqi@0 104
brutisso@7195 105 // Indicates whether all regions in the set should be free or
aoqi@0 106 // not. Only used during verification.
brutisso@7195 107 bool regions_free() { return _is_free; }
aoqi@0 108
aoqi@0 109 void check_mt_safety() {
aoqi@0 110 if (_mt_safety_checker != NULL) {
aoqi@0 111 _mt_safety_checker->check();
aoqi@0 112 }
aoqi@0 113 }
aoqi@0 114
aoqi@0 115 virtual void fill_in_ext_msg_extra(hrs_ext_msg* msg) { }
aoqi@0 116
brutisso@7195 117 HeapRegionSetBase(const char* name, bool humongous, bool free, HRSMtSafeChecker* mt_safety_checker);
aoqi@0 118
aoqi@0 119 public:
aoqi@0 120 const char* name() { return _name; }
aoqi@0 121
tschatzl@7009 122 uint length() const { return _count.length(); }
aoqi@0 123
aoqi@0 124 bool is_empty() { return _count.length() == 0; }
aoqi@0 125
aoqi@0 126 size_t total_capacity_bytes() {
aoqi@0 127 return _count.capacity();
aoqi@0 128 }
aoqi@0 129
aoqi@0 130 // It updates the fields of the set to reflect hr being added to
aoqi@0 131 // the set and tags the region appropriately.
aoqi@0 132 inline void add(HeapRegion* hr);
aoqi@0 133
aoqi@0 134 // It updates the fields of the set to reflect hr being removed
aoqi@0 135 // from the set and tags the region appropriately.
aoqi@0 136 inline void remove(HeapRegion* hr);
aoqi@0 137
aoqi@0 138 // fill_in_ext_msg() writes the the values of the set's attributes
aoqi@0 139 // in the custom err_msg (hrs_ext_msg). fill_in_ext_msg_extra()
aoqi@0 140 // allows subclasses to append further information.
aoqi@0 141 void fill_in_ext_msg(hrs_ext_msg* msg, const char* message);
aoqi@0 142
aoqi@0 143 virtual void verify();
aoqi@0 144 void verify_start();
aoqi@0 145 void verify_next_region(HeapRegion* hr);
aoqi@0 146 void verify_end();
aoqi@0 147
aoqi@0 148 #if HEAP_REGION_SET_FORCE_VERIFY
aoqi@0 149 void verify_optional() {
aoqi@0 150 verify();
aoqi@0 151 }
aoqi@0 152 #else // HEAP_REGION_SET_FORCE_VERIFY
aoqi@0 153 void verify_optional() { }
aoqi@0 154 #endif // HEAP_REGION_SET_FORCE_VERIFY
aoqi@0 155
aoqi@0 156 virtual void print_on(outputStream* out, bool print_contents = false);
aoqi@0 157 };
aoqi@0 158
aoqi@0 159 // Customized err_msg for heap region sets. Apart from a
aoqi@0 160 // assert/guarantee-specific message it also prints out the values of
aoqi@0 161 // the fields of the associated set. This can be very helpful in
aoqi@0 162 // diagnosing failures.
aoqi@0 163 class hrs_ext_msg : public hrs_err_msg {
aoqi@0 164 public:
tschatzl@7050 165 hrs_ext_msg(HeapRegionSetBase* set, const char* message) : hrs_err_msg("%s", "") {
aoqi@0 166 set->fill_in_ext_msg(this, message);
aoqi@0 167 }
aoqi@0 168 };
aoqi@0 169
aoqi@0 170 #define hrs_assert_sets_match(_set1_, _set2_) \
aoqi@0 171 do { \
aoqi@0 172 assert(((_set1_)->regions_humongous() == \
aoqi@0 173 (_set2_)->regions_humongous()) && \
brutisso@7195 174 ((_set1_)->regions_free() == (_set2_)->regions_free()), \
aoqi@0 175 hrs_err_msg("the contents of set %s and set %s should match", \
aoqi@0 176 (_set1_)->name(), (_set2_)->name())); \
aoqi@0 177 } while (0)
aoqi@0 178
aoqi@0 179 // This class represents heap region sets whose members are not
aoqi@0 180 // explicitly tracked. It's helpful to group regions using such sets
aoqi@0 181 // so that we can reason about all the region groups in the heap using
aoqi@0 182 // the same interface (namely, the HeapRegionSetBase API).
aoqi@0 183
aoqi@0 184 class HeapRegionSet : public HeapRegionSetBase {
aoqi@0 185 public:
aoqi@0 186 HeapRegionSet(const char* name, bool humongous, HRSMtSafeChecker* mt_safety_checker):
brutisso@7195 187 HeapRegionSetBase(name, humongous, false /* free */, mt_safety_checker) { }
aoqi@0 188
aoqi@0 189 void bulk_remove(const HeapRegionSetCount& removed) {
aoqi@0 190 _count.decrement(removed.length(), removed.capacity());
aoqi@0 191 }
aoqi@0 192 };
aoqi@0 193
aoqi@0 194 // A set that links all the regions added to it in a doubly-linked
tschatzl@7050 195 // sorted list. We should try to avoid doing operations that iterate over
aoqi@0 196 // such lists in performance critical paths. Typically we should
tschatzl@7050 197 // add / remove one region at a time or concatenate two lists.
aoqi@0 198
aoqi@0 199 class FreeRegionListIterator;
aoqi@0 200
aoqi@0 201 class FreeRegionList : public HeapRegionSetBase {
aoqi@0 202 friend class FreeRegionListIterator;
aoqi@0 203
aoqi@0 204 private:
aoqi@0 205 HeapRegion* _head;
aoqi@0 206 HeapRegion* _tail;
aoqi@0 207
aoqi@0 208 // _last is used to keep track of where we added an element the last
tschatzl@7050 209 // time. It helps to improve performance when adding several ordered items in a row.
aoqi@0 210 HeapRegion* _last;
aoqi@0 211
aoqi@0 212 static uint _unrealistically_long_length;
aoqi@0 213
tschatzl@7050 214 inline HeapRegion* remove_from_head_impl();
tschatzl@7050 215 inline HeapRegion* remove_from_tail_impl();
aoqi@0 216
aoqi@0 217 protected:
aoqi@0 218 virtual void fill_in_ext_msg_extra(hrs_ext_msg* msg);
aoqi@0 219
aoqi@0 220 // See the comment for HeapRegionSetBase::clear()
aoqi@0 221 virtual void clear();
aoqi@0 222
aoqi@0 223 public:
aoqi@0 224 FreeRegionList(const char* name, HRSMtSafeChecker* mt_safety_checker = NULL):
aoqi@0 225 HeapRegionSetBase(name, false /* humongous */, true /* empty */, mt_safety_checker) {
aoqi@0 226 clear();
aoqi@0 227 }
aoqi@0 228
aoqi@0 229 void verify_list();
aoqi@0 230
tschatzl@7050 231 #ifdef ASSERT
tschatzl@7050 232 bool contains(HeapRegion* hr) const {
tschatzl@7050 233 return hr->containing_set() == this;
tschatzl@7050 234 }
tschatzl@7050 235 #endif
aoqi@0 236
aoqi@0 237 static void set_unrealistically_long_length(uint len);
aoqi@0 238
aoqi@0 239 // Add hr to the list. The region should not be a member of another set.
aoqi@0 240 // Assumes that the list is ordered and will preserve that order. The order
tschatzl@7091 241 // is determined by hrm_index.
aoqi@0 242 inline void add_ordered(HeapRegion* hr);
aoqi@0 243
aoqi@0 244 // Removes from head or tail based on the given argument.
tschatzl@7050 245 HeapRegion* remove_region(bool from_head);
aoqi@0 246
aoqi@0 247 // Merge two ordered lists. The result is also ordered. The order is
tschatzl@7091 248 // determined by hrm_index.
aoqi@0 249 void add_ordered(FreeRegionList* from_list);
aoqi@0 250
aoqi@0 251 // It empties the list by removing all regions from it.
aoqi@0 252 void remove_all();
aoqi@0 253
tschatzl@7050 254 // Remove all (contiguous) regions from first to first + num_regions -1 from
tschatzl@7050 255 // this list.
tschatzl@7050 256 // Num_regions must be > 1.
tschatzl@7050 257 void remove_starting_at(HeapRegion* first, uint num_regions);
aoqi@0 258
aoqi@0 259 virtual void verify();
aoqi@0 260
aoqi@0 261 virtual void print_on(outputStream* out, bool print_contents = false);
aoqi@0 262 };
aoqi@0 263
aoqi@0 264 // Iterator class that provides a convenient way to iterate over the
tschatzl@7050 265 // regions of a FreeRegionList.
aoqi@0 266
aoqi@0 267 class FreeRegionListIterator : public StackObj {
aoqi@0 268 private:
aoqi@0 269 FreeRegionList* _list;
aoqi@0 270 HeapRegion* _curr;
aoqi@0 271
aoqi@0 272 public:
aoqi@0 273 bool more_available() {
aoqi@0 274 return _curr != NULL;
aoqi@0 275 }
aoqi@0 276
aoqi@0 277 HeapRegion* get_next() {
aoqi@0 278 assert(more_available(),
aoqi@0 279 "get_next() should be called when more regions are available");
aoqi@0 280
aoqi@0 281 // If we are going to introduce a count in the iterator we should
aoqi@0 282 // do the "cycle" check.
aoqi@0 283
aoqi@0 284 HeapRegion* hr = _curr;
aoqi@0 285 _list->verify_region(hr);
aoqi@0 286 _curr = hr->next();
aoqi@0 287 return hr;
aoqi@0 288 }
aoqi@0 289
aoqi@0 290 FreeRegionListIterator(FreeRegionList* list) : _curr(NULL), _list(list) {
tschatzl@7050 291 _curr = list->_head;
aoqi@0 292 }
aoqi@0 293 };
aoqi@0 294
aoqi@0 295 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_HPP

mercurial