parCardTableModRefBS.cpp revision 1879
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.
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 * 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 * 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 * 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
8ec981fc8b0105da5f071e40811e0c2472a6c3c9Stéphane Grabervoid CardTableModRefBS::par_non_clean_card_iterate_work(Space* sp, MemRegion mr,
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov assert((n_threads == 1 && ParallelGCThreads == 0) ||
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov "# worker threads != # requested!");
148315348760faf4ad822ded7c416d2de8050937Alexander Vladimirov // Make sure the LNC array is valid for the space.
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov uintptr_t lowest_non_clean_base_chunk_index;
b7b7d3884ef10bc2ba0f1aba35ee4f27858585bfLeonid Isaev SequentialSubTasksDone* pst = sp->par_seq_tasks();
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov while (!pst->is_task_claimed(/* reference */ stride)) {
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov process_stride(sp, mr, stride, n_strides, dcto_cl, cl, clear,
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");
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov uintptr_t lowest_non_clean_base_chunk_index,
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 // 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 uintptr_t start_chunk = addr_to_chunk_index(used.start());
2b67aaee94926d07dba6c6fea97d8ed138afa9d0Stéphane Graber uintptr_t start_chunk_stride_num = start_chunk % n_strides;
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov if ((uintptr_t)stride >= start_chunk_stride_num) {
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov chunk_card_start = (jbyte*)(start_card +
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) *
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),
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");
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov // Process the chunk.
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov non_clean_card_iterate_work(chunk_mr, cl, clear);
23cc88bae05f790dcdfa9f511bbb60b2225692beAlexander Vladimirov // Find the next chunk of the stride.
23cc88bae05f790dcdfa9f511bbb60b2225692beAlexander Vladimirov chunk_card_start += CardsPerStrideChunk * n_strides;
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov uintptr_t lowest_non_clean_base_chunk_index,
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov // We must worry about the chunk boundaries.
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov // First, set our max_to_do:
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 // This is not the last chunk in the used region. What is the last
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov HeapWord* last_block = sp->block_start(chunk_mr.end());
c194ffc100f488b08bae2d0df417fa9ffc507c7cAlexander Vladimirov assert(last_block <= chunk_mr.end(), "In case this property changes.");
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 // 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 // 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.
44b036309bd11ecde9ddbfa05ee74070e7456d6cLeonid Isaev size_t last_block_size = sp->block_size(last_block);
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 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 for (jbyte* cur = first_card_of_next_chunk;
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 limit_card = (jbyte*)MIN2((intptr_t)limit_card,
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov max_to_do = last_block + last_block_size;
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov // Now we can set the closure we're using so it doesn't to beyond
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.
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 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*) MIN2((intptr_t) last_card_of_cur_chunk,
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov for (jbyte* cur = first_card_of_cur_chunk;
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 uintptr_t& lowest_non_clean_base_chunk_index,
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov int i = find_covering_region_containing(sp->bottom());
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov size_t n_chunks = chunks_to_cover(covered);
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 // 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) {
f3849d01d8f31785bf933ffcf91a419c4ff2257dAlexander Vladimirov if (_last_LNC_resizing_collection[i] != cur_collection) {
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov n_chunks != _lowest_non_clean_chunk_size[i]) {
f6267d9011eea5074028dc44b49df3bd3df7443cAlexander Vladimirov // Should we delete the old?
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 // Now allocate a new one if necessary.
012f591a7df0a3cb025905ba2e7d2033b550dac1John Lane _lowest_non_clean[i] = NEW_C_HEAP_ARRAY(CardPtr, 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 _last_LNC_resizing_collection[i] = cur_collection;
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];