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 #include "utilities/macros.hpp"
30
31 class Bytes: AllStatic {
32 private:
33 #ifndef AMD64
34 // Helper function for swap_u8
35 static inline u8 swap_u8_base(u4 x, u4 y); // compiler-dependent implementation
36 #endif // AMD64
37
38 public:
39 // Efficient reading and writing of unaligned unsigned data in platform-specific byte ordering
40 template <typename T>
41 static inline T get_native(const void* p) {
42 assert(p != NULL, "null pointer");
43
44 T x;
45
46 if (is_aligned(p, sizeof(T))) {
47 x = *(T*)p;
48 } else {
|
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 #include "utilities/align.hpp"
30 #include "utilities/macros.hpp"
31
32 class Bytes: AllStatic {
33 private:
34 #ifndef AMD64
35 // Helper function for swap_u8
36 static inline u8 swap_u8_base(u4 x, u4 y); // compiler-dependent implementation
37 #endif // AMD64
38
39 public:
40 // Efficient reading and writing of unaligned unsigned data in platform-specific byte ordering
41 template <typename T>
42 static inline T get_native(const void* p) {
43 assert(p != NULL, "null pointer");
44
45 T x;
46
47 if (is_aligned(p, sizeof(T))) {
48 x = *(T*)p;
49 } else {
|