hotspot/src/share/vm/gc_implementation/parNew/parCardTableModRefBS.cpp
author ysr
Wed, 20 Apr 2011 19:19:30 -0700
changeset 9336 413920193f83
parent 9183 3d0e0687fe28
child 9624 c3657c3324ee
permissions -rw-r--r--
7037276: Unnecessary double traversal of dirty card windows Summary: Short-circuited an unnecessary double traversal of dirty card windows when iterating younger refs. Also renamed some cardtable methods for more clarity. Reviewed-by: jmasa, stefank, poonam
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
9183
3d0e0687fe28 7036482: clear argument is redundant and unused in cardtable methods
ysr
parents: 7397
diff changeset
     2
 * Copyright (c) 2007, 2011 Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3262
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3262
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3262
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6759
diff changeset
    25
#include "precompiled.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6759
diff changeset
    26
#include "memory/allocation.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6759
diff changeset
    27
#include "memory/cardTableModRefBS.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6759
diff changeset
    28
#include "memory/cardTableRS.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6759
diff changeset
    29
#include "memory/sharedHeap.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6759
diff changeset
    30
#include "memory/space.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6759
diff changeset
    31
#include "memory/universe.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6759
diff changeset
    32
#include "runtime/java.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6759
diff changeset
    33
#include "runtime/mutexLocker.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6759
diff changeset
    34
