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

Mon, 12 Mar 2012 14:59:00 -0700

author
johnc
date
Mon, 12 Mar 2012 14:59:00 -0700
changeset 3666
64bf7c8270cb
parent 3539
a9647476d1a4
child 3711
b632e80fc9dc
permissions
-rw-r--r--

7147724: G1: hang in SurrogateLockerThread::manipulatePLL
Summary: Attempting to initiate a marking cycle when allocating a humongous object can, if a marking cycle is successfully initiated by another thread, result in the allocating thread spinning until the marking cycle is complete. Eliminate a deadlock between the main ConcurrentMarkThread, the SurrogateLocker thread, the VM thread, and a mutator thread waiting on the SecondaryFreeList_lock (while free regions are going to become available) by not manipulating the pending list lock during the prologue and epilogue of the cleanup pause.
Reviewed-by: brutisso, jcoomes, tonyp

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

mercurial