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

Tue, 17 Oct 2017 12:58:25 +0800

author
aoqi
date
Tue, 17 Oct 2017 12:58:25 +0800
changeset 7994
04ff2f6cd0eb
parent 7990
1f646daf0d67
parent 7535
7ae4e26cb1e0
child 8604
04d83ba48607
permissions
-rw-r--r--

merge

aoqi@0 1 /*
tschatzl@7654 2 * Copyright (c) 2001, 2015, 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 #include "precompiled.hpp"
aoqi@0 26 #include "code/nmethod.hpp"
aoqi@0 27 #include "gc_implementation/g1/g1BlockOffsetTable.inline.hpp"
aoqi@0 28 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
aoqi@0 29 #include "gc_implementation/g1/g1OopClosures.inline.hpp"
aoqi@0 30 #include "gc_implementation/g1/heapRegion.inline.hpp"
sjohanss@7137 31 #include "gc_implementation/g1/heapRegionBounds.inline.hpp"
aoqi@0 32 #include "gc_implementation/g1/heapRegionRemSet.hpp"
tschatzl@7091 33 #include "gc_implementation/g1/heapRegionManager.inline.hpp"
mgerdin@6990 34 #include "gc_implementation/shared/liveRange.hpp"
aoqi@0 35 #include "memory/genOopClosures.inline.hpp"
aoqi@0 36 #include "memory/iterator.hpp"
goetz@6912 37 #include "memory/space.inline.hpp"
aoqi@0 38 #include "oops/oop.inline.hpp"
goetz@6911 39 #include "runtime/orderAccess.inline.hpp"
aoqi@0 40
aoqi@0 41 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
aoqi@0 42
aoqi@0 43 int HeapRegion::LogOfHRGrainBytes = 0;
aoqi@0 44 int HeapRegion::LogOfHRGrainWords = 0;
aoqi@0 45 size_t HeapRegion::GrainBytes = 0;
aoqi@0 46 size_t HeapRegion::GrainWords = 0;
aoqi@0 47 size_t HeapRegion::CardsPerRegion = 0;
aoqi@0 48
aoqi@0 49 HeapRegionDCTOC::HeapRegionDCTOC(G1CollectedHeap* g1,
mgerdin@7971 50 HeapRegion* hr,
mgerdin@7971 51 G1ParPushHeapRSClosure* cl,
mgerdin@7971 52 CardTableModRefBS::PrecisionStyle precision) :
mgerdin@6986 53 DirtyCardToOopClosure(hr, cl, precision, NULL),
mgerdin@7971 54 _hr(hr), _rs_scan(cl), _g1(g1) { }
aoqi@0 55
aoqi@0 56 FilterOutOfRegionClosure::FilterOutOfRegionClosure(HeapRegion* r,
aoqi@0 57 OopClosure* oc) :
aoqi@0 58 _r_bottom(r->bottom()), _r_end(r->end()), _oc(oc) { }
aoqi@0 59
mgerdin@6986 60 void HeapRegionDCTOC::walk_mem_region(MemRegion mr,
mgerdin@6986 61 HeapWord* bottom,
mgerdin@6986 62 HeapWord* top) {
aoqi@0 63 G1CollectedHeap* g1h = _g1;
mgerdin@6990 64 size_t oop_size;
mgerdin@7971 65 HeapWord* cur = bottom;
aoqi@0 66
aoqi@0 67 // Start filtering what we add to the remembered set. If the object is
aoqi@0 68 // not considered dead, either because it is marked (in the mark bitmap)
aoqi@0 69 // or it was allocated after marking finished, then we add it. Otherwise
aoqi@0 70 // we can safely ignore the object.
mgerdin@7971 71 if (!g1h->is_obj_dead(oop(cur), _hr)) {
mgerdin@7971 72 oop_size = oop(cur)->oop_iterate(_rs_scan, mr);
aoqi@0 73 } else {
mgerdin@7971 74 oop_size = _hr->block_size(cur);
aoqi@0 75 }
aoqi@0 76
mgerdin@7971 77 cur += oop_size;
aoqi@0 78
mgerdin@7971 79 if (cur < top) {
mgerdin@7971 80 oop cur_oop = oop(cur);
mgerdin@7971 81 oop_size = _hr->block_size(cur);
mgerdin@7971 82 HeapWord* next_obj = cur + oop_size;
mgerdin@7971 83 while (next_obj < top) {
mgerdin@7971 84 // Keep filtering the remembered set.
mgerdin@7971 85 if (!g1h->is_obj_dead(cur_oop, _hr)) {
mgerdin@7971 86 // Bottom lies entirely below top, so we can call the
mgerdin@7971 87 // non-memRegion version of oop_iterate below.
mgerdin@7971 88 cur_oop->oop_iterate(_rs_scan);
mgerdin@7971 89 }
mgerdin@7971 90 cur = next_obj;
mgerdin@7971 91 cur_oop = oop(cur);
mgerdin@7971 92 oop_size = _hr->block_size(cur);
mgerdin@7971 93 next_obj = cur + oop_size;
aoqi@0 94 }
aoqi@0 95
aoqi@0 96 // Last object. Need to do dead-obj filtering here too.
mgerdin@7971 97 if (!g1h->is_obj_dead(oop(cur), _hr)) {
mgerdin@7971 98 oop(cur)->oop_iterate(_rs_scan, mr);
aoqi@0 99 }
aoqi@0 100 }
aoqi@0 101 }
aoqi@0 102
aoqi@0 103 size_t HeapRegion::max_region_size() {
sjohanss@7137 104 return HeapRegionBounds::max_size();
aoqi@0 105 }
aoqi@0 106
aoqi@0 107 void HeapRegion::setup_heap_region_size(size_t initial_heap_size, size_t max_heap_size) {
aoqi@0 108 uintx region_size = G1HeapRegionSize;
aoqi@0 109 if (FLAG_IS_DEFAULT(G1HeapRegionSize)) {
aoqi@0 110 size_t average_heap_size = (initial_heap_size + max_heap_size) / 2;
sjohanss@7137 111 region_size = MAX2(average_heap_size / HeapRegionBounds::target_number(),
sjohanss@7137 112 (uintx) HeapRegionBounds::min_size());
aoqi@0 113 }
aoqi@0 114
aoqi@0 115 int region_size_log = log2_long((jlong) region_size);
aoqi@0 116 // Recalculate the region size to make sure it's a power of
aoqi@0 117 // 2. This means that region_size is the largest power of 2 that's
aoqi@0 118 // <= what we've calculated so far.
aoqi@0 119 region_size = ((uintx)1 << region_size_log);
aoqi@0 120
aoqi@0 121 // Now make sure that we don't go over or under our limits.
sjohanss@7137 122 if (region_size < HeapRegionBounds::min_size()) {
sjohanss@7137 123 region_size = HeapRegionBounds::min_size();
sjohanss@7137 124 } else if (region_size > HeapRegionBounds::max_size()) {
sjohanss@7137 125 region_size = HeapRegionBounds::max_size();
aoqi@0 126 }
aoqi@0 127
aoqi@0 128 // And recalculate the log.
aoqi@0 129 region_size_log = log2_long((jlong) region_size);
aoqi@0 130
aoqi@0 131 // Now, set up the globals.
aoqi@0 132 guarantee(LogOfHRGrainBytes == 0, "we should only set it once");
aoqi@0 133 LogOfHRGrainBytes = region_size_log;
aoqi@0 134
aoqi@0 135 guarantee(LogOfHRGrainWords == 0, "we should only set it once");
aoqi@0 136 LogOfHRGrainWords = LogOfHRGrainBytes - LogHeapWordSize;
aoqi@0 137
aoqi@0 138 guarantee(GrainBytes == 0, "we should only set it once");
aoqi@0 139 // The cast to int is safe, given that we've bounded region_size by
aoqi@0 140 // MIN_REGION_SIZE and MAX_REGION_SIZE.
aoqi@0 141 GrainBytes = (size_t)region_size;
aoqi@0 142
aoqi@0 143 guarantee(GrainWords == 0, "we should only set it once");
aoqi@0 144 GrainWords = GrainBytes >> LogHeapWordSize;
aoqi@0 145 guarantee((size_t) 1 << LogOfHRGrainWords == GrainWords, "sanity");
aoqi@0 146
aoqi@0 147 guarantee(CardsPerRegion == 0, "we should only set it once");
aoqi@0 148 CardsPerRegion = GrainBytes >> CardTableModRefBS::card_shift;
aoqi@0 149 }
aoqi@0 150
aoqi@0 151 void HeapRegion::reset_after_compaction() {
aoqi@0 152 G1OffsetTableContigSpace::reset_after_compaction();
aoqi@0 153 // After a compaction the mark bitmap is invalid, so we must
aoqi@0 154 // treat all objects as being inside the unmarked area.
aoqi@0 155 zero_marked_bytes();
aoqi@0 156 init_top_at_mark_start();
aoqi@0 157 }
aoqi@0 158
aoqi@0 159 void HeapRegion::hr_clear(bool par, bool clear_space, bool locked) {
aoqi@0 160 assert(_humongous_start_region == NULL,
aoqi@0 161 "we should have already filtered out humongous regions");
aoqi@0 162 assert(_end == _orig_end,
aoqi@0 163 "we should have already filtered out humongous regions");
aoqi@0 164
aoqi@0 165 _in_collection_set = false;
aoqi@0 166
sjohanss@7118 167 set_allocation_context(AllocationContext::system());
aoqi@0 168 set_young_index_in_cset(-1);
aoqi@0 169 uninstall_surv_rate_group();
brutisso@7195 170 set_free();
aoqi@0 171 reset_pre_dummy_top();
aoqi@0 172
aoqi@0 173 if (!par) {
aoqi@0 174 // If this is parallel, this will be done later.
aoqi@0 175 HeapRegionRemSet* hrrs = rem_set();
aoqi@0 176 if (locked) {
aoqi@0 177 hrrs->clear_locked();
aoqi@0 178 } else {
aoqi@0 179 hrrs->clear();
aoqi@0 180 }
aoqi@0 181 _claimed = InitialClaimValue;
aoqi@0 182 }
aoqi@0 183 zero_marked_bytes();
aoqi@0 184
aoqi@0 185 _offsets.resize(HeapRegion::GrainWords);
aoqi@0 186 init_top_at_mark_start();
aoqi@0 187 if (clear_space) clear(SpaceDecorator::Mangle);
aoqi@0 188 }
aoqi@0 189
aoqi@0 190 void HeapRegion::par_clear() {
aoqi@0 191 assert(used() == 0, "the region should have been already cleared");
aoqi@0 192 assert(capacity() == HeapRegion::GrainBytes, "should be back to normal");
aoqi@0 193 HeapRegionRemSet* hrrs = rem_set();
aoqi@0 194 hrrs->clear();
aoqi@0 195 CardTableModRefBS* ct_bs =
aoqi@0 196 (CardTableModRefBS*)G1CollectedHeap::heap()->barrier_set();
aoqi@0 197 ct_bs->clear(MemRegion(bottom(), end()));
aoqi@0 198 }
aoqi@0 199
aoqi@0 200 void HeapRegion::calc_gc_efficiency() {
aoqi@0 201 // GC efficiency is the ratio of how much space would be
aoqi@0 202 // reclaimed over how long we predict it would take to reclaim it.
aoqi@0 203 G1CollectedHeap* g1h = G1CollectedHeap::heap();
aoqi@0 204 G1CollectorPolicy* g1p = g1h->g1_policy();
aoqi@0 205
aoqi@0 206 // Retrieve a prediction of the elapsed time for this region for
aoqi@0 207 // a mixed gc because the region will only be evacuated during a
aoqi@0 208 // mixed gc.
aoqi@0 209 double region_elapsed_time_ms =
aoqi@0 210 g1p->predict_region_elapsed_time_ms(this, false /* for_young_gc */);
aoqi@0 211 _gc_efficiency = (double) reclaimable_bytes() / region_elapsed_time_ms;
aoqi@0 212 }
aoqi@0 213
aoqi@0 214 void HeapRegion::set_startsHumongous(HeapWord* new_top, HeapWord* new_end) {
aoqi@0 215 assert(!isHumongous(), "sanity / pre-condition");
aoqi@0 216 assert(end() == _orig_end,
aoqi@0 217 "Should be normal before the humongous object allocation");
aoqi@0 218 assert(top() == bottom(), "should be empty");
aoqi@0 219 assert(bottom() <= new_top && new_top <= new_end, "pre-condition");
aoqi@0 220
brutisso@7195 221 _type.set_starts_humongous();
aoqi@0 222 _humongous_start_region = this;
aoqi@0 223
aoqi@0 224 set_end(new_end);
aoqi@0 225 _offsets.set_for_starts_humongous(new_top);
aoqi@0 226 }
aoqi@0 227
aoqi@0 228 void HeapRegion::set_continuesHumongous(HeapRegion* first_hr) {
aoqi@0 229 assert(!isHumongous(), "sanity / pre-condition");
aoqi@0 230 assert(end() == _orig_end,
aoqi@0 231 "Should be normal before the humongous object allocation");
aoqi@0 232 assert(top() == bottom(), "should be empty");
aoqi@0 233 assert(first_hr->startsHumongous(), "pre-condition");
aoqi@0 234
brutisso@7195 235 _type.set_continues_humongous();
aoqi@0 236 _humongous_start_region = first_hr;
aoqi@0 237 }
aoqi@0 238
brutisso@7195 239 void HeapRegion::clear_humongous() {
aoqi@0 240 assert(isHumongous(), "pre-condition");
aoqi@0 241
aoqi@0 242 if (startsHumongous()) {
aoqi@0 243 assert(top() <= end(), "pre-condition");
aoqi@0 244 set_end(_orig_end);
aoqi@0 245 if (top() > end()) {
aoqi@0 246 // at least one "continues humongous" region after it
aoqi@0 247 set_top(end());
aoqi@0 248 }
aoqi@0 249 } else {
aoqi@0 250 // continues humongous
aoqi@0 251 assert(end() == _orig_end, "sanity");
aoqi@0 252 }
aoqi@0 253
aoqi@0 254 assert(capacity() == HeapRegion::GrainBytes, "pre-condition");
aoqi@0 255 _humongous_start_region = NULL;
aoqi@0 256 }
aoqi@0 257
aoqi@0 258 bool HeapRegion::claimHeapRegion(jint claimValue) {
aoqi@0 259 jint current = _claimed;
aoqi@0 260 if (current != claimValue) {
aoqi@0 261 jint res = Atomic::cmpxchg(claimValue, &_claimed, current);
aoqi@0 262 if (res == current) {
aoqi@0 263 return true;
aoqi@0 264 }
aoqi@0 265 }
aoqi@0 266 return false;
aoqi@0 267 }
aoqi@0 268
tschatzl@7091 269 HeapRegion::HeapRegion(uint hrm_index,
aoqi@0 270 G1BlockOffsetSharedArray* sharedOffsetArray,
aoqi@0 271 MemRegion mr) :
aoqi@0 272 G1OffsetTableContigSpace(sharedOffsetArray, mr),
sjohanss@7131 273 _hrm_index(hrm_index),
sjohanss@7131 274 _allocation_context(AllocationContext::system()),
brutisso@7195 275 _humongous_start_region(NULL),
aoqi@0 276 _in_collection_set(false),
aoqi@0 277 _next_in_special_set(NULL), _orig_end(NULL),
aoqi@0 278 _claimed(InitialClaimValue), _evacuation_failed(false),
aoqi@0 279 _prev_marked_bytes(0), _next_marked_bytes(0), _gc_efficiency(0.0),
brutisso@7195 280 _next_young_region(NULL),
tschatzl@7050 281 _next_dirty_cards_region(NULL), _next(NULL), _prev(NULL),
aoqi@0 282 #ifdef ASSERT
aoqi@0 283 _containing_set(NULL),
aoqi@0 284 #endif // ASSERT
aoqi@0 285 _young_index_in_cset(-1), _surv_rate_group(NULL), _age_index(-1),
aoqi@0 286 _rem_set(NULL), _recorded_rs_length(0), _predicted_elapsed_time_ms(0),
aoqi@0 287 _predicted_bytes_to_copy(0)
aoqi@0 288 {
aoqi@0 289 _rem_set = new HeapRegionRemSet(sharedOffsetArray, this);
tschatzl@7050 290 assert(HeapRegionRemSet::num_par_rem_sets() > 0, "Invariant.");
tschatzl@7050 291
tschatzl@7050 292 initialize(mr);
tschatzl@7050 293 }
tschatzl@7050 294
tschatzl@7050 295 void HeapRegion::initialize(MemRegion mr, bool clear_space, bool mangle_space) {
tschatzl@7050 296 assert(_rem_set->is_empty(), "Remembered set must be empty");
tschatzl@7050 297
tschatzl@7050 298 G1OffsetTableContigSpace::initialize(mr, clear_space, mangle_space);
tschatzl@7050 299
aoqi@0 300 _orig_end = mr.end();
aoqi@0 301 hr_clear(false /*par*/, false /*clear_space*/);
aoqi@0 302 set_top(bottom());
mgerdin@7647 303 record_timestamp();
aoqi@0 304 }
aoqi@0 305
aoqi@0 306 CompactibleSpace* HeapRegion::next_compaction_space() const {
tschatzl@7009 307 return G1CollectedHeap::heap()->next_compaction_region(this);
aoqi@0 308 }
aoqi@0 309
aoqi@0 310 void HeapRegion::note_self_forwarding_removal_start(bool during_initial_mark,
aoqi@0 311 bool during_conc_mark) {
aoqi@0 312 // We always recreate the prev marking info and we'll explicitly
aoqi@0 313 // mark all objects we find to be self-forwarded on the prev
aoqi@0 314 // bitmap. So all objects need to be below PTAMS.
aoqi@0 315 _prev_marked_bytes = 0;
aoqi@0 316
aoqi@0 317 if (during_initial_mark) {
aoqi@0 318 // During initial-mark, we'll also explicitly mark all objects
aoqi@0 319 // we find to be self-forwarded on the next bitmap. So all
aoqi@0 320 // objects need to be below NTAMS.
aoqi@0 321 _next_top_at_mark_start = top();
aoqi@0 322 _next_marked_bytes = 0;
aoqi@0 323 } else if (during_conc_mark) {
aoqi@0 324 // During concurrent mark, all objects in the CSet (including
aoqi@0 325 // the ones we find to be self-forwarded) are implicitly live.
aoqi@0 326 // So all objects need to be above NTAMS.
aoqi@0 327 _next_top_at_mark_start = bottom();
aoqi@0 328 _next_marked_bytes = 0;
aoqi@0 329 }
aoqi@0 330 }
aoqi@0 331
aoqi@0 332 void HeapRegion::note_self_forwarding_removal_end(bool during_initial_mark,
aoqi@0 333 bool during_conc_mark,
aoqi@0 334 size_t marked_bytes) {
aoqi@0 335 assert(0 <= marked_bytes && marked_bytes <= used(),
aoqi@0 336 err_msg("marked: "SIZE_FORMAT" used: "SIZE_FORMAT,
aoqi@0 337 marked_bytes, used()));
stefank@6992 338 _prev_top_at_mark_start = top();
aoqi@0 339 _prev_marked_bytes = marked_bytes;
aoqi@0 340 }
aoqi@0 341
aoqi@0 342 HeapWord*
aoqi@0 343 HeapRegion::object_iterate_mem_careful(MemRegion mr,
aoqi@0 344 ObjectClosure* cl) {
aoqi@0 345 G1CollectedHeap* g1h = G1CollectedHeap::heap();
aoqi@0 346 // We used to use "block_start_careful" here. But we're actually happy
aoqi@0 347 // to update the BOT while we do this...
aoqi@0 348 HeapWord* cur = block_start(mr.start());
aoqi@0 349 mr = mr.intersection(used_region());
aoqi@0 350 if (mr.is_empty()) return NULL;
aoqi@0 351 // Otherwise, find the obj that extends onto mr.start().
aoqi@0 352
aoqi@0 353 assert(cur <= mr.start()
aoqi@0 354 && (oop(cur)->klass_or_null() == NULL ||
aoqi@0 355 cur + oop(cur)->size() > mr.start()),
aoqi@0 356 "postcondition of block_start");
aoqi@0 357 oop obj;
aoqi@0 358 while (cur < mr.end()) {
aoqi@0 359 obj = oop(cur);
aoqi@0 360 if (obj->klass_or_null() == NULL) {
aoqi@0 361 // Ran into an unparseable point.
aoqi@0 362 return cur;
aoqi@0 363 } else if (!g1h->is_obj_dead(obj)) {
aoqi@0 364 cl->do_object(obj);
aoqi@0 365 }
aoqi@0 366 if (cl->abort()) return cur;
aoqi@0 367 // The check above must occur before the operation below, since an
aoqi@0 368 // abort might invalidate the "size" operation.
mgerdin@6990 369 cur += block_size(cur);
aoqi@0 370 }
aoqi@0 371 return NULL;
aoqi@0 372 }
aoqi@0 373
aoqi@0 374 HeapWord*
aoqi@0 375 HeapRegion::
aoqi@0 376 oops_on_card_seq_iterate_careful(MemRegion mr,
aoqi@0 377 FilterOutOfRegionClosure* cl,
aoqi@0 378 bool filter_young,
aoqi@0 379 jbyte* card_ptr) {
aoqi@0 380 // Currently, we should only have to clean the card if filter_young
aoqi@0 381 // is true and vice versa.
aoqi@0 382 if (filter_young) {
aoqi@0 383 assert(card_ptr != NULL, "pre-condition");
aoqi@0 384 } else {
aoqi@0 385 assert(card_ptr == NULL, "pre-condition");
aoqi@0 386 }
aoqi@0 387 G1CollectedHeap* g1h = G1CollectedHeap::heap();
aoqi@0 388
aoqi@0 389 // If we're within a stop-world GC, then we might look at a card in a
aoqi@0 390 // GC alloc region that extends onto a GC LAB, which may not be
mgerdin@7647 391 // parseable. Stop such at the "scan_top" of the region.
aoqi@0 392 if (g1h->is_gc_active()) {
mgerdin@7647 393 mr = mr.intersection(MemRegion(bottom(), scan_top()));
aoqi@0 394 } else {
aoqi@0 395 mr = mr.intersection(used_region());
aoqi@0 396 }
aoqi@0 397 if (mr.is_empty()) return NULL;
aoqi@0 398 // Otherwise, find the obj that extends onto mr.start().
aoqi@0 399
aoqi@0 400 // The intersection of the incoming mr (for the card) and the
aoqi@0 401 // allocated part of the region is non-empty. This implies that
aoqi@0 402 // we have actually allocated into this region. The code in
aoqi@0 403 // G1CollectedHeap.cpp that allocates a new region sets the
aoqi@0 404 // is_young tag on the region before allocating. Thus we
aoqi@0 405 // safely know if this region is young.
aoqi@0 406 if (is_young() && filter_young) {
aoqi@0 407 return NULL;
aoqi@0 408 }
aoqi@0 409
aoqi@0 410 assert(!is_young(), "check value of filter_young");
aoqi@0 411
aoqi@0 412 // We can only clean the card here, after we make the decision that
aoqi@0 413 // the card is not young. And we only clean the card if we have been
aoqi@0 414 // asked to (i.e., card_ptr != NULL).
aoqi@0 415 if (card_ptr != NULL) {
aoqi@0 416 *card_ptr = CardTableModRefBS::clean_card_val();
aoqi@0 417 // We must complete this write before we do any of the reads below.
aoqi@0 418 OrderAccess::storeload();
aoqi@0 419 }
aoqi@0 420
aoqi@0 421 // Cache the boundaries of the memory region in some const locals
aoqi@0 422 HeapWord* const start = mr.start();
aoqi@0 423 HeapWord* const end = mr.end();
aoqi@0 424
aoqi@0 425 // We used to use "block_start_careful" here. But we're actually happy
aoqi@0 426 // to update the BOT while we do this...
aoqi@0 427 HeapWord* cur = block_start(start);
aoqi@0 428 assert(cur <= start, "Postcondition");
aoqi@0 429
aoqi@0 430 oop obj;
aoqi@0 431
aoqi@0 432 HeapWord* next = cur;
tschatzl@7654 433 do {
aoqi@0 434 cur = next;
aoqi@0 435 obj = oop(cur);
aoqi@0 436 if (obj->klass_or_null() == NULL) {
aoqi@0 437 // Ran into an unparseable point.
aoqi@0 438 return cur;
aoqi@0 439 }
aoqi@0 440 // Otherwise...
mgerdin@6990 441 next = cur + block_size(cur);
tschatzl@7654 442 } while (next <= start);
aoqi@0 443
aoqi@0 444 // If we finish the above loop...We have a parseable object that
aoqi@0 445 // begins on or before the start of the memory region, and ends
aoqi@0 446 // inside or spans the entire region.
mgerdin@6990 447 assert(cur <= start, "Loop postcondition");
mgerdin@6990 448 assert(obj->klass_or_null() != NULL, "Loop postcondition");
aoqi@0 449
tschatzl@7654 450 do {
aoqi@0 451 obj = oop(cur);
tschatzl@7654 452 assert((cur + block_size(cur)) > (HeapWord*)obj, "Loop invariant");
aoqi@0 453 if (obj->klass_or_null() == NULL) {
aoqi@0 454 // Ran into an unparseable point.
aoqi@0 455 return cur;
tschatzl@7654 456 }
aoqi@0 457
tschatzl@7654 458 // Advance the current pointer. "obj" still points to the object to iterate.
tschatzl@7654 459 cur = cur + block_size(cur);
aoqi@0 460
aoqi@0 461 if (!g1h->is_obj_dead(obj)) {
tschatzl@7654 462 // Non-objArrays are sometimes marked imprecise at the object start. We
tschatzl@7654 463 // always need to iterate over them in full.
tschatzl@7654 464 // We only iterate over object arrays in full if they are completely contained
tschatzl@7654 465 // in the memory region.
tschatzl@7654 466 if (!obj->is_objArray() || (((HeapWord*)obj) >= start && cur <= end)) {
aoqi@0 467 obj->oop_iterate(cl);
aoqi@0 468 } else {
aoqi@0 469 obj->oop_iterate(cl, mr);
aoqi@0 470 }
aoqi@0 471 }
tschatzl@7654 472 } while (cur < end);
tschatzl@7654 473
aoqi@0 474 return NULL;
aoqi@0 475 }
aoqi@0 476
aoqi@0 477 // Code roots support
aoqi@0 478
aoqi@0 479 void HeapRegion::add_strong_code_root(nmethod* nm) {
aoqi@0 480 HeapRegionRemSet* hrrs = rem_set();
aoqi@0 481 hrrs->add_strong_code_root(nm);
aoqi@0 482 }
aoqi@0 483
mgerdin@7208 484 void HeapRegion::add_strong_code_root_locked(nmethod* nm) {
mgerdin@7208 485 assert_locked_or_safepoint(CodeCache_lock);
mgerdin@7208 486 HeapRegionRemSet* hrrs = rem_set();
mgerdin@7208 487 hrrs->add_strong_code_root_locked(nm);
mgerdin@7208 488 }
mgerdin@7208 489
aoqi@0 490 void HeapRegion::remove_strong_code_root(nmethod* nm) {
aoqi@0 491 HeapRegionRemSet* hrrs = rem_set();
aoqi@0 492 hrrs->remove_strong_code_root(nm);
aoqi@0 493 }
aoqi@0 494
aoqi@0 495 void HeapRegion::strong_code_roots_do(CodeBlobClosure* blk) const {
aoqi@0 496 HeapRegionRemSet* hrrs = rem_set();
aoqi@0 497 hrrs->strong_code_roots_do(blk);
aoqi@0 498 }
aoqi@0 499
aoqi@0 500 class VerifyStrongCodeRootOopClosure: public OopClosure {
aoqi@0 501 const HeapRegion* _hr;
aoqi@0 502 nmethod* _nm;
aoqi@0 503 bool _failures;
aoqi@0 504 bool _has_oops_in_region;
aoqi@0 505
aoqi@0 506 template <class T> void do_oop_work(T* p) {
aoqi@0 507 T heap_oop = oopDesc::load_heap_oop(p);
aoqi@0 508 if (!oopDesc::is_null(heap_oop)) {
aoqi@0 509 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
aoqi@0 510
aoqi@0 511 // Note: not all the oops embedded in the nmethod are in the
aoqi@0 512 // current region. We only look at those which are.
aoqi@0 513 if (_hr->is_in(obj)) {
aoqi@0 514 // Object is in the region. Check that its less than top
aoqi@0 515 if (_hr->top() <= (HeapWord*)obj) {
aoqi@0 516 // Object is above top
aoqi@0 517 gclog_or_tty->print_cr("Object "PTR_FORMAT" in region "
aoqi@0 518 "["PTR_FORMAT", "PTR_FORMAT") is above "
aoqi@0 519 "top "PTR_FORMAT,
aoqi@0 520 (void *)obj, _hr->bottom(), _hr->end(), _hr->top());
aoqi@0 521 _failures = true;
aoqi@0 522 return;
aoqi@0 523 }
aoqi@0 524 // Nmethod has at least one oop in the current region
aoqi@0 525 _has_oops_in_region = true;
aoqi@0 526 }
aoqi@0 527 }
aoqi@0 528 }
aoqi@0 529
aoqi@0 530 public:
aoqi@0 531 VerifyStrongCodeRootOopClosure(const HeapRegion* hr, nmethod* nm):
aoqi@0 532 _hr(hr), _failures(false), _has_oops_in_region(false) {}
aoqi@0 533
aoqi@0 534 void do_oop(narrowOop* p) { do_oop_work(p); }
aoqi@0 535 void do_oop(oop* p) { do_oop_work(p); }
aoqi@0 536
aoqi@0 537 bool failures() { return _failures; }
aoqi@0 538 bool has_oops_in_region() { return _has_oops_in_region; }
aoqi@0 539 };
aoqi@0 540
aoqi@0 541 class VerifyStrongCodeRootCodeBlobClosure: public CodeBlobClosure {
aoqi@0 542 const HeapRegion* _hr;
aoqi@0 543 bool _failures;
aoqi@0 544 public:
aoqi@0 545 VerifyStrongCodeRootCodeBlobClosure(const HeapRegion* hr) :
aoqi@0 546 _hr(hr), _failures(false) {}
aoqi@0 547
aoqi@0 548 void do_code_blob(CodeBlob* cb) {
aoqi@0 549 nmethod* nm = (cb == NULL) ? NULL : cb->as_nmethod_or_null();
aoqi@0 550 if (nm != NULL) {
aoqi@0 551 // Verify that the nemthod is live
aoqi@0 552 if (!nm->is_alive()) {
aoqi@0 553 gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] has dead nmethod "
aoqi@0 554 PTR_FORMAT" in its strong code roots",
aoqi@0 555 _hr->bottom(), _hr->end(), nm);
aoqi@0 556 _failures = true;
aoqi@0 557 } else {
aoqi@0 558 VerifyStrongCodeRootOopClosure oop_cl(_hr, nm);
aoqi@0 559 nm->oops_do(&oop_cl);
aoqi@0 560 if (!oop_cl.has_oops_in_region()) {
aoqi@0 561 gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] has nmethod "
aoqi@0 562 PTR_FORMAT" in its strong code roots "
aoqi@0 563 "with no pointers into region",
aoqi@0 564 _hr->bottom(), _hr->end(), nm);
aoqi@0 565 _failures = true;
aoqi@0 566 } else if (oop_cl.failures()) {
aoqi@0 567 gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] has other "
aoqi@0 568 "failures for nmethod "PTR_FORMAT,
aoqi@0 569 _hr->bottom(), _hr->end(), nm);
aoqi@0 570 _failures = true;
aoqi@0 571 }
aoqi@0 572 }
aoqi@0 573 }
aoqi@0 574 }
aoqi@0 575
aoqi@0 576 bool failures() { return _failures; }
aoqi@0 577 };
aoqi@0 578
aoqi@0 579 void HeapRegion::verify_strong_code_roots(VerifyOption vo, bool* failures) const {
aoqi@0 580 if (!G1VerifyHeapRegionCodeRoots) {
aoqi@0 581 // We're not verifying code roots.
aoqi@0 582 return;
aoqi@0 583 }
aoqi@0 584 if (vo == VerifyOption_G1UseMarkWord) {
aoqi@0 585 // Marking verification during a full GC is performed after class
aoqi@0 586 // unloading, code cache unloading, etc so the strong code roots
aoqi@0 587 // attached to each heap region are in an inconsistent state. They won't
aoqi@0 588 // be consistent until the strong code roots are rebuilt after the
aoqi@0 589 // actual GC. Skip verifying the strong code roots in this particular
aoqi@0 590 // time.
aoqi@0 591 assert(VerifyDuringGC, "only way to get here");
aoqi@0 592 return;
aoqi@0 593 }
aoqi@0 594
aoqi@0 595 HeapRegionRemSet* hrrs = rem_set();
aoqi@0 596 size_t strong_code_roots_length = hrrs->strong_code_roots_list_length();
aoqi@0 597
aoqi@0 598 // if this region is empty then there should be no entries
aoqi@0 599 // on its strong code root list
aoqi@0 600 if (is_empty()) {
aoqi@0 601 if (strong_code_roots_length > 0) {
aoqi@0 602 gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] is empty "
aoqi@0 603 "but has "SIZE_FORMAT" code root entries",
aoqi@0 604 bottom(), end(), strong_code_roots_length);
aoqi@0 605 *failures = true;
aoqi@0 606 }
aoqi@0 607 return;
aoqi@0 608 }
aoqi@0 609
aoqi@0 610 if (continuesHumongous()) {
aoqi@0 611 if (strong_code_roots_length > 0) {
aoqi@0 612 gclog_or_tty->print_cr("region "HR_FORMAT" is a continuation of a humongous "
aoqi@0 613 "region but has "SIZE_FORMAT" code root entries",
aoqi@0 614 HR_FORMAT_PARAMS(this), strong_code_roots_length);
aoqi@0 615 *failures = true;
aoqi@0 616 }
aoqi@0 617 return;
aoqi@0 618 }
aoqi@0 619
aoqi@0 620 VerifyStrongCodeRootCodeBlobClosure cb_cl(this);
aoqi@0 621 strong_code_roots_do(&cb_cl);
aoqi@0 622
aoqi@0 623 if (cb_cl.failures()) {
aoqi@0 624 *failures = true;
aoqi@0 625 }
aoqi@0 626 }
aoqi@0 627
aoqi@0 628 void HeapRegion::print() const { print_on(gclog_or_tty); }
aoqi@0 629 void HeapRegion::print_on(outputStream* st) const {
sjohanss@7118 630 st->print("AC%4u", allocation_context());
brutisso@7195 631 st->print(" %2s", get_short_type_str());
aoqi@0 632 if (in_collection_set())
aoqi@0 633 st->print(" CS");
aoqi@0 634 else
aoqi@0 635 st->print(" ");
aoqi@0 636 st->print(" TS %5d", _gc_time_stamp);
aoqi@0 637 st->print(" PTAMS "PTR_FORMAT" NTAMS "PTR_FORMAT,
aoqi@0 638 prev_top_at_mark_start(), next_top_at_mark_start());
aoqi@0 639 G1OffsetTableContigSpace::print_on(st);
aoqi@0 640 }
aoqi@0 641
aoqi@0 642 class VerifyLiveClosure: public OopClosure {
aoqi@0 643 private:
aoqi@0 644 G1CollectedHeap* _g1h;
aoqi@0 645 CardTableModRefBS* _bs;
aoqi@0 646 oop _containing_obj;
aoqi@0 647 bool _failures;
aoqi@0 648 int _n_failures;
aoqi@0 649 VerifyOption _vo;
aoqi@0 650 public:
aoqi@0 651 // _vo == UsePrevMarking -> use "prev" marking information,
aoqi@0 652 // _vo == UseNextMarking -> use "next" marking information,
aoqi@0 653 // _vo == UseMarkWord -> use mark word from object header.
aoqi@0 654 VerifyLiveClosure(G1CollectedHeap* g1h, VerifyOption vo) :
aoqi@0 655 _g1h(g1h), _bs(NULL), _containing_obj(NULL),
aoqi@0 656 _failures(false), _n_failures(0), _vo(vo)
aoqi@0 657 {
aoqi@0 658 BarrierSet* bs = _g1h->barrier_set();
aoqi@0 659 if (bs->is_a(BarrierSet::CardTableModRef))
aoqi@0 660 _bs = (CardTableModRefBS*)bs;
aoqi@0 661 }
aoqi@0 662
aoqi@0 663 void set_containing_obj(oop obj) {
aoqi@0 664 _containing_obj = obj;
aoqi@0 665 }
aoqi@0 666
aoqi@0 667 bool failures() { return _failures; }
aoqi@0 668 int n_failures() { return _n_failures; }
aoqi@0 669
aoqi@0 670 virtual void do_oop(narrowOop* p) { do_oop_work(p); }
aoqi@0 671 virtual void do_oop( oop* p) { do_oop_work(p); }
aoqi@0 672
aoqi@0 673 void print_object(outputStream* out, oop obj) {
aoqi@0 674 #ifdef PRODUCT
aoqi@0 675 Klass* k = obj->klass();
aoqi@0 676 const char* class_name = InstanceKlass::cast(k)->external_name();
aoqi@0 677 out->print_cr("class name %s", class_name);
aoqi@0 678 #else // PRODUCT
aoqi@0 679 obj->print_on(out);
aoqi@0 680 #endif // PRODUCT
aoqi@0 681 }
aoqi@0 682
aoqi@0 683 template <class T>
aoqi@0 684 void do_oop_work(T* p) {
aoqi@0 685 assert(_containing_obj != NULL, "Precondition");
aoqi@0 686 assert(!_g1h->is_obj_dead_cond(_containing_obj, _vo),
aoqi@0 687 "Precondition");
aoqi@0 688 T heap_oop = oopDesc::load_heap_oop(p);
aoqi@0 689 if (!oopDesc::is_null(heap_oop)) {
aoqi@0 690 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
aoqi@0 691 bool failed = false;
aoqi@0 692 if (!_g1h->is_in_closed_subset(obj) || _g1h->is_obj_dead_cond(obj, _vo)) {
aoqi@0 693 MutexLockerEx x(ParGCRareEvent_lock,
aoqi@0 694 Mutex::_no_safepoint_check_flag);
aoqi@0 695
aoqi@0 696 if (!_failures) {
aoqi@0 697 gclog_or_tty->cr();
aoqi@0 698 gclog_or_tty->print_cr("----------");
aoqi@0 699 }
aoqi@0 700 if (!_g1h->is_in_closed_subset(obj)) {
aoqi@0 701 HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
aoqi@0 702 gclog_or_tty->print_cr("Field "PTR_FORMAT
aoqi@0 703 " of live obj "PTR_FORMAT" in region "
aoqi@0 704 "["PTR_FORMAT", "PTR_FORMAT")",
aoqi@0 705 p, (void*) _containing_obj,
aoqi@0 706 from->bottom(), from->end());
aoqi@0 707 print_object(gclog_or_tty, _containing_obj);
aoqi@0 708 gclog_or_tty->print_cr("points to obj "PTR_FORMAT" not in the heap",
aoqi@0 709 (void*) obj);
aoqi@0 710 } else {
aoqi@0 711 HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
aoqi@0 712 HeapRegion* to = _g1h->heap_region_containing((HeapWord*)obj);
aoqi@0 713 gclog_or_tty->print_cr("Field "PTR_FORMAT
aoqi@0 714 " of live obj "PTR_FORMAT" in region "
aoqi@0 715 "["PTR_FORMAT", "PTR_FORMAT")",
aoqi@0 716 p, (void*) _containing_obj,
aoqi@0 717 from->bottom(), from->end());
aoqi@0 718 print_object(gclog_or_tty, _containing_obj);
aoqi@0 719 gclog_or_tty->print_cr("points to dead obj "PTR_FORMAT" in region "
aoqi@0 720 "["PTR_FORMAT", "PTR_FORMAT")",
aoqi@0 721 (void*) obj, to->bottom(), to->end());
aoqi@0 722 print_object(gclog_or_tty, obj);
aoqi@0 723 }
aoqi@0 724 gclog_or_tty->print_cr("----------");
aoqi@0 725 gclog_or_tty->flush();
aoqi@0 726 _failures = true;
aoqi@0 727 failed = true;
aoqi@0 728 _n_failures++;
aoqi@0 729 }
aoqi@0 730
aoqi@0 731 if (!_g1h->full_collection() || G1VerifyRSetsDuringFullGC) {
aoqi@0 732 HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
aoqi@0 733 HeapRegion* to = _g1h->heap_region_containing(obj);
aoqi@0 734 if (from != NULL && to != NULL &&
aoqi@0 735 from != to &&
aoqi@0 736 !to->isHumongous()) {
aoqi@0 737 jbyte cv_obj = *_bs->byte_for_const(_containing_obj);
aoqi@0 738 jbyte cv_field = *_bs->byte_for_const(p);
aoqi@0 739 const jbyte dirty = CardTableModRefBS::dirty_card_val();
aoqi@0 740
aoqi@0 741 bool is_bad = !(from->is_young()
aoqi@0 742 || to->rem_set()->contains_reference(p)
aoqi@0 743 || !G1HRRSFlushLogBuffersOnVerify && // buffers were not flushed
aoqi@0 744 (_containing_obj->is_objArray() ?
aoqi@0 745 cv_field == dirty
aoqi@0 746 : cv_obj == dirty || cv_field == dirty));
aoqi@0 747 if (is_bad) {
aoqi@0 748 MutexLockerEx x(ParGCRareEvent_lock,
aoqi@0 749 Mutex::_no_safepoint_check_flag);
aoqi@0 750
aoqi@0 751 if (!_failures) {
aoqi@0 752 gclog_or_tty->cr();
aoqi@0 753 gclog_or_tty->print_cr("----------");
aoqi@0 754 }
aoqi@0 755 gclog_or_tty->print_cr("Missing rem set entry:");
aoqi@0 756 gclog_or_tty->print_cr("Field "PTR_FORMAT" "
aoqi@0 757 "of obj "PTR_FORMAT", "
aoqi@0 758 "in region "HR_FORMAT,
aoqi@0 759 p, (void*) _containing_obj,
aoqi@0 760 HR_FORMAT_PARAMS(from));
aoqi@0 761 _containing_obj->print_on(gclog_or_tty);
aoqi@0 762 gclog_or_tty->print_cr("points to obj "PTR_FORMAT" "
aoqi@0 763 "in region "HR_FORMAT,
aoqi@0 764 (void*) obj,
aoqi@0 765 HR_FORMAT_PARAMS(to));
aoqi@0 766 obj->print_on(gclog_or_tty);
aoqi@0 767 gclog_or_tty->print_cr("Obj head CTE = %d, field CTE = %d.",
aoqi@0 768 cv_obj, cv_field);
aoqi@0 769 gclog_or_tty->print_cr("----------");
aoqi@0 770 gclog_or_tty->flush();
aoqi@0 771 _failures = true;
aoqi@0 772 if (!failed) _n_failures++;
aoqi@0 773 }
aoqi@0 774 }
aoqi@0 775 }
aoqi@0 776 }
aoqi@0 777 }
aoqi@0 778 };
aoqi@0 779
aoqi@0 780 // This really ought to be commoned up into OffsetTableContigSpace somehow.
aoqi@0 781 // We would need a mechanism to make that code skip dead objects.
aoqi@0 782
aoqi@0 783 void HeapRegion::verify(VerifyOption vo,
aoqi@0 784 bool* failures) const {
aoqi@0 785 G1CollectedHeap* g1 = G1CollectedHeap::heap();
aoqi@0 786 *failures = false;
aoqi@0 787 HeapWord* p = bottom();
aoqi@0 788 HeapWord* prev_p = NULL;
aoqi@0 789 VerifyLiveClosure vl_cl(g1, vo);
aoqi@0 790 bool is_humongous = isHumongous();
aoqi@0 791 bool do_bot_verify = !is_young();
aoqi@0 792 size_t object_num = 0;
aoqi@0 793 while (p < top()) {
aoqi@0 794 oop obj = oop(p);
mgerdin@6990 795 size_t obj_size = block_size(p);
aoqi@0 796 object_num += 1;
aoqi@0 797
stefank@6992 798 if (is_humongous != g1->isHumongous(obj_size) &&
stefank@6992 799 !g1->is_obj_dead(obj, this)) { // Dead objects may have bigger block_size since they span several objects.
aoqi@0 800 gclog_or_tty->print_cr("obj "PTR_FORMAT" is of %shumongous size ("
aoqi@0 801 SIZE_FORMAT" words) in a %shumongous region",
aoqi@0 802 p, g1->isHumongous(obj_size) ? "" : "non-",
aoqi@0 803 obj_size, is_humongous ? "" : "non-");
aoqi@0 804 *failures = true;
aoqi@0 805 return;
aoqi@0 806 }
aoqi@0 807
aoqi@0 808 // If it returns false, verify_for_object() will output the
tschatzl@7050 809 // appropriate message.
stefank@6992 810 if (do_bot_verify &&
stefank@6992 811 !g1->is_obj_dead(obj, this) &&
stefank@6992 812 !_offsets.verify_for_object(p, obj_size)) {
aoqi@0 813 *failures = true;
aoqi@0 814 return;
aoqi@0 815 }
aoqi@0 816
aoqi@0 817 if (!g1->is_obj_dead_cond(obj, this, vo)) {
aoqi@0 818 if (obj->is_oop()) {
aoqi@0 819 Klass* klass = obj->klass();
stefank@6992 820 bool is_metaspace_object = Metaspace::contains(klass) ||
stefank@6992 821 (vo == VerifyOption_G1UsePrevMarking &&
stefank@6992 822 ClassLoaderDataGraph::unload_list_contains(klass));
stefank@6992 823 if (!is_metaspace_object) {
aoqi@0 824 gclog_or_tty->print_cr("klass "PTR_FORMAT" of object "PTR_FORMAT" "
aoqi@0 825 "not metadata", klass, (void *)obj);
aoqi@0 826 *failures = true;
aoqi@0 827 return;
aoqi@0 828 } else if (!klass->is_klass()) {
aoqi@0 829 gclog_or_tty->print_cr("klass "PTR_FORMAT" of object "PTR_FORMAT" "
aoqi@0 830 "not a klass", klass, (void *)obj);
aoqi@0 831 *failures = true;
aoqi@0 832 return;
aoqi@0 833 } else {
aoqi@0 834 vl_cl.set_containing_obj(obj);
aoqi@0 835 obj->oop_iterate_no_header(&vl_cl);
aoqi@0 836 if (vl_cl.failures()) {
aoqi@0 837 *failures = true;
aoqi@0 838 }
aoqi@0 839 if (G1MaxVerifyFailures >= 0 &&
aoqi@0 840 vl_cl.n_failures() >= G1MaxVerifyFailures) {
aoqi@0 841 return;
aoqi@0 842 }
aoqi@0 843 }
aoqi@0 844 } else {
aoqi@0 845 gclog_or_tty->print_cr(PTR_FORMAT" no an oop", (void *)obj);
aoqi@0 846 *failures = true;
aoqi@0 847 return;
aoqi@0 848 }
aoqi@0 849 }
aoqi@0 850 prev_p = p;
aoqi@0 851 p += obj_size;
aoqi@0 852 }
aoqi@0 853
aoqi@0 854 if (p != top()) {
aoqi@0 855 gclog_or_tty->print_cr("end of last object "PTR_FORMAT" "
aoqi@0 856 "does not match top "PTR_FORMAT, p, top());
aoqi@0 857 *failures = true;
aoqi@0 858 return;
aoqi@0 859 }
aoqi@0 860
aoqi@0 861 HeapWord* the_end = end();
aoqi@0 862 assert(p == top(), "it should still hold");
aoqi@0 863 // Do some extra BOT consistency checking for addresses in the
aoqi@0 864 // range [top, end). BOT look-ups in this range should yield
aoqi@0 865 // top. No point in doing that if top == end (there's nothing there).
aoqi@0 866 if (p < the_end) {
aoqi@0 867 // Look up top
aoqi@0 868 HeapWord* addr_1 = p;
aoqi@0 869 HeapWord* b_start_1 = _offsets.block_start_const(addr_1);
aoqi@0 870 if (b_start_1 != p) {
aoqi@0 871 gclog_or_tty->print_cr("BOT look up for top: "PTR_FORMAT" "
aoqi@0 872 " yielded "PTR_FORMAT", expecting "PTR_FORMAT,
aoqi@0 873 addr_1, b_start_1, p);
aoqi@0 874 *failures = true;
aoqi@0 875 return;
aoqi@0 876 }
aoqi@0 877
aoqi@0 878 // Look up top + 1
aoqi@0 879 HeapWord* addr_2 = p + 1;
aoqi@0 880 if (addr_2 < the_end) {
aoqi@0 881 HeapWord* b_start_2 = _offsets.block_start_const(addr_2);
aoqi@0 882 if (b_start_2 != p) {
aoqi@0 883 gclog_or_tty->print_cr("BOT look up for top + 1: "PTR_FORMAT" "
aoqi@0 884 " yielded "PTR_FORMAT", expecting "PTR_FORMAT,
aoqi@0 885 addr_2, b_start_2, p);
aoqi@0 886 *failures = true;
aoqi@0 887 return;
aoqi@0 888 }
aoqi@0 889 }
aoqi@0 890
aoqi@0 891 // Look up an address between top and end
aoqi@0 892 size_t diff = pointer_delta(the_end, p) / 2;
aoqi@0 893 HeapWord* addr_3 = p + diff;
aoqi@0 894 if (addr_3 < the_end) {
aoqi@0 895 HeapWord* b_start_3 = _offsets.block_start_const(addr_3);
aoqi@0 896 if (b_start_3 != p) {
aoqi@0 897 gclog_or_tty->print_cr("BOT look up for top + diff: "PTR_FORMAT" "
aoqi@0 898 " yielded "PTR_FORMAT", expecting "PTR_FORMAT,
aoqi@0 899 addr_3, b_start_3, p);
aoqi@0 900 *failures = true;
aoqi@0 901 return;
aoqi@0 902 }
aoqi@0 903 }
aoqi@0 904
aoqi@0 905 // Loook up end - 1
aoqi@0 906 HeapWord* addr_4 = the_end - 1;
aoqi@0 907 HeapWord* b_start_4 = _offsets.block_start_const(addr_4);
aoqi@0 908 if (b_start_4 != p) {
aoqi@0 909 gclog_or_tty->print_cr("BOT look up for end - 1: "PTR_FORMAT" "
aoqi@0 910 " yielded "PTR_FORMAT", expecting "PTR_FORMAT,
aoqi@0 911 addr_4, b_start_4, p);
aoqi@0 912 *failures = true;
aoqi@0 913 return;
aoqi@0 914 }
aoqi@0 915 }
aoqi@0 916
aoqi@0 917 if (is_humongous && object_num > 1) {
aoqi@0 918 gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] is humongous "
aoqi@0 919 "but has "SIZE_FORMAT", objects",
aoqi@0 920 bottom(), end(), object_num);
aoqi@0 921 *failures = true;
aoqi@0 922 return;
aoqi@0 923 }
aoqi@0 924
aoqi@0 925 verify_strong_code_roots(vo, failures);
aoqi@0 926 }
aoqi@0 927
aoqi@0 928 void HeapRegion::verify() const {
aoqi@0 929 bool dummy = false;
aoqi@0 930 verify(VerifyOption_G1UsePrevMarking, /* failures */ &dummy);
aoqi@0 931 }
aoqi@0 932
aoqi@0 933 // G1OffsetTableContigSpace code; copied from space.cpp. Hope this can go
aoqi@0 934 // away eventually.
aoqi@0 935
aoqi@0 936 void G1OffsetTableContigSpace::clear(bool mangle_space) {
mgerdin@6990 937 set_top(bottom());
mgerdin@7647 938 _scan_top = bottom();
mgerdin@6990 939 CompactibleSpace::clear(mangle_space);
tschatzl@7050 940 reset_bot();
aoqi@0 941 }
aoqi@0 942
aoqi@0 943 void G1OffsetTableContigSpace::set_bottom(HeapWord* new_bottom) {
aoqi@0 944 Space::set_bottom(new_bottom);
aoqi@0 945 _offsets.set_bottom(new_bottom);
aoqi@0 946 }
aoqi@0 947
aoqi@0 948 void G1OffsetTableContigSpace::set_end(HeapWord* new_end) {
aoqi@0 949 Space::set_end(new_end);
aoqi@0 950 _offsets.resize(new_end - bottom());
aoqi@0 951 }
aoqi@0 952
aoqi@0 953 void G1OffsetTableContigSpace::print() const {
aoqi@0 954 print_short();
aoqi@0 955 gclog_or_tty->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", "
aoqi@0 956 INTPTR_FORMAT ", " INTPTR_FORMAT ")",
aoqi@0 957 bottom(), top(), _offsets.threshold(), end());
aoqi@0 958 }
aoqi@0 959
aoqi@0 960 HeapWord* G1OffsetTableContigSpace::initialize_threshold() {
aoqi@0 961 return _offsets.initialize_threshold();
aoqi@0 962 }
aoqi@0 963
aoqi@0 964 HeapWord* G1OffsetTableContigSpace::cross_threshold(HeapWord* start,
aoqi@0 965 HeapWord* end) {
aoqi@0 966 _offsets.alloc_block(start, end);
aoqi@0 967 return _offsets.threshold();
aoqi@0 968 }
aoqi@0 969
mgerdin@7647 970 HeapWord* G1OffsetTableContigSpace::scan_top() const {
aoqi@0 971 G1CollectedHeap* g1h = G1CollectedHeap::heap();
mgerdin@7366 972 HeapWord* local_top = top();
mgerdin@7366 973 OrderAccess::loadload();
mgerdin@7647 974 const unsigned local_time_stamp = _gc_time_stamp;
mgerdin@7647 975 assert(local_time_stamp <= g1h->get_gc_time_stamp(), "invariant");
mgerdin@7647 976 if (local_time_stamp < g1h->get_gc_time_stamp()) {
mgerdin@7366 977 return local_top;
mgerdin@7366 978 } else {
mgerdin@7647 979 return _scan_top;
mgerdin@7366 980 }
aoqi@0 981 }
aoqi@0 982
mgerdin@7647 983 void G1OffsetTableContigSpace::record_timestamp() {
aoqi@0 984 G1CollectedHeap* g1h = G1CollectedHeap::heap();
aoqi@0 985 unsigned curr_gc_time_stamp = g1h->get_gc_time_stamp();
aoqi@0 986
aoqi@0 987 if (_gc_time_stamp < curr_gc_time_stamp) {
mgerdin@7647 988 // Setting the time stamp here tells concurrent readers to look at
mgerdin@7647 989 // scan_top to know the maximum allowed address to look at.
mgerdin@7647 990
mgerdin@7647 991 // scan_top should be bottom for all regions except for the
mgerdin@7647 992 // retained old alloc region which should have scan_top == top
mgerdin@7647 993 HeapWord* st = _scan_top;
mgerdin@7647 994 guarantee(st == _bottom || st == _top, "invariant");
mgerdin@7647 995
aoqi@0 996 _gc_time_stamp = curr_gc_time_stamp;
aoqi@0 997 }
aoqi@0 998 }
aoqi@0 999
mgerdin@7647 1000 void G1OffsetTableContigSpace::record_retained_region() {
mgerdin@7647 1001 // scan_top is the maximum address where it's safe for the next gc to
mgerdin@7647 1002 // scan this region.
mgerdin@7647 1003 _scan_top = top();
mgerdin@7647 1004 }
mgerdin@7647 1005
mgerdin@6990 1006 void G1OffsetTableContigSpace::safe_object_iterate(ObjectClosure* blk) {
mgerdin@6990 1007 object_iterate(blk);
mgerdin@6990 1008 }
mgerdin@6990 1009
mgerdin@6990 1010 void G1OffsetTableContigSpace::object_iterate(ObjectClosure* blk) {
mgerdin@6990 1011 HeapWord* p = bottom();
mgerdin@6990 1012 while (p < top()) {
mgerdin@6990 1013 if (block_is_obj(p)) {
mgerdin@6990 1014 blk->do_object(oop(p));
mgerdin@6990 1015 }
mgerdin@6990 1016 p += block_size(p);
mgerdin@6990 1017 }
mgerdin@6990 1018 }
mgerdin@6990 1019
mgerdin@6990 1020 #define block_is_always_obj(q) true
mgerdin@6990 1021 void G1OffsetTableContigSpace::prepare_for_compaction(CompactPoint* cp) {
mgerdin@6990 1022 SCAN_AND_FORWARD(cp, top, block_is_always_obj, block_size);
mgerdin@6990 1023 }
mgerdin@6990 1024 #undef block_is_always_obj
mgerdin@6990 1025
aoqi@0 1026 G1OffsetTableContigSpace::
aoqi@0 1027 G1OffsetTableContigSpace(G1BlockOffsetSharedArray* sharedOffsetArray,
aoqi@0 1028 MemRegion mr) :
aoqi@0 1029 _offsets(sharedOffsetArray, mr),
aoqi@0 1030 _par_alloc_lock(Mutex::leaf, "OffsetTableContigSpace par alloc lock", true),
aoqi@0 1031 _gc_time_stamp(0)
aoqi@0 1032 {
aoqi@0 1033 _offsets.set_space(this);
aoqi@0 1034 }
tschatzl@7050 1035
tschatzl@7050 1036 void G1OffsetTableContigSpace::initialize(MemRegion mr, bool clear_space, bool mangle_space) {
tschatzl@7050 1037 CompactibleSpace::initialize(mr, clear_space, mangle_space);
mgerdin@6990 1038 _top = bottom();
mgerdin@7647 1039 _scan_top = bottom();
mgerdin@7647 1040 set_saved_mark_word(NULL);
tschatzl@7050 1041 reset_bot();
drchase@6680 1042 }
tschatzl@7050 1043

mercurial