annotate src/share/vm/gc_implementation/g1/heapRegion.cpp @ 2558:063382f9b575

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