g1RemSet.cpp revision 2815
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
#include "precompiled.hpp"
#include "gc_implementation/g1/bufferingOopClosure.hpp"
#include "gc_implementation/g1/concurrentG1Refine.hpp"
#include "gc_implementation/g1/concurrentG1RefineThread.hpp"
#include "gc_implementation/g1/g1BlockOffsetTable.inline.hpp"
#include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
#include "gc_implementation/g1/g1CollectorPolicy.hpp"
#include "gc_implementation/g1/g1OopClosures.inline.hpp"
#include "gc_implementation/g1/g1RemSet.inline.hpp"
#include "gc_implementation/g1/heapRegionSeq.inline.hpp"
#include "memory/iterator.hpp"
#include "oops/oop.inline.hpp"
#include "utilities/intHisto.hpp"
#define CARD_REPEAT_HISTO 0
static size_t ct_freq_sz;
}
}
}
void ct_freq_update_histo_and_reset() {
for (size_t j = 0; j < ct_freq_sz; j++) {
ct_freq[j] = 0;
}
}
#endif
{
_cset_rs_update_cl[i] = NULL;
}
}
delete _seq_task;
}
}
}
}
class ScanRSClosure : public HeapRegionClosure {
int _worker_i;
int _block_size;
bool _try_claimed;
public:
_cards(0),
_cards_done(0),
_try_claimed(false)
{
}
void set_try_claimed() { _try_claimed = true; }
r->new_dcto_closure(_oc,
// Set the "from" region in the closure.
_oc->set_region(r);
// We make the card as "claimed" lazily (so races are possible
// but they're benign), which reduces the number of duplicate
// scans (the rsets of the regions in the cset can intersect).
_cards_done++;
}
}
HeapWord* card_start) {
"RS names card %p: "
}
bool doHeapRegion(HeapRegion* r) {
// If we ever free the collection set concurrently, we should also
// clear the card table concurrently therefore we won't need to
// add regions of the collection set to the dirty cards region.
// If we didn't return above, then
// _try_claimed || r->claim_iter()
// is true: either we're supposed to work on claimed-but-not-complete
// regions, or we successfully claimed the region.
// We claim cards in block so as to recude the contention. The block size is determined by
// the G1RSetScanBlockSize parameter.
}
if (current_card < jump_to_card) continue;
#if 0
#endif
_cards++;
if (!card_region->is_on_dirty_cards_region_list()) {
}
// If the card is dirty, then we will scan it during updateRS.
if (!card_region->in_collection_set() &&
}
}
if (!_try_claimed) {
}
return false;
}
};
// We want the parallel threads to start their scanning at
// different collection set regions to avoid contention.
// If we have:
// n collection set regions
// p threads
// Then thread t will start at region t * floor (n/p)
if (ParallelGCThreads > 0) {
}
return result;
}
}
// Closure used for updating RSets and recording references that
// point into the collection set. Only called during an
// evacuation pause.
class RefineRecordRefsIntoCSCardTableEntryClosure: public CardTableEntryClosure {
public:
{}
// The only time we care about recording cards that
// contain references that point into the collection set
// is during RSet updating within an evacuation pause.
// In this case worker_i should be the id of a GC worker thread.
// 'card_ptr' contains references that point into the collection
// set. We need to record the card in the DCQS
// (G1CollectedHeap::into_cset_dirty_card_queue_set())
// that's used for that purpose.
//
// Enqueue the card
}
return true;
}
};
// Apply the given closure to all remaining log entries.
// Now there should be no dirty cards.
if (G1RSLogCheckCardTable) {
// XXX This isn't true any more: keeping cards of young regions
// marked dirty broke it. Need some reasonable fix.
}
}
class CountRSSizeClosure: public HeapRegionClosure {
enum {
N = 20,
MIN = 6
};
int _histo[N];
public:
for (int i = 0; i < N; i++) _histo[i] = 0;
}
bool doHeapRegion(HeapRegion* r) {
if (!r->continuesHumongous()) {
_n++;
_max_r = r;
}
// Fit it into a histo bin.
int s = 1 << MIN;
int i = 0;
s = s << 1;
i++;
}
_histo[i]++;
}
return false;
}
void print_histo() {
int mx = N;
while (mx >= 0) {
mx--;
}
1 << (MIN + i),
_histo[i]);
}
}
};
void G1RemSet::cleanupHRRS() {
}
int worker_i) {
#endif
if (worker_i == 0) {
}
// Make this into a command-line flag...
"max region is " PTR_FORMAT,
}
// We cache the value of 'oc' closure into the appropriate slot in the
// _cset_rs_update_cl for this worker
// A DirtyCardQueue that is used to hold cards containing references
// that point into the collection set. This DCQ is associated with a
// special DirtyCardQueueSet (see g1CollectedHeap.hpp). Under normal
// circumstances (i.e. the pause successfully completes), these cards
// are just discarded (there's no need to update the RSets of regions
// that were in the collection set - after the pause these regions
// are wholly 'free' of live objects. In the event of an evacuation
// * passed to the DirtyCardQueueSet that is used to manage deferred
// RSet updates, or
// * scanned for references that point into the collection set
// and the RSet of the corresponding region in the collection set
// is updated immediately.
// The two flags below were introduced temporarily to serialize
// the updating and scanning of remembered sets. There are some
// race conditions when these two operations are done in parallel
// and they are causing failures. When we resolve said race
// conditions, we'll revert back to parallel remembered set
// updating and scanning. See CRs 6677707 and 6677708.
if (G1UseParallelRSetUpdating || (worker_i == 0)) {
} else {
}
if (G1UseParallelRSetScanning || (worker_i == 0)) {
} else {
}
// We now clear the cached values of _cset_rs_update_cl for this worker
}
cleanupHRRS();
_g1->set_refine_cte_cl_concurrency(false);
if (ParallelGCThreads > 0) {
}
_cards_scanned[i] = 0;
}
_total_cards_scanned = 0;
}
// This closure, applied to a DirtyCardQueueSet, is used to immediately
// update the RSets for the regions in the CSet. For each card it iterates
// through the oops which coincide with that card. It scans the reference
// fields in each oop; when it finds an oop that points into the collection
// set, the RSet for the region containing the referenced object is updated.
class UpdateRSetCardTableEntryIntoCSetClosure: public CardTableEntryClosure {
public:
{ }
// Construct the region representing the card.
// And find the region containing it.
// Scan oops in the card looking for references into the collection set
// We can pass false as the "filter_young" parameter here as:
// * we should be in a STW pause,
// * the DCQS to which this closure is applied is used to hold
// references that point into the collection set from the prior
// RSet updating,
// * the post-write barrier shouldn't be logging updates to young
// regions (but there is a situation where this can happen - see
// the comment in G1RemSet::concurrentRefineOneCard below -
// that should not be applicable here), and
// * during actual RSet updating, the filtering of cards in young
// regions in HeapRegion::oops_on_card_seq_iterate_careful is
// employed.
// As a result, when this closure is applied to "refs into cset"
// DCQS, we shouldn't see any cards in young regions.
false /* filter_young */,
NULL /* card_ptr */);
// Since this is performed in the event of an evacuation failure, we
// we shouldn't see a non-null stop point
return true;
}
};
_total_cards_scanned = 0;
}
// Cleanup after copy
_g1->set_refine_cte_cl_concurrency(true);
// Set all cards back to clean.
_g1->cleanUpCardTable();
if (_g1->evacuation_failed()) {
// Restore remembered sets for the regions pointing into the collection set.
if (G1DeferredRSUpdate) {
// If deferred RS updates are enabled then we just need to transfer
// the completed buffers from (a) the DirtyCardQueueSet used to hold
// cards that contain references that point into the collection set
// to (b) the DCQS used to hold the deferred RS updates
} else {
int n_completed_buffers = 0;
0, 0, true)) {
}
}
}
// Free any completed buffers in the DirtyCardQueueSet used to hold cards
// which contain references that point into the collection.
"all buffers should be freed");
}
class ScrubRSClosure: public HeapRegionClosure {
public:
{
}
bool doHeapRegion(HeapRegion* r) {
if (!r->continuesHumongous()) {
}
return false;
}
};
}
int worker_num, int claim_val) {
}
class TriggerClosure : public OopClosure {
bool _trigger;
public:
TriggerClosure() : _trigger(false) { }
};
class InvokeIfNotTriggeredClosure: public OopClosure {
public:
template <class T> void do_oop_nv(T* p) {
}
};
class Mux2Closure : public OopClosure {
public:
template <class T> void do_oop_nv(T* p) {
}
};
bool check_for_refs_into_cset) {
// Construct the region representing the card.
// And find the region containing it.
#endif
_g1->g1_rem_set(),
worker_i);
(OopClosure*)&mux :
(OopClosure*)&update_rs_oop_cl));
// The region for the current card may be a young region. The
// current card may have been a card that was evicted from the
// card cache. When the card was inserted into the cache, we had
// determined that its region was non-young. While in the cache,
// the region may have been freed during a cleanup pause, reallocated
// and tagged as young.
//
// We wish to filter out cards for such a region but the current
// thread, if we're running concurrently, may "see" the young type
// change at any time (so an earlier "is_young" check may pass or
// fail arbitrarily). We tell the iteration code to perform this
// filtering when it has been determined that there has been an actual
// allocation in this region and making it safe to check the young type.
bool filter_young = true;
card_ptr);
// If stop_point is non-null, then we encountered an unallocated region
// (perhaps the unfilled portion of a TLAB.) For now, we'll dirty the
// card and re-enqueue: if we put off the card until a GC pause, then the
// unallocated portion will be filled in. Alternatively, we might try
// the full complexity of the technique used in "regular" precleaning.
if (stop_point != NULL) {
// The card might have gotten re-dirtied and re-enqueued while we
// worked. (In fact, it's pretty likely.)
}
} else {
}
return trigger_cl.value();
}
bool check_for_refs_into_cset) {
// If the card is no longer dirty, nothing to do.
// No need to return that this card contains refs that point
// into the collection set.
return false;
}
// Construct the region representing the card.
// And find the region containing it.
if (r == NULL) {
// Again no need to return that this card contains refs that
// point into the collection set.
return false; // Not in the G1 heap (might be in perm, for example.)
}
// Why do we have to check here whether a card is on a young region,
// given that we dirty young regions and, as a result, the
// post-barrier is supposed to filter them out and never to enqueue
// them? When we allocate a new region as the "allocation region" we
// actually dirty its cards after we release the lock, since card
// dirtying while holding the lock was a performance bottleneck. So,
// as a result, it is possible for other threads to actually
// allocate objects in the region (after the acquire the lock)
// before all the cards on the region are dirtied. This is unlikely,
// and it doesn't happen often, but it can happen. So, the extra
// check below filters out those cards.
if (r->is_young()) {
return false;
}
// While we are processing RSet buffers during the collection, we
// actually don't want to scan any cards on the collection set,
// since we don't want to update remebered sets with entries that
// point into the collection set, given that live objects from the
// collection set are about to move and such entries will be stale
// very soon. This change also deals with a reliability issue which
// involves scanning a card in the collection set and coming across
// an array that was being chunked and looking malformed. Note,
// however, that if evacuation fails, we have to scan any objects
// that were not moved and create any missing entries.
if (r->in_collection_set()) {
return false;
}
// Should we defer processing the card?
//
// Previously the result from the insert_cache call would be
// either card_ptr (implying that card_ptr was currently "cold"),
// null (meaning we had inserted the card ptr into the "hot"
// cache, which had some headroom), or a "hot" card ptr
// extracted from the "hot" cache.
//
// Now that the _card_counts cache in the ConcurrentG1Refine
// instance is an evicting hash table, the result we get back
// could be from evicting the card ptr in an already occupied
// bucket (in which case we have replaced the card ptr in the
// bucket with card_ptr and "defer" is set to false). To avoid
// having a data structure (updates to which would need a lock)
// to hold these unprocessed dirty cards, we need to immediately
// process card_ptr. The actions needed to be taken on return
// from cache_insert are summarized in the following table:
//
// res defer action
// --------------------------------------------------------------
// null false card evicted from _card_counts & replaced with
// card_ptr; evicted ptr added to hot cache.
// No need to process res; immediately process card_ptr
//
// null true card not evicted from _card_counts; card_ptr added
// to hot cache.
// Nothing to do.
//
// non-null false card evicted from _card_counts & replaced with
// card_ptr; evicted ptr is currently "cold" or
// caused an eviction from the hot cache.
// Immediately process res; process card_ptr.
//
// non-null true card not evicted from _card_counts; card_ptr is
// currently cold, or caused an eviction from hot
// cache.
// Immediately process res; no need to process card_ptr.
bool defer = false;
// This gets set to true if the card being refined has references
// that point into the collection set.
bool oops_into_cset = false;
if (r == NULL) {
} else {
// Checking whether the region we got back from the cache
// is young here is inappropriate. The region could have been
// freed, reallocated and tagged as young while in the cache.
// Hence we could see its young type change at any time.
//
// Process card pointer we get back from the hot card cache. This
// will check whether the region containing the card is young
// _after_ checking that the region has been allocated from.
false /* check_for_refs_into_cset */);
// The above call to concurrentRefineOneCard_impl is only
// performed if the hot card cache is enabled. This cache is
// disabled during an evacuation pause - which is the only
// time when we need know if the card contains references
// that point into the collection set. Also when the hot card
// cache is enabled, this code is executed by the concurrent
// refine threads - rather than the GC worker threads - and
// concurrentRefineOneCard_impl will return false.
}
}
}
if (!defer) {
// We should only be detecting that the card contains references
// that point into the collection set if the current thread is
// a GC worker thread.
"invalid result at non safepoint");
}
return oops_into_cset;
}
class HRRSStatsIter: public HeapRegionClosure {
public:
HRRSStatsIter() :
_occupied(0),
_total_mem_sz(0),
_max_mem_sz(0),
{}
bool doHeapRegion(HeapRegion* r) {
if (r->continuesHumongous()) return false;
if (mem_sz > _max_mem_sz) {
_max_mem_sz_region = r;
}
_total_mem_sz += mem_sz;
return false;
}
};
class PrintRSThreadVTimeClosure : public ThreadClosure {
public:
}
};
void G1RemSet::print_summary_info() {
#endif
}
(float)tot_processed_buffers);
(float)tot_processed_buffers);
HeapRegionRemSet::fl_mem_size()/K);
}
void G1RemSet::prepare_for_verify() {
&& !_g1->full_collection()) {
cleanupHRRS();
_g1->set_refine_cte_cl_concurrency(false);
if (SafepointSynchronize::is_at_safepoint()) {
}
_cg1r->set_use_cache(false);
updateRS(&into_cset_dcq, 0);
}
}