src/share/vm/gc_implementation/g1/heapRegionManager.cpp

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 /*
azakharov@7835 2 * Copyright (c) 2001, 2015, 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 #include "precompiled.hpp"
tonyp@2963 26 #include "gc_implementation/g1/heapRegion.hpp"
tschatzl@7091 27 #include "gc_implementation/g1/heapRegionManager.inline.hpp"
tschatzl@7050 28 #include "gc_implementation/g1/heapRegionSet.inline.hpp"
stefank@2314 29 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
tschatzl@7050 30 #include "gc_implementation/g1/concurrentG1Refine.hpp"
stefank@2314 31 #include "memory/allocation.hpp"
ysr@777 32
tschatzl@7091 33 void HeapRegionManager::initialize(G1RegionToSpaceMapper* heap_storage,
tschatzl@7051 34 G1RegionToSpaceMapper* prev_bitmap,
tschatzl@7051 35 G1RegionToSpaceMapper* next_bitmap,
tschatzl@7051 36 G1RegionToSpaceMapper* bot,
tschatzl@7051 37 G1RegionToSpaceMapper* cardtable,
tschatzl@7051 38 G1RegionToSpaceMapper* card_counts) {
tschatzl@7050 39 _allocated_heapregions_length = 0;
tschatzl@7050 40
tschatzl@7051 41 _heap_mapper = heap_storage;
tschatzl@7051 42
tschatzl@7051 43 _prev_bitmap_mapper = prev_bitmap;
tschatzl@7051 44 _next_bitmap_mapper = next_bitmap;
tschatzl@7051 45
tschatzl@7051 46 _bot_mapper = bot;
tschatzl@7051 47 _cardtable_mapper = cardtable;
tschatzl@7051 48
tschatzl@7051 49 _card_counts_mapper = card_counts;
tschatzl@7051 50
tschatzl@7051 51 MemRegion reserved = heap_storage->reserved();
tschatzl@7051 52 _regions.initialize(reserved.start(), reserved.end(), HeapRegion::GrainBytes);
tschatzl@7051 53
tschatzl@7051 54 _available_map.resize(_regions.length(), false);
tschatzl@7051 55 _available_map.clear();
tschatzl@7050 56 }
tschatzl@7050 57
tschatzl@7091 58 bool HeapRegionManager::is_available(uint region) const {
tschatzl@7051 59 return _available_map.at(region);
tschatzl@7050 60 }
tschatzl@7050 61
tschatzl@7050 62 #ifdef ASSERT
tschatzl@7091 63 bool HeapRegionManager::is_free(HeapRegion* hr) const {
tschatzl@7050 64 return _free_list.contains(hr);
tschatzl@7050 65 }
tschatzl@7050 66 #endif
tschatzl@7050 67
tschatzl@7091 68 HeapRegion* HeapRegionManager::new_heap_region(uint hrm_index) {
sjohanss@7131 69 G1CollectedHeap* g1h = G1CollectedHeap::heap();
sjohanss@7131 70 HeapWord* bottom = g1h->bottom_addr_for_region(hrm_index);
tschatzl@7050 71 MemRegion mr(bottom, bottom + HeapRegion::GrainWords);
tschatzl@7050 72 assert(reserved().contains(mr), "invariant");
sjohanss@7131 73 return g1h->allocator()->new_heap_region(hrm_index, g1h->bot_shared(), mr);
tschatzl@7050 74 }
tschatzl@7050 75
tschatzl@7091 76 void HeapRegionManager::commit_regions(uint index, size_t num_regions) {
tschatzl@7050 77 guarantee(num_regions > 0, "Must commit more than zero regions");
tschatzl@7050 78 guarantee(_num_committed + num_regions <= max_length(), "Cannot commit more than the maximum amount of regions");
tschatzl@7050 79
tschatzl@7051 80 _num_committed += (uint)num_regions;
tschatzl@7051 81
tschatzl@7051 82 _heap_mapper->commit_regions(index, num_regions);
tschatzl@7051 83
tschatzl@7051 84 // Also commit auxiliary data
tschatzl@7051 85 _prev_bitmap_mapper->commit_regions(index, num_regions);
tschatzl@7051 86 _next_bitmap_mapper->commit_regions(index, num_regions);
tschatzl@7051 87
tschatzl@7051 88 _bot_mapper->commit_regions(index, num_regions);
tschatzl@7051 89 _cardtable_mapper->commit_regions(index, num_regions);
tschatzl@7051 90
tschatzl@7051 91 _card_counts_mapper->commit_regions(index, num_regions);
tschatzl@7050 92 }
tschatzl@7050 93
tschatzl@7091 94 void HeapRegionManager::uncommit_regions(uint start, size_t num_regions) {
tschatzl@7051 95 guarantee(num_regions >= 1, err_msg("Need to specify at least one region to uncommit, tried to uncommit zero regions at %u", start));
tschatzl@7050 96 guarantee(_num_committed >= num_regions, "pre-condition");
tschatzl@7050 97
tschatzl@7050 98 // Print before uncommitting.
tschatzl@7050 99 if (G1CollectedHeap::heap()->hr_printer()->is_active()) {
tschatzl@7050 100 for (uint i = start; i < start + num_regions; i++) {
tschatzl@7050 101 HeapRegion* hr = at(i);
tschatzl@7050 102 G1CollectedHeap::heap()->hr_printer()->uncommit(hr->bottom(), hr->end());
tonyp@2472 103 }
tonyp@2472 104 }
tschatzl@7050 105
tschatzl@7050 106 _num_committed -= (uint)num_regions;
tschatzl@7050 107
tschatzl@7051 108 _available_map.par_clear_range(start, start + num_regions, BitMap::unknown_range);
tschatzl@7051 109 _heap_mapper->uncommit_regions(start, num_regions);
tschatzl@7051 110
tschatzl@7051 111 // Also uncommit auxiliary data
tschatzl@7051 112 _prev_bitmap_mapper->uncommit_regions(start, num_regions);
tschatzl@7051 113 _next_bitmap_mapper->uncommit_regions(start, num_regions);
tschatzl@7051 114
tschatzl@7051 115 _bot_mapper->uncommit_regions(start, num_regions);
tschatzl@7051 116 _cardtable_mapper->uncommit_regions(start, num_regions);
tschatzl@7051 117
tschatzl@7051 118 _card_counts_mapper->uncommit_regions(start, num_regions);
tschatzl@7050 119 }
tschatzl@7050 120
tschatzl@7091 121 void HeapRegionManager::make_regions_available(uint start, uint num_regions) {
tschatzl@7050 122 guarantee(num_regions > 0, "No point in calling this for zero regions");
tschatzl@7050 123 commit_regions(start, num_regions);
tschatzl@7050 124 for (uint i = start; i < start + num_regions; i++) {
tschatzl@7050 125 if (_regions.get_by_index(i) == NULL) {
tschatzl@7050 126 HeapRegion* new_hr = new_heap_region(i);
tschatzl@7050 127 _regions.set_by_index(i, new_hr);
tschatzl@7050 128 _allocated_heapregions_length = MAX2(_allocated_heapregions_length, i + 1);
tonyp@2472 129 }
tschatzl@7050 130 }
tschatzl@7050 131
tschatzl@7051 132 _available_map.par_set_range(start, start + num_regions, BitMap::unknown_range);
tschatzl@7050 133
tschatzl@7050 134 for (uint i = start; i < start + num_regions; i++) {
tschatzl@7050 135 assert(is_available(i), err_msg("Just made region %u available but is apparently not.", i));
tschatzl@7050 136 HeapRegion* hr = at(i);
tschatzl@7050 137 if (G1CollectedHeap::heap()->hr_printer()->is_active()) {
tschatzl@7050 138 G1CollectedHeap::heap()->hr_printer()->commit(hr->bottom(), hr->end());
tschatzl@7050 139 }
tschatzl@7050 140 HeapWord* bottom = G1CollectedHeap::heap()->bottom_addr_for_region(i);
tschatzl@7050 141 MemRegion mr(bottom, bottom + HeapRegion::GrainWords);
tschatzl@7050 142
tschatzl@7050 143 hr->initialize(mr);
tschatzl@7050 144 insert_into_free_list(at(i));
tonyp@2472 145 }
tonyp@2472 146 }
tonyp@2472 147
azakharov@7835 148 MemoryUsage HeapRegionManager::get_auxiliary_data_memory_usage() const {
azakharov@7835 149 size_t used_sz =
azakharov@7835 150 _prev_bitmap_mapper->committed_size() +
azakharov@7835 151 _next_bitmap_mapper->committed_size() +
azakharov@7835 152 _bot_mapper->committed_size() +
azakharov@7835 153 _cardtable_mapper->committed_size() +
azakharov@7835 154 _card_counts_mapper->committed_size();
azakharov@7835 155
azakharov@7835 156 size_t committed_sz =
azakharov@7835 157 _prev_bitmap_mapper->reserved_size() +
azakharov@7835 158 _next_bitmap_mapper->reserved_size() +
azakharov@7835 159 _bot_mapper->reserved_size() +
azakharov@7835 160 _cardtable_mapper->reserved_size() +
azakharov@7835 161 _card_counts_mapper->reserved_size();
azakharov@7835 162
azakharov@7835 163 return MemoryUsage(0, used_sz, committed_sz, committed_sz);
azakharov@7835 164 }
azakharov@7835 165
tschatzl@7091 166 uint HeapRegionManager::expand_by(uint num_regions) {
tschatzl@7051 167 return expand_at(0, num_regions);
tonyp@2963 168 }
tonyp@2963 169
tschatzl@7091 170 uint HeapRegionManager::expand_at(uint start, uint num_regions) {
tschatzl@7050 171 if (num_regions == 0) {
tschatzl@7050 172 return 0;
tschatzl@7050 173 }
tonyp@2963 174
tschatzl@7050 175 uint cur = start;
tschatzl@7050 176 uint idx_last_found = 0;
tschatzl@7050 177 uint num_last_found = 0;
tonyp@2963 178
tschatzl@7050 179 uint expanded = 0;
tonyp@2963 180
tschatzl@7050 181 while (expanded < num_regions &&
tschatzl@7050 182 (num_last_found = find_unavailable_from_idx(cur, &idx_last_found)) > 0) {
tschatzl@7050 183 uint to_expand = MIN2(num_regions - expanded, num_last_found);
tschatzl@7050 184 make_regions_available(idx_last_found, to_expand);
tschatzl@7050 185 expanded += to_expand;
tschatzl@7050 186 cur = idx_last_found + num_last_found + 1;
tschatzl@7050 187 }
tonyp@2963 188
tschatzl@7050 189 verify_optional();
tschatzl@7050 190 return expanded;
tonyp@2963 191 }
tonyp@2963 192
tschatzl@7091 193 uint HeapRegionManager::find_contiguous(size_t num, bool empty_only) {
tschatzl@7050 194 uint found = 0;
tschatzl@7050 195 size_t length_found = 0;
tschatzl@7050 196 uint cur = 0;
tschatzl@7050 197
tschatzl@7050 198 while (length_found < num && cur < max_length()) {
tschatzl@7050 199 HeapRegion* hr = _regions.get_by_index(cur);
tschatzl@7050 200 if ((!empty_only && !is_available(cur)) || (is_available(cur) && hr != NULL && hr->is_empty())) {
tschatzl@7050 201 // This region is a potential candidate for allocation into.
tschatzl@7050 202 length_found++;
tschatzl@7050 203 } else {
tschatzl@7050 204 // This region is not a candidate. The next region is the next possible one.
tschatzl@7050 205 found = cur + 1;
tschatzl@7050 206 length_found = 0;
tonyp@2963 207 }
tschatzl@7050 208 cur++;
tonyp@2472 209 }
tschatzl@7050 210
tschatzl@7050 211 if (length_found == num) {
tschatzl@7050 212 for (uint i = found; i < (found + num); i++) {
tschatzl@7050 213 HeapRegion* hr = _regions.get_by_index(i);
tschatzl@7050 214 // sanity check
tschatzl@7050 215 guarantee((!empty_only && !is_available(i)) || (is_available(i) && hr != NULL && hr->is_empty()),
tschatzl@7050 216 err_msg("Found region sequence starting at " UINT32_FORMAT ", length " SIZE_FORMAT
tschatzl@7050 217 " that is not empty at " UINT32_FORMAT ". Hr is " PTR_FORMAT, found, num, i, p2i(hr)));
tschatzl@7050 218 }
tschatzl@7050 219 return found;
tschatzl@7050 220 } else {
tschatzl@7091 221 return G1_NO_HRM_INDEX;
tschatzl@7050 222 }
ysr@777 223 }
ysr@777 224
tschatzl@7091 225 HeapRegion* HeapRegionManager::next_region_in_heap(const HeapRegion* r) const {
tschatzl@7050 226 guarantee(r != NULL, "Start region must be a valid region");
tschatzl@7091 227 guarantee(is_available(r->hrm_index()), err_msg("Trying to iterate starting from region %u which is not in the heap", r->hrm_index()));
tschatzl@7091 228 for (uint i = r->hrm_index() + 1; i < _allocated_heapregions_length; i++) {
tschatzl@7050 229 HeapRegion* hr = _regions.get_by_index(i);
tschatzl@7050 230 if (is_available(i)) {
tschatzl@7050 231 return hr;
tschatzl@7050 232 }
tonyp@2963 233 }
tschatzl@7050 234 return NULL;
ysr@777 235 }
ysr@777 236
tschatzl@7091 237 void HeapRegionManager::iterate(HeapRegionClosure* blk) const {
tschatzl@7050 238 uint len = max_length();
ysr@777 239
tschatzl@7050 240 for (uint i = 0; i < len; i++) {
tschatzl@7050 241 if (!is_available(i)) {
tschatzl@7050 242 continue;
ysr@777 243 }
tschatzl@7050 244 guarantee(at(i) != NULL, err_msg("Tried to access region %u that has a NULL HeapRegion*", i));
tonyp@2963 245 bool res = blk->doHeapRegion(at(i));
ysr@777 246 if (res) {
ysr@777 247 blk->incomplete();
ysr@777 248 return;
ysr@777 249 }
ysr@777 250 }
ysr@777 251 }
ysr@777 252
tschatzl@7091 253 uint HeapRegionManager::find_unavailable_from_idx(uint start_idx, uint* res_idx) const {
tschatzl@7050 254 guarantee(res_idx != NULL, "checking");
tschatzl@7050 255 guarantee(start_idx <= (max_length() + 1), "checking");
tschatzl@7050 256
tschatzl@7050 257 uint num_regions = 0;
tschatzl@7050 258
tschatzl@7050 259 uint cur = start_idx;
tschatzl@7050 260 while (cur < max_length() && is_available(cur)) {
tschatzl@7050 261 cur++;
tschatzl@7050 262 }
tschatzl@7050 263 if (cur == max_length()) {
tschatzl@7050 264 return num_regions;
tschatzl@7050 265 }
tschatzl@7050 266 *res_idx = cur;
tschatzl@7050 267 while (cur < max_length() && !is_available(cur)) {
tschatzl@7050 268 cur++;
tschatzl@7050 269 }
tschatzl@7050 270 num_regions = cur - *res_idx;
tschatzl@7050 271 #ifdef ASSERT
tschatzl@7050 272 for (uint i = *res_idx; i < (*res_idx + num_regions); i++) {
tschatzl@7050 273 assert(!is_available(i), "just checking");
tschatzl@7050 274 }
tschatzl@7050 275 assert(cur == max_length() || num_regions == 0 || is_available(cur),
tschatzl@7050 276 err_msg("The region at the current position %u must be available or at the end of the heap.", cur));
tschatzl@7050 277 #endif
tschatzl@7050 278 return num_regions;
tschatzl@7050 279 }
tschatzl@7050 280
tschatzl@7091 281 uint HeapRegionManager::start_region_for_worker(uint worker_i, uint num_workers, uint num_regions) const {
tschatzl@7050 282 return num_regions * worker_i / num_workers;
tschatzl@7050 283 }
tschatzl@7050 284
tschatzl@7091 285 void HeapRegionManager::par_iterate(HeapRegionClosure* blk, uint worker_id, uint num_workers, jint claim_value) const {
tschatzl@7050 286 const uint start_index = start_region_for_worker(worker_id, num_workers, _allocated_heapregions_length);
tschatzl@7050 287
tschatzl@7050 288 // Every worker will actually look at all regions, skipping over regions that
tschatzl@7050 289 // are currently not committed.
tschatzl@7050 290 // This also (potentially) iterates over regions newly allocated during GC. This
tschatzl@7050 291 // is no problem except for some extra work.
tschatzl@7050 292 for (uint count = 0; count < _allocated_heapregions_length; count++) {
tschatzl@7050 293 const uint index = (start_index + count) % _allocated_heapregions_length;
tschatzl@7050 294 assert(0 <= index && index < _allocated_heapregions_length, "sanity");
tschatzl@7050 295 // Skip over unavailable regions
tschatzl@7050 296 if (!is_available(index)) {
tschatzl@7050 297 continue;
tschatzl@7050 298 }
tschatzl@7050 299 HeapRegion* r = _regions.get_by_index(index);
tschatzl@7050 300 // We'll ignore "continues humongous" regions (we'll process them
tschatzl@7050 301 // when we come across their corresponding "start humongous"
tschatzl@7050 302 // region) and regions already claimed.
tschatzl@7050 303 if (r->claim_value() == claim_value || r->continuesHumongous()) {
tschatzl@7050 304 continue;
tschatzl@7050 305 }
tschatzl@7050 306 // OK, try to claim it
tschatzl@7050 307 if (!r->claimHeapRegion(claim_value)) {
tschatzl@7050 308 continue;
tschatzl@7050 309 }
tschatzl@7050 310 // Success!
tschatzl@7050 311 if (r->startsHumongous()) {
tschatzl@7050 312 // If the region is "starts humongous" we'll iterate over its
tschatzl@7050 313 // "continues humongous" first; in fact we'll do them
tschatzl@7050 314 // first. The order is important. In one case, calling the
tschatzl@7050 315 // closure on the "starts humongous" region might de-allocate
tschatzl@7050 316 // and clear all its "continues humongous" regions and, as a
tschatzl@7050 317 // result, we might end up processing them twice. So, we'll do
tschatzl@7050 318 // them first (note: most closures will ignore them anyway) and
tschatzl@7050 319 // then we'll do the "starts humongous" region.
tschatzl@7050 320 for (uint ch_index = index + 1; ch_index < index + r->region_num(); ch_index++) {
tschatzl@7050 321 HeapRegion* chr = _regions.get_by_index(ch_index);
tschatzl@7050 322
tschatzl@7050 323 assert(chr->continuesHumongous(), "Must be humongous region");
tschatzl@7050 324 assert(chr->humongous_start_region() == r,
tschatzl@7050 325 err_msg("Must work on humongous continuation of the original start region "
tschatzl@7050 326 PTR_FORMAT ", but is " PTR_FORMAT, p2i(r), p2i(chr)));
tschatzl@7050 327 assert(chr->claim_value() != claim_value,
tschatzl@7050 328 "Must not have been claimed yet because claiming of humongous continuation first claims the start region");
tschatzl@7050 329
tschatzl@7050 330 bool claim_result = chr->claimHeapRegion(claim_value);
tschatzl@7050 331 // We should always be able to claim it; no one else should
tschatzl@7050 332 // be trying to claim this region.
tschatzl@7050 333 guarantee(claim_result, "We should always be able to claim the continuesHumongous part of the humongous object");
tschatzl@7050 334
tschatzl@7050 335 bool res2 = blk->doHeapRegion(chr);
tschatzl@7050 336 if (res2) {
tschatzl@7050 337 return;
tschatzl@7050 338 }
tschatzl@7050 339
tschatzl@7050 340 // Right now, this holds (i.e., no closure that actually
tschatzl@7050 341 // does something with "continues humongous" regions
tschatzl@7050 342 // clears them). We might have to weaken it in the future,
tschatzl@7050 343 // but let's leave these two asserts here for extra safety.
tschatzl@7050 344 assert(chr->continuesHumongous(), "should still be the case");
tschatzl@7050 345 assert(chr->humongous_start_region() == r, "sanity");
tschatzl@7050 346 }
tschatzl@7050 347 }
tschatzl@7050 348
tschatzl@7050 349 bool res = blk->doHeapRegion(r);
tschatzl@7050 350 if (res) {
tschatzl@7050 351 return;
tschatzl@7050 352 }
tschatzl@7050 353 }
tschatzl@7050 354 }
tschatzl@7050 355
tschatzl@7091 356 uint HeapRegionManager::shrink_by(uint num_regions_to_remove) {
tonyp@2963 357 assert(length() > 0, "the region sequence should not be empty");
tschatzl@7050 358 assert(length() <= _allocated_heapregions_length, "invariant");
tschatzl@7050 359 assert(_allocated_heapregions_length > 0, "we should have at least one region committed");
brutisso@5074 360 assert(num_regions_to_remove < length(), "We should never remove all regions");
ysr@777 361
tschatzl@7050 362 if (num_regions_to_remove == 0) {
tschatzl@7050 363 return 0;
tschatzl@7050 364 }
tonyp@2963 365
tschatzl@7050 366 uint removed = 0;
tschatzl@7050 367 uint cur = _allocated_heapregions_length - 1;
tschatzl@7050 368 uint idx_last_found = 0;
tschatzl@7050 369 uint num_last_found = 0;
tschatzl@7050 370
tschatzl@7051 371 while ((removed < num_regions_to_remove) &&
tschatzl@7051 372 (num_last_found = find_empty_from_idx_reverse(cur, &idx_last_found)) > 0) {
tschatzl@7050 373 uint to_remove = MIN2(num_regions_to_remove - removed, num_last_found);
tschatzl@7050 374
tschatzl@7050 375 uncommit_regions(idx_last_found + num_last_found - to_remove, to_remove);
tschatzl@7050 376
tschatzl@7050 377 cur -= num_last_found;
tschatzl@7050 378 removed += to_remove;
ysr@777 379 }
brutisso@5074 380
tschatzl@7050 381 verify_optional();
tschatzl@7050 382
tschatzl@7050 383 return removed;
ysr@777 384 }
ysr@777 385
tschatzl@7091 386 uint HeapRegionManager::find_empty_from_idx_reverse(uint start_idx, uint* res_idx) const {
tschatzl@7050 387 guarantee(start_idx < _allocated_heapregions_length, "checking");
tschatzl@7050 388 guarantee(res_idx != NULL, "checking");
tschatzl@7050 389
tschatzl@7050 390 uint num_regions_found = 0;
tschatzl@7050 391
tschatzl@7050 392 jlong cur = start_idx;
tschatzl@7050 393 while (cur != -1 && !(is_available(cur) && at(cur)->is_empty())) {
tschatzl@7050 394 cur--;
tschatzl@7050 395 }
tschatzl@7050 396 if (cur == -1) {
tschatzl@7050 397 return num_regions_found;
tschatzl@7050 398 }
tschatzl@7050 399 jlong old_cur = cur;
tschatzl@7050 400 // cur indexes the first empty region
tschatzl@7050 401 while (cur != -1 && is_available(cur) && at(cur)->is_empty()) {
tschatzl@7050 402 cur--;
tschatzl@7050 403 }
tschatzl@7050 404 *res_idx = cur + 1;
tschatzl@7050 405 num_regions_found = old_cur - cur;
tschatzl@7050 406
tschatzl@7050 407 #ifdef ASSERT
tschatzl@7050 408 for (uint i = *res_idx; i < (*res_idx + num_regions_found); i++) {
tschatzl@7050 409 assert(at(i)->is_empty(), "just checking");
tschatzl@7050 410 }
tschatzl@7050 411 #endif
tschatzl@7050 412 return num_regions_found;
tschatzl@7050 413 }
tschatzl@7050 414
tschatzl@7091 415 void HeapRegionManager::verify() {
tschatzl@7050 416 guarantee(length() <= _allocated_heapregions_length,
tonyp@3713 417 err_msg("invariant: _length: %u _allocated_length: %u",
tschatzl@7050 418 length(), _allocated_heapregions_length));
tschatzl@7050 419 guarantee(_allocated_heapregions_length <= max_length(),
tonyp@3713 420 err_msg("invariant: _allocated_length: %u _max_length: %u",
tschatzl@7050 421 _allocated_heapregions_length, max_length()));
tonyp@2963 422
tschatzl@7050 423 bool prev_committed = true;
tschatzl@7050 424 uint num_committed = 0;
tschatzl@5773 425 HeapWord* prev_end = heap_bottom();
tschatzl@7050 426 for (uint i = 0; i < _allocated_heapregions_length; i++) {
tschatzl@7050 427 if (!is_available(i)) {
tschatzl@7050 428 prev_committed = false;
tschatzl@7050 429 continue;
tschatzl@7050 430 }
tschatzl@7050 431 num_committed++;
tschatzl@5773 432 HeapRegion* hr = _regions.get_by_index(i);
tonyp@3713 433 guarantee(hr != NULL, err_msg("invariant: i: %u", i));
tschatzl@7050 434 guarantee(!prev_committed || hr->bottom() == prev_end,
kevinw@9327 435 err_msg("invariant i: %u " HR_FORMAT " prev_end: " PTR_FORMAT,
drchase@6680 436 i, HR_FORMAT_PARAMS(hr), p2i(prev_end)));
tschatzl@7091 437 guarantee(hr->hrm_index() == i,
tschatzl@7091 438 err_msg("invariant: i: %u hrm_index(): %u", i, hr->hrm_index()));
tschatzl@7050 439 // Asserts will fire if i is >= _length
tschatzl@7050 440 HeapWord* addr = hr->bottom();
tschatzl@7050 441 guarantee(addr_to_region(addr) == hr, "sanity");
tschatzl@7050 442 // We cannot check whether the region is part of a particular set: at the time
tschatzl@7050 443 // this method may be called, we have only completed allocation of the regions,
tschatzl@7050 444 // but not put into a region set.
tschatzl@7050 445 prev_committed = true;
tonyp@2963 446 if (hr->startsHumongous()) {
tonyp@2963 447 prev_end = hr->orig_end();
tonyp@2963 448 } else {
tonyp@2963 449 prev_end = hr->end();
tonyp@2963 450 }
ysr@777 451 }
tschatzl@7050 452 for (uint i = _allocated_heapregions_length; i < max_length(); i++) {
tschatzl@5773 453 guarantee(_regions.get_by_index(i) == NULL, err_msg("invariant i: %u", i));
tonyp@2963 454 }
tschatzl@7050 455
tschatzl@7050 456 guarantee(num_committed == _num_committed, err_msg("Found %u committed regions, but should be %u", num_committed, _num_committed));
tschatzl@7050 457 _free_list.verify();
tschatzl@7050 458 }
tschatzl@7050 459
tschatzl@7050 460 #ifndef PRODUCT
tschatzl@7091 461 void HeapRegionManager::verify_optional() {
tschatzl@7050 462 verify();
ysr@777 463 }
tonyp@2963 464 #endif // PRODUCT
tschatzl@7050 465

mercurial