Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/jfr/leakprofiler/utilities/unifiedOopRef.inline.hpp
41155 views
1
/*
2
* Copyright (c) 2019, 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_LEAKPROFILER_UTILITIES_UNIFIEDOOPREF_INLINE_HPP
26
#define SHARE_JFR_LEAKPROFILER_UTILITIES_UNIFIEDOOPREF_INLINE_HPP
27
28
#include "jfr/leakprofiler/utilities/unifiedOopRef.hpp"
29
30
#include "oops/access.inline.hpp"
31
#include "utilities/debug.hpp"
32
33
template <typename T>
34
inline T UnifiedOopRef::addr() const {
35
return reinterpret_cast<T>(_value & ~uintptr_t(3));
36
}
37
38
// Visual Studio 2019 and earlier have a problem with reinterpret_cast
39
// when the new type is the same as the expression type. For example:
40
// reinterpret_cast<int>(1);
41
// "error C2440: 'reinterpret_cast': cannot convert from 'int' to 'int'"
42
// this specialization provides a workaround.
43
template<>
44
inline uintptr_t UnifiedOopRef::addr<uintptr_t>() const {
45
return _value & ~uintptr_t(3);
46
}
47
48
inline bool UnifiedOopRef::is_narrow() const {
49
return _value & 1;
50
}
51
52
inline bool UnifiedOopRef::is_native() const {
53
return _value & 2;
54
}
55
56
inline bool UnifiedOopRef::is_null() const {
57
return _value == 0;
58
}
59
60
inline UnifiedOopRef UnifiedOopRef::encode_in_native(const narrowOop* ref) {
61
assert(ref != NULL, "invariant");
62
UnifiedOopRef result = { reinterpret_cast<uintptr_t>(ref) | 3 };
63
assert(result.addr<narrowOop*>() == ref, "sanity");
64
return result;
65
}
66
67
inline UnifiedOopRef UnifiedOopRef::encode_in_native(const oop* ref) {
68
assert(ref != NULL, "invariant");
69
UnifiedOopRef result = { reinterpret_cast<uintptr_t>(ref) | 2 };
70
assert(result.addr<oop*>() == ref, "sanity");
71
return result;
72
}
73
74
inline UnifiedOopRef UnifiedOopRef::encode_in_heap(const narrowOop* ref) {
75
assert(ref != NULL, "invariant");
76
UnifiedOopRef result = { reinterpret_cast<uintptr_t>(ref) | 1 };
77
assert(result.addr<narrowOop*>() == ref, "sanity");
78
return result;
79
}
80
81
inline UnifiedOopRef UnifiedOopRef::encode_in_heap(const oop* ref) {
82
assert(ref != NULL, "invariant");
83
UnifiedOopRef result = { reinterpret_cast<uintptr_t>(ref) | 0 };
84
assert(result.addr<oop*>() == ref, "sanity");
85
return result;
86
}
87
88
inline UnifiedOopRef UnifiedOopRef::encode_null() {
89
UnifiedOopRef result = { 0 };
90
return result;
91
}
92
93
inline oop UnifiedOopRef::dereference() const {
94
if (is_native()) {
95
if (is_narrow()) {
96
return NativeAccess<AS_NO_KEEPALIVE>::oop_load(addr<narrowOop*>());
97
} else {
98
return NativeAccess<AS_NO_KEEPALIVE>::oop_load(addr<oop*>());
99
}
100
} else {
101
if (is_narrow()) {
102
return HeapAccess<AS_NO_KEEPALIVE>::oop_load(addr<narrowOop*>());
103
} else {
104
return HeapAccess<AS_NO_KEEPALIVE>::oop_load(addr<oop*>());
105
}
106
}
107
}
108
109
#endif // SHARE_JFR_LEAKPROFILER_UTILITIES_UNIFIEDOOPREF_INLINE_HPP
110
111