src/hotspot/share/gc/g1/heapRegionSet.hpp
author sangheki
Wed, 13 Nov 2019 10:49:12 -0800
changeset 59060 fce1fa1bdc91
parent 53244 9807daeb47c4
child 59062 6530de931b8e
permissions -rw-r--r--
8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3) Reviewed-by: kbarrett, sjohanss, tschatzl, pliden
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 53116
diff changeset
     2
 * Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved.
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     4
 *
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     8
 *
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    13
 * accompanied this code).
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    14
 *
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    18
 *
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    21
 * questions.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    22
 *
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    23
 */
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 53116
diff changeset
    25
#ifndef SHARE_GC_G1_HEAPREGIONSET_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 53116
diff changeset
    26
#define SHARE_GC_G1_HEAPREGIONSET_HPP
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    27
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 26696
diff changeset
    28
#include "gc/g1/heapRegion.hpp"
49725
e740e1a38c96 8200550: Xcode 9.3 produce warning -Wexpansion-to-defined
kbarrett
parents: 49632
diff changeset
    29
#include "utilities/macros.hpp"
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    30
35065
b4ff0249c092 8144996: Replace the HeapRegionSetCount class with an uint
david
parents: 35061
diff changeset
    31
#define assert_heap_region_set(p, message) \
b4ff0249c092 8144996: Replace the HeapRegionSetCount class with an uint
david
parents: 35061
diff changeset
    32
  do {                                     \
b4ff0249c092 8144996: Replace the HeapRegionSetCount class with an uint
david
parents: 35061
diff changeset
    33
    assert((p), "[%s] %s ln: %u",          \
b4ff0249c092 8144996: Replace the HeapRegionSetCount class with an uint
david
parents: 35061
diff changeset
    34
           name(), message, length());     \
33753
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
    35
  } while (0)
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
    36
35065
b4ff0249c092 8144996: Replace the HeapRegionSetCount class with an uint
david
parents: 35061
diff changeset
    37
#define guarantee_heap_region_set(p, message) \
b4ff0249c092 8144996: Replace the HeapRegionSetCount class with an uint
david
parents: 35061
diff changeset
    38
  do {                                        \
b4ff0249c092 8144996: Replace the HeapRegionSetCount class with an uint
david
parents: 35061
diff changeset
    39
    guarantee((p), "[%s] %s ln: %u",          \
b4ff0249c092 8144996: Replace the HeapRegionSetCount class with an uint
david
parents: 35061
diff changeset
    40
              name(), message, length());     \
33753
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
    41
  } while (0)
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
    42
35065
b4ff0249c092 8144996: Replace the HeapRegionSetCount class with an uint
david
parents: 35061
diff changeset
    43
#define assert_free_region_list(p, message)                          \
b4ff0249c092 8144996: Replace the HeapRegionSetCount class with an uint
david
parents: 35061
diff changeset
    44
  do {                                                               \
b4ff0249c092 8144996: Replace the HeapRegionSetCount class with an uint
david
parents: 35061
diff changeset
    45
    assert((p), "[%s] %s ln: %u hd: " PTR_FORMAT " tl: " PTR_FORMAT, \
b4ff0249c092 8144996: Replace the HeapRegionSetCount class with an uint
david
parents: 35061
diff changeset
    46
           name(), message, length(), p2i(_head), p2i(_tail));       \
33753
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
    47
  } while (0)
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
    48
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    49
51496
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 51494
diff changeset
    50
// Interface collecting various instance specific verification methods of
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 51494
diff changeset
    51
// HeapRegionSets.
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 51494
diff changeset
    52
class HeapRegionSetChecker : public CHeapObj<mtGC> {
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    53
public:
51496
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 51494
diff changeset
    54
  // Verify MT safety for this HeapRegionSet.
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 51494
diff changeset
    55
  virtual void check_mt_safety() = 0;
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 51494
diff changeset
    56
  // Returns true if the given HeapRegion is of the correct type for this HeapRegionSet.
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 51494
diff changeset
    57
  virtual bool is_correct_type(HeapRegion* hr) = 0;
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 51494
diff changeset
    58
  // Return a description of the type of regions this HeapRegionSet contains.
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 51494
diff changeset
    59
  virtual const char* get_description() = 0;
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    60
};
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    61
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    62
// Base class for all the classes that represent heap region sets. It
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    63
// contains the basic attributes that each set needs to maintain
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    64
// (e.g., length, region num, used bytes sum) plus any shared
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    65
// functionality (e.g., verification).
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    66
49392
2956d0ece7a9 8199282: Remove ValueObj class for allocation subclassing for gc code
coleenp
parents: 47216
diff changeset
    67
class HeapRegionSetBase {
11577
0af7e6e062a7 7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents: 10996
diff changeset
    68
  friend class VMStructs;
51494
1906adbef2dc 8208498: Put archive regions into a first-class HeapRegionSet
tschatzl
parents: 51332
diff changeset
    69
51496
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 51494
diff changeset
    70
  HeapRegionSetChecker* _checker;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    71
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    72
protected:
35065
b4ff0249c092 8144996: Replace the HeapRegionSetCount class with an uint
david
parents: 35061
diff changeset
    73
  // The number of regions in to the set.
b4ff0249c092 8144996: Replace the HeapRegionSetCount class with an uint
david
parents: 35061
diff changeset
    74
  uint _length;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    75
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    76
  const char* _name;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    77
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    78
  bool _verify_in_progress;
10996
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
    79
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    80
  // verify_region() is used to ensure that the contents of a region
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    81
  // added to / removed from a set are consistent.
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    82
  void verify_region(HeapRegion* hr) PRODUCT_RETURN;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    83
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    84
  void check_mt_safety() {
51496
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 51494
diff changeset
    85
    if (_checker != NULL) {
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 51494
diff changeset
    86
      _checker->check_mt_safety();
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    87
    }
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    88
  }
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    89
51496
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 51494
diff changeset
    90
  HeapRegionSetBase(const char* name, HeapRegionSetChecker* verifier);
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    91
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    92
public:
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    93
  const char* name() { return _name; }
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    94
35065
b4ff0249c092 8144996: Replace the HeapRegionSetCount class with an uint
david
parents: 35061
diff changeset
    95
  uint length() const { return _length; }
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    96
35065
b4ff0249c092 8144996: Replace the HeapRegionSetCount class with an uint
david
parents: 35061
diff changeset
    97
  bool is_empty() { return _length == 0; }
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    98
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    99
  // It updates the fields of the set to reflect hr being added to
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   100
  // the set and tags the region appropriately.
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   101
  inline void add(HeapRegion* hr);
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   102
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   103
  // It updates the fields of the set to reflect hr being removed
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   104
  // from the set and tags the region appropriately.
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   105
  inline void remove(HeapRegion* hr);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   106
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   107
  virtual void verify();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   108
  void verify_start();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   109
  void verify_next_region(HeapRegion* hr);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   110
  void verify_end();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   111
49725
e740e1a38c96 8200550: Xcode 9.3 produce warning -Wexpansion-to-defined
kbarrett
parents: 49632
diff changeset
   112
  void verify_optional() { DEBUG_ONLY(verify();) }
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   113
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   114
  virtual void print_on(outputStream* out, bool print_contents = false);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   115
};
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   116
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   117
// This class represents heap region sets whose members are not
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   118
// explicitly tracked. It's helpful to group regions using such sets
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   119
// so that we can reason about all the region groups in the heap using
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   120
// the same interface (namely, the HeapRegionSetBase API).
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   121
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   122
class HeapRegionSet : public HeapRegionSetBase {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   123
public:
51496
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 51494
diff changeset
   124
  HeapRegionSet(const char* name, HeapRegionSetChecker* checker):
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 51494
diff changeset
   125
    HeapRegionSetBase(name, checker) {
51494
1906adbef2dc 8208498: Put archive regions into a first-class HeapRegionSet
tschatzl
parents: 51332
diff changeset
   126
  }
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   127
35065
b4ff0249c092 8144996: Replace the HeapRegionSetCount class with an uint
david
parents: 35061
diff changeset
   128
  void bulk_remove(const uint removed) {
b4ff0249c092 8144996: Replace the HeapRegionSetCount class with an uint
david
parents: 35061
diff changeset
   129
    _length -= removed;
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   130
  }
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   131
};
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   132
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   133
// A set that links all the regions added to it in a doubly-linked
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 25730
diff changeset
   134
// sorted list. We should try to avoid doing operations that iterate over
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   135
// such lists in performance critical paths. Typically we should
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 25730
diff changeset
   136
// add / remove one region at a time or concatenate two lists.
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   137
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   138
class FreeRegionListIterator;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   139
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   140
class FreeRegionList : public HeapRegionSetBase {
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   141
  friend class FreeRegionListIterator;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   142
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   143
private:
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   144
  HeapRegion* _head;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   145
  HeapRegion* _tail;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   146
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   147
  // _last is used to keep track of where we added an element the last
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 25730
diff changeset
   148
  // time. It helps to improve performance when adding several ordered items in a row.
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   149
  HeapRegion* _last;
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   150
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   151
  static uint _unrealistically_long_length;
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   152
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 25730
diff changeset
   153
  inline HeapRegion* remove_from_head_impl();
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 25730
diff changeset
   154
  inline HeapRegion* remove_from_tail_impl();
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   155
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   156
protected:
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   157
  // See the comment for HeapRegionSetBase::clear()
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   158
  virtual void clear();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   159
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   160
public:
51496
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 51494
diff changeset
   161
  FreeRegionList(const char* name, HeapRegionSetChecker* checker = NULL):
bf6b66fa8bdf 8209700: Remove HeapRegionSetBase::RegionSetKind for a more flexible approach
tschatzl
parents: 51494
diff changeset
   162
    HeapRegionSetBase(name, checker) {
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   163
    clear();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   164
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   165
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   166
  void verify_list();
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   167
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 25730
diff changeset
   168
#ifdef ASSERT
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 25730
diff changeset
   169
  bool contains(HeapRegion* hr) const {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 25730
diff changeset
   170
    return hr->containing_set() == this;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 25730
diff changeset
   171
  }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 25730
diff changeset
   172
#endif
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   173
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   174
  static void set_unrealistically_long_length(uint len);
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   175
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   176
  // Add hr to the list. The region should not be a member of another set.
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   177
  // Assumes that the list is ordered and will preserve that order. The order
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26157
diff changeset
   178
  // is determined by hrm_index.
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   179
  inline void add_ordered(HeapRegion* hr);
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   180
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   181
  // Removes from head or tail based on the given argument.
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 25730
diff changeset
   182
  HeapRegion* remove_region(bool from_head);
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   183
59060
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 53244
diff changeset
   184
  HeapRegion* remove_region_with_node_index(bool from_head,
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 53244
diff changeset
   185
                                            const uint requested_node_index,
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 53244
diff changeset
   186
                                            uint* region_node_index);
fce1fa1bdc91 8220310: Implementation: NUMA-Aware Memory Allocation for G1, Mutator (1/3)
sangheki
parents: 53244
diff changeset
   187
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   188
  // Merge two ordered lists. The result is also ordered. The order is
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26157
diff changeset
   189
  // determined by hrm_index.
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   190
  void add_ordered(FreeRegionList* from_list);
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   191
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   192
  // It empties the list by removing all regions from it.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   193
  void remove_all();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   194
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 25730
diff changeset
   195
  // Remove all (contiguous) regions from first to first + num_regions -1 from
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 25730
diff changeset
   196
  // this list.
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 25730
diff changeset
   197
  // Num_regions must be > 1.
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 25730
diff changeset
   198
  void remove_starting_at(HeapRegion* first, uint num_regions);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   199
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   200
  virtual void verify();
53116
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51496
diff changeset
   201
bb03098c4dde 8211425: Allocation of old generation of java heap on alternate memory devices - G1 GC
sangheki
parents: 51496
diff changeset
   202
  uint num_of_regions_in_range(uint start, uint end) const;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   203
};
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   204
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   205
// Iterator class that provides a convenient way to iterate over the
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 25730
diff changeset
   206
// regions of a FreeRegionList.
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   207
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   208
class FreeRegionListIterator : public StackObj {
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   209
private:
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   210
  FreeRegionList* _list;
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   211
  HeapRegion*     _curr;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   212
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   213
public:
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   214
  bool more_available() {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   215
    return _curr != NULL;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   216
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   217
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   218
  HeapRegion* get_next() {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   219
    assert(more_available(),
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   220
           "get_next() should be called when more regions are available");
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   221
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   222
    // If we are going to introduce a count in the iterator we should
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   223
    // do the "cycle" check.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   224
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   225
    HeapRegion* hr = _curr;
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   226
    _list->verify_region(hr);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   227
    _curr = hr->next();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   228
    return hr;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   229
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   230
51332
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 49725
diff changeset
   231
  FreeRegionListIterator(FreeRegionList* list)
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 49725
diff changeset
   232
  : _list(list),
c25572739e7c 8208669: GC changes to allow enabling -Wreorder
tschatzl
parents: 49725
diff changeset
   233
    _curr(list->_head) {
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   234
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   235
};
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   236
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 53116
diff changeset
   237
#endif // SHARE_GC_G1_HEAPREGIONSET_HPP