diff -r 810409af12f1 -r f74ec3cbfcc0 src/hotspot/share/gc/z/zList.inline.hpp --- a/src/hotspot/share/gc/z/zList.inline.hpp Mon Oct 21 09:57:26 2019 +0200 +++ b/src/hotspot/share/gc/z/zList.inline.hpp Mon Oct 21 09:58:07 2019 +0200 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -25,14 +25,193 @@ #define SHARE_GC_Z_ZLIST_INLINE_HPP #include "gc/z/zList.hpp" +#include "utilities/debug.hpp" + +template +inline ZListNode::ZListNode(ZListNode* next, ZListNode* prev) : + _next(next), + _prev(prev) {} + +template +inline void ZListNode::set_unused() { + _next = NULL; + _prev = NULL; +} + +template +inline ZListNode::ZListNode() { + set_unused(); +} + +template +inline ZListNode::~ZListNode() { + set_unused(); +} + +template +inline bool ZListNode::is_unused() const { + return _next == NULL && _prev == NULL; +} + +template +inline void ZList::verify() const { + assert(_head._next->_prev == &_head, "List corrupt"); + assert(_head._prev->_next == &_head, "List corrupt"); +} + +template +inline void ZList::insert(ZListNode* before, ZListNode* node) { + verify(); + + assert(node->is_unused(), "Already in a list"); + node->_prev = before; + node->_next = before->_next; + before->_next = node; + node->_next->_prev = node; + + _size++; +} + +template +inline ZListNode* ZList::cast_to_inner(T* elem) const { + return &elem->_node; +} + +template +inline T* ZList::cast_to_outer(ZListNode* node) const { + return (T*)((uintptr_t)node - offset_of(T, _node)); +} + +template +inline ZList::ZList() : + _head(&_head, &_head), + _size(0) { + verify(); +} + +template +inline size_t ZList::size() const { + verify(); + return _size; +} + +template +inline bool ZList::is_empty() const { + return _size == 0; +} + +template +inline T* ZList::first() const { + return is_empty() ? NULL : cast_to_outer(_head._next); +} + +template +inline T* ZList::last() const { + return is_empty() ? NULL : cast_to_outer(_head._prev); +} + +template +inline T* ZList::next(T* elem) const { + verify(); + ZListNode* next = cast_to_inner(elem)->_next; + return (next == &_head) ? NULL : cast_to_outer(next); +} + +template +inline T* ZList::prev(T* elem) const { + verify(); + ZListNode* prev = cast_to_inner(elem)->_prev; + return (prev == &_head) ? NULL : cast_to_outer(prev); +} + +template +inline void ZList::insert_first(T* elem) { + insert(&_head, cast_to_inner(elem)); +} + +template +inline void ZList::insert_last(T* elem) { + insert(_head._prev, cast_to_inner(elem)); +} + +template +inline void ZList::insert_before(T* before, T* elem) { + insert(cast_to_inner(before)->_prev, cast_to_inner(elem)); +} + +template +inline void ZList::insert_after(T* after, T* elem) { + insert(cast_to_inner(after), cast_to_inner(elem)); +} + +template +inline void ZList::remove(T* elem) { + verify(); + + ZListNode* const node = cast_to_inner(elem); + assert(!node->is_unused(), "Not in a list"); + + ZListNode* const next = node->_next; + ZListNode* const prev = node->_prev; + assert(next->_prev == node, "List corrupt"); + assert(prev->_next == node, "List corrupt"); + + prev->_next = next; + next->_prev = prev; + node->set_unused(); + + _size--; +} + +template +inline T* ZList::remove_first() { + T* elem = first(); + if (elem != NULL) { + remove(elem); + } + + return elem; +} + +template +inline T* ZList::remove_last() { + T* elem = last(); + if (elem != NULL) { + remove(elem); + } + + return elem; +} + +template +inline void ZList::transfer(ZList* list) { + verify(); + + if (!list->is_empty()) { + list->_head._next->_prev = _head._prev; + list->_head._prev->_next = _head._prev->_next; + + _head._prev->_next = list->_head._next; + _head._prev = list->_head._prev; + + list->_head._next = &list->_head; + list->_head._prev = &list->_head; + + _size += list->_size; + list->_size = 0; + + list->verify(); + verify(); + } +} template -ZListIteratorImpl::ZListIteratorImpl(const ZList* list) : +inline ZListIteratorImpl::ZListIteratorImpl(const ZList* list) : _list(list), _next(forward ? list->first() : list->last()) {} template -bool ZListIteratorImpl::next(T** elem) { +inline bool ZListIteratorImpl::next(T** elem) { if (_next != NULL) { *elem = _next; _next = forward ? _list->next(_next) : _list->prev(_next); @@ -43,4 +222,12 @@ return false; } +template +inline ZListIterator::ZListIterator(const ZList* list) : + ZListIteratorImpl(list) {} + +template +inline ZListReverseIterator::ZListReverseIterator(const ZList* list) : + ZListIteratorImpl(list) {} + #endif // SHARE_GC_Z_ZLIST_INLINE_HPP