#include "runtime/virtualspace.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
9336
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    36
void CardTableModRefBS::non_clean_card_iterate_parallel_work(Space* sp, MemRegion mr,
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    37
                                                             DirtyCardToOopClosure* dcto_cl,
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    38
                                                             ClearNoncleanCardWrapper* cl,
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    39
                                                             int n_threads) {
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    40
  assert(n_threads > 0, "Error: expected n_threads > 0");
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    41
  assert((n_threads == 1 && ParallelGCThreads == 0) ||
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    42
         n_threads <= (int)ParallelGCThreads,
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    43
         "# worker threads != # requested!");
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    44
  // Make sure the LNC array is valid for the space.
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    45
  jbyte**   lowest_non_clean;
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    46
  uintptr_t lowest_non_clean_base_chunk_index;
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    47
  size_t    lowest_non_clean_chunk_size;
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    48
  get_LNC_array_for_space(sp, lowest_non_clean,
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    49
                          lowest_non_clean_base_chunk_index,
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    50
                          lowest_non_clean_chunk_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
9336
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    52
  int n_strides = n_threads * StridesPerThread;
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    53
  SequentialSubTasksDone* pst = sp->par_seq_tasks();
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    54
  pst->set_n_threads(n_threads);
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    55
  pst->set_n_tasks(n_strides);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
9336
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    57
  int stride = 0;
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    58
  while (!pst->is_task_claimed(/* reference */ stride)) {
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    59
    process_stride(sp, mr, stride, n_strides, dcto_cl, cl,
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    60
                   lowest_non_clean,
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    61
                   lowest_non_clean_base_chunk_index,
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    62
                   lowest_non_clean_chunk_size);
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    63
  }
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    64
  if (pst->all_tasks_completed()) {
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    65
    // Clear lowest_non_clean array for next time.
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    66
    intptr_t first_chunk_index = addr_to_chunk_index(mr.start());
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    67
    uintptr_t last_chunk_index  = addr_to_chunk_index(mr.last());
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    68
    for (uintptr_t ch = first_chunk_index; ch <= last_chunk_index; ch++) {
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    69
      intptr_t ind = ch - lowest_non_clean_base_chunk_index;
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    70
      assert(0 <= ind && ind < (intptr_t)lowest_non_clean_chunk_size,
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    71
             "Bounds error");
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    72
      lowest_non_clean[ind] = NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
CardTableModRefBS::
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
process_stride(Space* sp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
               MemRegion used,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
               jint stride, int n_strides,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
               DirtyCardToOopClosure* dcto_cl,
9336
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    83
               ClearNoncleanCardWrapper* cl,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
               jbyte** lowest_non_clean,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
               uintptr_t lowest_non_clean_base_chunk_index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
               size_t    lowest_non_clean_chunk_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  // We don't have to go downwards here; it wouldn't help anyway,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  // because of parallelism.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  // Find the first card address of the first chunk in the stride that is
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  // at least "bottom" of the used region.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  jbyte*    start_card  = byte_for(used.start());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
  jbyte*    end_card    = byte_after(used.last());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
  uintptr_t start_chunk = addr_to_chunk_index(used.start());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  uintptr_t start_chunk_stride_num = start_chunk % n_strides;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
  jbyte* chunk_card_start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  if ((uintptr_t)stride >= start_chunk_stride_num) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    chunk_card_start = (jbyte*)(start_card +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
                                (stride - start_chunk_stride_num) *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
                                CardsPerStrideChunk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    // Go ahead to the next chunk group boundary, then to the requested stride.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    chunk_card_start = (jbyte*)(start_card +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
                                (n_strides - start_chunk_stride_num + stride) *
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
                                CardsPerStrideChunk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  while (chunk_card_start < end_card) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    // We don't have to go downwards here; it wouldn't help anyway,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    // because of parallelism.  (We take care with "min_done"; see below.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    // Invariant: chunk_mr should be fully contained within the "used" region.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    jbyte*    chunk_card_end = chunk_card_start + CardsPerStrideChunk;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
    MemRegion chunk_mr       = MemRegion(addr_for(chunk_card_start),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
                                         chunk_card_end >= end_card ?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
                                           used.end() : addr_for(chunk_card_end));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
    assert(chunk_mr.word_size() > 0, "[chunk_card_start > used_end)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
    assert(used.contains(chunk_mr), "chunk_mr should be subset of used");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    // Process the chunk.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    process_chunk_boundaries(sp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
                             dcto_cl,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
                             chunk_mr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
                             used,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
                             lowest_non_clean,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
                             lowest_non_clean_base_chunk_index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
                             lowest_non_clean_chunk_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
9336
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
   129
    // We do not call the non_clean_card_iterate_serial() version because
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
   130
    // we want to clear the cards, and the ClearNoncleanCardWrapper closure
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
   131
    // itself does the work of finding contiguous dirty ranges of cards to
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
   132
    // process (and clear).
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
   133
    cl->do_MemRegion(chunk_mr);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
    // Find the next chunk of the stride.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
    chunk_card_start += CardsPerStrideChunk * n_strides;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
CardTableModRefBS::
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
process_chunk_boundaries(Space* sp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
                         DirtyCardToOopClosure* dcto_cl,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
                         MemRegion chunk_mr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
                         MemRegion used,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
                         jbyte** lowest_non_clean,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
                         uintptr_t lowest_non_clean_base_chunk_index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
                         size_t    lowest_non_clean_chunk_size)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  // We must worry about the chunk boundaries.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  // First, set our max_to_do:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  HeapWord* max_to_do = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  uintptr_t cur_chunk_index = addr_to_chunk_index(chunk_mr.start());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  cur_chunk_index           = cur_chunk_index - lowest_non_clean_base_chunk_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  if (chunk_mr.end() < used.end()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    // This is not the last chunk in the used region.  What is the last
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
    // object?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    HeapWord* last_block = sp->block_start(chunk_mr.end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    assert(last_block <= chunk_mr.end(), "In case this property changes.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
    if (last_block == chunk_mr.end()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
        || !sp->block_is_obj(last_block)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
      max_to_do = chunk_mr.end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
    } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
      // It is an object and starts before the end of the current chunk.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
      // last_obj_card is the card corresponding to the start of the last object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
      // in the chunk.  Note that the last object may not start in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
      // the chunk.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
      jbyte* last_obj_card = byte_for(last_block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
      if (!card_may_have_been_dirty(*last_obj_card)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
        // The card containing the head is not dirty.  Any marks in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
        // subsequent cards still in this chunk must have been made
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
        // precisely; we can cap processing at the end.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
        max_to_do = chunk_mr.end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
        // The last object must be considered dirty, and extends onto the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
        // following chunk.  Look for a dirty card in that chunk that will
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
        // bound our processing.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
        jbyte* limit_card = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
        size_t last_block_size = sp->block_size(last_block);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
        jbyte* last_card_of_last_obj =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
          byte_for(last_block + last_block_size - 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
        jbyte* first_card_of_next_chunk = byte_for(chunk_mr.end());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
        // This search potentially goes a long distance looking
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
        // for the next card that will be scanned.  For example,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
        // an object that is an array of primitives will not
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
        // have any cards covering regions interior to the array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
        // that will need to be scanned. The scan can be terminated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
        // at the last card of the next chunk.  That would leave
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
        // limit_card as NULL and would result in "max_to_do"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
        // being set with the LNC value or with the end
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
        // of the last block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
        jbyte* last_card_of_next_chunk = first_card_of_next_chunk +
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
          CardsPerStrideChunk;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
        assert(byte_for(chunk_mr.end()) - byte_for(chunk_mr.start())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
          == CardsPerStrideChunk, "last card of next chunk may be wrong");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
        jbyte* last_card_to_check = (jbyte*) MIN2(last_card_of_last_obj,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
                                                  last_card_of_next_chunk);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
        for (jbyte* cur = first_card_of_next_chunk;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
             cur <= last_card_to_check; cur++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
          if (card_will_be_scanned(*cur)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
            limit_card = cur; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
        assert(0 <= cur_chunk_index+1 &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
               cur_chunk_index+1 < lowest_non_clean_chunk_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
               "Bounds error.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
        // LNC for the next chunk
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
        jbyte* lnc_card = lowest_non_clean[cur_chunk_index+1];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
        if (limit_card == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
          limit_card = lnc_card;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
        if (limit_card != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
          if (lnc_card != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
            limit_card = (jbyte*)MIN2((intptr_t)limit_card,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
                                      (intptr_t)lnc_card);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
          max_to_do = addr_for(limit_card);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
        } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
          max_to_do = last_block + last_block_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    assert(max_to_do != NULL, "OOPS!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
    max_to_do = used.end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  // Now we can set the closure we're using so it doesn't to beyond
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  // max_to_do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  dcto_cl->set_min_done(max_to_do);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  dcto_cl->set_last_bottom(max_to_do);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  // Now we set *our" lowest_non_clean entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  // Find the object that spans our boundary, if one exists.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  // Nothing to do on the first chunk.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  if (chunk_mr.start() > used.start()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
    // first_block is the block possibly spanning the chunk start
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
    HeapWord* first_block = sp->block_start(chunk_mr.start());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
    // Does the block span the start of the chunk and is it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
    // an object?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
    if (first_block < chunk_mr.start() &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
        sp->block_is_obj(first_block)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
      jbyte* first_dirty_card = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
      jbyte* last_card_of_first_obj =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
          byte_for(first_block + sp->block_size(first_block) - 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
      jbyte* first_card_of_cur_chunk = byte_for(chunk_mr.start());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
      jbyte* last_card_of_cur_chunk = byte_for(chunk_mr.last());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
      jbyte* last_card_to_check =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
        (jbyte*) MIN2((intptr_t) last_card_of_cur_chunk,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
                      (intptr_t) last_card_of_first_obj);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
      for (jbyte* cur = first_card_of_cur_chunk;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
           cur <= last_card_to_check; cur++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
        if (card_will_be_scanned(*cur)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
          first_dirty_card = cur; break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
      if (first_dirty_card != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
        assert(0 <= cur_chunk_index &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
                 cur_chunk_index < lowest_non_clean_chunk_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
               "Bounds error.");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
        lowest_non_clean[cur_chunk_index] = first_dirty_card;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
CardTableModRefBS::
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
get_LNC_array_for_space(Space* sp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
                        jbyte**& lowest_non_clean,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
                        uintptr_t& lowest_non_clean_base_chunk_index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
                        size_t& lowest_non_clean_chunk_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  int       i        = find_covering_region_containing(sp->bottom());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  MemRegion covered  = _covered[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  size_t    n_chunks = chunks_to_cover(covered);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  // Only the first thread to obtain the lock will resize the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  // LNC array for the covered region.  Any later expansion can't affect
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
  // the used_at_save_marks region.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  // (I observed a bug in which the first thread to execute this would
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  // resize, and then it would cause "expand_and_allocates" that would
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  // Increase the number of chunks in the covered region.  Then a second
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
  // thread would come and execute this, see that the size didn't match,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  // and free and allocate again.  So the first thread would be using a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  // freed "_lowest_non_clean" array.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  // Do a dirty read here. If we pass the conditional then take the rare
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  // event lock and do the read again in case some other thread had already
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  // succeeded and done the resize.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
  int cur_collection = Universe::heap()->total_collections();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  if (_last_LNC_resizing_collection[i] != cur_collection) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
    MutexLocker x(ParGCRareEvent_lock);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
    if (_last_LNC_resizing_collection[i] != cur_collection) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
      if (_lowest_non_clean[i] == NULL ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
          n_chunks != _lowest_non_clean_chunk_size[i]) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
        // Should we delete the old?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
        if (_lowest_non_clean[i] != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
          assert(n_chunks != _lowest_non_clean_chunk_size[i],
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
                 "logical consequence");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
          FREE_C_HEAP_ARRAY(CardPtr, _lowest_non_clean[i]);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
          _lowest_non_clean[i] = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
        // Now allocate a new one if necessary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
        if (_lowest_non_clean[i] == NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
          _lowest_non_clean[i]                  = NEW_C_HEAP_ARRAY(CardPtr, n_chunks);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
          _lowest_non_clean_chunk_size[i]       = n_chunks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
          _lowest_non_clean_base_chunk_index[i] = addr_to_chunk_index(covered.start());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
          for (int j = 0; j < (int)n_chunks; j++)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
            _lowest_non_clean[i][j] = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
      _last_LNC_resizing_collection[i] = cur_collection;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  // In any case, now do the initialization.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  lowest_non_clean                  = _lowest_non_clean[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  lowest_non_clean_base_chunk_index = _lowest_non_clean_base_chunk_index[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
  lowest_non_clean_chunk_size       = _lowest_non_clean_chunk_size[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
}