hotspot/src/share/vm/gc_implementation/g1/heapRegionSet.hpp
author tonyp
Wed, 18 Apr 2012 07:21:15 -0400
changeset 12381 1438e0fbfa27
parent 11577 0af7e6e062a7
child 13336 e582172ff6ff
permissions -rw-r--r--
7157073: G1: type change size_t -> uint for region counts / indexes Summary: Change the type of fields / variables / etc. that represent region counts and indeces from size_t to uint. Reviewed-by: iveresov, brutisso, jmasa, jwilhelm
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     1
/*
11577
0af7e6e062a7 7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents: 10996
diff changeset
     2
 * Copyright (c) 2011, 2012, 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
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    25
#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_HPP
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    26
#define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_HPP
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    27
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    28
#include "gc_implementation/g1/heapRegion.hpp"
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    29
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    30
// Large buffer for some cases where the output might be larger than normal.
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
    31
#define HRS_ERR_MSG_BUFSZ 512
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
    32
typedef FormatBuffer<HRS_ERR_MSG_BUFSZ> hrs_err_msg;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    33
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    34
// Set verification will be forced either if someone defines
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    35
// 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
    36
// asserts are compiled in.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    37
#ifndef HEAP_REGION_SET_FORCE_VERIFY
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    38
#define HEAP_REGION_SET_FORCE_VERIFY defined(ASSERT)
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    39
#endif // HEAP_REGION_SET_FORCE_VERIFY
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    40
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    41
//////////////////// HeapRegionSetBase ////////////////////
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    42
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    43
// Base class for all the classes that represent heap region sets. It
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    44
// contains the basic attributes that each set needs to maintain
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    45
// (e.g., length, region num, used bytes sum) plus any shared
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    46
// functionality (e.g., verification).
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    47
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
    48
class hrs_ext_msg;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    49
10996
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
    50
typedef enum {
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
    51
  HRSPhaseNone,
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
    52
  HRSPhaseEvacuation,
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
    53
  HRSPhaseCleanup,
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
    54
  HRSPhaseFullGC
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
    55
} HRSPhase;
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
    56
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
    57
class HRSPhaseSetter;
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
    58
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    59
class HeapRegionSetBase VALUE_OBJ_CLASS_SPEC {
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
    60
  friend class hrs_ext_msg;
10996
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
    61
  friend class HRSPhaseSetter;
11577
0af7e6e062a7 7097586: G1: improve the per-space output when using jmap -heap
tonyp
parents: 10996
diff changeset
    62
  friend class VMStructs;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    63
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    64
protected:
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 11577
diff changeset
    65
  static uint calculate_region_num(HeapRegion* hr);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    66
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 11577
diff changeset
    67
  static uint _unrealistically_long_length;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    68
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    69
  // The number of regions added to the set. If the set contains
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    70
  // only humongous regions, this reflects only 'starts humongous'
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    71
  // regions and does not include 'continues humongous' ones.
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 11577
diff changeset
    72
  uint _length;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    73
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    74
  // The total number of regions represented by the set. If the set
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    75
  // does not contain humongous regions, this should be the same as
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    76
  // _length. If the set contains only humongous regions, this will
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    77
  // include the 'continues humongous' regions.
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 11577
diff changeset
    78
  uint _region_num;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    79
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    80
  // We don't keep track of the total capacity explicitly, we instead
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    81
  // recalculate it based on _region_num and the heap region size.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    82
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    83
  // The sum of used bytes in the all the regions in the set.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    84
  size_t _total_used_bytes;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    85
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    86
  const char* _name;
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
  bool        _verify_in_progress;
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 11577
diff changeset
    89
  uint        _calc_length;
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 11577
diff changeset
    90
  uint        _calc_region_num;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    91
  size_t      _calc_total_capacity_bytes;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    92
  size_t      _calc_total_used_bytes;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    93
10996
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
    94
  // This is here so that it can be used in the subclasses to assert
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
    95
  // something different depending on which phase the GC is in. This
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
    96
  // can be particularly helpful in the check_mt_safety() methods.
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
    97
  static HRSPhase _phase;
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
    98
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
    99
  // Only used by HRSPhaseSetter.
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
   100
  static void clear_phase();
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
   101
  static void set_phase(HRSPhase phase);
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
   102
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   103
  // verify_region() is used to ensure that the contents of a region
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   104
  // added to / removed from a set are consistent. Different sets
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   105
  // make different assumptions about the regions added to them. So
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   106
  // each set can override verify_region_extra(), which is called
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   107
  // from verify_region(), and do any extra verification it needs to
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   108
  // perform in that.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   109
  virtual const char* verify_region_extra(HeapRegion* hr) { return NULL; }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   110
  bool verify_region(HeapRegion* hr,
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   111
                     HeapRegionSetBase* expected_containing_set);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   112
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   113
  // Indicates whether all regions in the set should be humongous or
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   114
  // not. Only used during verification.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   115
  virtual bool regions_humongous() = 0;
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
  // Indicates whether all regions in the set should be empty or
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   118
  // not. Only used during verification.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   119
  virtual bool regions_empty() = 0;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   120
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   121
  // Subclasses can optionally override this to do MT safety protocol
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   122
  // checks. It is called in an assert from all methods that perform
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   123
  // updates on the set (and subclasses should also call it too).
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   124
  virtual bool check_mt_safety() { return true; }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   125
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   126
  // fill_in_ext_msg() writes the the values of the set's attributes
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   127
  // in the custom err_msg (hrs_ext_msg). fill_in_ext_msg_extra()
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   128
  // allows subclasses to append further information.
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   129
  virtual void fill_in_ext_msg_extra(hrs_ext_msg* msg) { }
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   130
  void fill_in_ext_msg(hrs_ext_msg* msg, const char* message);
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
  // It updates the fields of the set to reflect hr being added to
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   133
  // the set.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   134
  inline void update_for_addition(HeapRegion* hr);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   135
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   136
  // It updates the fields of the set to reflect hr being added to
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   137
  // the set and tags the region appropriately.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   138
  inline void add_internal(HeapRegion* hr);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   139
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   140
  // It updates the fields of the set to reflect hr being removed
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   141
  // from the set.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   142
  inline void update_for_removal(HeapRegion* hr);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   143
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   144
  // It updates the fields of the set to reflect hr being removed
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   145
  // from the set and tags the region appropriately.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   146
  inline void remove_internal(HeapRegion* hr);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   147
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   148
  // It clears all the fields of the sets. Note: it will not iterate
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   149
  // over the set and remove regions from it. It assumes that the
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   150
  // caller has already done so. It will literally just clear the fields.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   151
  virtual void clear();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   152
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   153
  HeapRegionSetBase(const char* name);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   154
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   155
public:
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 11577
diff changeset
   156
  static void set_unrealistically_long_length(uint len);
7923
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
  const char* name() { return _name; }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   159
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 11577
diff changeset
   160
  uint length() { return _length; }
7923
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
  bool is_empty() { return _length == 0; }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   163
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 11577
diff changeset
   164
  uint region_num() { return _region_num; }
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   165
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   166
  size_t total_capacity_bytes() {
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 11577
diff changeset
   167
    return (size_t) region_num() << HeapRegion::LogOfHRGrainBytes;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   168
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   169
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   170
  size_t total_used_bytes() { return _total_used_bytes; }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   171
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   172
  virtual void verify();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   173
  void verify_start();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   174
  void verify_next_region(HeapRegion* hr);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   175
  void verify_end();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   176
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   177
#if HEAP_REGION_SET_FORCE_VERIFY
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   178
  void verify_optional() {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   179
    verify();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   180
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   181
#else // HEAP_REGION_SET_FORCE_VERIFY
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   182
  void verify_optional() { }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   183
#endif // HEAP_REGION_SET_FORCE_VERIFY
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   184
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   185
  virtual void print_on(outputStream* out, bool print_contents = false);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   186
};
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
// Customized err_msg for heap region sets. Apart from a
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   189
// assert/guarantee-specific message it also prints out the values of
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   190
// the fields of the associated set. This can be very helpful in
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   191
// diagnosing failures.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   192
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   193
class hrs_ext_msg : public hrs_err_msg {
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   194
public:
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   195
  hrs_ext_msg(HeapRegionSetBase* set, const char* message) : hrs_err_msg("") {
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   196
    set->fill_in_ext_msg(this, message);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   197
  }
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
10996
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
   200
class HRSPhaseSetter {
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
   201
public:
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
   202
  HRSPhaseSetter(HRSPhase phase) {
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
   203
    HeapRegionSetBase::set_phase(phase);
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
   204
  }
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
   205
  ~HRSPhaseSetter() {
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
   206
    HeapRegionSetBase::clear_phase();
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
   207
  }
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
   208
};
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 9988
diff changeset
   209
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   210
// These two macros are provided for convenience, to keep the uses of
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   211
// these two asserts a bit more concise.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   212
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   213
#define hrs_assert_mt_safety_ok(_set_)                                        \
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   214
  do {                                                                        \
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   215
    assert((_set_)->check_mt_safety(), hrs_ext_msg((_set_), "MT safety"));    \
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   216
  } while (0)
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   217
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   218
#define hrs_assert_region_ok(_set_, _hr_, _expected_)                         \
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   219
  do {                                                                        \
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   220
    assert((_set_)->verify_region((_hr_), (_expected_)),                      \
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   221
           hrs_ext_msg((_set_), "region verification"));                      \
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   222
  } while (0)
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   223
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   224
//////////////////// HeapRegionSet ////////////////////
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   225
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   226
#define hrs_assert_sets_match(_set1_, _set2_)                                 \
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   227
  do {                                                                        \
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   228
    assert(((_set1_)->regions_humongous() ==                                  \
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   229
                                            (_set2_)->regions_humongous()) && \
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   230
           ((_set1_)->regions_empty() == (_set2_)->regions_empty()),          \
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   231
           hrs_err_msg("the contents of set %s and set %s should match",      \
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   232
                       (_set1_)->name(), (_set2_)->name()));                  \
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   233
  } while (0)
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
// This class represents heap region sets whose members are not
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   236
// explicitly tracked. It's helpful to group regions using such sets
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   237
// 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
   238
// the same interface (namely, the HeapRegionSetBase API).
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   239
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   240
class HeapRegionSet : public HeapRegionSetBase {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   241
protected:
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   242
  virtual const char* verify_region_extra(HeapRegion* hr) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   243
    if (hr->next() != NULL) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   244
      return "next() should always be NULL as we do not link the regions";
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   245
    }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   246
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   247
    return HeapRegionSetBase::verify_region_extra(hr);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   248
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   249
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   250
  HeapRegionSet(const char* name) : HeapRegionSetBase(name) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   251
    clear();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   252
  }
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
public:
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   255
  // It adds hr to the set. The region should not be a member of
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   256
  // another set.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   257
  inline void add(HeapRegion* hr);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   258
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   259
  // It removes hr from the set. The region should be a member of
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   260
  // this set.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   261
  inline void remove(HeapRegion* hr);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   262
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   263
  // It removes a region from the set. Instead of updating the fields
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   264
  // of the set to reflect this removal, it accumulates the updates
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   265
  // in proxy_set. The idea is that proxy_set is thread-local to
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   266
  // avoid multiple threads updating the fields of the set
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   267
  // concurrently and having to synchronize. The method
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   268
  // update_from_proxy() will update the fields of the set from the
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   269
  // proxy_set.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   270
  inline void remove_with_proxy(HeapRegion* hr, HeapRegionSet* proxy_set);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   271
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   272
  // After multiple calls to remove_with_proxy() the updates to the
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   273
  // fields of the set are accumulated in proxy_set. This call
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   274
  // updates the fields of the set from proxy_set.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   275
  void update_from_proxy(HeapRegionSet* proxy_set);
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
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   278
//////////////////// HeapRegionLinkedList ////////////////////
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   279
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   280
// A set that links all the regions added to it in a singly-linked
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   281
// list. We should try to avoid doing operations that iterate over
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   282
// such lists in performance critical paths. Typically we should
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   283
// add / remove one region at a time or concatenate two lists. All
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   284
// those operations are done in constant time.
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
class HeapRegionLinkedListIterator;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   287
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   288
class HeapRegionLinkedList : public HeapRegionSetBase {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   289
  friend class HeapRegionLinkedListIterator;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   290
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   291
private:
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   292
  HeapRegion* _head;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   293
  HeapRegion* _tail;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   294
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   295
  // These are provided for use by the friend classes.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   296
  HeapRegion* head() { return _head; }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   297
  HeapRegion* tail() { return _tail; }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   298
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   299
protected:
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   300
  virtual void fill_in_ext_msg_extra(hrs_ext_msg* msg);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   301
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   302
  // See the comment for HeapRegionSetBase::clear()
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   303
  virtual void clear();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   304
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   305
  HeapRegionLinkedList(const char* name) : HeapRegionSetBase(name) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   306
    clear();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   307
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   308
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   309
public:
8927
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   310
  // It adds hr to the list as the new head. The region should not be
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   311
  // a member of another set.
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   312
  inline void add_as_head(HeapRegion* hr);
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   313
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   314
  // It adds hr to the list as the new tail. The region should not be
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   315
  // a member of another set.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   316
  inline void add_as_tail(HeapRegion* hr);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   317
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   318
  // It removes and returns the head of the list. It assumes that the
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   319
  // list is not empty so it will return a non-NULL value.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   320
  inline HeapRegion* remove_head();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   321
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   322
  // Convenience method.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   323
  inline HeapRegion* remove_head_or_null();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   324
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   325
  // It moves the regions from from_list to this list and empties
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   326
  // from_list. The new regions will appear in the same order as they
8927
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   327
  // were in from_list and be linked in the beginning of this list.
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   328
  void add_as_head(HeapRegionLinkedList* from_list);
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   329
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   330
  // It moves the regions from from_list to this list and empties
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   331
  // from_list. The new regions will appear in the same order as they
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   332
  // were in from_list and be linked in the end of this list.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   333
  void add_as_tail(HeapRegionLinkedList* from_list);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   334
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   335
  // It empties the list by removing all regions from it.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   336
  void remove_all();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   337
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   338
  // It removes all regions in the list that are pending for removal
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   339
  // (i.e., they have been tagged with "pending_removal"). The list
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   340
  // must not be empty, target_count should reflect the exact number
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   341
  // of regions that are pending for removal in the list, and
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   342
  // target_count should be > 1 (currently, we never need to remove a
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   343
  // single region using this).
12381
1438e0fbfa27 7157073: G1: type change size_t -> uint for region counts / indexes
tonyp
parents: 11577
diff changeset
   344
  void remove_all_pending(uint target_count);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   345
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   346
  virtual void verify();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   347
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   348
  virtual void print_on(outputStream* out, bool print_contents = false);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   349
};
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   350
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   351
//////////////////// HeapRegionLinkedListIterator ////////////////////
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   352
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   353
// Iterator class that provides a convenient way to iterate over the
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   354
// regions of a HeapRegionLinkedList instance.
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   355
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   356
class HeapRegionLinkedListIterator : public StackObj {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   357
private:
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   358
  HeapRegionLinkedList* _list;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   359
  HeapRegion*           _curr;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   360
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   361
public:
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   362
  bool more_available() {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   363
    return _curr != NULL;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   364
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   365
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   366
  HeapRegion* get_next() {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   367
    assert(more_available(),
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   368
           "get_next() should be called when more regions are available");
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   369
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   370
    // 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
   371
    // do the "cycle" check.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   372
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   373
    HeapRegion* hr = _curr;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   374
    assert(_list->verify_region(hr, _list), "region verification");
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   375
    _curr = hr->next();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   376
    return hr;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   377
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   378
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   379
  HeapRegionLinkedListIterator(HeapRegionLinkedList* list)
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   380
    : _curr(NULL), _list(list) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   381
    _curr = list->head();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   382
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   383
};
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   384
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   385
#endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_HPP