parCardTableModRefBS.cpp revision 1879
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov/*
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov * Copyright (c) 2007, 2010 Oracle and/or its affiliates. All rights reserved.
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov *
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov * This code is free software; you can redistribute it and/or modify it
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov * under the terms of the GNU General Public License version 2 only, as
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov * published by the Free Software Foundation.
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov *
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov * This code is distributed in the hope that it will be useful, but WITHOUT
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
d0800999b2aff2c2445e1ac18905fddbfe71cb8cJohn Lane * version 2 for more details (a copy is included in the LICENSE file that
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov * accompanied this code).
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov *
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov * You should have received a copy of the GNU General Public License version
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov * 2 along with this work; if not, write to the Free Software Foundation,
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov *
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov * or visit www.oracle.com if you need additional information or have any
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov * questions.
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov *
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov */
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov#include "precompiled.hpp"
250b1eec71b074acdff1c5f6b5a1f0d7d2c20b77Stéphane Graber#include "memory/allocation.inline.hpp"
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov#include "memory/cardTableModRefBS.hpp"
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber#include "memory/cardTableRS.hpp"
c63c04fcaf1c3a78c70500eae253d72fa9c8358aTAMUKI Shoichi#include "memory/sharedHeap.hpp"
96283b546081e7ff709968378fca25cb44f1ab6cStéphane Graber#include "memory/space.inline.hpp"
96283b546081e7ff709968378fca25cb44f1ab6cStéphane Graber#include "memory/universe.hpp"
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber#include "runtime/java.hpp"
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber#include "runtime/mutexLocker.hpp"
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber#include "runtime/virtualspace.hpp"
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Grabervoid CardTableModRefBS::par_non_clean_card_iterate_work(Space* sp, MemRegion mr,
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Graber DirtyCardToOopClosure* dcto_cl,
207bf0e475f1dc6e9a2dac2cee3a209b56427855Stéphane Graber MemRegionClosure* cl,
207bf0e475f1dc6e9a2dac2cee3a209b56427855Stéphane Graber bool clear,
207bf0e475f1dc6e9a2dac2cee3a209b56427855Stéphane Graber int n_threads) {
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov if (n_threads > 0) {
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov assert((n_threads == 1 && ParallelGCThreads == 0) ||
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov n_threads <= (int)ParallelGCThreads,
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov "# worker threads != # requested!");
148315348760faf4ad822ded7c416d2de8050937Alexander Vladimirov // Make sure the LNC array is valid for the space.
23cc88bae05f790dcdfa9f511bbb60b2225692beAlexander Vladimirov jbyte** lowest_non_clean;
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov uintptr_t lowest_non_clean_base_chunk_index;
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov size_t lowest_non_clean_chunk_size;
b7b7d3884ef10bc2ba0f1aba35ee4f27858585bfLeonid Isaev get_LNC_array_for_space(sp, lowest_non_clean,
b7b7d3884ef10bc2ba0f1aba35ee4f27858585bfLeonid Isaev lowest_non_clean_base_chunk_index,
b7b7d3884ef10bc2ba0f1aba35ee4f27858585bfLeonid Isaev lowest_non_clean_chunk_size);
b7b7d3884ef10bc2ba0f1aba35ee4f27858585bfLeonid Isaev
b7b7d3884ef10bc2ba0f1aba35ee4f27858585bfLeonid Isaev int n_strides = n_threads * StridesPerThread;
b7b7d3884ef10bc2ba0f1aba35ee4f27858585bfLeonid Isaev SequentialSubTasksDone* pst = sp->par_seq_tasks();
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov pst->set_n_threads(n_threads);
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov pst->set_n_tasks(n_strides);
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov int stride = 0;
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov while (!pst->is_task_claimed(/* reference */ stride)) {
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov process_stride(sp, mr, stride, n_strides, dcto_cl, cl, clear,
17abf2784de1047fb2904ff130ee5efe4ea7b598Elan Ruusamäe lowest_non_clean,
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov lowest_non_clean_base_chunk_index,
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov lowest_non_clean_chunk_size);
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov }
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov if (pst->all_tasks_completed()) {
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov // Clear lowest_non_clean array for next time.
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov intptr_t first_chunk_index = addr_to_chunk_index(mr.start());
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov uintptr_t last_chunk_index = addr_to_chunk_index(mr.last());
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov for (uintptr_t ch = first_chunk_index; ch <= last_chunk_index; ch++) {
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov intptr_t ind = ch - lowest_non_clean_base_chunk_index;
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov assert(0 <= ind && ind < (intptr_t)lowest_non_clean_chunk_size,
17abf2784de1047fb2904ff130ee5efe4ea7b598Elan Ruusamäe "Bounds error");
21ca73b980b0888edaed6e1674870c28c1f515d8Leonid Isaev lowest_non_clean[ind] = NULL;
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov }
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov }
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov }
8fefbee4062ed863d242763676d4c57bea2ffb4cBill Kolokithas}
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirovvoid
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander VladimirovCardTableModRefBS::
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirovprocess_stride(Space* sp,
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov MemRegion used,
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov jint stride, int n_strides,
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov DirtyCardToOopClosure* dcto_cl,
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov MemRegionClosure* cl,
21ca73b980b0888edaed6e1674870c28c1f515d8Leonid Isaev bool clear,
21ca73b980b0888edaed6e1674870c28c1f515d8Leonid Isaev jbyte** lowest_non_clean,
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov uintptr_t lowest_non_clean_base_chunk_index,
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov size_t lowest_non_clean_chunk_size) {
2b67aaee94926d07dba6c6fea97d8ed138afa9d0Stéphane Graber // We don't have to go downwards here; it wouldn't help anyway,
2b67aaee94926d07dba6c6fea97d8ed138afa9d0Stéphane Graber // because of parallelism.
2b67aaee94926d07dba6c6fea97d8ed138afa9d0Stéphane Graber
2b67aaee94926d07dba6c6fea97d8ed138afa9d0Stéphane Graber // Find the first card address of the first chunk in the stride that is
2b67aaee94926d07dba6c6fea97d8ed138afa9d0Stéphane Graber // at least "bottom" of the used region.
2b67aaee94926d07dba6c6fea97d8ed138afa9d0Stéphane Graber jbyte* start_card = byte_for(used.start());
2b67aaee94926d07dba6c6fea97d8ed138afa9d0Stéphane Graber jbyte* end_card = byte_after(used.last());
2b67aaee94926d07dba6c6fea97d8ed138afa9d0Stéphane Graber uintptr_t start_chunk = addr_to_chunk_index(used.start());
2b67aaee94926d07dba6c6fea97d8ed138afa9d0Stéphane Graber uintptr_t start_chunk_stride_num = start_chunk % n_strides;
21ca73b980b0888edaed6e1674870c28c1f515d8Leonid Isaev jbyte* chunk_card_start;
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov if ((uintptr_t)stride >= start_chunk_stride_num) {
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov chunk_card_start = (jbyte*)(start_card +
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov (stride - start_chunk_stride_num) *
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov CardsPerStrideChunk);
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov } else {
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov // Go ahead to the next chunk group boundary, then to the requested stride.
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov chunk_card_start = (jbyte*)(start_card +
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov (n_strides - start_chunk_stride_num + stride) *
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov CardsPerStrideChunk);
427d42930d99f93bf78c61ec9f555dd883c5039eJakub Sztandera }
427d42930d99f93bf78c61ec9f555dd883c5039eJakub Sztandera
427d42930d99f93bf78c61ec9f555dd883c5039eJakub Sztandera while (chunk_card_start < end_card) {
427d42930d99f93bf78c61ec9f555dd883c5039eJakub Sztandera // We don't have to go downwards here; it wouldn't help anyway,
99cbd2996bd5cebf1869c2f7637f6c9fc2004849Alexander Vladimirov // because of parallelism. (We take care with "min_done"; see below.)
99cbd2996bd5cebf1869c2f7637f6c9fc2004849Alexander Vladimirov // Invariant: chunk_mr should be fully contained within the "used" region.
99cbd2996bd5cebf1869c2f7637f6c9fc2004849Alexander Vladimirov jbyte* chunk_card_end = chunk_card_start + CardsPerStrideChunk;
2b67aaee94926d07dba6c6fea97d8ed138afa9d0Stéphane Graber MemRegion chunk_mr = MemRegion(addr_for(chunk_card_start),
2b67aaee94926d07dba6c6fea97d8ed138afa9d0Stéphane Graber chunk_card_end >= end_card ?
2b67aaee94926d07dba6c6fea97d8ed138afa9d0Stéphane Graber used.end() : addr_for(chunk_card_end));
b91f0faeaa847774b7645b9172cc9a58277d1ed0Stéphane Graber assert(chunk_mr.word_size() > 0, "[chunk_card_start > used_end)");
b91f0faeaa847774b7645b9172cc9a58277d1ed0Stéphane Graber assert(used.contains(chunk_mr), "chunk_mr should be subset of used");
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov // Process the chunk.
23cc88bae05f790dcdfa9f511bbb60b2225692beAlexander Vladimirov process_chunk_boundaries(sp,
23cc88bae05f790dcdfa9f511bbb60b2225692beAlexander Vladimirov dcto_cl,
23cc88bae05f790dcdfa9f511bbb60b2225692beAlexander Vladimirov chunk_mr,
23cc88bae05f790dcdfa9f511bbb60b2225692beAlexander Vladimirov used,
23cc88bae05f790dcdfa9f511bbb60b2225692beAlexander Vladimirov lowest_non_clean,
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov lowest_non_clean_base_chunk_index,
23cc88bae05f790dcdfa9f511bbb60b2225692beAlexander Vladimirov lowest_non_clean_chunk_size);
23cc88bae05f790dcdfa9f511bbb60b2225692beAlexander Vladimirov
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov non_clean_card_iterate_work(chunk_mr, cl, clear);
23cc88bae05f790dcdfa9f511bbb60b2225692beAlexander Vladimirov
23cc88bae05f790dcdfa9f511bbb60b2225692beAlexander Vladimirov // Find the next chunk of the stride.
23cc88bae05f790dcdfa9f511bbb60b2225692beAlexander Vladimirov chunk_card_start += CardsPerStrideChunk * n_strides;
23cc88bae05f790dcdfa9f511bbb60b2225692beAlexander Vladimirov }
23cc88bae05f790dcdfa9f511bbb60b2225692beAlexander Vladimirov}
23cc88bae05f790dcdfa9f511bbb60b2225692beAlexander Vladimirov
23cc88bae05f790dcdfa9f511bbb60b2225692beAlexander Vladimirovvoid
23cc88bae05f790dcdfa9f511bbb60b2225692beAlexander VladimirovCardTableModRefBS::
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirovprocess_chunk_boundaries(Space* sp,
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov DirtyCardToOopClosure* dcto_cl,
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov MemRegion chunk_mr,
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov MemRegion used,
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov jbyte** lowest_non_clean,
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov uintptr_t lowest_non_clean_base_chunk_index,
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov size_t lowest_non_clean_chunk_size)
17abf2784de1047fb2904ff130ee5efe4ea7b598Elan Ruusamäe{
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov // We must worry about the chunk boundaries.
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov // First, set our max_to_do:
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov HeapWord* max_to_do = NULL;
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov uintptr_t cur_chunk_index = addr_to_chunk_index(chunk_mr.start());
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov cur_chunk_index = cur_chunk_index - lowest_non_clean_base_chunk_index;
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov if (chunk_mr.end() < used.end()) {
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov // This is not the last chunk in the used region. What is the last
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov // object?
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov HeapWord* last_block = sp->block_start(chunk_mr.end());
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov assert(last_block <= chunk_mr.end(), "In case this property changes.");
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov if (last_block == chunk_mr.end()
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov || !sp->block_is_obj(last_block)) {
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov max_to_do = chunk_mr.end();
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov } else {
17abf2784de1047fb2904ff130ee5efe4ea7b598Elan Ruusamäe // It is an object and starts before the end of the current chunk.
734d0bed55ea17793510e1ce1de34ebc8c5eb6abJohn Lane // last_obj_card is the card corresponding to the start of the last object
734d0bed55ea17793510e1ce1de34ebc8c5eb6abJohn Lane // in the chunk. Note that the last object may not start in
734d0bed55ea17793510e1ce1de34ebc8c5eb6abJohn Lane // the chunk.
734d0bed55ea17793510e1ce1de34ebc8c5eb6abJohn Lane jbyte* last_obj_card = byte_for(last_block);
734d0bed55ea17793510e1ce1de34ebc8c5eb6abJohn Lane if (!card_may_have_been_dirty(*last_obj_card)) {
734d0bed55ea17793510e1ce1de34ebc8c5eb6abJohn Lane // The card containing the head is not dirty. Any marks in
734d0bed55ea17793510e1ce1de34ebc8c5eb6abJohn Lane // subsequent cards still in this chunk must have been made
734d0bed55ea17793510e1ce1de34ebc8c5eb6abJohn Lane // precisely; we can cap processing at the end.
734d0bed55ea17793510e1ce1de34ebc8c5eb6abJohn Lane max_to_do = chunk_mr.end();
734d0bed55ea17793510e1ce1de34ebc8c5eb6abJohn Lane } else {
734d0bed55ea17793510e1ce1de34ebc8c5eb6abJohn Lane // The last object must be considered dirty, and extends onto the
734d0bed55ea17793510e1ce1de34ebc8c5eb6abJohn Lane // following chunk. Look for a dirty card in that chunk that will
734d0bed55ea17793510e1ce1de34ebc8c5eb6abJohn Lane // bound our processing.
734d0bed55ea17793510e1ce1de34ebc8c5eb6abJohn Lane jbyte* limit_card = NULL;
44b036309bd11ecde9ddbfa05ee74070e7456d6cLeonid Isaev size_t last_block_size = sp->block_size(last_block);
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov jbyte* last_card_of_last_obj =
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov byte_for(last_block + last_block_size - 1);
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov jbyte* first_card_of_next_chunk = byte_for(chunk_mr.end());
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov // This search potentially goes a long distance looking
734d0bed55ea17793510e1ce1de34ebc8c5eb6abJohn Lane // for the next card that will be scanned. For example,
734d0bed55ea17793510e1ce1de34ebc8c5eb6abJohn Lane // an object that is an array of primitives will not
734d0bed55ea17793510e1ce1de34ebc8c5eb6abJohn Lane // have any cards covering regions interior to the array
734d0bed55ea17793510e1ce1de34ebc8c5eb6abJohn Lane // that will need to be scanned. The scan can be terminated
734d0bed55ea17793510e1ce1de34ebc8c5eb6abJohn Lane // at the last card of the next chunk. That would leave
734d0bed55ea17793510e1ce1de34ebc8c5eb6abJohn Lane // limit_card as NULL and would result in "max_to_do"
734d0bed55ea17793510e1ce1de34ebc8c5eb6abJohn Lane // being set with the LNC value or with the end
734d0bed55ea17793510e1ce1de34ebc8c5eb6abJohn Lane // of the last block.
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov jbyte* last_card_of_next_chunk = first_card_of_next_chunk +
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov CardsPerStrideChunk;
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov assert(byte_for(chunk_mr.end()) - byte_for(chunk_mr.start())
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov == CardsPerStrideChunk, "last card of next chunk may be wrong");
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov jbyte* last_card_to_check = (jbyte*) MIN2(last_card_of_last_obj,
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov last_card_of_next_chunk);
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov for (jbyte* cur = first_card_of_next_chunk;
99cbd2996bd5cebf1869c2f7637f6c9fc2004849Alexander Vladimirov cur <= last_card_to_check; cur++) {
99cbd2996bd5cebf1869c2f7637f6c9fc2004849Alexander Vladimirov if (card_will_be_scanned(*cur)) {
99cbd2996bd5cebf1869c2f7637f6c9fc2004849Alexander Vladimirov limit_card = cur; break;
99cbd2996bd5cebf1869c2f7637f6c9fc2004849Alexander Vladimirov }
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov }
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov assert(0 <= cur_chunk_index+1 &&
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov cur_chunk_index+1 < lowest_non_clean_chunk_size,
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov "Bounds error.");
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov // LNC for the next chunk
69cbc333bd548771bdfaefc695e84cb355ec74d1Nicolas Porcel jbyte* lnc_card = lowest_non_clean[cur_chunk_index+1];
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov if (limit_card == NULL) {
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov limit_card = lnc_card;
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov }
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov if (limit_card != NULL) {
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov if (lnc_card != NULL) {
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov limit_card = (jbyte*)MIN2((intptr_t)limit_card,
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov (intptr_t)lnc_card);
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov }
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov max_to_do = addr_for(limit_card);
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov } else {
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov max_to_do = last_block + last_block_size;
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov }
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov }
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov }
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov assert(max_to_do != NULL, "OOPS!");
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov } else {
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov max_to_do = used.end();
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov }
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov // Now we can set the closure we're using so it doesn't to beyond
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov // max_to_do.
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov dcto_cl->set_min_done(max_to_do);
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov#ifndef PRODUCT
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov dcto_cl->set_last_bottom(max_to_do);
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov#endif
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallyn
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov // Now we set *our" lowest_non_clean entry.
012f591a7df0a3cb025905ba2e7d2033b550dac1John Lane // Find the object that spans our boundary, if one exists.
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov // Nothing to do on the first chunk.
148315348760faf4ad822ded7c416d2de8050937Alexander Vladimirov if (chunk_mr.start() > used.start()) {
734d0bed55ea17793510e1ce1de34ebc8c5eb6abJohn Lane // first_block is the block possibly spanning the chunk start
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov HeapWord* first_block = sp->block_start(chunk_mr.start());
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov // Does the block span the start of the chunk and is it
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov // an object?
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov if (first_block < chunk_mr.start() &&
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov sp->block_is_obj(first_block)) {
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov jbyte* first_dirty_card = NULL;
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov jbyte* last_card_of_first_obj =
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov byte_for(first_block + sp->block_size(first_block) - 1);
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov jbyte* first_card_of_cur_chunk = byte_for(chunk_mr.start());
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov jbyte* last_card_of_cur_chunk = byte_for(chunk_mr.last());
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov jbyte* last_card_to_check =
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov (jbyte*) MIN2((intptr_t) last_card_of_cur_chunk,
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov (intptr_t) last_card_of_first_obj);
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov for (jbyte* cur = first_card_of_cur_chunk;
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov cur <= last_card_to_check; cur++) {
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov if (card_will_be_scanned(*cur)) {
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov first_dirty_card = cur; break;
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov }
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov }
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov if (first_dirty_card != NULL) {
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov assert(0 <= cur_chunk_index &&
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov cur_chunk_index < lowest_non_clean_chunk_size,
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov "Bounds error.");
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov lowest_non_clean[cur_chunk_index] = first_dirty_card;
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov }
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov }
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallyn }
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallyn}
1897e3bcd36af9f3fe6d3649910a9adb93e5e988Serge Hallyn
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirovvoid
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander VladimirovCardTableModRefBS::
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirovget_LNC_array_for_space(Space* sp,
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov jbyte**& lowest_non_clean,
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov uintptr_t& lowest_non_clean_base_chunk_index,
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov size_t& lowest_non_clean_chunk_size) {
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov int i = find_covering_region_containing(sp->bottom());
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov MemRegion covered = _covered[i];
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov size_t n_chunks = chunks_to_cover(covered);
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov // Only the first thread to obtain the lock will resize the
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov // LNC array for the covered region. Any later expansion can't affect
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov // the used_at_save_marks region.
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov // (I observed a bug in which the first thread to execute this would
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov // resize, and then it would cause "expand_and_allocates" that would
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov // Increase the number of chunks in the covered region. Then a second
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov // thread would come and execute this, see that the size didn't match,
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov // and free and allocate again. So the first thread would be using a
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov // freed "_lowest_non_clean" array.)
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov // Do a dirty read here. If we pass the conditional then take the rare
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov // event lock and do the read again in case some other thread had already
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov // succeeded and done the resize.
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov int cur_collection = Universe::heap()->total_collections();
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov if (_last_LNC_resizing_collection[i] != cur_collection) {
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov MutexLocker x(ParGCRareEvent_lock);
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov if (_last_LNC_resizing_collection[i] != cur_collection) {
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov if (_lowest_non_clean[i] == NULL ||
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov n_chunks != _lowest_non_clean_chunk_size[i]) {
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov // Should we delete the old?
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov if (_lowest_non_clean[i] != NULL) {
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov assert(n_chunks != _lowest_non_clean_chunk_size[i],
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov "logical consequence");
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov FREE_C_HEAP_ARRAY(CardPtr, _lowest_non_clean[i]);
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov _lowest_non_clean[i] = NULL;
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov }
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov // Now allocate a new one if necessary.
012f591a7df0a3cb025905ba2e7d2033b550dac1John Lane if (_lowest_non_clean[i] == NULL) {
012f591a7df0a3cb025905ba2e7d2033b550dac1John Lane _lowest_non_clean[i] = NEW_C_HEAP_ARRAY(CardPtr, n_chunks);
012f591a7df0a3cb025905ba2e7d2033b550dac1John Lane _lowest_non_clean_chunk_size[i] = n_chunks;
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov _lowest_non_clean_base_chunk_index[i] = addr_to_chunk_index(covered.start());
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov for (int j = 0; j < (int)n_chunks; j++)
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov _lowest_non_clean[i][j] = NULL;
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov }
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov }
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov _last_LNC_resizing_collection[i] = cur_collection;
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov }
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov }
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov // In any case, now do the initialization.
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov lowest_non_clean = _lowest_non_clean[i];
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov lowest_non_clean_base_chunk_index = _lowest_non_clean_base_chunk_index[i];
012f591a7df0a3cb025905ba2e7d2033b550dac1John Lane lowest_non_clean_chunk_size = _lowest_non_clean_chunk_size[i];
012f591a7df0a3cb025905ba2e7d2033b550dac1John Lane}
012f591a7df0a3cb025905ba2e7d2033b550dac1John Lane