src/hotspot/share/gc/shared/blockOffsetTable.hpp
author lkorinth
Wed, 13 Nov 2019 11:37:29 +0100
changeset 59053 ba6c248cae19
parent 53244 9807daeb47c4
permissions -rw-r--r--
8232365: Implementation for JEP 363: Remove the Concurrent Mark Sweep (CMS) Garbage Collector Reviewed-by: kbarrett, tschatzl, erikj, coleenp, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53149
259c36ef27df 8215731: Move forward class definitions out of globalDefinitions.hpp
coleenp
parents: 49982
diff changeset
     2
 * Copyright (c) 2000, 2019, 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: 5431
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 5431
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: 5431
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
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 53149
diff changeset
    25
#ifndef SHARE_GC_SHARED_BLOCKOFFSETTABLE_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 53149
diff changeset
    26
#define SHARE_GC_SHARED_BLOCKOFFSETTABLE_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6274
diff changeset
    27
32598
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents: 30764
diff changeset
    28
#include "gc/shared/memset_with_concurrent_readers.hpp"
49392
2956d0ece7a9 8199282: Remove ValueObj class for allocation subclassing for gc code
coleenp
parents: 47216
diff changeset
    29
#include "memory/allocation.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6274
diff changeset
    30
#include "memory/memRegion.hpp"
30291
54cdc5c1a9cb 8068352: Move virtualspace.* out of src/share/vm/runtime to memory directory
coleenp
parents: 27899
diff changeset
    31
#include "memory/virtualspace.hpp"
32598
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents: 30764
diff changeset
    32
#include "runtime/globals.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6274
diff changeset
    33
#include "utilities/globalDefinitions.hpp"
32598
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents: 30764
diff changeset
    34
#include "utilities/macros.hpp"
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6274
diff changeset
    35
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// The CollectedHeap type requires subtypes to implement a method
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
// "block_start".  For some subtypes, notably generational
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// systems using card-table-based write barriers, the efficiency of this
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
// operation may be important.  Implementations of the "BlockOffsetArray"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
// class may be useful in providing such efficient implementations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
// BlockOffsetTable (abstract)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
//   - BlockOffsetArray (abstract)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
//     - BlockOffsetArrayContigSpace
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
class ContiguousSpace;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
    49
class BOTConstants : public AllStatic {
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
    50
public:
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
    51
  static const uint LogN = 9;
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
    52
  static const uint LogN_words = LogN - LogHeapWordSize;
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
    53
  static const uint N_bytes = 1 << LogN;
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
    54
  static const uint N_words = 1 << LogN_words;
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
    55
  // entries "e" of at least N_words mean "go back by Base^(e-N_words)."
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
    56
  // All entries are less than "N_words + N_powers".
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
    57
  static const uint LogBase = 4;
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
    58
  static const uint Base = (1 << LogBase);
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
    59
  static const uint N_powers = 14;
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
    60
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
    61
  static size_t power_to_cards_back(uint i) {
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
    62
    return (size_t)1 << (LogBase * i);
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
    63
  }
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
    64
  static size_t power_to_words_back(uint i) {
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
    65
    return power_to_cards_back(i) * N_words;
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
    66
  }
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
    67
  static size_t entry_to_cards_back(u_char entry) {
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
    68
    assert(entry >= N_words, "Precondition");
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
    69
    return power_to_cards_back(entry - N_words);
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
    70
  }
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
    71
  static size_t entry_to_words_back(u_char entry) {
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
    72
    assert(entry >= N_words, "Precondition");
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
    73
    return power_to_words_back(entry - N_words);
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
    74
  }
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
    75
};
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
    76
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
//////////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
// The BlockOffsetTable "interface"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
//////////////////////////////////////////////////////////////////////////
49392
2956d0ece7a9 8199282: Remove ValueObj class for allocation subclassing for gc code
coleenp
parents: 47216
diff changeset
    80
