src/hotspot/share/gc/shared/blockOffsetTable.cpp
author stefank
Thu, 22 Feb 2018 18:36:07 +0100
changeset 49047 8f004146e407
parent 47216 71c04702a3d5
child 58015 dd84de796f2c
permissions -rw-r--r--
8198515: Extract SoftReferencePolicy code out of CollectorPolicy Reviewed-by: pliden, sjohanss
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
46968
9119841280f4 8160399: is_oop_or_null involves undefined behavior
coleenp
parents: 35469
diff changeset
     2
 * Copyright (c) 2000, 2017, 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: 5402
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5402
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: 5402
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: 6258
diff changeset
    25
#include "precompiled.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29580
diff changeset
    26
#include "gc/shared/blockOffsetTable.inline.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29580
diff changeset
    27
#include "gc/shared/collectedHeap.inline.hpp"
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 29580
diff changeset
    28
#include "gc/shared/space.inline.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6258
diff changeset
    29
#include "memory/iterator.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6258
diff changeset
    30
#include "memory/universe.hpp"
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33105
diff changeset
    31
#include "logging/log.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6258
diff changeset
    32
#include "oops/oop.inline.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6258
diff changeset
    33
#include "runtime/java.hpp"
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 9969
diff changeset
    34
#include "services/memTracker.hpp"
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
//////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// BlockOffsetSharedArray
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
//////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
BlockOffsetSharedArray::BlockOffsetSharedArray(MemRegion reserved,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
                                               size_t init_word_size):
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  _reserved(reserved), _end(NULL)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  size_t size = compute_size(reserved.word_size());
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
  ReservedSpace rs(size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
  if (!rs.is_reserved()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
    vm_exit_during_initialization("Could not reserve enough space for heap offset array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  }
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 9969
diff changeset
    49
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 9969
diff changeset
    50
  MemTracker::record_virtual_memory_type((address)rs.base(), mtGC);
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 9969
diff changeset
    51
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  if (!_vs.initialize(rs, 0)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    vm_exit_during_initialization("Could not reserve enough space for heap offset array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  _offset_array = (u_char*)_vs.low_boundary();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  resize(init_word_size);
35061
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33105
diff changeset
    57
  log_trace(gc, bot)("BlockOffsetSharedArray::BlockOffsetSharedArray: ");
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33105
diff changeset
    58
  log_trace(gc, bot)("   rs.base(): " INTPTR_FORMAT " rs.size(): " INTPTR_FORMAT " rs end(): " INTPTR_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33105
diff changeset
    59
                     p2i(rs.base()), rs.size(), p2i(rs.base() + rs.size()));
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33105
diff changeset
    60
  log_trace(gc, bot)("   _vs.low_boundary(): " INTPTR_FORMAT "  _vs.high_boundary(): " INTPTR_FORMAT,
be6025ebffea 8145092: Use Unified Logging for the GC logging
brutisso
parents: 33105
diff changeset
    61
                     p2i(_vs.low_boundary()), p2i(_vs.high_boundary()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
void BlockOffsetSharedArray::resize(size_t new_word_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  assert(new_word_size <= _reserved.word_size(), "Resize larger than reserved");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  size_t new_size = compute_size(new_word_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  size_t old_size = _vs.committed_size();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  size_t delta;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  char* high = _vs.high();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  _end = _reserved.start() + new_word_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  if (new_size > old_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    delta = ReservedSpace::page_align_size_up(new_size - old_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    assert(delta > 0, "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
    if (!_vs.expand_by(delta)) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
      // Do better than this for Merlin
17087
f0b76c4c93a0 8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents: 13728
diff changeset
    76
      vm_exit_out_of_memory(delta, OOM_MMAP_ERROR, "offset table expansion");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
    assert(_vs.high() == high + delta, "invalid expansion");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
    delta = ReservedSpace::page_align_size_down(old_size - new_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
    if (delta == 0) return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    _vs.shrink_by(delta);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    assert(_vs.high() == high - delta, "invalid expansion");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
bool BlockOffsetSharedArray::is_card_boundary(HeapWord* p) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  assert(p >= _reserved.start(), "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
  size_t delta = pointer_delta(p, _reserved.start());
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
    90
  return (delta & right_n_bits((int)BOTConstants::LogN_words)) == (size_t)NoBits;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
//////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
// BlockOffsetArray
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
//////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
BlockOffsetArray::BlockOffsetArray(BlockOffsetSharedArray* array,
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
    99
                                   MemRegion mr, bool init_to_zero_) :
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
  BlockOffsetTable(mr.start(), mr.end()),
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   101
  _array(array)
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
{
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  assert(_bottom <= _end, "arguments out of order");
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   104
  set_init_to_zero(init_to_zero_);
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   105
  if (!init_to_zero_) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
    // initialize cards to point back to mr.start()
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   107
    set_remainder_to_point_to_start(mr.start() + BOTConstants::N_words, mr.end());
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
    _array->set_offset_array(0, 0);  // set first card to 0
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
// The arguments follow the normal convention of denoting
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
// a right-open interval: [start, end)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
BlockOffsetArray::
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   117
set_remainder_to_point_to_start(HeapWord* start, HeapWord* end, bool reducing) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   119
  check_reducing_assertion(reducing);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
  if (start >= end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
    // The start address is equal to the end address (or to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
    // the right of the end address) so there are not cards
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
    // that need to be updated..
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  // Write the backskip value for each region.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
  //    offset
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  //    card             2nd                       3rd
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  //     | +- 1st        |                         |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  //     v v             v                         v
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  //    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+     +-+-+-+-+-+-+-+-+-+-+-
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  //    |x|0|0|0|0|0|0|0|1|1|1|1|1|1| ... |1|1|1|1|2|2|2|2|2|2| ...
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  //    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+     +-+-+-+-+-+-+-+-+-+-+-
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  //    11              19                        75
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  //      12
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  //    offset card is the card that points to the start of an object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  //      x - offset value of offset card
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  //    1st - start of first logarithmic region
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  //      0 corresponds to logarithmic value N_words + 0 and 2**(3 * 0) = 1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  //    2nd - start of second logarithmic region
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  //      1 corresponds to logarithmic value N_words + 1 and 2**(3 * 1) = 8
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  //    3rd - start of third logarithmic region
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  //      2 corresponds to logarithmic value N_words + 2 and 2**(3 * 2) = 64
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  //    integer below the block offset entry is an example of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  //    the index of the entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  //    Given an address,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
  //      Find the index for the address
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
  //      Find the block offset table entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  //      Convert the entry to a back slide
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  //        (e.g., with today's, offset = 0x81 =>
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  //          back slip = 2**(3*(0x81 - N_words)) = 2**3) = 8
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  //      Move back N (e.g., 8) entries and repeat with the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  //        value of the new entry
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
  size_t start_card = _array->index_for(start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  size_t end_card = _array->index_for(end-1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  assert(start ==_array->address_for_index(start_card), "Precondition");
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   163
  assert(end ==_array->address_for_index(end_card)+BOTConstants::N_words, "Precondition");
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   164
  set_remainder_to_point_to_start_incl(start_card, end_card, reducing); // closed interval
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
// Unlike the normal convention in this code, the argument here denotes
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
// a closed, inclusive interval: [start_card, end_card], cf set_remainder_to_point_to_start()
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
// above.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
void
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   172
BlockOffsetArray::set_remainder_to_point_to_start_incl(size_t start_card, size_t end_card, bool reducing) {
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   173
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   174
  check_reducing_assertion(reducing);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  if (start_card > end_card) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  assert(start_card > _array->index_for(_bottom), "Cannot be first card");
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   179
  assert(_array->offset_array(start_card-1) <= BOTConstants::N_words,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    "Offset card has an unexpected value");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  size_t start_card_for_region = start_card;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
  u_char offset = max_jubyte;
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   183
  for (uint i = 0; i < BOTConstants::N_powers; i++) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    // -1 so that the the card with the actual offset is counted.  Another -1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
    // so that the reach ends in this region and not at the start
489c9b5090e2 Initial load
duke
parents:
diff changeset
   186
    // of the next.
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   187
    size_t reach = start_card - 1 + (BOTConstants::power_to_cards_back(i+1) - 1);
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   188
    offset = BOTConstants::N_words + i;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    if (reach >= end_card) {
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   190
      _array->set_offset_array(start_card_for_region, end_card, offset, reducing);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
      start_card_for_region = reach + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   192
      break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
    }
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   194
    _array->set_offset_array(start_card_for_region, reach, offset, reducing);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
    start_card_for_region = reach + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  assert(start_card_for_region > end_card, "Sanity check");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  DEBUG_ONLY(check_all_cards(start_card, end_card);)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
// The card-interval [start_card, end_card] is a closed interval; this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
// is an expensive check -- use with care and only under protection of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
// suitable flag.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
void BlockOffsetArray::check_all_cards(size_t start_card, size_t end_card) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  if (end_card < start_card) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  }
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   209
  guarantee(_array->offset_array(start_card) == BOTConstants::N_words, "Wrong value in second card");
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   210
  u_char last_entry = BOTConstants::N_words;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  for (size_t c = start_card + 1; c <= end_card; c++ /* yeah! */) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
    u_char entry = _array->offset_array(c);
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   213
    guarantee(entry >= last_entry, "Monotonicity");
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   214
    if (c - start_card > BOTConstants::power_to_cards_back(1)) {
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   215
      guarantee(entry > BOTConstants::N_words, "Should be in logarithmic region");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
    }
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   217
    size_t backskip = BOTConstants::entry_to_cards_back(entry);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
    size_t landing_card = c - backskip;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    guarantee(landing_card >= (start_card - 1), "Inv");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    if (landing_card >= start_card) {
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   221
      guarantee(_array->offset_array(landing_card) <= entry, "Monotonicity");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
    } else {
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   223
      guarantee(landing_card == (start_card - 1), "Tautology");
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   224
      // Note that N_words is the maximum offset value
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   225
      guarantee(_array->offset_array(landing_card) <= BOTConstants::N_words, "Offset value");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
    }
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   227
    last_entry = entry;  // remember for monotonicity test
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
BlockOffsetArray::alloc_block(HeapWord* blk_start, HeapWord* blk_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  assert(blk_start != NULL && blk_end > blk_start,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
         "phantom block");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
  single_block(blk_start, blk_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
// Action_mark - update the BOT for the block [blk_start, blk_end).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
//               Current typical use is for splitting a block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
// Action_single - udpate the BOT for an allocation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
// Action_verify - BOT verification.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
BlockOffsetArray::do_block_internal(HeapWord* blk_start,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
                                    HeapWord* blk_end,
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   246
                                    Action action, bool reducing) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
  assert(Universe::heap()->is_in_reserved(blk_start),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
         "reference must be into the heap");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  assert(Universe::heap()->is_in_reserved(blk_end-1),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
         "limit must be within the heap");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  // This is optimized to make the test fast, assuming we only rarely
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  // cross boundaries.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  uintptr_t end_ui = (uintptr_t)(blk_end - 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  uintptr_t start_ui = (uintptr_t)blk_start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
  // Calculate the last card boundary preceding end of blk
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  intptr_t boundary_before_end = (intptr_t)end_ui;
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   257
  clear_bits(boundary_before_end, right_n_bits((int)BOTConstants::LogN));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  if (start_ui <= (uintptr_t)boundary_before_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
    // blk starts at or crosses a boundary
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
    // Calculate index of card on which blk begins
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
    size_t    start_index = _array->index_for(blk_start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
    // Index of card on which blk ends
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
    size_t    end_index   = _array->index_for(blk_end - 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
    // Start address of card on which blk begins
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
    HeapWord* boundary    = _array->address_for_index(start_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
    assert(boundary <= blk_start, "blk should start at or after boundary");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
    if (blk_start != boundary) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
      // blk starts strictly after boundary
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
      // adjust card boundary and start_index forward to next card
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   270
      boundary += BOTConstants::N_words;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
      start_index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    assert(start_index <= end_index, "monotonicity of index_for()");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
    assert(boundary <= (HeapWord*)boundary_before_end, "tautology");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
    switch (action) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
      case Action_mark: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
        if (init_to_zero()) {
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   278
          _array->set_offset_array(start_index, boundary, blk_start, reducing);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
          break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
        } // Else fall through to the next case
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
      case Action_single: {
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   283
        _array->set_offset_array(start_index, boundary, blk_start, reducing);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
        // We have finished marking the "offset card". We need to now
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
        // mark the subsequent cards that this blk spans.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
        if (start_index < end_index) {
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   287
          HeapWord* rem_st = _array->address_for_index(start_index) + BOTConstants::N_words;
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   288
          HeapWord* rem_end = _array->address_for_index(end_index) + BOTConstants::N_words;
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   289
          set_remainder_to_point_to_start(rem_st, rem_end, reducing);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
      case Action_check: {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
        _array->check_offset_array(start_index, boundary, blk_start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
        // We have finished checking the "offset card". We need to now
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
        // check the subsequent cards that this blk spans.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
        check_all_cards(start_index + 1, end_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
        break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
      default:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
        ShouldNotReachHere();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
// The range [blk_start, blk_end) represents a single contiguous block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
// of storage; modify the block offset table to represent this
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
// information; Right-open interval: [blk_start, blk_end)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
// NOTE: this method does _not_ adjust _unallocated_block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
BlockOffsetArray::single_block(HeapWord* blk_start,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
                               HeapWord* blk_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
  do_block_internal(blk_start, blk_end, Action_single);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
void BlockOffsetArray::verify() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  // For each entry in the block offset table, verify that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  // the entry correctly finds the start of an object at the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  // first address covered by the block or to the left of that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
  // first address.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  size_t next_index = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
  size_t last_index = last_active_index();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  // Use for debugging.  Initialize to NULL to distinguish the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  // first iteration through the while loop.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  HeapWord* last_p = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  HeapWord* last_start = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  oop last_o = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
  while (next_index <= last_index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
    // Use an address past the start of the address for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
    // the entry.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
    HeapWord* p = _array->address_for_index(next_index) + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
    if (p >= _end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
      // That's all of the allocated block table.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
      return;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   338
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    // block_start() asserts that start <= p.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
    HeapWord* start = block_start(p);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
    // First check if the start is an allocated block and only
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
    // then if it is a valid object.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
    oop o = oop(start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
    assert(!Universe::is_fully_initialized() ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
           _sp->is_free_block(start) ||
46968
9119841280f4 8160399: is_oop_or_null involves undefined behavior
coleenp
parents: 35469
diff changeset
   346
           oopDesc::is_oop_or_null(o), "Bad object was found");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
    next_index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
    last_p = p;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
    last_start = start;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
    last_o = o;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
//////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
// BlockOffsetArrayNonContigSpace
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
//////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
// The block [blk_start, blk_end) has been allocated;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
// adjust the block offset table to represent this information;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
// NOTE: Clients of BlockOffsetArrayNonContigSpace: consider using
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
// the somewhat more lightweight split_block() or
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
// (when init_to_zero()) mark_block() wherever possible.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
// right-open interval: [blk_start, blk_end)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
BlockOffsetArrayNonContigSpace::alloc_block(HeapWord* blk_start,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
                                            HeapWord* blk_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  assert(blk_start != NULL && blk_end > blk_start,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
         "phantom block");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
  single_block(blk_start, blk_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  allocated(blk_start, blk_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
// Adjust BOT to show that a previously whole block has been split
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
// into two.  We verify the BOT for the first part (prefix) and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
// update the  BOT for the second part (suffix).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
//      blk is the start of the block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
//      blk_size is the size of the original block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
//      left_blk_size is the size of the first part of the split
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
void BlockOffsetArrayNonContigSpace::split_block(HeapWord* blk,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
                                                 size_t blk_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
                                                 size_t left_blk_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  // Verify that the BOT shows [blk, blk + blk_size) to be one block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
  verify_single_block(blk, blk_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  // Update the BOT to indicate that [blk + left_blk_size, blk + blk_size)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  // is one single block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  assert(blk_size > 0, "Should be positive");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
  assert(left_blk_size > 0, "Should be positive");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  assert(left_blk_size < blk_size, "Not a split");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  // Start addresses of prefix block and suffix block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
  HeapWord* pref_addr = blk;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  HeapWord* suff_addr = blk + left_blk_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  HeapWord* end_addr  = blk + blk_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  // Indices for starts of prefix block and suffix block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  size_t pref_index = _array->index_for(pref_addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
  if (_array->address_for_index(pref_index) != pref_addr) {
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   398
    // pref_addr does not begin pref_index
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
    pref_index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  size_t suff_index = _array->index_for(suff_addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  if (_array->address_for_index(suff_index) != suff_addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
    // suff_addr does not begin suff_index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
    suff_index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  // Definition: A block B, denoted [B_start, B_end) __starts__
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  //     a card C, denoted [C_start, C_end), where C_start and C_end
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  //     are the heap addresses that card C covers, iff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
  //     B_start <= C_start < B_end.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  //     We say that a card C "is started by" a block B, iff
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  //     B "starts" C.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  //     Note that the cardinality of the set of cards {C}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  //     started by a block B can be 0, 1, or more.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
  // Below, pref_index and suff_index are, respectively, the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  // first (least) card indices that the prefix and suffix of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  // the split start; end_index is one more than the index of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
  // the last (greatest) card that blk starts.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  size_t end_index  = _array->index_for(end_addr - 1) + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
  // Calculate the # cards that the prefix and suffix affect.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  size_t num_pref_cards = suff_index - pref_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  size_t num_suff_cards = end_index  - suff_index;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
  // Change the cards that need changing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  if (num_suff_cards > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
    HeapWord* boundary = _array->address_for_index(suff_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
    // Set the offset card for suffix block
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   433
    _array->set_offset_array(suff_index, boundary, suff_addr, true /* reducing */);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
    // Change any further cards that need changing in the suffix
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
    if (num_pref_cards > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
      if (num_pref_cards >= num_suff_cards) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
        // Unilaterally fix all of the suffix cards: closed card
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
        // index interval in args below.
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   439
        set_remainder_to_point_to_start_incl(suff_index + 1, end_index - 1, true /* reducing */);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
      } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
        // Unilaterally fix the first (num_pref_cards - 1) following
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
        // the "offset card" in the suffix block.
32746
11ab01b37e82 8081629: CMS split_block() does not correctly fix up block-offset-table for large blocks
jmasa
parents: 31592
diff changeset
   443
        const size_t right_most_fixed_index = suff_index + num_pref_cards - 1;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
        set_remainder_to_point_to_start_incl(suff_index + 1,
32746
11ab01b37e82 8081629: CMS split_block() does not correctly fix up block-offset-table for large blocks
jmasa
parents: 31592
diff changeset
   445
          right_most_fixed_index, true /* reducing */);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
        // Fix the appropriate cards in the remainder of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
        // suffix block -- these are the last num_pref_cards
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
        // cards in each power block of the "new" range plumbed
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
        // from suff_addr.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
        bool more = true;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
        uint i = 1;
32746
11ab01b37e82 8081629: CMS split_block() does not correctly fix up block-offset-table for large blocks
jmasa
parents: 31592
diff changeset
   452
        // Fix the first power block with  back_by > num_pref_cards.
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   453
        while (more && (i < BOTConstants::N_powers)) {
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   454
          size_t back_by = BOTConstants::power_to_cards_back(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
          size_t right_index = suff_index + back_by - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
          size_t left_index  = right_index - num_pref_cards + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
          if (right_index >= end_index - 1) { // last iteration
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
            right_index = end_index - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
            more = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
          }
32746
11ab01b37e82 8081629: CMS split_block() does not correctly fix up block-offset-table for large blocks
jmasa
parents: 31592
diff changeset
   461
          if (left_index <= right_most_fixed_index) {
11ab01b37e82 8081629: CMS split_block() does not correctly fix up block-offset-table for large blocks
jmasa
parents: 31592
diff changeset
   462
                left_index = right_most_fixed_index + 1;
11ab01b37e82 8081629: CMS split_block() does not correctly fix up block-offset-table for large blocks
jmasa
parents: 31592
diff changeset
   463
          }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
          if (back_by > num_pref_cards) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   465
            // Fill in the remainder of this "power block", if it
489c9b5090e2 Initial load
duke
parents:
diff changeset
   466
            // is non-null.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   467
            if (left_index <= right_index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
              _array->set_offset_array(left_index, right_index,
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   469
                                       BOTConstants::N_words + i - 1, true /* reducing */);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
            } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
              more = false; // we are done
32746
11ab01b37e82 8081629: CMS split_block() does not correctly fix up block-offset-table for large blocks
jmasa
parents: 31592
diff changeset
   472
              assert((end_index - 1) == right_index, "Must be at the end.");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   474
            i++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
            break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
          i++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
        }
32746
11ab01b37e82 8081629: CMS split_block() does not correctly fix up block-offset-table for large blocks
jmasa
parents: 31592
diff changeset
   479
        // Fix the rest of the power blocks.
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   480
        while (more && (i < BOTConstants::N_powers)) {
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   481
          size_t back_by = BOTConstants::power_to_cards_back(i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   482
          size_t right_index = suff_index + back_by - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   483
          size_t left_index  = right_index - num_pref_cards + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
          if (right_index >= end_index - 1) { // last iteration
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
            right_index = end_index - 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
            if (left_index > right_index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   487
              break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
            }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
            more  = false;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
          }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
          assert(left_index <= right_index, "Error");
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   492
          _array->set_offset_array(left_index, right_index, BOTConstants::N_words + i - 1, true /* reducing */);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
          i++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
    } // else no more cards to fix in suffix
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  } // else nothing needs to be done
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  // Verify that we did the right thing
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
  verify_single_block(pref_addr, left_blk_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
  verify_single_block(suff_addr, blk_size - left_blk_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
// Mark the BOT such that if [blk_start, blk_end) straddles a card
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
// boundary, the card following the first such boundary is marked
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
// with the appropriate offset.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
// NOTE: this method does _not_ adjust _unallocated_block or
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
// any cards subsequent to the first one.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
void
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
BlockOffsetArrayNonContigSpace::mark_block(HeapWord* blk_start,
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   511
                                           HeapWord* blk_end, bool reducing) {
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   512
  do_block_internal(blk_start, blk_end, Action_mark, reducing);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
HeapWord* BlockOffsetArrayNonContigSpace::block_start_unsafe(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
  const void* addr) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
  assert(_array->offset_array(0) == 0, "objects can't cross covered areas");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
  assert(_bottom <= addr && addr < _end,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
         "addr must be covered by this Array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
  // Must read this exactly once because it can be modified by parallel
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  // allocation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
  HeapWord* ub = _unallocated_block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
  if (BlockOffsetArrayUseUnallocatedBlock && addr >= ub) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
    assert(ub < _end, "tautology (see above)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
    return ub;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
  // Otherwise, find the block start using the table.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
  size_t index = _array->index_for(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
  HeapWord* q = _array->address_for_index(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
  uint offset = _array->offset_array(index);    // Extend u_char to uint.
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   533
  while (offset >= BOTConstants::N_words) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
    // The excess of the offset from N_words indicates a power of Base
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
    // to go back by.
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   536
    size_t n_cards_back = BOTConstants::entry_to_cards_back(offset);
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   537
    q -= (BOTConstants::N_words * n_cards_back);
9626
f3e12dc58265 7043891: CMS: assert(_whole_heap.contains(p)) failed: out of bounds access to card marking array
ysr
parents: 7397
diff changeset
   538
    assert(q >= _sp->bottom(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32746
diff changeset
   539
           "q = " PTR_FORMAT " crossed below bottom = " PTR_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32746
diff changeset
   540
           p2i(q), p2i(_sp->bottom()));
9626
f3e12dc58265 7043891: CMS: assert(_whole_heap.contains(p)) failed: out of bounds access to card marking array
ysr
parents: 7397
diff changeset
   541
    assert(q < _sp->end(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32746
diff changeset
   542
           "q = " PTR_FORMAT " crossed above end = " PTR_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32746
diff changeset
   543
           p2i(q), p2i(_sp->end()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
    index -= n_cards_back;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
    offset = _array->offset_array(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
  }
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   547
  assert(offset < BOTConstants::N_words, "offset too large");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
  index--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
  q -= offset;
9626
f3e12dc58265 7043891: CMS: assert(_whole_heap.contains(p)) failed: out of bounds access to card marking array
ysr
parents: 7397
diff changeset
   550
  assert(q >= _sp->bottom(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32746
diff changeset
   551
         "q = " PTR_FORMAT " crossed below bottom = " PTR_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32746
diff changeset
   552
         p2i(q), p2i(_sp->bottom()));
9626
f3e12dc58265 7043891: CMS: assert(_whole_heap.contains(p)) failed: out of bounds access to card marking array
ysr
parents: 7397
diff changeset
   553
  assert(q < _sp->end(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32746
diff changeset
   554
         "q = " PTR_FORMAT " crossed above end = " PTR_FORMAT,
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32746
diff changeset
   555
         p2i(q), p2i(_sp->end()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
  HeapWord* n = q;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
  while (n <= addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
    debug_only(HeapWord* last = q);   // for debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
    q = n;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
    n += _sp->block_size(n);
9626
f3e12dc58265 7043891: CMS: assert(_whole_heap.contains(p)) failed: out of bounds access to card marking array
ysr
parents: 7397
diff changeset
   562
    assert(n > q,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32746
diff changeset
   563
           "Looping at n = " PTR_FORMAT " with last = " PTR_FORMAT ","
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32746
diff changeset
   564
           " while querying blk_start(" PTR_FORMAT ")"
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32746
diff changeset
   565
           " on _sp = [" PTR_FORMAT "," PTR_FORMAT ")",
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32746
diff changeset
   566
           p2i(n), p2i(last), p2i(addr), p2i(_sp->bottom()), p2i(_sp->end()));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   567
  }
9969
57932d7294a9 7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents: 9626
diff changeset
   568
  assert(q <= addr,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32746
diff changeset
   569
         "wrong order for current (" INTPTR_FORMAT ")" " <= arg (" INTPTR_FORMAT ")",
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32746
diff changeset
   570
         p2i(q), p2i(addr));
9969
57932d7294a9 7042740: CMS: assert(n> q) failed: Looping at: ... blockOffsetTable.cpp:557
ysr
parents: 9626
diff changeset
   571
  assert(addr <= n,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32746
diff changeset
   572
         "wrong order for arg (" INTPTR_FORMAT ") <= next (" INTPTR_FORMAT ")",
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 32746
diff changeset
   573
         p2i(addr), p2i(n));
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   574
  return q;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   575
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   576
489c9b5090e2 Initial load
duke
parents:
diff changeset
   577
HeapWord* BlockOffsetArrayNonContigSpace::block_start_careful(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   578
  const void* addr) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   579
  assert(_array->offset_array(0) == 0, "objects can't cross covered areas");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   580
489c9b5090e2 Initial load
duke
parents:
diff changeset
   581
  assert(_bottom <= addr && addr < _end,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   582
         "addr must be covered by this Array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   583
  // Must read this exactly once because it can be modified by parallel
489c9b5090e2 Initial load
duke
parents:
diff changeset
   584
  // allocation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   585
  HeapWord* ub = _unallocated_block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   586
  if (BlockOffsetArrayUseUnallocatedBlock && addr >= ub) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   587
    assert(ub < _end, "tautology (see above)");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   588
    return ub;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   589
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   590
489c9b5090e2 Initial load
duke
parents:
diff changeset
   591
  // Otherwise, find the block start using the table, but taking
489c9b5090e2 Initial load
duke
parents:
diff changeset
   592
  // care (cf block_start_unsafe() above) not to parse any objects/blocks
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 22234
diff changeset
   593
  // on the cards themselves.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   594
  size_t index = _array->index_for(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   595
  assert(_array->address_for_index(index) == addr,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   596
         "arg should be start of card");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   597
489c9b5090e2 Initial load
duke
parents:
diff changeset
   598
  HeapWord* q = (HeapWord*)addr;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   599
  uint offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   600
  do {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   601
    offset = _array->offset_array(index);
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   602
    if (offset < BOTConstants::N_words) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   603
      q -= offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   604
    } else {
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   605
      size_t n_cards_back = BOTConstants::entry_to_cards_back(offset);
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   606
      q -= (n_cards_back * BOTConstants::N_words);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   607
      index -= n_cards_back;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   608
    }
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   609
  } while (offset >= BOTConstants::N_words);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   610
  assert(q <= addr, "block start should be to left of arg");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   611
  return q;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   612
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   613
489c9b5090e2 Initial load
duke
parents:
diff changeset
   614
#ifndef PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   615
// Verification & debugging - ensure that the offset table reflects the fact
489c9b5090e2 Initial load
duke
parents:
diff changeset
   616
// that the block [blk_start, blk_end) or [blk, blk + size) is a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   617
// single block of storage. NOTE: can't const this because of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   618
// call to non-const do_block_internal() below.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   619
void BlockOffsetArrayNonContigSpace::verify_single_block(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   620
  HeapWord* blk_start, HeapWord* blk_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   621
  if (VerifyBlockOffsetArray) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   622
    do_block_internal(blk_start, blk_end, Action_check);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   623
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   624
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   625
489c9b5090e2 Initial load
duke
parents:
diff changeset
   626
void BlockOffsetArrayNonContigSpace::verify_single_block(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   627
  HeapWord* blk, size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   628
  verify_single_block(blk, blk + size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   629
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   630
489c9b5090e2 Initial load
duke
parents:
diff changeset
   631
// Verify that the given block is before _unallocated_block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   632
void BlockOffsetArrayNonContigSpace::verify_not_unallocated(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   633
  HeapWord* blk_start, HeapWord* blk_end) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   634
  if (BlockOffsetArrayUseUnallocatedBlock) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   635
    assert(blk_start < blk_end, "Block inconsistency?");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   636
    assert(blk_end <= _unallocated_block, "_unallocated_block problem");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   637
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   638
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   639
489c9b5090e2 Initial load
duke
parents:
diff changeset
   640
void BlockOffsetArrayNonContigSpace::verify_not_unallocated(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   641
  HeapWord* blk, size_t size) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   642
  verify_not_unallocated(blk, blk + size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   643
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   644
#endif // PRODUCT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   645
489c9b5090e2 Initial load
duke
parents:
diff changeset
   646
size_t BlockOffsetArrayNonContigSpace::last_active_index() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   647
  if (_unallocated_block == _bottom) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   648
    return 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   649
  } else {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   650
    return _array->index_for(_unallocated_block - 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   651
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   652
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   653
489c9b5090e2 Initial load
duke
parents:
diff changeset
   654
//////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   655
// BlockOffsetArrayContigSpace
489c9b5090e2 Initial load
duke
parents:
diff changeset
   656
//////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   657
489c9b5090e2 Initial load
duke
parents:
diff changeset
   658
HeapWord* BlockOffsetArrayContigSpace::block_start_unsafe(const void* addr) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   659
  assert(_array->offset_array(0) == 0, "objects can't cross covered areas");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   660
489c9b5090e2 Initial load
duke
parents:
diff changeset
   661
  // Otherwise, find the block start using the table.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   662
  assert(_bottom <= addr && addr < _end,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   663
         "addr must be covered by this Array");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   664
  size_t index = _array->index_for(addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   665
  // We must make sure that the offset table entry we use is valid.  If
489c9b5090e2 Initial load
duke
parents:
diff changeset
   666
  // "addr" is past the end, start at the last known one and go forward.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   667
  index = MIN2(index, _next_offset_index-1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   668
  HeapWord* q = _array->address_for_index(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   669
489c9b5090e2 Initial load
duke
parents:
diff changeset
   670
  uint offset = _array->offset_array(index);    // Extend u_char to uint.
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   671
  while (offset > BOTConstants::N_words) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   672
    // The excess of the offset from N_words indicates a power of Base
489c9b5090e2 Initial load
duke
parents:
diff changeset
   673
    // to go back by.
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   674
    size_t n_cards_back = BOTConstants::entry_to_cards_back(offset);
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   675
    q -= (BOTConstants::N_words * n_cards_back);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   676
    assert(q >= _sp->bottom(), "Went below bottom!");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   677
    index -= n_cards_back;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   678
    offset = _array->offset_array(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   679
  }
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   680
  while (offset == BOTConstants::N_words) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   681
    assert(q >= _sp->bottom(), "Went below bottom!");
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   682
    q -= BOTConstants::N_words;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   683
    index--;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   684
    offset = _array->offset_array(index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   685
  }
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   686
  assert(offset < BOTConstants::N_words, "offset too large");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   687
  q -= offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   688
  HeapWord* n = q;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   689
489c9b5090e2 Initial load
duke
parents:
diff changeset
   690
  while (n <= addr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   691
    debug_only(HeapWord* last = q);   // for debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   692
    q = n;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   693
    n += _sp->block_size(n);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   694
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   695
  assert(q <= addr, "wrong order for current and arg");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   696
  assert(addr <= n, "wrong order for arg and next");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   697
  return q;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   698
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   699
489c9b5090e2 Initial load
duke
parents:
diff changeset
   700
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   701
//              _next_offset_threshold
489c9b5090e2 Initial load
duke
parents:
diff changeset
   702
//              |   _next_offset_index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   703
//              v   v
489c9b5090e2 Initial load
duke
parents:
diff changeset
   704
//      +-------+-------+-------+-------+-------+
489c9b5090e2 Initial load
duke
parents:
diff changeset
   705
//      | i-1   |   i   | i+1   | i+2   | i+3   |
489c9b5090e2 Initial load
duke
parents:
diff changeset
   706
//      +-------+-------+-------+-------+-------+
489c9b5090e2 Initial load
duke
parents:
diff changeset
   707
//       ( ^    ]
489c9b5090e2 Initial load
duke
parents:
diff changeset
   708
//         block-start
489c9b5090e2 Initial load
duke
parents:
diff changeset
   709
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   710
489c9b5090e2 Initial load
duke
parents:
diff changeset
   711
void BlockOffsetArrayContigSpace::alloc_block_work(HeapWord* blk_start,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   712
                                        HeapWord* blk_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   713
  assert(blk_start != NULL && blk_end > blk_start,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   714
         "phantom block");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   715
  assert(blk_end > _next_offset_threshold,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   716
         "should be past threshold");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   717
  assert(blk_start <= _next_offset_threshold,
5402
c51fd0c1d005 6888953: some calls to function-like macros are missing semicolons
jcoomes
parents: 1374
diff changeset
   718
         "blk_start should be at or before threshold");
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   719
  assert(pointer_delta(_next_offset_threshold, blk_start) <= BOTConstants::N_words,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   720
         "offset should be <= BlockOffsetSharedArray::N");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   721
  assert(Universe::heap()->is_in_reserved(blk_start),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   722
         "reference must be into the heap");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   723
  assert(Universe::heap()->is_in_reserved(blk_end-1),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   724
         "limit must be within the heap");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   725
  assert(_next_offset_threshold ==
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   726
         _array->_reserved.start() + _next_offset_index*BOTConstants::N_words,
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   727
         "index must agree with threshold");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   728
489c9b5090e2 Initial load
duke
parents:
diff changeset
   729
  debug_only(size_t orig_next_offset_index = _next_offset_index;)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   730
489c9b5090e2 Initial load
duke
parents:
diff changeset
   731
  // Mark the card that holds the offset into the block.  Note
489c9b5090e2 Initial load
duke
parents:
diff changeset
   732
  // that _next_offset_index and _next_offset_threshold are not
489c9b5090e2 Initial load
duke
parents:
diff changeset
   733
  // updated until the end of this method.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   734
  _array->set_offset_array(_next_offset_index,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   735
                           _next_offset_threshold,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   736
                           blk_start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   737
489c9b5090e2 Initial load
duke
parents:
diff changeset
   738
  // We need to now mark the subsequent cards that this blk spans.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   739
489c9b5090e2 Initial load
duke
parents:
diff changeset
   740
  // Index of card on which blk ends.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   741
  size_t end_index   = _array->index_for(blk_end - 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   742
489c9b5090e2 Initial load
duke
parents:
diff changeset
   743
  // Are there more cards left to be updated?
489c9b5090e2 Initial load
duke
parents:
diff changeset
   744
  if (_next_offset_index + 1 <= end_index) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   745
    HeapWord* rem_st  = _array->address_for_index(_next_offset_index + 1);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   746
    // Calculate rem_end this way because end_index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   747
    // may be the last valid index in the covered region.
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   748
    HeapWord* rem_end = _array->address_for_index(end_index) +  BOTConstants::N_words;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   749
    set_remainder_to_point_to_start(rem_st, rem_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   750
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   751
489c9b5090e2 Initial load
duke
parents:
diff changeset
   752
  // _next_offset_index and _next_offset_threshold updated here.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   753
  _next_offset_index = end_index + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   754
  // Calculate _next_offset_threshold this way because end_index
489c9b5090e2 Initial load
duke
parents:
diff changeset
   755
  // may be the last valid index in the covered region.
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   756
  _next_offset_threshold = _array->address_for_index(end_index) + BOTConstants::N_words;
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   757
  assert(_next_offset_threshold >= blk_end, "Incorrect offset threshold");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   758
489c9b5090e2 Initial load
duke
parents:
diff changeset
   759
#ifdef ASSERT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   760
  // The offset can be 0 if the block starts on a boundary.  That
489c9b5090e2 Initial load
duke
parents:
diff changeset
   761
  // is checked by an assertion above.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   762
  size_t start_index = _array->index_for(blk_start);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   763
  HeapWord* boundary    = _array->address_for_index(start_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   764
  assert((_array->offset_array(orig_next_offset_index) == 0 &&
489c9b5090e2 Initial load
duke
parents:
diff changeset
   765
          blk_start == boundary) ||
489c9b5090e2 Initial load
duke
parents:
diff changeset
   766
          (_array->offset_array(orig_next_offset_index) > 0 &&
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   767
         _array->offset_array(orig_next_offset_index) <= BOTConstants::N_words),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   768
         "offset array should have been set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   769
  for (size_t j = orig_next_offset_index + 1; j <= end_index; j++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   770
    assert(_array->offset_array(j) > 0 &&
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35061
diff changeset
   771
           _array->offset_array(j) <= (u_char) (BOTConstants::N_words+BOTConstants::N_powers-1),
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   772
           "offset array should have been set");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   773
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   774
#endif
489c9b5090e2 Initial load
duke
parents:
diff changeset
   775
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   776
489c9b5090e2 Initial load
duke
parents:
diff changeset
   777
HeapWord* BlockOffsetArrayContigSpace::initialize_threshold() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   778
  assert(!Universe::heap()->is_in_reserved(_array->_offset_array),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   779
         "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   780
  _next_offset_index = _array->index_for(_bottom);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   781
  _next_offset_index++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   782
  _next_offset_threshold =
489c9b5090e2 Initial load
duke
parents:
diff changeset
   783
    _array->address_for_index(_next_offset_index);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   784
  return _next_offset_threshold;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   785
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   786
489c9b5090e2 Initial load
duke
parents:
diff changeset
   787
void BlockOffsetArrayContigSpace::zero_bottom_entry() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   788
  assert(!Universe::heap()->is_in_reserved(_array->_offset_array),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   789
         "just checking");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   790
  size_t bottom_index = _array->index_for(_bottom);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   791
  _array->set_offset_array(bottom_index, 0);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   792
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
   793
489c9b5090e2 Initial load
duke
parents:
diff changeset
   794
size_t BlockOffsetArrayContigSpace::last_active_index() const {
29580
a67a581cfe11 8073315: Enable gcc -Wtype-limits and fix upcoming issues.
goetz
parents: 24424
diff changeset
   795
  return _next_offset_index == 0 ? 0 : _next_offset_index - 1;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   796
}