heapRegionSet.inline.hpp 4.2 KB
Newer Older
1
/*
2
 * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 *
 */

#ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP
#define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP

#include "gc_implementation/g1/heapRegionSet.hpp"

30 31 32
inline void HeapRegionSetBase::add(HeapRegion* hr) {
  check_mt_safety();
  assert(hr->containing_set() == NULL, hrs_ext_msg(this, "should not already have a containing set %u"));
33 34
  assert(hr->next() == NULL, hrs_ext_msg(this, "should not already be linked"));
  assert(hr->prev() == NULL, hrs_ext_msg(this, "should not already be linked"));
35

36
  _count.increment(1u, hr->capacity());
37
  hr->set_containing_set(this);
38
  verify_region(hr);
39 40
}

41 42 43
inline void HeapRegionSetBase::remove(HeapRegion* hr) {
  check_mt_safety();
  verify_region(hr);
44 45
  assert(hr->next() == NULL, hrs_ext_msg(this, "should already be unlinked"));
  assert(hr->prev() == NULL, hrs_ext_msg(this, "should already be unlinked"));
46 47

  hr->set_containing_set(NULL);
48 49
  assert(_count.length() > 0, hrs_ext_msg(this, "pre-condition"));
  _count.decrement(1u, hr->capacity());
50 51
}

52
inline void FreeRegionList::add_ordered(HeapRegion* hr) {
53
  assert((length() == 0 && _head == NULL && _tail == NULL && _last == NULL) ||
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
         (length() >  0 && _head != NULL && _tail != NULL),
         hrs_ext_msg(this, "invariant"));
  // add() will verify the region and check mt safety.
  add(hr);

  // Now link the region
  if (_head != NULL) {
    HeapRegion* curr;

    if (_last != NULL && _last->hrs_index() < hr->hrs_index()) {
      curr = _last;
    } else {
      curr = _head;
    }

    // Find first entry with a Region Index larger than entry to insert.
    while (curr != NULL && curr->hrs_index() < hr->hrs_index()) {
      curr = curr->next();
    }

    hr->set_next(curr);

    if (curr == NULL) {
      // Adding at the end
      hr->set_prev(_tail);
      _tail->set_next(hr);
      _tail = hr;
    } else if (curr->prev() == NULL) {
      // Adding at the beginning
      hr->set_prev(NULL);
      _head = hr;
      curr->set_prev(hr);
    } else {
      hr->set_prev(curr->prev());
      hr->prev()->set_next(hr);
      curr->set_prev(hr);
    }
  } else {
    // The list was empty
    _tail = hr;
    _head = hr;
  }
  _last = hr;
}

99 100 101
inline HeapRegion* FreeRegionList::remove_from_head_impl() {
  HeapRegion* result = _head;
  _head = result->next();
102 103
  if (_head == NULL) {
    _tail = NULL;
104 105
  } else {
    _head->set_prev(NULL);
106
  }
107 108 109
  result->set_next(NULL);
  return result;
}
110

111 112
inline HeapRegion* FreeRegionList::remove_from_tail_impl() {
  HeapRegion* result = _tail;
113

114 115 116 117 118 119 120 121
  _tail = result->prev();
  if (_tail == NULL) {
    _head = NULL;
  } else {
    _tail->set_next(NULL);
  }
  result->set_prev(NULL);
  return result;
122 123
}

124
inline HeapRegion* FreeRegionList::remove_region(bool from_head) {
125
  check_mt_safety();
126 127 128
  verify_optional();

  if (is_empty()) {
129 130
    return NULL;
  }
131 132 133
  assert(length() > 0 && _head != NULL && _tail != NULL,
         hrs_ext_msg(this, "invariant"));

134
  HeapRegion* hr;
135

136 137
  if (from_head) {
    hr = remove_from_head_impl();
138
  } else {
139
    hr = remove_from_tail_impl();
140 141 142 143 144 145 146 147 148 149 150
  }

  if (_last == hr) {
    _last = NULL;
  }

  // remove() will verify the region and check mt safety.
  remove(hr);
  return hr;
}

151
#endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP
152