annotate src/share/vm/gc_implementation/g1/heapRegion.cpp @ 5174:05e7f9c0c822

8027756: assert(!hr->isHumongous()) failed: code root in humongous region? Summary: Change checks for isHumongous() to continuesHumongous() as installing a code root for a humongous object is valid, but not for continuations of humongous objects. Cleaned up asserts. Reviewed-by: jmasa, tamao
author tschatzl
date Thu, 19 Dec 2013 09:22:30 +0100
parents 0114a0a4434c
children b86041bd7b99
rev   line source
ysr@345 1 /*
tonyp@3280 2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
ysr@345 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ysr@345 4 *
ysr@345 5 * This code is free software; you can redistribute it and/or modify it
ysr@345 6 * under the terms of the GNU General Public License version 2 only, as
ysr@345 7 * published by the Free Software Foundation.
ysr@345 8 *
ysr@345 9 * This code is distributed in the hope that it will be useful, but WITHOUT
ysr@345 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ysr@345 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
ysr@345 12 * version 2 for more details (a copy is included in the LICENSE file that
ysr@345 13 * accompanied this code).
ysr@345 14 *
ysr@345 15 * You should have received a copy of the GNU General Public License version
ysr@345 16 * 2 along with this work; if not, write to the Free Software Foundation,
ysr@345 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ysr@345 18 *
trims@1563 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1563 20 * or visit www.oracle.com if you need additional information or have any
trims@1563 21 * questions.
ysr@345 22 *
ysr@345 23 */
ysr@345 24
stefank@1992 25 #include "precompiled.hpp"
johnc@5169 26 #include "code/nmethod.hpp"
stefank@1992 27 #include "gc_implementation/g1/g1BlockOffsetTable.inline.hpp"
stefank@1992 28 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
stefank@1992 29 #include "gc_implementation/g1/g1OopClosures.inline.hpp"
stefank@1992 30 #include "gc_implementation/g1/heapRegion.inline.hpp"
stefank@1992 31 #include "gc_implementation/g1/heapRegionRemSet.hpp"
stefank@1992 32 #include "gc_implementation/g1/heapRegionSeq.inline.hpp"
stefank@1992 33 #include "memory/genOopClosures.inline.hpp"
stefank@1992 34 #include "memory/iterator.hpp"
stefank@1992 35 #include "oops/oop.inline.hpp"
ysr@345 36
johnc@3035 37 int HeapRegion::LogOfHRGrainBytes = 0;
johnc@3035 38 int HeapRegion::LogOfHRGrainWords = 0;
johnc@3035 39 size_t HeapRegion::GrainBytes = 0;
johnc@3035 40 size_t HeapRegion::GrainWords = 0;
johnc@3035 41 size_t HeapRegion::CardsPerRegion = 0;
tonyp@996 42
ysr@345 43 HeapRegionDCTOC::HeapRegionDCTOC(G1CollectedHeap* g1,
ysr@345 44 HeapRegion* hr, OopClosure* cl,
ysr@345 45 CardTableModRefBS::PrecisionStyle precision,
ysr@345 46 FilterKind fk) :
ysr@345 47 ContiguousSpaceDCTOC(hr, cl, precision, NULL),
tonyp@4192 48 _hr(hr), _fk(fk), _g1(g1) { }
ysr@345 49
ysr@345 50 FilterOutOfRegionClosure::FilterOutOfRegionClosure(HeapRegion* r,
ysr@345 51 OopClosure* oc) :
tonyp@4192 52 _r_bottom(r->bottom()), _r_end(r->end()), _oc(oc) { }
ysr@345 53
ysr@345 54 template<class ClosureType>
ysr@345 55 HeapWord* walk_mem_region_loop(ClosureType* cl, G1CollectedHeap* g1h,
ysr@345 56 HeapRegion* hr,
ysr@345 57 HeapWord* cur, HeapWord* top) {
ysr@345 58 oop cur_oop = oop(cur);
ysr@345 59 int oop_size = cur_oop->size();
ysr@345 60 HeapWord* next_obj = cur + oop_size;
ysr@345 61 while (next_obj < top) {
ysr@345 62 // Keep filtering the remembered set.
ysr@345 63 if (!g1h->is_obj_dead(cur_oop, hr)) {
ysr@345 64 // Bottom lies entirely below top, so we can call the
ysr@345 65 // non-memRegion version of oop_iterate below.
ysr@345 66 cur_oop->oop_iterate(cl);
ysr@345 67 }
ysr@345 68 cur = next_obj;
ysr@345 69 cur_oop = oop(cur);
ysr@345 70 oop_size = cur_oop->size();
ysr@345 71 next_obj = cur + oop_size;
ysr@345 72 }
ysr@345 73 return cur;
ysr@345 74 }
ysr@345 75
ysr@345 76 void HeapRegionDCTOC::walk_mem_region_with_cl(MemRegion mr,
ysr@345 77 HeapWord* bottom,
ysr@345 78 HeapWord* top,
ysr@345 79 OopClosure* cl) {
ysr@345 80 G1CollectedHeap* g1h = _g1;
johnc@2970 81 int oop_size;
johnc@2970 82 OopClosure* cl2 = NULL;
ysr@345 83
johnc@2970 84 FilterIntoCSClosure intoCSFilt(this, g1h, cl);
ysr@345 85 FilterOutOfRegionClosure outOfRegionFilt(_hr, cl);
johnc@2967 86
ysr@345 87 switch (_fk) {
johnc@2970 88 case NoFilterKind: cl2 = cl; break;
ysr@345 89 case IntoCSFilterKind: cl2 = &intoCSFilt; break;
ysr@345 90 case OutOfRegionFilterKind: cl2 = &outOfRegionFilt; break;
johnc@2970 91 default: ShouldNotReachHere();
ysr@345 92 }
ysr@345 93
ysr@345 94 // Start filtering what we add to the remembered set. If the object is
ysr@345 95 // not considered dead, either because it is marked (in the mark bitmap)
ysr@345 96 // or it was allocated after marking finished, then we add it. Otherwise
ysr@345 97 // we can safely ignore the object.
ysr@345 98 if (!g1h->is_obj_dead(oop(bottom), _hr)) {
ysr@345 99 oop_size = oop(bottom)->oop_iterate(cl2, mr);
ysr@345 100 } else {
ysr@345 101 oop_size = oop(bottom)->size();
ysr@345 102 }
ysr@345 103
ysr@345 104 bottom += oop_size;
ysr@345 105
ysr@345 106 if (bottom < top) {
ysr@345 107 // We replicate the loop below for several kinds of possible filters.
ysr@345 108 switch (_fk) {
ysr@345 109 case NoFilterKind:
ysr@345 110 bottom = walk_mem_region_loop(cl, g1h, _hr, bottom, top);
ysr@345 111 break;
johnc@2967 112
ysr@345 113 case IntoCSFilterKind: {
johnc@2970 114 FilterIntoCSClosure filt(this, g1h, cl);
ysr@345 115 bottom = walk_mem_region_loop(&filt, g1h, _hr, bottom, top);
ysr@345 116 break;
ysr@345 117 }
johnc@2967 118
ysr@345 119 case OutOfRegionFilterKind: {
ysr@345 120 FilterOutOfRegionClosure filt(_hr, cl);
ysr@345 121 bottom = walk_mem_region_loop(&filt, g1h, _hr, bottom, top);
ysr@345 122 break;
ysr@345 123 }
johnc@2967 124
ysr@345 125 default:
ysr@345 126 ShouldNotReachHere();
ysr@345 127 }
ysr@345 128
ysr@345 129 // Last object. Need to do dead-obj filtering here too.
ysr@345 130 if (!g1h->is_obj_dead(oop(bottom), _hr)) {
ysr@345 131 oop(bottom)->oop_iterate(cl2, mr);
ysr@345 132 }
ysr@345 133 }
ysr@345 134 }
ysr@345 135
tonyp@996 136 // Minimum region size; we won't go lower than that.
tonyp@996 137 // We might want to decrease this in the future, to deal with small
tonyp@996 138 // heaps a bit more efficiently.
tonyp@996 139 #define MIN_REGION_SIZE ( 1024 * 1024 )
tonyp@996 140
tonyp@996 141 // Maximum region size; we don't go higher than that. There's a good
tonyp@996 142 // reason for having an upper bound. We don't want regions to get too
tonyp@996 143 // large, otherwise cleanup's effectiveness would decrease as there
tonyp@996 144 // will be fewer opportunities to find totally empty regions after
tonyp@996 145 // marking.
tonyp@996 146 #define MAX_REGION_SIZE ( 32 * 1024 * 1024 )
tonyp@996 147
tonyp@996 148 // The automatic region size calculation will try to have around this
tonyp@996 149 // many regions in the heap (based on the min heap size).
tonyp@996 150 #define TARGET_REGION_NUMBER 2048
tonyp@996 151
tonyp@996 152 void HeapRegion::setup_heap_region_size(uintx min_heap_size) {
tonyp@996 153 // region_size in bytes
tonyp@996 154 uintx region_size = G1HeapRegionSize;
tonyp@996 155 if (FLAG_IS_DEFAULT(G1HeapRegionSize)) {
tonyp@996 156 // We base the automatic calculation on the min heap size. This
tonyp@996 157 // can be problematic if the spread between min and max is quite
tonyp@996 158 // wide, imagine -Xms128m -Xmx32g. But, if we decided it based on
tonyp@996 159 // the max size, the region size might be way too large for the
tonyp@996 160 // min size. Either way, some users might have to set the region
tonyp@996 161 // size manually for some -Xms / -Xmx combos.
tonyp@996 162
tonyp@996 163 region_size = MAX2(min_heap_size / TARGET_REGION_NUMBER,
tonyp@996 164 (uintx) MIN_REGION_SIZE);
tonyp@996 165 }
tonyp@996 166
tonyp@996 167 int region_size_log = log2_long((jlong) region_size);
tonyp@996 168 // Recalculate the region size to make sure it's a power of
tonyp@996 169 // 2. This means that region_size is the largest power of 2 that's
tonyp@996 170 // <= what we've calculated so far.
prr@1496 171 region_size = ((uintx)1 << region_size_log);
tonyp@996 172
tonyp@996 173 // Now make sure that we don't go over or under our limits.
tonyp@996 174 if (region_size < MIN_REGION_SIZE) {
tonyp@996 175 region_size = MIN_REGION_SIZE;
tonyp@996 176 } else if (region_size > MAX_REGION_SIZE) {
tonyp@996 177 region_size = MAX_REGION_SIZE;
tonyp@996 178 }
tonyp@996 179
johnc@5169 180 if (region_size != G1HeapRegionSize) {
johnc@5169 181 // Update the flag to make sure that PrintFlagsFinal logs the correct value
johnc@5169 182 FLAG_SET_ERGO(uintx, G1HeapRegionSize, region_size);
johnc@5169 183 }
johnc@5169 184
tonyp@996 185 // And recalculate the log.
tonyp@996 186 region_size_log = log2_long((jlong) region_size);
tonyp@996 187
tonyp@996 188 // Now, set up the globals.
tonyp@996 189 guarantee(LogOfHRGrainBytes == 0, "we should only set it once");
tonyp@996 190 LogOfHRGrainBytes = region_size_log;
tonyp@996 191
tonyp@996 192 guarantee(LogOfHRGrainWords == 0, "we should only set it once");
tonyp@996 193 LogOfHRGrainWords = LogOfHRGrainBytes - LogHeapWordSize;
tonyp@996 194
tonyp@996 195 guarantee(GrainBytes == 0, "we should only set it once");
tonyp@996 196 // The cast to int is safe, given that we've bounded region_size by
tonyp@996 197 // MIN_REGION_SIZE and MAX_REGION_SIZE.
johnc@3035 198 GrainBytes = (size_t)region_size;
tonyp@996 199
tonyp@996 200 guarantee(GrainWords == 0, "we should only set it once");
tonyp@996 201 GrainWords = GrainBytes >> LogHeapWordSize;
tonyp@3953 202 guarantee((size_t) 1 << LogOfHRGrainWords == GrainWords, "sanity");
tonyp@996 203
tonyp@996 204 guarantee(CardsPerRegion == 0, "we should only set it once");
tonyp@996 205 CardsPerRegion = GrainBytes >> CardTableModRefBS::card_shift;
tonyp@996 206 }
tonyp@996 207
ysr@345 208 void HeapRegion::reset_after_compaction() {
ysr@345 209 G1OffsetTableContigSpace::reset_after_compaction();
ysr@345 210 // After a compaction the mark bitmap is invalid, so we must
ysr@345 211 // treat all objects as being inside the unmarked area.
ysr@345 212 zero_marked_bytes();
ysr@345 213 init_top_at_mark_start();
ysr@345 214 }
ysr@345 215
ysr@345 216 void HeapRegion::hr_clear(bool par, bool clear_space) {
tonyp@2165 217 assert(_humongous_type == NotHumongous,
tonyp@2165 218 "we should have already filtered out humongous regions");
tonyp@2165 219 assert(_humongous_start_region == NULL,
tonyp@2165 220 "we should have already filtered out humongous regions");
tonyp@2165 221 assert(_end == _orig_end,
tonyp@2165 222 "we should have already filtered out humongous regions");
tonyp@2165 223
ysr@345 224 _in_collection_set = false;
ysr@345 225
ysr@345 226 set_young_index_in_cset(-1);
ysr@345 227 uninstall_surv_rate_group();
ysr@345 228 set_young_type(NotYoung);
tonyp@2417 229 reset_pre_dummy_top();
ysr@345 230
ysr@345 231 if (!par) {
ysr@345 232 // If this is parallel, this will be done later.
ysr@345 233 HeapRegionRemSet* hrrs = rem_set();
johnc@5169 234 hrrs->clear();
tonyp@358 235 _claimed = InitialClaimValue;
ysr@345 236 }
ysr@345 237 zero_marked_bytes();
ysr@345 238
ysr@345 239 _offsets.resize(HeapRegion::GrainWords);
ysr@345 240 init_top_at_mark_start();
tonyp@359 241 if (clear_space) clear(SpaceDecorator::Mangle);
ysr@345 242 }
ysr@345 243
tonyp@2558 244 void HeapRegion::par_clear() {
tonyp@2558 245 assert(used() == 0, "the region should have been already cleared");
johnc@3035 246 assert(capacity() == HeapRegion::GrainBytes, "should be back to normal");
tonyp@2558 247 HeapRegionRemSet* hrrs = rem_set();
tonyp@2558 248 hrrs->clear();
tonyp@2558 249 CardTableModRefBS* ct_bs =
tonyp@2558 250 (CardTableModRefBS*)G1CollectedHeap::heap()->barrier_set();
tonyp@2558 251 ct_bs->clear(MemRegion(bottom(), end()));
tonyp@2558 252 }
tonyp@2558 253
ysr@345 254 void HeapRegion::calc_gc_efficiency() {
johnc@4233 255 // GC efficiency is the ratio of how much space would be
johnc@4233 256 // reclaimed over how long we predict it would take to reclaim it.
ysr@345 257 G1CollectedHeap* g1h = G1CollectedHeap::heap();
tonyp@3414 258 G1CollectorPolicy* g1p = g1h->g1_policy();
johnc@4233 259
johnc@4233 260 // Retrieve a prediction of the elapsed time for this region for
johnc@4233 261 // a mixed gc because the region will only be evacuated during a
johnc@4233 262 // mixed gc.
johnc@4233 263 double region_elapsed_time_ms =
johnc@4233 264 g1p->predict_region_elapsed_time_ms(this, false /* for_young_gc */);
johnc@4233 265 _gc_efficiency = (double) reclaimable_bytes() / region_elapsed_time_ms;
ysr@345 266 }
ysr@345 267
tonyp@2146 268 void HeapRegion::set_startsHumongous(HeapWord* new_top, HeapWord* new_end) {
tonyp@2165 269 assert(!isHumongous(), "sanity / pre-condition");
tonyp@1911 270 assert(end() == _orig_end,
tonyp@1911 271 "Should be normal before the humongous object allocation");
tonyp@1911 272 assert(top() == bottom(), "should be empty");
tonyp@2146 273 assert(bottom() <= new_top && new_top <= new_end, "pre-condition");
tonyp@1911 274
tonyp@358 275 _humongous_type = StartsHumongous;
ysr@345 276 _humongous_start_region = this;
tonyp@1911 277
tonyp@1911 278 set_end(new_end);
tonyp@2146 279 _offsets.set_for_starts_humongous(new_top);
tonyp@1911 280 }
tonyp@1911 281
tonyp@2146 282 void HeapRegion::set_continuesHumongous(HeapRegion* first_hr) {
tonyp@2165 283 assert(!isHumongous(), "sanity / pre-condition");
tonyp@1911 284 assert(end() == _orig_end,
tonyp@1911 285 "Should be normal before the humongous object allocation");
tonyp@1911 286 assert(top() == bottom(), "should be empty");
tonyp@2146 287 assert(first_hr->startsHumongous(), "pre-condition");
tonyp@1911 288
tonyp@1911 289 _humongous_type = ContinuesHumongous;
tonyp@2146 290 _humongous_start_region = first_hr;
ysr@345 291 }
ysr@345 292
tonyp@2165 293 void HeapRegion::set_notHumongous() {
tonyp@2165 294 assert(isHumongous(), "pre-condition");
tonyp@2165 295
tonyp@2165 296 if (startsHumongous()) {
tonyp@2165 297 assert(top() <= end(), "pre-condition");
tonyp@2165 298 set_end(_orig_end);
tonyp@2165 299 if (top() > end()) {
tonyp@2165 300 // at least one "continues humongous" region after it
tonyp@2165 301 set_top(end());
tonyp@2165 302 }
tonyp@2165 303 } else {
tonyp@2165 304 // continues humongous
tonyp@2165 305 assert(end() == _orig_end, "sanity");
tonyp@2165 306 }
tonyp@2165 307
johnc@3035 308 assert(capacity() == HeapRegion::GrainBytes, "pre-condition");
tonyp@2165 309 _humongous_type = NotHumongous;
tonyp@2165 310 _humongous_start_region = NULL;
tonyp@2165 311 }
tonyp@2165 312
ysr@345 313 bool HeapRegion::claimHeapRegion(jint claimValue) {
ysr@345 314 jint current = _claimed;
ysr@345 315 if (current != claimValue) {
ysr@345 316 jint res = Atomic::cmpxchg(claimValue, &_claimed, current);
ysr@345 317 if (res == current) {
ysr@345 318 return true;
ysr@345 319 }
ysr@345 320 }
ysr@345 321 return false;
ysr@345 322 }
ysr@345 323
ysr@345 324 HeapWord* HeapRegion::next_block_start_careful(HeapWord* addr) {
ysr@345 325 HeapWord* low = addr;
ysr@345 326 HeapWord* high = end();
ysr@345 327 while (low < high) {
ysr@345 328 size_t diff = pointer_delta(high, low);
ysr@345 329 // Must add one below to bias toward the high amount. Otherwise, if
ysr@345 330 // "high" were at the desired value, and "low" were one less, we
ysr@345 331 // would not converge on "high". This is not symmetric, because
ysr@345 332 // we set "high" to a block start, which might be the right one,
ysr@345 333 // which we don't do for "low".
ysr@345 334 HeapWord* middle = low + (diff+1)/2;
ysr@345 335 if (middle == high) return high;
ysr@345 336 HeapWord* mid_bs = block_start_careful(middle);
ysr@345 337 if (mid_bs < addr) {
ysr@345 338 low = middle;
ysr@345 339 } else {
ysr@345 340 high = mid_bs;
ysr@345 341 }
ysr@345 342 }
ysr@345 343 assert(low == high && low >= addr, "Didn't work.");
ysr@345 344 return low;
ysr@345 345 }
ysr@345 346
tonyp@359 347 void HeapRegion::initialize(MemRegion mr, bool clear_space, bool mangle_space) {
tonyp@359 348 G1OffsetTableContigSpace::initialize(mr, false, mangle_space);
ysr@345 349 hr_clear(false/*par*/, clear_space);
ysr@345 350 }
ysr@345 351 #ifdef _MSC_VER // the use of 'this' below gets a warning, make it go away
ysr@345 352 #pragma warning( disable:4355 ) // 'this' : used in base member initializer list
ysr@345 353 #endif // _MSC_VER
ysr@345 354
ysr@345 355
tonyp@3953 356 HeapRegion::HeapRegion(uint hrs_index,
tonyp@3953 357 G1BlockOffsetSharedArray* sharedOffsetArray,
tonyp@3953 358 MemRegion mr, bool is_zeroed) :
tonyp@3953 359 G1OffsetTableContigSpace(sharedOffsetArray, mr, is_zeroed),
johnc@2967 360 _hrs_index(hrs_index),
tonyp@358 361 _humongous_type(NotHumongous), _humongous_start_region(NULL),
tonyp@2825 362 _in_collection_set(false),
ysr@345 363 _next_in_special_set(NULL), _orig_end(NULL),
tonyp@358 364 _claimed(InitialClaimValue), _evacuation_failed(false),
tonyp@3954 365 _prev_marked_bytes(0), _next_marked_bytes(0), _gc_efficiency(0.0),
ysr@345 366 _young_type(NotYoung), _next_young_region(NULL),
tonyp@2165 367 _next_dirty_cards_region(NULL), _next(NULL), _pending_removal(false),
tonyp@2165 368 #ifdef ASSERT
tonyp@2165 369 _containing_set(NULL),
tonyp@2165 370 #endif // ASSERT
tonyp@2165 371 _young_index_in_cset(-1), _surv_rate_group(NULL), _age_index(-1),
tonyp@2165 372 _rem_set(NULL), _recorded_rs_length(0), _predicted_elapsed_time_ms(0),
johnc@1483 373 _predicted_bytes_to_copy(0)
ysr@345 374 {
johnc@5169 375 _rem_set = new HeapRegionRemSet(sharedOffsetArray, this);
ysr@345 376 _orig_end = mr.end();
ysr@345 377 // Note that initialize() will set the start of the unmarked area of the
ysr@345 378 // region.
tonyp@359 379 this->initialize(mr, !is_zeroed, SpaceDecorator::Mangle);
tonyp@359 380 set_top(bottom());
tonyp@359 381 set_saved_mark();
ysr@345 382
ysr@345 383 assert(HeapRegionRemSet::num_par_rem_sets() > 0, "Invariant.");
ysr@345 384 }
ysr@345 385
tonyp@4192 386 CompactibleSpace* HeapRegion::next_compaction_space() const {
tonyp@4192 387 // We're not using an iterator given that it will wrap around when
tonyp@4192 388 // it reaches the last region and this is not what we want here.
tonyp@4192 389 G1CollectedHeap* g1h = G1CollectedHeap::heap();
tonyp@4192 390 uint index = hrs_index() + 1;
tonyp@4192 391 while (index < g1h->n_regions()) {
tonyp@4192 392 HeapRegion* hr = g1h->region_at(index);
tonyp@4192 393 if (!hr->isHumongous()) {
tonyp@4192 394 return hr;
ysr@345 395 }
tonyp@4192 396 index += 1;
ysr@345 397 }
tonyp@4192 398 return NULL;
ysr@345 399 }
ysr@345 400
ysr@345 401 void HeapRegion::save_marks() {
ysr@345 402 set_saved_mark();
ysr@345 403 }
ysr@345 404
ysr@345 405 void HeapRegion::oops_in_mr_iterate(MemRegion mr, OopClosure* cl) {
ysr@345 406 HeapWord* p = mr.start();
ysr@345 407 HeapWord* e = mr.end();
ysr@345 408 oop obj;
ysr@345 409 while (p < e) {
ysr@345 410 obj = oop(p);
ysr@345 411 p += obj->oop_iterate(cl);
ysr@345 412 }
ysr@345 413 assert(p == e, "bad memregion: doesn't end on obj boundary");
ysr@345 414 }
ysr@345 415
ysr@345 416 #define HeapRegion_OOP_SINCE_SAVE_MARKS_DEFN(OopClosureType, nv_suffix) \
ysr@345 417 void HeapRegion::oop_since_save_marks_iterate##nv_suffix(OopClosureType* cl) { \
ysr@345 418 ContiguousSpace::oop_since_save_marks_iterate##nv_suffix(cl); \
ysr@345 419 }
ysr@345 420 SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(HeapRegion_OOP_SINCE_SAVE_MARKS_DEFN)
ysr@345 421
ysr@345 422
ysr@345 423 void HeapRegion::oop_before_save_marks_iterate(OopClosure* cl) {
ysr@345 424 oops_in_mr_iterate(MemRegion(bottom(), saved_mark_word()), cl);
ysr@345 425 }
ysr@345 426
tonyp@3280 427 void HeapRegion::note_self_forwarding_removal_start(bool during_initial_mark,
tonyp@3280 428 bool during_conc_mark) {
tonyp@3280 429 // We always recreate the prev marking info and we'll explicitly
tonyp@3280 430 // mark all objects we find to be self-forwarded on the prev
tonyp@3280 431 // bitmap. So all objects need to be below PTAMS.
tonyp@3280 432 _prev_top_at_mark_start = top();
tonyp@3280 433 _prev_marked_bytes = 0;
tonyp@3280 434
tonyp@3280 435 if (during_initial_mark) {
tonyp@3280 436 // During initial-mark, we'll also explicitly mark all objects
tonyp@3280 437 // we find to be self-forwarded on the next bitmap. So all
tonyp@3280 438 // objects need to be below NTAMS.
tonyp@3280 439 _next_top_at_mark_start = top();
tonyp@3280 440 _next_marked_bytes = 0;
tonyp@3280 441 } else if (during_conc_mark) {
tonyp@3280 442 // During concurrent mark, all objects in the CSet (including
tonyp@3280 443 // the ones we find to be self-forwarded) are implicitly live.
tonyp@3280 444 // So all objects need to be above NTAMS.
tonyp@3280 445 _next_top_at_mark_start = bottom();
tonyp@3280 446 _next_marked_bytes = 0;
tonyp@3280 447 }
tonyp@3280 448 }
tonyp@3280 449
tonyp@3280 450 void HeapRegion::note_self_forwarding_removal_end(bool during_initial_mark,
tonyp@3280 451 bool during_conc_mark,
tonyp@3280 452 size_t marked_bytes) {
tonyp@3280 453 assert(0 <= marked_bytes && marked_bytes <= used(),
tonyp@3280 454 err_msg("marked: "SIZE_FORMAT" used: "SIZE_FORMAT,
tonyp@3280 455 marked_bytes, used()));
tonyp@3280 456 _prev_marked_bytes = marked_bytes;
tonyp@3280 457 }
tonyp@3280 458
ysr@345 459 HeapWord*
ysr@345 460 HeapRegion::object_iterate_mem_careful(MemRegion mr,
ysr@345 461 ObjectClosure* cl) {
ysr@345 462 G1CollectedHeap* g1h = G1CollectedHeap::heap();
ysr@345 463 // We used to use "block_start_careful" here. But we're actually happy
ysr@345 464 // to update the BOT while we do this...
ysr@345 465 HeapWord* cur = block_start(mr.start());
ysr@345 466 mr = mr.intersection(used_region());
ysr@345 467 if (mr.is_empty()) return NULL;
ysr@345 468 // Otherwise, find the obj that extends onto mr.start().
ysr@345 469
ysr@345 470 assert(cur <= mr.start()
ysr@896 471 && (oop(cur)->klass_or_null() == NULL ||
ysr@345 472 cur + oop(cur)->size() > mr.start()),
ysr@345 473 "postcondition of block_start");
ysr@345 474 oop obj;
ysr@345 475 while (cur < mr.end()) {
ysr@345 476 obj = oop(cur);
ysr@896 477 if (obj->klass_or_null() == NULL) {
ysr@345 478 // Ran into an unparseable point.
ysr@345 479 return cur;
ysr@345 480 } else if (!g1h->is_obj_dead(obj)) {
ysr@345 481 cl->do_object(obj);
ysr@345 482 }
ysr@345 483 if (cl->abort()) return cur;
ysr@345 484 // The check above must occur before the operation below, since an
ysr@345 485 // abort might invalidate the "size" operation.
ysr@345 486 cur += obj->size();
ysr@345 487 }
ysr@345 488 return NULL;
ysr@345 489 }
ysr@345 490
ysr@345 491 HeapWord*
ysr@345 492 HeapRegion::
ysr@345 493 oops_on_card_seq_iterate_careful(MemRegion mr,
johnc@1685 494 FilterOutOfRegionClosure* cl,
tonyp@2558 495 bool filter_young,
tonyp@2558 496 jbyte* card_ptr) {
tonyp@2558 497 // Currently, we should only have to clean the card if filter_young
tonyp@2558 498 // is true and vice versa.
tonyp@2558 499 if (filter_young) {
tonyp@2558 500 assert(card_ptr != NULL, "pre-condition");
tonyp@2558 501 } else {
tonyp@2558 502 assert(card_ptr == NULL, "pre-condition");
tonyp@2558 503 }
ysr@345 504 G1CollectedHeap* g1h = G1CollectedHeap::heap();
ysr@345 505
ysr@345 506 // If we're within a stop-world GC, then we might look at a card in a
ysr@345 507 // GC alloc region that extends onto a GC LAB, which may not be
ysr@345 508 // parseable. Stop such at the "saved_mark" of the region.
johnc@3335 509 if (g1h->is_gc_active()) {
ysr@345 510 mr = mr.intersection(used_region_at_save_marks());
ysr@345 511 } else {
ysr@345 512 mr = mr.intersection(used_region());
ysr@345 513 }
ysr@345 514 if (mr.is_empty()) return NULL;
ysr@345 515 // Otherwise, find the obj that extends onto mr.start().
ysr@345 516
johnc@1685 517 // The intersection of the incoming mr (for the card) and the
johnc@1685 518 // allocated part of the region is non-empty. This implies that
johnc@1685 519 // we have actually allocated into this region. The code in
johnc@1685 520 // G1CollectedHeap.cpp that allocates a new region sets the
johnc@1685 521 // is_young tag on the region before allocating. Thus we
johnc@1685 522 // safely know if this region is young.
johnc@1685 523 if (is_young() && filter_young) {
johnc@1685 524 return NULL;
johnc@1685 525 }
johnc@1685 526
johnc@1727 527 assert(!is_young(), "check value of filter_young");
johnc@1727 528
tonyp@2558 529 // We can only clean the card here, after we make the decision that
tonyp@2558 530 // the card is not young. And we only clean the card if we have been
tonyp@2558 531 // asked to (i.e., card_ptr != NULL).
tonyp@2558 532 if (card_ptr != NULL) {
tonyp@2558 533 *card_ptr = CardTableModRefBS::clean_card_val();
tonyp@2558 534 // We must complete this write before we do any of the reads below.
tonyp@2558 535 OrderAccess::storeload();
tonyp@2558 536 }
tonyp@2558 537
johnc@3335 538 // Cache the boundaries of the memory region in some const locals
johnc@3335 539 HeapWord* const start = mr.start();
johnc@3335 540 HeapWord* const end = mr.end();
johnc@3335 541
ysr@345 542 // We used to use "block_start_careful" here. But we're actually happy
ysr@345 543 // to update the BOT while we do this...
johnc@3335 544 HeapWord* cur = block_start(start);
johnc@3335 545 assert(cur <= start, "Postcondition");
ysr@345 546
johnc@3335 547 oop obj;
johnc@3335 548
johnc@3335 549 HeapWord* next = cur;
johnc@3335 550 while (next <= start) {
johnc@3335 551 cur = next;
johnc@3335 552 obj = oop(cur);
johnc@3335 553 if (obj->klass_or_null() == NULL) {
ysr@345 554 // Ran into an unparseable point.
ysr@345 555 return cur;
ysr@345 556 }
ysr@345 557 // Otherwise...
johnc@3335 558 next = (cur + obj->size());
ysr@345 559 }
johnc@3335 560
johnc@3335 561 // If we finish the above loop...We have a parseable object that
johnc@3335 562 // begins on or before the start of the memory region, and ends
johnc@3335 563 // inside or spans the entire region.
johnc@3335 564
johnc@3335 565 assert(obj == oop(cur), "sanity");
johnc@3335 566 assert(cur <= start &&
johnc@3335 567 obj->klass_or_null() != NULL &&
johnc@3335 568 (cur + obj->size()) > start,
ysr@345 569 "Loop postcondition");
johnc@3335 570
ysr@345 571 if (!g1h->is_obj_dead(obj)) {
ysr@345 572 obj->oop_iterate(cl, mr);
ysr@345 573 }
ysr@345 574
johnc@3335 575 while (cur < end) {
ysr@345 576 obj = oop(cur);
ysr@896 577 if (obj->klass_or_null() == NULL) {
ysr@345 578 // Ran into an unparseable point.
ysr@345 579 return cur;
ysr@345 580 };
johnc@3335 581
ysr@345 582 // Otherwise:
ysr@345 583 next = (cur + obj->size());
johnc@3335 584
ysr@345 585 if (!g1h->is_obj_dead(obj)) {
johnc@3335 586 if (next < end || !obj->is_objArray()) {
johnc@3335 587 // This object either does not span the MemRegion
johnc@3335 588 // boundary, or if it does it's not an array.
johnc@3335 589 // Apply closure to whole object.
ysr@345 590 obj->oop_iterate(cl);
ysr@345 591 } else {
johnc@3335 592 // This obj is an array that spans the boundary.
johnc@3335 593 // Stop at the boundary.
johnc@3335 594 obj->oop_iterate(cl, mr);
ysr@345 595 }
ysr@345 596 }
ysr@345 597 cur = next;
ysr@345 598 }
ysr@345 599 return NULL;
ysr@345 600 }
ysr@345 601
johnc@5169 602 // Code roots support
johnc@5169 603
johnc@5169 604 void HeapRegion::add_strong_code_root(nmethod* nm) {
johnc@5169 605 HeapRegionRemSet* hrrs = rem_set();
johnc@5169 606 hrrs->add_strong_code_root(nm);
johnc@5169 607 }
johnc@5169 608
johnc@5169 609 void HeapRegion::remove_strong_code_root(nmethod* nm) {
johnc@5169 610 HeapRegionRemSet* hrrs = rem_set();
johnc@5169 611 hrrs->remove_strong_code_root(nm);
johnc@5169 612 }
johnc@5169 613
johnc@5169 614 void HeapRegion::migrate_strong_code_roots() {
johnc@5169 615 assert(in_collection_set(), "only collection set regions");
tschatzl@5174 616 assert(!isHumongous(),
tschatzl@5174 617 err_msg("humongous region "HR_FORMAT" should not have been added to collection set",
tschatzl@5174 618 HR_FORMAT_PARAMS(this)));
johnc@5169 619
johnc@5169 620 HeapRegionRemSet* hrrs = rem_set();
johnc@5169 621 hrrs->migrate_strong_code_roots();
johnc@5169 622 }
johnc@5169 623
johnc@5169 624 void HeapRegion::strong_code_roots_do(CodeBlobClosure* blk) const {
johnc@5169 625 HeapRegionRemSet* hrrs = rem_set();
johnc@5169 626 hrrs->strong_code_roots_do(blk);
johnc@5169 627 }
johnc@5169 628
johnc@5169 629 class VerifyStrongCodeRootOopClosure: public OopClosure {
johnc@5169 630 const HeapRegion* _hr;
johnc@5169 631 nmethod* _nm;
johnc@5169 632 bool _failures;
johnc@5169 633 bool _has_oops_in_region;
johnc@5169 634
johnc@5169 635 template <class T> void do_oop_work(T* p) {
johnc@5169 636 T heap_oop = oopDesc::load_heap_oop(p);
johnc@5169 637 if (!oopDesc::is_null(heap_oop)) {
johnc@5169 638 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
johnc@5169 639
johnc@5169 640 // Note: not all the oops embedded in the nmethod are in the
johnc@5169 641 // current region. We only look at those which are.
johnc@5169 642 if (_hr->is_in(obj)) {
johnc@5169 643 // Object is in the region. Check that its less than top
johnc@5169 644 if (_hr->top() <= (HeapWord*)obj) {
johnc@5169 645 // Object is above top
johnc@5169 646 gclog_or_tty->print_cr("Object "PTR_FORMAT" in region "
johnc@5169 647 "["PTR_FORMAT", "PTR_FORMAT") is above "
johnc@5169 648 "top "PTR_FORMAT,
johnc@5169 649 obj, _hr->bottom(), _hr->end(), _hr->top());
johnc@5169 650 _failures = true;
johnc@5169 651 return;
johnc@5169 652 }
johnc@5169 653 // Nmethod has at least one oop in the current region
johnc@5169 654 _has_oops_in_region = true;
johnc@5169 655 }
johnc@5169 656 }
johnc@5169 657 }
johnc@5169 658
johnc@5169 659 public:
johnc@5169 660 VerifyStrongCodeRootOopClosure(const HeapRegion* hr, nmethod* nm):
johnc@5169 661 _hr(hr), _failures(false), _has_oops_in_region(false) {}
johnc@5169 662
johnc@5169 663 void do_oop(narrowOop* p) { do_oop_work(p); }
johnc@5169 664 void do_oop(oop* p) { do_oop_work(p); }
johnc@5169 665
johnc@5169 666 bool failures() { return _failures; }
johnc@5169 667 bool has_oops_in_region() { return _has_oops_in_region; }
johnc@5169 668 };
johnc@5169 669
johnc@5169 670 class VerifyStrongCodeRootCodeBlobClosure: public CodeBlobClosure {
johnc@5169 671 const HeapRegion* _hr;
johnc@5169 672 bool _failures;
johnc@5169 673 public:
johnc@5169 674 VerifyStrongCodeRootCodeBlobClosure(const HeapRegion* hr) :
johnc@5169 675 _hr(hr), _failures(false) {}
johnc@5169 676
johnc@5169 677 void do_code_blob(CodeBlob* cb) {
johnc@5169 678 nmethod* nm = (cb == NULL) ? NULL : cb->as_nmethod_or_null();
johnc@5169 679 if (nm != NULL) {
johnc@5169 680 // Verify that the nemthod is live
johnc@5169 681 if (!nm->is_alive()) {
johnc@5169 682 gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] has dead nmethod "
johnc@5169 683 PTR_FORMAT" in its strong code roots",
johnc@5169 684 _hr->bottom(), _hr->end(), nm);
johnc@5169 685 _failures = true;
johnc@5169 686 } else {
johnc@5169 687 VerifyStrongCodeRootOopClosure oop_cl(_hr, nm);
johnc@5169 688 nm->oops_do(&oop_cl);
johnc@5169 689 if (!oop_cl.has_oops_in_region()) {
johnc@5169 690 gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] has nmethod "
johnc@5169 691 PTR_FORMAT" in its strong code roots "
johnc@5169 692 "with no pointers into region",
johnc@5169 693 _hr->bottom(), _hr->end(), nm);
johnc@5169 694 _failures = true;
johnc@5169 695 } else if (oop_cl.failures()) {
johnc@5169 696 gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] has other "
johnc@5169 697 "failures for nmethod "PTR_FORMAT,
johnc@5169 698 _hr->bottom(), _hr->end(), nm);
johnc@5169 699 _failures = true;
johnc@5169 700 }
johnc@5169 701 }
johnc@5169 702 }
johnc@5169 703 }
johnc@5169 704
johnc@5169 705 bool failures() { return _failures; }
johnc@5169 706 };
johnc@5169 707
johnc@5169 708 void HeapRegion::verify_strong_code_roots(VerifyOption vo, bool* failures) const {
johnc@5169 709 if (!G1VerifyHeapRegionCodeRoots) {
johnc@5169 710 // We're not verifying code roots.
johnc@5169 711 return;
johnc@5169 712 }
johnc@5169 713 if (vo == VerifyOption_G1UseMarkWord) {
johnc@5169 714 // Marking verification during a full GC is performed after class
johnc@5169 715 // unloading, code cache unloading, etc so the strong code roots
johnc@5169 716 // attached to each heap region are in an inconsistent state. They won't
johnc@5169 717 // be consistent until the strong code roots are rebuilt after the
johnc@5169 718 // actual GC. Skip verifying the strong code roots in this particular
johnc@5169 719 // time.
johnc@5169 720 assert(VerifyDuringGC, "only way to get here");
johnc@5169 721 return;
johnc@5169 722 }
johnc@5169 723
johnc@5169 724 HeapRegionRemSet* hrrs = rem_set();
johnc@5169 725 int strong_code_roots_length = hrrs->strong_code_roots_list_length();
johnc@5169 726
johnc@5169 727 // if this region is empty then there should be no entries
johnc@5169 728 // on its strong code root list
johnc@5169 729 if (is_empty()) {
johnc@5169 730 if (strong_code_roots_length > 0) {
johnc@5169 731 gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] is empty "
johnc@5169 732 "but has "INT32_FORMAT" code root entries",
johnc@5169 733 bottom(), end(), strong_code_roots_length);
johnc@5169 734 *failures = true;
johnc@5169 735 }
johnc@5169 736 return;
johnc@5169 737 }
johnc@5169 738
tschatzl@5174 739 if (continuesHumongous()) {
johnc@5169 740 if (strong_code_roots_length > 0) {
tschatzl@5174 741 gclog_or_tty->print_cr("region "HR_FORMAT" is a continuation of a humongous "
tschatzl@5174 742 "region but has "INT32_FORMAT" code root entries",
tschatzl@5174 743 HR_FORMAT_PARAMS(this), strong_code_roots_length);
johnc@5169 744 *failures = true;
johnc@5169 745 }
johnc@5169 746 return;
johnc@5169 747 }
johnc@5169 748
johnc@5169 749 VerifyStrongCodeRootCodeBlobClosure cb_cl(this);
johnc@5169 750 strong_code_roots_do(&cb_cl);
johnc@5169 751
johnc@5169 752 if (cb_cl.failures()) {
johnc@5169 753 *failures = true;
johnc@5169 754 }
johnc@5169 755 }
johnc@5169 756
ysr@345 757 void HeapRegion::print() const { print_on(gclog_or_tty); }
ysr@345 758 void HeapRegion::print_on(outputStream* st) const {
ysr@345 759 if (isHumongous()) {
ysr@345 760 if (startsHumongous())
ysr@345 761 st->print(" HS");
ysr@345 762 else
ysr@345 763 st->print(" HC");
ysr@345 764 } else {
ysr@345 765 st->print(" ");
ysr@345 766 }
ysr@345 767 if (in_collection_set())
ysr@345 768 st->print(" CS");
ysr@345 769 else
ysr@345 770 st->print(" ");
ysr@345 771 if (is_young())
johnc@1483 772 st->print(is_survivor() ? " SU" : " Y ");
ysr@345 773 else
ysr@345 774 st->print(" ");
ysr@345 775 if (is_empty())
ysr@345 776 st->print(" F");
ysr@345 777 else
ysr@345 778 st->print(" ");
tonyp@3124 779 st->print(" TS %5d", _gc_time_stamp);
tonyp@1477 780 st->print(" PTAMS "PTR_FORMAT" NTAMS "PTR_FORMAT,
tonyp@1477 781 prev_top_at_mark_start(), next_top_at_mark_start());
ysr@345 782 G1OffsetTableContigSpace::print_on(st);
ysr@345 783 }
ysr@345 784
johnc@5169 785 class VerifyLiveClosure: public OopClosure {
johnc@5169 786 private:
johnc@5169 787 G1CollectedHeap* _g1h;
johnc@5169 788 CardTableModRefBS* _bs;
johnc@5169 789 oop _containing_obj;
johnc@5169 790 bool _failures;
johnc@5169 791 int _n_failures;
johnc@5169 792 VerifyOption _vo;
johnc@5169 793 public:
johnc@5169 794 // _vo == UsePrevMarking -> use "prev" marking information,
johnc@5169 795 // _vo == UseNextMarking -> use "next" marking information,
johnc@5169 796 // _vo == UseMarkWord -> use mark word from object header.
johnc@5169 797 VerifyLiveClosure(G1CollectedHeap* g1h, VerifyOption vo) :
johnc@5169 798 _g1h(g1h), _bs(NULL), _containing_obj(NULL),
johnc@5169 799 _failures(false), _n_failures(0), _vo(vo)
johnc@5169 800 {
johnc@5169 801 BarrierSet* bs = _g1h->barrier_set();
johnc@5169 802 if (bs->is_a(BarrierSet::CardTableModRef))
johnc@5169 803 _bs = (CardTableModRefBS*)bs;
johnc@5169 804 }
johnc@5169 805
johnc@5169 806 void set_containing_obj(oop obj) {
johnc@5169 807 _containing_obj = obj;
johnc@5169 808 }
johnc@5169 809
johnc@5169 810 bool failures() { return _failures; }
johnc@5169 811 int n_failures() { return _n_failures; }
johnc@5169 812
johnc@5169 813 virtual void do_oop(narrowOop* p) { do_oop_work(p); }
johnc@5169 814 virtual void do_oop( oop* p) { do_oop_work(p); }
johnc@5169 815
johnc@5169 816 void print_object(outputStream* out, oop obj) {
johnc@5169 817 #ifdef PRODUCT
johnc@5169 818 klassOop k = obj->klass();
johnc@5169 819 const char* class_name = instanceKlass::cast(k)->external_name();
johnc@5169 820 out->print_cr("class name %s", class_name);
johnc@5169 821 #else // PRODUCT
johnc@5169 822 obj->print_on(out);
johnc@5169 823 #endif // PRODUCT
johnc@5169 824 }
johnc@5169 825
johnc@5169 826 template <class T>
johnc@5169 827 void do_oop_work(T* p) {
johnc@5169 828 assert(_containing_obj != NULL, "Precondition");
johnc@5169 829 assert(!_g1h->is_obj_dead_cond(_containing_obj, _vo),
johnc@5169 830 "Precondition");
johnc@5169 831 T heap_oop = oopDesc::load_heap_oop(p);
johnc@5169 832 if (!oopDesc::is_null(heap_oop)) {
johnc@5169 833 oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
johnc@5169 834 bool failed = false;
johnc@5169 835 if (!_g1h->is_in_closed_subset(obj) || _g1h->is_obj_dead_cond(obj, _vo)) {
johnc@5169 836 MutexLockerEx x(ParGCRareEvent_lock,
johnc@5169 837 Mutex::_no_safepoint_check_flag);
johnc@5169 838
johnc@5169 839 if (!_failures) {
johnc@5169 840 gclog_or_tty->print_cr("");
johnc@5169 841 gclog_or_tty->print_cr("----------");
johnc@5169 842 }
johnc@5169 843 if (!_g1h->is_in_closed_subset(obj)) {
johnc@5169 844 HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
johnc@5169 845 gclog_or_tty->print_cr("Field "PTR_FORMAT
johnc@5169 846 " of live obj "PTR_FORMAT" in region "
johnc@5169 847 "["PTR_FORMAT", "PTR_FORMAT")",
johnc@5169 848 p, (void*) _containing_obj,
johnc@5169 849 from->bottom(), from->end());
johnc@5169 850 print_object(gclog_or_tty, _containing_obj);
johnc@5169 851 gclog_or_tty->print_cr("points to obj "PTR_FORMAT" not in the heap",
johnc@5169 852 (void*) obj);
johnc@5169 853 } else {
johnc@5169 854 HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
johnc@5169 855 HeapRegion* to = _g1h->heap_region_containing((HeapWord*)obj);
johnc@5169 856 gclog_or_tty->print_cr("Field "PTR_FORMAT
johnc@5169 857 " of live obj "PTR_FORMAT" in region "
johnc@5169 858 "["PTR_FORMAT", "PTR_FORMAT")",
johnc@5169 859 p, (void*) _containing_obj,
johnc@5169 860 from->bottom(), from->end());
johnc@5169 861 print_object(gclog_or_tty, _containing_obj);
johnc@5169 862 gclog_or_tty->print_cr("points to dead obj "PTR_FORMAT" in region "
johnc@5169 863 "["PTR_FORMAT", "PTR_FORMAT")",
johnc@5169 864 (void*) obj, to->bottom(), to->end());
johnc@5169 865 print_object(gclog_or_tty, obj);
johnc@5169 866 }
johnc@5169 867 gclog_or_tty->print_cr("----------");
johnc@5169 868 gclog_or_tty->flush();
johnc@5169 869 _failures = true;
johnc@5169 870 failed = true;
johnc@5169 871 _n_failures++;
johnc@5169 872 }
johnc@5169 873
johnc@5169 874 if (!_g1h->full_collection() || G1VerifyRSetsDuringFullGC) {
johnc@5169 875 HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
johnc@5169 876 HeapRegion* to = _g1h->heap_region_containing(obj);
johnc@5169 877 if (from != NULL && to != NULL &&
johnc@5169 878 from != to &&
johnc@5169 879 !to->isHumongous()) {
johnc@5169 880 jbyte cv_obj = *_bs->byte_for_const(_containing_obj);
johnc@5169 881 jbyte cv_field = *_bs->byte_for_const(p);
johnc@5169 882 const jbyte dirty = CardTableModRefBS::dirty_card_val();
johnc@5169 883
johnc@5169 884 bool is_bad = !(from->is_young()
johnc@5169 885 || to->rem_set()->contains_reference(p)
johnc@5169 886 || !G1HRRSFlushLogBuffersOnVerify && // buffers were not flushed
johnc@5169 887 (_containing_obj->is_objArray() ?
johnc@5169 888 cv_field == dirty
johnc@5169 889 : cv_obj == dirty || cv_field == dirty));
johnc@5169 890 if (is_bad) {
johnc@5169 891 MutexLockerEx x(ParGCRareEvent_lock,
johnc@5169 892 Mutex::_no_safepoint_check_flag);
johnc@5169 893
johnc@5169 894 if (!_failures) {
johnc@5169 895 gclog_or_tty->print_cr("");
johnc@5169 896 gclog_or_tty->print_cr("----------");
johnc@5169 897 }
johnc@5169 898 gclog_or_tty->print_cr("Missing rem set entry:");
johnc@5169 899 gclog_or_tty->print_cr("Field "PTR_FORMAT" "
johnc@5169 900 "of obj "PTR_FORMAT", "
johnc@5169 901 "in region "HR_FORMAT,
johnc@5169 902 p, (void*) _containing_obj,
johnc@5169 903 HR_FORMAT_PARAMS(from));
johnc@5169 904 _containing_obj->print_on(gclog_or_tty);
johnc@5169 905 gclog_or_tty->print_cr("points to obj "PTR_FORMAT" "
johnc@5169 906 "in region "HR_FORMAT,
johnc@5169 907 (void*) obj,
johnc@5169 908 HR_FORMAT_PARAMS(to));
johnc@5169 909 obj->print_on(gclog_or_tty);
johnc@5169 910 gclog_or_tty->print_cr("Obj head CTE = %d, field CTE = %d.",
johnc@5169 911 cv_obj, cv_field);
johnc@5169 912 gclog_or_tty->print_cr("----------");
johnc@5169 913 gclog_or_tty->flush();
johnc@5169 914 _failures = true;
johnc@5169 915 if (!failed) _n_failures++;
johnc@5169 916 }
johnc@5169 917 }
johnc@5169 918 }
johnc@5169 919 }
johnc@5169 920 }
johnc@5169 921 };
tonyp@860 922
ysr@345 923 // This really ought to be commoned up into OffsetTableContigSpace somehow.
ysr@345 924 // We would need a mechanism to make that code skip dead objects.
ysr@345 925
brutisso@3951 926 void HeapRegion::verify(VerifyOption vo,
tonyp@1079 927 bool* failures) const {
ysr@345 928 G1CollectedHeap* g1 = G1CollectedHeap::heap();
tonyp@1079 929 *failures = false;
ysr@345 930 HeapWord* p = bottom();
ysr@345 931 HeapWord* prev_p = NULL;
johnc@2767 932 VerifyLiveClosure vl_cl(g1, vo);
tonyp@1740 933 bool is_humongous = isHumongous();
tonyp@2146 934 bool do_bot_verify = !is_young();
tonyp@1740 935 size_t object_num = 0;
ysr@345 936 while (p < top()) {
tonyp@2146 937 oop obj = oop(p);
tonyp@2146 938 size_t obj_size = obj->size();
tonyp@2146 939 object_num += 1;
tonyp@2146 940
tonyp@2146 941 if (is_humongous != g1->isHumongous(obj_size)) {
tonyp@1740 942 gclog_or_tty->print_cr("obj "PTR_FORMAT" is of %shumongous size ("
tonyp@1740 943 SIZE_FORMAT" words) in a %shumongous region",
tonyp@2146 944 p, g1->isHumongous(obj_size) ? "" : "non-",
tonyp@2146 945 obj_size, is_humongous ? "" : "non-");
tonyp@1740 946 *failures = true;
tonyp@2146 947 return;
tonyp@1740 948 }
tonyp@2146 949
tonyp@2146 950 // If it returns false, verify_for_object() will output the
tonyp@2146 951 // appropriate messasge.
tonyp@2146 952 if (do_bot_verify && !_offsets.verify_for_object(p, obj_size)) {
tonyp@2146 953 *failures = true;
tonyp@2146 954 return;
tonyp@2146 955 }
tonyp@2146 956
johnc@2767 957 if (!g1->is_obj_dead_cond(obj, this, vo)) {
tonyp@2146 958 if (obj->is_oop()) {
tonyp@2146 959 klassOop klass = obj->klass();
tonyp@2146 960 if (!klass->is_perm()) {
tonyp@2146 961 gclog_or_tty->print_cr("klass "PTR_FORMAT" of object "PTR_FORMAT" "
tonyp@2146 962 "not in perm", klass, obj);
tonyp@2146 963 *failures = true;
tonyp@2146 964 return;
tonyp@2146 965 } else if (!klass->is_klass()) {
tonyp@2146 966 gclog_or_tty->print_cr("klass "PTR_FORMAT" of object "PTR_FORMAT" "
tonyp@2146 967 "not a klass", klass, obj);
tonyp@2146 968 *failures = true;
tonyp@2146 969 return;
tonyp@2146 970 } else {
tonyp@2146 971 vl_cl.set_containing_obj(obj);
tonyp@2146 972 obj->oop_iterate(&vl_cl);
tonyp@2146 973 if (vl_cl.failures()) {
tonyp@2146 974 *failures = true;
tonyp@2146 975 }
tonyp@2146 976 if (G1MaxVerifyFailures >= 0 &&
tonyp@2146 977 vl_cl.n_failures() >= G1MaxVerifyFailures) {
tonyp@2146 978 return;
tonyp@2146 979 }
tonyp@2146 980 }
tonyp@2146 981 } else {
tonyp@2146 982 gclog_or_tty->print_cr(PTR_FORMAT" no an oop", obj);
tonyp@1079 983 *failures = true;
tonyp@1079 984 return;
tonyp@1079 985 }
ysr@345 986 }
ysr@345 987 prev_p = p;
tonyp@2146 988 p += obj_size;
ysr@345 989 }
tonyp@2146 990
tonyp@2146 991 if (p != top()) {
tonyp@2146 992 gclog_or_tty->print_cr("end of last object "PTR_FORMAT" "
tonyp@2146 993 "does not match top "PTR_FORMAT, p, top());
tonyp@2146 994 *failures = true;
tonyp@2146 995 return;
tonyp@2146 996 }
tonyp@2146 997
tonyp@2146 998 HeapWord* the_end = end();
tonyp@2146 999 assert(p == top(), "it should still hold");
tonyp@2146 1000 // Do some extra BOT consistency checking for addresses in the
tonyp@2146 1001 // range [top, end). BOT look-ups in this range should yield
tonyp@2146 1002 // top. No point in doing that if top == end (there's nothing there).
tonyp@2146 1003 if (p < the_end) {
tonyp@2146 1004 // Look up top
tonyp@2146 1005 HeapWord* addr_1 = p;
tonyp@2146 1006 HeapWord* b_start_1 = _offsets.block_start_const(addr_1);
tonyp@2146 1007 if (b_start_1 != p) {
tonyp@2146 1008 gclog_or_tty->print_cr("BOT look up for top: "PTR_FORMAT" "
tonyp@2146 1009 " yielded "PTR_FORMAT", expecting "PTR_FORMAT,
tonyp@2146 1010 addr_1, b_start_1, p);
tonyp@2146 1011 *failures = true;
tonyp@2146 1012 return;
tonyp@2146 1013 }
tonyp@2146 1014
tonyp@2146 1015 // Look up top + 1
tonyp@2146 1016 HeapWord* addr_2 = p + 1;
tonyp@2146 1017 if (addr_2 < the_end) {
tonyp@2146 1018 HeapWord* b_start_2 = _offsets.block_start_const(addr_2);
tonyp@2146 1019 if (b_start_2 != p) {
tonyp@2146 1020 gclog_or_tty->print_cr("BOT look up for top + 1: "PTR_FORMAT" "
tonyp@2146 1021 " yielded "PTR_FORMAT", expecting "PTR_FORMAT,
tonyp@2146 1022 addr_2, b_start_2, p);
tonyp@1079 1023 *failures = true;
tonyp@1079 1024 return;
tonyp@2146 1025 }
tonyp@2146 1026 }
tonyp@2146 1027
tonyp@2146 1028 // Look up an address between top and end
tonyp@2146 1029 size_t diff = pointer_delta(the_end, p) / 2;
tonyp@2146 1030 HeapWord* addr_3 = p + diff;
tonyp@2146 1031 if (addr_3 < the_end) {
tonyp@2146 1032 HeapWord* b_start_3 = _offsets.block_start_const(addr_3);
tonyp@2146 1033 if (b_start_3 != p) {
tonyp@2146 1034 gclog_or_tty->print_cr("BOT look up for top + diff: "PTR_FORMAT" "
tonyp@2146 1035 " yielded "PTR_FORMAT", expecting "PTR_FORMAT,
tonyp@2146 1036 addr_3, b_start_3, p);
tonyp@2146 1037 *failures = true;
tonyp@2146 1038 return;
tonyp@2146 1039 }
tonyp@2146 1040 }
tonyp@2146 1041
tonyp@2146 1042 // Loook up end - 1
tonyp@2146 1043 HeapWord* addr_4 = the_end - 1;
tonyp@2146 1044 HeapWord* b_start_4 = _offsets.block_start_const(addr_4);
tonyp@2146 1045 if (b_start_4 != p) {
tonyp@2146 1046 gclog_or_tty->print_cr("BOT look up for end - 1: "PTR_FORMAT" "
tonyp@2146 1047 " yielded "PTR_FORMAT", expecting "PTR_FORMAT,
tonyp@2146 1048 addr_4, b_start_4, p);
tonyp@2146 1049 *failures = true;
tonyp@2146 1050 return;
tonyp@1079 1051 }
ysr@345 1052 }
tonyp@1079 1053
tonyp@1740 1054 if (is_humongous && object_num > 1) {
tonyp@1740 1055 gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] is humongous "
tonyp@1740 1056 "but has "SIZE_FORMAT", objects",
tonyp@1740 1057 bottom(), end(), object_num);
tonyp@1740 1058 *failures = true;
tonyp@1079 1059 return;
ysr@345 1060 }
johnc@5169 1061
johnc@5169 1062 verify_strong_code_roots(vo, failures);
johnc@5169 1063 }
johnc@5169 1064
johnc@5169 1065 void HeapRegion::verify() const {
johnc@5169 1066 bool dummy = false;
johnc@5169 1067 verify(VerifyOption_G1UsePrevMarking, /* failures */ &dummy);
ysr@345 1068 }
ysr@345 1069
ysr@345 1070 // G1OffsetTableContigSpace code; copied from space.cpp. Hope this can go
ysr@345 1071 // away eventually.
ysr@345 1072
tonyp@359 1073 void G1OffsetTableContigSpace::initialize(MemRegion mr, bool clear_space, bool mangle_space) {
ysr@345 1074 // false ==> we'll do the clearing if there's clearing to be done.
tonyp@359 1075 ContiguousSpace::initialize(mr, false, mangle_space);
ysr@345 1076 _offsets.zero_bottom_entry();
ysr@345 1077 _offsets.initialize_threshold();
tonyp@359 1078 if (clear_space) clear(mangle_space);
ysr@345 1079 }
ysr@345 1080
tonyp@359 1081 void G1OffsetTableContigSpace::clear(bool mangle_space) {
tonyp@359 1082 ContiguousSpace::clear(mangle_space);
ysr@345 1083 _offsets.zero_bottom_entry();
ysr@345 1084 _offsets.initialize_threshold();
ysr@345 1085 }
ysr@345 1086
ysr@345 1087 void G1OffsetTableContigSpace::set_bottom(HeapWord* new_bottom) {
ysr@345 1088 Space::set_bottom(new_bottom);
ysr@345 1089 _offsets.set_bottom(new_bottom);
ysr@345 1090 }
ysr@345 1091
ysr@345 1092 void G1OffsetTableContigSpace::set_end(HeapWord* new_end) {
ysr@345 1093 Space::set_end(new_end);
ysr@345 1094 _offsets.resize(new_end - bottom());
ysr@345 1095 }
ysr@345 1096
ysr@345 1097 void G1OffsetTableContigSpace::print() const {
ysr@345 1098 print_short();
ysr@345 1099 gclog_or_tty->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", "
ysr@345 1100 INTPTR_FORMAT ", " INTPTR_FORMAT ")",
ysr@345 1101 bottom(), top(), _offsets.threshold(), end());
ysr@345 1102 }
ysr@345 1103
ysr@345 1104 HeapWord* G1OffsetTableContigSpace::initialize_threshold() {
ysr@345 1105 return _offsets.initialize_threshold();
ysr@345 1106 }
ysr@345 1107
ysr@345 1108 HeapWord* G1OffsetTableContigSpace::cross_threshold(HeapWord* start,
ysr@345 1109 HeapWord* end) {
ysr@345 1110 _offsets.alloc_block(start, end);
ysr@345 1111 return _offsets.threshold();
ysr@345 1112 }
ysr@345 1113
ysr@345 1114 HeapWord* G1OffsetTableContigSpace::saved_mark_word() const {
ysr@345 1115 G1CollectedHeap* g1h = G1CollectedHeap::heap();
ysr@345 1116 assert( _gc_time_stamp <= g1h->get_gc_time_stamp(), "invariant" );
ysr@345 1117 if (_gc_time_stamp < g1h->get_gc_time_stamp())
ysr@345 1118 return top();
ysr@345 1119 else
ysr@345 1120 return ContiguousSpace::saved_mark_word();
ysr@345 1121 }
ysr@345 1122
ysr@345 1123 void G1OffsetTableContigSpace::set_saved_mark() {
ysr@345 1124 G1CollectedHeap* g1h = G1CollectedHeap::heap();
ysr@345 1125 unsigned curr_gc_time_stamp = g1h->get_gc_time_stamp();
ysr@345 1126
ysr@345 1127 if (_gc_time_stamp < curr_gc_time_stamp) {
ysr@345 1128 // The order of these is important, as another thread might be
ysr@345 1129 // about to start scanning this region. If it does so after
ysr@345 1130 // set_saved_mark and before _gc_time_stamp = ..., then the latter
ysr@345 1131 // will be false, and it will pick up top() as the high water mark
ysr@345 1132 // of region. If it does so after _gc_time_stamp = ..., then it
ysr@345 1133 // will pick up the right saved_mark_word() as the high water mark
ysr@345 1134 // of the region. Either way, the behaviour will be correct.
ysr@345 1135 ContiguousSpace::set_saved_mark();
ysr@896 1136 OrderAccess::storestore();
iveresov@356 1137 _gc_time_stamp = curr_gc_time_stamp;
tonyp@2417 1138 // No need to do another barrier to flush the writes above. If
tonyp@2417 1139 // this is called in parallel with other threads trying to
tonyp@2417 1140 // allocate into the region, the caller should call this while
tonyp@2417 1141 // holding a lock and when the lock is released the writes will be
tonyp@2417 1142 // flushed.
ysr@345 1143 }
ysr@345 1144 }
ysr@345 1145
ysr@345 1146 G1OffsetTableContigSpace::
ysr@345 1147 G1OffsetTableContigSpace(G1BlockOffsetSharedArray* sharedOffsetArray,
ysr@345 1148 MemRegion mr, bool is_zeroed) :
ysr@345 1149 _offsets(sharedOffsetArray, mr),
ysr@345 1150 _par_alloc_lock(Mutex::leaf, "OffsetTableContigSpace par alloc lock", true),
ysr@345 1151 _gc_time_stamp(0)
ysr@345 1152 {
ysr@345 1153 _offsets.set_space(this);
tonyp@359 1154 initialize(mr, !is_zeroed, SpaceDecorator::Mangle);
ysr@345 1155 }