tonyp@2472: /* jwilhelm@6422: * Copyright (c) 2011, 2014, 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: brutisso@6385: inline void HeapRegionSetBase::add(HeapRegion* hr) { brutisso@6385: check_mt_safety(); brutisso@6385: assert(hr->containing_set() == NULL, hrs_ext_msg(this, "should not already have a containing set %u")); tschatzl@7050: assert(hr->next() == NULL, hrs_ext_msg(this, "should not already be linked")); tschatzl@7050: assert(hr->prev() == NULL, hrs_ext_msg(this, "should not already be linked")); tonyp@2472: brutisso@6385: _count.increment(1u, hr->capacity()); brutisso@6385: hr->set_containing_set(this); brutisso@6385: verify_region(hr); tonyp@2472: } tonyp@2472: brutisso@6385: inline void HeapRegionSetBase::remove(HeapRegion* hr) { brutisso@6385: check_mt_safety(); brutisso@6385: verify_region(hr); tschatzl@7050: assert(hr->next() == NULL, hrs_ext_msg(this, "should already be unlinked")); tschatzl@7050: assert(hr->prev() == NULL, hrs_ext_msg(this, "should already be unlinked")); tonyp@2472: tonyp@2472: hr->set_containing_set(NULL); brutisso@6385: assert(_count.length() > 0, hrs_ext_msg(this, "pre-condition")); brutisso@6385: _count.decrement(1u, hr->capacity()); tonyp@2472: } tonyp@2472: jwilhelm@6422: inline void FreeRegionList::add_ordered(HeapRegion* hr) { tschatzl@7050: assert((length() == 0 && _head == NULL && _tail == NULL && _last == NULL) || jwilhelm@6422: (length() > 0 && _head != NULL && _tail != NULL), jwilhelm@6422: hrs_ext_msg(this, "invariant")); jwilhelm@6422: // add() will verify the region and check mt safety. jwilhelm@6422: add(hr); jwilhelm@6422: jwilhelm@6422: // Now link the region jwilhelm@6422: if (_head != NULL) { jwilhelm@6422: HeapRegion* curr; jwilhelm@6422: tschatzl@7091: if (_last != NULL && _last->hrm_index() < hr->hrm_index()) { jwilhelm@6422: curr = _last; jwilhelm@6422: } else { jwilhelm@6422: curr = _head; jwilhelm@6422: } jwilhelm@6422: jwilhelm@6422: // Find first entry with a Region Index larger than entry to insert. tschatzl@7091: while (curr != NULL && curr->hrm_index() < hr->hrm_index()) { jwilhelm@6422: curr = curr->next(); jwilhelm@6422: } jwilhelm@6422: jwilhelm@6422: hr->set_next(curr); jwilhelm@6422: jwilhelm@6422: if (curr == NULL) { jwilhelm@6422: // Adding at the end jwilhelm@6422: hr->set_prev(_tail); jwilhelm@6422: _tail->set_next(hr); jwilhelm@6422: _tail = hr; jwilhelm@6422: } else if (curr->prev() == NULL) { jwilhelm@6422: // Adding at the beginning jwilhelm@6422: hr->set_prev(NULL); jwilhelm@6422: _head = hr; jwilhelm@6422: curr->set_prev(hr); jwilhelm@6422: } else { jwilhelm@6422: hr->set_prev(curr->prev()); jwilhelm@6422: hr->prev()->set_next(hr); jwilhelm@6422: curr->set_prev(hr); jwilhelm@6422: } jwilhelm@6422: } else { jwilhelm@6422: // The list was empty jwilhelm@6422: _tail = hr; jwilhelm@6422: _head = hr; jwilhelm@6422: } jwilhelm@6422: _last = hr; jwilhelm@6422: } jwilhelm@6422: tschatzl@7050: inline HeapRegion* FreeRegionList::remove_from_head_impl() { tschatzl@7050: HeapRegion* result = _head; tschatzl@7050: _head = result->next(); tonyp@2472: if (_head == NULL) { tonyp@2472: _tail = NULL; jwilhelm@6422: } else { jwilhelm@6422: _head->set_prev(NULL); tonyp@2472: } tschatzl@7050: result->set_next(NULL); tschatzl@7050: return result; tschatzl@7050: } tschatzl@7050: tschatzl@7050: inline HeapRegion* FreeRegionList::remove_from_tail_impl() { tschatzl@7050: HeapRegion* result = _tail; tschatzl@7050: tschatzl@7050: _tail = result->prev(); tschatzl@7050: if (_tail == NULL) { tschatzl@7050: _head = NULL; tschatzl@7050: } else { tschatzl@7050: _tail->set_next(NULL); tschatzl@7050: } tschatzl@7050: result->set_prev(NULL); tschatzl@7050: return result; tschatzl@7050: } tschatzl@7050: tschatzl@7050: inline HeapRegion* FreeRegionList::remove_region(bool from_head) { tschatzl@7050: check_mt_safety(); tschatzl@7050: verify_optional(); tschatzl@7050: tschatzl@7050: if (is_empty()) { tschatzl@7050: return NULL; tschatzl@7050: } tschatzl@7050: assert(length() > 0 && _head != NULL && _tail != NULL, tschatzl@7050: hrs_ext_msg(this, "invariant")); tschatzl@7050: tschatzl@7050: HeapRegion* hr; tschatzl@7050: tschatzl@7050: if (from_head) { tschatzl@7050: hr = remove_from_head_impl(); tschatzl@7050: } else { tschatzl@7050: hr = remove_from_tail_impl(); tschatzl@7050: } tonyp@2472: jwilhelm@6422: if (_last == hr) { jwilhelm@6422: _last = NULL; jwilhelm@6422: } jwilhelm@6422: jwilhelm@6422: // remove() will verify the region and check mt safety. brutisso@6385: remove(hr); tonyp@2472: return hr; tonyp@2472: } tonyp@2472: tschatzl@7050: #endif // SHARE_VM_GC_IMPLEMENTATION_G1_HEAPREGIONSET_INLINE_HPP tonyp@2472: