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

Tue, 26 Aug 2014 09:36:53 +0200

author
tschatzl
date
Tue, 26 Aug 2014 09:36:53 +0200
changeset 7091
a8ea2f110d87
parent 7050
6701abbc4441
child 7118
227a9e5e4b4a
permissions
-rw-r--r--

8054819: Rename HeapRegionSeq to HeapRegionManager
Reviewed-by: jwilhelm, jmasa

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

mercurial