Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/jfr/utilities/jfrIterator.hpp
41149 views
1
/*
2
* Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
#ifndef SHARE_JFR_UTILITIES_JFRITERATOR_HPP
26
#define SHARE_JFR_UTILITIES_JFRITERATOR_HPP
27
28
#include "memory/allocation.hpp"
29
30
template <typename List>
31
class StopOnNullCondition {
32
typedef typename List::Node Node;
33
private:
34
List& _list;
35
mutable Node* _node;
36
public:
37
StopOnNullCondition(List& list) : _list(list), _node(list.head()) {}
38
bool has_next() const {
39
return _node != NULL;
40
}
41
Node* next() const {
42
assert(_node != NULL, "invariant");
43
Node* temp = _node;
44
_node = (Node*)_node->_next;
45
return temp;
46
}
47
};
48
49
template <typename List>
50
class StopOnNullConditionRemoval {
51
typedef typename List::Node Node;
52
private:
53
List& _list;
54
mutable Node* _node;
55
public:
56
StopOnNullConditionRemoval(List& list) : _list(list), _node(NULL) {}
57
bool has_next() const {
58
_node = _list.remove();
59
return _node != NULL;
60
}
61
Node* next() const {
62
assert(_node != NULL, "invariant");
63
return _node;
64
}
65
};
66
67
template <typename List, template <typename> class ContinuationPredicate>
68
class Navigator {
69
public:
70
typedef typename List::Node Node;
71
Navigator(List& list) : _continuation(list) {}
72
bool has_next() const {
73
return _continuation.has_next();
74
}
75
Node* next() const {
76
return _continuation.next();
77
}
78
private:
79
ContinuationPredicate<List> _continuation;
80
mutable Node* _node;
81
};
82
83
template <typename List>
84
class NavigatorStopOnNull : public Navigator<List, StopOnNullCondition> {
85
public:
86
NavigatorStopOnNull(List& list) : Navigator<List, StopOnNullCondition>(list) {}
87
};
88
89
template <typename List>
90
class NavigatorStopOnNullRemoval : public Navigator<List, StopOnNullConditionRemoval> {
91
public:
92
NavigatorStopOnNullRemoval(List& list) : Navigator<List, StopOnNullConditionRemoval>(list) {}
93
};
94
95
template<typename List, template <typename> class Navigator, typename AP = StackObj>
96
class IteratorHost : public AP {
97
private:
98
Navigator<List> _navigator;
99
public:
100
typedef typename List::NodePtr NodePtr;
101
IteratorHost(List& list) : AP(), _navigator(list) {}
102
void reset() { _navigator.reset(); }
103
bool has_next() const { return _navigator.has_next(); }
104
NodePtr next() const { return _navigator.next(); }
105
};
106
107
template<typename List, typename AP = StackObj>
108
class StopOnNullIterator : public IteratorHost<List, NavigatorStopOnNull, AP> {
109
public:
110
StopOnNullIterator(List& list) : IteratorHost<List, NavigatorStopOnNull, AP>(list) {}
111
};
112
113
template<typename List, typename AP = StackObj>
114
class StopOnNullIteratorRemoval : public IteratorHost<List, NavigatorStopOnNullRemoval, AP> {
115
public:
116
StopOnNullIteratorRemoval(List& list) : IteratorHost<List, NavigatorStopOnNullRemoval, AP>(list) {}
117
};
118
119
#endif // SHARE_JFR_UTILITIES_JFRITERATOR_HPP
120
121