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

Thu, 19 Jun 2014 13:31:14 +0200

author
brutisso
date
Thu, 19 Jun 2014 13:31:14 +0200
changeset 6904
0982ec23da03
parent 6680
78bbf4d43a14
child 6876
710a3c8b516e
child 7009
3f2894c5052e
permissions
-rw-r--r--

8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
Reviewed-by: jwilhelm, ehelin, tschatzl

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

mercurial