tonyp@2472: /* tonyp@3713: * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. tonyp@2472: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. tonyp@2472: * tonyp@2472: * This code is free software; you can redistribute it and/or modify it tonyp@2472: * under the terms of the GNU General Public License version 2 only, as tonyp@2472: * published by the Free Software Foundation. tonyp@2472: * tonyp@2472: * This code is distributed in the hope that it will be useful, but WITHOUT tonyp@2472: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or tonyp@2472: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License tonyp@2472: * version 2 for more details (a copy is included in the LICENSE file that tonyp@2472: * accompanied this code). tonyp@2472: * tonyp@2472: * You should have received a copy of the GNU General Public License version tonyp@2472: * 2 along with this work; if not, write to the Free Software Foundation, tonyp@2472: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. tonyp@2472: * tonyp@2472: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA tonyp@2472: * or visit www.oracle.com if you need additional information or have any tonyp@2472: * questions. tonyp@2472: * tonyp@2472: */ tonyp@2472: tonyp@2472: #ifndef SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP tonyp@2472: #define SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP tonyp@2472: tonyp@2472: #include "gc_implementation/g1/heapRegionSet.hpp" tonyp@2472: tonyp@2472: //////////////////// HeapRegionSetBase //////////////////// tonyp@2472: tonyp@2472: inline void HeapRegionSetBase::update_for_addition(HeapRegion* hr) { tonyp@2472: // Assumes the caller has already verified the region. tonyp@2472: tonyp@2472: _length += 1; tonyp@3957: _region_num += hr->region_num(); tonyp@2472: _total_used_bytes += hr->used(); tonyp@2472: } tonyp@2472: tonyp@2472: inline void HeapRegionSetBase::add_internal(HeapRegion* hr) { tonyp@2643: hrs_assert_region_ok(this, hr, NULL); tonyp@2643: assert(hr->next() == NULL, hrs_ext_msg(this, "should not already be linked")); tonyp@2472: tonyp@2472: update_for_addition(hr); tonyp@2472: hr->set_containing_set(this); tonyp@2472: } tonyp@2472: tonyp@2472: inline void HeapRegionSetBase::update_for_removal(HeapRegion* hr) { tonyp@2472: // Assumes the caller has already verified the region. tonyp@2643: assert(_length > 0, hrs_ext_msg(this, "pre-condition")); tonyp@2472: _length -= 1; tonyp@2472: tonyp@3957: uint region_num_diff = hr->region_num(); tonyp@2472: assert(region_num_diff <= _region_num, tonyp@3713: hrs_err_msg("[%s] region's region num: %u " tonyp@3713: "should be <= region num: %u", tonyp@2472: name(), region_num_diff, _region_num)); tonyp@2472: _region_num -= region_num_diff; tonyp@2472: tonyp@2472: size_t used_bytes = hr->used(); tonyp@2472: assert(used_bytes <= _total_used_bytes, tonyp@2643: hrs_err_msg("[%s] region's used bytes: "SIZE_FORMAT" " tonyp@2472: "should be <= used bytes: "SIZE_FORMAT, tonyp@2472: name(), used_bytes, _total_used_bytes)); tonyp@2472: _total_used_bytes -= used_bytes; tonyp@2472: } tonyp@2472: tonyp@2472: inline void HeapRegionSetBase::remove_internal(HeapRegion* hr) { tonyp@2643: hrs_assert_region_ok(this, hr, this); tonyp@2643: assert(hr->next() == NULL, hrs_ext_msg(this, "should already be unlinked")); tonyp@2472: tonyp@2472: hr->set_containing_set(NULL); tonyp@2472: update_for_removal(hr); tonyp@2472: } tonyp@2472: tonyp@2472: //////////////////// HeapRegionSet //////////////////// tonyp@2472: tonyp@2472: inline void HeapRegionSet::add(HeapRegion* hr) { tonyp@2643: hrs_assert_mt_safety_ok(this); tonyp@2472: // add_internal() will verify the region. tonyp@2472: add_internal(hr); tonyp@2472: } tonyp@2472: tonyp@2472: inline void HeapRegionSet::remove(HeapRegion* hr) { tonyp@2643: hrs_assert_mt_safety_ok(this); tonyp@2472: // remove_internal() will verify the region. tonyp@2472: remove_internal(hr); tonyp@2472: } tonyp@2472: tonyp@2472: inline void HeapRegionSet::remove_with_proxy(HeapRegion* hr, tonyp@2472: HeapRegionSet* proxy_set) { tonyp@2472: // No need to fo the MT safety check here given that this method tonyp@2472: // does not update the contents of the set but instead accumulates tonyp@2472: // the changes in proxy_set which is assumed to be thread-local. tonyp@2643: hrs_assert_sets_match(this, proxy_set); tonyp@2643: hrs_assert_region_ok(this, hr, this); tonyp@2472: tonyp@2472: hr->set_containing_set(NULL); tonyp@2472: proxy_set->update_for_addition(hr); tonyp@2472: } tonyp@2472: tonyp@2472: //////////////////// HeapRegionLinkedList //////////////////// tonyp@2472: tonyp@2714: inline void HeapRegionLinkedList::add_as_head(HeapRegion* hr) { tonyp@2714: hrs_assert_mt_safety_ok(this); tonyp@2714: assert((length() == 0 && _head == NULL && _tail == NULL) || tonyp@2714: (length() > 0 && _head != NULL && _tail != NULL), tonyp@2714: hrs_ext_msg(this, "invariant")); tonyp@2714: // add_internal() will verify the region. tonyp@2714: add_internal(hr); tonyp@2714: tonyp@2714: // Now link the region. tonyp@2714: if (_head != NULL) { tonyp@2714: hr->set_next(_head); tonyp@2714: } else { tonyp@2714: _tail = hr; tonyp@2714: } tonyp@2714: _head = hr; tonyp@2714: } tonyp@2714: tonyp@2472: inline void HeapRegionLinkedList::add_as_tail(HeapRegion* hr) { tonyp@2643: hrs_assert_mt_safety_ok(this); tonyp@2472: assert((length() == 0 && _head == NULL && _tail == NULL) || tonyp@2472: (length() > 0 && _head != NULL && _tail != NULL), tonyp@2643: hrs_ext_msg(this, "invariant")); tonyp@2472: // add_internal() will verify the region. tonyp@2472: add_internal(hr); tonyp@2472: tonyp@2472: // Now link the region. tonyp@2472: if (_tail != NULL) { tonyp@2472: _tail->set_next(hr); tonyp@2472: } else { tonyp@2472: _head = hr; tonyp@2472: } tonyp@2472: _tail = hr; tonyp@2472: } tonyp@2472: tonyp@2472: inline HeapRegion* HeapRegionLinkedList::remove_head() { tonyp@2643: hrs_assert_mt_safety_ok(this); tonyp@2643: assert(!is_empty(), hrs_ext_msg(this, "the list should not be empty")); tonyp@2472: assert(length() > 0 && _head != NULL && _tail != NULL, tonyp@2643: hrs_ext_msg(this, "invariant")); tonyp@2472: tonyp@2472: // We need to unlink it first. tonyp@2472: HeapRegion* hr = _head; tonyp@2472: _head = hr->next(); tonyp@2472: if (_head == NULL) { tonyp@2472: _tail = NULL; tonyp@2472: } tonyp@2472: hr->set_next(NULL); tonyp@2472: tonyp@2472: // remove_internal() will verify the region. tonyp@2472: remove_internal(hr); tonyp@2472: return hr; tonyp@2472: } tonyp@2472: tonyp@2472: inline HeapRegion* HeapRegionLinkedList::remove_head_or_null() { tonyp@2643: hrs_assert_mt_safety_ok(this); tonyp@2472: tonyp@2472: if (!is_empty()) { tonyp@2472: return remove_head(); tonyp@2472: } else { tonyp@2472: return NULL; tonyp@2472: } tonyp@2472: } tonyp@2472: tonyp@2472: #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP