annotate src/share/vm/gc_implementation/g1/heapRegion.cpp @ 6031:6e4b0b4481b9

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