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

Mon, 02 Feb 2015 10:38:39 +0100

author
tschatzl
date
Mon, 02 Feb 2015 10:38:39 +0100
changeset 7654
36c7518fd486
parent 7647
80ac3ee51955
child 7655
8e9ede9dd2cd
permissions
-rw-r--r--

8069760: When iterating over a card, G1 often iterates over much more references than are contained in the card
Summary: Properly bound the iteration work for objArray-oops.
Reviewed-by: mgerdin, kbarrett

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

mercurial