src/hotspot/share/gc/cms/cmsCardTable.cpp
author tschatzl
Wed, 13 Mar 2019 21:01:56 +0100
changeset 54110 f4f0dce5d0bb
parent 51598 c88019b32bc4
permissions -rw-r--r--
8220301: Remove jbyte use in CardTable Summary: Use CardTable::CardValue aliased to uint8_t instead. Reviewed-by: kbarrett, shade
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
49164
7e958a8ebcd3 8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy
eosterlund
parents: 47622
diff changeset
     2
 * Copyright (c) 2007, 2018, 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"
49733
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
    26
#include "gc/cms/cmsCardTable.hpp"
47622
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents: 47216
diff changeset
    27
#include "gc/cms/cmsHeap.hpp"
49455
848864ed9b17 8199604: Rename CardTableModRefBS to CardTableBarrierSet
eosterlund
parents: 49164
diff changeset
    28
#include "gc/shared/cardTableBarrierSet.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30291
diff changeset
    29
#include "gc/shared/cardTableRS.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30291
diff changeset
    30
#include "gc/shared/collectedHeap.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 30291
diff changeset
    31
#include "gc/shared/space.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6759
diff changeset
    32
#include "memory/allocation.inline.hpp"
30291
54cdc5c1a9cb 8068352: Move virtualspace.* out of src/share/vm/runtime to memory directory
coleenp
parents: 30173
diff changeset
    33
#include "memory/virtualspace.hpp"
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
    34
#include "oops/oop.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6759
diff changeset
    35
#include "runtime/java.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6759
diff changeset
    36
#include "runtime/mutexLocker.hpp"
50429
83aec1d357d4 8204301: Make OrderAccess functions available to hpp rather than inline.hpp files
coleenp
parents: 49733
diff changeset
    37
#include "runtime/orderAccess.hpp"
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 10273
diff changeset
    38
#include "runtime/vmThread.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
49733
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
    40
CMSCardTable::CMSCardTable(MemRegion whole_heap) :
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
    41
    CardTableRS(whole_heap, CMSPrecleaningEnabled /* scanned_concurrently */) {
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
    42
}
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
    43
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
    44
// Returns the number of chunks necessary to cover "mr".
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
    45
size_t CMSCardTable::chunks_to_cover(MemRegion mr) {
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
    46
  return (size_t)(addr_to_chunk_index(mr.last()) -
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
    47
                  addr_to_chunk_index(mr.start()) + 1);
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
    48
}
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
    49
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
    50
// Returns the index of the chunk in a stride which
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
    51
// covers the given address.
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
    52
uintptr_t CMSCardTable::addr_to_chunk_index(const void* addr) {
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
    53
  uintptr_t card = (uintptr_t) byte_for(addr);
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
    54
  return card / ParGCCardsPerStrideChunk;
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
    55
}
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
    56
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
    57
void CMSCardTable::
31964
d34ad1715d96 8130931: Refactor CardTableModRefBS[ForCTRS]
kbarrett
parents: 31330
diff changeset
    58
