ysr@777: /* johnc@2021: * Copyright (c) 2001, 2010, 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: ysr@777: #include "incls/_precompiled.incl" ysr@777: #include "incls/_g1RemSet.cpp.incl" ysr@777: ysr@777: #define CARD_REPEAT_HISTO 0 ysr@777: ysr@777: #if CARD_REPEAT_HISTO ysr@777: static size_t ct_freq_sz; ysr@777: static jbyte* ct_freq = NULL; ysr@777: ysr@777: void init_ct_freq_table(size_t heap_sz_bytes) { ysr@777: if (ct_freq == NULL) { ysr@777: ct_freq_sz = heap_sz_bytes/CardTableModRefBS::card_size; ysr@777: ct_freq = new jbyte[ct_freq_sz]; ysr@777: for (size_t j = 0; j < ct_freq_sz; j++) ct_freq[j] = 0; ysr@777: } ysr@777: } ysr@777: ysr@777: void ct_freq_note_card(size_t index) { ysr@777: assert(0 <= index && index < ct_freq_sz, "Bounds error."); ysr@777: if (ct_freq[index] < 100) { ct_freq[index]++; } ysr@777: } ysr@777: ysr@777: static IntHistogram card_repeat_count(10, 10); ysr@777: ysr@777: void ct_freq_update_histo_and_reset() { ysr@777: for (size_t j = 0; j < ct_freq_sz; j++) { ysr@777: card_repeat_count.add_entry(ct_freq[j]); ysr@777: ct_freq[j] = 0; ysr@777: } ysr@777: ysr@777: } ysr@777: #endif ysr@777: ysr@777: ysr@777: class IntoCSOopClosure: public OopsInHeapRegionClosure { ysr@777: OopsInHeapRegionClosure* _blk; ysr@777: G1CollectedHeap* _g1; ysr@777: public: ysr@777: IntoCSOopClosure(G1CollectedHeap* g1, OopsInHeapRegionClosure* blk) : ysr@777: _g1(g1), _blk(blk) {} ysr@777: void set_region(HeapRegion* from) { ysr@777: _blk->set_region(from); ysr@777: } ysr@1280: virtual void do_oop(narrowOop* p) { do_oop_work(p); } ysr@1280: virtual void do_oop( oop* p) { do_oop_work(p); } ysr@1280: template void do_oop_work(T* p) { ysr@1280: oop obj = oopDesc::load_decode_heap_oop(p); ysr@777: if (_g1->obj_in_cs(obj)) _blk->do_oop(p); ysr@777: } ysr@777: bool apply_to_weak_ref_discovered_field() { return true; } ysr@777: bool idempotent() { return true; } ysr@777: }; ysr@777: ysr@777: class IntoCSRegionClosure: public HeapRegionClosure { ysr@777: IntoCSOopClosure _blk; ysr@777: G1CollectedHeap* _g1; ysr@777: public: ysr@777: IntoCSRegionClosure(G1CollectedHeap* g1, OopsInHeapRegionClosure* blk) : ysr@777: _g1(g1), _blk(g1, blk) {} ysr@777: bool doHeapRegion(HeapRegion* r) { ysr@777: if (!r->in_collection_set()) { ysr@777: _blk.set_region(r); ysr@777: if (r->isHumongous()) { ysr@777: if (r->startsHumongous()) { ysr@777: oop obj = oop(r->bottom()); ysr@777: obj->oop_iterate(&_blk); ysr@777: } ysr@777: } else { ysr@777: r->oop_before_save_marks_iterate(&_blk); ysr@777: } ysr@777: } ysr@777: return false; ysr@777: } ysr@777: }; ysr@777: ysr@777: void ysr@777: StupidG1RemSet::oops_into_collection_set_do(OopsInHeapRegionClosure* oc, ysr@777: int worker_i) { ysr@777: IntoCSRegionClosure rc(_g1, oc); ysr@777: _g1->heap_region_iterate(&rc); ysr@777: } ysr@777: ysr@777: class VerifyRSCleanCardOopClosure: public OopClosure { ysr@777: G1CollectedHeap* _g1; ysr@777: public: ysr@777: VerifyRSCleanCardOopClosure(G1CollectedHeap* g1) : _g1(g1) {} ysr@777: ysr@1280: virtual void do_oop(narrowOop* p) { do_oop_work(p); } ysr@1280: virtual void do_oop( oop* p) { do_oop_work(p); } ysr@1280: template void do_oop_work(T* p) { ysr@1280: oop obj = oopDesc::load_decode_heap_oop(p); ysr@777: HeapRegion* to = _g1->heap_region_containing(obj); ysr@777: guarantee(to == NULL || !to->in_collection_set(), ysr@777: "Missed a rem set member."); ysr@777: } ysr@777: }; ysr@777: ysr@777: HRInto_G1RemSet::HRInto_G1RemSet(G1CollectedHeap* g1, CardTableModRefBS* ct_bs) ysr@777: : G1RemSet(g1), _ct_bs(ct_bs), _g1p(_g1->g1_policy()), ysr@777: _cg1r(g1->concurrent_g1_refine()), johnc@2060: _par_traversal_in_progress(false), johnc@2060: _cset_rs_update_cl(NULL), ysr@777: _cards_scanned(NULL), _total_cards_scanned(0) ysr@777: { ysr@777: _seq_task = new SubTasksDone(NumSeqTasks); iveresov@1051: guarantee(n_workers() > 0, "There should be some workers"); johnc@2060: _cset_rs_update_cl = NEW_C_HEAP_ARRAY(OopsInHeapRegionClosure*, n_workers()); iveresov@1051: for (uint i = 0; i < n_workers(); i++) { johnc@2060: _cset_rs_update_cl[i] = NULL; iveresov@1051: } ysr@777: } ysr@777: ysr@777: HRInto_G1RemSet::~HRInto_G1RemSet() { ysr@777: delete _seq_task; iveresov@1051: for (uint i = 0; i < n_workers(); i++) { johnc@2060: assert(_cset_rs_update_cl[i] == NULL, "it should be"); iveresov@1051: } johnc@2060: FREE_C_HEAP_ARRAY(OopsInHeapRegionClosure*, _cset_rs_update_cl); ysr@777: } ysr@777: ysr@777: void CountNonCleanMemRegionClosure::do_MemRegion(MemRegion mr) { ysr@777: if (_g1->is_in_g1_reserved(mr.start())) { ysr@777: _n += (int) ((mr.byte_size() / CardTableModRefBS::card_size)); ysr@777: if (_start_first == NULL) _start_first = mr.start(); ysr@777: } ysr@777: } ysr@777: ysr@777: class ScanRSClosure : public HeapRegionClosure { ysr@777: size_t _cards_done, _cards; ysr@777: G1CollectedHeap* _g1h; ysr@777: OopsInHeapRegionClosure* _oc; ysr@777: G1BlockOffsetSharedArray* _bot_shared; ysr@777: CardTableModRefBS *_ct_bs; ysr@777: int _worker_i; iveresov@1696: int _block_size; ysr@777: bool _try_claimed; ysr@777: public: ysr@777: ScanRSClosure(OopsInHeapRegionClosure* oc, int worker_i) : ysr@777: _oc(oc), ysr@777: _cards(0), ysr@777: _cards_done(0), ysr@777: _worker_i(worker_i), ysr@777: _try_claimed(false) ysr@777: { ysr@777: _g1h = G1CollectedHeap::heap(); ysr@777: _bot_shared = _g1h->bot_shared(); ysr@777: _ct_bs = (CardTableModRefBS*) (_g1h->barrier_set()); iveresov@1696: _block_size = MAX2(G1RSetScanBlockSize, 1); ysr@777: } ysr@777: ysr@777: void set_try_claimed() { _try_claimed = true; } ysr@777: ysr@777: void scanCard(size_t index, HeapRegion *r) { ysr@777: _cards_done++; ysr@777: DirtyCardToOopClosure* cl = ysr@777: r->new_dcto_closure(_oc, ysr@777: CardTableModRefBS::Precise, ysr@777: HeapRegionDCTOC::IntoCSFilterKind); ysr@777: ysr@777: // Set the "from" region in the closure. ysr@777: _oc->set_region(r); ysr@777: HeapWord* card_start = _bot_shared->address_for_index(index); ysr@777: HeapWord* card_end = card_start + G1BlockOffsetSharedArray::N_words; ysr@777: Space *sp = SharedHeap::heap()->space_containing(card_start); ysr@777: MemRegion sm_region; ysr@777: if (ParallelGCThreads > 0) { ysr@777: // first find the used area ysr@777: sm_region = sp->used_region_at_save_marks(); ysr@777: } else { ysr@777: // The closure is not idempotent. We shouldn't look at objects ysr@777: // allocated during the GC. ysr@777: sm_region = sp->used_region_at_save_marks(); ysr@777: } ysr@777: MemRegion mr = sm_region.intersection(MemRegion(card_start,card_end)); ysr@777: if (!mr.is_empty()) { ysr@777: cl->do_MemRegion(mr); ysr@777: } ysr@777: } ysr@777: ysr@777: void printCard(HeapRegion* card_region, size_t card_index, ysr@777: HeapWord* card_start) { ysr@777: gclog_or_tty->print_cr("T %d Region [" PTR_FORMAT ", " PTR_FORMAT ") " ysr@777: "RS names card %p: " ysr@777: "[" PTR_FORMAT ", " PTR_FORMAT ")", ysr@777: _worker_i, ysr@777: card_region->bottom(), card_region->end(), ysr@777: card_index, ysr@777: card_start, card_start + G1BlockOffsetSharedArray::N_words); ysr@777: } ysr@777: ysr@777: bool doHeapRegion(HeapRegion* r) { ysr@777: assert(r->in_collection_set(), "should only be called on elements of CS."); ysr@777: HeapRegionRemSet* hrrs = r->rem_set(); ysr@777: if (hrrs->iter_is_complete()) return false; // All done. ysr@777: if (!_try_claimed && !hrrs->claim_iter()) return false; apetrusenko@1231: _g1h->push_dirty_cards_region(r); ysr@777: // If we didn't return above, then ysr@777: // _try_claimed || r->claim_iter() ysr@777: // is true: either we're supposed to work on claimed-but-not-complete ysr@777: // regions, or we successfully claimed the region. ysr@777: HeapRegionRemSetIterator* iter = _g1h->rem_set_iterator(_worker_i); ysr@777: hrrs->init_iterator(iter); ysr@777: size_t card_index; iveresov@1696: iveresov@1696: // We claim cards in block so as to recude the contention. The block size is determined by iveresov@1696: // the G1RSetScanBlockSize parameter. iveresov@1696: size_t jump_to_card = hrrs->iter_claimed_next(_block_size); iveresov@1696: for (size_t current_card = 0; iter->has_next(card_index); current_card++) { iveresov@1696: if (current_card >= jump_to_card + _block_size) { iveresov@1696: jump_to_card = hrrs->iter_claimed_next(_block_size); iveresov@1182: } iveresov@1696: if (current_card < jump_to_card) continue; ysr@777: HeapWord* card_start = _g1h->bot_shared()->address_for_index(card_index); ysr@777: #if 0 ysr@777: gclog_or_tty->print("Rem set iteration yielded card [" PTR_FORMAT ", " PTR_FORMAT ").\n", ysr@777: card_start, card_start + CardTableModRefBS::card_size_in_words); ysr@777: #endif ysr@777: ysr@777: HeapRegion* card_region = _g1h->heap_region_containing(card_start); ysr@777: assert(card_region != NULL, "Yielding cards not in the heap?"); ysr@777: _cards++; ysr@777: apetrusenko@1231: if (!card_region->is_on_dirty_cards_region_list()) { apetrusenko@1231: _g1h->push_dirty_cards_region(card_region); apetrusenko@1231: } apetrusenko@1231: iveresov@1182: // If the card is dirty, then we will scan it during updateRS. iveresov@1182: if (!card_region->in_collection_set() && !_ct_bs->is_card_dirty(card_index)) { iveresov@1696: // We make the card as "claimed" lazily (so races are possible but they're benign), iveresov@1696: // which reduces the number of duplicate scans (the rsets of the regions in the cset iveresov@1696: // can intersect). iveresov@1696: if (!_ct_bs->is_card_claimed(card_index)) { iveresov@1696: _ct_bs->set_card_claimed(card_index); iveresov@1696: scanCard(card_index, card_region); iveresov@1696: } ysr@777: } ysr@777: } iveresov@1182: if (!_try_claimed) { iveresov@1182: hrrs->set_iter_complete(); iveresov@1182: } ysr@777: return false; ysr@777: } ysr@777: // Set all cards back to clean. ysr@777: void cleanup() {_g1h->cleanUpCardTable();} ysr@777: size_t cards_done() { return _cards_done;} ysr@777: size_t cards_looked_up() { return _cards;} ysr@777: }; ysr@777: ysr@777: // We want the parallel threads to start their scanning at ysr@777: // different collection set regions to avoid contention. ysr@777: // If we have: ysr@777: // n collection set regions ysr@777: // p threads ysr@777: // Then thread t will start at region t * floor (n/p) ysr@777: ysr@777: HeapRegion* HRInto_G1RemSet::calculateStartRegion(int worker_i) { ysr@777: HeapRegion* result = _g1p->collection_set(); ysr@777: if (ParallelGCThreads > 0) { ysr@777: size_t cs_size = _g1p->collection_set_size(); ysr@777: int n_workers = _g1->workers()->total_workers(); ysr@777: size_t cs_spans = cs_size / n_workers; ysr@777: size_t ind = cs_spans * worker_i; ysr@777: for (size_t i = 0; i < ind; i++) ysr@777: result = result->next_in_collection_set(); ysr@777: } ysr@777: return result; ysr@777: } ysr@777: ysr@777: void HRInto_G1RemSet::scanRS(OopsInHeapRegionClosure* oc, int worker_i) { ysr@777: double rs_time_start = os::elapsedTime(); ysr@777: HeapRegion *startRegion = calculateStartRegion(worker_i); ysr@777: iveresov@1696: ScanRSClosure scanRScl(oc, worker_i); ysr@777: _g1->collection_set_iterate_from(startRegion, &scanRScl); ysr@777: scanRScl.set_try_claimed(); ysr@777: _g1->collection_set_iterate_from(startRegion, &scanRScl); ysr@777: iveresov@1696: double scan_rs_time_sec = os::elapsedTime() - rs_time_start; ysr@777: ysr@777: assert( _cards_scanned != NULL, "invariant" ); ysr@777: _cards_scanned[worker_i] = scanRScl.cards_done(); ysr@777: ysr@777: _g1p->record_scan_rs_time(worker_i, scan_rs_time_sec * 1000.0); ysr@777: } ysr@777: johnc@2060: // Closure used for updating RSets and recording references that johnc@2060: // point into the collection set. Only called during an johnc@2060: // evacuation pause. ysr@777: johnc@2060: class RefineRecordRefsIntoCSCardTableEntryClosure: public CardTableEntryClosure { johnc@2060: G1RemSet* _g1rs; johnc@2060: DirtyCardQueue* _into_cset_dcq; johnc@2060: public: johnc@2060: RefineRecordRefsIntoCSCardTableEntryClosure(G1CollectedHeap* g1h, johnc@2060: DirtyCardQueue* into_cset_dcq) : johnc@2060: _g1rs(g1h->g1_rem_set()), _into_cset_dcq(into_cset_dcq) johnc@2060: {} johnc@2060: bool do_card_ptr(jbyte* card_ptr, int worker_i) { johnc@2060: // The only time we care about recording cards that johnc@2060: // contain references that point into the collection set johnc@2060: // is during RSet updating within an evacuation pause. johnc@2060: // In this case worker_i should be the id of a GC worker thread. johnc@2060: assert(SafepointSynchronize::is_at_safepoint(), "not during an evacuation pause"); johnc@2060: assert(worker_i < (int) DirtyCardQueueSet::num_par_ids(), "should be a GC worker"); johnc@2060: johnc@2060: if (_g1rs->concurrentRefineOneCard(card_ptr, worker_i, true)) { johnc@2060: // 'card_ptr' contains references that point into the collection johnc@2060: // set. We need to record the card in the DCQS johnc@2060: // (G1CollectedHeap::into_cset_dirty_card_queue_set()) johnc@2060: // that's used for that purpose. johnc@2060: // johnc@2060: // Enqueue the card johnc@2060: _into_cset_dcq->enqueue(card_ptr); johnc@2060: } johnc@2060: return true; johnc@2060: } johnc@2060: }; johnc@2060: johnc@2060: void HRInto_G1RemSet::updateRS(DirtyCardQueue* into_cset_dcq, int worker_i) { ysr@777: double start = os::elapsedTime(); johnc@2060: // Apply the given closure to all remaining log entries. johnc@2060: RefineRecordRefsIntoCSCardTableEntryClosure into_cset_update_rs_cl(_g1, into_cset_dcq); johnc@2060: _g1->iterate_dirty_card_closure(&into_cset_update_rs_cl, into_cset_dcq, false, worker_i); johnc@2060: iveresov@1229: // Now there should be no dirty cards. iveresov@1229: if (G1RSLogCheckCardTable) { iveresov@1229: CountNonCleanMemRegionClosure cl(_g1); iveresov@1229: _ct_bs->mod_card_iterate(&cl); iveresov@1229: // XXX This isn't true any more: keeping cards of young regions iveresov@1229: // marked dirty broke it. Need some reasonable fix. iveresov@1229: guarantee(cl.n() == 0, "Card table should be clean."); ysr@777: } iveresov@1229: ysr@777: _g1p->record_update_rs_time(worker_i, (os::elapsedTime() - start) * 1000.0); ysr@777: } ysr@777: ysr@777: #ifndef PRODUCT ysr@777: class PrintRSClosure : public HeapRegionClosure { ysr@777: int _count; ysr@777: public: ysr@777: PrintRSClosure() : _count(0) {} ysr@777: bool doHeapRegion(HeapRegion* r) { ysr@777: HeapRegionRemSet* hrrs = r->rem_set(); ysr@777: _count += (int) hrrs->occupied(); ysr@777: if (hrrs->occupied() == 0) { ysr@777: gclog_or_tty->print("Heap Region [" PTR_FORMAT ", " PTR_FORMAT ") " ysr@777: "has no remset entries\n", ysr@777: r->bottom(), r->end()); ysr@777: } else { ysr@777: gclog_or_tty->print("Printing rem set for heap region [" PTR_FORMAT ", " PTR_FORMAT ")\n", ysr@777: r->bottom(), r->end()); ysr@777: r->print(); ysr@777: hrrs->print(); ysr@777: gclog_or_tty->print("\nDone printing rem set\n"); ysr@777: } ysr@777: return false; ysr@777: } ysr@777: int occupied() {return _count;} ysr@777: }; ysr@777: #endif ysr@777: ysr@777: class CountRSSizeClosure: public HeapRegionClosure { ysr@777: size_t _n; ysr@777: size_t _tot; ysr@777: size_t _max; ysr@777: HeapRegion* _max_r; ysr@777: enum { ysr@777: N = 20, ysr@777: MIN = 6 ysr@777: }; ysr@777: int _histo[N]; ysr@777: public: ysr@777: CountRSSizeClosure() : _n(0), _tot(0), _max(0), _max_r(NULL) { ysr@777: for (int i = 0; i < N; i++) _histo[i] = 0; ysr@777: } ysr@777: bool doHeapRegion(HeapRegion* r) { ysr@777: if (!r->continuesHumongous()) { ysr@777: size_t occ = r->rem_set()->occupied(); ysr@777: _n++; ysr@777: _tot += occ; ysr@777: if (occ > _max) { ysr@777: _max = occ; ysr@777: _max_r = r; ysr@777: } ysr@777: // Fit it into a histo bin. ysr@777: int s = 1 << MIN; ysr@777: int i = 0; ysr@777: while (occ > (size_t) s && i < (N-1)) { ysr@777: s = s << 1; ysr@777: i++; ysr@777: } ysr@777: _histo[i]++; ysr@777: } ysr@777: return false; ysr@777: } ysr@777: size_t n() { return _n; } ysr@777: size_t tot() { return _tot; } ysr@777: size_t mx() { return _max; } ysr@777: HeapRegion* mxr() { return _max_r; } ysr@777: void print_histo() { ysr@777: int mx = N; ysr@777: while (mx >= 0) { ysr@777: if (_histo[mx-1] > 0) break; ysr@777: mx--; ysr@777: } ysr@777: gclog_or_tty->print_cr("Number of regions with given RS sizes:"); ysr@777: gclog_or_tty->print_cr(" <= %8d %8d", 1 << MIN, _histo[0]); ysr@777: for (int i = 1; i < mx-1; i++) { ysr@777: gclog_or_tty->print_cr(" %8d - %8d %8d", ysr@777: (1 << (MIN + i - 1)) + 1, ysr@777: 1 << (MIN + i), ysr@777: _histo[i]); ysr@777: } ysr@777: gclog_or_tty->print_cr(" > %8d %8d", (1 << (MIN+mx-2))+1, _histo[mx-1]); ysr@777: } ysr@777: }; ysr@777: ysr@777: void HRInto_G1RemSet::cleanupHRRS() { ysr@777: HeapRegionRemSet::cleanup(); ysr@777: } ysr@777: ysr@777: void ysr@777: HRInto_G1RemSet::oops_into_collection_set_do(OopsInHeapRegionClosure* oc, ysr@777: int worker_i) { ysr@777: #if CARD_REPEAT_HISTO ysr@777: ct_freq_update_histo_and_reset(); ysr@777: #endif ysr@777: if (worker_i == 0) { ysr@777: _cg1r->clear_and_record_card_counts(); ysr@777: } ysr@777: ysr@777: // Make this into a command-line flag... ysr@777: if (G1RSCountHisto && (ParallelGCThreads == 0 || worker_i == 0)) { ysr@777: CountRSSizeClosure count_cl; ysr@777: _g1->heap_region_iterate(&count_cl); ysr@777: gclog_or_tty->print_cr("Avg of %d RS counts is %f, max is %d, " ysr@777: "max region is " PTR_FORMAT, ysr@777: count_cl.n(), (float)count_cl.tot()/(float)count_cl.n(), ysr@777: count_cl.mx(), count_cl.mxr()); ysr@777: count_cl.print_histo(); ysr@777: } ysr@777: johnc@2060: // We cache the value of 'oc' closure into the appropriate slot in the johnc@2060: // _cset_rs_update_cl for this worker johnc@2060: assert(worker_i < (int)n_workers(), "sanity"); johnc@2060: _cset_rs_update_cl[worker_i] = oc; johnc@2060: johnc@2060: // A DirtyCardQueue that is used to hold cards containing references johnc@2060: // that point into the collection set. This DCQ is associated with a johnc@2060: // special DirtyCardQueueSet (see g1CollectedHeap.hpp). Under normal johnc@2060: // circumstances (i.e. the pause successfully completes), these cards johnc@2060: // are just discarded (there's no need to update the RSets of regions johnc@2060: // that were in the collection set - after the pause these regions johnc@2060: // are wholly 'free' of live objects. In the event of an evacuation johnc@2060: // failure the cards/buffers in this queue set are: johnc@2060: // * passed to the DirtyCardQueueSet that is used to manage deferred johnc@2060: // RSet updates, or johnc@2060: // * scanned for references that point into the collection set johnc@2060: // and the RSet of the corresponding region in the collection set johnc@2060: // is updated immediately. johnc@2060: DirtyCardQueue into_cset_dcq(&_g1->into_cset_dirty_card_queue_set()); johnc@2060: ysr@777: if (ParallelGCThreads > 0) { tonyp@1073: // The two flags below were introduced temporarily to serialize tonyp@1073: // the updating and scanning of remembered sets. There are some tonyp@1073: // race conditions when these two operations are done in parallel tonyp@1073: // and they are causing failures. When we resolve said race tonyp@1073: // conditions, we'll revert back to parallel remembered set tonyp@1073: // updating and scanning. See CRs 6677707 and 6677708. tonyp@1717: if (G1UseParallelRSetUpdating || (worker_i == 0)) { johnc@2060: updateRS(&into_cset_dcq, worker_i); tonyp@1083: } else { tonyp@1083: _g1p->record_update_rs_processed_buffers(worker_i, 0.0); tonyp@1083: _g1p->record_update_rs_time(worker_i, 0.0); tonyp@1073: } tonyp@1717: if (G1UseParallelRSetScanning || (worker_i == 0)) { ysr@777: scanRS(oc, worker_i); tonyp@1083: } else { tonyp@1083: _g1p->record_scan_rs_time(worker_i, 0.0); ysr@777: } ysr@777: } else { ysr@777: assert(worker_i == 0, "invariant"); johnc@2060: updateRS(&into_cset_dcq, 0); ysr@777: scanRS(oc, 0); ysr@777: } johnc@2060: johnc@2060: // We now clear the cached values of _cset_rs_update_cl for this worker johnc@2060: _cset_rs_update_cl[worker_i] = NULL; ysr@777: } ysr@777: ysr@777: void HRInto_G1RemSet:: ysr@777: prepare_for_oops_into_collection_set_do() { ysr@777: #if G1_REM_SET_LOGGING ysr@777: PrintRSClosure cl; ysr@777: _g1->collection_set_iterate(&cl); ysr@777: #endif ysr@777: cleanupHRRS(); ysr@777: ConcurrentG1Refine* cg1r = _g1->concurrent_g1_refine(); ysr@777: _g1->set_refine_cte_cl_concurrency(false); ysr@777: DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); ysr@777: dcqs.concatenate_logs(); ysr@777: ysr@777: assert(!_par_traversal_in_progress, "Invariant between iterations."); ysr@777: if (ParallelGCThreads > 0) { ysr@777: set_par_traversal(true); iveresov@1051: _seq_task->set_par_threads((int)n_workers()); ysr@777: } ysr@777: guarantee( _cards_scanned == NULL, "invariant" ); ysr@777: _cards_scanned = NEW_C_HEAP_ARRAY(size_t, n_workers()); apetrusenko@980: for (uint i = 0; i < n_workers(); ++i) { apetrusenko@980: _cards_scanned[i] = 0; apetrusenko@980: } ysr@777: _total_cards_scanned = 0; ysr@777: } ysr@777: ysr@777: ysr@777: class cleanUpIteratorsClosure : public HeapRegionClosure { ysr@777: bool doHeapRegion(HeapRegion *r) { ysr@777: HeapRegionRemSet* hrrs = r->rem_set(); ysr@777: hrrs->init_for_par_iteration(); ysr@777: return false; ysr@777: } ysr@777: }; ysr@777: johnc@2060: // This closure, applied to a DirtyCardQueueSet, is used to immediately johnc@2060: // update the RSets for the regions in the CSet. For each card it iterates johnc@2060: // through the oops which coincide with that card. It scans the reference johnc@2060: // fields in each oop; when it finds an oop that points into the collection johnc@2060: // set, the RSet for the region containing the referenced object is updated. johnc@2060: // Note: _par_traversal_in_progress in the G1RemSet must be FALSE; otherwise johnc@2060: // the UpdateRSetImmediate closure will cause cards to be enqueued on to johnc@2060: // the DCQS that we're iterating over, causing an infinite loop. johnc@2060: class UpdateRSetCardTableEntryIntoCSetClosure: public CardTableEntryClosure { iveresov@1051: G1CollectedHeap* _g1; johnc@2060: CardTableModRefBS* _ct_bs; iveresov@1051: public: johnc@2060: UpdateRSetCardTableEntryIntoCSetClosure(G1CollectedHeap* g1, johnc@2060: CardTableModRefBS* bs): johnc@2060: _g1(g1), _ct_bs(bs) johnc@2060: { } johnc@2060: johnc@2060: bool do_card_ptr(jbyte* card_ptr, int worker_i) { johnc@2060: // Construct the region representing the card. johnc@2060: HeapWord* start = _ct_bs->addr_for(card_ptr); johnc@2060: // And find the region containing it. johnc@2060: HeapRegion* r = _g1->heap_region_containing(start); johnc@2060: assert(r != NULL, "unexpected null"); johnc@2060: johnc@2060: // Scan oops in the card looking for references into the collection set johnc@2060: HeapWord* end = _ct_bs->addr_for(card_ptr + 1); johnc@2060: MemRegion scanRegion(start, end); johnc@2060: johnc@2060: UpdateRSetImmediate update_rs_cl(_g1->g1_rem_set()); johnc@2060: FilterIntoCSClosure update_rs_cset_oop_cl(NULL, _g1, &update_rs_cl); johnc@2060: FilterOutOfRegionClosure filter_then_update_rs_cset_oop_cl(r, &update_rs_cset_oop_cl); johnc@2060: johnc@2060: // We can pass false as the "filter_young" parameter here as: johnc@2060: // * we should be in a STW pause, johnc@2060: // * the DCQS to which this closure is applied is used to hold johnc@2060: // references that point into the collection set from the prior johnc@2060: // RSet updating, johnc@2060: // * the post-write barrier shouldn't be logging updates to young johnc@2060: // regions (but there is a situation where this can happen - see johnc@2060: // the comment in HRInto_G1RemSet::concurrentRefineOneCard below - johnc@2060: // that should not be applicable here), and johnc@2060: // * during actual RSet updating, the filtering of cards in young johnc@2060: // regions in HeapRegion::oops_on_card_seq_iterate_careful is johnc@2060: // employed. johnc@2060: // As a result, when this closure is applied to "refs into cset" johnc@2060: // DCQS, we shouldn't see any cards in young regions. johnc@2060: update_rs_cl.set_region(r); johnc@2060: HeapWord* stop_point = johnc@2060: r->oops_on_card_seq_iterate_careful(scanRegion, johnc@2060: &filter_then_update_rs_cset_oop_cl, johnc@2060: false /* filter_young */); johnc@2060: johnc@2060: // Since this is performed in the event of an evacuation failure, we johnc@2060: // we shouldn't see a non-null stop point johnc@2060: assert(stop_point == NULL, "saw an unallocated region"); johnc@2060: return true; iveresov@1051: } iveresov@1051: }; iveresov@1051: ysr@777: void HRInto_G1RemSet::cleanup_after_oops_into_collection_set_do() { ysr@777: guarantee( _cards_scanned != NULL, "invariant" ); ysr@777: _total_cards_scanned = 0; ysr@777: for (uint i = 0; i < n_workers(); ++i) ysr@777: _total_cards_scanned += _cards_scanned[i]; ysr@777: FREE_C_HEAP_ARRAY(size_t, _cards_scanned); ysr@777: _cards_scanned = NULL; ysr@777: // Cleanup after copy ysr@777: #if G1_REM_SET_LOGGING ysr@777: PrintRSClosure cl; ysr@777: _g1->heap_region_iterate(&cl); ysr@777: #endif ysr@777: _g1->set_refine_cte_cl_concurrency(true); ysr@777: cleanUpIteratorsClosure iterClosure; ysr@777: _g1->collection_set_iterate(&iterClosure); ysr@777: // Set all cards back to clean. ysr@777: _g1->cleanUpCardTable(); iveresov@1229: ysr@777: if (ParallelGCThreads > 0) { ysr@777: set_par_traversal(false); ysr@777: } iveresov@1051: johnc@2060: DirtyCardQueueSet& into_cset_dcqs = _g1->into_cset_dirty_card_queue_set(); johnc@2060: int into_cset_n_buffers = into_cset_dcqs.completed_buffers_num(); johnc@2060: iveresov@1051: if (_g1->evacuation_failed()) { johnc@2060: // Restore remembered sets for the regions pointing into the collection set. johnc@2060: iveresov@1051: if (G1DeferredRSUpdate) { johnc@2060: // If deferred RS updates are enabled then we just need to transfer johnc@2060: // the completed buffers from (a) the DirtyCardQueueSet used to hold johnc@2060: // cards that contain references that point into the collection set johnc@2060: // to (b) the DCQS used to hold the deferred RS updates johnc@2060: _g1->dirty_card_queue_set().merge_bufferlists(&into_cset_dcqs); iveresov@1051: } else { johnc@2060: johnc@2060: CardTableModRefBS* bs = (CardTableModRefBS*)_g1->barrier_set(); johnc@2060: UpdateRSetCardTableEntryIntoCSetClosure update_rs_cset_immediate(_g1, bs); johnc@2060: johnc@2060: int n_completed_buffers = 0; johnc@2060: while (into_cset_dcqs.apply_closure_to_completed_buffer(&update_rs_cset_immediate, johnc@2060: 0, 0, true)) { johnc@2060: n_completed_buffers++; johnc@2060: } johnc@2060: assert(n_completed_buffers == into_cset_n_buffers, "missed some buffers"); iveresov@1051: } iveresov@1051: } johnc@2060: johnc@2060: // Free any completed buffers in the DirtyCardQueueSet used to hold cards johnc@2060: // which contain references that point into the collection. johnc@2060: _g1->into_cset_dirty_card_queue_set().clear(); johnc@2060: assert(_g1->into_cset_dirty_card_queue_set().completed_buffers_num() == 0, johnc@2060: "all buffers should be freed"); johnc@2060: _g1->into_cset_dirty_card_queue_set().clear_n_completed_buffers(); iveresov@1051: ysr@777: assert(!_par_traversal_in_progress, "Invariant between iterations."); ysr@777: } ysr@777: ysr@777: class UpdateRSObjectClosure: public ObjectClosure { ysr@777: UpdateRSOopClosure* _update_rs_oop_cl; ysr@777: public: ysr@777: UpdateRSObjectClosure(UpdateRSOopClosure* update_rs_oop_cl) : ysr@777: _update_rs_oop_cl(update_rs_oop_cl) {} ysr@777: void do_object(oop obj) { ysr@777: obj->oop_iterate(_update_rs_oop_cl); ysr@777: } ysr@777: ysr@777: }; ysr@777: ysr@777: class ScrubRSClosure: public HeapRegionClosure { ysr@777: G1CollectedHeap* _g1h; ysr@777: BitMap* _region_bm; ysr@777: BitMap* _card_bm; ysr@777: CardTableModRefBS* _ctbs; ysr@777: public: ysr@777: ScrubRSClosure(BitMap* region_bm, BitMap* card_bm) : ysr@777: _g1h(G1CollectedHeap::heap()), ysr@777: _region_bm(region_bm), _card_bm(card_bm), ysr@777: _ctbs(NULL) ysr@777: { ysr@777: ModRefBarrierSet* bs = _g1h->mr_bs(); ysr@777: guarantee(bs->is_a(BarrierSet::CardTableModRef), "Precondition"); ysr@777: _ctbs = (CardTableModRefBS*)bs; ysr@777: } ysr@777: ysr@777: bool doHeapRegion(HeapRegion* r) { ysr@777: if (!r->continuesHumongous()) { ysr@777: r->rem_set()->scrub(_ctbs, _region_bm, _card_bm); ysr@777: } ysr@777: return false; ysr@777: } ysr@777: }; ysr@777: ysr@777: void HRInto_G1RemSet::scrub(BitMap* region_bm, BitMap* card_bm) { ysr@777: ScrubRSClosure scrub_cl(region_bm, card_bm); ysr@777: _g1->heap_region_iterate(&scrub_cl); ysr@777: } ysr@777: ysr@777: void HRInto_G1RemSet::scrub_par(BitMap* region_bm, BitMap* card_bm, ysr@777: int worker_num, int claim_val) { ysr@777: ScrubRSClosure scrub_cl(region_bm, card_bm); ysr@777: _g1->heap_region_par_iterate_chunked(&scrub_cl, worker_num, claim_val); ysr@777: } ysr@777: ysr@777: ysr@777: static IntHistogram out_of_histo(50, 50); ysr@777: johnc@2060: class TriggerClosure : public OopClosure { johnc@2060: bool _trigger; johnc@2060: public: johnc@2060: TriggerClosure() : _trigger(false) { } johnc@2060: bool value() const { return _trigger; } johnc@2060: template void do_oop_nv(T* p) { _trigger = true; } johnc@2060: virtual void do_oop(oop* p) { do_oop_nv(p); } johnc@2060: virtual void do_oop(narrowOop* p) { do_oop_nv(p); } johnc@2060: }; johnc@2060: johnc@2060: class InvokeIfNotTriggeredClosure: public OopClosure { johnc@2060: TriggerClosure* _t; johnc@2060: OopClosure* _oc; johnc@2060: public: johnc@2060: InvokeIfNotTriggeredClosure(TriggerClosure* t, OopClosure* oc): johnc@2060: _t(t), _oc(oc) { } johnc@2060: template void do_oop_nv(T* p) { johnc@2060: if (!_t->value()) _oc->do_oop(p); johnc@2060: } johnc@2060: virtual void do_oop(oop* p) { do_oop_nv(p); } johnc@2060: virtual void do_oop(narrowOop* p) { do_oop_nv(p); } johnc@2060: }; johnc@2060: johnc@2060: class Mux2Closure : public OopClosure { johnc@2060: OopClosure* _c1; johnc@2060: OopClosure* _c2; johnc@2060: public: johnc@2060: Mux2Closure(OopClosure *c1, OopClosure *c2) : _c1(c1), _c2(c2) { } johnc@2060: template void do_oop_nv(T* p) { johnc@2060: _c1->do_oop(p); _c2->do_oop(p); johnc@2060: } johnc@2060: virtual void do_oop(oop* p) { do_oop_nv(p); } johnc@2060: virtual void do_oop(narrowOop* p) { do_oop_nv(p); } johnc@2060: }; johnc@2060: johnc@2060: bool HRInto_G1RemSet::concurrentRefineOneCard_impl(jbyte* card_ptr, int worker_i, johnc@2060: bool check_for_refs_into_cset) { johnc@1325: // Construct the region representing the card. johnc@1325: HeapWord* start = _ct_bs->addr_for(card_ptr); johnc@1325: // And find the region containing it. johnc@1325: HeapRegion* r = _g1->heap_region_containing(start); johnc@1325: assert(r != NULL, "unexpected null"); johnc@1325: johnc@1325: HeapWord* end = _ct_bs->addr_for(card_ptr + 1); johnc@1325: MemRegion dirtyRegion(start, end); johnc@1325: johnc@1325: #if CARD_REPEAT_HISTO johnc@1325: init_ct_freq_table(_g1->g1_reserved_obj_bytes()); johnc@1325: ct_freq_note_card(_ct_bs->index_for(start)); johnc@1325: #endif johnc@1325: johnc@1325: UpdateRSOopClosure update_rs_oop_cl(this, worker_i); johnc@1325: update_rs_oop_cl.set_from(r); johnc@2060: johnc@2060: TriggerClosure trigger_cl; johnc@2060: FilterIntoCSClosure into_cs_cl(NULL, _g1, &trigger_cl); johnc@2060: InvokeIfNotTriggeredClosure invoke_cl(&trigger_cl, &into_cs_cl); johnc@2060: Mux2Closure mux(&invoke_cl, &update_rs_oop_cl); johnc@2060: johnc@2060: FilterOutOfRegionClosure filter_then_update_rs_oop_cl(r, johnc@2060: (check_for_refs_into_cset ? johnc@2060: (OopClosure*)&mux : johnc@2060: (OopClosure*)&update_rs_oop_cl)); johnc@1325: johnc@1325: // Undirty the card. johnc@1325: *card_ptr = CardTableModRefBS::clean_card_val(); johnc@1325: // We must complete this write before we do any of the reads below. johnc@1325: OrderAccess::storeload(); johnc@1325: // And process it, being careful of unallocated portions of TLAB's. johnc@2021: johnc@2021: // The region for the current card may be a young region. The johnc@2021: // current card may have been a card that was evicted from the johnc@2021: // card cache. When the card was inserted into the cache, we had johnc@2021: // determined that its region was non-young. While in the cache, johnc@2021: // the region may have been freed during a cleanup pause, reallocated johnc@2021: // and tagged as young. johnc@2021: // johnc@2021: // We wish to filter out cards for such a region but the current johnc@2021: // thread, if we're running conucrrently, may "see" the young type johnc@2021: // change at any time (so an earlier "is_young" check may pass or johnc@2021: // fail arbitrarily). We tell the iteration code to perform this johnc@2021: // filtering when it has been determined that there has been an actual johnc@2021: // allocation in this region and making it safe to check the young type. johnc@2021: bool filter_young = true; johnc@2021: johnc@1325: HeapWord* stop_point = johnc@1325: r->oops_on_card_seq_iterate_careful(dirtyRegion, johnc@2021: &filter_then_update_rs_oop_cl, johnc@2021: filter_young); johnc@2021: johnc@1325: // If stop_point is non-null, then we encountered an unallocated region johnc@1325: // (perhaps the unfilled portion of a TLAB.) For now, we'll dirty the johnc@1325: // card and re-enqueue: if we put off the card until a GC pause, then the johnc@1325: // unallocated portion will be filled in. Alternatively, we might try johnc@1325: // the full complexity of the technique used in "regular" precleaning. johnc@1325: if (stop_point != NULL) { johnc@1325: // The card might have gotten re-dirtied and re-enqueued while we johnc@1325: // worked. (In fact, it's pretty likely.) johnc@1325: if (*card_ptr != CardTableModRefBS::dirty_card_val()) { johnc@1325: *card_ptr = CardTableModRefBS::dirty_card_val(); johnc@1325: MutexLockerEx x(Shared_DirtyCardQ_lock, johnc@1325: Mutex::_no_safepoint_check_flag); johnc@1325: DirtyCardQueue* sdcq = johnc@1325: JavaThread::dirty_card_queue_set().shared_dirty_card_queue(); johnc@1325: sdcq->enqueue(card_ptr); johnc@1325: } johnc@1325: } else { johnc@1325: out_of_histo.add_entry(filter_then_update_rs_oop_cl.out_of_region()); johnc@1325: _conc_refine_cards++; johnc@1325: } johnc@2060: johnc@2060: return trigger_cl.value(); johnc@1325: } johnc@1325: johnc@2060: bool HRInto_G1RemSet::concurrentRefineOneCard(jbyte* card_ptr, int worker_i, johnc@2060: bool check_for_refs_into_cset) { ysr@777: // If the card is no longer dirty, nothing to do. johnc@2060: if (*card_ptr != CardTableModRefBS::dirty_card_val()) { johnc@2060: // No need to return that this card contains refs that point johnc@2060: // into the collection set. johnc@2060: return false; johnc@2060: } ysr@777: ysr@777: // Construct the region representing the card. ysr@777: HeapWord* start = _ct_bs->addr_for(card_ptr); ysr@777: // And find the region containing it. ysr@777: HeapRegion* r = _g1->heap_region_containing(start); ysr@777: if (r == NULL) { ysr@777: guarantee(_g1->is_in_permanent(start), "Or else where?"); johnc@2060: // Again no need to return that this card contains refs that johnc@2060: // point into the collection set. johnc@2060: return false; // Not in the G1 heap (might be in perm, for example.) ysr@777: } ysr@777: // Why do we have to check here whether a card is on a young region, ysr@777: // given that we dirty young regions and, as a result, the ysr@777: // post-barrier is supposed to filter them out and never to enqueue ysr@777: // them? When we allocate a new region as the "allocation region" we ysr@777: // actually dirty its cards after we release the lock, since card ysr@777: // dirtying while holding the lock was a performance bottleneck. So, ysr@777: // as a result, it is possible for other threads to actually ysr@777: // allocate objects in the region (after the acquire the lock) ysr@777: // before all the cards on the region are dirtied. This is unlikely, ysr@777: // and it doesn't happen often, but it can happen. So, the extra ysr@777: // check below filters out those cards. iveresov@1072: if (r->is_young()) { johnc@2060: return false; ysr@777: } ysr@777: // While we are processing RSet buffers during the collection, we ysr@777: // actually don't want to scan any cards on the collection set, ysr@777: // since we don't want to update remebered sets with entries that ysr@777: // point into the collection set, given that live objects from the ysr@777: // collection set are about to move and such entries will be stale ysr@777: // very soon. This change also deals with a reliability issue which ysr@777: // involves scanning a card in the collection set and coming across ysr@777: // an array that was being chunked and looking malformed. Note, ysr@777: // however, that if evacuation fails, we have to scan any objects ysr@777: // that were not moved and create any missing entries. ysr@777: if (r->in_collection_set()) { johnc@2060: return false; ysr@777: } ysr@777: johnc@1325: // Should we defer processing the card? johnc@1325: // johnc@1325: // Previously the result from the insert_cache call would be johnc@1325: // either card_ptr (implying that card_ptr was currently "cold"), johnc@1325: // null (meaning we had inserted the card ptr into the "hot" johnc@1325: // cache, which had some headroom), or a "hot" card ptr johnc@1325: // extracted from the "hot" cache. johnc@1325: // johnc@1325: // Now that the _card_counts cache in the ConcurrentG1Refine johnc@1325: // instance is an evicting hash table, the result we get back johnc@1325: // could be from evicting the card ptr in an already occupied johnc@1325: // bucket (in which case we have replaced the card ptr in the johnc@1325: // bucket with card_ptr and "defer" is set to false). To avoid johnc@1325: // having a data structure (updates to which would need a lock) johnc@1325: // to hold these unprocessed dirty cards, we need to immediately johnc@1325: // process card_ptr. The actions needed to be taken on return johnc@1325: // from cache_insert are summarized in the following table: johnc@1325: // johnc@1325: // res defer action johnc@1325: // -------------------------------------------------------------- johnc@1325: // null false card evicted from _card_counts & replaced with johnc@1325: // card_ptr; evicted ptr added to hot cache. johnc@1325: // No need to process res; immediately process card_ptr johnc@1325: // johnc@1325: // null true card not evicted from _card_counts; card_ptr added johnc@1325: // to hot cache. johnc@1325: // Nothing to do. johnc@1325: // johnc@1325: // non-null false card evicted from _card_counts & replaced with johnc@1325: // card_ptr; evicted ptr is currently "cold" or johnc@1325: // caused an eviction from the hot cache. johnc@1325: // Immediately process res; process card_ptr. johnc@1325: // johnc@1325: // non-null true card not evicted from _card_counts; card_ptr is johnc@1325: // currently cold, or caused an eviction from hot johnc@1325: // cache. johnc@1325: // Immediately process res; no need to process card_ptr. johnc@1325: johnc@2060: johnc@1325: jbyte* res = card_ptr; johnc@1325: bool defer = false; johnc@2060: johnc@2060: // This gets set to true if the card being refined has references johnc@2060: // that point into the collection set. johnc@2060: bool oops_into_cset = false; johnc@2060: ysr@777: if (_cg1r->use_cache()) { johnc@1325: jbyte* res = _cg1r->cache_insert(card_ptr, &defer); johnc@1325: if (res != NULL && (res != card_ptr || defer)) { johnc@1325: start = _ct_bs->addr_for(res); johnc@1325: r = _g1->heap_region_containing(start); johnc@1325: if (r == NULL) { johnc@1325: assert(_g1->is_in_permanent(start), "Or else where?"); johnc@1325: } else { johnc@2021: // Checking whether the region we got back from the cache johnc@2021: // is young here is inappropriate. The region could have been johnc@2021: // freed, reallocated and tagged as young while in the cache. johnc@2021: // Hence we could see its young type change at any time. johnc@2021: // johnc@2021: // Process card pointer we get back from the hot card cache. This johnc@2021: // will check whether the region containing the card is young johnc@2021: // _after_ checking that the region has been allocated from. johnc@2060: oops_into_cset = concurrentRefineOneCard_impl(res, worker_i, johnc@2060: false /* check_for_refs_into_cset */); johnc@2060: // The above call to concurrentRefineOneCard_impl is only johnc@2060: // performed if the hot card cache is enabled. This cache is johnc@2060: // disabled during an evacuation pause - which is the only johnc@2060: // time when we need know if the card contains references johnc@2060: // that point into the collection set. Also when the hot card johnc@2060: // cache is enabled, this code is executed by the concurrent johnc@2060: // refine threads - rather than the GC worker threads - and johnc@2060: // concurrentRefineOneCard_impl will return false. johnc@2060: assert(!oops_into_cset, "should not see true here"); johnc@1325: } ysr@777: } ysr@777: } ysr@777: johnc@1325: if (!defer) { johnc@2060: oops_into_cset = johnc@2060: concurrentRefineOneCard_impl(card_ptr, worker_i, check_for_refs_into_cset); johnc@2060: // We should only be detecting that the card contains references johnc@2060: // that point into the collection set if the current thread is johnc@2060: // a GC worker thread. johnc@2060: assert(!oops_into_cset || SafepointSynchronize::is_at_safepoint(), johnc@2060: "invalid result at non safepoint"); ysr@777: } johnc@2060: return oops_into_cset; ysr@777: } ysr@777: ysr@777: class HRRSStatsIter: public HeapRegionClosure { ysr@777: size_t _occupied; ysr@777: size_t _total_mem_sz; ysr@777: size_t _max_mem_sz; ysr@777: HeapRegion* _max_mem_sz_region; ysr@777: public: ysr@777: HRRSStatsIter() : ysr@777: _occupied(0), ysr@777: _total_mem_sz(0), ysr@777: _max_mem_sz(0), ysr@777: _max_mem_sz_region(NULL) ysr@777: {} ysr@777: ysr@777: bool doHeapRegion(HeapRegion* r) { ysr@777: if (r->continuesHumongous()) return false; ysr@777: size_t mem_sz = r->rem_set()->mem_size(); ysr@777: if (mem_sz > _max_mem_sz) { ysr@777: _max_mem_sz = mem_sz; ysr@777: _max_mem_sz_region = r; ysr@777: } ysr@777: _total_mem_sz += mem_sz; ysr@777: size_t occ = r->rem_set()->occupied(); ysr@777: _occupied += occ; ysr@777: return false; ysr@777: } ysr@777: size_t total_mem_sz() { return _total_mem_sz; } ysr@777: size_t max_mem_sz() { return _max_mem_sz; } ysr@777: size_t occupied() { return _occupied; } ysr@777: HeapRegion* max_mem_sz_region() { return _max_mem_sz_region; } ysr@777: }; ysr@777: iveresov@1229: class PrintRSThreadVTimeClosure : public ThreadClosure { iveresov@1229: public: iveresov@1229: virtual void do_thread(Thread *t) { iveresov@1229: ConcurrentG1RefineThread* crt = (ConcurrentG1RefineThread*) t; iveresov@1229: gclog_or_tty->print(" %5.2f", crt->vtime_accum()); iveresov@1229: } iveresov@1229: }; iveresov@1229: ysr@777: void HRInto_G1RemSet::print_summary_info() { ysr@777: G1CollectedHeap* g1 = G1CollectedHeap::heap(); ysr@777: ysr@777: #if CARD_REPEAT_HISTO ysr@777: gclog_or_tty->print_cr("\nG1 card_repeat count histogram: "); ysr@777: gclog_or_tty->print_cr(" # of repeats --> # of cards with that number."); ysr@777: card_repeat_count.print_on(gclog_or_tty); ysr@777: #endif ysr@777: ysr@777: if (FILTEROUTOFREGIONCLOSURE_DOHISTOGRAMCOUNT) { ysr@777: gclog_or_tty->print_cr("\nG1 rem-set out-of-region histogram: "); ysr@777: gclog_or_tty->print_cr(" # of CS ptrs --> # of cards with that number."); ysr@777: out_of_histo.print_on(gclog_or_tty); ysr@777: } iveresov@1229: gclog_or_tty->print_cr("\n Concurrent RS processed %d cards", iveresov@1229: _conc_refine_cards); ysr@777: DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); ysr@777: jint tot_processed_buffers = ysr@777: dcqs.processed_buffers_mut() + dcqs.processed_buffers_rs_thread(); ysr@777: gclog_or_tty->print_cr(" Of %d completed buffers:", tot_processed_buffers); iveresov@1229: gclog_or_tty->print_cr(" %8d (%5.1f%%) by conc RS threads.", ysr@777: dcqs.processed_buffers_rs_thread(), ysr@777: 100.0*(float)dcqs.processed_buffers_rs_thread()/ ysr@777: (float)tot_processed_buffers); ysr@777: gclog_or_tty->print_cr(" %8d (%5.1f%%) by mutator threads.", ysr@777: dcqs.processed_buffers_mut(), ysr@777: 100.0*(float)dcqs.processed_buffers_mut()/ ysr@777: (float)tot_processed_buffers); iveresov@1229: gclog_or_tty->print_cr(" Conc RS threads times(s)"); iveresov@1229: PrintRSThreadVTimeClosure p; iveresov@1229: gclog_or_tty->print(" "); iveresov@1229: g1->concurrent_g1_refine()->threads_do(&p); ysr@777: gclog_or_tty->print_cr(""); iveresov@1229: ysr@777: if (G1UseHRIntoRS) { ysr@777: HRRSStatsIter blk; ysr@777: g1->heap_region_iterate(&blk); ysr@777: gclog_or_tty->print_cr(" Total heap region rem set sizes = " SIZE_FORMAT "K." ysr@777: " Max = " SIZE_FORMAT "K.", ysr@777: blk.total_mem_sz()/K, blk.max_mem_sz()/K); ysr@777: gclog_or_tty->print_cr(" Static structures = " SIZE_FORMAT "K," ysr@777: " free_lists = " SIZE_FORMAT "K.", ysr@777: HeapRegionRemSet::static_mem_size()/K, ysr@777: HeapRegionRemSet::fl_mem_size()/K); ysr@777: gclog_or_tty->print_cr(" %d occupied cards represented.", ysr@777: blk.occupied()); ysr@777: gclog_or_tty->print_cr(" Max sz region = [" PTR_FORMAT ", " PTR_FORMAT " )" apetrusenko@1112: ", cap = " SIZE_FORMAT "K, occ = " SIZE_FORMAT "K.", ysr@777: blk.max_mem_sz_region()->bottom(), blk.max_mem_sz_region()->end(), ysr@777: (blk.max_mem_sz_region()->rem_set()->mem_size() + K - 1)/K, ysr@777: (blk.max_mem_sz_region()->rem_set()->occupied() + K - 1)/K); ysr@777: gclog_or_tty->print_cr(" Did %d coarsenings.", ysr@777: HeapRegionRemSet::n_coarsenings()); ysr@777: ysr@777: } ysr@777: } johnc@2060: ysr@777: void HRInto_G1RemSet::prepare_for_verify() { iveresov@1072: if (G1HRRSFlushLogBuffersOnVerify && iveresov@1072: (VerifyBeforeGC || VerifyAfterGC) iveresov@1072: && !_g1->full_collection()) { ysr@777: cleanupHRRS(); ysr@777: _g1->set_refine_cte_cl_concurrency(false); ysr@777: if (SafepointSynchronize::is_at_safepoint()) { ysr@777: DirtyCardQueueSet& dcqs = JavaThread::dirty_card_queue_set(); ysr@777: dcqs.concatenate_logs(); ysr@777: } ysr@777: bool cg1r_use_cache = _cg1r->use_cache(); ysr@777: _cg1r->set_use_cache(false); johnc@2060: DirtyCardQueue into_cset_dcq(&_g1->into_cset_dirty_card_queue_set()); johnc@2060: updateRS(&into_cset_dcq, 0); johnc@2060: _g1->into_cset_dirty_card_queue_set().clear(); ysr@777: _cg1r->set_use_cache(cg1r_use_cache); iveresov@1072: iveresov@1072: assert(JavaThread::dirty_card_queue_set().completed_buffers_num() == 0, "All should be consumed"); ysr@777: } ysr@777: }