2011-01-19 19:30:42 -05:00
|
|
|
/*
|
2014-02-28 15:27:09 +01:00
|
|
|
* Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
|
2011-01-19 19:30:42 -05:00
|
|
|
* 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"
|
|
|
|
|
2014-03-14 10:15:46 +01:00
|
|
|
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"));
|
2014-04-03 16:20:16 +02:00
|
|
|
assert(hr->next() == NULL && hr->prev() == NULL, hrs_ext_msg(this, "should not already be linked"));
|
2011-01-19 19:30:42 -05:00
|
|
|
|
2014-03-14 10:15:46 +01:00
|
|
|
_count.increment(1u, hr->capacity());
|
2011-01-19 19:30:42 -05:00
|
|
|
hr->set_containing_set(this);
|
2014-03-14 10:15:46 +01:00
|
|
|
verify_region(hr);
|
2011-01-19 19:30:42 -05:00
|
|
|
}
|
|
|
|
|
2014-03-14 10:15:46 +01:00
|
|
|
inline void HeapRegionSetBase::remove(HeapRegion* hr) {
|
|
|
|
check_mt_safety();
|
|
|
|
verify_region(hr);
|
2014-04-03 16:20:16 +02:00
|
|
|
assert(hr->next() == NULL && hr->prev() == NULL, hrs_ext_msg(this, "should already be unlinked"));
|
2011-01-19 19:30:42 -05:00
|
|
|
|
|
|
|
hr->set_containing_set(NULL);
|
2014-03-14 10:15:46 +01:00
|
|
|
assert(_count.length() > 0, hrs_ext_msg(this, "pre-condition"));
|
|
|
|
_count.decrement(1u, hr->capacity());
|
2011-01-19 19:30:42 -05:00
|
|
|
}
|
|
|
|
|
2014-02-28 15:27:09 +01:00
|
|
|
inline void FreeRegionList::add_ordered(HeapRegion* hr) {
|
|
|
|
check_mt_safety();
|
|
|
|
assert((length() == 0 && _head == NULL && _tail == NULL) ||
|
|
|
|
(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;
|
|
|
|
}
|
|
|
|
|
2014-03-14 10:15:46 +01:00
|
|
|
inline void FreeRegionList::add_as_head(HeapRegion* hr) {
|
2011-03-29 22:36:16 -04:00
|
|
|
assert((length() == 0 && _head == NULL && _tail == NULL) ||
|
|
|
|
(length() > 0 && _head != NULL && _tail != NULL),
|
|
|
|
hrs_ext_msg(this, "invariant"));
|
2014-03-14 10:15:46 +01:00
|
|
|
// add() will verify the region and check mt safety.
|
|
|
|
add(hr);
|
2011-03-29 22:36:16 -04:00
|
|
|
|
|
|
|
// Now link the region.
|
|
|
|
if (_head != NULL) {
|
|
|
|
hr->set_next(_head);
|
2014-02-28 15:27:09 +01:00
|
|
|
_head->set_prev(hr);
|
2011-03-29 22:36:16 -04:00
|
|
|
} else {
|
|
|
|
_tail = hr;
|
|
|
|
}
|
|
|
|
_head = hr;
|
|
|
|
}
|
|
|
|
|
2014-03-14 10:15:46 +01:00
|
|
|
inline void FreeRegionList::add_as_tail(HeapRegion* hr) {
|
|
|
|
check_mt_safety();
|
2011-01-19 19:30:42 -05:00
|
|
|
assert((length() == 0 && _head == NULL && _tail == NULL) ||
|
|
|
|
(length() > 0 && _head != NULL && _tail != NULL),
|
2011-03-04 17:13:19 -05:00
|
|
|
hrs_ext_msg(this, "invariant"));
|
2014-02-28 15:27:09 +01:00
|
|
|
// add() will verify the region and check mt safety.
|
2014-03-14 10:15:46 +01:00
|
|
|
add(hr);
|
2011-01-19 19:30:42 -05:00
|
|
|
|
|
|
|
// Now link the region.
|
|
|
|
if (_tail != NULL) {
|
|
|
|
_tail->set_next(hr);
|
2014-02-28 15:27:09 +01:00
|
|
|
hr->set_prev(_tail);
|
2011-01-19 19:30:42 -05:00
|
|
|
} else {
|
|
|
|
_head = hr;
|
|
|
|
}
|
|
|
|
_tail = hr;
|
|
|
|
}
|
|
|
|
|
2014-03-14 10:15:46 +01:00
|
|
|
inline HeapRegion* FreeRegionList::remove_head() {
|
2011-03-04 17:13:19 -05:00
|
|
|
assert(!is_empty(), hrs_ext_msg(this, "the list should not be empty"));
|
2011-01-19 19:30:42 -05:00
|
|
|
assert(length() > 0 && _head != NULL && _tail != NULL,
|
2011-03-04 17:13:19 -05:00
|
|
|
hrs_ext_msg(this, "invariant"));
|
2011-01-19 19:30:42 -05:00
|
|
|
|
|
|
|
// We need to unlink it first.
|
|
|
|
HeapRegion* hr = _head;
|
|
|
|
_head = hr->next();
|
|
|
|
if (_head == NULL) {
|
|
|
|
_tail = NULL;
|
2014-02-28 15:27:09 +01:00
|
|
|
} else {
|
|
|
|
_head->set_prev(NULL);
|
2011-01-19 19:30:42 -05:00
|
|
|
}
|
|
|
|
hr->set_next(NULL);
|
|
|
|
|
2014-02-28 15:27:09 +01:00
|
|
|
if (_last == hr) {
|
|
|
|
_last = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove() will verify the region and check mt safety.
|
2014-03-14 10:15:46 +01:00
|
|
|
remove(hr);
|
2011-01-19 19:30:42 -05:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2014-03-14 10:15:46 +01:00
|
|
|
inline HeapRegion* FreeRegionList::remove_head_or_null() {
|
|
|
|
check_mt_safety();
|
2011-01-19 19:30:42 -05:00
|
|
|
if (!is_empty()) {
|
|
|
|
return remove_head();
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-28 15:27:09 +01:00
|
|
|
inline HeapRegion* FreeRegionList::remove_tail() {
|
|
|
|
assert(!is_empty(), hrs_ext_msg(this, "The list should not be empty"));
|
|
|
|
assert(length() > 0 && _head != NULL && _tail != NULL,
|
|
|
|
hrs_ext_msg(this, "invariant"));
|
|
|
|
|
|
|
|
// We need to unlink it first
|
|
|
|
HeapRegion* hr = _tail;
|
|
|
|
|
|
|
|
_tail = hr->prev();
|
|
|
|
if (_tail == NULL) {
|
|
|
|
_head = NULL;
|
|
|
|
} else {
|
|
|
|
_tail->set_next(NULL);
|
|
|
|
}
|
|
|
|
hr->set_prev(NULL);
|
|
|
|
|
|
|
|
if (_last == hr) {
|
|
|
|
_last = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove() will verify the region and check mt safety.
|
|
|
|
remove(hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline HeapRegion* FreeRegionList::remove_tail_or_null() {
|
|
|
|
check_mt_safety();
|
|
|
|
|
|
|
|
if (!is_empty()) {
|
|
|
|
return remove_tail();
|
|
|
|
} else {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
inline HeapRegion* FreeRegionList::remove_region(bool from_head) {
|
|
|
|
if (from_head) {
|
|
|
|
return remove_head_or_null();
|
|
|
|
} else {
|
|
|
|
return remove_tail_or_null();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-01-19 19:30:42 -05:00
|
|
|
#endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP
|