Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/jfr/utilities/jfrBigEndian.hpp
38920 views
1
/*
2
* Copyright (c) 2012, 2018, 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_VM_JFR_UTILITIES_JFRBIGENDIAN_HPP
26
#define SHARE_VM_JFR_UTILITIES_JFRBIGENDIAN_HPP
27
28
#include "memory/allocation.hpp"
29
#include "utilities/macros.hpp"
30
#ifdef TARGET_ARCH_x86
31
# include "bytes_x86.hpp"
32
#endif
33
#ifdef TARGET_ARCH_sparc
34
# include "bytes_sparc.hpp"
35
#endif
36
#ifdef TARGET_ARCH_zero
37
# include "bytes_zero.hpp"
38
#endif
39
#ifdef TARGET_ARCH_arm
40
# include "bytes_arm.hpp"
41
#endif
42
#ifdef TARGET_ARCH_ppc
43
# include "bytes_ppc.hpp"
44
#endif
45
#ifdef TARGET_ARCH_aarch32
46
# include "bytes_aarch32.hpp"
47
#endif
48
49
#ifndef VM_LITTLE_ENDIAN
50
# define bigendian_16(x) (x)
51
# define bigendian_32(x) (x)
52
# define bigendian_64(x) (x)
53
#else
54
# define bigendian_16(x) Bytes::swap_u2(x)
55
# define bigendian_32(x) Bytes::swap_u4(x)
56
# define bigendian_64(x) Bytes::swap_u8(x)
57
#endif
58
59
class JfrBigEndian : AllStatic {
60
private:
61
template <typename T>
62
static T read_bytes(const address location);
63
template <typename T>
64
static T read_unaligned(const address location);
65
public:
66
static bool platform_supports_unaligned_reads(void);
67
static bool is_aligned(const void* location, size_t size);
68
template <typename T>
69
static T read(const void* location);
70
};
71
72
inline bool JfrBigEndian::is_aligned(const void* location, size_t size) {
73
assert(size <= sizeof(u8), "just checking");
74
if (size == sizeof(u1)) {
75
return true;
76
}
77
// check address alignment for datum access
78
return (((uintptr_t)location & (size -1)) == 0);
79
}
80
81
template <>
82
inline u1 JfrBigEndian::read_bytes(const address location) {
83
return (*location & 0xFF);
84
}
85
86
template <>
87
inline u2 JfrBigEndian::read_bytes(const address location) {
88
return Bytes::get_Java_u2(location);
89
}
90
91
template <>
92
inline u4 JfrBigEndian::read_bytes(const address location) {
93
return Bytes::get_Java_u4(location);
94
}
95
96
template <>
97
inline u8 JfrBigEndian::read_bytes(const address location) {
98
return Bytes::get_Java_u8(location);
99
}
100
101
template <typename T>
102
inline T JfrBigEndian::read_unaligned(const address location) {
103
assert(location != NULL, "just checking");
104
switch (sizeof(T)) {
105
case sizeof(u1) :
106
return read_bytes<u1>(location);
107
case sizeof(u2):
108
return read_bytes<u2>(location);
109
case sizeof(u4):
110
return read_bytes<u4>(location);
111
case sizeof(u8):
112
return read_bytes<u8>(location);
113
default:
114
assert(false, "not reach");
115
}
116
return 0;
117
}
118
119
inline bool JfrBigEndian::platform_supports_unaligned_reads(void) {
120
#if defined(IA32) || defined(AMD64) || defined(PPC) || defined(S390)
121
return true;
122
#elif defined(SPARC) || defined(ARM) || defined(AARCH64) || defined(AARCH32)
123
return false;
124
#else
125
#warning "Unconfigured platform"
126
return false;
127
#endif
128
}
129
130
template<typename T>
131
inline T JfrBigEndian::read(const void* location) {
132
assert(location != NULL, "just checking");
133
assert(sizeof(T) <= sizeof(u8), "no support for arbitrary sizes");
134
if (sizeof(T) == sizeof(u1)) {
135
return *(T*)location;
136
}
137
if (is_aligned(location, sizeof(T)) || platform_supports_unaligned_reads()) {
138
// fastest case
139
switch (sizeof(T)) {
140
case sizeof(u1):
141
return *(T*)location;
142
case sizeof(u2):
143
return bigendian_16(*(T*)(location));
144
case sizeof(u4):
145
return bigendian_32(*(T*)(location));
146
case sizeof(u8):
147
return bigendian_64(*(T*)(location));
148
}
149
}
150
return read_unaligned<T>((const address)location);
151
}
152
153
#endif // SHARE_VM_JFR_UTILITIES_JFRBIGENDIAN_HPP
154
155