non_clean_card_iterate_parallel_work(Space* sp, MemRegion mr,
d34ad1715d96 8130931: Refactor CardTableModRefBS[ForCTRS]
kbarrett
parents: 31330
diff changeset
    59
                                     OopsInGenClosure* cl,
d34ad1715d96 8130931: Refactor CardTableModRefBS[ForCTRS]
kbarrett
parents: 31330
diff changeset
    60
                                     CardTableRS* ct,
d34ad1715d96 8130931: Refactor CardTableModRefBS[ForCTRS]
kbarrett
parents: 31330
diff changeset
    61
                                     uint n_threads) {
30870
3050fdcdc60b 8080112: Replace and remove the last usages of CollectedHeap::n_par_threads()
stefank
parents: 30764
diff changeset
    62
  assert(n_threads > 0, "expected n_threads > 0");
3050fdcdc60b 8080112: Replace and remove the last usages of CollectedHeap::n_par_threads()
stefank
parents: 30764
diff changeset
    63
  assert(n_threads <= ParallelGCThreads,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31964
diff changeset
    64
         "n_threads: %u > ParallelGCThreads: %u", n_threads, ParallelGCThreads);
30870
3050fdcdc60b 8080112: Replace and remove the last usages of CollectedHeap::n_par_threads()
stefank
parents: 30764
diff changeset
    65
9336
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    66
  // Make sure the LNC array is valid for the space.
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
    67
  CardValue** lowest_non_clean;
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
    68
  uintptr_t   lowest_non_clean_base_chunk_index;
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
    69
  size_t      lowest_non_clean_chunk_size;
9336
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    70
  get_LNC_array_for_space(sp, lowest_non_clean,
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    71
                          lowest_non_clean_base_chunk_index,
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    72
                          lowest_non_clean_chunk_size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
11396
917d8673b5ef 7121618: Change type of number of GC workers to unsigned int.
jmasa
parents: 11174
diff changeset
    74
  uint n_strides = n_threads * ParGCStridesPerThread;
9336
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    75
  SequentialSubTasksDone* pst = sp->par_seq_tasks();
11174
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 10273
diff changeset
    76
  // Sets the condition for completion of the subtask (how many threads
fccee5238e70 6593758: RFE: Enhance GC ergonomics to dynamically choose ParallelGCThreads
jmasa
parents: 10273
diff changeset
    77
  // need to finish in order to be done).
9336
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    78
  pst->set_n_threads(n_threads);
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    79
  pst->set_n_tasks(n_strides);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
11396
917d8673b5ef 7121618: Change type of number of GC workers to unsigned int.
jmasa
parents: 11174
diff changeset
    81
  uint stride = 0;
51598
c88019b32bc4 8210119: Rename SubTasksDone::is_task_claimed
kbarrett
parents: 50429
diff changeset
    82
  while (pst->try_claim_task(/* reference */ stride)) {
30870
3050fdcdc60b 8080112: Replace and remove the last usages of CollectedHeap::n_par_threads()
stefank
parents: 30764
diff changeset
    83
    process_stride(sp, mr, stride, n_strides,
3050fdcdc60b 8080112: Replace and remove the last usages of CollectedHeap::n_par_threads()
stefank
parents: 30764
diff changeset
    84
                   cl, ct,
9336
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    85
                   lowest_non_clean,
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    86
                   lowest_non_clean_base_chunk_index,
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    87
                   lowest_non_clean_chunk_size);
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    88
  }
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    89
  if (pst->all_tasks_completed()) {
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    90
    // Clear lowest_non_clean array for next time.
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    91
    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
    92
    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
    93
    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
    94
      intptr_t ind = ch - lowest_non_clean_base_chunk_index;
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    95
      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
    96
             "Bounds error");
413920193f83 7037276: Unnecessary double traversal of dirty card windows
ysr
parents: 9183
diff changeset
    97
      lowest_non_clean[ind] = NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
void
49733
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
   103
CMSCardTable::
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
process_stride(Space* sp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
               MemRegion used,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
               jint stride, int n_strides,
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   107
               OopsInGenClosure* cl,
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   108
               CardTableRS* ct,
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   109
               CardValue** lowest_non_clean,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
               uintptr_t lowest_non_clean_base_chunk_index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
               size_t    lowest_non_clean_chunk_size) {
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   112
  // We go from higher to lower addresses here; it wouldn't help that much
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   113
  // because of the strided parallelism pattern used here.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
  // Find the first card address of the first chunk in the stride that is
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
  // at least "bottom" of the used region.
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   117
  CardValue* start_card  = byte_for(used.start());
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   118
  CardValue* end_card    = byte_after(used.last());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  uintptr_t start_chunk = addr_to_chunk_index(used.start());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  uintptr_t start_chunk_stride_num = start_chunk % n_strides;
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   121
  CardValue* chunk_card_start;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  if ((uintptr_t)stride >= start_chunk_stride_num) {
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   124
    chunk_card_start = (start_card +
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   125
                        (stride - start_chunk_stride_num) * ParGCCardsPerStrideChunk);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
    // Go ahead to the next chunk group boundary, then to the requested stride.
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   128
    chunk_card_start = (start_card +
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   129
                        (n_strides - start_chunk_stride_num + stride) * ParGCCardsPerStrideChunk);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  while (chunk_card_start < end_card) {
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   133
    // Even though we go from lower to higher addresses below, the
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   134
    // strided parallelism can interleave the actual processing of the
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   135
    // dirty pages in various ways. For a specific chunk within this
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   136
    // stride, we take care to avoid double scanning or missing a card
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   137
    // by suitably initializing the "min_done" field in process_chunk_boundaries()
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   138
    // below, together with the dirty region extension accomplished in
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   139
    // DirtyCardToOopClosure::do_MemRegion().
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   140
    CardValue* chunk_card_end = chunk_card_start + ParGCCardsPerStrideChunk;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    // Invariant: chunk_mr should be fully contained within the "used" region.
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   142
    MemRegion chunk_mr = MemRegion(addr_for(chunk_card_start),
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   143
                                   chunk_card_end >= end_card ?
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   144
                                   used.end() : addr_for(chunk_card_end));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
    assert(chunk_mr.word_size() > 0, "[chunk_card_start > used_end)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
    assert(used.contains(chunk_mr), "chunk_mr should be subset of used");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
30870
3050fdcdc60b 8080112: Replace and remove the last usages of CollectedHeap::n_par_threads()
stefank
parents: 30764
diff changeset
   148
    // This function is used by the parallel card table iteration.
3050fdcdc60b 8080112: Replace and remove the last usages of CollectedHeap::n_par_threads()
stefank
parents: 30764
diff changeset
   149
    const bool parallel = true;
3050fdcdc60b 8080112: Replace and remove the last usages of CollectedHeap::n_par_threads()
stefank
parents: 30764
diff changeset
   150
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   151
    DirtyCardToOopClosure* dcto_cl = sp->new_dcto_cl(cl, precision(),
30870
3050fdcdc60b 8080112: Replace and remove the last usages of CollectedHeap::n_par_threads()
stefank
parents: 30764
diff changeset
   152
                                                     cl->gen_boundary(),
3050fdcdc60b 8080112: Replace and remove the last usages of CollectedHeap::n_par_threads()
stefank
parents: 30764
diff changeset
   153
                                                     parallel);
3050fdcdc60b 8080112: Replace and remove the last usages of CollectedHeap::n_par_threads()
stefank
parents: 30764
diff changeset
   154
    ClearNoncleanCardWrapper clear_cl(dcto_cl, ct, parallel);
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   155
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   156
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
    // Process the chunk.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    process_chunk_boundaries(sp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
                             dcto_cl,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
                             chunk_mr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
                             used,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
                             lowest_non_clean,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
                             lowest_non_clean_base_chunk_index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
                             lowest_non_clean_chunk_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   166
    // We want the LNC array updates above in process_chunk_boundaries
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   167
    // to be visible before any of the card table value changes as a
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   168
    // result of the dirty card iteration below.
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   169
    OrderAccess::storestore();
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   170
29805
398335f2abed 8076241: Remove unused methods mod_card_iterate() and non_clean_card_iterate_serial()
brutisso
parents: 29799
diff changeset
   171
    // We want to clear the cards: clear_cl here does the work of finding
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   172
    // contiguous dirty ranges of cards to process and clear.
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   173
    clear_cl.do_MemRegion(chunk_mr);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
    // Find the next chunk of the stride.
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   176
    chunk_card_start += ParGCCardsPerStrideChunk * n_strides;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
void
49733
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
   181
CMSCardTable::
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
process_chunk_boundaries(Space* sp,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
                         DirtyCardToOopClosure* dcto_cl,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
                         MemRegion chunk_mr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
                         MemRegion used,
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   186
                         CardValue** lowest_non_clean,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   187
                         uintptr_t lowest_non_clean_base_chunk_index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   188
                         size_t    lowest_non_clean_chunk_size)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
{
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   190
  // We must worry about non-array objects that cross chunk boundaries,
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   191
  // because such objects are both precisely and imprecisely marked:
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   192
  // .. if the head of such an object is dirty, the entire object
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   193
  //    needs to be scanned, under the interpretation that this
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   194
  //    was an imprecise mark
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   195
  // .. if the head of such an object is not dirty, we can assume
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   196
  //    precise marking and it's efficient to scan just the dirty
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   197
  //    cards.
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   198
  // In either case, each scanned reference must be scanned precisely
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   199
  // once so as to avoid cloning of a young referent. For efficiency,
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   200
  // our closures depend on this property and do not protect against
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   201
  // double scans.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
29580
a67a581cfe11 8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents: 27880
diff changeset
   203
  uintptr_t start_chunk_index = addr_to_chunk_index(chunk_mr.start());
a67a581cfe11 8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents: 27880
diff changeset
   204
  assert(start_chunk_index >= lowest_non_clean_base_chunk_index, "Bounds error.");
a67a581cfe11 8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents: 27880
diff changeset
   205
  uintptr_t cur_chunk_index   = start_chunk_index - lowest_non_clean_base_chunk_index;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   207
  // First, set "our" lowest_non_clean entry, which would be
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   208
  // used by the thread scanning an adjoining left chunk with
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   209
  // a non-array object straddling the mutual boundary.
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   210
  // Find the object that spans our boundary, if one exists.
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   211
  // first_block is the block possibly straddling our left boundary.
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   212
  HeapWord* first_block = sp->block_start(chunk_mr.start());
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   213
  assert((chunk_mr.start() != used.start()) || (first_block == chunk_mr.start()),
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   214
         "First chunk should always have a co-initial block");
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   215
  // Does the block straddle the chunk's left boundary, and is it
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   216
  // a non-array object?
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   217
  if (first_block < chunk_mr.start()        // first block straddles left bdry
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   218
      && sp->block_is_obj(first_block)      // first block is an object
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   219
      && !(oop(first_block)->is_objArray()  // first block is not an array (arrays are precisely dirtied)
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   220
           || oop(first_block)->is_typeArray())) {
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 22234
diff changeset
   221
    // Find our least non-clean card, so that a left neighbor
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   222
    // does not scan an object straddling the mutual boundary
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   223
    // too far to the right, and attempt to scan a portion of
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   224
    // that object twice.
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   225
    CardValue* first_dirty_card = NULL;
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   226
    CardValue* last_card_of_first_obj =
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   227
        byte_for(first_block + sp->block_size(first_block) - 1);
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   228
    CardValue* first_card_of_cur_chunk = byte_for(chunk_mr.start());
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   229
    CardValue* last_card_of_cur_chunk = byte_for(chunk_mr.last());
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   230
    CardValue* last_card_to_check = MIN2(last_card_of_cur_chunk, last_card_of_first_obj);
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   231
    // Note that this does not need to go beyond our last card
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   232
    // if our first object completely straddles this chunk.
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   233
    for (CardValue* cur = first_card_of_cur_chunk;
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   234
         cur <= last_card_to_check; cur++) {
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   235
      CardValue val = *cur;
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   236
      if (card_will_be_scanned(val)) {
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   237
        first_dirty_card = cur;
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   238
        break;
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   239
      } else {
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   240
        assert(!card_may_have_been_dirty(val), "Error");
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   241
      }
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   242
    }
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   243
    if (first_dirty_card != NULL) {
29580
a67a581cfe11 8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents: 27880
diff changeset
   244
      assert(cur_chunk_index < lowest_non_clean_chunk_size, "Bounds error.");
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   245
      assert(lowest_non_clean[cur_chunk_index] == NULL,
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   246
             "Write exactly once : value should be stable hereafter for this round");
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   247
      lowest_non_clean[cur_chunk_index] = first_dirty_card;
37055
3ea6a0d5a78c 8151514: Remove the noisy NOISY debugging code from parCardTableModRefBS.cpp
brutisso
parents: 33105
diff changeset
   248
    }
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   249
  } else {
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 22234
diff changeset
   250
    // In this case we can help our neighbor by just asking them
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   251
    // to stop at our first card (even though it may not be dirty).
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   252
    assert(lowest_non_clean[cur_chunk_index] == NULL, "Write once : value should be stable hereafter");
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   253
    CardValue* first_card_of_cur_chunk = byte_for(chunk_mr.start());
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   254
    lowest_non_clean[cur_chunk_index] = first_card_of_cur_chunk;
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   255
  }
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   256
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   257
  // Next, set our own max_to_do, which will strictly/exclusively bound
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   258
  // the highest address that we will scan past the right end of our chunk.
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   259
  HeapWord* max_to_do = NULL;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
  if (chunk_mr.end() < used.end()) {
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   261
    // This is not the last chunk in the used region.
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   262
    // What is our last block? We check the first block of
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   263
    // the next (right) chunk rather than strictly check our last block
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   264
    // because it's potentially more efficient to do so.
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   265
    HeapWord* const last_block = sp->block_start(chunk_mr.end());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    assert(last_block <= chunk_mr.end(), "In case this property changes.");
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   267
    if ((last_block == chunk_mr.end())     // our last block does not straddle boundary
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   268
        || !sp->block_is_obj(last_block)   // last_block isn't an object
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   269
        || oop(last_block)->is_objArray()  // last_block is an array (precisely marked)
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   270
        || oop(last_block)->is_typeArray()) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
      max_to_do = chunk_mr.end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    } else {
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   273
      assert(last_block < chunk_mr.end(), "Tautology");
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   274
      // It is a non-array object that straddles the right boundary of this chunk.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
      // last_obj_card is the card corresponding to the start of the last object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
      // in the chunk.  Note that the last object may not start in
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
      // the chunk.
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   278
      CardValue* const last_obj_card = byte_for(last_block);
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   279
      const CardValue val = *last_obj_card;
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   280
      if (!card_will_be_scanned(val)) {
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   281
        assert(!card_may_have_been_dirty(val), "Error");
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   282
        // The card containing the head is not dirty.  Any marks on
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
        // subsequent cards still in this chunk must have been made
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   284
        // precisely; we can cap processing at the end of our chunk.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
        max_to_do = chunk_mr.end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
        // The last object must be considered dirty, and extends onto the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
        // following chunk.  Look for a dirty card in that chunk that will
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
        // bound our processing.
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   290
        CardValue* limit_card = NULL;
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   291
        const size_t last_block_size = sp->block_size(last_block);
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   292
        CardValue* const last_card_of_last_obj =
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
          byte_for(last_block + last_block_size - 1);
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   294
        CardValue* const first_card_of_next_chunk = byte_for(chunk_mr.end());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
        // This search potentially goes a long distance looking
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   296
        // for the next card that will be scanned, terminating
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   297
        // at the end of the last_block, if no earlier dirty card
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   298
        // is found.
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   299
        assert(byte_for(chunk_mr.end()) - byte_for(chunk_mr.start()) == ParGCCardsPerStrideChunk,
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   300
               "last card of next chunk may be wrong");
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   301
        for (CardValue* cur = first_card_of_next_chunk;
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   302
             cur <= last_card_of_last_obj; cur++) {
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   303
          const CardValue val = *cur;
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   304
          if (card_will_be_scanned(val)) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
            limit_card = cur; break;
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   306
          } else {
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   307
            assert(!card_may_have_been_dirty(val), "Error: card can't be skipped");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
        }
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   310
        if (limit_card != NULL) {
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   311
          max_to_do = addr_for(limit_card);
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   312
          assert(limit_card != NULL && max_to_do != NULL, "Error");
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   313
        } else {
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   314
          // The following is a pessimistic value, because it's possible
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   315
          // that a dirty card on a subsequent chunk has been cleared by
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   316
          // the time we get to look at it; we'll correct for that further below,
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   317
          // using the LNC array which records the least non-clean card
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   318
          // before cards were cleared in a particular chunk.
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   319
          limit_card = last_card_of_last_obj;
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   320
          max_to_do = last_block + last_block_size;
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   321
          assert(limit_card != NULL && max_to_do != NULL, "Error");
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   322
        }
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   323
        assert(0 < cur_chunk_index+1 && cur_chunk_index+1 < lowest_non_clean_chunk_size,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
               "Bounds error.");
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   325
        // It is possible that a dirty card for the last object may have been
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   326
        // cleared before we had a chance to examine it. In that case, the value
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   327
        // will have been logged in the LNC for that chunk.
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   328
        // We need to examine as many chunks to the right as this object
9985
afffb17bb75a 7048782: CMS: assert(last_chunk_index_to_check<= last_chunk_index) failed: parCardTableModRefBS.cpp:359
ysr
parents: 9626
diff changeset
   329
        // covers. However, we need to bound this checking to the largest
afffb17bb75a 7048782: CMS: assert(last_chunk_index_to_check<= last_chunk_index) failed: parCardTableModRefBS.cpp:359
ysr
parents: 9626
diff changeset
   330
        // entry in the LNC array: this is because the heap may expand
afffb17bb75a 7048782: CMS: assert(last_chunk_index_to_check<= last_chunk_index) failed: parCardTableModRefBS.cpp:359
ysr
parents: 9626
diff changeset
   331
        // after the LNC array has been created but before we reach this point,
afffb17bb75a 7048782: CMS: assert(last_chunk_index_to_check<= last_chunk_index) failed: parCardTableModRefBS.cpp:359
ysr
parents: 9626
diff changeset
   332
        // and the last block in our chunk may have been expanded to include
afffb17bb75a 7048782: CMS: assert(last_chunk_index_to_check<= last_chunk_index) failed: parCardTableModRefBS.cpp:359
ysr
parents: 9626
diff changeset
   333
        // the expansion delta (and possibly subsequently allocated from, so
afffb17bb75a 7048782: CMS: assert(last_chunk_index_to_check<= last_chunk_index) failed: parCardTableModRefBS.cpp:359
ysr
parents: 9626
diff changeset
   334
        // it wouldn't be sufficient to check whether that last block was
afffb17bb75a 7048782: CMS: assert(last_chunk_index_to_check<= last_chunk_index) failed: parCardTableModRefBS.cpp:359
ysr
parents: 9626
diff changeset
   335
        // or was not an object at this point).
afffb17bb75a 7048782: CMS: assert(last_chunk_index_to_check<= last_chunk_index) failed: parCardTableModRefBS.cpp:359
ysr
parents: 9626
diff changeset
   336
        uintptr_t last_chunk_index_to_check = addr_to_chunk_index(last_block + last_block_size - 1)
afffb17bb75a 7048782: CMS: assert(last_chunk_index_to_check<= last_chunk_index) failed: parCardTableModRefBS.cpp:359
ysr
parents: 9626
diff changeset
   337
                                              - lowest_non_clean_base_chunk_index;
afffb17bb75a 7048782: CMS: assert(last_chunk_index_to_check<= last_chunk_index) failed: parCardTableModRefBS.cpp:359
ysr
parents: 9626
diff changeset
   338
        const uintptr_t last_chunk_index    = addr_to_chunk_index(used.last())
afffb17bb75a 7048782: CMS: assert(last_chunk_index_to_check<= last_chunk_index) failed: parCardTableModRefBS.cpp:359
ysr
parents: 9626
diff changeset
   339
                                              - lowest_non_clean_base_chunk_index;
afffb17bb75a 7048782: CMS: assert(last_chunk_index_to_check<= last_chunk_index) failed: parCardTableModRefBS.cpp:359
ysr
parents: 9626
diff changeset
   340
        if (last_chunk_index_to_check > last_chunk_index) {
afffb17bb75a 7048782: CMS: assert(last_chunk_index_to_check<= last_chunk_index) failed: parCardTableModRefBS.cpp:359
ysr
parents: 9626
diff changeset
   341
          assert(last_block + last_block_size > used.end(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31964
diff changeset
   342
                 "Inconsistency detected: last_block [" PTR_FORMAT "," PTR_FORMAT "]"
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31964
diff changeset
   343
                 " does not exceed used.end() = " PTR_FORMAT ","
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31964
diff changeset
   344
                 " yet last_chunk_index_to_check " INTPTR_FORMAT
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31964
diff changeset
   345
                 " exceeds last_chunk_index " INTPTR_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31964
diff changeset
   346
                 p2i(last_block), p2i(last_block + last_block_size),
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31964
diff changeset
   347
                 p2i(used.end()),
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31964
diff changeset
   348
                 last_chunk_index_to_check, last_chunk_index);
9985
afffb17bb75a 7048782: CMS: assert(last_chunk_index_to_check<= last_chunk_index) failed: parCardTableModRefBS.cpp:359
ysr
parents: 9626
diff changeset
   349
          assert(sp->used_region().end() > used.end(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31964
diff changeset
   350
                 "Expansion did not happen: "
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31964
diff changeset
   351
                 "[" PTR_FORMAT "," PTR_FORMAT ") -> [" PTR_FORMAT "," PTR_FORMAT ")",
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31964
diff changeset
   352
                 p2i(sp->used_region().start()), p2i(sp->used_region().end()),
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31964
diff changeset
   353
                 p2i(used.start()), p2i(used.end()));
9985
afffb17bb75a 7048782: CMS: assert(last_chunk_index_to_check<= last_chunk_index) failed: parCardTableModRefBS.cpp:359
ysr
parents: 9626
diff changeset
   354
          last_chunk_index_to_check = last_chunk_index;
afffb17bb75a 7048782: CMS: assert(last_chunk_index_to_check<= last_chunk_index) failed: parCardTableModRefBS.cpp:359
ysr
parents: 9626
diff changeset
   355
        }
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   356
        for (uintptr_t lnc_index = cur_chunk_index + 1;
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   357
             lnc_index <= last_chunk_index_to_check;
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   358
             lnc_index++) {
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   359
          CardValue* lnc_card = lowest_non_clean[lnc_index];
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
          if (lnc_card != NULL) {
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   361
            // we can stop at the first non-NULL entry we find
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   362
            if (lnc_card <= limit_card) {
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   363
              limit_card = lnc_card;
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   364
              max_to_do = addr_for(limit_card);
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   365
              assert(limit_card != NULL && max_to_do != NULL, "Error");
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   366
            }
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   367
            // In any case, we break now
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   368
            break;
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   369
          }  // else continue to look for a non-NULL entry if any
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
        }
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   371
        assert(limit_card != NULL && max_to_do != NULL, "Error");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
      }
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   373
      assert(max_to_do != NULL, "OOPS 1 !");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
    }
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   375
    assert(max_to_do != NULL, "OOPS 2!");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
    max_to_do = used.end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  }
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   379
  assert(max_to_do != NULL, "OOPS 3!");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  // Now we can set the closure we're using so it doesn't to beyond
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
  // max_to_do.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  dcto_cl->set_min_done(max_to_do);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  dcto_cl->set_last_bottom(max_to_do);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
#endif
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   386
}
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
void
49733
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
   389
CMSCardTable::
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
get_LNC_array_for_space(Space* sp,
54110
f4f0dce5d0bb 8220301: Remove jbyte use in CardTable
tschatzl
parents: 51598
diff changeset
   391
                        CardValue**& lowest_non_clean,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
                        uintptr_t& lowest_non_clean_base_chunk_index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
                        size_t& lowest_non_clean_chunk_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  int       i        = find_covering_region_containing(sp->bottom());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  MemRegion covered  = _covered[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  size_t    n_chunks = chunks_to_cover(covered);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  // Only the first thread to obtain the lock will resize the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  // LNC array for the covered region.  Any later expansion can't affect
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  // the used_at_save_marks region.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  // (I observed a bug in which the first thread to execute this would
9624
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   403
  // resize, and then it would cause "expand_and_allocate" that would
c3657c3324ee 6883834: ParNew: assert(!_g->to()->is_in_reserved(obj),"Scanning field twice?") with LargeObjects tests
ysr
parents: 9336
diff changeset
   404
  // increase the number of chunks in the covered region.  Then a second
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  // thread would come and execute this, see that the size didn't match,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  // and free and allocate again.  So the first thread would be using a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  // freed "_lowest_non_clean" array.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  // Do a dirty read here. If we pass the conditional then take the rare
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  // event lock and do the read again in case some other thread had already
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  // succeeded and done the resize.
47622
817f2a7019e4 8179387: Factor out CMS specific code from GenCollectedHeap into its own subclass
rkennke
parents: 47216
diff changeset
   412
  int cur_collection = CMSHeap::heap()->total_collections();
42632
c4f00b77b6d4 8170409: CMS: Crash in CardTableModRefBSForCTRS::process_chunk_boundaries
simonis
parents: 37055
diff changeset
   413
  // Updated _last_LNC_resizing_collection[i] must not be visible before
c4f00b77b6d4 8170409: CMS: Crash in CardTableModRefBSForCTRS::process_chunk_boundaries
simonis
parents: 37055
diff changeset
   414
  // _lowest_non_clean and friends are visible. Therefore use acquire/release
c4f00b77b6d4 8170409: CMS: Crash in CardTableModRefBSForCTRS::process_chunk_boundaries
simonis
parents: 37055
diff changeset
   415
  // to guarantee this on non TSO architecures.
c4f00b77b6d4 8170409: CMS: Crash in CardTableModRefBSForCTRS::process_chunk_boundaries
simonis
parents: 37055
diff changeset
   416
  if (OrderAccess::load_acquire(&_last_LNC_resizing_collection[i]) != cur_collection) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
    MutexLocker x(ParGCRareEvent_lock);
42632
c4f00b77b6d4 8170409: CMS: Crash in CardTableModRefBSForCTRS::process_chunk_boundaries
simonis
parents: 37055
diff changeset
   418
    // This load_acquire is here for clarity only. The MutexLocker already fences.
c4f00b77b6d4 8170409: CMS: Crash in CardTableModRefBSForCTRS::process_chunk_boundaries
simonis
parents: 37055
diff changeset
   419
    if (OrderAccess::load_acquire(&_last_LNC_resizing_collection[i]) != cur_collection) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
      if (_lowest_non_clean[i] == NULL ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
          n_chunks != _lowest_non_clean_chunk_size[i]) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
        // Should we delete the old?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
        if (_lowest_non_clean[i] != NULL) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
          assert(n_chunks != _lowest_non_clean_chunk_size[i],
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
                 "logical consequence");
27880
afb974a04396 8060074: os::free() takes MemoryTrackingLevel but doesn't need it
coleenp
parents: 24424
diff changeset
   427
          FREE_C_HEAP_ARRAY(CardPtr, _lowest_non_clean[i]);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
          _lowest_non_clean[i] = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
        // Now allocate a new one if necessary.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
        if (_lowest_non_clean[i] == NULL) {
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 11396
diff changeset
   432
          _lowest_non_clean[i]                  = NEW_C_HEAP_ARRAY(CardPtr, n_chunks, mtGC);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
          _lowest_non_clean_chunk_size[i]       = n_chunks;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
          _lowest_non_clean_base_chunk_index[i] = addr_to_chunk_index(covered.start());
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
          for (int j = 0; j < (int)n_chunks; j++)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
            _lowest_non_clean[i][j] = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
      }
42632
c4f00b77b6d4 8170409: CMS: Crash in CardTableModRefBSForCTRS::process_chunk_boundaries
simonis
parents: 37055
diff changeset
   439
      // Make sure this gets visible only after _lowest_non_clean* was initialized
c4f00b77b6d4 8170409: CMS: Crash in CardTableModRefBSForCTRS::process_chunk_boundaries
simonis
parents: 37055
diff changeset
   440
      OrderAccess::release_store(&_last_LNC_resizing_collection[i], cur_collection);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  // In any case, now do the initialization.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  lowest_non_clean                  = _lowest_non_clean[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
  lowest_non_clean_base_chunk_index = _lowest_non_clean_base_chunk_index[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  lowest_non_clean_chunk_size       = _lowest_non_clean_chunk_size[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
}
49733
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
   448
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
   449
#ifdef ASSERT
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
   450
void CMSCardTable::verify_used_region_at_save_marks(Space* sp) const {
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
   451
  MemRegion ur    = sp->used_region();
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
   452
  MemRegion urasm = sp->used_region_at_save_marks();
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
   453
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
   454
  if (!ur.contains(urasm)) {
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
   455
    log_warning(gc)("CMS+ParNew: Did you forget to call save_marks()? "
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
   456
                    "[" PTR_FORMAT ", " PTR_FORMAT ") is not contained in "
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
   457
                    "[" PTR_FORMAT ", " PTR_FORMAT ")",
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
   458
                    p2i(urasm.start()), p2i(urasm.end()), p2i(ur.start()), p2i(ur.end()));
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
   459
    MemRegion ur2 = sp->used_region();
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
   460
    MemRegion urasm2 = sp->used_region_at_save_marks();
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
   461
    if (!ur.equals(ur2)) {
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
   462
      log_warning(gc)("CMS+ParNew: Flickering used_region()!!");
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
   463
    }
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
   464
    if (!urasm.equals(urasm2)) {
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
   465
      log_warning(gc)("CMS+ParNew: Flickering used_region_at_save_marks()!!");
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
   466
    }
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
   467
    ShouldNotReachHere();
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
   468
  }
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
   469
}
6f0a3ea5ab75 8201209: Separate out CMS specific functions into CMSCardTable
stefank
parents: 49488
diff changeset
   470
#endif // ASSERT