4539N/A * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. 342N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 342N/A * This code is free software; you can redistribute it and/or modify it 342N/A * under the terms of the GNU General Public License version 2 only, as 342N/A * published by the Free Software Foundation. 342N/A * This code is distributed in the hope that it will be useful, but WITHOUT 342N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 342N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 342N/A * version 2 for more details (a copy is included in the LICENSE file that 342N/A * accompanied this code). 342N/A * You should have received a copy of the GNU General Public License version 342N/A * 2 along with this work; if not, write to the Free Software Foundation, 342N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2861N/A // Stack allocate the DirtyCardToOopClosure instance 342N/A // Set the "from" region in the closure. 2414N/A // We make the card as "claimed" lazily (so races are possible 2414N/A // but they're benign), which reduces the number of duplicate 2414N/A // scans (the rsets of the regions in the cset can intersect). 2414N/A // If we ever free the collection set concurrently, we should also 2414N/A // clear the card table concurrently therefore we won't need to 2414N/A // add regions of the collection set to the dirty cards region. 342N/A // If we didn't return above, then 342N/A // _try_claimed || r->claim_iter() 342N/A // is true: either we're supposed to work on claimed-but-not-complete 342N/A // regions, or we successfully claimed the region. 1261N/A // We claim cards in block so as to recude the contention. The block size is determined by 1261N/A // the G1RSetScanBlockSize parameter. 2414N/A // If the card is dirty, then we will scan it during updateRS. 1625N/A// Closure used for updating RSets and recording references that 1625N/A// point into the collection set. Only called during an 1625N/A // The only time we care about recording cards that 1625N/A // contain references that point into the collection set 1625N/A // is during RSet updating within an evacuation pause. 1625N/A // In this case worker_i should be the id of a GC worker thread. 1625N/A // 'card_ptr' contains references that point into the collection 1625N/A // set. We need to record the card in the DCQS 1625N/A // (G1CollectedHeap::into_cset_dirty_card_queue_set()) 1625N/A // that's used for that purpose. 1625N/A // Apply the given closure to all remaining log entries. 794N/A // Now there should be no dirty cards. 794N/A // XXX This isn't true any more: keeping cards of young regions 794N/A // marked dirty broke it. Need some reasonable fix. 1625N/A // We cache the value of 'oc' closure into the appropriate slot in the 1625N/A // _cset_rs_update_cl for this worker 1625N/A // A DirtyCardQueue that is used to hold cards containing references 1625N/A // that point into the collection set. This DCQ is associated with a 1625N/A // circumstances (i.e. the pause successfully completes), these cards 1625N/A // are just discarded (there's no need to update the RSets of regions 1625N/A // that were in the collection set - after the pause these regions 1625N/A // are wholly 'free' of live objects. In the event of an evacuation 1625N/A // * passed to the DirtyCardQueueSet that is used to manage deferred 1625N/A // * scanned for references that point into the collection set 1625N/A // and the RSet of the corresponding region in the collection set 1628N/A // The two flags below were introduced temporarily to serialize 1628N/A // the updating and scanning of remembered sets. There are some 1628N/A // race conditions when these two operations are done in parallel 1628N/A // and they are causing failures. When we resolve said race 1628N/A // conditions, we'll revert back to parallel remembered set 1628N/A // updating and scanning. See CRs 6677707 and 6677708. 1625N/A // We now clear the cached values of _cset_rs_update_cl for this worker 2941N/A // Don't set the number of workers here. It will be set 2941N/A // _seq_task->set_n_termination((int)n_workers()); 1625N/A// This closure, applied to a DirtyCardQueueSet, is used to immediately 1625N/A// update the RSets for the regions in the CSet. For each card it iterates 1625N/A// through the oops which coincide with that card. It scans the reference 1625N/A// fields in each oop; when it finds an oop that points into the collection 1625N/A// set, the RSet for the region containing the referenced object is updated. 1625N/A // Construct the region representing the card. 1625N/A // And find the region containing it. 1625N/A // Scan oops in the card looking for references into the collection set 4539N/A // Don't use addr_for(card_ptr + 1) which can ask for 4539N/A // a card beyond the heap. This is not safe without a perm 1625N/A // We can pass false as the "filter_young" parameter here as: 1625N/A // * we should be in a STW pause, 1625N/A // * the DCQS to which this closure is applied is used to hold 1625N/A // references that point into the collection set from the prior 1625N/A // * the post-write barrier shouldn't be logging updates to young 1625N/A // regions (but there is a situation where this can happen - see 4539N/A // the comment in G1RemSet::refine_card() below - 1625N/A // that should not be applicable here), and 1625N/A // * during actual RSet updating, the filtering of cards in young 1625N/A // regions in HeapRegion::oops_on_card_seq_iterate_careful is 1625N/A // As a result, when this closure is applied to "refs into cset" 1625N/A // DCQS, we shouldn't see any cards in young regions. 1625N/A // Since this is performed in the event of an evacuation failure, we 1625N/A // we shouldn't see a non-null stop point 342N/A // Set all cards back to clean. 1625N/A // Restore remembered sets for the regions pointing into the collection set. 1625N/A // If deferred RS updates are enabled then we just need to transfer 1625N/A // the completed buffers from (a) the DirtyCardQueueSet used to hold 1625N/A // cards that contain references that point into the collection set 1625N/A // to (b) the DCQS used to hold the deferred RS updates 1625N/A // Free any completed buffers in the DirtyCardQueueSet used to hold cards 1625N/A // which contain references that point into the collection. 1625N/A "all buffers should be freed");
4539N/A// Returns true if the given card contains references that point 4539N/A// into the collection set, if we're checking for such references; 4539N/A // If the card is no longer dirty, nothing to do. 4539N/A // No need to return that this card contains refs that point 4539N/A // into the collection set. 890N/A // Construct the region representing the card. 890N/A // And find the region containing it. 4539N/A // Again no need to return that this card contains refs that 4539N/A // point into the collection set. 4539N/A return false;
// Not in the G1 heap (might be in perm, for example.) 4539N/A // Why do we have to check here whether a card is on a young region, 4539N/A // given that we dirty young regions and, as a result, the 4539N/A // post-barrier is supposed to filter them out and never to enqueue 4539N/A // them? When we allocate a new region as the "allocation region" we 4539N/A // actually dirty its cards after we release the lock, since card 4539N/A // dirtying while holding the lock was a performance bottleneck. So, 4539N/A // as a result, it is possible for other threads to actually 4539N/A // allocate objects in the region (after the acquire the lock) 4539N/A // before all the cards on the region are dirtied. This is unlikely, 4539N/A // and it doesn't happen often, but it can happen. So, the extra 4539N/A // check below filters out those cards. 4539N/A // While we are processing RSet buffers during the collection, we 4539N/A // actually don't want to scan any cards on the collection set, 4539N/A // since we don't want to update remebered sets with entries that 4539N/A // point into the collection set, given that live objects from the 4539N/A // collection set are about to move and such entries will be stale 4539N/A // very soon. This change also deals with a reliability issue which 4539N/A // involves scanning a card in the collection set and coming across 4539N/A // an array that was being chunked and looking malformed. Note, 4539N/A // however, that if evacuation fails, we have to scan any objects 4539N/A // that were not moved and create any missing entries. 4539N/A // The result from the hot card cache insert call is either: 4539N/A // * pointer to the current card 4539N/A // (implying that the current card is not 'hot'), 4539N/A // (meaning we had inserted the card ptr into the "hot" card cache, 4539N/A // which had some headroom), 4539N/A // * a pointer to a "hot" card that was evicted from the "hot" cache. 4539N/A // There was no eviction. Nothing to do. 4539N/A // Checking whether the region we got back from the cache 4539N/A // is young here is inappropriate. The region could have been 4539N/A // freed, reallocated and tagged as young while in the cache. 4539N/A // Hence we could see its young type change at any time. 4539N/A // Don't use addr_for(card_ptr + 1) which can ask for 4539N/A // a card beyond the heap. This is not safe without a perm 4539N/A // gen at the upper end of the heap. 2909N/A // ConcurrentG1RefineThreads have worker numbers larger than what 2909N/A // _cset_rs_update_cl[] is set up to handle. But those threads should 2909N/A // only be active outside of a collection which means that when they 2909N/A // reach here they should have check_for_refs_into_cset == false. 1586N/A // The region for the current card may be a young region. The 1586N/A // current card may have been a card that was evicted from the 1586N/A // card cache. When the card was inserted into the cache, we had 1586N/A // determined that its region was non-young. While in the cache, 1586N/A // the region may have been freed during a cleanup pause, reallocated 1586N/A // We wish to filter out cards for such a region but the current 2414N/A // thread, if we're running concurrently, may "see" the young type 1586N/A // change at any time (so an earlier "is_young" check may pass or 1586N/A // fail arbitrarily). We tell the iteration code to perform this 1586N/A // filtering when it has been determined that there has been an actual 1586N/A // allocation in this region and making it safe to check the young type. 890N/A // If stop_point is non-null, then we encountered an unallocated region 890N/A // (perhaps the unfilled portion of a TLAB.) For now, we'll dirty the 890N/A // card and re-enqueue: if we put off the card until a GC pause, then the 890N/A // unallocated portion will be filled in. Alternatively, we might try 890N/A // the full complexity of the technique used in "regular" precleaning. 890N/A // The card might have gotten re-dirtied and re-enqueued while we 890N/A // worked. (In fact, it's pretty likely.) 4539N/A // This gets set to true if the card being refined has 4539N/A // references that point into the collection set. 4539N/A // We should only be detecting that the card contains references 4539N/A // that point into the collection set if the current thread is 4539N/A "invalid result at non safepoint");