1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/cpu/x86/vm/bytes_x86.hpp Wed Apr 27 01:25:04 2016 +0800 1.3 @@ -0,0 +1,89 @@ 1.4 +/* 1.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef CPU_X86_VM_BYTES_X86_HPP 1.29 +#define CPU_X86_VM_BYTES_X86_HPP 1.30 + 1.31 +#include "memory/allocation.hpp" 1.32 + 1.33 +class Bytes: AllStatic { 1.34 + private: 1.35 +#ifndef AMD64 1.36 + // Helper function for swap_u8 1.37 + static inline u8 swap_u8_base(u4 x, u4 y); // compiler-dependent implementation 1.38 +#endif // AMD64 1.39 + 1.40 + public: 1.41 + // Returns true if the byte ordering used by Java is different from the native byte ordering 1.42 + // of the underlying machine. For example, this is true for Intel x86, but false for Solaris 1.43 + // on Sparc. 1.44 + static inline bool is_Java_byte_ordering_different(){ return true; } 1.45 + 1.46 + 1.47 + // Efficient reading and writing of unaligned unsigned data in platform-specific byte ordering 1.48 + // (no special code is needed since x86 CPUs can access unaligned data) 1.49 + static inline u2 get_native_u2(address p) { return *(u2*)p; } 1.50 + static inline u4 get_native_u4(address p) { return *(u4*)p; } 1.51 + static inline u8 get_native_u8(address p) { return *(u8*)p; } 1.52 + 1.53 + static inline void put_native_u2(address p, u2 x) { *(u2*)p = x; } 1.54 + static inline void put_native_u4(address p, u4 x) { *(u4*)p = x; } 1.55 + static inline void put_native_u8(address p, u8 x) { *(u8*)p = x; } 1.56 + 1.57 + 1.58 + // Efficient reading and writing of unaligned unsigned data in Java 1.59 + // byte ordering (i.e. big-endian ordering). Byte-order reversal is 1.60 + // needed since x86 CPUs use little-endian format. 1.61 + static inline u2 get_Java_u2(address p) { return swap_u2(get_native_u2(p)); } 1.62 + static inline u4 get_Java_u4(address p) { return swap_u4(get_native_u4(p)); } 1.63 + static inline u8 get_Java_u8(address p) { return swap_u8(get_native_u8(p)); } 1.64 + 1.65 + static inline void put_Java_u2(address p, u2 x) { put_native_u2(p, swap_u2(x)); } 1.66 + static inline void put_Java_u4(address p, u4 x) { put_native_u4(p, swap_u4(x)); } 1.67 + static inline void put_Java_u8(address p, u8 x) { put_native_u8(p, swap_u8(x)); } 1.68 + 1.69 + 1.70 + // Efficient swapping of byte ordering 1.71 + static inline u2 swap_u2(u2 x); // compiler-dependent implementation 1.72 + static inline u4 swap_u4(u4 x); // compiler-dependent implementation 1.73 + static inline u8 swap_u8(u8 x); 1.74 +}; 1.75 + 1.76 + 1.77 +// The following header contains the implementations of swap_u2, swap_u4, and swap_u8[_base] 1.78 +#ifdef TARGET_OS_ARCH_linux_x86 1.79 +# include "bytes_linux_x86.inline.hpp" 1.80 +#endif 1.81 +#ifdef TARGET_OS_ARCH_solaris_x86 1.82 +# include "bytes_solaris_x86.inline.hpp" 1.83 +#endif 1.84 +#ifdef TARGET_OS_ARCH_windows_x86 1.85 +# include "bytes_windows_x86.inline.hpp" 1.86 +#endif 1.87 +#ifdef TARGET_OS_ARCH_bsd_x86 1.88 +# include "bytes_bsd_x86.inline.hpp" 1.89 +#endif 1.90 + 1.91 + 1.92 +#endif // CPU_X86_VM_BYTES_X86_HPP