src/cpu/x86/vm/bytes_x86.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
equal deleted inserted replaced
-1:000000000000 0:f90c822e73f8
1 /*
2 * Copyright (c) 1997, 2010, 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 CPU_X86_VM_BYTES_X86_HPP
26 #define CPU_X86_VM_BYTES_X86_HPP
27
28 #include "memory/allocation.hpp"
29
30 class Bytes: AllStatic {
31 private:
32 #ifndef AMD64
33 // Helper function for swap_u8
34 static inline u8 swap_u8_base(u4 x, u4 y); // compiler-dependent implementation
35 #endif // AMD64
36
37 public:
38 // Returns true if the byte ordering used by Java is different from the native byte ordering
39 // of the underlying machine. For example, this is true for Intel x86, but false for Solaris
40 // on Sparc.
41 static inline bool is_Java_byte_ordering_different(){ return true; }
42
43
44 // Efficient reading and writing of unaligned unsigned data in platform-specific byte ordering
45 // (no special code is needed since x86 CPUs can access unaligned data)
46 static inline u2 get_native_u2(address p) { return *(u2*)p; }
47 static inline u4 get_native_u4(address p) { return *(u4*)p; }
48 static inline u8 get_native_u8(address p) { return *(u8*)p; }
49
50 static inline void put_native_u2(address p, u2 x) { *(u2*)p = x; }
51 static inline void put_native_u4(address p, u4 x) { *(u4*)p = x; }
52 static inline void put_native_u8(address p, u8 x) { *(u8*)p = x; }
53
54
55 // Efficient reading and writing of unaligned unsigned data in Java
56 // byte ordering (i.e. big-endian ordering). Byte-order reversal is
57 // needed since x86 CPUs use little-endian format.
58 static inline u2 get_Java_u2(address p) { return swap_u2(get_native_u2(p)); }
59 static inline u4 get_Java_u4(address p) { return swap_u4(get_native_u4(p)); }
60 static inline u8 get_Java_u8(address p) { return swap_u8(get_native_u8(p)); }
61
62 static inline void put_Java_u2(address p, u2 x) { put_native_u2(p, swap_u2(x)); }
63 static inline void put_Java_u4(address p, u4 x) { put_native_u4(p, swap_u4(x)); }
64 static inline void put_Java_u8(address p, u8 x) { put_native_u8(p, swap_u8(x)); }
65
66
67 // Efficient swapping of byte ordering
68 static inline u2 swap_u2(u2 x); // compiler-dependent implementation
69 static inline u4 swap_u4(u4 x); // compiler-dependent implementation
70 static inline u8 swap_u8(u8 x);
71 };
72
73
74 // The following header contains the implementations of swap_u2, swap_u4, and swap_u8[_base]
75 #ifdef TARGET_OS_ARCH_linux_x86
76 # include "bytes_linux_x86.inline.hpp"
77 #endif
78 #ifdef TARGET_OS_ARCH_solaris_x86
79 # include "bytes_solaris_x86.inline.hpp"
80 #endif
81 #ifdef TARGET_OS_ARCH_windows_x86
82 # include "bytes_windows_x86.inline.hpp"
83 #endif
84 #ifdef TARGET_OS_ARCH_bsd_x86
85 # include "bytes_bsd_x86.inline.hpp"
86 #endif
87
88
89 #endif // CPU_X86_VM_BYTES_X86_HPP

mercurial