Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/jfr/utilities/jfrIterator.hpp
38920 views
/*1* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_JFR_UTILITIES_JFRLISTITERATOR_HPP25#define SHARE_VM_JFR_UTILITIES_JFRLISTITERATOR_HPP2627#include "memory/allocation.hpp"2829enum jfr_iter_direction {30forward = 1,31backward32};3334template <typename Node>35class StopOnNullCondition : public AllStatic {36public:37static bool has_next(const Node* node) {38return node != NULL;39}40};4142template <typename List, template <typename> class ContinuationPredicate>43class Navigator {44public:45typedef typename List::Node Node;46typedef jfr_iter_direction Direction;47Navigator(List& list, Direction direction) :48_list(list), _node(direction == forward ? list.head() : list.tail()), _direction(direction) {}49bool has_next() const {50return ContinuationPredicate<Node>::has_next(_node);51}5253bool direction_forward() const {54return _direction == forward;55}5657Node* next() const {58assert(_node != NULL, "invariant");59Node* temp = _node;60_node = direction_forward() ? (Node*)_node->next() : (Node*)_node->prev();61return temp;62}6364void set_direction(Direction direction) {65_direction = direction;66}6768void reset(Direction direction) {69set_direction(direction);70_node = direction_forward() ? _list.head() : _list.tail();71}7273private:74List& _list;75mutable Node* _node;76Direction _direction;77};7879template <typename List>80class NavigatorStopOnNull : public Navigator<List, StopOnNullCondition> {81public:82NavigatorStopOnNull(List& list, jfr_iter_direction direction = forward) : Navigator<List, StopOnNullCondition>(list, direction) {}83};8485template<typename List, template <typename> class Navigator, typename AP = StackObj>86class IteratorHost : public AP {87private:88Navigator<List> _navigator;8990public:91typedef typename List::Node Node;92typedef jfr_iter_direction Direction;93IteratorHost(List& list, Direction direction = forward) : AP(), _navigator(list, direction) {}94void reset(Direction direction = forward) { _navigator.reset(direction); }95bool has_next() const { return _navigator.has_next(); }96Node* next() const { return _navigator.next(); }97void set_direction(Direction direction) { _navigator.set_direction(direction); }98};99100template<typename List, typename AP = StackObj>101class StopOnNullIterator : public IteratorHost<List, NavigatorStopOnNull, AP> {102public:103StopOnNullIterator(List& list, jfr_iter_direction direction = forward) : IteratorHost<List, NavigatorStopOnNull, AP>(list, direction) {}104};105106#endif // SHARE_VM_JFR_UTILITIES_JFRLISTITERATOR_HPP107108109