author | stefank |
Thu, 09 May 2019 14:28:30 +0200 | |
changeset 54786 | ebf733a324d4 |
parent 53244 | 9807daeb47c4 |
permissions | -rw-r--r-- |
4013 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. |
4013 | 3 |
* Copyright 2007, 2008, 2009 Red Hat, Inc. |
4 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
5 |
* |
|
6 |
* This code is free software; you can redistribute it and/or modify it |
|
7 |
* under the terms of the GNU General Public License version 2 only, as |
|
8 |
* published by the Free Software Foundation. |
|
9 |
* |
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
14 |
* accompanied this code). |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License version |
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4013
diff
changeset
|
20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4013
diff
changeset
|
21 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4013
diff
changeset
|
22 |
* questions. |
4013 | 23 |
* |
24 |
*/ |
|
25 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
47216
diff
changeset
|
26 |
#ifndef CPU_ZERO_BYTES_ZERO_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
47216
diff
changeset
|
27 |
#define CPU_ZERO_BYTES_ZERO_HPP |
7397 | 28 |
|
29 |
#include "memory/allocation.hpp" |
|
30 |
||
4013 | 31 |
typedef union unaligned { |
32 |
u4 u; |
|
33 |
u2 us; |
|
34 |
u8 ul; |
|
35 |
} __attribute__((packed)) unaligned; |
|
36 |
||
37 |
class Bytes: AllStatic { |
|
38 |
public: |
|
39 |
// Efficient reading and writing of unaligned unsigned data in |
|
40 |
// platform-specific byte ordering. |
|
41 |
static inline u2 get_native_u2(address p){ |
|
42 |
unaligned *up = (unaligned *) p; |
|
43 |
return up->us; |
|
44 |
} |
|
45 |
||
46 |
static inline u4 get_native_u4(address p) { |
|
47 |
unaligned *up = (unaligned *) p; |
|
48 |
return up->u; |
|
49 |
} |
|
50 |
||
51 |
static inline u8 get_native_u8(address p) { |
|
52 |
unaligned *up = (unaligned *) p; |
|
53 |
return up->ul; |
|
54 |
} |
|
55 |
||
56 |
static inline void put_native_u2(address p, u2 x) { |
|
57 |
unaligned *up = (unaligned *) p; |
|
58 |
up->us = x; |
|
59 |
} |
|
60 |
||
61 |
static inline void put_native_u4(address p, u4 x) { |
|
62 |
unaligned *up = (unaligned *) p; |
|
63 |
up->u = x; |
|
64 |
} |
|
65 |
||
66 |
static inline void put_native_u8(address p, u8 x) { |
|
67 |
unaligned *up = (unaligned *) p; |
|
68 |
up->ul = x; |
|
69 |
} |
|
70 |
||
71 |
// Efficient reading and writing of unaligned unsigned data in Java |
|
72 |
// byte ordering (i.e. big-endian ordering). |
|
73 |
#ifdef VM_LITTLE_ENDIAN |
|
74 |
// Byte-order reversal is needed |
|
75 |
static inline u2 get_Java_u2(address p) { |
|
76 |
return (u2(p[0]) << 8) | |
|
77 |
(u2(p[1]) ); |
|
78 |
} |
|
79 |
static inline u4 get_Java_u4(address p) { |
|
80 |
return (u4(p[0]) << 24) | |
|
81 |
(u4(p[1]) << 16) | |
|
82 |
(u4(p[2]) << 8) | |
|
83 |
(u4(p[3]) ); |
|
84 |
} |
|
85 |
static inline u8 get_Java_u8(address p) { |
|
86 |
u4 hi, lo; |
|
87 |
hi = (u4(p[0]) << 24) | |
|
88 |
(u4(p[1]) << 16) | |
|
89 |
(u4(p[2]) << 8) | |
|
90 |
(u4(p[3]) ); |
|
91 |
lo = (u4(p[4]) << 24) | |
|
92 |
(u4(p[5]) << 16) | |
|
93 |
(u4(p[6]) << 8) | |
|
94 |
(u4(p[7]) ); |
|
95 |
return u8(lo) | (u8(hi) << 32); |
|
96 |
} |
|
97 |
||
98 |
static inline void put_Java_u2(address p, u2 x) { |
|
99 |
p[0] = x >> 8; |
|
100 |
p[1] = x; |
|
101 |
} |
|
102 |
static inline void put_Java_u4(address p, u4 x) { |
|
103 |
p[0] = x >> 24; |
|
104 |
p[1] = x >> 16; |
|
105 |
p[2] = x >> 8; |
|
106 |
p[3] = x; |
|
107 |
} |
|
108 |
static inline void put_Java_u8(address p, u8 x) { |
|
109 |
u4 hi, lo; |
|
110 |
lo = x; |
|
111 |
hi = x >> 32; |
|
112 |
p[0] = hi >> 24; |
|
113 |
p[1] = hi >> 16; |
|
114 |
p[2] = hi >> 8; |
|
115 |
p[3] = hi; |
|
116 |
p[4] = lo >> 24; |
|
117 |
p[5] = lo >> 16; |
|
118 |
p[6] = lo >> 8; |
|
119 |
p[7] = lo; |
|
120 |
} |
|
121 |
||
122 |
// Efficient swapping of byte ordering |
|
123 |
static inline u2 swap_u2(u2 x); |
|
124 |
static inline u4 swap_u4(u4 x); |
|
125 |
static inline u8 swap_u8(u8 x); |
|
126 |
#else |
|
127 |
// No byte-order reversal is needed |
|
128 |
static inline u2 get_Java_u2(address p) { |
|
129 |
return get_native_u2(p); |
|
130 |
} |
|
131 |
static inline u4 get_Java_u4(address p) { |
|
132 |
return get_native_u4(p); |
|
133 |
} |
|
134 |
static inline u8 get_Java_u8(address p) { |
|
135 |
return get_native_u8(p); |
|
136 |
} |
|
137 |
||
138 |
static inline void put_Java_u2(address p, u2 x) { |
|
139 |
put_native_u2(p, x); |
|
140 |
} |
|
141 |
static inline void put_Java_u4(address p, u4 x) { |
|
142 |
put_native_u4(p, x); |
|
143 |
} |
|
144 |
static inline void put_Java_u8(address p, u8 x) { |
|
145 |
put_native_u8(p, x); |
|
146 |
} |
|
147 |
||
148 |
// No byte-order reversal is needed |
|
149 |
static inline u2 swap_u2(u2 x) { return x; } |
|
150 |
static inline u4 swap_u4(u4 x) { return x; } |
|
151 |
static inline u8 swap_u8(u8 x) { return x; } |
|
152 |
#endif // VM_LITTLE_ENDIAN |
|
153 |
}; |
|
154 |
||
155 |
#ifdef VM_LITTLE_ENDIAN |
|
156 |
// The following header contains the implementations of swap_u2, |
|
157 |
// swap_u4, and swap_u8 |
|
40010 | 158 |
|
159 |
#include OS_CPU_HEADER_INLINE(bytes) |
|
7397 | 160 |
|
4013 | 161 |
#endif // VM_LITTLE_ENDIAN |
7397 | 162 |
|
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
47216
diff
changeset
|
163 |
#endif // CPU_ZERO_BYTES_ZERO_HPP |