hotspot/src/share/vm/gc_implementation/g1/heapRegionSet.cpp
author tonyp
Mon, 07 Nov 2011 22:11:12 -0500
changeset 10996 b9d07748e5b3
parent 8927 461fa7ee5254
child 12381 1438e0fbfa27
permissions -rw-r--r--
7092309: G1: introduce old region set Summary: Keep track of all the old regions in the heap with a heap region set. Reviewed-by: brutisso, johnc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     1
/*
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
     2
 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
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
#include "precompiled.hpp"
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    26
#include "gc_implementation/g1/heapRegionSet.inline.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
size_t HeapRegionSetBase::_unrealistically_long_length = 0;
10996
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 8927
diff changeset
    29
HRSPhase HeapRegionSetBase::_phase = HRSPhaseNone;
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    30
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    31
//////////////////// HeapRegionSetBase ////////////////////
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    32
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    33
void HeapRegionSetBase::set_unrealistically_long_length(size_t len) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    34
  guarantee(_unrealistically_long_length == 0, "should only be set once");
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    35
  _unrealistically_long_length = len;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    36
}
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    37
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    38
size_t HeapRegionSetBase::calculate_region_num(HeapRegion* hr) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    39
  assert(hr->startsHumongous(), "pre-condition");
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    40
  assert(hr->capacity() % HeapRegion::GrainBytes == 0, "invariant");
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    41
  size_t region_num = hr->capacity() >> HeapRegion::LogOfHRGrainBytes;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    42
  assert(region_num > 0, "sanity");
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    43
  return region_num;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    44
}
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    45
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
    46
void HeapRegionSetBase::fill_in_ext_msg(hrs_ext_msg* msg, const char* message) {
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    47
  msg->append("[%s] %s "
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    48
              "ln: "SIZE_FORMAT" rn: "SIZE_FORMAT" "
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    49
              "cy: "SIZE_FORMAT" ud: "SIZE_FORMAT,
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    50
              name(), message, length(), region_num(),
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    51
              total_capacity_bytes(), total_used_bytes());
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    52
  fill_in_ext_msg_extra(msg);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    53
}
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    54
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    55
bool HeapRegionSetBase::verify_region(HeapRegion* hr,
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    56
                                  HeapRegionSetBase* expected_containing_set) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    57
  const char* error_message = NULL;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    58
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    59
  if (!regions_humongous()) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    60
    if (hr->isHumongous()) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    61
      error_message = "the region should not be humongous";
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    62
    }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    63
  } else {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    64
    if (!hr->isHumongous() || !hr->startsHumongous()) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    65
      error_message = "the region should be 'starts humongous'";
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    66
    }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    67
  }
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
  if (!regions_empty()) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    70
    if (hr->is_empty()) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    71
      error_message = "the region should not be empty";
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    72
    }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    73
  } else {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    74
    if (!hr->is_empty()) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    75
      error_message = "the region should be empty";
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    76
    }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    77
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    78
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    79
#ifdef ASSERT
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    80
  // The _containing_set field is only available when ASSERT is defined.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    81
  if (hr->containing_set() != expected_containing_set) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    82
    error_message = "inconsistent containing set found";
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    83
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    84
#endif // ASSERT
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* extra_error_message = verify_region_extra(hr);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    87
  if (extra_error_message != NULL) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    88
    error_message = extra_error_message;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    89
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    90
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    91
  if (error_message != NULL) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    92
    outputStream* out = tty;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    93
    out->cr();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    94
    out->print_cr("## [%s] %s", name(), error_message);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    95
    out->print_cr("## Offending Region: "PTR_FORMAT, hr);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    96
    out->print_cr("   "HR_FORMAT, HR_FORMAT_PARAMS(hr));
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    97
#ifdef ASSERT
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    98
    out->print_cr("   containing set: "PTR_FORMAT, hr->containing_set());
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
    99
#endif // ASSERT
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   100
    out->print_cr("## Offending Region Set: "PTR_FORMAT, this);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   101
    print_on(out);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   102
    return false;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   103
  } else {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   104
    return true;
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
}
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   107
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   108
void HeapRegionSetBase::verify() {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   109
  // It's important that we also observe the MT safety protocol even
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   110
  // for the verification calls. If we do verification without the
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   111
  // appropriate locks and the set changes underneath our feet
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   112
  // verification might fail and send us on a wild goose chase.
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   113
  hrs_assert_mt_safety_ok(this);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   114
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   115
  guarantee(( is_empty() && length() == 0 && region_num() == 0 &&
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   116
              total_used_bytes() == 0 && total_capacity_bytes() == 0) ||
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   117
            (!is_empty() && length() >= 0 && region_num() >= 0 &&
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   118
              total_used_bytes() >= 0 && total_capacity_bytes() >= 0),
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   119
            hrs_ext_msg(this, "invariant"));
7923
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
  guarantee((!regions_humongous() && region_num() == length()) ||
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   122
            ( regions_humongous() && region_num() >= length()),
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   123
            hrs_ext_msg(this, "invariant"));
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   124
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   125
  guarantee(!regions_empty() || total_used_bytes() == 0,
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   126
            hrs_ext_msg(this, "invariant"));
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   127
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   128
  guarantee(total_used_bytes() <= total_capacity_bytes(),
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   129
            hrs_ext_msg(this, "invariant"));
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   130
}
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
void HeapRegionSetBase::verify_start() {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   133
  // See comment in verify() about MT safety and verification.
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   134
  hrs_assert_mt_safety_ok(this);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   135
  assert(!_verify_in_progress,
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   136
         hrs_ext_msg(this, "verification should not be in progress"));
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   137
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   138
  // Do the basic verification first before we do the checks over the regions.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   139
  HeapRegionSetBase::verify();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   140
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   141
  _calc_length               = 0;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   142
  _calc_region_num           = 0;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   143
  _calc_total_capacity_bytes = 0;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   144
  _calc_total_used_bytes     = 0;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   145
  _verify_in_progress        = true;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   146
}
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
void HeapRegionSetBase::verify_next_region(HeapRegion* hr) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   149
  // See comment in verify() about MT safety and verification.
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   150
  hrs_assert_mt_safety_ok(this);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   151
  assert(_verify_in_progress,
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   152
         hrs_ext_msg(this, "verification should be in progress"));
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   153
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   154
  guarantee(verify_region(hr, this), hrs_ext_msg(this, "region verification"));
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
  _calc_length               += 1;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   157
  if (!hr->isHumongous()) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   158
    _calc_region_num         += 1;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   159
  } else {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   160
    _calc_region_num         += calculate_region_num(hr);
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
  _calc_total_capacity_bytes += hr->capacity();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   163
  _calc_total_used_bytes     += hr->used();
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
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   166
void HeapRegionSetBase::verify_end() {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   167
  // See comment in verify() about MT safety and verification.
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   168
  hrs_assert_mt_safety_ok(this);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   169
  assert(_verify_in_progress,
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   170
         hrs_ext_msg(this, "verification should be in progress"));
7923
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
  guarantee(length() == _calc_length,
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   173
            hrs_err_msg("[%s] length: "SIZE_FORMAT" should be == "
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   174
                        "calc length: "SIZE_FORMAT,
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   175
                        name(), length(), _calc_length));
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
  guarantee(region_num() == _calc_region_num,
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   178
            hrs_err_msg("[%s] region num: "SIZE_FORMAT" should be == "
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   179
                        "calc region num: "SIZE_FORMAT,
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   180
                        name(), region_num(), _calc_region_num));
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   181
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   182
  guarantee(total_capacity_bytes() == _calc_total_capacity_bytes,
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   183
            hrs_err_msg("[%s] capacity bytes: "SIZE_FORMAT" should be == "
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   184
                        "calc capacity bytes: "SIZE_FORMAT,
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   185
                        name(),
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   186
                        total_capacity_bytes(), _calc_total_capacity_bytes));
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
  guarantee(total_used_bytes() == _calc_total_used_bytes,
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   189
            hrs_err_msg("[%s] used bytes: "SIZE_FORMAT" should be == "
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   190
                        "calc used bytes: "SIZE_FORMAT,
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   191
                        name(), total_used_bytes(), _calc_total_used_bytes));
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   192
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   193
  _verify_in_progress = false;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   194
}
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   195
10996
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 8927
diff changeset
   196
void HeapRegionSetBase::clear_phase() {
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 8927
diff changeset
   197
  assert(_phase != HRSPhaseNone, "pre-condition");
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 8927
diff changeset
   198
  _phase = HRSPhaseNone;
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 8927
diff changeset
   199
}
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 8927
diff changeset
   200
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 8927
diff changeset
   201
void HeapRegionSetBase::set_phase(HRSPhase phase) {
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 8927
diff changeset
   202
  assert(_phase == HRSPhaseNone, "pre-condition");
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 8927
diff changeset
   203
  assert(phase != HRSPhaseNone, "pre-condition");
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 8927
diff changeset
   204
  _phase = phase;
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 8927
diff changeset
   205
}
b9d07748e5b3 7092309: G1: introduce old region set
tonyp
parents: 8927
diff changeset
   206
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   207
void HeapRegionSetBase::print_on(outputStream* out, bool print_contents) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   208
  out->cr();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   209
  out->print_cr("Set: %s ("PTR_FORMAT")", name(), this);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   210
  out->print_cr("  Region Assumptions");
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   211
  out->print_cr("    humongous         : %s", BOOL_TO_STR(regions_humongous()));
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   212
  out->print_cr("    empty             : %s", BOOL_TO_STR(regions_empty()));
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   213
  out->print_cr("  Attributes");
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   214
  out->print_cr("    length            : "SIZE_FORMAT_W(14), length());
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   215
  out->print_cr("    region num        : "SIZE_FORMAT_W(14), region_num());
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   216
  out->print_cr("    total capacity    : "SIZE_FORMAT_W(14)" bytes",
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   217
                total_capacity_bytes());
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   218
  out->print_cr("    total used        : "SIZE_FORMAT_W(14)" bytes",
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   219
                total_used_bytes());
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
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   222
void HeapRegionSetBase::clear() {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   223
  _length           = 0;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   224
  _region_num       = 0;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   225
  _total_used_bytes = 0;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   226
}
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   227
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   228
HeapRegionSetBase::HeapRegionSetBase(const char* name)
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   229
  : _name(name), _verify_in_progress(false),
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   230
    _calc_length(0), _calc_region_num(0),
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   231
    _calc_total_capacity_bytes(0), _calc_total_used_bytes(0) { }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   232
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   233
//////////////////// HeapRegionSet ////////////////////
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
void HeapRegionSet::update_from_proxy(HeapRegionSet* proxy_set) {
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   236
  hrs_assert_mt_safety_ok(this);
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   237
  hrs_assert_mt_safety_ok(proxy_set);
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   238
  hrs_assert_sets_match(this, proxy_set);
7923
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
  verify_optional();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   241
  proxy_set->verify_optional();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   242
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   243
  if (proxy_set->is_empty()) return;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   244
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   245
  assert(proxy_set->length() <= _length,
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   246
         hrs_err_msg("[%s] proxy set length: "SIZE_FORMAT" "
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   247
                     "should be <= length: "SIZE_FORMAT,
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   248
                     name(), proxy_set->length(), _length));
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   249
  _length -= proxy_set->length();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   250
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   251
  assert(proxy_set->region_num() <= _region_num,
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   252
         hrs_err_msg("[%s] proxy set region num: "SIZE_FORMAT" "
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   253
                     "should be <= region num: "SIZE_FORMAT,
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   254
                     name(), proxy_set->region_num(), _region_num));
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   255
  _region_num -= proxy_set->region_num();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   256
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   257
  assert(proxy_set->total_used_bytes() <= _total_used_bytes,
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   258
         hrs_err_msg("[%s] proxy set used bytes: "SIZE_FORMAT" "
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   259
                     "should be <= used bytes: "SIZE_FORMAT,
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   260
                     name(), proxy_set->total_used_bytes(),
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   261
                     _total_used_bytes));
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   262
  _total_used_bytes -= proxy_set->total_used_bytes();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   263
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   264
  proxy_set->clear();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   265
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   266
  verify_optional();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   267
  proxy_set->verify_optional();
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
//////////////////// HeapRegionLinkedList ////////////////////
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   271
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   272
void HeapRegionLinkedList::fill_in_ext_msg_extra(hrs_ext_msg* msg) {
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   273
  msg->append(" hd: "PTR_FORMAT" tl: "PTR_FORMAT, head(), tail());
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   274
}
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   275
8927
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   276
void HeapRegionLinkedList::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
   277
  hrs_assert_mt_safety_ok(this);
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   278
  hrs_assert_mt_safety_ok(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
   279
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   280
  verify_optional();
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   281
  from_list->verify_optional();
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   282
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   283
  if (from_list->is_empty()) return;
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   284
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   285
#ifdef ASSERT
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   286
  HeapRegionLinkedListIterator iter(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
   287
  while (iter.more_available()) {
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   288
    HeapRegion* hr = iter.get_next();
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   289
    // In set_containing_set() we check that we either set the value
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   290
    // from NULL to non-NULL or vice versa to catch bugs. So, we have
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   291
    // to NULL it first before setting it to the value.
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   292
    hr->set_containing_set(NULL);
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   293
    hr->set_containing_set(this);
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   294
  }
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   295
#endif // ASSERT
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   296
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   297
  if (_head != NULL) {
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   298
    assert(length() >  0 && _tail != NULL, hrs_ext_msg(this, "invariant"));
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   299
    from_list->_tail->set_next(_head);
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   300
  } else {
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   301
    assert(length() == 0 && _head == NULL, hrs_ext_msg(this, "invariant"));
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   302
    _tail = from_list->_tail;
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   303
  }
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   304
  _head = from_list->_head;
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   305
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   306
  _length           += from_list->length();
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   307
  _region_num       += from_list->region_num();
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   308
  _total_used_bytes += from_list->total_used_bytes();
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   309
  from_list->clear();
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   310
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   311
  verify_optional();
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   312
  from_list->verify_optional();
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   313
}
461fa7ee5254 7029458: G1: Add newly-reclaimed regions to the beginning of the region free list, not the end
tonyp
parents: 8680
diff changeset
   314
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   315
void HeapRegionLinkedList::add_as_tail(HeapRegionLinkedList* from_list) {
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   316
  hrs_assert_mt_safety_ok(this);
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   317
  hrs_assert_mt_safety_ok(from_list);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   318
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   319
  verify_optional();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   320
  from_list->verify_optional();
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
  if (from_list->is_empty()) return;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   323
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   324
#ifdef ASSERT
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   325
  HeapRegionLinkedListIterator iter(from_list);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   326
  while (iter.more_available()) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   327
    HeapRegion* hr = iter.get_next();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   328
    // In set_containing_set() we check that we either set the value
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   329
    // from NULL to non-NULL or vice versa to catch bugs. So, we have
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   330
    // to NULL it first before setting it to the value.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   331
    hr->set_containing_set(NULL);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   332
    hr->set_containing_set(this);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   333
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   334
#endif // ASSERT
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   335
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   336
  if (_tail != NULL) {
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   337
    assert(length() >  0 && _head != NULL, hrs_ext_msg(this, "invariant"));
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   338
    _tail->set_next(from_list->_head);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   339
  } else {
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   340
    assert(length() == 0 && _head == NULL, hrs_ext_msg(this, "invariant"));
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   341
    _head = from_list->_head;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   342
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   343
  _tail = from_list->_tail;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   344
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   345
  _length           += from_list->length();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   346
  _region_num       += from_list->region_num();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   347
  _total_used_bytes += from_list->total_used_bytes();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   348
  from_list->clear();
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
  verify_optional();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   351
  from_list->verify_optional();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   352
}
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   353
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   354
void HeapRegionLinkedList::remove_all() {
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   355
  hrs_assert_mt_safety_ok(this);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   356
  verify_optional();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   357
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   358
  HeapRegion* curr = _head;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   359
  while (curr != NULL) {
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   360
    hrs_assert_region_ok(this, curr, this);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   361
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   362
    HeapRegion* next = curr->next();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   363
    curr->set_next(NULL);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   364
    curr->set_containing_set(NULL);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   365
    curr = next;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   366
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   367
  clear();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   368
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   369
  verify_optional();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   370
}
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   371
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   372
void HeapRegionLinkedList::remove_all_pending(size_t target_count) {
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   373
  hrs_assert_mt_safety_ok(this);
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   374
  assert(target_count > 1, hrs_ext_msg(this, "pre-condition"));
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   375
  assert(!is_empty(), hrs_ext_msg(this, "pre-condition"));
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   376
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   377
  verify_optional();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   378
  DEBUG_ONLY(size_t old_length = length();)
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   379
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   380
  HeapRegion* curr = _head;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   381
  HeapRegion* prev = NULL;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   382
  size_t count = 0;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   383
  while (curr != NULL) {
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   384
    hrs_assert_region_ok(this, curr, this);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   385
    HeapRegion* next = curr->next();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   386
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   387
    if (curr->pending_removal()) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   388
      assert(count < target_count,
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   389
             hrs_err_msg("[%s] should not come across more regions "
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   390
                         "pending for removal than target_count: "SIZE_FORMAT,
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   391
                         name(), target_count));
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   392
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   393
      if (prev == NULL) {
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   394
        assert(_head == curr, hrs_ext_msg(this, "invariant"));
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   395
        _head = next;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   396
      } else {
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   397
        assert(_head != curr, hrs_ext_msg(this, "invariant"));
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   398
        prev->set_next(next);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   399
      }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   400
      if (next == NULL) {
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   401
        assert(_tail == curr, hrs_ext_msg(this, "invariant"));
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   402
        _tail = prev;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   403
      } else {
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   404
        assert(_tail != curr, hrs_ext_msg(this, "invariant"));
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   405
      }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   406
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   407
      curr->set_next(NULL);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   408
      remove_internal(curr);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   409
      curr->set_pending_removal(false);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   410
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   411
      count += 1;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   412
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   413
      // If we have come across the target number of regions we can
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   414
      // just bail out. However, for debugging purposes, we can just
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   415
      // carry on iterating to make sure there are not more regions
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   416
      // tagged with pending removal.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   417
      DEBUG_ONLY(if (count == target_count) break;)
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   418
    } else {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   419
      prev = curr;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   420
    }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   421
    curr = next;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   422
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   423
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   424
  assert(count == target_count,
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   425
         hrs_err_msg("[%s] count: "SIZE_FORMAT" should be == "
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   426
                     "target_count: "SIZE_FORMAT, name(), count, target_count));
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   427
  assert(length() + target_count == old_length,
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   428
         hrs_err_msg("[%s] new length should be consistent "
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   429
                     "new length: "SIZE_FORMAT" old length: "SIZE_FORMAT" "
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   430
                     "target_count: "SIZE_FORMAT,
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   431
                     name(), length(), old_length, target_count));
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   432
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   433
  verify_optional();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   434
}
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   435
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   436
void HeapRegionLinkedList::verify() {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   437
  // See comment in HeapRegionSetBase::verify() about MT safety and
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   438
  // verification.
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   439
  hrs_assert_mt_safety_ok(this);
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   440
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   441
  // This will also do the basic verification too.
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   442
  verify_start();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   443
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   444
  HeapRegion* curr  = _head;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   445
  HeapRegion* prev1 = NULL;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   446
  HeapRegion* prev0 = NULL;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   447
  size_t      count = 0;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   448
  while (curr != NULL) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   449
    verify_next_region(curr);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   450
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   451
    count += 1;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   452
    guarantee(count < _unrealistically_long_length,
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   453
              hrs_err_msg("[%s] the calculated length: "SIZE_FORMAT" "
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   454
                          "seems very long, is there maybe a cycle? "
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   455
                          "curr: "PTR_FORMAT" prev0: "PTR_FORMAT" "
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   456
                          "prev1: "PTR_FORMAT" length: "SIZE_FORMAT,
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   457
                          name(), count, curr, prev0, prev1, length()));
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   458
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   459
    prev1 = prev0;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   460
    prev0 = curr;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   461
    curr  = curr->next();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   462
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   463
8680
f1c414e16a4c 7014923: G1: code cleanup
tonyp
parents: 7923
diff changeset
   464
  guarantee(_tail == prev0, hrs_ext_msg(this, "post-condition"));
7923
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   465
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   466
  verify_end();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   467
}
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   468
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   469
void HeapRegionLinkedList::clear() {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   470
  HeapRegionSetBase::clear();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   471
  _head = NULL;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   472
  _tail = NULL;
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   473
}
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   474
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   475
void HeapRegionLinkedList::print_on(outputStream* out, bool print_contents) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   476
  HeapRegionSetBase::print_on(out, print_contents);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   477
  out->print_cr("  Linking");
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   478
  out->print_cr("    head              : "PTR_FORMAT, _head);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   479
  out->print_cr("    tail              : "PTR_FORMAT, _tail);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   480
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   481
  if (print_contents) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   482
    out->print_cr("  Contents");
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   483
    HeapRegionLinkedListIterator iter(this);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   484
    while (iter.more_available()) {
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   485
      HeapRegion* hr = iter.get_next();
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   486
      hr->print_on(out);
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   487
    }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   488
  }
fc200fcd4e05 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
   489
}