0N/A/*
2685N/A * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "memory/allocation.inline.hpp"
1879N/A#include "memory/cardTableModRefBS.hpp"
1879N/A#include "memory/cardTableRS.hpp"
1879N/A#include "memory/sharedHeap.hpp"
1879N/A#include "memory/space.inline.hpp"
1879N/A#include "memory/universe.hpp"
2454N/A#include "oops/oop.inline.hpp"
1879N/A#include "runtime/java.hpp"
1879N/A#include "runtime/mutexLocker.hpp"
1879N/A#include "runtime/virtualspace.hpp"
2941N/A#include "runtime/vmThread.hpp"
0N/A
2384N/Avoid CardTableModRefBS::non_clean_card_iterate_parallel_work(Space* sp, MemRegion mr,
2454N/A OopsInGenClosure* cl,
2454N/A CardTableRS* ct,
2384N/A int n_threads) {
2384N/A assert(n_threads > 0, "Error: expected n_threads > 0");
2384N/A assert((n_threads == 1 && ParallelGCThreads == 0) ||
2384N/A n_threads <= (int)ParallelGCThreads,
2384N/A "# worker threads != # requested!");
2941N/A assert(!Thread::current()->is_VM_thread() || (n_threads == 1), "There is only 1 VM thread");
2941N/A assert(UseDynamicNumberOfGCThreads ||
2941N/A !FLAG_IS_DEFAULT(ParallelGCThreads) ||
2941N/A n_threads == (int)ParallelGCThreads,
2941N/A "# worker threads != # requested!");
2384N/A // Make sure the LNC array is valid for the space.
2384N/A jbyte** lowest_non_clean;
2384N/A uintptr_t lowest_non_clean_base_chunk_index;
2384N/A size_t lowest_non_clean_chunk_size;
2384N/A get_LNC_array_for_space(sp, lowest_non_clean,
2384N/A lowest_non_clean_base_chunk_index,
2384N/A lowest_non_clean_chunk_size);
0N/A
3008N/A uint n_strides = n_threads * ParGCStridesPerThread;
2384N/A SequentialSubTasksDone* pst = sp->par_seq_tasks();
2941N/A // Sets the condition for completion of the subtask (how many threads
2941N/A // need to finish in order to be done).
2384N/A pst->set_n_threads(n_threads);
2384N/A pst->set_n_tasks(n_strides);
0N/A
3008N/A uint stride = 0;
2384N/A while (!pst->is_task_claimed(/* reference */ stride)) {
2454N/A process_stride(sp, mr, stride, n_strides, cl, ct,
2384N/A lowest_non_clean,
2384N/A lowest_non_clean_base_chunk_index,
2384N/A lowest_non_clean_chunk_size);
2384N/A }
2384N/A if (pst->all_tasks_completed()) {
2384N/A // Clear lowest_non_clean array for next time.
2384N/A intptr_t first_chunk_index = addr_to_chunk_index(mr.start());
2384N/A uintptr_t last_chunk_index = addr_to_chunk_index(mr.last());
2384N/A for (uintptr_t ch = first_chunk_index; ch <= last_chunk_index; ch++) {
2384N/A intptr_t ind = ch - lowest_non_clean_base_chunk_index;
2384N/A assert(0 <= ind && ind < (intptr_t)lowest_non_clean_chunk_size,
2384N/A "Bounds error");
2384N/A lowest_non_clean[ind] = NULL;
0N/A }
0N/A }
0N/A}
0N/A
0N/Avoid
0N/ACardTableModRefBS::
0N/Aprocess_stride(Space* sp,
0N/A MemRegion used,
0N/A jint stride, int n_strides,
2454N/A OopsInGenClosure* cl,
2454N/A CardTableRS* ct,
0N/A jbyte** lowest_non_clean,
0N/A uintptr_t lowest_non_clean_base_chunk_index,
0N/A size_t lowest_non_clean_chunk_size) {
2454N/A // We go from higher to lower addresses here; it wouldn't help that much
2454N/A // because of the strided parallelism pattern used here.
0N/A
0N/A // Find the first card address of the first chunk in the stride that is
0N/A // at least "bottom" of the used region.
0N/A jbyte* start_card = byte_for(used.start());
0N/A jbyte* end_card = byte_after(used.last());
0N/A uintptr_t start_chunk = addr_to_chunk_index(used.start());
0N/A uintptr_t start_chunk_stride_num = start_chunk % n_strides;
0N/A jbyte* chunk_card_start;
0N/A
0N/A if ((uintptr_t)stride >= start_chunk_stride_num) {
0N/A chunk_card_start = (jbyte*)(start_card +
0N/A (stride - start_chunk_stride_num) *
2454N/A ParGCCardsPerStrideChunk);
0N/A } else {
0N/A // Go ahead to the next chunk group boundary, then to the requested stride.
0N/A chunk_card_start = (jbyte*)(start_card +
0N/A (n_strides - start_chunk_stride_num + stride) *
2454N/A ParGCCardsPerStrideChunk);
0N/A }
0N/A
0N/A while (chunk_card_start < end_card) {
2454N/A // Even though we go from lower to higher addresses below, the
2454N/A // strided parallelism can interleave the actual processing of the
2454N/A // dirty pages in various ways. For a specific chunk within this
2454N/A // stride, we take care to avoid double scanning or missing a card
2454N/A // by suitably initializing the "min_done" field in process_chunk_boundaries()
2454N/A // below, together with the dirty region extension accomplished in
2454N/A // DirtyCardToOopClosure::do_MemRegion().
2454N/A jbyte* chunk_card_end = chunk_card_start + ParGCCardsPerStrideChunk;
0N/A // Invariant: chunk_mr should be fully contained within the "used" region.
0N/A MemRegion chunk_mr = MemRegion(addr_for(chunk_card_start),
0N/A chunk_card_end >= end_card ?
0N/A used.end() : addr_for(chunk_card_end));
0N/A assert(chunk_mr.word_size() > 0, "[chunk_card_start > used_end)");
0N/A assert(used.contains(chunk_mr), "chunk_mr should be subset of used");
0N/A
2454N/A DirtyCardToOopClosure* dcto_cl = sp->new_dcto_cl(cl, precision(),
2454N/A cl->gen_boundary());
2454N/A ClearNoncleanCardWrapper clear_cl(dcto_cl, ct);
2454N/A
2454N/A
0N/A // Process the chunk.
0N/A process_chunk_boundaries(sp,
0N/A dcto_cl,
0N/A chunk_mr,
0N/A used,
0N/A lowest_non_clean,
0N/A lowest_non_clean_base_chunk_index,
0N/A lowest_non_clean_chunk_size);
0N/A
2454N/A // We want the LNC array updates above in process_chunk_boundaries
2454N/A // to be visible before any of the card table value changes as a
2454N/A // result of the dirty card iteration below.
2454N/A OrderAccess::storestore();
2454N/A
2384N/A // We do not call the non_clean_card_iterate_serial() version because
2454N/A // we want to clear the cards: clear_cl here does the work of finding
2454N/A // contiguous dirty ranges of cards to process and clear.
2454N/A clear_cl.do_MemRegion(chunk_mr);
0N/A
0N/A // Find the next chunk of the stride.
2454N/A chunk_card_start += ParGCCardsPerStrideChunk * n_strides;
0N/A }
0N/A}
0N/A
2454N/A
2454N/A// If you want a talkative process_chunk_boundaries,
2454N/A// then #define NOISY(x) x
2454N/A#ifdef NOISY
2454N/A#error "Encountered a global preprocessor flag, NOISY, which might clash with local definition to follow"
2454N/A#else
2454N/A#define NOISY(x)
2454N/A#endif
2454N/A
0N/Avoid
0N/ACardTableModRefBS::
0N/Aprocess_chunk_boundaries(Space* sp,
0N/A DirtyCardToOopClosure* dcto_cl,
0N/A MemRegion chunk_mr,
0N/A MemRegion used,
0N/A jbyte** lowest_non_clean,
0N/A uintptr_t lowest_non_clean_base_chunk_index,
0N/A size_t lowest_non_clean_chunk_size)
0N/A{
2454N/A // We must worry about non-array objects that cross chunk boundaries,
2454N/A // because such objects are both precisely and imprecisely marked:
2454N/A // .. if the head of such an object is dirty, the entire object
2454N/A // needs to be scanned, under the interpretation that this
2454N/A // was an imprecise mark
2454N/A // .. if the head of such an object is not dirty, we can assume
2454N/A // precise marking and it's efficient to scan just the dirty
2454N/A // cards.
2454N/A // In either case, each scanned reference must be scanned precisely
2454N/A // once so as to avoid cloning of a young referent. For efficiency,
2454N/A // our closures depend on this property and do not protect against
2454N/A // double scans.
0N/A
0N/A uintptr_t cur_chunk_index = addr_to_chunk_index(chunk_mr.start());
0N/A cur_chunk_index = cur_chunk_index - lowest_non_clean_base_chunk_index;
0N/A
2454N/A NOISY(tty->print_cr("===========================================================================");)
2454N/A NOISY(tty->print_cr(" process_chunk_boundary: Called with [" PTR_FORMAT "," PTR_FORMAT ")",
2454N/A chunk_mr.start(), chunk_mr.end());)
2454N/A
2454N/A // First, set "our" lowest_non_clean entry, which would be
2454N/A // used by the thread scanning an adjoining left chunk with
2454N/A // a non-array object straddling the mutual boundary.
2454N/A // Find the object that spans our boundary, if one exists.
2454N/A // first_block is the block possibly straddling our left boundary.
2454N/A HeapWord* first_block = sp->block_start(chunk_mr.start());
2454N/A assert((chunk_mr.start() != used.start()) || (first_block == chunk_mr.start()),
2454N/A "First chunk should always have a co-initial block");
2454N/A // Does the block straddle the chunk's left boundary, and is it
2454N/A // a non-array object?
2454N/A if (first_block < chunk_mr.start() // first block straddles left bdry
2454N/A && sp->block_is_obj(first_block) // first block is an object
2454N/A && !(oop(first_block)->is_objArray() // first block is not an array (arrays are precisely dirtied)
2454N/A || oop(first_block)->is_typeArray())) {
2454N/A // Find our least non-clean card, so that a left neighbour
2454N/A // does not scan an object straddling the mutual boundary
2454N/A // too far to the right, and attempt to scan a portion of
2454N/A // that object twice.
2454N/A jbyte* first_dirty_card = NULL;
2454N/A jbyte* last_card_of_first_obj =
2454N/A byte_for(first_block + sp->block_size(first_block) - 1);
2454N/A jbyte* first_card_of_cur_chunk = byte_for(chunk_mr.start());
2454N/A jbyte* last_card_of_cur_chunk = byte_for(chunk_mr.last());
2454N/A jbyte* last_card_to_check =
2454N/A (jbyte*) MIN2((intptr_t) last_card_of_cur_chunk,
2454N/A (intptr_t) last_card_of_first_obj);
2454N/A // Note that this does not need to go beyond our last card
2454N/A // if our first object completely straddles this chunk.
2454N/A for (jbyte* cur = first_card_of_cur_chunk;
2454N/A cur <= last_card_to_check; cur++) {
2454N/A jbyte val = *cur;
2454N/A if (card_will_be_scanned(val)) {
2454N/A first_dirty_card = cur; break;
2454N/A } else {
2454N/A assert(!card_may_have_been_dirty(val), "Error");
2454N/A }
2454N/A }
2454N/A if (first_dirty_card != NULL) {
2454N/A NOISY(tty->print_cr(" LNC: Found a dirty card at " PTR_FORMAT " in current chunk",
2454N/A first_dirty_card);)
2454N/A assert(0 <= cur_chunk_index && cur_chunk_index < lowest_non_clean_chunk_size,
2454N/A "Bounds error.");
2454N/A assert(lowest_non_clean[cur_chunk_index] == NULL,
2454N/A "Write exactly once : value should be stable hereafter for this round");
2454N/A lowest_non_clean[cur_chunk_index] = first_dirty_card;
2454N/A } NOISY(else {
2454N/A tty->print_cr(" LNC: Found no dirty card in current chunk; leaving LNC entry NULL");
2454N/A // In the future, we could have this thread look for a non-NULL value to copy from its
2454N/A // right neighbour (up to the end of the first object).
2454N/A if (last_card_of_cur_chunk < last_card_of_first_obj) {
2454N/A tty->print_cr(" LNC: BEWARE!!! first obj straddles past right end of chunk:\n"
2454N/A " might be efficient to get value from right neighbour?");
2454N/A }
2454N/A })
2454N/A } else {
2454N/A // In this case we can help our neighbour by just asking them
2454N/A // to stop at our first card (even though it may not be dirty).
2454N/A NOISY(tty->print_cr(" LNC: first block is not a non-array object; setting LNC to first card of current chunk");)
2454N/A assert(lowest_non_clean[cur_chunk_index] == NULL, "Write once : value should be stable hereafter");
2454N/A jbyte* first_card_of_cur_chunk = byte_for(chunk_mr.start());
2454N/A lowest_non_clean[cur_chunk_index] = first_card_of_cur_chunk;
2454N/A }
2454N/A NOISY(tty->print_cr(" process_chunk_boundary: lowest_non_clean[" INTPTR_FORMAT "] = " PTR_FORMAT
2454N/A " which corresponds to the heap address " PTR_FORMAT,
2454N/A cur_chunk_index, lowest_non_clean[cur_chunk_index],
2454N/A (lowest_non_clean[cur_chunk_index] != NULL)
2454N/A ? addr_for(lowest_non_clean[cur_chunk_index])
2454N/A : NULL);)
2454N/A NOISY(tty->print_cr("---------------------------------------------------------------------------");)
2454N/A
2454N/A // Next, set our own max_to_do, which will strictly/exclusively bound
2454N/A // the highest address that we will scan past the right end of our chunk.
2454N/A HeapWord* max_to_do = NULL;
0N/A if (chunk_mr.end() < used.end()) {
2454N/A // This is not the last chunk in the used region.
2454N/A // What is our last block? We check the first block of
2454N/A // the next (right) chunk rather than strictly check our last block
2454N/A // because it's potentially more efficient to do so.
2454N/A HeapWord* const last_block = sp->block_start(chunk_mr.end());
0N/A assert(last_block <= chunk_mr.end(), "In case this property changes.");
2454N/A if ((last_block == chunk_mr.end()) // our last block does not straddle boundary
2454N/A || !sp->block_is_obj(last_block) // last_block isn't an object
2454N/A || oop(last_block)->is_objArray() // last_block is an array (precisely marked)
2454N/A || oop(last_block)->is_typeArray()) {
0N/A max_to_do = chunk_mr.end();
2454N/A NOISY(tty->print_cr(" process_chunk_boundary: Last block on this card is not a non-array object;\n"
2454N/A " max_to_do left at " PTR_FORMAT, max_to_do);)
0N/A } else {
2454N/A assert(last_block < chunk_mr.end(), "Tautology");
2454N/A // It is a non-array object that straddles the right boundary of this chunk.
0N/A // last_obj_card is the card corresponding to the start of the last object
0N/A // in the chunk. Note that the last object may not start in
0N/A // the chunk.
2454N/A jbyte* const last_obj_card = byte_for(last_block);
2454N/A const jbyte val = *last_obj_card;
2454N/A if (!card_will_be_scanned(val)) {
2454N/A assert(!card_may_have_been_dirty(val), "Error");
2454N/A // The card containing the head is not dirty. Any marks on
0N/A // subsequent cards still in this chunk must have been made
2454N/A // precisely; we can cap processing at the end of our chunk.
0N/A max_to_do = chunk_mr.end();
2454N/A NOISY(tty->print_cr(" process_chunk_boundary: Head of last object on this card is not dirty;\n"
2454N/A " max_to_do left at " PTR_FORMAT,
2454N/A max_to_do);)
0N/A } else {
0N/A // The last object must be considered dirty, and extends onto the
0N/A // following chunk. Look for a dirty card in that chunk that will
0N/A // bound our processing.
0N/A jbyte* limit_card = NULL;
2454N/A const size_t last_block_size = sp->block_size(last_block);
2454N/A jbyte* const last_card_of_last_obj =
0N/A byte_for(last_block + last_block_size - 1);
2454N/A jbyte* const first_card_of_next_chunk = byte_for(chunk_mr.end());
0N/A // This search potentially goes a long distance looking
2454N/A // for the next card that will be scanned, terminating
2454N/A // at the end of the last_block, if no earlier dirty card
2454N/A // is found.
2454N/A assert(byte_for(chunk_mr.end()) - byte_for(chunk_mr.start()) == ParGCCardsPerStrideChunk,
2454N/A "last card of next chunk may be wrong");
0N/A for (jbyte* cur = first_card_of_next_chunk;
2454N/A cur <= last_card_of_last_obj; cur++) {
2454N/A const jbyte val = *cur;
2454N/A if (card_will_be_scanned(val)) {
2454N/A NOISY(tty->print_cr(" Found a non-clean card " PTR_FORMAT " with value 0x%x",
2454N/A cur, (int)val);)
0N/A limit_card = cur; break;
2454N/A } else {
2454N/A assert(!card_may_have_been_dirty(val), "Error: card can't be skipped");
0N/A }
0N/A }
2454N/A if (limit_card != NULL) {
2454N/A max_to_do = addr_for(limit_card);
2454N/A assert(limit_card != NULL && max_to_do != NULL, "Error");
2454N/A NOISY(tty->print_cr(" process_chunk_boundary: Found a dirty card at " PTR_FORMAT
2454N/A " max_to_do set at " PTR_FORMAT " which is before end of last block in chunk: "
2454N/A PTR_FORMAT " + " PTR_FORMAT " = " PTR_FORMAT,
2454N/A limit_card, max_to_do, last_block, last_block_size, (last_block+last_block_size));)
2454N/A } else {
2454N/A // The following is a pessimistic value, because it's possible
2454N/A // that a dirty card on a subsequent chunk has been cleared by
2454N/A // the time we get to look at it; we'll correct for that further below,
2454N/A // using the LNC array which records the least non-clean card
2454N/A // before cards were cleared in a particular chunk.
2454N/A limit_card = last_card_of_last_obj;
2454N/A max_to_do = last_block + last_block_size;
2454N/A assert(limit_card != NULL && max_to_do != NULL, "Error");
2454N/A NOISY(tty->print_cr(" process_chunk_boundary: Found no dirty card before end of last block in chunk\n"
2454N/A " Setting limit_card to " PTR_FORMAT
2454N/A " and max_to_do " PTR_FORMAT " + " PTR_FORMAT " = " PTR_FORMAT,
2454N/A limit_card, last_block, last_block_size, max_to_do);)
2454N/A }
2454N/A assert(0 < cur_chunk_index+1 && cur_chunk_index+1 < lowest_non_clean_chunk_size,
0N/A "Bounds error.");
2454N/A // It is possible that a dirty card for the last object may have been
2454N/A // cleared before we had a chance to examine it. In that case, the value
2454N/A // will have been logged in the LNC for that chunk.
2454N/A // We need to examine as many chunks to the right as this object
2587N/A // covers. However, we need to bound this checking to the largest
2587N/A // entry in the LNC array: this is because the heap may expand
2587N/A // after the LNC array has been created but before we reach this point,
2587N/A // and the last block in our chunk may have been expanded to include
2587N/A // the expansion delta (and possibly subsequently allocated from, so
2587N/A // it wouldn't be sufficient to check whether that last block was
2587N/A // or was not an object at this point).
2587N/A uintptr_t last_chunk_index_to_check = addr_to_chunk_index(last_block + last_block_size - 1)
2587N/A - lowest_non_clean_base_chunk_index;
2587N/A const uintptr_t last_chunk_index = addr_to_chunk_index(used.last())
2587N/A - lowest_non_clean_base_chunk_index;
2587N/A if (last_chunk_index_to_check > last_chunk_index) {
2587N/A assert(last_block + last_block_size > used.end(),
2587N/A err_msg("Inconsistency detected: last_block [" PTR_FORMAT "," PTR_FORMAT "]"
2587N/A " does not exceed used.end() = " PTR_FORMAT ","
2587N/A " yet last_chunk_index_to_check " INTPTR_FORMAT
2587N/A " exceeds last_chunk_index " INTPTR_FORMAT,
4348N/A last_block, last_block + last_block_size,
4348N/A used.end(),
2587N/A last_chunk_index_to_check, last_chunk_index));
2587N/A assert(sp->used_region().end() > used.end(),
2587N/A err_msg("Expansion did not happen: "
2587N/A "[" PTR_FORMAT "," PTR_FORMAT ") -> [" PTR_FORMAT "," PTR_FORMAT ")",
2587N/A sp->used_region().start(), sp->used_region().end(), used.start(), used.end()));
2587N/A NOISY(tty->print_cr(" process_chunk_boundary: heap expanded; explicitly bounding last_chunk");)
2587N/A last_chunk_index_to_check = last_chunk_index;
2587N/A }
2454N/A for (uintptr_t lnc_index = cur_chunk_index + 1;
2454N/A lnc_index <= last_chunk_index_to_check;
2454N/A lnc_index++) {
2454N/A jbyte* lnc_card = lowest_non_clean[lnc_index];
0N/A if (lnc_card != NULL) {
2454N/A // we can stop at the first non-NULL entry we find
2454N/A if (lnc_card <= limit_card) {
2454N/A NOISY(tty->print_cr(" process_chunk_boundary: LNC card " PTR_FORMAT " is lower than limit_card " PTR_FORMAT,
2454N/A " max_to_do will be lowered to " PTR_FORMAT " from " PTR_FORMAT,
2454N/A lnc_card, limit_card, addr_for(lnc_card), max_to_do);)
2454N/A limit_card = lnc_card;
2454N/A max_to_do = addr_for(limit_card);
2454N/A assert(limit_card != NULL && max_to_do != NULL, "Error");
2454N/A }
2454N/A // In any case, we break now
2454N/A break;
2454N/A } // else continue to look for a non-NULL entry if any
0N/A }
2454N/A assert(limit_card != NULL && max_to_do != NULL, "Error");
0N/A }
2454N/A assert(max_to_do != NULL, "OOPS 1 !");
0N/A }
2454N/A assert(max_to_do != NULL, "OOPS 2!");
0N/A } else {
0N/A max_to_do = used.end();
2454N/A NOISY(tty->print_cr(" process_chunk_boundary: Last chunk of this space;\n"
2454N/A " max_to_do left at " PTR_FORMAT,
2454N/A max_to_do);)
0N/A }
2454N/A assert(max_to_do != NULL, "OOPS 3!");
0N/A // Now we can set the closure we're using so it doesn't to beyond
0N/A // max_to_do.
0N/A dcto_cl->set_min_done(max_to_do);
0N/A#ifndef PRODUCT
0N/A dcto_cl->set_last_bottom(max_to_do);
0N/A#endif
2454N/A NOISY(tty->print_cr("===========================================================================\n");)
2454N/A}
0N/A
2454N/A#undef NOISY
0N/A
0N/Avoid
0N/ACardTableModRefBS::
0N/Aget_LNC_array_for_space(Space* sp,
0N/A jbyte**& lowest_non_clean,
0N/A uintptr_t& lowest_non_clean_base_chunk_index,
0N/A size_t& lowest_non_clean_chunk_size) {
0N/A
0N/A int i = find_covering_region_containing(sp->bottom());
0N/A MemRegion covered = _covered[i];
0N/A size_t n_chunks = chunks_to_cover(covered);
0N/A
0N/A // Only the first thread to obtain the lock will resize the
0N/A // LNC array for the covered region. Any later expansion can't affect
0N/A // the used_at_save_marks region.
0N/A // (I observed a bug in which the first thread to execute this would
2454N/A // resize, and then it would cause "expand_and_allocate" that would
2454N/A // increase the number of chunks in the covered region. Then a second
0N/A // thread would come and execute this, see that the size didn't match,
0N/A // and free and allocate again. So the first thread would be using a
0N/A // freed "_lowest_non_clean" array.)
0N/A
0N/A // Do a dirty read here. If we pass the conditional then take the rare
0N/A // event lock and do the read again in case some other thread had already
0N/A // succeeded and done the resize.
0N/A int cur_collection = Universe::heap()->total_collections();
0N/A if (_last_LNC_resizing_collection[i] != cur_collection) {
0N/A MutexLocker x(ParGCRareEvent_lock);
0N/A if (_last_LNC_resizing_collection[i] != cur_collection) {
0N/A if (_lowest_non_clean[i] == NULL ||
0N/A n_chunks != _lowest_non_clean_chunk_size[i]) {
0N/A
0N/A // Should we delete the old?
0N/A if (_lowest_non_clean[i] != NULL) {
0N/A assert(n_chunks != _lowest_non_clean_chunk_size[i],
0N/A "logical consequence");
3863N/A FREE_C_HEAP_ARRAY(CardPtr, _lowest_non_clean[i], mtGC);
0N/A _lowest_non_clean[i] = NULL;
0N/A }
0N/A // Now allocate a new one if necessary.
0N/A if (_lowest_non_clean[i] == NULL) {
3863N/A _lowest_non_clean[i] = NEW_C_HEAP_ARRAY(CardPtr, n_chunks, mtGC);
0N/A _lowest_non_clean_chunk_size[i] = n_chunks;
0N/A _lowest_non_clean_base_chunk_index[i] = addr_to_chunk_index(covered.start());
0N/A for (int j = 0; j < (int)n_chunks; j++)
0N/A _lowest_non_clean[i][j] = NULL;
0N/A }
0N/A }
0N/A _last_LNC_resizing_collection[i] = cur_collection;
0N/A }
0N/A }
0N/A // In any case, now do the initialization.
0N/A lowest_non_clean = _lowest_non_clean[i];
0N/A lowest_non_clean_base_chunk_index = _lowest_non_clean_base_chunk_index[i];
0N/A lowest_non_clean_chunk_size = _lowest_non_clean_chunk_size[i];
0N/A}