src/hotspot/share/gc/g1/g1BiasedArray.hpp
author eosterlund
Mon, 26 Feb 2018 09:34:12 +0100
changeset 49164 7e958a8ebcd3
parent 47216 71c04702a3d5
child 49392 2956d0ece7a9
permissions -rw-r--r--
8195142: Refactor out card table from CardTableModRefBS to flatten the BarrierSet hierarchy Reviewed-by: stefank, coleenp, kvn, ehelin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
     1
/*
43407
f6dc40ed6ce9 8171924: Use SIZE_FORMAT to print size_t values.
goetz
parents: 33105
diff changeset
     2
 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
     4
 *
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
     7
 * published by the Free Software Foundation.
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
     8
 *
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    13
 * accompanied this code).
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    14
 *
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    18
 *
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    21
 * questions.
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    22
 *
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    23
 */
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    24
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 24424
diff changeset
    25
#ifndef SHARE_VM_GC_G1_G1BIASEDARRAY_HPP
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 24424
diff changeset
    26
#define SHARE_VM_GC_G1_G1BIASEDARRAY_HPP
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    27
23458
947a3d680f3e 8036860: Pad and cache-align the BiasedMappedArray
tschatzl
parents: 22553
diff changeset
    28
#include "memory/allocation.hpp"
31350
b856c6918480 8098552: 8079792 breaks Zero builds without precompiled headers.
sgehwolf
parents: 31346
diff changeset
    29
#include "memory/memRegion.hpp"
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    30
#include "utilities/debug.hpp"
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    31
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    32
// Implements the common base functionality for arrays that contain provisions
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    33
// for accessing its elements using a biased index.
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    34
// The element type is defined by the instantiating the template.
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    35
class G1BiasedMappedArrayBase VALUE_OBJ_CLASS_SPEC {
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    36
  friend class VMStructs;
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    37
public:
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    38
  typedef size_t idx_t;
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    39
protected:
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    40
  address _base;          // the real base address
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    41
  size_t _length;         // the length of the array
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    42
  address _biased_base;   // base address biased by "bias" elements
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    43
  size_t _bias;           // the bias, i.e. the offset biased_base is located to the right in elements
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    44
  uint _shift_by;         // the amount of bits to shift right when mapping to an index of the array.
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    45
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    46
protected:
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    47
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    48
  G1BiasedMappedArrayBase() : _base(NULL), _length(0), _biased_base(NULL),
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    49
    _bias(0), _shift_by(0) { }
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    50
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    51
  // Allocate a new array, generic version.
23458
947a3d680f3e 8036860: Pad and cache-align the BiasedMappedArray
tschatzl
parents: 22553
diff changeset
    52
  static address create_new_base_array(size_t length, size_t elem_size);
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    53
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    54
  // Initialize the members of this class. The biased start address of this array
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    55
  // is the bias (in elements) multiplied by the element size.
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    56
  void initialize_base(address base, size_t length, size_t bias, size_t elem_size, uint shift_by) {
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    57
    assert(base != NULL, "just checking");
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    58
    assert(length > 0, "just checking");
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31592
diff changeset
    59
    assert(shift_by < sizeof(uintptr_t) * 8, "Shifting by %u, larger than word size?", shift_by);
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    60
    _base = base;
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    61
    _length = length;
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    62
    _biased_base = base - (bias * elem_size);
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    63
    _bias = bias;
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    64
    _shift_by = shift_by;
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    65
  }
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    66
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    67
  // Allocate and initialize this array to cover the heap addresses in the range
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    68
  // of [bottom, end).
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    69
  void initialize(HeapWord* bottom, HeapWord* end, size_t target_elem_size_in_bytes, size_t mapping_granularity_in_bytes) {
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    70
    assert(mapping_granularity_in_bytes > 0, "just checking");
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    71
    assert(is_power_of_2(mapping_granularity_in_bytes),
43407
f6dc40ed6ce9 8171924: Use SIZE_FORMAT to print size_t values.
goetz
parents: 33105
diff changeset
    72
           "mapping granularity must be power of 2, is " SIZE_FORMAT, mapping_granularity_in_bytes);
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    73
    assert((uintptr_t)bottom % mapping_granularity_in_bytes == 0,
43407
f6dc40ed6ce9 8171924: Use SIZE_FORMAT to print size_t values.
goetz
parents: 33105
diff changeset
    74
           "bottom mapping area address must be a multiple of mapping granularity " SIZE_FORMAT ", is  " PTR_FORMAT,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31592
diff changeset
    75
           mapping_granularity_in_bytes, p2i(bottom));
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    76
    assert((uintptr_t)end % mapping_granularity_in_bytes == 0,
43407
f6dc40ed6ce9 8171924: Use SIZE_FORMAT to print size_t values.
goetz
parents: 33105
diff changeset
    77
           "end mapping area address must be a multiple of mapping granularity " SIZE_FORMAT ", is " PTR_FORMAT,
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 31592
diff changeset
    78
           mapping_granularity_in_bytes, p2i(end));
22553
12b903843ee2 8031686: G1: assert(_hrs.max_length() == _expansion_regions) failed
sjohanss
parents: 20083
diff changeset
    79
    size_t num_target_elems = pointer_delta(end, bottom, mapping_granularity_in_bytes);
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    80
    idx_t bias = (uintptr_t)bottom / mapping_granularity_in_bytes;
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    81
    address base = create_new_base_array(num_target_elems, target_elem_size_in_bytes);
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    82
    initialize_base(base, num_target_elems, bias, target_elem_size_in_bytes, log2_intptr(mapping_granularity_in_bytes));
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    83
  }
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    84
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    85
  size_t bias() const { return _bias; }
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    86
  uint shift_by() const { return _shift_by; }
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    87
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    88
  void verify_index(idx_t index) const PRODUCT_RETURN;
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    89
  void verify_biased_index(idx_t biased_index) const PRODUCT_RETURN;
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    90
  void verify_biased_index_inclusive_end(idx_t biased_index) const PRODUCT_RETURN;
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    91
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    92
public:
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    93
   // Return the length of the array in elements.
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    94
   size_t length() const { return _length; }
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    95
};
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    96
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    97
// Array that provides biased access and mapping from (valid) addresses in the
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    98
// heap into this array.
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
    99
