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