src/share/vm/gc_implementation/g1/heapRegionSet.inline.hpp

changeset 2472
0fa27f37d4d4
child 2643
1216415d8e35
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/gc_implementation/g1/heapRegionSet.inline.hpp	Wed Jan 19 19:30:42 2011 -0500
     1.3 @@ -0,0 +1,159 @@
     1.4 +/*
     1.5 + * copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP
    1.29 +#define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP
    1.30 +
    1.31 +#include "gc_implementation/g1/heapRegionSet.hpp"
    1.32 +
    1.33 +//////////////////// HeapRegionSetBase ////////////////////
    1.34 +
    1.35 +inline void HeapRegionSetBase::update_for_addition(HeapRegion* hr) {
    1.36 +  // Assumes the caller has already verified the region.
    1.37 +
    1.38 +  _length           += 1;
    1.39 +  if (!hr->isHumongous()) {
    1.40 +    _region_num     += 1;
    1.41 +  } else {
    1.42 +    _region_num     += calculate_region_num(hr);
    1.43 +  }
    1.44 +  _total_used_bytes += hr->used();
    1.45 +}
    1.46 +
    1.47 +inline void HeapRegionSetBase::add_internal(HeapRegion* hr) {
    1.48 +  hrl_assert_region_ok(this, hr, NULL);
    1.49 +  assert(hr->next() == NULL, hrl_ext_msg(this, "should not already be linked"));
    1.50 +
    1.51 +  update_for_addition(hr);
    1.52 +  hr->set_containing_set(this);
    1.53 +}
    1.54 +
    1.55 +inline void HeapRegionSetBase::update_for_removal(HeapRegion* hr) {
    1.56 +  // Assumes the caller has already verified the region.
    1.57 +  assert(_length > 0, hrl_ext_msg(this, "pre-condition"));
    1.58 +  _length -= 1;
    1.59 +
    1.60 +  size_t region_num_diff;
    1.61 +  if (!hr->isHumongous()) {
    1.62 +    region_num_diff = 1;
    1.63 +  } else {
    1.64 +    region_num_diff = calculate_region_num(hr);
    1.65 +  }
    1.66 +  assert(region_num_diff <= _region_num,
    1.67 +         hrl_err_msg("[%s] region's region num: "SIZE_FORMAT" "
    1.68 +                     "should be <= region num: "SIZE_FORMAT,
    1.69 +                     name(), region_num_diff, _region_num));
    1.70 +  _region_num -= region_num_diff;
    1.71 +
    1.72 +  size_t used_bytes = hr->used();
    1.73 +  assert(used_bytes <= _total_used_bytes,
    1.74 +         hrl_err_msg("[%s] region's used bytes: "SIZE_FORMAT" "
    1.75 +                     "should be <= used bytes: "SIZE_FORMAT,
    1.76 +                     name(), used_bytes, _total_used_bytes));
    1.77 +  _total_used_bytes -= used_bytes;
    1.78 +}
    1.79 +
    1.80 +inline void HeapRegionSetBase::remove_internal(HeapRegion* hr) {
    1.81 +  hrl_assert_region_ok(this, hr, this);
    1.82 +  assert(hr->next() == NULL, hrl_ext_msg(this, "should already be unlinked"));
    1.83 +
    1.84 +  hr->set_containing_set(NULL);
    1.85 +  update_for_removal(hr);
    1.86 +}
    1.87 +
    1.88 +//////////////////// HeapRegionSet ////////////////////
    1.89 +
    1.90 +inline void HeapRegionSet::add(HeapRegion* hr) {
    1.91 +  hrl_assert_mt_safety_ok(this);
    1.92 +  // add_internal() will verify the region.
    1.93 +  add_internal(hr);
    1.94 +}
    1.95 +
    1.96 +inline void HeapRegionSet::remove(HeapRegion* hr) {
    1.97 +  hrl_assert_mt_safety_ok(this);
    1.98 +  // remove_internal() will verify the region.
    1.99 +  remove_internal(hr);
   1.100 +}
   1.101 +
   1.102 +inline void HeapRegionSet::remove_with_proxy(HeapRegion* hr,
   1.103 +                                             HeapRegionSet* proxy_set) {
   1.104 +  // No need to fo the MT safety check here given that this method
   1.105 +  // does not update the contents of the set but instead accumulates
   1.106 +  // the changes in proxy_set which is assumed to be thread-local.
   1.107 +  hrl_assert_sets_match(this, proxy_set);
   1.108 +  hrl_assert_region_ok(this, hr, this);
   1.109 +
   1.110 +  hr->set_containing_set(NULL);
   1.111 +  proxy_set->update_for_addition(hr);
   1.112 +}
   1.113 +
   1.114 +//////////////////// HeapRegionLinkedList ////////////////////
   1.115 +
   1.116 +inline void HeapRegionLinkedList::add_as_tail(HeapRegion* hr) {
   1.117 +  hrl_assert_mt_safety_ok(this);
   1.118 +  assert((length() == 0 && _head == NULL && _tail == NULL) ||
   1.119 +         (length() >  0 && _head != NULL && _tail != NULL),
   1.120 +         hrl_ext_msg(this, "invariant"));
   1.121 +  // add_internal() will verify the region.
   1.122 +  add_internal(hr);
   1.123 +
   1.124 +  // Now link the region.
   1.125 +  if (_tail != NULL) {
   1.126 +    _tail->set_next(hr);
   1.127 +  } else {
   1.128 +    _head = hr;
   1.129 +  }
   1.130 +  _tail = hr;
   1.131 +}
   1.132 +
   1.133 +inline HeapRegion* HeapRegionLinkedList::remove_head() {
   1.134 +  hrl_assert_mt_safety_ok(this);
   1.135 +  assert(!is_empty(), hrl_ext_msg(this, "the list should not be empty"));
   1.136 +  assert(length() > 0 && _head != NULL && _tail != NULL,
   1.137 +         hrl_ext_msg(this, "invariant"));
   1.138 +
   1.139 +  // We need to unlink it first.
   1.140 +  HeapRegion* hr = _head;
   1.141 +  _head = hr->next();
   1.142 +  if (_head == NULL) {
   1.143 +    _tail = NULL;
   1.144 +  }
   1.145 +  hr->set_next(NULL);
   1.146 +
   1.147 +  // remove_internal() will verify the region.
   1.148 +  remove_internal(hr);
   1.149 +  return hr;
   1.150 +}
   1.151 +
   1.152 +inline HeapRegion* HeapRegionLinkedList::remove_head_or_null() {
   1.153 +  hrl_assert_mt_safety_ok(this);
   1.154 +
   1.155 +  if (!is_empty()) {
   1.156 +    return remove_head();
   1.157 +  } else {
   1.158 +    return NULL;
   1.159 +  }
   1.160 +}
   1.161 +
   1.162 +#endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP

mercurial