template<class T>
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   100
class G1BiasedMappedArray : public G1BiasedMappedArrayBase {
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   101
public:
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   102
  typedef G1BiasedMappedArrayBase::idx_t idx_t;
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   103
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   104
  T* base() const { return (T*)G1BiasedMappedArrayBase::_base; }
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   105
  // Return the element of the given array at the given index. Assume
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   106
  // the index is valid. This is a convenience method that does sanity
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   107
  // checking on the index.
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   108
  T get_by_index(idx_t index) const {
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   109
    verify_index(index);
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   110
    return this->base()[index];
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   111
  }
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   112
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   113
  // Set the element of the given array at the given index to the
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   114
  // given value. Assume the index is valid. This is a convenience
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   115
  // method that does sanity checking on the index.
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   116
  void set_by_index(idx_t index, T value) {
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   117
    verify_index(index);
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   118
    this->base()[index] = value;
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   119
  }
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   120
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   121
  // The raw biased base pointer.
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   122
  T* biased_base() const { return (T*)G1BiasedMappedArrayBase::_biased_base; }
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   123
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   124
  // Return the element of the given array that covers the given word in the
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   125
  // heap. Assumes the index is valid.
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   126
  T get_by_address(HeapWord* value) const {
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   127
    idx_t biased_index = ((uintptr_t)value) >> this->shift_by();
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   128
    this->verify_biased_index(biased_index);
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   129
    return biased_base()[biased_index];
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   130
  }
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   131
31346
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   132
  // Return the index of the element of the given array that covers the given
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   133
  // word in the heap.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   134
  idx_t get_index_by_address(HeapWord* value) const {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   135
    idx_t biased_index = ((uintptr_t)value) >> this->shift_by();
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   136
    this->verify_biased_index(biased_index);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   137
    return biased_index - _bias;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   138
  }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   139
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   140
  // Set the value of the array entry that corresponds to the given array.
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   141
  void set_by_address(HeapWord * address, T value) {
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   142
    idx_t biased_index = ((uintptr_t)address) >> this->shift_by();
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   143
    this->verify_biased_index(biased_index);
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   144
    biased_base()[biased_index] = value;
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   145
  }
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   146
31346
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   147
  // Set the value of all array entries that correspond to addresses
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   148
  // in the specified MemRegion.
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   149
  void set_by_address(MemRegion range, T value) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   150
    idx_t biased_start = ((uintptr_t)range.start()) >> this->shift_by();
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   151
    idx_t biased_last = ((uintptr_t)range.last()) >> this->shift_by();
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   152
    this->verify_biased_index(biased_start);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   153
    this->verify_biased_index(biased_last);
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   154
    for (idx_t i = biased_start; i <= biased_last; i++) {
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   155
      biased_base()[i] = value;
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   156
    }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   157
  }
a70d45c06136 8042668: GC Support for shared heap ranges in CDS
jiangli
parents: 30764
diff changeset
   158
20083
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   159
protected:
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   160
  // Returns the address of the element the given address maps to
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   161
  T* address_mapped_to(HeapWord* address) {
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   162
    idx_t biased_index = ((uintptr_t)address) >> this->shift_by();
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   163
    this->verify_biased_index_inclusive_end(biased_index);
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   164
    return biased_base() + biased_index;
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   165
  }
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   166
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   167
public:
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   168
  // Return the smallest address (inclusive) in the heap that this array covers.
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   169
  HeapWord* bottom_address_mapped() const {
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   170
    return (HeapWord*) ((uintptr_t)this->bias() << this->shift_by());
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   171
  }
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   172
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   173
  // Return the highest address (exclusive) in the heap that this array covers.
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   174
  HeapWord* end_address_mapped() const {
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   175
    return (HeapWord*) ((uintptr_t)(this->bias() + this->length()) << this->shift_by());
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   176
  }
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   177
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   178
protected:
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   179
  virtual T default_value() const = 0;
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   180
  // Set all elements of the given array to the given value.
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   181
  void clear() {
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   182
    T value = default_value();
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   183
    for (idx_t i = 0; i < length(); i++) {
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   184
      set_by_index(i, value);
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   185
    }
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   186
  }
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   187
public:
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   188
  G1BiasedMappedArray() {}
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   189
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   190
  // Allocate and initialize this array to cover the heap addresses in the range
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   191
  // of [bottom, end).
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   192
  void initialize(HeapWord* bottom, HeapWord* end, size_t mapping_granularity) {
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   193
    G1BiasedMappedArrayBase::initialize(bottom, end, sizeof(T), mapping_granularity);
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   194
    this->clear();
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   195
  }
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   196
};
df032615dd00 7163191: G1: introduce a "heap spanning table" abstraction
tschatzl
parents:
diff changeset
   197
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 24424
diff changeset
   198
#endif // SHARE_VM_GC_G1_G1BIASEDARRAY_HPP