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

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial