hotspot/src/share/vm/gc/g1/heapRegionSet.hpp
author tschatzl
Wed, 25 Nov 2015 14:43:29 +0100
changeset 34300 6075c1e0e913
parent 33753 3add06d0880f
child 35061 be6025ebffea
permissions -rw-r--r--
8136679: JFR event for adaptive IHOP Reviewed-by: tbenson, mgerdin, sangheki, ehelin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     1
/*
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 26696
diff changeset
     2
 * Copyright (c) 2011, 2015, 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
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 26696
diff changeset
    25
#ifndef SHARE_VM_GC_G1_HEAPREGIONSET_HPP
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 26696
diff changeset
    26
#define SHARE_VM_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"
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    29
33753
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
    30
#define assert_heap_region_set(p, message)                        \
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
    31
  do {                                                            \
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
    32
    assert((p), "[%s] %s ln: %u cy: " SIZE_FORMAT,                \
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
    33
           name(), message, length(), total_capacity_bytes());    \
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
    34
  } while (0)
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
    35
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
    36
#define guarantee_heap_region_set(p, message)                     \
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
    37
  do {                                                            \
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
    38
    guarantee((p), "[%s] %s ln: %u cy: " SIZE_FORMAT,             \
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
    39
              name(), message, length(), total_capacity_bytes()); \
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
    40
  } while (0)
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
    41
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
    42
#define assert_free_region_list(p, message)                                              \
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
    43
  do {                                                                                   \
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
    44
    assert((p), "[%s] %s ln: %u cy: " SIZE_FORMAT " hd: " PTR_FORMAT " tl: " PTR_FORMAT, \
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
    45
           name(), message, length(), total_capacity_bytes(), p2i(_head), p2i(_tail));   \
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
    46
  } while (0)
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
    47
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    48
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    49
// Set verification will be forced either if someone defines
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    50
// HEAP_REGION_SET_FORCE_VERIFY to be 1, or in builds in which
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    51
// asserts are compiled in.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    52
#ifndef HEAP_REGION_SET_FORCE_VERIFY
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    53
#define HEAP_REGION_SET_FORCE_VERIFY defined(ASSERT)
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    54
#endif // HEAP_REGION_SET_FORCE_VERIFY
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    55
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    56
class HRSMtSafeChecker : public CHeapObj<mtGC> {
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    57
public:
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    58
  virtual void check() = 0;
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    59
};
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
class MasterFreeRegionListMtSafeChecker    : public HRSMtSafeChecker { public: void check(); };
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    62
class SecondaryFreeRegionListMtSafeChecker : public HRSMtSafeChecker { public: void check(); };
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    63
class HumongousRegionSetMtSafeChecker      : public HRSMtSafeChecker { public: void check(); };
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    64
class OldRegionSetMtSafeChecker            : public HRSMtSafeChecker { public: void check(); };
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    65
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    66
class HeapRegionSetCount VALUE_OBJ_CLASS_SPEC {
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    67
  friend class VMStructs;
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    68
  uint   _length;
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    69
  size_t _capacity;
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    70
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    71
public:
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    72
  HeapRegionSetCount() : _length(0), _capacity(0) { }
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    73
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    74
  const uint   length()   const { return _length;   }
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    75
  const size_t capacity() const { return _capacity; }
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    76
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    77
  void increment(uint length_to_add, size_t capacity_to_add) {
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    78
    _length += length_to_add;
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    79
    _capacity += capacity_to_add;
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    80
  }
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    81
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    82
  void decrement(const uint length_to_remove, const size_t capacity_to_remove) {
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    83
    _length -= length_to_remove;
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    84
    _capacity -= capacity_to_remove;
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    85
  }
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    86
};
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    87
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    88
// Base class for all the classes that represent heap region sets. It
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    89
// contains the basic attributes that each set needs to maintain
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    90
// (e.g., length, region num, used bytes sum) plus any shared
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    91
// functionality (e.g., verification).
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    92
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    93
class HeapRegionSetBase VALUE_OBJ_CLASS_SPEC {
11577
0af7e6e062a7 7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents: 10996
diff changeset
    94
  friend class VMStructs;
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    95
private:
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    96
  bool _is_humongous;
26696
623a25e6c686 8057768: Make heap region region type in G1 HeapRegion explicit
tonyp
parents: 26316
diff changeset
    97
  bool _is_free;
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
    98
  HRSMtSafeChecker* _mt_safety_checker;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    99
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   100
protected:
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   101
  // The number of regions added to the set. If the set contains
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   102
  // only humongous regions, this reflects only 'starts humongous'
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   103
  // regions and does not include 'continues humongous' ones.
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   104
  HeapRegionSetCount _count;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   105
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   106
  const char* _name;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   107
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   108
  bool _verify_in_progress;
10996
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
   109
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   110
  // 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
   111
  // added to / removed from a set are consistent.
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   112
  void verify_region(HeapRegion* hr) PRODUCT_RETURN;
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
  // Indicates whether all regions in the set should be humongous or
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   115
  // not. Only used during verification.
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   116
  bool regions_humongous() { return _is_humongous; }
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   117
26696
623a25e6c686 8057768: Make heap region region type in G1 HeapRegion explicit
tonyp
parents: 26316
diff changeset
   118
  // Indicates whether all regions in the set should be free or
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   119
  // not. Only used during verification.
26696
623a25e6c686 8057768: Make heap region region type in G1 HeapRegion explicit
tonyp
parents: 26316
diff changeset
   120
  bool regions_free() { return _is_free; }
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   121
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   122
  void check_mt_safety() {
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   123
    if (_mt_safety_checker != NULL) {
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   124
      _mt_safety_checker->check();
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   125
    }
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   126
  }
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   127
26696
623a25e6c686 8057768: Make heap region region type in G1 HeapRegion explicit
tonyp
parents: 26316
diff changeset
   128
  HeapRegionSetBase(const char* name, bool humongous, bool free, HRSMtSafeChecker* mt_safety_checker);
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   129
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   130
public:
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   131
  const char* name() { return _name; }
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   132
25730
7eb4e685f739 8048112: G1 Full GC needs to support the case when the very first region is not available
tschatzl
parents: 24424
diff changeset
   133
  uint length() const { return _count.length(); }
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   134
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   135
  bool is_empty() { return _count.length() == 0; }
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   136
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   137
  size_t total_capacity_bytes() {
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   138
    return _count.capacity();
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   139
  }
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   140
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   141
  // 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
   142
  // the set and tags the region appropriately.
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   143
  inline void add(HeapRegion* hr);
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   144
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   145
  // It updates the fields of the set to reflect hr being removed
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   146
  // from the set and tags the region appropriately.
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   147
  inline void remove(HeapRegion* hr);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   148
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   149
  virtual void verify();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   150
  void verify_start();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   151
  void verify_next_region(HeapRegion* hr);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   152
  void verify_end();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   153
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   154
#if HEAP_REGION_SET_FORCE_VERIFY
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   155
  void verify_optional() {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   156
    verify();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   157
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   158
#else // HEAP_REGION_SET_FORCE_VERIFY
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   159
  void verify_optional() { }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   160
#endif // HEAP_REGION_SET_FORCE_VERIFY
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   161
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   162
  virtual void print_on(outputStream* out, bool print_contents = false);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   163
};
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   164
33753
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
   165
#define hrs_assert_sets_match(_set1_, _set2_)                                  \
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
   166
  do {                                                                         \
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
   167
    assert(((_set1_)->regions_humongous() == (_set2_)->regions_humongous()) && \
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
   168
           ((_set1_)->regions_free() == (_set2_)->regions_free()),             \
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
   169
           "the contents of set %s and set %s should match",                   \
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
   170
           (_set1_)->name(),                                                   \
3add06d0880f 8137756: Remove hrs_err_msg and hrs_ext_msg from heapRegionSet
david
parents: 30764
diff changeset
   171
           (_set2_)->name());                                                  \
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   172
  } while (0)
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   173
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   174
// This class represents heap region sets whose members are not
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   175
// explicitly tracked. It's helpful to group regions using such sets
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   176
// 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
   177
// the same interface (namely, the HeapRegionSetBase API).
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   178
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   179
class HeapRegionSet : public HeapRegionSetBase {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   180
public:
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   181
  HeapRegionSet(const char* name, bool humongous, HRSMtSafeChecker* mt_safety_checker):
26696
623a25e6c686 8057768: Make heap region region type in G1 HeapRegion explicit
tonyp
parents: 26316
diff changeset
   182
    HeapRegionSetBase(name, humongous, false /* free */, mt_safety_checker) { }
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   183
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   184
  void bulk_remove(const HeapRegionSetCount& removed) {
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   185
    _count.decrement(removed.length(), removed.capacity());
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   186
  }
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   187
};
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   188
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   189
// 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
   190
// 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
   191
// 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
   192
// add / remove one region at a time or concatenate two lists.
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   193
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   194
class FreeRegionListIterator;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   195
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   196
class FreeRegionList : public HeapRegionSetBase {
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   197
  friend class FreeRegionListIterator;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   198
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   199
private:
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   200
  HeapRegion* _head;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   201
  HeapRegion* _tail;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   202
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   203
  // _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
   204
  // 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
   205
  HeapRegion* _last;
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   206
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   207
  static uint _unrealistically_long_length;
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   208
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 25730
diff changeset
   209
  inline HeapRegion* remove_from_head_impl();
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 25730
diff changeset
   210
  inline HeapRegion* remove_from_tail_impl();
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   211
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   212
protected:
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   213
  // See the comment for HeapRegionSetBase::clear()
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   214
  virtual void clear();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   215
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   216
public:
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   217
  FreeRegionList(const char* name, HRSMtSafeChecker* mt_safety_checker = NULL):
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   218
    HeapRegionSetBase(name, false /* humongous */, true /* empty */, mt_safety_checker) {
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   219
    clear();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   220
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   221
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   222
  void verify_list();
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   223
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 25730
diff changeset
   224
#ifdef ASSERT
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 25730
diff changeset
   225
  bool contains(HeapRegion* hr) const {
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 25730
diff changeset
   226
    return hr->containing_set() == this;
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 25730
diff changeset
   227
  }
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 25730
diff changeset
   228
#endif
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   229
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   230
  static void set_unrealistically_long_length(uint len);
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   231
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   232
  // 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
   233
  // 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
   234
  // is determined by hrm_index.
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   235
  inline void add_ordered(HeapRegion* hr);
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   236
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   237
  // 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
   238
  HeapRegion* remove_region(bool from_head);
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   239
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   240
  // Merge two ordered lists. The result is also ordered. The order is
26316
93f6b40c038b 8054819: Rename HeapRegionSeq to HeapRegionManager
tschatzl
parents: 26157
diff changeset
   241
  // determined by hrm_index.
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   242
  void add_ordered(FreeRegionList* from_list);
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   243
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   244
  // It empties the list by removing all regions from it.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   245
  void remove_all();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   246
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 25730
diff changeset
   247
  // 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
   248
  // this list.
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 25730
diff changeset
   249
  // Num_regions must be > 1.
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 25730
diff changeset
   250
  void remove_starting_at(HeapRegion* first, uint num_regions);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   251
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   252
  virtual void verify();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   253
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   254
  virtual void print_on(outputStream* out, bool print_contents = false);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   255
};
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   256
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   257
// 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
   258
// regions of a FreeRegionList.
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   259
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   260
class FreeRegionListIterator : public StackObj {
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   261
private:
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   262
  FreeRegionList* _list;
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   263
  HeapRegion*     _curr;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   264
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   265
public:
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   266
  bool more_available() {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   267
    return _curr != NULL;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   268
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   269
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   270
  HeapRegion* get_next() {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   271
    assert(more_available(),
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   272
           "get_next() should be called when more regions are available");
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   273
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   274
    // 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
   275
    // do the "cycle" check.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   276
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   277
    HeapRegion* hr = _curr;
23450
c7c6202fc7e2 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 13336
diff changeset
   278
    _list->verify_region(hr);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   279
    _curr = hr->next();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   280
    return hr;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   281
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   282
23471
ec9427262f0a 8036025: Sort the freelist in order to shrink the heap
jwilhelm
parents: 23450
diff changeset
   283
  FreeRegionListIterator(FreeRegionList* list) : _curr(NULL), _list(list) {
26157
70eddb655686 8054818: Refactor HeapRegionSeq to manage heap region and auxiliary data
tschatzl
parents: 25730
diff changeset
   284
    _curr = list->_head;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   285
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   286
};
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   287
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 26696
diff changeset
   288
#endif // SHARE_VM_GC_G1_HEAPREGIONSET_HPP