class BlockOffsetTable {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
  // These members describe the region covered by the table.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
  // The space this table is covering.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
  HeapWord* _bottom;    // == reserved.start
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  HeapWord* _end;       // End of currently allocated region.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  // Initialize the table to cover the given space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
  // The contents of the initial table are undefined.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
  BlockOffsetTable(HeapWord* bottom, HeapWord* end):
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
    _bottom(bottom), _end(end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
    assert(_bottom <= _end, "arguments out of order");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
  // Note that the committed size of the covered space may have changed,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
  // so the table size might also wish to change.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
  virtual void resize(size_t new_word_size) = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
  virtual void set_bottom(HeapWord* new_bottom) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
    assert(new_bottom <= _end, "new_bottom > _end");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
    _bottom = new_bottom;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
    resize(pointer_delta(_end, _bottom));
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
  // Requires "addr" to be contained by a block, and returns the address of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
  // the start of that block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  virtual HeapWord* block_start_unsafe(const void* addr) const = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
  // Returns the address of the start of the block containing "addr", or
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
  // else "null" if it is covered by no block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
  HeapWord* block_start(const void* addr) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
//////////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
// One implementation of "BlockOffsetTable," the BlockOffsetArray,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
// divides the covered region into "N"-word subregions (where
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
// "N" = 2^"LogN".  An array with an entry for each such subregion
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
// indicates how far back one must go to find the start of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
// chunk that includes the first word of the subregion.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
// Each BlockOffsetArray is owned by a Space.  However, the actual array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
// may be shared by several BlockOffsetArrays; this is useful
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
// when a single resizable area (such as a generation) is divided up into
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
// several spaces in which contiguous allocation takes place.  (Consider,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
// for example, the garbage-first generation.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
// Here is the shared array type.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
//////////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
// BlockOffsetSharedArray
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
//////////////////////////////////////////////////////////////////////////
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   133
class BlockOffsetSharedArray: public CHeapObj<mtGC> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  friend class BlockOffsetArray;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  friend class BlockOffsetArrayNonContigSpace;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  friend class BlockOffsetArrayContigSpace;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
 private:
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   140
  bool _init_to_zero;
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   141
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
  // The reserved region covered by the shared array.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  MemRegion _reserved;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
  // End of the current committed region.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  HeapWord* _end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
  // Array for keeping offsets for retrieving object start fast given an
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
  // address.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
  VirtualSpace _vs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   151
  u_char* _offset_array;          // byte array keeping backwards offsets
489c9b5090e2 Initial load
duke
parents:
diff changeset
   152
32598
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents: 30764
diff changeset
   153
  void fill_range(size_t start, size_t num_cards, u_char offset) {
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents: 30764
diff changeset
   154
    void* start_ptr = &_offset_array[start];
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents: 30764
diff changeset
   155
    // If collector is concurrent, special handling may be needed.
49982
9042ffe5b7fe 8200729: Conditional compilation of GCs
stefank
parents: 49392
diff changeset
   156
    G1GC_ONLY(assert(!UseG1GC, "Shouldn't be here when using G1");)
32598
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents: 30764
diff changeset
   157
    memset(start_ptr, offset, num_cards);
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents: 30764
diff changeset
   158
  }
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents: 30764
diff changeset
   159
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
  // Bounds checking accessors:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   162
  // For performance these have to devolve to array accesses in product builds.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   163
  u_char offset_array(size_t index) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
    assert(index < _vs.committed_size(), "index out of range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
    return _offset_array[index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  }
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   167
  // An assertion-checking helper method for the set_offset_array() methods below.
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   168
  void check_reducing_assertion(bool reducing);
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   169
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   170
  void set_offset_array(size_t index, u_char offset, bool reducing = false) {
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   171
    check_reducing_assertion(reducing);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
    assert(index < _vs.committed_size(), "index out of range");
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   173
    assert(!reducing || _offset_array[index] >= offset, "Not reducing");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
    _offset_array[index] = offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  }
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   176
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   177
  void set_offset_array(size_t index, HeapWord* high, HeapWord* low, bool reducing = false) {
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   178
    check_reducing_assertion(reducing);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
    assert(index < _vs.committed_size(), "index out of range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
    assert(high >= low, "addresses out of order");
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
   181
    assert(pointer_delta(high, low) <= BOTConstants::N_words, "offset too large");
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   182
    assert(!reducing || _offset_array[index] >=  (u_char)pointer_delta(high, low),
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   183
           "Not reducing");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
    _offset_array[index] = (u_char)pointer_delta(high, low);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  }
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   186
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   187
  void set_offset_array(HeapWord* left, HeapWord* right, u_char offset, bool reducing = false) {
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   188
    check_reducing_assertion(reducing);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   189
    assert(index_for(right - 1) < _vs.committed_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   190
           "right address out of range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
    assert(left  < right, "Heap addresses out of order");
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
   192
    size_t num_cards = pointer_delta(right, left) >> BOTConstants::LogN_words;
5431
5c4054a50dbb 6948537: CMS: BOT walkers observe out-of-thin-air zeros on sun4v sparc/CMT
ysr
parents: 3261
diff changeset
   193
32598
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents: 30764
diff changeset
   194
    fill_range(index_for(left), num_cards, offset);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   197
  void set_offset_array(size_t left, size_t right, u_char offset, bool reducing = false) {
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   198
    check_reducing_assertion(reducing);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
    assert(right < _vs.committed_size(), "right address out of range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
    assert(left  <= right, "indexes out of order");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
    size_t num_cards = right - left + 1;
5431
5c4054a50dbb 6948537: CMS: BOT walkers observe out-of-thin-air zeros on sun4v sparc/CMT
ysr
parents: 3261
diff changeset
   202
32598
70b490faa49f 8131330: G1CollectedHeap::verify_dirty_young_list fails with assert
kbarrett
parents: 30764
diff changeset
   203
    fill_range(left, num_cards, offset);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  void check_offset_array(size_t index, HeapWord* high, HeapWord* low) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
    assert(index < _vs.committed_size(), "index out of range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
    assert(high >= low, "addresses out of order");
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
   209
    assert(pointer_delta(high, low) <= BOTConstants::N_words, "offset too large");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
    assert(_offset_array[index] == pointer_delta(high, low),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
           "Wrong offset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  bool is_card_boundary(HeapWord* p) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  // Return the number of slots needed for an offset array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
  // that covers mem_region_words words.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  // We always add an extra slot because if an object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
  // ends on a card boundary we put a 0 in the next
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  // offset array slot, so we want that slot always
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  // to be reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
  size_t compute_size(size_t mem_region_words) {
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
   224
    size_t number_of_slots = (mem_region_words / BOTConstants::N_words) + 1;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
    return ReservedSpace::allocation_align_size_up(number_of_slots);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  // Initialize the table to cover from "base" to (at least)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  // "base + init_word_size".  In the future, the table may be expanded
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
  // (see "resize" below) up to the size of "_reserved" (which must be at
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  // least "init_word_size".)  The contents of the initial table are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  // undefined; it is the responsibility of the constituent
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  // BlockOffsetTable(s) to initialize cards.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  BlockOffsetSharedArray(MemRegion reserved, size_t init_word_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  // Notes a change in the committed size of the region covered by the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
  // table.  The "new_word_size" may not be larger than the size of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   239
  // reserved region this table covers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   240
  void resize(size_t new_word_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   241
489c9b5090e2 Initial load
duke
parents:
diff changeset
   242
  void set_bottom(HeapWord* new_bottom);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   243
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   244
  // Whether entries should be initialized to zero. Used currently only for
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   245
  // error checking.
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   246
  void set_init_to_zero(bool val) { _init_to_zero = val; }
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   247
  bool init_to_zero() { return _init_to_zero; }
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   248
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  // Updates all the BlockOffsetArray's sharing this shared array to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
  // reflect the current "top"'s of their spaces.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  void update_offset_arrays();   // Not yet implemented!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  // Return the appropriate index into "_offset_array" for "p".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
  size_t index_for(const void* p) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   255
489c9b5090e2 Initial load
duke
parents:
diff changeset
   256
  // Return the address indicating the start of the region corresponding to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   257
  // "index" in "_offset_array".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   258
  HeapWord* address_for_index(size_t index) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   259
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
53149
259c36ef27df 8215731: Move forward class definitions out of globalDefinitions.hpp
coleenp
parents: 49982
diff changeset
   261
class Space;
259c36ef27df 8215731: Move forward class definitions out of globalDefinitions.hpp
coleenp
parents: 49982
diff changeset
   262
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
//////////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
// The BlockOffsetArray whose subtypes use the BlockOffsetSharedArray.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
//////////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
class BlockOffsetArray: public BlockOffsetTable {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   267
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   268
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   269
  // The following enums are used by do_block_internal() below
489c9b5090e2 Initial load
duke
parents:
diff changeset
   270
  enum Action {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   271
    Action_single,      // BOT records a single block (see single_block())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   272
    Action_mark,        // BOT marks the start of a block (see mark_block())
489c9b5090e2 Initial load
duke
parents:
diff changeset
   273
    Action_check        // Check that BOT records block correctly
489c9b5090e2 Initial load
duke
parents:
diff changeset
   274
                        // (see verify_single_block()).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   275
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   276
489c9b5090e2 Initial load
duke
parents:
diff changeset
   277
  // The shared array, which is shared with other BlockOffsetArray's
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
  // corresponding to different spaces within a generation or span of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
  // memory.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
  BlockOffsetSharedArray* _array;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
  // The space that owns this subregion.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
  Space* _sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  // If true, array entries are initialized to 0; otherwise, they are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
  // initialized to point backwards to the beginning of the covered region.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  bool _init_to_zero;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   288
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   289
  // An assertion-checking helper method for the set_remainder*() methods below.
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   290
  void check_reducing_assertion(bool reducing) { _array->check_reducing_assertion(reducing); }
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   291
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  // Sets the entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  // corresponding to the cards starting at "start" and ending at "end"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
  // to point back to the card before "start": the interval [start, end)
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   295
  // is right-open. The last parameter, reducing, indicates whether the
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   296
  // updates to individual entries always reduce the entry from a higher
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   297
  // to a lower value. (For example this would hold true during a temporal
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   298
  // regime during which only block splits were updating the BOT.
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   299
  void set_remainder_to_point_to_start(HeapWord* start, HeapWord* end, bool reducing = false);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  // Same as above, except that the args here are a card _index_ interval
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
  // that is closed: [start_index, end_index]
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   302
  void set_remainder_to_point_to_start_incl(size_t start, size_t end, bool reducing = false);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  // A helper function for BOT adjustment/verification work
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   305
  void do_block_internal(HeapWord* blk_start, HeapWord* blk_end, Action action, bool reducing = false);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  // The space may not have its bottom and top set yet, which is why the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
  // region is passed as a parameter.  If "init_to_zero" is true, the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  // elements of the array are initialized to zero.  Otherwise, they are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  // initialized to point backwards to the beginning.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  BlockOffsetArray(BlockOffsetSharedArray* array, MemRegion mr,
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   313
                   bool init_to_zero_);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   314
489c9b5090e2 Initial load
duke
parents:
diff changeset
   315
  // Note: this ought to be part of the constructor, but that would require
489c9b5090e2 Initial load
duke
parents:
diff changeset
   316
  // "this" to be passed as a parameter to a member constructor for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  // the containing concrete subtype of Space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  // This would be legal C++, but MS VC++ doesn't allow it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  void set_space(Space* sp) { _sp = sp; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   320
489c9b5090e2 Initial load
duke
parents:
diff changeset
   321
  // Resets the covered region to the given "mr".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   322
  void set_region(MemRegion mr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   323
    _bottom = mr.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   324
    _end = mr.end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
489c9b5090e2 Initial load
duke
parents:
diff changeset
   327
  // Note that the committed size of the covered space may have changed,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   328
  // so the table size might also wish to change.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  virtual void resize(size_t new_word_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   330
    HeapWord* new_end = _bottom + new_word_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
    if (_end < new_end && !init_to_zero()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
      // verify that the old and new boundaries are also card boundaries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
      assert(_array->is_card_boundary(_end),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
             "_end not a card boundary");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
      assert(_array->is_card_boundary(new_end),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
             "new _end would not be a card boundary");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
      // set all the newly added cards
35469
17ea1b453dd5 8146694: Break out shared constants and static BOT functions.
david
parents: 35461
diff changeset
   338
      _array->set_offset_array(_end, new_end, BOTConstants::N_words);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
    _end = new_end;  // update _end
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  // Adjust the BOT to show that it has a single block in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  // range [blk_start, blk_start + size). All necessary BOT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
  // cards are adjusted, but _unallocated_block isn't.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
  void single_block(HeapWord* blk_start, HeapWord* blk_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  void single_block(HeapWord* blk, size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
    single_block(blk, blk + size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
  // When the alloc_block() call returns, the block offset table should
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  // have enough information such that any subsequent block_start() call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  // with an argument equal to an address that is within the range
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  // [blk_start, blk_end) would return the value blk_start, provided
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
  // there have been no calls in between that reset this information
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
  // (e.g. see BlockOffsetArrayNonContigSpace::single_block() call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
  // for an appropriate range covering the said interval).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
  // These methods expect to be called with [blk_start, blk_end)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
  // representing a block of memory in the heap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
  virtual void alloc_block(HeapWord* blk_start, HeapWord* blk_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
  void alloc_block(HeapWord* blk, size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
    alloc_block(blk, blk + size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
  // If true, initialize array slots with no allocated blocks to zero.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  // Otherwise, make them point back to the front.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
  bool init_to_zero() { return _init_to_zero; }
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   368
  // Corresponding setter
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   369
  void set_init_to_zero(bool val) {
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   370
    _init_to_zero = val;
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   371
    assert(_array != NULL, "_array should be non-NULL");
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   372
    _array->set_init_to_zero(val);
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   373
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
  // Debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  // Return the index of the last entry in the "active" region.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
  virtual size_t last_active_index() const = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  // Verify the block offset table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  void verify() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  void check_all_cards(size_t left_card, size_t right_card) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
////////////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
// A subtype of BlockOffsetArray that takes advantage of the fact
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
// that its underlying space is a ContiguousSpace, so that its "active"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
// region can be more efficiently tracked (than for a non-contiguous space).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
////////////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
class BlockOffsetArrayContigSpace: public BlockOffsetArray {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
  // allocation boundary at which offset array must be updated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  HeapWord* _next_offset_threshold;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   393
  size_t    _next_offset_index;      // index corresponding to that boundary
489c9b5090e2 Initial load
duke
parents:
diff changeset
   394
489c9b5090e2 Initial load
duke
parents:
diff changeset
   395
  // Work function when allocation start crosses threshold.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   396
  void alloc_block_work(HeapWord* blk_start, HeapWord* blk_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   397
489c9b5090e2 Initial load
duke
parents:
diff changeset
   398
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
  BlockOffsetArrayContigSpace(BlockOffsetSharedArray* array, MemRegion mr):
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
    BlockOffsetArray(array, mr, true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
    _next_offset_threshold = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
    _next_offset_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  void set_contig_space(ContiguousSpace* sp) { set_space((Space*)sp); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
  // Initialize the threshold for an empty heap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
  HeapWord* initialize_threshold();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
  // Zero out the entry for _bottom (offset will be zero)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
  void      zero_bottom_entry();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
  // Return the next threshold, the point at which the table should be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
  // updated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
  HeapWord* threshold() const { return _next_offset_threshold; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
  // In general, these methods expect to be called with
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  // [blk_start, blk_end) representing a block of memory in the heap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  // In this implementation, however, we are OK even if blk_start and/or
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
  // blk_end are NULL because NULL is represented as 0, and thus
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  // never exceeds the "_next_offset_threshold".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
  void alloc_block(HeapWord* blk_start, HeapWord* blk_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
    if (blk_end > _next_offset_threshold) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
      alloc_block_work(blk_start, blk_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
  void alloc_block(HeapWord* blk, size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   427
    alloc_block(blk, blk + size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
  HeapWord* block_start_unsafe(const void* addr) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  // Debugging support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
  virtual size_t last_active_index() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6274
diff changeset
   435
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 53149
diff changeset
   436
#endif // SHARE_GC_SHARED_BLOCKOFFSETTABLE_HPP