Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/jfr/utilities/jfrLinkedList.inline.hpp
41152 views
1
/*
2
* Copyright (c) 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_JFRLINKEDLIST_INLINE_HPP
26
#define SHARE_JFR_UTILITIES_JFRLINKEDLIST_INLINE_HPP
27
28
#include "jfr/utilities/jfrLinkedList.hpp"
29
30
#include "runtime/atomic.hpp"
31
32
template <typename NodeType, typename AllocPolicy>
33
JfrLinkedList<NodeType, AllocPolicy>::JfrLinkedList() : _head(NULL) {}
34
35
template <typename NodeType, typename AllocPolicy>
36
bool JfrLinkedList<NodeType, AllocPolicy>::initialize() {
37
return true;
38
}
39
40
template <typename NodeType, typename AllocPolicy>
41
inline NodeType* JfrLinkedList<NodeType, AllocPolicy>::head() const {
42
return (NodeType*)Atomic::load_acquire(&_head);
43
}
44
45
template <typename NodeType, typename AllocPolicy>
46
inline bool JfrLinkedList<NodeType, AllocPolicy>::is_empty() const {
47
return NULL == head();
48
}
49
50
template <typename NodeType, typename AllocPolicy>
51
inline bool JfrLinkedList<NodeType, AllocPolicy>::is_nonempty() const {
52
return !is_empty();
53
}
54
55
template <typename NodeType, typename AllocPolicy>
56
inline void JfrLinkedList<NodeType, AllocPolicy>::add(NodeType* node) {
57
assert(node != NULL, "invariant");
58
NodePtr next;
59
do {
60
next = head();
61
node->_next = next;
62
} while (Atomic::cmpxchg(&_head, next, node) != next);
63
}
64
65
template <typename NodeType, typename AllocPolicy>
66
inline NodeType* JfrLinkedList<NodeType, AllocPolicy>::remove() {
67
NodePtr node;
68
NodePtr next;
69
do {
70
node = head();
71
if (node == NULL) break;
72
next = (NodePtr)node->_next;
73
} while (Atomic::cmpxchg(&_head, node, next) != node);
74
return node;
75
}
76
77
template <typename NodeType, typename AllocPolicy>
78
template <typename Callback>
79
void JfrLinkedList<NodeType, AllocPolicy>::iterate(Callback& cb) {
80
NodePtr current = head();
81
while (current != NULL) {
82
NodePtr next = (NodePtr)current->_next;
83
if (!cb.process(current)) {
84
return;
85
}
86
current = next;
87
}
88
}
89
90
template <typename NodeType, typename AllocPolicy>
91
NodeType* JfrLinkedList<NodeType, AllocPolicy>::excise(NodeType* prev, NodeType* node) {
92
NodePtr next = (NodePtr)node->_next;
93
if (prev == NULL) {
94
prev = Atomic::cmpxchg(&_head, node, next);
95
if (prev == node) {
96
return NULL;
97
}
98
}
99
assert(prev != NULL, "invariant");
100
while (prev->_next != node) {
101
prev = (NodePtr)prev->_next;
102
}
103
assert(prev->_next == node, "invariant");
104
prev->_next = next;
105
return prev;
106
}
107
108
template <typename NodeType, typename AllocPolicy>
109
bool JfrLinkedList<NodeType, AllocPolicy>::in_list(const NodeType* node) const {
110
assert(node != NULL, "invariant");
111
const NodeType* current = head();
112
while (current != NULL) {
113
if (current == node) {
114
return true;
115
}
116
current = (NodeType*)current->_next;
117
}
118
return false;
119
}
120
121
#endif // SHARE_JFR_UTILITIES_JFRLINKEDLIST_INLINE_HPP
122
123