hotspot/src/share/vm/memory/blockOffsetTable.hpp
author stefank
Fri, 14 Feb 2014 09:29:56 +0100
changeset 22883 5378704451dc
parent 22551 9bf46d16dcc6
child 27899 17754211a7ab
permissions -rw-r--r--
8034764: Use process_strong_roots to adjust the StringTable Reviewed-by: tschatzl, brutisso
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
13728
882756847a04 6964458: Reimplement class meta-data storage to use native memory
coleenp
parents: 13195
diff changeset
     2
 * Copyright (c) 2000, 2012, 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
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6274
diff changeset
    25
#ifndef SHARE_VM_MEMORY_BLOCKOFFSETTABLE_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6274
diff changeset
    26
#define SHARE_VM_MEMORY_BLOCKOFFSETTABLE_HPP
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6274
diff changeset
    27
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6274
diff changeset
    28
#include "memory/memRegion.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6274
diff changeset
    29
#include "runtime/virtualspace.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6274
diff changeset
    30
#include "utilities/globalDefinitions.hpp"
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6274
diff changeset
    31
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
// The CollectedHeap type requires subtypes to implement a method
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
// "block_start".  For some subtypes, notably generational
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
// systems using card-table-based write barriers, the efficiency of this
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
// operation may be important.  Implementations of the "BlockOffsetArray"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
// class may be useful in providing such efficient implementations.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
// BlockOffsetTable (abstract)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
//   - BlockOffsetArray (abstract)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
//     - BlockOffsetArrayNonContigSpace
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
//     - BlockOffsetArrayContigSpace
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
class ContiguousSpace;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
//////////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
// The BlockOffsetTable "interface"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
//////////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
class BlockOffsetTable VALUE_OBJ_CLASS_SPEC {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
  // These members describe the region covered by the table.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
  // The space this table is covering.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  HeapWord* _bottom;    // == reserved.start
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
  HeapWord* _end;       // End of currently allocated region.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  // Initialize the table to cover the given space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
  // The contents of the initial table are undefined.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  BlockOffsetTable(HeapWord* bottom, HeapWord* end):
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
    _bottom(bottom), _end(end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
    assert(_bottom <= _end, "arguments out of order");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
  // Note that the committed size of the covered space may have changed,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  // so the table size might also wish to change.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
  virtual void resize(size_t new_word_size) = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  virtual void set_bottom(HeapWord* new_bottom) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
    assert(new_bottom <= _end, "new_bottom > _end");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
    _bottom = new_bottom;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
    resize(pointer_delta(_end, _bottom));
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
  // Requires "addr" to be contained by a block, and returns the address of
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  // the start of that block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  virtual HeapWord* block_start_unsafe(const void* addr) const = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  // Returns the address of the start of the block containing "addr", or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  // else "null" if it is covered by no block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
  HeapWord* block_start(const void* addr) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
//////////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
// One implementation of "BlockOffsetTable," the BlockOffsetArray,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
// divides the covered region into "N"-word subregions (where
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
// "N" = 2^"LogN".  An array with an entry for each such subregion
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
// indicates how far back one must go to find the start of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
// chunk that includes the first word of the subregion.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
//
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
// Each BlockOffsetArray is owned by a Space.  However, the actual array
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
// may be shared by several BlockOffsetArrays; this is useful
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
// when a single resizable area (such as a generation) is divided up into
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
// several spaces in which contiguous allocation takes place.  (Consider,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
// for example, the garbage-first generation.)
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
// Here is the shared array type.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
//////////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
// BlockOffsetSharedArray
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
//////////////////////////////////////////////////////////////////////////
13195
be27e1b6a4b9 6995781: Native Memory Tracking (Phase 1)
zgu
parents: 7397
diff changeset
   102
class BlockOffsetSharedArray: public CHeapObj<mtGC> {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
  friend class BlockOffsetArray;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
  friend class BlockOffsetArrayNonContigSpace;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
  friend class BlockOffsetArrayContigSpace;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
  enum SomePrivateConstants {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
    LogN = 9,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
    LogN_words = LogN - LogHeapWordSize,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    N_bytes = 1 << LogN,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    N_words = 1 << LogN_words
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   116
  bool _init_to_zero;
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   117
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
  // The reserved region covered by the shared array.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
  MemRegion _reserved;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  // End of the current committed region.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
  HeapWord* _end;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
  // Array for keeping offsets for retrieving object start fast given an
489c9b5090e2 Initial load
duke
parents:
diff changeset
   125
  // address.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   126
  VirtualSpace _vs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   127
  u_char* _offset_array;          // byte array keeping backwards offsets
489c9b5090e2 Initial load
duke
parents:
diff changeset
   128
489c9b5090e2 Initial load
duke
parents:
diff changeset
   129
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   130
  // Bounds checking accessors:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   131
  // For performance these have to devolve to array accesses in product builds.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  u_char offset_array(size_t index) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
    assert(index < _vs.committed_size(), "index out of range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
    return _offset_array[index];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  }
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   136
  // 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
   137
  void check_reducing_assertion(bool reducing);
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   138
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   139
  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
   140
    check_reducing_assertion(reducing);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
    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
   142
    assert(!reducing || _offset_array[index] >= offset, "Not reducing");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
    _offset_array[index] = offset;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  }
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   145
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   146
  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
   147
    check_reducing_assertion(reducing);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
    assert(index < _vs.committed_size(), "index out of range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   149
    assert(high >= low, "addresses out of order");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   150
    assert(pointer_delta(high, low) <= N_words, "offset too large");
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   151
    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
   152
           "Not reducing");
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
    _offset_array[index] = (u_char)pointer_delta(high, low);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  }
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   155
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   156
  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
   157
    check_reducing_assertion(reducing);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
    assert(index_for(right - 1) < _vs.committed_size(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   159
           "right address out of range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   160
    assert(left  < right, "Heap addresses out of order");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
    size_t num_cards = pointer_delta(right, left) >> LogN_words;
5431
5c4054a50dbb 6948537: CMS: BOT walkers observe out-of-thin-air zeros on sun4v sparc/CMT
ysr
parents: 3261
diff changeset
   162
5c4054a50dbb 6948537: CMS: BOT walkers observe out-of-thin-air zeros on sun4v sparc/CMT
ysr
parents: 3261
diff changeset
   163
    // Below, we may use an explicit loop instead of memset()
5c4054a50dbb 6948537: CMS: BOT walkers observe out-of-thin-air zeros on sun4v sparc/CMT
ysr
parents: 3261
diff changeset
   164
    // because on certain platforms memset() can give concurrent
5c4054a50dbb 6948537: CMS: BOT walkers observe out-of-thin-air zeros on sun4v sparc/CMT
ysr
parents: 3261
diff changeset
   165
    // readers "out-of-thin-air," phantom zeros; see 6948537.
5c4054a50dbb 6948537: CMS: BOT walkers observe out-of-thin-air zeros on sun4v sparc/CMT
ysr
parents: 3261
diff changeset
   166
    if (UseMemSetInBOT) {
5c4054a50dbb 6948537: CMS: BOT walkers observe out-of-thin-air zeros on sun4v sparc/CMT
ysr
parents: 3261
diff changeset
   167
      memset(&_offset_array[index_for(left)], offset, num_cards);
5c4054a50dbb 6948537: CMS: BOT walkers observe out-of-thin-air zeros on sun4v sparc/CMT
ysr
parents: 3261
diff changeset
   168
    } else {
5c4054a50dbb 6948537: CMS: BOT walkers observe out-of-thin-air zeros on sun4v sparc/CMT
ysr
parents: 3261
diff changeset
   169
      size_t i = index_for(left);
5c4054a50dbb 6948537: CMS: BOT walkers observe out-of-thin-air zeros on sun4v sparc/CMT
ysr
parents: 3261
diff changeset
   170
      const size_t end = i + num_cards;
5c4054a50dbb 6948537: CMS: BOT walkers observe out-of-thin-air zeros on sun4v sparc/CMT
ysr
parents: 3261
diff changeset
   171
      for (; i < end; i++) {
6274
a4a2e26fe2d0 6978533: CMS: Elide BOT update asserts until 6977974 is fixed correctly
ysr
parents: 6258
diff changeset
   172
        // Elided until CR 6977974 is fixed properly.
a4a2e26fe2d0 6978533: CMS: Elide BOT update asserts until 6977974 is fixed correctly
ysr
parents: 6258
diff changeset
   173
        // assert(!reducing || _offset_array[i] >= offset, "Not reducing");
5431
5c4054a50dbb 6948537: CMS: BOT walkers observe out-of-thin-air zeros on sun4v sparc/CMT
ysr
parents: 3261
diff changeset
   174
        _offset_array[i] = offset;
5c4054a50dbb 6948537: CMS: BOT walkers observe out-of-thin-air zeros on sun4v sparc/CMT
ysr
parents: 3261
diff changeset
   175
      }
5c4054a50dbb 6948537: CMS: BOT walkers observe out-of-thin-air zeros on sun4v sparc/CMT
ysr
parents: 3261
diff changeset
   176
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   179
  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
   180
    check_reducing_assertion(reducing);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
    assert(right < _vs.committed_size(), "right address out of range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   182
    assert(left  <= right, "indexes out of order");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   183
    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
   184
5c4054a50dbb 6948537: CMS: BOT walkers observe out-of-thin-air zeros on sun4v sparc/CMT
ysr
parents: 3261
diff changeset
   185
    // Below, we may use an explicit loop instead of memset
5c4054a50dbb 6948537: CMS: BOT walkers observe out-of-thin-air zeros on sun4v sparc/CMT
ysr
parents: 3261
diff changeset
   186
    // because on certain platforms memset() can give concurrent
5c4054a50dbb 6948537: CMS: BOT walkers observe out-of-thin-air zeros on sun4v sparc/CMT
ysr
parents: 3261
diff changeset
   187
    // readers "out-of-thin-air," phantom zeros; see 6948537.
5c4054a50dbb 6948537: CMS: BOT walkers observe out-of-thin-air zeros on sun4v sparc/CMT
ysr
parents: 3261
diff changeset
   188
    if (UseMemSetInBOT) {
5c4054a50dbb 6948537: CMS: BOT walkers observe out-of-thin-air zeros on sun4v sparc/CMT
ysr
parents: 3261
diff changeset
   189
      memset(&_offset_array[left], offset, num_cards);
5c4054a50dbb 6948537: CMS: BOT walkers observe out-of-thin-air zeros on sun4v sparc/CMT
ysr
parents: 3261
diff changeset
   190
    } else {
5c4054a50dbb 6948537: CMS: BOT walkers observe out-of-thin-air zeros on sun4v sparc/CMT
ysr
parents: 3261
diff changeset
   191
      size_t i = left;
5c4054a50dbb 6948537: CMS: BOT walkers observe out-of-thin-air zeros on sun4v sparc/CMT
ysr
parents: 3261
diff changeset
   192
      const size_t end = i + num_cards;
5c4054a50dbb 6948537: CMS: BOT walkers observe out-of-thin-air zeros on sun4v sparc/CMT
ysr
parents: 3261
diff changeset
   193
      for (; i < end; i++) {
6274
a4a2e26fe2d0 6978533: CMS: Elide BOT update asserts until 6977974 is fixed correctly
ysr
parents: 6258
diff changeset
   194
        // Elided until CR 6977974 is fixed properly.
a4a2e26fe2d0 6978533: CMS: Elide BOT update asserts until 6977974 is fixed correctly
ysr
parents: 6258
diff changeset
   195
        // assert(!reducing || _offset_array[i] >= offset, "Not reducing");
5431
5c4054a50dbb 6948537: CMS: BOT walkers observe out-of-thin-air zeros on sun4v sparc/CMT
ysr
parents: 3261
diff changeset
   196
        _offset_array[i] = offset;
5c4054a50dbb 6948537: CMS: BOT walkers observe out-of-thin-air zeros on sun4v sparc/CMT
ysr
parents: 3261
diff changeset
   197
      }
5c4054a50dbb 6948537: CMS: BOT walkers observe out-of-thin-air zeros on sun4v sparc/CMT
ysr
parents: 3261
diff changeset
   198
    }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  void check_offset_array(size_t index, HeapWord* high, HeapWord* low) const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
    assert(index < _vs.committed_size(), "index out of range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
    assert(high >= low, "addresses out of order");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
    assert(pointer_delta(high, low) <= N_words, "offset too large");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    assert(_offset_array[index] == pointer_delta(high, low),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
           "Wrong offset");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
  bool is_card_boundary(HeapWord* p) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
  // Return the number of slots needed for an offset array
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  // that covers mem_region_words words.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
  // We always add an extra slot because if an object
489c9b5090e2 Initial load
duke
parents:
diff changeset
   214
  // ends on a card boundary we put a 0 in the next
489c9b5090e2 Initial load
duke
parents:
diff changeset
   215
  // offset array slot, so we want that slot always
489c9b5090e2 Initial load
duke
parents:
diff changeset
   216
  // to be reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   217
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  size_t compute_size(size_t mem_region_words) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
    size_t number_of_slots = (mem_region_words / N_words) + 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
    return ReservedSpace::allocation_align_size_up(number_of_slots);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   222
489c9b5090e2 Initial load
duke
parents:
diff changeset
   223
public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   224
  // Initialize the table to cover from "base" to (at least)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   225
  // "base + init_word_size".  In the future, the table may be expanded
489c9b5090e2 Initial load
duke
parents:
diff changeset
   226
  // (see "resize" below) up to the size of "_reserved" (which must be at
489c9b5090e2 Initial load
duke
parents:
diff changeset
   227
  // least "init_word_size".)  The contents of the initial table are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   228
  // undefined; it is the responsibility of the constituent
489c9b5090e2 Initial load
duke
parents:
diff changeset
   229
  // BlockOffsetTable(s) to initialize cards.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   230
  BlockOffsetSharedArray(MemRegion reserved, size_t init_word_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   231
489c9b5090e2 Initial load
duke
parents:
diff changeset
   232
  // Notes a change in the committed size of the region covered by the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   233
  // table.  The "new_word_size" may not be larger than the size of the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   234
  // reserved region this table covers.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   235
  void resize(size_t new_word_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   236
489c9b5090e2 Initial load
duke
parents:
diff changeset
   237
  void set_bottom(HeapWord* new_bottom);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   238
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   239
  // 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
   240
  // error checking.
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   241
  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
   242
  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
   243
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   244
  // Updates all the BlockOffsetArray's sharing this shared array to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   245
  // reflect the current "top"'s of their spaces.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   246
  void update_offset_arrays();   // Not yet implemented!
489c9b5090e2 Initial load
duke
parents:
diff changeset
   247
489c9b5090e2 Initial load
duke
parents:
diff changeset
   248
  // Return the appropriate index into "_offset_array" for "p".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   249
  size_t index_for(const void* p) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   250
489c9b5090e2 Initial load
duke
parents:
diff changeset
   251
  // Return the address indicating the start of the region corresponding to
489c9b5090e2 Initial load
duke
parents:
diff changeset
   252
  // "index" in "_offset_array".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   253
  HeapWord* address_for_index(size_t index) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   254
1063
f666dc7f514d 6728478: Assertion at parallel promotion from young to old generation
jmasa
parents: 1
diff changeset
   255
  // Return the address "p" incremented by the size of
f666dc7f514d 6728478: Assertion at parallel promotion from young to old generation
jmasa
parents: 1
diff changeset
   256
  // a region.  This method does not align the address
f666dc7f514d 6728478: Assertion at parallel promotion from young to old generation
jmasa
parents: 1
diff changeset
   257
  // returned to the start of a region.  It is a simple
f666dc7f514d 6728478: Assertion at parallel promotion from young to old generation
jmasa
parents: 1
diff changeset
   258
  // primitive.
f666dc7f514d 6728478: Assertion at parallel promotion from young to old generation
jmasa
parents: 1
diff changeset
   259
  HeapWord* inc_by_region_size(HeapWord* p) const { return p + N_words; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   260
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   261
489c9b5090e2 Initial load
duke
parents:
diff changeset
   262
//////////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   263
// The BlockOffsetArray whose subtypes use the BlockOffsetSharedArray.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   264
//////////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   265
class BlockOffsetArray: public BlockOffsetTable {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   266
  friend class VMStructs;
1374
4c24294029a9 6711316: Open source the Garbage-First garbage collector
ysr
parents: 1
diff changeset
   267
  friend class G1BlockOffsetArray; // temp. until we restructure and cleanup
1
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
  enum SomePrivateConstants {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   278
    N_words = BlockOffsetSharedArray::N_words,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   279
    LogN    = BlockOffsetSharedArray::LogN,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   280
    // entries "e" of at least N_words mean "go back by Base^(e-N_words)."
489c9b5090e2 Initial load
duke
parents:
diff changeset
   281
    // All entries are less than "N_words + N_powers".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   282
    LogBase = 4,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   283
    Base = (1 << LogBase),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   284
    N_powers = 14
489c9b5090e2 Initial load
duke
parents:
diff changeset
   285
  };
489c9b5090e2 Initial load
duke
parents:
diff changeset
   286
489c9b5090e2 Initial load
duke
parents:
diff changeset
   287
  static size_t power_to_cards_back(uint i) {
13752
92f03fcf979a 7197906: BlockOffsetArray::power_to_cards_back() needs to handle > 32 bit shifts
brutisso
parents: 13728
diff changeset
   288
    return (size_t)1 << (LogBase * i);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   289
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   290
  static size_t power_to_words_back(uint i) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   291
    return power_to_cards_back(i) * N_words;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   292
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   293
  static size_t entry_to_cards_back(u_char entry) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   294
    assert(entry >= N_words, "Precondition");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   295
    return power_to_cards_back(entry - N_words);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   296
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   297
  static size_t entry_to_words_back(u_char entry) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   298
    assert(entry >= N_words, "Precondition");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   299
    return power_to_words_back(entry - N_words);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   300
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   301
489c9b5090e2 Initial load
duke
parents:
diff changeset
   302
  // The shared array, which is shared with other BlockOffsetArray's
489c9b5090e2 Initial load
duke
parents:
diff changeset
   303
  // corresponding to different spaces within a generation or span of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   304
  // memory.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   305
  BlockOffsetSharedArray* _array;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   306
489c9b5090e2 Initial load
duke
parents:
diff changeset
   307
  // The space that owns this subregion.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   308
  Space* _sp;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   309
489c9b5090e2 Initial load
duke
parents:
diff changeset
   310
  // If true, array entries are initialized to 0; otherwise, they are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   311
  // initialized to point backwards to the beginning of the covered region.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   312
  bool _init_to_zero;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   313
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   314
  // 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
   315
  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
   316
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   317
  // Sets the entries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   318
  // corresponding to the cards starting at "start" and ending at "end"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   319
  // 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
   320
  // 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
   321
  // 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
   322
  // 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
   323
  // 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
   324
  void set_remainder_to_point_to_start(HeapWord* start, HeapWord* end, bool reducing = false);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   325
  // Same as above, except that the args here are a card _index_ interval
489c9b5090e2 Initial load
duke
parents:
diff changeset
   326
  // 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
   327
  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
   328
489c9b5090e2 Initial load
duke
parents:
diff changeset
   329
  // 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
   330
  void do_block_internal(HeapWord* blk_start, HeapWord* blk_end, Action action, bool reducing = false);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   331
489c9b5090e2 Initial load
duke
parents:
diff changeset
   332
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   333
  // The space may not have its bottom and top set yet, which is why the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   334
  // region is passed as a parameter.  If "init_to_zero" is true, the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   335
  // elements of the array are initialized to zero.  Otherwise, they are
489c9b5090e2 Initial load
duke
parents:
diff changeset
   336
  // initialized to point backwards to the beginning.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   337
  BlockOffsetArray(BlockOffsetSharedArray* array, MemRegion mr,
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   338
                   bool init_to_zero_);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   339
489c9b5090e2 Initial load
duke
parents:
diff changeset
   340
  // Note: this ought to be part of the constructor, but that would require
489c9b5090e2 Initial load
duke
parents:
diff changeset
   341
  // "this" to be passed as a parameter to a member constructor for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   342
  // the containing concrete subtype of Space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   343
  // This would be legal C++, but MS VC++ doesn't allow it.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   344
  void set_space(Space* sp) { _sp = sp; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   345
489c9b5090e2 Initial load
duke
parents:
diff changeset
   346
  // Resets the covered region to the given "mr".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   347
  void set_region(MemRegion mr) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   348
    _bottom = mr.start();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   349
    _end = mr.end();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   350
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   351
489c9b5090e2 Initial load
duke
parents:
diff changeset
   352
  // Note that the committed size of the covered space may have changed,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   353
  // so the table size might also wish to change.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   354
  virtual void resize(size_t new_word_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   355
    HeapWord* new_end = _bottom + new_word_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   356
    if (_end < new_end && !init_to_zero()) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   357
      // verify that the old and new boundaries are also card boundaries
489c9b5090e2 Initial load
duke
parents:
diff changeset
   358
      assert(_array->is_card_boundary(_end),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   359
             "_end not a card boundary");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   360
      assert(_array->is_card_boundary(new_end),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   361
             "new _end would not be a card boundary");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   362
      // set all the newly added cards
489c9b5090e2 Initial load
duke
parents:
diff changeset
   363
      _array->set_offset_array(_end, new_end, N_words);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   364
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   365
    _end = new_end;  // update _end
489c9b5090e2 Initial load
duke
parents:
diff changeset
   366
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   367
489c9b5090e2 Initial load
duke
parents:
diff changeset
   368
  // Adjust the BOT to show that it has a single block in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   369
  // range [blk_start, blk_start + size). All necessary BOT
489c9b5090e2 Initial load
duke
parents:
diff changeset
   370
  // cards are adjusted, but _unallocated_block isn't.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   371
  void single_block(HeapWord* blk_start, HeapWord* blk_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   372
  void single_block(HeapWord* blk, size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   373
    single_block(blk, blk + size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   374
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   375
489c9b5090e2 Initial load
duke
parents:
diff changeset
   376
  // When the alloc_block() call returns, the block offset table should
489c9b5090e2 Initial load
duke
parents:
diff changeset
   377
  // have enough information such that any subsequent block_start() call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   378
  // with an argument equal to an address that is within the range
489c9b5090e2 Initial load
duke
parents:
diff changeset
   379
  // [blk_start, blk_end) would return the value blk_start, provided
489c9b5090e2 Initial load
duke
parents:
diff changeset
   380
  // there have been no calls in between that reset this information
489c9b5090e2 Initial load
duke
parents:
diff changeset
   381
  // (e.g. see BlockOffsetArrayNonContigSpace::single_block() call
489c9b5090e2 Initial load
duke
parents:
diff changeset
   382
  // for an appropriate range covering the said interval).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   383
  // These methods expect to be called with [blk_start, blk_end)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   384
  // representing a block of memory in the heap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   385
  virtual void alloc_block(HeapWord* blk_start, HeapWord* blk_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   386
  void alloc_block(HeapWord* blk, size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   387
    alloc_block(blk, blk + size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   388
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   389
489c9b5090e2 Initial load
duke
parents:
diff changeset
   390
  // If true, initialize array slots with no allocated blocks to zero.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   391
  // Otherwise, make them point back to the front.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   392
  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
   393
  // Corresponding setter
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   394
  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
   395
    _init_to_zero = val;
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   396
    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
   397
    _array->set_init_to_zero(val);
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   398
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   399
489c9b5090e2 Initial load
duke
parents:
diff changeset
   400
  // Debugging
489c9b5090e2 Initial load
duke
parents:
diff changeset
   401
  // Return the index of the last entry in the "active" region.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   402
  virtual size_t last_active_index() const = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   403
  // Verify the block offset table
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
  void verify() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
  void check_all_cards(size_t left_card, size_t right_card) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   406
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   407
489c9b5090e2 Initial load
duke
parents:
diff changeset
   408
////////////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   409
// A subtype of BlockOffsetArray that takes advantage of the fact
489c9b5090e2 Initial load
duke
parents:
diff changeset
   410
// that its underlying space is a NonContiguousSpace, so that some
489c9b5090e2 Initial load
duke
parents:
diff changeset
   411
// specialized interfaces can be made available for spaces that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   412
// manipulate the table.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   413
////////////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   414
class BlockOffsetArrayNonContigSpace: public BlockOffsetArray {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   415
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   416
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   417
  // The portion [_unallocated_block, _sp.end()) of the space that
489c9b5090e2 Initial load
duke
parents:
diff changeset
   418
  // is a single block known not to contain any objects.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   419
  // NOTE: See BlockOffsetArrayUseUnallocatedBlock flag.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   420
  HeapWord* _unallocated_block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   421
489c9b5090e2 Initial load
duke
parents:
diff changeset
   422
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   423
  BlockOffsetArrayNonContigSpace(BlockOffsetSharedArray* array, MemRegion mr):
489c9b5090e2 Initial load
duke
parents:
diff changeset
   424
    BlockOffsetArray(array, mr, false),
489c9b5090e2 Initial load
duke
parents:
diff changeset
   425
    _unallocated_block(_bottom) { }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   426
22551
9bf46d16dcc6 8025856: Fix typos in the GC code
jwilhelm
parents: 13752
diff changeset
   427
  // Accessor
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   428
  HeapWord* unallocated_block() const {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   429
    assert(BlockOffsetArrayUseUnallocatedBlock,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   430
           "_unallocated_block is not being maintained");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   431
    return _unallocated_block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   432
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   433
489c9b5090e2 Initial load
duke
parents:
diff changeset
   434
  void set_unallocated_block(HeapWord* block) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   435
    assert(BlockOffsetArrayUseUnallocatedBlock,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   436
           "_unallocated_block is not being maintained");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   437
    assert(block >= _bottom && block <= _end, "out of range");
489c9b5090e2 Initial load
duke
parents:
diff changeset
   438
    _unallocated_block = block;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   439
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   440
489c9b5090e2 Initial load
duke
parents:
diff changeset
   441
  // These methods expect to be called with [blk_start, blk_end)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   442
  // representing a block of memory in the heap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   443
  void alloc_block(HeapWord* blk_start, HeapWord* blk_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   444
  void alloc_block(HeapWord* blk, size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   445
    alloc_block(blk, blk + size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   446
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   447
489c9b5090e2 Initial load
duke
parents:
diff changeset
   448
  // The following methods are useful and optimized for a
489c9b5090e2 Initial load
duke
parents:
diff changeset
   449
  // non-contiguous space.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   450
489c9b5090e2 Initial load
duke
parents:
diff changeset
   451
  // Given a block [blk_start, blk_start + full_blk_size), and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   452
  // a left_blk_size < full_blk_size, adjust the BOT to show two
489c9b5090e2 Initial load
duke
parents:
diff changeset
   453
  // blocks [blk_start, blk_start + left_blk_size) and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   454
  // [blk_start + left_blk_size, blk_start + full_blk_size).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   455
  // It is assumed (and verified in the non-product VM) that the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   456
  // BOT was correct for the original block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   457
  void split_block(HeapWord* blk_start, size_t full_blk_size,
489c9b5090e2 Initial load
duke
parents:
diff changeset
   458
                           size_t left_blk_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   459
489c9b5090e2 Initial load
duke
parents:
diff changeset
   460
  // Adjust BOT to show that it has a block in the range
489c9b5090e2 Initial load
duke
parents:
diff changeset
   461
  // [blk_start, blk_start + size). Only the first card
489c9b5090e2 Initial load
duke
parents:
diff changeset
   462
  // of BOT is touched. It is assumed (and verified in the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   463
  // non-product VM) that the remaining cards of the block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   464
  // are correct.
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   465
  void mark_block(HeapWord* blk_start, HeapWord* blk_end, bool reducing = false);
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   466
  void mark_block(HeapWord* blk, size_t size, bool reducing = false) {
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   467
    mark_block(blk, blk + size, reducing);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   468
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   469
489c9b5090e2 Initial load
duke
parents:
diff changeset
   470
  // Adjust _unallocated_block to indicate that a particular
489c9b5090e2 Initial load
duke
parents:
diff changeset
   471
  // block has been newly allocated or freed. It is assumed (and
489c9b5090e2 Initial load
duke
parents:
diff changeset
   472
  // verified in the non-product VM) that the BOT is correct for
489c9b5090e2 Initial load
duke
parents:
diff changeset
   473
  // the given block.
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   474
  void allocated(HeapWord* blk_start, HeapWord* blk_end, bool reducing = false) {
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   475
    // Verify that the BOT shows [blk, blk + blk_size) to be one block.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   476
    verify_single_block(blk_start, blk_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   477
    if (BlockOffsetArrayUseUnallocatedBlock) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   478
      _unallocated_block = MAX2(_unallocated_block, blk_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   479
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   480
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   481
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   482
  void allocated(HeapWord* blk, size_t size, bool reducing = false) {
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   483
    allocated(blk, blk + size, reducing);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   484
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   485
489c9b5090e2 Initial load
duke
parents:
diff changeset
   486
  void freed(HeapWord* blk_start, HeapWord* blk_end);
6258
68f252c6e825 6948538: CMS: BOT walkers can fall into object allocation and initialization cracks
ysr
parents: 5547
diff changeset
   487
  void freed(HeapWord* blk, size_t size);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   488
489c9b5090e2 Initial load
duke
parents:
diff changeset
   489
  HeapWord* block_start_unsafe(const void* addr) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   490
489c9b5090e2 Initial load
duke
parents:
diff changeset
   491
  // Requires "addr" to be the start of a card and returns the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   492
  // start of the block that contains the given address.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   493
  HeapWord* block_start_careful(const void* addr) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   494
489c9b5090e2 Initial load
duke
parents:
diff changeset
   495
  // Verification & debugging: ensure that the offset table reflects
489c9b5090e2 Initial load
duke
parents:
diff changeset
   496
  // the fact that the block [blk_start, blk_end) or [blk, blk + size)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   497
  // is a single block of storage. NOTE: can't const this because of
489c9b5090e2 Initial load
duke
parents:
diff changeset
   498
  // call to non-const do_block_internal() below.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   499
  void verify_single_block(HeapWord* blk_start, HeapWord* blk_end)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   500
    PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   501
  void verify_single_block(HeapWord* blk, size_t size) PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   502
489c9b5090e2 Initial load
duke
parents:
diff changeset
   503
  // Verify that the given block is before _unallocated_block
489c9b5090e2 Initial load
duke
parents:
diff changeset
   504
  void verify_not_unallocated(HeapWord* blk_start, HeapWord* blk_end)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   505
    const PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   506
  void verify_not_unallocated(HeapWord* blk, size_t size)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   507
    const PRODUCT_RETURN;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   508
489c9b5090e2 Initial load
duke
parents:
diff changeset
   509
  // Debugging support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   510
  virtual size_t last_active_index() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   511
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   512
489c9b5090e2 Initial load
duke
parents:
diff changeset
   513
////////////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   514
// A subtype of BlockOffsetArray that takes advantage of the fact
489c9b5090e2 Initial load
duke
parents:
diff changeset
   515
// that its underlying space is a ContiguousSpace, so that its "active"
489c9b5090e2 Initial load
duke
parents:
diff changeset
   516
// region can be more efficiently tracked (than for a non-contiguous space).
489c9b5090e2 Initial load
duke
parents:
diff changeset
   517
////////////////////////////////////////////////////////////////////////////
489c9b5090e2 Initial load
duke
parents:
diff changeset
   518
class BlockOffsetArrayContigSpace: public BlockOffsetArray {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   519
  friend class VMStructs;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   520
 private:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   521
  // allocation boundary at which offset array must be updated
489c9b5090e2 Initial load
duke
parents:
diff changeset
   522
  HeapWord* _next_offset_threshold;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   523
  size_t    _next_offset_index;      // index corresponding to that boundary
489c9b5090e2 Initial load
duke
parents:
diff changeset
   524
489c9b5090e2 Initial load
duke
parents:
diff changeset
   525
  // Work function when allocation start crosses threshold.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   526
  void alloc_block_work(HeapWord* blk_start, HeapWord* blk_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   527
489c9b5090e2 Initial load
duke
parents:
diff changeset
   528
 public:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   529
  BlockOffsetArrayContigSpace(BlockOffsetSharedArray* array, MemRegion mr):
489c9b5090e2 Initial load
duke
parents:
diff changeset
   530
    BlockOffsetArray(array, mr, true) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   531
    _next_offset_threshold = NULL;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   532
    _next_offset_index = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   533
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   534
489c9b5090e2 Initial load
duke
parents:
diff changeset
   535
  void set_contig_space(ContiguousSpace* sp) { set_space((Space*)sp); }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   536
489c9b5090e2 Initial load
duke
parents:
diff changeset
   537
  // Initialize the threshold for an empty heap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   538
  HeapWord* initialize_threshold();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   539
  // Zero out the entry for _bottom (offset will be zero)
489c9b5090e2 Initial load
duke
parents:
diff changeset
   540
  void      zero_bottom_entry();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   541
489c9b5090e2 Initial load
duke
parents:
diff changeset
   542
  // Return the next threshold, the point at which the table should be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   543
  // updated.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   544
  HeapWord* threshold() const { return _next_offset_threshold; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   545
489c9b5090e2 Initial load
duke
parents:
diff changeset
   546
  // In general, these methods expect to be called with
489c9b5090e2 Initial load
duke
parents:
diff changeset
   547
  // [blk_start, blk_end) representing a block of memory in the heap.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   548
  // In this implementation, however, we are OK even if blk_start and/or
489c9b5090e2 Initial load
duke
parents:
diff changeset
   549
  // blk_end are NULL because NULL is represented as 0, and thus
489c9b5090e2 Initial load
duke
parents:
diff changeset
   550
  // never exceeds the "_next_offset_threshold".
489c9b5090e2 Initial load
duke
parents:
diff changeset
   551
  void alloc_block(HeapWord* blk_start, HeapWord* blk_end) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   552
    if (blk_end > _next_offset_threshold) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   553
      alloc_block_work(blk_start, blk_end);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   554
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   555
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   556
  void alloc_block(HeapWord* blk, size_t size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   557
    alloc_block(blk, blk + size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   558
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   559
489c9b5090e2 Initial load
duke
parents:
diff changeset
   560
  HeapWord* block_start_unsafe(const void* addr) const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   561
489c9b5090e2 Initial load
duke
parents:
diff changeset
   562
  // Debugging support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   563
  virtual size_t last_active_index() const;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   564
};
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6274
diff changeset
   565
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 6274
diff changeset
   566
#endif // SHARE_VM_MEMORY_BLOCKOFFSETTABLE_HPP