/*
* 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 "memory/allocation.inline.hpp"
#include "memory/cardTableModRefBS.hpp"
#include "memory/cardTableRS.hpp"
#include "memory/sharedHeap.hpp"
#include "memory/space.inline.hpp"
#include "memory/universe.hpp"
#include "oops/oop.inline.hpp"
#include "runtime/mutexLocker.hpp"
#include "runtime/virtualspace.hpp"
#include "runtime/vmThread.hpp"
int n_threads) {
n_threads <= (int)ParallelGCThreads,
"# worker threads != # requested!");
n_threads == (int)ParallelGCThreads,
"# worker threads != # requested!");
// Make sure the LNC array is valid for the space.
// Sets the condition for completion of the subtask (how many threads
// need to finish in order to be done).
}
if (pst->all_tasks_completed()) {
// Clear lowest_non_clean array for next time.
"Bounds error");
}
}
}
void
// We go from higher to lower addresses here; it wouldn't help that much
// because of the strided parallelism pattern used here.
// Find the first card address of the first chunk in the stride that is
// at least "bottom" of the used region.
(stride - start_chunk_stride_num) *
} else {
// Go ahead to the next chunk group boundary, then to the requested stride.
}
while (chunk_card_start < end_card) {
// Even though we go from lower to higher addresses below, the
// strided parallelism can interleave the actual processing of the
// dirty pages in various ways. For a specific chunk within this
// stride, we take care to avoid double scanning or missing a card
// by suitably initializing the "min_done" field in process_chunk_boundaries()
// below, together with the dirty region extension accomplished in
// DirtyCardToOopClosure::do_MemRegion().
// Invariant: chunk_mr should be fully contained within the "used" region.
chunk_card_end >= end_card ?
cl->gen_boundary());
// Process the chunk.
used,
// We want the LNC array updates above in process_chunk_boundaries
// to be visible before any of the card table value changes as a
// result of the dirty card iteration below.
// We do not call the non_clean_card_iterate_serial() version because
// we want to clear the cards: clear_cl here does the work of finding
// contiguous dirty ranges of cards to process and clear.
// Find the next chunk of the stride.
}
}
// If you want a talkative process_chunk_boundaries,
// then #define NOISY(x) x
#ifdef NOISY
#error "Encountered a global preprocessor flag, NOISY, which might clash with local definition to follow"
#else
#define NOISY(x)
#endif
void
{
// We must worry about non-array objects that cross chunk boundaries,
// because such objects are both precisely and imprecisely marked:
// .. if the head of such an object is dirty, the entire object
// needs to be scanned, under the interpretation that this
// was an imprecise mark
// .. if the head of such an object is not dirty, we can assume
// precise marking and it's efficient to scan just the dirty
// cards.
// In either case, each scanned reference must be scanned precisely
// once so as to avoid cloning of a young referent. For efficiency,
// our closures depend on this property and do not protect against
// double scans.
NOISY(tty->print_cr("===========================================================================");)
// First, set "our" lowest_non_clean entry, which would be
// used by the thread scanning an adjoining left chunk with
// a non-array object straddling the mutual boundary.
// Find the object that spans our boundary, if one exists.
// first_block is the block possibly straddling our left boundary.
"First chunk should always have a co-initial block");
// Does the block straddle the chunk's left boundary, and is it
// a non-array object?
// Find our least non-clean card, so that a left neighbour
// does not scan an object straddling the mutual boundary
// too far to the right, and attempt to scan a portion of
// that object twice.
// Note that this does not need to go beyond our last card
// if our first object completely straddles this chunk.
if (card_will_be_scanned(val)) {
first_dirty_card = cur; break;
} else {
}
}
if (first_dirty_card != NULL) {
"Bounds error.");
"Write exactly once : value should be stable hereafter for this round");
} NOISY(else {
// In the future, we could have this thread look for a non-NULL value to copy from its
// right neighbour (up to the end of the first object).
" might be efficient to get value from right neighbour?");
}
})
} else {
// In this case we can help our neighbour by just asking them
// to stop at our first card (even though it may not be dirty).
NOISY(tty->print_cr(" LNC: first block is not a non-array object; setting LNC to first card of current chunk");)
}
" which corresponds to the heap address " PTR_FORMAT,
: NULL);)
NOISY(tty->print_cr("---------------------------------------------------------------------------");)
// Next, set our own max_to_do, which will strictly/exclusively bound
// the highest address that we will scan past the right end of our chunk.
// This is not the last chunk in the used region.
// What is our last block? We check the first block of
// the next (right) chunk rather than strictly check our last block
// because it's potentially more efficient to do so.
} else {
// It is a non-array object that straddles the right boundary of this chunk.
// last_obj_card is the card corresponding to the start of the last object
// in the chunk. Note that the last object may not start in
// the chunk.
if (!card_will_be_scanned(val)) {
// The card containing the head is not dirty. Any marks on
// subsequent cards still in this chunk must have been made
// precisely; we can cap processing at the end of our chunk.
" max_to_do left at " PTR_FORMAT,
max_to_do);)
} else {
// The last object must be considered dirty, and extends onto the
// following chunk. Look for a dirty card in that chunk that will
// bound our processing.
// This search potentially goes a long distance looking
// for the next card that will be scanned, terminating
// at the end of the last_block, if no earlier dirty card
// is found.
"last card of next chunk may be wrong");
if (card_will_be_scanned(val)) {
limit_card = cur; break;
} else {
}
}
if (limit_card != NULL) {
} else {
// The following is a pessimistic value, because it's possible
// that a dirty card on a subsequent chunk has been cleared by
// the time we get to look at it; we'll correct for that further below,
// using the LNC array which records the least non-clean card
// before cards were cleared in a particular chunk.
NOISY(tty->print_cr(" process_chunk_boundary: Found no dirty card before end of last block in chunk\n"
" Setting limit_card to " PTR_FORMAT
}
"Bounds error.");
// It is possible that a dirty card for the last object may have been
// cleared before we had a chance to examine it. In that case, the value
// will have been logged in the LNC for that chunk.
// We need to examine as many chunks to the right as this object
// covers. However, we need to bound this checking to the largest
// entry in the LNC array: this is because the heap may expand
// after the LNC array has been created but before we reach this point,
// and the last block in our chunk may have been expanded to include
// the expansion delta (and possibly subsequently allocated from, so
// it wouldn't be sufficient to check whether that last block was
// or was not an object at this point).
" yet last_chunk_index_to_check " INTPTR_FORMAT
" exceeds last_chunk_index " INTPTR_FORMAT,
err_msg("Expansion did not happen: "
}
lnc_index++) {
// we can stop at the first non-NULL entry we find
if (lnc_card <= limit_card) {
NOISY(tty->print_cr(" process_chunk_boundary: LNC card " PTR_FORMAT " is lower than limit_card " PTR_FORMAT,
}
// In any case, we break now
break;
} // else continue to look for a non-NULL entry if any
}
}
}
} else {
" max_to_do left at " PTR_FORMAT,
max_to_do);)
}
// Now we can set the closure we're using so it doesn't to beyond
// max_to_do.
#ifndef PRODUCT
#endif
NOISY(tty->print_cr("===========================================================================\n");)
}
void
// Only the first thread to obtain the lock will resize the
// LNC array for the covered region. Any later expansion can't affect
// the used_at_save_marks region.
// (I observed a bug in which the first thread to execute this would
// resize, and then it would cause "expand_and_allocate" that would
// increase the number of chunks in the covered region. Then a second
// thread would come and execute this, see that the size didn't match,
// and free and allocate again. So the first thread would be using a
// freed "_lowest_non_clean" array.)
// Do a dirty read here. If we pass the conditional then take the rare
// event lock and do the read again in case some other thread had already
// succeeded and done the resize.
if (_last_LNC_resizing_collection[i] != cur_collection) {
if (_last_LNC_resizing_collection[i] != cur_collection) {
if (_lowest_non_clean[i] == NULL ||
n_chunks != _lowest_non_clean_chunk_size[i]) {
// Should we delete the old?
if (_lowest_non_clean[i] != NULL) {
"logical consequence");
_lowest_non_clean[i] = NULL;
}
// Now allocate a new one if necessary.
if (_lowest_non_clean[i] == NULL) {
for (int j = 0; j < (int)n_chunks; j++)
_lowest_non_clean[i][j] = NULL;
}
}
}
}
// In any case, now do the initialization.
}