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

Tue, 25 Sep 2012 07:05:55 -0700

author
jmasa
date
Tue, 25 Sep 2012 07:05:55 -0700
changeset 4097
5baec2e69518
parent 4065
8fbf05030e24
child 5205
3a4805ad0005
permissions
-rw-r--r--

7200615: NPG: optimized VM build is broken
Reviewed-by: kvn

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

mercurial