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

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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;
aoqi@0 84 bool _is_empty;
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
aoqi@0 105 // Indicates whether all regions in the set should be empty or
aoqi@0 106 // not. Only used during verification.
aoqi@0 107 bool regions_empty() { return _is_empty; }
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
aoqi@0 117 HeapRegionSetBase(const char* name, bool humongous, bool empty, HRSMtSafeChecker* mt_safety_checker);
aoqi@0 118
aoqi@0 119 public:
aoqi@0 120 const char* name() { return _name; }
aoqi@0 121
aoqi@0 122 uint length() { 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:
aoqi@0 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()) && \
aoqi@0 174 ((_set1_)->regions_empty() == (_set2_)->regions_empty()), \
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):
aoqi@0 187 HeapRegionSetBase(name, humongous, false /* empty */, 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
aoqi@0 195 // list. We should try to avoid doing operations that iterate over
aoqi@0 196 // such lists in performance critical paths. Typically we should
aoqi@0 197 // add / remove one region at a time or concatenate two lists. There are
aoqi@0 198 // two ways to treat your lists, ordered and un-ordered. All un-ordered
aoqi@0 199 // operations are done in constant time. To keep a list ordered only use
aoqi@0 200 // add_ordered() to add elements to the list. If a list is not ordered
aoqi@0 201 // from start, there is no way to sort it later.
aoqi@0 202
aoqi@0 203 class FreeRegionListIterator;
aoqi@0 204
aoqi@0 205 class FreeRegionList : public HeapRegionSetBase {
aoqi@0 206 friend class FreeRegionListIterator;
aoqi@0 207
aoqi@0 208 private:
aoqi@0 209 HeapRegion* _head;
aoqi@0 210 HeapRegion* _tail;
aoqi@0 211
aoqi@0 212 // _last is used to keep track of where we added an element the last
aoqi@0 213 // time in ordered lists. It helps to improve performance when adding
aoqi@0 214 // several ordered items in a row.
aoqi@0 215 HeapRegion* _last;
aoqi@0 216
aoqi@0 217 static uint _unrealistically_long_length;
aoqi@0 218
aoqi@0 219 void add_as_head_or_tail(FreeRegionList* from_list, bool as_head);
aoqi@0 220
aoqi@0 221 protected:
aoqi@0 222 virtual void fill_in_ext_msg_extra(hrs_ext_msg* msg);
aoqi@0 223
aoqi@0 224 // See the comment for HeapRegionSetBase::clear()
aoqi@0 225 virtual void clear();
aoqi@0 226
aoqi@0 227 public:
aoqi@0 228 FreeRegionList(const char* name, HRSMtSafeChecker* mt_safety_checker = NULL):
aoqi@0 229 HeapRegionSetBase(name, false /* humongous */, true /* empty */, mt_safety_checker) {
aoqi@0 230 clear();
aoqi@0 231 }
aoqi@0 232
aoqi@0 233 void verify_list();
aoqi@0 234
aoqi@0 235 HeapRegion* head() { return _head; }
aoqi@0 236 HeapRegion* tail() { return _tail; }
aoqi@0 237
aoqi@0 238 static void set_unrealistically_long_length(uint len);
aoqi@0 239
aoqi@0 240 // Add hr to the list. The region should not be a member of another set.
aoqi@0 241 // Assumes that the list is ordered and will preserve that order. The order
aoqi@0 242 // is determined by hrs_index.
aoqi@0 243 inline void add_ordered(HeapRegion* hr);
aoqi@0 244
aoqi@0 245 // It adds hr to the list as the new head. The region should not be
aoqi@0 246 // a member of another set.
aoqi@0 247 inline void add_as_head(HeapRegion* hr);
aoqi@0 248
aoqi@0 249 // It adds hr to the list as the new tail. The region should not be
aoqi@0 250 // a member of another set.
aoqi@0 251 inline void add_as_tail(HeapRegion* hr);
aoqi@0 252
aoqi@0 253 // It removes and returns the head of the list. It assumes that the
aoqi@0 254 // list is not empty so it will return a non-NULL value.
aoqi@0 255 inline HeapRegion* remove_head();
aoqi@0 256
aoqi@0 257 // Convenience method.
aoqi@0 258 inline HeapRegion* remove_head_or_null();
aoqi@0 259
aoqi@0 260 // Removes and returns the last element (_tail) of the list. It assumes
aoqi@0 261 // that the list isn't empty so that it can return a non-NULL value.
aoqi@0 262 inline HeapRegion* remove_tail();
aoqi@0 263
aoqi@0 264 // Convenience method
aoqi@0 265 inline HeapRegion* remove_tail_or_null();
aoqi@0 266
aoqi@0 267 // Removes from head or tail based on the given argument.
aoqi@0 268 inline HeapRegion* remove_region(bool from_head);
aoqi@0 269
aoqi@0 270 // Merge two ordered lists. The result is also ordered. The order is
aoqi@0 271 // determined by hrs_index.
aoqi@0 272 void add_ordered(FreeRegionList* from_list);
aoqi@0 273
aoqi@0 274 // It moves the regions from from_list to this list and empties
aoqi@0 275 // from_list. The new regions will appear in the same order as they
aoqi@0 276 // were in from_list and be linked in the beginning of this list.
aoqi@0 277 void add_as_head(FreeRegionList* from_list);
aoqi@0 278
aoqi@0 279 // It moves the regions from from_list to this list and empties
aoqi@0 280 // from_list. The new regions will appear in the same order as they
aoqi@0 281 // were in from_list and be linked in the end of this list.
aoqi@0 282 void add_as_tail(FreeRegionList* from_list);
aoqi@0 283
aoqi@0 284 // It empties the list by removing all regions from it.
aoqi@0 285 void remove_all();
aoqi@0 286
aoqi@0 287 // It removes all regions in the list that are pending for removal
aoqi@0 288 // (i.e., they have been tagged with "pending_removal"). The list
aoqi@0 289 // must not be empty, target_count should reflect the exact number
aoqi@0 290 // of regions that are pending for removal in the list, and
aoqi@0 291 // target_count should be > 1 (currently, we never need to remove a
aoqi@0 292 // single region using this).
aoqi@0 293 void remove_all_pending(uint target_count);
aoqi@0 294
aoqi@0 295 virtual void verify();
aoqi@0 296
aoqi@0 297 virtual void print_on(outputStream* out, bool print_contents = false);
aoqi@0 298 };
aoqi@0 299
aoqi@0 300 // Iterator class that provides a convenient way to iterate over the
aoqi@0 301 // regions of a HeapRegionLinkedList instance.
aoqi@0 302
aoqi@0 303 class FreeRegionListIterator : public StackObj {
aoqi@0 304 private:
aoqi@0 305 FreeRegionList* _list;
aoqi@0 306 HeapRegion* _curr;
aoqi@0 307
aoqi@0 308 public:
aoqi@0 309 bool more_available() {
aoqi@0 310 return _curr != NULL;
aoqi@0 311 }
aoqi@0 312
aoqi@0 313 HeapRegion* get_next() {
aoqi@0 314 assert(more_available(),
aoqi@0 315 "get_next() should be called when more regions are available");
aoqi@0 316
aoqi@0 317 // If we are going to introduce a count in the iterator we should
aoqi@0 318 // do the "cycle" check.
aoqi@0 319
aoqi@0 320 HeapRegion* hr = _curr;
aoqi@0 321 _list->verify_region(hr);
aoqi@0 322 _curr = hr->next();
aoqi@0 323 return hr;
aoqi@0 324 }
aoqi@0 325
aoqi@0 326 FreeRegionListIterator(FreeRegionList* list) : _curr(NULL), _list(list) {
aoqi@0 327 _curr = list->head();
aoqi@0 328 }
aoqi@0 329 };
aoqi@0 330
aoqi@0 331 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_HPP

mercurial