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

Mon, 19 Aug 2019 10:11:31 +0200

author
neugens
date
Mon, 19 Aug 2019 10:11:31 +0200
changeset 9861
a248d0be1309
parent 9327
f96fcd9e1e1b
child 9931
fd44df5e3bc3
permissions
-rw-r--r--

8229401: Fix JFR code cache test failures
8223689: Add JFR Thread Sampling Support
8223690: Add JFR BiasedLock Event Support
8223691: Add JFR G1 Region Type Change Event Support
8223692: Add JFR G1 Heap Summary Event Support
Summary: Backport JFR from JDK11, additional fixes
Reviewed-by: neugens, apetushkov
Contributed-by: denghui.ddh@alibaba-inc.com

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

mercurial