aoqi@0: /* aoqi@0: * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "code/nmethod.hpp" aoqi@0: #include "gc_implementation/g1/g1BlockOffsetTable.inline.hpp" aoqi@0: #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" aoqi@0: #include "gc_implementation/g1/g1OopClosures.inline.hpp" aoqi@0: #include "gc_implementation/g1/heapRegion.inline.hpp" aoqi@0: #include "gc_implementation/g1/heapRegionRemSet.hpp" aoqi@0: #include "gc_implementation/g1/heapRegionSeq.inline.hpp" aoqi@0: #include "memory/genOopClosures.inline.hpp" aoqi@0: #include "memory/iterator.hpp" aoqi@0: #include "oops/oop.inline.hpp" aoqi@0: aoqi@0: PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC aoqi@0: aoqi@0: int HeapRegion::LogOfHRGrainBytes = 0; aoqi@0: int HeapRegion::LogOfHRGrainWords = 0; aoqi@0: size_t HeapRegion::GrainBytes = 0; aoqi@0: size_t HeapRegion::GrainWords = 0; aoqi@0: size_t HeapRegion::CardsPerRegion = 0; aoqi@0: aoqi@0: HeapRegionDCTOC::HeapRegionDCTOC(G1CollectedHeap* g1, aoqi@0: HeapRegion* hr, ExtendedOopClosure* cl, aoqi@0: CardTableModRefBS::PrecisionStyle precision, aoqi@0: FilterKind fk) : aoqi@0: ContiguousSpaceDCTOC(hr, cl, precision, NULL), aoqi@0: _hr(hr), _fk(fk), _g1(g1) { } aoqi@0: aoqi@0: FilterOutOfRegionClosure::FilterOutOfRegionClosure(HeapRegion* r, aoqi@0: OopClosure* oc) : aoqi@0: _r_bottom(r->bottom()), _r_end(r->end()), _oc(oc) { } aoqi@0: aoqi@0: template aoqi@0: HeapWord* walk_mem_region_loop(ClosureType* cl, G1CollectedHeap* g1h, aoqi@0: HeapRegion* hr, aoqi@0: HeapWord* cur, HeapWord* top) { aoqi@0: oop cur_oop = oop(cur); aoqi@0: int oop_size = cur_oop->size(); aoqi@0: HeapWord* next_obj = cur + oop_size; aoqi@0: while (next_obj < top) { aoqi@0: // Keep filtering the remembered set. aoqi@0: if (!g1h->is_obj_dead(cur_oop, hr)) { aoqi@0: // Bottom lies entirely below top, so we can call the aoqi@0: // non-memRegion version of oop_iterate below. aoqi@0: cur_oop->oop_iterate(cl); aoqi@0: } aoqi@0: cur = next_obj; aoqi@0: cur_oop = oop(cur); aoqi@0: oop_size = cur_oop->size(); aoqi@0: next_obj = cur + oop_size; aoqi@0: } aoqi@0: return cur; aoqi@0: } aoqi@0: aoqi@0: void HeapRegionDCTOC::walk_mem_region_with_cl(MemRegion mr, aoqi@0: HeapWord* bottom, aoqi@0: HeapWord* top, aoqi@0: ExtendedOopClosure* cl) { aoqi@0: G1CollectedHeap* g1h = _g1; aoqi@0: int oop_size; aoqi@0: ExtendedOopClosure* cl2 = NULL; aoqi@0: aoqi@0: FilterIntoCSClosure intoCSFilt(this, g1h, cl); aoqi@0: FilterOutOfRegionClosure outOfRegionFilt(_hr, cl); aoqi@0: aoqi@0: switch (_fk) { aoqi@0: case NoFilterKind: cl2 = cl; break; aoqi@0: case IntoCSFilterKind: cl2 = &intoCSFilt; break; aoqi@0: case OutOfRegionFilterKind: cl2 = &outOfRegionFilt; break; aoqi@0: default: ShouldNotReachHere(); aoqi@0: } aoqi@0: aoqi@0: // Start filtering what we add to the remembered set. If the object is aoqi@0: // not considered dead, either because it is marked (in the mark bitmap) aoqi@0: // or it was allocated after marking finished, then we add it. Otherwise aoqi@0: // we can safely ignore the object. aoqi@0: if (!g1h->is_obj_dead(oop(bottom), _hr)) { aoqi@0: oop_size = oop(bottom)->oop_iterate(cl2, mr); aoqi@0: } else { aoqi@0: oop_size = oop(bottom)->size(); aoqi@0: } aoqi@0: aoqi@0: bottom += oop_size; aoqi@0: aoqi@0: if (bottom < top) { aoqi@0: // We replicate the loop below for several kinds of possible filters. aoqi@0: switch (_fk) { aoqi@0: case NoFilterKind: aoqi@0: bottom = walk_mem_region_loop(cl, g1h, _hr, bottom, top); aoqi@0: break; aoqi@0: aoqi@0: case IntoCSFilterKind: { aoqi@0: FilterIntoCSClosure filt(this, g1h, cl); aoqi@0: bottom = walk_mem_region_loop(&filt, g1h, _hr, bottom, top); aoqi@0: break; aoqi@0: } aoqi@0: aoqi@0: case OutOfRegionFilterKind: { aoqi@0: FilterOutOfRegionClosure filt(_hr, cl); aoqi@0: bottom = walk_mem_region_loop(&filt, g1h, _hr, bottom, top); aoqi@0: break; aoqi@0: } aoqi@0: aoqi@0: default: aoqi@0: ShouldNotReachHere(); aoqi@0: } aoqi@0: aoqi@0: // Last object. Need to do dead-obj filtering here too. aoqi@0: if (!g1h->is_obj_dead(oop(bottom), _hr)) { aoqi@0: oop(bottom)->oop_iterate(cl2, mr); aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Minimum region size; we won't go lower than that. aoqi@0: // We might want to decrease this in the future, to deal with small aoqi@0: // heaps a bit more efficiently. aoqi@0: #define MIN_REGION_SIZE ( 1024 * 1024 ) aoqi@0: aoqi@0: // Maximum region size; we don't go higher than that. There's a good aoqi@0: // reason for having an upper bound. We don't want regions to get too aoqi@0: // large, otherwise cleanup's effectiveness would decrease as there aoqi@0: // will be fewer opportunities to find totally empty regions after aoqi@0: // marking. aoqi@0: #define MAX_REGION_SIZE ( 32 * 1024 * 1024 ) aoqi@0: aoqi@0: // The automatic region size calculation will try to have around this aoqi@0: // many regions in the heap (based on the min heap size). aoqi@0: #define TARGET_REGION_NUMBER 2048 aoqi@0: aoqi@0: size_t HeapRegion::max_region_size() { aoqi@0: return (size_t)MAX_REGION_SIZE; aoqi@0: } aoqi@0: aoqi@0: void HeapRegion::setup_heap_region_size(size_t initial_heap_size, size_t max_heap_size) { aoqi@0: uintx region_size = G1HeapRegionSize; aoqi@0: if (FLAG_IS_DEFAULT(G1HeapRegionSize)) { aoqi@0: size_t average_heap_size = (initial_heap_size + max_heap_size) / 2; aoqi@0: region_size = MAX2(average_heap_size / TARGET_REGION_NUMBER, aoqi@0: (uintx) MIN_REGION_SIZE); aoqi@0: } aoqi@0: aoqi@0: int region_size_log = log2_long((jlong) region_size); aoqi@0: // Recalculate the region size to make sure it's a power of aoqi@0: // 2. This means that region_size is the largest power of 2 that's aoqi@0: // <= what we've calculated so far. aoqi@0: region_size = ((uintx)1 << region_size_log); aoqi@0: aoqi@0: // Now make sure that we don't go over or under our limits. aoqi@0: if (region_size < MIN_REGION_SIZE) { aoqi@0: region_size = MIN_REGION_SIZE; aoqi@0: } else if (region_size > MAX_REGION_SIZE) { aoqi@0: region_size = MAX_REGION_SIZE; aoqi@0: } aoqi@0: aoqi@0: // And recalculate the log. aoqi@0: region_size_log = log2_long((jlong) region_size); aoqi@0: aoqi@0: // Now, set up the globals. aoqi@0: guarantee(LogOfHRGrainBytes == 0, "we should only set it once"); aoqi@0: LogOfHRGrainBytes = region_size_log; aoqi@0: aoqi@0: guarantee(LogOfHRGrainWords == 0, "we should only set it once"); aoqi@0: LogOfHRGrainWords = LogOfHRGrainBytes - LogHeapWordSize; aoqi@0: aoqi@0: guarantee(GrainBytes == 0, "we should only set it once"); aoqi@0: // The cast to int is safe, given that we've bounded region_size by aoqi@0: // MIN_REGION_SIZE and MAX_REGION_SIZE. aoqi@0: GrainBytes = (size_t)region_size; aoqi@0: aoqi@0: guarantee(GrainWords == 0, "we should only set it once"); aoqi@0: GrainWords = GrainBytes >> LogHeapWordSize; aoqi@0: guarantee((size_t) 1 << LogOfHRGrainWords == GrainWords, "sanity"); aoqi@0: aoqi@0: guarantee(CardsPerRegion == 0, "we should only set it once"); aoqi@0: CardsPerRegion = GrainBytes >> CardTableModRefBS::card_shift; aoqi@0: } aoqi@0: aoqi@0: void HeapRegion::reset_after_compaction() { aoqi@0: G1OffsetTableContigSpace::reset_after_compaction(); aoqi@0: // After a compaction the mark bitmap is invalid, so we must aoqi@0: // treat all objects as being inside the unmarked area. aoqi@0: zero_marked_bytes(); aoqi@0: init_top_at_mark_start(); aoqi@0: } aoqi@0: aoqi@0: void HeapRegion::hr_clear(bool par, bool clear_space, bool locked) { aoqi@0: assert(_humongous_type == NotHumongous, aoqi@0: "we should have already filtered out humongous regions"); aoqi@0: assert(_humongous_start_region == NULL, aoqi@0: "we should have already filtered out humongous regions"); aoqi@0: assert(_end == _orig_end, aoqi@0: "we should have already filtered out humongous regions"); aoqi@0: aoqi@0: _in_collection_set = false; aoqi@0: aoqi@0: set_young_index_in_cset(-1); aoqi@0: uninstall_surv_rate_group(); aoqi@0: set_young_type(NotYoung); aoqi@0: reset_pre_dummy_top(); aoqi@0: aoqi@0: if (!par) { aoqi@0: // If this is parallel, this will be done later. aoqi@0: HeapRegionRemSet* hrrs = rem_set(); aoqi@0: if (locked) { aoqi@0: hrrs->clear_locked(); aoqi@0: } else { aoqi@0: hrrs->clear(); aoqi@0: } aoqi@0: _claimed = InitialClaimValue; aoqi@0: } aoqi@0: zero_marked_bytes(); aoqi@0: aoqi@0: _offsets.resize(HeapRegion::GrainWords); aoqi@0: init_top_at_mark_start(); aoqi@0: if (clear_space) clear(SpaceDecorator::Mangle); aoqi@0: } aoqi@0: aoqi@0: void HeapRegion::par_clear() { aoqi@0: assert(used() == 0, "the region should have been already cleared"); aoqi@0: assert(capacity() == HeapRegion::GrainBytes, "should be back to normal"); aoqi@0: HeapRegionRemSet* hrrs = rem_set(); aoqi@0: hrrs->clear(); aoqi@0: CardTableModRefBS* ct_bs = aoqi@0: (CardTableModRefBS*)G1CollectedHeap::heap()->barrier_set(); aoqi@0: ct_bs->clear(MemRegion(bottom(), end())); aoqi@0: } aoqi@0: aoqi@0: void HeapRegion::calc_gc_efficiency() { aoqi@0: // GC efficiency is the ratio of how much space would be aoqi@0: // reclaimed over how long we predict it would take to reclaim it. aoqi@0: G1CollectedHeap* g1h = G1CollectedHeap::heap(); aoqi@0: G1CollectorPolicy* g1p = g1h->g1_policy(); aoqi@0: aoqi@0: // Retrieve a prediction of the elapsed time for this region for aoqi@0: // a mixed gc because the region will only be evacuated during a aoqi@0: // mixed gc. aoqi@0: double region_elapsed_time_ms = aoqi@0: g1p->predict_region_elapsed_time_ms(this, false /* for_young_gc */); aoqi@0: _gc_efficiency = (double) reclaimable_bytes() / region_elapsed_time_ms; aoqi@0: } aoqi@0: aoqi@0: void HeapRegion::set_startsHumongous(HeapWord* new_top, HeapWord* new_end) { aoqi@0: assert(!isHumongous(), "sanity / pre-condition"); aoqi@0: assert(end() == _orig_end, aoqi@0: "Should be normal before the humongous object allocation"); aoqi@0: assert(top() == bottom(), "should be empty"); aoqi@0: assert(bottom() <= new_top && new_top <= new_end, "pre-condition"); aoqi@0: aoqi@0: _humongous_type = StartsHumongous; aoqi@0: _humongous_start_region = this; aoqi@0: aoqi@0: set_end(new_end); aoqi@0: _offsets.set_for_starts_humongous(new_top); aoqi@0: } aoqi@0: aoqi@0: void HeapRegion::set_continuesHumongous(HeapRegion* first_hr) { aoqi@0: assert(!isHumongous(), "sanity / pre-condition"); aoqi@0: assert(end() == _orig_end, aoqi@0: "Should be normal before the humongous object allocation"); aoqi@0: assert(top() == bottom(), "should be empty"); aoqi@0: assert(first_hr->startsHumongous(), "pre-condition"); aoqi@0: aoqi@0: _humongous_type = ContinuesHumongous; aoqi@0: _humongous_start_region = first_hr; aoqi@0: } aoqi@0: aoqi@0: void HeapRegion::set_notHumongous() { aoqi@0: assert(isHumongous(), "pre-condition"); aoqi@0: aoqi@0: if (startsHumongous()) { aoqi@0: assert(top() <= end(), "pre-condition"); aoqi@0: set_end(_orig_end); aoqi@0: if (top() > end()) { aoqi@0: // at least one "continues humongous" region after it aoqi@0: set_top(end()); aoqi@0: } aoqi@0: } else { aoqi@0: // continues humongous aoqi@0: assert(end() == _orig_end, "sanity"); aoqi@0: } aoqi@0: aoqi@0: assert(capacity() == HeapRegion::GrainBytes, "pre-condition"); aoqi@0: _humongous_type = NotHumongous; aoqi@0: _humongous_start_region = NULL; aoqi@0: } aoqi@0: aoqi@0: bool HeapRegion::claimHeapRegion(jint claimValue) { aoqi@0: jint current = _claimed; aoqi@0: if (current != claimValue) { aoqi@0: jint res = Atomic::cmpxchg(claimValue, &_claimed, current); aoqi@0: if (res == current) { aoqi@0: return true; aoqi@0: } aoqi@0: } aoqi@0: return false; aoqi@0: } aoqi@0: aoqi@0: HeapWord* HeapRegion::next_block_start_careful(HeapWord* addr) { aoqi@0: HeapWord* low = addr; aoqi@0: HeapWord* high = end(); aoqi@0: while (low < high) { aoqi@0: size_t diff = pointer_delta(high, low); aoqi@0: // Must add one below to bias toward the high amount. Otherwise, if aoqi@0: // "high" were at the desired value, and "low" were one less, we aoqi@0: // would not converge on "high". This is not symmetric, because aoqi@0: // we set "high" to a block start, which might be the right one, aoqi@0: // which we don't do for "low". aoqi@0: HeapWord* middle = low + (diff+1)/2; aoqi@0: if (middle == high) return high; aoqi@0: HeapWord* mid_bs = block_start_careful(middle); aoqi@0: if (mid_bs < addr) { aoqi@0: low = middle; aoqi@0: } else { aoqi@0: high = mid_bs; aoqi@0: } aoqi@0: } aoqi@0: assert(low == high && low >= addr, "Didn't work."); aoqi@0: return low; aoqi@0: } aoqi@0: aoqi@0: #ifdef _MSC_VER // the use of 'this' below gets a warning, make it go away aoqi@0: #pragma warning( disable:4355 ) // 'this' : used in base member initializer list aoqi@0: #endif // _MSC_VER aoqi@0: aoqi@0: aoqi@0: HeapRegion::HeapRegion(uint hrs_index, aoqi@0: G1BlockOffsetSharedArray* sharedOffsetArray, aoqi@0: MemRegion mr) : aoqi@0: G1OffsetTableContigSpace(sharedOffsetArray, mr), aoqi@0: _hrs_index(hrs_index), aoqi@0: _humongous_type(NotHumongous), _humongous_start_region(NULL), aoqi@0: _in_collection_set(false), aoqi@0: _next_in_special_set(NULL), _orig_end(NULL), aoqi@0: _claimed(InitialClaimValue), _evacuation_failed(false), aoqi@0: _prev_marked_bytes(0), _next_marked_bytes(0), _gc_efficiency(0.0), aoqi@0: _young_type(NotYoung), _next_young_region(NULL), aoqi@0: _next_dirty_cards_region(NULL), _next(NULL), _prev(NULL), _pending_removal(false), aoqi@0: #ifdef ASSERT aoqi@0: _containing_set(NULL), aoqi@0: #endif // ASSERT aoqi@0: _young_index_in_cset(-1), _surv_rate_group(NULL), _age_index(-1), aoqi@0: _rem_set(NULL), _recorded_rs_length(0), _predicted_elapsed_time_ms(0), aoqi@0: _predicted_bytes_to_copy(0) aoqi@0: { aoqi@0: _rem_set = new HeapRegionRemSet(sharedOffsetArray, this); aoqi@0: _orig_end = mr.end(); aoqi@0: // Note that initialize() will set the start of the unmarked area of the aoqi@0: // region. aoqi@0: hr_clear(false /*par*/, false /*clear_space*/); aoqi@0: set_top(bottom()); aoqi@0: set_saved_mark(); aoqi@0: aoqi@0: assert(HeapRegionRemSet::num_par_rem_sets() > 0, "Invariant."); aoqi@0: } aoqi@0: aoqi@0: CompactibleSpace* HeapRegion::next_compaction_space() const { aoqi@0: // We're not using an iterator given that it will wrap around when aoqi@0: // it reaches the last region and this is not what we want here. aoqi@0: G1CollectedHeap* g1h = G1CollectedHeap::heap(); aoqi@0: uint index = hrs_index() + 1; aoqi@0: while (index < g1h->n_regions()) { aoqi@0: HeapRegion* hr = g1h->region_at(index); aoqi@0: if (!hr->isHumongous()) { aoqi@0: return hr; aoqi@0: } aoqi@0: index += 1; aoqi@0: } aoqi@0: return NULL; aoqi@0: } aoqi@0: aoqi@0: void HeapRegion::save_marks() { aoqi@0: set_saved_mark(); aoqi@0: } aoqi@0: aoqi@0: void HeapRegion::oops_in_mr_iterate(MemRegion mr, ExtendedOopClosure* cl) { aoqi@0: HeapWord* p = mr.start(); aoqi@0: HeapWord* e = mr.end(); aoqi@0: oop obj; aoqi@0: while (p < e) { aoqi@0: obj = oop(p); aoqi@0: p += obj->oop_iterate(cl); aoqi@0: } aoqi@0: assert(p == e, "bad memregion: doesn't end on obj boundary"); aoqi@0: } aoqi@0: aoqi@0: #define HeapRegion_OOP_SINCE_SAVE_MARKS_DEFN(OopClosureType, nv_suffix) \ aoqi@0: void HeapRegion::oop_since_save_marks_iterate##nv_suffix(OopClosureType* cl) { \ aoqi@0: ContiguousSpace::oop_since_save_marks_iterate##nv_suffix(cl); \ aoqi@0: } aoqi@0: SPECIALIZED_SINCE_SAVE_MARKS_CLOSURES(HeapRegion_OOP_SINCE_SAVE_MARKS_DEFN) aoqi@0: aoqi@0: aoqi@0: void HeapRegion::oop_before_save_marks_iterate(ExtendedOopClosure* cl) { aoqi@0: oops_in_mr_iterate(MemRegion(bottom(), saved_mark_word()), cl); aoqi@0: } aoqi@0: aoqi@0: void HeapRegion::note_self_forwarding_removal_start(bool during_initial_mark, aoqi@0: bool during_conc_mark) { aoqi@0: // We always recreate the prev marking info and we'll explicitly aoqi@0: // mark all objects we find to be self-forwarded on the prev aoqi@0: // bitmap. So all objects need to be below PTAMS. aoqi@0: _prev_top_at_mark_start = top(); aoqi@0: _prev_marked_bytes = 0; aoqi@0: aoqi@0: if (during_initial_mark) { aoqi@0: // During initial-mark, we'll also explicitly mark all objects aoqi@0: // we find to be self-forwarded on the next bitmap. So all aoqi@0: // objects need to be below NTAMS. aoqi@0: _next_top_at_mark_start = top(); aoqi@0: _next_marked_bytes = 0; aoqi@0: } else if (during_conc_mark) { aoqi@0: // During concurrent mark, all objects in the CSet (including aoqi@0: // the ones we find to be self-forwarded) are implicitly live. aoqi@0: // So all objects need to be above NTAMS. aoqi@0: _next_top_at_mark_start = bottom(); aoqi@0: _next_marked_bytes = 0; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void HeapRegion::note_self_forwarding_removal_end(bool during_initial_mark, aoqi@0: bool during_conc_mark, aoqi@0: size_t marked_bytes) { aoqi@0: assert(0 <= marked_bytes && marked_bytes <= used(), aoqi@0: err_msg("marked: "SIZE_FORMAT" used: "SIZE_FORMAT, aoqi@0: marked_bytes, used())); aoqi@0: _prev_marked_bytes = marked_bytes; aoqi@0: } aoqi@0: aoqi@0: HeapWord* aoqi@0: HeapRegion::object_iterate_mem_careful(MemRegion mr, aoqi@0: ObjectClosure* cl) { aoqi@0: G1CollectedHeap* g1h = G1CollectedHeap::heap(); aoqi@0: // We used to use "block_start_careful" here. But we're actually happy aoqi@0: // to update the BOT while we do this... aoqi@0: HeapWord* cur = block_start(mr.start()); aoqi@0: mr = mr.intersection(used_region()); aoqi@0: if (mr.is_empty()) return NULL; aoqi@0: // Otherwise, find the obj that extends onto mr.start(). aoqi@0: aoqi@0: assert(cur <= mr.start() aoqi@0: && (oop(cur)->klass_or_null() == NULL || aoqi@0: cur + oop(cur)->size() > mr.start()), aoqi@0: "postcondition of block_start"); aoqi@0: oop obj; aoqi@0: while (cur < mr.end()) { aoqi@0: obj = oop(cur); aoqi@0: if (obj->klass_or_null() == NULL) { aoqi@0: // Ran into an unparseable point. aoqi@0: return cur; aoqi@0: } else if (!g1h->is_obj_dead(obj)) { aoqi@0: cl->do_object(obj); aoqi@0: } aoqi@0: if (cl->abort()) return cur; aoqi@0: // The check above must occur before the operation below, since an aoqi@0: // abort might invalidate the "size" operation. aoqi@0: cur += obj->size(); aoqi@0: } aoqi@0: return NULL; aoqi@0: } aoqi@0: aoqi@0: HeapWord* aoqi@0: HeapRegion:: aoqi@0: oops_on_card_seq_iterate_careful(MemRegion mr, aoqi@0: FilterOutOfRegionClosure* cl, aoqi@0: bool filter_young, aoqi@0: jbyte* card_ptr) { aoqi@0: // Currently, we should only have to clean the card if filter_young aoqi@0: // is true and vice versa. aoqi@0: if (filter_young) { aoqi@0: assert(card_ptr != NULL, "pre-condition"); aoqi@0: } else { aoqi@0: assert(card_ptr == NULL, "pre-condition"); aoqi@0: } aoqi@0: G1CollectedHeap* g1h = G1CollectedHeap::heap(); aoqi@0: aoqi@0: // If we're within a stop-world GC, then we might look at a card in a aoqi@0: // GC alloc region that extends onto a GC LAB, which may not be aoqi@0: // parseable. Stop such at the "saved_mark" of the region. aoqi@0: if (g1h->is_gc_active()) { aoqi@0: mr = mr.intersection(used_region_at_save_marks()); aoqi@0: } else { aoqi@0: mr = mr.intersection(used_region()); aoqi@0: } aoqi@0: if (mr.is_empty()) return NULL; aoqi@0: // Otherwise, find the obj that extends onto mr.start(). aoqi@0: aoqi@0: // The intersection of the incoming mr (for the card) and the aoqi@0: // allocated part of the region is non-empty. This implies that aoqi@0: // we have actually allocated into this region. The code in aoqi@0: // G1CollectedHeap.cpp that allocates a new region sets the aoqi@0: // is_young tag on the region before allocating. Thus we aoqi@0: // safely know if this region is young. aoqi@0: if (is_young() && filter_young) { aoqi@0: return NULL; aoqi@0: } aoqi@0: aoqi@0: assert(!is_young(), "check value of filter_young"); aoqi@0: aoqi@0: // We can only clean the card here, after we make the decision that aoqi@0: // the card is not young. And we only clean the card if we have been aoqi@0: // asked to (i.e., card_ptr != NULL). aoqi@0: if (card_ptr != NULL) { aoqi@0: *card_ptr = CardTableModRefBS::clean_card_val(); aoqi@0: // We must complete this write before we do any of the reads below. aoqi@0: OrderAccess::storeload(); aoqi@0: } aoqi@0: aoqi@0: // Cache the boundaries of the memory region in some const locals aoqi@0: HeapWord* const start = mr.start(); aoqi@0: HeapWord* const end = mr.end(); aoqi@0: aoqi@0: // We used to use "block_start_careful" here. But we're actually happy aoqi@0: // to update the BOT while we do this... aoqi@0: HeapWord* cur = block_start(start); aoqi@0: assert(cur <= start, "Postcondition"); aoqi@0: aoqi@0: oop obj; aoqi@0: aoqi@0: HeapWord* next = cur; aoqi@0: while (next <= start) { aoqi@0: cur = next; aoqi@0: obj = oop(cur); aoqi@0: if (obj->klass_or_null() == NULL) { aoqi@0: // Ran into an unparseable point. aoqi@0: return cur; aoqi@0: } aoqi@0: // Otherwise... aoqi@0: next = (cur + obj->size()); aoqi@0: } aoqi@0: aoqi@0: // If we finish the above loop...We have a parseable object that aoqi@0: // begins on or before the start of the memory region, and ends aoqi@0: // inside or spans the entire region. aoqi@0: aoqi@0: assert(obj == oop(cur), "sanity"); aoqi@0: assert(cur <= start && aoqi@0: obj->klass_or_null() != NULL && aoqi@0: (cur + obj->size()) > start, aoqi@0: "Loop postcondition"); aoqi@0: aoqi@0: if (!g1h->is_obj_dead(obj)) { aoqi@0: obj->oop_iterate(cl, mr); aoqi@0: } aoqi@0: aoqi@0: while (cur < end) { aoqi@0: obj = oop(cur); aoqi@0: if (obj->klass_or_null() == NULL) { aoqi@0: // Ran into an unparseable point. aoqi@0: return cur; aoqi@0: }; aoqi@0: aoqi@0: // Otherwise: aoqi@0: next = (cur + obj->size()); aoqi@0: aoqi@0: if (!g1h->is_obj_dead(obj)) { aoqi@0: if (next < end || !obj->is_objArray()) { aoqi@0: // This object either does not span the MemRegion aoqi@0: // boundary, or if it does it's not an array. aoqi@0: // Apply closure to whole object. aoqi@0: obj->oop_iterate(cl); aoqi@0: } else { aoqi@0: // This obj is an array that spans the boundary. aoqi@0: // Stop at the boundary. aoqi@0: obj->oop_iterate(cl, mr); aoqi@0: } aoqi@0: } aoqi@0: cur = next; aoqi@0: } aoqi@0: return NULL; aoqi@0: } aoqi@0: aoqi@0: // Code roots support aoqi@0: aoqi@0: void HeapRegion::add_strong_code_root(nmethod* nm) { aoqi@0: HeapRegionRemSet* hrrs = rem_set(); aoqi@0: hrrs->add_strong_code_root(nm); aoqi@0: } aoqi@0: aoqi@0: void HeapRegion::remove_strong_code_root(nmethod* nm) { aoqi@0: HeapRegionRemSet* hrrs = rem_set(); aoqi@0: hrrs->remove_strong_code_root(nm); aoqi@0: } aoqi@0: aoqi@0: void HeapRegion::migrate_strong_code_roots() { aoqi@0: assert(in_collection_set(), "only collection set regions"); aoqi@0: assert(!isHumongous(), aoqi@0: err_msg("humongous region "HR_FORMAT" should not have been added to collection set", aoqi@0: HR_FORMAT_PARAMS(this))); aoqi@0: aoqi@0: HeapRegionRemSet* hrrs = rem_set(); aoqi@0: hrrs->migrate_strong_code_roots(); aoqi@0: } aoqi@0: aoqi@0: void HeapRegion::strong_code_roots_do(CodeBlobClosure* blk) const { aoqi@0: HeapRegionRemSet* hrrs = rem_set(); aoqi@0: hrrs->strong_code_roots_do(blk); aoqi@0: } aoqi@0: aoqi@0: class VerifyStrongCodeRootOopClosure: public OopClosure { aoqi@0: const HeapRegion* _hr; aoqi@0: nmethod* _nm; aoqi@0: bool _failures; aoqi@0: bool _has_oops_in_region; aoqi@0: aoqi@0: template void do_oop_work(T* p) { aoqi@0: T heap_oop = oopDesc::load_heap_oop(p); aoqi@0: if (!oopDesc::is_null(heap_oop)) { aoqi@0: oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); aoqi@0: aoqi@0: // Note: not all the oops embedded in the nmethod are in the aoqi@0: // current region. We only look at those which are. aoqi@0: if (_hr->is_in(obj)) { aoqi@0: // Object is in the region. Check that its less than top aoqi@0: if (_hr->top() <= (HeapWord*)obj) { aoqi@0: // Object is above top aoqi@0: gclog_or_tty->print_cr("Object "PTR_FORMAT" in region " aoqi@0: "["PTR_FORMAT", "PTR_FORMAT") is above " aoqi@0: "top "PTR_FORMAT, aoqi@0: (void *)obj, _hr->bottom(), _hr->end(), _hr->top()); aoqi@0: _failures = true; aoqi@0: return; aoqi@0: } aoqi@0: // Nmethod has at least one oop in the current region aoqi@0: _has_oops_in_region = true; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: public: aoqi@0: VerifyStrongCodeRootOopClosure(const HeapRegion* hr, nmethod* nm): aoqi@0: _hr(hr), _failures(false), _has_oops_in_region(false) {} aoqi@0: aoqi@0: void do_oop(narrowOop* p) { do_oop_work(p); } aoqi@0: void do_oop(oop* p) { do_oop_work(p); } aoqi@0: aoqi@0: bool failures() { return _failures; } aoqi@0: bool has_oops_in_region() { return _has_oops_in_region; } aoqi@0: }; aoqi@0: aoqi@0: class VerifyStrongCodeRootCodeBlobClosure: public CodeBlobClosure { aoqi@0: const HeapRegion* _hr; aoqi@0: bool _failures; aoqi@0: public: aoqi@0: VerifyStrongCodeRootCodeBlobClosure(const HeapRegion* hr) : aoqi@0: _hr(hr), _failures(false) {} aoqi@0: aoqi@0: void do_code_blob(CodeBlob* cb) { aoqi@0: nmethod* nm = (cb == NULL) ? NULL : cb->as_nmethod_or_null(); aoqi@0: if (nm != NULL) { aoqi@0: // Verify that the nemthod is live aoqi@0: if (!nm->is_alive()) { aoqi@0: gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] has dead nmethod " aoqi@0: PTR_FORMAT" in its strong code roots", aoqi@0: _hr->bottom(), _hr->end(), nm); aoqi@0: _failures = true; aoqi@0: } else { aoqi@0: VerifyStrongCodeRootOopClosure oop_cl(_hr, nm); aoqi@0: nm->oops_do(&oop_cl); aoqi@0: if (!oop_cl.has_oops_in_region()) { aoqi@0: gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] has nmethod " aoqi@0: PTR_FORMAT" in its strong code roots " aoqi@0: "with no pointers into region", aoqi@0: _hr->bottom(), _hr->end(), nm); aoqi@0: _failures = true; aoqi@0: } else if (oop_cl.failures()) { aoqi@0: gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] has other " aoqi@0: "failures for nmethod "PTR_FORMAT, aoqi@0: _hr->bottom(), _hr->end(), nm); aoqi@0: _failures = true; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: bool failures() { return _failures; } aoqi@0: }; aoqi@0: aoqi@0: void HeapRegion::verify_strong_code_roots(VerifyOption vo, bool* failures) const { aoqi@0: if (!G1VerifyHeapRegionCodeRoots) { aoqi@0: // We're not verifying code roots. aoqi@0: return; aoqi@0: } aoqi@0: if (vo == VerifyOption_G1UseMarkWord) { aoqi@0: // Marking verification during a full GC is performed after class aoqi@0: // unloading, code cache unloading, etc so the strong code roots aoqi@0: // attached to each heap region are in an inconsistent state. They won't aoqi@0: // be consistent until the strong code roots are rebuilt after the aoqi@0: // actual GC. Skip verifying the strong code roots in this particular aoqi@0: // time. aoqi@0: assert(VerifyDuringGC, "only way to get here"); aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: HeapRegionRemSet* hrrs = rem_set(); aoqi@0: size_t strong_code_roots_length = hrrs->strong_code_roots_list_length(); aoqi@0: aoqi@0: // if this region is empty then there should be no entries aoqi@0: // on its strong code root list aoqi@0: if (is_empty()) { aoqi@0: if (strong_code_roots_length > 0) { aoqi@0: gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] is empty " aoqi@0: "but has "SIZE_FORMAT" code root entries", aoqi@0: bottom(), end(), strong_code_roots_length); aoqi@0: *failures = true; aoqi@0: } aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: if (continuesHumongous()) { aoqi@0: if (strong_code_roots_length > 0) { aoqi@0: gclog_or_tty->print_cr("region "HR_FORMAT" is a continuation of a humongous " aoqi@0: "region but has "SIZE_FORMAT" code root entries", aoqi@0: HR_FORMAT_PARAMS(this), strong_code_roots_length); aoqi@0: *failures = true; aoqi@0: } aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: VerifyStrongCodeRootCodeBlobClosure cb_cl(this); aoqi@0: strong_code_roots_do(&cb_cl); aoqi@0: aoqi@0: if (cb_cl.failures()) { aoqi@0: *failures = true; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void HeapRegion::print() const { print_on(gclog_or_tty); } aoqi@0: void HeapRegion::print_on(outputStream* st) const { aoqi@0: if (isHumongous()) { aoqi@0: if (startsHumongous()) aoqi@0: st->print(" HS"); aoqi@0: else aoqi@0: st->print(" HC"); aoqi@0: } else { aoqi@0: st->print(" "); aoqi@0: } aoqi@0: if (in_collection_set()) aoqi@0: st->print(" CS"); aoqi@0: else aoqi@0: st->print(" "); aoqi@0: if (is_young()) aoqi@0: st->print(is_survivor() ? " SU" : " Y "); aoqi@0: else aoqi@0: st->print(" "); aoqi@0: if (is_empty()) aoqi@0: st->print(" F"); aoqi@0: else aoqi@0: st->print(" "); aoqi@0: st->print(" TS %5d", _gc_time_stamp); aoqi@0: st->print(" PTAMS "PTR_FORMAT" NTAMS "PTR_FORMAT, aoqi@0: prev_top_at_mark_start(), next_top_at_mark_start()); aoqi@0: G1OffsetTableContigSpace::print_on(st); aoqi@0: } aoqi@0: aoqi@0: class VerifyLiveClosure: public OopClosure { aoqi@0: private: aoqi@0: G1CollectedHeap* _g1h; aoqi@0: CardTableModRefBS* _bs; aoqi@0: oop _containing_obj; aoqi@0: bool _failures; aoqi@0: int _n_failures; aoqi@0: VerifyOption _vo; aoqi@0: public: aoqi@0: // _vo == UsePrevMarking -> use "prev" marking information, aoqi@0: // _vo == UseNextMarking -> use "next" marking information, aoqi@0: // _vo == UseMarkWord -> use mark word from object header. aoqi@0: VerifyLiveClosure(G1CollectedHeap* g1h, VerifyOption vo) : aoqi@0: _g1h(g1h), _bs(NULL), _containing_obj(NULL), aoqi@0: _failures(false), _n_failures(0), _vo(vo) aoqi@0: { aoqi@0: BarrierSet* bs = _g1h->barrier_set(); aoqi@0: if (bs->is_a(BarrierSet::CardTableModRef)) aoqi@0: _bs = (CardTableModRefBS*)bs; aoqi@0: } aoqi@0: aoqi@0: void set_containing_obj(oop obj) { aoqi@0: _containing_obj = obj; aoqi@0: } aoqi@0: aoqi@0: bool failures() { return _failures; } aoqi@0: int n_failures() { return _n_failures; } aoqi@0: aoqi@0: virtual void do_oop(narrowOop* p) { do_oop_work(p); } aoqi@0: virtual void do_oop( oop* p) { do_oop_work(p); } aoqi@0: aoqi@0: void print_object(outputStream* out, oop obj) { aoqi@0: #ifdef PRODUCT aoqi@0: Klass* k = obj->klass(); aoqi@0: const char* class_name = InstanceKlass::cast(k)->external_name(); aoqi@0: out->print_cr("class name %s", class_name); aoqi@0: #else // PRODUCT aoqi@0: obj->print_on(out); aoqi@0: #endif // PRODUCT aoqi@0: } aoqi@0: aoqi@0: template aoqi@0: void do_oop_work(T* p) { aoqi@0: assert(_containing_obj != NULL, "Precondition"); aoqi@0: assert(!_g1h->is_obj_dead_cond(_containing_obj, _vo), aoqi@0: "Precondition"); aoqi@0: T heap_oop = oopDesc::load_heap_oop(p); aoqi@0: if (!oopDesc::is_null(heap_oop)) { aoqi@0: oop obj = oopDesc::decode_heap_oop_not_null(heap_oop); aoqi@0: bool failed = false; aoqi@0: if (!_g1h->is_in_closed_subset(obj) || _g1h->is_obj_dead_cond(obj, _vo)) { aoqi@0: MutexLockerEx x(ParGCRareEvent_lock, aoqi@0: Mutex::_no_safepoint_check_flag); aoqi@0: aoqi@0: if (!_failures) { aoqi@0: gclog_or_tty->cr(); aoqi@0: gclog_or_tty->print_cr("----------"); aoqi@0: } aoqi@0: if (!_g1h->is_in_closed_subset(obj)) { aoqi@0: HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p); aoqi@0: gclog_or_tty->print_cr("Field "PTR_FORMAT aoqi@0: " of live obj "PTR_FORMAT" in region " aoqi@0: "["PTR_FORMAT", "PTR_FORMAT")", aoqi@0: p, (void*) _containing_obj, aoqi@0: from->bottom(), from->end()); aoqi@0: print_object(gclog_or_tty, _containing_obj); aoqi@0: gclog_or_tty->print_cr("points to obj "PTR_FORMAT" not in the heap", aoqi@0: (void*) obj); aoqi@0: } else { aoqi@0: HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p); aoqi@0: HeapRegion* to = _g1h->heap_region_containing((HeapWord*)obj); aoqi@0: gclog_or_tty->print_cr("Field "PTR_FORMAT aoqi@0: " of live obj "PTR_FORMAT" in region " aoqi@0: "["PTR_FORMAT", "PTR_FORMAT")", aoqi@0: p, (void*) _containing_obj, aoqi@0: from->bottom(), from->end()); aoqi@0: print_object(gclog_or_tty, _containing_obj); aoqi@0: gclog_or_tty->print_cr("points to dead obj "PTR_FORMAT" in region " aoqi@0: "["PTR_FORMAT", "PTR_FORMAT")", aoqi@0: (void*) obj, to->bottom(), to->end()); aoqi@0: print_object(gclog_or_tty, obj); aoqi@0: } aoqi@0: gclog_or_tty->print_cr("----------"); aoqi@0: gclog_or_tty->flush(); aoqi@0: _failures = true; aoqi@0: failed = true; aoqi@0: _n_failures++; aoqi@0: } aoqi@0: aoqi@0: if (!_g1h->full_collection() || G1VerifyRSetsDuringFullGC) { aoqi@0: HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p); aoqi@0: HeapRegion* to = _g1h->heap_region_containing(obj); aoqi@0: if (from != NULL && to != NULL && aoqi@0: from != to && aoqi@0: !to->isHumongous()) { aoqi@0: jbyte cv_obj = *_bs->byte_for_const(_containing_obj); aoqi@0: jbyte cv_field = *_bs->byte_for_const(p); aoqi@0: const jbyte dirty = CardTableModRefBS::dirty_card_val(); aoqi@0: aoqi@0: bool is_bad = !(from->is_young() aoqi@0: || to->rem_set()->contains_reference(p) aoqi@0: || !G1HRRSFlushLogBuffersOnVerify && // buffers were not flushed aoqi@0: (_containing_obj->is_objArray() ? aoqi@0: cv_field == dirty aoqi@0: : cv_obj == dirty || cv_field == dirty)); aoqi@0: if (is_bad) { aoqi@0: MutexLockerEx x(ParGCRareEvent_lock, aoqi@0: Mutex::_no_safepoint_check_flag); aoqi@0: aoqi@0: if (!_failures) { aoqi@0: gclog_or_tty->cr(); aoqi@0: gclog_or_tty->print_cr("----------"); aoqi@0: } aoqi@0: gclog_or_tty->print_cr("Missing rem set entry:"); aoqi@0: gclog_or_tty->print_cr("Field "PTR_FORMAT" " aoqi@0: "of obj "PTR_FORMAT", " aoqi@0: "in region "HR_FORMAT, aoqi@0: p, (void*) _containing_obj, aoqi@0: HR_FORMAT_PARAMS(from)); aoqi@0: _containing_obj->print_on(gclog_or_tty); aoqi@0: gclog_or_tty->print_cr("points to obj "PTR_FORMAT" " aoqi@0: "in region "HR_FORMAT, aoqi@0: (void*) obj, aoqi@0: HR_FORMAT_PARAMS(to)); aoqi@0: obj->print_on(gclog_or_tty); aoqi@0: gclog_or_tty->print_cr("Obj head CTE = %d, field CTE = %d.", aoqi@0: cv_obj, cv_field); aoqi@0: gclog_or_tty->print_cr("----------"); aoqi@0: gclog_or_tty->flush(); aoqi@0: _failures = true; aoqi@0: if (!failed) _n_failures++; aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: } aoqi@0: }; aoqi@0: aoqi@0: // This really ought to be commoned up into OffsetTableContigSpace somehow. aoqi@0: // We would need a mechanism to make that code skip dead objects. aoqi@0: aoqi@0: void HeapRegion::verify(VerifyOption vo, aoqi@0: bool* failures) const { aoqi@0: G1CollectedHeap* g1 = G1CollectedHeap::heap(); aoqi@0: *failures = false; aoqi@0: HeapWord* p = bottom(); aoqi@0: HeapWord* prev_p = NULL; aoqi@0: VerifyLiveClosure vl_cl(g1, vo); aoqi@0: bool is_humongous = isHumongous(); aoqi@0: bool do_bot_verify = !is_young(); aoqi@0: size_t object_num = 0; aoqi@0: while (p < top()) { aoqi@0: oop obj = oop(p); aoqi@0: size_t obj_size = obj->size(); aoqi@0: object_num += 1; aoqi@0: aoqi@0: if (is_humongous != g1->isHumongous(obj_size)) { aoqi@0: gclog_or_tty->print_cr("obj "PTR_FORMAT" is of %shumongous size (" aoqi@0: SIZE_FORMAT" words) in a %shumongous region", aoqi@0: p, g1->isHumongous(obj_size) ? "" : "non-", aoqi@0: obj_size, is_humongous ? "" : "non-"); aoqi@0: *failures = true; aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: // If it returns false, verify_for_object() will output the aoqi@0: // appropriate messasge. aoqi@0: if (do_bot_verify && !_offsets.verify_for_object(p, obj_size)) { aoqi@0: *failures = true; aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: if (!g1->is_obj_dead_cond(obj, this, vo)) { aoqi@0: if (obj->is_oop()) { aoqi@0: Klass* klass = obj->klass(); aoqi@0: if (!klass->is_metaspace_object()) { aoqi@0: gclog_or_tty->print_cr("klass "PTR_FORMAT" of object "PTR_FORMAT" " aoqi@0: "not metadata", klass, (void *)obj); aoqi@0: *failures = true; aoqi@0: return; aoqi@0: } else if (!klass->is_klass()) { aoqi@0: gclog_or_tty->print_cr("klass "PTR_FORMAT" of object "PTR_FORMAT" " aoqi@0: "not a klass", klass, (void *)obj); aoqi@0: *failures = true; aoqi@0: return; aoqi@0: } else { aoqi@0: vl_cl.set_containing_obj(obj); aoqi@0: obj->oop_iterate_no_header(&vl_cl); aoqi@0: if (vl_cl.failures()) { aoqi@0: *failures = true; aoqi@0: } aoqi@0: if (G1MaxVerifyFailures >= 0 && aoqi@0: vl_cl.n_failures() >= G1MaxVerifyFailures) { aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: } else { aoqi@0: gclog_or_tty->print_cr(PTR_FORMAT" no an oop", (void *)obj); aoqi@0: *failures = true; aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: prev_p = p; aoqi@0: p += obj_size; aoqi@0: } aoqi@0: aoqi@0: if (p != top()) { aoqi@0: gclog_or_tty->print_cr("end of last object "PTR_FORMAT" " aoqi@0: "does not match top "PTR_FORMAT, p, top()); aoqi@0: *failures = true; aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: HeapWord* the_end = end(); aoqi@0: assert(p == top(), "it should still hold"); aoqi@0: // Do some extra BOT consistency checking for addresses in the aoqi@0: // range [top, end). BOT look-ups in this range should yield aoqi@0: // top. No point in doing that if top == end (there's nothing there). aoqi@0: if (p < the_end) { aoqi@0: // Look up top aoqi@0: HeapWord* addr_1 = p; aoqi@0: HeapWord* b_start_1 = _offsets.block_start_const(addr_1); aoqi@0: if (b_start_1 != p) { aoqi@0: gclog_or_tty->print_cr("BOT look up for top: "PTR_FORMAT" " aoqi@0: " yielded "PTR_FORMAT", expecting "PTR_FORMAT, aoqi@0: addr_1, b_start_1, p); aoqi@0: *failures = true; aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: // Look up top + 1 aoqi@0: HeapWord* addr_2 = p + 1; aoqi@0: if (addr_2 < the_end) { aoqi@0: HeapWord* b_start_2 = _offsets.block_start_const(addr_2); aoqi@0: if (b_start_2 != p) { aoqi@0: gclog_or_tty->print_cr("BOT look up for top + 1: "PTR_FORMAT" " aoqi@0: " yielded "PTR_FORMAT", expecting "PTR_FORMAT, aoqi@0: addr_2, b_start_2, p); aoqi@0: *failures = true; aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Look up an address between top and end aoqi@0: size_t diff = pointer_delta(the_end, p) / 2; aoqi@0: HeapWord* addr_3 = p + diff; aoqi@0: if (addr_3 < the_end) { aoqi@0: HeapWord* b_start_3 = _offsets.block_start_const(addr_3); aoqi@0: if (b_start_3 != p) { aoqi@0: gclog_or_tty->print_cr("BOT look up for top + diff: "PTR_FORMAT" " aoqi@0: " yielded "PTR_FORMAT", expecting "PTR_FORMAT, aoqi@0: addr_3, b_start_3, p); aoqi@0: *failures = true; aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // Loook up end - 1 aoqi@0: HeapWord* addr_4 = the_end - 1; aoqi@0: HeapWord* b_start_4 = _offsets.block_start_const(addr_4); aoqi@0: if (b_start_4 != p) { aoqi@0: gclog_or_tty->print_cr("BOT look up for end - 1: "PTR_FORMAT" " aoqi@0: " yielded "PTR_FORMAT", expecting "PTR_FORMAT, aoqi@0: addr_4, b_start_4, p); aoqi@0: *failures = true; aoqi@0: return; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: if (is_humongous && object_num > 1) { aoqi@0: gclog_or_tty->print_cr("region ["PTR_FORMAT","PTR_FORMAT"] is humongous " aoqi@0: "but has "SIZE_FORMAT", objects", aoqi@0: bottom(), end(), object_num); aoqi@0: *failures = true; aoqi@0: return; aoqi@0: } aoqi@0: aoqi@0: verify_strong_code_roots(vo, failures); aoqi@0: } aoqi@0: aoqi@0: void HeapRegion::verify() const { aoqi@0: bool dummy = false; aoqi@0: verify(VerifyOption_G1UsePrevMarking, /* failures */ &dummy); aoqi@0: } aoqi@0: aoqi@0: // G1OffsetTableContigSpace code; copied from space.cpp. Hope this can go aoqi@0: // away eventually. aoqi@0: aoqi@0: void G1OffsetTableContigSpace::clear(bool mangle_space) { aoqi@0: ContiguousSpace::clear(mangle_space); aoqi@0: _offsets.zero_bottom_entry(); aoqi@0: _offsets.initialize_threshold(); aoqi@0: } aoqi@0: aoqi@0: void G1OffsetTableContigSpace::set_bottom(HeapWord* new_bottom) { aoqi@0: Space::set_bottom(new_bottom); aoqi@0: _offsets.set_bottom(new_bottom); aoqi@0: } aoqi@0: aoqi@0: void G1OffsetTableContigSpace::set_end(HeapWord* new_end) { aoqi@0: Space::set_end(new_end); aoqi@0: _offsets.resize(new_end - bottom()); aoqi@0: } aoqi@0: aoqi@0: void G1OffsetTableContigSpace::print() const { aoqi@0: print_short(); aoqi@0: gclog_or_tty->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " aoqi@0: INTPTR_FORMAT ", " INTPTR_FORMAT ")", aoqi@0: bottom(), top(), _offsets.threshold(), end()); aoqi@0: } aoqi@0: aoqi@0: HeapWord* G1OffsetTableContigSpace::initialize_threshold() { aoqi@0: return _offsets.initialize_threshold(); aoqi@0: } aoqi@0: aoqi@0: HeapWord* G1OffsetTableContigSpace::cross_threshold(HeapWord* start, aoqi@0: HeapWord* end) { aoqi@0: _offsets.alloc_block(start, end); aoqi@0: return _offsets.threshold(); aoqi@0: } aoqi@0: aoqi@0: HeapWord* G1OffsetTableContigSpace::saved_mark_word() const { aoqi@0: G1CollectedHeap* g1h = G1CollectedHeap::heap(); aoqi@0: assert( _gc_time_stamp <= g1h->get_gc_time_stamp(), "invariant" ); aoqi@0: if (_gc_time_stamp < g1h->get_gc_time_stamp()) aoqi@0: return top(); aoqi@0: else aoqi@0: return ContiguousSpace::saved_mark_word(); aoqi@0: } aoqi@0: aoqi@0: void G1OffsetTableContigSpace::set_saved_mark() { aoqi@0: G1CollectedHeap* g1h = G1CollectedHeap::heap(); aoqi@0: unsigned curr_gc_time_stamp = g1h->get_gc_time_stamp(); aoqi@0: aoqi@0: if (_gc_time_stamp < curr_gc_time_stamp) { aoqi@0: // The order of these is important, as another thread might be aoqi@0: // about to start scanning this region. If it does so after aoqi@0: // set_saved_mark and before _gc_time_stamp = ..., then the latter aoqi@0: // will be false, and it will pick up top() as the high water mark aoqi@0: // of region. If it does so after _gc_time_stamp = ..., then it aoqi@0: // will pick up the right saved_mark_word() as the high water mark aoqi@0: // of the region. Either way, the behaviour will be correct. aoqi@0: ContiguousSpace::set_saved_mark(); aoqi@0: OrderAccess::storestore(); aoqi@0: _gc_time_stamp = curr_gc_time_stamp; aoqi@0: // No need to do another barrier to flush the writes above. If aoqi@0: // this is called in parallel with other threads trying to aoqi@0: // allocate into the region, the caller should call this while aoqi@0: // holding a lock and when the lock is released the writes will be aoqi@0: // flushed. aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: G1OffsetTableContigSpace:: aoqi@0: G1OffsetTableContigSpace(G1BlockOffsetSharedArray* sharedOffsetArray, aoqi@0: MemRegion mr) : aoqi@0: _offsets(sharedOffsetArray, mr), aoqi@0: _par_alloc_lock(Mutex::leaf, "OffsetTableContigSpace par alloc lock", true), aoqi@0: _gc_time_stamp(0) aoqi@0: { aoqi@0: _offsets.set_space(this); aoqi@0: // false ==> we'll do the clearing if there's clearing to be done. aoqi@0: ContiguousSpace::initialize(mr, false, SpaceDecorator::Mangle); aoqi@0: _offsets.zero_bottom_entry(); aoqi@0: _offsets.initialize_threshold(); aoqi@0: }