Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/jfr/utilities/jfrNode.hpp
41149 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_JFRNODE_HPP
26
#define SHARE_JFR_UTILITIES_JFRNODE_HPP
27
28
#include "jfr/utilities/jfrTypes.hpp"
29
#include "memory/allocation.hpp"
30
#include "runtime/atomic.hpp"
31
32
const uint64_t JFR_NODE_LOGICAL_EXCISION_BIT = 1;
33
const uint64_t JFR_NODE_LOGICAL_INSERTION_BIT = 2;
34
const uint64_t JFR_NODE_MASK = ~(JFR_NODE_LOGICAL_INSERTION_BIT | JFR_NODE_LOGICAL_EXCISION_BIT);
35
36
template <typename Node>
37
inline bool cas(Node** address, Node* current, Node* exchange) {
38
return Atomic::cmpxchg(address, current, exchange) == current;
39
}
40
41
template <typename Node>
42
inline bool is_marked_for_removal(const Node* ptr) {
43
return ((uint64_t)ptr & JFR_NODE_LOGICAL_EXCISION_BIT) == JFR_NODE_LOGICAL_EXCISION_BIT;
44
}
45
46
template <typename Node>
47
inline bool is_marked_for_insertion(const Node* ptr) {
48
return ((uint64_t)ptr & JFR_NODE_LOGICAL_INSERTION_BIT) == JFR_NODE_LOGICAL_INSERTION_BIT;
49
}
50
51
template <typename Node>
52
inline Node* set_excision_bit(const Node* ptr) {
53
return (Node*)(((uint64_t)ptr) | JFR_NODE_LOGICAL_EXCISION_BIT);
54
}
55
56
template <typename Node>
57
inline Node* set_insertion_bit(const Node* ptr) {
58
return (Node*)(((uint64_t)ptr) | JFR_NODE_LOGICAL_INSERTION_BIT);
59
}
60
61
template <typename Node>
62
inline Node* unmask(const Node* ptr) {
63
return (Node*)(((uint64_t)ptr) & JFR_NODE_MASK);
64
}
65
66
template <typename Derived, typename Version = traceid>
67
class JfrLinkedNode : public ResourceObj {
68
public:
69
typedef Version VersionType;
70
Derived* _next;
71
JfrLinkedNode() : _next(NULL) {}
72
JfrLinkedNode(JfrLinkedNode<Derived, VersionType>* next) : _next(next) {}
73
};
74
75
template <typename V>
76
class JfrKeyIsThisNode : public JfrLinkedNode<JfrKeyIsThisNode<V> > {
77
private:
78
V _value;
79
public:
80
typedef V Value;
81
typedef const JfrKeyIsThisNode<V>* Key;
82
JfrKeyIsThisNode(const Value value = NULL) : JfrLinkedNode<JfrKeyIsThisNode<V> >(), _value(value) {}
83
Key key() const { return this; }
84
Value value() const { return _value; }
85
void set_value(Value value) { _value = value; }
86
};
87
88
template <typename V>
89
class JfrValueNode : public JfrLinkedNode<JfrValueNode<V> > {
90
private:
91
V _value;
92
public:
93
typedef V Value;
94
typedef Value Key;
95
JfrValueNode(const Value value = NULL) : JfrLinkedNode<JfrValueNode<V> >(), _value(value) {}
96
Key key() const { return value(); }
97
Value value() const { return _value; }
98
void set_value(Value value) { _value = value; }
99
};
100
101
template <typename V>
102
class JfrKeyIsFreeSizeNode : public JfrLinkedNode<JfrKeyIsFreeSizeNode<V> > {
103
private:
104
V _value;
105
public:
106
typedef V Value;
107
typedef size_t Key;
108
JfrKeyIsFreeSizeNode(const Value value = NULL) : JfrLinkedNode<JfrKeyIsFreeSizeNode<V> >(), _value(value) {}
109
Key key() const { return value()->free_size(); }
110
Value value() const { return _value; }
111
void set_value(Value value) { _value = value; }
112
};
113
114
#endif // SHARE_JFR_UTILITIES_JFRNODE_HPP
115
116