Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8245204: ZGC: Introduce ZListRemoveIterator
Reviewed-by: eosterlund, stefank
  • Loading branch information
pliden committed Jun 9, 2020
1 parent 4d8189b commit 63a3d8f0f295d2432c81b3f5279407c53368e823
Showing with 40 additions and 9 deletions.
  1. +19 −2 src/hotspot/share/gc/z/zList.hpp
  2. +21 −7 src/hotspot/share/gc/z/zList.inline.hpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2020, 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
@@ -88,7 +88,7 @@ class ZList {
void transfer(ZList<T>* list);
};

template <typename T, bool forward>
template <typename T, bool Forward>
class ZListIteratorImpl : public StackObj {
private:
const ZList<T>* const _list;
@@ -100,6 +100,17 @@ class ZListIteratorImpl : public StackObj {
bool next(T** elem);
};

template <typename T, bool Forward>
class ZListRemoveIteratorImpl : public StackObj {
private:
ZList<T>* const _list;

public:
ZListRemoveIteratorImpl(ZList<T>* list);

bool next(T** elem);
};

// Iterator types
#define ZLIST_FORWARD true
#define ZLIST_REVERSE false
@@ -116,4 +127,10 @@ class ZListReverseIterator : public ZListIteratorImpl<T, ZLIST_REVERSE> {
ZListReverseIterator(const ZList<T>* list);
};

template <typename T>
class ZListRemoveIterator : public ZListRemoveIteratorImpl<T, ZLIST_FORWARD> {
public:
ZListRemoveIterator(ZList<T>* list);
};

#endif // SHARE_GC_Z_ZLIST_HPP
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2020, 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
@@ -205,23 +205,33 @@ inline void ZList<T>::transfer(ZList<T>* list) {
}
}

template <typename T, bool forward>
inline ZListIteratorImpl<T, forward>::ZListIteratorImpl(const ZList<T>* list) :
template <typename T, bool Forward>
inline ZListIteratorImpl<T, Forward>::ZListIteratorImpl(const ZList<T>* list) :
_list(list),
_next(forward ? list->first() : list->last()) {}
_next(Forward ? list->first() : list->last()) {}

template <typename T, bool forward>
inline bool ZListIteratorImpl<T, forward>::next(T** elem) {
template <typename T, bool Forward>
inline bool ZListIteratorImpl<T, Forward>::next(T** elem) {
if (_next != NULL) {
*elem = _next;
_next = forward ? _list->next(_next) : _list->prev(_next);
_next = Forward ? _list->next(_next) : _list->prev(_next);
return true;
}

// No more elements
return false;
}

template <typename T, bool Forward>
inline ZListRemoveIteratorImpl<T, Forward>::ZListRemoveIteratorImpl(ZList<T>* list) :
_list(list) {}

template <typename T, bool Forward>
inline bool ZListRemoveIteratorImpl<T, Forward>::next(T** elem) {
*elem = Forward ? _list->remove_first() : _list->remove_last();
return *elem != NULL;
}

template <typename T>
inline ZListIterator<T>::ZListIterator(const ZList<T>* list) :
ZListIteratorImpl<T, ZLIST_FORWARD>(list) {}
@@ -230,4 +240,8 @@ template <typename T>
inline ZListReverseIterator<T>::ZListReverseIterator(const ZList<T>* list) :
ZListIteratorImpl<T, ZLIST_REVERSE>(list) {}

template <typename T>
inline ZListRemoveIterator<T>::ZListRemoveIterator(ZList<T>* list) :
ZListRemoveIteratorImpl<T, ZLIST_FORWARD>(list) {}

#endif // SHARE_GC_Z_ZLIST_INLINE_HPP

0 comments on commit 63a3d8f

Please sign in to comment.